Why is get_current() not const function?
A message that is not in the archive (sent off-list or not yet received): 20030313061926.S3910@devserv.devel.redhat.com.suse.lists.linux.kernel
Quoted 9 lines · Jakub Jelinek
E.g. on x86-64,
NEW_AUX_ENT(AT_UID, (elf_addr_t) current->uid); NEW_AUX_ENT(AT_EUID, (elf_addr_t) current->euid); NEW_AUX_ENT(AT_GID, (elf_addr_t) current->gid); NEW_AUX_ENT(AT_EGID, (elf_addr_t) current->egid);results in 4 movq %gs:0,%rax instructions while one is completely enough.
Anyone remembers whyget_currentfunction (on arches which define current toget_current()) is not const and why on x86-64
I tried it once. Then spent a day in fixing all the obvious problems (addings lots of compile barriers to early bootup and the scheduler to make it boot again etc.)
In the end I gave up because there were some weird crashes left and I ran out of time on this one.
Feel free to retry it, but it'll be lots of work I suspect.
-Andi
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 9 lines · [email protected] (Linus Torvalds) writes:
Quoted 2 lines
and why on x86-64the movq %%gs:0, %0 inline asm is volatile with "memory" clobber?
Can't help you on that one, but it looks like it uses various helper functions for doing the x86-64 per-processor data structures, and I bet those helper functions are shared by _other_ users who definitely want to have their data properly re-read. Ie "
current()" may be constant in process context, but that sure isn't true about a lot of other things in the per-processor data structures.
Yes, that's the big issue. const current requires non volatile read_pda() and making read_pda non volatile breaks lots of code currently and probably needs an audit over all users.
-Andi
Quoted 12 lines · Andi Kleen
Quoted 9 lines · [email protected] (Linus Torvalds) writes:
Quoted 2 lines
and why on x86-64the movq %%gs:0, %0 inline asm is volatile with "memory" clobber?
Can't help you on that one, but it looks like it uses various helper functions for doing the x86-64 per-processor data structures, and I bet those helper functions are shared by _other_ users who definitely want to have their data properly re-read. Ie "
current()" may be constant in process context, but that sure isn't true about a lot of other things in the per-processor data structures.
Quoted 3 lines
Yes, that's the big issue. const current requires non volatile
read_pda()and makingread_pdanon volatile breaks lots of code currently and probably needs an audit over all users.
Well, that's one that is not particularly hard to fix.
Either a new set of pda access macros without volatile and memory clobber can be written, or just get_current can use its own asm, ie. static inline struct task_struct *get_current(void)
{
struct task_struct *t;
asm ("movq %%gs:%c1,%0" : "=r" (t) : "i"(pda_offset(pcurrent)));
return t;
}Jakub