From: Cyril Hrubis <chrubis@suse.cz>
To: Samir Mulani <samir@linux.vnet.ibm.com>
Cc: rpalethorpe@suse.de, ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v3] Migrating the libhugetlbfs/testcases/stack_grow_into_huge.c test.
Date: Fri, 12 Apr 2024 13:28:25 +0200 [thread overview]
Message-ID: <Zhka2TEpvdMhiBNO@yuki> (raw)
In-Reply-To: <20240407102425.65452-1-samir@linux.vnet.ibm.com>
Hi!
> +#if defined(__powerpc__) || defined(__powerpc64__)
We have supported_archs array in the tst_test structure now so instead
of ifdefing out the whole test we should add:
.supported_archs = {"ppc", "ppc64", NULL},
> +#ifdef __LP64__
> +#define STACK_ALLOCATION_SIZE (256*1024*1024)
> +#else
> +#define STACK_ALLOCATION_SIZE (16*1024*1024)
> +#endif
> +#define PALIGN(p, a) ((void *)LTP_ALIGN((unsigned long)(p), (a)))
> +#define MNTPOINT "hugetlbfs/"
> +static int fd = -1;
> +static unsigned long long hpage_size;
> +static int page_size;
> +
> +
> +void do_child(void *stop_address)
> +{
> + struct rlimit r;
> + volatile int *x;
> +
> + /* corefile from this process is not interesting and limiting
> + * its size can save a lot of time. '1' is a special value,
> + * that will also abort dumping via pipe, which by default
> + * sets limit to RLIM_INFINITY.
> + */
> + r.rlim_cur = 1;
> + r.rlim_max = 1;
> + SAFE_SETRLIMIT(RLIMIT_CORE, &r);
> +
> + do {
> + x = alloca(STACK_ALLOCATION_SIZE);
> + *x = 1;
> + } while ((void *)x >= stop_address);
> +}
> +
> +static void run_test(void)
> +{
> + int pid, status;
> + void *stack_address, *mmap_address, *heap_address, *map;
> +
> + stack_address = alloca(0);
> + heap_address = sbrk(0);
> +
> + /*
> + * paranoia: start mapping two hugepages below the start of the stack,
> + * in case the alignment would cause us to map over something if we
> + * only used a gap of one hugepage.
> + */
> + mmap_address = PALIGN(stack_address - 2 * hpage_size, hpage_size);
> + do {
> + map = mmap(mmap_address, hpage_size, PROT_READ|PROT_WRITE,
> + MAP_SHARED | MAP_FIXED_NOREPLACE, fd, 0);
> + if (map == MAP_FAILED) {
> + if (errno == ENOMEM) {
> + tst_res(TCONF, "There is no enough memory in the system to do mmap");
> + exit(-1);
This should be just return;
> + }
> + }
> + mmap_address -= hpage_size;
> + /*
> + * if we get all the way down to the heap, stop trying
> + */
> + } while (mmap_address <= heap_address);
> + pid = SAFE_FORK();
> + if (pid == 0)
> + do_child(mmap_address);
> +
> + SAFE_WAITPID(pid, &status, 0);
> + if (WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV)
> + tst_res(TPASS, "Child killed by %s as expected", tst_strsig(SIGSEGV));
> + else
> + tst_res(TFAIL, "Child: %s", tst_strstatus(status));
> +}
> +
> +void setup(void)
> +{
> + struct rlimit r;
> +
> + page_size = getpagesize();
> + hpage_size = tst_get_hugepage_size();
> + /*
> + * Setting the stack size to unlimited.
> + */
> + r.rlim_cur = RLIM_INFINITY;
> + r.rlim_max = RLIM_INFINITY;
> + SAFE_SETRLIMIT(RLIMIT_STACK, &r);
> + SAFE_GETRLIMIT(RLIMIT_STACK, &r);
> + if (r.rlim_cur != RLIM_INFINITY)
> + tst_brk(TCONF, "Stack rlimit must be 'unlimited'");
> + fd = tst_creat_unlinked(MNTPOINT, 0);
> +}
> +
> +void cleanup(void)
> +{
> + if (fd > 0)
> + SAFE_CLOSE(fd);
> +}
> +
> +static struct tst_test test = {
> + .tags = (struct tst_tag[]) {
> + {"linux-git", "0d59a01bc461"},
> + {}
> + },
> + .needs_root = 1,
> + .mntpoint = MNTPOINT,
> + .needs_hugetlbfs = 1,
> + .needs_tmpdir = 1,
> + .setup = setup,
> + .cleanup = cleanup,
> + .test_all = run_test,
> + .hugepages = {1, TST_NEEDS},
> + .forks_child = 1,
> +};
> +#else
> +TST_TEST_TCONF("stack_grow_into_huge dosen't support on other architecture");
> +#endif
> --
> 2.43.0
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
prev parent reply other threads:[~2024-04-12 11:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-07 10:24 [LTP] [PATCH v3] Migrating the libhugetlbfs/testcases/stack_grow_into_huge.c test Samir Mulani
2024-04-12 11:28 ` Cyril Hrubis [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Zhka2TEpvdMhiBNO@yuki \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
--cc=rpalethorpe@suse.de \
--cc=samir@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.