From: Philippe Gerum <rpm@xenomai.org>
To: Jan Kiszka <jan.kiszka@siemens.com>
Cc: Florian Bezdeka <florian.bezdeka@siemens.com>, xenomai@xenomai.org
Subject: Re: [dovetail][PATCH v2 1/4] dovetail: Track the owner of a trap notification by exception frame
Date: Thu, 19 Nov 2026 19:29:32 +0100 [thread overview]
Message-ID: <87h5hcoesz.fsf@xenomai.org> (raw)
In-Reply-To: <576b2607-3fb6-4aa7-b96f-e76ac2f542c1@siemens.com> (Jan Kiszka's message of "Thu, 19 Nov 2026 17:52:59 +0100")
Jan Kiszka <jan.kiszka@siemens.com> writes:
> On 11.11.26 13:10, Jan Kiszka wrote:
>> From: Jan Kiszka <jan.kiszka@siemens.com>
>>
>> Trap notifications are guarded by _TLF_OOBTRAP: oob_trap_notify() only
>> calls into the companion core if the flag is clear, and sets it;
>> oob_trap_unwind() calls the exit handler and clears the flag whenever
>> it is set.
>>
>> This does not cope with nested traps. A trap handler running on behalf
>> of an oob thread may trigger another trap before it reaches its own
>> exit annotation, e.g. a user access from an emulation handler faulting
>> in a not yet resident page on ARM:
>>
>> do_alignment() <- notify, _TLF_OOBTRAP set
>> do_alignment_ldmstm()
>> ldrt/strt to user address <- translation fault (SVC mode)
>> do_DataAbort()
>> do_page_fault()
>> dovetail_fault_entry() <- notify suppressed, fine
>> handle_mm_fault()
>> dovetail_fault_exit() <- unwind fires: wrong trap number,
>> wrong frame, and the core may
>> switch us back to oob
>> ...emulation continues oob...
>> dovetail_fault_exit() <- no-op, flag already clear
>>
>> Since _TLF_OOBTRAP is per-thread and the thread does not change across
>> nesting levels, the flag alone cannot tell which trap occurrence owns
>> the notification. The exception frame can: every nesting level pushes
>> its own pt_regs on the kernel stack, and the frame is already passed
>> to both the notify and unwind helpers.
>>
>> Record the owning frame in the task struct when notifying, and only
>> unwind when the frame passed to oob_trap_unwind() matches. Inner trap
>> exits become no-ops, the outer exit unwinds with the trap number and
>> frame the core was notified with. oob_trap_regs can in fact encode the
>> semantic of the _TLF_OOBTRAP flag, thus drop it.
>>
>> A forking parent can never be inside a trap handler, so neither the
>> flag nor the owner frame can legitimately be set when a new task
>> inherits its state. Add a debug assertion for this in
>> inband_task_init(), which turns an unbalanced trap entry into a
>> loud warning on the next fork instead of silently propagating the
>> stuck state to the children.
>>
>> Assisted-by: opencode:Fable-5.1
>> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
>> ---
>> arch/arm/include/asm/thread_info.h | 1 -
>> arch/arm64/include/asm/thread_info.h | 1 -
>> arch/riscv/include/asm/thread_info.h | 1 -
>> arch/x86/include/asm/thread_info.h | 2 --
>> include/linux/dovetail.h | 12 ++++++++++--
>> include/linux/sched.h | 5 +++++
>> kernel/dovetail.c | 10 ++++++++--
>> 7 files changed, 23 insertions(+), 9 deletions(-)
>>
>> diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
>> index 23cae59037c1e..12ab7e49b7b76 100644
>> --- a/arch/arm/include/asm/thread_info.h
>> +++ b/arch/arm/include/asm/thread_info.h
>> @@ -196,7 +196,6 @@ extern int vfp_restore_user_hwstate(struct user_vfp *,
>> #define _TLF_OOB 0x0001
>> #define _TLF_DOVETAIL 0x0002
>> #define _TLF_OFFSTAGE 0x0004
>> -#define _TLF_OOBTRAP 0x0008
>>
>> #endif /* __KERNEL__ */
>> #endif /* __ASM_ARM_THREAD_INFO_H */
>> diff --git a/arch/arm64/include/asm/thread_info.h b/arch/arm64/include/asm/thread_info.h
>> index 48563d782a99a..934b080246146 100644
>> --- a/arch/arm64/include/asm/thread_info.h
>> +++ b/arch/arm64/include/asm/thread_info.h
>> @@ -144,7 +144,6 @@ void arch_setup_new_exec(void);
>> #define _TLF_OOB 0x0001
>> #define _TLF_DOVETAIL 0x0002
>> #define _TLF_OFFSTAGE 0x0004
>> -#define _TLF_OOBTRAP 0x0008
>> #define _TLF_KERNEL_FPU_PREEMPTED 0x0010 /* Dovetail: kernel mode FPSIMD section preempted by OOB */
>>
>> #endif /* __ASM_THREAD_INFO_H */
>> diff --git a/arch/riscv/include/asm/thread_info.h b/arch/riscv/include/asm/thread_info.h
>> index 820a596d9bf65..11164e12317fa 100644
>> --- a/arch/riscv/include/asm/thread_info.h
>> +++ b/arch/riscv/include/asm/thread_info.h
>> @@ -140,6 +140,5 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
>> #define _TLF_OOB 0x0001
>> #define _TLF_DOVETAIL 0x0002
>> #define _TLF_OFFSTAGE 0x0004
>> -#define _TLF_OOBTRAP 0x0008
>>
>> #endif /* _ASM_RISCV_THREAD_INFO_H */
>
> This hunk was forgotten while merging the patch.
>
> Jan
Not sure how that can ever happen since I'm applying patches with mu4e
directly from the MUA (mu4e-action-git-apply-mbox). Anyway, ... fixed.
--
Philippe.
next prev parent reply other threads:[~2026-11-19 18:29 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 12:10 [dovetail][PATCH v2 0/4] ARM trap fixes and generic handling of trap nesting Jan Kiszka
2026-11-11 12:10 ` [dovetail][PATCH v2 1/4] dovetail: Track the owner of a trap notification by exception frame Jan Kiszka
2026-11-11 23:11 ` Florian Bezdeka
2026-11-19 16:52 ` Jan Kiszka
2026-11-19 18:29 ` Philippe Gerum [this message]
2026-11-20 6:24 ` Jan Kiszka
2026-11-20 9:13 ` Philippe Gerum
2026-11-20 9:24 ` Philippe Gerum
2026-11-20 10:45 ` Jan Kiszka
2026-11-20 11:03 ` Philippe Gerum
2026-11-11 12:10 ` [dovetail][PATCH v2 2/4] ARM: dovetail: Fix trap unwind condition in __und_svc Jan Kiszka
2026-11-11 12:10 ` [dovetail][PATCH v2 3/4] ARM: dovetail: Notify the core about undefined instruction traps from user mode Jan Kiszka
2026-11-11 12:10 ` [dovetail][PATCH v2 4/4] ARM: dovetail: Fix VFP exception trap notification Jan Kiszka
2026-11-11 23:21 ` [dovetail][PATCH v2 0/4] ARM trap fixes and generic handling of trap nesting Florian Bezdeka
2026-11-12 6:11 ` Jan Kiszka
2026-11-12 10:31 ` Philippe Gerum
2026-11-12 11:05 ` Florian Bezdeka
2026-11-12 11:16 ` Jan Kiszka
2026-11-12 11:25 ` Florian Bezdeka
2026-11-12 11:30 ` Jan Kiszka
2026-11-12 11:39 ` Florian Bezdeka
2026-11-12 12:04 ` Jan Kiszka
2026-11-12 12:59 ` Philippe Gerum
2026-11-12 13:29 ` Jan Kiszka
2026-11-12 13:49 ` Philippe Gerum
2026-11-12 14:03 ` Jan Kiszka
2026-11-12 14:43 ` Philippe Gerum
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=87h5hcoesz.fsf@xenomai.org \
--to=rpm@xenomai.org \
--cc=florian.bezdeka@siemens.com \
--cc=jan.kiszka@siemens.com \
--cc=xenomai@xenomai.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.