X86 platform drivers
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Mario Limonciello <mario.limonciello@amd.com>
Cc: Hans de Goede <hansg@kernel.org>,
	open list <linux-kernel@vger.kernel.org>,
	 "open list:X86 PLATFORM DRIVERS"
	<platform-driver-x86@vger.kernel.org>,
	 Francis De Brabandere <francisdb@gmail.com>,
	stable@vger.kernel.org
Subject: Re: [PATCH 2/4] platform/x86/amd/pmc: Fix error handling in amd_stb_s2d_init()
Date: Tue, 21 Jul 2026 13:24:32 +0300 (EEST)	[thread overview]
Message-ID: <54655f38-edf4-e756-e24c-5f4cb041d63c@linux.intel.com> (raw)
In-Reply-To: <20260717162023.956346-3-mario.limonciello@amd.com>

On Fri, 17 Jul 2026, Mario Limonciello wrote:

> amd_stb_s2d_init() has two problems on its error paths:
> 
>  - The return value of the S2D_TELEMETRY_SIZE SMU command is discarded.
>    When the SMU refuses the command (e.g. "SMU cmd failed. err: 0xff")
>    the failure is only noticed indirectly through the telemetry size
>    check and reported as -EIO, masking the real error.
> 
>  - dev->msg_port is switched to MSG_PORT_S2D before issuing the S2D SMU
>    commands but is only restored to MSG_PORT_PMC on the success path.
>    The early "return -EIO" leaves the port stuck on MSG_PORT_S2D, so all
>    subsequent SMU communication - including the s2idle prepare/restore
>    handlers - is directed at the wrong mailbox.

If you fix the second one first (see below, it seems another place needs 
similar fix), the first one can be fixed on top of it in own patch.

> Consolidate the exit path through a single label so the message port is
> always restored, and propagate the SMU command error directly instead of
> inferring it from the size.
> 
> Assisted-by: Claude:opus
> Reported-by: Francis De Brabandere <francisdb@gmail.com>
> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=221759
> Tested-by: Francis De Brabandere <francisdb@gmail.com>
> Fixes: 3d7d407dfb05 ("platform/x86: amd-pmc: Add support for AMD Spill to DRAM STB feature")
> Cc: stable@vger.kernel.org
> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
> ---
>  drivers/platform/x86/amd/pmc/mp1_stb.c | 28 +++++++++++++++-----------
>  1 file changed, 16 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/platform/x86/amd/pmc/mp1_stb.c b/drivers/platform/x86/amd/pmc/mp1_stb.c
> index 753d630f3283d..6a048cb2605ec 100644
> --- a/drivers/platform/x86/amd/pmc/mp1_stb.c
> +++ b/drivers/platform/x86/amd/pmc/mp1_stb.c
> @@ -289,7 +289,7 @@ int amd_stb_s2d_init(struct amd_pmc_dev *dev)
>  	u32 phys_addr_low, phys_addr_hi;
>  	u64 stb_phys_addr;
>  	u32 size = 0;
> -	int ret;
> +	int ret = 0;
>  
>  	if (!enable_stb)
>  		return 0;
> @@ -306,13 +306,17 @@ int amd_stb_s2d_init(struct amd_pmc_dev *dev)
>  	/* Spill to DRAM feature uses separate SMU message port */
>  	dev->msg_port = MSG_PORT_S2D;
>  
> -	amd_pmc_send_cmd(dev, S2D_TELEMETRY_SIZE, &size, dev->stb_arg.s2d_msg_id, true);
> -	if (size != S2D_TELEMETRY_BYTES_MAX)
> -		return -EIO;
> +	ret = amd_pmc_send_cmd(dev, S2D_TELEMETRY_SIZE, &size, dev->stb_arg.s2d_msg_id, true);
> +	if (ret)
> +		goto out;
> +	if (size != S2D_TELEMETRY_BYTES_MAX) {
> +		ret = -EIO;
> +		goto out;
> +	}
>  
> -	/* Get DRAM size */
> -	ret = amd_pmc_send_cmd(dev, S2D_DRAM_SIZE, &dev->dram_size, dev->stb_arg.s2d_msg_id, true);
> -	if (ret || !dev->dram_size)
> +	/* Get DRAM size; fall back to the default if the query fails */
> +	if (amd_pmc_send_cmd(dev, S2D_DRAM_SIZE, &dev->dram_size, dev->stb_arg.s2d_msg_id, true) ||
> +	    !dev->dram_size)
>  		dev->dram_size = S2D_TELEMETRY_DRAMBYTES_MAX;
>  
>  	/* Get STB DRAM address */
> @@ -321,12 +325,12 @@ int amd_stb_s2d_init(struct amd_pmc_dev *dev)
>  
>  	stb_phys_addr = ((u64)phys_addr_hi << 32 | phys_addr_low);
>  
> -	/* Clear msg_port for other SMU operation */
> -	dev->msg_port = MSG_PORT_PMC;
> -
>  	dev->stb_virt_addr = devm_ioremap(dev->dev, stb_phys_addr, dev->dram_size);
>  	if (!dev->stb_virt_addr)
> -		return -ENOMEM;
> +		ret = -ENOMEM;
>  
> -	return 0;
> +out:
> +	/* Restore the default message port for subsequent SMU operations */
> +	dev->msg_port = MSG_PORT_PMC;

Sashiko (correctly?) points out amd_stb_debugfs_open_v2() has the same 
problem of leaving from msg_port.

To me it looks like having ->msg_port in dev is design error and it should 
be a parameter to the relevant functions instead or with some wrapping 
given by those functions that actually need to give the non-default port.

-- 
 i.


  reply	other threads:[~2026-07-21 10:24 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-17 16:20 [PATCH 0/4] Some fixes for amd-pmc handling of the STB Mario Limonciello
2026-07-17 16:20 ` [PATCH 1/4] platform/x86/amd/pmc: Fix LPS0 and debugfs leaks when STB init fails Mario Limonciello
2026-07-21 10:19   ` Ilpo Järvinen
2026-07-17 16:20 ` [PATCH 2/4] platform/x86/amd/pmc: Fix error handling in amd_stb_s2d_init() Mario Limonciello
2026-07-21 10:24   ` Ilpo Järvinen [this message]
2026-07-17 16:20 ` [PATCH 3/4] platform/x86/amd/pmc: Do not fail probe when STB init fails Mario Limonciello
2026-07-21 10:29   ` Ilpo Järvinen
2026-07-17 16:20 ` [PATCH 4/4] platform/x86/amd/pmc: Validate S2D physical address before ioremap Mario Limonciello

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=54655f38-edf4-e756-e24c-5f4cb041d63c@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=francisdb@gmail.com \
    --cc=hansg@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mario.limonciello@amd.com \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=stable@vger.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