Skip to content

Commit 8c149eb

Browse files
committed
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/[email protected] [1] Reported-by: Luis Chamberlain <[email protected]> Signed-off-by: Dan Williams <[email protected]>
1 parent e520d52 commit 8c149eb

File tree

8 files changed

+69
-0
lines changed

8 files changed

+69
-0
lines changed

tools/testing/cxl/Kbuild

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,27 @@ obj-m += cxl_acpi.o
2424
cxl_acpi-y := $(CXL_SRC)/acpi.o
2525
cxl_acpi-y += mock_acpi.o
2626
cxl_acpi-y += config_check.o
27+
cxl_acpi-y += cxl_acpi_test.o
2728

2829
obj-m += cxl_pmem.o
2930

3031
cxl_pmem-y := $(CXL_SRC)/pmem.o
3132
cxl_pmem-y += $(CXL_SRC)/security.o
3233
cxl_pmem-y += config_check.o
34+
cxl_pmem-y += cxl_pmem_test.o
3335

3436
obj-m += cxl_port.o
3537

3638
cxl_port-y := $(CXL_SRC)/port.o
3739
cxl_port-y += config_check.o
40+
cxl_port-y += cxl_port_test.o
41+
3842

3943
obj-m += cxl_mem.o
4044

4145
cxl_mem-y := $(CXL_SRC)/mem.o
4246
cxl_mem-y += config_check.o
47+
cxl_mem-y += cxl_mem_test.o
4348

4449
obj-m += cxl_core.o
4550

@@ -53,5 +58,6 @@ cxl_core-y += $(CXL_CORE_SRC)/hdm.o
5358
cxl_core-$(CONFIG_TRACING) += $(CXL_CORE_SRC)/trace.o
5459
cxl_core-$(CONFIG_CXL_REGION) += $(CXL_CORE_SRC)/region.o
5560
cxl_core-y += config_check.o
61+
cxl_core-y += cxl_core_test.o
5662

5763
obj-m += test/

tools/testing/cxl/cxl_acpi_test.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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);

tools/testing/cxl/cxl_core_test.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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);

tools/testing/cxl/cxl_mem_test.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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);

tools/testing/cxl/cxl_pmem_test.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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);

tools/testing/cxl/cxl_port_test.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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);

tools/testing/cxl/test/cxl.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <linux/pci.h>
1010
#include <linux/mm.h>
1111
#include <cxlmem.h>
12+
13+
#include "../watermark.h"
1214
#include "mock.h"
1315

1416
static int interleave_arithmetic;
@@ -1119,6 +1121,12 @@ static __init int cxl_test_init(void)
11191121
{
11201122
int rc, i;
11211123

1124+
cxl_acpi_test();
1125+
cxl_core_test();
1126+
cxl_mem_test();
1127+
cxl_pmem_test();
1128+
cxl_port_test();
1129+
11221130
register_cxl_mock_ops(&cxl_mock_ops);
11231131

11241132
cxl_mock_pool = gen_pool_create(ilog2(SZ_2M), NUMA_NO_NODE);

tools/testing/cxl/watermark.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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_ */

0 commit comments

Comments
 (0)