From nobody Thu Apr 2 04:22:54 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 8F4872D97B7; Mon, 30 Mar 2026 10:45:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774867561; cv=none; b=eXj0sQSrWcSLosXLsnsfT6SiShwn3h1zRNLegsxbmo2UxppiGEXpUTVYcDzN3xaYwn+KiO/pztsqLoCmVji/VoRFt6J5pP1prOaC4HuqZTmGO0xYaSfXSNGS5facecc9m+JjP4xwWrQI5rWwvJbsuAIFK0scmJ/COXRH+p+M+x4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774867561; c=relaxed/simple; bh=u7zrFoP2g5LjSWx9KWVqxu+x8t67FZYRfzkFCu2T2D0=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=s8RX7DidKoDYIQDjkrhYrYbymSk5F7CCo3kxADjkGkTl5F4TMSrHP/ZhSg38etx66EZGzGGTzZPVQkvGmy9Rxofctc35Ekmlg01x+WvMGUxiFQ3Y0CboS/ZwwsUlHTPra9PuBbxyw17l4OP+6VKgft0QZxOj6q9/3NRYDT6HoQA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=sSKadjJV; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=AChTWXmH; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="sSKadjJV"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="AChTWXmH" Date: Mon, 30 Mar 2026 10:45:56 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1774867558; h=from:from:sender:sender:reply-to: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=KEz9aG3fmvC7mlVllCHIReJj+6EGeGQeP8Rne84DkCM=; b=sSKadjJVIqik2TJbJ+8XJozGDixSEeLKsJyqwmCDkz5uBd8ZJTvctlvBPC5tSh/28mwLoU 5lHaCOuBCtIB7Sap1lJvSu29SVC59SumYp1XQ8SVSv6kSd8XaEurJM8EkDp+rkG1mxkmGy eXnHTTO7sNYvOcCRyF+xL4dcSI6BWNjWZ7G+qHEuXUflVKXzUuJAYi3lksKrybIloFYSFb +Zwy85SyeslQ0raOppspQfMPE2q6MCgXLjMWzSAhWqf/7/+1y+ntWdA3V1fzV7KaqFiwrS xgV0XWIzvbFcm70mrmFAC7r3RK4xCwe8R4gdsvcOcQdVr+FE/yTMMrnayEHJrA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1774867558; h=from:from:sender:sender:reply-to: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=KEz9aG3fmvC7mlVllCHIReJj+6EGeGQeP8Rne84DkCM=; b=AChTWXmHyN32L0/duXQGOVVtEfddu16tuTyrkWMHSWNGGFwFRdSn1HHNCaVgCIqEa+3bx2 rsB1yZPZYJTfGXBg== From: "tip-bot2 for Tycho Andersen (AMD)" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/sev] crypto/ccp: Implement SNP x86 shutdown Cc: "Tycho Andersen (AMD)" , "Borislav Petkov (AMD)" , Tom Lendacky , Herbert Xu , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20260324161301.1353976-7-tycho@kernel.org> References: <20260324161301.1353976-7-tycho@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <177486755686.1647592.11576963399186027894.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the x86/sev branch of tip: Commit-ID: f995fc377ac7d3757e1d94e6403940c4b8f3d76e Gitweb: https://git.kernel.org/tip/f995fc377ac7d3757e1d94e6403940c4b= 8f3d76e Author: Tycho Andersen (AMD) AuthorDate: Tue, 24 Mar 2026 10:13:00 -06:00 Committer: Borislav Petkov (AMD) CommitterDate: Mon, 30 Mar 2026 12:02:12 +02:00 crypto/ccp: Implement SNP x86 shutdown The SEV firmware has support to disable SNP during an SNP_SHUTDOWN_EX comma= nd. Verify that this support is available and set the flag so that SNP is disab= led when it is not being used. In cases where SNP is disabled, skip the call to amd_iommu_snp_disable(), as all of the IOMMU pages have already been made shared. Also skip the panic case, since snp_shutdown() does IPIs. Signed-off-by: Tycho Andersen (AMD) Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Tom Lendacky Acked-by: Herbert Xu Link: https://patch.msgid.link/20260324161301.1353976-7-tycho@kernel.org --- drivers/crypto/ccp/sev-dev.c | 41 ++++++++++++++++++++--------------- include/linux/psp-sev.h | 5 +++- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index 0d0c09a..cc5c5b3 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -2039,6 +2039,8 @@ static int __sev_snp_shutdown_locked(int *error, bool= panic) memset(&data, 0, sizeof(data)); data.len =3D sizeof(data); data.iommu_snp_shutdown =3D 1; + if (sev->snp_feat_info_0.ecx & SNP_X86_SHUTDOWN_SUPPORTED) + data.x86_snp_shutdown =3D 1; =20 /* * If invoked during panic handling, local interrupts are disabled @@ -2072,23 +2074,28 @@ static int __sev_snp_shutdown_locked(int *error, bo= ol panic) return ret; } =20 - /* - * SNP_SHUTDOWN_EX with IOMMU_SNP_SHUTDOWN set to 1 disables SNP - * enforcement by the IOMMU and also transitions all pages - * associated with the IOMMU to the Reclaim state. - * Firmware was transitioning the IOMMU pages to Hypervisor state - * before version 1.53. But, accounting for the number of assigned - * 4kB pages in a 2M page was done incorrectly by not transitioning - * to the Reclaim state. This resulted in RMP #PF when later accessing - * the 2M page containing those pages during kexec boot. Hence, the - * firmware now transitions these pages to Reclaim state and hypervisor - * needs to transition these pages to shared state. SNP Firmware - * version 1.53 and above are needed for kexec boot. - */ - ret =3D amd_iommu_snp_disable(); - if (ret) { - dev_err(sev->dev, "SNP IOMMU shutdown failed\n"); - return ret; + if (data.x86_snp_shutdown) { + if (!panic) + snp_shutdown(); + } else { + /* + * SNP_SHUTDOWN_EX with IOMMU_SNP_SHUTDOWN set to 1 disables SNP + * enforcement by the IOMMU and also transitions all pages + * associated with the IOMMU to the Reclaim state. + * Firmware was transitioning the IOMMU pages to Hypervisor state + * before version 1.53. But, accounting for the number of assigned + * 4kB pages in a 2M page was done incorrectly by not transitioning + * to the Reclaim state. This resulted in RMP #PF when later accessing + * the 2M page containing those pages during kexec boot. Hence, the + * firmware now transitions these pages to Reclaim state and hypervisor + * needs to transition these pages to shared state. SNP Firmware + * version 1.53 and above are needed for kexec boot. + */ + ret =3D amd_iommu_snp_disable(); + if (ret) { + dev_err(sev->dev, "SNP IOMMU shutdown failed\n"); + return ret; + } } =20 snp_leak_hv_fixed_pages(); diff --git a/include/linux/psp-sev.h b/include/linux/psp-sev.h index 69ffa4b..d5099a2 100644 --- a/include/linux/psp-sev.h +++ b/include/linux/psp-sev.h @@ -829,12 +829,14 @@ struct sev_data_range_list { * * @len: length of the command buffer read by the PSP * @iommu_snp_shutdown: Disable enforcement of SNP in the IOMMU + * @x86_snp_shutdown: Disable SNP on all cores * @rsvd1: reserved */ struct sev_data_snp_shutdown_ex { u32 len; u32 iommu_snp_shutdown:1; - u32 rsvd1:31; + u32 x86_snp_shutdown:1; + u32 rsvd1:30; } __packed; =20 /** @@ -891,6 +893,7 @@ struct snp_feature_info { } __packed; =20 /* Feature bits in ECX */ +#define SNP_X86_SHUTDOWN_SUPPORTED BIT(1) #define SNP_RAPL_DISABLE_SUPPORTED BIT(2) #define SNP_CIPHER_TEXT_HIDING_SUPPORTED BIT(3) #define SNP_AES_256_XTS_POLICY_SUPPORTED BIT(4)