From mboxrd@z Thu Jan 1 00:00:00 1970 From: Brijesh Singh Subject: [RFC Part2 PATCH v3 10/26] KVM: Introduce KVM_MEMORY_ENCRYPT_REGISTER/UNREGISTER_RAM ioctl Date: Mon, 24 Jul 2017 15:02:47 -0500 Message-ID: <20170724200303.12197-11-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-by2nam01on0080.outbound.protection.outlook.com ([104.47.34.80]:6848 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753183AbdGXUEj (ORCPT ); Mon, 24 Jul 2017 16:04:39 -0400 In-Reply-To: <20170724200303.12197-1-brijesh.singh@amd.com> Sender: kvm-owner@vger.kernel.org List-ID: If hardware support memory encryption then KVM_MEMORY_REGISTER_RAM and KVM_MEMORY_UNREGISTER_RAM ioctl's can be used by userspace to register/ unregister the guest memory regions which may contains the encrypted data (e.g guest RAM, PCI BAR, SMRAM etc). Signed-off-by: Brijesh Singh --- arch/x86/include/asm/kvm_host.h | 4 ++++ arch/x86/kvm/x86.c | 36 ++++++++++++++++++++++++++++++++++++ include/uapi/linux/kvm.h | 9 +++++++++ 3 files changed, 49 insertions(+) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 99a0e11..4295f82 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1059,6 +1059,10 @@ struct kvm_x86_ops { void (*setup_mce)(struct kvm_vcpu *vcpu); int (*memory_encryption_op)(struct kvm *kvm, void __user *argp); + int (*memory_encryption_register_ram)(struct kvm *kvm, + struct kvm_memory_encrypt_ram *ram); + int (*memory_encryption_unregister_ram)(struct kvm *kvm, + struct kvm_memory_encrypt_ram *ram); }; struct kvm_arch_async_pf { diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index c9d3ff5..8febdb5 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3982,6 +3982,24 @@ static int kvm_vm_ioctl_memory_encryption_op(struct kvm *kvm, void __user *argp) return -ENOTTY; } +static int kvm_vm_ioctl_mem_encrypt_register_ram(struct kvm *kvm, + struct kvm_memory_encrypt_ram *ram) +{ + if (kvm_x86_ops->memory_encryption_register_ram) + return kvm_x86_ops->memory_encryption_register_ram(kvm, ram); + + return -ENOTTY; +} + +static int kvm_vm_ioctl_mem_encrypt_unregister_ram(struct kvm *kvm, + struct kvm_memory_encrypt_ram *ram) +{ + if (kvm_x86_ops->memory_encryption_unregister_ram) + return kvm_x86_ops->memory_encryption_unregister_ram(kvm, ram); + + return -ENOTTY; +} + long kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg) { @@ -4246,6 +4264,24 @@ long kvm_arch_vm_ioctl(struct file *filp, r = kvm_vm_ioctl_memory_encryption_op(kvm, argp); break; } + case KVM_MEMORY_ENCRYPT_REGISTER_RAM: { + struct kvm_memory_encrypt_ram ram; + + r = -EFAULT; + if (copy_from_user(&ram, argp, sizeof(ram))) + goto out; + r = kvm_vm_ioctl_mem_encrypt_register_ram(kvm, &ram); + break; + } + case KVM_MEMORY_ENCRYPT_UNREGISTER_RAM: { + struct kvm_memory_encrypt_ram ram; + + r = -EFAULT; + if (copy_from_user(&ram, argp, sizeof(ram))) + goto out; + r = kvm_vm_ioctl_mem_encrypt_unregister_ram(kvm, &ram); + break; + } default: r = -ENOTTY; } diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index ab3b711..6074065 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1357,6 +1357,15 @@ struct kvm_s390_ucas_mapping { #define KVM_S390_SET_CMMA_BITS _IOW(KVMIO, 0xb9, struct kvm_s390_cmma_log) /* Memory Encryption Commands */ #define KVM_MEMORY_ENCRYPT_OP _IOWR(KVMIO, 0xba, unsigned long) +#define KVM_MEMORY_ENCRYPT_REGISTER_RAM _IOR(KVMIO, 0xbb, \ + struct kvm_memory_encrypt_ram) +#define KVM_MEMORY_ENCRYPT_UNREGISTER_RAM _IOR(KVMIO, 0xbc, \ + struct kvm_memory_encrypt_ram) + +struct kvm_memory_encrypt_ram { + __u64 address; + __u64 size; +}; #define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0) #define KVM_DEV_ASSIGN_PCI_2_3 (1 << 1) -- 2.9.4