Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2206100imm; Thu, 19 Jul 2018 15:23:58 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf0/2e67uK+sZxp6iTcipXI8nbBlaxNx4CtkB2A+GiSps4/cGwl6S62riyCzX+XuGCx7PA+ X-Received: by 2002:a63:ab0c:: with SMTP id p12-v6mr11532828pgf.190.1532039038259; Thu, 19 Jul 2018 15:23:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532039038; cv=none; d=google.com; s=arc-20160816; b=xMGqIhzURqlA0coaQMhllcUCMXyGXU0OClGtu/alZeQ7N76Osprrw1qtVHN/IfPgzK ckoURK4klq+FmBOibQglyunr003ItantjX7kiZSC5En8Q91WNoQ6yqP4crFVRa9k3N6u dVmsAt55Dc1PUQJP6rrPPXd+Jy8Fv8/OH/kdpCqQELs1SZMCRqwmlxJS3SBUfujvnc39 34NJc98ZkLgvv7KytJJI5CGrNNfAVGdP4mK0vQ53DHOzLiqvzIdwFZlq3ScegoRcyBiF NbvKNvPwXm8Og4RIxLk+wWUhTMxk45dX7c19mJ57SRzzgQAUTyRQ6iDSnD09WKdhAdlF GqZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=c8xEebubil87JWnBnVdolqoEthlVnw8BXyNm01/149w=; b=g0YizqpdOaDZ9qYig+KE0g0oFHRSfmiMiPzyNeWHpUpjM0wVKgF/oTKauHL5kWfFQ+ 2hlFvQVqLqqvJfjrU8Z1TS4p9XWm7471j1eU7SRBEi7ZPQ8eeGs1qmwqeQYuM0fSCh+e IQ3SMsRP+ijGa9XRihSmoJ5nRSCJmkz6fmVWBKIwfCoqY4ZtLJv+Y9qcSZMIBErQ5e0D jcpLg9QaBJz0VjnvYOnWRnViXd/LHKYYIsJirYijurTCFCC77yGODRL2zVZ9oIyH0Wbb RUjiEdo4woo9Akm/jpKT7pCm1cAqStE4BPYhJ2QyTad0GgFFAr2P5SLMEreLK42QfUA+ 5S5A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i124-v6si288704pfc.110.2018.07.19.15.23.42; Thu, 19 Jul 2018 15:23:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730902AbeGSXHf (ORCPT + 99 others); Thu, 19 Jul 2018 19:07:35 -0400 Received: from terminus.zytor.com ([198.137.202.136]:37989 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730383AbeGSXHf (ORCPT ); Thu, 19 Jul 2018 19:07:35 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w6JMLvH12437005 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 19 Jul 2018 15:21:57 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w6JMLunU2437002; Thu, 19 Jul 2018 15:21:56 -0700 Date: Thu, 19 Jul 2018 15:21:56 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Pavel Tatashin Message-ID: Cc: hpa@zytor.com, pbonzini@redhat.com, pasha.tatashin@oracle.com, linux-kernel@vger.kernel.org, tglx@linutronix.de, mingo@kernel.org Reply-To: hpa@zytor.com, pasha.tatashin@oracle.com, pbonzini@redhat.com, mingo@kernel.org, linux-kernel@vger.kernel.org, tglx@linutronix.de In-Reply-To: <20180719205545.16512-2-pasha.tatashin@oracle.com> References: <20180719205545.16512-2-pasha.tatashin@oracle.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/timers] x86/kvmclock: Remove memblock dependency Git-Commit-ID: 368a540e0232ad446931f5a4e8a5e06f69f21343 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 368a540e0232ad446931f5a4e8a5e06f69f21343 Gitweb: https://git.kernel.org/tip/368a540e0232ad446931f5a4e8a5e06f69f21343 Author: Pavel Tatashin AuthorDate: Thu, 19 Jul 2018 16:55:20 -0400 Committer: Thomas Gleixner CommitDate: Fri, 20 Jul 2018 00:02:36 +0200 x86/kvmclock: Remove memblock dependency KVM clock is initialized later compared to other hypervisor clocks because it has a dependency on the memblock allocator. Bring it in line with other hypervisors by using memory from the BSS instead of allocating it. The benefits: - Remove ifdef from common code - Earlier availability of the clock - Remove dependency on memblock, and reduce code The downside: - Static allocation of the per cpu data structures sized NR_CPUS * 64byte Will be addressed in follow up patches. [ tglx: Split out from larger series ] Signed-off-by: Pavel Tatashin Signed-off-by: Thomas Gleixner Acked-by: Paolo Bonzini Cc: steven.sistare@oracle.com Cc: daniel.m.jordan@oracle.com Cc: linux@armlinux.org.uk Cc: schwidefsky@de.ibm.com Cc: heiko.carstens@de.ibm.com Cc: john.stultz@linaro.org Cc: sboyd@codeaurora.org Cc: hpa@zytor.com Cc: douly.fnst@cn.fujitsu.com Cc: peterz@infradead.org Cc: prarit@redhat.com Cc: feng.tang@intel.com Cc: pmladek@suse.com Cc: gnomes@lxorguk.ukuu.org.uk Cc: linux-s390@vger.kernel.org Cc: boris.ostrovsky@oracle.com Cc: jgross@suse.com Link: https://lkml.kernel.org/r/20180719205545.16512-2-pasha.tatashin@oracle.com --- arch/x86/kernel/kvm.c | 1 + arch/x86/kernel/kvmclock.c | 66 ++++++++-------------------------------------- arch/x86/kernel/setup.c | 4 --- 3 files changed, 12 insertions(+), 59 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 3b8e7c13c614..1f6ac5aaa904 100644 --- a/arch/x86/kernel/kvmclock.c +++ b/arch/x86/kernel/kvmclock.c @@ -23,9 +23,9 @@ #include #include #include -#include #include #include +#include #include #include @@ -44,6 +44,13 @@ 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; @@ -245,43 +252,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; @@ -291,28 +267,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; } @@ -357,13 +316,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 2f86d883dd95..da1dbd99cb6e 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -1197,10 +1197,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();