All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Netvsc: Call hv_unmap_memory() in the netvsc_device_remove()
@ 2022-02-01 16:32 ` Tianyu Lan
  0 siblings, 0 replies; 8+ messages in thread
From: Tianyu Lan @ 2022-02-01 16:32 UTC (permalink / raw)
  To: kys, haiyangz, sthemmin, wei.liu, decui, tglx, mingo, bp,
	dave.hansen, x86, hpa, davem, kuba, hch, m.szyprowski,
	robin.murphy, michael.h.kelley
  Cc: Tianyu Lan, iommu, linux-hyperv, linux-kernel, netdev

From: Tianyu Lan <Tianyu.Lan@microsoft.com>

netvsc_device_remove() calls vunmap() inside which should not be
called in the interrupt context. Current code calls hv_unmap_memory()
in the free_netvsc_device() which is rcu callback and maybe called
in the interrupt context. This will trigger BUG_ON(in_interrupt())
in the vunmap(). Fix it via moving hv_unmap_memory() to netvsc_device_
remove().

Fixes: 846da38de0e8 ("net: netvsc: Add Isolation VM support for netvsc driver")
Signed-off-by: Tianyu Lan <Tianyu.Lan@microsoft.com>
---
 drivers/net/hyperv/netvsc.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
index afa81a9480cc..f989f920d4ce 100644
--- a/drivers/net/hyperv/netvsc.c
+++ b/drivers/net/hyperv/netvsc.c
@@ -154,19 +154,15 @@ static void free_netvsc_device(struct rcu_head *head)
 
 	kfree(nvdev->extension);
 
-	if (nvdev->recv_original_buf) {
-		hv_unmap_memory(nvdev->recv_buf);
+	if (nvdev->recv_original_buf)
 		vfree(nvdev->recv_original_buf);
-	} else {
+	else
 		vfree(nvdev->recv_buf);
-	}
 
-	if (nvdev->send_original_buf) {
-		hv_unmap_memory(nvdev->send_buf);
+	if (nvdev->send_original_buf)
 		vfree(nvdev->send_original_buf);
-	} else {
+	else
 		vfree(nvdev->send_buf);
-	}
 
 	bitmap_free(nvdev->send_section_map);
 
@@ -765,6 +761,12 @@ void netvsc_device_remove(struct hv_device *device)
 		netvsc_teardown_send_gpadl(device, net_device, ndev);
 	}
 
+	if (net_device->recv_original_buf)
+		hv_unmap_memory(net_device->recv_buf);
+
+	if (net_device->send_original_buf)
+		hv_unmap_memory(net_device->send_buf);
+
 	/* Release all resources */
 	free_netvsc_device_rcu(net_device);
 }
-- 
2.25.1


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

* [PATCH] Netvsc: Call hv_unmap_memory() in the netvsc_device_remove()
@ 2022-02-01 16:32 ` Tianyu Lan
  0 siblings, 0 replies; 8+ messages in thread
From: Tianyu Lan @ 2022-02-01 16:32 UTC (permalink / raw)
  To: kys, haiyangz, sthemmin, wei.liu, decui, tglx, mingo, bp,
	dave.hansen, x86, hpa, davem, kuba, hch, m.szyprowski,
	robin.murphy, michael.h.kelley
  Cc: netdev, iommu, Tianyu Lan, linux-hyperv, linux-kernel

From: Tianyu Lan <Tianyu.Lan@microsoft.com>

netvsc_device_remove() calls vunmap() inside which should not be
called in the interrupt context. Current code calls hv_unmap_memory()
in the free_netvsc_device() which is rcu callback and maybe called
in the interrupt context. This will trigger BUG_ON(in_interrupt())
in the vunmap(). Fix it via moving hv_unmap_memory() to netvsc_device_
remove().

Fixes: 846da38de0e8 ("net: netvsc: Add Isolation VM support for netvsc driver")
Signed-off-by: Tianyu Lan <Tianyu.Lan@microsoft.com>
---
 drivers/net/hyperv/netvsc.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
index afa81a9480cc..f989f920d4ce 100644
--- a/drivers/net/hyperv/netvsc.c
+++ b/drivers/net/hyperv/netvsc.c
@@ -154,19 +154,15 @@ static void free_netvsc_device(struct rcu_head *head)
 
 	kfree(nvdev->extension);
 
