Sashiko fixup for patch 3/8 This is largely an overly aggressive fix for systems with >1024 cpus, but it's simple enough and can just be squashed.
sched_getcpu() can return a CPU number at or above CPU_SETSIZE on large systems. CPU_SET() ignores such a number, so the fixed-size mask stays empty, sched_setaffinity() fails with EINVAL, and every test that pins itself fails. Size the mask to the CPU number with CPU_ALLOC() instead. Signed-off-by: Gregory Price (Meta) <[email protected]> --- tools/testing/selftests/mm/madvise.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/mm/madvise.c b/tools/testing/selftests/mm/madvise.c index d59c03ec8191..3f361bcf1039 100644 --- a/tools/testing/selftests/mm/madvise.c +++ b/tools/testing/selftests/mm/madvise.c @@ -224,12 +224,18 @@ static bool pageout_until_evicted(struct __test_metadata *_metadata, static void pin_to_current_cpu(struct __test_metadata *_metadata) { int cpu = sched_getcpu(); - cpu_set_t mask; + cpu_set_t *mask; + size_t size; ASSERT_GE(cpu, 0); - CPU_ZERO(&mask); - CPU_SET(cpu, &mask); - ASSERT_EQ(sched_setaffinity(0, sizeof(mask), &mask), 0); + /* CPU numbers can exceed CPU_SETSIZE, so size the mask to fit. */ + mask = CPU_ALLOC(cpu + 1); + ASSERT_NE(mask, NULL); + size = CPU_ALLOC_SIZE(cpu + 1); + CPU_ZERO_S(size, mask); + CPU_SET_S(cpu, size, mask); + ASSERT_EQ(sched_setaffinity(0, size, mask), 0); + CPU_FREE(mask); } static bool page_is_present(int pagemap_fd, char *addr) -- 2.56.0

