Skip to contentSkip to conversation

FC-NVMe csn initialisation

DISCUSSION Hannes Reinecke 3 participants 6 messages Apr 8, 2019 – Apr 10, 2019 NVMe

lore
Share & tools
lore
#0 lore raw

Hi James,

checking the FC-NVMe spec it states:

a) the CSN shall be equal to zero for the first NVMe_CMND IU for each NVMeoFC connection and shall be incremented by one for each subsequent command on the NVMeoFC connection;

yet we have:

static void
nvme_fc_init_queue(struct nvme_fc_ctrl *ctrl, int idx)

{
	struct nvme_fc_queue *queue;

	queue = &ctrl->queues[idx];
	memset(queue, 0, sizeof(*queue));
	queue->ctrl = ctrl;
	queue->qnum = idx;
	atomic_set(&queue->csn, 1);
	queue->dev = ctrl->dev;

Is this by design?
Or a simple bug?

Cheers,

Hannes

Signature · 5 lines
Dr. Hannes Reinecke		   Teamlead Storage & Networking
hare at suse.de			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg
GF: Felix Imend?rffer, Mary Higgins, Sri Rasiah
HRB 21284 (AG N?rnberg)
#1 lore raw
Quoted 3 lines

a) the CSN shall be equal to zero for the first NVMe_CMND IU for each NVMeoFC connection and shall be incremented by one for each subsequent command on the NVMeoFC connection;

I'm not sure it matters if the csn starts at 0. As long as the csn is incremented with every FC_CMD_IU that's put on the wire, I think we're good.

However, I do think I see a bug were nvme_fc_start_fcp_op() increments the queue->csn counter and then never puts the cmdiu on the transport queue.

This can happen when nvme_fc_map_data() returns an error.

/John

static blk_status_t
nvme_fc_start_fcp_op(struct nvme_fc_ctrl *ctrl, struct nvme_fc_queue *queue,
struct nvme_fc_fcp_op *op, u32 data_len,
enum nvmefc_fcp_datadir io_dir)

{
        struct nvme_fc_cmd_iu *cmdiu = &op->cmd_iu;
        struct nvme_command *sqe = &cmdiu->sqe;
        u32 csn;
        int ret, opstate;
   ...
        /* format the FC-NVME CMD IU and fcp_req */
        cmdiu->connection_id = cpu_to_be64(queue->connection_id);
        csn = atomic_inc_return(&queue->csn);
        cmdiu->csn = cpu_to_be32(csn);
  ...
        if (!(op->flags & FCOP_FLAGS_AEN)) {
                ret = nvme_fc_map_data(ctrl, op->rq, op);
                if (ret < 0) {
                        nvme_cleanup_cmd(op->rq);
                        nvme_fc_ctrl_put(ctrl);
                        if (ret == -ENOMEM || ret == -EAGAIN)
                                return BLK_STS_RESOURCE;
                        return BLK_STS_IOERR;
                }
        }
   ...
        ret = ctrl->lport->ops->fcp_io(&ctrl->lport->localport,
                                        &ctrl->rport->remoteport,
                                        queue->lldd_handle, &op->fcp_req);

?On 4/8/19, 4:38 AM, "Hannes Reinecke" <[email protected]> wrote:

Hi James,

checking the FC-NVMe spec it states:

a) the CSN shall be equal to zero for the first NVMe_CMND IU for each NVMeoFC connection and shall be incremented by one for each subsequent command on the NVMeoFC connection;

yet we have:

static void
nvme_fc_init_queue(struct nvme_fc_ctrl *ctrl, int idx) {
struct nvme_fc_queue *queue;

queue = &ctrl->queues[idx];
memset(queue, 0, sizeof(*queue));
queue->ctrl = ctrl;
queue->qnum = idx;
atomic_set(&queue->csn, 1);
queue->dev = ctrl->dev;

Is this by design?
Or a simple bug?

Cheers,

Hannes
--
Dr. Hannes Reinecke Teamlead Storage & Networking
hare at suse.de +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg
GF: Felix Imend?rffer, Mary Higgins, Sri Rasiah HRB 21284 (AG N?rnberg)

#2 lore raw
Quoted 71 lines · John
Quoted 3 lines

a) the CSN shall be equal to zero for the first NVMe_CMND IU for each NVMeoFC connection and shall be incremented by one for each subsequent command on the NVMeoFC connection;

