Skip to content

Commit 9824b00

Browse files
jgross1bp3tk0v
authored andcommitted
x86/paravirt: Move some functions and defines to alternative.c
As a preparation for replacing paravirt patching completely by alternative patching, move some backend functions and #defines to the alternatives code and header. Signed-off-by: Juergen Gross <jgross@suse.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://lore.kernel.org/r/20231129133332.31043-3-jgross@suse.com
1 parent 772ca41 commit 9824b00

8 files changed

Lines changed: 41 additions & 41 deletions

File tree

arch/x86/include/asm/alternative.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,22 @@ static inline int alternatives_text_reserved(void *start, void *end)
330330
*/
331331
#define ASM_NO_INPUT_CLOBBER(clbr...) "i" (0) : clbr
332332

333+
/* Macro for creating assembler functions avoiding any C magic. */
334+
#define DEFINE_ASM_FUNC(func, instr, sec) \
335+
asm (".pushsection " #sec ", \"ax\"\n" \
336+
".global " #func "\n\t" \
337+
".type " #func ", @function\n\t" \
338+
ASM_FUNC_ALIGN "\n" \
339+
#func ":\n\t" \
340+
ASM_ENDBR \
341+
instr "\n\t" \
342+
ASM_RET \
343+
".size " #func ", . - " #func "\n\t" \
344+
".popsection")
345+
346+
void BUG_func(void);
347+
void nop_func(void);
348+
333349
#else /* __ASSEMBLY__ */
334350

335351
#ifdef CONFIG_SMP

arch/x86/include/asm/paravirt.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -720,18 +720,6 @@ static __always_inline unsigned long arch_local_irq_save(void)
720720
#undef PVOP_VCALL4
721721
#undef PVOP_CALL4
722722

723-
#define DEFINE_PARAVIRT_ASM(func, instr, sec) \
724-
asm (".pushsection " #sec ", \"ax\"\n" \
725-
".global " #func "\n\t" \
726-
".type " #func ", @function\n\t" \
727-
ASM_FUNC_ALIGN "\n" \
728-
#func ":\n\t" \
729-
ASM_ENDBR \
730-
instr "\n\t" \
731-
ASM_RET \
732-
".size " #func ", . - " #func "\n\t" \
733-
".popsection")
734-
735723
extern void default_banner(void);
736724
void native_pv_lock_init(void) __init;
737725

arch/x86/include/asm/paravirt_types.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,6 @@ int paravirt_disable_iospace(void);
540540
__PVOP_VCALL(op, PVOP_CALL_ARG1(arg1), PVOP_CALL_ARG2(arg2), \
541541
PVOP_CALL_ARG3(arg3), PVOP_CALL_ARG4(arg4))
542542

543-
void _paravirt_nop(void);
544-
void paravirt_BUG(void);
545543
unsigned long paravirt_ret0(void);
546544
#ifdef CONFIG_PARAVIRT_XXL
547545
u64 _paravirt_ident_64(u64);
@@ -551,7 +549,7 @@ void pv_native_irq_enable(void);
551549
unsigned long pv_native_read_cr2(void);
552550
#endif
553551

554-
#define paravirt_nop ((void *)_paravirt_nop)
552+
#define paravirt_nop ((void *)nop_func)
555553

556554
extern struct paravirt_patch_site __parainstructions[],
557555
__parainstructions_end[];

arch/x86/include/asm/qspinlock_paravirt.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ __PV_CALLEE_SAVE_REGS_THUNK(__pv_queued_spin_unlock_slowpath, ".spinlock.text");
5656
"pop %rdx\n\t" \
5757
FRAME_END
5858

59-
DEFINE_PARAVIRT_ASM(__raw_callee_save___pv_queued_spin_unlock,
60-
PV_UNLOCK_ASM, .spinlock.text);
59+
DEFINE_ASM_FUNC(__raw_callee_save___pv_queued_spin_unlock,
60+
PV_UNLOCK_ASM, .spinlock.text);
6161

6262
#else /* CONFIG_64BIT */
6363

arch/x86/kernel/alternative.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,16 @@ apply_relocation(u8 *buf, size_t len, u8 *dest, u8 *src, size_t src_len)
385385
}
386386
}
387387

