Skip to contentSkip to conversation

Drivers: vmbus: Fix rescind handling in uio_hv_generic

PATCH Superseded Naman Jain 4 participants 13 messages Aug 22, 2024 – Aug 28, 2024

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Naman Jain

author
#0 lore raw

cover Drivers: vmbus: Fix rescind handling in uio_hv_generic

Fix a few issues in rescind handling in uio_hv_generic driver. Patches are based on linux-next-rc4 tip.

Steps to reproduce issue:
* Probe uio_hv_generic driver and create channels to use fcopy
* Disable the guest service on host and then Enable it. or
* repeatedly do cat "/dev/uioX" on the device created for fcopy.

Naman Jain (1):
Drivers: hv: vmbus: Fix rescind handling in uio_hv_generic

Saurabh Sengar (1):
uio_hv_generic: Fix kernel NULL pointer dereference in hv_uio_rescind

 drivers/hv/vmbus_drv.c       |  1 +
 drivers/uio/uio_hv_generic.c | 10 +++++++++-
 2 files changed, 10 insertions(+), 1 deletion(-)

base-commit: 469f1bad3c1c6e268059f78c0eec7e9552b3894c

Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/2 uio_hv_generic: Fix kernel NULL pointer dereference in hv_uio_rescind

From: Saurabh Sengar <[email protected]>

For primary VMBus channels primary_channel pointer is always NULL. This pointer is valid only for the secondry channels.

Fix NULL pointer dereference by retrieving the device_obj from the parent in the absence of a valid primary_channel pointer.

Fixes ca3cda6fcf1e ("uio_hv_generic: add rescind support")
---
 drivers/uio/uio_hv_generic.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/uio/uio_hv_generic.c +2 -1