I'm not sure it matters if the csn starts at 0. As long as the csn is incremented with every FC_CMD_IU that's put on the wire, I think we're good.

However, I do think I see a bug were nvme_fc_start_fcp_op() increments the queue->csn counter and then never puts the cmdiu on the transport queue.

This can happen when nvme_fc_map_data() returns an error.

/John

static blk_status_t
nvme_fc_start_fcp_op(struct nvme_fc_ctrl *ctrl, struct nvme_fc_queue *queue,
struct nvme_fc_fcp_op *op, u32 data_len,
enum nvmefc_fcp_datadir io_dir)

{
         struct nvme_fc_cmd_iu *cmdiu = &op->cmd_iu;
         struct nvme_command *sqe = &cmdiu->sqe;
         u32 csn;
         int ret, opstate;
    ...
         /* format the FC-NVME CMD IU and fcp_req */
         cmdiu->connection_id = cpu_to_be64(queue->connection_id);
         csn = atomic_inc_return(&queue->csn);
         cmdiu->csn = cpu_to_be32(csn);
   ...
         if (!(op->flags & FCOP_FLAGS_AEN)) {
                 ret = nvme_fc_map_data(ctrl, op->rq, op);
                 if (ret < 0) {
                         nvme_cleanup_cmd(op->rq);
                         nvme_fc_ctrl_put(ctrl);
                         if (ret == -ENOMEM || ret == -EAGAIN)
                                 return BLK_STS_RESOURCE;
                         return BLK_STS_IOERR;
                 }
         }
    ...
         ret = ctrl->lport->ops->fcp_io(&ctrl->lport->localport,
                                         &ctrl->rport->remoteport,
                                         queue->lldd_handle, &op->fcp_req);

?On 4/8/19, 4:38 AM, "Hannes Reinecke" <[email protected]> wrote:

Hi James,

checking the FC-NVMe spec it states:

a) the CSN shall be equal to zero for the first NVMe_CMND IU for each NVMeoFC connection and shall be incremented by one for each subsequent command on the NVMeoFC connection;

yet we have:

static void
nvme_fc_init_queue(struct nvme_fc_ctrl *ctrl, int idx) {
struct nvme_fc_queue *queue;

queue = &ctrl->queues[idx];
memset(queue, 0, sizeof(*queue));
queue->ctrl = ctrl;
queue->qnum = idx;
atomic_set(&queue->csn, 1);
queue->dev = ctrl->dev;

Is this by design?
Or a simple bug?

Cheers,

Quoted 9 lines

Hannes
--
Dr. Hannes Reinecke Teamlead Storage & Networking
hare at suse.de +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg
GF: Felix Imend?rffer, Mary Higgins, Sri Rasiah HRB 21284 (AG N?rnberg)

Good question. I believe a simple bug from a long time ago. The target side, for the most part, doesn't care about what the csn is until a fused io comes, then it would has to use the csn to pair them up.? As linux never sends fuse ios, csn is effectively irrelevant when used with linux.? If one were to be "spec compliant" yes, the target could choose to validate the connect cmd had cmdiu=0. But for any other command on the connection, order isn't dictated so there's no way to guess what the csn should be.

And I do agree with John. I'll send a patchup shortly.

-- james

#3 lore raw
Quoted 62 lines · James Smart
Quoted 39 lines · John
Quoted 4 lines

a) the CSN shall be equal to zero for the first NVMe_CMND IU for each ??? NVMeoFC connection and shall be incremented by one for each subsequent
??? command on the NVMeoFC connection;

I'm not sure it matters if the csn starts at 0. As long as the csn is incremented with every FC_CMD_IU that's put on the wire, I think we're good.

However, I do think I see a bug were nvme_fc_start_fcp_op() increments the queue->csn counter and then never puts the cmdiu on the transport queue.

This can happen when nvme_fc_map_data() returns an error.

/John

