Received: by 10.223.164.202 with SMTP id h10csp281279wrb; Thu, 9 Nov 2017 06:18:38 -0800 (PST) X-Google-Smtp-Source: ABhQp+RAF75giWKWxap7sE/BijylTBihdTZTG1zEyhAO9QGMZI0RhsQRbYboZqzkJaZGbh7GJq2p X-Received: by 10.98.233.21 with SMTP id j21mr633977pfh.97.1510237118067; Thu, 09 Nov 2017 06:18:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510237118; cv=none; d=google.com; s=arc-20160816; b=pW5tnMNFpWh5rFfozwvwJhs79fpeS83NvT97/xmS3/bzR7+pzaYFLXF+FTGgT0ZqRB wTqJHOsaz8ziRW+O1IRw8LR3m/8tz/67TqXcae1JPj6/23ygoXydXtGKKU/26NSEqeI7 R5wem4WpjQAYUs8qIS5BgBoQrvEddzdpmazqBGIlr31I7XJkyN9EXsP/vOc7J7F+TyAl 1PXqOPwsyu7PX8aVtJrSkd+Jm4ZB2tSrmEsGKY89zxrS6rnbim+bmQ/OvwqqQlovJXGM yna3w/BTS3g6t0jUYc+TCNE6e1gdLFjao1S4Q7GI/1JrQm0FErdKyNoxRSX7XA78Ihbl uRcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=x8rAhEhhSnEOryps0lSdQ6h/GRAAHGLA7ibBtWbnjsw=; b=mIp08DbXp9H7p0a7OSb2QFjeuPzIWkX/sOaDhhPf/ETz7MhrFCYM42O+kVYf6oG7uT yIZwef9MCaZ+KIbS4QlPPsvF3KbWjD2IdRJIxxVeOj4tB/JDPeG2pdTrsk4jmSb2Sapk d5VvVgbZ4QTpwhhi6c66FnkrkU9Vp17wYQzMo49TLoZRl0kw0sQpZICfUG6nvbucaAQZ n/qgFXQ93JqBGBWU21174qiuaAqzn4dhK93caWsFS6TZBln6s4i7qAxr2ptzkkyEV8Vz SMN+Bzgy6qX23wFv/i6dwGeptfshx1+/y9UhZrM6hDOu0fIlI9Vu3H+mTtc0roOoArMP Y9eg== 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 q2si6164297plh.590.2017.11.09.06.18.26; Thu, 09 Nov 2017 06:18:38 -0800 (PST) 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 S1754890AbdKIORp (ORCPT + 80 others); Thu, 9 Nov 2017 09:17:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55580 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753849AbdKIORn (ORCPT ); Thu, 9 Nov 2017 09:17:43 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4723D2CE909; Thu, 9 Nov 2017 14:17:43 +0000 (UTC) Received: from flask (unknown [10.43.2.80]) by smtp.corp.redhat.com (Postfix) with SMTP id E28A66375A; Thu, 9 Nov 2017 14:17:33 +0000 (UTC) Received: by flask (sSMTP sendmail emulation); Thu, 09 Nov 2017 15:17:33 +0100 Date: Thu, 9 Nov 2017 15:17:33 +0100 From: Radim =?utf-8?B?S3LEjW3DocWZ?= To: Eduardo Valentin Cc: Paolo Bonzini , Matt Wilson , Jonathan Corbet , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Peter Zijlstra , Waiman Long , kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, "Jan H . Schoenherr" , Anthony Liguori Subject: Re: [PATCHv3 1/1] locking/qspinlock/x86: Avoid test-and-set when PV_DEDICATED is set Message-ID: <20171109141732.GA20859@flask> References: <1509999980-10828-1-git-send-email-eduval@amazon.com> <20171108173651.GA3664@flask> <20171109085547.GA5107@u40b0340c692b58f6553c.ant.amazon.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20171109085547.GA5107@u40b0340c692b58f6553c.ant.amazon.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 09 Nov 2017 14:17:43 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2017-11-09 00:55-0800, Eduardo Valentin: > Hello, > > On Wed, Nov 08, 2017 at 06:36:52PM +0100, Radim Krčmář wrote: > > 2017-11-06 12:26-0800, Eduardo Valentin: > > > Currently, the existing qspinlock implementation will fallback to > > > test-and-set if the hypervisor has not set the PV_UNHALT flag. > > > > > > This patch gives the opportunity to guest kernels to select > > > between test-and-set and the regular queueu fair lock implementation > > > based on the PV_DEDICATED KVM feature flag. When the PV_DEDICATED > > > flag is not set, the code will still fall back to test-and-set, > > > but when the PV_DEDICATED flag is set, the code will use > > > the regular queue spinlock implementation. > > > > > > With this patch, when in autoselect mode, the guest will > > > use the default spinlock implementation based on host feature > > > flags as follows: > > > > > > PV_DEDICATED = 1, PV_UNHALT = anything: default is qspinlock > > > PV_DEDICATED = 0, PV_UNHALT = 1: default is pvqspinlock > > > PV_DEDICATED = 0, PV_UNHALT = 0: default is tas > > > > > > Cc: Paolo Bonzini > > > Cc: "Radim Krčmář" > > > Cc: Jonathan Corbet > > > Cc: Thomas Gleixner > > > Cc: Ingo Molnar > > > Cc: "H. Peter Anvin" > > > Cc: x86@kernel.org > > > Cc: Peter Zijlstra > > > Cc: Waiman Long > > > Cc: kvm@vger.kernel.org > > > Cc: linux-doc@vger.kernel.org > > > Cc: linux-kernel@vger.kernel.org > > > Cc: Jan H. Schoenherr > > > Cc: Anthony Liguori > > > Suggested-by: Matt Wilson > > > Signed-off-by: Eduardo Valentin > > > --- > > > V3: > > > - When PV_DEDICATED is set (1), qspinlock is selected, > > > regardless of the value of PV_UNHAULT. Suggested by Paolo Bonzini. > > > - Refreshed on top of tip/master. > > > V2: > > > - rebase on top of tip/master > > > > > > Documentation/virtual/kvm/cpuid.txt | 6 ++++++ > > > arch/x86/include/asm/qspinlock.h | 4 ++++ > > > arch/x86/include/uapi/asm/kvm_para.h | 1 + > > > arch/x86/kernel/kvm.c | 2 ++ > > > 4 files changed, 13 insertions(+) > > > > > > diff --git a/Documentation/virtual/kvm/cpuid.txt b/Documentation/virtual/kvm/cpuid.txt > > > index 3c65feb..117066a 100644 > > > --- a/Documentation/virtual/kvm/cpuid.txt > > > +++ b/Documentation/virtual/kvm/cpuid.txt > > > @@ -54,6 +54,12 @@ KVM_FEATURE_PV_UNHALT || 7 || guest checks this feature bit > > > || || before enabling paravirtualized > > > || || spinlock support. > > > ------------------------------------------------------------------------------ > > > +KVM_FEATURE_PV_DEDICATED || 8 || guest checks this feature bit > > > + || || to determine if they run on > > > + || || dedicated vCPUs, allowing opti- > > > + || || mizations such as usage of > > > + || || qspinlocks. > > > +------------------------------------------------------------------------------ > > > KVM_FEATURE_CLOCKSOURCE_STABLE_BIT || 24 || host will warn if no guest-side > > > || || per-cpu warps are expected in > > > || || kvmclock. > > > diff --git a/arch/x86/include/asm/qspinlock.h b/arch/x86/include/asm/qspinlock.h > > > index 5e16b5d..de42694 100644 > > > --- a/arch/x86/include/asm/qspinlock.h > > > +++ b/arch/x86/include/asm/qspinlock.h > > > @@ -3,6 +3,8 @@ > > > #define _ASM_X86_QSPINLOCK_H > > > > > > #include > > > +#include > > > + > > > #include > > > #include > > > #include > > > @@ -58,6 +60,8 @@ static inline bool virt_spin_lock(struct qspinlock *lock) > > > if (!static_branch_likely(&virt_spin_lock_key)) > > > return false; > > > > > > + if (kvm_para_has_feature(KVM_FEATURE_PV_DEDICATED)) > > > + return false; > > > > Hm, every spinlock slowpath calls cpuid, which causes a VM exit, so I > > wouldn't expect it to be faster than the existing implementations. > > (Using the static key would be better.) > > > > How does this patch perform compared to user-forced qspinlock and hybrid > > pvqspinlock? > > This patch should have same effect as user-forced qspinlock. This is what I'm doubting, because the patch is adding about two thousand cycles to every spinlock-taken path. Doesn't this patch yield better results? diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index 3df743b60c80..d9225e48c11a 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -676,6 +676,12 @@ void __init kvm_spinlock_init(void) { if (!kvm_para_available()) return; + + if (kvm_para_has_feature(KVM_FEATURE_PV_DEDICATED)) { + static_branch_disable(&virt_spin_lock_key); + return; + } + /* Does host kernel support KVM_FEATURE_PV_UNHALT? */ if (!kvm_para_has_feature(KVM_FEATURE_PV_UNHALT)) return; > However, the key aspect > here is this patch gives a way for the host to instruct the guest to use qspinlock. > Even with Longman's patch which allows guest to select the spinlock implementation, > there should still be the auto-select mode. In such mode, PV_DEDICATED should > allow the host to get the guest to use qspinlock, without, the guest will fallback > to tas when PV_UNHALT == 0. I agree that a flag can be useful for certains setups. From 1583592449275202699@xxx Thu Nov 09 12:44:06 +0000 2017 X-GM-THRID: 1583352031107436177 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread