Skip to content

Commit a4a7644

Browse files
committed
x86/xen: move paravirt lazy code
Only Xen is using the paravirt lazy mode code, so it can be moved to Xen specific sources. This allows to make some of the functions static or to merge them into their only call sites. While at it do a rename from "paravirt" to "xen" for all moved specifiers. No functional change. Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com> Link: https://lore.kernel.org/r/20230913113828.18421-3-jgross@suse.com Signed-off-by: Juergen Gross <jgross@suse.com>
1 parent 361239f commit a4a7644

File tree

7 files changed

+102
-116
lines changed

7 files changed

+102
-116
lines changed

arch/x86/include/asm/paravirt_types.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@ struct paravirt_patch_site {
99
u8 type; /* type of this instruction */
1010
u8 len; /* length of original instruction */
1111
};
12-
13-
/* Lazy mode for batching updates / context switch */
14-
enum paravirt_lazy_mode {
15-
PARAVIRT_LAZY_NONE,
16-
PARAVIRT_LAZY_MMU,
17-
PARAVIRT_LAZY_CPU,
18-
};
1912
#endif
2013

2114
#ifdef CONFIG_PARAVIRT
@@ -549,14 +542,6 @@ int paravirt_disable_iospace(void);
549542
__PVOP_VCALL(op, PVOP_CALL_ARG1(arg1), PVOP_CALL_ARG2(arg2), \
550543
PVOP_CALL_ARG3(arg3), PVOP_CALL_ARG4(arg4))
551544

552-
enum paravirt_lazy_mode paravirt_get_lazy_mode(void);
553-
void paravirt_start_context_switch(struct task_struct *prev);
554-
void paravirt_end_context_switch(struct task_struct *next);
555-
556-
void paravirt_enter_lazy_mmu(void);
557-
void paravirt_leave_lazy_mmu(void);
558-
void paravirt_flush_lazy_mmu(void);
559-
560545
void _paravirt_nop(void);
561546
void paravirt_BUG(void);
562547
unsigned long paravirt_ret0(void);

arch/x86/include/asm/xen/hypervisor.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
extern struct shared_info *HYPERVISOR_shared_info;
3737
extern struct start_info *xen_start_info;
3838

39+
#include <asm/bug.h>
3940
#include <asm/processor.h>
4041

4142
#define XEN_SIGNATURE "XenVMMXenVMM"
@@ -63,4 +64,29 @@ void __init xen_pvh_init(struct boot_params *boot_params);
6364
void __init mem_map_via_hcall(struct boot_params *boot_params_p);
6465
#endif
6566

67+
/* Lazy mode for batching updates / context switch */
68+
enum xen_lazy_mode {
69+
XEN_LAZY_NONE,
70+
XEN_LAZY_MMU,
71+
XEN_LAZY_CPU,
72+
};
73+
74+
DECLARE_PER_CPU(enum xen_lazy_mode, xen_lazy_mode);
75+
76+
static inline void enter_lazy(enum xen_lazy_mode mode)
77+
{
78+
BUG_ON(this_cpu_read(xen_lazy_mode) != XEN_LAZY_NONE);
79+
80+
this_cpu_write(xen_lazy_mode, mode);
81+
}
82+
83+
static inline void leave_lazy(enum xen_lazy_mode mode)
84+
{
85+
BUG_ON(this_cpu_read(xen_lazy_mode) != mode);
86+
87+
this_cpu_write(xen_lazy_mode, XEN_LAZY_NONE);
88+
}
89+
90+
enum xen_lazy_mode xen_get_lazy_mode(void);
91+
6692
#endif /* _ASM_X86_XEN_HYPERVISOR_H */

arch/x86/kernel/paravirt.c

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -143,66 +143,7 @@ int paravirt_disable_iospace(void)
143143
return request_resource(&ioport_resource, &reserve_ioports);
144144
}
145145

146-
static DEFINE_PER_CPU(enum paravirt_lazy_mode, paravirt_lazy_mode) = PARAVIRT_LAZY_NONE;
147-
148-
static inline void enter_lazy(enum paravirt_lazy_mode mode)
149-
{
150-
BUG_ON(this_cpu_read(paravirt_lazy_mode) != PARAVIRT_LAZY_NONE);
151-
152-
this_cpu_write(paravirt_lazy_mode, mode);
153-
}
154-
155-
static void leave_lazy(enum paravirt_lazy_mode mode)
156-
{
157-
BUG_ON(this_cpu_read(paravirt_lazy_mode) != mode);
158-
159-
this_cpu_write(paravirt_lazy_mode, PARAVIRT_LAZY_NONE);
160-
}
161-
162-
void paravirt_enter_lazy_mmu(void)
163-
{
164-
enter_lazy(PARAVIRT_LAZY_MMU);
165-
}
166-
167-
void paravirt_leave_lazy_mmu(void)
168-
{
169-
leave_lazy(PARAVIRT_LAZY_MMU);
170-
}
171-
172-
void paravirt_flush_lazy_mmu(void)
173-
{
174-
preempt_disable();
175-
176-
if (paravirt_get_lazy_mode() == PARAVIRT_LAZY_MMU) {
177-
arch_leave_lazy_mmu_mode();
178-
arch_enter_lazy_mmu_mode();
179-
}
180-
181-
preempt_enable();
182-
}
183-
184146
#ifdef CONFIG_PARAVIRT_XXL
185-
void paravirt_start_context_switch(struct task_struct *prev)
186-
{
187-
BUG_ON(preemptible());
188-
189-
if (this_cpu_read(paravirt_lazy_mode) == PARAVIRT_LAZY_MMU) {
190-
arch_leave_lazy_mmu_mode();
191-
set_ti_thread_flag(task_thread_info(prev), TIF_LAZY_MMU_UPDATES);
192-
}
193-
enter_lazy(PARAVIRT_LAZY_CPU);
194-
}
195-
196-
void paravirt_end_context_switch(struct task_struct *next)
197-
{
198-
BUG_ON(preemptible());
199-
200-
leave_lazy(PARAVIRT_LAZY_CPU);
201-
202-
if (test_and_clear_ti_thread_flag(task_thread_info(next), TIF_LAZY_MMU_UPDATES))
203-
arch_enter_lazy_mmu_mode();
204-
}
205-
206147
static noinstr void pv_native_write_cr2(unsigned long val)
207148
{
208149
native_write_cr2(val);
@@ -229,14 +170,6 @@ static noinstr void pv_native_safe_halt(void)
229170
}
230171
#endif
231172

