Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp459423imm; Thu, 13 Sep 2018 02:38:24 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbmBdAbkpd2MH1gF1g2XvGM/MBFu8dL9LnD9hTU35CEOJ6ohRSK6muceCYNN+E6cBLJGfbR X-Received: by 2002:a17:902:28a4:: with SMTP id f33-v6mr6423444plb.297.1536831504738; Thu, 13 Sep 2018 02:38:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536831504; cv=none; d=google.com; s=arc-20160816; b=cdmV6CvzucmfGQ8FtHeTFY+rWxIv9vTs8Tpa3VxBWNlaAESD9xUFgoVivICX3+Uixq yAX8uc7i8Axq5qKveGGf67ytUb95KRlNrYUr1cNPOgHRp/ASbFclizn+xsaSxFJUimQG lBI2zxVXtiyphAXoiCFmxjau3/1WPNXeypSu56WbHxH8gWGhbq99mUBhRZnSDblwxm2w A8erx79hFkX+T3hWDygdo7TBo9ICUWJn1Mk/t8KH7hbtO0U4edhB4M2j+5E2JTWgGYeD waer5DBdHp4cYy+WnzQv11sbBZSsa5PRfjt9hxevUprMp7H2vM1eTI63tyQUeMrXTa9Q EPAw== 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=JmOH4L3wbZybkxHqaM+FXe9iStPaKwhbFZNBJDf9VHY=; b=SS1VMseqS0I/MTWZgk0Eu4M2RZ7oMY8u01ENaieKZsA1NUZo0y/uRUlvXJSEAOPV6c LfDaqYcZ9ytOYFZ4q8+xUyqc1T5pNHOjEcoT58TDU5SzFACvb7ebG9Dckf7jaesxCjSi hEzTA4N8fkcsk8b45RBEumoNhcHN9x0s+il2sOmu+GmsoQN4VBGyAuwQzgl78HxPWYU9 21sYVdpc1RBpXCclRQJ6vtKsJjZYbmwbekD7JJ0byrHSynUAZ9VUgvKS1gm0wKP2qtFC YINfGUlj159RSh3UJ/Da9T+4i4ySdoWZbPTax8YpTrfuzkoIvi+lGSU1byROSjFwTVZc az9A== 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 c128-v6si3628006pfg.347.2018.09.13.02.38.09; Thu, 13 Sep 2018 02:38:24 -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 S1728084AbeIMOqi (ORCPT + 99 others); Thu, 13 Sep 2018 10:46:38 -0400 Received: from mga01.intel.com ([192.55.52.88]:49364 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728031AbeIMOqh (ORCPT ); Thu, 13 Sep 2018 10:46:37 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Sep 2018 02:37:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,368,1531810800"; d="scan'208";a="90093148" Received: from svm-s2600wft.bj.intel.com ([10.240.193.45]) by orsmga001.jf.intel.com with ESMTP; 13 Sep 2018 02:37:50 -0700 From: Yi Sun To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, chao.p.peng@intel.com, chao.gao@intel.com, isaku.yamahata@intel.com, michael.h.kelly@microsoft.com, tianyu.lan@microsoft.com, Yi Sun , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger Subject: [PATCH v1 2/3] locking/pvqspinlock, hv: Enable PV qspinlock for Hyper-V Date: Thu, 13 Sep 2018 17:13:24 +0800 Message-Id: <1536830005-37260-3-git-send-email-yi.y.sun@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1536830005-37260-1-git-send-email-yi.y.sun@linux.intel.com> References: <1536830005-37260-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. HVCALL_NOTIFY_LONG_SPIN_WAIT is a hypercall used by a guest OS to notify the hypervisor that the calling virtual processor is attempting to acquire a resource that is potentially held by another virtual processor within the same partition. This scheduling hint improves the scalability of partitions with more than one virtual processor. Cc: "K. Y. Srinivasan" Cc: Haiyang Zhang Cc: Stephen Hemminger Signed-off-by: Yi Sun --- arch/x86/hyperv/Makefile | 2 +- arch/x86/hyperv/hv_spinlock.c | 99 +++++++++++++++++++++++++++++++++++++++++ arch/x86/include/asm/mshyperv.h | 3 ++ arch/x86/kernel/smpboot.c | 2 + 4 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 arch/x86/hyperv/hv_spinlock.c diff --git a/arch/x86/hyperv/Makefile b/arch/x86/hyperv/Makefile index b21ee65..5b6937c 100644 --- a/arch/x86/hyperv/Makefile +++ b/arch/x86/hyperv/Makefile @@ -1,2 +1,2 @@ obj-y := hv_init.o mmu.o nested.o -obj-$(CONFIG_X86_64) += hv_apic.o +obj-$(CONFIG_X86_64) += hv_apic.o hv_spinlock.o diff --git a/arch/x86/hyperv/hv_spinlock.c b/arch/x86/hyperv/hv_spinlock.c new file mode 100644 index 0000000..134c89f --- /dev/null +++ b/arch/x86/hyperv/hv_spinlock.c @@ -0,0 +1,99 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Hyper-V specific spinlock code. + * + * Copyright (C) 2018, Intel, Inc. + * + * Author : Yi Sun + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or + * NON INFRINGEMENT. See the GNU General Public License for more + * details. + * + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +static bool hv_pvspin = true; +static u32 spin_wait_info = 0; + +static void hv_notify_long_spin_wait(void) +{ + u64 input = spin_wait_info | 0x00000000ffffffff; + + spin_wait_info++; + hv_do_fast_hypercall8(HVCALL_NOTIFY_LONG_SPIN_WAIT, input); +} + +static void hv_qlock_kick(int cpu) +{ + spin_wait_info--; + apic->send_IPI(cpu, X86_PLATFORM_IPI_VECTOR); +} + +/* + * Halt the current CPU & release it back to the host + */ +static void hv_qlock_wait(u8 *byte, u8 val) +{ + unsigned long msr_val; + + if (READ_ONCE(*byte) != val) + return; + + hv_notify_long_spin_wait(); + + 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_warn("hv: PV spinlocks disabled\n"); + return; + } + pr_info("hv: 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/smpboot.c b/arch/x86/kernel/smpboot.c index f02ecaf..8bf08ba 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -81,6 +81,7 @@ #include #include #include +#include /* representing HT siblings of each logical CPU */ DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_sibling_map); @@ -1335,6 +1336,7 @@ void __init native_smp_prepare_boot_cpu(void) /* already set me in cpu_online_mask in boot_cpu_init() */ cpumask_set_cpu(me, cpu_callout_mask); cpu_set_state_online(me); + hv_init_spinlocks(); } void __init calculate_max_logical_packages(void) -- 1.9.1