Skip to contentSkip to conversation

Why is get_current() not const function?

DISCUSSION Andi Kleen 3 participants 3 messages Mar 13, 2003 – Mar 17, 2003 2 messages not in the archive

lore
Share & tools
lore

Andi Kleen

author
#1 lore raw
In reply to a message not in the archive
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 why get_current function (on arches which define current to get_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

#3 lore raw
In reply to a message not in the archive
Quoted 9 lines · [email protected] (Linus Torvalds) writes:
Quoted 2 lines
					 and why on x86-64

the 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

#4 lore raw
Quoted 12 lines · Andi Kleen
Quoted 9 lines · [email protected] (Linus Torvalds) writes:
Quoted 2 lines
					 and why on x86-64

the 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 making read_pda non 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