From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 9/9] bthread: fix use of ASAN fiber stack switch API
Date: Mon, 25 Nov 2024 16:35:23 +0100 [thread overview]
Message-ID: <20241125153523.1411849-10-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20241125153523.1411849-1-a.fatoum@pengutronix.de>
We misused the fiber API so far and ASAN complained about it.
Fix this.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/bthread.c | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/common/bthread.c b/common/bthread.c
index 943f4c22b346..d8f1350f2e36 100644
--- a/common/bthread.c
+++ b/common/bthread.c
@@ -23,9 +23,6 @@ static struct bthread {
void *stack;
u32 stack_size;
struct list_head list;
-#ifdef CONFIG_ARCH_HAS_ASAN_FIBER_API
- void *fake_stack_save;
-#endif
u8 awake :1;
u8 should_stop :1;
u8 should_clean :1;
@@ -41,21 +38,21 @@ struct bthread *current = &main_thread;
/*
* When using ASAN, it needs to be told when we switch stacks.
*/
-static void bthread_finish_switch_fiber(struct bthread *bthread)
+static void bthread_finish_switch_fiber(void *stack_save)
{
- finish_switch_fiber(bthread->fake_stack_save,
+ finish_switch_fiber(stack_save,
&main_thread.stack, &main_thread.stack_size);
}
-static void bthread_start_switch_fiber(struct bthread *to, bool terminate_old)
+static void bthread_start_switch_fiber(void **stack_save)
{
- start_switch_fiber(terminate_old ? &to->fake_stack_save : NULL,
- to->stack, to->stack_size);
+ start_switch_fiber(stack_save,
+ current->stack, current->stack_size);
}
static void __noreturn bthread_trampoline(void)
{
- bthread_finish_switch_fiber(current);
+ bthread_finish_switch_fiber(NULL);
bthread_reschedule();
@@ -65,7 +62,7 @@ static void __noreturn bthread_trampoline(void)
current->has_stopped = true;
current = &main_thread;
- bthread_start_switch_fiber(current, true);
+ bthread_start_switch_fiber(NULL);
longjmp(current->jmp_buf, 1);
}
@@ -202,15 +199,15 @@ void bthread_reschedule(void)
void bthread_schedule(struct bthread *to)
{
struct bthread *from = current;
+ void *stack_save = NULL;
int ret;
- bthread_start_switch_fiber(to, false);
-
ret = setjmp(from->jmp_buf);
if (ret == 0) {
current = to;
+ bthread_start_switch_fiber(&stack_save);
longjmp(to->jmp_buf, 1);
}
- bthread_finish_switch_fiber(from);
+ bthread_finish_switch_fiber(stack_save);
}
--
2.39.5
prev parent reply other threads:[~2024-11-25 15:36 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-25 15:35 [PATCH 0/9] sandbox: use native setjmp/longjmp/initjmp implementation by default Ahmad Fatoum
2024-11-25 15:35 ` [PATCH 1/9] sandbox: asm: support inclusion from sandbox os support code Ahmad Fatoum
2024-11-25 15:35 ` [PATCH 2/9] test: self: setjmp: add simple initial testcase Ahmad Fatoum
2024-11-25 15:35 ` [PATCH 3/9] sandbox: source/invoke um Makefiles provided by host architecture Ahmad Fatoum
2024-11-25 15:35 ` [PATCH 4/9] sandbox: setjmp: mark C version as __weak Ahmad Fatoum
2024-11-25 15:35 ` [PATCH 5/9] sandbox: use native setjmp/longjmp/initjmp implementation by default Ahmad Fatoum
2024-11-25 15:35 ` [PATCH 6/9] sandbox: retire HAVE_ARCH_ASAN Ahmad Fatoum
2024-11-25 15:35 ` [PATCH 7/9] bthread: move asan fiber API into header Ahmad Fatoum
2024-11-25 15:35 ` [PATCH 8/9] test: self: setjmp: make compatible with ASAN Ahmad Fatoum
2024-11-25 15:35 ` Ahmad Fatoum [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=20241125153523.1411849-10-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.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