]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: SEV: Document/enforce page-alignment for KVM_SEV_SNP_LAUNCH_UPDATE
authorMichael Roth <michael.roth@amd.com>
Thu, 8 Jan 2026 21:46:20 +0000 (15:46 -0600)
committerSean Christopherson <seanjc@google.com>
Thu, 15 Jan 2026 20:31:16 +0000 (12:31 -0800)
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>
Documentation/virt/kvm/x86/amd-memory-encryption.rst
arch/x86/kvm/svm/sev.c

index 1ddb6a86ce7ff57755349ac1e92ea3826a1dba07..5a88d0197cb364ba4611e0862c2285ba01e8540b 100644 (file)
@@ -523,7 +523,7 @@ Returns: 0 on success, < 0 on error, -EAGAIN if caller should retry
 
         struct kvm_sev_snp_launch_update {
                 __u64 gfn_start;        /* Guest page number to load/encrypt data into. */
-                __u64 uaddr;            /* Userspace address of data to be loaded/encrypted. */
+                __u64 uaddr;            /* 4k-aligned address of data to be loaded/encrypted. */
                 __u64 len;              /* 4k-aligned length in bytes to copy into guest memory.*/
                 __u8 type;              /* The type of the guest pages being initialized. */
                 __u8 pad0;
index a70bd3f19e29c662ca38f36038a9d1a494b2265f..b4409bc652d1e6af6954878d2f43ad76eac4292b 100644 (file)
@@ -2367,6 +2367,11 @@ static int snp_launch_update(struct kvm *kvm, struct kvm_sev_cmd *argp)
             params.type != KVM_SEV_SNP_PAGE_TYPE_CPUID))
                return -EINVAL;
 
+       src = params.type == KVM_SEV_SNP_PAGE_TYPE_ZERO ? NULL : u64_to_user_ptr(params.uaddr);
+
+       if (!PAGE_ALIGNED(src))
+               return -EINVAL;
+
        npages = params.len / PAGE_SIZE;
 
        /*
@@ -2398,7 +2403,6 @@ static int snp_launch_update(struct kvm *kvm, struct kvm_sev_cmd *argp)
 
        sev_populate_args.sev_fd = argp->sev_fd;
        sev_populate_args.type = params.type;
-       src = params.type == KVM_SEV_SNP_PAGE_TYPE_ZERO ? NULL : u64_to_user_ptr(params.uaddr);
 
        count = kvm_gmem_populate(kvm, params.gfn_start, src, npages,
                                  sev_gmem_post_populate, &sev_populate_args);