Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

tools/testing/cxl: Prevent cxl_test from confusing production modules

The cxl_test machinery builds modified versions of the modules in
drivers/cxl/ and intercepts some of their calls to allow cxl_test to
inject mock CXL topologies for test.

However, if cxl_test attempts the same with production modules,
fireworks ensue as Luis discovered [1]. Prevent that scenario by
arranging for cxl_test to check for a "watermark" symbol in each of the
modules it expects to be modified before the test can run. This turns
undefined runtime behavior or crashes into a safer failure to load the
cxl_test module.

Link: http://lore.kernel.org/r/20221209062919.1096779-1-mcgrof@kernel.org [1]
Reported-by: Luis Chamberlain <mcgrof@kernel.org>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>

+69
+6
tools/testing/cxl/Kbuild
··· 24 24 cxl_acpi-y := $(CXL_SRC)/acpi.o 25 25 cxl_acpi-y += mock_acpi.o 26 26 cxl_acpi-y += config_check.o 27 + cxl_acpi-y += cxl_acpi_test.o 27 28 28 29 obj-m += cxl_pmem.o 29 30 30 31 cxl_pmem-y := $(CXL_SRC)/pmem.o 31 32 cxl_pmem-y += $(CXL_SRC)/security.o 32 33 cxl_pmem-y += config_check.o 34 + cxl_pmem-y += cxl_pmem_test.o 33 35 34 36 obj-m += cxl_port.o 35 37 36 38 cxl_port-y := $(CXL_SRC)/port.o 37 39 cxl_port-y += config_check.o 40 + cxl_port-y += cxl_port_test.o 41 + 38 42 39 43 obj-m += cxl_mem.o 40 44 41 45 cxl_mem-y := $(CXL_SRC)/mem.o 42 46 cxl_mem-y += config_check.o 47 + cxl_mem-y += cxl_mem_test.o 43 48 44 49 obj-m += cxl_core.o 45 50 ··· 58 53 cxl_core-$(CONFIG_TRACING) += $(CXL_CORE_SRC)/trace.o 59 54 cxl_core-$(CONFIG_CXL_REGION) += $(CXL_CORE_SRC)/region.o 60 55 cxl_core-y += config_check.o 56 + cxl_core-y += cxl_core_test.o 61 57 62 58 obj-m += test/
+6
tools/testing/cxl/cxl_acpi_test.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* Copyright(c) 2022 Intel Corporation. All rights reserved. */ 3 + 4 + #include "watermark.h" 5 + 6 + cxl_test_watermark(cxl_acpi);
+6
tools/testing/cxl/cxl_core_test.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* Copyright(c) 2022 Intel Corporation. All rights reserved. */ 3 + 4 + #include "watermark.h" 5 + 6 + cxl_test_watermark(cxl_core);
+6
tools/testing/cxl/cxl_mem_test.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* Copyright(c) 2022 Intel Corporation. All rights reserved. */ 3 + 4 + #include "watermark.h" 5 + 6 + cxl_test_watermark(cxl_mem);
+6
tools/testing/cxl/cxl_pmem_test.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* Copyright(c) 2022 Intel Corporation. All rights reserved. */ 3 + 4 + #include "watermark.h" 5 + 6 + cxl_test_watermark(cxl_pmem);
+6
tools/testing/cxl/cxl_port_test.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* Copyright(c) 2022 Intel Corporation. All rights reserved. */ 3 + 4 + #include "watermark.h" 5 + 6 + cxl_test_watermark(cxl_port);
+8
tools/testing/cxl/test/cxl.c
··· 9 9 #include <linux/pci.h> 10 10 #include <linux/mm.h> 11 11 #include <cxlmem.h> 12 + 13 + #include "../watermark.h" 12 14 #include "mock.h" 13 15 14 16 static int interleave_arithmetic; ··· 1120 1118 static __init int cxl_test_init(void) 1121 1119 { 1122 1120 int rc, i; 1121 + 1122 + cxl_acpi_test(); 1123 + cxl_core_test(); 1124 + cxl_mem_test(); 1125 + cxl_pmem_test(); 1126 + cxl_port_test(); 1123 1127 1124 1128 register_cxl_mock_ops(&cxl_mock_ops); 1125 1129
+25
tools/testing/cxl/watermark.h
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* Copyright(c) 2022 Intel Corporation. All rights reserved. */ 3 + #ifndef _TEST_CXL_WATERMARK_H_ 4 + #define _TEST_CXL_WATERMARK_H_ 5 + #include <linux/module.h> 6 + #include <linux/printk.h> 7 + 8 + int cxl_acpi_test(void); 9 + int cxl_core_test(void); 10 + int cxl_mem_test(void); 11 + int cxl_pmem_test(void); 12 + int cxl_port_test(void); 13 + 14 + /* 15 + * dummy routine for cxl_test to validate it is linking to the properly 16 + * mocked module and not the standard one from the base tree. 17 + */ 18 + #define cxl_test_watermark(x) \ 19 + int x##_test(void) \ 20 + { \ 21 + pr_debug("%s for cxl_test\n", KBUILD_MODNAME); \ 22 + return 0; \ 23 + } \ 24 + EXPORT_SYMBOL(x##_test) 25 + #endif /* _TEST_CXL_WATERMARK_H_ */