On Tue, May 11, 2021 at 08:27:52PM -0700, Bart Van Assche wrote: > Define .init_cmd_priv and .exit_cmd_priv callback functions in struct > scsi_host_template. Set .cmd_size such that the SCSI core allocates > per-command private data. Use scsi_cmd_priv() to access that private > data. Remove the req_ring pointer from struct srp_rdma_ch since it is > no longer necessary. Convert srp_alloc_req_data() and srp_free_req_data() > into functions that initialize one instance of the SRP-private command > data. This is a micro-optimization since this patch removes several > pointer dereferences from the hot path. > > Note: due to commit e73a5e8e8003 ("scsi: core: Only return started requests > from scsi_host_find_tag()"), it is no longer necessary to protect the > completion path against duplicate responses. > > Cc: Nicolas Morey-Chaisemartin <nmoreychaisemartin@xxxxxxxx> > Signed-off-by: Bart Van Assche <bvanassche@xxxxxxx> > --- > drivers/infiniband/ulp/srp/ib_srp.c | 156 ++++++++++++---------------- > drivers/infiniband/ulp/srp/ib_srp.h | 2 - > 2 files changed, 65 insertions(+), 93 deletions(-) > > diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c > index 52db42af421b..773ac5929082 100644 > --- a/drivers/infiniband/ulp/srp/ib_srp.c > +++ b/drivers/infiniband/ulp/srp/ib_srp.c > @@ -965,69 +965,55 @@ static void srp_disconnect_target(struct srp_target_port *target) > } > } > > -static void srp_free_req_data(struct srp_target_port *target, > - struct srp_rdma_ch *ch) > +static int srp_exit_cmd_priv(struct Scsi_Host *shost, struct scsi_cmnd *cmd) > { > + struct srp_target_port *target = host_to_target(shost); > struct srp_device *dev = target->srp_host->srp_dev; > struct ib_device *ibdev = dev->dev; > - struct srp_request *req; > - int i; > + struct srp_request *req = scsi_cmd_priv(cmd); > > - if (!ch->req_ring) > - return; > - > - for (i = 0; i < target->req_ring_size; ++i) { > - req = &ch->req_ring[i]; > - if (dev->use_fast_reg) > - kfree(req->fr_list); > - if (req->indirect_dma_addr) { > - ib_dma_unmap_single(ibdev, req->indirect_dma_addr, > - target->indirect_size, > - DMA_TO_DEVICE); > - } > - kfree(req->indirect_desc); > + if (dev->use_fast_reg) > + kfree(req->fr_list); Isn't cleaner will be to ensure that fr_list is NULL for !dev->use_fast_reg path? In patch #4 https://lore.kernel.org/linux-rdma/20210512032752.16611-5-bvanassche@xxxxxxx Thanks