Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp5643998ybg; Tue, 22 Oct 2019 06:24:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqzPNMAyp/kYMkYULjLs4NqgMjuOkkqM1GpgQDCr98jdkvRFuZ7IwiFsCOKIUoJ12cMjex1F X-Received: by 2002:a17:906:4545:: with SMTP id s5mr26413280ejq.223.1571750664038; Tue, 22 Oct 2019 06:24:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571750664; cv=none; d=google.com; s=arc-20160816; b=00ncGlOufQwDlDiMXzK1CKtPZelUajRCqWmBtt5ACxWhN+UkKXa5ScpKUIdKdNK59X BA/EJqE3P/V/KlSMrspI2nHi4QvKD8LjFWjdPEfF8e0shDkwn64IHr35L2gFPOCaVwHz NVgoWBf5dZqzp7Im88m8DwNHqlTJLy0MbCeN4orynigbyshQBSlmvgnWqcnMslePL8y1 QzUQy9uhDznHMj/PG4Yzrpx+LMw1nNaGUjA/vr6LDgBBVdHdLzDqTbSCrvuipskSxel5 Aa1gpypMmJs7tun2baU4Fs8vp/4Mepe4xpf8GXxRXloKlz2cFwptuihWAcfbsH75wmHP 8rNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from; bh=FTSbOqc/cP0++TLaNzktd3vhmDx93fKNtqalIV8xNj4=; b=nRLC4dwBJz5HFvdBqbmtND4xpPUw3wAtL/VtoODVst3DAV443LgW9fLqlcjVMV9n4M LNRxuElfIuYgfIUxk8coxByk2eIBm/nKWVhuUjzRERmfCbGKtAUG8GsX3uZawYIm+efR 4asTUV9l7lt/RvH608HvFSmOTVVfhqbGvhgs5YblGXv1yZuqV82X0hs60FRs7DoMvtBJ Q/rB+rc5KCHCsacB5rCQcbIPaF72TEfB0mlOOXmJsrwvwSi3u1wYCcHZlP/O5sS3/+Ff KmVO5tZDwENXFH3MDTxdtYcrYTdjYoA2MwGl/zc2VtmEkuwc0nPmQHxwXx4ohyYOYlCD TvQg== 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 bo22si10815563ejb.369.2019.10.22.06.23.59; Tue, 22 Oct 2019 06:24: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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388713AbfJVLgj (ORCPT + 99 others); Tue, 22 Oct 2019 07:36:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49892 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388705AbfJVLgj (ORCPT ); Tue, 22 Oct 2019 07:36:39 -0400 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A32B93688E for ; Tue, 22 Oct 2019 11:36:38 +0000 (UTC) Received: by mail-wr1-f72.google.com with SMTP id a6so6163430wru.1 for ; Tue, 22 Oct 2019 04:36:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=FTSbOqc/cP0++TLaNzktd3vhmDx93fKNtqalIV8xNj4=; b=K/hLQUH/IFvxazJNog+HGOwIJXRg/f+m2oXk1wZuInjE6ZuKlNoWsOjujh3dQYP+nH vOghgWY7Z7pPdXOrIG/s74x2hrSU8gsBBO5ZRGXRQga7Hf+s1e6Kpo6B8u9HL6OlvHJI zhGOa0uP8trv+XY9l6rg3EySxJacBDcAU6T4LirnNZHJyvP7LpRd0aKP0oIZ+8+zcbAx Fqk12LMJpwiiRKHiJ2cIZqKaD2mXYZB/IrQVooET7l0L4RGQEV+c2w8dynVP2KtxPSpm SGKE93dulEi8mg6wfXTa9aYO09TespXeV4FQcL4tofZ2uNIoB+UG4qRMviC0QDBtsJGP 5GYg== X-Gm-Message-State: APjAAAWo0O5hejFrhOdu8t//RR2AnDvMFh5cQ7S4QiJgtb1V4yiEp2uu WCl53Eh3HIRRPxB+avnedduvTUxl2JiYTjUJZnJOLwq95E2Jqv+2TIWmqGZZD6ejpJ76Co7YR28 ZsL9YFy7SNBCxYx2jXgF+Ys/P X-Received: by 2002:a1c:814b:: with SMTP id c72mr2717182wmd.167.1571744197227; Tue, 22 Oct 2019 04:36:37 -0700 (PDT) X-Received: by 2002:a1c:814b:: with SMTP id c72mr2717136wmd.167.1571744196883; Tue, 22 Oct 2019 04:36:36 -0700 (PDT) Received: from vitty.brq.redhat.com (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id p10sm20019762wrx.2.2019.10.22.04.36.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2019 04:36:36 -0700 (PDT) From: Vitaly Kuznetsov To: Zhenzhong Duan , linux-kernel@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, pbonzini@redhat.com, rkrcmar@redhat.com, sean.j.christopherson@intel.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, boris.ostrovsky@oracle.com, jgross@suse.com, peterz@infradead.org, will@kernel.org, linux-hyperv@vger.kernel.org, kvm@vger.kernel.org, mikelley@microsoft.com, kys@microsoft.com, haiyangz@microsoft.com, sthemmin@microsoft.com, sashal@kernel.org, Zhenzhong Duan , Jonathan Corbet , "H. Peter Anvin" Subject: Re: [PATCH v7 3/5] x86/kvm: Add "nopvspin" parameter to disable PV spinlocks In-Reply-To: <1571649076-2421-4-git-send-email-zhenzhong.duan@oracle.com> References: <1571649076-2421-1-git-send-email-zhenzhong.duan@oracle.com> <1571649076-2421-4-git-send-email-zhenzhong.duan@oracle.com> Date: Tue, 22 Oct 2019 13:36:34 +0200 Message-ID: <8736fl1071.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Zhenzhong Duan writes: > There are cases where a guest tries to switch spinlocks to bare metal > behavior (e.g. by setting "xen_nopvspin" on XEN platform and > "hv_nopvspin" on HYPER_V). > > That feature is missed on KVM, add a new parameter "nopvspin" to disable > PV spinlocks for KVM guest. > > The new 'nopvspin' parameter will also replace Xen and Hyper-V specific > parameters in future patches. > > Define variable nopvsin as global because it will be used in future > patches as above. > > Signed-off-by: Zhenzhong Duan > Reviewed-by: Vitaly Kuznetsov > Cc: Jonathan Corbet > Cc: Thomas Gleixner > Cc: Ingo Molnar > Cc: Borislav Petkov > Cc: "H. Peter Anvin" > Cc: Paolo Bonzini > Cc: Radim Krcmar > Cc: Sean Christopherson > Cc: Vitaly Kuznetsov > Cc: Wanpeng Li > Cc: Jim Mattson > Cc: Joerg Roedel > Cc: Peter Zijlstra > Cc: Will Deacon > --- > Documentation/admin-guide/kernel-parameters.txt | 5 ++++ > arch/x86/include/asm/qspinlock.h | 1 + > arch/x86/kernel/kvm.c | 34 ++++++++++++++++++++----- > kernel/locking/qspinlock.c | 7 +++++ > 4 files changed, 40 insertions(+), 7 deletions(-) > > diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt > index a84a83f..bd49ed2 100644 > --- a/Documentation/admin-guide/kernel-parameters.txt > +++ b/Documentation/admin-guide/kernel-parameters.txt > @@ -5334,6 +5334,11 @@ > as generic guest with no PV drivers. Currently support > XEN HVM, KVM, HYPER_V and VMWARE guest. > > + nopvspin [X86,KVM] > + Disables the qspinlock slow path using PV optimizations > + which allow the hypervisor to 'idle' the guest on lock > + contention. > + > xirc2ps_cs= [NET,PCMCIA] > Format: > ,,,,,[,[,[,]]] > diff --git a/arch/x86/include/asm/qspinlock.h b/arch/x86/include/asm/qspinlock.h > index 444d6fd..d86ab94 100644 > --- a/arch/x86/include/asm/qspinlock.h > +++ b/arch/x86/include/asm/qspinlock.h > @@ -32,6 +32,7 @@ static __always_inline u32 queued_fetch_set_pending_acquire(struct qspinlock *lo > extern void __pv_init_lock_hash(void); > extern void __pv_queued_spin_lock_slowpath(struct qspinlock *lock, u32 val); > extern void __raw_callee_save___pv_queued_spin_unlock(struct qspinlock *lock); > +extern bool nopvspin; > > #define queued_spin_unlock queued_spin_unlock > /** > diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c > index 249f14a..3945aa5 100644 > --- a/arch/x86/kernel/kvm.c > +++ b/arch/x86/kernel/kvm.c > @@ -825,18 +825,36 @@ __visible bool __kvm_vcpu_is_preempted(long cpu) > */ > void __init kvm_spinlock_init(void) > { > - /* Does host kernel support KVM_FEATURE_PV_UNHALT? */ > - if (!kvm_para_has_feature(KVM_FEATURE_PV_UNHALT)) > + /* > + * In case host doesn't support KVM_FEATURE_PV_UNHALT there is still an > + * advantage of keeping virt_spin_lock_key enabled: virt_spin_lock() is > + * preferred over native qspinlock when vCPU is preempted. > + */ > + if (!kvm_para_has_feature(KVM_FEATURE_PV_UNHALT)) { > + pr_info("PV spinlocks disabled, no host support.\n"); > return; > + } > > + /* > + * Disable PV qspinlock and use native qspinlock when dedicated pCPUs > + * are available. > + */ > if (kvm_para_has_hint(KVM_HINTS_REALTIME)) { > - static_branch_disable(&virt_spin_lock_key); > - return; > + pr_info("PV spinlocks disabled with KVM_HINTS_REALTIME hints.\n"); > + goto out; > } > > - /* Don't use the pvqspinlock code if there is only 1 vCPU. */ > - if (num_possible_cpus() == 1) > - return; > + if (num_possible_cpus() == 1) { > + pr_info("PV spinlocks disabled, single CPU.\n"); > + goto out; > + } > + > + if (nopvspin) { > + pr_info("PV spinlocks disabled, forced by \"nopvspin\" parameter.\n"); > + goto out; > + } > + > + pr_info("PV spinlocks enabled\n"); > > __pv_init_lock_hash(); > pv_ops.lock.queued_spin_lock_slowpath = __pv_queued_spin_lock_slowpath; > @@ -849,6 +867,8 @@ void __init kvm_spinlock_init(void) > pv_ops.lock.vcpu_is_preempted = > PV_CALLEE_SAVE(__kvm_vcpu_is_preempted); > } > +out: > + static_branch_disable(&virt_spin_lock_key); You probably need to add 'return' before 'out:' as it seems you're disabling virt_spin_lock_key in all cases now). > } > > #endif /* CONFIG_PARAVIRT_SPINLOCKS */ > diff --git a/kernel/locking/qspinlock.c b/kernel/locking/qspinlock.c > index 2473f10..75193d6 100644 > --- a/kernel/locking/qspinlock.c > +++ b/kernel/locking/qspinlock.c > @@ -580,4 +580,11 @@ void queued_spin_lock_slowpath(struct qspinlock *lock, u32 val) > #include "qspinlock_paravirt.h" > #include "qspinlock.c" > > +bool nopvspin __initdata; > +static __init int parse_nopvspin(char *arg) > +{ > + nopvspin = true; > + return 0; > +} > +early_param("nopvspin", parse_nopvspin); > #endif -- Vitaly