Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934639AbeAORbi (ORCPT + 1 other); Mon, 15 Jan 2018 12:31:38 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46020 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935429AbeAORbd (ORCPT ); Mon, 15 Jan 2018 12:31:33 -0500 From: Vitaly Kuznetsov To: kvm@vger.kernel.org Cc: x86@kernel.org, Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , "Michael Kelley (EOSG)" , Mohammed Gamal , Cathy Avery , Bandan Das , linux-kernel@vger.kernel.org Subject: [RFC 3/6] x86/hyper-v: allocate and use hv_vp_assist_pages Date: Mon, 15 Jan 2018 18:31:02 +0100 Message-Id: <20180115173105.31845-4-vkuznets@redhat.com> In-Reply-To: <20180115173105.31845-1-vkuznets@redhat.com> References: <20180115173105.31845-1-vkuznets@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 15 Jan 2018 17:31:32 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: These pages are going to be used for Enlightened VMCS support in KVM. Signed-off-by: Vitaly Kuznetsov --- arch/x86/hyperv/hv_init.c | 35 ++++++++++++++++++++++++++++++++++- arch/x86/include/asm/mshyperv.h | 1 + 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index 189a398290db..a5eb0a89e299 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -85,6 +85,9 @@ EXPORT_SYMBOL_GPL(hyperv_cs); u32 *hv_vp_index; EXPORT_SYMBOL_GPL(hv_vp_index); +struct hv_vp_assist_page **hv_vp_assist_page; +EXPORT_SYMBOL_GPL(hv_vp_assist_page); + u32 hv_max_vp_index; static int hv_cpu_init(unsigned int cpu) @@ -98,6 +101,31 @@ static int hv_cpu_init(unsigned int cpu) if (msr_vp_index > hv_max_vp_index) hv_max_vp_index = msr_vp_index; + if (!hv_vp_assist_page[smp_processor_id()]) + hv_vp_assist_page[smp_processor_id()] = + __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL); + + if (hv_vp_assist_page[smp_processor_id()]) { + u64 val; + + val = vmalloc_to_pfn(hv_vp_assist_page[smp_processor_id()]); + val = (val << HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_SHIFT) | + HV_X64_MSR_VP_ASSIST_PAGE_ENABLE; + + wrmsrl(HV_X64_MSR_VP_ASSIST_PAGE, val); + } + + return 0; +} + +static int hv_cpu_die(unsigned int cpu) +{ + if (hv_vp_assist_page[cpu]) { + wrmsrl(HV_X64_MSR_VP_ASSIST_PAGE, 0); + vfree(hv_vp_assist_page[cpu]); + hv_vp_assist_page[cpu] = NULL; + } + return 0; } @@ -122,8 +150,13 @@ void hyperv_init(void) if (!hv_vp_index) return; + hv_vp_assist_page = kcalloc(num_possible_cpus(), + sizeof(*hv_vp_assist_page), GFP_KERNEL); + if (!hv_vp_assist_page) + return; + if (cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/hyperv_init:online", - hv_cpu_init, NULL) < 0) + hv_cpu_init, hv_cpu_die) < 0) goto free_vp_index; /* diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h index 5400add2885b..245e08a2e48d 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -291,6 +291,7 @@ static inline u64 hv_do_rep_hypercall(u16 code, u16 rep_count, u16 varhead_size, */ extern u32 *hv_vp_index; extern u32 hv_max_vp_index; +extern struct hv_vp_assist_page **hv_vp_assist_page; /** * hv_cpu_number_to_vp_number() - Map CPU to VP. -- 2.14.3