From: Paolo Bonzini <pbonzini@redhat.com>
To: Pavel Tatashin <pasha.tatashin@oracle.com>,
steven.sistare@oracle.com, daniel.m.jordan@oracle.com,
linux@armlinux.org.uk, schwidefsky@de.ibm.com,
heiko.carstens@de.ibm.com, john.stultz@linaro.org,
sboyd@codeaurora.org, x86@kernel.org,
linux-kernel@vger.kernel.org, mingo@redhat.com,
tglx@linutronix.de, hpa@zytor.com, douly.fnst@cn.fujitsu.com,
peterz@infradead.org, prarit@redhat.com, feng.tang@intel.com,
pmladek@suse.com, gnomes@lxorguk.ukuu.org.uk,
linux-s390@vger.kernel.org
Subject: Re: [PATCH v12 04/11] kvm/x86: remove kvm memblock dependency
Date: Thu, 5 Jul 2018 18:12:03 +0200 [thread overview]
Message-ID: <fc67276e-643d-8a78-29e3-273c6dc79275@redhat.com> (raw)
In-Reply-To: <20180621212518.19914-5-pasha.tatashin@oracle.com>
On 21/06/2018 23:25, Pavel Tatashin wrote:
> KVM clock is initialized later compared to other hypervisor because it has
> dependency on memblock allocator.
>
> Lets bring it inline with other hypervisors by removing this dependency by
> using memory from BSS instead of allocating it.
>
> The benefits:
> - remove ifdef from common code
> - earlier availability of TSC.
> - remove dependency on memblock, and reduce code
> - earlier kvm sched_clock()
>
> Signed-off-by: Pavel Tatashin <pasha.tatashin@oracle.com>
The reason for this is to avoid wasting a lot of BSS memory when KVM is
not in use. Thomas is going to send his take on this!
Paolo
> ---
> arch/x86/kernel/kvm.c | 1 +
> arch/x86/kernel/kvmclock.c | 64 ++++++--------------------------------
> arch/x86/kernel/setup.c | 7 ++---
> 3 files changed, 12 insertions(+), 60 deletions(-)
>
> diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
> index 5b2300b818af..c65c232d3ddd 100644
> --- a/arch/x86/kernel/kvm.c
> +++ b/arch/x86/kernel/kvm.c
> @@ -628,6 +628,7 @@ const __initconst struct hypervisor_x86 x86_hyper_kvm = {
> .name = "KVM",
> .detect = kvm_detect,
> .type = X86_HYPER_KVM,
> + .init.init_platform = kvmclock_init,
> .init.guest_late_init = kvm_guest_init,
> .init.x2apic_available = kvm_para_available,
> };
> diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c
> index bf8d1eb7fca3..01558d41ec2c 100644
> --- a/arch/x86/kernel/kvmclock.c
> +++ b/arch/x86/kernel/kvmclock.c
> @@ -23,9 +23,9 @@
> #include <asm/apic.h>
> #include <linux/percpu.h>
> #include <linux/hardirq.h>
> -#include <linux/memblock.h>
> #include <linux/sched.h>
> #include <linux/sched/clock.h>
> +#include <linux/mm.h>
>
> #include <asm/mem_encrypt.h>
> #include <asm/x86_init.h>
> @@ -44,6 +44,11 @@ static int parse_no_kvmclock(char *arg)
> }
> early_param("no-kvmclock", parse_no_kvmclock);
>
> +/* Aligned to page sizes to match whats mapped via vsyscalls to userspace */
> +#define HV_CLOCK_SIZE (sizeof(struct pvclock_vsyscall_time_info) * NR_CPUS)
> +#define WALL_CLOCK_SIZE (sizeof(struct pvclock_wall_clock))
> +static u8 hv_clock_mem[PAGE_ALIGN(HV_CLOCK_SIZE)] __aligned(PAGE_SIZE);
> +static u8 wall_clock_mem[PAGE_ALIGN(WALL_CLOCK_SIZE)] __aligned(PAGE_SIZE);
> /* The hypervisor will put information about time periodically here */
> static struct pvclock_vsyscall_time_info *hv_clock;
> static struct pvclock_wall_clock *wall_clock;
> @@ -244,43 +249,12 @@ static void kvm_shutdown(void)
> native_machine_shutdown();
> }
>
> -static phys_addr_t __init kvm_memblock_alloc(phys_addr_t size,
> - phys_addr_t align)
> -{
> - phys_addr_t mem;
> -
> - mem = memblock_alloc(size, align);
> - if (!mem)
> - return 0;
> -
> - if (sev_active()) {
> - if (early_set_memory_decrypted((unsigned long)__va(mem), size))
> - goto e_free;
> - }
> -
> - return mem;
> -e_free:
> - memblock_free(mem, size);
> - return 0;
> -}
> -
> -static void __init kvm_memblock_free(phys_addr_t addr, phys_addr_t size)
> -{
> - if (sev_active())
> - early_set_memory_encrypted((unsigned long)__va(addr), size);
> -
> - memblock_free(addr, size);
> -}
> -
> void __init kvmclock_init(void)
> {
> struct pvclock_vcpu_time_info *vcpu_time;
> - unsigned long mem, mem_wall_clock;
> - int size, cpu, wall_clock_size;
> + int cpu;
> u8 flags;
>
> - size = PAGE_ALIGN(sizeof(struct pvclock_vsyscall_time_info)*NR_CPUS);
> -
> if (!kvm_para_available())
> return;
>
> @@ -290,28 +264,11 @@ void __init kvmclock_init(void)
> } else if (!(kvmclock && kvm_para_has_feature(KVM_FEATURE_CLOCKSOURCE)))
> return;
>
> - wall_clock_size = PAGE_ALIGN(sizeof(struct pvclock_wall_clock));
> - mem_wall_clock = kvm_memblock_alloc(wall_clock_size, PAGE_SIZE);
> - if (!mem_wall_clock)
> - return;
> -
> - wall_clock = __va(mem_wall_clock);
> - memset(wall_clock, 0, wall_clock_size);
> -
> - mem = kvm_memblock_alloc(size, PAGE_SIZE);
> - if (!mem) {
> - kvm_memblock_free(mem_wall_clock, wall_clock_size);
> - wall_clock = NULL;
> - return;
> - }
> -
> - hv_clock = __va(mem);
> - memset(hv_clock, 0, size);
> + wall_clock = (struct pvclock_wall_clock *)wall_clock_mem;
> + hv_clock = (struct pvclock_vsyscall_time_info *)hv_clock_mem;
>
> if (kvm_register_clock("primary cpu clock")) {
> hv_clock = NULL;
> - kvm_memblock_free(mem, size);
> - kvm_memblock_free(mem_wall_clock, wall_clock_size);
> wall_clock = NULL;
> return;
> }
> @@ -354,13 +311,10 @@ int __init kvm_setup_vsyscall_timeinfo(void)
> int cpu;
> u8 flags;
> struct pvclock_vcpu_time_info *vcpu_time;
> - unsigned int size;
>
> if (!hv_clock)
> return 0;
>
> - size = PAGE_ALIGN(sizeof(struct pvclock_vsyscall_time_info)*NR_CPUS);
> -
> cpu = get_cpu();
>
> vcpu_time = &hv_clock[cpu].pvti;
> diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
> index 403b2d2c31d2..01fcc8bf7c8f 100644
> --- a/arch/x86/kernel/setup.c
> +++ b/arch/x86/kernel/setup.c
> @@ -1014,6 +1014,8 @@ void __init setup_arch(char **cmdline_p)
> */
> init_hypervisor_platform();
>
> + tsc_early_delay_calibrate();
> +
> x86_init.resources.probe_roms();
>
> /* after parse_early_param, so could debug it */
> @@ -1199,11 +1201,6 @@ void __init setup_arch(char **cmdline_p)
>
> memblock_find_dma_reserve();
>
> -#ifdef CONFIG_KVM_GUEST
> - kvmclock_init();
> -#endif
> -
> - tsc_early_delay_calibrate();
> if (!early_xdbc_setup_hardware())
> early_xdbc_register_console();
>
>
next prev parent reply other threads:[~2018-07-05 16:12 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-21 21:25 [PATCH v12 00/11] Early boot time stamps for x86 Pavel Tatashin
2018-06-21 21:25 ` [PATCH v12 01/11] x86: text_poke() may access uninitialized struct pages Pavel Tatashin
2018-06-21 21:37 ` Randy Dunlap
2018-06-25 8:14 ` Peter Zijlstra
2018-06-25 8:39 ` Thomas Gleixner
2018-06-25 9:09 ` Peter Zijlstra
2018-06-25 9:18 ` Thomas Gleixner
2018-06-25 9:22 ` Peter Zijlstra
2018-06-25 12:32 ` Pavel Tatashin
2018-06-25 13:48 ` Peter Zijlstra
2018-06-25 14:06 ` Pavel Tatashin
2018-06-21 21:25 ` [PATCH v12 02/11] x86: initialize static branching early Pavel Tatashin
2018-06-23 9:16 ` Borislav Petkov
2018-06-23 13:11 ` Pavel Tatashin
2018-06-21 21:25 ` [PATCH v12 03/11] x86/tsc: redefine notsc to behave as tsc=unstable Pavel Tatashin
2018-06-23 13:32 ` Thomas Gleixner
2018-06-21 21:25 ` [PATCH v12 04/11] kvm/x86: remove kvm memblock dependency Pavel Tatashin
2018-06-23 13:36 ` Thomas Gleixner
2018-07-05 16:12 ` Paolo Bonzini [this message]
2018-07-06 9:24 ` Thomas Gleixner
2018-07-06 9:36 ` Paolo Bonzini
2018-07-06 9:45 ` Thomas Gleixner
2018-07-06 10:08 ` Paolo Bonzini
2018-07-06 10:44 ` Thomas Gleixner
2018-07-06 10:50 ` Thomas Gleixner
2018-07-06 15:03 ` Pavel Tatashin
2018-07-06 15:09 ` Paolo Bonzini
2018-06-21 21:25 ` [PATCH v12 05/11] s390/time: add read_persistent_wall_and_boot_offset() Pavel Tatashin
2018-06-25 7:07 ` Martin Schwidefsky
2018-06-25 12:45 ` Pavel Tatashin
2018-06-21 21:25 ` [PATCH v12 06/11] time: replace read_boot_clock64() with read_persistent_wall_and_boot_offset() Pavel Tatashin
2018-06-23 13:49 ` Thomas Gleixner
2018-06-21 21:25 ` [PATCH v12 07/11] s390/time: remove read_boot_clock64() Pavel Tatashin
2018-06-21 21:25 ` [PATCH v12 08/11] ARM/time: " Pavel Tatashin
2018-06-23 13:52 ` Thomas Gleixner
2018-06-21 21:25 ` [PATCH v12 09/11] x86/tsc: prepare for early sched_clock Pavel Tatashin
2018-06-23 16:50 ` Thomas Gleixner
2018-06-23 18:49 ` Pavel Tatashin
2018-06-23 20:11 ` Thomas Gleixner
2018-06-23 21:29 ` Pavel Tatashin
2018-06-23 23:38 ` Thomas Gleixner
2018-06-24 2:43 ` Pavel Tatashin
2018-06-24 7:30 ` Thomas Gleixner
2018-06-26 15:42 ` Thomas Gleixner
2018-06-26 18:42 ` Pavel Tatashin
2018-06-26 19:47 ` Pavel Tatashin
2018-06-28 7:31 ` Thomas Gleixner
2018-06-28 10:43 ` Thomas Gleixner
2018-06-28 11:46 ` Peter Zijlstra
2018-06-28 12:27 ` Thomas Gleixner
2018-06-28 19:42 ` Pavel Tatashin
2018-06-29 7:30 ` Thomas Gleixner
2018-06-29 8:57 ` Pavel Tatashin
2018-07-03 20:59 ` Thomas Gleixner
2018-07-02 17:18 ` Konrad Rzeszutek Wilk
2018-06-29 14:30 ` Andy Shevchenko
2018-06-29 17:50 ` Andy Shevchenko
2018-07-09 23:16 ` Boris Ostrovsky
2018-06-21 21:25 ` [PATCH v12 10/11] sched: early boot clock Pavel Tatashin
2018-06-25 8:55 ` Peter Zijlstra
2018-06-25 12:44 ` Pavel Tatashin
2018-06-25 19:23 ` Pavel Tatashin
2018-06-26 9:00 ` Peter Zijlstra
2018-06-26 11:27 ` Pavel Tatashin
2018-06-26 11:51 ` Pavel Tatashin
2018-06-26 15:07 ` Peter Zijlstra
2018-06-21 21:25 ` [PATCH v12 11/11] x86/tsc: use tsc early Pavel Tatashin
2018-06-23 16:56 ` Thomas Gleixner
2018-06-23 21:38 ` Pavel Tatashin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fc67276e-643d-8a78-29e3-273c6dc79275@redhat.com \
--to=pbonzini@redhat.com \
--cc=daniel.m.jordan@oracle.com \
--cc=douly.fnst@cn.fujitsu.com \
--cc=feng.tang@intel.com \
--cc=gnomes@lxorguk.ukuu.org.uk \
--cc=heiko.carstens@de.ibm.com \
--cc=hpa@zytor.com \
--cc=john.stultz@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=mingo@redhat.com \
--cc=pasha.tatashin@oracle.com \
--cc=peterz@infradead.org \
--cc=pmladek@suse.com \
--cc=prarit@redhat.com \
--cc=sboyd@codeaurora.org \
--cc=schwidefsky@de.ibm.com \
--cc=steven.sistare@oracle.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox