Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3324096imm; Mon, 8 Oct 2018 01:55:50 -0700 (PDT) X-Google-Smtp-Source: ACcGV61iUiEw82uVaOClwioMYu5PFU6htK1+db/SrVGauHL7MrJtW3xDjDQsYVcKTet5BboO5Cvl X-Received: by 2002:a63:4b44:: with SMTP id k4-v6mr20019622pgl.51.1538988950688; Mon, 08 Oct 2018 01:55:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538988950; cv=none; d=google.com; s=arc-20160816; b=OmetR6SPGYQEFIc7q/FXBiPbXi4Rj5mFTX9qznrv7Wqse9naJ2lb7VfkDFw39pA8Iv wo36VUbII/NXmqKwF8azLePg2ZQkZZg2tkCuoDGBPww9t6Vp4slRFgkYKKK6QibavaaC 33twZv6xWOs8yDqkD9Qc0G+XalB/ZYxuifxDl8ksCwM56LwUA9xHLFMjT2N0AXQmtpRo CXOSYh2mtuVlbO0p9eb/bUpT3lVneeqFbhVON+3PEIK1IWy/RZWcZBdh6BliopKHMfCI 7s+qa78bEPBY5HF+2/w49Ggor85oFJ5PKgxmR/VRuFRg0wmrkuNklvIcZTOkCOqDu/cq EY+Q== 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; bh=EJrLZd4g4MIpkretfyZYUWuJxaQNimhJQZqJII1TzgI=; b=iDInyTercm6ESv0rmDfU3QCeMOjhmrv2D05vFVv9+ap4phTZdUA+lZWEjL17EG0JDT nJv+nH4dFcTZ1lFvA6OKkCXAMs5pVyQclRr1zkLAB9Ey7E7/jho+49bZSakhb3FKXszD LZLt5d8HbUinGmKVbWlxNB5BoaPLqlq8DfXe0P1TOBc/RYfpujaQGZmdmqSAuv3qcX9X ccctZ/F5Ve39mwN7Duq0fxR6iCp5ROsMEPJP5hvJLpqLXryM3FF+PeoBUy4hjR8/9rTk eAMFnyFXDOTylGBK55SY14GvNDMoqw+BhWhv9Xf8Bs5viW+Snt3aDFFclYLRjK1dVHPb fWhQ== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l1-v6si15560752pld.375.2018.10.08.01.55.35; Mon, 08 Oct 2018 01:55:50 -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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727403AbeJHQFv (ORCPT + 99 others); Mon, 8 Oct 2018 12:05:51 -0400 Received: from mga14.intel.com ([192.55.52.115]:6001 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727363AbeJHQFv (ORCPT ); Mon, 8 Oct 2018 12:05:51 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Oct 2018 01:55:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,356,1534834800"; d="scan'208";a="93194735" Received: from svm-s2600wft.bj.intel.com ([10.240.193.45]) by fmsmga002.fm.intel.com with ESMTP; 08 Oct 2018 01:55:01 -0700 From: Yi Sun To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, tglx@linutronix.de, jgross@suse.com, chao.p.peng@intel.com, chao.gao@intel.com, isaku.yamahata@intel.com, michael.h.kelley@microsoft.com, tianyu.lan@microsoft.com, Yi Sun , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , "Michael Kelley (EOSG)" Subject: [PATCH v4 2/2] locking/pvqspinlock, hv: Enable PV qspinlock for Hyper-V Date: Mon, 8 Oct 2018 16:29:34 +0800 Message-Id: <1538987374-51217-3-git-send-email-yi.y.sun@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1538987374-51217-1-git-send-email-yi.y.sun@linux.intel.com> References: <1538987374-51217-1-git-send-email-yi.y.sun@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Follow PV spinlock mechanism to implement the callback functions to allow the CPU idling and kicking operations on Hyper-V. Cc: "K. Y. Srinivasan" Cc: Haiyang Zhang Cc: Stephen Hemminger Cc: Thomas Gleixner Cc: Michael Kelley (EOSG) Cc: Juergen Gross Signed-off-by: Yi Sun --- v3->v4: - To avoid possible hang issue (if hv_qlock_wait can be interrupted, kick may happen before reading HV_X64_MSR_GUEST_IDLE so that hang happens), disable interrupt before READ_ONCE, then restore it after reading HV_X64_MSR_GUEST_IDLE. (suggested by Juergen Gross) --- Documentation/admin-guide/kernel-parameters.txt | 5 ++ arch/x86/hyperv/Makefile | 4 ++ arch/x86/hyperv/hv_spinlock.c | 85 +++++++++++++++++++++++++ arch/x86/include/asm/mshyperv.h | 1 + arch/x86/kernel/cpu/mshyperv.c | 14 ++++ 5 files changed, 109 insertions(+) create mode 100644 arch/x86/hyperv/hv_spinlock.c diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 92eb1f4..0fc8448 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 b21ee65..1c11f94 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 0000000..b628343 --- /dev/null +++ b/arch/x86/hyperv/hv_spinlock.c @@ -0,0 +1,85 @@ +// 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; + unsigned long flags; + + if (in_nmi()) + return; + + local_irq_save(flags); + + if (READ_ONCE(*byte) != val) + goto out; + + /* + * 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); + +out: + local_irq_restore(flags); +} + +/* + * Hyper-V does not support this so far. + */ +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 f377044..759cfd2 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -351,6 +351,7 @@ static inline int cpumask_to_vpset(struct hv_vpset *vpset, #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 ad12733..a5cc219 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); + +#if defined(CONFIG_SMP) + smp_ops.smp_prepare_boot_cpu = hv_smp_prepare_boot_cpu; +#endif #endif } -- 1.9.1