-	if (nvdev->recv_original_buf) {
-		hv_unmap_memory(nvdev->recv_buf);
+	if (nvdev->recv_original_buf)
 		vfree(nvdev->recv_original_buf);
-	} else {
+	else
 		vfree(nvdev->recv_buf);
-	}
 
-	if (nvdev->send_original_buf) {
-		hv_unmap_memory(nvdev->send_buf);
+	if (nvdev->send_original_buf)
 		vfree(nvdev->send_original_buf);
-	} else {
+	else
 		vfree(nvdev->send_buf);
-	}
 
 	bitmap_free(nvdev->send_section_map);
 
@@ -765,6 +761,12 @@ void netvsc_device_remove(struct hv_device *device)
 		netvsc_teardown_send_gpadl(device, net_device, ndev);
 	}
 
+	if (net_device->recv_original_buf)
+		hv_unmap_memory(net_device->recv_buf);
+
+	if (net_device->send_original_buf)
+		hv_unmap_memory(net_device->send_buf);
+
 	/* Release all resources */
 	free_netvsc_device_rcu(net_device);
 }
-- 
2.25.1

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* RE: [PATCH] Netvsc: Call hv_unmap_memory() in the netvsc_device_remove()
  2022-02-01 16:32 ` Tianyu Lan
@ 2022-02-01 23:20   ` Haiyang Zhang via iommu
  -1 siblings, 0 replies; 8+ messages in thread
From: Haiyang Zhang @ 2022-02-01 23:20 UTC (permalink / raw)
  To: Tianyu Lan, KY Srinivasan, Stephen Hemminger, wei.liu,
	Dexuan Cui, tglx, mingo, bp, dave.hansen, x86, hpa, davem, kuba,
	hch, m.szyprowski, robin.murphy, Michael Kelley (LINUX)
  Cc: Tianyu Lan, iommu, linux-hyperv, linux-kernel, netdev



> -----Original Message-----
> From: Tianyu Lan <ltykernel@gmail.com>
> Sent: Tuesday, February 1, 2022 11:32 AM
> To: KY Srinivasan <kys@microsoft.com>; Haiyang Zhang <haiyangz@microsoft.com>; Stephen
> Hemminger <sthemmin@microsoft.com>; wei.liu@kernel.org; Dexuan Cui <decui@microsoft.com>;
> tglx@linutronix.de; mingo@redhat.com; bp@alien8.de; dave.hansen@linux.intel.com;
> x86@kernel.org; hpa@zytor.com; davem@davemloft.net; kuba@kernel.org; hch@infradead.org;
> m.szyprowski@samsung.com; robin.murphy@arm.com; Michael Kelley (LINUX)
> <mikelley@microsoft.com>
> Cc: Tianyu Lan <Tianyu.Lan@microsoft.com>; iommu@lists.linux-foundation.org; linux-
> hyperv@vger.kernel.org; linux-kernel@vger.kernel.org; netdev@vger.kernel.org
> Subject: [PATCH] Netvsc: Call hv_unmap_memory() in the netvsc_device_remove()
> 
> From: Tianyu Lan <Tianyu.Lan@microsoft.com>
> 
> netvsc_device_remove() calls vunmap() inside which should not be
> called in the interrupt context. Current code calls hv_unmap_memory()
> in the free_netvsc_device() which is rcu callback and maybe called
> in the interrupt context. This will trigger BUG_ON(in_interrupt())
> in the vunmap(). Fix it via moving hv_unmap_memory() to netvsc_device_
> remove().
> 
> Fixes: 846da38de0e8 ("net: netvsc: Add Isolation VM support for netvsc driver")
> Signed-off-by: Tianyu Lan <Tianyu.Lan@microsoft.com>
> ---
>  drivers/net/hyperv/netvsc.c | 18 ++++++++++--------
>  1 file changed, 10 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
> index afa81a9480cc..f989f920d4ce 100644
> --- a/drivers/net/hyperv/netvsc.c
> +++ b/drivers/net/hyperv/netvsc.c
> @@ -154,19 +154,15 @@ static void free_netvsc_device(struct rcu_head *head)
> 
>  	kfree(nvdev->extension);
> 
> -	if (nvdev->recv_original_buf) {
> -		hv_unmap_memory(nvdev->recv_buf);
> +	if (nvdev->recv_original_buf)
>  		vfree(nvdev->recv_original_buf);
> -	} else {
> +	else
>  		vfree(nvdev->recv_buf);
> -	}
> 
> -	if (nvdev->send_original_buf) {
> -		hv_unmap_memory(nvdev->send_buf);
> +	if (nvdev->send_original_buf)
>  		vfree(nvdev->send_original_buf);
> -	} else {
> +	else
>  		vfree(nvdev->send_buf);
> -	}
> 
>  	bitmap_free(nvdev->send_section_map);
> 
> @@ -765,6 +761,12 @@ void netvsc_device_remove(struct hv_device *device)
>  		netvsc_teardown_send_gpadl(device, net_device, ndev);
>  	}
> 
> +	if (net_device->recv_original_buf)
> +		hv_unmap_memory(net_device->recv_buf);
> +
> +	if (net_device->send_original_buf)
> +		hv_unmap_memory(net_device->send_buf);
> +
>  	/* Release all resources */
>  	free_netvsc_device_rcu(net_device);
>  }

