x86: Add the support of ACRN guest under arch/x86
Subsystems (4)
v3 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
Zhao Yakui (4):
x86: Add new config symbol to unify conditional definition of
hv_irq_callback_count
x86: Add the support of ACRN guest
x86: Use HYPERVISOR_CALLBACK_VECTOR for acrn_guest upcall vector
x86: Add hypercall for acrn_guest
arch/x86/Kconfig | 12 +++++ arch/x86/entry/entry_64.S | 5 +++ arch/x86/include/asm/acrn_hypercall.h | 82 +++++++++++++++++++++++++++++++++++ arch/x86/include/asm/acrnhyper.h | 19 ++++++++ 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 | 57 ++++++++++++++++++++++++ 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, 185 insertions(+), 2 deletions(-) create mode 100644 arch/x86/include/asm/acrn_hypercall.h create mode 100644 arch/x86/include/asm/acrnhyper.h create mode 100644 arch/x86/kernel/cpu/acrn.c
Signature · 1 line
2.7.4
RFC PATCH v3 1/4 x86: Add new config symbol to unify conditional definition of hv_irq_callback_count
Now the CONFIG_HYPERV and CONFIG_XEN can be used to control the definition /usage of hv_irq_callback_count. If another linux guest also needs to use the hv_irq_callback_count, current conditional definition looks unreadable.
--- 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
Re: [RFC PATCH v3 1/4] x86: Add new config symbol to unify conditional definition of hv_irq_callback_count
Subject: x86/kconfig: Add ...
Quoted 3 lines · Zhao Yakui
Now the
CONFIG_HYPERVandCONFIG_XENcan be used to control the definition /usage ofhv_irq_callback_count. If another linux guest also needs to use thehv_irq_callback_count, current conditional definition looks unreadable.
Rewrite that to:
"Add a special Kconfig symbol X86_HV_CALLBACK_VECTOR which 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."
with that fixed you can add:
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.Re: [RFC PATCH v3 1/4] x86: Add new config symbol to unify conditional definition of hv_irq_callback_count
Quoted 13 lines · Borislav Petkov
Subject: x86/kconfig: Add ...
Quoted 3 lines · Zhao Yakui
Now the
CONFIG_HYPERVandCONFIG_XENcan be used to control the definition /usage ofhv_irq_callback_count. If another linux guest also needs to use thehv_irq_callback_count, current conditional definition looks unreadable.Rewrite that to:
"Add a special
KconfigsymbolX86_HV_CALLBACK_VECTORwhich guests using the hypervisor interrupt callback counter can select and thus enable that counter. Select it when xen or hyperv support is enabled.
Quoted 5 lines
No functional changes."
with that fixed you can add:
Reviewed-by Borislav Petkov <[email protected]>
Thanks for your review.
Will update the title and commit log as you suggested.
Thanks
Quoted 3 lines
Thx.
RFC PATCH v3 2/4 x86: Add the support of ACRN guest
In reply to Zhao YakuiACRN is an open-source hypervisor maintained by Linuxfoundation. This is to add the Linux guest support on acrn-hypervisor.
Add x86_hyper_acrn into supported hypervisors array, which enables Linux ACRN guest running on ACRN hypervisor. It is restricted to X86_64.
---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
--- arch/x86/Kconfig | 8 ++++++++ arch/x86/include/asm/hypervisor.h | 1 + arch/x86/kernel/cpu/Makefile | 1 + arch/x86/kernel/cpu/acrn.c | 35 +++++++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/hypervisor.c | 4 ++++ 5 files changed, 49 insertions(+) create mode 100644 arch/x86/kernel/cpu/acrn.c
arch/x86/Kconfig +8 -0
@@ -845,6 +845,14 @@ 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. + 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 +35 -0
@@ -0,0 +1,35 @@ +// 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 ) +{ +/* do not support x2apic */ +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
Borislav Petkov
maintainerRe: [RFC PATCH v3 2/4] x86: Add the support of ACRN guest
Quoted 1 line · Zhao Yakui
ACRN is an open-source hypervisor maintained by Linuxfoundation.
I think tglx wanted to say "by the Linux Foundation" here.
Quoted 1 line
This is to add the Linux guest support on acrn-hypervisor.
I think you were told already:
"Please do not use 'This is to add' or 'This adds'. Just say:
Add ...."
So please take your time, work in *all* review feedback instead of hurrying the next version out without addressing all review comments.
Quoted 2 lines
Add
x86_hyper_acrninto supported hypervisors array, which enables Linux ACRN guest running on ACRN hypervisor. It is restricted toX86_64.
So this all talks about *what* the patch does. But that is visible from the diff below and doesn't belong in the commit message.
Rather, your commit message should talk about *why* a change is being done.
Quoted 23 lines
Co-developed-by Jason Chen CJ <[email protected]>Signed-off-by Jason Chen CJ <[email protected]>Signed-off-by Zhao Yakui <[email protected]>---
v1->v2: Change theCONFIG_ACRNtoCONFIG_ACRN_GUEST, which makes it easy to understand.
Remove the export ofx86_hyper_acrn.
v2->v3: Remove the unnecessary dependency of PARAVIRT--- arch/x86/Kconfig | 8 ++++++++ arch/x86/include/asm/hypervisor.h | 1 + arch/x86/kernel/cpu/Makefile | 1 + arch/x86/kernel/cpu/acrn.c | 35 +++++++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/hypervisor.c | 4 ++++ 5 files changed, 49 insertions(+) create mode 100644 arch/x86/kernel/cpu/acrn.carch/x86/Kconfig +0
-0
arch/x86/Kconfig config JAILHOUSE_GUEST · line 854
Quoted 10 lines
arch/x86/Kconfig +7
-0@@ -845,6 +845,14 @@ 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.
WARNING: please write a paragraph that describes the config symbol fully #47: FILE: arch/x86/Kconfig:848:
+config ACRN_GUEST
That help text above could use some of the explanation what ACRN is from your 0/4 message.
Quoted 49 lines
arch/x86/Kconfig +1
-0+ 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 +15
-0@@ -0,0 +1,35 @@ +// 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 ) +{
arch/x86/kernel/cpu/acrn.c line 25
Quoted 10 lines
arch/x86/kernel/cpu/acrn.c new file +10
-0+return hypervisor_cpuid_base ("ACRNACRNACRN\0\0" ,0 ); +} + +static void __init acrn_init_platform (void ) +{ +} + +static bool acrn_x2apic_available (void ) +{ +/* do not support x2apic */
Why?
This comment could explain why that choice has been made.
Signature · 4 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.Re: [RFC PATCH v3 2/4] x86: Add the support of ACRN guest
Quoted 4 lines · Borislav Petkov
Quoted 1 line · Zhao Yakui
ACRN is an open-source hypervisor maintained by Linuxfoundation.
I think tglx wanted to say "by the Linux Foundation" here.
Sure. It will be fixed.
Quoted 12 lines
Quoted 2 lines
This is to add the Linux guest support on acrn-hypervisor.
I think you were told already:
"Please do not use 'This is to add' or 'This adds'. Just say:
Add ...."
So please take your time, work in *all* review feedback instead of hurrying the next version out without addressing all review comments.
Quoted 8 lines
Quoted 2 lines
Add
x86_hyper_acrninto supported hypervisors array, which enables Linux ACRN guest running on ACRN hypervisor. It is restricted toX86_64.So this all talks about *what* the patch does. But that is visible from the diff below and doesn't belong in the commit message.
Rather, your commit message should talk about *why* a change is being done.
I will refine the commit log and only talk about "why" a changed is added.
Quoted 39 lines
Quoted 24 lines
Co-developed-by Jason Chen CJ <[email protected]>Signed-off-by Jason Chen CJ <[email protected]>Signed-off-by Zhao Yakui <[email protected]>---
v1->v2: Change theCONFIG_ACRNtoCONFIG_ACRN_GUEST, which makes it easy to understand.
Remove the export ofx86_hyper_acrn.
v2->v3: Remove the unnecessary dependency of PARAVIRT--- arch/x86/Kconfig | 8 ++++++++ arch/x86/include/asm/hypervisor.h | 1 + arch/x86/kernel/cpu/Makefile | 1 + arch/x86/kernel/cpu/acrn.c | 35 +++++++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/hypervisor.c | 4 ++++ 5 files changed, 49 insertions(+)create mode 100644
arch/x86/kernel/cpu/acrn.carch/x86/Kconfig +0
-0arch/x86/Kconfig config JAILHOUSE_GUEST · line 854
Quoted 10 lines
arch/x86/Kconfig +7
-0@@ -845,6 +845,14 @@ 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.WARNING: please write a paragraph that describes the config symbol fully #47: FILE:
arch/x86/Kconfig:848:
+configACRN_GUEST
Quoted 3 lines
That help text above could use some of the explanation what ACRN is from your 0/4 message.
Make sense. I will add some description in patch 0 for the Kconfig description.
Quoted 62 lines
Quoted 49 lines
arch/x86/Kconfig +1
-0+ 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 +15
-0@@ -0,0 +1,35 @@ +// 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 ) +{arch/x86/kernel/cpu/acrn.c line 25
Quoted 10 lines
arch/x86/kernel/cpu/acrn.c new file +10
-0+return hypervisor_cpuid_base ("ACRNACRNACRN\0\0" ,0 ); +} + +static void __init acrn_init_platform (void ) +{ +} + +static bool acrn_x2apic_available (void ) +{ +/* do not support x2apic */ Why?
Quoted 2 lines
This comment could explain why that choice has been made.
Currently the x2apic is not enabled in the first step.
Next step it needs to check the cpu info reported by ACRN hypervisor to determine whether the x2apic should be supported. How about using the below comments?
" x2apic is not supported now. Later it will check the cpu info to determine whether the x2apic can be supported or not."
Thanks
Borislav Petkov
maintainerRe: [RFC PATCH v3 2/4] x86: Add the support of ACRN guest
Quoted 3 lines · Yakui
Currently the x2apic is not enabled in the first step.
Next step it needs to check the cpu info reported by ACRN hypervisor to determine whether the x2apic should be supported.
What "cpu info"? CPUID or something ACRN-specific?
Signature · 4 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.Re: [RFC PATCH v3 2/4] x86: Add the support of ACRN guest
Quoted 6 lines · Borislav Petkov
Quoted 3 lines · Yakui
Currently the x2apic is not enabled in the first step.
Next step it needs to check the cpu info reported by ACRN hypervisor to determine whether the x2apic should be supported.What "cpu info"? CPUID or something ACRN-specific?
It is based on CPUID.
The low-level ACRN hypervisor can return the different output of CPUID when several linux guests executes the CPUID instruction. Then it can control whether x2apic is supported in one linux guest.
So we will leverage the X86_FEATURE_X2APIC bit from CPUID to indicate whether the x2apic is supported in linux guest when ACRN hypervisor is detected. Is this fine to you?
Thanks
Quoted 1 line
Borislav Petkov
maintainerRe: [RFC PATCH v3 2/4] x86: Add the support of ACRN guest
Quoted 4 lines · Yakui
So we will leverage the
X86_FEATURE_X2APICbit from CPUID to indicate whether the x2apic is supported in linux guest when ACRN hypervisor is detected.
Is this fine to you?
Yes, put that more precise info in the comment pls.
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.RFC PATCH v3 3/4 x86: 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.
--- arch/x86/Kconfig | 1 + arch/x86/entry/entry_64.S | 5 +++++ arch/x86/include/asm/acrnhyper.h | 19 +++++++++++++++++++ arch/x86/kernel/cpu/acrn.c | 22 ++++++++++++++++++++++ 4 files changed, 47 insertions(+) create mode 100644 arch/x86/include/asm/acrnhyper.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/acrnhyper.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_X86_ACRNHYPER_H +#define _ASM_X86_ACRNHYPER_H + +#include <linux/types.h> +#include <linux/atomic.h> +#include <linux/nmi.h> +#include <asm/io.h> + +#ifdef CONFIG_ACRN_GUEST +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 + +#endif
arch/x86/kernel/cpu/acrn.c +22 -0
@@ -9,7 +9,11 @@* */ +#include <linux/interrupt.h> #include <asm/hypervisor.h> +#include <asm/acrnhyper.h> +#include <asm/desc.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 )
@@ -26,6 +32,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
Borislav Petkov
maintainerRe: [RFC PATCH v3 3/4] x86: Use HYPERVISOR_CALLBACK_VECTOR for acrn_guest upcall vector
You can prefix your subject now like this:
x86/acrn: Use ...
arch/x86/include/asm/acrnhyper.h
Quoted 55 lines · Zhao Yakui
Linux kernel uses the
HYPERVISOR_CALLBACK_VECTORfor 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.Co-developed-by Jason Chen CJ <[email protected]>Signed-off-by Jason Chen CJ <[email protected]>Signed-off-by Zhao Yakui <[email protected]>---
V1->V2: Remove the unused API definition ofacrn_setup_intr_handlerandacrn_remove_intr_handler.
Adjust the order of header file
Add the declaration ofacrn_hv_vector_handlerand tracing
definition ofacrn_hv_callback_vector.--- arch/x86/Kconfig | 1 + arch/x86/entry/entry_64.S | 5 +++++ arch/x86/include/asm/acrnhyper.h | 19 +++++++++++++++++++ arch/x86/kernel/cpu/acrn.c | 22 ++++++++++++++++++++++ 4 files changed, 47 insertions(+) create mode 100644 arch/x86/include/asm/acrnhyper.harch/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 underarch/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=1arch/x86/include/asm/acrnhyper.h new file +0
-0
Simply
.../acrn.h
I'd say.
arch/x86/include/asm/acrnhyper.h line 10
Quoted 11 lines
arch/x86/include/asm/acrnhyper.h new file +10
-0@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_X86_ACRNHYPER_H +#define _ASM_X86_ACRNHYPER_H + +#include <linux/types.h> +#include <linux/atomic.h> +#include <linux/nmi.h> +#include <asm/io.h> + +#ifdef CONFIG_ACRN_GUEST
Why is that ifdef needed?
arch/x86/include/asm/acrnhyper.h line 16
Quoted 6 lines
arch/x86/include/asm/acrnhyper.h new file +6
-0+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);
end marker:
#endif /* _ASM_X86_ACRNHYPER_H */
arch/x86/kernel/cpu/acrn.c line 16
Quoted 13 lines
arch/x86/kernel/cpu/acrn.c +4
-0@@ -9,7 +9,11 @@* */ +#include <linux/interrupt.h> #include <asm/hypervisor.h> +#include <asm/acrnhyper.h> +#include <asm/desc.h> +#include <asm/irq_regs.h>
What's the sorting order here? Length or alphabetic? Or none? :)
linux/ path includes still need to come first, of course.
Signature · 4 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.Re: [RFC PATCH v3 3/4] x86: Use HYPERVISOR_CALLBACK_VECTOR for acrn_guest upcall vector
Quoted 3 lines · Borislav Petkov
You can prefix your subject now like this:
x86/acrn: Use ...
Thanks for suggestion.
It will be updated in next version.
Quoted 60 lines · Zhao Yakui
arch/x86/include/asm/acrnhyper.h
Quoted 55 lines
Linux kernel uses the
HYPERVISOR_CALLBACK_VECTORfor 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.Co-developed-by Jason Chen CJ <[email protected]>Signed-off-by Jason Chen CJ <[email protected]>Signed-off-by Zhao Yakui <[email protected]>---
V1->V2: Remove the unused API definition ofacrn_setup_intr_handlerandacrn_remove_intr_handler.
Adjust the order of header file
Add the declaration ofacrn_hv_vector_handlerand tracing
definition ofacrn_hv_callback_vector.--- arch/x86/Kconfig | 1 + arch/x86/entry/entry_64.S | 5 +++++ arch/x86/include/asm/acrnhyper.h | 19 +++++++++++++++++++ arch/x86/kernel/cpu/acrn.c | 22 ++++++++++++++++++++++ 4 files changed, 47 insertions(+)create mode 100644
arch/x86/include/asm/acrnhyper.harch/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 underarch/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=1arch/x86/include/asm/acrnhyper.h new file +0
-0Simply
Quoted 3 lines
.../acrn.hI'd say.
OK. The simplifed file name(acrn.h) will be used in next version.
Quoted 14 lines
arch/x86/include/asm/acrnhyper.h line 10
Quoted 12 lines
arch/x86/include/asm/acrnhyper.h new file +10
-0@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_X86_ACRNHYPER_H +#define _ASM_X86_ACRNHYPER_H + +#include <linux/types.h> +#include <linux/atomic.h> +#include <linux/nmi.h> +#include <asm/io.h> + +#ifdef CONFIG_ACRN_GUEST Why is that ifdef needed?
It is used to avoid that one function declaration has no definition when asm/acrnhyper.h is included and ACRN_GUEST is not enabled.
Quoted 11 lines
arch/x86/include/asm/acrnhyper.h line 16
Quoted 7 lines
arch/x86/include/asm/acrnhyper.h new file +6
-0+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);end marker:
#endif /*
_ASM_X86_ACRNHYPER_H*/
It will be added in next version.
Quoted 9 lines
Quoted 9 lines
arch/x86/kernel/cpu/acrn.c +0
-0@@ -9,7 +9,11 @@* */
Quoted 7 lines
arch/x86/kernel/cpu/acrn.c line 16
Quoted 5 lines
arch/x86/kernel/cpu/acrn.c +4
-0+#include <linux/interrupt.h> #include <asm/hypervisor.h> +#include <asm/acrnhyper.h> +#include <asm/desc.h> +#include <asm/irq_regs.h> What's the sorting order here? Length or alphabetic? Or none? :)
Sorry that I don't consider the oder.
The required new header file is appended one by one. Of course linux/ path and asm / are appended separately. Do you have any suggestion about the header order?
Quoted 3 lines
linux/ path includes still need to come first, of course.
Borislav Petkov
maintainerRe: [RFC PATCH v3 3/4] x86: Use HYPERVISOR_CALLBACK_VECTOR for acrn_guest upcall vector
Quoted 2 lines · Yakui
It is used to avoid that one function declaration has no definition when
asm/acrnhyper.his included andACRN_GUESTis not enabled.
And that is a problem because...?
Quoted 3 lines
Do you have any suggestion about the header order?
Quoted 2 lines
linux/ path includes still need to come first, of course.
As said above:
linux/ path first, then asm/
Feel free to look around the tree for inspiration :)
Signature · 4 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.Re: [RFC PATCH v3 3/4] x86: Use HYPERVISOR_CALLBACK_VECTOR for acrn_guest upcall vector
Quoted 5 lines · Borislav Petkov
Quoted 2 lines · Yakui
It is used to avoid that one function declaration has no definition when
asm/acrnhyper.his included andACRN_GUESTis not enabled.And that is a problem because...?
This is not a problem.
I take a look at the header file of mshyperv.h and xen/events.h. It seems that they have no such extra conditional definition. To follow the same style, I will remove it.
Quoted 10 lines
Quoted 4 lines
Do you have any suggestion about the header order?
Quoted 2 lines
linux/ path includes still need to come first, of course.
As said above:
linux/ path first, then asm/
Feel free to look around the tree for inspiration :)
I take a look at the file of vwmare.c/mshyperv.c under the directory of arch/x86/kernel/cpu. It seems that the header file only follows the order of: linux/ path first and then asm/.
Anyway, I will follow your idea in previous email and use the alphabetic order.
Thanks
Quoted 1 line
Borislav Petkov
maintainerRe: [RFC PATCH v3 3/4] x86: Use HYPERVISOR_CALLBACK_VECTOR for acrn_guest upcall vector
Quoted 4 lines · Yakui
This is not a problem.
I take a look at the header file ofmshyperv.handxen/events.h. It seems that they have no such extra conditional definition. To follow the same style, I will remove it.
Yes, the less ifdeffery the better. If it is not really needed.
Signature · 4 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.RFC PATCH v3 4/4 x86: 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 system.
So the hypercall is added so that the kernel can communicate with the low-level acrn-hypervisor. On x86 it is implemented by using vmacll when the acrn hypervisor is enabled.
---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
--- arch/x86/include/asm/acrn_hypercall.h | 82 +++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 arch/x86/include/asm/acrn_hypercall.h
arch/x86/include/asm/acrn_hypercall.h new file +82 -0
@@ -0,0 +1,82 @@ +/* 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" ); + +/* vmcall is used to implment the hypercall. +* 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 + +#endif /* _ASM_X86_ACRNHYPERCALL_H */
Signature · 1 line
2.7.4
Borislav Petkov
maintainerRe: [RFC PATCH v3 4/4] x86: Add hypercall for acrn_guest
Quoted 4 lines · Zhao Yakui
When
acrn_hypervisoris 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 system.
Good example.
What is "Guest system" and why is capitalized? Do you mean "the guest operating system" or simply "the guest"?
Quoted 1 line
So the hypercall is added so that the kernel can communicate with the
"So add the hypercall so that... "
Quoted 1 line
low-level acrn-hypervisor.
Is it acrn_hypervisor or acrn-hypervisor or the ACRN hypervisor or ...?
Unify the naming pls.
Quoted 1 line
On x86 it is implemented by using vmacll when
During last review Thomas said:
"is implemented with the VMCALL instruction"
You still have it wrong. Which makes me think you haven't even gone over *all* review comments as this is the second missed review comment in a 4-patches set.
So I'm going to stop reviewing here and won't look at your patches until you incorporate *all* review comments from all people.
Signature · 4 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.Re: [RFC PATCH v3 4/4] x86: Add hypercall for acrn_guest
Quoted 10 lines · Borislav Petkov
Quoted 4 lines · Zhao Yakui
When
acrn_hypervisoris 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 system.Good example.
What is "Guest system" and why is capitalized? Do you mean "the guest operating system" or simply "the guest"?
it means the "guest operating system".
It will be changed to "guest operating system".
Quoted 10 lines
Quoted 2 lines
So the hypercall is added so that the kernel can communicate with the
"So add the hypercall so that..."
Quoted 1 line
low-level acrn-hypervisor.
Is it
acrn_hypervisoror acrn-hypervisor or the ACRN hypervisor or ...?Unify the naming pls.
Sure. They will be unified to "ACRN hypervisor" in next version.
Quoted 14 lines
Quoted 2 lines
On x86 it is implemented by using vmacll when
During last review Thomas said:
"is implemented with the VMCALL instruction"
You still have it wrong. Which makes me think you haven't even gone over *all* review comments as this is the second missed review comment in a 4-patches set.
So I'm going to stop reviewing here and won't look at your patches until you incorporate *all* review comments from all people.