388+
/* Low-level backend functions usable from alternative code replacements. */
389+
DEFINE_ASM_FUNC(nop_func, "", .entry.text);
390+
EXPORT_SYMBOL_GPL(nop_func);
391+
392+
noinstr void BUG_func(void)
393+
{
394+
BUG();
395+
}
396+
EXPORT_SYMBOL_GPL(BUG_func);
397+
388398
/*
389399
* Replace instructions with better alternatives for this CPU type. This runs
390400
* before SMP is initialized to avoid SMP problems with self modifying code.

arch/x86/kernel/kvm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -803,8 +803,8 @@ extern bool __raw_callee_save___kvm_vcpu_is_preempted(long);
803803
"cmpb $0, " __stringify(KVM_STEAL_TIME_preempted) "+steal_time(%rax)\n\t" \
804804
"setne %al\n\t"
805805

806-
DEFINE_PARAVIRT_ASM(__raw_callee_save___kvm_vcpu_is_preempted,
807-
PV_VCPU_PREEMPTED_ASM, .text);
806+
DEFINE_ASM_FUNC(__raw_callee_save___kvm_vcpu_is_preempted,
807+
PV_VCPU_PREEMPTED_ASM, .text);
808808
#endif
809809

810810
static void __init kvm_guest_init(void)

arch/x86/kernel/paravirt.c

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,15 @@
3434
#include <asm/io_bitmap.h>
3535
#include <asm/gsseg.h>
3636

37-
/*
38-
* nop stub, which must not clobber anything *including the stack* to
39-
* avoid confusing the entry prologues.
40-
*/
41-
DEFINE_PARAVIRT_ASM(_paravirt_nop, "", .entry.text);
42-
4337
/* stub always returning 0. */
44-
DEFINE_PARAVIRT_ASM(paravirt_ret0, "xor %eax,%eax", .entry.text);
38+
DEFINE_ASM_FUNC(paravirt_ret0, "xor %eax,%eax", .entry.text);
4539

4640
void __init default_banner(void)
4741
{
4842
printk(KERN_INFO "Booting paravirtualized kernel on %s\n",
4943
pv_info.name);
5044
}
5145

52-
/* Undefined instruction for dealing with missing ops pointers. */
53-
noinstr void paravirt_BUG(void)
54-
{
55-
BUG();
56-
}
57-
5846
static unsigned paravirt_patch_call(void *insn_buff, const void *target,
5947
unsigned long addr, unsigned len)
6048
{
@@ -64,11 +52,11 @@ static unsigned paravirt_patch_call(void *insn_buff, const void *target,
6452
}
6553

6654
#ifdef CONFIG_PARAVIRT_XXL
67-
DEFINE_PARAVIRT_ASM(_paravirt_ident_64, "mov %rdi, %rax", .text);
68-
DEFINE_PARAVIRT_ASM(pv_native_save_fl, "pushf; pop %rax", .noinstr.text);
69-
DEFINE_PARAVIRT_ASM(pv_native_irq_disable, "cli", .noinstr.text);
70-
DEFINE_PARAVIRT_ASM(pv_native_irq_enable, "sti", .noinstr.text);
71-
DEFINE_PARAVIRT_ASM(pv_native_read_cr2, "mov %cr2, %rax", .noinstr.text);
55+
DEFINE_ASM_FUNC(_paravirt_ident_64, "mov %rdi, %rax", .text);
56+
DEFINE_ASM_FUNC(pv_native_save_fl, "pushf; pop %rax", .noinstr.text);
57+
DEFINE_ASM_FUNC(pv_native_irq_disable, "cli", .noinstr.text);
58+
DEFINE_ASM_FUNC(pv_native_irq_enable, "sti", .noinstr.text);
59+
DEFINE_ASM_FUNC(pv_native_read_cr2, "mov %cr2, %rax", .noinstr.text);
7260
#endif
7361

7462
DEFINE_STATIC_KEY_TRUE(virt_spin_lock_key);
@@ -96,9 +84,9 @@ unsigned int paravirt_patch(u8 type, void *insn_buff, unsigned long addr,
9684
unsigned ret;
9785

9886
if (opfunc == NULL)
99-
/* If there's no function, patch it with paravirt_BUG() */
100-
ret = paravirt_patch_call(insn_buff, paravirt_BUG, addr, len);
101-
else if (opfunc == _paravirt_nop)
87+
/* If there's no function, patch it with BUG_func() */
88+
ret = paravirt_patch_call(insn_buff, BUG_func, addr, len);
89+
else if (opfunc == nop_func)
10290
ret = 0;
10391
else
10492
/* Otherwise call the function. */

arch/x86/xen/irq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static const typeof(pv_ops) xen_irq_ops __initconst = {
4545
/* Initial interrupt flag handling only called while interrupts off. */
4646
.save_fl = __PV_IS_CALLEE_SAVE(paravirt_ret0),
4747
.irq_disable = __PV_IS_CALLEE_SAVE(paravirt_nop),
48-
.irq_enable = __PV_IS_CALLEE_SAVE(paravirt_BUG),
48+
.irq_enable = __PV_IS_CALLEE_SAVE(BUG_func),
4949

5050
.safe_halt = xen_safe_halt,
5151
.halt = xen_halt,

0 commit comments

Comments
 (0)