Resolve unwanted DMA backing with IOMMU
Subsystems (7)
cover Resolve unwanted DMA backing with IOMMU
Hello,
There is a trouble on ARM with DMA allocations made by device drivers, the trouble is that DMA allocations are getting implicitly backed with IOMMU mapping by the driver core if IOMMU presents in a system and IOMMU could handle device. This is an undesired behaviour for drivers that manage IOMMU by themselves, like NVIDIA Tegra GPU driver. On arm32 the implicit backing happens if CONFIG_ARM_DMA_USE_IOMMU=y (multiplatform kernel configuration), on arm64 it happens if IOMMU domain type for a device is equal to IOMMU_DOMAIN_DMA.
The proposed solution adds a new option to the base device driver structure that allows device drivers to explicitly convey to the drivers core that the implicit IOMMU backing for devices must not happen.
Dmitry Osipenko (6):
driver core: Add option for disabling of backing devices DMA with
IOMMU
of/device: Don't back devices DMA with IOMMU if that's undesired by
driver
drm/tegra: Avoid implicit DMA backing with IOMMU
gpu: host1x: Avoid implicit DMA backing with IOMMU drm/nouveau: tegra: Universally avoid implicit DMA backing with IOMMU Revert "drm/nouveau: tegra: Detach from ARM DMA/IOMMU mapping"
drivers/gpu/drm/nouveau/nouveau_platform.c | 1 + drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c | 13 ------------- drivers/gpu/drm/tegra/dc.c | 1 + drivers/gpu/drm/tegra/gr2d.c | 1 + drivers/gpu/drm/tegra/gr3d.c | 1 + drivers/gpu/drm/tegra/vic.c | 1 + drivers/gpu/host1x/dev.c | 1 + drivers/of/device.c | 7 +++++++ include/linux/device.h | 2 ++ 9 files changed, 15 insertions(+), 13 deletions(-)
Signature · 1 line
2.18.0
RFC PATCH 1/6 driver core: Add option for disabling of backing devices DMA with IOMMU
This allows device drivers to convey the drivers core that implicit IOMMU backing for devices DMA shouldn't happen. It is needed for drivers that manage IOMMU by themselves, like for example it is needed by the NVIDIA Tegra GPU driver.
--- include/linux/device.h | 2 ++ 1 file changed, 2 insertions(+)
include/linux/device.h +2 -0
@@ -244,6 +244,7 @@ enum probe_type {* @bus: The bus which the device of this driver belongs to. * @owner: The module owner. * @mod_name: Used for built-in modules. +* @no_implicit_iommu: Disables backing DMA allocations with IOMMU mapping. * @suppress_bind_attrs: Disables bind/unbind via sysfs. * @probe_type: Type of the probe (synchronous or asynchronous) to use. * @of_match_table: The open firmware table.
@@ -281,6 +282,7 @@ struct device_driver {struct module *owner;const char *mod_name;/* used for built-in modules */ +bool no_implicit_iommu;/* disables implicit IOMMU for DMA */ bool suppress_bind_attrs;/* disables bind/unbind via sysfs */ enum probe_type probe_type;
Signature · 1 line
2.18.0
RFC PATCH 2/6 of/device: Don't back devices DMA with IOMMU if that's undesired by driver
In reply to Dmitry OsipenkoRespect device driver requirement for device DMA not to be implicitly backed with IOMMU by skipping the backing setup for drivers that do not want that.
--- drivers/of/device.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/of/device.c +7 -0
@@ -163,6 +163,13 @@ int of_dma_configure(struct device *dev, struct device_node *np, bool force_dma)dev_dbg (dev,"device is%sbehind an iommu\n" , iommu ?" " :" not " ); +/* +* Respect device driver requirement for device DMA not to be +* implicitly backed with IOMMU. +*/ +if (iommu && dev->driver->no_implicit_iommu) + iommu =NULL ; +arch_setup_dma_ops (dev, dma_addr, size, iommu, coherent);return 0 ;
Signature · 6 lines
2.18.0 _______________________________________________ Nouveau mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/nouveau
RFC PATCH 3/6 drm/tegra: Avoid implicit DMA backing with IOMMU
In reply to Dmitry OsipenkoTegra DRM manages IOMMU by itself, backing DMA with IOMMU by the drivers core breaks the Tegra driver.
--- drivers/gpu/drm/tegra/dc.c | 1 + drivers/gpu/drm/tegra/gr2d.c | 1 + drivers/gpu/drm/tegra/gr3d.c | 1 + drivers/gpu/drm/tegra/vic.c | 1 + 4 files changed, 4 insertions(+)
drivers/gpu/drm/tegra/dc.c +1 -0
@@ -2675,6 +2675,7 @@ static const struct dev_pm_ops tegra_dc_pm_ops = {struct platform_driver tegra_dc_driver = { .driver = { .name ="tegra-dc" , + .no_implicit_iommu = true, .of_match_table = tegra_dc_of_match, .pm = &tegra_dc_pm_ops, },
drivers/gpu/drm/tegra/gr2d.c +1 -0
@@ -327,6 +327,7 @@ static int gr2d_remove(struct platform_device *pdev)struct platform_driver tegra_gr2d_driver = { .driver = { .name ="tegra-gr2d" , + .no_implicit_iommu = true, .of_match_table = gr2d_match, }, .probe = gr2d_probe,
drivers/gpu/drm/tegra/gr3d.c +1 -0
@@ -481,6 +481,7 @@ static int gr3d_remove(struct platform_device *pdev)struct platform_driver tegra_gr3d_driver = { .driver = { .name ="tegra-gr3d" , + .no_implicit_iommu = true, .of_match_table = tegra_gr3d_match, }, .probe = gr3d_probe,
drivers/gpu/drm/tegra/vic.c +1 -0
@@ -402,6 +402,7 @@ static const struct dev_pm_ops vic_pm_ops = {struct platform_driver tegra_vic_driver = { .driver = { .name ="tegra-vic" , + .no_implicit_iommu = true, .of_match_table = vic_match, .pm = &vic_pm_ops },
Signature · 6 lines
2.18.0 _______________________________________________ Nouveau mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/nouveau
RFC PATCH 4/6 gpu: host1x: Avoid implicit DMA backing with IOMMU
In reply to Dmitry OsipenkoHost1x driver manages IOMMU by itself, backing DMA with IOMMU by the drivers core breaks the Host1x driver.
--- drivers/gpu/host1x/dev.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/host1x/dev.c +1 -0
@@ -361,6 +361,7 @@ static int host1x_remove(struct platform_device *pdev)static struct platform_driver tegra_host1x_driver = { .driver = { .name ="tegra-host1x" , + .no_implicit_iommu = true, .of_match_table = host1x_of_match, }, .probe = host1x_probe,
Signature · 6 lines
2.18.0 _______________________________________________ Nouveau mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/nouveau
RFC PATCH 5/6 drm/nouveau: tegra: Universally avoid implicit DMA backing with IOMMU
In reply to Dmitry OsipenkoImplicit backing DMA with IOMMU breaks Nouveau on Tegra, the current approach with detaching device from IOMMU that was added in commit b59fb482b522 ("drm/nouveau: tegra: Detach from ARM DMA/IOMMU mapping") works only for arm32 which has the CONFIG_ARM_DMA_USE_IOMMU, but not for arm64 which doesn't have that config option. Drivers core now allows to avoid the implicit backing, that is a universal solution unlike the current variant with the detaching.
--- drivers/gpu/drm/nouveau/nouveau_platform.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/nouveau/nouveau_platform.c +1 -0
@@ -90,6 +90,7 @@ MODULE_DEVICE_TABLE(of, nouveau_platform_match);struct platform_driver nouveau_platform_driver = { .driver = { .name ="nouveau" , + .no_implicit_iommu = true, .of_match_table =of_match_ptr (nouveau_platform_match), }, .probe = nouveau_platform_probe,
Signature · 1 line
2.18.0
RFC PATCH 6/6 Revert "drm/nouveau: tegra: Detach from ARM DMA/IOMMU mapping"
In reply to Dmitry OsipenkoImproper DMA backing with IOMMU has been resolved now using the new drivers core option that allows to avoid the implicit backing, hence detaching isn't necessary anymore.
This reverts commit b59fb482b52269977ee5de205308e5b236a03917.
--- drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c | 13 ------------- 1 file changed, 13 deletions(-)
drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c +0 -13
@@ -23,10 +23,6 @@#ifdef CONFIG_NOUVEAU_PLATFORM_DRIVER #include "priv.h" -#if IS_ENABLED (CONFIG_ARM_DMA_USE_IOMMU ) -#include <asm/dma-iommu.h> -#endif -static int nvkm_device_tegra_power_up (struct nvkm_device_tegra *tdev) {
@@ -109,15 +105,6 @@ nvkm_device_tegra_probe_iommu(struct nvkm_device_tegra *tdev)unsigned long pgsize_bitmap;int ret; -#if IS_ENABLED (CONFIG_ARM_DMA_USE_IOMMU ) -if (dev->archdata.mapping) { -struct dma_iommu_mapping *mapping =to_dma_iommu_mapping (dev); - -arm_iommu_detach_device (dev); -arm_iommu_release_mapping (mapping); - } -#endif -if (!tdev->func->iommu_bit)return ;
Signature · 6 lines
2.18.0 _______________________________________________ Nouveau mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/nouveau
Quoted 3 lines · Dmitry Osipenko
The proposed solution adds a new option to the base device driver structure that allows device drivers to explicitly convey to the drivers core that the implicit IOMMU backing for devices must not happen.
Why is IOMMU mapping a problem for the Tegra GPU driver?
If we add something like this then it should not be the choice of the device driver, but of the user and/or the firmware.
Joerg
Quoted 9 lines · Joerg Roedel
Quoted 3 lines · Dmitry Osipenko
The proposed solution adds a new option to the base device driver structure that allows device drivers to explicitly convey to the drivers core that the implicit IOMMU backing for devices must not happen.
Why is IOMMU mapping a problem for the Tegra GPU driver?
If we add something like this then it should not be the choice of the device driver, but of the user and/or the firmware.
Agreed, and it would still need somebody to configure an identity domain so that transactions aren't aborted immediately. We currently allow the identity domain to be used by default via a command-line option, so I guess we'd need a way for firmware to request that on a per-device basis.
Will
Quoted 8 lines · On Friday, 27 July 2018 12:03:28 MSK Will Deacon wrote:
Quoted 7 lines · Joerg Roedel
Quoted 3 lines · Dmitry Osipenko
The proposed solution adds a new option to the base device driver structure that allows device drivers to explicitly convey to the drivers core that the implicit IOMMU backing for devices must not happen.
Why is IOMMU mapping a problem for the Tegra GPU driver?
Quoted 7 lines
Quoted 2 lines
If we add something like this then it should not be the choice of the device driver, but of the user and/or the firmware.
Agreed, and it would still need somebody to configure an identity domain so that transactions aren't aborted immediately. We currently allow the identity domain to be used by default via a command-line option, so I guess we'd need a way for firmware to request that on a per-device basis.
The IOMMU mapping itself is not a problem, the problem is the management of the IOMMU. For Tegra we don't want anything to intrude into the IOMMU activities because:
1) GPU HW require additional configuration for the IOMMU usage and dumb mapping of the allocations simply doesn't work.
2) Older Tegra generations have a limited resource and capabilities in regards to IOMMU usage, allocating IOMMU domain per-device is just impossible for example.
3) HW performs context switches and so particular allocations have to be assigned to a particular contexts IOMMU domain.
Some of the above is due to a SW driver model (and its work-in-progress status), other is due to a HW model. So essentially we need a way for a driver to tell the core not to mess with IOMMU stuff of drivers device behind the drivers back.
I'm not sure what you guys are meaning by the "firmware", could you elaborate please? Do you mean the Open Firmware and hence the devicetree or what?
_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau
Quoted 2 lines · Dmitry Osipenko
I'm not sure what you guys are meaning by the "firmware", could you elaborate please? Do you mean the Open Firmware and hence the devicetree or what?
Yes, I think the best way to request this is using a device-tree property. Letting the device driver request it is definitly a bad idea.
Joerg
_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau
Quoted 7 lines · Joerg Roedel
Quoted 2 lines · Dmitry Osipenko
I'm not sure what you guys are meaning by the "firmware", could you elaborate please? Do you mean the Open Firmware and hence the devicetree or what?
Yes, I think the best way to request this is using a device-tree property. Letting the device driver request it is definitly a bad idea.
I don't follow why we need a property rather than being implied by the device's (the GPU) compatible string.
Rob
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 2 lines · Rob Herring
I don't follow why we need a property rather than being implied by the device's (the GPU) compatible string.
There might be devices where either setup works, with or without IOMMU translation, and the firmware can set the property depending on whether the user wants more performance or more security.
If we have a whitelist in the kernel this gets more complicated, we probably need additional kernel-parameters to overwrite those whitelist entries. Having a property in the device-tree seems to be a better way here, imho.
Joerg
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 4 lines · On Friday, 27 July 2018 21:31:34 MSK Joerg Roedel wrote:
Quoted 2 lines · Rob Herring
I don't follow why we need a property rather than being implied by the device's (the GPU) compatible string.
Quoted 8 lines
There might be devices where either setup works, with or without IOMMU translation, and the firmware can set the property depending on whether the user wants more performance or more security.
If we have a whitelist in the kernel this gets more complicated, we probably need additional kernel-parameters to overwrite those whitelist entries. Having a property in the device-tree seems to be a better way here, imho.
IIUC, device-tree should be considered to be "written in stone" for a consumer device and hence firmware property isn't something that could be easily changed. The kernel-parameter will be much more universal. Anyway the global whitelisting should be a different topic for discussion, right now we need a kind of private whitelisting that is internal to kernel.
_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau
Quoted 17 lines · Dmitry Osipenko
Quoted 8 lines · On Friday, 27 July 2018 12:03:28 MSK Will Deacon wrote:
Quoted 7 lines · Joerg Roedel
Quoted 3 lines · Dmitry Osipenko
The proposed solution adds a new option to the base device driver structure that allows device drivers to explicitly convey to the drivers core that the implicit IOMMU backing for devices must not happen.
Why is IOMMU mapping a problem for the Tegra GPU driver?
Quoted 7 lines
Quoted 2 lines
If we add something like this then it should not be the choice of the device driver, but of the user and/or the firmware.
Agreed, and it would still need somebody to configure an identity domain so that transactions aren't aborted immediately. We currently allow the identity domain to be used by default via a command-line option, so I guess we'd need a way for firmware to request that on a per-device basis.
Quoted 6 lines
The IOMMU mapping itself is not a problem, the problem is the management of the IOMMU. For Tegra we don't want anything to intrude into the IOMMU activities because:
1) GPU HW require additional configuration for the IOMMU usage and dumb mapping of the allocations simply doesn't work.
Generally, that's already handled by the DRM drivers allocating their own unmanaged domains. The only problem we really need to solve in that regard is that currently the device DMA ops don't get updated when moving away from the managed domain. That's been OK for the VFIO case where the device is bound to a different driver which we know won't make any explicit DMA API calls, but for the more general case of IOMMU-aware drivers we could certainly do with a bit of cooperation between the IOMMU API, DMA API, and arch code to update the DMA ops dynamically to cope with intermediate subsystems making DMA API calls on behalf of devices they don't know the intimate details of.
Quoted 6 lines
2) Older Tegra generations have a limited resource and capabilities in regards to IOMMU usage, allocating IOMMU domain per-device is just impossible for example.
3) HW performs context switches and so particular allocations have to be assigned to a particular contexts IOMMU domain.
I understand Qualcomm SoCs have a similar thing too, and AFAICS that case just doesn't fit into the current API model at all. We need the IOMMU driver to somehow know about the specific details of which devices have magic associations with specific contexts, and we almost certainly need a more expressive interface than iommu_domain_alloc() to have any hope of reliable results.
Robin.
Quoted 10 lines
Some of the above is due to a SW driver model (and its work-in-progress status), other is due to a HW model. So essentially we need a way for a driver to tell the core not to mess with IOMMU stuff of drivers device behind the drivers back.
I'm not sure what you guys are meaning by the "firmware", could you elaborate please? Do you mean the Open Firmware and hence the devicetree or what?
Quoted 5 lines
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 44 lines · Robin Murphy
Quoted 17 lines · Dmitry Osipenko
Quoted 8 lines · On Friday, 27 July 2018 12:03:28 MSK Will Deacon wrote:
Quoted 7 lines · Joerg Roedel
Quoted 3 lines · Dmitry Osipenko
The proposed solution adds a new option to the base device driver structure that allows device drivers to explicitly convey to the drivers core that the implicit IOMMU backing for devices must not happen.
Why is IOMMU mapping a problem for the Tegra GPU driver?
Quoted 7 lines
Quoted 2 lines
If we add something like this then it should not be the choice of the device driver, but of the user and/or the firmware.
Agreed, and it would still need somebody to configure an identity domain so that transactions aren't aborted immediately. We currently allow the identity domain to be used by default via a command-line option, so I guess we'd need a way for firmware to request that on a per-device basis.
Quoted 6 lines
The IOMMU mapping itself is not a problem, the problem is the management of the IOMMU. For Tegra we don't want anything to intrude into the IOMMU activities because:
1) GPU HW require additional configuration for the IOMMU usage and dumb mapping of the allocations simply doesn't work.
Generally, that's already handled by the DRM drivers allocating their own unmanaged domains. The only problem we really need to solve in that regard is that currently the device DMA ops don't get updated when moving away from the managed domain. That's been OK for the VFIO case where the device is bound to a different driver which we know won't make any explicit DMA API calls, but for the more general case of IOMMU-aware drivers we could certainly do with a bit of cooperation between the IOMMU API, DMA API, and arch code to update the DMA ops dynamically to cope with intermediate subsystems making DMA API calls on behalf of devices they don't know the intimate details of.
Quoted 6 lines
2) Older Tegra generations have a limited resource and capabilities in regards to IOMMU usage, allocating IOMMU domain per-device is just impossible for example.
3) HW performs context switches and so particular allocations have to be assigned to a particular contexts IOMMU domain.
Quoted 6 lines
I understand Qualcomm SoCs have a similar thing too, and AFAICS that case just doesn't fit into the current API model at all. We need the IOMMU driver to somehow know about the specific details of which devices have magic associations with specific contexts, and we almost certainly need a more expressive interface than
iommu_domain_alloc()to have any hope of reliable results.
This is correct for Qualcomm GPUs - The GPU hardware context switching requires a specific context and there are some restrictions around secure contexts as well.
We don't really care if the DMA attaches to a context just as long as it doesn't attach to the one(s) we care about. Perhaps a "valid context" mask would work in from the DT or the device struct to give the subsystems a clue as to which domains they were allowed to use. I recognize that there isn't a one-size-fits-all solution to this problem so I'm open to different ideas.
Jordan
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Quoted 60 lines · On Friday, 27 July 2018 20:03:26 MSK Jordan Crouse wrote:
Quoted 48 lines · Robin Murphy
Quoted 20 lines · Dmitry Osipenko
Quoted 12 lines · On Friday, 27 July 2018 12:03:28 MSK Will Deacon wrote:
Quoted 10 lines · Joerg Roedel
Quoted 4 lines · Dmitry Osipenko
The proposed solution adds a new option to the base device driver structure that allows device drivers to explicitly convey to the drivers
core that the implicit IOMMU backing for devices must not happen.Why is IOMMU mapping a problem for the Tegra GPU driver?
If we add something like this then it should not be the choice of the device driver, but of the user and/or the firmware.
Quoted 6 lines
Agreed, and it would still need somebody to configure an identity domain so
that transactions aren't aborted immediately. We currently allow the identity domain to be used by default via a command-line option, so I guess
we'd need a way for firmware to request that on a per-device basis.Quoted 7 lines
The IOMMU mapping itself is not a problem, the problem is the management of
the IOMMU. For Tegra we don't want anything to intrude into the IOMMU activities because:1) GPU HW require additional configuration for the IOMMU usage and dumb mapping of the allocations simply doesn't work.
Generally, that's already handled by the DRM drivers allocating their own unmanaged domains. The only problem we really need to solve in that regard is that currently the device DMA ops don't get updated when moving away from the managed domain. That's been OK for the VFIO case where the device is bound to a different driver which we know won't make any explicit DMA API calls, but for the more general case of IOMMU-aware drivers we could certainly do with a bit of cooperation between the IOMMU API, DMA API, and arch code to update the DMA ops dynamically to cope with intermediate subsystems making DMA API calls on behalf of devices they don't know the intimate details of.
Quoted 6 lines
2) Older Tegra generations have a limited resource and capabilities in regards to IOMMU usage, allocating IOMMU domain per-device is just impossible for example.
3) HW performs context switches and so particular allocations have to be assigned to a particular contexts IOMMU domain.
Quoted 6 lines
I understand Qualcomm SoCs have a similar thing too, and AFAICS that case just doesn't fit into the current API model at all. We need the IOMMU driver to somehow know about the specific details of which devices have magic associations with specific contexts, and we almost certainly need a more expressive interface than
iommu_domain_alloc()to have any hope of reliable results.This is correct for Qualcomm GPUs - The GPU hardware context switching requires a specific context and there are some restrictions around secure contexts as well.
Quoted 6 lines
We don't really care if the DMA attaches to a context just as long as it doesn't attach to the one(s) we care about. Perhaps a "valid context" mask would work in from the DT or the device struct to give the subsystems a clue as to which domains they were allowed to use. I recognize that there isn't a one-size-fits-all solution to this problem so I'm open to different ideas.
Designating whether implicit IOMMU backing is appropriate for a device via device-tree property sounds a bit awkward because that will be a kinda software description (of a custom Linux driver model), while device-tree is supposed to describe HW.
What about to grant IOMMU drivers with ability to decide whether the implicit backing for a device is appropriate? Like this:
bool implicit_iommu_for_dma_is_allowed(struct device *dev)
{
const struct iommu_ops *ops = dev->bus->iommu_ops;
struct iommu_group *group;
group = iommu_group_get(dev);
if (!group)
return NULL;
iommu_group_put(group);
if (!ops->implicit_iommu_for_dma_is_allowed)
return true;
return ops->implicit_iommu_for_dma_is_allowed(dev);
}Then arch_setup_dma_ops() could have a clue whether implicit IOMMU backing for a device is appropriate.
Quoted 72 lines · On Friday, 27 July 2018 20:16:53 MSK Dmitry Osipenko wrote:
Quoted 63 lines · On Friday, 27 July 2018 20:03:26 MSK Jordan Crouse wrote:
Quoted 51 lines · Robin Murphy
Quoted 21 lines · Dmitry Osipenko
Quoted 12 lines · On Friday, 27 July 2018 12:03:28 MSK Will Deacon wrote:
Quoted 10 lines · Joerg Roedel
Quoted 4 lines · Dmitry Osipenko
The proposed solution adds a new option to the base device driver structure that allows device drivers to explicitly convey to the drivers
core that the implicit IOMMU backing for devices must not happen.Why is IOMMU mapping a problem for the Tegra GPU driver?
If we add something like this then it should not be the choice of the device driver, but of the user and/or the firmware.
Quoted 7 lines
Agreed, and it would still need somebody to configure an identity domain
so
that transactions aren't aborted immediately. We currently allow the identity domain to be used by default via a command-line option, so I guess
we'd need a way for firmware to request that on a per-device basis.Quoted 8 lines
The IOMMU mapping itself is not a problem, the problem is the management
of
the IOMMU. For Tegra we don't want anything to intrude into the IOMMU activities because:1) GPU HW require additional configuration for the IOMMU usage and dumb mapping of the allocations simply doesn't work.
Generally, that's already handled by the DRM drivers allocating their own unmanaged domains. The only problem we really need to solve in that regard is that currently the device DMA ops don't get updated when moving away from the managed domain. That's been OK for the VFIO case where the device is bound to a different driver which we know won't make any explicit DMA API calls, but for the more general case of IOMMU-aware drivers we could certainly do with a bit of cooperation between the IOMMU API, DMA API, and arch code to update the DMA ops dynamically to cope with intermediate subsystems making DMA API calls on behalf of devices they don't know the intimate details of.
Quoted 7 lines
2) Older Tegra generations have a limited resource and capabilities in regards to IOMMU usage, allocating IOMMU domain per-device is just impossible for example.
3) HW performs context switches and so particular allocations have to be
assigned to a particular contexts IOMMU domain.Quoted 6 lines
I understand Qualcomm SoCs have a similar thing too, and AFAICS that case just doesn't fit into the current API model at all. We need the IOMMU driver to somehow know about the specific details of which devices have magic associations with specific contexts, and we almost certainly need a more expressive interface than
iommu_domain_alloc()to have any hope of reliable results.This is correct for Qualcomm GPUs - The GPU hardware context switching requires a specific context and there are some restrictions around secure contexts as well.
Quoted 7 lines
We don't really care if the DMA attaches to a context just as long as it doesn't attach to the one(s) we care about. Perhaps a "valid context" mask would work in from the DT or the device struct to give the subsystems a clue as to which domains they were allowed to use. I recognize that there isn't a one-size-fits-all solution to this problem so I'm open to different
ideas.
Quoted 1 line
Designating whether implicit IOMMU backing is appropriate for a device via
[snip]
[I've noticed that this should've been an answer to different message in the thread..]
As of the domain type, I don't think that any domain requirements should be defined via the DT, that should be purely internal to the kernel drivers. Maybe iommu_domain_alloc() could get an additional argument, like some platform-specific domain descriptor.
Anyway a custom IOMMU domain type requirements should be a different topic for discussion, at least for now (AFAIK) there is no need for that on Tegra and I can't suggest anything really constructive about it. Though maybe Mikko could give a comment from the Tegra perspective about whether custom domain type requirements could be ever needed on Tegra, what those requirements are and how it could be implemented.
Quoted 97 lines · On Friday, 27 July 2018 20:16:53 MSK Dmitry Osipenko wrote:
Quoted 63 lines · On Friday, 27 July 2018 20:03:26 MSK Jordan Crouse wrote:
Quoted 51 lines · Robin Murphy
Quoted 21 lines · Dmitry Osipenko
Quoted 12 lines · On Friday, 27 July 2018 12:03:28 MSK Will Deacon wrote:
Quoted 10 lines · Joerg Roedel
Quoted 4 lines · Dmitry Osipenko
The proposed solution adds a new option to the base device driver structure that allows device drivers to explicitly convey to the drivers
core that the implicit IOMMU backing for devices must not happen.Why is IOMMU mapping a problem for the Tegra GPU driver?
If we add something like this then it should not be the choice of the device driver, but of the user and/or the firmware.
Quoted 7 lines
Agreed, and it would still need somebody to configure an identity domain
so
that transactions aren't aborted immediately. We currently allow the identity domain to be used by default via a command-line option, so I guess
we'd need a way for firmware to request that on a per-device basis.Quoted 8 lines
The IOMMU mapping itself is not a problem, the problem is the management
of
the IOMMU. For Tegra we don't want anything to intrude into the IOMMU activities because:1) GPU HW require additional configuration for the IOMMU usage and dumb mapping of the allocations simply doesn't work.
Generally, that's already handled by the DRM drivers allocating their own unmanaged domains. The only problem we really need to solve in that regard is that currently the device DMA ops don't get updated when moving away from the managed domain. That's been OK for the VFIO case where the device is bound to a different driver which we know won't make any explicit DMA API calls, but for the more general case of IOMMU-aware drivers we could certainly do with a bit of cooperation between the IOMMU API, DMA API, and arch code to update the DMA ops dynamically to cope with intermediate subsystems making DMA API calls on behalf of devices they don't know the intimate details of.
Quoted 7 lines
2) Older Tegra generations have a limited resource and capabilities in regards to IOMMU usage, allocating IOMMU domain per-device is just impossible for example.
3) HW performs context switches and so particular allocations have to be
assigned to a particular contexts IOMMU domain.Quoted 6 lines
I understand Qualcomm SoCs have a similar thing too, and AFAICS that case just doesn't fit into the current API model at all. We need the IOMMU driver to somehow know about the specific details of which devices have magic associations with specific contexts, and we almost certainly need a more expressive interface than
iommu_domain_alloc()to have any hope of reliable results.This is correct for Qualcomm GPUs - The GPU hardware context switching requires a specific context and there are some restrictions around secure contexts as well.
Quoted 7 lines
We don't really care if the DMA attaches to a context just as long as it doesn't attach to the one(s) we care about. Perhaps a "valid context" mask would work in from the DT or the device struct to give the subsystems a clue as to which domains they were allowed to use. I recognize that there isn't a one-size-fits-all solution to this problem so I'm open to different
ideas.Designating whether implicit IOMMU backing is appropriate for a device via device-tree property sounds a bit awkward because that will be a kinda software description (of a custom Linux driver model), while device-tree is supposed to describe HW.
What about to grant IOMMU drivers with ability to decide whether the implicit backing for a device is appropriate? Like this:
bool
implicit_iommu_for_dma_is_allowed(struct device *dev){ const struct iommu_ops *ops = dev->bus->iommu_ops; struct iommu_group *group; group = iommu_group_get(dev); if (!group) return NULL; iommu_group_put(group); if (!ops->implicit_iommu_for_dma_is_allowed) return true; return ops->implicit_iommu_for_dma_is_allowed(dev); }
Quoted 2 lines
Then
arch_setup_dma_ops()could have a clue whether implicit IOMMU backing for a device is appropriate.
Guys, does it sound good to you or maybe you have something else on your mind? Even if it's not an ideal solution, it fixes the immediate problem and should be good enough for the starter.
Quoted 98 lines · Dmitry Osipenko
Quoted 97 lines · On Friday, 27 July 2018 20:16:53 MSK Dmitry Osipenko wrote:
Quoted 63 lines · On Friday, 27 July 2018 20:03:26 MSK Jordan Crouse wrote:
Quoted 51 lines · Robin Murphy
Quoted 21 lines · Dmitry Osipenko
Quoted 12 lines · On Friday, 27 July 2018 12:03:28 MSK Will Deacon wrote:
Quoted 10 lines · Joerg Roedel
Quoted 4 lines · Dmitry Osipenko
The proposed solution adds a new option to the base device driver structure that allows device drivers to explicitly convey to the drivers
core that the implicit IOMMU backing for devices must not happen.Why is IOMMU mapping a problem for the Tegra GPU driver?
If we add something like this then it should not be the choice of the device driver, but of the user and/or the firmware.
Quoted 7 lines
Agreed, and it would still need somebody to configure an identity domain
so
that transactions aren't aborted immediately. We currently allow the identity domain to be used by default via a command-line option, so I guess
we'd need a way for firmware to request that on a per-device basis.Quoted 8 lines
The IOMMU mapping itself is not a problem, the problem is the management
of
the IOMMU. For Tegra we don't want anything to intrude into the IOMMU activities because:1) GPU HW require additional configuration for the IOMMU usage and dumb mapping of the allocations simply doesn't work.
Generally, that's already handled by the DRM drivers allocating their own unmanaged domains. The only problem we really need to solve in that regard is that currently the device DMA ops don't get updated when moving away from the managed domain. That's been OK for the VFIO case where the device is bound to a different driver which we know won't make any explicit DMA API calls, but for the more general case of IOMMU-aware drivers we could certainly do with a bit of cooperation between the IOMMU API, DMA API, and arch code to update the DMA ops dynamically to cope with intermediate subsystems making DMA API calls on behalf of devices they don't know the intimate details of.
Quoted 7 lines
2) Older Tegra generations have a limited resource and capabilities in regards to IOMMU usage, allocating IOMMU domain per-device is just impossible for example.
3) HW performs context switches and so particular allocations have to be
assigned to a particular contexts IOMMU domain.Quoted 6 lines
I understand Qualcomm SoCs have a similar thing too, and AFAICS that case just doesn't fit into the current API model at all. We need the IOMMU driver to somehow know about the specific details of which devices have magic associations with specific contexts, and we almost certainly need a more expressive interface than
iommu_domain_alloc()to have any hope of reliable results.This is correct for Qualcomm GPUs - The GPU hardware context switching requires a specific context and there are some restrictions around secure contexts as well.
Quoted 7 lines
We don't really care if the DMA attaches to a context just as long as it doesn't attach to the one(s) we care about. Perhaps a "valid context" mask would work in from the DT or the device struct to give the subsystems a clue as to which domains they were allowed to use. I recognize that there isn't a one-size-fits-all solution to this problem so I'm open to different
ideas.Designating whether implicit IOMMU backing is appropriate for a device via device-tree property sounds a bit awkward because that will be a kinda software description (of a custom Linux driver model), while device-tree is supposed to describe HW.
What about to grant IOMMU drivers with ability to decide whether the implicit backing for a device is appropriate? Like this:
bool
implicit_iommu_for_dma_is_allowed(struct device *dev){ const struct iommu_ops *ops = dev->bus->iommu_ops; struct iommu_group *group; group = iommu_group_get(dev); if (!group) return NULL; iommu_group_put(group); if (!ops->implicit_iommu_for_dma_is_allowed) return true; return ops->implicit_iommu_for_dma_is_allowed(dev); }
Quoted 6 lines
Quoted 2 lines
Then
arch_setup_dma_ops()could have a clue whether implicit IOMMU backing for a device is appropriate.Guys, does it sound good to you or maybe you have something else on your mind? Even if it's not an ideal solution, it fixes the immediate problem and should be good enough for the starter.
To me that looks like a step ion the wrong direction that won't help at all in actually addressing the underlying issues.
If the GPU driver wants to explicitly control IOMMU mappings instead of relying on the IOMMU_DOMAIN_DMA abstraction, then it should use its own unmanaged domain. At that point it shouldn't matter if a DMA ops domain was allocated, since the GPU device will no longer be attached to it. Yes, there may be some improvements to make like having unused domains not consume hardware contexts, but that's internal to the relevant IOMMU drivers. If moving in and out of DMA ops domains leaves the actual dma_ops broken, that's already a problem between the IOMMU API and the arch DMA code as I've mentioned before.
Furthermore, given what the example above is trying to do, arch_setup_dma_ops() is way too late to do it - the default domain was already set up in iommu_group_get_for_dev() when the IOMMU driver first saw that device. An "opt-out" mechanism that doesn't actually opt out and just bodges around being opted-in after the fact doesn't strike me as something which can grow to be robust and maintainable.
For the case where a device has some special hardware relationship with a particular IOMMU context, the IOMMU driver *has* to be completely aware of that, i.e. it needs to be described in DT/ACPI, either via some explicit binding or at least inferred from some SoC/instance-specific IOMMU compatible. Then the IOMMU driver needs to know when the driver for that device is requesting its special domain so that it provide the correct context (and *not* allocate that context for other uses). Anything which just relies on the order in which things currently happen to be allocated is far too fragile long-term.
Robin.
Quoted 128 lines · Robin Murphy
Quoted 98 lines · Dmitry Osipenko
Quoted 97 lines · On Friday, 27 July 2018 20:16:53 MSK Dmitry Osipenko wrote:
Quoted 63 lines · On Friday, 27 July 2018 20:03:26 MSK Jordan Crouse wrote:
Quoted 51 lines · Robin Murphy
Quoted 21 lines · Dmitry Osipenko
Quoted 12 lines · On Friday, 27 July 2018 12:03:28 MSK Will Deacon wrote:
Quoted 10 lines · Joerg Roedel
Quoted 4 lines · Dmitry Osipenko
The proposed solution adds a new option to the base device driver structure that allows device drivers to explicitly convey to the drivers
core that the implicit IOMMU backing for devices must not happen.Why is IOMMU mapping a problem for the Tegra GPU driver?
If we add something like this then it should not be the choice of the device driver, but of the user and/or the firmware.
Quoted 7 lines
Agreed, and it would still need somebody to configure an identity domain
so
that transactions aren't aborted immediately. We currently allow the identity domain to be used by default via a command-line option, so I guess
we'd need a way for firmware to request that on a per-device basis.Quoted 8 lines
The IOMMU mapping itself is not a problem, the problem is the management
of
the IOMMU. For Tegra we don't want anything to intrude into the IOMMU activities because:1) GPU HW require additional configuration for the IOMMU usage and dumb mapping of the allocations simply doesn't work.
Generally, that's already handled by the DRM drivers allocating their own unmanaged domains. The only problem we really need to solve in that regard is that currently the device DMA ops don't get updated when moving away from the managed domain. That's been OK for the VFIO case where the device is bound to a different driver which we know won't make any explicit DMA API calls, but for the more general case of IOMMU-aware drivers we could certainly do with a bit of cooperation between the IOMMU API, DMA API, and arch code to update the DMA ops dynamically to cope with intermediate subsystems making DMA API calls on behalf of devices they don't know the intimate details of.
Quoted 7 lines
2) Older Tegra generations have a limited resource and capabilities in regards to IOMMU usage, allocating IOMMU domain per-device is just impossible for example.
3) HW performs context switches and so particular allocations have to be
assigned to a particular contexts IOMMU domain.Quoted 6 lines
I understand Qualcomm SoCs have a similar thing too, and AFAICS that case just doesn't fit into the current API model at all. We need the IOMMU driver to somehow know about the specific details of which devices have magic associations with specific contexts, and we almost certainly need a more expressive interface than
iommu_domain_alloc()to have any hope of reliable results.This is correct for Qualcomm GPUs - The GPU hardware context switching requires a specific context and there are some restrictions around secure contexts as well.
Quoted 7 lines
We don't really care if the DMA attaches to a context just as long as it doesn't attach to the one(s) we care about. Perhaps a "valid context" mask would work in from the DT or the device struct to give the subsystems a clue as to which domains they were allowed to use. I recognize that there isn't a one-size-fits-all solution to this problem so I'm open to different
ideas.Designating whether implicit IOMMU backing is appropriate for a device via device-tree property sounds a bit awkward because that will be a kinda software description (of a custom Linux driver model), while device-tree is supposed to describe HW.
What about to grant IOMMU drivers with ability to decide whether the implicit backing for a device is appropriate? Like this:
bool
implicit_iommu_for_dma_is_allowed(struct device *dev){ const struct iommu_ops *ops = dev->bus->iommu_ops; struct iommu_group *group; group = iommu_group_get(dev); if (!group) return NULL; iommu_group_put(group); if (!ops->implicit_iommu_for_dma_is_allowed) return true; return ops->implicit_iommu_for_dma_is_allowed(dev); }Quoted 6 lines
Quoted 2 lines
Then
arch_setup_dma_ops()could have a clue whether implicit IOMMU backing for a device is appropriate.Guys, does it sound good to you or maybe you have something else on your mind? Even if it's not an ideal solution, it fixes the immediate problem and should be good enough for the starter.
To me that looks like a step ion the wrong direction that won't help at all in actually addressing the underlying issues.
If the GPU driver wants to explicitly control IOMMU mappings instead of relying on the
IOMMU_DOMAIN_DMAabstraction, then it should use its own unmanaged domain. At that point it shouldn't matter if a DMA ops domain was allocated, since the GPU device will no longer be attached to it. Yes, there may be some improvements to make like having unused domains not consume hardware contexts, but that's internal to the relevant IOMMU drivers. If moving in and out of DMA ops domains leaves the actualdma_opsbroken, that's already a problem between the IOMMU API and the arch DMA code as I've mentioned before.Furthermore, given what the example above is trying to do,
arch_setup_dma_ops()is way too late to do it - the default domain was already set up iniommu_group_get_for_dev()when the IOMMU driver first saw that device. An "opt-out" mechanism that doesn't actually opt out and just bodges around being opted-in after the fact doesn't strike me as something which can grow to be robust and maintainable.
Quoted 10 lines
For the case where a device has some special hardware relationship with a particular IOMMU context, the IOMMU driver *has* to be completely aware of that, i.e. it needs to be described in DT/ACPI, either via some explicit binding or at least inferred from some SoC/instance-specific IOMMU compatible. Then the IOMMU driver needs to know when the driver for that device is requesting its special domain so that it provide the correct context (and *not* allocate that context for other uses). Anything which just relies on the order in which things currently happen to be allocated is far too fragile long-term.
Speculating what this would look like for arm-smmu-v2. Thinking we would add either a mask or a bit to the per-device smmu data to identify the "available" contexts for dma (or alternatively, the "reserved" domains for the device) and then change up _arm_smmu_alloc_bitmap() to hand out the right numbers accordingly.
Then that leaves the interface for the device to request a specific context
- I guess a DOMAIN_ATTR would work for that in lieu of changing iommu_alloc_domain() and friends.
Would this match up with your thinking?
Jordan
Signature · 6 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 117 lines · On Friday, 3 August 2018 18:43:41 MSK Robin Murphy wrote:
Quoted 108 lines · Dmitry Osipenko
Quoted 107 lines · On Friday, 27 July 2018 20:16:53 MSK Dmitry Osipenko wrote:
Quoted 65 lines · On Friday, 27 July 2018 20:03:26 MSK Jordan Crouse wrote:
Quoted 53 lines · Robin Murphy
Quoted 28 lines · Dmitry Osipenko
Quoted 13 lines · On Friday, 27 July 2018 12:03:28 MSK Will Deacon wrote:
Quoted 11 lines · Joerg Roedel
Quoted 4 lines · Dmitry Osipenko
The proposed solution adds a new option to the base device driver structure that allows device drivers to explicitly convey to the drivers
core that the implicit IOMMU backing for devices must not happen.Why is IOMMU mapping a problem for the Tegra GPU driver?
If we add something like this then it should not be the choice of the
device driver, but of the user and/or the firmware.Quoted 7 lines
Agreed, and it would still need somebody to configure an identity domain
so
that transactions aren't aborted immediately. We currently allow the identity domain to be used by default via a command-line option, so I guess
we'd need a way for firmware to request that on a per-device basis.The IOMMU mapping itself is not a problem, the problem is the management
of
the IOMMU. For Tegra we don't want anything to intrude into the IOMMU activities because:Quoted 3 lines
1) GPU HW require additional configuration for the IOMMU usage and dumb
mapping of the allocations simply doesn't work.Generally, that's already handled by the DRM drivers allocating their own unmanaged domains. The only problem we really need to solve in that regard is that currently the device DMA ops don't get updated when moving away from the managed domain. That's been OK for the VFIO case where the device is bound to a different driver which we know won't make any explicit DMA API calls, but for the more general case of IOMMU-aware drivers we could certainly do with a bit of cooperation between the IOMMU API, DMA API, and arch code to update the DMA ops dynamically to cope with intermediate subsystems making DMA API calls on behalf of devices they don't know the intimate details of.
Quoted 7 lines
2) Older Tegra generations have a limited resource and capabilities in regards to IOMMU usage, allocating IOMMU domain per-device is just impossible for example.
3) HW performs context switches and so particular allocations have to be
assigned to a particular contexts IOMMU domain.Quoted 6 lines
I understand Qualcomm SoCs have a similar thing too, and AFAICS that case just doesn't fit into the current API model at all. We need the IOMMU driver to somehow know about the specific details of which devices have magic associations with specific contexts, and we almost certainly need a more expressive interface than
iommu_domain_alloc()to have any hope of reliable results.This is correct for Qualcomm GPUs - The GPU hardware context switching requires a specific context and there are some restrictions around secure contexts as well.
Quoted 9 lines
We don't really care if the DMA attaches to a context just as long as it doesn't attach to the one(s) we care about. Perhaps a "valid context" mask
would work in from the DT or the device struct to give the subsystems a clue as to which domains they were allowed to use. I recognize that there
isn't a one-size-fits-all solution to this problem so I'm open to different
ideas.Designating whether implicit IOMMU backing is appropriate for a device via
device-tree property sounds a bit awkward because that will be a kinda software description (of a custom Linux driver model), while device-tree is
supposed to describe HW.What about to grant IOMMU drivers with ability to decide whether the implicit backing for a device is appropriate? Like this:
bool
implicit_iommu_for_dma_is_allowed(struct device *dev){const struct iommu_ops *ops = dev->bus->iommu_ops; struct iommu_group *group; group = iommu_group_get(dev); if (!group) return NULL; iommu_group_put(group); if (!ops->implicit_iommu_for_dma_is_allowed) return true; return ops->implicit_iommu_for_dma_is_allowed(dev);}
Quoted 7 lines
Quoted 3 lines
Then
arch_setup_dma_ops()could have a clue whether implicit IOMMU backing
for a device is appropriate.Guys, does it sound good to you or maybe you have something else on your mind? Even if it's not an ideal solution, it fixes the immediate problem and should be good enough for the starter.
Quoted 7 lines
To me that looks like a step ion the wrong direction that won't help at all in actually addressing the underlying issues.
If the GPU driver wants to explicitly control IOMMU mappings instead of relying on the
IOMMU_DOMAIN_DMAabstraction, then it should use its own unmanaged domain. At that point it shouldn't matter if a DMA ops domain was allocated, since the GPU device will no longer be attached to it.
It is not obvious to me what solution you are proposing..
Are you saying that the detaching from the DMA IOMMU domain that is provided by dma_ops() implementer (ARM32 arch for example) should be generalized and hence there should be something like:
dma_detach_device_from_iommu_dma_domain(dev);
that drivers will have to invoke.
And hence there will be dma_map_ops.iommu_detach_device() that dma_ops() provider will have to implement. Thereby provider will detach device from DMA domain, destroy the domain and update the DMA ops of the device.
Quoted 13 lines
Yes, there may be some improvements to make like having unused domains not consume hardware contexts, but that's internal to the relevant IOMMU drivers. If moving in and out of DMA ops domains leaves the actual
dma_opsbroken, that's already a problem between the IOMMU API and the arch DMA code as I've mentioned before.Furthermore, given what the example above is trying to do,
arch_setup_dma_ops()is way too late to do it - the default domain was already set up iniommu_group_get_for_dev()when the IOMMU driver first saw that device. An "opt-out" mechanism that doesn't actually opt out and just bodges around being opted-in after the fact doesn't strike me as something which can grow to be robust and maintainable.
Quoted 9 lines
For the case where a device has some special hardware relationship with a particular IOMMU context, the IOMMU driver *has* to be completely aware of that, i.e. it needs to be described in DT/ACPI, either via some explicit binding or at least inferred from some SoC/instance-specific IOMMU compatible. Then the IOMMU driver needs to know when the driver for that device is requesting its special domain so that it provide the correct context (and *not* allocate that context for other uses). Anything which just relies on the order in which things currently happen to be allocated is far too fragile long-term.
If hardware has some restrictions, then that should be reflected in the hardware description. But that's not what we are trying to solve, at least there is no such problem right now for NVIDIA Tegra.
Quoted 128 lines · Dmitry Osipenko
Quoted 117 lines · On Friday, 3 August 2018 18:43:41 MSK Robin Murphy wrote:
Quoted 108 lines · Dmitry Osipenko
Quoted 107 lines · On Friday, 27 July 2018 20:16:53 MSK Dmitry Osipenko wrote:
Quoted 65 lines · On Friday, 27 July 2018 20:03:26 MSK Jordan Crouse wrote:
Quoted 53 lines · Robin Murphy
Quoted 28 lines · Dmitry Osipenko
Quoted 13 lines · On Friday, 27 July 2018 12:03:28 MSK Will Deacon wrote:
Quoted 11 lines · Joerg Roedel
Quoted 4 lines · Dmitry Osipenko
The proposed solution adds a new option to the base device driver structure that allows device drivers to explicitly convey to the drivers
core that the implicit IOMMU backing for devices must not happen.Why is IOMMU mapping a problem for the Tegra GPU driver?
If we add something like this then it should not be the choice of the
device driver, but of the user and/or the firmware.Quoted 7 lines
Agreed, and it would still need somebody to configure an identity domain
so
that transactions aren't aborted immediately. We currently allow the identity domain to be used by default via a command-line option, so I guess
we'd need a way for firmware to request that on a per-device basis.The IOMMU mapping itself is not a problem, the problem is the management
of
the IOMMU. For Tegra we don't want anything to intrude into the IOMMU activities because:Quoted 3 lines
1) GPU HW require additional configuration for the IOMMU usage and dumb
mapping of the allocations simply doesn't work.Generally, that's already handled by the DRM drivers allocating their own unmanaged domains. The only problem we really need to solve in that regard is that currently the device DMA ops don't get updated when moving away from the managed domain. That's been OK for the VFIO case where the device is bound to a different driver which we know won't make any explicit DMA API calls, but for the more general case of IOMMU-aware drivers we could certainly do with a bit of cooperation between the IOMMU API, DMA API, and arch code to update the DMA ops dynamically to cope with intermediate subsystems making DMA API calls on behalf of devices they don't know the intimate details of.
Quoted 7 lines
2) Older Tegra generations have a limited resource and capabilities in regards to IOMMU usage, allocating IOMMU domain per-device is just impossible for example.
3) HW performs context switches and so particular allocations have to be
assigned to a particular contexts IOMMU domain.Quoted 6 lines
I understand Qualcomm SoCs have a similar thing too, and AFAICS that case just doesn't fit into the current API model at all. We need the IOMMU driver to somehow know about the specific details of which devices have magic associations with specific contexts, and we almost certainly need a more expressive interface than
iommu_domain_alloc()to have any hope of reliable results.This is correct for Qualcomm GPUs - The GPU hardware context switching requires a specific context and there are some restrictions around secure contexts as well.
Quoted 9 lines
We don't really care if the DMA attaches to a context just as long as it doesn't attach to the one(s) we care about. Perhaps a "valid context" mask
would work in from the DT or the device struct to give the subsystems a clue as to which domains they were allowed to use. I recognize that there
isn't a one-size-fits-all solution to this problem so I'm open to different
ideas.Designating whether implicit IOMMU backing is appropriate for a device via
device-tree property sounds a bit awkward because that will be a kinda software description (of a custom Linux driver model), while device-tree is
supposed to describe HW.What about to grant IOMMU drivers with ability to decide whether the implicit backing for a device is appropriate? Like this:
bool
implicit_iommu_for_dma_is_allowed(struct device *dev){const struct iommu_ops *ops = dev->bus->iommu_ops; struct iommu_group *group; group = iommu_group_get(dev); if (!group) return NULL; iommu_group_put(group); if (!ops->implicit_iommu_for_dma_is_allowed) return true; return ops->implicit_iommu_for_dma_is_allowed(dev);}
Quoted 7 lines
Quoted 3 lines
Then
arch_setup_dma_ops()could have a clue whether implicit IOMMU backing
for a device is appropriate.Guys, does it sound good to you or maybe you have something else on your mind? Even if it's not an ideal solution, it fixes the immediate problem and should be good enough for the starter.
Quoted 7 lines
To me that looks like a step ion the wrong direction that won't help at all in actually addressing the underlying issues.
If the GPU driver wants to explicitly control IOMMU mappings instead of relying on the
IOMMU_DOMAIN_DMAabstraction, then it should use its own unmanaged domain. At that point it shouldn't matter if a DMA ops domain was allocated, since the GPU device will no longer be attached to it.It is not obvious to me what solution you are proposing..
Quoted 7 lines
Are you saying that the detaching from the DMA IOMMU domain that is provided by
dma_ops()implementer (ARM32 arch for example) should be generalized and hence there should be something like:dma_detach_device_from_iommu_dma_domain(dev);that drivers will have to invoke.
No, I mean that drivers should not have to care at all. If the device has been given a set of DMA ops which rely on it being attached to a default DMA domain, that's not the driver's fault and it's not something the driver should have deal with. Either the DMA ops themselves should be robust and provide a non-IOMMU fallback if they detect that the device is currently attached to a different domain, or the attach operation (ideally in the IOMMU core, but at worst in the IOMMU driver's .attach_dev callback) should automatically tell the arch code to update the device's DMA ops appropriately for the target domain. There are already examples of both approaches dotted around arch-specific code, so the question is which particular solution is most appropriate to standardise on in what is intended to be generic code.
Quoted 27 lines
And hence there will be
dma_map_ops.iommu_detach_device()thatdma_ops()provider will have to implement. Thereby provider will detach device from DMA domain, destroy the domain and update the DMA ops of the device.Quoted 13 lines
Yes, there may be some improvements to make like having unused domains not consume hardware contexts, but that's internal to the relevant IOMMU drivers. If moving in and out of DMA ops domains leaves the actual
dma_opsbroken, that's already a problem between the IOMMU API and the arch DMA code as I've mentioned before.Furthermore, given what the example above is trying to do,
arch_setup_dma_ops()is way too late to do it - the default domain was already set up iniommu_group_get_for_dev()when the IOMMU driver first saw that device. An "opt-out" mechanism that doesn't actually opt out and just bodges around being opted-in after the fact doesn't strike me as something which can grow to be robust and maintainable.Quoted 9 lines
For the case where a device has some special hardware relationship with a particular IOMMU context, the IOMMU driver *has* to be completely aware of that, i.e. it needs to be described in DT/ACPI, either via some explicit binding or at least inferred from some SoC/instance-specific IOMMU compatible. Then the IOMMU driver needs to know when the driver for that device is requesting its special domain so that it provide the correct context (and *not* allocate that context for other uses). Anything which just relies on the order in which things currently happen to be allocated is far too fragile long-term.
Quoted 3 lines
If hardware has some restrictions, then that should be reflected in the hardware description. But that's not what we are trying to solve, at least there is no such problem right now for NVIDIA Tegra.
OK, maybe I misunderstood "HW performs context switches and so particular allocations have to be assigned to a particular contexts IOMMU domain." - is it that the domain can be backed by any hardware context and the Tegra GPU driver only needs to know *which* one, rather then needing a specific hard-wired context to be allocated as in the Qcom case?
Robin.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 133 lines · Robin Murphy
Quoted 132 lines · Dmitry Osipenko
Quoted 117 lines · On Friday, 3 August 2018 18:43:41 MSK Robin Murphy wrote:
Quoted 108 lines · Dmitry Osipenko
Quoted 107 lines · On Friday, 27 July 2018 20:16:53 MSK Dmitry Osipenko wrote:
Quoted 65 lines · On Friday, 27 July 2018 20:03:26 MSK Jordan Crouse wrote:
Quoted 53 lines · Robin Murphy
Quoted 28 lines · Dmitry Osipenko
Quoted 13 lines · On Friday, 27 July 2018 12:03:28 MSK Will Deacon wrote:
Quoted 11 lines · Joerg Roedel
Quoted 4 lines · Dmitry Osipenko
The proposed solution adds a new option to the base device driver structure that allows device drivers to explicitly convey to the drivers
core that the implicit IOMMU backing for devices must not happen.Why is IOMMU mapping a problem for the Tegra GPU driver?
If we add something like this then it should not be the choice of the
device driver, but of the user and/or the firmware.Quoted 7 lines
Agreed, and it would still need somebody to configure an identity domain
so
that transactions aren't aborted immediately. We currently allow the identity domain to be used by default via a command-line option, so I guess
we'd need a way for firmware to request that on a per-device basis.The IOMMU mapping itself is not a problem, the problem is the management
of
the IOMMU. For Tegra we don't want anything to intrude into the IOMMU activities because:Quoted 3 lines
1) GPU HW require additional configuration for the IOMMU usage and dumb
mapping of the allocations simply doesn't work.Generally, that's already handled by the DRM drivers allocating their own unmanaged domains. The only problem we really need to solve in that regard is that currently the device DMA ops don't get updated when moving away from the managed domain. That's been OK for the VFIO case where the device is bound to a different driver which we know won't make any explicit DMA API calls, but for the more general case of IOMMU-aware drivers we could certainly do with a bit of cooperation between the IOMMU API, DMA API, and arch code to update the DMA ops dynamically to cope with intermediate subsystems making DMA API calls on behalf of devices they don't know the intimate details of.
Quoted 7 lines
2) Older Tegra generations have a limited resource and capabilities in regards to IOMMU usage, allocating IOMMU domain per-device is just impossible for example.
3) HW performs context switches and so particular allocations have to be
assigned to a particular contexts IOMMU domain.Quoted 6 lines
I understand Qualcomm SoCs have a similar thing too, and AFAICS that case just doesn't fit into the current API model at all. We need the IOMMU driver to somehow know about the specific details of which devices have magic associations with specific contexts, and we almost certainly need a more expressive interface than
iommu_domain_alloc()to have any hope of reliable results.This is correct for Qualcomm GPUs - The GPU hardware context switching requires a specific context and there are some restrictions around secure contexts as well.
Quoted 9 lines
We don't really care if the DMA attaches to a context just as long as it doesn't attach to the one(s) we care about. Perhaps a "valid context" mask
would work in from the DT or the device struct to give the subsystems a clue as to which domains they were allowed to use. I recognize that there
isn't a one-size-fits-all solution to this problem so I'm open to different
ideas.Designating whether implicit IOMMU backing is appropriate for a device via
device-tree property sounds a bit awkward because that will be a kinda software description (of a custom Linux driver model), while device-tree is
supposed to describe HW.What about to grant IOMMU drivers with ability to decide whether the implicit backing for a device is appropriate? Like this:
bool
implicit_iommu_for_dma_is_allowed(struct device *dev){const struct
iommu_ops*ops =dev->bus->iommu_ops; structiommu_group*group;group =
iommu_group_get(dev);
if (!group)return NULL;
iommu_group_put(group);
if (!ops->implicit_iommu_for_dma_is_allowed)
return true;
return
ops->implicit_iommu_for_dma_is_allowed(dev);}
Quoted 7 lines
Quoted 3 lines
Then
arch_setup_dma_ops()could have a clue whether implicit IOMMU backing
for a device is appropriate.Guys, does it sound good to you or maybe you have something else on your mind? Even if it's not an ideal solution, it fixes the immediate problem and should be good enough for the starter.
Quoted 7 lines
To me that looks like a step ion the wrong direction that won't help at all in actually addressing the underlying issues.
If the GPU driver wants to explicitly control IOMMU mappings instead of relying on the
IOMMU_DOMAIN_DMAabstraction, then it should use its own unmanaged domain. At that point it shouldn't matter if a DMA ops domain was allocated, since the GPU device will no longer be attached to it.It is not obvious to me what solution you are proposing..
Are you saying that the detaching from the DMA IOMMU domain that is provided by
dma_ops()implementer (ARM32 arch for example) should be generalized and hence there should be something like:
Quoted 5 lines
Quoted 3 lines
dma_detach_device_from_iommu_dma_domain(dev);
that drivers will have to invoke.
No, I mean that drivers should not have to care at all. If the device has been given a set of DMA ops which rely on it being attached to a default DMA domain, that's not the driver's fault and it's not something the driver should have deal with. Either the DMA ops themselves should be robust and provide a non-IOMMU fallback if they detect that the device is currently attached to a different domain, or the attach operation (ideally in the IOMMU core, but at worst in the IOMMU driver's .attach_dev callback) should automatically tell the arch code to update the device's DMA ops appropriately for the target domain. There are already examples of both approaches dotted around arch-specific code, so the question is which particular solution is most appropriate to standardise on in what is intended to be generic code.
Okay, thank you for the clarification. It will be better to start with a workaround within the driver, maybe later we could come up with a universal solution. Is there any chance that you or Joerg could help with the standardization in the future? I don't feel that I have enough expertise and capacity to do that.
Quoted 27 lines
Quoted 27 lines
And hence there will be
dma_map_ops.iommu_detach_device()thatdma_ops()provider will have to implement. Thereby provider will detach device from DMA domain, destroy the domain and update the DMA ops of the device.Quoted 22 lines
Yes, there may be some improvements to make like having unused domains not consume hardware contexts, but that's internal to the relevant IOMMU drivers. If moving in and out of DMA ops domains leaves the actual
dma_opsbroken, that's already a problem between the IOMMU API and the arch DMA code as I've mentioned before.Furthermore, given what the example above is trying to do,
arch_setup_dma_ops()is way too late to do it - the default domain was already set up iniommu_group_get_for_dev()when the IOMMU driver first saw that device. An "opt-out" mechanism that doesn't actually opt out and just bodges around being opted-in after the fact doesn't strike me as something which can grow to be robust and maintainable.For the case where a device has some special hardware relationship with a particular IOMMU context, the IOMMU driver *has* to be completely aware of that, i.e. it needs to be described in DT/ACPI, either via some explicit binding or at least inferred from some SoC/instance-specific IOMMU compatible. Then the IOMMU driver needs to know when the driver for that device is requesting its special domain so that it provide the correct context (and *not* allocate that context for other uses). Anything which just relies on the order in which things currently happen to be allocated is far too fragile long-term.
Quoted 5 lines
Quoted 3 lines
If hardware has some restrictions, then that should be reflected in the hardware description. But that's not what we are trying to solve, at least there is no such problem right now for NVIDIA Tegra.
OK, maybe I misunderstood "HW performs context switches and so particular allocations have to be assigned to a particular contexts IOMMU domain." - is it that the domain can be backed by any hardware context and the Tegra GPU driver only needs to know *which* one, rather then needing a specific hard-wired context to be allocated as in the Qcom case?
Yes, I can't recall that Tegra has any limitations like Qcom has.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu