All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Drivers: hv: vmbus: Call hv_synic_free() if hv_synic_alloc() fails
@ 2023-05-04 22:41 Dexuan Cui
  2023-05-06  0:29 ` Michael Kelley (LINUX)
  0 siblings, 1 reply; 4+ messages in thread
From: Dexuan Cui @ 2023-05-04 22:41 UTC (permalink / raw)
  To: kys, haiyangz, wei.liu, linux-hyperv, mikelley
  Cc: linux-kernel, Dexuan Cui, stable

Commit 572086325ce9 ("Drivers: hv: vmbus: Cleanup synic memory free path")
says "Any memory allocations that succeeded will be freed when the caller
cleans up by calling hv_synic_free()", but if the get_zeroed_page() in
hv_synic_alloc() fails, currently hv_synic_free() is not really called
in vmbus_bus_init(), consequently there will be a memory lead, e.g.
hv_context.hv_numa_map is not freed in the error path. Fix this by
updating the goto lables.

Cc: stable@kernel.org
Signed-off-by: Dexuan Cui <decui@microsoft.com>
---
 drivers/hv/vmbus_drv.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 59eb5fad12e7..c41e6ad0cf64 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -1525,7 +1525,7 @@ static int vmbus_bus_init(void)
 	ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "hyperv/vmbus:online",
 				hv_synic_init, hv_synic_cleanup);
 	if (ret < 0)
-		goto err_cpuhp;
+		goto err_alloc;
 	hyperv_cpuhp_online = ret;
 
 	ret = vmbus_connect();
@@ -1577,9 +1577,8 @@ static int vmbus_bus_init(void)
 
 err_connect:
 	cpuhp_remove_state(hyperv_cpuhp_online);
-err_cpuhp:
-	hv_synic_free();
 err_alloc:
+	hv_synic_free();
 	if (vmbus_irq == -1) {
 		hv_remove_vmbus_handler();
 	} else {
-- 
2.25.1


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

* RE: [PATCH] Drivers: hv: vmbus: Call hv_synic_free() if hv_synic_alloc() fails
  2023-05-04 22:41 [PATCH] Drivers: hv: vmbus: Call hv_synic_free() if hv_synic_alloc() fails Dexuan Cui
@ 2023-05-06  0:29 ` Michael Kelley (LINUX)
  2023-05-06  2:38   ` Dexuan Cui
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Kelley (LINUX) @ 2023-05-06  0:29 UTC (permalink / raw)
  To: Dexuan Cui, KY Srinivasan, Haiyang Zhang, wei.liu, linux-hyperv
  Cc: linux-kernel, stable

From: Dexuan Cui <decui@microsoft.com> Sent: Thursday, May 4, 2023 3:42 PM
> 
> Commit 572086325ce9 ("Drivers: hv: vmbus: Cleanup synic memory free path")
> says "Any memory allocations that succeeded will be freed when the caller
> cleans up by calling hv_synic_free()", but if the get_zeroed_page() in
> hv_synic_alloc() fails, currently hv_synic_free() is not really called
> in vmbus_bus_init(), consequently there will be a memory lead, e.g.

s/lead/leak/

> hv_context.hv_numa_map is not freed in the error path. Fix this by
> updating the goto lables.

s/lables/labels/

The statement in commit 572086325ce9 was true at the time of that
commit.  But I broke things in commit 4df4cb9e99f8.  Should add a
"Fixes:" tag for 4df4cb9e99f8.

> 
> Cc: stable@kernel.org
> Signed-off-by: Dexuan Cui <decui@microsoft.com>
> ---
>  drivers/hv/vmbus_drv.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
> index 59eb5fad12e7..c41e6ad0cf64 100644
> --- a/drivers/hv/vmbus_drv.c
> +++ b/drivers/hv/vmbus_drv.c
> @@ -1525,7 +1525,7 @@ static int vmbus_bus_init(void)
>  	ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "hyperv/vmbus:online",
>  				hv_synic_init, hv_synic_cleanup);
>  	if (ret < 0)
> -		goto err_cpuhp;
> +		goto err_alloc;
>  	hyperv_cpuhp_online = ret;
> 
>  	ret = vmbus_connect();
> @@ -1577,9 +1577,8 @@ static int vmbus_bus_init(void)
> 
>  err_connect:
>  	cpuhp_remove_state(hyperv_cpuhp_online);
> -err_cpuhp:
> -	hv_synic_free();
>  err_alloc:
> +	hv_synic_free();
>  	if (vmbus_irq == -1) {
>  		hv_remove_vmbus_handler();
>  	} else {
> --
> 2.25.1

Nits notwithstanding,

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


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

* RE: [PATCH] Drivers: hv: vmbus: Call hv_synic_free() if hv_synic_alloc() fails
  2023-05-06  0:29 ` Michael Kelley (LINUX)