index b45653752301..c99890c16d29 100644
@@ -109,7 +109,8 @@ static void hv_uio_channel_cb(void *context)
  */
 static void hv_uio_rescind(struct vmbus_channel *channel)
 {
-	struct hv_device *hv_dev = channel->primary_channel->device_obj;
+	struct hv_device *hv_dev = channel->primary_channel ?
+				   channel->primary_channel->device_obj : channel->device_obj;
 	struct hv_uio_private_data *pdata = hv_get_drvdata(hv_dev);
 
 	/*
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH 1/2] uio_hv_generic: Fix kernel NULL pointer dereference in hv_uio_rescind

Quoted 8 lines · Naman Jain

From: Saurabh Sengar <[email protected]>

For primary VMBus channels primary_channel pointer is always NULL. This pointer is valid only for the secondry channels.

Fix NULL pointer dereference by retrieving the device_obj from the parent in the absence of a valid primary_channel pointer.

Quoted 7 lines
Fixes ca3cda6fcf1e ("uio_hv_generic: add rescind support")
---
 drivers/uio/uio_hv_generic.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Hi,

This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him a patch that has triggered this response. He used to manually respond to these common problems, but in order to save his sanity (he kept writing the same thing over and over, yet to different people), I was created. Hopefully you will not take offence and will fix the problem in your patch and resubmit it so that it can be accepted into the Linux kernel tree.

You are receiving this message because of the following common error(s) as indicated below:

- You have marked a patch with a "Fixes:" tag for a commit that is in an older released kernel, yet you do not have a cc: stable line in the signed-off-by area at all, which means that the patch will not be applied to any older kernel releases. To properly fix this, please follow the documented rules in the Documentation/process/stable-kernel-rules.rst file for how to resolve this.

If you wish to discuss this problem further, or you have questions about how to resolve this issue, please feel free to respond to this email and Greg will reply once he has dug out from the pending patches received from other developers.

thanks,

greg k-h's patch email bot

#3 lore raw

RE: [PATCH 1/2] uio_hv_generic: Fix kernel NULL pointer dereference in hv_uio_rescind

In reply to Naman Jain

From: Naman Jain <[email protected]> Sent: Thursday, August 22, 2024 4:09 AM

Quoted 21 lines

From: Saurabh Sengar <[email protected]>

For primary VMBus channels primary_channel pointer is always NULL. This pointer is valid only for the secondry channels.

Fix NULL pointer dereference by retrieving the device_obj from the parent in the absence of a valid primary_channel pointer.

Fixes ca3cda6fcf1e ("uio_hv_generic: add rescind support")
---
 drivers/uio/uio_hv_generic.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/uio/uio_hv_generic.c +0 -0
index b45653752301..c99890c16d29 100644

drivers/uio/uio_hv_generic.c static void hv_uio_channel_cb(void *context) · line 113

Quoted 6 lines
drivers/uio/uio_hv_generic.c +2 -1
@@ -109,7 +109,8 @@ static void hv_uio_channel_cb(void *context)
  */
 static void hv_uio_rescind(struct vmbus_channel *channel)
 {
-	struct hv_device *hv_dev = channel->primary_channel->device_obj;
+	struct hv_device *hv_dev = channel->primary_channel ?
+				   channel->primary_channel->device_obj : channel->device_obj;

It looks to me like hv_uio_rescind() is called only for the primary channel. That makes sense, because waking up the reader should presumably be done once for the device, not once for each channel.

Rather than generalizing the function so it works for both primary and secondary channels, I'd suggest checking if the channel is a secondary channel. If so, output a warning message or do WARN(), and then return immediately, as some there's some kind of programming error.

Looking at the history of the code, it appears that rescinding a UIO device could never have worked. Is that your conclusion as well, or am I missing something?

Michael

author
#4 lore raw

Re: [PATCH 1/2] uio_hv_generic: Fix kernel NULL pointer dereference in hv_uio_rescind

Quoted 33 lines · Michael Kelley

From: Naman Jain <[email protected]> Sent: Thursday, August 22, 2024 4:09 AM

Quoted 21 lines

From: Saurabh Sengar <[email protected]>

For primary VMBus channels primary_channel pointer is always NULL. This pointer is valid only for the secondry channels.

Fix NULL pointer dereference by retrieving the device_obj from the parent in the absence of a valid primary_channel pointer.

Fixes ca3cda6fcf1e ("uio_hv_generic: add rescind support")
---
  drivers/uio/uio_hv_generic.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/uio/uio_hv_generic.c +0 -0
index b45653752301..c99890c16d29 100644

drivers/uio/uio_hv_generic.c static void hv_uio_channel_cb(void *context) · line 113

Quoted 6 lines
drivers/uio/uio_hv_generic.c +2 -1
@@ -109,7 +109,8 @@ static void hv_uio_channel_cb(void *context)
   */
  static void hv_uio_rescind(struct vmbus_channel *channel)
  {
-	struct hv_device *hv_dev = channel->primary_channel->device_obj;
+	struct hv_device *hv_dev = channel->primary_channel ?
+				   channel->primary_channel->device_obj : channel->device_obj;

It looks to me like hv_uio_rescind() is called only for the primary channel. That makes sense, because waking up the reader should presumably be done once for the device, not once for each channel.

Quoted 5 lines

Rather than generalizing the function so it works for both primary and secondary channels, I'd suggest checking if the channel is a secondary channel. If so, output a warning message or do WARN(), and then return immediately, as some there's some kind of programming error.

Thanks for reviewing Michael. By design, there is different handling for secondary channel rescind in channel_mgmt.c [1] and this callback is not expected to be called. I will make the change in my next patch to make it a warning.

[1]
} else if (channel->primary_channel != NULL) {
/*
* Sub-channel is being rescinded. Following is the channel
* close sequence when initiated from the driveri (refer to
* vmbus_close() for details):
* 1. Close all sub-channels first
* 2. Then close the primary channel.
*/

Quoted 6 lines

Looking at the history of the code, it appears that rescinding a UIO device could never have worked. Is that your conclusion as well, or am I missing something?

Michael

Most likely, yes.

Regards,
Naman

author
#5 lore raw

PATCH 2/2 Drivers: hv: vmbus: Fix rescind handling in uio_hv_generic

In reply to Naman Jain

Rescind offer handling relies on rescind callbacks for some of the resources cleanup, if they are registered. It does not unregister vmbus device for the primary channel closure, when callback is registered.
Add logic to unregister vmbus for the primary channel in rescind callback to ensure channel removal and relid release, and to ensure rescind flag is false when driver probe happens again.

Fixes ca3cda6fcf1e ("uio_hv_generic: add rescind support")
---
 drivers/hv/vmbus_drv.c       | 1 +
 drivers/uio/uio_hv_generic.c | 7 +++++++
 2 files changed, 8 insertions(+)
drivers/hv/vmbus_drv.c +1 -0
index c857dc3975be..4bae382a3eb4 100644
@@ -1952,6 +1952,7 @@ void vmbus_device_unregister(struct hv_device *device_obj)
 	 */
 	device_unregister(&device_obj->device);
 }
+EXPORT_SYMBOL_GPL(vmbus_device_unregister);
 
 #ifdef CONFIG_ACPI
 /*
drivers/uio/uio_hv_generic.c +7 -0
index c99890c16d29..ea26c0b460d6 100644
@@ -121,6 +121,13 @@ static void hv_uio_rescind(struct vmbus_channel *channel)
 
 	/* Wake up reader */
 	uio_event_notify(&pdata->info);
+
+	/*
+	 * With rescind callback registered, rescind path will not unregister the device
+	 * when the primary channel is rescinded. Without it, next onoffer msg does not come.
+	 */
+	if (!channel->primary_channel)
+		vmbus_device_unregister(channel->device_obj);
 }
 
 /* Sysfs API to allow mmap of the ring buffers
Signature · 1 line
2.34.1
#6 lore raw

Re: [PATCH 2/2] Drivers: hv: vmbus: Fix rescind handling in uio_hv_generic

Quoted 8 lines · Naman Jain

Rescind offer handling relies on rescind callbacks for some of the resources cleanup, if they are registered. It does not unregister vmbus device for the primary channel closure, when callback is registered.
Add logic to unregister vmbus for the primary channel in rescind callback to ensure channel removal and relid release, and to ensure rescind flag is false when driver probe happens again.

Quoted 7 lines
Fixes ca3cda6fcf1e ("uio_hv_generic: add rescind support")
---
 drivers/hv/vmbus_drv.c       | 1 +
 drivers/uio/uio_hv_generic.c | 7 +++++++
 2 files changed, 8 insertions(+)

Hi,

This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him a patch that has triggered this response. He used to manually respond to these common problems, but in order to save his sanity (he kept writing the same thing over and over, yet to different people), I was created. Hopefully you will not take offence and will fix the problem in your patch and resubmit it so that it can be accepted into the Linux kernel tree.

You are receiving this message because of the following common error(s) as indicated below:

- You have marked a patch with a "Fixes:" tag for a commit that is in an older released kernel, yet you do not have a cc: stable line in the signed-off-by area at all, which means that the patch will not be applied to any older kernel releases. To properly fix this, please follow the documented rules in the Documentation/process/stable-kernel-rules.rst file for how to resolve this.

If you wish to discuss this problem further, or you have questions about how to resolve this issue, please feel free to respond to this email and Greg will reply once he has dug out from the pending patches received from other developers.

thanks,

greg k-h's patch email bot

#7 lore raw

RE: [PATCH 2/2] Drivers: hv: vmbus: Fix rescind handling in uio_hv_generic

In reply to Naman Jain

From: Naman Jain <[email protected]> Sent: Thursday, August 22, 2024 4:09 AM

Quoted 34 lines

Rescind offer handling relies on rescind callbacks for some of the resources cleanup, if they are registered. It does not unregister vmbus device for the primary channel closure, when callback is registered.
Add logic to unregister vmbus for the primary channel in rescind callback to ensure channel removal and relid release, and to ensure rescind flag is false when driver probe happens again.

Fixes ca3cda6fcf1e ("uio_hv_generic: add rescind support")
---
 drivers/hv/vmbus_drv.c       | 1 +
 drivers/uio/uio_hv_generic.c | 7 +++++++
 2 files changed, 8 insertions(+)
drivers/hv/vmbus_drv.c +1 -0
index c857dc3975be..4bae382a3eb4 100644
@@ -1952,6 +1952,7 @@ void vmbus_device_unregister(struct hv_device
 *device_obj)
 	 */
 	device_unregister(&device_obj->device);
 }
