diff options
| author | Nicholas Bellinger <nab@linux-iscsi.org> | 2014-02-22 21:34:43 -0500 |
|---|---|---|
| committer | Nicholas Bellinger <nab@linux-iscsi.org> | 2014-06-02 15:42:07 -0400 |
| commit | e31885dd901e80d5bd528c1cbedde07ebbf051b2 (patch) | |
| tree | 607777156b57654c5ec44a3a33667fb3938e852a /drivers/vhost | |
| parent | b1935f687bb93b207ef690f7debc0e9921fc484f (diff) | |
vhost/scsi: Add T10 PI IOV -> SGL memory mapping logic
This patch adds vhost_scsi_map_iov_to_prot() to perform the mapping of
T10 data integrity memory between virtio iov + struct scatterlist using
get_user_pages_fast() following existing code.
As with vhost_scsi_map_iov_to_sgl(), this does sanity checks against the
total prot_sgl_count vs. pre-allocated SGLs, and loops across protection
iovs using vhost_scsi_map_to_sgl() to perform the actual memory mapping.
Also update tcm_vhost_release_cmd() to release associated tvc_prot_sgl[]
struct page.
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Martin K. Petersen <martin.petersen@oracle.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.de>
Cc: Sagi Grimberg <sagig@dev.mellanox.co.il>
Cc: H. Peter Anvin <hpa@zytor.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Diffstat (limited to 'drivers/vhost')
| -rw-r--r-- | drivers/vhost/scsi.c | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c index 30402e618078..eabcf1875831 100644 --- a/drivers/vhost/scsi.c +++ b/drivers/vhost/scsi.c | |||
| @@ -80,6 +80,7 @@ struct tcm_vhost_cmd { | |||
| 80 | u64 tvc_tag; | 80 | u64 tvc_tag; |
| 81 | /* The number of scatterlists associated with this cmd */ | 81 | /* The number of scatterlists associated with this cmd */ |
| 82 | u32 tvc_sgl_count; | 82 | u32 tvc_sgl_count; |
| 83 | u32 tvc_prot_sgl_count; | ||
| 83 | /* Saved unpacked SCSI LUN for tcm_vhost_submission_work() */ | 84 | /* Saved unpacked SCSI LUN for tcm_vhost_submission_work() */ |
| 84 | u32 tvc_lun; | 85 | u32 tvc_lun; |
| 85 | /* Pointer to the SGL formatted memory from virtio-scsi */ | 86 | /* Pointer to the SGL formatted memory from virtio-scsi */ |
| @@ -458,12 +459,16 @@ static void tcm_vhost_release_cmd(struct se_cmd *se_cmd) | |||
| 458 | struct tcm_vhost_cmd *tv_cmd = container_of(se_cmd, | 459 | struct tcm_vhost_cmd *tv_cmd = container_of(se_cmd, |
| 459 | struct tcm_vhost_cmd, tvc_se_cmd); | 460 | struct tcm_vhost_cmd, tvc_se_cmd); |
| 460 | struct se_session *se_sess = se_cmd->se_sess; | 461 | struct se_session *se_sess = se_cmd->se_sess; |
| 462 | int i; | ||
| 461 | 463 | ||
| 462 | if (tv_cmd->tvc_sgl_count) { | 464 | if (tv_cmd->tvc_sgl_count) { |
| 463 | u32 i; | ||
| 464 | for (i = 0; i < tv_cmd->tvc_sgl_count; i++) | 465 | for (i = 0; i < tv_cmd->tvc_sgl_count; i++) |
| 465 | put_page(sg_page(&tv_cmd->tvc_sgl[i])); | 466 | put_page(sg_page(&tv_cmd->tvc_sgl[i])); |
| 466 | } | 467 | } |
| 468 | if (tv_cmd->tvc_prot_sgl_count) { | ||
| 469 | for (i = 0; i < tv_cmd->tvc_prot_sgl_count; i++) | ||
| 470 | put_page(sg_page(&tv_cmd->tvc_prot_sgl[i])); | ||
| 471 | } | ||
| 467 | 472 | ||
| 468 | tcm_vhost_put_inflight(tv_cmd->inflight); | 473 | tcm_vhost_put_inflight(tv_cmd->inflight); |
| 469 | percpu_ida_free(&se_sess->sess_tag_pool, se_cmd->map_tag); | 474 | percpu_ida_free(&se_sess->sess_tag_pool, se_cmd->map_tag); |
| @@ -861,6 +866,47 @@ vhost_scsi_map_iov_to_sgl(struct tcm_vhost_cmd *cmd, | |||
| 861 | return 0; | 866 | return 0; |
| 862 | } | 867 | } |
| 863 | 868 | ||
| 869 | static int | ||
| 870 | vhost_scsi_map_iov_to_prot(struct tcm_vhost_cmd *cmd, | ||
| 871 | struct iovec *iov, | ||
| 872 | int niov, | ||
| 873 | bool write) | ||
| 874 | { | ||
| 875 | struct scatterlist *prot_sg = cmd->tvc_prot_sgl; | ||
| 876 | unsigned int prot_sgl_count = 0; | ||
| 877 | int ret, i; | ||
| 878 | |||
| 879 | for (i = 0; i < niov; i++) | ||
| 880 | prot_sgl_count += iov_num_pages(&iov[i]); | ||
| 881 | |||
| 882 | if (prot_sgl_count > TCM_VHOST_PREALLOC_PROT_SGLS) { | ||
| 883 | pr_err("vhost_scsi_map_iov_to_prot() sgl_count: %u greater than" | ||
| 884 | " preallocated TCM_VHOST_PREALLOC_PROT_SGLS: %u\n", | ||
| 885 | prot_sgl_count, TCM_VHOST_PREALLOC_PROT_SGLS); | ||
| 886 | return -ENOBUFS; | ||
| 887 | } | ||
| 888 | |||
| 889 | pr_debug("%s prot_sg %p prot_sgl_count %u\n", __func__, | ||
| 890 | prot_sg, prot_sgl_count); | ||
| 891 | sg_init_table(prot_sg, prot_sgl_count); | ||
| 892 | cmd->tvc_prot_sgl_count = prot_sgl_count; | ||
| 893 | |||
| 894 | for (i = 0; i < niov; i++) { | ||
| 895 | ret = vhost_scsi_map_to_sgl(cmd, prot_sg, prot_sgl_count, &iov[i], | ||
| 896 | cmd->tvc_upages, write); | ||
| 897 | if (ret < 0) { | ||
| 898 | for (i = 0; i < cmd->tvc_prot_sgl_count; i++) | ||
| 899 | put_page(sg_page(&cmd->tvc_prot_sgl[i])); | ||
| 900 | |||
| 901 | cmd->tvc_prot_sgl_count = 0; | ||
| 902 | return ret; | ||
| 903 | } | ||
| 904 | prot_sg += ret; | ||
| 905 | prot_sgl_count -= ret; | ||
| 906 | } | ||
| 907 | return 0; | ||
| 908 | } | ||
| 909 | |||
| 864 | static void tcm_vhost_submission_work(struct work_struct *work) | 910 | static void tcm_vhost_submission_work(struct work_struct *work) |
| 865 | { | 911 | { |
| 866 | struct tcm_vhost_cmd *cmd = | 912 | struct tcm_vhost_cmd *cmd = |
