From patchwork Tue Jan 22 03:20:26 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Asias He X-Patchwork-Id: 2015341 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id B7266DF2A1 for ; Tue, 22 Jan 2013 03:19:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753657Ab3AVDSz (ORCPT ); Mon, 21 Jan 2013 22:18:55 -0500 Received: from mx1.redhat.com ([209.132.183.28]:19811 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752969Ab3AVDSt (ORCPT ); Mon, 21 Jan 2013 22:18:49 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r0M3Ikwp004711 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 21 Jan 2013 22:18:46 -0500 Received: from hj.localdomain.com ([10.66.6.0]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r0M3Ia6i014098; Mon, 21 Jan 2013 22:18:43 -0500 From: Asias He To: Nicholas Bellinger Cc: "Michael S. Tsirkin" , Rusty Russell , Marcelo Tosatti , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, target-devel@vger.kernel.org Subject: [PATCH v2 2/3] tcm_vhost: Use iov_num_pages to calculate sgl_count Date: Tue, 22 Jan 2013 11:20:26 +0800 Message-Id: <1358824827-16169-3-git-send-email-asias@redhat.com> In-Reply-To: <1358824827-16169-1-git-send-email-asias@redhat.com> References: <1358824827-16169-1-git-send-email-asias@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Signed-off-by: Asias He --- drivers/vhost/tcm_vhost.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/vhost/tcm_vhost.c b/drivers/vhost/tcm_vhost.c index ca35c16..796a6b0 100644 --- a/drivers/vhost/tcm_vhost.c +++ b/drivers/vhost/tcm_vhost.c @@ -479,11 +479,9 @@ static int vhost_scsi_map_iov_to_sgl(struct tcm_vhost_cmd *tv_cmd, * Find out how long sglist needs to be */ sgl_count = 0; - for (i = 0; i < niov; i++) { - sgl_count += (((uintptr_t)iov[i].iov_base + iov[i].iov_len + - PAGE_SIZE - 1) >> PAGE_SHIFT) - - ((uintptr_t)iov[i].iov_base >> PAGE_SHIFT); - } + for (i = 0; i < niov; i++) + sgl_count += iov_num_pages(&iov[i]); + /* TODO overflow checking */ sg = kmalloc(sizeof(tv_cmd->tvc_sgl[0]) * sgl_count, GFP_ATOMIC);