+EXPORT_SYMBOL_GPL(vmbus_device_unregister);
 
 #ifdef CONFIG_ACPI

/*

drivers/uio/uio_hv_generic.c +0 -0
index c99890c16d29..ea26c0b460d6 100644

drivers/uio/uio_hv_generic.c static void hv_uio_rescind(struct vmbus_channel *channel) · line 130

Quoted 10 lines
drivers/uio/uio_hv_generic.c +7 -0
@@ -121,6 +121,13 @@ static void hv_uio_rescind(struct vmbus_channel *channel)
 
 	/* Wake up reader */
 	uio_event_notify(&pdata->info);
+
+	/*
+	 * With rescind callback registered, rescind path will not unregister the device
+	 * when the primary channel is rescinded. Without it, next onoffer msg does not come.
+	 */
+	if (!channel->primary_channel)
+		vmbus_device_unregister(channel->device_obj);

When the rescind callback is *not* set, vmbus_onoffer_rescind() makes the call to vmbus_device_unregister(). But it does so bracketed with get_device()/ put_device(). Your code here does not do the bracketing. Is there a reason for the difference? Frankly, I'm not sure why vmbus_onoffer_rescind() does the bracketing, and I can't definitively say if it is really needed. So I guess I'm just asking if you know. :-)

Michael

