From: Jeff Xu <jeffxu@chromium.org>
To: Pedro Falcato <pedro.falcato@gmail.com>
Cc: akpm@linux-foundation.org, linux-kselftest@vger.kernel.org,
linux-mm@kvack.org, linux-hardening@vger.kernel.org,
linux-kernel@vger.kernel.org, willy@infradead.org,
lorenzo.stoakes@oracle.com, broonie@kernel.org, vbabka@suse.cz,
Liam.Howlett@oracle.com, rientjes@google.com,
keescook@chromium.org
Subject: Re: [PATCH v2 2/4] selftests/mm: mseal_test add sealed madvise type
Date: Fri, 30 Aug 2024 08:46:41 -0700 [thread overview]
Message-ID: <CABi2SkUESzc6yjf5TbfZM7gHDcx4wXC5R8+xtqgYZAmY1fm64A@mail.gmail.com> (raw)
In-Reply-To: <ggnces6muodr4q27yuprhyhjovn7vlaj4pdnmte44kg2of62sx@ihwlrb52hsmm>
On Fri, Aug 30, 2024 at 5:52 AM Pedro Falcato <pedro.falcato@gmail.com> wrote:
>
> On Thu, Aug 29, 2024 at 09:43:50PM GMT, jeffxu@chromium.org wrote:
> > From: Jeff Xu <jeffxu@chromium.org>
> >
> > Add a testcase to cover all sealed madvise type.
> >
> > Signed-off-by: Jeff Xu <jeffxu@chromium.org>
> > ---
> > tools/testing/selftests/mm/mseal_test.c | 108 +++++++++++++++++++++++-
> > 1 file changed, 107 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/testing/selftests/mm/mseal_test.c b/tools/testing/selftests/mm/mseal_test.c
> > index adc646cf576c..ae06c354220d 100644
> > --- a/tools/testing/selftests/mm/mseal_test.c
> > +++ b/tools/testing/selftests/mm/mseal_test.c
> > @@ -2121,6 +2121,107 @@ static void test_seal_madvise_nodiscard(bool seal)
> > REPORT_TEST_PASS();
> > }
> >
> > +static void test_seal_discard_madvise_advice(void)
> > +{
> > + void *ptr;
> > + unsigned long page_size = getpagesize();
> > + unsigned long size = 4 * page_size;
> > + int ret;
> > + int sealed_advice[] = {MADV_FREE, MADV_DONTNEED,
> > + MADV_DONTNEED_LOCKED, MADV_REMOVE,
> > + MADV_DONTFORK, MADV_WIPEONFORK};
> > + int size_sealed_advice = sizeof(sealed_advice) / sizeof(int);
> > +
> > + setup_single_address(size, &ptr);
> > + FAIL_TEST_IF_FALSE(ptr != (void *)-1);
> > +
> > + ret = seal_single_address(ptr, size);
> > + FAIL_TEST_IF_FALSE(!ret);
> > +
> > + for (int i = 0; i < size_sealed_advice; i++) {
> > + ret = sys_madvise(ptr, size, sealed_advice[i]);
> > + FAIL_TEST_IF_FALSE(ret < 0);
> > + FAIL_TEST_IF_FALSE(errno == EPERM);
> > + }
> > +
> > + REPORT_TEST_PASS();
> > +}
>
> This can replace some of the other 9 discard tests already there, no?
>
No, this is focused on enumerating all types.
> > +
> > +static void test_munmap_free_multiple_ranges(bool seal)
> > +{
> > + void *ptr;
> > + unsigned long page_size = getpagesize();
> > + unsigned long size = 8 * page_size;
> > + int ret;
> > + int prot;
> > +
> > + setup_single_address(size, &ptr);
> > + FAIL_TEST_IF_FALSE(ptr != (void *)-1);
> > +
> > + /* unmap one page from beginning. */
> > + ret = sys_munmap(ptr, page_size);
> > + FAIL_TEST_IF_FALSE(!ret);
> > +
> > + /* unmap one page from middle. */
> > + ret = sys_munmap(ptr + 4 * page_size, page_size);
> > + FAIL_TEST_IF_FALSE(!ret);
> > +
> > + size = get_vma_size(ptr + page_size, &prot);
> > + FAIL_TEST_IF_FALSE(size == 3 * page_size);
> > + FAIL_TEST_IF_FALSE(prot == 4);
> > +
> > + size = get_vma_size(ptr + 5 * page_size, &prot);
> > + FAIL_TEST_IF_FALSE(size == 3 * page_size);
> > + FAIL_TEST_IF_FALSE(prot == 4);
> > +
> > +
> > + /* seal the last page */
> > + if (seal) {
> > + ret = sys_mseal(ptr + 7 * page_size, page_size);
> > + FAIL_TEST_IF_FALSE(!ret);
> > +
> > + size = get_vma_size(ptr + 1 * page_size, &prot);
> > + FAIL_TEST_IF_FALSE(size == 3 * page_size);
> > + FAIL_TEST_IF_FALSE(prot == 4);
> > +
> > + size = get_vma_size(ptr + 5 * page_size, &prot);
> > + FAIL_TEST_IF_FALSE(size == 2 * page_size);
> > + FAIL_TEST_IF_FALSE(prot == 4);
> > +
> > + size = get_vma_size(ptr + 7 * page_size, &prot);
> > + FAIL_TEST_IF_FALSE(size == 1 * page_size);
> > + FAIL_TEST_IF_FALSE(prot == 4);
> > + }
> > +
> > + /* munmap all 8 pages from beginning */
> > + ret = sys_munmap(ptr, 8 * page_size);
> > + if (seal) {
> > + FAIL_TEST_IF_FALSE(ret);
> > +
> > + /* verify mapping are not changed */
> > + size = get_vma_size(ptr + 1 * page_size, &prot);
> > + FAIL_TEST_IF_FALSE(size == 3 * page_size);
> > + FAIL_TEST_IF_FALSE(prot == 4);
> > +
> > + size = get_vma_size(ptr + 5 * page_size, &prot);
> > + FAIL_TEST_IF_FALSE(size == 2 * page_size);
> > + FAIL_TEST_IF_FALSE(prot == 4);
> > +
> > + size = get_vma_size(ptr + 7 * page_size, &prot);
> > + FAIL_TEST_IF_FALSE(size == 1 * page_size);
> > + FAIL_TEST_IF_FALSE(prot == 4);
> > + } else {
> > + FAIL_TEST_IF_FALSE(!ret);
> > +
> > + for (int i = 0; i < 8; i++) {
> > + size = get_vma_size(ptr, &prot);
> > + FAIL_TEST_IF_FALSE(size == 0);
> > + }
> > + }
> > +
> > + REPORT_TEST_PASS();
> > +}
>
> Unrelated munmap change.
will move.
>
> --
> Pedro
next prev parent reply other threads:[~2024-08-30 15:46 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-29 21:43 [PATCH v2 0/4] Increase mseal test coverage jeffxu
2024-08-29 21:43 ` [PATCH v2 1/4] selftests/mm: mseal_test, add vma size check jeffxu
2024-08-30 12:45 ` Pedro Falcato
2024-08-30 15:45 ` Jeff Xu
2024-08-29 21:43 ` [PATCH v2 2/4] selftests/mm: mseal_test add sealed madvise type jeffxu
2024-08-30 12:52 ` Pedro Falcato
2024-08-30 15:46 ` Jeff Xu [this message]
2024-08-29 21:43 ` [PATCH v2 3/4] selftests/mm: mseal_test add more tests for mmap jeffxu
2024-08-30 12:57 ` Pedro Falcato
2024-08-30 15:52 ` Jeff Xu
2024-08-29 21:43 ` [PATCH v2 4/4] selftests/mm: mseal_test add more tests for mremap jeffxu
2024-08-30 12:31 ` [PATCH v2 0/4] Increase mseal test coverage Pedro Falcato
2024-08-30 15:38 ` Jeff Xu
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=CABi2SkUESzc6yjf5TbfZM7gHDcx4wXC5R8+xtqgYZAmY1fm64A@mail.gmail.com \
--to=jeffxu@chromium.org \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=broonie@kernel.org \
--cc=keescook@chromium.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=pedro.falcato@gmail.com \
--cc=rientjes@google.com \
--cc=vbabka@suse.cz \
--cc=willy@infradead.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox