Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1046534ybl; Fri, 10 Jan 2020 11:07:22 -0800 (PST) X-Google-Smtp-Source: APXvYqyRc8DqC/qsfdjUDTDu/S0MKSCYZxpg+XKMkuNEJ5b7YhGG420LhrmPX3W2T1QH9ejK/0td X-Received: by 2002:a05:6830:1d59:: with SMTP id p25mr3988786oth.308.1578683241858; Fri, 10 Jan 2020 11:07:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578683241; cv=none; d=google.com; s=arc-20160816; b=EJERON3VTI++xtO0Cw+IGIykWsQxGvC7UKb7jhcUOS5TLYVRhdPobKJC4govKuy8ZB 38OYWvidGAnmxd7JJhuYOCajngcc+PC8UIQWphXqZQRW6AoSUwh6Q1u7Rqlga7JLBkmp EGobiGRN62EaJSrDUqw2YuTGYuo0kiMYi0bx8RKaaCzFuBDtQUwp71p2SysUaGCLQSzl aWRWMLUrnr18aQTlUoVvy7p6tOFxuBfjFLyPz4+SboMQ7McxFRckOBq3VqnX5E3O+zsl jbf2jgXG4GwWFvzOaG8vEPcCDD87hOS9e3HB+Zkz7src4zVBdkZ7GSJdxjpEhmZj7bog Dncg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=wn9KcLolGATFIJ85MhQjHSQWXqsU1jEhASuaJIiaAfM=; b=ffv66ogqhP8ZW0dzMix5MsDVbWFTPAVSHFMc7uerk3ewX1yk3j1+1O9nU/ZYDXbKIW 3BOLnzPRgcN01RG3ThvUPX9E4lCq24VEkWFVHdpl7GhKhVnFC4/VKjkJqiR3GXr2JfCQ HCXLcUFbUw9Psim9XnDa/QosAcTo5MH5yb9pzmnlwNawZid31aLQ00S8zBabAmXEjLCv lQF3e63Py1Tb/abDJ1BfK6fw3GggQSkBOc3MZxQRP7pw+d//PjNy5ein3zubTfqLBadw bXgaeF4sploU0Hbkr+DK80gvJTUBsk+jBBkU6vYRBcIQ9fXGW9AXPvOdCEakqy6oUXDa WhHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2019-08-05 header.b=dxO0KB0S; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a128si1551748oib.142.2020.01.10.11.07.06; Fri, 10 Jan 2020 11:07:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2019-08-05 header.b=dxO0KB0S; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728885AbgAJTFy (ORCPT + 99 others); Fri, 10 Jan 2020 14:05:54 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:53436 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728853AbgAJTFw (ORCPT ); Fri, 10 Jan 2020 14:05:52 -0500 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 2.17.1