Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3456790pxk; Mon, 7 Sep 2020 13:41:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8gHtRNTgbD4ccq3+xOsKaDbDCth7tKK6N0dxCAoApbc9BdnGldpo8TQf/S9OrmGkQ/Di2 X-Received: by 2002:a17:906:95cd:: with SMTP id n13mr22047237ejy.297.1599511272948; Mon, 07 Sep 2020 13:41:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599511272; cv=none; d=google.com; s=arc-20160816; b=0z8dGh58DEaGiZIV0KYL0gzGvY9E++hF+05OeifudDZOLZjUZz1/s8H/Lqk79tTPhQ EvC4IHz1GpTueF0EWskuvKXydBGhC769ccwj5Rx0qL3aXR+izjawaZrFkc31RfRDr9ix OZxn9pjlgCKDc8VOFZyoeFME4nlxmcz7Keb7M69lSjhGdpwn9blkQylcJIGawvFy91mV MwIuW/41Xud/BEvb/d8+vuBMeZBgcQvQYorKCVJ5b+MP/oVUh16j88cxSs9J2ltPsRd6 faak66/1S5d+pWS4QsedZZpLV98kH1jWWvGllgTFBV003qkUH0iKkGlm/tGdWauuIKPG OuCw== 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=JE3ZXvXaEdFgj90ZNbo1hIni2SoMPQf79f8I+mu4RZc=; b=JIKApSmAD7gmbz5C1o2gNeN8/hIO6goc4um7QHxJry6rtIt4+2xfaE5fOCCxVbY7mO olDjICgFra1aQ01Y84Sg2YfPt9fRoopKt6vFYFfYQ9WZR4Im/FKmcQeMUSqOiE9u+Vx+ lQMUOudFklzbA+YtXFGFfbIkOzj1usJHlisFBK50k4xkMcOAz6HI1pZLZdlMC4iMyLH2 2byX04InipM2jt/9zqInph4h5fUPV0Qzm+dPYCF9N3ZK1/1zta+3gkcYufZPbne3qj81 xGriiezbl5vOvTMriaIbztglYloj9yo72nYgoOLzhO5/IUrYFI5O6aRdxQUhHYOUg7n5 in3A== 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 lk17si9848764ejb.188.2020.09.07.13.40.50; Mon, 07 Sep 2020 13:41:12 -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 S1727769AbgIGUjX (ORCPT + 99 others); Mon, 7 Sep 2020 16:39:23 -0400 Received: from ex13-edg-ou-001.vmware.com ([208.91.0.189]:9185 "EHLO EX13-EDG-OU-001.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726962AbgIGUjW (ORCPT ); Mon, 7 Sep 2020 16:39:22 -0400 Received: from sc9-mailhost3.vmware.com (10.113.161.73) by EX13-EDG-OU-001.vmware.com (10.113.208.155) with Microsoft SMTP Server id 15.0.1156.6; Mon, 7 Sep 2020 13:39:20 -0700 Received: from akaher-virtual-machine.eng.vmware.com (unknown [10.197.103.239]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id 6F07240385; Mon, 7 Sep 2020 13:39:21 -0700 (PDT) From: Ajay Kaher To: , CC: , , , , , , , , , Subject: [PATCH v4.9.y 1/3] vfio/type1: Support faulting PFNMAP vmas Date: Tue, 8 Sep 2020 02:05:14 +0530 Message-ID: <1599510917-23734-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-001.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.9] 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 a9f58f3..ccef02c 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -213,6 +213,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(unsigned long vaddr, int prot, unsigned long *pfn) { struct page *page[1]; @@ -226,12 +252,16 @@ static int vaddr_get_pfn(unsigned long vaddr, int prot, unsigned long *pfn) down_read(¤t->mm->mmap_sem); +retry: vma = find_vma_intersection(current->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, current->mm, vaddr, pfn, prot & IOMMU_WRITE); + if (ret == -EAGAIN) + goto retry; + + if (!ret && !is_invalid_reserved_pfn(*pfn)) + ret = -EFAULT; } up_read(¤t->mm->mmap_sem); -- 2.7.4