static blk_status_t
nvme_fc_start_fcp_op(struct nvme_fc_ctrl *ctrl, struct nvme_fc_queue *queue,
???????? struct nvme_fc_fcp_op *op, u32 data_len, ???????? enum nvmefc_fcp_datadir io_dir)
{
???????? struct nvme_fc_cmd_iu *cmdiu = &op->cmd_iu; ???????? struct nvme_command *sqe = &cmdiu->sqe;
???????? u32 csn;
???????? int ret, opstate;
??? ...
???????? /* format the FC-NVME CMD IU and fcp_req */ ???????? cmdiu->connection_id = cpu_to_be64(queue->connection_id); ???????? csn = atomic_inc_return(&queue->csn);
???????? cmdiu->csn = cpu_to_be32(csn);
?? ...
???????? if (!(op->flags & FCOP_FLAGS_AEN)) { ???????????????? ret = nvme_fc_map_data(ctrl, op->rq, op); ???????????????? if (ret < 0) {
???????????????????????? nvme_cleanup_cmd(op->rq); ???????????????????????? nvme_fc_ctrl_put(ctrl); ???????????????????????? if (ret == -ENOMEM || ret == -EAGAIN) ???????????????????????????????? return BLK_STS_RESOURCE;

Quoted 10 lines

???????????????????????? return BLK_STS_IOERR; ???????????????? }
???????? }
??? ...
???????? ret = ctrl->lport->ops->fcp_io(&ctrl->lport->localport, ???????????????????????????????????????? &ctrl->rport->remoteport, ???????????????????????????????????????? queue->lldd_handle, &op->fcp_req);

Good question. I believe a simple bug from a long time ago. The target side, for the most part, doesn't care about what the csn is until a fused io comes, then it would has to use the csn to pair them up.? As linux never sends fuse ios, csn is effectively irrelevant when used with linux.? If one were to be "spec compliant" yes, the target could choose to validate the connect cmd had cmdiu=0. But for any other command on the connection, order isn't dictated so there's no way to guess what the csn should be.

Quoted 2 lines

And I do agree with John. I'll send a patchup shortly.

Well, the _actual_ background of this question was that I'd been thinking if one could use csn to implement SQ flow control; after all, csn is pretty similar to the SQ Head pointer, albeit with a different modulo. If the spec would allow us to wrap-around csn at any arbitrary fixed number we wouldn't need to implement a separate SQ head pointer at all :-)
Sadly, FC-NVMe is pretty adamant that we should be wrapping around at UINT_MAX...

Cheers,

Hannes

Signature · 5 lines
Dr. Hannes Reinecke		   Teamlead Storage & Networking
hare at suse.de			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg
GF: Felix Imend?rffer, Mary Higgins, Sri Rasiah
HRB 21284 (AG N?rnberg)
#4 lore raw
Quoted 73 lines · Hannes Reinecke
Quoted 61 lines · James Smart
Quoted 38 lines · John
Quoted 4 lines

a) the CSN shall be equal to zero for the first NVMe_CMND IU for each ??? NVMeoFC connection and shall be incremented by one for each subsequent
??? command on the NVMeoFC connection;

I'm not sure it matters if the csn starts at 0. As long as the csn is incremented with every FC_CMD_IU that's put on the wire, I think we're good.

However, I do think I see a bug were nvme_fc_start_fcp_op() increments the queue->csn counter and then never puts the cmdiu on the transport queue.

This can happen when nvme_fc_map_data() returns an error.

/John

