Skip to content

Commit dcbcc23

Browse files
mdrothsean-jc
authored andcommitted
KVM: SEV: Document/enforce page-alignment for KVM_SEV_SNP_LAUNCH_UPDATE
In the past, KVM_SEV_SNP_LAUNCH_UPDATE accepted a non-page-aligned 'uaddr' parameter to copy data from, but continuing to support this with new functionality like in-place conversion and hugepages in the pipeline has proven to be more trouble than it is worth, since there are no known users that have been identified who use a non-page-aligned 'uaddr' parameter. Rather than locking guest_memfd into continuing to support this, go ahead and document page-alignment as a requirement and begin enforcing this in the handling function. Reviewed-by: Vishal Annapurve <vannapurve@google.com> Tested-by: Kai Huang <kai.huang@intel.com> Signed-off-by: Michael Roth <michael.roth@amd.com> Link: https://patch.msgid.link/20260108214622.1084057-5-michael.roth@amd.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 8622ef0 commit dcbcc23

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

Documentation/virt/kvm/x86/amd-memory-encryption.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ Returns: 0 on success, < 0 on error, -EAGAIN if caller should retry
523523

524524
struct kvm_sev_snp_launch_update {
525525
__u64 gfn_start; /* Guest page number to load/encrypt data into. */
526-
__u64 uaddr; /* Userspace address of data to be loaded/encrypted. */
526+
__u64 uaddr; /* 4k-aligned address of data to be loaded/encrypted. */
527527
__u64 len; /* 4k-aligned length in bytes to copy into guest memory.*/
528528
__u8 type; /* The type of the guest pages being initialized. */
529529
__u8 pad0;

arch/x86/kvm/svm/sev.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2367,6 +2367,11 @@ static int snp_launch_update(struct kvm *kvm, struct kvm_sev_cmd *argp)
23672367
params.type != KVM_SEV_SNP_PAGE_TYPE_CPUID))
23682368
return -EINVAL;
23692369

2370+
src = params.type == KVM_SEV_SNP_PAGE_TYPE_ZERO ? NULL : u64_to_user_ptr(params.uaddr);
2371+
2372+
if (!PAGE_ALIGNED(src))
2373+
return -EINVAL;
2374+
23702375
npages = params.len / PAGE_SIZE;
23712376

23722377
/*
@@ -2398,7 +2403,6 @@ static int snp_launch_update(struct kvm *kvm, struct kvm_sev_cmd *argp)
23982403

23992404
sev_populate_args.sev_fd = argp->sev_fd;
24002405
sev_populate_args.type = params.type;
2401-
src = params.type == KVM_SEV_SNP_PAGE_TYPE_ZERO ? NULL : u64_to_user_ptr(params.uaddr);
24022406

24032407
count = kvm_gmem_populate(kvm, params.gfn_start, src, npages,
24042408
sev_gmem_post_populate, &sev_populate_args);

0 commit comments

Comments
 (0)