linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@kernel.org>
To: Marco Elver <elver@google.com>
Cc: mark.rutland@arm.com, dvyukov@google.com, glider@google.com,
	boqun.feng@gmail.com, kasan-dev@googlegroups.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] kcsan: selftest: Cleanup and add missing __init
Date: Fri, 13 Aug 2021 10:58:13 -0700	[thread overview]
Message-ID: <20210813175813.GC4126399@paulmck-ThinkPad-P17-Gen-1> (raw)
In-Reply-To: <20210813081055.3119894-1-elver@google.com>

On Fri, Aug 13, 2021 at 10:10:55AM +0200, Marco Elver wrote:
> Make test_encode_decode() more readable and add missing __init.
> 
> Signed-off-by: Marco Elver <elver@google.com>

Thank you!  I have queued and pushed this one as well as your previous
series:

https://lkml.kernel.org/r/20210813081055.3119894-1-elver@google.com

							Thanx, Paul

> ---
>  kernel/kcsan/selftest.c | 72 +++++++++++++++++------------------------
>  1 file changed, 30 insertions(+), 42 deletions(-)
> 
> diff --git a/kernel/kcsan/selftest.c b/kernel/kcsan/selftest.c
> index 7f29cb0f5e63..b4295a3892b7 100644
> --- a/kernel/kcsan/selftest.c
> +++ b/kernel/kcsan/selftest.c
> @@ -18,7 +18,7 @@
>  #define ITERS_PER_TEST 2000
>  
>  /* Test requirements. */
> -static bool test_requires(void)
> +static bool __init test_requires(void)
>  {
>  	/* random should be initialized for the below tests */
>  	return prandom_u32() + prandom_u32() != 0;
> @@ -28,14 +28,18 @@ static bool test_requires(void)
>   * Test watchpoint encode and decode: check that encoding some access's info,
>   * and then subsequent decode preserves the access's info.
>   */
> -static bool test_encode_decode(void)
> +static bool __init test_encode_decode(void)
>  {
>  	int i;
>  
>  	for (i = 0; i < ITERS_PER_TEST; ++i) {
>  		size_t size = prandom_u32_max(MAX_ENCODABLE_SIZE) + 1;
>  		bool is_write = !!prandom_u32_max(2);
> +		unsigned long verif_masked_addr;
> +		long encoded_watchpoint;
> +		bool verif_is_write;
>  		unsigned long addr;
> +		size_t verif_size;
>  
>  		prandom_bytes(&addr, sizeof(addr));
>  		if (addr < PAGE_SIZE)
> @@ -44,53 +48,37 @@ static bool test_encode_decode(void)
>  		if (WARN_ON(!check_encodable(addr, size)))
>  			return false;
>  
> -		/* Encode and decode */
> -		{
> -			const long encoded_watchpoint =
> -				encode_watchpoint(addr, size, is_write);
> -			unsigned long verif_masked_addr;
> -			size_t verif_size;
> -			bool verif_is_write;
> -
> -			/* Check special watchpoints */
> -			if (WARN_ON(decode_watchpoint(
> -				    INVALID_WATCHPOINT, &verif_masked_addr,
> -				    &verif_size, &verif_is_write)))
> -				return false;
> -			if (WARN_ON(decode_watchpoint(
> -				    CONSUMED_WATCHPOINT, &verif_masked_addr,
> -				    &verif_size, &verif_is_write)))
> -				return false;
> -
> -			/* Check decoding watchpoint returns same data */
> -			if (WARN_ON(!decode_watchpoint(
> -				    encoded_watchpoint, &verif_masked_addr,
> -				    &verif_size, &verif_is_write)))
> -				return false;
> -			if (WARN_ON(verif_masked_addr !=
> -				    (addr & WATCHPOINT_ADDR_MASK)))
> -				goto fail;
> -			if (WARN_ON(verif_size != size))
> -				goto fail;
> -			if (WARN_ON(is_write != verif_is_write))
> -				goto fail;
> -
> -			continue;
> -fail:
> -			pr_err("%s fail: %s %zu bytes @ %lx -> encoded: %lx -> %s %zu bytes @ %lx\n",
> -			       __func__, is_write ? "write" : "read", size,
> -			       addr, encoded_watchpoint,
> -			       verif_is_write ? "write" : "read", verif_size,
> -			       verif_masked_addr);
> +		encoded_watchpoint = encode_watchpoint(addr, size, is_write);
> +
> +		/* Check special watchpoints */
> +		if (WARN_ON(decode_watchpoint(INVALID_WATCHPOINT, &verif_masked_addr, &verif_size, &verif_is_write)))
>  			return false;
> -		}
> +		if (WARN_ON(decode_watchpoint(CONSUMED_WATCHPOINT, &verif_masked_addr, &verif_size, &verif_is_write)))
> +			return false;
> +
> +		/* Check decoding watchpoint returns same data */
> +		if (WARN_ON(!decode_watchpoint(encoded_watchpoint, &verif_masked_addr, &verif_size, &verif_is_write)))
> +			return false;
> +		if (WARN_ON(verif_masked_addr != (addr & WATCHPOINT_ADDR_MASK)))
> +			goto fail;
> +		if (WARN_ON(verif_size != size))
> +			goto fail;
> +		if (WARN_ON(is_write != verif_is_write))
> +			goto fail;
> +
> +		continue;
> +fail:
> +		pr_err("%s fail: %s %zu bytes @ %lx -> encoded: %lx -> %s %zu bytes @ %lx\n",
> +		       __func__, is_write ? "write" : "read", size, addr, encoded_watchpoint,
> +		       verif_is_write ? "write" : "read", verif_size, verif_masked_addr);
> +		return false;
>  	}
>  
>  	return true;
>  }
>  
>  /* Test access matching function. */
> -static bool test_matching_access(void)
> +static bool __init test_matching_access(void)
>  {
>  	if (WARN_ON(!matching_access(10, 1, 10, 1)))
>  		return false;
> -- 
> 2.33.0.rc1.237.g0d66db33f3-goog
> 

      reply	other threads:[~2021-08-13 17:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-13  8:10 [PATCH] kcsan: selftest: Cleanup and add missing __init Marco Elver
2021-08-13 17:58 ` Paul E. McKenney [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=20210813175813.GC4126399@paulmck-ThinkPad-P17-Gen-1 \
    --to=paulmck@kernel.org \
    --cc=boqun.feng@gmail.com \
    --cc=dvyukov@google.com \
    --cc=elver@google.com \
    --cc=glider@google.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).