Reviewed-by: Haiyang Zhang <haiyangz@microsoft.com>

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

* RE: [PATCH] Netvsc: Call hv_unmap_memory() in the netvsc_device_remove()
@ 2022-02-01 23:20   ` Haiyang Zhang via iommu
  0 siblings, 0 replies; 8+ messages in thread
From: Haiyang Zhang via iommu @ 2022-02-01 23:20 UTC (permalink / raw)
  To: Tianyu Lan, KY Srinivasan, Stephen Hemminger, wei.liu,
	Dexuan Cui, tglx, mingo, bp, dave.hansen, x86, hpa, davem, kuba,
	hch, m.szyprowski, robin.murphy, Michael Kelley (LINUX)
  Cc: netdev, iommu, Tianyu Lan, linux-hyperv, linux-kernel



> -----Original Message-----
> From: Tianyu Lan <ltykernel@gmail.com>
> Sent: Tuesday, February 1, 2022 11:32 AM
> To: KY Srinivasan <kys@microsoft.com>; Haiyang Zhang <haiyangz@microsoft.com>; Stephen
> Hemminger <sthemmin@microsoft.com>; wei.liu@kernel.org; Dexuan Cui <decui@microsoft.com>;
> tglx@linutronix.de; mingo@redhat.com; bp@alien8.de; dave.hansen@linux.intel.com;
> x86@kernel.org; hpa@zytor.com; davem@davemloft.net; kuba@kernel.org; hch@infradead.org;
> m.szyprowski@samsung.com; robin.murphy@arm.com; Michael Kelley (LINUX)
> <mikelley@microsoft.com>
> Cc: Tianyu Lan <Tianyu.Lan@microsoft.com>; iommu@lists.linux-foundation.org; linux-
> hyperv@vger.kernel.org; linux-kernel@vger.kernel.org; netdev@vger.kernel.org
> Subject: [PATCH] Netvsc: Call hv_unmap_memory() in the netvsc_device_remove()
> 
> From: Tianyu Lan <Tianyu.Lan@microsoft.com>
> 
> netvsc_device_remove() calls vunmap() inside which should not be
> called in the interrupt context. Current code calls hv_unmap_memory()
> in the free_netvsc_device() which is rcu callback and maybe called
> in the interrupt context. This will trigger BUG_ON(in_interrupt())
> in the vunmap(). Fix it via moving hv_unmap_memory() to netvsc_device_
> remove().
> 
> Fixes: 846da38de0e8 ("net: netvsc: Add Isolation VM support for netvsc driver")
> Signed-off-by: Tianyu Lan <Tianyu.Lan@microsoft.com>
> ---
>  drivers/net/hyperv/netvsc.c | 18 ++++++++++--------
>  1 file changed, 10 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
> index afa81a9480cc..f989f920d4ce 100644
> --- a/drivers/net/hyperv/netvsc.c
> +++ b/drivers/net/hyperv/netvsc.c
> @@ -154,19 +154,15 @@ static void free_netvsc_device(struct rcu_head *head)
> 
>  	kfree(nvdev->extension);
> 
> -	if (nvdev->recv_original_buf) {
> -		hv_unmap_memory(nvdev->recv_buf);
> +	if (nvdev->recv_original_buf)
>  		vfree(nvdev->recv_original_buf);
> -	} else {
> +	else
>  		vfree(nvdev->recv_buf);
> -	}
> 
> -	if (nvdev->send_original_buf) {
> -		hv_unmap_memory(nvdev->send_buf);
> +	if (nvdev->send_original_buf)
>  		vfree(nvdev->send_original_buf);
> -	} else {
> +	else
>  		vfree(nvdev->send_buf);
> -	}
> 
>  	bitmap_free(nvdev->send_section_map);
> 
> @@ -765,6 +761,12 @@ void netvsc_device_remove(struct hv_device *device)
>  		netvsc_teardown_send_gpadl(device, net_device, ndev);
>  	}
> 
> +	if (net_device->recv_original_buf)
> +		hv_unmap_memory(net_device->recv_buf);
> +
> +	if (net_device->send_original_buf)
> +		hv_unmap_memory(net_device->send_buf);
> +
>  	/* Release all resources */
>  	free_netvsc_device_rcu(net_device);
>  }

Reviewed-by: Haiyang Zhang <haiyangz@microsoft.com>
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* RE: [PATCH] Netvsc: Call hv_unmap_memory() in the netvsc_device_remove()
  2022-02-01 16:32 ` Tianyu Lan
