Received: by 10.213.65.68 with SMTP id h4csp425666imn; Fri, 16 Mar 2018 07:25:01 -0700 (PDT) X-Google-Smtp-Source: AG47ELtjRZSQnuuy043KuqOVjYuks5UpQCjWiowV7NjywovUo5TDTlGa5QSiRsrKxwBsSo1rxYtn X-Received: by 2002:a17:902:7008:: with SMTP id y8-v6mr2415256plk.395.1521210301562; Fri, 16 Mar 2018 07:25:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521210301; cv=none; d=google.com; s=arc-20160816; b=m2+hNdNR6qYjNSc3zKeJhNTiHqX8DmvsDZn3u+/q/X5P/0Rdt60pVVaHQu8KcoIj6X mmCocbZwazqmLab0EgLEqpvqO2Bt/wxS+xs7CI+NPqsUiboA+tLsAT3dBGybz6dR2TF+ IAbyTxlTULNjqP8UKmGK55O2ct1889Iy3SaQIld4S4Shk6qI9eu8ceguRi9aK7I786jb Mm/PWIHDq2q7J9zjxHvoJHtZQaDyXvr5ebop9AitGmgGfLUmAb5gMo0HPKZTqy5QrK71 YPllzv2rPZsHUjGHV7QhDTE09+wGfgf2qmOYYQLQGkXRvkD8gjCDzWulSVs5Cp6zvNj6 fDjA== 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=gpu6YBxbaQaQhsOCLYtNILYDt0ufFclVss5cbcM8Io8=; b=Tjy9k8IMx17cHf/mhs1523kJE1G0NYf6wNy0gMbCGCJYU0OvPMTWh9+DCiYHTpzWTW zmNacgFpVUHk7qtgz8Jg+q+ZBKEWxMgC5I94W1yufB4qTEX0M0J8ybDmQ2xdOq44rqbG SQ4U5S1Gac3Gw2NEY0ezRwQJhD3XrMp9pICYy8cyEsD2ddo9y4JvACxICV3gzeY7wK4F 644wNVt7Y92PKsDNpOK6ajQdrG+OMeyoWjgHpdEHu7P9Ai4HkaQ+OTPYoHaJ9353Id+W DI3A+eT+o+yHDjElJeuNFwR0e+F4Q8Lg5PKoVnxdDb+6aXZDEGrj8gCfUUMQ1QatrRlh CQfA== 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 p18si2723178pfk.396.2018.03.16.07.24.46; Fri, 16 Mar 2018 07:25:01 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753229AbeCPOWi (ORCPT + 99 others); Fri, 16 Mar 2018 10:22:38 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:35258 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753208AbeCPOWe (ORCPT ); Fri, 16 Mar 2018 10:22:34 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AC50A7C6CC; Fri, 16 Mar 2018 14:22:33 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.43.2.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id A47C6202322B; Fri, 16 Mar 2018 14:22:31 +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 , Thomas Gleixner , Christoph Hellwig , linux-kernel@vger.kernel.org Subject: [PATCH v4 4/7] x86/hyper-v: allocate and use Virtual Processor Assist Pages Date: Fri, 16 Mar 2018 15:22:17 +0100 Message-Id: <20180316142220.32506-5-vkuznets@redhat.com> In-Reply-To: <20180316142220.32506-1-vkuznets@redhat.com> References: <20180316142220.32506-1-vkuznets@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 16 Mar 2018 14:22:33 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 16 Mar 2018 14:22:33 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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 v3: - remove vfree() from hv_cpu_die() [Thomas Gleixner] - free hv_vp_assist_page() in the error path [Thomas Gleixner] While on it, add cpuhp_remove_state() call when we fail to allocate hypercall page to make the error path complete. - check hv_vp_assist_page != NULL in hv_get_vp_assist_page() [Thomas Gleixner] --- arch/x86/hyperv/hv_init.c | 43 +++++++++++++++++++++++++++++++++++--- arch/x86/include/asm/hyperv-tlfs.h | 13 ++++++++++++ arch/x86/include/asm/mshyperv.h | 13 ++++++++++++ 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index 4b82bc206929..c17e2a36aab7 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,9 @@ 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); + if (hv_reenlightenment_cb == NULL) return 0; @@ -224,6 +247,7 @@ void hyperv_init(void) { u64 guest_id, required_msrs; union hv_x64_msr_hypercall_contents hypercall_msr; + int cpuhp; if (x86_hyper_type != X86_HYPER_MS_HYPERV) return; @@ -241,9 +265,17 @@ void hyperv_init(void) if (!hv_vp_index) return; - if (cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/hyperv_init:online", - hv_cpu_init, hv_cpu_die) < 0) + 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; goto free_vp_index; + } + + cpuhp = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/hyperv_init:online", + hv_cpu_init, hv_cpu_die); + if (cpuhp < 0) + goto free_vp_assist_page; /* * Setup the hypercall page and enable hypercalls. @@ -256,7 +288,7 @@ void hyperv_init(void) hv_hypercall_pg = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX); if (hv_hypercall_pg == NULL) { wrmsrl(HV_X64_MSR_GUEST_OS_ID, 0); - goto free_vp_index; + goto remove_cpuhp_state; } rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); @@ -304,6 +336,11 @@ void hyperv_init(void) return; +remove_cpuhp_state: + cpuhp_remove_state(cpuhp); +free_vp_assist_page: + kfree(hv_vp_assist_page); + hv_vp_assist_page = NULL; free_vp_index: kfree(hv_vp_index); hv_vp_index = NULL; diff --git a/arch/x86/include/asm/hyperv-tlfs.h b/arch/x86/include/asm/hyperv-tlfs.h index acdec9a957db..41eac22db5e3 100644 --- a/arch/x86/include/asm/hyperv-tlfs.h +++ b/arch/x86/include/asm/hyperv-tlfs.h @@ -163,6 +163,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. */ @@ -476,6 +479,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) diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h index 38cfbe9a5794..3f162353f180 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -218,6 +218,15 @@ 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) +{ + if (!hv_vp_assist_page) + return NULL; + + return hv_vp_assist_page[cpu]; +} /** * hv_cpu_number_to_vp_number() - Map CPU to VP. @@ -254,6 +263,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 -- 2.14.3