scsi: target: core: Add gfp_t arg to target_cmd_init_cdb()
authorMike Christie <michael.christie@oracle.com>
Sat, 27 Feb 2021 16:59:56 +0000 (10:59 -0600)
committerMartin K. Petersen <martin.petersen@oracle.com>
Thu, 4 Mar 2021 22:37:02 +0000 (17:37 -0500)
tcm_loop could be used like a normal block device, so we can't use
GFP_KERNEL and should use GFP_NOIO. This adds a gfp_t arg to
target_cmd_init_cdb() and converts the users. For every driver but loop
GFP_KERNEL is kept.

This will also be useful in subsequent patches where loop needs to do
target_submit_prep() from interrupt context to get a ref to the se_device,
and so it will need to use GFP_ATOMIC.

Link: https://lore.kernel.org/r/20210227170006.5077-16-michael.christie@oracle.com
Tested-by: Laurence Oberman <loberman@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Mike Christie <michael.christie@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/infiniband/ulp/srpt/ib_srpt.c
drivers/scsi/qla2xxx/tcm_qla2xxx.c
drivers/target/iscsi/iscsi_target.c
drivers/target/loopback/tcm_loop.c
drivers/target/target_core_transport.c
drivers/target/target_core_xcopy.c
drivers/target/tcm_fc/tfc_cmd.c
drivers/vhost/scsi.c
drivers/xen/xen-scsiback.c
include/target/target_core_fabric.h

index 87741e0b4bcad1bb4ac554dab8ae7ee1c01cb98c..51c386a215f5e47a508fefaa7dc8cbd3560a5597 100644 (file)
@@ -1537,7 +1537,8 @@ static void srpt_handle_cmd(struct srpt_rdma_ch *ch,
                goto busy;
        }
 
-       if (target_submit_prep(cmd, srp_cmd->cdb, sg, sg_cnt, NULL, 0, NULL, 0))
+       if (target_submit_prep(cmd, srp_cmd->cdb, sg, sg_cnt, NULL, 0, NULL, 0,
+                              GFP_KERNEL))
                return;
 
        target_submit(cmd);
