[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20171108091323.kidsiiim2mqenphf@gmail.com>
Date: Wed, 8 Nov 2017 10:13:23 +0100
From: Ingo Molnar <mingo@...nel.org>
To: Juergen Gross <jgross@...e.com>
Cc: linux-kernel@...r.kernel.org, x86@...nel.org, kvm@...r.kernel.org,
xen-devel@...ts.xenproject.org, tglx@...utronix.de,
mingo@...hat.com, hpa@...or.com, boris.ostrovsky@...cle.com,
pbonzini@...hat.com, rkrcmar@...hat.com, rjw@...ysocki.net,
len.brown@...el.com, pavel@....cz
Subject: Re: [PATCH 2/3] x86: add guest_late_init hook to hypervisor_x86
structure
* Juergen Gross <jgross@...e.com> wrote:
> Add a new guest_late_init hook to the hypervisor_x86 structure. It
> will replace the current kvm_guest_init() call which is changed to
> make use of the new hook.
>
> Signed-off-by: Juergen Gross <jgross@...e.com>
> ---
> arch/x86/include/asm/hypervisor.h | 11 +++++++++++
> arch/x86/include/asm/kvm_para.h | 2 --
> arch/x86/kernel/kvm.c | 3 ++-
> arch/x86/kernel/setup.c | 2 +-
> 4 files changed, 14 insertions(+), 4 deletions(-)
>
> diff --git a/arch/x86/include/asm/hypervisor.h b/arch/x86/include/asm/hypervisor.h
> index 0ead9dbb9130..37320687b8cb 100644
> --- a/arch/x86/include/asm/hypervisor.h
> +++ b/arch/x86/include/asm/hypervisor.h
> @@ -38,6 +38,9 @@ struct hypervisor_x86 {
> /* Platform setup (run once per boot) */
> void (*init_platform)(void);
>
> + /* Guest late init */
> + void (*guest_late_init)(void);
> +
> /* X2APIC detection (run once per boot) */
> bool (*x2apic_available)(void);
>
> @@ -66,9 +69,17 @@ static inline void hypervisor_init_mem_mapping(void)
> if (x86_hyper && x86_hyper->init_mem_mapping)
> x86_hyper->init_mem_mapping();
> }
> +
> +static inline void hypervisor_guest_late_init(void)
> +{
> + if (x86_hyper && x86_hyper->guest_late_init)
> + x86_hyper->guest_late_init();
> +}
> +
> #else
> static inline void init_hypervisor_platform(void) { }
> static inline bool hypervisor_x2apic_available(void) { return false; }
> static inline void hypervisor_init_mem_mapping(void) { }
> +static inline void hypervisor_guest_late_init(void) { }
> #endif /* CONFIG_HYPERVISOR_GUEST */
> #endif /* _ASM_X86_HYPERVISOR_H */
> diff --git a/arch/x86/include/asm/kvm_para.h b/arch/x86/include/asm/kvm_para.h
> index c373e44049b1..7b407dda2bd7 100644
> --- a/arch/x86/include/asm/kvm_para.h
> +++ b/arch/x86/include/asm/kvm_para.h
> @@ -88,7 +88,6 @@ static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
> #ifdef CONFIG_KVM_GUEST
> bool kvm_para_available(void);
> unsigned int kvm_arch_para_features(void);
> -void __init kvm_guest_init(void);
> void kvm_async_pf_task_wait(u32 token, int interrupt_kernel);
> void kvm_async_pf_task_wake(u32 token);
> u32 kvm_read_and_reset_pf_reason(void);
> @@ -103,7 +102,6 @@ static inline void kvm_spinlock_init(void)
> #endif /* CONFIG_PARAVIRT_SPINLOCKS */
>
> #else /* CONFIG_KVM_GUEST */
> -#define kvm_guest_init() do {} while (0)
> #define kvm_async_pf_task_wait(T, I) do {} while(0)
> #define kvm_async_pf_task_wake(T) do {} while(0)
>
> diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
> index 8bb9594d0761..d331b5060aa9 100644
> --- a/arch/x86/kernel/kvm.c
> +++ b/arch/x86/kernel/kvm.c
> @@ -465,7 +465,7 @@ static void __init kvm_apf_trap_init(void)
> update_intr_gate(X86_TRAP_PF, async_page_fault);
> }
>
> -void __init kvm_guest_init(void)
> +static void __init kvm_guest_init(void)
> {
> int i;
>
> @@ -548,6 +548,7 @@ const struct hypervisor_x86 x86_hyper_kvm __refconst = {
> .name = "KVM",
> .detect = kvm_detect,
> .x2apic_available = kvm_para_available,
> + .guest_late_init = kvm_guest_init,
> };
> EXPORT_SYMBOL_GPL(x86_hyper_kvm);
>
> diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
> index 0957dd73d127..578569481d87 100644
> --- a/arch/x86/kernel/setup.c
> +++ b/arch/x86/kernel/setup.c
> @@ -1294,7 +1294,7 @@ void __init setup_arch(char **cmdline_p)
>
> io_apic_init_mappings();
>
> - kvm_guest_init();
> + hypervisor_guest_late_init();
No principal objections, but could we please use a more obvious pattern showing
that this is a callback, by calling it directly:
x86_hyper->guest_late_init();
Plus add a default empty function (which hypervisors can override). This avoids
all the hidden conditions and wrappery.
Thanks,
Ingo
Powered by blists - more mailing lists