diff options
| author | Nicholas Bellinger <nab@linux-iscsi.org> | 2015-01-28 16:10:51 -0500 |
|---|---|---|
| committer | Nicholas Bellinger <nab@linux-iscsi.org> | 2015-02-04 13:55:36 -0500 |
| commit | b4078b5face3c1e79ef6e2dd254af04a470ed2bc (patch) | |
| tree | 55692e7ced0d180fd202c2c03f740a68d69d68f3 /drivers | |
| parent | de1419e42088e99f8f839710c42aec759e45de77 (diff) | |
vhost/scsi: Change vhost_scsi_map_to_sgl to accept iov ptr + len
This patch changes vhost_scsi_map_to_sgl() parameters to accept virtio
iovec ptr + len when determing pages_nr.
This is currently done with iov_num_pages() -> PAGE_ALIGN, so allow
the same parameters as well.
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Diffstat (limited to 'drivers')
| -rw-r--r-- | drivers/vhost/scsi.c | 37 |
1 files changed, 15 insertions, 22 deletions
diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c index 62de820ae2f4..b9800c7a1d5d 100644 --- a/drivers/vhost/scsi.c +++ b/drivers/vhost/scsi.c | |||
| @@ -222,10 +222,10 @@ static struct workqueue_struct *tcm_vhost_workqueue; | |||
| 222 | static DEFINE_MUTEX(tcm_vhost_mutex); | 222 | static DEFINE_MUTEX(tcm_vhost_mutex); |
| 223 | static LIST_HEAD(tcm_vhost_list); | 223 | static LIST_HEAD(tcm_vhost_list); |
| 224 | 224 | ||
| 225 | static int iov_num_pages(struct iovec *iov) | 225 | static int iov_num_pages(void __user *iov_base, size_t iov_len) |
| 226 | { | 226 | { |
| 227 | return (PAGE_ALIGN((unsigned long)iov->iov_base + iov->iov_len) - | 227 | return (PAGE_ALIGN((unsigned long)iov_base + iov_len) - |
| 228 | ((unsigned long)iov->iov_base & PAGE_MASK)) >> PAGE_SHIFT; | 228 | ((unsigned long)iov_base & PAGE_MASK)) >> PAGE_SHIFT; |
| 229 | } | 229 | } |
| 230 | 230 | ||
| 231 | static void tcm_vhost_done_inflight(struct kref *kref) | 231 | static void tcm_vhost_done_inflight(struct kref *kref) |
| @@ -782,25 +782,18 @@ vhost_scsi_get_tag(struct vhost_virtqueue *vq, struct tcm_vhost_tpg *tpg, | |||
| 782 | * Returns the number of scatterlist entries used or -errno on error. | 782 | * Returns the number of scatterlist entries used or -errno on error. |
| 783 | */ | 783 | */ |
| 784 | static int | 784 | static int |
| 785 | vhost_scsi_map_to_sgl(struct tcm_vhost_cmd *tv_cmd, | 785 | vhost_scsi_map_to_sgl(struct tcm_vhost_cmd *cmd, |
| 786 | void __user *ptr, | ||
| 787 | size_t len, | ||
| 786 | struct scatterlist *sgl, | 788 | struct scatterlist *sgl, |
| 787 | unsigned int sgl_count, | ||
| 788 | struct iovec *iov, | ||
| 789 | struct page **pages, | ||
| 790 | bool write) | 789 | bool write) |
| 791 | { | 790 | { |
| 792 | unsigned int npages = 0, pages_nr, offset, nbytes; | 791 | unsigned int npages = 0, offset, nbytes; |
| 792 | unsigned int pages_nr = iov_num_pages(ptr, len); | ||
| 793 | struct scatterlist *sg = sgl; | 793 | struct scatterlist *sg = sgl; |
| 794 | void __user *ptr = iov->iov_base; | 794 | struct page **pages = cmd->tvc_upages; |
| 795 | size_t len = iov->iov_len; | ||
| 796 | int ret, i; | 795 | int ret, i; |
| 797 | 796 | ||
| 798 | pages_nr = iov_num_pages(iov); | ||
| 799 | if (pages_nr > sgl_count) { | ||
| 800 | pr_err("vhost_scsi_map_to_sgl() pages_nr: %u greater than" | ||
| 801 | " sgl_count: %u\n", pages_nr, sgl_count); | ||
| 802 | return -ENOBUFS; | ||
| 803 | } | ||
| 804 | if (pages_nr > TCM_VHOST_PREALLOC_UPAGES) { | 797 | if (pages_nr > TCM_VHOST_PREALLOC_UPAGES) { |
| 805 | pr_err("vhost_scsi_map_to_sgl() pages_nr: %u greater than" | 798 | pr_err("vhost_scsi_map_to_sgl() pages_nr: %u greater than" |
| 806 | " preallocated TCM_VHOST_PREALLOC_UPAGES: %u\n", | 799 | " preallocated TCM_VHOST_PREALLOC_UPAGES: %u\n", |
| @@ -845,7 +838,7 @@ vhost_scsi_map_iov_to_sgl(struct tcm_vhost_cmd *cmd, | |||
| 845 | int ret, i; | 838 | int ret, i; |
| 846 | 839 | ||
| 847 | for (i = 0; i < niov; i++) | 840 | for (i = 0; i < niov; i++) |
| 848 | sgl_count += iov_num_pages(&iov[i]); | 841 | sgl_count += iov_num_pages(iov[i].iov_base, iov[i].iov_len); |
| 849 | 842 | ||
| 850 | if (sgl_count > TCM_VHOST_PREALLOC_SGLS) { | 843 | if (sgl_count > TCM_VHOST_PREALLOC_SGLS) { |
| 851 | pr_err("vhost_scsi_map_iov_to_sgl() sgl_count: %u greater than" | 844 | pr_err("vhost_scsi_map_iov_to_sgl() sgl_count: %u greater than" |
| @@ -861,8 +854,8 @@ vhost_scsi_map_iov_to_sgl(struct tcm_vhost_cmd *cmd, | |||
| 861 | pr_debug("Mapping iovec %p for %u pages\n", &iov[0], sgl_count); | 854 | pr_debug("Mapping iovec %p for %u pages\n", &iov[0], sgl_count); |
| 862 | 855 | ||
| 863 | for (i = 0; i < niov; i++) { | 856 | for (i = 0; i < niov; i++) { |
| 864 | ret = vhost_scsi_map_to_sgl(cmd, sg, sgl_count, &iov[i], | 857 | ret = vhost_scsi_map_to_sgl(cmd, iov[i].iov_base, iov[i].iov_len, |
| 865 | cmd->tvc_upages, write); | 858 | sg, write); |
| 866 | if (ret < 0) { | 859 | if (ret < 0) { |
| 867 | for (i = 0; i < cmd->tvc_sgl_count; i++) { | 860 | for (i = 0; i < cmd->tvc_sgl_count; i++) { |
| 868 | struct page *page = sg_page(&cmd->tvc_sgl[i]); | 861 | struct page *page = sg_page(&cmd->tvc_sgl[i]); |
| @@ -889,7 +882,7 @@ vhost_scsi_map_iov_to_prot(struct tcm_vhost_cmd *cmd, | |||
| 889 | int ret, i; | 882 | int ret, i; |
| 890 | 883 | ||
| 891 | for (i = 0; i < niov; i++) | 884 | for (i = 0; i < niov; i++) |
| 892 | prot_sgl_count += iov_num_pages(&iov[i]); | 885 | prot_sgl_count += iov_num_pages(iov[i].iov_base, iov[i].iov_len); |
| 893 | 886 | ||
| 894 | if (prot_sgl_count > TCM_VHOST_PREALLOC_PROT_SGLS) { | 887 | if (prot_sgl_count > TCM_VHOST_PREALLOC_PROT_SGLS) { |
| 895 | pr_err("vhost_scsi_map_iov_to_prot() sgl_count: %u greater than" | 888 | pr_err("vhost_scsi_map_iov_to_prot() sgl_count: %u greater than" |
| @@ -904,8 +897,8 @@ vhost_scsi_map_iov_to_prot(struct tcm_vhost_cmd *cmd, | |||
| 904 | cmd->tvc_prot_sgl_count = prot_sgl_count; | 897 | cmd->tvc_prot_sgl_count = prot_sgl_count; |
| 905 | 898 | ||
| 906 | for (i = 0; i < niov; i++) { | 899 | for (i = 0; i < niov; i++) { |
| 907 | ret = vhost_scsi_map_to_sgl(cmd, prot_sg, prot_sgl_count, &iov[i], | 900 | ret = vhost_scsi_map_to_sgl(cmd, iov[i].iov_base, iov[i].iov_len, |
| 908 | cmd->tvc_upages, write); | 901 | prot_sg, write); |
| 909 | if (ret < 0) { | 902 | if (ret < 0) { |
| 910 | for (i = 0; i < cmd->tvc_prot_sgl_count; i++) { | 903 | for (i = 0; i < cmd->tvc_prot_sgl_count; i++) { |
| 911 | struct page *page = sg_page(&cmd->tvc_prot_sgl[i]); | 904 | struct page *page = sg_page(&cmd->tvc_prot_sgl[i]); |
