Skip to content

Commit fb2af07

Browse files
KAGA-KOKOIngo Molnar
authored andcommitted
x86/paravirt: Unify the 32/64 bit paravirt patching code
Large parts of these two files are identical. Merge them together. Signed-off-by: Thomas Gleixner <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Brian Gerst <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Denys Vlasenko <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Juergen Gross <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Rik van Riel <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 11e86dc commit fb2af07

File tree

3 files changed

+50
-80
lines changed

3 files changed

+50
-80
lines changed

arch/x86/kernel/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ KASAN_SANITIZE_paravirt.o := n
3030

3131
OBJECT_FILES_NON_STANDARD_relocate_kernel_$(BITS).o := y
3232
OBJECT_FILES_NON_STANDARD_test_nx.o := y
33-
OBJECT_FILES_NON_STANDARD_paravirt_patch_$(BITS).o := y
33+
OBJECT_FILES_NON_STANDARD_paravirt_patch.o := y
3434

3535
ifdef CONFIG_FRAME_POINTER
3636
OBJECT_FILES_NON_STANDARD_ftrace_$(BITS).o := y
@@ -112,7 +112,7 @@ obj-$(CONFIG_AMD_NB) += amd_nb.o
112112
obj-$(CONFIG_DEBUG_NMI_SELFTEST) += nmi_selftest.o
113113

114114
obj-$(CONFIG_KVM_GUEST) += kvm.o kvmclock.o
115-
obj-$(CONFIG_PARAVIRT) += paravirt.o paravirt_patch_$(BITS).o
115+
obj-$(CONFIG_PARAVIRT) += paravirt.o paravirt_patch.o
116116
obj-$(CONFIG_PARAVIRT_SPINLOCKS)+= paravirt-spinlocks.o
117117
obj-$(CONFIG_PARAVIRT_CLOCK) += pvclock.o
118118
obj-$(CONFIG_X86_PMEM_LEGACY_DEVICE) += pmem.o

arch/x86/kernel/paravirt_patch_64.c renamed to arch/x86/kernel/paravirt_patch.c

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// SPDX-License-Identifier: GPL-2.0
2+
#include <linux/stringify.h>
3+
24
#include <asm/paravirt.h>
35
#include <asm/asm-offsets.h>
4-
#include <linux/stringify.h>
56

6-
#ifdef CONFIG_PARAVIRT_XXL
7+
#ifdef CONFIG_X86_64
8+
# ifdef CONFIG_PARAVIRT_XXL
79
DEF_NATIVE(irq, irq_disable, "cli");
810
DEF_NATIVE(irq, irq_enable, "sti");
911
DEF_NATIVE(irq, restore_fl, "pushq %rdi; popfq");
@@ -12,24 +14,49 @@ DEF_NATIVE(mmu, read_cr2, "movq %cr2, %rax");
1214
DEF_NATIVE(mmu, read_cr3, "movq %cr3, %rax");
1315
DEF_NATIVE(mmu, write_cr3, "movq %rdi, %cr3");
1416
DEF_NATIVE(cpu, wbinvd, "wbinvd");
15-
1617
DEF_NATIVE(cpu, usergs_sysret64, "swapgs; sysretq");
1718
DEF_NATIVE(cpu, swapgs, "swapgs");
1819
DEF_NATIVE(, mov64, "mov %rdi, %rax");
1920

20-
unsigned paravirt_patch_ident_64(void *insnbuf, unsigned len)
21+
unsigned int paravirt_patch_ident_64(void *insnbuf, unsigned int len)
2122
{
22-
return paravirt_patch_insns(insnbuf, len,
23-
start__mov64, end__mov64);
23+
return paravirt_patch_insns(insnbuf, len, start__mov64, end__mov64);
2424
}
25-
#endif
25+
# endif /* CONFIG_PARAVIRT_XXL */
2626

27-
#if defined(CONFIG_PARAVIRT_SPINLOCKS)
27+
# ifdef CONFIG_PARAVIRT_SPINLOCKS
2828
DEF_NATIVE(lock, queued_spin_unlock, "movb $0, (%rdi)");
2929
DEF_NATIVE(lock, vcpu_is_preempted, "xor %eax, %eax");
30-
#endif
30+
# endif
31+
32+
#else /* CONFIG_X86_64 */
33+
34+
# ifdef CONFIG_PARAVIRT_XXL
35+
DEF_NATIVE(irq, irq_disable, "cli");
36+
DEF_NATIVE(irq, irq_enable, "sti");
37+
DEF_NATIVE(irq, restore_fl, "push %eax; popf");
38+
DEF_NATIVE(irq, save_fl, "pushf; pop %eax");
39+
DEF_NATIVE(cpu, iret, "iret");
40+
DEF_NATIVE(mmu, read_cr2, "mov %cr2, %eax");
41+
DEF_NATIVE(mmu, write_cr3, "mov %eax, %cr3");
42+
DEF_NATIVE(mmu, read_cr3, "mov %cr3, %eax");
43+
44+
unsigned int paravirt_patch_ident_64(void *insnbuf, unsigned int len)
45+
{
46+
/* arg in %edx:%eax, return in %edx:%eax */
47+
return 0;
48+
}
49+
# endif /* CONFIG_PARAVIRT_XXL */
50+
51+
# ifdef CONFIG_PARAVIRT_SPINLOCKS
52+
DEF_NATIVE(lock, queued_spin_unlock, "movb $0, (%eax)");
53+
DEF_NATIVE(lock, vcpu_is_preempted, "xor %eax, %eax");
54+
# endif
55+
56+
#endif /* !CONFIG_X86_64 */
3157

32-
unsigned native_patch(u8 type, void *ibuf, unsigned long addr, unsigned len)
58+
unsigned int native_patch(u8 type, void *ibuf, unsigned long addr,
59+
unsigned int len)
3360
{
3461
#define PATCH_SITE(ops, x) \
3562
case PARAVIRT_PATCH(ops.x): \
@@ -41,14 +68,21 @@ unsigned native_patch(u8 type, void *ibuf, unsigned long addr, unsigned len)
4168
PATCH_SITE(irq, save_fl);
4269
PATCH_SITE(irq, irq_enable);
4370
PATCH_SITE(irq, irq_disable);
44-
PATCH_SITE(cpu, usergs_sysret64);
45-
PATCH_SITE(cpu, swapgs);
46-
PATCH_SITE(cpu, wbinvd);
71+
4772
PATCH_SITE(mmu, read_cr2);
4873
PATCH_SITE(mmu, read_cr3);
4974
PATCH_SITE(mmu, write_cr3);
75+
76+
# ifdef CONFIG_X86_64
77+
PATCH_SITE(cpu, usergs_sysret64);
78+
PATCH_SITE(cpu, swapgs);
79+
PATCH_SITE(cpu, wbinvd);
80+
# else
81+
PATCH_SITE(cpu, iret);
82+
# endif
5083
#endif
51-
#if defined(CONFIG_PARAVIRT_SPINLOCKS)
84+
85+
#ifdef CONFIG_PARAVIRT_SPINLOCKS
5286
case PARAVIRT_PATCH(lock.queued_spin_unlock):
5387
if (pv_is_native_spin_unlock())
5488
return paravirt_patch_insns(ibuf, len,

arch/x86/kernel/paravirt_patch_32.c

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)