From: James Smart <james.smart@broadcom.com>
To: Hannes Reinecke <hare@suse.de>, Christoph Hellwig <hch@lst.de>
Cc: Keith Busch <keith.busch@wdc.com>,
linux-nvme@lists.infradead.org, Sagi Grimberg <sagi@grimberg.me>,
Chaitanya Kulkarni <Chaitanya.Kulkarni@wdc.com>
Subject: Re: [PATCH 1/3] nvmet/fc: Sanitize tgtport reference counting for LS requests
Date: Fri, 6 Mar 2020 17:00:01 -0800 [thread overview]
Message-ID: <ba9055c6-746f-607e-d2c3-d354ec591e59@broadcom.com> (raw)
In-Reply-To: <20200306130440.16864-2-hare@suse.de>
On 3/6/2020 5:04 AM, Hannes Reinecke wrote:
> We need to validate the targetport upon first access, otherwise
> there's a risk of accessing an invalid targetport.
>
> Signed-off-by: Hannes Reinecke <hare@suse.de>
> ---
> drivers/nvme/target/fc.c | 23 ++++++++++++-----------
> 1 file changed, 12 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c
> index 0a0f03b2faf3..aff959300ef3 100644
> --- a/drivers/nvme/target/fc.c
> +++ b/drivers/nvme/target/fc.c
> @@ -358,6 +358,7 @@ __nvmet_fc_finish_ls_req(struct nvmet_fc_ls_req_op *lsop)
>
> if (!lsop->req_queued) {
> spin_unlock_irqrestore(&tgtport->lock, flags);
> + nvmet_fc_tgtport_put(tgtport);
> return;
> }
>
> @@ -386,9 +387,6 @@ __nvmet_fc_send_ls_req(struct nvmet_fc_tgtport *tgtport,
> if (!tgtport->ops->ls_req)
> return -EOPNOTSUPP;
>
> - if (!nvmet_fc_tgtport_get(tgtport))
> - return -ESHUTDOWN;
> -
> lsreq->done = done;
> lsop->req_queued = false;
> INIT_LIST_HEAD(&lsop->lsreq_list);
> @@ -396,10 +394,9 @@ __nvmet_fc_send_ls_req(struct nvmet_fc_tgtport *tgtport,
> lsreq->rqstdma = fc_dma_map_single(tgtport->dev, lsreq->rqstaddr,
> lsreq->rqstlen + lsreq->rsplen,
> DMA_BIDIRECTIONAL);
> - if (fc_dma_mapping_error(tgtport->dev, lsreq->rqstdma)) {
> - ret = -EFAULT;
> - goto out_puttgtport;
> - }
> + if (fc_dma_mapping_error(tgtport->dev, lsreq->rqstdma))
> + return -EFAULT;
> +
> lsreq->rspdma = lsreq->rqstdma + lsreq->rqstlen;
>
> spin_lock_irqsave(&tgtport->lock, flags);
> @@ -426,9 +423,6 @@ __nvmet_fc_send_ls_req(struct nvmet_fc_tgtport *tgtport,
> fc_dma_unmap_single(tgtport->dev, lsreq->rqstdma,
> (lsreq->rqstlen + lsreq->rsplen),
> DMA_BIDIRECTIONAL);
> -out_puttgtport:
> - nvmet_fc_tgtport_put(tgtport);
> -
> return ret;
> }
>
> @@ -482,14 +476,19 @@ nvmet_fc_xmt_disconnect_assoc(struct nvmet_fc_tgt_assoc *assoc)
> struct nvmefc_ls_req *lsreq;
> int ret;
>
> + if (!nvmet_fc_tgtport_get(tgtport))
> + return;
> +
> /*
> * If ls_req is NULL or no hosthandle, it's an older lldd and no
> * message is normal. Otherwise, send unless the hostport has
> * already been invalidated by the lldd.
> */
> if (!tgtport->ops->ls_req || !assoc->hostport ||
> - assoc->hostport->invalid)
> + assoc->hostport->invalid) {
> + nvmet_fc_tgtport_put(tgtport);
> return;
> + }
>
> lsop = kzalloc((sizeof(*lsop) +
> sizeof(*discon_rqst) + sizeof(*discon_acc) +
> @@ -498,6 +497,7 @@ nvmet_fc_xmt_disconnect_assoc(struct nvmet_fc_tgt_assoc *assoc)
> dev_info(tgtport->dev,
> "{%d:%d} send Disconnect Association failed: ENOMEM\n",
> tgtport->fc_target_port.port_num, assoc->a_id);
> + nvmet_fc_tgtport_put(tgtport);
> return;
> }
>
> @@ -522,6 +522,7 @@ nvmet_fc_xmt_disconnect_assoc(struct nvmet_fc_tgt_assoc *assoc)
> "{%d:%d} XMT Disconnect Association failed: %d\n",
> tgtport->fc_target_port.port_num, assoc->a_id, ret);
> kfree(lsop);
> + nvmet_fc_tgtport_put(tgtport);
> }
> }
>
I guess I don't see anything wrong with this, but it seems messier to
handle the ref counting. I prefer it to be on the send/completion
localized to the common op processing. Also creates a different
implementation than what was done on the host side, even though the rest
is very similar.
Reviewed-by: James Smart <james.smart@broadcom.com>
_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
next prev parent reply other threads:[~2020-03-07 1:00 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-06 13:04 [PATCH 0/3] nvmet/fcloop fixes Hannes Reinecke
2020-03-06 13:04 ` [PATCH 1/3] nvmet/fc: Sanitize tgtport reference counting for LS requests Hannes Reinecke
2020-03-06 22:11 ` Sagi Grimberg
2020-03-07 1:00 ` James Smart [this message]
2020-03-10 16:52 ` Christoph Hellwig
2020-03-06 13:04 ` [PATCH 2/3] nvme/fcloop: short-circuit LS requests if no association is present Hannes Reinecke
2020-03-06 22:12 ` Sagi Grimberg
2020-03-07 1:11 ` James Smart
2020-03-07 8:39 ` Hannes Reinecke
2020-03-06 13:04 ` [PATCH 3/3] nvme/fcloop: flush workqueue before calling nvme_fc_unregister_remoteport() Hannes Reinecke
2020-03-06 22:12 ` Sagi Grimberg
2020-03-07 1:12 ` James Smart
2020-03-07 8:41 ` Hannes Reinecke
2020-03-31 14:24 ` [PATCH 0/3] nvmet/fcloop fixes Christoph Hellwig
2020-04-16 10:37 ` Hannes Reinecke
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=ba9055c6-746f-607e-d2c3-d354ec591e59@broadcom.com \
--to=james.smart@broadcom.com \
--cc=Chaitanya.Kulkarni@wdc.com \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=keith.busch@wdc.com \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
/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