Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=85.214.250.239 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796118344; b=L8+cpoxUpl4nXgLqlqHLEnWaWf2dHnMh6TxLO9PlJ51X11PJVgN1OnPQExMm9XqrhghW hdrcQtCCoZzUA5LpKrStzNAidhKUulZLxOQQedOGRIKglUMUAA17dbrIOuVV2ZNNxNMpH WUAdJ2qAiMgDtTLsJkDeDmEbAgB56w6y/NZjWVl9d/SBims457UWQ/niSKOLuRKOEW7qw OKgQmR8lPm6pHX5ImuH29wGjG/XeDIuA+00iHwO+avQuhV2wO2GW5YbivAwaTR8jUwXw3 rueNpzKRjLvLg9QqLVJyXke9EUaxgfF4GlKJMw1cy+TYkmYFWDbNfKlK+zZxXC3DbKg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796118344; h=DMARC-Filter:Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=sobnCan6FjXL7ruKrsatbmd3M6Avh3kSEVekSwFR0iI=; b=Wo9RljTkENp9nik9iyKyqcQAdQL/GqvCZW2cyWBvKpkRH0BZukCTp/84ubietMOXOPr7 dKQx9ENfJ6pggzwEkVD6nITzlwMOtE31DHZIDunlI+hGipRdAxyXVznripJy8iyg6rkoi 3B45Psuk3Iw09OCkqK22hj72Cqd2acGd4LbcTNhJNn8Dns9mw07CxrjjPOoey9QgpJspB JkUd3ooqYXkKkztuNXx4imy4PrsIJ2c2/awbBnaUFS6/ktRoOGOJWjz5qUarI5B2jp69M 98v2tPqqRKR/bALu4mfF98xYUpBjgWhu+IB/RDhNJXPiGk74z+OYqvhyM7bxA+3iXXQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=8bytes.org; spf=pass smtp.mailfrom=8bytes.org; arc=none smtp.remote-ip=85.214.250.239 Received: from mail.8bytes.org (mail.8bytes.org [85.214.250.239]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 899B3606A684 for ; Tue, 1 Dec 2026 09:45:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 899B3606A684 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=8bytes.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=8bytes.org Received: from io.home.8bytes.org (p549216fa.dip0.t-ipconnect.de [84.146.22.250]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.8bytes.org (Postfix) with ESMTPSA id 2B32224586F; Tue, 1 Dec 2026 10:45:34 +0100 (CET) From: =?UTF-8?q?J=C3=B6rg=20R=C3=B6del?= To: Paolo Bonzini , Sean Christopherson Cc: Michael Roth , Liam Merwick , Vishal Annapurve , Ninad Naik , Joerg Roedel , Tom Lendacky , James Bottomley , kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, coconut-svsm@lists.linux.dev, joro@8bytes.org Subject: [PATCH v4 4/7] KVM: SEV: Allow VMSA pages in SNP launch updates Date: Tue, 1 Dec 2026 10:45:22 +0100 Message-ID: <20261201094525.1240736-5-joro@8bytes.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261201094525.1240736-1-joro@8bytes.org> References: <20261201094525.1240736-1-joro@8bytes.org> X-Mailing-List: coconut-svsm@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Joerg Roedel Pass the firmware VMSA page type through KVM_SEV_SNP_LAUNCH_UPDATE. Accept exactly one 4 KiB page per request when KVM_CAP_SNP_DIRECT_VMSA is enabled. Keep measurement independent of association with a vCPU. Require VMPL 0 and match sev_features against the VM's configured VMSA features before submitting the page to firmware. Signed-off-by: Joerg Roedel --- arch/x86/include/uapi/asm/kvm.h | 1 + arch/x86/kvm/svm/sev.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/arch/x86/include/uapi/asm/kvm.h b/arch/x86/include/uapi/asm/kvm.h index 00ce265391e1..f3c389d3c70e 100644 --- a/arch/x86/include/uapi/asm/kvm.h +++ b/arch/x86/include/uapi/asm/kvm.h @@ -885,6 +885,7 @@ struct kvm_sev_snp_launch_start { /* Kept in sync with firmware values for simplicity. */ #define KVM_SEV_PAGE_TYPE_INVALID 0x0 #define KVM_SEV_SNP_PAGE_TYPE_NORMAL 0x1 +#define KVM_SEV_SNP_PAGE_TYPE_VMSA 0x2 #define KVM_SEV_SNP_PAGE_TYPE_ZERO 0x3 #define KVM_SEV_SNP_PAGE_TYPE_UNMEASURED 0x4 #define KVM_SEV_SNP_PAGE_TYPE_SECRETS 0x5 diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index f22490f86a4a..4d492abb233b 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -2374,6 +2374,7 @@ struct sev_gmem_populate_args { __u8 type; int sev_fd; int fw_error; + bool vmsa_invalid; }; static int sev_gmem_post_populate(struct kvm *kvm, gfn_t gfn, kvm_pfn_t pfn, @@ -2404,6 +2405,19 @@ static int sev_gmem_post_populate(struct kvm *kvm, gfn_t gfn, kvm_pfn_t pfn, kunmap_local(src_vaddr); } + if (sev_populate_args->type == KVM_SEV_SNP_PAGE_TYPE_VMSA) { + struct sev_es_save_area *vmsa = kmap_local_pfn(pfn); + + if (vmsa->vmpl || vmsa->sev_features != sev->vmsa_features) { + sev_populate_args->vmsa_invalid = true; + ret = -EINVAL; + } + + kunmap_local(vmsa); + if (ret) + goto out; + } + ret = rmp_make_private(pfn, gfn << PAGE_SHIFT, PG_LEVEL_4K, sev_get_asid(kvm), true); if (ret) @@ -2467,7 +2481,10 @@ static int snp_launch_update(struct kvm *kvm, struct kvm_sev_cmd *argp) params.gfn_start, params.len, params.type, params.flags, params.uaddr); if (!params.len || !PAGE_ALIGNED(params.len) || params.flags || + (params.type == KVM_SEV_SNP_PAGE_TYPE_VMSA && + (!sev->snp_direct_vmsa || params.len != PAGE_SIZE)) || (params.type != KVM_SEV_SNP_PAGE_TYPE_NORMAL && + params.type != KVM_SEV_SNP_PAGE_TYPE_VMSA && params.type != KVM_SEV_SNP_PAGE_TYPE_ZERO && params.type != KVM_SEV_SNP_PAGE_TYPE_UNMEASURED && params.type != KVM_SEV_SNP_PAGE_TYPE_SECRETS && @@ -2516,6 +2533,9 @@ static int snp_launch_update(struct kvm *kvm, struct kvm_sev_cmd *argp) params.type == KVM_SEV_SNP_PAGE_TYPE_CPUID, sev_gmem_post_populate, &sev_populate_args); if (count < 0) { + if (sev_populate_args.vmsa_invalid) + return -EINVAL; + argp->error = sev_populate_args.fw_error; pr_debug("%s: kvm_gmem_populate failed, ret %ld (fw_error %d)\n", __func__, count, argp->error); -- 2.53.0