232-
enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
233-
{
234-
if (in_interrupt())
235-
return PARAVIRT_LAZY_NONE;
236-
237-
return this_cpu_read(paravirt_lazy_mode);
238-
}
239-
240173
struct pv_info pv_info = {
241174
.name = "bare hardware",
242175
#ifdef CONFIG_PARAVIRT_XXL

arch/x86/xen/enlighten_pv.c

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ struct tls_descs {
101101
struct desc_struct desc[3];
102102
};
103103

104+
DEFINE_PER_CPU(enum xen_lazy_mode, xen_lazy_mode) = XEN_LAZY_NONE;
105+
106+
enum xen_lazy_mode xen_get_lazy_mode(void)
107+
{
108+
if (in_interrupt())
109+
return XEN_LAZY_NONE;
110+
111+
return this_cpu_read(xen_lazy_mode);
112+
}
113+
104114
/*
105115
* Updating the 3 TLS descriptors in the GDT on every task switch is
106116
* surprisingly expensive so we avoid updating them if they haven't
@@ -362,10 +372,25 @@ static noinstr unsigned long xen_get_debugreg(int reg)
362372
return HYPERVISOR_get_debugreg(reg);
363373
}
364374

375+
static void xen_start_context_switch(struct task_struct *prev)
376+
{
377+
BUG_ON(preemptible());
378+
379+
if (this_cpu_read(xen_lazy_mode) == XEN_LAZY_MMU) {
380+
arch_leave_lazy_mmu_mode();
381+
set_ti_thread_flag(task_thread_info(prev), TIF_LAZY_MMU_UPDATES);
382+
}
383+
enter_lazy(XEN_LAZY_CPU);
384+
}
385+
365386
static void xen_end_context_switch(struct task_struct *next)
366387
{
388+
BUG_ON(preemptible());
389+
367390
xen_mc_flush();
368-
paravirt_end_context_switch(next);
391+
leave_lazy(XEN_LAZY_CPU);
392+
if (test_and_clear_ti_thread_flag(task_thread_info(next), TIF_LAZY_MMU_UPDATES))
393+
arch_enter_lazy_mmu_mode();
369394
}
370395

371396
static unsigned long xen_store_tr(void)
@@ -472,7 +497,7 @@ static void xen_set_ldt(const void *addr, unsigned entries)
472497

473498
MULTI_mmuext_op(mcs.mc, op, 1, NULL, DOMID_SELF);
474499

475-
xen_mc_issue(PARAVIRT_LAZY_CPU);
500+
xen_mc_issue(XEN_LAZY_CPU);
476501
}
477502

478503
static void xen_load_gdt(const struct desc_ptr *dtr)
@@ -568,7 +593,7 @@ static void xen_load_tls(struct thread_struct *t, unsigned int cpu)
568593
* exception between the new %fs descriptor being loaded and
569594
* %fs being effectively cleared at __switch_to().
570595
*/
571-
if (paravirt_get_lazy_mode() == PARAVIRT_LAZY_CPU)
596+
if (xen_get_lazy_mode() == XEN_LAZY_CPU)
572597
loadsegment(fs, 0);
573598

574599
xen_mc_batch();
@@ -577,7 +602,7 @@ static void xen_load_tls(struct thread_struct *t, unsigned int cpu)
577602
load_TLS_descriptor(t, cpu, 1);
578603
load_TLS_descriptor(t, cpu, 2);
579604

580-
xen_mc_issue(PARAVIRT_LAZY_CPU);
605+
xen_mc_issue(XEN_LAZY_CPU);
581606
}
582607

583608
static void xen_load_gs_index(unsigned int idx)
@@ -909,7 +934,7 @@ static void xen_load_sp0(unsigned long sp0)
909934

910935
mcs = xen_mc_entry(0);
911936
MULTI_stack_switch(mcs.mc, __KERNEL_DS, sp0);
912-
xen_mc_issue(PARAVIRT_LAZY_CPU);
937+
xen_mc_issue(XEN_LAZY_CPU);
913938
this_cpu_write(cpu_tss_rw.x86_tss.sp0, sp0);
914939
}
915940

@@ -973,7 +998,7 @@ static void xen_write_cr0(unsigned long cr0)
973998

974999
MULTI_fpu_taskswitch(mcs.mc, (cr0 & X86_CR0_TS) != 0);
9751000

976-
xen_mc_issue(PARAVIRT_LAZY_CPU);
1001+
xen_mc_issue(XEN_LAZY_CPU);
9771002
}
9781003

9791004
static void xen_write_cr4(unsigned long cr4)
@@ -1156,7 +1181,7 @@ static const typeof(pv_ops) xen_cpu_ops __initconst = {
11561181
#endif
11571182
.io_delay = xen_io_delay,
11581183

1159-
.start_context_switch = paravirt_start_context_switch,
1184+
.start_context_switch = xen_start_context_switch,
11601185
.end_context_switch = xen_end_context_switch,
11611186
},
11621187
};

0 commit comments

Comments
 (0)