Quoted 6 lines
drivers/uio/uio_hv_generic.c +0 -1
 }
 
 /* ysfs API to allow mmap of the ring buffers
--

2.34.1

author
#8 lore raw

Re: [PATCH 2/2] Drivers: hv: vmbus: Fix rescind handling in uio_hv_generic

Quoted 53 lines · Michael Kelley

From: Naman Jain <[email protected]> Sent: Thursday, August 22, 2024 4:09 AM

Quoted 34 lines

Rescind offer handling relies on rescind callbacks for some of the resources cleanup, if they are registered. It does not unregister vmbus device for the primary channel closure, when callback is registered.
Add logic to unregister vmbus for the primary channel in rescind callback to ensure channel removal and relid release, and to ensure rescind flag is false when driver probe happens again.

Fixes ca3cda6fcf1e ("uio_hv_generic: add rescind support")
---
  drivers/hv/vmbus_drv.c       | 1 +
  drivers/uio/uio_hv_generic.c | 7 +++++++
  2 files changed, 8 insertions(+)
drivers/hv/vmbus_drv.c +1 -0
index c857dc3975be..4bae382a3eb4 100644
@@ -1952,6 +1952,7 @@ void vmbus_device_unregister(struct hv_device
 *device_obj)
  	 */
  	device_unregister(&device_obj->device);
  }
+EXPORT_SYMBOL_GPL(vmbus_device_unregister);
 
  #ifdef CONFIG_ACPI

/*

drivers/uio/uio_hv_generic.c +0 -0
index c99890c16d29..ea26c0b460d6 100644

drivers/uio/uio_hv_generic.c static void hv_uio_rescind(struct vmbus_channel *channel) · line 130

Quoted 10 lines
drivers/uio/uio_hv_generic.c +7 -0
@@ -121,6 +121,13 @@ static void hv_uio_rescind(struct vmbus_channel *channel)
 
  	/* Wake up reader */
  	uio_event_notify(&pdata->info);
