iommu: Permit modular builds of io-pgtable drivers
Subsystems (6)
cover iommu: Permit modular builds of io-pgtable drivers
The goal of the Generic Kernel Image (GKI) effort is to have a common kernel image that works across multiple Android devices. This involves generating a kernel image that has core features integrated into it, while SoC specific functionality can be added to the kernel for the device as a module.
Along with modularizing IOMMU drivers, this also means building the io-pgtable code as modules, which allows for SoC vendors to only include the io-pgtable implementations that they use. For example, GKI for arm64 must include support for both the IOMMU ARM LPAE/V7S formats at the moment. Having the code for both formats as modules allows SoC vendors to only provide the page table format that they use, along with their IOMMU driver.
The patches are split into 4 parts:
1) Modularizing io-pgtable-arm[-v7s].c, while leaving the io-pgtable.c code as part of the core kernel, requires removing the references to the ARM LPAE and ARM V7S io-pgtable init functions, and using a dynamic method for formats to register their io-pgtable init functions.
2) Taking references to the io-pgtable format drivers to ensure that they cannot be unloaded while in use.
3) Adding pre MODULE_SOFTDEP() dependencies to drivers in the kernel that are tristate, and invoke [alloc/free]_io_pgtable_ops(). This makes it so that the io-pgtable format drivers are loaded before the driver that needs them.
4) Changing the Kconfig options for the ARM LPAE nad ARM V7S to tristate and allowing the io-pgtable code to be enabled without having to select either page table format. The reason for doing this is so that a kernel can be built, such that it only provides the interface for io-pgtable formats to be registered as modules, as would be the case for the GKI.
Thanks,
Isaac
Isaac J. Manjarres (7):
iommu/io-pgtable: Introduce dynamic io-pgtable format registration iommu/io-pgtable: Add refcounting for io-pgtable format modules iommu/arm-smmu: Add dependency on io-pgtable format modules iommu/arm-smmu-v3: Add dependency on io-pgtable-arm format module drm/msm: Add dependency on io-pgtable-arm format module drm/panfrost: Add dependency on io-pgtable-arm format module iommu/io-pgtable-arm: Allow building modular io-pgtable formats
drivers/gpu/drm/msm/msm_drv.c | 1 + drivers/gpu/drm/panfrost/panfrost_drv.c | 1 + drivers/iommu/Kconfig | 11 +-- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 1 + drivers/iommu/arm/arm-smmu/arm-smmu.c | 1 + drivers/iommu/io-pgtable-arm-v7s.c | 36 +++++++++- drivers/iommu/io-pgtable-arm.c | 104 +++++++++++++++++++++------- drivers/iommu/io-pgtable.c | 54 ++++++++++----- include/linux/io-pgtable.h | 52 +++++++++----- 9 files changed, 196 insertions(+), 65 deletions(-)
Signature · 7 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH RESEND 1/7 iommu/io-pgtable: Introduce dynamic io-pgtable format registration
The io-pgtable code constructs an array of init functions for each page table format at compile time. This is not ideal, as it prevents io-pgtable formats from being built as kernel modules.
In preparation for modularizing the io-pgtable formats, switch to a dynamic registration scheme, where each io-pgtable format can register their init functions with the io-pgtable code at boot or module insertion time.
--- drivers/iommu/io-pgtable-arm-v7s.c | 33 ++++++++++++- drivers/iommu/io-pgtable-arm.c | 97 ++++++++++++++++++++++++++++---------- drivers/iommu/io-pgtable.c | 44 +++++++++++------ include/linux/io-pgtable.h | 50 ++++++++++++-------- 4 files changed, 164 insertions(+), 60 deletions(-)
drivers/iommu/io-pgtable-arm-v7s.c +31 -2
@@ -28,6 +28,7 @@#include <linux/iommu.h> #include <linux/kernel.h> #include <linux/kmemleak.h> +#include <linux/module.h> #include <linux/sizes.h> #include <linux/slab.h> #include <linux/spinlock.h>
@@ -835,7 +836,7 @@ static struct io_pgtable *arm_v7s_alloc_pgtable(struct io_pgtable_cfg *cfg,return NULL ; } -struct io_pgtable_init_fns io_pgtable_arm_v7s_init_fns = { +static struct io_pgtable_init_fns io_pgtable_arm_v7s_init_fns = { .alloc = arm_v7s_alloc_pgtable, .free = arm_v7s_free_pgtable, };
@@ -982,5 +983,33 @@ static int __init arm_v7s_do_selftests(void)pr_info ("self test ok\n" );return 0 ; } -subsys_initcall (arm_v7s_do_selftests); +#else +static int arm_v7s_do_selftests (void ) +{ +return 0 ; +}#endif + +static int __init arm_v7s_init (void ) +{ +int ret; + + ret =io_pgtable_ops_register (ARM_V7S , &io_pgtable_arm_v7s_init_fns); +if (ret <0 ) { +pr_err ("Failed to register ARM v7s fmt ret = %d\n" , ret); +return ret; + } + + ret =arm_v7s_do_selftests (); +if (ret <0 ) +io_pgtable_ops_unregister (ARM_V7S ); + +return ret; +} +core_initcall (arm_v7s_init); + +static void __exit arm_v7s_exit(void) +{ +io_pgtable_ops_unregister (ARM_V7S ); +} +module_exit (arm_v7s_exit);
drivers/iommu/io-pgtable-arm.c +73 -24
119 lines not on this page · raw message
drivers/iommu/io-pgtable.c +29 -15
67 lines not on this page · raw message
include/linux/io-pgtable.h +31 -19
60 lines not on this page · raw message
Signature · 7 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH RESEND 2/7 iommu/io-pgtable: Add refcounting for io-pgtable format modules
In reply to Isaac J. ManjarresIn preparation for modularizing io-pgtable formats, add support for reference counting the io-pgtable format modules to ensure that the modules are not unloaded while they are in use.
--- drivers/iommu/io-pgtable-arm-v7s.c | 1 + drivers/iommu/io-pgtable-arm.c | 5 +++++ drivers/iommu/io-pgtable.c | 12 ++++++++++-- include/linux/io-pgtable.h | 2 ++ 4 files changed, 18 insertions(+), 2 deletions(-)
drivers/iommu/io-pgtable-arm-v7s.c +1 -0
@@ -839,6 +839,7 @@ static struct io_pgtable *arm_v7s_alloc_pgtable(struct io_pgtable_cfg *cfg,static struct io_pgtable_init_fns io_pgtable_arm_v7s_init_fns = { .alloc = arm_v7s_alloc_pgtable, .free = arm_v7s_free_pgtable, + .owner =THIS_MODULE , };#ifdef CONFIG_IOMMU_IO_PGTABLE_ARMV7S_SELFTEST
drivers/iommu/io-pgtable-arm.c +5 -0
@@ -1054,26 +1054,31 @@ static struct arm_lpae_io_pgtable_init_fns arm_lpae_init_fns_table[] = { .fmt = ARM_32_LPAE_S1, .init_fns.alloc = arm_32_lpae_alloc_pgtable_s1, .init_fns.free = arm_lpae_free_pgtable, + .init_fns.owner = THIS_MODULE, }, { .fmt = ARM_32_LPAE_S2, .init_fns.alloc = arm_32_lpae_alloc_pgtable_s2, .init_fns.free = arm_lpae_free_pgtable, + .init_fns.owner = THIS_MODULE, }, { .fmt = ARM_64_LPAE_S1, .init_fns.alloc = arm_64_lpae_alloc_pgtable_s1, .init_fns.free = arm_lpae_free_pgtable, + .init_fns.owner = THIS_MODULE, }, { .fmt = ARM_64_LPAE_S2, .init_fns.alloc = arm_64_lpae_alloc_pgtable_s2, .init_fns.free = arm_lpae_free_pgtable, + .init_fns.owner = THIS_MODULE, }, { .fmt = ARM_MALI_LPAE, .init_fns.alloc = arm_mali_lpae_alloc_pgtable, .init_fns.free = arm_lpae_free_pgtable, + .init_fns.owner = THIS_MODULE, }, };
drivers/iommu/io-pgtable.c +10 -2
@@ -10,6 +10,7 @@#include <linux/bug.h> #include <linux/io-pgtable.h> #include <linux/kernel.h> +#include <linux/module.h> #include <linux/types.h> static struct io_pgtable_init_fns *io_pgtable_init_table[IO_PGTABLE_NUM_FMTS ];
@@ -28,9 +29,14 @@ struct io_pgtable_ops *alloc_io_pgtable_ops(enum io_pgtable_fmt fmt,if (!fns)return NULL ; +if (!try_module_get (fns->owner)) +return NULL ; + iop = fns->alloc (cfg, cookie); -if (!iop) +if (!iop) { +module_put (fns->owner);return NULL ; + } iop->fmt = fmt; iop->cookie = cookie;
@@ -55,8 +61,10 @@ void free_io_pgtable_ops(struct io_pgtable_ops *ops) iop =io_pgtable_ops_to_pgtable (ops);io_pgtable_tlb_flush_all (iop); fns = io_pgtable_init_table[iop->fmt]; -if (fns) +if (fns) { fns->free (iop); +module_put (fns->owner); + } }EXPORT_SYMBOL_GPL (free_io_pgtable_ops);
include/linux/io-pgtable.h +2 -0
@@ -168,10 +168,12 @@ struct io_pgtable_ops {* * @alloc: Allocate a set of page tables described by cfg. * @free: Free the page tables associated with iop. +* @owner: Driver module providing these ops. */ struct io_pgtable_init_fns {struct io_pgtable *(*alloc)(struct io_pgtable_cfg *cfg,void *cookie);void (*free)(struct io_pgtable *iop); +struct module *owner; };/**
Signature · 7 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH RESEND 3/7 iommu/arm-smmu: Add dependency on io-pgtable format modules
In reply to Isaac J. ManjarresThe SMMU driver depends on the availability of the ARM LPAE io-pgtable format code to work properly. In preparation for having the io-pgtable formats as modules, add a "pre" dependency with MODULE_SOFTDEP() to ensure that the ARM LPAE io-pgtable format module is loaded before loading the ARM SMMU driver module. Also, add a dependency on the ARMv7 short descriptor io-pgtable format, so that it can be loaded before the SMMU driver module, if available.
--- drivers/iommu/arm/arm-smmu/arm-smmu.c | 1 + 1 file changed, 1 insertion(+)
drivers/iommu/arm/arm-smmu/arm-smmu.c +1 -0
@@ -2351,3 +2351,4 @@ MODULE_DESCRIPTION("IOMMU API for ARM architected SMMU implementations");MODULE_AUTHOR ("Will Deacon <[email protected]>" );MODULE_ALIAS ("platform:arm-smmu" );MODULE_LICENSE ("GPL v2" ); +MODULE_SOFTDEP ("pre: io-pgtable-arm io-pgtable-arm-v7s" );
Signature · 7 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH RESEND 4/7 iommu/arm-smmu-v3: Add dependency on io-pgtable-arm format module
In reply to Isaac J. ManjarresThe SMMUv3 driver depends on the availability of the ARM LPAE io-pgtable format code to work properly. In preparation for having the io-pgtable formats as modules, add a "pre" dependency with MODULE_SOFTDEP() to ensure that the io-pgtable-arm format module is loaded before loading the ARM SMMUv3 driver module.
--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 1 + 1 file changed, 1 insertion(+)
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +1 -0
@@ -3650,3 +3650,4 @@ MODULE_DESCRIPTION("IOMMU API for ARM architected SMMUv3 implementations");MODULE_AUTHOR ("Will Deacon <[email protected]>" );MODULE_ALIAS ("platform:arm-smmu-v3" );MODULE_LICENSE ("GPL v2" ); +MODULE_SOFTDEP ("pre: io-pgtable-arm" );
Signature · 7 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH RESEND 5/7 drm/msm: Add dependency on io-pgtable-arm format module
In reply to Isaac J. ManjarresThe MSM DRM driver depends on the availability of the ARM LPAE io-pgtable format code to work properly. In preparation for having the io-pgtable formats as modules, add a "pre" dependency with MODULE_SOFTDEP() to ensure that the io-pgtable-arm format module is loaded before loading the MSM DRM driver module.
--- drivers/gpu/drm/msm/msm_drv.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/msm/msm_drv.c +1 -0
@@ -1369,3 +1369,4 @@ module_exit(msm_drm_unregister);MODULE_AUTHOR ("Rob Clark <[email protected]" );MODULE_DESCRIPTION ("MSM DRM Driver" );MODULE_LICENSE ("GPL" ); +MODULE_SOFTDEP ("pre: io-pgtable-arm" );
Signature · 7 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH RESEND 6/7 drm/panfrost: Add dependency on io-pgtable-arm format module
In reply to Isaac J. ManjarresThe Panfrost DRM driver depends on the availability of the ARM LPAE io-pgtable format code to work properly. In preparation for having the io-pgtable formats as modules, add a "pre" dependency with MODULE_SOFTDEP() to ensure that the io-pgtable-arm format module is loaded before loading the Panfrost DRM driver module.
--- drivers/gpu/drm/panfrost/panfrost_drv.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/panfrost/panfrost_drv.c +1 -0
@@ -704,3 +704,4 @@ module_platform_driver(panfrost_driver);MODULE_AUTHOR ("Panfrost Project Developers" );MODULE_DESCRIPTION ("Panfrost DRM Driver" );MODULE_LICENSE ("GPL v2" ); +MODULE_SOFTDEP ("pre: io-pgtable-arm" );
Signature · 7 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH RESEND 7/7 iommu/io-pgtable-arm: Allow building modular io-pgtable formats
In reply to Isaac J. ManjarresNow that everything is in place for modular io-pgtable formats, allow the ARM LPAE and ARMV7S io-pgtable formats to be built as modules, and allow the io-pgtable framework to be enabled, without having to explicitly enable an io-pgtable format.
--- drivers/iommu/Kconfig | 11 +++++++---- drivers/iommu/io-pgtable-arm-v7s.c | 2 ++ drivers/iommu/io-pgtable-arm.c | 2 ++ 3 files changed, 11 insertions(+), 4 deletions(-)
drivers/iommu/Kconfig +7 -4
@@ -25,12 +25,15 @@ if IOMMU_SUPPORT menu "Generic IOMMU Pagetable Support" -# Selected by the actual pagetable implementations config IOMMU_IO_PGTABLE - bool + bool "IOMMU Pagetable support" + help + Enable support for using IOMMU pagetables. This option enables + the generic IOMMU pagetable framework for registering IOMMU + pagetable formats, as well as managing IOMMU pagetable instances. config IOMMU_IO_PGTABLE_LPAE - bool "ARMv7/v8 Long Descriptor Format" + tristate "ARMv7/v8 Long Descriptor Format" select IOMMU_IO_PGTABLE depends on ARM || ARM64 || (COMPILE_TEST && !GENERIC_ATOMIC64) help
@@ -49,7 +52,7 @@ config IOMMU_IO_PGTABLE_LPAE_SELFTEST If unsure, say N here. config IOMMU_IO_PGTABLE_ARMV7S - bool "ARMv7/v8 Short Descriptor Format" + tristate "ARMv7/v8 Short Descriptor Format" select IOMMU_IO_PGTABLE depends on ARM || ARM64 || COMPILE_TEST help
drivers/iommu/io-pgtable-arm-v7s.c +2 -0
@@ -1014,3 +1014,5 @@ static void __exit arm_v7s_exit(void)io_pgtable_ops_unregister (ARM_V7S ); }module_exit (arm_v7s_exit); + +MODULE_LICENSE ("GPL v2" );
drivers/iommu/io-pgtable-arm.c +2 -0
@@ -1306,3 +1306,5 @@ static void __exit arm_lpae_exit(void)io_pgtable_ops_unregister (arm_lpae_init_fns_table[i].fmt); }module_exit (arm_lpae_exit); + +MODULE_LICENSE ("GPL v2" );
Signature · 7 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Will Deacon
maintainerQuoted 6 lines · Isaac J. Manjarres
The goal of the Generic Kernel Image (GKI) effort is to have a common kernel image that works across multiple Android devices. This involves generating a kernel image that has core features integrated into it, while SoC specific functionality can be added to the kernel for the device as a module.
Quoted 7 lines
Along with modularizing IOMMU drivers, this also means building the io-pgtable code as modules, which allows for SoC vendors to only include the io-pgtable implementations that they use. For example, GKI for arm64 must include support for both the IOMMU ARM LPAE/V7S formats at the moment. Having the code for both formats as modules allows SoC vendors to only provide the page table format that they use, along with their IOMMU driver.
Why is this desirable for upstream? This code isn't especially large, and the formats we support are largely architectural, meaning that they are shared between different IOMMU drivers. I think that making this modular just means that out-of-tree modifications are likely to generate page-tables which are specific to a particular IOMMU, and lead to horrible problems (crashes and data corruption) if another IOMMU driver tries to use them.
Please can you upstream whatever changes you want to make instead?
Will
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel