x86: Add the support of ACRN guest under arch/x86
Subsystems (4)
v4 cover x86: Add the support of ACRN guest under arch/x86
ACRN is a flexible, lightweight reference hypervisor, built with real-time and safety-criticality in mind, optimized to streamline embedded development through an open source platform. It is built for embedded IOT with small footprint and real-time features. More details can be found
in https://projectacrn.org/
This is the patch set that allows the Linux to work on ACRN hypervisor and it can work with the following patch set to manage the Linux guest on acrn-hypervisor. It includes the detection of acrn_hypervisor, upcall notification vector from hypervisor, hypercall. The hypervisor detection is similar to Xen/VMWARE/Hyperv. ACRN also uses the upcall notification mechanism similar to that in Xen/Microsoft HyperV when it needs to send the notification to Linux OS. The hypercall provides the mechanism that can be used to query/configure the acrn-hypervisor by Linux guest.
Following this patch set, we will send acrn driver part, which provides the interface that can be used to manage the virtualized CPU/memory/device/interrupt for other guest OS after the acrn hypervisor is detected.
v1->v2: Change the CONFIG_ACRN to CONFIG_ACRN_GUEST, which makes it easy to understand.
Remove the export of x86_hyper_acrn.
Remove the unused API definition of acrn_setup_intr_handler andacrn_remove_intr_handler.
Adjust the order of header file
Add the declaration of acrn_hv_vector_handler and tracing
definition of acrn_hv_callback_vector.
Refine the comments for the function of acrn_hypercall0/1/2
v2-v3: Add one new config symbol to unify the conditional definition of hv_irq_callback_count
Use the "vmcall" mnemonic to replace the hard-code byte definition Remove the unnecessary dependency of CONFIG_PARAVIRT for ACRN_GUEST
v3-v4: Rename the file name of acrnhyper.h to acrn.h
Refine the commit log and some other minor changes(more comments and
redundant ifdef in acrn.h, sorting the header file in acrn.c)
Zhao Yakui (4):
x86/Kconfig: Add new config symbol to unify conditional definition of
hv_irq_callback_count
x86: Add the support of Linux guest on ACRN hypervisor x86/acrn: Use HYPERVISOR_CALLBACK_VECTOR for ACRN guest upcall vector x86/acrn: Add hypercall for ACRN guest
arch/x86/Kconfig | 16 +++++++ arch/x86/entry/entry_64.S | 5 +++ arch/x86/include/asm/acrn.h | 11 +++++ arch/x86/include/asm/acrn_hypercall.h | 81 +++++++++++++++++++++++++++++++++++ arch/x86/include/asm/hardirq.h | 2 +- arch/x86/include/asm/hypervisor.h | 1 + arch/x86/kernel/cpu/Makefile | 1 + arch/x86/kernel/cpu/acrn.c | 61 ++++++++++++++++++++++++++ arch/x86/kernel/cpu/hypervisor.c | 4 ++ arch/x86/kernel/irq.c | 2 +- arch/x86/xen/Kconfig | 1 + drivers/hv/Kconfig | 1 + 12 files changed, 184 insertions(+), 2 deletions(-) create mode 100644 arch/x86/include/asm/acrn.h create mode 100644 arch/x86/include/asm/acrn_hypercall.h create mode 100644 arch/x86/kernel/cpu/acrn.c
Signature · 1 line
2.7.4
RFC PATCH v4 1/4 x86/Kconfig: Add new config symbol to unify conditional definition of hv_irq_callback_count
Add a special Kconfig symbol X86_HV_CALLBACK_VECTOR so that the guests using the hypervisor interrupt callback counter can select and thus enable that counter. Select it when xen or hyperv support is enabled. No functional changes.
---v3->v4: Follow the comments to refine the commit log.
--- arch/x86/Kconfig | 3 +++ arch/x86/include/asm/hardirq.h | 2 +- arch/x86/kernel/irq.c | 2 +- arch/x86/xen/Kconfig | 1 + drivers/hv/Kconfig | 1 + 5 files changed, 7 insertions(+), 2 deletions(-)
arch/x86/Kconfig +3 -0
@@ -791,6 +791,9 @@ config QUEUED_LOCK_STAT behavior of paravirtualized queued spinlocks and report them on debugfs. +config X86_HV_CALLBACK_VECTOR + def_bool n + source "arch/x86/xen/Kconfig" config KVM_GUEST
arch/x86/include/asm/hardirq.h +1 -1
@@ -37,7 +37,7 @@ typedef struct {#ifdef CONFIG_X86_MCE_AMD unsigned int irq_deferred_error_count;#endif -#if IS_ENABLED (CONFIG_HYPERV ) || defined(CONFIG_XEN ) +#ifdef CONFIG_X86_HV_CALLBACK_VECTOR unsigned int irq_hv_callback_count;#endif #if IS_ENABLED (CONFIG_HYPERV )
arch/x86/kernel/irq.c +1 -1
@@ -134,7 +134,7 @@ int arch_show_interrupts(struct seq_file *p, int prec)seq_printf (p,"%10u " ,per_cpu (mce_poll_count, j));seq_puts (p," Machine check polls\n" );#endif -#if IS_ENABLED (CONFIG_HYPERV ) || defined(CONFIG_XEN ) +#ifdef CONFIG_X86_HV_CALLBACK_VECTOR if (test_bit (HYPERVISOR_CALLBACK_VECTOR , system_vectors)) {seq_printf (p,"%*s: " , prec,"HYP" );for_each_online_cpu (j)
arch/x86/xen/Kconfig +1 -0
@@ -7,6 +7,7 @@ config XEN bool "Xen guest support" depends on PARAVIRT select PARAVIRT_CLOCK + select X86_HV_CALLBACK_VECTOR depends on X86_64 || (X86_32 && X86_PAE) depends on X86_LOCAL_APIC && X86_TSC help
drivers/hv/Kconfig +1 -0
@@ -6,6 +6,7 @@ config HYPERV tristate "Microsoft Hyper-V client drivers" depends on X86 && ACPI && X86_LOCAL_APIC && HYPERVISOR_GUEST select PARAVIRT + select X86_HV_CALLBACK_VECTOR help Select this option to run Linux as a Hyper-V client operating system.
Signature · 1 line
2.7.4
PATCH v4 2/4 x86: Add the support of Linux guest on ACRN hypervisor
In reply to Zhao YakuiACRN is an open-source hypervisor maintained by Linux Foundation. It is built for embedded IOT with small footprint and real-time features. Add the ACRN guest support so that it allows linux to be booted under ACRN hypervisor. Following this patch it will setup the upcall notification vector, enable hypercall and provide the interface that is used to manage the virtualized CPU/memory/device/interrupt for other guest OS.
---v1->v2: Change the CONFIG_ACRN to CONFIG_ACRN_GUEST, which makes it easy to understand.
Remove the export of x86_hyper_acrn.
v2->v3: Remove the unnecessary dependency of PARAVIRT v3->v4: Refine the commit log and add meaningful description in Kconfig
--- arch/x86/Kconfig | 12 ++++++++++++ arch/x86/include/asm/hypervisor.h | 1 + arch/x86/kernel/cpu/Makefile | 1 + arch/x86/kernel/cpu/acrn.c | 39 +++++++++++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/hypervisor.c | 4 ++++ 5 files changed, 57 insertions(+) create mode 100644 arch/x86/kernel/cpu/acrn.c
arch/x86/Kconfig +12 -0
@@ -845,6 +845,18 @@ config JAILHOUSE_GUEST cell. You can leave this option disabled if you only want to start Jailhouse and run Linux afterwards in the root cell. +config ACRN_GUEST + bool "ACRN Guest support" + depends on X86_64 + help + This option allows to run Linux as guest in ACRN hypervisor. Enabling + this will allow the kernel to boot in virtualized environment under + the ACRN hypervisor. + ACRN is a flexible, lightweight reference open-source hypervisor, built + with real-time and safety-criticality in mind. It is built for embedded + IOT with small footprint and real-time features. More details can be + found in https://projectacrn.org/ + endif #HYPERVISOR_GUEST source "arch/x86/Kconfig.cpu"
arch/x86/include/asm/hypervisor.h +1 -0
@@ -29,6 +29,7 @@ enum x86_hypervisor_type {X86_HYPER_XEN_HVM ,X86_HYPER_KVM ,X86_HYPER_JAILHOUSE , + X86_HYPER_ACRN, };#ifdef CONFIG_HYPERVISOR_GUEST
arch/x86/kernel/cpu/Makefile +1 -0
@@ -44,6 +44,7 @@ obj-$(CONFIG_X86_CPU_RESCTRL) += resctrl/ obj-$(CONFIG_X86_LOCAL_APIC) += perfctr-watchdog.o obj-$(CONFIG_HYPERVISOR_GUEST) += vmware.o hypervisor.o mshyperv.o +obj-$(CONFIG_ACRN_GUEST) += acrn.o ifdef CONFIG_X86_FEATURE_NAMES quiet_cmd_mkcapflags = MKCAP $@
arch/x86/kernel/cpu/acrn.c new file +39 -0
@@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* ACRN detection support +* +* Copyright (C) 2019 Intel Corporation. All rights reserved. +* +* Jason Chen CJ <[email protected]> +* Zhao Yakui <[email protected]> +* +*/ + +#include <asm/hypervisor.h> + +static uint32_t __init acrn_detect (void ) +{ +return hypervisor_cpuid_base ("ACRNACRNACRN\0\0" ,0 ); +} + +static void __init acrn_init_platform (void ) +{ +} + +static bool acrn_x2apic_available (void ) +{ +/* x2apic is not supported now. +* Later it needs to check the X86_FEATURE_X2APIC bit of cpu info +* returned by CPUID to determine whether the x2apic is +* supported in Linux guest. +*/ +return false; +} + +const __initconst struct hypervisor_x86 x86_hyper_acrn = { + .name ="ACRN" , + .detect = acrn_detect, + .type =X86_HYPER_ACRN , + .init.init_platform = acrn_init_platform, + .init.x2apic_available = acrn_x2apic_available, +};
arch/x86/kernel/cpu/hypervisor.c +4 -0
@@ -32,6 +32,7 @@ extern const struct hypervisor_x86 x86_hyper_xen_pv;extern const struct hypervisor_x86 x86_hyper_xen_hvm;extern const struct hypervisor_x86 x86_hyper_kvm;extern const struct hypervisor_x86 x86_hyper_jailhouse; +extern const struct hypervisor_x86 x86_hyper_acrn;static const __initconst struct hypervisor_x86 *const hypervisors[] = {
@@ -49,6 +50,9 @@ static const __initconst struct hypervisor_x86 * const hypervisors[] =#ifdef CONFIG_JAILHOUSE_GUEST &x86_hyper_jailhouse,#endif +#ifdef CONFIG_ACRN_GUEST + &x86_hyper_acrn, +#endif };enum x86_hypervisor_type x86_hyper_type;
Signature · 1 line
2.7.4
RFC PATCH v4 3/4 x86/acrn: Use HYPERVISOR_CALLBACK_VECTOR for ACRN guest upcall vector
In reply to Zhao YakuiLinux kernel uses the HYPERVISOR_CALLBACK_VECTOR for hypervisor upcall vector. And it is already used for Xen and HyperV.
After ACRN hypervisor is detected, it will also use this defined vector to notify kernel.
---V1->V2: Remove the unused API definition of acrn_setup_intr_handler and acrn_remove_intr_handler.
Adjust the order of header file
Add the declaration of acrn_hv_vector_handler and tracing
definition of acrn_hv_callback_vector.
v2->v3: Select the X86_HV_CALLBACK_VECTOR for ACRN guest v3->v4: Refine the file name of acrnhyper.h to acrn.h
--- arch/x86/Kconfig | 1 + arch/x86/entry/entry_64.S | 5 +++++ arch/x86/include/asm/acrn.h | 11 +++++++++++ arch/x86/kernel/cpu/acrn.c | 22 ++++++++++++++++++++++ 4 files changed, 39 insertions(+) create mode 100644 arch/x86/include/asm/acrn.h
arch/x86/Kconfig +1 -0
@@ -848,6 +848,7 @@ config JAILHOUSE_GUEST config ACRN_GUEST bool "ACRN Guest support" depends on X86_64 + select X86_HV_CALLBACK_VECTOR help This option allows to run Linux as guest in ACRN hypervisor. Enabling this will allow the kernel to boot in virtualized environment under
arch/x86/entry/entry_64.S +5 -0
@@ -1129,6 +1129,11 @@ apicinterrupt3 HYPERV_STIMER0_VECTOR \ hv_stimer0_callback_vector hv_stimer0_vector_handler #endif /* CONFIG_HYPERV */ +#if IS_ENABLED(CONFIG_ACRN_GUEST) +apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \ + acrn_hv_callback_vector acrn_hv_vector_handler +#endif + idtentry debug do_debug has_error_code=0 paranoid=1 shift_ist=DEBUG_STACK idtentry int3 do_int3 has_error_code=0 idtentry stack_segment do_stack_segment has_error_code=1
arch/x86/include/asm/acrn.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_X86_ACRN_H +#define _ASM_X86_ACRN_H + +void acrn_hv_callback_vector (void ); +#ifdef CONFIG_TRACING +#define trace_acrn_hv_callback_vector acrn_hv_callback_vector +#endif + +void acrn_hv_vector_handler (struct pt_regs *regs); +#endif /* _ASM_X86_ACRN_H */
arch/x86/kernel/cpu/acrn.c +22 -0
@@ -9,7 +9,11 @@* */ +#include <linux/interrupt.h> +#include <asm/acrn.h> +#include <asm/desc.h> #include <asm/hypervisor.h> +#include <asm/irq_regs.h> static uint32_t __init acrn_detect (void ) {
@@ -18,6 +22,8 @@ static uint32_t __init acrn_detect(void)static void __init acrn_init_platform (void ) { +alloc_intr_gate (HYPERVISOR_CALLBACK_VECTOR , + acrn_hv_callback_vector); }static bool acrn_x2apic_available (void )
@@ -30,6 +36,22 @@ static bool acrn_x2apic_available(void)return false; } +static void (*acrn_intr_handler)(void ); + +__visible void __irq_entry acrn_hv_vector_handler(struct pt_regs *regs) +{ +struct pt_regs *old_regs =set_irq_regs (regs); + +entering_ack_irq (); +inc_irq_stat (irq_hv_callback_count); + +if (acrn_intr_handler) +acrn_intr_handler (); + +exiting_irq (); +set_irq_regs (old_regs); +} +const __initconst struct hypervisor_x86 x86_hyper_acrn = { .name ="ACRN" , .detect = acrn_detect,
Signature · 1 line
2.7.4
RFC PATCH v4 4/4 x86/acrn: Add hypercall for ACRN guest
In reply to Zhao YakuiWhen ACRN hypervisor is detected, the hypercall is needed so that the ACRN guest can query/config some settings. For example: it can be used to query the resources in hypervisor and manage the CPU/memory/device/ interrupt for guest operating system.
Add the hypercall so that the kernel can communicate with the low-level ACRN hypervisor. It is implemented with vmacll instruction.
---V1->V2: Refine the comments for the function of acrn_hypercall0/1/2 v2->v3: Use the "vmcall" mnemonic to replace hard-code byte definition v3->v4: refine the commit log(minor change)
--- arch/x86/include/asm/acrn_hypercall.h | 81 +++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 arch/x86/include/asm/acrn_hypercall.h
arch/x86/include/asm/acrn_hypercall.h new file +81 -0
@@ -0,0 +1,81 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _ASM_X86_ACRNHYPERCALL_H +#define _ASM_X86_ACRNHYPERCALL_H + +#include <linux/errno.h> + +#ifdef CONFIG_ACRN_GUEST + +/* +* Hypercalls for ACRN Guest +* +* Hypercall number is passed in r8 register. +* Return value will be placed in rax. +* Up to 2 arguments are passed in rdi, rsi. +*/ + +static inline long acrn_hypercall0 (unsigned long hcall_id) +{ + register unsigned long r8 asm("r8") = hcall_id; + registerlong result asm("rax" ); + +/* the hypercall is implemented with vmcall instruction. +* asm volatile is used to avoid that it is dropped because of +* compiler optimization. +*/ + asmvolatile ("vmcall" + :"=r" (result) + :"r" (r8)); + +return result; +} + +static inline long acrn_hypercall1 (unsigned long hcall_id, +unsigned long param1) +{ + register unsigned long r8 asm("r8") = hcall_id; + registerlong result asm("rax" ); + + asmvolatile ("vmcall" + :"=r" (result) + :"D" (param1),"r" (r8)); + +return result; +} + +static inline long acrn_hypercall2 (unsigned long hcall_id, +unsigned long param1, +unsigned long param2) +{ + register unsigned long r8 asm("r8") = hcall_id; + registerlong result asm("rax" ); + + asmvolatile ("vmcall" + :"=r" (result) + :"D" (param1),"S" (param2),"r" (r8)); + +return result; +} + +#else + +static inline long acrn_hypercall0 (unsigned long hcall_id) +{ +return -ENOTSUPP ; +} + +static inline long acrn_hypercall1 (unsigned long hcall_id, +unsigned long param1) +{ +return -ENOTSUPP ; +} + +static inline long acrn_hypercall2 (unsigned long hcall_id, +unsigned long param1, +unsigned long param2) +{ +return -ENOTSUPP ; +} +#endif /* CONFIG_ACRN_GUEST */ +#endif /* _ASM_X86_ACRNHYPERCALL_H */
Signature · 1 line
2.7.4
Borislav Petkov
maintainerRe: [RFC PATCH v4 4/4] x86/acrn: Add hypercall for ACRN guest
Quoted 7 lines · Zhao Yakui
When ACRN hypervisor is detected, the hypercall is needed so that the ACRN guest can query/config some settings. For example: it can be used to query the resources in hypervisor and manage the CPU/memory/device/ interrupt for guest operating system.
Add the hypercall so that the kernel can communicate with the low-level ACRN hypervisor. It is implemented with vmacll instruction.
This still has unfixed stuff from 2 review cycles ago.
Thomas corrected this in his review to:
"is implemented with the VMCALL instruction"
https://lkml.kernel.org/r/[email protected]
You ignored it.
I reminded you about it and suggested to check and incorporate *all* review feedback before sending another version:
https://lkml.kernel.org/r/[email protected]
You ignored it again.
Now, if you get ignored, you know why, right?
Signature · 4 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.