From patchwork Tue Oct 24 00:44:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eduardo Valentin X-Patchwork-Id: 10023395 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2BA2A603D7 for ; Tue, 24 Oct 2017 00:45:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E0D828946 for ; Tue, 24 Oct 2017 00:45:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 123F928951; Tue, 24 Oct 2017 00:45:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B6622894D for ; Tue, 24 Oct 2017 00:45:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751273AbdJXApE (ORCPT ); Mon, 23 Oct 2017 20:45:04 -0400 Received: from smtp-fw-6002.amazon.com ([52.95.49.90]:62580 "EHLO smtp-fw-6002.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751113AbdJXApC (ORCPT ); Mon, 23 Oct 2017 20:45:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1508805902; x=1540341902; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=2II/pqTMWIJaOvmuYOP/Aq4bR1SUqtz1mS/FNyfNClg=; b=l9kpu4WwDnPAZeDiZhJ5SuALikBUKb9Y+sgAbCiCBvNssQYzZno1FKNN 3NSyboKTRL0kmdmWNtwHHwzHPfdtUYtQxIJm1Wt+EPOF6UTbg64UQTZgK ihw97cvpiif/aaUtrI02SWFyuOF+FqYRbIKTn5VkVgYvfKe1dCBjHb5LK E=; X-IronPort-AV: E=Sophos;i="5.43,424,1503360000"; d="scan'208";a="312751162" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-1d-9ec21598.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6002.iad6.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 24 Oct 2017 00:44:54 +0000 Received: from EX13MTAUWA001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1d-9ec21598.us-east-1.amazon.com (8.14.7/8.14.7) with ESMTP id v9O0ikia066463 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Tue, 24 Oct 2017 00:44:49 GMT Received: from EX13d09UWA002.ant.amazon.com (10.43.160.186) by EX13MTAUWA001.ant.amazon.com (10.43.160.58) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Tue, 24 Oct 2017 00:44:48 +0000 Received: from EX13MTAUWA001.ant.amazon.com (10.43.160.58) by EX13d09UWA002.ant.amazon.com (10.43.160.186) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Tue, 24 Oct 2017 00:44:48 +0000 Received: from localhost (10.85.20.179) by mail-relay.amazon.com (10.43.160.118) with Microsoft SMTP Server id 15.0.1236.3 via Frontend Transport; Tue, 24 Oct 2017 00:44:48 +0000 From: Eduardo Valentin To: Paolo Bonzini , CC: Eduardo Valentin , Jonathan Corbet , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , , Peter Zijlstra , Waiman Long , , , , "Jan H . Schoenherr" , Anthony Liguori Subject: [PATCH 1/1] locking/qspinlock/x86: Avoid test-and-set when PV_DEDICATED is set Date: Mon, 23 Oct 2017 17:44:27 -0700 Message-ID: <1508805867-14583-1-git-send-email-eduval@amazon.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. 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 --- Documentation/virtual/kvm/cpuid.txt | 6 ++++++ arch/x86/include/asm/qspinlock.h | 4 ++++ arch/x86/include/uapi/asm/kvm_para.h | 1 + 3 files changed, 11 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 eaba080..f89b469 100644 --- a/arch/x86/include/asm/qspinlock.h +++ b/arch/x86/include/asm/qspinlock.h @@ -1,6 +1,8 @@ #ifndef _ASM_X86_QSPINLOCK_H #define _ASM_X86_QSPINLOCK_H +#include + #include #include #include @@ -46,6 +48,8 @@ static inline bool virt_spin_lock(struct qspinlock *lock) if (!static_cpu_has(X86_FEATURE_HYPERVISOR)) 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 94dc8ca..ad2e8fe 100644 --- a/arch/x86/include/uapi/asm/kvm_para.h +++ b/arch/x86/include/uapi/asm/kvm_para.h @@ -24,6 +24,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.