From patchwork Fri Feb 6 05:06:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nicholas A. Bellinger" X-Patchwork-Id: 5788621 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 30DA9BF440 for ; Fri, 6 Feb 2015 05:40:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 40F2B2015E for ; Fri, 6 Feb 2015 05:40:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3E07420155 for ; Fri, 6 Feb 2015 05:40:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754084AbbBFFki (ORCPT ); Fri, 6 Feb 2015 00:40:38 -0500 Received: from mail-oi0-f46.google.com ([209.85.218.46]:55467 "EHLO mail-oi0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751444AbbBFFjt (ORCPT ); Fri, 6 Feb 2015 00:39:49 -0500 Received: by mail-oi0-f46.google.com with SMTP id a141so10313811oig.5 for ; Thu, 05 Feb 2015 21:39:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Ve801CJv8IrNMKT0yZ8A2wi0b4j4qtKHKqeA9yZO5sE=; b=IB8Piv17hi84kdxEtVRUYrm+hxl58gkv2950FIpmhFT/3158MvaGsyEwoX2Nno1iTR a+SCfzNCvh+y70OHTuNV96C/zBKIuACH5pLUYd8Jxn83Ct2FooElF+IANEligU/NOqOa Dm5sVMTSTHZZnqQbLOHn1J3BlfA7TDrGu+uJJkdXMwxIIQKo1JEf04MkB/40PbNkZdEb OZGcHhO9ZKDC/F/laxGA6uo990+RxEj+YHpfhi2L0wltMhAZ5YYs867aRTkNNpmm5CGB DkXZuNt30ym8+maQbHJ7EbXXweMuoR1cO+AhHjOid6QJ8Hho7l7qjghxJBgMG+MHRUS8 /35g== X-Gm-Message-State: ALoCoQmWTTu1yy0DUYKLncDle6ajBojWUORa4r9dtH8pZhSd47/oAt0J2LP3+uUaK1i4OInb3Wbi X-Received: by 10.182.56.70 with SMTP id y6mr1274154obp.55.1423201189229; Thu, 05 Feb 2015 21:39:49 -0800 (PST) Received: from localhost.localdomain (mail.linux-iscsi.org. [67.23.28.174]) by mx.google.com with ESMTPSA id x8sm800393obg.18.2015.02.05.21.39.48 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 05 Feb 2015 21:39:48 -0800 (PST) From: "Nicholas A. Bellinger" To: target-devel Cc: linux-scsi , kvm-devel , Paolo Bonzini , "Michael S. Tsirkin" , Al Viro , Christoph Hellwig , Nicholas Bellinger Subject: [PATCH-v4 3/8] vhost/scsi: Change vhost_scsi_map_to_sgl to accept iov ptr + len Date: Fri, 6 Feb 2015 05:06:36 +0000 Message-Id: <1423199201-14659-4-git-send-email-nab@daterainc.com> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1423199201-14659-1-git-send-email-nab@daterainc.com> References: <1423199201-14659-1-git-send-email-nab@daterainc.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Nicholas Bellinger 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 Cc: Paolo Bonzini Signed-off-by: Nicholas Bellinger --- drivers/vhost/scsi.c | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c index 62de820..b9800c7 100644 --- a/drivers/vhost/scsi.c +++ b/drivers/vhost/scsi.c @@ -222,10 +222,10 @@ static struct workqueue_struct *tcm_vhost_workqueue; static DEFINE_MUTEX(tcm_vhost_mutex); static LIST_HEAD(tcm_vhost_list); -static int iov_num_pages(struct iovec *iov) +static int iov_num_pages(void __user *iov_base, size_t iov_len) { - return (PAGE_ALIGN((unsigned long)iov->iov_base + iov->iov_len) - - ((unsigned long)iov->iov_base & PAGE_MASK)) >> PAGE_SHIFT; + return (PAGE_ALIGN((unsigned long)iov_base + iov_len) - + ((unsigned long)iov_base & PAGE_MASK)) >> PAGE_SHIFT; } 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, * Returns the number of scatterlist entries used or -errno on error. */ static int -vhost_scsi_map_to_sgl(struct tcm_vhost_cmd *tv_cmd, +vhost_scsi_map_to_sgl(struct tcm_vhost_cmd *cmd, + void __user *ptr, + size_t len, struct scatterlist *sgl, - unsigned int sgl_count, - struct iovec *iov, - struct page **pages, bool write) { - unsigned int npages = 0, pages_nr, offset, nbytes; + unsigned int npages = 0, offset, nbytes; + unsigned int pages_nr = iov_num_pages(ptr, len); struct scatterlist *sg = sgl; - void __user *ptr = iov->iov_base; - size_t len = iov->iov_len; + struct page **pages = cmd->tvc_upages; int ret, i; - pages_nr = iov_num_pages(iov); - if (pages_nr > sgl_count) { - pr_err("vhost_scsi_map_to_sgl() pages_nr: %u greater than" - " sgl_count: %u\n", pages_nr, sgl_count); - return -ENOBUFS; - } if (pages_nr > TCM_VHOST_PREALLOC_UPAGES) { pr_err("vhost_scsi_map_to_sgl() pages_nr: %u greater than" " preallocated TCM_VHOST_PREALLOC_UPAGES: %u\n", @@ -845,7 +838,7 @@ vhost_scsi_map_iov_to_sgl(struct tcm_vhost_cmd *cmd, int ret, i; for (i = 0; i < niov; i++) - sgl_count += iov_num_pages(&iov[i]); + sgl_count += iov_num_pages(iov[i].iov_base, iov[i].iov_len); if (sgl_count > TCM_VHOST_PREALLOC_SGLS) { 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, pr_debug("Mapping iovec %p for %u pages\n", &iov[0], sgl_count); for (i = 0; i < niov; i++) { - ret = vhost_scsi_map_to_sgl(cmd, sg, sgl_count, &iov[i], - cmd->tvc_upages, write); + ret = vhost_scsi_map_to_sgl(cmd, iov[i].iov_base, iov[i].iov_len, + sg, write); if (ret < 0) { for (i = 0; i < cmd->tvc_sgl_count; i++) { struct page *page = sg_page(&cmd->tvc_sgl[i]); @@ -889,7 +882,7 @@ vhost_scsi_map_iov_to_prot(struct tcm_vhost_cmd *cmd, int ret, i; for (i = 0; i < niov; i++) - prot_sgl_count += iov_num_pages(&iov[i]); + prot_sgl_count += iov_num_pages(iov[i].iov_base, iov[i].iov_len); if (prot_sgl_count > TCM_VHOST_PREALLOC_PROT_SGLS) { 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, cmd->tvc_prot_sgl_count = prot_sgl_count; for (i = 0; i < niov; i++) { - ret = vhost_scsi_map_to_sgl(cmd, prot_sg, prot_sgl_count, &iov[i], - cmd->tvc_upages, write); + ret = vhost_scsi_map_to_sgl(cmd, iov[i].iov_base, iov[i].iov_len, + prot_sg, write); if (ret < 0) { for (i = 0; i < cmd->tvc_prot_sgl_count; i++) { struct page *page = sg_page(&cmd->tvc_prot_sgl[i]);