mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tom Lendacky <thomas.lendacky@amd.com>
To: Tycho Andersen <tycho@kernel.org>,
	Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
	Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	Ashish Kalra <ashish.kalra@amd.com>,
	John Allen <john.allen@amd.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>,
	Ard Biesheuvel <ardb@kernel.org>,
	Alexey Kardashevskiy <aik@amd.com>,
	Nikunj A Dadhania <nikunj@amd.com>,
	"Peter Zijlstra (Intel)" <peterz@infradead.org>,
	Kim Phillips <kim.phillips@amd.com>,
	Sean Christopherson <seanjc@google.com>
Cc: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org
Subject: Re: [PATCH 10/11] crypto: ccp - implement SNP x86 shutdown
Date: Mon, 2 Mar 2026 14:47:03 -0600	[thread overview]
Message-ID: <12e7f995-b55e-4090-b733-d25874871593@amd.com> (raw)
In-Reply-To: <20260302191334.937981-11-tycho@kernel.org>

On 3/2/26 13:13, Tycho Andersen wrote:
> From: "Tycho Andersen (AMD)" <tycho@kernel.org>
> 
> The SEV firmware has support to disable SNP during an SNP_SHUTDOWN_EX
> command. Verify that this support is available and set the flag so that SNP
> is disabled 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.
> 
> Signed-off-by: Tycho Andersen (AMD) <tycho@kernel.org>

Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>