@ 2022-02-02 17:05   ` Michael Kelley (LINUX) via iommu
  -1 siblings, 0 replies; 8+ messages in thread
From: Michael Kelley (LINUX) @ 2022-02-02 17:05 UTC (permalink / raw)
  To: Tianyu Lan, KY Srinivasan, Haiyang Zhang, Stephen Hemminger,
	wei.liu, Dexuan Cui, tglx, mingo, bp, dave.hansen, x86, hpa,
	davem, kuba, hch, m.szyprowski, robin.murphy
  Cc: Tianyu Lan, iommu, linux-hyperv, linux-kernel, netdev

From: Tianyu Lan <ltykernel@gmail.com> Sent: Tuesday, February 1, 2022 8:32 AM
> 
> netvsc_device_remove() calls vunmap() inside which should not be
> called in the interrupt context. Current code calls hv_unmap_memory()
> in the free_netvsc_device() which is rcu callback and maybe called
> in the interrupt context. This will trigger BUG_ON(in_interrupt())
> in the vunmap(). Fix it via moving hv_unmap_memory() to netvsc_device_
> remove().

I think this change can fail to call hv_unmap_memory() in an error case.

If netvsc_init_buf() fails after hv_map_memory() succeeds for the receive
buffer or for the send buffer, no corresponding hv_unmap_memory() will
be done.  The failure in netvsc_init_buf() will cause netvsc_connect_vsp()
to fail, so netvsc_add_device() will "goto close" where free_netvsc_device()
will be called.  But free_netvsc_device() no longer calls hv_unmap_memory(),
so it won't ever happen.   netvsc_device_remove() is never called in this case
because netvsc_add_device() failed.

Michael

> 
> Fixes: 846da38de0e8 ("net: netvsc: Add Isolation VM support for netvsc driver")
> Signed-off-by: Tianyu Lan <Tianyu.Lan@microsoft.com>
> ---
>  drivers/net/hyperv/netvsc.c | 18 ++++++++++--------
>  1 file changed, 10 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
> index afa81a9480cc..f989f920d4ce 100644
> --- a/drivers/net/hyperv/netvsc.c
> +++ b/drivers/net/hyperv/netvsc.c
> @@ -154,19 +154,15 @@ static void free_netvsc_device(struct rcu_head *head)
> 
>  	kfree(nvdev->extension);
> 
> -	if (nvdev->recv_original_buf) {
> -		hv_unmap_memory(nvdev->recv_buf);
> +	if (nvdev->recv_original_buf)
>  		vfree(nvdev->recv_original_buf);
> -	} else {
> +	else
>  		vfree(nvdev->recv_buf);
> -	}
> 
> -	if (nvdev->send_original_buf) {
> -		hv_unmap_memory(nvdev->send_buf);
> +	if (nvdev->send_original_buf)
>  		vfree(nvdev->send_original_buf);
> -	} else {
> +	else
>  		vfree(nvdev->send_buf);
> -	}
> 
>  	bitmap_free(nvdev->send_section_map);
> 
> @@ -765,6 +761,12 @@ void netvsc_device_remove(struct hv_device *device)
>  		netvsc_teardown_send_gpadl(device, net_device, ndev);
>  	}
> 
> +	if (net_device->recv_original_buf)
> +		hv_unmap_memory(net_device->recv_buf);
> +
> +	if (net_device->send_original_buf)
> +		hv_unmap_memory(net_device->send_buf);
> +
>  	/* Release all resources */
>  	free_netvsc_device_rcu(net_device);
>  }
> --
> 2.25.1


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

* RE: [PATCH] Netvsc: Call hv_unmap_memory() in the netvsc_device_remove()
@ 2022-02-02 17:05   ` Michael Kelley (LINUX) via iommu
  0 siblings, 0 replies; 8+ messages in thread
