diff mbox series

[RFC,v2,34/69] KVM: x86: Add support for vCPU and device-scoped KVM_MEMORY_ENCRYPT_OP

Message ID 68b1d5fb6afc30e41e46be63ef67412ec3b08fab.1625186503.git.isaku.yamahata@intel.com (mailing list archive)
State New, archived
Headers show
Series KVM: X86: TDX support | expand

Commit Message

Isaku Yamahata July 2, 2021, 10:04 p.m. UTC
From: Sean Christopherson <sean.j.christopherson@intel.com>

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
---
 arch/x86/include/asm/kvm_host.h |  2 ++
 arch/x86/kvm/x86.c              | 12 ++++++++++++
 2 files changed, 14 insertions(+)

Comments

Paolo Bonzini July 6, 2021, 2:12 p.m. UTC | #1
On 03/07/21 00:04, isaku.yamahata@intel.com wrote:
> From: Sean Christopherson <sean.j.christopherson@intel.com>
> 
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
> ---
>   arch/x86/include/asm/kvm_host.h |  2 ++
>   arch/x86/kvm/x86.c              | 12 ++++++++++++
>   2 files changed, 14 insertions(+)
> 
> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> index 9791c4bb5198..e3abf077f328 100644
> --- a/arch/x86/include/asm/kvm_host.h
> +++ b/arch/x86/include/asm/kvm_host.h
> @@ -1377,7 +1377,9 @@ struct kvm_x86_ops {
>   	int (*pre_leave_smm)(struct kvm_vcpu *vcpu, const char *smstate);
>   	void (*enable_smi_window)(struct kvm_vcpu *vcpu);
>   
> +	int (*mem_enc_op_dev)(void __user *argp);
>   	int (*mem_enc_op)(struct kvm *kvm, void __user *argp);
> +	int (*mem_enc_op_vcpu)(struct kvm_vcpu *vcpu, void __user *argp);
>   	int (*mem_enc_reg_region)(struct kvm *kvm, struct kvm_enc_region *argp);
>   	int (*mem_enc_unreg_region)(struct kvm *kvm, struct kvm_enc_region *argp);
>   	int (*vm_copy_enc_context_from)(struct kvm *kvm, unsigned int source_fd);
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index f7ae0a47e555..da9f1081cb03 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -4109,6 +4109,12 @@ long kvm_arch_dev_ioctl(struct file *filp,
>   	case KVM_GET_SUPPORTED_HV_CPUID:
>   		r = kvm_ioctl_get_supported_hv_cpuid(NULL, argp);
>   		break;
> +	case KVM_MEMORY_ENCRYPT_OP:
> +		r = -EINVAL;
> +		if (!kvm_x86_ops.mem_enc_op_dev)
> +			goto out;
> +		r = kvm_x86_ops.mem_enc_op_dev(argp);
> +		break;
>   	default:
>   		r = -EINVAL;
>   		break;
> @@ -5263,6 +5269,12 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
>   		break;
>   	}
>   #endif
> +	case KVM_MEMORY_ENCRYPT_OP:
> +		r = -EINVAL;
> +		if (!kvm_x86_ops.mem_enc_op_vcpu)
> +			goto out;
> +		r = kvm_x86_ops.mem_enc_op_vcpu(vcpu, argp);
> +		break;
>   	default:
>   		r = -EINVAL;
>   	}
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
diff mbox series

Patch

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 9791c4bb5198..e3abf077f328 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -1377,7 +1377,9 @@  struct kvm_x86_ops {
 	int (*pre_leave_smm)(struct kvm_vcpu *vcpu, const char *smstate);
 	void (*enable_smi_window)(struct kvm_vcpu *vcpu);
 
+	int (*mem_enc_op_dev)(void __user *argp);
 	int (*mem_enc_op)(struct kvm *kvm, void __user *argp);
+	int (*mem_enc_op_vcpu)(struct kvm_vcpu *vcpu, void __user *argp);
 	int (*mem_enc_reg_region)(struct kvm *kvm, struct kvm_enc_region *argp);
 	int (*mem_enc_unreg_region)(struct kvm *kvm, struct kvm_enc_region *argp);
 	int (*vm_copy_enc_context_from)(struct kvm *kvm, unsigned int source_fd);
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index f7ae0a47e555..da9f1081cb03 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -4109,6 +4109,12 @@  long kvm_arch_dev_ioctl(struct file *filp,
 	case KVM_GET_SUPPORTED_HV_CPUID:
 		r = kvm_ioctl_get_supported_hv_cpuid(NULL, argp);
 		break;
+	case KVM_MEMORY_ENCRYPT_OP:
+		r = -EINVAL;
+		if (!kvm_x86_ops.mem_enc_op_dev)
+			goto out;
+		r = kvm_x86_ops.mem_enc_op_dev(argp);
+		break;
 	default:
 		r = -EINVAL;
 		break;
@@ -5263,6 +5269,12 @@  long kvm_arch_vcpu_ioctl(struct file *filp,
 		break;
 	}
 #endif
+	case KVM_MEMORY_ENCRYPT_OP:
+		r = -EINVAL;
+		if (!kvm_x86_ops.mem_enc_op_vcpu)
+			goto out;
+		r = kvm_x86_ops.mem_enc_op_vcpu(vcpu, argp);
+		break;
 	default:
 		r = -EINVAL;
 	}