lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20210504115411.GF1847222@casper.infradead.org>
Date:   Tue, 4 May 2021 12:54:11 +0100
From:   Matthew Wilcox <willy@...radead.org>
To:     Dan Carpenter <dan.carpenter@...cle.com>
Cc:     "Fabio M. De Francesco" <fmdefrancesco@...il.com>,
        outreachy-kernel@...glegroups.com,
        David Kershner <david.kershner@...sys.com>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        sparmaintainer@...sys.com, linux-staging@...ts.linux.dev,
        linux-kernel@...r.kernel.org, Daniel Vetter <daniel@...ll.ch>
Subject: Re: [Outreachy kernel] Re: [PATCH v6] staging: unisys: visorhba:
 Convert module from IDR to XArray

On Tue, May 04, 2021 at 02:00:01PM +0300, Dan Carpenter wrote:
> On Tue, May 04, 2021 at 12:07:44PM +0200, Fabio M. De Francesco wrote:
> > -static void setup_scsitaskmgmt_handles(struct idr *idrtable, spinlock_t *lock,
> > -				       struct uiscmdrsp *cmdrsp,
> > +static int setup_scsitaskmgmt_handles(struct xarray *xa, struct uiscmdrsp *cmdrsp,
> >  				       wait_queue_head_t *event, int *result)
> >  {
> > -	/* specify the event that has to be triggered when this */
> > -	/* cmd is complete */
> > -	cmdrsp->scsitaskmgmt.notify_handle =
> > -		simple_idr_get(idrtable, event, lock);
> > -	cmdrsp->scsitaskmgmt.notifyresult_handle =
> > -		simple_idr_get(idrtable, result, lock);
> > +	int ret;
> > +	u32 id;
> > +
> > +	/* specify the event that has to be triggered when this cmd is complete */
> > +	ret = xa_alloc_irq(xa, &id, event, xa_limit_32b, GFP_KERNEL);
> > +	if (ret == 0)
> > +		cmdrsp->scsitaskmgmt.notify_handle = id;
> > +	else
> > +		return ret;
> 
> Reverse the condition.  Always do error handling, not success handling.
> Try keep the success path at one tab indent and the failure path at two
> tab indents.
> 
> 	ret = xa_alloc_irq(xa, &id, event, xa_limit_32b, GFP_KERNEL);
> 	if (ret)
> 		return ret;
> 	cmdrsp->scsitaskmgmt.notify_handle = id;
> 
> 	ret = xa_alloc_irq(xa, &id, result, xa_limit_32b, GFP_KERNEL);
> 	if (ret) {
> 		xa_erase(xa, cmdrsp->scsitaskmgmt.notify_handle);

umm.  When you put these things right next to each other, it's obvious
that should be xa_erase_irq().

> > -static void cleanup_scsitaskmgmt_handles(struct idr *idrtable,
> > +static void cleanup_scsitaskmgmt_handles(struct xarray *xa,
> >  					 struct uiscmdrsp *cmdrsp)
> >  {
> > -	if (cmdrsp->scsitaskmgmt.notify_handle)
> > -		idr_remove(idrtable, cmdrsp->scsitaskmgmt.notify_handle);
> > -	if (cmdrsp->scsitaskmgmt.notifyresult_handle)
> > -		idr_remove(idrtable, cmdrsp->scsitaskmgmt.notifyresult_handle);
> > +	xa_erase(xa, cmdrsp->scsitaskmgmt.notify_handle);
> > +	xa_erase(xa, cmdrsp->scsitaskmgmt.notifyresult_handle);

If this code were even run, assuming the appropriate lockdep options
were enabled, xarray would point out that you were taking a lock with
interrupts enabled that was previously taken with interrupts disabled.
That's a good thing!  Because before, this code was deleting entries
from the IDR with _no_ locking.

So these should both be xa_erase_irq().

> > @@ -1096,8 +1085,6 @@ static void visorhba_remove(struct visor_device *dev)
> >  	scsi_remove_host(scsihost);
> >  	scsi_host_put(scsihost);
> >  
> > -	idr_destroy(&devdata->idr);
> 
> Do we not have to call xa_destroy()?

Correct.  We covered this in earlier iterations of this series and I
don't feel like typing out the explanation again.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