Skip to content

Commit ae755b5

Browse files
jgross1suryasaimadhu
authored andcommitted
x86/paravirt: Switch iret pvops to ALTERNATIVE
The iret paravirt op is rather special as it is using a jmp instead of a call instruction. Switch it to ALTERNATIVE. Signed-off-by: Juergen Gross <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 0b8d366 commit ae755b5

File tree

5 files changed

+7
-38
lines changed

5 files changed

+7
-38
lines changed

arch/x86/include/asm/paravirt.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -747,9 +747,9 @@ extern void default_banner(void);
747747
#define PARA_INDIRECT(addr) *addr(%rip)
748748

749749
#define INTERRUPT_RETURN \
750-
PARA_SITE(PARA_PATCH(PV_CPU_iret), \
751-
ANNOTATE_RETPOLINE_SAFE; \
752-
jmp PARA_INDIRECT(pv_ops+PV_CPU_iret);)
750+
ANNOTATE_RETPOLINE_SAFE; \
751+
ALTERNATIVE_TERNARY("jmp *paravirt_iret(%rip);", \
752+
X86_FEATURE_XENPV, "jmp xen_iret;", "jmp native_iret;")
753753

754754
#ifdef CONFIG_DEBUG_ENTRY
755755
#define SAVE_FLAGS(clobbers) \

arch/x86/include/asm/paravirt_types.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,6 @@ struct pv_cpu_ops {
151151

152152
u64 (*read_pmc)(int counter);
153153

154-
/* Normal iret. Jump to this with the standard iret stack
155-
frame set up. */
156-
void (*iret)(void);
157-
158154
void (*start_context_switch)(struct task_struct *prev);
159155
void (*end_context_switch)(struct task_struct *next);
160156
#endif
@@ -294,6 +290,7 @@ struct paravirt_patch_template {
294290

295291
extern struct pv_info pv_info;
296292
extern struct paravirt_patch_template pv_ops;
293+
extern void (*paravirt_iret)(void);
297294

298295
#define PARAVIRT_PATCH(x) \
299296
(offsetof(struct paravirt_patch_template, x) / sizeof(void *))

arch/x86/kernel/asm-offsets.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ static void __used common(void)
6161
OFFSET(IA32_RT_SIGFRAME_sigcontext, rt_sigframe_ia32, uc.uc_mcontext);
6262
#endif
6363

64-
#ifdef CONFIG_PARAVIRT_XXL
65-
BLANK();
66-
OFFSET(PV_CPU_iret, paravirt_patch_template, cpu.iret);
67-
#endif
68-
6964
#ifdef CONFIG_XEN
7065
BLANK();
7166
OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);

arch/x86/kernel/paravirt.c

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -86,25 +86,6 @@ u64 notrace _paravirt_ident_64(u64 x)
8686
{
8787
return x;
8888
}
89-
90-
static unsigned paravirt_patch_jmp(void *insn_buff, const void *target,
91-
unsigned long addr, unsigned len)
92-
{
93-
struct branch *b = insn_buff;
94-
unsigned long delta = (unsigned long)target - (addr+5);
95-
96-
if (len < 5) {
97-
#ifdef CONFIG_RETPOLINE
98-
WARN_ONCE(1, "Failing to patch indirect JMP in %ps\n", (void *)addr);
99-
#endif
100-
return len; /* call too long for patch site */
101-
}
102-
103-
b->opcode = 0xe9; /* jmp */
104-
b->delta = delta;
105-
106-
return 5;
107-
}
10889
#endif
10990

11091
DEFINE_STATIC_KEY_TRUE(virt_spin_lock_key);
@@ -136,9 +117,6 @@ unsigned paravirt_patch_default(u8 type, void *insn_buff,
136117
else if (opfunc == _paravirt_ident_64)
137118
ret = paravirt_patch_ident_64(insn_buff, len);
138119

139-
else if (type == PARAVIRT_PATCH(cpu.iret))
140-
/* If operation requires a jmp, then jmp */
141-
ret = paravirt_patch_jmp(insn_buff, opfunc, addr, len);
142120
#endif
143121
else
144122
/* Otherwise call the function. */
@@ -313,8 +291,6 @@ struct paravirt_patch_template pv_ops = {
313291

314292
.cpu.load_sp0 = native_load_sp0,
315293

316-
.cpu.iret = native_iret,
317-
318294
#ifdef CONFIG_X86_IOPL_IOPERM
319295
.cpu.invalidate_io_bitmap = native_tss_invalidate_io_bitmap,
320296
.cpu.update_io_bitmap = native_tss_update_io_bitmap,
@@ -419,6 +395,8 @@ struct paravirt_patch_template pv_ops = {
419395
NOKPROBE_SYMBOL(native_get_debugreg);
420396
NOKPROBE_SYMBOL(native_set_debugreg);
421397
NOKPROBE_SYMBOL(native_load_idt);
398+
399+
void (*paravirt_iret)(void) = native_iret;
422400
#endif
423401

424402
EXPORT_SYMBOL(pv_ops);

arch/x86/xen/enlighten_pv.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,8 +1070,6 @@ static const struct pv_cpu_ops xen_cpu_ops __initconst = {
10701070

10711071
.read_pmc = xen_read_pmc,
10721072

1073-
.iret = xen_iret,
1074-
10751073
.load_tr_desc = paravirt_nop,
10761074
.set_ldt = xen_set_ldt,
10771075
.load_gdt = xen_load_gdt,
@@ -1235,6 +1233,7 @@ asmlinkage __visible void __init xen_start_kernel(void)
12351233
pv_info = xen_info;
12361234
pv_ops.init.patch = paravirt_patch_default;
12371235
pv_ops.cpu = xen_cpu_ops;
1236+
paravirt_iret = xen_iret;
12381237
xen_init_irq_ops();
12391238

12401239
/*

0 commit comments

Comments
 (0)