+
+	/*
+	 * With rescind callback registered, rescind path will not unregister the device
+	 * when the primary channel is rescinded. Without it, next onoffer msg does not come.
+	 */
+	if (!channel->primary_channel)
+		vmbus_device_unregister(channel->device_obj);

When the rescind callback is *not* set, vmbus_onoffer_rescind() makes the call to vmbus_device_unregister(). But it does so bracketed with get_device()/ put_device(). Your code here does not do the bracketing. Is there a reason for the difference? Frankly, I'm not sure why vmbus_onoffer_rescind() does the bracketing, and I can't definitively say if it is really needed. So I guess I'm just asking if you know. :-)

Quoted 8 lines

Michael

Quoted 6 lines
drivers/uio/uio_hv_generic.c +0 -1
  }
 
  /* ysfs API to allow mmap of the ring buffers
--

2.34.1

IMHO, we have already NULL checked channel->device_obj and other couple of things to make sure we are safe to clean this up. At other places as well, I don't see the use of put and get device. So I think its not required. I am open to suggestions.

Regards,
Naman

#9 lore raw

RE: [PATCH 2/2] Drivers: hv: vmbus: Fix rescind handling in uio_hv_generic

From: Naman Jain <[email protected]> Sent: Sunday, August 25, 2024 10:32 PM

Quoted 56 lines · Michael Kelley
Quoted 52 lines

From: Naman Jain <[email protected]> Sent: Thursday, August 22, 2024 4:09 AM

Quoted 33 lines

Rescind offer handling relies on rescind callbacks for some of the resources cleanup, if they are registered. It does not unregister vmbus device for the primary channel closure, when callback is registered.
Add logic to unregister vmbus for the primary channel in rescind callback to ensure channel removal and relid release, and to ensure rescind flag is false when driver probe happens again.

Fixes ca3cda6fcf1e ("uio_hv_generic: add rescind support")
---
  drivers/hv/vmbus_drv.c       | 1 +
  drivers/uio/uio_hv_generic.c | 7 +++++++
  2 files changed, 8 insertions(+)
drivers/hv/vmbus_drv.c +1 -0
index c857dc3975be..4bae382a3eb4 100644
@@ -1952,6 +1952,7 @@ void vmbus_device_unregister(struct hv_device *device_obj)
  	 */
  	device_unregister(&device_obj->device);
  }
+EXPORT_SYMBOL_GPL(vmbus_device_unregister);
 
  #ifdef CONFIG_ACPI
  /*
drivers/uio/uio_hv_generic.c +0 -0
index c99890c16d29..ea26c0b460d6 100644

drivers/uio/uio_hv_generic.c static void hv_uio_rescind(struct vmbus_channel *channel) · line 130

Quoted 10 lines
drivers/uio/uio_hv_generic.c +7 -0
@@ -121,6 +121,13 @@ static void hv_uio_rescind(struct vmbus_channel *channel)
 
  	/* Wake up reader */
  	uio_event_notify(&pdata->info);
+
+	/*
+	 * With rescind callback registered, rescind path will not unregister the device
+	 * when the primary channel is rescinded. Without it, next onoffer msg does not come.
+	 */
+	if (!channel->primary_channel)
+		vmbus_device_unregister(channel->device_obj);

When the rescind callback is *not* set, vmbus_onoffer_rescind() makes the call to vmbus_device_unregister(). But it does so bracketed with get_device()/ put_device(). Your code here does not do the bracketing. Is there a reason for the difference? Frankly, I'm not sure why vmbus_onoffer_rescind() does the bracketing, and I can't definitively say if it is really needed. So I guess I'm just asking if you know. :-)

Quoted 1 line

Michael

Quoted 7 lines

