Skip to content

Commit bf42df0

Browse files
arndbpmladek
authored andcommitted
printk: kunit: support offstack cpumask
For large values of CONFIG_NR_CPUS, the newly added kunit test fails to build: kernel/printk/printk_ringbuffer_kunit_test.c: In function 'test_readerwriter': kernel/printk/printk_ringbuffer_kunit_test.c:279:1: error: the frame size of 1432 bytes is larger than 1280 bytes [-Werror=frame-larger-than=] Change this to use cpumask_var_t and allocate it dynamically when CONFIG_CPUMASK_OFFSTACK is set. The variable has to be released via a KUnit action wrapper so that it is freed when the test fails and gets aborted. The parameter type is hardcoded to "struct cpumask *" because the macro KUNIT_DEFINE_ACTION_WRAPPER() does not accept an array. But the function does nothing when CONFIG_CPUMASK_OFFSTACK is not set anyway. Fixes: 5ea2bcd ("printk: ringbuffer: Add KUnit test") Signed-off-by: Arnd Bergmann <arnd@arndb.de> Link: https://lore.kernel.org/all/20250620192554.2234184-1-arnd@kernel.org # v1 [pmladek@suse.com: Correctly handle allocation failures and freeing using KUnit test API.] Link: https://lore.kernel.org/all/20250702095157.110916-3-pmladek@suse.com # v2 Signed-off-by: Petr Mladek <pmladek@suse.com>
1 parent d18d798 commit bf42df0

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

kernel/printk/printk_ringbuffer_kunit_test.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,17 @@ static int prbtest_reader(struct prbtest_data *test_data, unsigned long timeout_
223223
return 0;
224224
}
225225

226+
KUNIT_DEFINE_ACTION_WRAPPER(prbtest_cpumask_cleanup, free_cpumask_var, struct cpumask *);
226227
KUNIT_DEFINE_ACTION_WRAPPER(prbtest_kthread_cleanup, kthread_stop, struct task_struct *);
227228

229+
static void prbtest_add_cpumask_cleanup(struct kunit *test, cpumask_var_t mask)
230+
{
231+
int err;
232+
233+
err = kunit_add_action_or_reset(test, prbtest_cpumask_cleanup, mask);
234+
KUNIT_ASSERT_EQ(test, err, 0);
235+
}
236+
228237
static void prbtest_add_kthread_cleanup(struct kunit *test, struct task_struct *kthread)
229238
{
230239
int err;
@@ -247,25 +256,28 @@ static void test_readerwriter(struct kunit *test)
247256
struct prbtest_thread_data *thread_data;
248257
struct prbtest_data *test_data;
249258
struct task_struct *thread;
250-
cpumask_t test_cpus;
259+
cpumask_var_t test_cpus;
251260
int cpu, reader_cpu;
252261

262+
KUNIT_ASSERT_TRUE(test, alloc_cpumask_var(&test_cpus, GFP_KERNEL));
263+
prbtest_add_cpumask_cleanup(test, test_cpus);
264+
253265
cpus_read_lock();
254266
/*
255267
* Failure of KUNIT_ASSERT() kills the current task
256268
* so it can not be called while the CPU hotplug lock is held.
257269
* Instead use a snapshot of the online CPUs.
258270
* If they change during test execution it is unfortunate but not a grave error.
259271
*/
260-
cpumask_copy(&test_cpus, cpu_online_mask);
272+
cpumask_copy(test_cpus, cpu_online_mask);
261273
cpus_read_unlock();
262274

263275
/* One CPU is for the reader, all others are writers */
264-
reader_cpu = cpumask_first(&test_cpus);
265-
if (cpumask_weight(&test_cpus) == 1)
276+
reader_cpu = cpumask_first(test_cpus);
277+
if (cpumask_weight(test_cpus) == 1)
266278
kunit_warn(test, "more than one CPU is recommended");
267279
else
268-
cpumask_clear_cpu(reader_cpu, &test_cpus);
280+
cpumask_clear_cpu(reader_cpu, test_cpus);
269281

270282
/* KUnit test can get restarted more times. */
271283
prbtest_prb_reinit(&test_rb);
@@ -278,7 +290,7 @@ static void test_readerwriter(struct kunit *test)
278290

279291
kunit_info(test, "running for %lu ms\n", runtime_ms);
280292

281-
for_each_cpu(cpu, &test_cpus) {
293+
for_each_cpu(cpu, test_cpus) {
282294
thread_data = kunit_kmalloc(test, sizeof(*thread_data), GFP_KERNEL);
283295
KUNIT_ASSERT_NOT_NULL(test, thread_data);
284296
thread_data->test_data = test_data;

0 commit comments

Comments
 (0)