Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp2987387pxf; Sun, 14 Mar 2021 20:19:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzwZYEivCLnmo4too+eYiNoKC3i9Ha/nHNuapfLxpAyz/6+uioo+xODHzDBY7IyRfjj2HpD X-Received: by 2002:a17:906:1bf2:: with SMTP id t18mr21254937ejg.418.1615778384703; Sun, 14 Mar 2021 20:19:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615778384; cv=none; d=google.com; s=arc-20160816; b=nhx4+nZ0xpo/tYDpb+rfHtT+M7QDMXGIX8kmUXwthT9A1Tin64+leayALWcy1psXHZ U+RptBoKnmXFIMoNEGN+p1Oo7QJzxUKi6lm2gHsx8BhgZklPXyMSPNu5LLwnBj1BtHFQ 7QXAMqkqpG6EA3iM8iIzEmzka9nK5GPKeZ8ZQTIwYEj6/4XxRs98/55viWMXz2Vi7Lhq EUl0rxZy5etuzKqpwJTinvg9ucM/c8PNTVax1xO1KL59zEBHOGo4pxDCyASJqW4hCvy9 Nwhc7cgHjeXonKrOQQETkKtLKCrO27+J5Ntrv4K/THbD2wmyvOOfmG51YCjyY384nONX PdZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject; bh=UXxI78qAudCDBqLatGhpvtC49G9laVIbM9ofDXR71wc=; b=kehh9jPVAddz82WyeOGCjJX8DQkZ8b/R3UqIg2WEwR09ZZmkZGaXn6+JyNKMGf0ARn HnXm3uuyQsO5qcWJlt4q9kV1akGZzwqNJSZbbGa+xu9DuhxQB8uvaafuDewQPs8DjWh9 OZByUKwAxunARhx7J7yu2LtwiaiLcQHzl+lvjsDQcbMgMQ0KyO7lCgWbKFHqPGTzQhBi OP1Gu1yNee4tW52Bx1Pg37C2GtG6xNwyaqj4CHrsvpCrzlnavuNtYm7Jw5vER67eaNl0 +2moIB3hdSMR5CRoQtDsM9DPogdBGkjlkXv6PUFsUaDX+7Y8ujlEgORcUjLUhsVe5VM7 UTtg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u5si9988462ejt.35.2021.03.14.20.19.22; Sun, 14 Mar 2021 20:19:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229776AbhCODSM (ORCPT + 99 others); Sun, 14 Mar 2021 23:18:12 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:13924 "EHLO szxga06-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229672AbhCODRt (ORCPT ); Sun, 14 Mar 2021 23:17:49 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4DzM596d3szjJZc; Mon, 15 Mar 2021 11:16:13 +0800 (CST) Received: from [10.174.184.42] (10.174.184.42) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.498.0; Mon, 15 Mar 2021 11:17:42 +0800 Subject: Re: [PATCH] vfio/type1: fix vaddr_get_pfns() return in vfio_pin_page_external() To: Daniel Jordan , Alex Williamson , Cornelia Huck References: <20210308172452.38864-1-daniel.m.jordan@oracle.com> CC: , , From: Keqian Zhu Message-ID: <5a0f3949-2643-51b2-20f9-e6b6983e223e@huawei.com> Date: Mon, 15 Mar 2021 11:17:42 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 In-Reply-To: <20210308172452.38864-1-daniel.m.jordan@oracle.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.184.42] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Daniel, [+Cc iommu mail list] This patch looks good to me. (but I don't test it too.) Thanks, Keqian On 2021/3/9 1:24, Daniel Jordan wrote: > vaddr_get_pfns() now returns the positive number of pfns successfully > gotten instead of zero. vfio_pin_page_external() might return 1 to > vfio_iommu_type1_pin_pages(), which will treat it as an error, if > vaddr_get_pfns() is successful but vfio_pin_page_external() doesn't > reach vfio_lock_acct(). > > Fix it up in vfio_pin_page_external(). Found by inspection. > > Fixes: be16c1fd99f4 ("vfio/type1: Change success value of vaddr_get_pfn()") > Signed-off-by: Daniel Jordan > --- > > I couldn't test this due to lack of hardware. > > drivers/vfio/vfio_iommu_type1.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c > index 4bb162c1d649..2a0e3b3ce206 100644 > --- a/drivers/vfio/vfio_iommu_type1.c > +++ b/drivers/vfio/vfio_iommu_type1.c > @@ -785,7 +785,12 @@ static int vfio_pin_page_external(struct vfio_dma *dma, unsigned long vaddr, > return -ENODEV; > > ret = vaddr_get_pfns(mm, vaddr, 1, dma->prot, pfn_base, pages); > - if (ret == 1 && do_accounting && !is_invalid_reserved_pfn(*pfn_base)) { > + if (ret != 1) > + goto out; > + > + ret = 0; > + > + if (do_accounting && !is_invalid_reserved_pfn(*pfn_base)) { > ret = vfio_lock_acct(dma, 1, true); > if (ret) { > put_pfn(*pfn_base, dma->prot); > @@ -797,6 +802,7 @@ static int vfio_pin_page_external(struct vfio_dma *dma, unsigned long vaddr, > } > } > > +out: > mmput(mm); > return ret; > } > > base-commit: 144c79ef33536b4ecb4951e07dbc1f2b7fa99d32 >