Received: by 10.223.164.202 with SMTP id h10csp403310wrb; Thu, 9 Nov 2017 08:06:33 -0800 (PST) X-Google-Smtp-Source: ABhQp+QKZj0rbIXhm5UbeSumNkRiN5fggiuxIikCPBdx0khGBofnqcYIEmvFALZliY8l5tIME0yv X-Received: by 10.84.224.65 with SMTP id a1mr883326plt.421.1510243593825; Thu, 09 Nov 2017 08:06:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510243593; cv=none; d=google.com; s=arc-20160816; b=YScoKAJNucsuny/1L5WZor0Z0Pn6Y6EhIw77c1/b1HbRFE+a+WIEUT3LF2GDO40SSZ r17uHdota09YeV59E/kxqKu84/yfgKR55rUqvZGzzyn61EgHf7V1SK/Ma7FzPlcj74JK qMVLXCPW7Qh+uifXjwEwDbXrOcJv+X329YdrmfB3JAxZioLMJkOnm1UIsOF0WKblBnrr aujFK1XDpNtlhnHWTQYq5VqJFL5LxQKJK+SxlR6Vv5O5yXFhvFEuPEVQanOoVhO+vzWc H7pnXOFyy6Mr0iE6NWuUuWKNMeZLKXoRd+73QEGZeRP7dMTjWaIaSmLppn1atPCg7TUf Edlg== 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=MWu1q2sR1AcPNvD80Xlunc8E3jqp21C9kGBypj/2e90=; b=a1+CHaH6KEzTz3KJyCe7DYLsM0T+oKIwKBahGHimf45fjf2dUz1xYSKa2jxsHXgdyY IBKsTJRkFjNM23yhfQqHvrsxEMvPbZaB58/9PYqHbd2xglb4u/RhUDh6y6HvtlAiClaZ y0T2cY2WoXw9XB2QLZtd2IxHxICKMduv3Qkb2uXWblxFI0gxyOfZTT7UkxAxoBsyh9HA 519QkFuQzvirQyclGXn/rqAOy/zzLCGywJGMv9hOCjjcR7HdDRYO77ju4OGR2OI6MziC z9bkcNXWm9NIXZxDgxRF9+zDDCHckgVemYbfJfv/l154uQxoxPrcL1xYb7M7reOvNDed HVdg== 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 a8si6580482pls.287.2017.11.09.08.06.21; Thu, 09 Nov 2017 08:06:33 -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 S1751197AbdKIQFo (ORCPT + 81 others); Thu, 9 Nov 2017 11:05:44 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35928 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752667AbdKIQFm (ORCPT ); Thu, 9 Nov 2017 11:05:42 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 012A785A02; Thu, 9 Nov 2017 16:05:42 +0000 (UTC) Received: from flask (unknown [10.43.2.80]) by smtp.corp.redhat.com (Postfix) with SMTP id B3F4B6F977; Thu, 9 Nov 2017 16:05:37 +0000 (UTC) Received: by flask (sSMTP sendmail emulation); Thu, 09 Nov 2017 17:05:36 +0100 Date: Thu, 9 Nov 2017 17:05:36 +0100 From: Radim Krcmar To: Pankaj Gupta Cc: Wanpeng Li , Eduardo Valentin , Paolo Bonzini , Matt Wilson , Jonathan Corbet , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , the arch/x86 maintainers , Peter Zijlstra , Waiman Long , kvm , 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: <20171109160536.GE20859@flask> References: <1509999980-10828-1-git-send-email-eduval@amazon.com> <789734192.29237413.1510242805535.JavaMail.zimbra@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <789734192.29237413.1510242805535.JavaMail.zimbra@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 09 Nov 2017 16:05:42 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2017-11-09 10:53-0500, Pankaj Gupta: > > > > 2017-11-07 4:26 GMT+08:00 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; > > > /* > > > * On hypervisors without PARAVIRT_SPINLOCKS support we fall > > > * back to a Test-and-Set spinlock, because fair locks have > > > diff --git a/arch/x86/include/uapi/asm/kvm_para.h > > > b/arch/x86/include/uapi/asm/kvm_para.h > > > index 554aa8f..85a9875 100644 > > > --- a/arch/x86/include/uapi/asm/kvm_para.h > > > +++ b/arch/x86/include/uapi/asm/kvm_para.h > > > @@ -25,6 +25,7 @@ > > > #define KVM_FEATURE_STEAL_TIME 5 > > > #define KVM_FEATURE_PV_EOI 6 > > > #define KVM_FEATURE_PV_UNHALT 7 > > > +#define KVM_FEATURE_PV_DEDICATED 8 > > > > > > /* The last 8 bits are used to indicate how to interpret the flags field > > > * in pvclock structure. If no bits are set, all flags are ignored. > > > diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c > > > index 8bb9594..dacd7cf 100644 > > > --- a/arch/x86/kernel/kvm.c > > > +++ b/arch/x86/kernel/kvm.c > > > @@ -642,6 +642,8 @@ void __init kvm_spinlock_init(void) > > > { > > > if (!kvm_para_available()) > > > return; > > > + if (kvm_para_has_feature(KVM_FEATURE_PV_DEDICATED)) > > > + return; > > > /* Does host kernel support KVM_FEATURE_PV_UNHALT? */ > > > if (!kvm_para_has_feature(KVM_FEATURE_PV_UNHALT)) > > > return; > > > -- > > > 2.7.4 > > > > > > > You should also add a cpuid flag in kvm part. > > Also, I am thinking if PV_DEDICATED helps in performance and with conjunction > with PV TLB patch in other thread. For use-case e.g KVM-RT where we don't overcommit > vCPU's and pin vCPU:pCPU 1:1 we need a way from host side with which user can decide > to enable PV_DEDICATED option. Such that if vCPU's are unlikely going to preempt or > sleep we should avoid traversing the cpulist in PV TLB code. > > So, two things: > > 1] A way to configure PV_DEDICATED from host. Userspace can already configure it through KVM_SET_CPUID2 ioctl (regardless of KVM version). > 2] PV TLB should also behave as per option PV_DEDICATED for better performance. Right, thanks. From 1583605009280079043@xxx Thu Nov 09 16:03:44 +0000 2017 X-GM-THRID: 1583352031107436177 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread