Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2320957pxu; Mon, 7 Dec 2020 03:40:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJwQFsBL9klEg47JBMNsaVvKJnLTK2DsUgtpcP81Fd7vpTTSjl9vF/YehM/xieKKPxbaxMmJ X-Received: by 2002:a50:bf4a:: with SMTP id g10mr896952edk.201.1607341215962; Mon, 07 Dec 2020 03:40:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607341215; cv=none; d=google.com; s=arc-20160816; b=NRswMvkaWqrPZ60QKGRXDLaiiKWTJNJDQle5UfFMnOvPp7G5zvLzK0zvzn31JD22Lx M2bBv3QZbcZgNaJclMwdDC7pCeFIO6ixhuFXL1Zf6ypeXKeDWwJyS0fcpFaMz3CpoP5n F5e4J2B+L2/zAE0CvJdfSQ3IQuruOKlmPJlIF4s5/MvFk3/jM/fbxWpEsL3GH3lek06k xq7YY66yhmdLHzUH53LLgEXsvj9njzfCFOOmn/etujMJDoDoTuGbQvBjsvwowi8nn2VO yId5+tpCF69uAMO8k5iJQtNEmw24uc5XVcRzmkQ/JXlAUsAqnwmUTbbkMr8Z3jlpYqwv jpWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DlQnH7arXkpV3AxvylV8KPwG+QOIFG2k6zceWF8EMek=; b=uplsuk7P4a8l4h1Q9C4MRTExAswiGYy/VBLUEr43bHNPmEeCUMcet8IdDvsNNiRos9 pQApODpecWJoJXfJyLuZx7vOTiva1YCP7vjAokoVIWCaWa4ZST/Nenf+AdwVi2hrsfDl V+h7vTsJJVIvEOgnRVDnWpRSUv9ndR0H/V2P6WOfJ89nMvcCClsget6r6WtS4zyNmzpx c6PV+ISsqvKeGJVQugZ6MvKGDQ2fln417dGmkuAwzLJG+/X+MNi8dZZx/IB4Sll78B+s CJdsDVAvA4tqzMiT/UVryZE8kTAVcrJJhFMGIx7K1UlgNTAdUmLrn+JEzvhlI7hz9UPJ 3CLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=slULaRgC; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id go40si6215792ejc.141.2020.12.07.03.39.52; Mon, 07 Dec 2020 03:40:15 -0800 (PST) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=slULaRgC; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727756AbgLGLhR (ORCPT + 99 others); Mon, 7 Dec 2020 06:37:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727403AbgLGLf3 (ORCPT ); Mon, 7 Dec 2020 06:35:29 -0500 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2C6BC094241; Mon, 7 Dec 2020 03:35:05 -0800 (PST) Received: by mail-pf1-x441.google.com with SMTP id i3so6030219pfd.6; Mon, 07 Dec 2020 03:35:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DlQnH7arXkpV3AxvylV8KPwG+QOIFG2k6zceWF8EMek=; b=slULaRgClfSRtlq6MZQolWl14N3WoKzCDl91aATl6tX8HOfVXd7kfIwWn5h47oBm3h xiPGbI6vPy35U0R/c4QR8TcprKIJDFu9YT12UcQuplY38vOUzuIMOUmOng8ftygUWfTr R1ZAIx1wp1N0xM3YOBmolFbpCccHmRq/UeETV4HjisGBwUXZHQZrrafX6WsVEOPwXQu9 0N2lNLtp3gJavRT6Vww4WvELq4NKpp8UbezAjxjLamlZR2rUohbuyED91YZZx9c5W52C 8RHuWAx0H4siG5FrBXMPIyV8dIchxJEE581mAM4LCKH+oYKBsM2HDcxznhasrQeZ1BcL O2Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DlQnH7arXkpV3AxvylV8KPwG+QOIFG2k6zceWF8EMek=; b=PXIYBKFFvVghRkPHNXzdVcE9ivR57Ta2J1FYEX673hG7DjbHXODYzKrodgoir2Pyty 4irQtt/ec8GYFVRAfA08c8415BrTei3Qd5dNqoRJfB77SvG8MnYY7x+UVnPBNGxMsiQI AFUvPgGRG9BHHt/bcrJ14iqBdajVZFKcUgj+fXrI+1EkTbyZR1BlWCTdjm111OUirCj5 5t0R66dN0baYMVypnKXL2phGfXckO/drnHcUNTHiSVG/Xq6YHvyUKG+LqgD4FmNlLr0w X/MkoA3Op2ncZ3ZQMyIgX8HEkUzHz/7tN4E7AZhtlhVyhgVNLvigKDg7wr1GX4WNGpdk 3CaQ== X-Gm-Message-State: AOAM532WOuQg82k2N7Gl28h3Kija0jMiGlVBNkzO/78RTefUxsqaZ8yi QFjXRPdSpCy8iAcu9MSr5tTkxzb0DG8= X-Received: by 2002:a17:902:bc4b:b029:db:2d61:5f37 with SMTP id t11-20020a170902bc4bb02900db2d615f37mr99717plz.79.1607340905372; Mon, 07 Dec 2020 03:35:05 -0800 (PST) Received: from localhost.localdomain ([203.205.141.39]) by smtp.gmail.com with ESMTPSA id d4sm14219822pfo.127.2020.12.07.03.35.02 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Dec 2020 03:35:04 -0800 (PST) From: yulei.kernel@gmail.com X-Google-Original-From: yuleixzhang@tencent.com To: linux-mm@kvack.org, akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, naoya.horiguchi@nec.com, viro@zeniv.linux.org.uk, pbonzini@redhat.com Cc: joao.m.martins@oracle.com, rdunlap@infradead.org, sean.j.christopherson@intel.com, xiaoguangrong.eric@gmail.com, kernellwp@gmail.com, lihaiwei.kernel@gmail.com, Yulei Zhang , Chen Zhuo Subject: [RFC V2 25/37] mm, x86, dmem: fix estimation of reserved page for vaddr_get_pfn() Date: Mon, 7 Dec 2020 19:31:18 +0800 Message-Id: <3bd3e2d485c46fae9eaeb501e1a6c51d19570b49.1607332046.git.yuleixzhang@tencent.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yulei Zhang Fix estimation of reserved page for vaddr_get_pfn() and check 'ret' before checking writable permission Signed-off-by: Chen Zhuo Signed-off-by: Yulei Zhang --- drivers/vfio/vfio_iommu_type1.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 67e8276..c465d1a 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -471,6 +471,10 @@ static int vaddr_get_pfn(struct mm_struct *mm, unsigned long vaddr, if (ret == -EAGAIN) goto retry; + if (!ret && (prot & IOMMU_WRITE) && + !(vma->vm_flags & VM_WRITE)) + ret = -EFAULT; + if (!ret && !is_invalid_reserved_pfn(*pfn)) ret = -EFAULT; } -- 1.8.3.1