virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] vhost-vdpa: switch to use vmf_insert_pfn() in the fault handler
@ 2024-07-01  3:31 Jason Wang
  2024-07-01 12:37 ` Michal Kubiak
  0 siblings, 1 reply; 2+ messages in thread
From: Jason Wang @ 2024-07-01  3:31 UTC (permalink / raw)
  To: mst, jasowang, eperezma
  Cc: kvm, virtualization, netdev, linux-kernel, Dragos Tatulea, stable

remap_pfn_page() should not be called in the fault handler as it may
change the vma->flags which may trigger lockdep warning since the vma
write lock is not held. Actually there's no need to modify the
vma->flags as it has been set in the mmap(). So this patch switches to
use vmf_insert_pfn() instead.

Reported-by: Dragos Tatulea <dtatulea@nvidia.com>
Tested-by: Dragos Tatulea <dtatulea@nvidia.com>
Fixes: ddd89d0a059d ("vhost_vdpa: support doorbell mapping via mmap")
Cc: stable@vger.kernel.org
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 drivers/vhost/vdpa.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
index 63a53680a85c..6b9c12acf438 100644
--- a/drivers/vhost/vdpa.c
+++ b/drivers/vhost/vdpa.c
@@ -1483,13 +1483,7 @@ static vm_fault_t vhost_vdpa_fault(struct vm_fault *vmf)
 
 	notify = ops->get_vq_notification(vdpa, index);
 
-	vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
-	if (remap_pfn_range(vma, vmf->address & PAGE_MASK,
-			    PFN_DOWN(notify.addr), PAGE_SIZE,
-			    vma->vm_page_prot))
-		return VM_FAULT_SIGBUS;
-
-	return VM_FAULT_NOPAGE;
+	return vmf_insert_pfn(vma, vmf->address & PAGE_MASK, PFN_DOWN(notify.addr));
 }
 
 static const struct vm_operations_struct vhost_vdpa_vm_ops = {
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] vhost-vdpa: switch to use vmf_insert_pfn() in the fault handler
  2024-07-01  3:31 [PATCH] vhost-vdpa: switch to use vmf_insert_pfn() in the fault handler Jason Wang
@ 2024-07-01 12:37 ` Michal Kubiak
  0 siblings, 0 replies; 2+ messages in thread
From: Michal Kubiak @ 2024-07-01 12:37 UTC (permalink / raw)
  To: Jason Wang
  Cc: mst, eperezma, kvm, virtualization, netdev, linux-kernel,
	Dragos Tatulea, stable

On Mon, Jul 01, 2024 at 11:31:59AM +0800, Jason Wang wrote:
> remap_pfn_page() should not be called in the fault handler as it may
> change the vma->flags which may trigger lockdep warning since the vma
> write lock is not held. Actually there's no need to modify the
> vma->flags as it has been set in the mmap(). So this patch switches to
> use vmf_insert_pfn() instead.
> 
> Reported-by: Dragos Tatulea <dtatulea@nvidia.com>
> Tested-by: Dragos Tatulea <dtatulea@nvidia.com>
> Fixes: ddd89d0a059d ("vhost_vdpa: support doorbell mapping via mmap")
> Cc: stable@vger.kernel.org
> Signed-off-by: Jason Wang <jasowang@redhat.com>
> ---
>  drivers/vhost/vdpa.c | 8 +-------
>  1 file changed, 1 insertion(+), 7 deletions(-)
> 
> diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
> index 63a53680a85c..6b9c12acf438 100644
> --- a/drivers/vhost/vdpa.c
> +++ b/drivers/vhost/vdpa.c
> @@ -1483,13 +1483,7 @@ static vm_fault_t vhost_vdpa_fault(struct vm_fault *vmf)
>  
>  	notify = ops->get_vq_notification(vdpa, index);
>  
> -	vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
> -	if (remap_pfn_range(vma, vmf->address & PAGE_MASK,
> -			    PFN_DOWN(notify.addr), PAGE_SIZE,
> -			    vma->vm_page_prot))
> -		return VM_FAULT_SIGBUS;
> -
> -	return VM_FAULT_NOPAGE;
> +	return vmf_insert_pfn(vma, vmf->address & PAGE_MASK, PFN_DOWN(notify.addr));
>  }
>  
>  static const struct vm_operations_struct vhost_vdpa_vm_ops = {
> -- 
> 2.31.1
> 
> 

I would only consider pasting an example warning log. (It's my
suggestion only).

Anyway, the patch looks OK to me.

Thanks,
Reviewed-by: Michal Kubiak <michal.kubiak@intel.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-07-01 12:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-01  3:31 [PATCH] vhost-vdpa: switch to use vmf_insert_pfn() in the fault handler Jason Wang
2024-07-01 12:37 ` Michal Kubiak

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).