Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp104157ybg; Tue, 22 Oct 2019 16:58:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqy+p9GlkasLYaQFZlpkVJNmpOTcjY0SPK9BwJT/uyW1Q42oJYxpHnS3rCXKg+glPac8D0l6 X-Received: by 2002:a17:906:4895:: with SMTP id v21mr25754967ejq.2.1571788710391; Tue, 22 Oct 2019 16:58:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571788710; cv=none; d=google.com; s=arc-20160816; b=kNOoXCwrJ3ggJwVDx6VpiVHm5plGDMdqEF7QjemqEqCIucp/g3bukI/3mOIPl37HOi wl2PpAH6Hkl5MJxfvxfkz+mNpT+vAnZqaaBoLmEd//law1dS+LqMfhsbcHVbpqFJ9PY1 9Zvp5xofHP/fOlItSc+uFkM7bmd+NDgP35d0yuNcD/CVruBMovMZKBdeB3R1ymcJCLYE DDNRMAmPl6oNB0Va6Q9gnM5Sn51Y/uwoa/UgJcZ5GuThX7bazbFuOxRLII8+jIzMDVn8 5q3E2FMjyS6o6Ohu4ZRJjGSA20NyqgDEFVYRxf/mo03Q64ttDlcdjbkw9smDRPnHfgNP Iu9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=6CAhxNEEyUyRE4iNtVl89zWv8nfeKCDF9+LcJD9kmHk=; b=WDODZQoOWpHePZ4/yas4xMQVOM9gAmZ2cf7P+056eilDFTBmGdKt3MaJtmAilOJWnz CTgtuzIGSlme0fQMKEqR2MM+USDQGq0zgimehzc39Hjq9E2Rb7GglWtDuQPkV6EkjzrS t7guv2flmLlmyx347dD/riPS72WHRsPf6FJy3vtw6KKBnDleCByTKuAEGKjLHj/+3QME MdtbmO2RlL9fyhK7ErFWjNa3Wu/xu1dad+UhWLTNl8wqO0VZPtdc8YPFxo1d/xxqRNN5 R+LG7FbrUa6o7xeBPTAHhdoHdod1tUMQJf1y8sJtdfWmw8WzcgtvgIGzH21JUd5STuYC veWA== 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 dx19si2175512ejb.113.2019.10.22.16.58.06; Tue, 22 Oct 2019 16:58:30 -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 S1732066AbfJVVD5 (ORCPT + 99 others); Tue, 22 Oct 2019 17:03:57 -0400 Received: from mga11.intel.com ([192.55.52.93]:60522 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725874AbfJVVD5 (ORCPT ); Tue, 22 Oct 2019 17:03:57 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Oct 2019 14:03:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,217,1569308400"; d="scan'208";a="349192117" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.41]) by orsmga004.jf.intel.com with ESMTP; 22 Oct 2019 14:03:55 -0700 Date: Tue, 22 Oct 2019 14:03:55 -0700 From: Sean Christopherson To: Zhenzhong Duan Cc: Vitaly Kuznetsov , linux-kernel@vger.kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, pbonzini@redhat.com, rkrcmar@redhat.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, Jonathan Corbet , "H. Peter Anvin" Subject: Re: [PATCH v7 3/5] x86/kvm: Add "nopvspin" parameter to disable PV spinlocks Message-ID: <20191022210355.GR2343@linux.intel.com> References: <1571649076-2421-1-git-send-email-zhenzhong.duan@oracle.com> <1571649076-2421-4-git-send-email-zhenzhong.duan@oracle.com> <8736fl1071.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 22, 2019 at 08:46:46PM +0800, Zhenzhong Duan wrote: > Hi Vitaly, > > On 2019/10/22 19:36, Vitaly Kuznetsov wrote: > > >Zhenzhong Duan writes: > > > ...snip > > >>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). > > virt_spin_lock_key is kept enabled in !kvm_para_has_feature(KVM_FEATURE_PV_UNHALT) > case which is the only case virt_spin_lock() optimization is used. > > When PV qspinlock is enabled, virt_spin_lock() isn't called in > __pv_queued_spin_lock_slowpath() in which case we don't care > virt_spin_lock_key's value. > > So adding 'return' or not are both ok, I chosed to save a line, > let me know if you prefer to add a 'return' and I'll change it. It'd be worth adding a comment here if you end up spinning another version to change the logging prefix. The logic is sound and I like the end result, but I had the same knee jerk "this can't be right!?!?" reaction as Vitaly.