Linux-NVME Archive on lore.kernel.org
 help / color / Atom feed
From: Himanshu Madhani <himanshu.madhani@oracle.com>
To: James Smart <jsmart2021@gmail.com>, linux-nvme@lists.infradead.org
Cc: martin.petersen@oracle.com
Subject: Re: [PATCH 09/29] nvme-fc: Ensure private pointers are NULL if no data
Date: Thu, 26 Mar 2020 11:39:47 -0500
Message-ID: <e1a5f53d-1cd7-b3fe-b98a-38413483b92c@oracle.com> (raw)
In-Reply-To: <20200205183753.25959-10-jsmart2021@gmail.com>

On 2/5/2020 12:37 PM, James Smart wrote:
> Ensure that when allocations are done, and the lldd options indicate
> no private data is needed, that private pointers will be set to NULL
> (catches driver error that forgot to set private data size).
> 
> Slightly reorg the allocations so that private data follows allocations
> for LS request/response buffers. Ensures better alignments for the buffers
> as well as the private pointer.
> 
> Signed-off-by: James Smart <jsmart2021@gmail.com>
> ---
>   drivers/nvme/host/fc.c   | 81 ++++++++++++++++++++++++++++++------------------
>   drivers/nvme/target/fc.c |  5 ++-
>   2 files changed, 54 insertions(+), 32 deletions(-)
> 
> diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c
> index 2e5163600f63..1a58e3dc0399 100644
> --- a/drivers/nvme/host/fc.c
> +++ b/drivers/nvme/host/fc.c
> @@ -396,7 +396,10 @@ nvme_fc_register_localport(struct nvme_fc_port_info *pinfo,
>   	newrec->ops = template;
>   	newrec->dev = dev;
>   	ida_init(&newrec->endp_cnt);
> -	newrec->localport.private = &newrec[1];
> +	if (template->local_priv_sz)
> +		newrec->localport.private = &newrec[1];
> +	else
> +		newrec->localport.private = NULL;
>   	newrec->localport.node_name = pinfo->node_name;
>   	newrec->localport.port_name = pinfo->port_name;
>   	newrec->localport.port_role = pinfo->port_role;
> @@ -705,7 +708,10 @@ nvme_fc_register_remoteport(struct nvme_fc_local_port *localport,
>   	newrec->remoteport.localport = &lport->localport;
>   	newrec->dev = lport->dev;
>   	newrec->lport = lport;
> -	newrec->remoteport.private = &newrec[1];
> +	if (lport->ops->remote_priv_sz)
> +		newrec->remoteport.private = &newrec[1];
> +	else
> +		newrec->remoteport.private = NULL;
>   	newrec->remoteport.port_role = pinfo->port_role;
>   	newrec->remoteport.node_name = pinfo->node_name;
>   	newrec->remoteport.port_name = pinfo->port_name;
> @@ -1153,18 +1159,23 @@ nvme_fc_connect_admin_queue(struct nvme_fc_ctrl *ctrl,
>   	int ret, fcret = 0;
>   
>   	lsop = kzalloc((sizeof(*lsop) +
> -			 ctrl->lport->ops->lsrqst_priv_sz +
> -			 sizeof(*assoc_rqst) + sizeof(*assoc_acc)), GFP_KERNEL);
> +			 sizeof(*assoc_rqst) + sizeof(*assoc_acc) +
> +			 ctrl->lport->ops->lsrqst_priv_sz), GFP_KERNEL);
>   	if (!lsop) {
> +		dev_info(ctrl->ctrl.device,
> +			"NVME-FC{%d}: send Create Association failed: ENOMEM\n",
> +			ctrl->cnum);
>   		ret = -ENOMEM;
>   		goto out_no_memory;
>   	}
> -	lsreq = &lsop->ls_req;
>   
> -	lsreq->private = (void *)&lsop[1];
> -	assoc_rqst = (struct fcnvme_ls_cr_assoc_rqst *)
> -			(lsreq->private + ctrl->lport->ops->lsrqst_priv_sz);
> +	assoc_rqst = (struct fcnvme_ls_cr_assoc_rqst *)&lsop[1];
>   	assoc_acc = (struct fcnvme_ls_cr_assoc_acc *)&assoc_rqst[1];
> +	lsreq = &lsop->ls_req;
> +	if (ctrl->lport->ops->lsrqst_priv_sz)
> +		lsreq->private = &assoc_acc[1];
> +	else
> +		lsreq->private = NULL;
>   
>   	assoc_rqst->w0.ls_cmd = FCNVME_LS_CREATE_ASSOCIATION;
>   	assoc_rqst->desc_list_len =
> @@ -1262,18 +1273,23 @@ nvme_fc_connect_queue(struct nvme_fc_ctrl *ctrl, struct nvme_fc_queue *queue,
>   	int ret, fcret = 0;
>   
>   	lsop = kzalloc((sizeof(*lsop) +
> -			 ctrl->lport->ops->lsrqst_priv_sz +
> -			 sizeof(*conn_rqst) + sizeof(*conn_acc)), GFP_KERNEL);
> +			 sizeof(*conn_rqst) + sizeof(*conn_acc) +
> +			 ctrl->lport->ops->lsrqst_priv_sz), GFP_KERNEL);
>   	if (!lsop) {
> +		dev_info(ctrl->ctrl.device,
> +			"NVME-FC{%d}: send Create Connection failed: ENOMEM\n",
> +			ctrl->cnum);
>   		ret = -ENOMEM;
>   		goto out_no_memory;
>   	}
> -	lsreq = &lsop->ls_req;
>   
> -	lsreq->private = (void *)&lsop[1];
> -	conn_rqst = (struct fcnvme_ls_cr_conn_rqst *)
> -			(lsreq->private + ctrl->lport->ops->lsrqst_priv_sz);
> +	conn_rqst = (struct fcnvme_ls_cr_conn_rqst *)&lsop[1];
>   	conn_acc = (struct fcnvme_ls_cr_conn_acc *)&conn_rqst[1];
> +	lsreq = &lsop->ls_req;
> +	if (ctrl->lport->ops->lsrqst_priv_sz)
> +		lsreq->private = (void *)&conn_acc[1];
> +	else
> +		lsreq->private = NULL;
>   
>   	conn_rqst->w0.ls_cmd = FCNVME_LS_CREATE_CONNECTION;
>   	conn_rqst->desc_list_len = cpu_to_be32(
> @@ -1387,19 +1403,23 @@ nvme_fc_xmt_disconnect_assoc(struct nvme_fc_ctrl *ctrl)
>   	int ret;
>   
>   	lsop = kzalloc((sizeof(*lsop) +
> -			 ctrl->lport->ops->lsrqst_priv_sz +
> -			 sizeof(*discon_rqst) + sizeof(*discon_acc)),
> -			GFP_KERNEL);
> -	if (!lsop)
> -		/* couldn't sent it... too bad */
> +			sizeof(*discon_rqst) + sizeof(*discon_acc) +
> +			ctrl->lport->ops->lsrqst_priv_sz), GFP_KERNEL);
> +	if (!lsop) {
> +		dev_info(ctrl->ctrl.device,
> +			"NVME-FC{%d}: send Disconnect Association "
> +			"failed: ENOMEM\n",
> +			ctrl->cnum);
>   		return;
> +	}
>   
> -	lsreq = &lsop->ls_req;
> -
> -	lsreq->private = (void *)&lsop[1];
> -	discon_rqst = (struct fcnvme_ls_disconnect_assoc_rqst *)
> -			(lsreq->private + ctrl->lport->ops->lsrqst_priv_sz);
> +	discon_rqst = (struct fcnvme_ls_disconnect_assoc_rqst *)&lsop[1];
>   	discon_acc = (struct fcnvme_ls_disconnect_assoc_acc *)&discon_rqst[1];
> +	lsreq = &lsop->ls_req;
> +	if (ctrl->lport->ops->lsrqst_priv_sz)
> +		lsreq->private = (void *)&discon_acc[1];
> +	else
> +		lsreq->private = NULL;
>   
>   	discon_rqst->w0.ls_cmd = FCNVME_LS_DISCONNECT_ASSOC;
>   	discon_rqst->desc_list_len = cpu_to_be32(
> @@ -1785,15 +1805,17 @@ nvme_fc_init_aen_ops(struct nvme_fc_ctrl *ctrl)
>   	struct nvme_fc_fcp_op *aen_op;
>   	struct nvme_fc_cmd_iu *cmdiu;
>   	struct nvme_command *sqe;
> -	void *private;
> +	void *private = NULL;
>   	int i, ret;
>   
>   	aen_op = ctrl->aen_ops;
>   	for (i = 0; i < NVME_NR_AEN_COMMANDS; i++, aen_op++) {
> -		private = kzalloc(ctrl->lport->ops->fcprqst_priv_sz,
> +		if (ctrl->lport->ops->fcprqst_priv_sz) {
> +			private = kzalloc(ctrl->lport->ops->fcprqst_priv_sz,
>   						GFP_KERNEL);
> -		if (!private)
> -			return -ENOMEM;
> +			if (!private)
> +				return -ENOMEM;
> +		}
>   
>   		cmdiu = &aen_op->cmd_iu;
>   		sqe = &cmdiu->sqe;
> @@ -1824,9 +1846,6 @@ nvme_fc_term_aen_ops(struct nvme_fc_ctrl *ctrl)
>   
>   	aen_op = ctrl->aen_ops;
>   	for (i = 0; i < NVME_NR_AEN_COMMANDS; i++, aen_op++) {
> -		if (!aen_op->fcp_req.private)
> -			continue;
> -
>   		__nvme_fc_exit_request(ctrl, aen_op);
>   
>   		kfree(aen_op->fcp_req.private);
> diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c
> index 66de6bd8f4fd..66a60a218994 100644
> --- a/drivers/nvme/target/fc.c
> +++ b/drivers/nvme/target/fc.c
> @@ -1047,7 +1047,10 @@ nvmet_fc_register_targetport(struct nvmet_fc_port_info *pinfo,
>   
>   	newrec->fc_target_port.node_name = pinfo->node_name;
>   	newrec->fc_target_port.port_name = pinfo->port_name;
> -	newrec->fc_target_port.private = &newrec[1];
> +	if (template->target_priv_sz)
> +		newrec->fc_target_port.private = &newrec[1];
> +	else
> +		newrec->fc_target_port.private = NULL;
>   	newrec->fc_target_port.port_id = pinfo->port_id;
>   	newrec->fc_target_port.port_num = idx;
>   	INIT_LIST_HEAD(&newrec->tgt_list);
> 

Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>

_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

  parent reply index

Thread overview: 80+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-05 18:37 [PATCH 00/29] nvme-fc/nvmet-fc: Add FC-NVME-2 disconnect association support James Smart
2020-02-05 18:37 ` [PATCH 01/29] nvme-fc: Sync header to FC-NVME-2 rev 1.08 James Smart
2020-02-28 20:36   ` Sagi Grimberg
2020-03-06  8:16   ` Hannes Reinecke
2020-03-26 16:10   ` Himanshu Madhani
2020-02-05 18:37 ` [PATCH 02/29] nvmet-fc: fix typo in comment James Smart
2020-02-28 20:36   ` Sagi Grimberg
2020-03-06  8:17   ` Hannes Reinecke
2020-03-26 16:10   ` Himanshu Madhani
2020-02-05 18:37 ` [PATCH 03/29] nvme-fc and nvmet-fc: revise LLDD api for LS reception and LS request James Smart
2020-02-28 20:38   ` Sagi Grimberg
2020-03-06  8:19   ` Hannes Reinecke
2020-03-26 16:16   ` Himanshu Madhani
2020-02-05 18:37 ` [PATCH 04/29] nvme-fc nvmet_fc nvme_fcloop: adapt code to changed names in api header James Smart
2020-02-28 20:40   ` Sagi Grimberg
2020-03-06  8:21   ` Hannes Reinecke
2020-03-26 16:26   ` Himanshu Madhani
2020-02-05 18:37 ` [PATCH 05/29] lpfc: " James Smart
2020-02-28 20:40   ` Sagi Grimberg
2020-03-06  8:25   ` Hannes Reinecke
2020-03-26 16:30   ` Himanshu Madhani
2020-02-05 18:37 ` [PATCH 06/29] nvme-fcloop: Fix deallocation of working context James Smart
2020-02-28 20:43   ` Sagi Grimberg
2020-03-06  8:34   ` Hannes Reinecke
2020-03-26 16:35   ` Himanshu Madhani
2020-02-05 18:37 ` [PATCH 07/29] nvme-fc nvmet-fc: refactor for common LS definitions James Smart
2020-03-06  8:35   ` Hannes Reinecke
2020-03-26 16:36   ` Himanshu Madhani
2020-02-05 18:37 ` [PATCH 08/29] nvmet-fc: Better size LS buffers James Smart
2020-02-28 21:04   ` Sagi Grimberg
2020-03-06  8:36   ` Hannes Reinecke
2020-02-05 18:37 ` [PATCH 09/29] nvme-fc: Ensure private pointers are NULL if no data James Smart
2020-02-28 21:05   ` Sagi Grimberg
2020-03-06  8:44   ` Hannes Reinecke
2020-03-26 16:39   ` Himanshu Madhani [this message]
2020-02-05 18:37 ` [PATCH 10/29] nvmefc: Use common definitions for LS names, formatting, and validation James Smart
2020-03-06  8:44   ` Hannes Reinecke
2020-03-26 16:41   ` Himanshu Madhani
2020-02-05 18:37 ` [PATCH 11/29] nvme-fc: convert assoc_active flag to atomic James Smart
2020-02-28 21:08   ` Sagi Grimberg
2020-03-06  8:47   ` Hannes Reinecke
2020-03-26 19:16   ` Himanshu Madhani
2020-02-05 18:37 ` [PATCH 12/29] nvme-fc: Add Disconnect Association Rcv support James Smart
2020-03-06  9:00   ` Hannes Reinecke
2020-02-05 18:37 ` [PATCH 13/29] nvmet-fc: add LS failure messages James Smart
2020-03-06  9:01   ` Hannes Reinecke
2020-02-05 18:37 ` [PATCH 14/29] nvmet-fc: perform small cleanups on unneeded checks James Smart
2020-03-06  9:01   ` Hannes Reinecke
2020-02-05 18:37 ` [PATCH 15/29] nvmet-fc: track hostport handle for associations James Smart
2020-03-06  9:02   ` Hannes Reinecke
2020-02-05 18:37 ` [PATCH 16/29] nvmet-fc: rename ls_list to ls_rcv_list James Smart
2020-03-06  9:03   ` Hannes Reinecke
2020-02-05 18:37 ` [PATCH 17/29] nvmet-fc: Add Disconnect Association Xmt support James Smart
2020-03-06  9:04   ` Hannes Reinecke
2020-02-05 18:37 ` [PATCH 18/29] nvme-fcloop: refactor to enable target to host LS James Smart
2020-03-06  9:06   ` Hannes Reinecke
2020-02-05 18:37 ` [PATCH 19/29] nvme-fcloop: add target to host LS request support James Smart
2020-03-06  9:07   ` Hannes Reinecke
2020-02-05 18:37 ` [PATCH 20/29] lpfc: Refactor lpfc nvme headers James Smart
2020-03-06  9:18   ` Hannes Reinecke
2020-02-05 18:37 ` [PATCH 21/29] lpfc: Refactor nvmet_rcv_ctx to create lpfc_async_xchg_ctx James Smart
2020-03-06  9:19   ` Hannes Reinecke
2020-02-05 18:37 ` [PATCH 22/29] lpfc: Commonize lpfc_async_xchg_ctx state and flag definitions James Smart
2020-03-06  9:19   ` Hannes Reinecke
2020-02-05 18:37 ` [PATCH 23/29] lpfc: Refactor NVME LS receive handling James Smart
2020-03-06  9:20   ` Hannes Reinecke
2020-02-05 18:37 ` [PATCH 24/29] lpfc: Refactor Send LS Request support James Smart
2020-03-06  9:20   ` Hannes Reinecke
2020-02-05 18:37 ` [PATCH 25/29] lpfc: Refactor Send LS Abort support James Smart
2020-03-06  9:21   ` Hannes Reinecke
2020-02-05 18:37 ` [PATCH 26/29] lpfc: Refactor Send LS Response support James Smart
2020-03-06  9:21   ` Hannes Reinecke
2020-02-05 18:37 ` [PATCH 27/29] lpfc: nvme: Add Receive LS Request and Send LS Response support to nvme James Smart
2020-03-06  9:23   ` Hannes Reinecke
2020-02-05 18:37 ` [PATCH 28/29] lpfc: nvmet: Add support for NVME LS request hosthandle James Smart
2020-03-06  9:23   ` Hannes Reinecke
2020-02-05 18:37 ` [PATCH 29/29] lpfc: nvmet: Add Send LS Request and Abort LS Request support James Smart
2020-03-06  9:24   ` Hannes Reinecke
2020-03-06  9:26 ` [PATCH 00/29] nvme-fc/nvmet-fc: Add FC-NVME-2 disconnect association support Hannes Reinecke
2020-03-31 14:29 ` Christoph Hellwig

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=e1a5f53d-1cd7-b3fe-b98a-38413483b92c@oracle.com \
    --to=himanshu.madhani@oracle.com \
    --cc=jsmart2021@gmail.com \
    --cc=linux-nvme@lists.infradead.org \
    --cc=martin.petersen@oracle.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

Linux-NVME Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-nvme/0 linux-nvme/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-nvme linux-nvme/ https://lore.kernel.org/linux-nvme \
		linux-nvme@lists.infradead.org
	public-inbox-index linux-nvme

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-nvme


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git