From patchwork Fri Jan 10 19:03:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 11328251 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 86F9D92A for ; Fri, 10 Jan 2020 19:05:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5422620838 for ; Fri, 10 Jan 2020 19:05:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="dxO0KB0S" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5422620838 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8E9678E0008; Fri, 10 Jan 2020 14:05:40 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8988F8E0001; Fri, 10 Jan 2020 14:05:40 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 789398E0008; Fri, 10 Jan 2020 14:05:40 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0227.hostedemail.com [216.40.44.227]) by kanga.kvack.org (Postfix) with ESMTP id 60D408E0001 for ; Fri, 10 Jan 2020 14:05:40 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id 2C66F5820 for ; Fri, 10 Jan 2020 19:05:40 +0000 (UTC) X-FDA: 76362653640.18.club52_144e584d31037 X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,joao.m.martins@oracle.com,:linux-nvdimm@lists.01.org:dan.j.williams@intel.com:vishal.l.verma@intel.com:dave.jiang@intel.com:ira.weiny@intel.com:alex.williamson@redhat.com:cohuck@redhat.com:kvm@vger.kernel.org:akpm@linux-foundation.org::linux-kernel@vger.kernel.org:tglx@linutronix.de:mingo@redhat.com:bp@alien8.de:hpa@zytor.com:x86@kernel.org:liran.alon@oracle.com:nikita.leshchenko@oracle.com:brho@google.com:boris.ostrovsky@oracle.com:willy@infradead.org:konrad.wilk@oracle.com,RULES_HIT:30054:30064,0,RBL:141.146.126.78:@oracle.com:.lbl8.mailshell.net-62.18.0.100 64.10.201.10,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: club52_144e584d31037 X-Filterd-Recvd-Size: 5212 Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Fri, 10 Jan 2020 19:05:39 +0000 (UTC) Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id 00AJ3rr5101264; Fri, 10 Jan 2020 19:05:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2019-08-05; bh=wn9KcLolGATFIJ85MhQjHSQWXqsU1jEhASuaJIiaAfM=; b=dxO0KB0SDg6HkWerdmIGSxGHOlTPRZSiNToovSwdX2j1Wns32wgYGJopODhJFOD5rSBn puqZvYSK0bJOyTs3l2hiJo4Cva72swDScgam4nCkBGfEH0npV1q3Dz0CNk7uyqRfY7FP mzMT06ji8VS9wWPwZ9YuLo7iB61f1WJv+tqv3QCkYbLlHsUm4czNCS/d5x3gXk+Ehzjk Gbplaa1hJCHQYOg153zpccEUoxTfPctfoAqwCj46FWlQXVm8Wa/LIxvGEx8DRAo4VMtj SfzhCbDg63K6GPa+zzAbmswgAJ2e68gj1Cz2gpVJRcYBA9/KUzhr7D6WXqkJyPLgsgKt Fg== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 2xajnqm1e5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Jan 2020 19:05:27 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id 00AJ4QTA038469; Fri, 10 Jan 2020 19:05:26 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 2xekkvjmhk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 10 Jan 2020 19:05:26 +0000 Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 00AJ5PCf014949; Fri, 10 Jan 2020 19:05:25 GMT Received: from paddy.uk.oracle.com (/10.175.192.165) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 10 Jan 2020 11:05:24 -0800 From: Joao Martins To: linux-nvdimm@lists.01.org Cc: Dan Williams , Vishal Verma , Dave Jiang , Ira Weiny , Alex Williamson , Cornelia Huck , kvm@vger.kernel.org, Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , x86@kernel.org, Liran Alon , Nikita Leshenko , Barret Rhoden , Boris Ostrovsky , Matthew Wilcox , Konrad Rzeszutek Wilk Subject: [PATCH RFC 09/10] vfio/type1: Use follow_pfn for VM_FPNMAP VMAs Date: Fri, 10 Jan 2020 19:03:12 +0000 Message-Id: <20200110190313.17144-10-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200110190313.17144-1-joao.m.martins@oracle.com> References: <20200110190313.17144-1-joao.m.martins@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9496 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=848 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1911140001 definitions=main-2001100154 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9496 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=904 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1911140001 definitions=main-2001100154 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Nikita Leshenko Unconditionally interpreting vm_pgoff as a PFN is incorrect. VMAs created by /dev/mem do this, but in general VM_PFNMAP just means that the VMA doesn't have an associated struct page and is being managed directly by something other than the core mmu. Use follow_pfn like KVM does to find the PFN. Signed-off-by: Nikita Leshenko --- drivers/vfio/vfio_iommu_type1.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 2ada8e6cdb88..1e43581f95ea 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -362,9 +362,9 @@ static int vaddr_get_pfn(struct mm_struct *mm, unsigned long vaddr, vma = find_vma_intersection(mm, vaddr, vaddr + 1); if (vma && vma->vm_flags & VM_PFNMAP) { - *pfn = ((vaddr - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff; - if (is_invalid_reserved_pfn(*pfn)) - ret = 0; + ret = follow_pfn(vma, vaddr, pfn); + if (!ret && !is_invalid_reserved_pfn(*pfn)) + ret = -EOPNOTSUPP; } up_read(&mm->mmap_sem);