Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3449081pxk; Mon, 7 Sep 2020 13:22:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5GF/VJ5Q/HSyA0vVjFTABvfBGRujY+rxxeWCH2a+BzVnf9STnPymifAuzsgtPaCx6jVxg X-Received: by 2002:a50:d2d1:: with SMTP id q17mr23694987edg.167.1599510148068; Mon, 07 Sep 2020 13:22:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599510148; cv=none; d=google.com; s=arc-20160816; b=pTsr5/IZi0MY2jrm3H+gEH72Bt9NRvABDPhc7ZfBCjVOhyUlRVJ3jQRxsePp7UirD6 zcAXPjrNRcwehUGj3kBdIjtl7bEHHmQJTfNq6fY3nZgZboS3rC6S2rsFurycEr2RWPu3 FbNfekzFCzAVsI5MdQwIySz8dvjdDtTmAebvN5nM+L4p7EHEMBM0wOeLOMKkZZbdMF7D 58k5KCOvhN6SvOmFIw7g0ugFEdWRQo5Y6YjWxCEEvkmf/Ms1qAcrzWMGHbM1K75IqkKx uPtEQaYIODLd6SavM45IKV0F2imKidFaYlfFcXGAVCL621YnxdWIzCKUgkFQmIUYNRNT yDHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=mtOhBpLJxYQs0IHowJw1/GN4IskvwEpavnvchj55tNc=; b=Hy82eNqREkYJyf+/oRAvxc2LCHXd3uk76b/KN+inWV0hddESmhWGk2alzrU0cLK6aK GFkIWZM8TKpwFiaD67LrdcTe9Dhu1/AC+YVbT3XwKpnKo1lX+BkeViDsF8BrecUqmC0C aAK8sAG+Ps4D2AsBzifoi6L4j/AHXUDCh9LBAr0RNdpfUSzKyYW0zzvsdq+QFHYiv3MC CW+YbZwlt9NgYsxb/4FEsaAbEmdYlMKMdamlPyT8/QTQe6dL4kAViWOUHj/a6Y017svh Tj0pcTzkM80nLCZcUI1VK1aCLlVUcM0V0UDKmYkdEUSOAlTIBW+Wq1/6LUwTrDkcKhEt 4pTg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=vmware.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j24si10271061edt.105.2020.09.07.13.22.05; Mon, 07 Sep 2020 13:22:28 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=vmware.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729557AbgIGUVI (ORCPT + 99 others); Mon, 7 Sep 2020 16:21:08 -0400 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:12698 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729184AbgIGUVI (ORCPT ); Mon, 7 Sep 2020 16:21:08 -0400 Received: from sc9-mailhost3.vmware.com (10.113.161.73) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Mon, 7 Sep 2020 13:21:07 -0700 Received: from akaher-virtual-machine.eng.vmware.com (unknown [10.197.103.239]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id BDD3C4072D; Mon, 7 Sep 2020 13:21:07 -0700 (PDT) From: Ajay Kaher To: , CC: , , , , , , , , , Subject: [PATCH v4.14.y 1/3] vfio/type1: Support faulting PFNMAP vmas Date: Tue, 8 Sep 2020 01:47:05 +0530 Message-ID: <1599509828-23596-1-git-send-email-akaher@vmware.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain Received-SPF: None (EX13-EDG-OU-002.vmware.com: akaher@vmware.com does not designate permitted sender hosts) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alex Williamson commit 41311242221e3482b20bfed10fa4d9db98d87016 upstream. With conversion to follow_pfn(), DMA mapping a PFNMAP range depends on the range being faulted into the vma. Add support to manually provide that, in the same way as done on KVM with hva_to_pfn_remapped(). Reviewed-by: Peter Xu Signed-off-by: Alex Williamson [Ajay: Regenerated the patch for v4.14] Signed-off-by: Ajay Kaher --- drivers/vfio/vfio_iommu_type1.c | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 35a3750..150be10 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -336,6 +336,32 @@ static int put_pfn(unsigned long pfn, int prot) return 0; } +static int follow_fault_pfn(struct vm_area_struct *vma, struct mm_struct *mm, + unsigned long vaddr, unsigned long *pfn, + bool write_fault) +{ + int ret; + + ret = follow_pfn(vma, vaddr, pfn); + if (ret) { + bool unlocked = false; + + ret = fixup_user_fault(NULL, mm, vaddr, + FAULT_FLAG_REMOTE | + (write_fault ? FAULT_FLAG_WRITE : 0), + &unlocked); + if (unlocked) + return -EAGAIN; + + if (ret) + return ret; + + ret = follow_pfn(vma, vaddr, pfn); + } + + return ret; +} + static int vaddr_get_pfn(struct mm_struct *mm, unsigned long vaddr, int prot, unsigned long *pfn) { @@ -375,12 +401,16 @@ static int vaddr_get_pfn(struct mm_struct *mm, unsigned long vaddr, down_read(&mm->mmap_sem); +retry: vma = find_vma_intersection(mm, vaddr, vaddr + 1); if (vma && vma->vm_flags & VM_PFNMAP) { - if (!follow_pfn(vma, vaddr, pfn) && - is_invalid_reserved_pfn(*pfn)) - ret = 0; + ret = follow_fault_pfn(vma, mm, vaddr, pfn, prot & IOMMU_WRITE); + if (ret == -EAGAIN) + goto retry; + + if (!ret && !is_invalid_reserved_pfn(*pfn)) + ret = -EFAULT; } up_read(&mm->mmap_sem); -- 2.7.4