* [PATCH] powerpc/powernv/pci: Return failure for some uses of dma_set_mask()
@ 2017-07-26 5:26 Alistair Popple
2017-07-28 0:54 ` Russell Currey
2017-07-31 6:31 ` Michael Ellerman
0 siblings, 2 replies; 3+ messages in thread
From: Alistair Popple @ 2017-07-26 5:26 UTC (permalink / raw)
To: ruscur, benh, linuxppc-dev; +Cc: mpe, Alistair Popple
Commit 8e3f1b1d8255 ("powerpc/powernv/pci: Enable 64-bit devices to access
>4GB DMA space") introduced the ability for PCI device drivers to request a
DMA mask between 64 and 32 bits and actually get a mask greater than
32-bits. However currently if certain machine configuration dependent
conditions are not meet the code silently falls back to a 32-bit mask.
This makes it hard for device drivers to detect which mask they actually
got. Instead we should return an error when the request could not be
fulfilled which allows drivers to either fallback or implement other
workarounds as documented in DMA-API-HOWTO.txt.
Signed-off-by: Alistair Popple <alistair@popple.id.au>
---
Ideally we should do the same thing for 64-bit mode as well however there
are a lot more drivers requesting a dma mask of 64-bits so it's a much
larger task to audit them all to see if they behave correctly when
dma_set_mask() fails. Such an audit may be required as previously these
calls would not have failed on PPC64 (although may have on other
architectures).
A quick bit of grepping didn't turn up many drivers requesting 33-63 bit
dma masks. Most of the ones that do are specific to other HW, although
there were a couple of more generic drivers requesting eg. 48 bits. However
those tested the return values of dma_set_mask() and took appropriate
action (falling back to 32 bits) in the case of failure.
- Alistair
arch/powerpc/platforms/powernv/pci-ioda.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c
index 4376135..b900eb1 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -1852,6 +1852,14 @@ static int pnv_pci_ioda_dma_set_mask(struct pci_dev *pdev, u64 dma_mask)
/* 4GB offset bypasses 32-bit space */
set_dma_offset(&pdev->dev, (1ULL << 32));
set_dma_ops(&pdev->dev, &dma_direct_ops);
+ } else if (dma_mask >> 32 && dma_mask != DMA_BIT_MASK(64)) {
+ /*
+ * Fail the request if a DMA mask between 32 and 64 bits
+ * was requested but couldn't be fulfilled. Ideally we
+ * would do this for 64-bits but historically we have
+ * always fallen back to 32-bits.
+ */
+ return -ENOMEM;
} else {
dev_info(&pdev->dev, "Using 32-bit DMA via iommu\n");
set_dma_ops(&pdev->dev, &dma_iommu_ops);
--
2.1.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] powerpc/powernv/pci: Return failure for some uses of dma_set_mask()
2017-07-26 5:26 [PATCH] powerpc/powernv/pci: Return failure for some uses of dma_set_mask() Alistair Popple
@ 2017-07-28 0:54 ` Russell Currey
2017-07-31 6:31 ` Michael Ellerman
1 sibling, 0 replies; 3+ messages in thread
From: Russell Currey @ 2017-07-28 0:54 UTC (permalink / raw)
To: Alistair Popple, benh, linuxppc-dev
On Wed, 2017-07-26 at 15:26 +1000, Alistair Popple wrote:
> Commit 8e3f1b1d8255 ("powerpc/powernv/pci: Enable 64-bit devices to access
> > 4GB DMA space") introduced the ability for PCI device drivers to request a
>
> DMA mask between 64 and 32 bits and actually get a mask greater than
> 32-bits. However currently if certain machine configuration dependent
> conditions are not meet the code silently falls back to a 32-bit mask.
>
> This makes it hard for device drivers to detect which mask they actually
> got. Instead we should return an error when the request could not be
> fulfilled which allows drivers to either fallback or implement other
> workarounds as documented in DMA-API-HOWTO.txt.
>
> Signed-off-by: Alistair Popple <alistair@popple.id.au>
Acked-by: Russell Currey <ruscur@russell.cc>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: powerpc/powernv/pci: Return failure for some uses of dma_set_mask()
2017-07-26 5:26 [PATCH] powerpc/powernv/pci: Return failure for some uses of dma_set_mask() Alistair Popple
2017-07-28 0:54 ` Russell Currey
@ 2017-07-31 6:31 ` Michael Ellerman
1 sibling, 0 replies; 3+ messages in thread
From: Michael Ellerman @ 2017-07-31 6:31 UTC (permalink / raw)
To: Alistair Popple, ruscur, benh, linuxppc-dev; +Cc: Alistair Popple
On Wed, 2017-07-26 at 05:26:40 UTC, Alistair Popple wrote:
> Commit 8e3f1b1d8255 ("powerpc/powernv/pci: Enable 64-bit devices to access
> >4GB DMA space") introduced the ability for PCI device drivers to request a
> DMA mask between 64 and 32 bits and actually get a mask greater than
> 32-bits. However currently if certain machine configuration dependent
> conditions are not meet the code silently falls back to a 32-bit mask.
>
> This makes it hard for device drivers to detect which mask they actually
> got. Instead we should return an error when the request could not be
> fulfilled which allows drivers to either fallback or implement other
> workarounds as documented in DMA-API-HOWTO.txt.
>
> Signed-off-by: Alistair Popple <alistair@popple.id.au>
> Acked-by: Russell Currey <ruscur@russell.cc>
Applied to powerpc fixes, thanks.
https://git.kernel.org/powerpc/c/253fd51e2f533552ae35a0c661705d
cheers
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-07-31 6:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-26 5:26 [PATCH] powerpc/powernv/pci: Return failure for some uses of dma_set_mask() Alistair Popple
2017-07-28 0:54 ` Russell Currey
2017-07-31 6:31 ` Michael Ellerman
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).