[PATCH 04/11] regmap: kunit: Run sparse cache tests at non-zero register addresses

Richard Fitzgerald posted 11 patches 1 year, 10 months ago
[PATCH 04/11] regmap: kunit: Run sparse cache tests at non-zero register addresses
Posted by Richard Fitzgerald 1 year, 10 months ago
Run the cache_drop() and cache_present() tests at blocks of addresses
that don't start at zero.

This adds a from_reg parameter to struct regmap_test_param. This is
used to set the base address of the register defaults created by
gen_regmap().

Extra entries are added to sparse_cache_types_list[] to test at non-zero
from_reg values. The cache_drop() and cache_present() tests are updated
to test at the given offset.

The aim here is to add test cases to cache_drop() for the bug fixed by
commit 00bb549d7d63 ("regmap: maple: Fix cache corruption in
regcache_maple_drop()")

But the same parameter table is used by the cache_present() test so
let's also update that to use from_reg.

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
---
 drivers/base/regmap/regmap-kunit.c | 67 ++++++++++++++++++++----------
 1 file changed, 45 insertions(+), 22 deletions(-)

diff --git a/drivers/base/regmap/regmap-kunit.c b/drivers/base/regmap/regmap-kunit.c
index 2029135f68fb..ae147fc8509b 100644
--- a/drivers/base/regmap/regmap-kunit.c
+++ b/drivers/base/regmap/regmap-kunit.c
@@ -17,6 +17,8 @@ struct regmap_test_priv {
 struct regmap_test_param {
 	enum regcache_type cache;
 	enum regmap_endian val_endian;
+
+	unsigned int from_reg;
 };
 
 static void get_changed_bytes(void *orig, void *new, size_t size)
@@ -37,7 +39,6 @@ static void get_changed_bytes(void *orig, void *new, size_t size)
 }
 
 static const struct regmap_config test_regmap_config = {
-	.max_register = BLOCK_TEST_SIZE,
 	.reg_stride = 1,
 	.val_bits = sizeof(unsigned int) * 8,
 };
@@ -76,9 +77,10 @@ static const char *regmap_endian_name(enum regmap_endian endian)
 
 static void param_to_desc(const struct regmap_test_param *param, char *desc)
 {
-	snprintf(desc, KUNIT_PARAM_DESC_SIZE, "%s-%s",
+	snprintf(desc, KUNIT_PARAM_DESC_SIZE, "%s-%s @%#x",
 		 regcache_type_name(param->cache),
-		 regmap_endian_name(param->val_endian));
+		 regmap_endian_name(param->val_endian),
+		 param->from_reg);
 }
 
 static const struct regmap_test_param regcache_types_list[] = {
@@ -99,8 +101,16 @@ static const struct regmap_test_param real_cache_types_list[] = {
 KUNIT_ARRAY_PARAM(real_cache_types, real_cache_types_list, param_to_desc);
 
 static const struct regmap_test_param sparse_cache_types_list[] = {
-	{ .cache = REGCACHE_RBTREE },
-	{ .cache = REGCACHE_MAPLE },
+	{ .cache = REGCACHE_RBTREE, .from_reg = 0 },
+	{ .cache = REGCACHE_RBTREE, .from_reg = 0x2001 },
+	{ .cache = REGCACHE_RBTREE, .from_reg = 0x2002 },
+	{ .cache = REGCACHE_RBTREE, .from_reg = 0x2003 },
+	{ .cache = REGCACHE_RBTREE, .from_reg = 0x2004 },
+	{ .cache = REGCACHE_MAPLE,  .from_reg = 0 },
+	{ .cache = REGCACHE_MAPLE,  .from_reg = 0x2001 },
+	{ .cache = REGCACHE_MAPLE,  .from_reg = 0x2002 },
+	{ .cache = REGCACHE_MAPLE,  .from_reg = 0x2003 },
+	{ .cache = REGCACHE_MAPLE,  .from_reg = 0x2004 },
 };
 
 KUNIT_ARRAY_PARAM(sparse_cache_types, sparse_cache_types_list, param_to_desc);
@@ -113,7 +123,7 @@ static struct regmap *gen_regmap(struct kunit *test,
 	struct regmap_test_priv *priv = test->priv;
 	unsigned int *buf;
 	struct regmap *ret;
-	size_t size = (config->max_register + 1) * sizeof(unsigned int);
+	size_t size;
 	int i;
 	struct reg_default *defaults;
 
@@ -121,6 +131,16 @@ static struct regmap *gen_regmap(struct kunit *test,
 	config->disable_locking = config->cache_type == REGCACHE_RBTREE ||
 					config->cache_type == REGCACHE_MAPLE;
 
+	if (config->max_register == 0) {
+		config->max_register = param->from_reg;
+		if (config->num_reg_defaults)
+			config->max_register += (config->num_reg_defaults - 1) *
+						config->reg_stride;
+		else
+			config->max_register += (BLOCK_TEST_SIZE * config->reg_stride);
+	}
+
+	size = (config->max_register + 1) * sizeof(unsigned int);
 	buf = kmalloc(size, GFP_KERNEL);
 	if (!buf)
 		return ERR_PTR(-ENOMEM);
@@ -141,8 +161,8 @@ static struct regmap *gen_regmap(struct kunit *test,
 		config->reg_defaults = defaults;
 
 		for (i = 0; i < config->num_reg_defaults; i++) {
-			defaults[i].reg = i * config->reg_stride;
-			defaults[i].def = buf[i * config->reg_stride];
+			defaults[i].reg = param->from_reg + (i * config->reg_stride);
+			defaults[i].def = buf[param->from_reg + (i * config->reg_stride)];
 		}
 	}
 
@@ -832,6 +852,7 @@ static void cache_sync_patch(struct kunit *test)
 
 static void cache_drop(struct kunit *test)
 {
+	const struct regmap_test_param *param = test->param_value;
 	struct regmap *map;
 	struct regmap_config config;
 	struct regmap_ram_data *data;
@@ -848,30 +869,32 @@ static void cache_drop(struct kunit *test)
 
 	/* Ensure the data is read from the cache */
 	for (i = 0; i < BLOCK_TEST_SIZE; i++)
-		data->read[i] = false;
-	KUNIT_EXPECT_EQ(test, 0, regmap_bulk_read(map, 0, rval,
+		data->read[param->from_reg + i] = false;
+	KUNIT_EXPECT_EQ(test, 0, regmap_bulk_read(map, param->from_reg, rval,
 						  BLOCK_TEST_SIZE));
 	for (i = 0; i < BLOCK_TEST_SIZE; i++) {
-		KUNIT_EXPECT_FALSE(test, data->read[i]);
-		data->read[i] = false;
+		KUNIT_EXPECT_FALSE(test, data->read[param->from_reg + i]);
+		data->read[param->from_reg + i] = false;
 	}
-	KUNIT_EXPECT_MEMEQ(test, data->vals, rval, sizeof(rval));
+	KUNIT_EXPECT_MEMEQ(test, &data->vals[param->from_reg], rval, sizeof(rval));
 
 	/* Drop some registers */
-	KUNIT_EXPECT_EQ(test, 0, regcache_drop_region(map, 3, 5));
+	KUNIT_EXPECT_EQ(test, 0, regcache_drop_region(map, param->from_reg + 3,
+						      param->from_reg + 5));
 
 	/* Reread and check only the dropped registers hit the device. */
-	KUNIT_EXPECT_EQ(test, 0, regmap_bulk_read(map, 0, rval,
+	KUNIT_EXPECT_EQ(test, 0, regmap_bulk_read(map, param->from_reg, rval,
 						  BLOCK_TEST_SIZE));
 	for (i = 0; i < BLOCK_TEST_SIZE; i++)
-		KUNIT_EXPECT_EQ(test, data->read[i], i >= 3 && i <= 5);
-	KUNIT_EXPECT_MEMEQ(test, data->vals, rval, sizeof(rval));
+		KUNIT_EXPECT_EQ(test, data->read[param->from_reg + i], i >= 3 && i <= 5);
+	KUNIT_EXPECT_MEMEQ(test, &data->vals[param->from_reg], rval, sizeof(rval));
 
 	regmap_exit(map);
 }
 
 static void cache_present(struct kunit *test)
 {
+	const struct regmap_test_param *param = test->param_value;
 	struct regmap *map;
 	struct regmap_config config;
 	struct regmap_ram_data *data;
@@ -886,23 +909,23 @@ static void cache_present(struct kunit *test)
 		return;
 
 	for (i = 0; i < BLOCK_TEST_SIZE; i++)
-		data->read[i] = false;
+		data->read[param->from_reg + i] = false;
 
 	/* No defaults so no registers cached. */
 	for (i = 0; i < BLOCK_TEST_SIZE; i++)
-		KUNIT_ASSERT_FALSE(test, regcache_reg_cached(map, i));
+		KUNIT_ASSERT_FALSE(test, regcache_reg_cached(map, param->from_reg + i));
 
 	/* We didn't trigger any reads */
 	for (i = 0; i < BLOCK_TEST_SIZE; i++)
-		KUNIT_ASSERT_FALSE(test, data->read[i]);
+		KUNIT_ASSERT_FALSE(test, data->read[param->from_reg + i]);
 
 	/* Fill the cache */
 	for (i = 0; i < BLOCK_TEST_SIZE; i++)
-		KUNIT_EXPECT_EQ(test, 0, regmap_read(map, i, &val));
+		KUNIT_EXPECT_EQ(test, 0, regmap_read(map, param->from_reg + i, &val));
 
 	/* Now everything should be cached */
 	for (i = 0; i < BLOCK_TEST_SIZE; i++)
-		KUNIT_ASSERT_TRUE(test, regcache_reg_cached(map, i));
+		KUNIT_ASSERT_TRUE(test, regcache_reg_cached(map, param->from_reg + i));
 
 	regmap_exit(map);
 }
-- 
2.39.2
Re: [PATCH 04/11] regmap: kunit: Run sparse cache tests at non-zero register addresses
Posted by Guenter Roeck 1 year, 8 months ago
Hi,

On Mon, Apr 08, 2024 at 03:45:53PM +0100, Richard Fitzgerald wrote:
> Run the cache_drop() and cache_present() tests at blocks of addresses
> that don't start at zero.
> 
> This adds a from_reg parameter to struct regmap_test_param. This is
> used to set the base address of the register defaults created by
> gen_regmap().
> 
> Extra entries are added to sparse_cache_types_list[] to test at non-zero
> from_reg values. The cache_drop() and cache_present() tests are updated
> to test at the given offset.
> 
> The aim here is to add test cases to cache_drop() for the bug fixed by
> commit 00bb549d7d63 ("regmap: maple: Fix cache corruption in
> regcache_maple_drop()")
> 
> But the same parameter table is used by the cache_present() test so
> let's also update that to use from_reg.
> 
> Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>

With this patch in mainline, I get lots of errors such as

[   23.494308] =============================================================================
[   23.496391] BUG kmalloc-64 (Tainted: G                 N): kmalloc Redzone overwritten

Bisect log and first of many backtraces attached for reference.

Guenter

---
# bad: [1b294a1f35616977caddaddf3e9d28e576a1adbc] Merge tag 'net-next-6.10' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next
# good: [a5131c3fdf2608f1c15f3809e201cf540eb28489] Merge tag 'x86-shstk-2024-05-13' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
git bisect start '1b294a1f3561' 'a5131c3fdf26'
# good: [f8beae078c82abde57fed4a5be0bbc3579b59ad0] Merge tag 'gtp-24-05-07' of git://git.kernel.org/pub/scm/linux/kernel/git/pablo/gtp Pablo neira Ayuso says:
git bisect good f8beae078c82abde57fed4a5be0bbc3579b59ad0
# bad: [ce952d8f0e9b58dc6a2bde7e47ca7fa7925583cc] Merge tag 'gpio-updates-for-v6.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux
git bisect bad ce952d8f0e9b58dc6a2bde7e47ca7fa7925583cc
# good: [f952b6c863090464c148066df9f46cb3edd603da] Merge tag 'thermal-6.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
git bisect good f952b6c863090464c148066df9f46cb3edd603da
# bad: [07bbfc6aba1efe332d9994b2995c9bea0cd3b25f] Merge tag 'regulator-v6.10' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator
git bisect bad 07bbfc6aba1efe332d9994b2995c9bea0cd3b25f
# good: [e573d27e18f8289454b6abb378de531374bd3cde] Merge branches 'acpi-tools', 'acpi-docs' and 'pnp'
git bisect good e573d27e18f8289454b6abb378de531374bd3cde
# good: [440f9d47dfac065a8da663adbc4b28703fdf550e] Merge branches 'pm-cpuidle', 'pm-sleep' and 'pm-powercap'
git bisect good 440f9d47dfac065a8da663adbc4b28703fdf550e
# good: [41b94bc6d96b9b046ef08114f057dcc6c52e28b6] iio: addac: ad74115: Use devm_regulator_get_enable_read_voltage()
git bisect good 41b94bc6d96b9b046ef08114f057dcc6c52e28b6
# bad: [991b5e2aad870828669ca105f424ef1b2534f820] regmap: kunit: Fix an NULL vs IS_ERR() check
git bisect bad 991b5e2aad870828669ca105f424ef1b2534f820
# bad: [ce75e06eea9cfdddaa0082cef663cf2d4aa5ed1d] regmap: kunit: Use a KUnit action to call regmap_exit()
git bisect bad ce75e06eea9cfdddaa0082cef663cf2d4aa5ed1d
# bad: [710915743d53d19a1baf0326302aa1f743ab018e] regmap: kunit: Run sparse cache tests at non-zero register addresses
git bisect bad 710915743d53d19a1baf0326302aa1f743ab018e
# good: [7b7982f14315e0f6910e13b22ed38a47144a83ec] regmap: kunit: Create a struct device for the regmap
git bisect good 7b7982f14315e0f6910e13b22ed38a47144a83ec
# good: [48bccea96fead1b212e19e38e50bf8e69287c45d] regmap: kunit: Introduce struct for test case parameters
git bisect good 48bccea96fead1b212e19e38e50bf8e69287c45d
# first bad commit: [710915743d53d19a1baf0326302aa1f743ab018e] regmap: kunit: Run sparse cache tests at non-zero register addresses

---
[   23.494308] =============================================================================
[   23.496391] BUG kmalloc-64 (Tainted: G                 N): kmalloc Redzone overwritten
[   23.496900] -----------------------------------------------------------------------------
[   23.496900]
[   23.497510] 0xc69ee28b-0xc69ee28b @offset=651. First byte 0x0 instead of 0xcc
[   23.498079] Allocated in __regmap_init_ram+0x30/0xa0 age=2 cpu=0 pid=1064
[   23.499422]  __kmalloc+0x270/0x378
[   23.499783]  __regmap_init_ram+0x30/0xa0
[   23.500109]  gen_regmap.constprop.0+0x144/0x198
[   23.500440]  stride+0x58/0x4e4
[   23.500715]  kunit_try_run_case+0x5c/0x1a4
[   23.501016]  kunit_generic_run_threadfn_adapter+0x1c/0x34
[   23.501396]  kthread+0xfc/0x120
[   23.501682]  ret_from_fork+0x14/0x24
[   23.502030] Freed in pinctrl_free+0x9c/0x184 age=4 cpu=0 pid=10
[   23.502450]  pinctrl_free+0x9c/0x184
[   23.502711]  release_nodes+0x50/0x7c
[   23.502985]  devres_release_all+0x80/0xf0
[   23.503265]  device_unbind_cleanup+0xc/0x60
[   23.503587]  really_probe+0x188/0x2d0
[   23.503890]  __driver_probe_device+0x84/0x1a0
[   23.504175]  driver_probe_device+0x2c/0xc4
[   23.504454]  __device_attach_driver+0x94/0xc4
[   23.504738]  bus_for_each_drv+0x84/0xdc
[   23.505003]  __device_attach+0xac/0x1d8
[   23.505268]  bus_probe_device+0x8c/0x90
[   23.505541]  deferred_probe_work_func+0x8c/0xc0
[   23.505822]  process_one_work+0x260/0x6f8
[   23.506100]  worker_thread+0x178/0x3b0
[   23.506373]  kthread+0xfc/0x120
[   23.506605]  ret_from_fork+0x14/0x24
[   23.506906] Slab 0xcbeacdc0 objects=21 used=19 fp=0xc69eec40 flags=0xa00(workingset|slab|zone=0)
[   23.507770] Object 0xc69ee280 @offset=640 fp=0xc69ee100
[   23.507770]
[   23.508668] Redzone  c69ee240: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc  ................
[   23.509138] Redzone  c69ee250: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc  ................
[   23.509538] Redzone  c69ee260: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc  ................
[   23.509935] Redzone  c69ee270: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc  ................
[   23.510453] Object   c69ee280: 01 00 01 00 01 00 01 00 01 00 01 00 cc cc cc cc  ................
[   23.510984] Object   c69ee290: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc  ................
[   23.511488] Object   c69ee2a0: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc  ................
[   23.511857] Object   c69ee2b0: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc  ................
[   23.512268] Redzone  c69ee2c0: cc cc cc cc                                      ....
[   23.512738] Padding  c69ee2f4: 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a              ZZZZZZZZZZZZ
[   23.513444] CPU: 0 PID: 1065 Comm: kunit_try_catch Tainted: G                 N 6.9.0-05151-g1b294a1f3561 #1
[   23.514023] Hardware name: Freescale i.MX6 Ultralite (Device Tree)
[   23.514542] Call trace:
[   23.514722]  unwind_backtrace from show_stack+0x10/0x14
[   23.515298]  show_stack from dump_stack_lvl+0x78/0xa8
[   23.515621]  dump_stack_lvl from check_bytes_and_report+0x110/0x12c
[   23.515972]  check_bytes_and_report from check_object+0x36c/0x3a8
[   23.516310]  check_object from free_to_partial_list+0x15c/0x5ec
[   23.516647]  free_to_partial_list from kfree+0x218/0x2cc
[   23.516967]  kfree from regmap_ram_free_context+0x18/0x2c
[   23.517298]  regmap_ram_free_context from regmap_exit+0x7c/0x148
[   23.517650]  regmap_exit from kunit_remove_resource+0xac/0xc4
[   23.518001]  kunit_remove_resource from kunit_cleanup+0x2c/0x5c
[   23.518435]  kunit_cleanup from kunit_generic_run_threadfn_adapter+0x1c/0x34
[   23.518876]  kunit_generic_run_threadfn_adapter from kthread+0xfc/0x120
[   23.519305]  kthread from ret_from_fork+0x14/0x24
[   23.519764] Exception stack(0xd2541fb0 to 0xd2541ff8)
[   23.520248] 1fa0:                                     00000000 00000000 00000000 00000000
[   23.520717] 1fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[   23.521161] 1fe0: 00000000 00000000 00000000 00000000 00000013 00000000
[   23.521753] Disabling lock debugging due to kernel taint
[   23.522060] FIX kmalloc-64: Restoring kmalloc Redzone 0xc69ee28b-0xc69ee28b=0xcc
[   23.522403] FIX kmalloc-64: Object at 0xc69ee280 not freed
Re: [PATCH 04/11] regmap: kunit: Run sparse cache tests at non-zero register addresses
Posted by Richard Fitzgerald 1 year, 8 months ago
On 16/05/2024 20:53, Guenter Roeck wrote:
> Hi,
> 
> On Mon, Apr 08, 2024 at 03:45:53PM +0100, Richard Fitzgerald wrote:
>> Run the cache_drop() and cache_present() tests at blocks of addresses
>> that don't start at zero.
>>
>> This adds a from_reg parameter to struct regmap_test_param. This is
>> used to set the base address of the register defaults created by
>> gen_regmap().
>>
>> Extra entries are added to sparse_cache_types_list[] to test at non-zero
>> from_reg values. The cache_drop() and cache_present() tests are updated
>> to test at the given offset.
>>
>> The aim here is to add test cases to cache_drop() for the bug fixed by
>> commit 00bb549d7d63 ("regmap: maple: Fix cache corruption in
>> regcache_maple_drop()")
>>
>> But the same parameter table is used by the cache_present() test so
>> let's also update that to use from_reg.
>>
>> Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
> 
> With this patch in mainline, I get lots of errors such as
> 
> [   23.494308] =============================================================================
> [   23.496391] BUG kmalloc-64 (Tainted: G                 N): kmalloc Redzone overwritten
>

Fix sent:
https://lore.kernel.org/lkml/20240517144703.1200995-1-rf@opensource.cirrus.com/T/#u
Re: [PATCH 04/11] regmap: kunit: Run sparse cache tests at non-zero register addresses
Posted by Guenter Roeck 1 year, 8 months ago
On 5/17/24 08:44, Richard Fitzgerald wrote:
> On 16/05/2024 20:53, Guenter Roeck wrote:
>> Hi,
>>
>> On Mon, Apr 08, 2024 at 03:45:53PM +0100, Richard Fitzgerald wrote:
>>> Run the cache_drop() and cache_present() tests at blocks of addresses
>>> that don't start at zero.
>>>
>>> This adds a from_reg parameter to struct regmap_test_param. This is
>>> used to set the base address of the register defaults created by
>>> gen_regmap().
>>>
>>> Extra entries are added to sparse_cache_types_list[] to test at non-zero
>>> from_reg values. The cache_drop() and cache_present() tests are updated
>>> to test at the given offset.
>>>
>>> The aim here is to add test cases to cache_drop() for the bug fixed by
>>> commit 00bb549d7d63 ("regmap: maple: Fix cache corruption in
>>> regcache_maple_drop()")
>>>
>>> But the same parameter table is used by the cache_present() test so
>>> let's also update that to use from_reg.
>>>
>>> Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
>>
>> With this patch in mainline, I get lots of errors such as
>>
>> [   23.494308] =============================================================================
>> [   23.496391] BUG kmalloc-64 (Tainted: G                 N): kmalloc Redzone overwritten
>>
> 
> Fix sent:
> https://lore.kernel.org/lkml/20240517144703.1200995-1-rf@opensource.cirrus.com/T/#u
> 

I noticed. Thanks a lot for the quick turnaround. Currently testing.

Thanks,
Guenter

Re: [PATCH 04/11] regmap: kunit: Run sparse cache tests at non-zero register addresses
Posted by Richard Fitzgerald 1 year, 8 months ago
On 16/05/2024 20:53, Guenter Roeck wrote:
> Hi,
> 
> On Mon, Apr 08, 2024 at 03:45:53PM +0100, Richard Fitzgerald wrote:
>> Run the cache_drop() and cache_present() tests at blocks of addresses
>> that don't start at zero.
>>
>> This adds a from_reg parameter to struct regmap_test_param. This is
>> used to set the base address of the register defaults created by
>> gen_regmap().
>>
>> Extra entries are added to sparse_cache_types_list[] to test at non-zero
>> from_reg values. The cache_drop() and cache_present() tests are updated
>> to test at the given offset.
>>
>> The aim here is to add test cases to cache_drop() for the bug fixed by
>> commit 00bb549d7d63 ("regmap: maple: Fix cache corruption in
>> regcache_maple_drop()")
>>
>> But the same parameter table is used by the cache_present() test so
>> let's also update that to use from_reg.
>>
>> Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
> 
> With this patch in mainline, I get lots of errors such as
> 
> [   23.494308] =============================================================================
> [   23.496391] BUG kmalloc-64 (Tainted: G                 N): kmalloc Redzone overwritten
> 
I've managed to reproduce redzone errors in a x86_64 build with some of
the SLUB debugging enabled. I will investigate.
Re: [PATCH 04/11] regmap: kunit: Run sparse cache tests at non-zero register addresses
Posted by Richard Fitzgerald 1 year, 8 months ago
On 16/05/2024 20:53, Guenter Roeck wrote:
> Hi,
> 
> On Mon, Apr 08, 2024 at 03:45:53PM +0100, Richard Fitzgerald wrote:
>> Run the cache_drop() and cache_present() tests at blocks of addresses
>> that don't start at zero.
>>
>> This adds a from_reg parameter to struct regmap_test_param. This is
>> used to set the base address of the register defaults created by
>> gen_regmap().
>>
>> Extra entries are added to sparse_cache_types_list[] to test at non-zero
>> from_reg values. The cache_drop() and cache_present() tests are updated
>> to test at the given offset.
>>
>> The aim here is to add test cases to cache_drop() for the bug fixed by
>> commit 00bb549d7d63 ("regmap: maple: Fix cache corruption in
>> regcache_maple_drop()")
>>
>> But the same parameter table is used by the cache_present() test so
>> let's also update that to use from_reg.
>>
>> Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
> 
> With this patch in mainline, I get lots of errors such as
> 
> [   23.494308] =============================================================================
> [   23.496391] BUG kmalloc-64 (Tainted: G                 N): kmalloc Redzone overwritten
> 

Just a random thought, I wonder whether in gen_regmap() this:

   if (config->num_reg_defaults)
	config->max_register += (config->num_reg_defaults - 1) *
				config->reg_stride;
   else
	config->max_register += (BLOCK_TEST_SIZE * config->reg_stride);

should be:

config->max_register += max(config->num_reg_defaults - 1,
			    BLOCK_TEST_SIZE) * config->reg_stride;

I've only had a quick scan through the code without seeing any other
obvious problem.
Re: [PATCH 04/11] regmap: kunit: Run sparse cache tests at non-zero register addresses
Posted by Mark Brown 1 year, 8 months ago
On Thu, May 16, 2024 at 12:53:34PM -0700, Guenter Roeck wrote:

> 
> With this patch in mainline, I get lots of errors such as
> 
> [   23.494308] =============================================================================
> [   23.496391] BUG kmalloc-64 (Tainted: G                 N): kmalloc Redzone overwritten
> 
> Bisect log and first of many backtraces attached for reference.

What's your kernel architecture and config for this - it looks like
there's some sanitiser enabled?
Re: [PATCH 04/11] regmap: kunit: Run sparse cache tests at non-zero register addresses
Posted by Guenter Roeck 1 year, 8 months ago
On 5/17/24 04:28, Mark Brown wrote:
> On Thu, May 16, 2024 at 12:53:34PM -0700, Guenter Roeck wrote:
> 
>>
>> With this patch in mainline, I get lots of errors such as
>>
>> [   23.494308] =============================================================================
>> [   23.496391] BUG kmalloc-64 (Tainted: G                 N): kmalloc Redzone overwritten
>>
>> Bisect log and first of many backtraces attached for reference.
> 
> What's your kernel architecture and config for this - it looks like
> there's some sanitiser enabled?

I have CONFIG_SLUB_DEBUG and CONFIG_SLUB_DEBUG_ON enabled. I also have
various other debug options enabled, but slub debugging should be the
relevant one. I see the problem with several architectures.

- arm (all variants)
- arm64 (little and big endian)
- loongarch
- mips (all variants)
- nios2
- ppc (all variants)
- riscv (32 and 64 bit)
- x86 (32 and 64 bit)

Guenter