* [PATCH] virtio: Simplify DMA setting
@ 2022-01-08 7:08 Christophe JAILLET
2022-01-10 6:14 ` Jason Wang
0 siblings, 1 reply; 3+ messages in thread
From: Christophe JAILLET @ 2022-01-08 7:08 UTC (permalink / raw)
To: mst, jasowang
Cc: virtualization, linux-kernel, kernel-janitors, Christophe JAILLET
As stated in [1], dma_set_mask() with a 64-bit mask will never fail if
dev->dma_mask is non-NULL.
So, if it fails, the 32 bits case will also fail for the same reason.
Simplify code and remove some dead code accordingly.
While at it, include directly <linux/dma-mapping.h> instead on relying on
indirect inclusion.
[1]: https://lkml.org/lkml/2021/6/7/398
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
drivers/virtio/virtio_mmio.c | 4 +---
drivers/virtio/virtio_pci_legacy_dev.c | 7 +++----
drivers/virtio/virtio_pci_modern_dev.c | 6 ++----
3 files changed, 6 insertions(+), 11 deletions(-)
diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
index 56128b9c46eb..aa1efa854de1 100644
--- a/drivers/virtio/virtio_mmio.c
+++ b/drivers/virtio/virtio_mmio.c
@@ -617,9 +617,7 @@ static int virtio_mmio_probe(struct platform_device *pdev)
rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
}
if (rc)
- rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
- if (rc)
- dev_warn(&pdev->dev, "Failed to enable 64-bit or 32-bit DMA. Trying to continue, but this might not work.\n");
+ dev_warn(&pdev->dev, "Failed to enable DMA. Trying to continue, but this might not work.\n");
platform_set_drvdata(pdev, vm_dev);
diff --git a/drivers/virtio/virtio_pci_legacy_dev.c b/drivers/virtio/virtio_pci_legacy_dev.c
index 677d1f68bc9b..52b1c4dd43fe 100644
--- a/drivers/virtio/virtio_pci_legacy_dev.c
+++ b/drivers/virtio/virtio_pci_legacy_dev.c
@@ -2,6 +2,7 @@
#include "linux/virtio_pci.h"
#include <linux/virtio_pci_legacy.h>
+#include <linux/dma-mapping.h>
#include <linux/module.h>
#include <linux/pci.h>
@@ -26,9 +27,7 @@ int vp_legacy_probe(struct virtio_pci_legacy_device *ldev)
return -ENODEV;
rc = dma_set_mask(&pci_dev->dev, DMA_BIT_MASK(64));
- if (rc) {
- rc = dma_set_mask_and_coherent(&pci_dev->dev, DMA_BIT_MASK(32));
- } else {
+ if (!rc) {
/*
* The virtio ring base address is expressed as a 32-bit PFN,
* with a page size of 1 << VIRTIO_PCI_QUEUE_ADDR_SHIFT.
@@ -38,7 +37,7 @@ int vp_legacy_probe(struct virtio_pci_legacy_device *ldev)
}
if (rc)
- dev_warn(&pci_dev->dev, "Failed to enable 64-bit or 32-bit DMA. Trying to continue, but this might not work.\n");
+ dev_warn(&pci_dev->dev, "Failed to enable DMA. Trying to continue, but this might not work.\n");
rc = pci_request_region(pci_dev, 0, "virtio-pci-legacy");
if (rc)
diff --git a/drivers/virtio/virtio_pci_modern_dev.c b/drivers/virtio/virtio_pci_modern_dev.c
index e8b3ff2b9fbc..830dc269d68f 100644
--- a/drivers/virtio/virtio_pci_modern_dev.c
+++ b/drivers/virtio/virtio_pci_modern_dev.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include <linux/virtio_pci_modern.h>
+#include <linux/dma-mapping.h>
#include <linux/module.h>
#include <linux/pci.h>
@@ -256,10 +257,7 @@ int vp_modern_probe(struct virtio_pci_modern_device *mdev)
err = dma_set_mask_and_coherent(&pci_dev->dev, DMA_BIT_MASK(64));
if (err)
- err = dma_set_mask_and_coherent(&pci_dev->dev,
- DMA_BIT_MASK(32));
- if (err)
- dev_warn(&pci_dev->dev, "Failed to enable 64-bit or 32-bit DMA. Trying to continue, but this might not work.\n");
+ dev_warn(&pci_dev->dev, "Failed to enable DMA. Trying to continue, but this might not work.\n");
/* Device capability is only mandatory for devices that have
* device-specific configuration.
--
2.32.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] virtio: Simplify DMA setting
2022-01-08 7:08 [PATCH] virtio: Simplify DMA setting Christophe JAILLET
@ 2022-01-10 6:14 ` Jason Wang
2022-01-10 18:16 ` Christophe JAILLET
0 siblings, 1 reply; 3+ messages in thread
From: Jason Wang @ 2022-01-10 6:14 UTC (permalink / raw)
To: Christophe JAILLET, mst; +Cc: virtualization, linux-kernel, kernel-janitors
在 2022/1/8 下午3:08, Christophe JAILLET 写道:
> As stated in [1], dma_set_mask() with a 64-bit mask will never fail if
> dev->dma_mask is non-NULL.
> So, if it fails, the 32 bits case will also fail for the same reason.
I'd expect to be more verbose here. E.g I see dma_supported() who has a
brunch of checks need to be called if dma_mask is non-NULL.
Thanks
>
> Simplify code and remove some dead code accordingly.
>
>
> While at it, include directly <linux/dma-mapping.h> instead on relying on
> indirect inclusion.
>
> [1]: https://lkml.org/lkml/2021/6/7/398
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> drivers/virtio/virtio_mmio.c | 4 +---
> drivers/virtio/virtio_pci_legacy_dev.c | 7 +++----
> drivers/virtio/virtio_pci_modern_dev.c | 6 ++----
> 3 files changed, 6 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
> index 56128b9c46eb..aa1efa854de1 100644
> --- a/drivers/virtio/virtio_mmio.c
> +++ b/drivers/virtio/virtio_mmio.c
> @@ -617,9 +617,7 @@ static int virtio_mmio_probe(struct platform_device *pdev)
> rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
> }
> if (rc)
> - rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
> - if (rc)
> - dev_warn(&pdev->dev, "Failed to enable 64-bit or 32-bit DMA. Trying to continue, but this might not work.\n");
> + dev_warn(&pdev->dev, "Failed to enable DMA. Trying to continue, but this might not work.\n");
>
> platform_set_drvdata(pdev, vm_dev);
>
> diff --git a/drivers/virtio/virtio_pci_legacy_dev.c b/drivers/virtio/virtio_pci_legacy_dev.c
> index 677d1f68bc9b..52b1c4dd43fe 100644
> --- a/drivers/virtio/virtio_pci_legacy_dev.c
> +++ b/drivers/virtio/virtio_pci_legacy_dev.c
> @@ -2,6 +2,7 @@
>
> #include "linux/virtio_pci.h"
> #include <linux/virtio_pci_legacy.h>
> +#include <linux/dma-mapping.h>
> #include <linux/module.h>
> #include <linux/pci.h>
>
> @@ -26,9 +27,7 @@ int vp_legacy_probe(struct virtio_pci_legacy_device *ldev)
> return -ENODEV;
>
> rc = dma_set_mask(&pci_dev->dev, DMA_BIT_MASK(64));
> - if (rc) {
> - rc = dma_set_mask_and_coherent(&pci_dev->dev, DMA_BIT_MASK(32));
> - } else {
> + if (!rc) {
> /*
> * The virtio ring base address is expressed as a 32-bit PFN,
> * with a page size of 1 << VIRTIO_PCI_QUEUE_ADDR_SHIFT.
> @@ -38,7 +37,7 @@ int vp_legacy_probe(struct virtio_pci_legacy_device *ldev)
> }
>
> if (rc)
> - dev_warn(&pci_dev->dev, "Failed to enable 64-bit or 32-bit DMA. Trying to continue, but this might not work.\n");
> + dev_warn(&pci_dev->dev, "Failed to enable DMA. Trying to continue, but this might not work.\n");
>
> rc = pci_request_region(pci_dev, 0, "virtio-pci-legacy");
> if (rc)
> diff --git a/drivers/virtio/virtio_pci_modern_dev.c b/drivers/virtio/virtio_pci_modern_dev.c
> index e8b3ff2b9fbc..830dc269d68f 100644
> --- a/drivers/virtio/virtio_pci_modern_dev.c
> +++ b/drivers/virtio/virtio_pci_modern_dev.c
> @@ -1,6 +1,7 @@
> // SPDX-License-Identifier: GPL-2.0-or-later
>
> #include <linux/virtio_pci_modern.h>
> +#include <linux/dma-mapping.h>
> #include <linux/module.h>
> #include <linux/pci.h>
>
> @@ -256,10 +257,7 @@ int vp_modern_probe(struct virtio_pci_modern_device *mdev)
>
> err = dma_set_mask_and_coherent(&pci_dev->dev, DMA_BIT_MASK(64));
> if (err)
> - err = dma_set_mask_and_coherent(&pci_dev->dev,
> - DMA_BIT_MASK(32));
> - if (err)
> - dev_warn(&pci_dev->dev, "Failed to enable 64-bit or 32-bit DMA. Trying to continue, but this might not work.\n");
> + dev_warn(&pci_dev->dev, "Failed to enable DMA. Trying to continue, but this might not work.\n");
>
> /* Device capability is only mandatory for devices that have
> * device-specific configuration.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] virtio: Simplify DMA setting
2022-01-10 6:14 ` Jason Wang
@ 2022-01-10 18:16 ` Christophe JAILLET
0 siblings, 0 replies; 3+ messages in thread
From: Christophe JAILLET @ 2022-01-10 18:16 UTC (permalink / raw)
To: Jason Wang, mst
Cc: virtualization, linux-kernel, kernel-janitors, Christoph Hellwig
Le 10/01/2022 à 07:14, Jason Wang a écrit :
>
> 在 2022/1/8 下午3:08, Christophe JAILLET 写道:
>> As stated in [1], dma_set_mask() with a 64-bit mask will never fail if
>> dev->dma_mask is non-NULL.
>> So, if it fails, the 32 bits case will also fail for the same reason.
>
>
> I'd expect to be more verbose here. E.g I see dma_supported() who has a
> brunch of checks need to be called if dma_mask is non-NULL.
>
> Thanks
>
>
Hi,
If Christoph Hellwig's references ([1], [2]) are not enough, here is my
own analysis.
I put him in copy in case he has be better wording or explanation than me.
I've searched all dma_supported() function with grep
grep -r --include=*.[ch] \\.dma_supported * > dma_supported.txt
I've removed duplicates, then, I've audited audit all functions.
Short summary below.
Adding all this in the commit looks an overkill to me.
Maybe we can add a link to this mail if it looks good to you.
CJ
arch/arm/common/dmabounce.c: .dma_supported = dmabounce_dma_supported
==> Same as arm_dma_supported()
arch/arm/mm/dma-mapping.c: .dma_supported = arm_dma_supported
==> If a mask fails, smaller masks will fail as well.
arch/alpha/kernel/pci_iommu.c: .dma_supported = alpha_pci_supported
==> If a mask fails, smaller masks will fail as well.
arch/x86/kernel/amd_gart_64.c: .dma_supported = dma_direct_supported
==> Succeeds if >= 32 bits. If a mask fails, smaller masks will fail as
well.
arch/powerpc/kernel/dma-iommu.c: .dma_supported = dma_iommu_dma_supported
==> Tricky because of dma_iommu_bypass_supported(), but if a mask fails,
smaller masks will fail as well.
arch/powerpc/platforms/ps3/system-bus.c: .dma_supported = ps3_dma_supported
==> Succeeds if >= 32 bits
arch/powerpc/platforms/pseries/ibmebus.c: .dma_supported =
ibmebus_dma_supported
==> Succeeds if == 64 bits
arch/sparc/kernel/iommu.c: .dma_supported = dma_4u_supported
==> One corner case which accept only 31 bits
==> If a mask fails, smaller masks will fail as well
arch/sparc/kernel/pci_sun4v.c: .dma_supported = dma_4v_supported
==> Same as dma_4u_supported() above
arch/ia64/hp/common/sba_iommu.c: .dma_supported = sba_dma_supported
==> Succeeds if >= 32 bits
drivers/xen/swiotlb-xen.c: .dma_supported = xen_swiotlb_dma_supported
==> If a mask fails, smaller masks will fail as well.
drivers/parisc/ccio-dma.c: .dma_supported = ccio_dma_supported
==> Succeeds if >= 32 bits
drivers/parisc/sba_iommu.c: .dma_supported = sba_dma_supported
==> If a mask fails, smaller masks will fail as well.
kernel/dma/dummy.c: .dma_supported = dma_dummy_supported
==> Always fails, whatever the value of the mask
[1]: https://lore.kernel.org/linux-kernel/YL3vSPK5DXTNvgdx@infradead.org/
[2]: https://lore.kernel.org/kernel-janitors/YdK4IIFvi5O5eXHC@infradead.org/
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-01-10 18:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-08 7:08 [PATCH] virtio: Simplify DMA setting Christophe JAILLET
2022-01-10 6:14 ` Jason Wang
2022-01-10 18:16 ` Christophe JAILLET
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).