IMHO, we have already NULL checked channel->device_obj and other couple of things to make sure we are safe to clean this up. At other places as well, I don't see the use of put and get device. So I think its not required. I am open to suggestions.

Regards,
Naman

OK. I'm good with what you've said, and don't have any further suggestions. Go with what your patch already has. :-)

Michael

author
#10 lore raw

Re: [PATCH 2/2] Drivers: hv: vmbus: Fix rescind handling in uio_hv_generic

Quoted 62 lines · Michael Kelley

From: Naman Jain <[email protected]> Sent: Sunday, August 25, 2024 10:32 PM

Quoted 61 lines · Michael Kelley
Quoted 52 lines

From: Naman Jain <[email protected]> Sent: Thursday, August 22, 2024 4:09 AM

Quoted 33 lines

Rescind offer handling relies on rescind callbacks for some of the resources cleanup, if they are registered. It does not unregister vmbus device for the primary channel closure, when callback is registered.
Add logic to unregister vmbus for the primary channel in rescind callback to ensure channel removal and relid release, and to ensure rescind flag is false when driver probe happens again.

Fixes ca3cda6fcf1e ("uio_hv_generic: add rescind support")
---
   drivers/hv/vmbus_drv.c       | 1 +
   drivers/uio/uio_hv_generic.c | 7 +++++++
   2 files changed, 8 insertions(+)
drivers/hv/vmbus_drv.c +1 -0
index c857dc3975be..4bae382a3eb4 100644
@@ -1952,6 +1952,7 @@ void vmbus_device_unregister(struct hv_device *device_obj)
   	 */
   	device_unregister(&device_obj->device);
   }
+EXPORT_SYMBOL_GPL(vmbus_device_unregister);
 
   #ifdef CONFIG_ACPI
   /*
drivers/uio/uio_hv_generic.c +0 -0
index c99890c16d29..ea26c0b460d6 100644

drivers/uio/uio_hv_generic.c static void hv_uio_rescind(struct vmbus_channel *channel) · line 130

Quoted 10 lines
drivers/uio/uio_hv_generic.c +7 -0
@@ -121,6 +121,13 @@ static void hv_uio_rescind(struct vmbus_channel *channel)
 
   	/* Wake up reader */
   	uio_event_notify(&pdata->info);
+
+	/*
+	 * With rescind callback registered, rescind path will not unregister the device
+	 * when the primary channel is rescinded. Without it, next onoffer msg does not come.
+	 */
+	if (!channel->primary_channel)
+		vmbus_device_unregister(channel->device_obj);

When the rescind callback is *not* set, vmbus_onoffer_rescind() makes the call to vmbus_device_unregister(). But it does so bracketed with get_device()/ put_device(). Your code here does not do the bracketing. Is there a reason for the difference? Frankly, I'm not sure why vmbus_onoffer_rescind() does the bracketing, and I can't definitively say if it is really needed. So I guess I'm just asking if you know. :-)

Quoted 1 line

Michael

IMHO, we have already NULL checked channel->device_obj and other couple of things to make sure we are safe to clean this up. At other places as well, I don't see the use of put and get device. So I think its not required. I am open to suggestions.

Quoted 7 lines
Quoted 2 lines

Regards,
Naman

OK. I'm good with what you've said, and don't have any further suggestions. Go with what your patch already has. :-)

Michael

Thank you Michael. I'll wait for some time before posting v2, if there are any more review comments.

Regards,
Naman

#11 lore raw

Re: [PATCH 2/2] Drivers: hv: vmbus: Fix rescind handling in uio_hv_generic

In reply to Michael Kelley
Quoted 62 lines · Michael Kelley

From: Naman Jain <[email protected]> Sent: Sunday, August 25, 2024 10:32 PM

Quoted 61 lines · Michael Kelley
Quoted 52 lines

From: Naman Jain <[email protected]> Sent: Thursday, August 22, 2024 4:09 AM

