From nobody Wed Nov 12 10:09:26 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1569722345; cv=none; d=zoho.com; s=zohoarc; b=VabRfh/LEmXzzOXvtPiR22E6letmp1POYGvhdnINzY/Drjs+EH7cdZwZH92z5FFoZQX4HfaslVfGW60zUx4J1fCNDPhkwEqwu/bTOTzooti+tivjnXHDpA5GhGvZyqMarQYYYk1JFWzxlxkcJkrSIdNRgENK7x2MQVKhHNMBQlY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569722345; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=X8BfVDzM8rj51zmiiXisAJcK5O/o4le6S8VIrK4r+Rk=; b=O+tDSO9mI4D6RoKXc0BdLjkFUfz03/2kV8W+yubzKK9+H2LrEtBzjJJr7bL96DEJG7mZnNBZLCr/d2+I1FNI+J3/pFPRk0JrR3s6SM53ztT/AC73FRyFArgJiKRhFtz0SIpAIZH4l41Zpm7QRRktxeDNH/6Lthf+YtqK9RJS3yI= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 156972234550438.85708601916747; Sat, 28 Sep 2019 18:59:05 -0700 (PDT) Received: from localhost ([::1]:35930 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iEOUB-0002TH-5N for importer@patchew.org; Sat, 28 Sep 2019 21:58:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56430) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iEOSl-0001G3-K0 for qemu-devel@nongnu.org; Sat, 28 Sep 2019 21:57:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iEOSj-0004Aw-Ds for qemu-devel@nongnu.org; Sat, 28 Sep 2019 21:57:26 -0400 Received: from mga14.intel.com ([192.55.52.115]:19353) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iEOSj-0004AR-67 for qemu-devel@nongnu.org; Sat, 28 Sep 2019 21:57:25 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Sep 2019 18:57:23 -0700 Received: from tao-optiplex-7060.sh.intel.com ([10.239.159.36]) by fmsmga001.fm.intel.com with ESMTP; 28 Sep 2019 18:57:21 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,561,1559545200"; d="scan'208";a="204501452" From: Tao Xu To: pbonzini@redhat.com, rth@twiddle.net, ehabkost@redhat.com, mtosatti@redhat.com Subject: [PATCH v5 1/2] x86/cpu: Add support for UMONITOR/UMWAIT/TPAUSE Date: Sun, 29 Sep 2019 09:57:17 +0800 Message-Id: <20190929015718.19562-2-tao3.xu@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190929015718.19562-1-tao3.xu@intel.com> References: <20190929015718.19562-1-tao3.xu@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.115 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jingqi.liu@intel.com, tao3.xu@intel.com, qemu-devel@nongnu.org, kvm@vger.kernel.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" UMONITOR, UMWAIT and TPAUSE are a set of user wait instructions. This patch adds support for user wait instructions in KVM. Availability of the user wait instructions is indicated by the presence of the CPUID feature flag WAITPKG CPUID.0x07.0x0:ECX[5]. User wait instructions may be executed at any privilege level, and use IA32_UMWAIT_CONTROL MSR to set the maximum time. The patch enable the umonitor, umwait and tpause features in KVM. Because umwait and tpause can put a (psysical) CPU into a power saving state, by default we dont't expose it to kvm and enable it only when guest CPUID has it. And use QEMU command-line "-overcommit cpu-pm=3Don" (enable_cpu_pm is enabled), a VM can use UMONITOR, UMWAIT and TPAUSE instructions. If the instruction causes a delay, the amount of time delayed is called here the physical delay. The physical delay is first computed by determining the virtual delay (the time to delay relative to the VM=E2=80=99s timestamp counter). Otherwise, UMONITOR, UMWAIT and TPAUSE= cause an invalid-opcode exception(#UD). The release document ref below link: https://software.intel.com/sites/default/files/\ managed/39/c5/325462-sdm-vol-1-2abcd-3abcd.pdf Co-developed-by: Jingqi Liu Signed-off-by: Jingqi Liu Signed-off-by: Tao Xu --- Changes in v5: - Remove CPUID_7_0_ECX_WAITPKG if enable_cpu_pm is not set. (Paolo) --- target/i386/cpu.c | 3 ++- target/i386/cpu.h | 1 + target/i386/kvm.c | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 9e0bac31e8..15f888b13f 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -1062,7 +1062,7 @@ static FeatureWordInfo feature_word_info[FEATURE_WORD= S] =3D { .type =3D CPUID_FEATURE_WORD, .feat_names =3D { NULL, "avx512vbmi", "umip", "pku", - NULL /* ospke */, NULL, "avx512vbmi2", NULL, + NULL /* ospke */, "waitpkg", "avx512vbmi2", NULL, "gfni", "vaes", "vpclmulqdq", "avx512vnni", "avx512bitalg", NULL, "avx512-vpopcntdq", NULL, "la57", NULL, NULL, NULL, @@ -5227,6 +5227,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error= **errp) host_cpuid(5, 0, &cpu->mwait.eax, &cpu->mwait.ebx, &cpu->mwait.ecx, &cpu->mwait.edx); env->features[FEAT_1_ECX] |=3D CPUID_EXT_MONITOR; + env->features[FEAT_7_0_ECX] |=3D CPUID_7_0_ECX_WAITPKG; } } =20 diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 5f6e3a029a..33a0b8b365 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -673,6 +673,7 @@ typedef uint32_t FeatureWordArray[FEATURE_WORDS]; #define CPUID_7_0_ECX_UMIP (1U << 2) #define CPUID_7_0_ECX_PKU (1U << 3) #define CPUID_7_0_ECX_OSPKE (1U << 4) +#define CPUID_7_0_ECX_WAITPKG (1U << 5) /* UMONITOR/UMWAIT/TPAUSE Instruc= tions */ #define CPUID_7_0_ECX_VBMI2 (1U << 6) /* Additional VBMI Instrs */ #define CPUID_7_0_ECX_GFNI (1U << 8) #define CPUID_7_0_ECX_VAES (1U << 9) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 92069099ab..ea9a87bfd8 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -400,6 +400,12 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uin= t32_t function, if (host_tsx_blacklisted()) { ret &=3D ~(CPUID_7_0_EBX_RTM | CPUID_7_0_EBX_HLE); } + } else if (function =3D=3D 7 && index =3D=3D 0 && reg =3D=3D R_ECX) { + if (enable_cpu_pm) { + ret |=3D CPUID_7_0_ECX_WAITPKG; + } else { + ret &=3D ~CPUID_7_0_ECX_WAITPKG; + } } else if (function =3D=3D 7 && index =3D=3D 0 && reg =3D=3D R_EDX) { /* * Linux v4.17-v4.20 incorrectly return ARCH_CAPABILITIES on SVM h= osts. --=20 2.20.1