Re: [PATCH] x86/ptrace: Use savesegment() in get_segment_reg() instead of inline asm

From: Oleg Nesterov

Date: Thu Apr 02 2026 - 08:48:47 EST


On 04/02, Uros Bizjak wrote:
>
> @@ -251,32 +251,31 @@ static u16 get_segment_reg(struct task_struct *task, unsigned long offset)
> /*
> * Returning the value truncates it to 16 bits.
> */
> - unsigned int seg;
> + unsigned int retval;

LGTM, but perhaps it would be better to use "u16 retval" ? and remove the
comment.

Oleg.

>
> switch (offset) {
> case offsetof(struct user_regs_struct, fs):
> if (task == current) {
> - /* Older gas can't assemble movq %?s,%r?? */
> - asm("movl %%fs,%0" : "=r" (seg));
> - return seg;
> + savesegment(fs, retval);
> + return retval;
> }
> return task->thread.fsindex;
> case offsetof(struct user_regs_struct, gs):
> if (task == current) {
> - asm("movl %%gs,%0" : "=r" (seg));
> - return seg;
> + savesegment(gs, retval);
> + return retval;
> }
> return task->thread.gsindex;
> case offsetof(struct user_regs_struct, ds):
> if (task == current) {
> - asm("movl %%ds,%0" : "=r" (seg));
> - return seg;
> + savesegment(ds, retval);
> + return retval;
> }
> return task->thread.ds;
> case offsetof(struct user_regs_struct, es):
> if (task == current) {
> - asm("movl %%es,%0" : "=r" (seg));
> - return seg;
> + savesegment(es, retval);
> + return retval;
> }
> return task->thread.es;
>
> --
> 2.53.0
>