Skip to content

Commit 3a24a60

Browse files
Brian Gerstsuryasaimadhu
authored andcommitted
x86/32: Remove lazy GS macros
GS is always a user segment now. Signed-off-by: Brian Gerst <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Reviewed-by: Thomas Gleixner <[email protected]> Acked-by: Andy Lutomirski <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 9554e90 commit 3a24a60

File tree

9 files changed

+20
-28
lines changed

9 files changed

+20
-28
lines changed

arch/x86/include/asm/mmu_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ do { \
141141
#ifdef CONFIG_X86_32
142142
#define deactivate_mm(tsk, mm) \
143143
do { \
144-
lazy_load_gs(0); \
144+
loadsegment(gs, 0); \
145145
} while (0)
146146
#else
147147
#define deactivate_mm(tsk, mm) \

arch/x86/include/asm/segment.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,6 @@ static inline void __loadsegment_fs(unsigned short value)
354354
* x86-32 user GS accessors. This is ugly and could do with some cleaning up.
355355
*/
356356
#ifdef CONFIG_X86_32
357-
# define get_user_gs(regs) (u16)({ unsigned long v; savesegment(gs, v); v; })
358-
# define set_user_gs(regs, v) loadsegment(gs, (unsigned long)(v))
359-
# define task_user_gs(tsk) ((tsk)->thread.gs)
360-
# define lazy_save_gs(v) savesegment(gs, (v))
361-
# define lazy_load_gs(v) loadsegment(gs, (v))
362357
# define load_gs_index(v) loadsegment(gs, (v))
363358
#endif /* X86_32 */
364359

arch/x86/kernel/process.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp, unsigned long arg,
160160
savesegment(ds, p->thread.ds);
161161
#else
162162
p->thread.sp0 = (unsigned long) (childregs + 1);
163+
savesegment(gs, p->thread.gs);
163164
/*
164165
* Clear all status flags including IF and set fixed bit. 64bit
165166
* does not have this initialization as the frame does not contain
@@ -191,10 +192,6 @@ int copy_thread(unsigned long clone_flags, unsigned long sp, unsigned long arg,
191192
if (sp)
192193
childregs->sp = sp;
193194

194-
#ifdef CONFIG_X86_32
195-
task_user_gs(p) = get_user_gs(current_pt_regs());
196-
#endif
197-
198195
if (unlikely(p->flags & PF_IO_WORKER)) {
199196
/*
200197
* An IO thread is a user space thread, but it doesn't

arch/x86/kernel/process_32.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,7 @@ void __show_regs(struct pt_regs *regs, enum show_regs_mode mode,
6363
unsigned long d0, d1, d2, d3, d6, d7;
6464
unsigned short gs;
6565

66-
if (user_mode(regs))
67-
gs = get_user_gs(regs);
68-
else
69-
savesegment(gs, gs);
66+
savesegment(gs, gs);
7067

7168
show_ip(regs, log_lvl);
7269

@@ -114,7 +111,7 @@ void release_thread(struct task_struct *dead_task)
114111
void
115112
start_thread(struct pt_regs *regs, unsigned long new_ip, unsigned long new_sp)
116113
{
117-
set_user_gs(regs, 0);
114+
loadsegment(gs, 0);
118115
regs->fs = 0;
119116
regs->ds = __USER_DS;
120117
regs->es = __USER_DS;
@@ -177,7 +174,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
177174
* used %fs or %gs (it does not today), or if the kernel is
178175
* running inside of a hypervisor layer.
179176
*/
180-
lazy_save_gs(prev->gs);
177+
savesegment(gs, prev->gs);
181178

182179
/*
183180
* Load the per-thread Thread-Local Storage descriptor.
@@ -208,7 +205,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
208205
* Restore %gs if needed (which is common)
209206
*/
210207
if (prev->gs | next->gs)
211-
lazy_load_gs(next->gs);
208+
loadsegment(gs, next->gs);
212209

213210
this_cpu_write(current_task, next_p);
214211

arch/x86/kernel/ptrace.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ static u16 get_segment_reg(struct task_struct *task, unsigned long offset)
170170
retval = *pt_regs_access(task_pt_regs(task), offset);
171171
else {
172172
if (task == current)
173-
retval = get_user_gs(task_pt_regs(task));
173+
savesegment(gs, retval);
174174
else
175-
retval = task_user_gs(task);
175+
retval = task->thread.gs;
176176
}
177177
return retval;
178178
}
@@ -210,7 +210,7 @@ static int set_segment_reg(struct task_struct *task,
210210
break;
211211

212212
case offsetof(struct user_regs_struct, gs):
213-
task_user_gs(task) = value;
213+
task->thread.gs = value;
214214
}
215215