Quoted 33 lines

Rescind offer handling relies on rescind callbacks for some of the resources cleanup, if they are registered. It does not unregister vmbus device for the primary channel closure, when callback is registered.
Add logic to unregister vmbus for the primary channel in rescind callback to ensure channel removal and relid release, and to ensure rescind flag is false when driver probe happens again.

Fixes ca3cda6fcf1e ("uio_hv_generic: add rescind support")
---
  drivers/hv/vmbus_drv.c       | 1 +
  drivers/uio/uio_hv_generic.c | 7 +++++++
  2 files changed, 8 insertions(+)
drivers/hv/vmbus_drv.c +1 -0
index c857dc3975be..4bae382a3eb4 100644
@@ -1952,6 +1952,7 @@ void vmbus_device_unregister(struct hv_device *device_obj)
  	 */
  	device_unregister(&device_obj->device);
  }
+EXPORT_SYMBOL_GPL(vmbus_device_unregister);
 
  #ifdef CONFIG_ACPI
  /*
drivers/uio/uio_hv_generic.c +0 -0
index c99890c16d29..ea26c0b460d6 100644

drivers/uio/uio_hv_generic.c static void hv_uio_rescind(struct vmbus_channel *channel) · line 130

Quoted 10 lines
drivers/uio/uio_hv_generic.c +7 -0
@@ -121,6 +121,13 @@ static void hv_uio_rescind(struct vmbus_channel *channel)
 
  	/* Wake up reader */
  	uio_event_notify(&pdata->info);
+
+	/*
+	 * With rescind callback registered, rescind path will not unregister the device
+	 * when the primary channel is rescinded. Without it, next onoffer msg does not come.
+	 */
+	if (!channel->primary_channel)
+		vmbus_device_unregister(channel->device_obj);

When the rescind callback is *not* set, vmbus_onoffer_rescind() makes the call to vmbus_device_unregister(). But it does so bracketed with get_device()/ put_device(). Your code here does not do the bracketing. Is there a reason for the difference? Frankly, I'm not sure why vmbus_onoffer_rescind() does the bracketing, and I can't definitively say if it is really needed. So I guess I'm just asking if you know. :-)

Quoted 1 line

Michael

IMHO, we have already NULL checked channel->device_obj and other couple of things to make sure we are safe to clean this up. At other places as well, I don't see the use of put and get device. So I think its not required. I am open to suggestions.

Quoted 7 lines
Quoted 2 lines

Regards,
Naman

OK. I'm good with what you've said, and don't have any further suggestions. Go with what your patch already has. :-)

Michael

Michael,

If we look at vmbus_onoffer_rescind function, hv_uio_rescind can only be called if channel->device_obj is not NULL. By this if we conclude that hv_uio_rescind can never be called for secondary channel I think we can simplify hv_uio_rescind only for primary channel.

In the first patch of this series, instead of this:
+ struct hv_device *hv_dev = channel->primary_channel ?
+ channel->primary_channel->device_obj : channel->device_obj;

We can only have

+ struct hv_device *hv_dev = channel->device_obj;

In second patch, instead of this:
+ if (!channel->primary_channel)
+ vmbus_device_unregister(channel->device_obj);

We can only have:
+ vmbus_device_unregister(channel->device_obj);

Possibly WARN for secondary channel is also not required as that will never happen ?

- Saurabh

#12 lore raw

RE: [PATCH 2/2] Drivers: hv: vmbus: Fix rescind handling in uio_hv_generic

From: Saurabh Singh Sengar <[email protected]> Sent: Tuesday, August 27, 2024 11:24 AM

Quoted 87 lines · Michael Kelley
Quoted 62 lines

From: Naman Jain <[email protected]> Sent: Sunday, August 25, 2024 10:32 PM

Quoted 61 lines · Michael Kelley
Quoted 52 lines

From: Naman Jain <[email protected]> Sent: Thursday, August 22, 2024 4:09 AM

Quoted 33 lines

Rescind offer handling relies on rescind callbacks for some of the resources cleanup, if they are registered. It does not unregister vmbus device for the primary channel closure, when callback is registered.
Add logic to unregister vmbus for the primary channel in rescind callback to ensure channel removal and relid release, and to ensure rescind flag is false when driver probe happens again.

Fixes ca3cda6fcf1e ("uio_hv_generic: add rescind support")
---
  drivers/hv/vmbus_drv.c       | 1 +
  drivers/uio/uio_hv_generic.c | 7 +++++++
  2 files changed, 8 insertions(+)
drivers/hv/vmbus_drv.c +1 -0
index c857dc3975be..4bae382a3eb4 100644
@@ -1952,6 +1952,7 @@ void vmbus_device_unregister(struct hv_device *device_obj)
  	 */
  	device_unregister(&device_obj->device);
  }
+EXPORT_SYMBOL_GPL(vmbus_device_unregister);
 
  #ifdef CONFIG_ACPI
  /*
drivers/uio/uio_hv_generic.c +0 -0
index c99890c16d29..ea26c0b460d6 100644

drivers/uio/uio_hv_generic.c static void hv_uio_rescind(struct vmbus_channel *channel) · line 130

Quoted 10 lines
drivers/uio/uio_hv_generic.c +7 -0
@@ -121,6 +121,13 @@ static void hv_uio_rescind(struct vmbus_channel *channel)
 
  	/* Wake up reader */
  	uio_event_notify(&pdata->info);
+
+	/*
+	 * With rescind callback registered, rescind path will not unregister the device
+	 * when the primary channel is rescinded. Without it, next onoffer msg does not come.
+	 */
+	if (!channel->primary_channel)
+		vmbus_device_unregister(channel->device_obj);

When the rescind callback is *not* set, vmbus_onoffer_rescind() makes the call to vmbus_device_unregister(). But it does so bracketed with get_device()/ put_device(). Your code here does not do the bracketing. Is there a reason for the difference? Frankly, I'm not sure why vmbus_onoffer_rescind() does the bracketing, and I can't definitively say if it is really needed. So I guess I'm just asking if you know. :-)

Quoted 1 line

Michael

IMHO, we have already NULL checked channel->device_obj and other couple of things to make sure we are safe to clean this up. At other places as well, I don't see the use of put and get device. So I think its not required. I am open to suggestions.

Quoted 7 lines
Quoted 2 lines

Regards,
Naman

OK. I'm good with what you've said, and don't have any further suggestions. Go with what your patch already has. :-)

Michael

Michael,

If we look at vmbus_onoffer_rescind function, hv_uio_rescind can only be called if channel->device_obj is not NULL. By this if we conclude that hv_uio_rescind can never be called for secondary channel I think we can simplify hv_uio_rescind only for primary channel.

In the first patch of this series, instead of this:

(quoted diff) +2 -0
+	struct hv_device *hv_dev = channel->primary_channel ?
+				   channel->primary_channel->device_obj : channel->device_obj;

We can only have

Review

Quoted 1 line
(quoted diff) +1 -0
+	struct hv_device *hv_dev = channel->device_obj;

Agreed. That was the intent of my previous comments on the first patch.

Quoted 8 lines

In second patch, instead of this:

drivers/uio/uio_hv_generic.c +2 -0
+        if (!channel->primary_channel)
+                vmbus_device_unregister(channel->device_obj);

We can only have:
+ vmbus_device_unregister(channel->device_obj);

Agreed.

Quoted 3 lines

Possibly WARN for secondary channel is also not required as that will never happen ?

Agreed -- the WARN is optional. I'm OK with leaving it out. But please leave a comment in both places that the function is only called for the primary channel, so it's not necessary to do any checking of the primary_channel field. Future readers of the code will thank you. :-)

Michael

Quoted 2 lines

- Saurabh