From: Dan Williams > Sent: 22 November 2022 20:23 ... > > > > > Lukas pointed out that object_is_on_stack() is available to detect this > > > > > automatically. > > > > > > > > > > Use object_is_on_stack() to determine the correct init work function to > > > > > call. > > > > > > > > This is all a bit strange. > > > > The 'onstack' flag is needed for the diagnostic check: > > > > is_on_stack = object_is_on_stack(addr); > > > > if (is_on_stack == onstack) > > > > return; > > > > pr_warn(...); > > > > WARN_ON(1); > > > > > > > > So setting the flag to the location of the buffer just subverts the check. > > > > It that is sane there ought to be a proper way to do it. > > > > > > If object_is_on_stack() is sufficient to check whether a struct > > > is on the stack or not, why doesn't __init_work() use it to > > > auto-detect whether to call debug_object_init_on_stack() or > > > debug_object_init()? > > > > > > Forcing developers to use a specific initializer for something > > > that can be auto-detected is akin to treating them like kids > > > and telling them "You didn't say the magic word." > > > > > > What's the point? > > I had this initial reaction as well, but INIT_WORK_ONSTACK() documents > an important detail of the object's lifetime. Here are 2 examples of > functions that would become trickier to read if the kernel did a > global s/INIT_WORK_ONSTACK()/INIT_WORK()/ > > synchronize_rcu_expedited_queue_work() > insert_wq_barrier() > > ...where those take arguments that are known to come from the stack and > be used in async context. I suspect the check was added in response to some code that added on on-stack item and then slept after returning from that function. One option would be to change the diagnostic check to: is_on_stack != !object_is_on_stack(addr) and then pass in 2 so the test always succeeds. But I suspect that won't be liked. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)