On Mon, Aug 10, 2020 at 09:01:02AM -0600, Jens Axboe wrote:
+struct callback_head work_exited = {
- .next = NULL /* all we need is ->next == NULL */
+};
Would it make sense to make this const ? Esp. with the thing exposed, sticking it in R/O memory might avoid a mistake somewhere.
That was my original intent, but that makes 'head' in task_work_run() const as well, and cmpxchg() doesn't like that:
kernel/task_work.c: In function ‘task_work_run’: ./arch/x86/include/asm/cmpxchg.h:89:29: warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers] 89 | __typeof__(*(ptr)) __new = (new); \ | ^ ./arch/x86/include/asm/cmpxchg.h:134:2: note: in expansion of macro ‘__raw_cmpxchg’ 134 | __raw_cmpxchg((ptr), (old), (new), (size), LOCK_PREFIX) | ^~~~~~~~~~~~~ ./arch/x86/include/asm/cmpxchg.h:149:2: note: in expansion of macro ‘__cmpxchg’ 149 | __cmpxchg(ptr, old, new, sizeof(*(ptr))) | ^~~~~~~~~ ./include/asm-generic/atomic-instrumented.h:1685:2: note: in expansion of macro ‘arch_cmpxchg’ 1685 | arch_cmpxchg(__ai_ptr, __VA_ARGS__); \ | ^~~~~~~~~~~~ kernel/task_work.c:126:12: note: in expansion of macro ‘cmpxchg’ 126 | } while (cmpxchg(&task->task_works, work, head) != work); | ^~~~~~~
which is somewhat annoying. Because there's really no good reason why it can't be const, it'll just require the changes to dig a bit deeper.
Bah! Best I can come up with is casting the const away there, what a mess :-(