Re: [PATCH 1/2] selftests/mm: reuse FORCE_READ to replace "asm volatile("" : "+r" (XXX));"

From: Zi Yan
Date: Fri Jul 18 2025 - 11:11:40 EST


On 17 Jul 2025, at 9:18, wang lian wrote:

> Several mm selftests use the `asm volatile("" : "+r" (variable));`
> construct to force a read of a variable, preventing the compiler from
> optimizing away the memory access. This idiom is cryptic and duplicated
> across multiple test files.
>
> Following a suggestion from David[1], this patch refactors this
> common pattern into a FORCE_READ() macro
>
> [1] https://lore.kernel.org/lkml/4a3e0759-caa1-4cfa-bc3f-402593f1eee3@xxxxxxxxxx/
>
> Signed-off-by: wang lian <lianux.mm@xxxxxxxxx>
> Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@xxxxxxxxxx>
> ---
> tools/testing/selftests/mm/cow.c | 30 +++++++++----------
> tools/testing/selftests/mm/guard-regions.c | 7 -----
> tools/testing/selftests/mm/hugetlb-madvise.c | 5 +---
> tools/testing/selftests/mm/migration.c | 13 ++++----
> tools/testing/selftests/mm/pagemap_ioctl.c | 4 +--
> .../selftests/mm/split_huge_page_test.c | 4 +--
> tools/testing/selftests/mm/vm_util.h | 7 +++++
> 7 files changed, 31 insertions(+), 39 deletions(-)

Reviewed-by: Zi Yan <ziy@xxxxxxxxxx>
Best Regards,
Yan, Zi