@ 2023-05-06  2:38   ` Dexuan Cui
  2023-05-08 17:38     ` Wei Liu
  0 siblings, 1 reply; 4+ messages in thread
From: Dexuan Cui @ 2023-05-06  2:38 UTC (permalink / raw)
  To: Michael Kelley (LINUX),
	KY Srinivasan, Haiyang Zhang, wei.liu, linux-hyperv
  Cc: linux-kernel, stable

> From: Michael Kelley (LINUX) <mikelley@microsoft.com>
> Sent: Friday, May 5, 2023 5:30 PM
> ...
> From: Dexuan Cui <decui@microsoft.com> Sent: Thursday, May 4, 2023 3:42
> PM
> >
> > Commit 572086325ce9 ("Drivers: hv: vmbus: Cleanup synic memory free
> > path")
> > says "Any memory allocations that succeeded will be freed when the caller
> > cleans up by calling hv_synic_free()", but if the get_zeroed_page() in
> > hv_synic_alloc() fails, currently hv_synic_free() is not really called
> > in vmbus_bus_init(), consequently there will be a memory lead, e.g.
> 
> s/lead/leak/

Sorry for the typo. Wei, can you please help fix this?
 
> > hv_context.hv_numa_map is not freed in the error path. Fix this by
> > updating the goto lables.
> 
> s/lables/labels/
Ditto.
 
> The statement in commit 572086325ce9 was true at the time of that
> commit.  But I broke things in commit 4df4cb9e99f8.  Should add a
> "Fixes:" tag for 4df4cb9e99f8.

I suppose Wei can help add the line:
Fixes: 4df4cb9e99f8 ("x86/hyperv: Initialize clockevents earlier in CPU onlining")

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

Thanks!

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

* Re: [PATCH] Drivers: hv: vmbus: Call hv_synic_free() if hv_synic_alloc() fails
  2023-05-06  2:38   ` Dexuan Cui
@ 2023-05-08 17:38     ` Wei Liu
  0 siblings, 0 replies; 4+ messages in thread
From: Wei Liu @ 2023-05-08 17:38 UTC (permalink / raw)
  To: Dexuan Cui
  Cc: Michael Kelley (LINUX),
	KY Srinivasan, Haiyang Zhang, wei.liu, linux-hyperv,
	linux-kernel, stable

On Sat, May 06, 2023 at 02:38:04AM +0000, Dexuan Cui wrote:
> > From: Michael Kelley (LINUX) <mikelley@microsoft.com>
> > Sent: Friday, May 5, 2023 5:30 PM
> > ...
> > From: Dexuan Cui <decui@microsoft.com> Sent: Thursday, May 4, 2023 3:42
> > PM
> > >
> > > Commit 572086325ce9 ("Drivers: hv: vmbus: Cleanup synic memory free
> > > path")
> > > says "Any memory allocations that succeeded will be freed when the caller
> > > cleans up by calling hv_synic_free()", but if the get_zeroed_page() in
> > > hv_synic_alloc() fails, currently hv_synic_free() is not really called
> > > in vmbus_bus_init(), consequently there will be a memory lead, e.g.
> > 
> > s/lead/leak/
> 
> Sorry for the typo. Wei, can you please help fix this?
>  
> > > hv_context.hv_numa_map is not freed in the error path. Fix this by
> > > updating the goto lables.
> > 
> > s/lables/labels/
> Ditto.
>  
> > The statement in commit 572086325ce9 was true at the time of that
> > commit.  But I broke things in commit 4df4cb9e99f8.  Should add a
> > "Fixes:" tag for 4df4cb9e99f8.
> 
> I suppose Wei can help add the line:
> Fixes: 4df4cb9e99f8 ("x86/hyperv: Initialize clockevents earlier in CPU onlining")
> 
> > Nits notwithstanding,
> > 
> > Reviewed-by: Michael Kelley <mikelley@microsoft.com>

Applied to hyperv-fixes. Thanks.

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

end of thread, other threads:[~2023-05-08 17:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-04 22:41 [PATCH] Drivers: hv: vmbus: Call hv_synic_free() if hv_synic_alloc() fails Dexuan Cui
2023-05-06  0:29 ` Michael Kelley (LINUX)
2023-05-06  2:38   ` Dexuan Cui
2023-05-08 17:38     ` 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.