From: Michael Kelley (LINUX) via iommu @ 2022-02-02 17:05 UTC (permalink / raw)
  To: Tianyu Lan, KY Srinivasan, Haiyang Zhang, Stephen Hemminger,
	wei.liu, Dexuan Cui, tglx, mingo, bp, dave.hansen, x86, hpa,
	davem, kuba, hch, m.szyprowski, robin.murphy
  Cc: netdev, iommu, Tianyu Lan, linux-hyperv, linux-kernel

From: Tianyu Lan <ltykernel@gmail.com> Sent: Tuesday, February 1, 2022 8:32 AM
> 
> netvsc_device_remove() calls vunmap() inside which should not be
> called in the interrupt context. Current code calls hv_unmap_memory()
> in the free_netvsc_device() which is rcu callback and maybe called
> in the interrupt context. This will trigger BUG_ON(in_interrupt())
> in the vunmap(). Fix it via moving hv_unmap_memory() to netvsc_device_
> remove().

I think this change can fail to call hv_unmap_memory() in an error case.

If netvsc_init_buf() fails after hv_map_memory() succeeds for the receive
buffer or for the send buffer, no corresponding hv_unmap_memory() will
be done.  The failure in netvsc_init_buf() will cause netvsc_connect_vsp()
to fail, so netvsc_add_device() will "goto close" where free_netvsc_device()
will be called.  But free_netvsc_device() no longer calls hv_unmap_memory(),
so it won't ever happen.   netvsc_device_remove() is never called in this case
because netvsc_add_device() failed.

Michael

> 
> Fixes: 846da38de0e8 ("net: netvsc: Add Isolation VM support for netvsc driver")
> Signed-off-by: Tianyu Lan <Tianyu.Lan@microsoft.com>
> ---
>  drivers/net/hyperv/netvsc.c | 18 ++++++++++--------
>  1 file changed, 10 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
> index afa81a9480cc..f989f920d4ce 100644
> --- a/drivers/net/hyperv/netvsc.c
> +++ b/drivers/net/hyperv/netvsc.c
> @@ -154,19 +154,15 @@ static void free_netvsc_device(struct rcu_head *head)
> 
>  	kfree(nvdev->extension);
> 
> -	if (nvdev->recv_original_buf) {
> -		hv_unmap_memory(nvdev->recv_buf);
> +	if (nvdev->recv_original_buf)
>  		vfree(nvdev->recv_original_buf);
> -	} else {
> +	else
>  		vfree(nvdev->recv_buf);
> -	}
> 
> -	if (nvdev->send_original_buf) {
> -		hv_unmap_memory(nvdev->send_buf);
> +	if (nvdev->send_original_buf)
>  		vfree(nvdev->send_original_buf);
> -	} else {
> +	else
>  		vfree(nvdev->send_buf);
> -	}
> 
>  	bitmap_free(nvdev->send_section_map);
> 
> @@ -765,6 +761,12 @@ void netvsc_device_remove(struct hv_device *device)
>  		netvsc_teardown_send_gpadl(device, net_device, ndev);
>  	}
> 
> +	if (net_device->recv_original_buf)
> +		hv_unmap_memory(net_device->recv_buf);
> +
> +	if (net_device->send_original_buf)
> +		hv_unmap_memory(net_device->send_buf);
> +
>  	/* Release all resources */
>  	free_netvsc_device_rcu(net_device);
>  }
> --
> 2.25.1

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* Re: [PATCH] Netvsc: Call hv_unmap_memory() in the netvsc_device_remove()
  2022-02-02 17:05   ` Michael Kelley (LINUX) via iommu
@ 2022-02-08 14:19     ` Tianyu Lan
  -1 siblings, 0 replies; 8+ messages in thread
