mirror of
https://github.com/torvalds/linux.git
synced 2026-05-28 09:04:39 +02:00
KVM: selftests: Introduce SEV VM type check
In preparation for SNP, declutter the vm type check by introducing a SEV-SNP VM type check as well as a transitive set of helper functions. The SNP VM type is the subset of SEV-ES. Similarly, the SEV-ES and SNP types are subset of the SEV VM type check. Signed-off-by: Pratik R. Sampat <prsampat@amd.com> Link: https://lore.kernel.org/r/20250305230000.231025-7-prsampat@amd.com [sean: make the helpers static inlines] Signed-off-by: Sean Christopherson <seanjc@google.com>
This commit is contained in:
parent
f694f30e81
commit
4a4e1e8e92
|
|
@ -27,6 +27,21 @@ enum sev_guest_state {
|
|||
|
||||
#define GHCB_MSR_TERM_REQ 0x100
|
||||
|
||||
static inline bool is_sev_snp_vm(struct kvm_vm *vm)
|
||||
{
|
||||
return vm->type == KVM_X86_SNP_VM;
|
||||
}
|
||||
|
||||
static inline bool is_sev_es_vm(struct kvm_vm *vm)
|
||||
{
|
||||
return is_sev_snp_vm(vm) || vm->type == KVM_X86_SEV_ES_VM;
|
||||
}
|
||||
|
||||
static inline bool is_sev_vm(struct kvm_vm *vm)
|
||||
{
|
||||
return is_sev_es_vm(vm) || vm->type == KVM_X86_SEV_VM;
|
||||
}
|
||||
|
||||
void sev_vm_launch(struct kvm_vm *vm, uint32_t policy);
|
||||
void sev_vm_launch_measure(struct kvm_vm *vm, uint8_t *measurement);
|
||||
void sev_vm_launch_finish(struct kvm_vm *vm);
|
||||
|
|
|
|||
|
|
@ -639,7 +639,7 @@ void kvm_arch_vm_post_create(struct kvm_vm *vm)
|
|||
sync_global_to_guest(vm, host_cpu_is_amd);
|
||||
sync_global_to_guest(vm, is_forced_emulation_enabled);
|
||||
|
||||
if (vm->type == KVM_X86_SEV_VM || vm->type == KVM_X86_SEV_ES_VM) {
|
||||
if (is_sev_vm(vm)) {
|
||||
struct kvm_sev_init init = { 0 };
|
||||
|
||||
vm_sev_ioctl(vm, KVM_SEV_INIT2, &init);
|
||||
|
|
@ -1156,7 +1156,7 @@ void kvm_get_cpu_address_width(unsigned int *pa_bits, unsigned int *va_bits)
|
|||
|
||||
void kvm_init_vm_address_properties(struct kvm_vm *vm)
|
||||
{
|
||||
if (vm->type == KVM_X86_SEV_VM || vm->type == KVM_X86_SEV_ES_VM) {
|
||||
if (is_sev_vm(vm)) {
|
||||
vm->arch.sev_fd = open_sev_dev_path_or_exit();
|
||||
vm->arch.c_bit = BIT_ULL(this_cpu_property(X86_PROPERTY_SEV_C_BIT));
|
||||
vm->gpa_tag_mask = vm->arch.c_bit;
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ static void test_sev(void *guest_code, uint64_t policy)
|
|||
for (;;) {
|
||||
vcpu_run(vcpu);
|
||||
|
||||
if (policy & SEV_POLICY_ES) {
|
||||
if (is_sev_es_vm(vm)) {
|
||||
TEST_ASSERT(vcpu->run->exit_reason == KVM_EXIT_SYSTEM_EVENT,
|
||||
"Wanted SYSTEM_EVENT, got %s",
|
||||
exit_reason_str(vcpu->run->exit_reason));
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user