iommu/io-pgtable-arm: dynamically allocate selftest device struct
Subsystems (2)
PATCH v2 1/1 iommu/io-pgtable-arm: dynamically allocate selftest device struct
From: Arnd Bergmann <[email protected]>
In general a 'struct device' is way too large to be put on the kernel stack. Apparently something just caused it to grow a slightly larger, which pushed the arm_lpae_do_selftests() function over the warning limit in some configurations:
drivers/iommu/io-pgtable-arm.c:1423:19: error: stack frame size (1032) exceeds limit (1024) in 'arm_lpae_do_selftests' [-Werror,-Wframe-larger-than]
1423 | static int __init arm_lpae_do_selftests(void)
| ^
Change the function to use a dynamically allocated faux_device instead of the on-stack device structure.
---
v2: use faux device instead of platform_device, as Robin suggested.
The faux device is more appropriate here since the is no actual physical device, though on the other hand the v1 patch had the advantage of not actually needing to register the device.
--- drivers/iommu/io-pgtable-arm.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/iommu/io-pgtable-arm.c +9 -4
@@ -13,6 +13,7 @@#include <linux/bitops.h> #include <linux/io-pgtable.h> #include <linux/kernel.h> +#include <linux/device/faux.h> #include <linux/sizes.h> #include <linux/slab.h> #include <linux/types.h>
@@ -1437,15 +1438,17 @@ static int __init arm_lpae_do_selftests(void) };int i, j, k, pass =0 , fail =0 ; -struct device dev; +struct faux_device *dev;struct io_pgtable_cfg cfg = { .tlb = &dummy_tlb_ops, .coherent_walk = true, - .iommu_dev = &dev, }; -/* __arm_lpae_alloc_pages() merely needs dev_to_node() to work */ -set_dev_node (&dev,NUMA_NO_NODE ); + dev =faux_device_create ("io-pgtable-test" ,NULL ,0 ); +if (!dev) +return -ENOMEM ; + + cfg.iommu_dev = &dev->dev;for (i =0 ; i <ARRAY_SIZE (pgsize); ++i) {for (j =0 ; j <ARRAY_SIZE (address_size); ++j) {
@@ -1465,6 +1468,8 @@ static int __init arm_lpae_do_selftests(void) }pr_info ("selftest: completed with %d PASS %d FAIL\n" , pass, fail); +faux_device_destroy (dev); +return fail ? -EFAULT :0 ; }subsys_initcall (arm_lpae_do_selftests);
Signature · 1 line
2.39.5
Quoted 7 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
In general a 'struct device' is way too large to be put on the kernel stack. Apparently something just caused it to grow a slightly larger, which pushed the
arm_lpae_do_selftests()function over the warning limit in some configurations:
Quoted 6 lines
drivers/iommu/io-pgtable-arm.c:1423:19: error: stack frame size (1032) exceeds limit (1024) in 'arm_lpae_do_selftests' [-Werror,-Wframe-larger-than]
1423 | static int__initarm_lpae_do_selftests(void)
| ^Change the function to use a dynamically allocated
faux_deviceinstead of the on-stack device structure.
Quoted 55 lines
Fixes ca25ec247aad ("iommu/io-pgtable-arm: Remove iommu_dev==NULL special case")Signed-off-by Arnd Bergmann <[email protected]>---
v2: use faux device instead ofplatform_device, as Robin suggested.
The faux device is more appropriate here since the is no actual physical device, though on the other hand the v1 patch had the advantage of not actually needing to register the device.--- drivers/iommu/io-pgtable-arm.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)drivers/iommu/io-pgtable-arm.c +9
-4@@ -13,6 +13,7 @@#include <linux/bitops.h> #include <linux/io-pgtable.h> #include <linux/kernel.h> +#include <linux/device/faux.h> #include <linux/sizes.h> #include <linux/slab.h> #include <linux/types.h> @@ -1437,15 +1438,17 @@ static int __init arm_lpae_do_selftests(void) };int i, j, k, pass =0 , fail =0 ; -struct device dev; +struct faux_device *dev;struct io_pgtable_cfg cfg = { .tlb = &dummy_tlb_ops, .coherent_walk = true, - .iommu_dev = &dev, }; -/* __arm_lpae_alloc_pages() merely needs dev_to_node() to work */ -set_dev_node (&dev,NUMA_NO_NODE ); + dev =faux_device_create ("io-pgtable-test" ,NULL ,0 ); +if (!dev) +return -ENOMEM ; + + cfg.iommu_dev = &dev->dev;for (i =0 ; i <ARRAY_SIZE (pgsize); ++i) {for (j =0 ; j <ARRAY_SIZE (address_size); ++j) {@@ -1465,6 +1468,8 @@ static int __init arm_lpae_do_selftests(void) }pr_info ("selftest: completed with %d PASS %d FAIL\n" , pass, fail); +faux_device_destroy (dev); +return fail ? -EFAULT :0 ; }subsys_initcall (arm_lpae_do_selftests);
Quoted 17 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
In general a 'struct device' is way too large to be put on the kernel stack. Apparently something just caused it to grow a slightly larger, which pushed the
arm_lpae_do_selftests()function over the warning limit in some configurations:
drivers/iommu/io-pgtable-arm.c:1423:19: error: stack frame size (1032) exceeds limit (1024) in 'arm_lpae_do_selftests' [-Werror,-Wframe-larger-than]
1423 | static int__initarm_lpae_do_selftests(void)
| ^Change the function to use a dynamically allocated
faux_deviceinstead of the on-stack device structure.Fixes ca25ec247aad ("iommu/io-pgtable-arm: Remove iommu_dev==NULL special case")Signed-off-by Arnd Bergmann <[email protected]>
Quoted 8 lines
---
v2: use faux device instead ofplatform_device, as Robin suggested.
The faux device is more appropriate here since the is no actual physical device, though on the other hand the v1 patch had the advantage of not actually needing to register the device.--- drivers/iommu/io-pgtable-arm.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
Applied, thanks.