mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-07-23 14:27:37 -04:00
selftests/mm: protection_keys: use library code for HugeTLB setup
protection_keys open codes setup of HugeTLB pages. Replace it with the library functions from hugepage_setup. Replace exit() calls with _exit() to avoid restoring HugeTLB settings in the middle of test. Link: https://lore.kernel.org/20260511162840.375890-48-rppt@kernel.org Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Tested-by: Luiz Capitulino <luizcap@redhat.com> Cc: Baolin Wang <baolin.wang@linux.alibaba.com> Cc: Barry Song <baohua@kernel.org> Cc: David Hildenbrand <david@kernel.org> Cc: Dev Jain <dev.jain@arm.com> Cc: Donet Tom <donettom@linux.ibm.com> Cc: Jason Gunthorpe <jgg@ziepe.ca> Cc: John Hubbard <jhubbard@nvidia.com> Cc: Lance Yang <lance.yang@linux.dev> Cc: Leon Romanovsky <leon@kernel.org> Cc: Liam Howlett <liam@infradead.org> Cc: Li Wang <li.wang@linux.dev> Cc: Lorenzo Stoakes <ljs@kernel.org> Cc: Mark Brown <broonie@kernel.org> Cc: Michal Hocko <mhocko@suse.com> Cc: Nico Pache <npache@redhat.com> Cc: Peter Xu <peterx@redhat.com> Cc: Ryan Roberts <ryan.roberts@arm.com> Cc: Sarthak Sharma <sarthak.sharma@arm.com> Cc: Shuah Khan <shuah@kernel.org> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Vlastimil Babka <vbabka@kernel.org> Cc: Zi Yan <ziy@nvidia.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
committed by
Andrew Morton
parent
857f2f8169
commit
2535608189
@@ -62,6 +62,7 @@ noinline int read_ptr(int *ptr)
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
#if CONTROL_TRACING > 0
|
||||
static void cat_into_file(char *str, char *file)
|
||||
{
|
||||
int fd = open(file, O_RDWR);
|
||||
@@ -87,7 +88,6 @@ static void cat_into_file(char *str, char *file)
|
||||
close(fd);
|
||||
}
|
||||
|
||||
#if CONTROL_TRACING > 0
|
||||
static int warned_tracing;
|
||||
static int tracing_root_ok(void)
|
||||
{
|
||||
@@ -710,50 +710,28 @@ static void *malloc_pkey_anon_huge(long size, int prot, u16 pkey)
|
||||
}
|
||||
|
||||
static int hugetlb_setup_ok;
|
||||
#define SYSFS_FMT_NR_HUGE_PAGES "/sys/kernel/mm/hugepages/hugepages-%ldkB/nr_hugepages"
|
||||
#define GET_NR_HUGE_PAGES 10
|
||||
static void setup_hugetlbfs(void)
|
||||
{
|
||||
int err;
|
||||
int fd;
|
||||
char buf[256];
|
||||
long hpagesz_kb;
|
||||
long hpagesz_mb;
|
||||
long hpagesz_mb = HPAGE_SIZE / 1024 / 1024;
|
||||
unsigned long free_pages;
|
||||
|
||||
if (geteuid() != 0) {
|
||||
ksft_print_msg("WARNING: not run as root, can not do hugetlb test\n");
|
||||
return;
|
||||
}
|
||||
|
||||
cat_into_file(__stringify(GET_NR_HUGE_PAGES), "/proc/sys/vm/nr_hugepages");
|
||||
|
||||
/*
|
||||
* Now go make sure that we got the pages and that they
|
||||
* Make sure that we got the pages and that they
|
||||
* are PMD-level pages. Someone might have made PUD-level
|
||||
* pages the default.
|
||||
*/
|
||||
hpagesz_kb = HPAGE_SIZE / 1024;
|
||||
hpagesz_mb = hpagesz_kb / 1024;
|
||||
sprintf(buf, SYSFS_FMT_NR_HUGE_PAGES, hpagesz_kb);
|
||||
fd = open(buf, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "opening sysfs %ldM hugetlb config: %s\n",
|
||||
hpagesz_mb, strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
/* -1 to guarantee leaving the trailing \0 */
|
||||
err = read(fd, buf, sizeof(buf)-1);
|
||||
close(fd);
|
||||
if (err <= 0) {
|
||||
fprintf(stderr, "reading sysfs %ldM hugetlb config: %s\n",
|
||||
hpagesz_mb, strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
if (atoi(buf) != GET_NR_HUGE_PAGES) {
|
||||
fprintf(stderr, "could not confirm %ldM pages, got: '%s' expected %d\n",
|
||||
hpagesz_mb, buf, GET_NR_HUGE_PAGES);
|
||||
hugetlb_save_settings();
|
||||
hugetlb_set_nr_pages(HPAGE_SIZE, GET_NR_HUGE_PAGES);
|
||||
free_pages = hugetlb_free_pages(HPAGE_SIZE);
|
||||
if (free_pages < GET_NR_HUGE_PAGES) {
|
||||
ksft_print_msg("could not confirm %ldM pages, got: '%lu' expected %d\n",
|
||||
hpagesz_mb, free_pages, GET_NR_HUGE_PAGES);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1130,7 +1108,7 @@ static void become_child(void)
|
||||
/* in the child */
|
||||
return;
|
||||
}
|
||||
exit(0);
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
/* Assumes that all pkeys other than 'pkey' are unallocated */
|
||||
@@ -1509,18 +1487,18 @@ static void test_ptrace_modifies_pkru(int *ptr, u16 pkey)
|
||||
* checking
|
||||
*/
|
||||
if (__read_pkey_reg() != new_pkru)
|
||||
exit(1);
|
||||
_exit(1);
|
||||
|
||||
/* Stop and allow the tracer to clear XSTATE_BV for PKRU */
|
||||
raise(SIGSTOP);
|
||||
|
||||
if (__read_pkey_reg() != 0)
|
||||
exit(1);
|
||||
_exit(1);
|
||||
|
||||
/* Stop and allow the tracer to examine PKRU */
|
||||
raise(SIGSTOP);
|
||||
|
||||
exit(0);
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
pkey_assert(child == waitpid(child, &status, 0));
|
||||
|
||||
Reference in New Issue
Block a user