linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] kcsan: test: don't put the expect array on the stack
@ 2022-12-31  0:45 Max Filippov
  2023-01-02  7:00 ` Marco Elver
  0 siblings, 1 reply; 3+ messages in thread
From: Max Filippov @ 2022-12-31  0:45 UTC (permalink / raw)
  To: Marco Elver
  Cc: Dmitry Vyukov, kasan-dev, linux-kernel, linux-xtensa, Max Filippov

Size of the 'expect' array in the __report_matches is 1536 bytes, which
is exactly the default frame size warning limit of the xtensa
architecture.
As a result allmodconfig xtensa kernel builds with the gcc that does not
support the compiler plugins (which otherwise would push the said
warning limit to 2K) fail with the following message:

  kernel/kcsan/kcsan_test.c:257:1: error: the frame size of 1680 bytes
    is larger than 1536 bytes

Fix it by dynamically alocating the 'expect' array.

Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
---
Changes v1->v2:
- add WARN_ON in case of kmalloc failure

 kernel/kcsan/kcsan_test.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/kernel/kcsan/kcsan_test.c b/kernel/kcsan/kcsan_test.c
index dcec1b743c69..a60c561724be 100644
--- a/kernel/kcsan/kcsan_test.c
+++ b/kernel/kcsan/kcsan_test.c
@@ -159,7 +159,7 @@ static bool __report_matches(const struct expect_report *r)
 	const bool is_assert = (r->access[0].type | r->access[1].type) & KCSAN_ACCESS_ASSERT;
 	bool ret = false;
 	unsigned long flags;
-	typeof(observed.lines) expect;
+	typeof(*observed.lines) *expect;
 	const char *end;
 	char *cur;
 	int i;
@@ -168,6 +168,10 @@ static bool __report_matches(const struct expect_report *r)
 	if (!report_available())
 		return false;
 
+	expect = kmalloc(sizeof(observed.lines), GFP_KERNEL);
+	if (WARN_ON(!expect))
+		return false;
+
 	/* Generate expected report contents. */
 
 	/* Title */
@@ -253,6 +257,7 @@ static bool __report_matches(const struct expect_report *r)
 		strstr(observed.lines[2], expect[1])));
 out:
 	spin_unlock_irqrestore(&observed.lock, flags);
+	kfree(expect);
 	return ret;
 }
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] kcsan: test: don't put the expect array on the stack
  2022-12-31  0:45 [PATCH v2] kcsan: test: don't put the expect array on the stack Max Filippov
@ 2023-01-02  7:00 ` Marco Elver
  2023-01-02 16:56   ` Max Filippov
  0 siblings, 1 reply; 3+ messages in thread
From: Marco Elver @ 2023-01-02  7:00 UTC (permalink / raw)
  To: Max Filippov; +Cc: Dmitry Vyukov, kasan-dev, linux-kernel, linux-xtensa

On Sat, 31 Dec 2022 at 01:45, Max Filippov <jcmvbkbc@gmail.com> wrote:
>
> Size of the 'expect' array in the __report_matches is 1536 bytes, which
> is exactly the default frame size warning limit of the xtensa
> architecture.
> As a result allmodconfig xtensa kernel builds with the gcc that does not
> support the compiler plugins (which otherwise would push the said
> warning limit to 2K) fail with the following message:
>
>   kernel/kcsan/kcsan_test.c:257:1: error: the frame size of 1680 bytes
>     is larger than 1536 bytes
>
> Fix it by dynamically alocating the 'expect' array.
>
> Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>

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

Can you take this through the xtensa tree?

> ---
> Changes v1->v2:
> - add WARN_ON in case of kmalloc failure
>
>  kernel/kcsan/kcsan_test.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/kcsan/kcsan_test.c b/kernel/kcsan/kcsan_test.c
> index dcec1b743c69..a60c561724be 100644
> --- a/kernel/kcsan/kcsan_test.c
> +++ b/kernel/kcsan/kcsan_test.c
> @@ -159,7 +159,7 @@ static bool __report_matches(const struct expect_report *r)
>         const bool is_assert = (r->access[0].type | r->access[1].type) & KCSAN_ACCESS_ASSERT;
>         bool ret = false;
>         unsigned long flags;
> -       typeof(observed.lines) expect;
> +       typeof(*observed.lines) *expect;
>         const char *end;
>         char *cur;
>         int i;
> @@ -168,6 +168,10 @@ static bool __report_matches(const struct expect_report *r)
>         if (!report_available())
>                 return false;
>
> +       expect = kmalloc(sizeof(observed.lines), GFP_KERNEL);
> +       if (WARN_ON(!expect))
> +               return false;
> +
>         /* Generate expected report contents. */
>
>         /* Title */
> @@ -253,6 +257,7 @@ static bool __report_matches(const struct expect_report *r)
>                 strstr(observed.lines[2], expect[1])));
>  out:
>         spin_unlock_irqrestore(&observed.lock, flags);
> +       kfree(expect);
>         return ret;
>  }
>
> --
> 2.30.2
>
> --
> You received this message because you are subscribed to the Google Groups "kasan-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kasan-dev+unsubscribe@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/20221231004514.317809-1-jcmvbkbc%40gmail.com.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] kcsan: test: don't put the expect array on the stack
  2023-01-02  7:00 ` Marco Elver
@ 2023-01-02 16:56   ` Max Filippov
  0 siblings, 0 replies; 3+ messages in thread
From: Max Filippov @ 2023-01-02 16:56 UTC (permalink / raw)
  To: Marco Elver; +Cc: Dmitry Vyukov, kasan-dev, linux-kernel, linux-xtensa

On Sun, Jan 1, 2023 at 11:00 PM Marco Elver <elver@google.com> wrote:
>
> On Sat, 31 Dec 2022 at 01:45, Max Filippov <jcmvbkbc@gmail.com> wrote:
> >
> > Size of the 'expect' array in the __report_matches is 1536 bytes, which
> > is exactly the default frame size warning limit of the xtensa
> > architecture.
> > As a result allmodconfig xtensa kernel builds with the gcc that does not
> > support the compiler plugins (which otherwise would push the said
> > warning limit to 2K) fail with the following message:
> >
> >   kernel/kcsan/kcsan_test.c:257:1: error: the frame size of 1680 bytes
> >     is larger than 1536 bytes
> >
> > Fix it by dynamically alocating the 'expect' array.
> >
> > Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
>
> Reviewed-by: Marco Elver <elver@google.com>
> Tested-by: Marco Elver <elver@google.com>
>
> Can you take this through the xtensa tree?

Sure. Thanks for your review and testing.

-- Max

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-01-02 16:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-31  0:45 [PATCH v2] kcsan: test: don't put the expect array on the stack Max Filippov
2023-01-02  7:00 ` Marco Elver
2023-01-02 16:56   ` Max Filippov

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).