Re: [PATCH x86/mm 6/6] x86-64 ia32 ptrace get/putreg32 current task

H. Peter Anvin
2007-11-29T18:17:33Z

Linus Torvalds wrote:
>
> But this one is correct:
>
>>> case offsetof(struct user32, regs.gs):
>>> *val = child->thread.gsindex;
>>> + if (child == current)
>>> + asm("movl %%gs,%0" : "=r" (*val));
>> Won't this return the kernel's GS instead of the user's?
>
> No, %gs is untouched by the kernel, so it contains user space version, and
> getting the value directly from %gs looks correct.
>

Brief summary/reminder:

The kernel uses %fs in 32-bit mode and %gs in 64-bit mode.
User space TLS uses %gs in 32-bit mode and %fs in 64-bit mode.

The 64-bit kernel has to use %gs in order for SWAPGS to be available to
it (by which time the 32-bit ABI was already fixed.) It is advantageous
for user space to use the register the kernel typically won't, in order
to speed up system call entry/exit.

-hpa