From: Matthew Wilcox <willy@infradead.org>
To: "Fabio M. De Francesco" <fmdefrancesco@gmail.com>
Cc: outreachy-kernel@googlegroups.com,
David Kershner <david.kershner@unisys.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org,
Daniel Vetter <daniel@ffwll.ch>
Subject: Re: [Outreachy kernel] [PATCH v5] staging: unisys: visorhba: Convert module from IDR to XArray
Date: Mon, 3 May 2021 19:26:29 +0100 [thread overview]
Message-ID: <20210503182629.GE1847222@casper.infradead.org> (raw)
In-Reply-To: <20210427150719.30841-1-fmdefrancesco@gmail.com>
On Tue, Apr 27, 2021 at 05:07:19PM +0200, Fabio M. De Francesco wrote:
> Converted visorhba from IDR to XArray. The abstract data type XArray is
> more memory-efficient, parallelisable and cache friendly. It takes
> advantage of RCU to perform lookups without locking.
I think the commit message could use a little more work. The advantage
of the XArray over the IDR is that it has a better API (and the IDR
interface is deprecated).
> -static void setup_scsitaskmgmt_handles(struct idr *idrtable, spinlock_t *lock,
> - struct uiscmdrsp *cmdrsp,
> +static void 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(1, INT_MAX), GFP_KERNEL);
> + if (ret == 0)
> + cmdrsp->scsitaskmgmt.notify_handle = id;
> + ret = xa_alloc_irq(xa, &id, result, XA_LIMIT(1, INT_MAX), GFP_KERNEL);
> + if (ret == 0)
> + cmdrsp->scsitaskmgmt.notifyresult_handle = id;
> }
I think there's a preexisting bug here that you haven't fixed ;-)
Think through the failure case -- if we fail to allocate an ID, then we
can't send the command, because it won't be able to notify on completion.
So I'd start out by making this function return an int (0 on success,
errno on failure). Then if the first one succeeds and the second fails,
free the first one before returning an error.
> /*
> * cleanup_scsitaskmgmt_handles - Forget handles created by
> * setup_scsitaskmgmt_handles()
> - * @idrtable: The data object maintaining the pointer<-->int mappings
> + * @xa: The data object maintaining the pointer<-->int mappings
> * @cmdrsp: Response from the IOVM
> */
> -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);
> + xa_erase(xa, cmdrsp->scsitaskmgmt.notify_handle);
> if (cmdrsp->scsitaskmgmt.notifyresult_handle)
> - idr_remove(idrtable, cmdrsp->scsitaskmgmt.notifyresult_handle);
> + xa_erase(xa, cmdrsp->scsitaskmgmt.notifyresult_handle);
> }
These can then be unconditional, because cleanup_scsitaskmgmt_handles()
won't get called unless we sent the command.
> /*
> @@ -284,8 +257,7 @@ static int forward_taskmgmt_command(enum task_mgmt_types tasktype,
>
> /* issue TASK_MGMT_ABORT_TASK */
> cmdrsp->cmdtype = CMD_SCSITASKMGMT_TYPE;
> - setup_scsitaskmgmt_handles(&devdata->idr, &devdata->privlock, cmdrsp,
> - ¬ifyevent, ¬ifyresult);
> + setup_scsitaskmgmt_handles(&devdata->xa, cmdrsp, ¬ifyevent, ¬ifyresult);
This needs to check the result from setup() and decline to send the
command if it fails.
> /* save destination */
> cmdrsp->scsitaskmgmt.tasktype = tasktype;
> @@ -311,14 +283,14 @@ static int forward_taskmgmt_command(enum task_mgmt_types tasktype,
> dev_dbg(&scsidev->sdev_gendev,
> "visorhba: taskmgmt type=%d success; result=0x%x\n",
> tasktype, notifyresult);
> - cleanup_scsitaskmgmt_handles(&devdata->idr, cmdrsp);
> + cleanup_scsitaskmgmt_handles(&devdata->xa, cmdrsp);
> return SUCCESS;
>
> err_del_scsipending_ent:
> dev_dbg(&scsidev->sdev_gendev,
> "visorhba: taskmgmt type=%d not executed\n", tasktype);
> del_scsipending_ent(devdata, scsicmd_id);
> - cleanup_scsitaskmgmt_handles(&devdata->idr, cmdrsp);
> + cleanup_scsitaskmgmt_handles(&devdata->xa, cmdrsp);
... be sure not to call cleanup() on that path, though.
> return FAILED;
> }
>
prev parent reply other threads:[~2021-05-03 18:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-27 15:07 Fabio M. De Francesco
2021-05-03 16:31 ` Greg Kroah-Hartman
2021-05-03 18:41 ` Fabio M. De Francesco
2021-05-03 18:26 ` Matthew Wilcox [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210503182629.GE1847222@casper.infradead.org \
--to=willy@infradead.org \
--cc=daniel@ffwll.ch \
--cc=david.kershner@unisys.com \
--cc=fmdefrancesco@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=outreachy-kernel@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®