From mboxrd@z Thu Jan 1 00:00:00 1970 From: Brijesh Singh Subject: [RFC Part2 PATCH v3 23/26] KVM: X86: Add memory encryption enabled ops Date: Mon, 24 Jul 2017 15:03:00 -0500 Message-ID: <20170724200303.12197-24-brijesh.singh@amd.com> References: <20170724200303.12197-1-brijesh.singh@amd.com> Mime-Version: 1.0 Content-Type: text/plain Cc: Thomas Gleixner , Borislav Petkov , Joerg Roedel , "Michael S . Tsirkin" , Paolo Bonzini , =?UTF-8?q?=5C=22Radim=20Kr=C4=8Dm=C3=A1=C5=99=5C=22?= , Tom Lendacky , Brijesh Singh To: linux-kernel@vger.kernel.org, x86@kernel.org, kvm@vger.kernel.org Return-path: Received: from mail-by2nam01on0059.outbound.protection.outlook.com ([104.47.34.59]:4032 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753555AbdGXUIS (ORCPT ); Mon, 24 Jul 2017 16:08:18 -0400 In-Reply-To: <20170724200303.12197-1-brijesh.singh@amd.com> Sender: kvm-owner@vger.kernel.org List-ID: Extend kvm_x86_ops to add memory_encyption_enabled() ops. It returns a boolean indicating whether memory encryption is enabled on the VCPU. Signed-off-by: Brijesh Singh --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/svm.c | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index a91aadf..a14d4dd 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1073,6 +1073,7 @@ struct kvm_x86_ops { struct kvm_memory_encrypt_ram *ram); int (*memory_encryption_unregister_ram)(struct kvm *kvm, struct kvm_memory_encrypt_ram *ram); + bool (*memory_encryption_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 cdb1cf3..0bbd050 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -6548,6 +6548,12 @@ static int mem_encrypt_unregister_ram(struct kvm *kvm, return 0; } +static bool mem_encrypt_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, @@ -6664,6 +6670,8 @@ static struct kvm_x86_ops svm_x86_ops __ro_after_init = { .memory_encryption_op = svm_memory_encryption_op, .memory_encryption_register_ram = mem_encrypt_register_ram, .memory_encryption_unregister_ram = mem_encrypt_unregister_ram, + .memory_encryption_enabled = mem_encrypt_enabled, + }; static int __init svm_init(void) -- 2.9.4