index 56394d9017916edb62141d41cf45d27c64e6f666..12a2265eb2dec88ba1df1890e616ec32b75be2bb 100644 (file)
@@ -492,7 +492,8 @@ static int tcm_qla2xxx_handle_cmd(scsi_qla_host_t *vha, struct qla_tgt_cmd *cmd,
        if (rc)
                return rc;
 
-       if (target_submit_prep(se_cmd, cdb, NULL, 0, NULL, 0, NULL, 0))
+       if (target_submit_prep(se_cmd, cdb, NULL, 0, NULL, 0, NULL, 0,
+                              GFP_KERNEL))
                return 0;
 
        target_submit(se_cmd);
index ef9133a674f6ed48c3f3619654a76f8655d74255..cf7f0465dd6316faee07e905c1ea46b97b382342 100644 (file)
@@ -1166,7 +1166,8 @@ int iscsit_setup_scsi_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd,
 
        target_get_sess_cmd(&cmd->se_cmd, true);
 
-       cmd->sense_reason = target_cmd_init_cdb(&cmd->se_cmd, hdr->cdb);
+       cmd->sense_reason = target_cmd_init_cdb(&cmd->se_cmd, hdr->cdb,
+                                               GFP_KERNEL);
        if (cmd->sense_reason) {
                if (cmd->sense_reason == TCM_OUT_OF_RESOURCES) {
                        return iscsit_add_reject_cmd(cmd,
index 461f4125fcabb2f212493fcfe48818f6ed02b9e1..677e4b8f064272c27603f29b0c917c3d83882624 100644 (file)
@@ -156,7 +156,8 @@ static void tcm_loop_submission_work(struct work_struct *work)
 
        if (target_submit_prep(se_cmd, sc->cmnd, scsi_sglist(sc),
                               scsi_sg_count(sc), sgl_bidi, sgl_bidi_count,
-                              scsi_prot_sglist(sc), scsi_prot_sg_count(sc)))
+                              scsi_prot_sglist(sc), scsi_prot_sg_count(sc),
+                              GFP_NOIO))
                return;
 
        target_submit(se_cmd);
index 560daf9bb039da37c2100db8e676f3081a56a955..bd3d125a3978e8b55cdb0de59e3dc335e4e83cc2 100644 (file)
@@ -1429,7 +1429,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
 }
 
 sense_reason_t
-target_cmd_init_cdb(struct se_cmd *cmd, unsigned char *cdb)
+target_cmd_init_cdb(struct se_cmd *cmd, unsigned char *cdb, gfp_t gfp)
 {
        sense_reason_t ret;
 
@@ -1450,8 +1450,7 @@ target_cmd_init_cdb(struct se_cmd *cmd, unsigned char *cdb)
         * setup the pointer from __t_task_cdb to t_task_cdb.
         */
        if (scsi_command_size(cdb) > sizeof(cmd->__t_task_cdb)) {
-               cmd->t_task_cdb = kzalloc(scsi_command_size(cdb),
-                                               GFP_KERNEL);
+               cmd->t_task_cdb = kzalloc(scsi_command_size(cdb), gfp);
                if (!cmd->t_task_cdb) {
                        pr_err("Unable to allocate cmd->t_task_cdb"
                                " %u > sizeof(cmd->__t_task_cdb): %lu ops\n",
@@ -1640,6 +1639,7 @@ EXPORT_SYMBOL_GPL(target_init_cmd);
  * @sgl_bidi_count: scatterlist count for bidirectional READ mapping
  * @sgl_prot: struct scatterlist memory protection information
  * @sgl_prot_count: scatterlist count for protection information
+ * @gfp: gfp allocation type
  *
  * Returns:
  *     - less than zero to signal failure.
@@ -1650,11 +1650,12 @@ EXPORT_SYMBOL_GPL(target_init_cmd);
 int target_submit_prep(struct se_cmd *se_cmd, unsigned char *cdb,
                       struct scatterlist *sgl, u32 sgl_count,
                       struct scatterlist *sgl_bidi, u32 sgl_bidi_count,
-                      struct scatterlist *sgl_prot, u32 sgl_prot_count)
+                      struct scatterlist *sgl_prot, u32 sgl_prot_count,
+                      gfp_t gfp)
 {
        sense_reason_t rc;
 
-       rc = target_cmd_init_cdb(se_cmd, cdb);
+       rc = target_cmd_init_cdb(se_cmd, cdb, gfp);
        if (rc)
                goto send_cc_direct;
 
@@ -1790,7 +1791,8 @@ void target_submit_cmd(struct se_cmd *se_cmd, struct se_session *se_sess,
        if (rc)
                return;
 
-       if (target_submit_prep(se_cmd, cdb, NULL, 0, NULL, 0, NULL, 0))
+       if (target_submit_prep(se_cmd, cdb, NULL, 0, NULL, 0, NULL, 0,
+                              GFP_KERNEL))
                return;
 
        target_submit(se_cmd);
index e86cc613558703502356308b8aa4a9e8dc2dccfc..d31ed071cb0825ed1d892fe39cfbdf6d8f4aef98 100644 (file)
@@ -554,7 +554,7 @@ static int target_xcopy_setup_pt_cmd(
        }
        cmd->se_cmd_flags |= SCF_SE_LUN_CMD;
 
-       if (target_cmd_init_cdb(cmd, cdb))
+       if (target_cmd_init_cdb(cmd, cdb, GFP_KERNEL))
                return -EINVAL;
 
        cmd->tag = 0;
index 1376501ee3d0b22d52838782c6f5b5d91066ca22..410b723f9d79cedd9895b5880b183f65203352b9 100644 (file)
@@ -555,7 +555,7 @@ static void ft_send_work(struct work_struct *work)
                goto err;
 
        if (target_submit_prep(&cmd->se_cmd, fcp->fc_cdb, NULL, 0, NULL, 0,
-                              NULL, 0))
+                              NULL, 0, GFP_KERNEL))
                return;
 
        target_submit(&cmd->se_cmd);
index ec7ffd51fe5b285d20e39a3e93c69935e855eb13..9b448a197cb5e38517f10335f57598ed85f3ee3f 100644 (file)
@@ -811,7 +811,7 @@ static void vhost_scsi_submission_work(struct work_struct *work)
 
        if (target_submit_prep(se_cmd, cmd->tvc_cdb, sg_ptr,
                               cmd->tvc_sgl_count, NULL, 0, sg_prot_ptr,
-                              cmd->tvc_prot_sgl_count))
+                              cmd->tvc_prot_sgl_count, GFP_KERNEL))
                return;
 
        target_submit(se_cmd);
index 18b9549f6fa3c0d2cdcb13815e92d9d3978770b4..55a4763da05e7c74cdbeabc0a617e36ec5ab4273 100644 (file)
@@ -368,7 +368,7 @@ static void scsiback_cmd_exec(struct vscsibk_pend *pending_req)
                        pending_req->sc_data_direction, TARGET_SCF_ACK_KREF);
 
        if (target_submit_prep(se_cmd, pending_req->cmnd, pending_req->sgl,
-                              pending_req->n_sg, NULL, 0, NULL, 0))
+                              pending_req->n_sg, NULL, 0, NULL, 0, GFP_KERNEL))
                return;
 
        target_submit(se_cmd);
index 86b0d4a7df925d3836cf56a3926a172772c72a79..0543ab1077238f249bc785791d08e5cb631de4fb 100644 (file)
@@ -157,10 +157,11 @@ int       target_init_cmd(struct se_cmd *se_cmd, struct se_session *se_sess,
 int    target_submit_prep(struct se_cmd *se_cmd, unsigned char *cdb,
                struct scatterlist *sgl, u32 sgl_count,
                struct scatterlist *sgl_bidi, u32 sgl_bidi_count,
-               struct scatterlist *sgl_prot, u32 sgl_prot_count);
+               struct scatterlist *sgl_prot, u32 sgl_prot_count, gfp_t gfp);
 void   target_submit(struct se_cmd *se_cmd);
 sense_reason_t transport_lookup_cmd_lun(struct se_cmd *);
-sense_reason_t target_cmd_init_cdb(struct se_cmd *, unsigned char *);
+sense_reason_t target_cmd_init_cdb(struct se_cmd *se_cmd, unsigned char *cdb,
+                                  gfp_t gfp);
 sense_reason_t target_cmd_parse_cdb(struct se_cmd *);
 void   target_submit_cmd(struct se_cmd *, struct se_session *, unsigned char *,
                unsigned char *, u64, u32, int, int, int);