Skip to content
Permalink
Browse files
KVM: SVM: move sev_decommission to psp driver
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.

Cc: Alper Gun <alpergun@google.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: David Rienjes <rientjes@google.com>
Cc: Marc Orr <marcorr@google.com>
Cc: John Allen <john.allen@amd.com>
Cc: Peter Gonda <pgonda@google.com>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Vipin Sharma <vipinsh@google.com>

Suggested-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Mingwei Zhang <mizhang@google.com>
  • Loading branch information
mzhang3579 authored and intel-lab-lkp committed Aug 16, 2021
1 parent a3e0b8b commit 9e861d15c92e637c18f50884ef30352edb0da7aa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
@@ -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;
}

@@ -903,8 +903,14 @@ 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)
{
struct sev_data_decommission decommission;

if (!handle)
return -EINVAL;

decommission.handle = handle;
return sev_do_cmd(SEV_CMD_DECOMMISSION, data, error);
}
EXPORT_SYMBOL_GPL(sev_guest_decommission);
@@ -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; }

0 comments on commit 9e861d1

Please sign in to comment.