public inbox for linux-pci@vger.kernel.org
 help / color / mirror / Atom feed
From: Damien Le Moal <dlemoal@kernel.org>
To: "Niklas Cassel" <cassel@kernel.org>,
	"Jingoo Han" <jingoohan1@gmail.com>,
	"Manivannan Sadhasivam" <mani@kernel.org>,
	"Lorenzo Pieralisi" <lpieralisi@kernel.org>,
	"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Frank Li" <Frank.Li@nxp.com>
Cc: Randolph Lin <randolph@andestech.com>,
	Samuel Holland <samuel.holland@sifive.com>,
	Charles Mirabile <cmirabil@redhat.com>,
	tim609@andestech.com,
	Krishna Chaitanya Chundru <krishna.chundru@oss.qualcomm.com>,
	"Maciej W. Rozycki" <macro@orcam.me.uk>,
	stable@vger.kernel.org, Shawn Lin <shawn.lin@rock-chips.com>,
	linux-pci@vger.kernel.org
Subject: Re: [PATCH v5 1/3] PCI: dwc: Fix msg_atu_index assignment
Date: Wed, 28 Jan 2026 15:36:57 +0900	[thread overview]
Message-ID: <cfacec0b-4855-44c7-b710-41fe28cc43b2@kernel.org> (raw)
In-Reply-To: <20260127151038.1484881-6-cassel@kernel.org>

On 1/28/26 12:10 AM, Niklas Cassel wrote:
> When dw_pcie_iatu_setup() configures outbound address translation for both
> type PCIE_ATU_TYPE_MEM and PCIE_ATU_TYPE_IO, the iATU index to use is
> incremented before calling dw_pcie_prog_outbound_atu().
> 
> However, for msg_atu_index the index is not incremented before use,
> causing the iATU index to be the same as the last configured iATU index,
> which means that it will incorrectly use the same iATU index that is
> already in use, breaking outbound address translation.
> 
> In total there are three problems with this code:
> -It assigns msg_atu_index the same index that was used for the last
>  outbound address translation window, rather than incrementing the index
>  before assignment.
> -The index should only be incremented (and msg_atu_index assigned) if the
>  use_atu_msg feature is actually requested/in use (pp->use_atu_msg is set).
> -If the use_atu_msg feature is requested/in use, and there are no outbound
>  iATUs available, the code should return an error, as otherwise when this
>  this feature is used, it will use an iATU index that is out of bounds.
> 
> Fixes: e1a4ec1a9520 ("PCI: dwc: Add generic MSG TLP support for sending PME_Turn_Off when system suspend")
> Cc: stable@vger.kernel.org
> Reviewed-by: Frank Li <Frank.Li@nxp.com>
> Reviewed-by: Shawn Lin <shawn.lin@rock-chips.com>
> Signed-off-by: Niklas Cassel <cassel@kernel.org>
> ---
>  drivers/pci/controller/dwc/pcie-designware-host.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
> index b3d6a474fd16..d7f57d77bdf5 100644
> --- a/drivers/pci/controller/dwc/pcie-designware-host.c
> +++ b/drivers/pci/controller/dwc/pcie-designware-host.c
> @@ -982,7 +982,14 @@ static int dw_pcie_iatu_setup(struct dw_pcie_rp *pp)
>  		dev_warn(pci->dev, "Ranges exceed outbound iATU size (%d)\n",
>  			 pci->num_ob_windows);
>  
> -	pp->msg_atu_index = i;
> +	if (pp->use_atu_msg) {
> +		if (pci->num_ob_windows > ++i) {

I would still prefer:

		i++;
		if (pci->num_ob_windows > i) {

As that is far easier to understand rather than having to remember the value
return vs increment order for ++ as a prefix or suffix.
But not going to fight it.

Reviewed-by: Damien Le Moal <dlemoal@kernel.org>

> +			pp->msg_atu_index = i;
> +		} else {
> +			dev_err(pci->dev, "Cannot add outbound window for MSG TLP\n");
> +			return -ENOMEM;
> +		}
> +	}
>  
>  	i = 0;
>  	resource_list_for_each_entry(entry, &pp->bridge->dma_ranges) {


-- 
Damien Le Moal
Western Digital Research

  parent reply	other threads:[~2026-01-28  6:41 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-27 15:10 [PATCH v5 0/3] PCI: dwc: Clean up iATU index mess Niklas Cassel
2026-01-27 15:10 ` [PATCH v5 1/3] PCI: dwc: Fix msg_atu_index assignment Niklas Cassel
2026-01-28  6:07   ` Hans Zhang
2026-01-28  6:36   ` Damien Le Moal [this message]
2026-02-04 16:04   ` Maciej W. Rozycki
2026-01-27 15:10 ` [PATCH v5 2/3] PCI: dwc: Clean up iATU index usage in dw_pcie_iatu_setup() Niklas Cassel
2026-01-27 18:14   ` Frank Li
2026-01-28  6:10   ` Hans Zhang
2026-01-28  6:37   ` Damien Le Moal
2026-02-04 16:05   ` Maciej W. Rozycki
2026-01-27 15:10 ` [PATCH v5 3/3] PCI: dwc: Fix missing iATU setup when ECAM is enabled Niklas Cassel
2026-01-27 18:16   ` Frank Li
2026-01-28  6:11   ` Hans Zhang
2026-01-28  6:40   ` Damien Le Moal
2026-02-04 16:05   ` Maciej W. Rozycki
2026-01-28  8:02 ` [PATCH v5 0/3] PCI: dwc: Clean up iATU index mess Manivannan Sadhasivam
2026-02-02 12:47   ` Niklas Cassel
2026-02-04 16:13     ` Maciej W. Rozycki
2026-02-05  8:04       ` Niklas Cassel
2026-02-05 12:56 ` Manivannan Sadhasivam
2026-02-05 13:23   ` Niklas Cassel

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=cfacec0b-4855-44c7-b710-41fe28cc43b2@kernel.org \
    --to=dlemoal@kernel.org \
    --cc=Frank.Li@nxp.com \
    --cc=bhelgaas@google.com \
    --cc=cassel@kernel.org \
    --cc=cmirabil@redhat.com \
    --cc=jingoohan1@gmail.com \
    --cc=krishna.chundru@oss.qualcomm.com \
    --cc=kwilczynski@kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=macro@orcam.me.uk \
    --cc=mani@kernel.org \
    --cc=randolph@andestech.com \
    --cc=robh@kernel.org \
    --cc=samuel.holland@sifive.com \
    --cc=shawn.lin@rock-chips.com \
    --cc=stable@vger.kernel.org \
    --cc=tim609@andestech.com \
    /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