Drivers: hv: Fix bad ref to hv_synic_eventring_tail when CPU goes offline
Subsystems (2)
PATCH 1/1 Drivers: hv: Fix bad ref to hv_synic_eventring_tail when CPU goes offline
From: Michael Kelley <[email protected]>
When a CPU goes offline, hv_common_cpu_die() frees the hv_synic_eventring_tail memory for the CPU. But in a normal VM (i.e., not running in the root partition) the per-CPU memory has not been allocated, resulting in a bad memory reference and oops when computing the argument to kfree().
Fix this by freeing the memory only when running in the root partition.
--- drivers/hv/hv_common.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/hv/hv_common.c +5 -3
@@ -566,9 +566,11 @@ int hv_common_cpu_die(unsigned int cpu)* originally allocated memory is reused in hv_common_cpu_init(). */ - synic_eventring_tail =this_cpu_ptr (hv_synic_eventring_tail); -kfree (*synic_eventring_tail); - *synic_eventring_tail =NULL ; +if (hv_root_partition ()) { + synic_eventring_tail =this_cpu_ptr (hv_synic_eventring_tail); +kfree (*synic_eventring_tail); + *synic_eventring_tail =NULL ; + }return 0 ; }
Signature · 1 line
2.25.1
Quoted 25 lines · On 4/21/2025 9:31 AM, [email protected] wrote:
From: Michael Kelley <[email protected]>
When a CPU goes offline,
hv_common_cpu_die()frees thehv_synic_eventring_tailmemory for the CPU. But in a normal VM (i.e., not running in the root partition) the per-CPU memory has not been allocated, resulting in a bad memory reference and oops when computing the argument tokfree().Fix this by freeing the memory only when running in the root partition.
Fixes 04df7ac39943 ("Drivers: hv: Introduce per-cpu event ring tail")Signed-off-by Michael Kelley <[email protected]>--- drivers/hv/hv_common.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)drivers/hv/hv_common.c +0
-1@@ -566,9 +566,11 @@ int hv_common_cpu_die(unsigned int cpu)* originally allocated memory is reused in hv_common_cpu_init(). */ - synic_eventring_tail =this_cpu_ptr (hv_synic_eventring_tail);
drivers/hv/hv_common.c int hv_common_cpu_die(unsigned int cpu) · line 576
Quoted 10 lines
drivers/hv/hv_common.c +5
-2-kfree (*synic_eventring_tail); - *synic_eventring_tail =NULL ; +if (hv_root_partition ()) { + synic_eventring_tail =this_cpu_ptr (hv_synic_eventring_tail); +kfree (*synic_eventring_tail); + *synic_eventring_tail =NULL ; + }return 0 ; }
Quoted 34 lines · Nuno Das Neves
Quoted 33 lines · On 4/21/2025 9:31 AM, [email protected] wrote:
From: Michael Kelley <[email protected]>
When a CPU goes offline,
hv_common_cpu_die()frees thehv_synic_eventring_tailmemory for the CPU. But in a normal VM (i.e., not running in the root partition) the per-CPU memory has not been allocated, resulting in a bad memory reference and oops when computing the argument tokfree().Fix this by freeing the memory only when running in the root partition.
Fixes 04df7ac39943 ("Drivers: hv: Introduce per-cpu event ring tail")Signed-off-by Michael Kelley <[email protected]>--- drivers/hv/hv_common.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)drivers/hv/hv_common.c +5
-3@@ -566,9 +566,11 @@ int hv_common_cpu_die(unsigned int cpu)* originally allocated memory is reused in hv_common_cpu_init(). */ - synic_eventring_tail =this_cpu_ptr (hv_synic_eventring_tail); -kfree (*synic_eventring_tail); - *synic_eventring_tail =NULL ; +if (hv_root_partition ()) { + synic_eventring_tail =this_cpu_ptr (hv_synic_eventring_tail); +kfree (*synic_eventring_tail); + *synic_eventring_tail =NULL ; + }
Quoted 4 lines
drivers/hv/hv_common.c int hv_common_cpu_die(unsigned int cpu) · line 576
Quoted 2 lines
drivers/hv/hv_common.c +0
-0return 0 ; }Reviewed-by Nuno Das Neves <[email protected]>
Applied to hyperv-fixes.