x86/hyperv: Reserve 3 interrupt vectors used exclusively by mshv
Subsystems (3)
PATCH 1/1 x86/hyperv: Reserve 3 interrupt vectors used exclusively by mshv
MSVC compiler, used to compile the Microsoft Hyper-V hypervisor currently, has an assert intrinsic that uses interrupt vector 0x29 to create an exception. This will cause hypervisor to then crash and collect core. As such, if this interrupt number is assigned to a device by linux and the device generates it, hypervisor will crash. There are two other such vectors hard coded in the hypervisor, 0x2C and 0x2D for debug purposes. Fortunately, the three vectors are part of the kernel driver space and that makes it feasible to reserve them early so they are not assigned later.
---
v1: Add ifndef CONFIG_X86_FRED (thanks hpa)
arch/x86/kernel/cpu/mshyperv.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
arch/x86/kernel/cpu/mshyperv.c +26 -0
@@ -478,6 +478,27 @@ int hv_get_hypervisor_version(union hv_hypervisor_version_info *info) }EXPORT_SYMBOL_GPL (hv_get_hypervisor_version); +#ifndef CONFIG_X86_FRED +/* +* Reserve vectors hard coded in the hypervisor. If used outside, the hypervisor +* will crash or hang or break into debugger. +*/ +static void hv_reserve_irq_vectors (void ) +{ +#define HYPERV_DBG_FASTFAIL_VECTOR 0x29 +#define HYPERV_DBG_ASSERT_VECTOR 0x2C +#define HYPERV_DBG_SERVICE_VECTOR 0x2D + +if (test_and_set_bit (HYPERV_DBG_ASSERT_VECTOR , system_vectors) || +test_and_set_bit (HYPERV_DBG_SERVICE_VECTOR , system_vectors) || +test_and_set_bit (HYPERV_DBG_FASTFAIL_VECTOR , system_vectors)) +BUG (); + +pr_info ("Hyper-V:reserve vectors: %d %d %d\n" ,HYPERV_DBG_ASSERT_VECTOR , +HYPERV_DBG_SERVICE_VECTOR ,HYPERV_DBG_FASTFAIL_VECTOR ); +} +#endif /* CONFIG_X86_FRED */ +static void __init ms_hyperv_init_platform (void ) {int hv_max_functions_eax, eax;
@@ -510,6 +531,11 @@ static void __init ms_hyperv_init_platform(void)hv_identify_partition_type (); +#ifndef CONFIG_X86_FRED +if (hv_root_partition ()) +hv_reserve_irq_vectors (); +#endif /* CONFIG_X86_FRED */ +if (cc_platform_has (CC_ATTR_SNP_SECURE_AVIC )) ms_hyperv.hints |=HV_DEPRECATING_AEOI_RECOMMENDED ;
Signature · 1 line
2.51.2.vfs.0.1
Wei Liu
maintainerQuoted 23 lines · Mukesh Rathor
MSVC compiler, used to compile the Microsoft Hyper-V hypervisor currently, has an assert intrinsic that uses interrupt vector
0x29to create an exception. This will cause hypervisor to then crash and collect core. As such, if this interrupt number is assigned to a device by linux and the device generates it, hypervisor will crash. There are two other such vectors hard coded in the hypervisor,0x2Cand0x2Dfor debug purposes. Fortunately, the three vectors are part of the kernel driver space and that makes it feasible to reserve them early so they are not assigned later.Signed-off-by Mukesh Rathor <[email protected]>---
v1: Add ifndef
CONFIG_X86_FRED(thanks hpa)arch/x86/kernel/cpu/mshyperv.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)arch/x86/kernel/cpu/mshyperv.c +0
-0
arch/x86/kernel/cpu/mshyperv.c int hv_get_hypervisor_version(union hv_hypervisor_version_info *info) · line 481
Quoted 4 lines
arch/x86/kernel/cpu/mshyperv.c +1
-0@@ -478,6 +478,27 @@ int hv_get_hypervisor_version(union hv_hypervisor_version_info *info) }EXPORT_SYMBOL_GPL (hv_get_hypervisor_version); +#ifndef CONFIG_X86_FRED
I briefly looked up FRED and checked the code. I understand that once it is enabled, Linux kernel doesn't setup the IDT anymore (code in arch/x86/kernel/traps.c).
My question is, do we need to do anything when FRED is enabled?
Wei
Quoted 38 lines
arch/x86/kernel/cpu/mshyperv.c +25
-0+/* +* Reserve vectors hard coded in the hypervisor. If used outside, the hypervisor +* will crash or hang or break into debugger. +*/ +static void hv_reserve_irq_vectors (void ) +{ +#define HYPERV_DBG_FASTFAIL_VECTOR 0x29 +#define HYPERV_DBG_ASSERT_VECTOR 0x2C +#define HYPERV_DBG_SERVICE_VECTOR 0x2D + +if (test_and_set_bit (HYPERV_DBG_ASSERT_VECTOR , system_vectors) || +test_and_set_bit (HYPERV_DBG_SERVICE_VECTOR , system_vectors) || +test_and_set_bit (HYPERV_DBG_FASTFAIL_VECTOR , system_vectors)) +BUG (); + +pr_info ("Hyper-V:reserve vectors: %d %d %d\n" ,HYPERV_DBG_ASSERT_VECTOR , +HYPERV_DBG_SERVICE_VECTOR ,HYPERV_DBG_FASTFAIL_VECTOR ); +} +#endif /* CONFIG_X86_FRED */ +static void __init ms_hyperv_init_platform (void ) {int hv_max_functions_eax, eax;@@ -510,6 +531,11 @@ static void __init ms_hyperv_init_platform(void)hv_identify_partition_type (); +#ifndef CONFIG_X86_FRED +if (hv_root_partition ()) +hv_reserve_irq_vectors (); +#endif /* CONFIG_X86_FRED */ +if (cc_platform_has (CC_ATTR_SNP_SECURE_AVIC )) ms_hyperv.hints |=HV_DEPRECATING_AEOI_RECOMMENDED ;Signature · 1 line
2.51.2.vfs.0.1
Quoted 27 lines · Wei Liu
Quoted 26 lines · Mukesh Rathor
MSVC compiler, used to compile the Microsoft Hyper-V hypervisor currently, has an assert intrinsic that uses interrupt vector
0x29to create an exception. This will cause hypervisor to then crash and collect core. As such, if this interrupt number is assigned to a device by linux and the device generates it, hypervisor will crash. There are two other such vectors hard coded in the hypervisor,0x2Cand0x2Dfor debug purposes. Fortunately, the three vectors are part of the kernel driver space and that makes it feasible to reserve them early so they are not assigned later.Signed-off-by Mukesh Rathor <[email protected]>---
v1: Add ifndef
CONFIG_X86_FRED(thanks hpa)arch/x86/kernel/cpu/mshyperv.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)arch/x86/kernel/cpu/mshyperv.c +0
-0@@ -478,6 +478,27 @@ int hv_get_hypervisor_version(union hv_hypervisor_version_info *info) }EXPORT_SYMBOL_GPL (hv_get_hypervisor_version);
Quoted 7 lines
arch/x86/kernel/cpu/mshyperv.c int hv_get_hypervisor_version(union hv_hypervisor_version_info *info) · line 481
Quoted 1 line
arch/x86/kernel/cpu/mshyperv.c +1
-0+#ifndef CONFIG_X86_FRED I briefly looked up FRED and checked the code. I understand that once it is enabled, Linux kernel doesn't setup the IDT anymore (code in
arch/x86/kernel/traps.c).My question is, do we need to do anything when FRED is enabled?
Yeah, at first glance my thought was it probably has greater implications (in terms of double checking exceptions), and so when time allows do deeper investigation and perhaps run it by the hypervisor team to see if there is any other work we need to do.
Thanks,
-Mukesh
Quoted 40 lines
Wei
Quoted 38 lines
arch/x86/kernel/cpu/mshyperv.c +25
-0+/* +* Reserve vectors hard coded in the hypervisor. If used outside, the hypervisor +* will crash or hang or break into debugger. +*/ +static void hv_reserve_irq_vectors (void ) +{ +#define HYPERV_DBG_FASTFAIL_VECTOR 0x29 +#define HYPERV_DBG_ASSERT_VECTOR 0x2C +#define HYPERV_DBG_SERVICE_VECTOR 0x2D + +if (test_and_set_bit (HYPERV_DBG_ASSERT_VECTOR , system_vectors) || +test_and_set_bit (HYPERV_DBG_SERVICE_VECTOR , system_vectors) || +test_and_set_bit (HYPERV_DBG_FASTFAIL_VECTOR , system_vectors)) +BUG (); + +pr_info ("Hyper-V:reserve vectors: %d %d %d\n" ,HYPERV_DBG_ASSERT_VECTOR , +HYPERV_DBG_SERVICE_VECTOR ,HYPERV_DBG_FASTFAIL_VECTOR ); +} +#endif /* CONFIG_X86_FRED */ +static void __init ms_hyperv_init_platform (void ) {int hv_max_functions_eax, eax;@@ -510,6 +531,11 @@ static void __init ms_hyperv_init_platform(void)hv_identify_partition_type (); +#ifndef CONFIG_X86_FRED +if (hv_root_partition ()) +hv_reserve_irq_vectors (); +#endif /* CONFIG_X86_FRED */ +if (cc_platform_has (CC_ATTR_SNP_SECURE_AVIC )) ms_hyperv.hints |=HV_DEPRECATING_AEOI_RECOMMENDED ;Signature · 1 line
2.51.2.vfs.0.1
H. Peter Anvin
reviewerQuoted 7 lines · Wei Liu
I briefly looked up FRED and checked the code. I understand that once it is enabled, Linux kernel doesn't setup the IDT anymore (code in
arch/x86/kernel/traps.c).My question is, do we need to do anything when FRED is enabled?
Assuming you don't need them handled in any specific way, then you don't. INT instructions are treated completely separately from hardware interrupts in FRED, and so they cannot be confused.
By default they will emulate a #GP(0) just as if an INT instruction had been executed in user space with the DPL of the corresponding interrupt gate < 3; this is currently the case for interrupt vectors other than 3, 4, and 0x80 (which are handled in fred_intx).
Any INT instruction in kernel space will end up in fred_bad_type().
-hpa
Quoted 52 lines · Mukesh Rathor
MSVC compiler, used to compile the Microsoft Hyper-V hypervisor currently, has an assert intrinsic that uses interrupt vector
0x29to create an exception. This will cause hypervisor to then crash and collect core. As such, if this interrupt number is assigned to a device by linux and the device generates it, hypervisor will crash. There are two other such vectors hard coded in the hypervisor,0x2Cand0x2Dfor debug purposes. Fortunately, the three vectors are part of the kernel driver space and that makes it feasible to reserve them early so they are not assigned later.Signed-off-by Mukesh Rathor <[email protected]>---
v1: Add ifndef
CONFIG_X86_FRED(thanks hpa)arch/x86/kernel/cpu/mshyperv.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)arch/x86/kernel/cpu/mshyperv.c +21
-0@@ -478,6 +478,27 @@ int hv_get_hypervisor_version(union hv_hypervisor_version_info *info) }EXPORT_SYMBOL_GPL (hv_get_hypervisor_version); +#ifndef CONFIG_X86_FRED +/* +* Reserve vectors hard coded in the hypervisor. If used outside, the hypervisor +* will crash or hang or break into debugger. +*/ +static void hv_reserve_irq_vectors (void ) +{ +#define HYPERV_DBG_FASTFAIL_VECTOR 0x29 +#define HYPERV_DBG_ASSERT_VECTOR 0x2C +#define HYPERV_DBG_SERVICE_VECTOR 0x2D + +if (test_and_set_bit (HYPERV_DBG_ASSERT_VECTOR , system_vectors) || +test_and_set_bit (HYPERV_DBG_SERVICE_VECTOR , system_vectors) || +test_and_set_bit (HYPERV_DBG_FASTFAIL_VECTOR , system_vectors)) +BUG (); + +pr_info ("Hyper-V:reserve vectors: %d %d %d\n" ,HYPERV_DBG_ASSERT_VECTOR , +HYPERV_DBG_SERVICE_VECTOR ,HYPERV_DBG_FASTFAIL_VECTOR ); +} +#endif /* CONFIG_X86_FRED */ +static void __init ms_hyperv_init_platform (void ) {int hv_max_functions_eax, eax;@@ -510,6 +531,11 @@ static void __init ms_hyperv_init_platform(void)
arch/x86/kernel/cpu/mshyperv.c static void __init ms_hyperv_init_platform(void) · line 541
Quoted 10 lines
arch/x86/kernel/cpu/mshyperv.c +5
-0hv_identify_partition_type (); +#ifndef CONFIG_X86_FRED +if (hv_root_partition ()) +hv_reserve_irq_vectors (); +#endif /* CONFIG_X86_FRED */ +if (cc_platform_has (CC_ATTR_SNP_SECURE_AVIC )) ms_hyperv.hints |=HV_DEPRECATING_AEOI_RECOMMENDED ;
Hi Wei,
Ping on this one... this is show stopper. Are we waiting for an ack from someone else on x86 side? If so, pl lmk if you know best person to ping.
Thanks,
-Mukesh
H. Peter Anvin
reviewerQuoted 3 lines · Mukesh Rathor
v1: Add ifndef
CONFIG_X86_FRED(thanks hpa)
It just clicked in my brain.
This must be cpu_feature_enabled() not a static #ifndef. Just because the kernel is compiled with FRED support doesn't mean that it is *using* FRED!
-hpa
Quoted 47 lines
arch/x86/kernel/cpu/mshyperv.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)arch/x86/kernel/cpu/mshyperv.c +26
-0@@ -478,6 +478,27 @@ int hv_get_hypervisor_version(union hv_hypervisor_version_info *info) }EXPORT_SYMBOL_GPL (hv_get_hypervisor_version); +#ifndef CONFIG_X86_FRED +/* +* Reserve vectors hard coded in the hypervisor. If used outside, the hypervisor +* will crash or hang or break into debugger. +*/ +static void hv_reserve_irq_vectors (void ) +{ +#define HYPERV_DBG_FASTFAIL_VECTOR 0x29 +#define HYPERV_DBG_ASSERT_VECTOR 0x2C +#define HYPERV_DBG_SERVICE_VECTOR 0x2D + +if (test_and_set_bit (HYPERV_DBG_ASSERT_VECTOR , system_vectors) || +test_and_set_bit (HYPERV_DBG_SERVICE_VECTOR , system_vectors) || +test_and_set_bit (HYPERV_DBG_FASTFAIL_VECTOR , system_vectors)) +BUG (); + +pr_info ("Hyper-V:reserve vectors: %d %d %d\n" ,HYPERV_DBG_ASSERT_VECTOR , +HYPERV_DBG_SERVICE_VECTOR ,HYPERV_DBG_FASTFAIL_VECTOR ); +} +#endif /* CONFIG_X86_FRED */ +static void __init ms_hyperv_init_platform (void ) {int hv_max_functions_eax, eax;@@ -510,6 +531,11 @@ static void __init ms_hyperv_init_platform(void)hv_identify_partition_type (); +#ifndef CONFIG_X86_FRED +if (hv_root_partition ()) +hv_reserve_irq_vectors (); +#endif /* CONFIG_X86_FRED */ +if (cc_platform_has (CC_ATTR_SNP_SECURE_AVIC )) ms_hyperv.hints |=HV_DEPRECATING_AEOI_RECOMMENDED ;
Quoted 2 lines · Mukesh Rathor
+#ifndef
CONFIG_X86_FRED
This #ifndef is broken. A FRED enabled kernel is no guarantee that the CPU has FRED. So this has to be unconditional.
arch/x86/kernel/cpu/mshyperv.c int hv_get_hypervisor_version(union hv_hypervisor_version_info *info) · line 490
Quoted 8 lines
+ * Reserve vectors hard coded in the hypervisor. If used outside, the hypervisor
+ * will crash or hang or break into debugger.
+ */arch/x86/kernel/cpu/mshyperv.c +5
-0+static void hv_reserve_irq_vectors (void ) +{ +#define HYPERV_DBG_FASTFAIL_VECTOR 0x29 +#define HYPERV_DBG_ASSERT_VECTOR 0x2C +#define HYPERV_DBG_SERVICE_VECTOR 0x2D
As FRED does not need this bit fiddling you want:
if (cpu_feature_enabled(X86_FEATURE_FRED))
return;right here.
arch/x86/kernel/cpu/mshyperv.c int hv_get_hypervisor_version(union hv_hypervisor_version_info *info) · line 496
Quoted 5 lines
arch/x86/kernel/cpu/mshyperv.c +5
-0+if (test_and_set_bit (HYPERV_DBG_ASSERT_VECTOR , system_vectors) || +test_and_set_bit (HYPERV_DBG_SERVICE_VECTOR , system_vectors) || +test_and_set_bit (HYPERV_DBG_FASTFAIL_VECTOR , system_vectors)) +BUG (); +
Thanks,
tglx