* [PATCH] Drivers: hv: Do not free synic pages when they were not allocated
@ 2023-04-03 23:22 Nuno Das Neves
2023-04-04 10:39 ` Jinank Jain
2023-04-07 15:22 ` Michael Kelley (LINUX)
0 siblings, 2 replies; 3+ messages in thread
From: Nuno Das Neves @ 2023-04-03 23:22 UTC (permalink / raw)
To: linux-hyperv, linux-kernel; +Cc: mikelley, kys, wei.liu, haiyangz, decui
In case of root partition or snp, the synic pages are allocated by the
hypervisor instead of the kernel, so they should not be freed.
Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
---
drivers/hv/hv.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
index c7f7652932ca..a10cf642c9ad 100644
--- a/drivers/hv/hv.c
+++ b/drivers/hv/hv.c
@@ -193,8 +193,10 @@ void hv_synic_free(void)
struct hv_per_cpu_context *hv_cpu
= per_cpu_ptr(hv_context.cpu_context, cpu);
- free_page((unsigned long)hv_cpu->synic_event_page);
- free_page((unsigned long)hv_cpu->synic_message_page);
+ if (!hv_isolation_type_snp() && !hv_root_partition) {
+ free_page((unsigned long)hv_cpu->synic_event_page);
+ free_page((unsigned long)hv_cpu->synic_message_page);
+ }
free_page((unsigned long)hv_cpu->post_msg_page);
}
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Drivers: hv: Do not free synic pages when they were not allocated
2023-04-03 23:22 [PATCH] Drivers: hv: Do not free synic pages when they were not allocated Nuno Das Neves
@ 2023-04-04 10:39 ` Jinank Jain
2023-04-07 15:22 ` Michael Kelley (LINUX)
1 sibling, 0 replies; 3+ messages in thread
From: Jinank Jain @ 2023-04-04 10:39 UTC (permalink / raw)
To: Nuno Das Neves, linux-hyperv, linux-kernel
Cc: mikelley, kys, wei.liu, haiyangz, decui
Reviewed-by: Jinank Jain <jinankjain@linux.microsoft.com>
On 4/4/2023 4:52 AM, Nuno Das Neves wrote:
> In case of root partition or snp, the synic pages are allocated by the
> hypervisor instead of the kernel, so they should not be freed.
>
> Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
> ---
> drivers/hv/hv.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
> index c7f7652932ca..a10cf642c9ad 100644
> --- a/drivers/hv/hv.c
> +++ b/drivers/hv/hv.c
> @@ -193,8 +193,10 @@ void hv_synic_free(void)
> struct hv_per_cpu_context *hv_cpu
> = per_cpu_ptr(hv_context.cpu_context, cpu);
>
> - free_page((unsigned long)hv_cpu->synic_event_page);
> - free_page((unsigned long)hv_cpu->synic_message_page);
> + if (!hv_isolation_type_snp() && !hv_root_partition) {
> + free_page((unsigned long)hv_cpu->synic_event_page);
> + free_page((unsigned long)hv_cpu->synic_message_page);
> + }
> free_page((unsigned long)hv_cpu->post_msg_page);
> }
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [PATCH] Drivers: hv: Do not free synic pages when they were not allocated
2023-04-03 23:22 [PATCH] Drivers: hv: Do not free synic pages when they were not allocated Nuno Das Neves
2023-04-04 10:39 ` Jinank Jain
@ 2023-04-07 15:22 ` Michael Kelley (LINUX)
1 sibling, 0 replies; 3+ messages in thread
From: Michael Kelley (LINUX) @ 2023-04-07 15:22 UTC (permalink / raw)
To: Nuno Das Neves, linux-hyperv@vger.kernel.org,
linux-kernel@vger.kernel.org
Cc: KY Srinivasan, wei.liu@kernel.org, Haiyang Zhang, Dexuan Cui
From: Nuno Das Neves <nunodasneves@linux.microsoft.com> Sent: Monday, April 3, 2023 4:22 PM
>
> In case of root partition or snp, the synic pages are allocated by the
> hypervisor instead of the kernel, so they should not be freed.
This patch doesn't hurt anything, but is it really needed? In the SNP
Isolation or root partition case, after hv_synic_alloc() has run, the
synic_event_page and synic_message_page pointers are NULL. Then
when hv_synic_enable_regs() is run by a particular CPU, that CPU
maps the pages and the pointers are non-NULL. But the corresponding
hv_synic_disable_regs() sets the pointers back to NULL, so
hv_synic_free() will already skip those pages.
Is there ever a case where hv_synic_free() would run after a CPU
has done hv_synic_enable_regs(), but not hv_synic_disable_regs()?
If that were the case, it seems like we would have other problems,
such as missing calls to iounmap().
Michael
>
> Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
> ---
> drivers/hv/hv.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
> index c7f7652932ca..a10cf642c9ad 100644
> --- a/drivers/hv/hv.c
> +++ b/drivers/hv/hv.c
> @@ -193,8 +193,10 @@ void hv_synic_free(void)
> struct hv_per_cpu_context *hv_cpu
> = per_cpu_ptr(hv_context.cpu_context, cpu);
>
> - free_page((unsigned long)hv_cpu->synic_event_page);
> - free_page((unsigned long)hv_cpu->synic_message_page);
> + if (!hv_isolation_type_snp() && !hv_root_partition) {
> + free_page((unsigned long)hv_cpu->synic_event_page);
> + free_page((unsigned long)hv_cpu->synic_message_page);
> + }
> free_page((unsigned long)hv_cpu->post_msg_page);
> }
>
> --
> 2.25.1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-04-07 15:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-03 23:22 [PATCH] Drivers: hv: Do not free synic pages when they were not allocated Nuno Das Neves
2023-04-04 10:39 ` Jinank Jain
2023-04-07 15:22 ` Michael Kelley (LINUX)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).