Skip to contentSkip to conversation

kcsan: test: don't put the expect array on the stack

PATCH Superseded Max Filippov 2 participants 2 messages Dec 23, 2022 – Dec 28, 2022 KCSAN

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kcsan: test: don't put the expect array on the stack

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.

---
 kernel/kcsan/kcsan_test.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/kcsan/kcsan_test.c +6 -1
index dcec1b743c69..af62ec51bd5f 100644
@@ -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 (!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;
 }
 
Signature · 1 line
2.30.2
maintainer
#1 lore raw
Quoted 32 lines · 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.

---
 kernel/kcsan/kcsan_test.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/kcsan/kcsan_test.c +1 -1
index dcec1b743c69..af62ec51bd5f 100644
@@ -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;

kernel/kcsan/kcsan_test.c static bool __report_matches(const struct expect_report *r) · line 172

Quoted 5 lines
kernel/kcsan/kcsan_test.c +2 -0
@@ -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 (!expect)

WARN_ON(), because this may either spuriously fail or pass a test case, and we'd want to know about that.

Thanks,
-- Marco