216216
return 0;

arch/x86/kernel/signal.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static bool restore_sigcontext(struct pt_regs *regs,
9393
return false;
9494

9595
#ifdef CONFIG_X86_32
96-
set_user_gs(regs, sc.gs);
96+
loadsegment(gs, sc.gs);
9797
regs->fs = sc.fs;
9898
regs->es = sc.es;
9999
regs->ds = sc.ds;
@@ -146,8 +146,10 @@ __unsafe_setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate,
146146
struct pt_regs *regs, unsigned long mask)
147147
{
148148
#ifdef CONFIG_X86_32
149-
unsafe_put_user(get_user_gs(regs),
150-
(unsigned int __user *)&sc->gs, Efault);
149+
unsigned int gs;
150+
savesegment(gs, gs);
151+
152+
unsafe_put_user(gs, (unsigned int __user *)&sc->gs, Efault);
151153
unsafe_put_user(regs->fs, (unsigned int __user *)&sc->fs, Efault);
152154
unsafe_put_user(regs->es, (unsigned int __user *)&sc->es, Efault);
153155
unsafe_put_user(regs->ds, (unsigned int __user *)&sc->ds, Efault);

arch/x86/kernel/vm86_32.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ void save_v86_state(struct kernel_vm86_regs *regs, int retval)
151151

152152
memcpy(&regs->pt, &vm86->regs32, sizeof(struct pt_regs));
153153

154-
lazy_load_gs(vm86->regs32.gs);
154+
loadsegment(gs, vm86->regs32.gs);
155155

156156
regs->pt.ax = retval;
157157
return;
@@ -325,7 +325,7 @@ static long do_sys_vm86(struct vm86plus_struct __user *user_vm86, bool plus)
325325
* Save old state
326326
*/
327327
vm86->saved_sp0 = tsk->thread.sp0;
328-
lazy_save_gs(vm86->regs32.gs);
328+
savesegment(gs, vm86->regs32.gs);
329329

330330
/* make room for real-mode segments */
331331
preempt_disable();

arch/x86/lib/insn-eval.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,9 @@ static int resolve_seg_reg(struct insn *insn, struct pt_regs *regs, int regoff)
342342
*/
343343
static short get_segment_selector(struct pt_regs *regs, int seg_reg_idx)
344344
{
345-
#ifdef CONFIG_X86_64
346345
unsigned short sel;
347346

347+
#ifdef CONFIG_X86_64
348348
switch (seg_reg_idx) {
349349
case INAT_SEG_REG_IGNORE:
350350
return 0;
@@ -402,7 +402,8 @@ static short get_segment_selector(struct pt_regs *regs, int seg_reg_idx)
402402
case INAT_SEG_REG_FS:
403403
return (unsigned short)(regs->fs & 0xffff);
404404
case INAT_SEG_REG_GS:
405-
return get_user_gs(regs);
405+
savesegment(gs, sel);
406+
return sel;
406407
case INAT_SEG_REG_IGNORE:
407408
default:
408409
return -EINVAL;

arch/x86/math-emu/get_address.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ static long pm_address(u_char FPU_modrm, u_char segment,
153153
switch (segment) {
154154
case PREFIX_GS_ - 1:
155155
/* user gs handling can be lazy, use special accessors */
156-
addr->selector = get_user_gs(FPU_info->regs);
156+
savesegment(gs, addr->selector);
157157
break;
158158
default:
159159
addr->selector = PM_REG_(segment);

0 commit comments

Comments
 (0)