Re: [PATCH v4 30/39] unwind_user/deferred: Make unwind deferral requests NMI-safe

Peter Zijlstra
2025-01-22T14:24:31Z

On Tue, Jan 21, 2025 at 06:31:22PM -0800, Josh Poimboeuf wrote:
> +static int unwind_deferred_request_nmi(struct unwind_work *work, u64 *cookie)
> +{
> + struct unwind_task_info *info = &current->unwind_info;
> + bool inited_cookie = false;
> + int ret;
> +
> + *cookie = info->cookie;
> + if (!*cookie) {
> + /*
> + * This is the first unwind request since the most recent entry
> + * from user. Initialize the task cookie.
> + *
> + * Don't write to info->cookie directly, otherwise it may get
> + * cleared if the NMI occurred in the kernel during early entry
> + * or late exit before the task work gets to run. Instead, use
> + * info->nmi_cookie which gets synced later by get_cookie().
> + */
> + if (!info->nmi_cookie) {
> + u64 cpu = raw_smp_processor_id();
> + u64 ctx_ctr;
> +
> + ctx_ctr = __this_cpu_inc_return(unwind_ctx_ctr);

__this_cpu_inc_return() is *NOT* NMI safe IIRC.