All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] hv_balloon: Fix balloon_probe() and balloon_remove() error handling
@ 2022-05-16  4:50 Shradha Gupta
  2022-05-24  0:29 ` Michael Kelley (LINUX)
  0 siblings, 1 reply; 3+ messages in thread
From: Shradha Gupta @ 2022-05-16  4:50 UTC (permalink / raw)
  To: linux-hyperv, linux-kernel, K. Y. Srinivasan, Haiyang Zhang,
	Stephen Hemminger, Wei Liu, Dexuan Cui

Add missing cleanup in balloon_probe() if the call to
balloon_connect_vsp() fails.  Also correctly handle cleanup in
balloon_remove() when dm_state is DM_INIT_ERROR because
balloon_resume() failed.

Signed-off-by: Shradha Gupta <shradhagupta@microsoft.com>

---

Changes in v2:
* Use a goto instead of inline code to handle the cleanup
   in balloon_probe()
* Add a comment in balloon_remove() explaining the
   cleanup scenario
* Add missing disable of page reporting when resume
   from hibernation fails

---
 drivers/hv/hv_balloon.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
index eee7402cfc02..98fcfb516bbc 100644
--- a/drivers/hv/hv_balloon.c
+++ b/drivers/hv/hv_balloon.c
@@ -1842,7 +1842,7 @@ static int balloon_probe(struct hv_device *dev,
 
 	ret = balloon_connect_vsp(dev);
 	if (ret != 0)
-		return ret;
+		goto connect_error;
 
 	enable_page_reporting();
 	dm_device.state = DM_INITIALIZED;
@@ -1861,6 +1861,7 @@ static int balloon_probe(struct hv_device *dev,
 	dm_device.thread  = NULL;
 	disable_page_reporting();
 	vmbus_close(dev->channel);
+connect_error:
 #ifdef CONFIG_MEMORY_HOTPLUG
 	unregister_memory_notifier(&hv_memory_nb);
 	restore_online_page_callback(&hv_online_page);
@@ -1882,12 +1883,21 @@ static int balloon_remove(struct hv_device *dev)
 	cancel_work_sync(&dm->ha_wrk.wrk);
 
 	kthread_stop(dm->thread);
-	disable_page_reporting();
-	vmbus_close(dev->channel);
+
+	/*
+	 * This is to handle the case when balloon_resume()
+	 * call has failed and some cleanup has been done as
+	 * a part of the error handling.
+	 */
+	if (dm_device.state != DM_INIT_ERROR) {
+		disable_page_reporting();
+		vmbus_close(dev->channel);
 #ifdef CONFIG_MEMORY_HOTPLUG
-	unregister_memory_notifier(&hv_memory_nb);
-	restore_online_page_callback(&hv_online_page);
+		unregister_memory_notifier(&hv_memory_nb);
+		restore_online_page_callback(&hv_online_page);
 #endif
+	}
+
 	spin_lock_irqsave(&dm_device.ha_lock, flags);
 	list_for_each_entry_safe(has, tmp, &dm->ha_region_list, list) {
 		list_for_each_entry_safe(gap, tmp_gap, &has->gap_list, list) {
@@ -1948,6 +1958,7 @@ static int balloon_resume(struct hv_device *dev)
 	vmbus_close(dev->channel);
 out:
 	dm_device.state = DM_INIT_ERROR;
+	disable_page_reporting();
 #ifdef CONFIG_MEMORY_HOTPLUG
 	unregister_memory_notifier(&hv_memory_nb);
 	restore_online_page_callback(&hv_online_page);
-- 
2.17.1


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

* RE: [PATCH v2] hv_balloon: Fix balloon_probe() and balloon_remove() error handling
  2022-05-16  4:50 [PATCH v2] hv_balloon: Fix balloon_probe() and balloon_remove() error handling Shradha Gupta
@ 2022-05-24  0:29 ` Michael Kelley (LINUX)
  2022-05-26 10:05   ` Wei Liu
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Kelley (LINUX) @ 2022-05-24  0:29 UTC (permalink / raw)
  To: Shradha Gupta, linux-hyperv, linux-kernel, KY Srinivasan,
	Haiyang Zhang, Stephen Hemminger, Wei Liu, Dexuan Cui

From: Shradha Gupta <shradhagupta@linux.microsoft.com>
> 
> Add missing cleanup in balloon_probe() if the call to
> balloon_connect_vsp() fails.  Also correctly handle cleanup in
> balloon_remove() when dm_state is DM_INIT_ERROR because
> balloon_resume() failed.
> 
> Signed-off-by: Shradha Gupta <shradhagupta@microsoft.com>
> 
> ---
> 
> Changes in v2:
> * Use a goto instead of inline code to handle the cleanup
>    in balloon_probe()
> * Add a comment in balloon_remove() explaining the
>    cleanup scenario
> * Add missing disable of page reporting when resume
>    from hibernation fails
> 
> ---
>  drivers/hv/hv_balloon.c | 21 ++++++++++++++++-----
>  1 file changed, 16 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
> index eee7402cfc02..98fcfb516bbc 100644
> --- a/drivers/hv/hv_balloon.c
> +++ b/drivers/hv/hv_balloon.c
> @@ -1842,7 +1842,7 @@ static int balloon_probe(struct hv_device *dev,
> 
>  	ret = balloon_connect_vsp(dev);
>  	if (ret != 0)
> -		return ret;
> +		goto connect_error;
> 
>  	enable_page_reporting();
>  	dm_device.state = DM_INITIALIZED;
> @@ -1861,6 +1861,7 @@ static int balloon_probe(struct hv_device *dev,
>  	dm_device.thread  = NULL;
>  	disable_page_reporting();
>  	vmbus_close(dev->channel);
> +connect_error:
>  #ifdef CONFIG_MEMORY_HOTPLUG
>  	unregister_memory_notifier(&hv_memory_nb);
>  	restore_online_page_callback(&hv_online_page);
> @@ -1882,12 +1883,21 @@ static int balloon_remove(struct hv_device *dev)
>  	cancel_work_sync(&dm->ha_wrk.wrk);
> 
>  	kthread_stop(dm->thread);
> -	disable_page_reporting();
> -	vmbus_close(dev->channel);
> +
> +	/*
> +	 * This is to handle the case when balloon_resume()
> +	 * call has failed and some cleanup has been done as
> +	 * a part of the error handling.
> +	 */
> +	if (dm_device.state != DM_INIT_ERROR) {
> +		disable_page_reporting();
> +		vmbus_close(dev->channel);
>  #ifdef CONFIG_MEMORY_HOTPLUG
> -	unregister_memory_notifier(&hv_memory_nb);
> -	restore_online_page_callback(&hv_online_page);
> +		unregister_memory_notifier(&hv_memory_nb);
> +		restore_online_page_callback(&hv_online_page);
>  #endif
> +	}
> +
>  	spin_lock_irqsave(&dm_device.ha_lock, flags);
>  	list_for_each_entry_safe(has, tmp, &dm->ha_region_list, list) {
>  		list_for_each_entry_safe(gap, tmp_gap, &has->gap_list, list) {
> @@ -1948,6 +1958,7 @@ static int balloon_resume(struct hv_device *dev)
>  	vmbus_close(dev->channel);
>  out:
>  	dm_device.state = DM_INIT_ERROR;
> +	disable_page_reporting();
>  #ifdef CONFIG_MEMORY_HOTPLUG
>  	unregister_memory_notifier(&hv_memory_nb);
>  	restore_online_page_callback(&hv_online_page);
> --
> 2.17.1

Reviewed-by: Michael Kelley <mikelley@microsoft.com>


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

* Re: [PATCH v2] hv_balloon: Fix balloon_probe() and balloon_remove() error handling
  2022-05-24  0:29 ` Michael Kelley (LINUX)