From: Tianyu Lan @ 2022-02-08 14:19 UTC (permalink / raw)
  To: Michael Kelley (LINUX),
	KY Srinivasan, Haiyang Zhang, Stephen Hemminger, wei.liu,
	Dexuan Cui, tglx, mingo, bp, dave.hansen, x86, hpa, davem, kuba,
	hch, m.szyprowski, robin.murphy
  Cc: Tianyu Lan, iommu, linux-hyperv, linux-kernel, netdev

On 2/3/2022 1:05 AM, Michael Kelley (LINUX) wrote:
> From: Tianyu Lan<ltykernel@gmail.com>  Sent: Tuesday, February 1, 2022 8:32 AM
>> netvsc_device_remove() calls vunmap() inside which should not be
>> called in the interrupt context. Current code calls hv_unmap_memory()
>> in the free_netvsc_device() which is rcu callback and maybe called
>> in the interrupt context. This will trigger BUG_ON(in_interrupt())
>> in the vunmap(). Fix it via moving hv_unmap_memory() to netvsc_device_
>> remove().
> I think this change can fail to call hv_unmap_memory() in an error case.
> 
> If netvsc_init_buf() fails after hv_map_memory() succeeds for the receive
> buffer or for the send buffer, no corresponding hv_unmap_memory() will
> be done.  The failure in netvsc_init_buf() will cause netvsc_connect_vsp()
> to fail, so netvsc_add_device() will "goto close" where free_netvsc_device()
> will be called.  But free_netvsc_device() no longer calls hv_unmap_memory(),
> so it won't ever happen.   netvsc_device_remove() is never called in this case
> because netvsc_add_device() failed.
> 

Hi Michael:
       Thanks for your review. Nice catch and will fix in the next
version.


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

* Re: [PATCH] Netvsc: Call hv_unmap_memory() in the netvsc_device_remove()
@ 2022-02-08 14:19     ` Tianyu Lan
  0 siblings, 0 replies; 8+ messages in thread
From: Tianyu Lan @ 2022-02-08 14:19 UTC (permalink / raw)
  To: Michael Kelley (LINUX),
	KY Srinivasan, Haiyang Zhang, Stephen Hemminger, wei.liu,
	Dexuan Cui, tglx, mingo, bp, dave.hansen, x86, hpa, davem, kuba,
	hch, m.szyprowski, robin.murphy
  Cc: netdev, iommu, Tianyu Lan, linux-hyperv, linux-kernel

On 2/3/2022 1:05 AM, Michael Kelley (LINUX) wrote:
> From: Tianyu Lan<ltykernel@gmail.com>  Sent: Tuesday, February 1, 2022 8:32 AM
>> netvsc_device_remove() calls vunmap() inside which should not be
>> called in the interrupt context. Current code calls hv_unmap_memory()
>> in the free_netvsc_device() which is rcu callback and maybe called
>> in the interrupt context. This will trigger BUG_ON(in_interrupt())
>> in the vunmap(). Fix it via moving hv_unmap_memory() to netvsc_device_
>> remove().
> I think this change can fail to call hv_unmap_memory() in an error case.
> 
> If netvsc_init_buf() fails after hv_map_memory() succeeds for the receive
> buffer or for the send buffer, no corresponding hv_unmap_memory() will
> be done.  The failure in netvsc_init_buf() will cause netvsc_connect_vsp()
> to fail, so netvsc_add_device() will "goto close" where free_netvsc_device()
> will be called.  But free_netvsc_device() no longer calls hv_unmap_memory(),
> so it won't ever happen.   netvsc_device_remove() is never called in this case
> because netvsc_add_device() failed.
> 

Hi Michael:
       Thanks for your review. Nice catch and will fix in the next
version.

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

end of thread, other threads:[~2022-02-08 14:19 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-01 16:32 [PATCH] Netvsc: Call hv_unmap_memory() in the netvsc_device_remove() Tianyu Lan
2022-02-01 16:32 ` Tianyu Lan
2022-02-01 23:20 ` Haiyang Zhang
2022-02-01 23:20   ` Haiyang Zhang via iommu
2022-02-02 17:05 ` Michael Kelley (LINUX)
2022-02-02 17:05   ` Michael Kelley (LINUX) via iommu
2022-02-08 14:19   ` Tianyu Lan
2022-02-08 14:19     ` Tianyu Lan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.