* [RFC PATCH v3 0/8] SVM guest shadow stack support
@ 2023-08-17 18:18 John Allen
2023-08-17 18:18 ` [RFC PATCH v3 1/8] KVM: x86: SVM: Emulate reads and writes to shadow stack MSRs John Allen
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: John Allen @ 2023-08-17 18:18 UTC (permalink / raw)
To: kvm
Cc: linux-kernel, pbonzini, weijiang.yang, rick.p.edgecombe, seanjc,
x86, thomas.lendacky, bp, John Allen
AMD Zen3 and newer processors support shadow stack, a feature designed to
protect against ROP (return-oriented programming) attacks in which an attacker
manipulates return addresses on the call stack in order to execute arbitrary
code. To prevent this, shadow stacks can be allocated that are only used by
control transfer and return instructions. When a CALL instruction is issued, it
writes the return address to both the program stack and the shadow stack. When
the subsequent RET instruction is issued, it pops the return address from both
stacks and compares them. If the addresses don't match, a control-protection
exception is raised.
Shadow stack and a related feature, Indirect Branch Tracking (IBT), are
collectively referred to as Control-flow Enforcement Technology (CET). However,
current AMD processors only support shadow stack and not IBT.
This series adds support for shadow stack in SVM guests and builds upon
the support added in the CET guest support patch series [1]. Additional
patches are required to support shadow stack enabled guests in qemu [2]
and glibc [3].
[1]: CET guest support patches (v5)
https://lore.kernel.org/all/20230803042732.88515-1-weijiang.yang@intel.com/
[2]: CET qemu patches
https://patchwork.ozlabs.org/project/qemu-devel/patch/20201013051935.6052-2-weijiang.yang@intel.com/
[3]: glibc tree containing necessary updates
https://gitlab.com/x86-glibc/glibc/-/tree/users/hjl/cet/master/
---
v2:
- Rebased on v3 of the Intel CET virtualization series, dropping the
patch that moved cet_is_msr_accessible to common code as that has
been pulled into the Intel series.
- Minor change removing curly brackets around if statement introduced
in patch 6/6.
v3:
- Rebased on v5 of the Intel CET virtualization series.
- Add patch changing the name of vmplX_ssp SEV-ES save area fields to
plX_ssp.
- Merge this series intended for KVM with the separate guest kernel
patch (now patch 7/8).
- Update MSR passthrough code to conditionally pass through shadow
stack MSRS based on both host and guest support.
- Don't save PL0_SSP, PL1_SSP, and PL2_SSP MSRs on SEV-ES VMRUN as
these are currently unused.
John Allen (8):
KVM: x86: SVM: Emulate reads and writes to shadow stack MSRs
KVM: x86: SVM: Update dump_vmcb with shadow stack save area additions
KVM: x86: SVM: Pass through shadow stack MSRs
KVM: SVM: Rename vmplX_ssp -> plX_ssp
KVM: SVM: Save shadow stack host state on VMRUN
KVM: SVM: Add MSR_IA32_XSS to the GHCB for hypervisor kernel
x86/sev-es: Include XSS value in GHCB CPUID request
KVM: SVM: Add CET features to supported_xss
arch/x86/include/asm/svm.h | 9 +++---
arch/x86/kernel/sev-shared.c | 15 ++++++++++
arch/x86/kvm/svm/sev.c | 21 ++++++++++++--
arch/x86/kvm/svm/svm.c | 53 ++++++++++++++++++++++++++++++++++++
arch/x86/kvm/svm/svm.h | 2 +-
5 files changed, 93 insertions(+), 7 deletions(-)
--
2.39.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [RFC PATCH v3 1/8] KVM: x86: SVM: Emulate reads and writes to shadow stack MSRs
2023-08-17 18:18 [RFC PATCH v3 0/8] SVM guest shadow stack support John Allen
@ 2023-08-17 18:18 ` John Allen
2023-08-17 18:18 ` [RFC PATCH v3 2/8] KVM: x86: SVM: Update dump_vmcb with shadow stack save area additions John Allen
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: John Allen @ 2023-08-17 18:18 UTC (permalink / raw)
To: kvm
Cc: linux-kernel, pbonzini, weijiang.yang, rick.p.edgecombe, seanjc,
x86, thomas.lendacky, bp, John Allen
Set up interception of shadow stack MSRs. In the event that shadow stack
is unsupported on the host or the MSRs are otherwise inaccessible, the
interception code will return an error. In certain circumstances such as
host initiated MSR reads or writes, the interception code will get or
set the requested MSR value.
Signed-off-by: John Allen <john.allen@amd.com>
---
v3:
- Updated to depend on the new x86 common msr handling introduced in
v5 of Weijiang Yang's series:
https://lore.kernel.org/all/20230803042732.88515-12-weijiang.yang@intel.com/
---
arch/x86/kvm/svm/svm.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 8652e86fbfb2..57864e83f634 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -2833,6 +2833,15 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
if (guest_cpuid_is_intel(vcpu))
msr_info->data |= (u64)svm->sysenter_esp_hi << 32;
break;
+ case MSR_IA32_S_CET:
+ msr_info->data = svm->vmcb->save.s_cet;
+ break;
+ case MSR_IA32_INT_SSP_TAB:
+ msr_info->data = svm->vmcb->save.isst_addr;
+ break;
+ case MSR_KVM_GUEST_SSP:
+ msr_info->data = svm->vmcb->save.ssp;
+ break;
case MSR_TSC_AUX:
msr_info->data = svm->tsc_aux;
break;
@@ -3050,6 +3059,15 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
svm->vmcb01.ptr->save.sysenter_esp = (u32)data;
svm->sysenter_esp_hi = guest_cpuid_is_intel(vcpu) ? (data >> 32) : 0;
break;
+ case MSR_IA32_S_CET:
+ svm->vmcb->save.s_cet = data;
+ break;
+ case MSR_IA32_INT_SSP_TAB:
+ svm->vmcb->save.isst_addr = data;
+ break;
+ case MSR_KVM_GUEST_SSP:
+ svm->vmcb->save.ssp = data;
+ break;
case MSR_TSC_AUX:
/*
* TSC_AUX is usually changed only during boot and never read
--
2.39.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [RFC PATCH v3 2/8] KVM: x86: SVM: Update dump_vmcb with shadow stack save area additions
2023-08-17 18:18 [RFC PATCH v3 0/8] SVM guest shadow stack support John Allen
2023-08-17 18:18 ` [RFC PATCH v3 1/8] KVM: x86: SVM: Emulate reads and writes to shadow stack MSRs John Allen
@ 2023-08-17 18:18 ` John Allen
2023-08-17 18:18 ` [RFC PATCH v3 3/8] KVM: x86: SVM: Pass through shadow stack MSRs John Allen
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: John Allen @ 2023-08-17 18:18 UTC (permalink / raw)
To: kvm
Cc: linux-kernel, pbonzini, weijiang.yang, rick.p.edgecombe, seanjc,
x86, thomas.lendacky, bp, John Allen
Add shadow stack VMCB save area fields to dump_vmcb. Only include S_CET,
SSP, and ISST_ADDR. Since there currently isn't support to decrypt and
dump the SEV-ES save area, exclude PL0_SSP, PL1_SSP, PL2_SSP, PL3_SSP, and
U_CET which are only inlcuded in the SEV-ES save area.
Signed-off-by: John Allen <john.allen@amd.com>
---
arch/x86/kvm/svm/svm.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 57864e83f634..1ac5b51c3f2c 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -3386,6 +3386,10 @@ static void dump_vmcb(struct kvm_vcpu *vcpu)
"rip:", save->rip, "rflags:", save->rflags);
pr_err("%-15s %016llx %-13s %016llx\n",
"rsp:", save->rsp, "rax:", save->rax);
+ pr_err("%-15s %016llx %-13s %016llx\n",
+ "s_cet:", save->s_cet, "ssp:", save->ssp);
+ pr_err("%-15s %016llx\n",
+ "isst_addr:", save->isst_addr);
pr_err("%-15s %016llx %-13s %016llx\n",
"star:", save01->star, "lstar:", save01->lstar);
pr_err("%-15s %016llx %-13s %016llx\n",
--
2.39.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [RFC PATCH v3 3/8] KVM: x86: SVM: Pass through shadow stack MSRs
2023-08-17 18:18 [RFC PATCH v3 0/8] SVM guest shadow stack support John Allen
2023-08-17 18:18 ` [RFC PATCH v3 1/8] KVM: x86: SVM: Emulate reads and writes to shadow stack MSRs John Allen
2023-08-17 18:18 ` [RFC PATCH v3 2/8] KVM: x86: SVM: Update dump_vmcb with shadow stack save area additions John Allen
@ 2023-08-17 18:18 ` John Allen
2023-08-17 18:18 ` [RFC PATCH v3 4/8] KVM: SVM: Rename vmplX_ssp -> plX_ssp John Allen
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: John Allen @ 2023-08-17 18:18 UTC (permalink / raw)
To: kvm
Cc: linux-kernel, pbonzini, weijiang.yang, rick.p.edgecombe, seanjc,
x86, thomas.lendacky, bp, John Allen
If kvm supports shadow stack, pass through shadow stack MSRs to improve
guest performance.
Signed-off-by: John Allen <john.allen@amd.com>
---
v3:
- Conditionally pass through MSRs depending on both host and guest
shadow stack support.
---
arch/x86/kvm/svm/svm.c | 26 ++++++++++++++++++++++++++
arch/x86/kvm/svm/svm.h | 2 +-
2 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 1ac5b51c3f2c..dd67f435cd33 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -140,6 +140,13 @@ static const struct svm_direct_access_msrs {
{ .index = X2APIC_MSR(APIC_TMICT), .always = false },
{ .index = X2APIC_MSR(APIC_TMCCT), .always = false },
{ .index = X2APIC_MSR(APIC_TDCR), .always = false },
+ { .index = MSR_IA32_U_CET, .always = false },
+ { .index = MSR_IA32_S_CET, .always = false },
+ { .index = MSR_IA32_INT_SSP_TAB, .always = false },
+ { .index = MSR_IA32_PL0_SSP, .always = false },
+ { .index = MSR_IA32_PL1_SSP, .always = false },
+ { .index = MSR_IA32_PL2_SSP, .always = false },
+ { .index = MSR_IA32_PL3_SSP, .always = false },
{ .index = MSR_INVALID, .always = false },
};
@@ -1205,6 +1212,25 @@ static inline void init_vmcb_after_set_cpuid(struct kvm_vcpu *vcpu)
set_msr_interception(vcpu, svm->msrpm, MSR_IA32_SYSENTER_EIP, 1, 1);
set_msr_interception(vcpu, svm->msrpm, MSR_IA32_SYSENTER_ESP, 1, 1);
}
+
+ if (kvm_cpu_cap_has(X86_FEATURE_SHSTK)) {
+ bool shstk_enabled = guest_cpuid_has(vcpu, X86_FEATURE_SHSTK);
+
+ set_msr_interception(vcpu, svm->msrpm, MSR_IA32_U_CET,
+ shstk_enabled, shstk_enabled);
+ set_msr_interception(vcpu, svm->msrpm, MSR_IA32_S_CET,
+ shstk_enabled, shstk_enabled);
+ set_msr_interception(vcpu, svm->msrpm, MSR_IA32_INT_SSP_TAB,
+ shstk_enabled, shstk_enabled);
+ set_msr_interception(vcpu, svm->msrpm, MSR_IA32_PL0_SSP,
+ shstk_enabled, shstk_enabled);
+ set_msr_interception(vcpu, svm->msrpm, MSR_IA32_PL1_SSP,
+ shstk_enabled, shstk_enabled);
+ set_msr_interception(vcpu, svm->msrpm, MSR_IA32_PL2_SSP,
+ shstk_enabled, shstk_enabled);
+ set_msr_interception(vcpu, svm->msrpm, MSR_IA32_PL3_SSP,
+ shstk_enabled, shstk_enabled);
+ }
}
static void init_vmcb(struct kvm_vcpu *vcpu)
diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h
index 800ca1776b59..f824dde86e96 100644
--- a/arch/x86/kvm/svm/svm.h
+++ b/arch/x86/kvm/svm/svm.h
@@ -29,7 +29,7 @@
#define IOPM_SIZE PAGE_SIZE * 3
#define MSRPM_SIZE PAGE_SIZE * 2
-#define MAX_DIRECT_ACCESS_MSRS 46
+#define MAX_DIRECT_ACCESS_MSRS 53
#define MSRPM_OFFSETS 32
extern u32 msrpm_offsets[MSRPM_OFFSETS] __read_mostly;
extern bool npt_enabled;
--
2.39.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [RFC PATCH v3 4/8] KVM: SVM: Rename vmplX_ssp -> plX_ssp
2023-08-17 18:18 [RFC PATCH v3 0/8] SVM guest shadow stack support John Allen
` (2 preceding siblings ...)
2023-08-17 18:18 ` [RFC PATCH v3 3/8] KVM: x86: SVM: Pass through shadow stack MSRs John Allen
@ 2023-08-17 18:18 ` John Allen
2023-08-17 18:18 ` [RFC PATCH v3 5/8] KVM: SVM: Save shadow stack host state on VMRUN John Allen
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: John Allen @ 2023-08-17 18:18 UTC (permalink / raw)
To: kvm
Cc: linux-kernel, pbonzini, weijiang.yang, rick.p.edgecombe, seanjc,
x86, thomas.lendacky, bp, John Allen
Rename SEV-ES save area SSP fields to be consistent with the APM.
Signed-off-by: John Allen <john.allen@amd.com>
---
v3:
- New in v3.
---
arch/x86/include/asm/svm.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h
index 72ebd5e4e975..d14536761309 100644
--- a/arch/x86/include/asm/svm.h
+++ b/arch/x86/include/asm/svm.h
@@ -361,10 +361,10 @@ struct sev_es_save_area {
struct vmcb_seg ldtr;
struct vmcb_seg idtr;
struct vmcb_seg tr;
- u64 vmpl0_ssp;
- u64 vmpl1_ssp;
- u64 vmpl2_ssp;
- u64 vmpl3_ssp;
+ u64 pl0_ssp;
+ u64 pl1_ssp;
+ u64 pl2_ssp;
+ u64 pl3_ssp;
u64 u_cet;
u8 reserved_0xc8[2];
u8 vmpl;
--
2.39.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [RFC PATCH v3 5/8] KVM: SVM: Save shadow stack host state on VMRUN
2023-08-17 18:18 [RFC PATCH v3 0/8] SVM guest shadow stack support John Allen
` (3 preceding siblings ...)
2023-08-17 18:18 ` [RFC PATCH v3 4/8] KVM: SVM: Rename vmplX_ssp -> plX_ssp John Allen
@ 2023-08-17 18:18 ` John Allen
2023-08-17 18:18 ` [RFC PATCH v3 6/8] KVM: SVM: Add MSR_IA32_XSS to the GHCB for hypervisor kernel John Allen
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: John Allen @ 2023-08-17 18:18 UTC (permalink / raw)
To: kvm
Cc: linux-kernel, pbonzini, weijiang.yang, rick.p.edgecombe, seanjc,
x86, thomas.lendacky, bp, John Allen
When running as an SEV-ES guest, the PL0_SSP, PL1_SSP, PL2_SSP, PL3_SSP,
and U_CET fields in the VMCB save area are type B, meaning the host
state is automatically loaded on a VMEXIT, but is not saved on a VMRUN.
The other shadow stack MSRs, S_CET, SSP, and ISST_ADDR are type A,
meaning they are loaded on VMEXIT and saved on VMRUN. PL0_SSP, PL1_SSP,
and PL2_SSP are currently unused. Manually save the other type B host
MSR values before VMRUN.
Signed-off-by: John Allen <john.allen@amd.com>
---
v3:
- Don't save unused PL0_SSP, PL1_SSP, and PL2_SSP MSRs.
---
arch/x86/kvm/svm/sev.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 2cd15783dfb9..021ead4dd201 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -3097,6 +3097,15 @@ void sev_es_prepare_switch_to_guest(struct sev_es_save_area *hostsa)
hostsa->dr2_addr_mask = amd_get_dr_addr_mask(2);
hostsa->dr3_addr_mask = amd_get_dr_addr_mask(3);
}
+
+ if (boot_cpu_has(X86_FEATURE_SHSTK)) {
+ /*
+ * MSR_IA32_U_CET and MSR_IA32_PL3_SSP are restored on VMEXIT,
+ * save the current host values.
+ */
+ rdmsrl(MSR_IA32_U_CET, hostsa->u_cet);
+ rdmsrl(MSR_IA32_PL3_SSP, hostsa->pl3_ssp);
+ }
}
void sev_vcpu_deliver_sipi_vector(struct kvm_vcpu *vcpu, u8 vector)
--
2.39.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [RFC PATCH v3 6/8] KVM: SVM: Add MSR_IA32_XSS to the GHCB for hypervisor kernel
2023-08-17 18:18 [RFC PATCH v3 0/8] SVM guest shadow stack support John Allen
` (4 preceding siblings ...)
2023-08-17 18:18 ` [RFC PATCH v3 5/8] KVM: SVM: Save shadow stack host state on VMRUN John Allen
@ 2023-08-17 18:18 ` John Allen
2023-08-17 18:18 ` [RFC PATCH v3 7/8] x86/sev-es: Include XSS value in GHCB CPUID request John Allen
2023-08-17 18:18 ` [RFC PATCH v3 8/8] KVM: SVM: Add CET features to supported_xss John Allen
7 siblings, 0 replies; 9+ messages in thread
From: John Allen @ 2023-08-17 18:18 UTC (permalink / raw)
To: kvm
Cc: linux-kernel, pbonzini, weijiang.yang, rick.p.edgecombe, seanjc,
x86, thomas.lendacky, bp, John Allen
When a guest issues a cpuid instruction for Fn0000000D_x0B
(CetUserOffset), KVM will intercept and need to access the guest
MSR_IA32_XSS value. For SEV-ES, this is encrypted and needs to be
included in the GHCB to be visible to the hypervisor.
Signed-off-by: John Allen <john.allen@amd.com>
---
arch/x86/include/asm/svm.h | 1 +
arch/x86/kvm/svm/sev.c | 12 ++++++++++--
arch/x86/kvm/svm/svm.c | 1 +
arch/x86/kvm/svm/svm.h | 2 +-
4 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h
index d14536761309..890ec51eb9d6 100644
--- a/arch/x86/include/asm/svm.h
+++ b/arch/x86/include/asm/svm.h
@@ -678,5 +678,6 @@ DEFINE_GHCB_ACCESSORS(sw_exit_info_1)
DEFINE_GHCB_ACCESSORS(sw_exit_info_2)
DEFINE_GHCB_ACCESSORS(sw_scratch)
DEFINE_GHCB_ACCESSORS(xcr0)
+DEFINE_GHCB_ACCESSORS(xss)
#endif
diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 021ead4dd201..5db76675b416 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -2442,8 +2442,13 @@ static void sev_es_sync_from_ghcb(struct vcpu_svm *svm)
svm->vmcb->save.cpl = ghcb_get_cpl_if_valid(ghcb);
- if (ghcb_xcr0_is_valid(ghcb)) {
- vcpu->arch.xcr0 = ghcb_get_xcr0(ghcb);
+ if (ghcb_xcr0_is_valid(ghcb) || ghcb_xss_is_valid(ghcb)) {
+ if (ghcb_xcr0_is_valid(ghcb))
+ vcpu->arch.xcr0 = ghcb_get_xcr0(ghcb);
+
+ if (ghcb_xss_is_valid(ghcb))
+ vcpu->arch.ia32_xss = ghcb_get_xss(ghcb);
+
kvm_update_cpuid_runtime(vcpu);
}
@@ -3031,6 +3036,9 @@ static void sev_es_init_vmcb(struct vcpu_svm *svm)
if (guest_cpuid_has(&svm->vcpu, X86_FEATURE_RDTSCP))
svm_clr_intercept(svm, INTERCEPT_RDTSCP);
}
+
+ if (kvm_caps.supported_xss)
+ set_msr_interception(vcpu, svm->msrpm, MSR_IA32_XSS, 1, 1);
}
void sev_init_vmcb(struct vcpu_svm *svm)
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index dd67f435cd33..683bf18b965d 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -147,6 +147,7 @@ static const struct svm_direct_access_msrs {
{ .index = MSR_IA32_PL1_SSP, .always = false },
{ .index = MSR_IA32_PL2_SSP, .always = false },
{ .index = MSR_IA32_PL3_SSP, .always = false },
+ { .index = MSR_IA32_XSS, .always = false },
{ .index = MSR_INVALID, .always = false },
};
diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h
index f824dde86e96..87b6831bac42 100644
--- a/arch/x86/kvm/svm/svm.h
+++ b/arch/x86/kvm/svm/svm.h
@@ -29,7 +29,7 @@
#define IOPM_SIZE PAGE_SIZE * 3
#define MSRPM_SIZE PAGE_SIZE * 2
-#define MAX_DIRECT_ACCESS_MSRS 53
+#define MAX_DIRECT_ACCESS_MSRS 54
#define MSRPM_OFFSETS 32
extern u32 msrpm_offsets[MSRPM_OFFSETS] __read_mostly;
extern bool npt_enabled;
--
2.39.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [RFC PATCH v3 7/8] x86/sev-es: Include XSS value in GHCB CPUID request
2023-08-17 18:18 [RFC PATCH v3 0/8] SVM guest shadow stack support John Allen
` (5 preceding siblings ...)
2023-08-17 18:18 ` [RFC PATCH v3 6/8] KVM: SVM: Add MSR_IA32_XSS to the GHCB for hypervisor kernel John Allen
@ 2023-08-17 18:18 ` John Allen
2023-08-17 18:18 ` [RFC PATCH v3 8/8] KVM: SVM: Add CET features to supported_xss John Allen
7 siblings, 0 replies; 9+ messages in thread
From: John Allen @ 2023-08-17 18:18 UTC (permalink / raw)
To: kvm
Cc: linux-kernel, pbonzini, weijiang.yang, rick.p.edgecombe, seanjc,
x86, thomas.lendacky, bp, John Allen
When a guest issues a cpuid instruction for Fn0000000D_x0B (CetUserOffset), the
hypervisor may intercept and access the guest XSS value. For SEV-ES, this is
encrypted and needs to be included in the GHCB to be visible to the hypervisor.
The rdmsr instruction needs to be called directly as the code may be used in
early boot in which case the rdmsr wrappers should be avoided as they are
incompatible with the decompression boot phase.
Signed-off-by: John Allen <john.allen@amd.com>
---
v3:
- New in v3. Merged KVM support series and this single patch for guest
kernel support.
---
arch/x86/kernel/sev-shared.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/arch/x86/kernel/sev-shared.c b/arch/x86/kernel/sev-shared.c
index 2eabccde94fb..e38a1d049bc1 100644
--- a/arch/x86/kernel/sev-shared.c
+++ b/arch/x86/kernel/sev-shared.c
@@ -890,6 +890,21 @@ static enum es_result vc_handle_cpuid(struct ghcb *ghcb,
/* xgetbv will cause #GP - use reset value for xcr0 */
ghcb_set_xcr0(ghcb, 1);
+ if (has_cpuflag(X86_FEATURE_SHSTK) && regs->ax == 0xd && regs->cx <= 1) {
+ unsigned long lo, hi;
+ u64 xss;
+
+ /*
+ * Since vc_handle_cpuid may be used during early boot, the
+ * rdmsr wrappers are incompatible and should not be used.
+ * Invoke the instruction directly.
+ */
+ asm volatile("rdmsr" : "=a" (lo), "=d" (hi)
+ : "c" (MSR_IA32_XSS));
+ xss = (hi << 32) | lo;
+ ghcb_set_xss(ghcb, xss);
+ }
+
ret = sev_es_ghcb_hv_call(ghcb, ctxt, SVM_EXIT_CPUID, 0, 0);
if (ret != ES_OK)
return ret;
--
2.39.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [RFC PATCH v3 8/8] KVM: SVM: Add CET features to supported_xss
2023-08-17 18:18 [RFC PATCH v3 0/8] SVM guest shadow stack support John Allen
` (6 preceding siblings ...)
2023-08-17 18:18 ` [RFC PATCH v3 7/8] x86/sev-es: Include XSS value in GHCB CPUID request John Allen
@ 2023-08-17 18:18 ` John Allen
7 siblings, 0 replies; 9+ messages in thread
From: John Allen @ 2023-08-17 18:18 UTC (permalink / raw)
To: kvm
Cc: linux-kernel, pbonzini, weijiang.yang, rick.p.edgecombe, seanjc,
x86, thomas.lendacky, bp, John Allen
If the CPU supports CET, add CET XSAVES feature bits to the
supported_xss mask.
Signed-off-by: John Allen <john.allen@amd.com>
---
v2:
- Remove curly braces around if statement
---
arch/x86/kvm/svm/svm.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 683bf18b965d..685f8715a716 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -5105,6 +5105,10 @@ static __init void svm_set_cpu_caps(void)
boot_cpu_has(X86_FEATURE_AMD_SSBD))
kvm_cpu_cap_set(X86_FEATURE_VIRT_SSBD);
+ if (kvm_cpu_cap_has(X86_FEATURE_SHSTK))
+ kvm_caps.supported_xss |= XFEATURE_MASK_CET_USER |
+ XFEATURE_MASK_CET_KERNEL;
+
if (enable_pmu) {
/*
* Enumerate support for PERFCTR_CORE if and only if KVM has
--
2.39.1
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2023-08-17 18:20 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-17 18:18 [RFC PATCH v3 0/8] SVM guest shadow stack support John Allen
2023-08-17 18:18 ` [RFC PATCH v3 1/8] KVM: x86: SVM: Emulate reads and writes to shadow stack MSRs John Allen
2023-08-17 18:18 ` [RFC PATCH v3 2/8] KVM: x86: SVM: Update dump_vmcb with shadow stack save area additions John Allen
2023-08-17 18:18 ` [RFC PATCH v3 3/8] KVM: x86: SVM: Pass through shadow stack MSRs John Allen
2023-08-17 18:18 ` [RFC PATCH v3 4/8] KVM: SVM: Rename vmplX_ssp -> plX_ssp John Allen
2023-08-17 18:18 ` [RFC PATCH v3 5/8] KVM: SVM: Save shadow stack host state on VMRUN John Allen
2023-08-17 18:18 ` [RFC PATCH v3 6/8] KVM: SVM: Add MSR_IA32_XSS to the GHCB for hypervisor kernel John Allen
2023-08-17 18:18 ` [RFC PATCH v3 7/8] x86/sev-es: Include XSS value in GHCB CPUID request John Allen
2023-08-17 18:18 ` [RFC PATCH v3 8/8] KVM: SVM: Add CET features to supported_xss John Allen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®