ccp/sev-dev.c is part of the software layer in psp that allows KVM to manage SEV/ES/SNP enabled VMs. Among the APIs exposed in sev-dev, many of them requires caller (KVM) to understand psp specific data structures. This often ends up with the fact that KVM has to create its own 'wrapper' API to make it easy to use. The following is the pattern: kvm_func(unsigned int handle) { psp_data_structure data; data.handle = handle; psp_func(&data, NULL); } psp_func(psp_data_structure *data, int *error) { sev_do_cmd(data, error); } struct psp_data_structure { u32 handle; }; sev_decommission is one example following the above pattern. Since KVM is the only user for this API and 'handle' is the only data that is meaningful to KVM, simplify the interface by putting the code from kvm function sev_decommission into the psp function sev_guest_decomssion. No functional change intended. Cc: Alper Gun <alpergun@xxxxxxxxxx> Cc: Borislav Petkov <bp@xxxxxxxxx> Cc: Brijesh Singh <brijesh.singh@xxxxxxx> Cc: David Rienjes <rientjes@xxxxxxxxxx> Cc: Marc Orr <marcorr@xxxxxxxxxx> Cc: John Allen <john.allen@xxxxxxx> Cc: Peter Gonda <pgonda@xxxxxxxxxx> Cc: Sean Christopherson <seanjc@xxxxxxxxxx> Cc: Tom Lendacky <thomas.lendacky@xxxxxxx> Cc: Vipin Sharma <vipinsh@xxxxxxxxxx> Acked-by: Brijesh Singh <brijesh.singh@xxxxxxx> Suggested-by: Sean Christopherson <seanjc@xxxxxxxxxx> Signed-off-by: Mingwei Zhang <mizhang@xxxxxxxxxx> --- arch/x86/kvm/svm/sev.c | 17 +++-------------- drivers/crypto/ccp/sev-dev.c | 10 ++++++++-- include/linux/psp-sev.h | 7 ++++--- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 55d8b9c933c3..b8b26a9c5369 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -198,17 +198,6 @@ static void sev_asid_free(struct kvm_sev_info *sev) sev->misc_cg = NULL; } -static void sev_decommission(unsigned int handle) -{ - struct sev_data_decommission decommission; - - if (!handle) - return; - - decommission.handle = handle; - sev_guest_decommission(&decommission, NULL); -} - static void sev_unbind_asid(struct kvm *kvm, unsigned int handle) { struct sev_data_deactivate deactivate; @@ -223,7 +212,7 @@ static void sev_unbind_asid(struct kvm *kvm, unsigned int handle) sev_guest_deactivate(&deactivate, NULL); up_read(&sev_deactivate_lock); - sev_decommission(handle); + sev_guest_decommission(handle, NULL); } static int sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp) @@ -349,7 +338,7 @@ static int sev_launch_start(struct kvm *kvm, struct kvm_sev_cmd *argp) /* Bind ASID to this guest */ ret = sev_bind_asid(kvm, start.handle, error); if (ret) { - sev_decommission(start.handle); + sev_guest_decommission(start.handle, NULL); goto e_free_session; } @@ -1398,7 +1387,7 @@ static int sev_receive_start(struct kvm *kvm, struct kvm_sev_cmd *argp) /* Bind ASID to this guest */ ret = sev_bind_asid(kvm, start.handle, error); if (ret) { - sev_decommission(start.handle); + sev_guest_decommission(start.handle, NULL); goto e_free_session; } diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index 91808402e0bf..e2d49bedc0ef 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -903,9 +903,15 @@ int sev_guest_activate(struct sev_data_activate *data, int *error) } EXPORT_SYMBOL_GPL(sev_guest_activate); -int sev_guest_decommission(struct sev_data_decommission *data, int *error) +int sev_guest_decommission(unsigned int handle, int *error) { - return sev_do_cmd(SEV_CMD_DECOMMISSION, data, error); + struct sev_data_decommission decommission; + + if (!handle) + return -EINVAL; + + decommission.handle = handle; + return sev_do_cmd(SEV_CMD_DECOMMISSION, &decommission, error); } EXPORT_SYMBOL_GPL(sev_guest_decommission); diff --git a/include/linux/psp-sev.h b/include/linux/psp-sev.h index d48a7192e881..6c0f2f451c89 100644 --- a/include/linux/psp-sev.h +++ b/include/linux/psp-sev.h @@ -612,17 +612,18 @@ int sev_guest_df_flush(int *error); /** * sev_guest_decommission - perform SEV DECOMMISSION command * - * @decommission: sev_data_decommission structure to be processed + * @handle: sev_data_decommission structure to be processed * @sev_ret: sev command return code * * Returns: * 0 if the sev successfully processed the command + * -%EINVAL if handle is NULL * -%ENODEV if the sev device is not available * -%ENOTSUPP if the sev does not support SEV * -%ETIMEDOUT if the sev command timed out * -%EIO if the sev returned a non-zero return code */ -int sev_guest_decommission(struct sev_data_decommission *data, int *error); +int sev_guest_decommission(unsigned int handle, int *error); void *psp_copy_user_blob(u64 uaddr, u32 len); @@ -637,7 +638,7 @@ static inline int sev_guest_deactivate(struct sev_data_deactivate *data, int *error) { return -ENODEV; } static inline int -sev_guest_decommission(struct sev_data_decommission *data, int *error) { return -ENODEV; } +sev_guest_decommission(unsigned int handle, int *error) { return -ENODEV; } static inline int sev_guest_activate(struct sev_data_activate *data, int *error) { return -ENODEV; } -- 2.33.0.rc1.237.g0d66db33f3-goog