make dma_addressing_limited work for memory encryption setups
Subsystems (2)
Hi all,
this little series fixes dma_addressing_limited to return true for systems that use bounce buffers due to memory encryption.
PATCH 1/2 dma-mapping: move dma_addressing_limited out of line
This function isn't used in the fast path, and moving it out of line will reduce include clutter with the next change.
--- include/linux/dma-mapping.h | 14 +------------- kernel/dma/mapping.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 13 deletions(-)
include/linux/dma-mapping.h +1 -13
@@ -687,19 +687,7 @@ static inline int dma_coerce_mask_and_coherent(struct device *dev, u64 mask)return dma_set_mask_and_coherent (dev, mask); } -/** -* dma_addressing_limited - return if the device is addressing limited -* @dev: device to check -* -* Return %true if the devices DMA mask is too small to address all memory in -* the system, else %false. Lack of addressing bits is the prime reason for -* bounce buffering, but might not be the only one. -*/ -static inline bool dma_addressing_limited (struct device *dev) -{ -return min_not_zero (dma_get_mask (dev), dev->bus_dma_limit) < -dma_get_required_mask (dev); -} +bool dma_addressing_limited (struct device *dev);#ifdef CONFIG_ARCH_HAS_SETUP_DMA_OPS void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
kernel/dma/mapping.c +15 -0
@@ -405,3 +405,18 @@ unsigned long dma_get_merge_boundary(struct device *dev)return ops->get_merge_boundary (dev); }EXPORT_SYMBOL_GPL (dma_get_merge_boundary); + +/** +* dma_addressing_limited - return if the device is addressing limited +* @dev: device to check +* +* Return %true if the devices DMA mask is too small to address all memory in +* the system, else %false. Lack of addressing bits is the prime reason for +* bounce buffering, but might not be the only one. +*/ +bool dma_addressing_limited (struct device *dev) +{ +return min_not_zero (dma_get_mask (dev), dev->bus_dma_limit) < +dma_get_required_mask (dev); +} +EXPORT_SYMBOL_GPL (dma_addressing_limited);
Signature · 1 line
2.20.1
Re: [PATCH 1/2] dma-mapping: move dma_addressing_limited out of line
Quoted 5 lines · Christoph Hellwig
+/**
+ *dma_addressing_limited- return if the device is addressing limited
+ * @dev: device to check
+ *
+ * Return %true if the devices DMA mask is too small to address all memory in
Could I trouble you to use a : after Return? That turns it into its own section rather than making it part of the generic description.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH 2/2 dma-mapping: force unencryped devices are always addressing limited
In reply to Christoph HellwigDevices that are forced to DMA through unencrypted bounce buffers need to be treated as if they are addressing limited.
--- kernel/dma/mapping.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/dma/mapping.c +2 -0
@@ -416,6 +416,8 @@ EXPORT_SYMBOL_GPL(dma_get_merge_boundary);*/ bool dma_addressing_limited (struct device *dev) { +if (force_dma_unencrypted (dev)) +return true;return min_not_zero (dma_get_mask (dev), dev->bus_dma_limit) <dma_get_required_mask (dev); }
Signature · 6 lines
2.20.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [PATCH 2/2] dma-mapping: force unencryped devices are always addressing limited
Hi,
Quoted 13 lines · Christoph Hellwig
Devices that are forced to DMA through unencrypted bounce buffers need to be treated as if they are addressing limited.
Signed-off-by Christoph Hellwig <[email protected]>--- kernel/dma/mapping.c | 2 ++ 1 file changed, 2 insertions(+)kernel/dma/mapping.c +0
-0
kernel/dma/mapping.c EXPORT_SYMBOL_GPL(dma_get_merge_boundary); · line 423
Quoted 8 lines
kernel/dma/mapping.c +2
-0@@ -416,6 +416,8 @@ EXPORT_SYMBOL_GPL(dma_get_merge_boundary);*/ bool dma_addressing_limited (struct device *dev) { +if (force_dma_unencrypted (dev)) +return true;return min_not_zero (dma_get_mask (dev), dev->bus_dma_limit) <dma_get_required_mask (dev); }
Any chance to have the case
(swiotlb_force == SWIOTLB_FORCE)
also included?
Otherwise for the series
Re: [PATCH 2/2] dma-mapping: force unencryped devices are always addressing limited
Quoted 10 lines · Thomas Hellstrom
kernel/dma/mapping.c EXPORT_SYMBOL_GPL(dma_get_merge_boundary); · line 423
Quoted 7 lines
bool
dma_addressing_limited(struct device *dev)
{kernel/dma/mapping.c +2
-0+if (force_dma_unencrypted (dev)) +return true;return min_not_zero (dma_get_mask (dev), dev->bus_dma_limit) <dma_get_required_mask (dev); }Any chance to have the case
Quoted 3 lines
(
swiotlb_force==SWIOTLB_FORCE)also included?
We have a hard time handling that in generic code. Do we have any good use case for SWIOTLB_FORCE not that we have force_dma_unencrypted? I'd love to be able to get rid of it..
Re: [PATCH 2/2] dma-mapping: force unencryped devices are always addressing limited
Quoted 10 lines · On 11/28/19 8:51 AM, [email protected] wrote:
Quoted 9 lines · Thomas Hellstrom
kernel/dma/mapping.c EXPORT_SYMBOL_GPL(dma_get_merge_boundary); · line 423
Quoted 7 lines
bool
dma_addressing_limited(struct device *dev)
{kernel/dma/mapping.c +2
-0+if (force_dma_unencrypted (dev)) +return true;return min_not_zero (dma_get_mask (dev), dev->bus_dma_limit) <dma_get_required_mask (dev); }Any chance to have the case
Quoted 7 lines
Quoted 3 lines
(
swiotlb_force==SWIOTLB_FORCE)also included?
We have a hard time handling that in generic code. Do we have any good use case for
SWIOTLB_FORCEnot that we haveforce_dma_unencrypted? I'd love to be able to get rid of it..
IIRC the justification for it is debugging. Drivers that don't do syncing correctly or have incorrect assumptions of initialization of DMA memory will not work properly when SWIOTLB is forced. We recently found a vmw_pvscsi device flaw that way...
/Thomas
Re: [PATCH 2/2] dma-mapping: force unencryped devices are always addressing limited
Quoted 8 lines · Thomas Hellstrom
Quoted 4 lines
We have a hard time handling that in generic code. Do we have any good use case for
SWIOTLB_FORCEnot that we haveforce_dma_unencrypted? I'd love to be able to get rid of it..IIRC the justification for it is debugging. Drivers that don't do syncing correctly or have incorrect assumptions of initialization of DMA memory will not work properly when SWIOTLB is forced. We recently found a
vmw_pvscsidevice flaw that way...
Ok. I guess debugging is reasonable. Although that means I need to repsin this quite a bit as I now need a callout to dma_direct. I'll respin it in the next days.