Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1195334imm; Tue, 2 Oct 2018 04:29:08 -0700 (PDT) X-Google-Smtp-Source: ACcGV62uWm6GLPCeo7OTWeUf0c0ur+/nS0LszxE8qvjUNjFIWYRYZXG0203ME42onhkmkBXA8yUT X-Received: by 2002:a17:902:bd4b:: with SMTP id b11-v6mr16401135plx.0.1538479748567; Tue, 02 Oct 2018 04:29:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538479748; cv=none; d=google.com; s=arc-20160816; b=g3xDMyvQd6mT51aZozVwAv0LQZypDh9bncuqpU4bqUXXRqz7afhMXqSGTkh+akp+Iw ZFsUvSnFfv88J6LePtdvQkWHfkrxyRoU2HlhkZoKo2bSVjg89OOGw1jGo2Ios5HV9hsY DD7Q+ACd5+zsyxCNQRey/JWqtjadl95fJbXfdVxS2TWZcQWXXDkTOGl0ag++9tA/9Fo0 Nk6YSwudnWfG/OqvXnZeXIODQdiwHXijzx3eLq2naYzaGwgwHvyqs8O6hUryuvWXiQ1F E1wm3k1gDHNmoO7kLrjZ/it552+W8H8Pr2XE59IVoqJF4Ak8cCWn9HUa0bMVRaJkUFwk iIqw== 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; bh=A12r+Y3FnJD0y1B3Byx3yEku5fPsXJT3ma2KnSSKRjY=; b=M3ZJc87DzkPJoRDp83PjH2TwQmGcAQTpZM1Z7B8EfxXHClkKHOfIv0kA1p2gch9SOP OdgjuO21ptVbt2vTFJt+X2F2hIk46STuILw9GWajclPUsLnvXDYM5b6TQw4YEHjP/kOR klAROx/rorDuom8FuZyFU3jeAsY46AwZg8bmRaNTfJR6btsQ2Lqm5MIF0UKalJDqESSs sep8W+vgApRJrJS1coIKRuBAGV3eksWmeHTHmnLj+HdiqQ9d+1xdVHPU1n4a0oaYQak3 4y0u0gie7svWwqh5k+QlQp8f8NkM4QU7YkSCOjF6tw/lu7pmdB9M6bcKGyqkgIwlOBig 4Y2w== 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 m29-v6si3698235pgd.361.2018.10.02.04.28.53; Tue, 02 Oct 2018 04:29:08 -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 S1727609AbeJBSLY (ORCPT + 99 others); Tue, 2 Oct 2018 14:11:24 -0400 Received: from terminus.zytor.com ([198.137.202.136]:52129 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727443AbeJBSLY (ORCPT ); Tue, 2 Oct 2018 14:11:24 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w92BSSR21937411 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 2 Oct 2018 04:28:28 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w92BSRuR1937408; Tue, 2 Oct 2018 04:28:27 -0700 Date: Tue, 2 Oct 2018 04:28:27 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Yi Sun Message-ID: Cc: mingo@kernel.org, tglx@linutronix.de, linux-kernel@vger.kernel.org, sthemmin@microsoft.com, mikelley@microsoft.com, haiyangz@microsoft.com, kys@microsoft.com, hpa@zytor.com, yi.y.sun@linux.intel.com Reply-To: linux-kernel@vger.kernel.org, tglx@linutronix.de, mingo@kernel.org, sthemmin@microsoft.com, mikelley@microsoft.com, kys@microsoft.com, haiyangz@microsoft.com, yi.y.sun@linux.intel.com, hpa@zytor.com In-Reply-To: <1538028104-114050-3-git-send-email-yi.y.sun@linux.intel.com> References: <1538028104-114050-3-git-send-email-yi.y.sun@linux.intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/hyperv] x86/hyperv: Enable PV qspinlock for Hyper-V Git-Commit-ID: aaa7fc34c003bd8133a49f7634480cef6288ad55 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.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: aaa7fc34c003bd8133a49f7634480cef6288ad55 Gitweb: https://git.kernel.org/tip/aaa7fc34c003bd8133a49f7634480cef6288ad55 Author: Yi Sun AuthorDate: Thu, 27 Sep 2018 14:01:44 +0800 Committer: Thomas Gleixner CommitDate: Tue, 2 Oct 2018 13:22:06 +0200 x86/hyperv: Enable PV qspinlock for Hyper-V Implement the necessary callbacks for PV spinlocks which allow vCPU idling and kicking operations when running as a guest on Hyper-V Signed-off-by: Yi Sun Signed-off-by: Thomas Gleixner Reviewed-by: Michael Kelley Cc: chao.p.peng@intel.com Cc: chao.gao@intel.com Cc: isaku.yamahata@intel.com Cc: tianyu.lan@microsoft.com Cc: "K. Y. Srinivasan" Cc: Haiyang Zhang Cc: Stephen Hemminger Link: https://lkml.kernel.org/r/1538028104-114050-3-git-send-email-yi.y.sun@linux.intel.com --- Documentation/admin-guide/kernel-parameters.txt | 5 ++ arch/x86/hyperv/Makefile | 4 ++ arch/x86/hyperv/hv_spinlock.c | 75 +++++++++++++++++++++++++ arch/x86/include/asm/mshyperv.h | 1 + arch/x86/kernel/cpu/mshyperv.c | 14 +++++ 5 files changed, 99 insertions(+) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 92eb1f42240d..0fc8448a85ea 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -1385,6 +1385,11 @@ hvc_iucv_allow= [S390] Comma-separated list of z/VM user IDs. If specified, z/VM IUCV HVC accepts connections from listed z/VM user IDs only. + + hv_nopvspin [X86,HYPER_V] + Disables the ticketlock slowpath using HYPER-V PV + optimizations. + keep_bootcon [KNL] Do not unregister boot console at start. This is only useful for debugging when something happens in the window diff --git a/arch/x86/hyperv/Makefile b/arch/x86/hyperv/Makefile index b21ee65c4101..1c11f9420a82 100644 --- a/arch/x86/hyperv/Makefile +++ b/arch/x86/hyperv/Makefile @@ -1,2 +1,6 @@ obj-y := hv_init.o mmu.o nested.o obj-$(CONFIG_X86_64) += hv_apic.o + +ifdef CONFIG_X86_64 +obj-$(CONFIG_PARAVIRT_SPINLOCKS) += hv_spinlock.o +endif diff --git a/arch/x86/hyperv/hv_spinlock.c b/arch/x86/hyperv/hv_spinlock.c new file mode 100644 index 000000000000..6d3221322d0d --- /dev/null +++ b/arch/x86/hyperv/hv_spinlock.c @@ -0,0 +1,75 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Hyper-V specific spinlock code. + * + * Copyright (C) 2018, Intel, Inc. + * + * Author : Yi Sun + */ + +#define pr_fmt(fmt) "Hyper-V: " fmt + +#include + +#include +#include +#include +#include +#include + +static bool __initdata hv_pvspin = true; + +static void hv_qlock_kick(int cpu) +{ + apic->send_IPI(cpu, X86_PLATFORM_IPI_VECTOR); +} + +static void hv_qlock_wait(u8 *byte, u8 val) +{ + unsigned long msr_val; + + if (READ_ONCE(*byte) != val) + return; + + /* + * Read HV_X64_MSR_GUEST_IDLE MSR can trigger the guest's + * transition to the idle power state which can be exited + * by an IPI even if IF flag is disabled. + */ + rdmsrl(HV_X64_MSR_GUEST_IDLE, msr_val); +} + +/* + * Hyper-V does not support this so far. + */ +static bool hv_vcpu_is_preempted(int vcpu) +{ + return false; +} +PV_CALLEE_SAVE_REGS_THUNK(hv_vcpu_is_preempted); + +void __init hv_init_spinlocks(void) +{ + if (!hv_pvspin || !apic || + !(ms_hyperv.hints & HV_X64_CLUSTER_IPI_RECOMMENDED) || + !(ms_hyperv.features & HV_X64_MSR_GUEST_IDLE_AVAILABLE)) { + pr_info("PV spinlocks disabled\n"); + return; + } + pr_info("PV spinlocks enabled\n"); + + __pv_init_lock_hash(); + pv_lock_ops.queued_spin_lock_slowpath = __pv_queued_spin_lock_slowpath; + pv_lock_ops.queued_spin_unlock = PV_CALLEE_SAVE(__pv_queued_spin_unlock); + pv_lock_ops.wait = hv_qlock_wait; + pv_lock_ops.kick = hv_qlock_kick; + pv_lock_ops.vcpu_is_preempted = PV_CALLEE_SAVE(hv_vcpu_is_preempted); +} + +static __init int hv_parse_nopvspin(char *arg) +{ + hv_pvspin = false; + return 0; +} +early_param("hv_nopvspin", hv_parse_nopvspin); diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h index f37704497d8f..759cfd214eb9 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -351,6 +351,7 @@ int hyperv_flush_guest_mapping(u64 as); #ifdef CONFIG_X86_64 void hv_apic_init(void); +void __init hv_init_spinlocks(void); #else static inline void hv_apic_init(void) {} #endif diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index ad12733f6058..1c72f3819eb1 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -199,6 +199,16 @@ static unsigned long hv_get_tsc_khz(void) return freq / 1000; } +#if defined(CONFIG_SMP) && IS_ENABLED(CONFIG_HYPERV) +static void __init hv_smp_prepare_boot_cpu(void) +{ + native_smp_prepare_boot_cpu(); +#if defined(CONFIG_X86_64) && defined(CONFIG_PARAVIRT_SPINLOCKS) + hv_init_spinlocks(); +#endif +} +#endif + static void __init ms_hyperv_init_platform(void) { int hv_host_info_eax; @@ -303,6 +313,10 @@ static void __init ms_hyperv_init_platform(void) if (ms_hyperv.misc_features & HV_STIMER_DIRECT_MODE_AVAILABLE) alloc_intr_gate(HYPERV_STIMER0_VECTOR, hv_stimer0_callback_vector); + +# ifdef CONFIG_SMP + smp_ops.smp_prepare_boot_cpu = hv_smp_prepare_boot_cpu; +# endif #endif }