Received: by 10.223.185.116 with SMTP id b49csp3985857wrg; Mon, 26 Feb 2018 09:15:03 -0800 (PST) X-Google-Smtp-Source: AH8x226S4EhsSyA+OoXUKVDrdxTuhRKrvJppiXq/TMgHGsLTWKQFcm+eYqpLIC3D/TOPskHfC9VI X-Received: by 10.98.60.144 with SMTP id b16mr11317338pfk.61.1519665303472; Mon, 26 Feb 2018 09:15:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519665303; cv=none; d=google.com; s=arc-20160816; b=X6t4b5QZXuHlsWfrTjPQUZXrInIqDN4QCdQ5hC3vROrFy2RSI6zGuxLF086nWl+plk wJXObSea7lt9ukryhRZEU/HK2ruOxWUAQHGo2E1l5g56H1SLPWgtCsc52yJY/5s6T57y 6LUM3GQc1pV0rMHoKIpiQ/YUENhxoEZJv29rFf0wuHOeQCMQQ53F/lsnhKwJbVVl+uoE 7asnsUNzyEnVVRkYHJbeJOyD/G5zixxHfqPRzQo1hkz+ozVn1ByTudm6ZeFvAoMXrpWQ Sgnm6F9U8WrprmoSY42Z/ZcJQZ5Z+zT1lIoMxfPHGkhJkesSKFW4GMrVZrztYK+SKA3U Wf2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=pzgxuoS58y1tsN52OpwKfx5R85QvYRNlJvf7L/cClpY=; b=RsiG6ZmmrEKyO31WKvYEEIcNEycbQMlsKFxcY7EgxiQWiOEglga0vKI32wNjUz01ro vrWxo62+NYPOfA4pLTfJuihbUM5v/gKu+7NDBUULhVueZDOh4RntBEBrYVXyAgyBHdJZ hUsLbmpS3sImk7dxWZOVi9S37rPeK6HqO6UKAafY/kx1D4fKSzj6wVWN1n47oV+EvVEp Gv/P6NjdP70DH9jXcseb0zUFoAtovqfHjPl67U7b+z/wWxwzDLWLR1wKVz2DDVnwBlEB TOtJBXI24gGWCB22JWacUKnhAa+Vm69ec5Z03tALnNV9B5VEyHAV721SG814vuLYATdb ydiA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a33-v6si2467005plc.101.2018.02.26.09.14.47; Mon, 26 Feb 2018 09:15:03 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751943AbeBZRND (ORCPT + 99 others); Mon, 26 Feb 2018 12:13:03 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:36686 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751396AbeBZRLb (ORCPT ); Mon, 26 Feb 2018 12:11:31 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CEE3A40363B6; Mon, 26 Feb 2018 17:11:30 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.43.2.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0B85F10B0F26; Mon, 26 Feb 2018 17:11:28 +0000 (UTC) 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: [PATCH v2 2/5] x86/hyper-v: allocate and use Virtual Processor Assist Pages Date: Mon, 26 Feb 2018 18:11:18 +0100 Message-Id: <20180226171121.18974-3-vkuznets@redhat.com> In-Reply-To: <20180226171121.18974-1-vkuznets@redhat.com> References: <20180226171121.18974-1-vkuznets@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 26 Feb 2018 17:11:30 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 26 Feb 2018 17:11:30 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'vkuznets@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Virtual Processor Assist Pages usage allows us to do optimized EOI processing for APIC, enable Enlightened VMCS support in KVM and more. struct hv_vp_assist_page is defined according to the Hyper-V TLFS v5.0b. Signed-off-by: Vitaly Kuznetsov --- Changes since v1: move HV_X64_ENLIGHTENED_VMCS_RECOMMENDED definition to this patch --- arch/x86/hyperv/hv_init.c | 33 +++++++++++++++++++++++++++++++++ arch/x86/include/asm/mshyperv.h | 10 ++++++++++ arch/x86/include/uapi/asm/hyperv.h | 13 +++++++++++++ 3 files changed, 56 insertions(+) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index 2edc49e7409b..acf21fa93e2c 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -88,6 +88,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) @@ -101,6 +104,23 @@ 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) + return 0; + + 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; } @@ -198,6 +218,12 @@ static int hv_cpu_die(unsigned int cpu) struct hv_reenlightenment_control re_ctrl; unsigned int new_cpu; + if (hv_vp_assist_page && 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; + } + if (hv_reenlightenment_cb == NULL) return 0; @@ -241,6 +267,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) { + ms_hyperv.hints &= ~HV_X64_ENLIGHTENED_VMCS_RECOMMENDED; + return; + } + if (cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/hyperv_init:online", 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 25283f7eb299..778d2efd34f1 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -294,6 +294,12 @@ 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; + +static inline struct hv_vp_assist_page *hv_get_vp_assist_page(unsigned int cpu) +{ + return hv_vp_assist_page[cpu]; +} /** * hv_cpu_number_to_vp_number() - Map CPU to VP. @@ -330,6 +336,10 @@ static inline void hyperv_setup_mmu_ops(void) {} static inline void set_hv_tscchange_cb(void (*cb)(void)) {} static inline void clear_hv_tscchange_cb(void) {} static inline void hyperv_stop_tsc_emulation(void) {}; +static inline struct hv_vp_assist_page *hv_get_vp_assist_page(unsigned int cpu) +{ + return NULL; +} #endif /* CONFIG_HYPERV */ #ifdef CONFIG_HYPERV_TSCPAGE diff --git a/arch/x86/include/uapi/asm/hyperv.h b/arch/x86/include/uapi/asm/hyperv.h index 45cc62352040..bd7a2f020f68 100644 --- a/arch/x86/include/uapi/asm/hyperv.h +++ b/arch/x86/include/uapi/asm/hyperv.h @@ -156,6 +156,9 @@ /* Recommend using the newer ExProcessorMasks interface */ #define HV_X64_EX_PROCESSOR_MASKS_RECOMMENDED (1 << 11) +/* Recommend using enlightened VMCS */ +#define HV_X64_ENLIGHTENED_VMCS_RECOMMENDED (1 << 14) + /* * Crash notification flag. */ @@ -414,6 +417,16 @@ struct hv_timer_message_payload { __u64 delivery_time; /* When the message was delivered */ }; +/* Define virtual processor assist page structure. */ +struct hv_vp_assist_page { + __u32 apic_assist; + __u32 reserved; + __u64 vtl_control[2]; + __u64 nested_enlightenments_control[2]; + __u32 enlighten_vmentry; + __u64 current_nested_vmcs; +}; + #define HV_STIMER_ENABLE (1ULL << 0) #define HV_STIMER_PERIODIC (1ULL << 1) #define HV_STIMER_LAZY (1ULL << 2) -- 2.14.3