Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Mario Limonciello <mario.limonciello@amd.com>
To: Lukas Wunner <lukas@wunner.de>
Cc: "Bjorn Helgaas" <bhelgaas@google.com>,
	"Rafael J . Wysocki" <rjw@rjwysocki.net>,
	"Mika Westerberg" <mika.westerberg@linux.intel.com>,
	"Hans de Goede" <hdegoede@redhat.com>,
	iain@orangesquash.org.uk,
	"Shyam Sundar S K" <Shyam-sundar.S-k@amd.com>,
	"open list:PCI SUBSYSTEM" <linux-pci@vger.kernel.org>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	stable@vger.kernel.org
Subject: Re: [PATCH v21] PCI: Avoid D3 at suspend for AMD PCIe root ports w/ USB4 controllers
Date: Tue, 3 Oct 2023 15:16:47 -0500	[thread overview]
Message-ID: <33524298-88fe-461e-afdd-85f0763beec9@amd.com> (raw)
In-Reply-To: <20231003200034.GB16417@wunner.de>

On 10/3/2023 15:00, Lukas Wunner wrote:
> On Mon, Oct 02, 2023 at 01:09:06PM -0500, Mario Limonciello wrote:
>> Iain reports that USB devices can't be used to wake a Lenovo Z13 from
>> suspend.  This occurs because on some AMD platforms, even though the Root
>> Ports advertise PME_Support for D3hot and D3cold, they don't handle PME
>> messages and generate wakeup interrupts from those states when amd-pmc has
>> put the platform in a hardware sleep state.
>>
>> Iain reported this on an AMD Rembrandt platform, but it also affects
>> Phoenix SoCs.  On Iain's system, a USB4 router below the affected Root Port
>> generates the PME. To avoid this issue, disable D3 for the root port
>> associated with USB4 controllers at suspend time.
> [...]
>> +static void quirk_disable_rp_d3cold_suspend(struct pci_dev *dev)
>> +{
>> +	struct pci_dev *rp;
>> +
>> +	/*
>> +	 * PM_SUSPEND_ON means we're doing runtime suspend, which means
>> +	 * amd-pmc will not be involved so PMEs during D3 work as advertised.
>> +	 *
>> +	 * The PMEs *do* work if amd-pmc doesn't put the SoC in the hardware
>> +	 * sleep state, but we assume amd-pmc is always present.
>> +	 */
>> +	if (pm_suspend_target_state == PM_SUSPEND_ON)
>> +		return;
>> +
>> +	rp = pcie_find_root_port(dev);
>> +	pci_d3cold_disable(rp);
>> +	dev_info_once(&rp->dev, "quirk: disabling D3cold for suspend\n");
>> +}
> 
> I think you mentioned in an earlier version of the patch that the
> USB controller could in theory be built into a Thunderbolt-attached
> device and that you wouldn't want to apply the quirk in that case.

It's not necessary with this approach of detecting the PCI IDs used for 
USB4 controllers in Rembrandt and Phoenix.  Those would not be used in 
any hypothetical discrete device.

> 
> Yet this patch doesn't seem to check for that possibility.
> 
> I guess in the affected systems, the USB controller is directly
> below the Root Port.  

Yes

> The pcie_find_root_port() function you're
> using here will walk up the hierarchy until it finds the Root Port,
> i.e. it's specifically for the case where there are switches between
> the USB controller and Root Port (which I think you want to exclude).
> I would have expected that you just call pci_upstream_bridge(dev) once
> and check whether the returned device is a PCI_EXP_TYPE_ROOT_PORT.
> 

Is there an advantage to using pci_upstream_bridge() given it's just one 
step up with pcie_find_root_port()?

> I'm also wondering why you're not invoking pci_d3cold_disable() with
> the USB controller's device (instead of the Root Port).  Setting
> no_d3cold on the USB controller should force all upstream bridges
> into D0.
> 
> Perhaps the reason you're not doing this is because the xhci_hcd driver
> might have called pci_d3cold_disable() as part of a quirk and the
> unconditional pci_d3cold_enable() on resume might clobber that?

That's exactly what I was worried about - what if other callers end up 
using pci_d3cold_disable/pci_d3cold_enable for some reason. We're all 
fighting for the same policy bits.

This being said, I am tending to agree with Bjorn, it's better to just 
clear the PME bits.


  reply	other threads:[~2023-10-03 20:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-02 18:09 [PATCH v21] PCI: Avoid D3 at suspend for AMD PCIe root ports w/ USB4 controllers Mario Limonciello
2023-10-03  9:41 ` Mika Westerberg
2023-10-03 17:24 ` Bjorn Helgaas
2023-10-03 18:06   ` Mario Limonciello
2023-10-03 18:31     ` Bjorn Helgaas
2023-10-03 18:37       ` Mario Limonciello
2023-10-03 19:16         ` Bjorn Helgaas
2023-10-03 19:24           ` Mario Limonciello
2023-10-03 19:59             ` Bjorn Helgaas
2023-10-03 20:02               ` Mario Limonciello
2023-10-03 20:00 ` Lukas Wunner
2023-10-03 20:16   ` Mario Limonciello [this message]
2023-10-03 20:29     ` Lukas Wunner

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=33524298-88fe-461e-afdd-85f0763beec9@amd.com \
    --to=mario.limonciello@amd.com \
    --cc=Shyam-sundar.S-k@amd.com \
    --cc=bhelgaas@google.com \
    --cc=hdegoede@redhat.com \
    --cc=iain@orangesquash.org.uk \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=mika.westerberg@linux.intel.com \
    --cc=rjw@rjwysocki.net \
    --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