Re: [RESEND PATCH v2 1/3] x86/fred: Allow variable-sized event frame

From: Xin Li
Date: Wed Mar 19 2025 - 12:35:36 EST


On 3/19/2025 6:55 AM, Brian Gerst wrote:

+/*
+ * Initialize thread_info.user_pt_regs for IDT event delivery.
+ *
+ * For IDT user level event delivery, a pt_regs structure is pushed by both
+ * hardware and software and always resides at a fixed offset from top of
+ * current task kernel stack, thus thread_info.user_pt_regs is a per-task
+ * constant and NEVER changes after initialization.
+ *
+ * While for FRED user level event delivery, user_pt_regs is updated in
+ * fred_entry_from_user() immediately after user level event delivery.
+ *
+ * Note: thread_info.user_pt_regs of the init task is initialized at build
+ * time.
+ */
+void arch_init_user_pt_regs(struct task_struct *tsk)
+{
+ unsigned long top_of_stack = (unsigned long)task_stack_page(tsk) + THREAD_SIZE;
+
+ top_of_stack -= TOP_OF_KERNEL_STACK_PADDING;
+ tsk->thread_info.user_pt_regs = (struct pt_regs *)top_of_stack - 1;
+}

Can this be put into arch_dup_task_struct() instead of creating another hook?

I wanted to do it at the beginning but task stack is no longer part of
the task_struct on x86. Make sense?

I see that now. My concern here is that using a weak function makes
all other arches pay the cost of an empty function call. That's why
many hooks are static linlines or macros, especially if the default is
a no-op.


Same here.

As you have gone through the code and logic, mind to give a RB?

Thanks!
Xin