|
|
9ae3a8 |
From 27f52a18ed8503f5a0333106c38e44f911052d4d Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: "plai@redhat.com" <plai@redhat.com>
|
|
|
9ae3a8 |
Date: Mon, 11 Sep 2017 21:57:36 +0200
|
|
|
9ae3a8 |
Subject: [PATCH 4/4] target-i386: Add PKU and and OSPKE support
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: plai@redhat.com
|
|
|
9ae3a8 |
Message-id: <1505167056-5861-1-git-send-email-plai@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 76308
|
|
|
9ae3a8 |
O-Subject: [RHEL7.5 PATCH BZ 1387648 v2] target-i386: Add PKU and and OSPKE support
|
|
|
9ae3a8 |
Bugzilla: 1387648
|
|
|
9ae3a8 |
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Bandan Das <bsd@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
From: Huaitong Han <huaitong.han@intel.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
------ v2 comment
|
|
|
9ae3a8 |
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1387648
|
|
|
9ae3a8 |
BREW: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=14031692
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
In v1, Eduardo noticed "avx512-vpopcntdq" moved in
|
|
|
9ae3a8 |
target-i386/cpu.c:cpuid_7_0_ecx_feature_name[].
|
|
|
9ae3a8 |
Corrected the patch typo here in v2.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Tested on intel-purley-fpgabmp-01.khw.lab.eng.bos.redhat.com.
|
|
|
9ae3a8 |
VM guest was fedora-26 image (linux 4.11.0-300).
|
|
|
9ae3a8 |
Tests Run (of tools/testing/selftests/x86/protection_keys.c):
|
|
|
9ae3a8 |
1. Successful test on host,
|
|
|
9ae3a8 |
2. Successful negative test w/ current qemu-kvm in VM guest.
|
|
|
9ae3a8 |
3. Successful test w/ test build qemu-kvm in VM guest.
|
|
|
9ae3a8 |
------
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Add PKU and OSPKE CPUID features, including xsave state and
|
|
|
9ae3a8 |
migration support.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Huaitong Han <huaitong.han@intel.com>
|
|
|
9ae3a8 |
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
|
|
|
9ae3a8 |
[ehabkost: squashed 3 patches together, edited patch description]
|
|
|
9ae3a8 |
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
(cherry picked from commit f74eefe0b98cd7e13825de8e8d9f32e22aed102c)
|
|
|
9ae3a8 |
Signed-off-by: Paul Lai <plai@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Resolved Conflicts:
|
|
|
9ae3a8 |
target-i386/cpu.c
|
|
|
9ae3a8 |
target-i386/cpu.h
|
|
|
9ae3a8 |
target-i386/kvm.c
|
|
|
9ae3a8 |
target-i386/machine.c
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
target-i386/cpu.c | 6 ++++--
|
|
|
9ae3a8 |
target-i386/cpu.h | 6 ++++++
|
|
|
9ae3a8 |
target-i386/kvm.c | 3 +++
|
|
|
9ae3a8 |
target-i386/machine.c | 25 +++++++++++++++++++++++++
|
|
|
9ae3a8 |
4 files changed, 38 insertions(+), 2 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
|
|
|
9ae3a8 |
index ae56995..fbd3117 100644
|
|
|
9ae3a8 |
--- a/target-i386/cpu.c
|
|
|
9ae3a8 |
+++ b/target-i386/cpu.c
|
|
|
9ae3a8 |
@@ -155,8 +155,8 @@ static const char *cpuid_7_0_ebx_feature_name[] = {
|
|
|
9ae3a8 |
};
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
static const char *cpuid_7_0_ecx_feature_name[] = {
|
|
|
9ae3a8 |
- NULL, "avx512vbmi", NULL, NULL,
|
|
|
9ae3a8 |
- NULL, NULL, NULL, NULL,
|
|
|
9ae3a8 |
+ NULL, "avx512vbmi", NULL, "pku",
|
|
|
9ae3a8 |
+ "ospke", NULL, NULL, NULL,
|
|
|
9ae3a8 |
NULL, NULL, NULL, NULL,
|
|
|
9ae3a8 |
NULL, NULL, "avx512-vpopcntdq", NULL,
|
|
|
9ae3a8 |
NULL, NULL, NULL, NULL,
|
|
|
9ae3a8 |
@@ -361,6 +361,8 @@ static const ExtSaveArea ext_save_areas[] = {
|
|
|
9ae3a8 |
.offset = 0x480, .size = 0x200 },
|
|
|
9ae3a8 |
[7] = { .feature = FEAT_7_0_EBX, .bits = CPUID_7_0_EBX_AVX512F,
|
|
|
9ae3a8 |
.offset = 0x680, .size = 0x400 },
|
|
|
9ae3a8 |
+ [9] = { .feature = FEAT_7_0_ECX, .bits = CPUID_7_0_ECX_PKU,
|
|
|
9ae3a8 |
+ .offset = 0xA80, .size = 0x8 },
|
|
|
9ae3a8 |
};
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
const char *get_register_name_32(unsigned int reg)
|
|
|
9ae3a8 |
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
|
|
|
9ae3a8 |
index ac60309..7a12c0d 100644
|
|
|
9ae3a8 |
--- a/target-i386/cpu.h
|
|
|
9ae3a8 |
+++ b/target-i386/cpu.h
|
|
|
9ae3a8 |
@@ -394,6 +394,7 @@
|
|
|
9ae3a8 |
#define XSTATE_OPMASK (1ULL << 5)
|
|
|
9ae3a8 |
#define XSTATE_ZMM_Hi256 (1ULL << 6)
|
|
|
9ae3a8 |
#define XSTATE_Hi16_ZMM (1ULL << 7)
|
|
|
9ae3a8 |
+#define XSTATE_PKRU (1ULL << 9)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* CPUID feature words */
|
|
|
9ae3a8 |
@@ -586,6 +587,9 @@ typedef uint32_t FeatureWordArray[FEATURE_WORDS];
|
|
|
9ae3a8 |
#define CPUID_7_0_EDX_AVX512_4VNNIW (1U << 2) /* AVX512 Neural Network Instructions */
|
|
|
9ae3a8 |
#define CPUID_7_0_EDX_AVX512_4FMAPS (1U << 3) /* AVX512 Multiply Accumulation Single Precision */
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+#define CPUID_7_0_ECX_PKU (1U << 3)
|
|
|
9ae3a8 |
+#define CPUID_7_0_ECX_OSPKE (1U << 4)
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
#define CPUID_XSAVE_XSAVEOPT (1U << 0)
|
|
|
9ae3a8 |
#define CPUID_XSAVE_XSAVEC (1U << 1)
|
|
|
9ae3a8 |
#define CPUID_XSAVE_XGETBV1 (1U << 2)
|
|
|
9ae3a8 |
@@ -1029,6 +1033,8 @@ typedef struct CPUX86State {
|
|
|
9ae3a8 |
uint64_t xcr0;
|
|
|
9ae3a8 |
uint64_t xss;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+ uint32_t pkru;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
TPRAccess tpr_access_type;
|
|
|
9ae3a8 |
} CPUX86State;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
|
|
|
9ae3a8 |
index 6a479f4..0dc0e79 100644
|
|
|
9ae3a8 |
--- a/target-i386/kvm.c
|
|
|
9ae3a8 |
+++ b/target-i386/kvm.c
|
|
|
9ae3a8 |
@@ -1008,6 +1008,7 @@ static int kvm_put_fpu(X86CPU *cpu)
|
|
|
9ae3a8 |
#define XSAVE_OPMASK 272
|
|
|
9ae3a8 |
#define XSAVE_ZMM_Hi256 288
|
|
|
9ae3a8 |
#define XSAVE_Hi16_ZMM 416
|
|
|
9ae3a8 |
+#define XSAVE_PKRU 672
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
static int kvm_put_xsave(X86CPU *cpu)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
@@ -1051,6 +1052,7 @@ static int kvm_put_xsave(X86CPU *cpu)
|
|
|
9ae3a8 |
#ifdef TARGET_X86_64
|
|
|
9ae3a8 |
memcpy(&xsave->region[XSAVE_Hi16_ZMM], env->hi16_zmm_regs,
|
|
|
9ae3a8 |
sizeof env->hi16_zmm_regs);
|
|
|
9ae3a8 |
+ memcpy(&xsave->region[XSAVE_PKRU], &env->pkru, sizeof env->pkru);
|
|
|
9ae3a8 |
#endif
|
|
|
9ae3a8 |
r = kvm_vcpu_ioctl(CPU(cpu), KVM_SET_XSAVE, xsave);
|
|
|
9ae3a8 |
return r;
|
|
|
9ae3a8 |
@@ -1388,6 +1390,7 @@ static int kvm_get_xsave(X86CPU *cpu)
|
|
|
9ae3a8 |
#ifdef TARGET_X86_64
|
|
|
9ae3a8 |
memcpy(env->hi16_zmm_regs, &xsave->region[XSAVE_Hi16_ZMM],
|
|
|
9ae3a8 |
sizeof env->hi16_zmm_regs);
|
|
|
9ae3a8 |
+ memcpy(&env->pkru, &xsave->region[XSAVE_PKRU], sizeof env->pkru);
|
|
|
9ae3a8 |
#endif
|
|
|
9ae3a8 |
return 0;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
diff --git a/target-i386/machine.c b/target-i386/machine.c
|
|
|
9ae3a8 |
index ce7fcd3..ba34088 100644
|
|
|
9ae3a8 |
--- a/target-i386/machine.c
|
|
|
9ae3a8 |
+++ b/target-i386/machine.c
|
|
|
9ae3a8 |
@@ -722,6 +722,26 @@ static const VMStateDescription vmstate_xss = {
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
};
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+#ifdef TARGET_X86_64
|
|
|
9ae3a8 |
+static bool pkru_needed(void *opaque)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ X86CPU *cpu = opaque;
|
|
|
9ae3a8 |
+ CPUX86State *env = &cpu->env;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ return env->pkru != 0;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static const VMStateDescription vmstate_pkru = {
|
|
|
9ae3a8 |
+ .name = "cpu/pkru",
|
|
|
9ae3a8 |
+ .version_id = 1,
|
|
|
9ae3a8 |
+ .minimum_version_id = 1,
|
|
|
9ae3a8 |
+ .fields = (VMStateField[]){
|
|
|
9ae3a8 |
+ VMSTATE_UINT32(env.pkru, X86CPU),
|
|
|
9ae3a8 |
+ VMSTATE_END_OF_LIST()
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+};
|
|
|
9ae3a8 |
+#endif
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
const VMStateDescription vmstate_x86_cpu = {
|
|
|
9ae3a8 |
.name = "cpu",
|
|
|
9ae3a8 |
.version_id = 12,
|
|
|
9ae3a8 |
@@ -871,6 +891,11 @@ const VMStateDescription vmstate_x86_cpu = {
|
|
|
9ae3a8 |
}, {
|
|
|
9ae3a8 |
.vmsd = &vmstate_xss,
|
|
|
9ae3a8 |
.needed = xss_needed,
|
|
|
9ae3a8 |
+#ifdef TARGET_X86_64
|
|
|
9ae3a8 |
+ }, {
|
|
|
9ae3a8 |
+ .vmsd = &vmstate_pkru,
|
|
|
9ae3a8 |
+ .needed = pkru_needed,
|
|
|
9ae3a8 |
+#endif
|
|
|
9ae3a8 |
} , {
|
|
|
9ae3a8 |
/* empty */
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.8.3.1
|
|
|
9ae3a8 |
|