Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: target: core: Add gfp_t arg to target_cmd_init_cdb()

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>

authored by

Mike Christie and committed by
Martin K. Petersen
08694199 0fa50a8b

+23 -16
+2 -1
drivers/infiniband/ulp/srpt/ib_srpt.c
··· 1537 1537 goto busy; 1538 1538 } 1539 1539 1540 - if (target_submit_prep(cmd, srp_cmd->cdb, sg, sg_cnt, NULL, 0, NULL, 0)) 1540 + if (target_submit_prep(cmd, srp_cmd->cdb, sg, sg_cnt, NULL, 0, NULL, 0, 1541 + GFP_KERNEL)) 1541 1542 return; 1542 1543 1543 1544 target_submit(cmd);
+2 -1
drivers/scsi/qla2xxx/tcm_qla2xxx.c
··· 492 492 if (rc) 493 493 return rc; 494 494 495 - if (target_submit_prep(se_cmd, cdb, NULL, 0, NULL, 0, NULL, 0)) 495 + if (target_submit_prep(se_cmd, cdb, NULL, 0, NULL, 0, NULL, 0, 496 + GFP_KERNEL)) 496 497 return 0; 497 498 498 499 target_submit(se_cmd);
+2 -1
drivers/target/iscsi/iscsi_target.c
··· 1166 1166 1167 1167 target_get_sess_cmd(&cmd->se_cmd, true); 1168 1168 1169 - cmd->sense_reason = target_cmd_init_cdb(&cmd->se_cmd, hdr->cdb); 1169 + cmd->sense_reason = target_cmd_init_cdb(&cmd->se_cmd, hdr->cdb, 1170 + GFP_KERNEL); 1170 1171 if (cmd->sense_reason) { 1171 1172 if (cmd->sense_reason == TCM_OUT_OF_RESOURCES) { 1172 1173 return iscsit_add_reject_cmd(cmd,
+2 -1
drivers/target/loopback/tcm_loop.c
··· 156 156 157 157 if (target_submit_prep(se_cmd, sc->cmnd, scsi_sglist(sc), 158 158 scsi_sg_count(sc), sgl_bidi, sgl_bidi_count, 159 - scsi_prot_sglist(sc), scsi_prot_sg_count(sc))) 159 + scsi_prot_sglist(sc), scsi_prot_sg_count(sc), 160 + GFP_NOIO)) 160 161 return; 161 162 162 163 target_submit(se_cmd);
+8 -6
drivers/target/target_core_transport.c
··· 1429 1429 } 1430 1430 1431 1431 sense_reason_t 1432 - target_cmd_init_cdb(struct se_cmd *cmd, unsigned char *cdb) 1432 + target_cmd_init_cdb(struct se_cmd *cmd, unsigned char *cdb, gfp_t gfp) 1433 1433 { 1434 1434 sense_reason_t ret; 1435 1435 ··· 1450 1450 * setup the pointer from __t_task_cdb to t_task_cdb. 1451 1451 */ 1452 1452 if (scsi_command_size(cdb) > sizeof(cmd->__t_task_cdb)) { 1453 - cmd->t_task_cdb = kzalloc(scsi_command_size(cdb), 1454 - GFP_KERNEL); 1453 + cmd->t_task_cdb = kzalloc(scsi_command_size(cdb), gfp); 1455 1454 if (!cmd->t_task_cdb) { 1456 1455 pr_err("Unable to allocate cmd->t_task_cdb" 1457 1456 " %u > sizeof(cmd->__t_task_cdb): %lu ops\n", ··· 1639 1640 * @sgl_bidi_count: scatterlist count for bidirectional READ mapping 1640 1641 * @sgl_prot: struct scatterlist memory protection information 1641 1642 * @sgl_prot_count: scatterlist count for protection information 1643 + * @gfp: gfp allocation type 1642 1644 * 1643 1645 * Returns: 1644 1646 * - less than zero to signal failure. ··· 1650 1650 int target_submit_prep(struct se_cmd *se_cmd, unsigned char *cdb, 1651 1651 struct scatterlist *sgl, u32 sgl_count, 1652 1652 struct scatterlist *sgl_bidi, u32 sgl_bidi_count, 1653 - struct scatterlist *sgl_prot, u32 sgl_prot_count) 1653 + struct scatterlist *sgl_prot, u32 sgl_prot_count, 1654 + gfp_t gfp) 1654 1655 { 1655 1656 sense_reason_t rc; 1656 1657 1657 - rc = target_cmd_init_cdb(se_cmd, cdb); 1658 + rc = target_cmd_init_cdb(se_cmd, cdb, gfp); 1658 1659 if (rc) 1659 1660 goto send_cc_direct; 1660 1661 ··· 1791 1790 if (rc) 1792 1791 return; 1793 1792 1794 - if (target_submit_prep(se_cmd, cdb, NULL, 0, NULL, 0, NULL, 0)) 1793 + if (target_submit_prep(se_cmd, cdb, NULL, 0, NULL, 0, NULL, 0, 1794 + GFP_KERNEL)) 1795 1795 return; 1796 1796 1797 1797 target_submit(se_cmd);
+1 -1
drivers/target/target_core_xcopy.c
··· 554 554 } 555 555 cmd->se_cmd_flags |= SCF_SE_LUN_CMD; 556 556 557 - if (target_cmd_init_cdb(cmd, cdb)) 557 + if (target_cmd_init_cdb(cmd, cdb, GFP_KERNEL)) 558 558 return -EINVAL; 559 559 560 560 cmd->tag = 0;
+1 -1
drivers/target/tcm_fc/tfc_cmd.c
··· 555 555 goto err; 556 556 557 557 if (target_submit_prep(&cmd->se_cmd, fcp->fc_cdb, NULL, 0, NULL, 0, 558 - NULL, 0)) 558 + NULL, 0, GFP_KERNEL)) 559 559 return; 560 560 561 561 target_submit(&cmd->se_cmd);
+1 -1
drivers/vhost/scsi.c
··· 811 811 812 812 if (target_submit_prep(se_cmd, cmd->tvc_cdb, sg_ptr, 813 813 cmd->tvc_sgl_count, NULL, 0, sg_prot_ptr, 814 - cmd->tvc_prot_sgl_count)) 814 + cmd->tvc_prot_sgl_count, GFP_KERNEL)) 815 815 return; 816 816 817 817 target_submit(se_cmd);
+1 -1
drivers/xen/xen-scsiback.c
··· 368 368 pending_req->sc_data_direction, TARGET_SCF_ACK_KREF); 369 369 370 370 if (target_submit_prep(se_cmd, pending_req->cmnd, pending_req->sgl, 371 - pending_req->n_sg, NULL, 0, NULL, 0)) 371 + pending_req->n_sg, NULL, 0, NULL, 0, GFP_KERNEL)) 372 372 return; 373 373 374 374 target_submit(se_cmd);
+3 -2
include/target/target_core_fabric.h
··· 157 157 int target_submit_prep(struct se_cmd *se_cmd, unsigned char *cdb, 158 158 struct scatterlist *sgl, u32 sgl_count, 159 159 struct scatterlist *sgl_bidi, u32 sgl_bidi_count, 160 - struct scatterlist *sgl_prot, u32 sgl_prot_count); 160 + struct scatterlist *sgl_prot, u32 sgl_prot_count, gfp_t gfp); 161 161 void target_submit(struct se_cmd *se_cmd); 162 162 sense_reason_t transport_lookup_cmd_lun(struct se_cmd *); 163 - sense_reason_t target_cmd_init_cdb(struct se_cmd *, unsigned char *); 163 + sense_reason_t target_cmd_init_cdb(struct se_cmd *se_cmd, unsigned char *cdb, 164 + gfp_t gfp); 164 165 sense_reason_t target_cmd_parse_cdb(struct se_cmd *); 165 166 void target_submit_cmd(struct se_cmd *, struct se_session *, unsigned char *, 166 167 unsigned char *, u64, u32, int, int, int);