> ---
>  drivers/crypto/ccp/sev-dev.c | 44 ++++++++++++++++++++++--------------
>  include/linux/psp-sev.h      |  4 +++-
>  2 files changed, 30 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
> index ef45977b09b6..665fe0615b06 100644
> --- a/drivers/crypto/ccp/sev-dev.c
> +++ b/drivers/crypto/ccp/sev-dev.c
> @@ -2028,6 +2028,7 @@ static int __sev_snp_shutdown_locked(int *error, bool panic)
>  	struct psp_device *psp = psp_master;
>  	struct sev_device *sev;
>  	struct sev_data_snp_shutdown_ex data;
> +	u64 syscfg;
>  	int ret;
>  
>  	if (!psp || !psp->sev_data)
> @@ -2041,6 +2042,8 @@ static int __sev_snp_shutdown_locked(int *error, bool panic)
>  	memset(&data, 0, sizeof(data));
>  	data.len = sizeof(data);
>  	data.iommu_snp_shutdown = 1;
> +	if (sev->snp_feat_info_0.ecx & SNP_X86_SHUTDOWN_SUPPORTED)
> +		data.x86_snp_shutdown = 1;
>  
>  	/*
>  	 * If invoked during panic handling, local interrupts are disabled
> @@ -2074,23 +2077,30 @@ static int __sev_snp_shutdown_locked(int *error, bool panic)
>  		return ret;
>  	}
>  
> -	/*
> -	 * 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 = amd_iommu_snp_disable();
> -	if (ret) {
> -		dev_err(sev->dev, "SNP IOMMU shutdown failed\n");
> -		return ret;
> +	rdmsrq(MSR_AMD64_SYSCFG, syscfg);
> +	if (data.x86_snp_shutdown &&
> +	    !WARN_ON_ONCE(syscfg & MSR_AMD64_SYSCFG_SNP_EN)) {
> +		if (!panic)
> +			snp_x86_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 = amd_iommu_snp_disable();
> +		if (ret) {
> +			dev_err(sev->dev, "SNP IOMMU shutdown failed\n");
> +			return ret;
> +		}
>  	}
>  
>  	snp_leak_hv_fixed_pages();
> diff --git a/include/linux/psp-sev.h b/include/linux/psp-sev.h
> index 69ffa4b4d1fa..2adb990189c1 100644
> --- a/include/linux/psp-sev.h
> +++ b/include/linux/psp-sev.h
> @@ -834,7 +834,8 @@ struct sev_data_range_list {
>  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;
>  
>  /**
> @@ -891,6 +892,7 @@ struct snp_feature_info {
>  } __packed;
>  
>  /* 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)


  reply	other threads:[~2026-03-02 20:47 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-02 19:13 [PATCH 00/11] Move SEV-SNP initialization to ccp driver Tycho Andersen
2026-03-02 19:13 ` [PATCH 01/11] x86/snp: drop support for SNP hotplug Tycho Andersen
2026-03-02 19:56   ` Tom Lendacky
2026-03-05 12:57   ` Borislav Petkov
2026-03-06 15:38   ` Borislav Petkov
2026-03-09 18:00     ` [PATCH v2 00/10] Move SNP initialization to the CCP driver Tycho Andersen
2026-03-09 18:00       ` [PATCH v2 01/10] x86/snp: drop support for SNP hotplug Tycho Andersen
2026-03-10 10:47         ` [tip: x86/sev] x86/virt/sev: Drop " tip-bot2 for Tycho Andersen (AMD)
2026-03-09 18:00       ` [PATCH v2 02/10] x86/snp: drop WBINVD before setting SNPEn Tycho Andersen
2026-03-10 10:47         ` [tip: x86/sev] x86/virt/sev: Drop WBINVD before setting MSR_AMD64_SYSCFG_SNP_EN tip-bot2 for Tycho Andersen (AMD)
2026-03-09 18:00       ` [PATCH v2 03/10] x86/snp: Keep the RMP table bookkeeping area mapped Tycho Andersen
2026-03-10 10:47         ` [tip: x86/sev] x86/virt/sev: " tip-bot2 for Tom Lendacky
2026-03-09 18:00       ` [PATCH v2 04/10] x86/snp: Create a function to clear/zero the RMP Tycho Andersen
2026-03-13 16:17         ` Borislav Petkov
2026-03-09 18:00       ` [PATCH v2 05/10] x86/snp: create snp_prepare_for_snp_init() Tycho Andersen
2026-03-09 18:00       ` [PATCH v2 06/10] x86/snp, crypto: move SNP init to ccp driver Tycho Andersen
2026-03-09 18:00       ` [PATCH v2 07/10] x86/snp, crypto: move HSAVE_PA setup to arch/ Tycho Andersen
2026-03-09 18:00       ` [PATCH v2 08/10] x86/snp: create snp_x86_shutdown() Tycho Andersen
2026-03-09 18:00       ` [PATCH v2 09/10] crypto: ccp - implement SNP x86 shutdown Tycho Andersen
2026-03-09 18:00       ` [PATCH v2 10/10] crypto: ccp - Update HV_FIXED page states to allow freeing of memory Tycho Andersen
2026-03-02 19:13 ` [PATCH 02/11] x86/snp: Keep the RMP table bookkeeping area mapped Tycho Andersen
2026-03-06 15:55   ` Borislav Petkov
2026-03-02 19:13 ` [PATCH 03/11] x86/snp: Create a function to clear/zero the RMP Tycho Andersen
2026-03-02 19:13 ` [PATCH 04/11] x86/snp: drop WBINVD before setting SNPEn Tycho Andersen
2026-03-02 20:00   ` Tom Lendacky
2026-03-02 19:13 ` [PATCH 05/11] x86/snp: create snp_prepare_for_snp_init() Tycho Andersen
2026-03-02 20:03   ` Tom Lendacky
2026-03-02 19:13 ` [PATCH 06/11] x86/snp, crypto: move SNP init to ccp driver Tycho Andersen
2026-03-02 20:25   ` Tom Lendacky
2026-03-02 19:13 ` [PATCH 07/11] x86/snp, crypto: move HSAVE_PA setup to arch/ Tycho Andersen
2026-03-02 20:27   ` Tom Lendacky
2026-03-02 19:13 ` [PATCH 08/11] x86/snp: allow disabling MFDM Tycho Andersen
2026-03-02 20:29   ` Tom Lendacky
2026-03-02 19:13 ` [PATCH 09/11] x86/snp: create snp_x86_shutdown() Tycho Andersen
2026-03-02 20:35   ` Tom Lendacky
2026-03-02 21:20     ` Tycho Andersen
2026-03-02 19:13 ` [PATCH 10/11] crypto: ccp - implement SNP x86 shutdown Tycho Andersen
2026-03-02 20:47   ` Tom Lendacky [this message]
2026-03-02 19:13 ` [PATCH 11/11] crypto: ccp - Update HV_FIXED page states to allow freeing of memory Tycho Andersen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=12e7f995-b55e-4090-b733-d25874871593@amd.com \
    --to=thomas.lendacky@amd.com \
    --cc=aik@amd.com \
    --cc=ardb@kernel.org \
    --cc=ashish.kalra@amd.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=hpa@zytor.com \
    --cc=john.allen@amd.com \
    --cc=kim.phillips@amd.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=nikunj@amd.com \
    --cc=peterz@infradead.org \
    --cc=seanjc@google.com \
    --cc=tglx@kernel.org \
    --cc=tycho@kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®