static blk_status_t
nvme_fc_start_fcp_op(struct nvme_fc_ctrl *ctrl, struct nvme_fc_queue *queue,
???????? struct nvme_fc_fcp_op *op, u32 data_len, ???????? enum nvmefc_fcp_datadir io_dir)
{
???????? struct nvme_fc_cmd_iu *cmdiu = &op->cmd_iu; ???????? struct nvme_command *sqe = &cmdiu->sqe;
???????? u32 csn;
???????? int ret, opstate;
??? ...
???????? /* format the FC-NVME CMD IU and fcp_req */ ???????? cmdiu->connection_id = cpu_to_be64(queue->connection_id); ???????? csn = atomic_inc_return(&queue->csn);
???????? cmdiu->csn = cpu_to_be32(csn);
?? ...
???????? if (!(op->flags & FCOP_FLAGS_AEN)) { ???????????????? ret = nvme_fc_map_data(ctrl, op->rq, op); ???????????????? if (ret < 0) {
???????????????????????? nvme_cleanup_cmd(op->rq); ???????????????????????? nvme_fc_ctrl_put(ctrl); ???????????????????????? if (ret == -ENOMEM || ret == -EAGAIN)

Quoted 10 lines

???????????????????????????????? return BLK_STS_RESOURCE; ???????????????????????? return BLK_STS_IOERR; ???????????????? }
???????? }
??? ...
???????? ret = ctrl->lport->ops->fcp_io(&ctrl->lport->localport, &ctrl->rport->remoteport,
queue->lldd_handle, &op->fcp_req);

Good question. I believe a simple bug from a long time ago. The target side, for the most part, doesn't care about what the csn is until a fused io comes, then it would has to use the csn to pair them up.? As linux never sends fuse ios, csn is effectively irrelevant when used with linux.? If one were to be "spec compliant" yes, the target could choose to validate the connect cmd had cmdiu=0. But for any other command on the connection, order isn't dictated so there's no way to guess what the csn should be.

Quoted 2 lines

And I do agree with John. I'll send a patchup shortly.

Well, the _actual_ background of this question was that I'd been thinking if one could use csn to implement SQ flow control; after all, csn is pretty similar to the SQ Head pointer, albeit with a different modulo. If the spec would allow us to wrap-around csn at any arbitrary fixed number we wouldn't need to implement a separate SQ head pointer at all :-)
Sadly, FC-NVMe is pretty adamant that we should be wrapping around at UINT_MAX...

Quoted 3 lines

Cheers,

Hannes

Nope. CSN is a different beast with different semantics. Why wouldn't you go to SQHD/SQTAIL like the standard says ? (which our initiators purposely ignore)

it actually wouldn't be such a big deal to implement in the transport - we already have the retry logic for other things, and the nvmet target does properly increment SQHD - by 1 on every command completion, thus it's compliant with fabric flow control style too.? But you could then pace SQHD updates to give you the flow control like you wanted (per spec). Granted the question would then be do all transports honor it per spec. ? It could also open to using more than a single io queues's depth worth of commands on a controller (can scale out by the number of queues; I dislike how many target resources we leave unused today), but it goes against some of the things Christoph was trying to do, one of which checking SQHD/SQTAIL.

-- james

#5 lore raw
Quoted 3 lines · James Smart

On 4/8/2019 11:08 PM, Hannes Reinecke wrote:

[ .. ]

Quoted 17 lines
Quoted 9 lines

Well, the _actual_ background of this question was that I'd been thinking if one could use csn to implement SQ flow control; after all, csn is pretty similar to the SQ Head pointer, albeit with a different modulo. If the spec would allow us to wrap-around csn at any arbitrary fixed number we wouldn't need to implement a separate SQ head pointer at all :-)
Sadly, FC-NVMe is pretty adamant that we should be wrapping around at UINT_MAX...

Quoted 3 lines

Cheers,

Hannes

Nope. CSN is a different beast with different semantics. Why wouldn't you go to SQHD/SQTAIL like the standard says ? (which our initiators purposely ignore)

Quoted 12 lines

it actually wouldn't be such a big deal to implement in the transport - we already have the retry logic for other things, and the nvmet target does properly increment SQHD - by 1 on every command completion, thus it's compliant with fabric flow control style too.? But you could then pace SQHD updates to give you the flow control like you wanted (per spec). Granted the question would then be do all transports honor it per spec. ? It could also open to using more than a single io queues's depth worth of commands on a controller (can scale out by the number of queues; I dislike how many target resources we leave unused today), but it goes against some of the things Christoph was trying to do, one of which checking SQHD/SQTAIL.

Yes, I'm aware. I just had been discussing with John, and we figured that having proper SQ flow control might actually help with the OnTap array. But of course, it'll need to be carefully measured so as not to incur regressions in the general case.

Cheers,

Hannes

Signature · 5 lines
Dr. Hannes Reinecke		   Teamlead Storage & Networking
hare at suse.de			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg
GF: Felix Imend?rffer, Mary Higgins, Sri Rasiah
HRB 21284 (AG N?rnberg)