From nobody Mon Jun 8 05:28:10 2026 Received: from out-180.mta0.migadu.com (out-180.mta0.migadu.com [91.218.175.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 71AB63A9626 for ; Tue, 2 Jun 2026 22:36:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780439814; cv=none; b=gYNH8izYIRVzxHR060pgfBS9CL2sVkur1AO/XtcFjMJz5sTUSmWWv6oAosTYxpi6YG821j7xFTtcL/hZFzoX88RsXogz04+BjB++nlqXDVfPihRKfsRdRbXk8rC2kAWBMhGriXN2bjCjLLtwWj96eOdsYtfy3UTdCfuh6IYHkfY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780439814; c=relaxed/simple; bh=nLmgK2QUTw1cM7CspAyD0+EJIbz7/EpovpRhFQ4nPyg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Uar8u8LkpOVvQ3qLFJ5xzHynSR1rhloNJoH/+lVKlPX7RPGmFjl5/oD01WQt0KkjgHQSWbjjxbrNEMoDq1lmIu1PKk4DjgHLWqM5Iy3IB+NO/IiV8KCYdUvHiguoWGi9eEQHp6mGsYwWGBQXLYbVOmJM1AHkKTVWkxyQbTZABrs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=sTPVwVRE; arc=none smtp.client-ip=91.218.175.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="sTPVwVRE" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1780439809; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YU3VGYDHMSuXOk2TlF1/XLiQKn7O+Ll77KLtsMACVqw=; b=sTPVwVRERoNEMtd4MBnKVafqVhpUTs8gV9/gqRM5ohPJ/FIyyFE5GYSGX/KRLRdW3b2lmM 9cPxHthtwG58xNu1E+sTSkJ3db3Qw2qvZ+C4DjePNsJ99tmYajze3IFMoJo6v7H0xsT3se 3k/HD1lbSAoevqEJRoLu99K/zbyN2Ac= From: Atish Patra Date: Tue, 02 Jun 2026 15:36:32 -0700 Subject: [PATCH v3 1/4] KVM: SEV: Do not allow intra-host migration/mirroring of SNP VMs Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260602-sev_snp_fixes-v3-1-24bfd3ae047c@meta.com> References: <20260602-sev_snp_fixes-v3-0-24bfd3ae047c@meta.com> In-Reply-To: <20260602-sev_snp_fixes-v3-0-24bfd3ae047c@meta.com> To: Sean Christopherson , Paolo Bonzini , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Tom Lendacky , Peter Gonda , Brijesh Singh , Youngjae Lee , Ashish Kalra , Michael Roth , John Allen , Herbert Xu Cc: clm@meta.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, stable@vger.kernel.org, Atish Patra , Sashiko X-Migadu-Flow: FLOW_OUT From: Atish Patra The intra-host migration/mirroring feature is not fully implemented for SEV-SNP VMs. The proper migration requires additional SNP-specific state such as guest_req_mutex, guest_req_buf, and guest_resp_buf to be transferred or initialized on the destination. The SNP VM mirroring requires vmsa features to be copied as well otherwise ASID would be bound to SNP range while VM is detected as a SEV VM. Reject SNP source VMs in migration/mirroring until proper SNP state transfer is implemented. Fixes: 1dfe571c12cf ("KVM: SEV: Add initial SEV-SNP support") Reported-by: Chris Mason Reported-by: Sashiko Assisted-by: Claude:claude-opus-4-6 Reviewed-by: Tom Lendacky Signed-off-by: Atish Patra --- arch/x86/kvm/svm/sev.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index c2126b3c3072..a34326a77290 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -2141,8 +2141,10 @@ int sev_vm_move_enc_context_from(struct kvm *kvm, un= signed int source_fd) if (ret) return ret; =20 + /* Do not allow SNP VM migration until additional state transfer is imple= mented */ if (kvm->arch.vm_type !=3D source_kvm->arch.vm_type || - sev_guest(kvm) || !sev_guest(source_kvm)) { + sev_guest(kvm) || !sev_guest(source_kvm) || + sev_snp_guest(source_kvm)) { ret =3D -EINVAL; goto out_unlock; } @@ -2863,8 +2865,10 @@ int sev_vm_copy_enc_context_from(struct kvm *kvm, un= signed int source_fd) * disallow out-of-band SEV/SEV-ES init if the target is already an * SEV guest, or if vCPUs have been created. KVM relies on vCPUs being * created after SEV/SEV-ES initialization, e.g. to init intercepts. + * Also do not allow SNP VM mirroring until additional state transfer is = implemented. */ if (sev_guest(kvm) || !sev_guest(source_kvm) || + sev_snp_guest(source_kvm) || is_mirroring_enc_context(source_kvm) || kvm->created_vcpus) { ret =3D -EINVAL; goto e_unlock; --=20 2.53.0-Meta From nobody Mon Jun 8 05:28:10 2026 Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D73613C768A for ; Tue, 2 Jun 2026 22:36:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780439816; cv=none; b=OzvotlITp8Qci+g8iGVVos6UrpimvYsOFR0LMNjip6yiK24ix25Rb6REUuBlIwrCXvlPSJNJCPCOK5y+zyXsEUYlr5OqWBL4CWYZQEap6UZ9aqXsivMeM8AMsdMQXIwgvqh3aDqjcqws51reqWZHOpU1q2bpwMAqJyo86Dmf7vA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780439816; c=relaxed/simple; bh=hJHj9af2b4aGE8hdvzxfH1HNHgYHgZ+5YN6mW3BKutM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Kb9wJVJoxT+2vS/TBSi4W6Pmd7OAo+R17TvaYzN2bM57QQ+0N3YWGBQ0GN+mVqCJL+a/wEInLQmcKDlpPz4uFJS21VNl4SstAsS2AxwRtmNaFAcH7SEXWb/utoAiF9mOxYKT9B8UgDUwB1EcHUf/NZBEQCkFuH1bir10051XoJU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=SoyRONPK; arc=none smtp.client-ip=91.218.175.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="SoyRONPK" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1780439812; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qwUuu9T1lQ6cMXR7h0uQbhUHWqF4ALjjRwoKhkOobCI=; b=SoyRONPKp4Ug4mCFZHWRI62iAUsegWvVxtlzNu8Iv1nqJ5WrOm3merrIDlJo9ie/xt+VMy KpiFMb0f65wJFnw1va/ETFuvcxziFT2PU583U/gVnwJzj/rnbAMstfh78K7/W19qRMwMXC aIonyrqntDDY2OxVaSUyU7/CXvuZEQ8= From: Atish Patra Date: Tue, 02 Jun 2026 15:36:33 -0700 Subject: [PATCH v3 2/4] KVM: selftests: Verify SNP VMs are rejected from migration and mirroring Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260602-sev_snp_fixes-v3-2-24bfd3ae047c@meta.com> References: <20260602-sev_snp_fixes-v3-0-24bfd3ae047c@meta.com> In-Reply-To: <20260602-sev_snp_fixes-v3-0-24bfd3ae047c@meta.com> To: Sean Christopherson , Paolo Bonzini , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Tom Lendacky , Peter Gonda , Brijesh Singh , Youngjae Lee , Ashish Kalra , Michael Roth , John Allen , Herbert Xu Cc: clm@meta.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, stable@vger.kernel.org, Atish Patra X-Migadu-Flow: FLOW_OUT From: Atish Patra Migration and mirroring of SEV-SNP VMs are not supported yet. Add two selftests that verify KVM rejects intra-host migration and mirroring when the source VM is an SNP VM, so the restriction stays enforced until proper SNP state transfer is implemented. Signed-off-by: Atish Patra --- .../testing/selftests/kvm/x86/sev_migrate_tests.c | 47 ++++++++++++++++++= ++++ 1 file changed, 47 insertions(+) diff --git a/tools/testing/selftests/kvm/x86/sev_migrate_tests.c b/tools/te= sting/selftests/kvm/x86/sev_migrate_tests.c index 6b0928e69051..acef6ab26d3d 100644 --- a/tools/testing/selftests/kvm/x86/sev_migrate_tests.c +++ b/tools/testing/selftests/kvm/x86/sev_migrate_tests.c @@ -313,6 +313,49 @@ static void test_sev_mirror_parameters(void) kvm_vm_free(vm_no_vcpu); } =20 +static void test_sev_snp_migrate_reject(void) +{ + struct kvm_vm *src_vm, *dst_vm; + int ret; + + src_vm =3D vm_create_barebones_type(KVM_X86_SNP_VM); + snp_vm_init(src_vm); + __vm_vcpu_add(src_vm, 0); + vm_sev_launch(src_vm, snp_default_policy(), NULL); + + dst_vm =3D vm_create_barebones_type(KVM_X86_SNP_VM); + __vm_vcpu_add(dst_vm, 0); + + ret =3D __sev_migrate_from(dst_vm, src_vm); + TEST_ASSERT(ret =3D=3D -1 && errno =3D=3D EINVAL, + "SNP VM migration should be rejected. ret: %d, errno: %d", + ret, errno); + + kvm_vm_free(src_vm); + kvm_vm_free(dst_vm); +} + +static void test_sev_snp_mirror_reject(void) +{ + struct kvm_vm *src_vm, *dst_vm; + int ret; + + src_vm =3D vm_create_barebones_type(KVM_X86_SNP_VM); + snp_vm_init(src_vm); + __vm_vcpu_add(src_vm, 0); + vm_sev_launch(src_vm, snp_default_policy(), NULL); + + dst_vm =3D aux_vm_create(false); + + ret =3D __sev_mirror_create(dst_vm, src_vm); + TEST_ASSERT(ret =3D=3D -1 && errno =3D=3D EINVAL, + "SNP VM mirroring should be rejected. ret: %d, errno: %d", + ret, errno); + + kvm_vm_free(src_vm); + kvm_vm_free(dst_vm); +} + static void test_sev_move_copy(void) { struct kvm_vm *dst_vm, *dst2_vm, *dst3_vm, *sev_vm, *mirror_vm, @@ -384,12 +427,16 @@ int main(int argc, char *argv[]) test_sev_migrate_parameters(); if (kvm_has_cap(KVM_CAP_VM_COPY_ENC_CONTEXT_FROM)) test_sev_move_copy(); + if (kvm_cpu_has(X86_FEATURE_SEV_SNP)) + test_sev_snp_migrate_reject(); } if (kvm_has_cap(KVM_CAP_VM_COPY_ENC_CONTEXT_FROM)) { test_sev_mirror(/* es=3D */ false); if (have_sev_es) test_sev_mirror(/* es=3D */ true); test_sev_mirror_parameters(); + if (kvm_cpu_has(X86_FEATURE_SEV_SNP)) + test_sev_snp_mirror_reject(); } return 0; } --=20 2.53.0-Meta From nobody Mon Jun 8 05:28:10 2026 Received: from out-182.mta1.migadu.com (out-182.mta1.migadu.com [95.215.58.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AACB93A9626 for ; Tue, 2 Jun 2026 22:37:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780439822; cv=none; b=chCQlO/uqtHXRJy59I+nGGyurI44WhmFRfA6yPodQn6yr2IfPtwMPRTbhvghZmxT46UMqALzF4fgVtndX+9/jrdMvuAPPJ9o1E8a+nqIj14E8tSOLiZT4N2x1ULzC356iAzDXVCQgLpnAKfxBspPS4Pa0GQyEaEQ6o3PK1oN/sE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780439822; c=relaxed/simple; bh=9hq6zdSwsjyPBSgr32Ip1dWxtQ83+EJXhKVsLpA1Ebg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=W5EhNIEFl1XJlT7AsRTT43mKgo63Tekrb1l+IxI1ZpeAwl7omWCbP17yvSW+37p2q1mVePPGQNLssNKl7JAotb45tHaQ2CuX8HFgYyp8l64OjOUu00+N4B2j0XMuU5Kmm1uWVs8iUCWKE6NxpWkNIbOSGLz63AUtyn5OgtVZH28= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=ff25GIZm; arc=none smtp.client-ip=95.215.58.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="ff25GIZm" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1780439818; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h+027DcSYo9NyoKNOAow6QM7b5wUq0wevIvgDFOXMNA=; b=ff25GIZmC7IEb4xhl/jlEAtYkb95u2yCf1hjmu/CjcErN57NqZrLttc7G4+/o133PrzYBC 9oyu3wbX4G4IzZ+9uF+2ASpfETT5HEDfmKh0uVAQaT1kS7ZBqhRsn0oyxnLXfpsenv2JMn CcQjFcQ9cbKNW7E8meUf+WfbuXJi2Y8= From: Atish Patra Date: Tue, 02 Jun 2026 15:36:34 -0700 Subject: [PATCH v3 3/4] crypto: ccp: Fix possible deadlock in SEV init failure path Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260602-sev_snp_fixes-v3-3-24bfd3ae047c@meta.com> References: <20260602-sev_snp_fixes-v3-0-24bfd3ae047c@meta.com> In-Reply-To: <20260602-sev_snp_fixes-v3-0-24bfd3ae047c@meta.com> To: Sean Christopherson , Paolo Bonzini , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Tom Lendacky , Peter Gonda , Brijesh Singh , Youngjae Lee , Ashish Kalra , Michael Roth , John Allen , Herbert Xu Cc: clm@meta.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, stable@vger.kernel.org, Atish Patra X-Migadu-Flow: FLOW_OUT From: Atish Patra __sev_platform_init_handle_init_ex_path() calls rmp_mark_pages_firmware() with locked=3Dfalse while the parent function of init_ex_path already acquired the sev_cmd_mutex. In the case of an RMPUPDATE failure for any page after the first, the clean= up path would invoke reclaim pages which would result in a deadlock in sev_do_cmd. Pass locked=3Dtrue to honor the lock status of the parent function. Fixes: 7364a6fbca45 ("crypto: ccp: Handle non-volatile INIT_EX data when SN= P is enabled") Reported-by: Chris Mason Assisted-by: Claude:claude-opus-4-6 Fixes: 7364a6fbca45 ("crypto: ccp: Handle non-volatile INIT_EX data when SN= P is enabled") Reviewed-by: Tom Lendacky Signed-off-by: Atish Patra --- drivers/crypto/ccp/sev-dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index d1e9e0ac63b6..3d4793e8e34b 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -1557,7 +1557,7 @@ static int __sev_platform_init_handle_init_ex_path(st= ruct sev_device *sev) unsigned long npages; =20 npages =3D 1UL << get_order(NV_LENGTH); - if (rmp_mark_pages_firmware(__pa(sev_init_ex_buffer), npages, false)) { + if (rmp_mark_pages_firmware(__pa(sev_init_ex_buffer), npages, true)) { dev_err(sev->dev, "SEV: INIT_EX NV memory page state change failed.\n"); return -ENOMEM; } --=20 2.53.0-Meta From nobody Mon Jun 8 05:28:10 2026 Received: from out-170.mta0.migadu.com (out-170.mta0.migadu.com [91.218.175.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 817033CAA31 for ; Tue, 2 Jun 2026 22:37:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780439826; cv=none; b=UiCwW8dKig4lHXj1xHEd2ARQwi46d5yB3hJqBMONR3mC0A0RZBa3b6nl367GDb5H3H/dH8NTKTgKTb/SnJgtutwEvSGD2zs8/dx3tBsEy6YjQpXnkGMAf7QSLsQD8JGj5hmrVddMgdrzFqNtJd9PLtx0JhNVCSvRMRELE7oRXp8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780439826; c=relaxed/simple; bh=jYNiQtLVpZZ7lTPv8P842pmNxaEEFedXW05/Mcqpfr0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Kz3cE3X9+5Wf/Cq9We5d3ia0ifDo7o04Xv0KKjV0bviaF6WjXML0f0I5zxI1uKS6rPaKo+U5jbRPZY6NHM52BDNKzNWufYT4FqpzY9s7fQZpixxnyQHuiBahF1qYHN6g5NDOdbALD6znsaOho2nXe1AtyAtOh4Z7NGt1wRhdU6U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=PJqSJABR; arc=none smtp.client-ip=91.218.175.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="PJqSJABR" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1780439822; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k/dcKBQxfjoEPDMB8xdOqV0xZBkG7A4yvXz6y/EVP6M=; b=PJqSJABR7oQAgf37e8OY305ZCfXC2B8NHIya+ZCVmpv6J0CVUPRzhr/FXHdy1XSkkSrBvJ 4+Q9N5UeijjegRq+GbqSOuC74ZGUUN6Aq0dx0BDeFY3gHRpPT65KKUd33wOZe17bamfywx UXSHlXVnfKCX+0tWX/zYkGHgh0qXsr8= From: Atish Patra Date: Tue, 02 Jun 2026 15:36:35 -0700 Subject: [PATCH v3 4/4] crypto: ccp: Fix memory leak in SEV INIT_EX path Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260602-sev_snp_fixes-v3-4-24bfd3ae047c@meta.com> References: <20260602-sev_snp_fixes-v3-0-24bfd3ae047c@meta.com> In-Reply-To: <20260602-sev_snp_fixes-v3-0-24bfd3ae047c@meta.com> To: Sean Christopherson , Paolo Bonzini , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Tom Lendacky , Peter Gonda , Brijesh Singh , Youngjae Lee , Ashish Kalra , Michael Roth , John Allen , Herbert Xu Cc: clm@meta.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, stable@vger.kernel.org, Atish Patra , Sashiko X-Migadu-Flow: FLOW_OUT From: Atish Patra allocated pages in _init_ext_path are never freed and sev_init_ex_buffer is left pointing at the leaked memory in case of any failures during the function.. Fix by adding an error path that frees the pages and clears sev_init_ex_buffer. Make sure we only free the memory if the failure happens before the conversion. Otherwise, we may end up trying to free up converted pages in case of reclaim failure. rmp_mark_pages_firmware failures should be rare enough to avoid more code complexity to track down which pages were reclaimed/leaked vs which are not. Fixes: 7364a6fbca45 ("crypto: ccp: Handle non-volatile INIT_EX data when SN= P is enabled") Reported-by: Sashiko Reviewed-by: Tom Lendacky Signed-off-by: Atish Patra --- drivers/crypto/ccp/sev-dev.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index 3d4793e8e34b..57b4c1e79589 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -1540,7 +1540,7 @@ static int __sev_platform_init_handle_init_ex_path(st= ruct sev_device *sev) if (sev_init_ex_buffer) return 0; =20 - page =3D alloc_pages(GFP_KERNEL, get_order(NV_LENGTH)); + page =3D alloc_pages(GFP_KERNEL | __GFP_ZERO, get_order(NV_LENGTH)); if (!page) { dev_err(sev->dev, "SEV: INIT_EX NV memory allocation failed\n"); return -ENOMEM; @@ -1550,7 +1550,7 @@ static int __sev_platform_init_handle_init_ex_path(st= ruct sev_device *sev) =20 rc =3D sev_read_init_ex_file(); if (rc) - return rc; + goto err_free; =20 /* If SEV-SNP is initialized, transition to firmware page. */ if (sev->snp_initialized) { @@ -1559,11 +1559,22 @@ static int __sev_platform_init_handle_init_ex_path(= struct sev_device *sev) npages =3D 1UL << get_order(NV_LENGTH); if (rmp_mark_pages_firmware(__pa(sev_init_ex_buffer), npages, true)) { dev_err(sev->dev, "SEV: INIT_EX NV memory page state change failed.\n"); - return -ENOMEM; + rc =3D -ENOMEM; + /* + * Pages can be in an inconsistent state, don't release them back to the + * system. + */ + goto err_reset; } } =20 return 0; + +err_free: + __free_pages(page, get_order(NV_LENGTH)); +err_reset: + sev_init_ex_buffer =3D NULL; + return rc; } =20 static int __sev_platform_init_locked(int *error) --=20 2.53.0-Meta