* [PATCH v2] vfio/type1: Use follow_pte()
@ 2021-02-16 22:49 Alex Williamson
2021-02-16 23:43 ` Peter Xu
2021-02-22 18:39 ` Alex Williamson
0 siblings, 2 replies; 3+ messages in thread
From: Alex Williamson @ 2021-02-16 22:49 UTC (permalink / raw)
To: alex.williamson; +Cc: cohuck, kvm, linux-kernel, pbonzini, jgg, peterx
follow_pfn() doesn't make sure that we're using the correct page
protections, get the pte with follow_pte() so that we can test
protections and get the pfn from the pte.
Fixes: 5cbf3264bc71 ("vfio/type1: Fix VA->PA translation for PFNMAP VMAs in vaddr_get_pfn()")
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
v2: Update to current follow_pte() API, add Reviews
drivers/vfio/vfio_iommu_type1.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index ec9fd95a138b..ae4fd2295c95 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -463,9 +463,11 @@ static int follow_fault_pfn(struct vm_area_struct *vma, struct mm_struct *mm,
unsigned long vaddr, unsigned long *pfn,
bool write_fault)
{
+ pte_t *ptep;
+ spinlock_t *ptl;
int ret;
- ret = follow_pfn(vma, vaddr, pfn);
+ ret = follow_pte(vma->vm_mm, vaddr, &ptep, &ptl);
if (ret) {
bool unlocked = false;
@@ -479,9 +481,17 @@ static int follow_fault_pfn(struct vm_area_struct *vma, struct mm_struct *mm,
if (ret)
return ret;
- ret = follow_pfn(vma, vaddr, pfn);
+ ret = follow_pte(vma->vm_mm, vaddr, &ptep, &ptl);
+ if (ret)
+ return ret;
}
+ if (write_fault && !pte_write(*ptep))
+ ret = -EFAULT;
+ else
+ *pfn = pte_pfn(*ptep);
+
+ pte_unmap_unlock(ptep, ptl);
return ret;
}
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] vfio/type1: Use follow_pte()
2021-02-16 22:49 [PATCH v2] vfio/type1: Use follow_pte() Alex Williamson
@ 2021-02-16 23:43 ` Peter Xu
2021-02-22 18:39 ` Alex Williamson
1 sibling, 0 replies; 3+ messages in thread
From: Peter Xu @ 2021-02-16 23:43 UTC (permalink / raw)
To: Alex Williamson; +Cc: cohuck, kvm, linux-kernel, pbonzini, jgg
On Tue, Feb 16, 2021 at 03:49:34PM -0700, Alex Williamson wrote:
> follow_pfn() doesn't make sure that we're using the correct page
> protections, get the pte with follow_pte() so that we can test
> protections and get the pfn from the pte.
>
> Fixes: 5cbf3264bc71 ("vfio/type1: Fix VA->PA translation for PFNMAP VMAs in vaddr_get_pfn()")
> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
> Reviewed-by: Cornelia Huck <cohuck@redhat.com>
> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
--
Peter Xu
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] vfio/type1: Use follow_pte()
2021-02-16 22:49 [PATCH v2] vfio/type1: Use follow_pte() Alex Williamson
2021-02-16 23:43 ` Peter Xu
@ 2021-02-22 18:39 ` Alex Williamson
1 sibling, 0 replies; 3+ messages in thread
From: Alex Williamson @ 2021-02-22 18:39 UTC (permalink / raw)
To: alex.williamson; +Cc: cohuck, kvm, linux-kernel, pbonzini, jgg, peterx
On Tue, 16 Feb 2021 15:49:34 -0700
Alex Williamson <alex.williamson@redhat.com> wrote:
> follow_pfn() doesn't make sure that we're using the correct page
> protections, get the pte with follow_pte() so that we can test
> protections and get the pfn from the pte.
>
> Fixes: 5cbf3264bc71 ("vfio/type1: Fix VA->PA translation for PFNMAP VMAs in vaddr_get_pfn()")
> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
> Reviewed-by: Cornelia Huck <cohuck@redhat.com>
> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
> ---
>
> v2: Update to current follow_pte() API, add Reviews
>
> drivers/vfio/vfio_iommu_type1.c | 14 ++++++++++++--
> 1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
> index ec9fd95a138b..ae4fd2295c95 100644
> --- a/drivers/vfio/vfio_iommu_type1.c
> +++ b/drivers/vfio/vfio_iommu_type1.c
> @@ -463,9 +463,11 @@ static int follow_fault_pfn(struct vm_area_struct *vma, struct mm_struct *mm,
> unsigned long vaddr, unsigned long *pfn,
> bool write_fault)
> {
> + pte_t *ptep;
> + spinlock_t *ptl;
> int ret;
>
> - ret = follow_pfn(vma, vaddr, pfn);
> + ret = follow_pte(vma->vm_mm, vaddr, &ptep, &ptl);
> if (ret) {
> bool unlocked = false;
>
> @@ -479,9 +481,17 @@ static int follow_fault_pfn(struct vm_area_struct *vma, struct mm_struct *mm,
> if (ret)
> return ret;
>
> - ret = follow_pfn(vma, vaddr, pfn);
> + ret = follow_pte(vma->vm_mm, vaddr, &ptep, &ptl);
> + if (ret)
> + return ret;
> }
>
> + if (write_fault && !pte_write(*ptep))
> + ret = -EFAULT;
> + else
> + *pfn = pte_pfn(*ptep);
> +
> + pte_unmap_unlock(ptep, ptl);
> return ret;
> }
>
>
Adding the following to resolve 32-bit build:
diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index 8a777250764a..ed03f3fcb07e 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -24,6 +24,7 @@
#include <linux/compat.h>
#include <linux/device.h>
#include <linux/fs.h>
+#include <linux/highmem.h>
#include <linux/iommu.h>
#include <linux/module.h>
#include <linux/mm.h>
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-02-22 18:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-16 22:49 [PATCH v2] vfio/type1: Use follow_pte() Alex Williamson
2021-02-16 23:43 ` Peter Xu
2021-02-22 18:39 ` Alex Williamson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).