Skip to content

Commit

Permalink
KVM: SVM: Drop redundant svm_sev_enabled() helper
Browse files Browse the repository at this point in the history
Replace calls to svm_sev_enabled() with direct checks on sev_enabled, or
in the case of svm_mem_enc_op, simply drop the call to svm_sev_enabled().
This effectively replaces checks against a valid max_sev_asid with checks
against sev_enabled.  sev_enabled is forced off by sev_hardware_setup()
if max_sev_asid is invalid, all call sites are guaranteed to run after
sev_hardware_setup(), and all of the checks care about SEV being fully
enabled (as opposed to intentionally handling the scenario where
max_sev_asid is valid but SEV enabling fails due to OOM).

Reviewed by: Tom Lendacky <thomas.lendacky@amd.com>
Reviewed-by: Brijesh Singh <brijesh.singh@amd.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-Id: <20210422021125.3417167-14-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
Sean Christopherson authored and Paolo Bonzini committed Apr 26, 2021
1 parent b95c221 commit a5c1c5a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
6 changes: 3 additions & 3 deletions arch/x86/kvm/svm/sev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,7 @@ int svm_mem_enc_op(struct kvm *kvm, void __user *argp)
struct kvm_sev_cmd sev_cmd;
int r;

if (!svm_sev_enabled() || !sev_enabled)
if (!sev_enabled)
return -ENOTTY;

if (!argp)
Expand Down Expand Up @@ -1895,7 +1895,7 @@ void __init sev_hardware_setup(void)

void sev_hardware_teardown(void)
{
if (!svm_sev_enabled())
if (!sev_enabled)
return;

bitmap_free(sev_asid_bitmap);
Expand All @@ -1908,7 +1908,7 @@ void sev_hardware_teardown(void)

int sev_cpu_init(struct svm_cpu_data *sd)
{
if (!svm_sev_enabled())
if (!sev_enabled)
return 0;

sd->sev_vmcbs = kcalloc(max_sev_asid + 1, sizeof(void *), GFP_KERNEL);
Expand Down
5 changes: 0 additions & 5 deletions arch/x86/kvm/svm/svm.h
Original file line number Diff line number Diff line change
Expand Up @@ -562,11 +562,6 @@ void svm_vcpu_unblocking(struct kvm_vcpu *vcpu);

extern unsigned int max_sev_asid;

static inline bool svm_sev_enabled(void)
{
return IS_ENABLED(CONFIG_KVM_AMD_SEV) ? max_sev_asid : 0;
}

void sev_vm_destroy(struct kvm *kvm);
int svm_mem_enc_op(struct kvm *kvm, void __user *argp);
int svm_register_enc_region(struct kvm *kvm,
Expand Down

0 comments on commit a5c1c5a

Please sign in to comment.