mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-31 14:04:27 -04:00
selftests/mm: thuge-gen: fix test_shmget() for PAGE_SIZE check
Commit49a4e7186b("selftests/mm: thuge-gen: add setup of HugeTLB pages") changed thuge-gen test to use common functions for reading hugetlb attributes from sysfs, but it missed that the original read_free() function special cased PAGE_SIZE tests. For PAGE_SIZE tests, failure to read sysfs was ignored and read_free() returned 0. This allowed test_shmget() to essentially skip the check of how many huge pages was consumed when it ran with PAGE_SIZE. Commit 3199b0c09efa ("selftests/mm: fix read_file() return value check") fixed checks for read_file() return value and this exposed the issue in test_shmget() that checks the number of free hugetlb pages even for PAGE_SIZE test, tries to access /sys/kernel/mm/hugepages/hugepages-<PAGE_SIZE>/free_hugepages and obviously fails there. Gate the checks for free huge pages on size != getpagesize() and initialize before and after variables to values matching PAGE_SIZE test. Link: https://lore.kernel.org/20260812-selftests-thuge-gen-fix-v2-1-9adaa693e73b@kernel.org Fixes:49a4e7186b("selftests/mm: thuge-gen: add setup of HugeTLB pages") Acked-by: David Hildenbrand (Arm) <david@kernel.org> Reviewed-by: Sarthak Sharma <sarthak.sharma@arm.com> Acked-by: Lorenzo Stoakes (ARM) <ljs@kernel.org> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Cc: Liam R. Howlett <liam@infradead.org> Cc: Michal Hocko <mhocko@suse.com> Cc: Shuah Khan <shuah@kernel.org> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Vlastimil Babka <vbabka@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
committed by
Andrew Morton
parent
288058d8db
commit
08745c6235
@@ -71,12 +71,16 @@ void test_mmap(unsigned long size, unsigned flags)
|
||||
|
||||
void test_shmget(unsigned long size, unsigned flags)
|
||||
{
|
||||
int id;
|
||||
unsigned long before, after;
|
||||
/* values for PAGE_SIZE test */
|
||||
unsigned long before = NUM_PAGES;
|
||||
unsigned long after = 0;
|
||||
struct shm_info i;
|
||||
char *map;
|
||||
int id;
|
||||
|
||||
if (size != getpagesize())
|
||||
before = hugetlb_free_pages(size);
|
||||
|
||||
before = hugetlb_free_pages(size);
|
||||
id = shmget(IPC_PRIVATE, size * NUM_PAGES, IPC_CREAT|0600|flags);
|
||||
if (id < 0) {
|
||||
if (errno == EPERM) {
|
||||
@@ -97,10 +101,11 @@ void test_shmget(unsigned long size, unsigned flags)
|
||||
shmctl(id, IPC_RMID, NULL);
|
||||
|
||||
memset(map, 0xff, size*NUM_PAGES);
|
||||
after = hugetlb_free_pages(size);
|
||||
if (size != getpagesize())
|
||||
after = hugetlb_free_pages(size);
|
||||
|
||||
show(size);
|
||||
ksft_test_result(size == getpagesize() || (before - after) == NUM_PAGES,
|
||||
ksft_test_result((before - after) == NUM_PAGES,
|
||||
"%s: mmap %lu %x\n", __func__, size, flags);
|
||||
if (shmdt(map))
|
||||
ksft_exit_fail_msg("%s: shmdt: %s\n", __func__, strerror(errno));
|
||||
|
||||
Reference in New Issue
Block a user