* [PATCH v6 1/5] hyperv: Define struct hv_output_get_vp_registers
2025-01-08 22:21 [PATCH v6 0/5] hyperv: Fixes for get_vtl(), hv_vtl_apicid_to_vp_id() Roman Kisel
@ 2025-01-08 22:21 ` Roman Kisel
2025-01-08 23:25 ` Nuno Das Neves
2025-01-08 22:21 ` [PATCH v6 2/5] hyperv: Fix pointer type in get_vtl(void) Roman Kisel
` (4 subsequent siblings)
5 siblings, 1 reply; 18+ messages in thread
From: Roman Kisel @ 2025-01-08 22:21 UTC (permalink / raw)
To: hpa, kys, bp, dave.hansen, decui, eahariha, haiyangz, mingo,
mhklinux, nunodasneves, tglx, tiala, wei.liu, linux-hyperv,
linux-kernel, x86
Cc: apais, benhill, ssengar, sunilmut, vdso
There is no definition of the output structure for the
GetVpRegisters hypercall. Hence, using the hypercall
is not possible when the output value has some structure
to it. Even getting a datum of a primitive type reads
as ad-hoc without that definition.
Define struct hv_output_get_vp_registers to enable using
the GetVpRegisters hypercall. Make provisions for all
supported architectures. No functional changes.
Signed-off-by: Roman Kisel <romank@linux.microsoft.com>
---
include/hyperv/hvgdk_mini.h | 41 +++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/include/hyperv/hvgdk_mini.h b/include/hyperv/hvgdk_mini.h
index db3d1aaf7330..4fffca9e16df 100644
--- a/include/hyperv/hvgdk_mini.h
+++ b/include/hyperv/hvgdk_mini.h
@@ -1068,6 +1068,35 @@ union hv_dispatch_suspend_register {
} __packed;
};
+union hv_arm64_pending_interruption_register {
+ u64 as_uint64;
+ struct {
+ u64 interruption_pending : 1;
+ u64 interruption_type: 1;
+ u64 reserved : 30;
+ u64 error_code : 32;
+ } __packed;
+};
+
+union hv_arm64_interrupt_state_register {
+ u64 as_uint64;
+ struct {
+ u64 interrupt_shadow : 1;
+ u64 reserved : 63;
+ } __packed;
+};
+
+union hv_arm64_pending_synthetic_exception_event {
+ u64 as_uint64[2];
+ struct {
+ u8 event_pending : 1;
+ u8 event_type : 3;
+ u8 reserved : 4;
+ u8 rsvd[3];
+ u64 context;
+ } __packed;
+};
+
union hv_x64_interrupt_state_register {
u64 as_uint64;
struct {
@@ -1103,8 +1132,20 @@ union hv_register_value {
union hv_explicit_suspend_register explicit_suspend;
union hv_intercept_suspend_register intercept_suspend;
union hv_dispatch_suspend_register dispatch_suspend;
+#ifdef CONFIG_ARM64
+ union hv_arm64_interrupt_state_register interrupt_state;
+ union hv_arm64_pending_interruption_register pending_interruption;
+#endif
+#ifdef CONFIG_X86
union hv_x64_interrupt_state_register interrupt_state;
union hv_x64_pending_interruption_register pending_interruption;
+#endif
+ union hv_arm64_pending_synthetic_exception_event pending_synthetic_exception_event;
+};
+
+/* NOTE: Linux helper struct - NOT from Hyper-V code. */
+struct hv_output_get_vp_registers {
+ DECLARE_FLEX_ARRAY(union hv_register_value, values);
};
#if defined(CONFIG_ARM64)
--
2.34.1
^ permalink raw reply related [flat|nested] 18+ messages in thread* Re: [PATCH v6 1/5] hyperv: Define struct hv_output_get_vp_registers
2025-01-08 22:21 ` [PATCH v6 1/5] hyperv: Define struct hv_output_get_vp_registers Roman Kisel
@ 2025-01-08 23:25 ` Nuno Das Neves
2025-01-09 5:50 ` Wei Liu
0 siblings, 1 reply; 18+ messages in thread
From: Nuno Das Neves @ 2025-01-08 23:25 UTC (permalink / raw)
To: Roman Kisel, hpa, kys, bp, dave.hansen, decui, eahariha, haiyangz,
mingo, mhklinux, tglx, tiala, wei.liu, linux-hyperv, linux-kernel,
x86
Cc: apais, benhill, ssengar, sunilmut, vdso
On 1/8/2025 2:21 PM, Roman Kisel wrote:
> There is no definition of the output structure for the
> GetVpRegisters hypercall. Hence, using the hypercall
> is not possible when the output value has some structure
> to it. Even getting a datum of a primitive type reads
> as ad-hoc without that definition.
>
> Define struct hv_output_get_vp_registers to enable using
> the GetVpRegisters hypercall. Make provisions for all
> supported architectures. No functional changes.
>
> Signed-off-by: Roman Kisel <romank@linux.microsoft.com>
> ---
> include/hyperv/hvgdk_mini.h | 41 +++++++++++++++++++++++++++++++++++++
> 1 file changed, 41 insertions(+)
>
> diff --git a/include/hyperv/hvgdk_mini.h b/include/hyperv/hvgdk_mini.h
> index db3d1aaf7330..4fffca9e16df 100644
> --- a/include/hyperv/hvgdk_mini.h
> +++ b/include/hyperv/hvgdk_mini.h
> @@ -1068,6 +1068,35 @@ union hv_dispatch_suspend_register {
> } __packed;
> };
>
> +union hv_arm64_pending_interruption_register {
> + u64 as_uint64;
> + struct {
> + u64 interruption_pending : 1;
> + u64 interruption_type: 1;
> + u64 reserved : 30;
> + u64 error_code : 32;
> + } __packed;
> +};
> +
> +union hv_arm64_interrupt_state_register {
> + u64 as_uint64;
> + struct {
> + u64 interrupt_shadow : 1;
> + u64 reserved : 63;
> + } __packed;
> +};
> +
> +union hv_arm64_pending_synthetic_exception_event {
> + u64 as_uint64[2];
> + struct {
> + u8 event_pending : 1;
> + u8 event_type : 3;
> + u8 reserved : 4;
> + u8 rsvd[3];
> + u64 context;
> + } __packed;
> +};
> +
You've omitted the exception_type field.
This is how it should be:
union hv_arm64_pending_synthetic_exception_event {
u64 as_uint64[2];
struct {
u8 event_pending : 1;
u8 event_type : 3;
u8 reserved : 4;
u8 rsvd[3];
u32 exception_type;
u64 context;
} __packed;
};
> union hv_x64_interrupt_state_register {
> u64 as_uint64;
> struct {
> @@ -1103,8 +1132,20 @@ union hv_register_value {
> union hv_explicit_suspend_register explicit_suspend;
> union hv_intercept_suspend_register intercept_suspend;
> union hv_dispatch_suspend_register dispatch_suspend;
> +#ifdef CONFIG_ARM64
> + union hv_arm64_interrupt_state_register interrupt_state;
> + union hv_arm64_pending_interruption_register pending_interruption;
> +#endif
> +#ifdef CONFIG_X86
> union hv_x64_interrupt_state_register interrupt_state;
> union hv_x64_pending_interruption_register pending_interruption;
> +#endif
> + union hv_arm64_pending_synthetic_exception_event pending_synthetic_exception_event;
> +};
> +
> +/* NOTE: Linux helper struct - NOT from Hyper-V code. */
> +struct hv_output_get_vp_registers {
> + DECLARE_FLEX_ARRAY(union hv_register_value, values);
> };
>
> #if defined(CONFIG_ARM64)
^ permalink raw reply [flat|nested] 18+ messages in thread* Re: [PATCH v6 1/5] hyperv: Define struct hv_output_get_vp_registers
2025-01-08 23:25 ` Nuno Das Neves
@ 2025-01-09 5:50 ` Wei Liu
2025-01-09 17:25 ` Roman Kisel
0 siblings, 1 reply; 18+ messages in thread
From: Wei Liu @ 2025-01-09 5:50 UTC (permalink / raw)
To: Nuno Das Neves
Cc: Roman Kisel, hpa, kys, bp, dave.hansen, decui, eahariha, haiyangz,
mingo, mhklinux, tglx, tiala, wei.liu, linux-hyperv, linux-kernel,
x86, apais, benhill, ssengar, sunilmut, vdso
On Wed, Jan 08, 2025 at 03:25:22PM -0800, Nuno Das Neves wrote:
> On 1/8/2025 2:21 PM, Roman Kisel wrote:
> > There is no definition of the output structure for the
> > GetVpRegisters hypercall. Hence, using the hypercall
> > is not possible when the output value has some structure
> > to it. Even getting a datum of a primitive type reads
> > as ad-hoc without that definition.
> >
> > Define struct hv_output_get_vp_registers to enable using
> > the GetVpRegisters hypercall. Make provisions for all
> > supported architectures. No functional changes.
> >
> > Signed-off-by: Roman Kisel <romank@linux.microsoft.com>
> > ---
> > include/hyperv/hvgdk_mini.h | 41 +++++++++++++++++++++++++++++++++++++
> > 1 file changed, 41 insertions(+)
> >
> > diff --git a/include/hyperv/hvgdk_mini.h b/include/hyperv/hvgdk_mini.h
> > index db3d1aaf7330..4fffca9e16df 100644
> > --- a/include/hyperv/hvgdk_mini.h
> > +++ b/include/hyperv/hvgdk_mini.h
> > @@ -1068,6 +1068,35 @@ union hv_dispatch_suspend_register {
> > } __packed;
> > };
> >
> > +union hv_arm64_pending_interruption_register {
> > + u64 as_uint64;
> > + struct {
> > + u64 interruption_pending : 1;
> > + u64 interruption_type: 1;
> > + u64 reserved : 30;
> > + u64 error_code : 32;
> > + } __packed;
> > +};
> > +
> > +union hv_arm64_interrupt_state_register {
> > + u64 as_uint64;
> > + struct {
> > + u64 interrupt_shadow : 1;
> > + u64 reserved : 63;
> > + } __packed;
> > +};
> > +
> > +union hv_arm64_pending_synthetic_exception_event {
> > + u64 as_uint64[2];
> > + struct {
> > + u8 event_pending : 1;
> > + u8 event_type : 3;
> > + u8 reserved : 4;
> > + u8 rsvd[3];
> > + u64 context;
> > + } __packed;
> > +};
> > +
>
> You've omitted the exception_type field.
> This is how it should be:
>
> union hv_arm64_pending_synthetic_exception_event {
> u64 as_uint64[2];
> struct {
> u8 event_pending : 1;
> u8 event_type : 3;
> u8 reserved : 4;
> u8 rsvd[3];
> u32 exception_type;
> u64 context;
> } __packed;
> };
>
I can fix this when I commit the change . This patch will be folded into
your old one anyway.
Thanks,
Wei.
^ permalink raw reply [flat|nested] 18+ messages in thread* Re: [PATCH v6 1/5] hyperv: Define struct hv_output_get_vp_registers
2025-01-09 5:50 ` Wei Liu
@ 2025-01-09 17:25 ` Roman Kisel
2025-01-09 19:09 ` Wei Liu
0 siblings, 1 reply; 18+ messages in thread
From: Roman Kisel @ 2025-01-09 17:25 UTC (permalink / raw)
To: Wei Liu, Nuno Das Neves
Cc: hpa, kys, bp, dave.hansen, decui, eahariha, haiyangz, mingo,
mhklinux, tglx, tiala, linux-hyperv, linux-kernel, x86, apais,
benhill, ssengar, sunilmut, vdso
On 1/8/2025 9:50 PM, Wei Liu wrote:
> On Wed, Jan 08, 2025 at 03:25:22PM -0800, Nuno Das Neves wrote:
>> On 1/8/2025 2:21 PM, Roman Kisel wrote:
[...]
>>
>
> I can fix this when I commit the change . This patch will be folded into
> your old one anyway.
>
Nuno, thank you very much for spotting that! Wei, appreciate that!
Didn't mean to create more work for you, sorry about that.
> Thanks,
> Wei.
--
Thank you,
Roman
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v6 1/5] hyperv: Define struct hv_output_get_vp_registers
2025-01-09 17:25 ` Roman Kisel
@ 2025-01-09 19:09 ` Wei Liu
0 siblings, 0 replies; 18+ messages in thread
From: Wei Liu @ 2025-01-09 19:09 UTC (permalink / raw)
To: Roman Kisel
Cc: Wei Liu, Nuno Das Neves, hpa, kys, bp, dave.hansen, decui,
eahariha, haiyangz, mingo, mhklinux, tglx, tiala, linux-hyperv,
linux-kernel, x86, apais, benhill, ssengar, sunilmut, vdso
On Thu, Jan 09, 2025 at 09:25:58AM -0800, Roman Kisel wrote:
>
>
> On 1/8/2025 9:50 PM, Wei Liu wrote:
> > On Wed, Jan 08, 2025 at 03:25:22PM -0800, Nuno Das Neves wrote:
> > > On 1/8/2025 2:21 PM, Roman Kisel wrote:
>
> [...]
>
> > >
> >
> > I can fix this when I commit the change . This patch will be folded into
> > your old one anyway.
> >
> Nuno, thank you very much for spotting that! Wei, appreciate that!
> Didn't mean to create more work for you, sorry about that.
No problem at all. I'm happy to help.
Wei.
>
> > Thanks,
> > Wei.
>
> --
> Thank you,
> Roman
>
>
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v6 2/5] hyperv: Fix pointer type in get_vtl(void)
2025-01-08 22:21 [PATCH v6 0/5] hyperv: Fixes for get_vtl(), hv_vtl_apicid_to_vp_id() Roman Kisel
2025-01-08 22:21 ` [PATCH v6 1/5] hyperv: Define struct hv_output_get_vp_registers Roman Kisel
@ 2025-01-08 22:21 ` Roman Kisel
2025-01-08 22:21 ` [PATCH v6 3/5] hyperv: Enable the hypercall output page for the VTL mode Roman Kisel
` (3 subsequent siblings)
5 siblings, 0 replies; 18+ messages in thread
From: Roman Kisel @ 2025-01-08 22:21 UTC (permalink / raw)
To: hpa, kys, bp, dave.hansen, decui, eahariha, haiyangz, mingo,
mhklinux, nunodasneves, tglx, tiala, wei.liu, linux-hyperv,
linux-kernel, x86
Cc: apais, benhill, ssengar, sunilmut, vdso
Commit bc905fa8b633 ("hyperv: Switch from hyperv-tlfs.h to hyperv/hvhdk.h")
changed the type of the output pointer to `struct hv_register_assoc` from
`struct hv_get_vp_registers_output`. That leads to an incorrect computation,
and leaves the system broken.
Use the correct pointer type for the output of the GetVpRegisters hypercall.
Signed-off-by: Roman Kisel <romank@linux.microsoft.com>
Reviewed-by: Easwar Hariharan <eahariha@linux.microsoft.com>
Reviewed-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
---
arch/x86/hyperv/hv_init.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
index 9e5e8328df6b..f82d1aefaa8a 100644
--- a/arch/x86/hyperv/hv_init.c
+++ b/arch/x86/hyperv/hv_init.c
@@ -416,13 +416,13 @@ static u8 __init get_vtl(void)
{
u64 control = HV_HYPERCALL_REP_COMP_1 | HVCALL_GET_VP_REGISTERS;
struct hv_input_get_vp_registers *input;
- struct hv_register_assoc *output;
+ struct hv_output_get_vp_registers *output;
unsigned long flags;
u64 ret;
local_irq_save(flags);
input = *this_cpu_ptr(hyperv_pcpu_input_arg);
- output = (struct hv_register_assoc *)input;
+ output = (struct hv_output_get_vp_registers *)input;
memset(input, 0, struct_size(input, names, 1));
input->partition_id = HV_PARTITION_ID_SELF;
@@ -432,7 +432,7 @@ static u8 __init get_vtl(void)
ret = hv_do_hypercall(control, input, output);
if (hv_result_success(ret)) {
- ret = output->value.reg8 & HV_X64_VTL_MASK;
+ ret = output->values[0].reg8 & HV_X64_VTL_MASK;
} else {
pr_err("Failed to get VTL(error: %lld) exiting...\n", ret);
BUG();
--
2.34.1
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH v6 3/5] hyperv: Enable the hypercall output page for the VTL mode
2025-01-08 22:21 [PATCH v6 0/5] hyperv: Fixes for get_vtl(), hv_vtl_apicid_to_vp_id() Roman Kisel
2025-01-08 22:21 ` [PATCH v6 1/5] hyperv: Define struct hv_output_get_vp_registers Roman Kisel
2025-01-08 22:21 ` [PATCH v6 2/5] hyperv: Fix pointer type in get_vtl(void) Roman Kisel
@ 2025-01-08 22:21 ` Roman Kisel
2025-01-08 23:27 ` Nuno Das Neves
2025-01-08 22:21 ` [PATCH v6 4/5] hyperv: Do not overlap the hvcall IO areas in get_vtl() Roman Kisel
` (2 subsequent siblings)
5 siblings, 1 reply; 18+ messages in thread
From: Roman Kisel @ 2025-01-08 22:21 UTC (permalink / raw)
To: hpa, kys, bp, dave.hansen, decui, eahariha, haiyangz, mingo,
mhklinux, nunodasneves, tglx, tiala, wei.liu, linux-hyperv,
linux-kernel, x86
Cc: apais, benhill, ssengar, sunilmut, vdso
Due to the hypercall page not being allocated in the VTL mode,
the code resorts to using a part of the input page.
Allocate the hypercall output page in the VTL mode thus enabling
it to use it for output and share code with dom0.
Signed-off-by: Roman Kisel <romank@linux.microsoft.com>
---
drivers/hv/hv_common.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
index c6ed3ba4bf61..af5d1dc451f6 100644
--- a/drivers/hv/hv_common.c
+++ b/drivers/hv/hv_common.c
@@ -278,6 +278,11 @@ static void hv_kmsg_dump_register(void)
}
}
+static inline bool hv_output_page_exists(void)
+{
+ return hv_root_partition || IS_ENABLED(CONFIG_HYPERV_VTL_MODE);
+}
+
int __init hv_common_init(void)
{
int i;
@@ -340,7 +345,7 @@ int __init hv_common_init(void)
BUG_ON(!hyperv_pcpu_input_arg);
/* Allocate the per-CPU state for output arg for root */
- if (hv_root_partition) {
+ if (hv_output_page_exists()) {
hyperv_pcpu_output_arg = alloc_percpu(void *);
BUG_ON(!hyperv_pcpu_output_arg);
}
@@ -435,7 +440,7 @@ int hv_common_cpu_init(unsigned int cpu)
void **inputarg, **outputarg;
u64 msr_vp_index;
gfp_t flags;
- int pgcount = hv_root_partition ? 2 : 1;
+ const int pgcount = hv_output_page_exists() ? 2 : 1;
void *mem;
int ret;
@@ -453,7 +458,7 @@ int hv_common_cpu_init(unsigned int cpu)
if (!mem)
return -ENOMEM;
- if (hv_root_partition) {
+ if (hv_output_page_exists()) {
outputarg = (void **)this_cpu_ptr(hyperv_pcpu_output_arg);
*outputarg = (char *)mem + HV_HYP_PAGE_SIZE;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 18+ messages in thread* Re: [PATCH v6 3/5] hyperv: Enable the hypercall output page for the VTL mode
2025-01-08 22:21 ` [PATCH v6 3/5] hyperv: Enable the hypercall output page for the VTL mode Roman Kisel
@ 2025-01-08 23:27 ` Nuno Das Neves
0 siblings, 0 replies; 18+ messages in thread
From: Nuno Das Neves @ 2025-01-08 23:27 UTC (permalink / raw)
To: Roman Kisel, hpa, kys, bp, dave.hansen, decui, eahariha, haiyangz,
mingo, mhklinux, tglx, tiala, wei.liu, linux-hyperv, linux-kernel,
x86
Cc: apais, benhill, ssengar, sunilmut, vdso
On 1/8/2025 2:21 PM, Roman Kisel wrote:
> Due to the hypercall page not being allocated in the VTL mode,
> the code resorts to using a part of the input page.
>
> Allocate the hypercall output page in the VTL mode thus enabling
> it to use it for output and share code with dom0.
>
> Signed-off-by: Roman Kisel <romank@linux.microsoft.com>
> ---
> drivers/hv/hv_common.c | 11 ++++++++---
> 1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
> index c6ed3ba4bf61..af5d1dc451f6 100644
> --- a/drivers/hv/hv_common.c
> +++ b/drivers/hv/hv_common.c
> @@ -278,6 +278,11 @@ static void hv_kmsg_dump_register(void)
> }
> }
>
> +static inline bool hv_output_page_exists(void)
> +{
> + return hv_root_partition || IS_ENABLED(CONFIG_HYPERV_VTL_MODE);
> +}
> +
> int __init hv_common_init(void)
> {
> int i;
> @@ -340,7 +345,7 @@ int __init hv_common_init(void)
> BUG_ON(!hyperv_pcpu_input_arg);
>
> /* Allocate the per-CPU state for output arg for root */
> - if (hv_root_partition) {
> + if (hv_output_page_exists()) {
> hyperv_pcpu_output_arg = alloc_percpu(void *);
> BUG_ON(!hyperv_pcpu_output_arg);
> }
> @@ -435,7 +440,7 @@ int hv_common_cpu_init(unsigned int cpu)
> void **inputarg, **outputarg;
> u64 msr_vp_index;
> gfp_t flags;
> - int pgcount = hv_root_partition ? 2 : 1;
> + const int pgcount = hv_output_page_exists() ? 2 : 1;
> void *mem;
> int ret;
>
> @@ -453,7 +458,7 @@ int hv_common_cpu_init(unsigned int cpu)
> if (!mem)
> return -ENOMEM;
>
> - if (hv_root_partition) {
> + if (hv_output_page_exists()) {
> outputarg = (void **)this_cpu_ptr(hyperv_pcpu_output_arg);
> *outputarg = (char *)mem + HV_HYP_PAGE_SIZE;
> }
Reviewed-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v6 4/5] hyperv: Do not overlap the hvcall IO areas in get_vtl()
2025-01-08 22:21 [PATCH v6 0/5] hyperv: Fixes for get_vtl(), hv_vtl_apicid_to_vp_id() Roman Kisel
` (2 preceding siblings ...)
2025-01-08 22:21 ` [PATCH v6 3/5] hyperv: Enable the hypercall output page for the VTL mode Roman Kisel
@ 2025-01-08 22:21 ` Roman Kisel
2025-01-08 22:21 ` [PATCH v6 5/5] hyperv: Do not overlap the hvcall IO areas in hv_vtl_apicid_to_vp_id() Roman Kisel
2025-01-09 20:18 ` [PATCH v6 0/5] hyperv: Fixes for get_vtl(), hv_vtl_apicid_to_vp_id() Wei Liu
5 siblings, 0 replies; 18+ messages in thread
From: Roman Kisel @ 2025-01-08 22:21 UTC (permalink / raw)
To: hpa, kys, bp, dave.hansen, decui, eahariha, haiyangz, mingo,
mhklinux, nunodasneves, tglx, tiala, wei.liu, linux-hyperv,
linux-kernel, x86
Cc: apais, benhill, ssengar, sunilmut, vdso
The Top-Level Functional Specification for Hyper-V, Section 3.6 [1, 2],
disallows overlapping of the input and output hypercall areas, and
get_vtl(void) does overlap them.
Use the output hypercall page of the current vCPU for the hypercall.
[1] https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/tlfs/hypercall-interface
[2] https://github.com/MicrosoftDocs/Virtualization-Documentation/tree/main/tlfs
Fixes: 8387ce06d70b ("x86/hyperv: Set Virtual Trust Level in VMBus init message")
Signed-off-by: Roman Kisel <romank@linux.microsoft.com>
Reviewed-by: Tianyu Lan <tiala@microsoft.com>
Reviewed-by: Easwar Hariharan <eahariha@linux.microsoft.com>
---
arch/x86/hyperv/hv_init.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
index f82d1aefaa8a..173005e6a95d 100644
--- a/arch/x86/hyperv/hv_init.c
+++ b/arch/x86/hyperv/hv_init.c
@@ -422,7 +422,7 @@ static u8 __init get_vtl(void)
local_irq_save(flags);
input = *this_cpu_ptr(hyperv_pcpu_input_arg);
- output = (struct hv_output_get_vp_registers *)input;
+ output = *this_cpu_ptr(hyperv_pcpu_output_arg);
memset(input, 0, struct_size(input, names, 1));
input->partition_id = HV_PARTITION_ID_SELF;
--
2.34.1
^ permalink raw reply related [flat|nested] 18+ messages in thread* [PATCH v6 5/5] hyperv: Do not overlap the hvcall IO areas in hv_vtl_apicid_to_vp_id()
2025-01-08 22:21 [PATCH v6 0/5] hyperv: Fixes for get_vtl(), hv_vtl_apicid_to_vp_id() Roman Kisel
` (3 preceding siblings ...)
2025-01-08 22:21 ` [PATCH v6 4/5] hyperv: Do not overlap the hvcall IO areas in get_vtl() Roman Kisel
@ 2025-01-08 22:21 ` Roman Kisel
2025-01-08 23:34 ` Nuno Das Neves
2025-01-09 20:18 ` [PATCH v6 0/5] hyperv: Fixes for get_vtl(), hv_vtl_apicid_to_vp_id() Wei Liu
5 siblings, 1 reply; 18+ messages in thread
From: Roman Kisel @ 2025-01-08 22:21 UTC (permalink / raw)
To: hpa, kys, bp, dave.hansen, decui, eahariha, haiyangz, mingo,
mhklinux, nunodasneves, tglx, tiala, wei.liu, linux-hyperv,
linux-kernel, x86
Cc: apais, benhill, ssengar, sunilmut, vdso
The Top-Level Functional Specification for Hyper-V, Section 3.6 [1, 2],
disallows overlapping of the input and output hypercall areas, and
hv_vtl_apicid_to_vp_id() overlaps them.
Use the output hypercall page of the current vCPU for the hypercall.
[1] https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/tlfs/hypercall-interface
[2] https://github.com/MicrosoftDocs/Virtualization-Documentation/tree/main/tlfs
Reported-by: Michael Kelley <mhklinux@outlook.com>
Closes: https://lore.kernel.org/lkml/SN6PR02MB4157B98CD34781CC87A9D921D40D2@SN6PR02MB4157.namprd02.prod.outlook.com/
Signed-off-by: Roman Kisel <romank@linux.microsoft.com>
Reviewed-by: Easwar Hariharan <eahariha@linux.microsoft.com>
---
arch/x86/hyperv/hv_vtl.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/hyperv/hv_vtl.c b/arch/x86/hyperv/hv_vtl.c
index 04775346369c..4e1b1e3b5658 100644
--- a/arch/x86/hyperv/hv_vtl.c
+++ b/arch/x86/hyperv/hv_vtl.c
@@ -189,7 +189,7 @@ static int hv_vtl_apicid_to_vp_id(u32 apic_id)
input->partition_id = HV_PARTITION_ID_SELF;
input->apic_ids[0] = apic_id;
- output = (u32 *)input;
+ output = *this_cpu_ptr(hyperv_pcpu_output_arg);
control = HV_HYPERCALL_REP_COMP_1 | HVCALL_GET_VP_ID_FROM_APIC_ID;
status = hv_do_hypercall(control, input, output);
--
2.34.1
^ permalink raw reply related [flat|nested] 18+ messages in thread* Re: [PATCH v6 5/5] hyperv: Do not overlap the hvcall IO areas in hv_vtl_apicid_to_vp_id()
2025-01-08 22:21 ` [PATCH v6 5/5] hyperv: Do not overlap the hvcall IO areas in hv_vtl_apicid_to_vp_id() Roman Kisel
@ 2025-01-08 23:34 ` Nuno Das Neves
0 siblings, 0 replies; 18+ messages in thread
From: Nuno Das Neves @ 2025-01-08 23:34 UTC (permalink / raw)
To: Roman Kisel, hpa, kys, bp, dave.hansen, decui, eahariha, haiyangz,
mingo, mhklinux, tglx, tiala, wei.liu, linux-hyperv, linux-kernel,
x86
Cc: apais, benhill, ssengar, sunilmut, vdso
On 1/8/2025 2:21 PM, Roman Kisel wrote:
> The Top-Level Functional Specification for Hyper-V, Section 3.6 [1, 2],
> disallows overlapping of the input and output hypercall areas, and
> hv_vtl_apicid_to_vp_id() overlaps them.
>
> Use the output hypercall page of the current vCPU for the hypercall.
>
> [1] https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/tlfs/hypercall-interface
> [2] https://github.com/MicrosoftDocs/Virtualization-Documentation/tree/main/tlfs
>
> Reported-by: Michael Kelley <mhklinux@outlook.com>
> Closes: https://lore.kernel.org/lkml/SN6PR02MB4157B98CD34781CC87A9D921D40D2@SN6PR02MB4157.namprd02.prod.outlook.com/
> Signed-off-by: Roman Kisel <romank@linux.microsoft.com>
> Reviewed-by: Easwar Hariharan <eahariha@linux.microsoft.com>
> ---
> arch/x86/hyperv/hv_vtl.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/hyperv/hv_vtl.c b/arch/x86/hyperv/hv_vtl.c
> index 04775346369c..4e1b1e3b5658 100644
> --- a/arch/x86/hyperv/hv_vtl.c
> +++ b/arch/x86/hyperv/hv_vtl.c
> @@ -189,7 +189,7 @@ static int hv_vtl_apicid_to_vp_id(u32 apic_id)
> input->partition_id = HV_PARTITION_ID_SELF;
> input->apic_ids[0] = apic_id;
>
> - output = (u32 *)input;
> + output = *this_cpu_ptr(hyperv_pcpu_output_arg);
>
> control = HV_HYPERCALL_REP_COMP_1 | HVCALL_GET_VP_ID_FROM_APIC_ID;
> status = hv_do_hypercall(control, input, output);
Reviewed-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v6 0/5] hyperv: Fixes for get_vtl(), hv_vtl_apicid_to_vp_id()
2025-01-08 22:21 [PATCH v6 0/5] hyperv: Fixes for get_vtl(), hv_vtl_apicid_to_vp_id() Roman Kisel
` (4 preceding siblings ...)
2025-01-08 22:21 ` [PATCH v6 5/5] hyperv: Do not overlap the hvcall IO areas in hv_vtl_apicid_to_vp_id() Roman Kisel
@ 2025-01-09 20:18 ` Wei Liu
2025-01-09 20:28 ` Nuno Das Neves
2025-01-09 21:40 ` Roman Kisel
5 siblings, 2 replies; 18+ messages in thread
From: Wei Liu @ 2025-01-09 20:18 UTC (permalink / raw)
To: Roman Kisel
Cc: hpa, kys, bp, dave.hansen, decui, eahariha, haiyangz, mingo,
mhklinux, nunodasneves, tglx, tiala, wei.liu, linux-hyperv,
linux-kernel, x86, apais, benhill, ssengar, sunilmut, vdso
On Wed, Jan 08, 2025 at 02:21:33PM -0800, Roman Kisel wrote:
[...]
> Roman Kisel (5):
> hyperv: Define struct hv_output_get_vp_registers
> hyperv: Fix pointer type in get_vtl(void)
> hyperv: Enable the hypercall output page for the VTL mode
> hyperv: Do not overlap the hvcall IO areas in get_vtl()
> hyperv: Do not overlap the hvcall IO areas in hv_vtl_apicid_to_vp_id()
The patches have been pushed to hyperv-next. Roman and Nuno, please
check the tree for correctness.
Thanks,
Wei.
^ permalink raw reply [flat|nested] 18+ messages in thread* Re: [PATCH v6 0/5] hyperv: Fixes for get_vtl(), hv_vtl_apicid_to_vp_id()
2025-01-09 20:18 ` [PATCH v6 0/5] hyperv: Fixes for get_vtl(), hv_vtl_apicid_to_vp_id() Wei Liu
@ 2025-01-09 20:28 ` Nuno Das Neves
2025-01-09 21:28 ` Roman Kisel
2025-01-09 21:40 ` Roman Kisel
1 sibling, 1 reply; 18+ messages in thread
From: Nuno Das Neves @ 2025-01-09 20:28 UTC (permalink / raw)
To: Wei Liu, Roman Kisel
Cc: hpa, kys, bp, dave.hansen, decui, eahariha, haiyangz, mingo,
mhklinux, tglx, tiala, linux-hyperv, linux-kernel, x86, apais,
benhill, ssengar, sunilmut, vdso
On 1/9/2025 12:18 PM, Wei Liu wrote:
> On Wed, Jan 08, 2025 at 02:21:33PM -0800, Roman Kisel wrote:
> [...]
>> Roman Kisel (5):
>> hyperv: Define struct hv_output_get_vp_registers
>> hyperv: Fix pointer type in get_vtl(void)
>> hyperv: Enable the hypercall output page for the VTL mode
>> hyperv: Do not overlap the hvcall IO areas in get_vtl()
>> hyperv: Do not overlap the hvcall IO areas in hv_vtl_apicid_to_vp_id()
>
> The patches have been pushed to hyperv-next. Roman and Nuno, please
> check the tree for correctness.
>
> Thanks,
> Wei.
I checked, looks like the first two patches of the series are missing?
Nuno
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v6 0/5] hyperv: Fixes for get_vtl(), hv_vtl_apicid_to_vp_id()
2025-01-09 20:28 ` Nuno Das Neves
@ 2025-01-09 21:28 ` Roman Kisel
0 siblings, 0 replies; 18+ messages in thread
From: Roman Kisel @ 2025-01-09 21:28 UTC (permalink / raw)
To: Nuno Das Neves, Wei Liu
Cc: hpa, kys, bp, dave.hansen, decui, eahariha, haiyangz, mingo,
mhklinux, tglx, tiala, linux-hyperv, linux-kernel, x86, apais,
benhill, ssengar, sunilmut, vdso
On 1/9/2025 12:28 PM, Nuno Das Neves wrote:
> On 1/9/2025 12:18 PM, Wei Liu wrote:
>> On Wed, Jan 08, 2025 at 02:21:33PM -0800, Roman Kisel wrote:
>> [...]
>>> Roman Kisel (5):
>>> hyperv: Define struct hv_output_get_vp_registers
>>> hyperv: Fix pointer type in get_vtl(void)
>>> hyperv: Enable the hypercall output page for the VTL mode
>>> hyperv: Do not overlap the hvcall IO areas in get_vtl()
>>> hyperv: Do not overlap the hvcall IO areas in hv_vtl_apicid_to_vp_id()
>>
>> The patches have been pushed to hyperv-next. Roman and Nuno, please
>> check the tree for correctness.
>>
>> Thanks,
>> Wei.
>
> I checked, looks like the first two patches of the series are missing?
IIUC, they were to be rolled up into your earlier patches
>
> Nuno
--
Thank you,
Roman
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v6 0/5] hyperv: Fixes for get_vtl(), hv_vtl_apicid_to_vp_id()
2025-01-09 20:18 ` [PATCH v6 0/5] hyperv: Fixes for get_vtl(), hv_vtl_apicid_to_vp_id() Wei Liu
2025-01-09 20:28 ` Nuno Das Neves
@ 2025-01-09 21:40 ` Roman Kisel
2025-01-09 21:56 ` Wei Liu
1 sibling, 1 reply; 18+ messages in thread
From: Roman Kisel @ 2025-01-09 21:40 UTC (permalink / raw)
To: Wei Liu
Cc: hpa, kys, bp, dave.hansen, decui, eahariha, haiyangz, mingo,
mhklinux, nunodasneves, tglx, tiala, linux-hyperv, linux-kernel,
x86, apais, benhill, ssengar, sunilmut, vdso
On 1/9/2025 12:18 PM, Wei Liu wrote:
> On Wed, Jan 08, 2025 at 02:21:33PM -0800, Roman Kisel wrote:
> [...]
>> Roman Kisel (5):
>> hyperv: Define struct hv_output_get_vp_registers
>> hyperv: Fix pointer type in get_vtl(void)
>> hyperv: Enable the hypercall output page for the VTL mode
>> hyperv: Do not overlap the hvcall IO areas in get_vtl()
>> hyperv: Do not overlap the hvcall IO areas in hv_vtl_apicid_to_vp_id()
>
> The patches have been pushed to hyperv-next. Roman and Nuno, please
> check the tree for correctness.
This
```c
union hv_arm64_pending_synthetic_exception_event {
u64 as_uint64[2];
struct {
u8 event_pending : 1;
u8 event_type : 3;
u8 reserved : 4;
u8 rsvd[3];
u64 context;
} __packed;
};
```
needs to have the `u32 exception_type;` field:
```c
union hv_arm64_pending_synthetic_exception_event {
u64 as_uint64[2];
struct {
u8 event_pending : 1;
u8 event_type : 3;
u8 reserved : 4;
u8 rsvd[3];
u32 exception_type;
u64 context;
} __packed;
};
```
as otherwise the struct won't cover the array.
Testing the VMs currently with the latest hyperv-next.
>
> Thanks,
> Wei.
--
Thank you,
Roman
^ permalink raw reply [flat|nested] 18+ messages in thread* Re: [PATCH v6 0/5] hyperv: Fixes for get_vtl(), hv_vtl_apicid_to_vp_id()
2025-01-09 21:40 ` Roman Kisel
@ 2025-01-09 21:56 ` Wei Liu
2025-01-09 22:19 ` Roman Kisel
0 siblings, 1 reply; 18+ messages in thread
From: Wei Liu @ 2025-01-09 21:56 UTC (permalink / raw)
To: Roman Kisel
Cc: Wei Liu, hpa, kys, bp, dave.hansen, decui, eahariha, haiyangz,
mingo, mhklinux, nunodasneves, tglx, tiala, linux-hyperv,
linux-kernel, x86, apais, benhill, ssengar, sunilmut, vdso
On Thu, Jan 09, 2025 at 01:40:34PM -0800, Roman Kisel wrote:
>
>
> On 1/9/2025 12:18 PM, Wei Liu wrote:
> > On Wed, Jan 08, 2025 at 02:21:33PM -0800, Roman Kisel wrote:
> > [...]
> > > Roman Kisel (5):
> > > hyperv: Define struct hv_output_get_vp_registers
> > > hyperv: Fix pointer type in get_vtl(void)
> > > hyperv: Enable the hypercall output page for the VTL mode
> > > hyperv: Do not overlap the hvcall IO areas in get_vtl()
> > > hyperv: Do not overlap the hvcall IO areas in hv_vtl_apicid_to_vp_id()
> >
> > The patches have been pushed to hyperv-next. Roman and Nuno, please
> > check the tree for correctness.
>
> This
>
> ```c
> union hv_arm64_pending_synthetic_exception_event {
> u64 as_uint64[2];
> struct {
> u8 event_pending : 1;
> u8 event_type : 3;
> u8 reserved : 4;
> u8 rsvd[3];
> u64 context;
> } __packed;
> };
> ```
>
> needs to have the `u32 exception_type;` field:
>
> ```c
> union hv_arm64_pending_synthetic_exception_event {
> u64 as_uint64[2];
> struct {
> u8 event_pending : 1;
> u8 event_type : 3;
> u8 reserved : 4;
> u8 rsvd[3];
> u32 exception_type;
> u64 context;
> } __packed;
> };
> ```
> as otherwise the struct won't cover the array.
> Testing the VMs currently with the latest hyperv-next.
Fixed. I c&p'ed the code then deleted the right version of the struct.
Thanks for checking.
Wei.
^ permalink raw reply [flat|nested] 18+ messages in thread* Re: [PATCH v6 0/5] hyperv: Fixes for get_vtl(), hv_vtl_apicid_to_vp_id()
2025-01-09 21:56 ` Wei Liu
@ 2025-01-09 22:19 ` Roman Kisel
0 siblings, 0 replies; 18+ messages in thread
From: Roman Kisel @ 2025-01-09 22:19 UTC (permalink / raw)
To: Wei Liu, bp@alien8.de
Cc: hpa, kys, bp, dave.hansen, decui, eahariha, haiyangz, mingo,
mhklinux, nunodasneves, tglx, tiala, linux-hyperv, linux-kernel,
x86, apais, benhill, ssengar, sunilmut, vdso
On 1/9/2025 1:56 PM, Wei Liu wrote:
> On Thu, Jan 09, 2025 at 01:40:34PM -0800, Roman Kisel wrote:
[...]
>>
>> needs to have the `u32 exception_type;` field:
>>
>> ```c
>> union hv_arm64_pending_synthetic_exception_event {
>> u64 as_uint64[2];
>> struct {
>> u8 event_pending : 1;
>> u8 event_type : 3;
>> u8 reserved : 4;
>> u8 rsvd[3];
>> u32 exception_type;
>> u64 context;
>> } __packed;
>> };
>> ```
>> as otherwise the struct won't cover the array.
>> Testing the VMs currently with the latest hyperv-next.
>
> Fixed. I c&p'ed the code then deleted the right version of the struct.
> Thanks for checking.
Happy to help :D
Validated with the VMs, and with the latest hyperv-next, the issue is
fixed!! Appreciate your help and guidance; thank you, Easwar, Michael,
Nuno, Stanislav, Tianyu and Wei for the suggestions that have let make
this patchset so much better :)
Borislav, I apologize for sending the patchset versions too often. I'm
sorry for causing you trouble due to that. I have read up the kernel
documentation, and will be a better citizen of the LKML.
>
> Wei.
--
Thank you,
Roman
^ permalink raw reply [flat|nested] 18+ messages in thread