Extend kvm_x86_ops to add mem_enc_enabled() ops. The ops can be used to
check if memory encryption is enabled for a given VCPU.

Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: "Radim Krčmář" <[email protected]>
Cc: Joerg Roedel <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Tom Lendacky <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Brijesh Singh <[email protected]>
---
 arch/x86/include/asm/kvm_host.h | 1 +
 arch/x86/kvm/svm.c              | 6 ++++++
 2 files changed, 7 insertions(+)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 3195a8cc517d..cad9672fbe8c 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -1076,6 +1076,7 @@ struct kvm_x86_ops {
        int (*mem_enc_op)(struct kvm *kvm, void __user *argp);
        int (*mem_enc_register_region)(struct kvm *kvm, struct kvm_enc_region 
*argp);
        int (*mem_enc_unregister_region)(struct kvm *kvm, struct kvm_enc_region 
*argp);
+       bool (*mem_enc_enabled)(struct kvm_vcpu *vcpu);
 };
 
 struct kvm_arch_async_pf {
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 0bb62a114a20..208c8abf0bbd 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -6631,6 +6631,11 @@ static int svm_unregister_enc_region(struct kvm *kvm,
        return 0;
 }
 
+static bool mem_enc_enabled(struct kvm_vcpu *vcpu)
+{
+       return to_svm(vcpu)->vmcb->control.nested_ctl & 
SVM_NESTED_CTL_SEV_ENABLE;
+}
+
 static struct kvm_x86_ops svm_x86_ops __ro_after_init = {
        .cpu_has_kvm_support = has_svm,
        .disabled_by_bios = is_disabled,
@@ -6745,6 +6750,7 @@ static struct kvm_x86_ops svm_x86_ops __ro_after_init = {
        .mem_enc_op = svm_mem_enc_op,
        .mem_enc_register_region = svm_register_enc_region,
        .mem_enc_unregister_region = svm_unregister_enc_region,
+       .mem_enc_enabled = mem_enc_enabled
 };
 
 static int __init svm_init(void)
-- 
2.9.5

Reply via email to