Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp339995imm; Fri, 21 Sep 2018 00:50:07 -0700 (PDT) X-Google-Smtp-Source: ANB0VdamUiUnAiEXPve8vkjRxxs+h24mQ3zz9sZLw43oqgGalyLCC+qBxqav1f1OTXvsQPlCMtuY X-Received: by 2002:a17:902:26c:: with SMTP id 99-v6mr43200424plc.341.1537516207315; Fri, 21 Sep 2018 00:50:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537516207; cv=none; d=google.com; s=arc-20160816; b=j7g3MCbBxKElwfxObwhB+n0VNFaAVpMl4RxK6b+2Q5uhY2yZ45Rj7xVfYYav5u9tHX HhUg4w7rKINDaXyfzmGd9FD97doiT6BzLq83uoO5ma9yRKdtsc0etvLCeU3UXybv6F4D 0wYh/GH3abDquPR6qT9X02dN3uOcioSGRedn2ii5dZrjRCJCpCjvqt3BidYJlo8c7iKb lOS0ZFSqUlv7u8Zzf4sPlh9C442RDMaeOgIHG4blLjCtQLjjhe6QYHmBEQTSYFsqQenY 1XIlauPPoJBZgqaCLxxtIsZW2D7TQnCx7AJ/GWLJL6FuerPn41kY/cNzciGdXaOwvEVx sqFQ== 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=3p86GhzxykeEmOAJrS3YLD/pTaBBvwR0YKxhsDSgrVc=; b=QeC6JQzDTYtxExIdSv6/a2VHwcnHOrezRRhOCvJ2LsXF+5d98j3Roac+e3Ki8EeaS7 k9VzMnfjnKbKcZ9OHbKuNeASgmcqpaxPbCtlSHLhaocv2WCCH5P3CXWu6Km5xK892DiB 0Bm7YoPljD7t+7swWK44sqIn8QAQJu5bRFibPQkCQ+/6z2pQQtjoJI9oZN+CJUQSDBxi AYDEye4bK7E3QlT9QXyvVhJDV77x4rCXfFk9iWzLXgj42DFplZ0GctUOGlS1HPSiSFah cndz9GenIyuAbjr/S+5fMfFJFUN25WEaM0eaPN+IiS9rL8lfbd/yCvcppEYt/za2V4aI ofZQ== 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 j24-v6si26151055pfn.363.2018.09.21.00.49.50; Fri, 21 Sep 2018 00:50:07 -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 S2389448AbeIUNhU (ORCPT + 99 others); Fri, 21 Sep 2018 09:37:20 -0400 Received: from mga03.intel.com ([134.134.136.65]:46880 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725898AbeIUNhS (ORCPT ); Fri, 21 Sep 2018 09:37:18 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Sep 2018 00:49:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,284,1534834800"; d="scan'208";a="90711525" Received: from svm-s2600wft.bj.intel.com ([10.240.193.45]) by fmsmga004.fm.intel.com with ESMTP; 21 Sep 2018 00:49:33 -0700 From: Yi Sun To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, tglx@linutronix.de, 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 Subject: [PATCH v2 2/2] locking/pvqspinlock, hv: Enable PV qspinlock for Hyper-V Date: Fri, 21 Sep 2018 15:25:12 +0800 Message-Id: <1537514712-62434-3-git-send-email-yi.y.sun@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1537514712-62434-1-git-send-email-yi.y.sun@linux.intel.com> References: <1537514712-62434-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 Signed-off-by: Yi Sun --- v1->v2: - compile hv_spinlock.c only when CONFIG_PARAVIRT_SPINLOCKS enabled - merge v1 patch 2/3 to single patch (suggested by Thomas Gleixner) - remove part of the boilerplate in hv_spinlock.c (suggested by Thomas Gleixner) - declare hv_pvspin as __initdata (suggested by Thomas Gleixner) - remove spin_wait_info and hv_notify_long_spin_wait because SpinWaitInfo is a standalone feature. - add comments for reading HV_X64_MSR_GUEST_IDLE (suggested by Thomas Gleixner) - replace pr_warn to pr_info (suggested by Thomas Gleixner) - use pr_fmt instead of the 'hv:' prefix (suggested by Thomas Gleixner) - register callback function for smp_ops.smp_prepare_boot_cpu to initialize hyper-v spinlock (suggested by Thomas Gleixner) --- Documentation/admin-guide/kernel-parameters.txt | 5 ++ arch/x86/hyperv/Makefile | 4 ++ arch/x86/hyperv/hv_spinlock.c | 81 +++++++++++++++++++++++++ arch/x86/include/asm/mshyperv.h | 3 + arch/x86/kernel/cpu/mshyperv.c | 12 ++++ 5 files changed, 105 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..0dafcc6 --- /dev/null +++ b/arch/x86/hyperv/hv_spinlock.c @@ -0,0 +1,81 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Hyper-V specific spinlock code. + * + * Copyright (C) 2018, Intel, Inc. + * + * Author : Yi Sun + */ + +#define pr_fmt(fmt) "hv: " fmt + +#include +#include +#include +#include +#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. + */ + if (ms_hyperv.features & HV_X64_MSR_GUEST_IDLE_AVAILABLE) + rdmsrl(HV_X64_MSR_GUEST_IDLE, msr_val); +} + +/* + * 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..ac36ea9 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -355,6 +355,8 @@ static inline int cpumask_to_vpset(struct hv_vpset *vpset, static inline void hv_apic_init(void) {} #endif +void __init hv_init_spinlocks(void); + #else /* CONFIG_HYPERV */ static inline void hyperv_init(void) {} static inline bool hv_is_hyperv_initialized(void) { return false; } @@ -368,6 +370,7 @@ static inline struct hv_vp_assist_page *hv_get_vp_assist_page(unsigned int cpu) return NULL; } static inline int hyperv_flush_guest_mapping(u64 as) { return -1; } +void __init hv_init_spinlocks(void) {} #endif /* CONFIG_HYPERV */ #ifdef CONFIG_HYPERV_TSCPAGE diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index ad12733..4d12d3c 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -199,6 +199,14 @@ static unsigned long hv_get_tsc_khz(void) return freq / 1000; } +#if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS) +static void __init hv_smp_prepare_boot_cpu(void) +{ + native_smp_prepare_boot_cpu(); + hv_init_spinlocks(); +} +#endif + static void __init ms_hyperv_init_platform(void) { int hv_host_info_eax; @@ -304,6 +312,10 @@ static void __init ms_hyperv_init_platform(void) alloc_intr_gate(HYPERV_STIMER0_VECTOR, hv_stimer0_callback_vector); #endif + +#if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS) + smp_ops.smp_prepare_boot_cpu = hv_smp_prepare_boot_cpu; +#endif } const __initconst struct hypervisor_x86 x86_hyper_ms_hyperv = { -- 1.9.1