linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Lobakin <alexandr.lobakin@intel.com>
To: 이왕석 <wangseok.lee@samsung.com>
Cc: "Alexander Lobakin" <alexandr.lobakin@intel.com>,
	"jingoohan1@gmail.com" <jingoohan1@gmail.com>,
	"gustavo.pimentel@synopsys.com" <gustavo.pimentel@synopsys.com>,
	"lorenzo.pieralisi@arm.com" <lorenzo.pieralisi@arm.com>,
	"robh@kernel.org" <robh@kernel.org>,
	"kw@linux.com" <kw@linux.com>,
	"bhelgaas@google.com" <bhelgaas@google.com>,
	"linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>,
	"jesper.nilsson@axis.com" <jesper.nilsson@axis.com>,
	"vkoul@kernel.org" <vkoul@kernel.org>,
	"kernel@axis.com" <kernel@axis.com>, 전문기 <moonki.jun@samsung.com>
Subject: Re: [PATCH] PCI: dwc: Modify the check about MSI DMA mask 32-bit
Date: Mon, 28 Mar 2022 16:32:28 +0200	[thread overview]
Message-ID: <20220328143228.1902883-1-alexandr.lobakin@intel.com> (raw)
In-Reply-To: <20220328023009epcms2p309a5dfc2ff29d0a9945f65799963193c@epcms2p3>

From: 이왕석 <wangseok.lee@samsung.com>
Date: Mon, 28 Mar 2022 11:30:09 +0900

> If dma_mask is more than 32 bits this will trigger an error occurs when
> dma_map_single_attrs() is performed.
> 
> dma_map_single_attrs() -> dma_map_page_attrs()->
> error return in dma_direct_map_page().
> 
> On ARTPEC-8, this fails with:
> artpec8-pcie 17200000.pcie: DMA addr 0x0000000106b052c8+2 overflow
> (mask ffffffff, bus limit 27fffffff)

Isn't it a bug in the platform DMA code? dma_set_mask(32)
explicitly says that the system *must not* give DMA addresses wider
than 32 bits. If the system can't satisfy this requirement, then it
should return failure on dma_set_mask(32) -- this way you will only
get the corresponding warning, but there'll be no overflows (as the
mask will not be changed).
The idea of this call is to try to avoid getting 33+ bit mappings
so that PCI controllers which support only 32-bit masks could still
work correctly on the 64-bit systems. If the call fails, then this
message gets printed that you've been warned and it's your
responsibility to make sure that the controller won't get truncated
addresses. Having the call succeeded and then 33+ bit DMA addresses
is wrong.

Please correct me if I'm wrong.

> 
> There is no sequence that re-sets dev->dma_mask to more than 32 bits
> before call dma_map_single_attrs().
> The dev->dma_mask is first set just prior to the dw_pcie_host_init() call.
> Therefore, the check logic was modified to be performed only when
> the dev-dma_mask is not set larger than 32 bits.
> 
> Always setting dma_mask to 32 bits is not always correct,
> for example the ARTPEC-8 is an arm64 platform, and can access
> more than 32 bits
> 
> Signed-off-by: Wangseok Lee <wangseok.lee@samsung.com>
> ---
>  drivers/pci/controller/dwc/pcie-designware-host.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
> index 2fa86f3..7e25958 100644
> --- a/drivers/pci/controller/dwc/pcie-designware-host.c
> +++ b/drivers/pci/controller/dwc/pcie-designware-host.c
> @@ -388,9 +388,11 @@ int dw_pcie_host_init(struct pcie_port *pp)
>  							    dw_chained_msi_isr,
>  							    pp);
>  
> -			ret = dma_set_mask(pci->dev, DMA_BIT_MASK(32));
> -			if (ret)
> -				dev_warn(pci->dev, "Failed to set DMA mask to 32-bit. Devices with only 32-bit MSI support may not work properly\n");
> +			if (!(*dev->dma_mask &  ~(GENMASK(31, 0)))) {
> +				ret = dma_set_mask(pci->dev, DMA_BIT_MASK(32));
> +					if (ret)
> +						dev_warn(pci->dev, "Failed to set DMA mask to 32-bit. Devices with only 32-bit MSI support may not work properly\n");
> +			}
>  
>  			pp->msi_data = dma_map_single_attrs(pci->dev, &pp->msi_msg,
>  						      sizeof(pp->msi_msg),
> -- 
> 2.9.5

Thanks,
Al

  reply	other threads:[~2022-03-28 14:34 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20220328023009epcms2p309a5dfc2ff29d0a9945f65799963193c@epcms2p3>
2022-03-28  2:30 ` [PATCH] PCI: dwc: Modify the check about MSI DMA mask 32-bit 이왕석
2022-03-28 14:32   ` Alexander Lobakin [this message]
     [not found]   ` <CGME20220328143454epcas2p27a340d09e9f4e74af1eaa44559e372a5@epcms2p8>
2022-03-30  3:52     ` 이왕석
2022-03-30  9:35       ` Alexander Lobakin
2022-03-30 15:45         ` Christoph Hellwig
     [not found]         ` <CGME20220328143454epcas2p27a340d09e9f4e74af1eaa44559e372a5@epcms2p4>
2022-04-08  2:34           ` Wangseok Lee
2022-04-08  5:06             ` Christoph Hellwig
     [not found]         ` <CGME20220328143454epcas2p27a340d09e9f4e74af1eaa44559e372a5@epcms2p7>
2022-03-31  5:34           ` 이왕석
2022-04-08  5:32           ` Wangseok Lee
2022-04-08  5:39             ` Christoph Hellwig
2022-04-08 15:47             ` Lorenzo Pieralisi
     [not found]             ` <CGME20220328143454epcas2p27a340d09e9f4e74af1eaa44559e372a5@epcms2p5>
2022-04-11  6:59               ` Wangseok Lee
2022-04-11  7:10                 ` Christoph Hellwig
     [not found]                 ` <CGME20220328143454epcas2p27a340d09e9f4e74af1eaa44559e372a5@epcms2p1>
2022-04-11  9:47                   ` Wangseok Lee
2022-04-11 12:54                     ` Christoph Hellwig
2022-04-13 11:54                       ` Robin Murphy
2022-04-18  3:12                   ` Wangseok Lee

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=20220328143228.1902883-1-alexandr.lobakin@intel.com \
    --to=alexandr.lobakin@intel.com \
    --cc=bhelgaas@google.com \
    --cc=gustavo.pimentel@synopsys.com \
    --cc=jesper.nilsson@axis.com \
    --cc=jingoohan1@gmail.com \
    --cc=kernel@axis.com \
    --cc=kw@linux.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=moonki.jun@samsung.com \
    --cc=robh@kernel.org \
    --cc=vkoul@kernel.org \
    --cc=wangseok.lee@samsung.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;
as well as URLs for NNTP newsgroup(s).