linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Marco Elver <elver@google.com>
To: Alexander Potapenko <glider@google.com>
Cc: dvyukov@google.com, akpm@linux-foundation.org,
	linux-mm@kvack.org,  linux-kernel@vger.kernel.org,
	kasan-dev@googlegroups.com
Subject: Re: [PATCH v2 3/4] kmsan: merge test_memcpy_aligned_to_unaligned{,2}() together
Date: Mon, 11 Sep 2023 17:06:42 +0200	[thread overview]
Message-ID: <CANpmjNP61zOdXR=FYjtzUqcjxg=j_Otqotqv_OTN_Hi2E-LXLg@mail.gmail.com> (raw)
In-Reply-To: <20230911145702.2663753-3-glider@google.com>

On Mon, 11 Sept 2023 at 16:57, Alexander Potapenko <glider@google.com> wrote:
>
> Introduce report_reset() that allows checking for more than one KMSAN
> report per testcase.
> Fold test_memcpy_aligned_to_unaligned2() into
> test_memcpy_aligned_to_unaligned(), so that they share the setup phase
> and check the behavior of a single memcpy() call.
>
> Signed-off-by: Alexander Potapenko <glider@google.com>

Acked-by: Marco Elver <elver@google.com>

> ---
>  mm/kmsan/kmsan_test.c | 37 +++++++++++++------------------------
>  1 file changed, 13 insertions(+), 24 deletions(-)
>
> diff --git a/mm/kmsan/kmsan_test.c b/mm/kmsan/kmsan_test.c
> index a8d4ca4a1066d..6eb1e1a4d08f9 100644
> --- a/mm/kmsan/kmsan_test.c
> +++ b/mm/kmsan/kmsan_test.c
> @@ -67,6 +67,17 @@ static bool report_available(void)
>         return READ_ONCE(observed.available);
>  }
>
> +/* Reset observed.available, so that the test can trigger another report. */
> +static void report_reset(void)
> +{
> +       unsigned long flags;
> +
> +       spin_lock_irqsave(&observed.lock, flags);
> +       WRITE_ONCE(observed.available, false);
> +       observed.ignore = false;
> +       spin_unlock_irqrestore(&observed.lock, flags);
> +}
> +
>  /* Information we expect in a report. */
>  struct expect_report {
>         const char *error_type; /* Error type. */
> @@ -454,7 +465,7 @@ static void test_memcpy_aligned_to_aligned(struct kunit *test)
>   *
>   * Copying aligned 4-byte value to an unaligned one leads to touching two
>   * aligned 4-byte values. This test case checks that KMSAN correctly reports an
> - * error on the first of the two values.
> + * error on the mentioned two values.
>   */
>  static void test_memcpy_aligned_to_unaligned(struct kunit *test)
>  {
> @@ -470,28 +481,7 @@ static void test_memcpy_aligned_to_unaligned(struct kunit *test)
>                         sizeof(uninit_src));
>         kmsan_check_memory((void *)dst, 4);
>         KUNIT_EXPECT_TRUE(test, report_matches(&expect));
> -}
> -
> -/*
> - * Test case: ensure that memcpy() correctly copies uninitialized values between
> - * aligned `src` and unaligned `dst`.
> - *
> - * Copying aligned 4-byte value to an unaligned one leads to touching two
> - * aligned 4-byte values. This test case checks that KMSAN correctly reports an
> - * error on the second of the two values.
> - */
> -static void test_memcpy_aligned_to_unaligned2(struct kunit *test)
> -{
> -       EXPECTATION_UNINIT_VALUE_FN(expect,
> -                                   "test_memcpy_aligned_to_unaligned2");
> -       volatile int uninit_src;
> -       volatile char dst[8] = { 0 };
> -
> -       kunit_info(
> -               test,
> -               "memcpy()ing aligned uninit src to unaligned dst - part 2 (UMR report)\n");
> -       memcpy_noinline((void *)&dst[1], (void *)&uninit_src,
> -                       sizeof(uninit_src));
> +       report_reset();
>         kmsan_check_memory((void *)&dst[4], sizeof(uninit_src));
>         KUNIT_EXPECT_TRUE(test, report_matches(&expect));
>  }
> @@ -589,7 +579,6 @@ static struct kunit_case kmsan_test_cases[] = {
>         KUNIT_CASE(test_init_memcpy),
>         KUNIT_CASE(test_memcpy_aligned_to_aligned),
>         KUNIT_CASE(test_memcpy_aligned_to_unaligned),
> -       KUNIT_CASE(test_memcpy_aligned_to_unaligned2),
>         KUNIT_CASE(test_memset16),
>         KUNIT_CASE(test_memset32),
>         KUNIT_CASE(test_memset64),
> --
> 2.42.0.283.g2d96d420d3-goog
>


  reply	other threads:[~2023-09-11 15:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-11 14:56 [PATCH v2 1/4] kmsan: simplify kmsan_internal_memmove_metadata() Alexander Potapenko
2023-09-11 14:57 ` [PATCH v2 2/4] kmsan: prevent optimizations in memcpy tests Alexander Potapenko
2023-09-11 15:07   ` Marco Elver
2023-09-11 14:57 ` [PATCH v2 3/4] kmsan: merge test_memcpy_aligned_to_unaligned{,2}() together Alexander Potapenko
2023-09-11 15:06   ` Marco Elver [this message]
2023-09-11 14:57 ` [PATCH v2 4/4] kmsan: introduce test_memcpy_initialized_gap() Alexander Potapenko
2023-09-11 15:06   ` Marco Elver

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='CANpmjNP61zOdXR=FYjtzUqcjxg=j_Otqotqv_OTN_Hi2E-LXLg@mail.gmail.com' \
    --to=elver@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=dvyukov@google.com \
    --cc=glider@google.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.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