@ 2022-05-26 10:05   ` Wei Liu
  0 siblings, 0 replies; 3+ messages in thread
From: Wei Liu @ 2022-05-26 10:05 UTC (permalink / raw)
  To: Michael Kelley (LINUX)
  Cc: Shradha Gupta, linux-hyperv, linux-kernel, KY Srinivasan,
	Haiyang Zhang, Stephen Hemminger, Wei Liu, Dexuan Cui

On Tue, May 24, 2022 at 12:29:18AM +0000, Michael Kelley (LINUX) wrote:
> From: Shradha Gupta <shradhagupta@linux.microsoft.com>
> > 
> > Add missing cleanup in balloon_probe() if the call to
> > balloon_connect_vsp() fails.  Also correctly handle cleanup in
> > balloon_remove() when dm_state is DM_INIT_ERROR because
> > balloon_resume() failed.
> > 
> > Signed-off-by: Shradha Gupta <shradhagupta@microsoft.com>
> > 
[...]
> > --
> > 2.17.1
> 
> Reviewed-by: Michael Kelley <mikelley@microsoft.com>
> 

Applied to hyperv-next. Thanks.

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

end of thread, other threads:[~2022-05-26 10:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-16  4:50 [PATCH v2] hv_balloon: Fix balloon_probe() and balloon_remove() error handling Shradha Gupta
2022-05-24  0:29 ` Michael Kelley (LINUX)
2022-05-26 10:05   ` Wei Liu

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.