Skip to content

Commit f7af697

Browse files
jgross1bp3tk0v
authored andcommitted
x86/paravirt: Remove no longer needed paravirt patching code
Now that paravirt is using the alternatives patching infrastructure, remove the paravirt patching code. Signed-off-by: Juergen Gross <jgross@suse.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lore.kernel.org/r/20231210062138.2417-6-jgross@suse.com
1 parent 60bc276 commit f7af697

7 files changed

Lines changed: 3 additions & 172 deletions

File tree

arch/x86/include/asm/paravirt.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -725,23 +725,10 @@ void native_pv_lock_init(void) __init;
725725

726726
#else /* __ASSEMBLY__ */
727727

728-
#define _PVSITE(ptype, ops) \
729-
771:; \
730-
ops; \
731-
772:; \
732-
.pushsection .parainstructions,"a"; \
733-
.long 771b-.; \
734-
.byte ptype; \
735-
.byte 772b-771b; \
736-
.popsection
737-
738-
739728
#ifdef CONFIG_X86_64
740729
#ifdef CONFIG_PARAVIRT_XXL
741730
#ifdef CONFIG_DEBUG_ENTRY
742731

743-
#define PARA_PATCH(off) ((off) / 8)
744-
#define PARA_SITE(ptype, ops) _PVSITE(ptype, ops)
745732
#define PARA_INDIRECT(addr) *addr(%rip)
746733

747734
.macro PARA_IRQ_save_fl

arch/x86/include/asm/paravirt_types.h

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,6 @@
22
#ifndef _ASM_X86_PARAVIRT_TYPES_H
33
#define _ASM_X86_PARAVIRT_TYPES_H
44

5-
#ifndef __ASSEMBLY__
6-
/* These all sit in the .parainstructions section to tell us what to patch. */
7-
struct paravirt_patch_site {
8-
s32 instr_offset; /* original instructions */
9-
u8 type; /* type of this instruction */
10-
u8 len; /* length of original instruction */
11-
} __packed;
12-
#endif
13-
145
#ifdef CONFIG_PARAVIRT
156

167
#ifndef __ASSEMBLY__
@@ -250,32 +241,6 @@ struct paravirt_patch_template {
250241
extern struct pv_info pv_info;
251242
extern struct paravirt_patch_template pv_ops;
252243

253-
#define PARAVIRT_PATCH(x) \
254-
(offsetof(struct paravirt_patch_template, x) / sizeof(void *))
255-
256-
#define paravirt_type(op) \
257-
[paravirt_typenum] "i" (PARAVIRT_PATCH(op)), \
258-
[paravirt_opptr] "m" (pv_ops.op)
259-
/*
260-
* Generate some code, and mark it as patchable by the
261-
* apply_paravirt() alternate instruction patcher.
262-
*/
263-
#define _paravirt_alt(insn_string, type) \
264-
"771:\n\t" insn_string "\n" "772:\n" \
265-
".pushsection .parainstructions,\"a\"\n" \
266-
" .long 771b-.\n" \
267-
" .byte " type "\n" \
268-
" .byte 772b-771b\n" \
269-
".popsection\n"
270-
271-
/* Generate patchable code, with the default asm parameters. */
272-
#define paravirt_alt(insn_string) \
273-
_paravirt_alt(insn_string, "%c[paravirt_typenum]")
274-
275-
/* Simple instruction patching code. */
276-
#define NATIVE_LABEL(a,x,b) "\n\t.globl " a #x "_" #b "\n" a #x "_" #b ":\n\t"
277-
278-
unsigned int paravirt_patch(u8 type, void *insn_buff, unsigned long addr, unsigned int len);
279244
#define paravirt_ptr(op) [paravirt_opptr] "m" (pv_ops.op)
280245

281246
int paravirt_disable_iospace(void);
@@ -555,9 +520,6 @@ unsigned long pv_native_read_cr2(void);
555520

556521
#define paravirt_nop ((void *)nop_func)
557522

558-
extern struct paravirt_patch_site __parainstructions[],
559-
__parainstructions_end[];
560-
561523
#endif /* __ASSEMBLY__ */
562524

563525
#define ALT_NOT_XEN ALT_NOT(X86_FEATURE_XENPV)

arch/x86/include/asm/text-patching.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,6 @@
66
#include <linux/stddef.h>
77
#include <asm/ptrace.h>
88

9-
struct paravirt_patch_site;
10-
#ifdef CONFIG_PARAVIRT
11-
void apply_paravirt(struct paravirt_patch_site *start,
12-
struct paravirt_patch_site *end);
13-
#else
14-
static inline void apply_paravirt(struct paravirt_patch_site *start,
15-
struct paravirt_patch_site *end)
16-
{}
17-
#define __parainstructions NULL
18-
#define __parainstructions_end NULL
19-
#endif
20-
219
/*
2210
* Currently, the max observed size in the kernel code is
2311
* JUMP_LABEL_NOP_SIZE/RELATIVEJUMP_SIZE, which are 5.

arch/x86/kernel/alternative.c

Lines changed: 2 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,48 +1472,6 @@ int alternatives_text_reserved(void *start, void *end)
14721472
}
14731473
#endif /* CONFIG_SMP */
14741474

1475-
#ifdef CONFIG_PARAVIRT
1476-
1477-
/* Use this to add nops to a buffer, then text_poke the whole buffer. */
1478-
static void __init_or_module add_nops(void *insns, unsigned int len)
1479-
{
1480-
while (len > 0) {
1481-
unsigned int noplen = len;
1482-
if (noplen > ASM_NOP_MAX)
1483-
noplen = ASM_NOP_MAX;
1484-
memcpy(insns, x86_nops[noplen], noplen);
1485-
insns += noplen;
1486-
len -= noplen;
1487-
}
1488-
}
1489-
1490-
void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
1491-
struct paravirt_patch_site *end)
1492-
{
1493-
struct paravirt_patch_site *p;
1494-
char insn_buff[MAX_PATCH_LEN];
1495-
u8 *instr;
1496-
1497-
for (p = start; p < end; p++) {
1498-
unsigned int used;
1499-
1500-
instr = (u8 *)&p->instr_offset + p->instr_offset;
1501-
BUG_ON(p->len > MAX_PATCH_LEN);
1502-
/* prep the buffer with the original instructions */
1503-
memcpy(insn_buff, instr, p->len);
1504-
used = paravirt_patch(p->type, insn_buff, (unsigned long)instr, p->len);
1505-
1506-
BUG_ON(used > p->len);
1507-
1508-
/* Pad the rest with nops */
1509-
add_nops(insn_buff + used, p->len - used);
1510-
text_poke_early(instr, insn_buff, p->len);
1511-
}
1512-
}
1513-
extern struct paravirt_patch_site __start_parainstructions[],
1514-
__stop_parainstructions[];
1515-
#endif /* CONFIG_PARAVIRT */
1516-
15171475
/*
15181476
* Self-test for the INT3 based CALL emulation code.
15191477
*
@@ -1649,28 +1607,11 @@ void __init alternative_instructions(void)
16491607
*/
16501608

16511609
/*
1652-
* Paravirt patching and alternative patching can be combined to
1653-
* replace a function call with a short direct code sequence (e.g.
1654-
* by setting a constant return value instead of doing that in an
1655-
* external function).
1656-
* In order to make this work the following sequence is required:
1657-
* 1. set (artificial) features depending on used paravirt
1658-
* functions which can later influence alternative patching
1659-
* 2. apply paravirt patching (generally replacing an indirect
1660-
* function call with a direct one)
1661-
* 3. apply alternative patching (e.g. replacing a direct function
1662-
* call with a custom code sequence)
1663-
* Doing paravirt patching after alternative patching would clobber
1664-
* the optimization of the custom code with a function call again.
1610+
* Make sure to set (artificial) features depending on used paravirt
1611+
* functions which can later influence alternative patching.
16651612
*/
16661613
paravirt_set_cap();
16671614

1668-
/*
1669-
* First patch paravirt functions, such that we overwrite the indirect
1670-
* call with the direct call.
1671-
*/
1672-
apply_paravirt(__parainstructions, __parainstructions_end);
1673-
16741615
__apply_fineibt(__retpoline_sites, __retpoline_sites_end,
16751616
__cfi_sites, __cfi_sites_end, true);
16761617

@@ -1681,10 +1622,6 @@ void __init alternative_instructions(void)
16811622
apply_retpolines(__retpoline_sites, __retpoline_sites_end);
16821623
apply_returns(__return_sites, __return_sites_end);
16831624

1684-
/*
1685-
* Then patch alternatives, such that those paravirt calls that are in
1686-
* alternatives can be overwritten by their immediate fragments.
1687-
*/
16881625
apply_alternatives(__alt_instructions, __alt_instructions_end);
16891626

16901627
/*

arch/x86/kernel/paravirt.c

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,6 @@ void __init default_banner(void)
4343
pv_info.name);
4444
}
4545

46-
static unsigned paravirt_patch_call(void *insn_buff, const void *target,
47-
unsigned long addr, unsigned len)
48-
{
49-
__text_gen_insn(insn_buff, CALL_INSN_OPCODE,
50-
(void *)addr, target, CALL_INSN_SIZE);
51-
return CALL_INSN_SIZE;
52-
}
53-
5446
#ifdef CONFIG_PARAVIRT_XXL
5547
DEFINE_ASM_FUNC(_paravirt_ident_64, "mov %rdi, %rax", .text);
5648
DEFINE_ASM_FUNC(pv_native_save_fl, "pushf; pop %rax", .noinstr.text);
@@ -73,28 +65,6 @@ static void native_tlb_remove_table(struct mmu_gather *tlb, void *table)
7365
tlb_remove_page(tlb, table);
7466
}
7567

76-
unsigned int paravirt_patch(u8 type, void *insn_buff, unsigned long addr,
77-
unsigned int len)
78-
{
79-
/*
80-
* Neat trick to map patch type back to the call within the
81-
* corresponding structure.
82-
*/
83-
void *opfunc = *((void **)&pv_ops + type);
84-
unsigned ret;
85-
86-
if (opfunc == NULL)
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)
90-
ret = 0;
91-
else
92-
/* Otherwise call the function. */
93-
ret = paravirt_patch_call(insn_buff, opfunc, addr, len);
94-
95-
return ret;
96-
}
97-
9868
struct static_key paravirt_steal_enabled;
9969
struct static_key paravirt_steal_rq_enabled;
10070

arch/x86/kernel/vmlinux.lds.S

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -267,19 +267,6 @@ SECTIONS
267267
}
268268
#endif
269269

270-
/*
271-
* start address and size of operations which during runtime
272-
* can be patched with virtualization friendly instructions or
273-
* baremetal native ones. Think page table operations.
274-
* Details in paravirt_types.h
275-
*/
276-
. = ALIGN(8);
277-
.parainstructions : AT(ADDR(.parainstructions) - LOAD_OFFSET) {
278-
__parainstructions = .;
279-
*(.parainstructions)
280-
__parainstructions_end = .;
281-
}
282-
283270
#ifdef CONFIG_RETPOLINE
284271
/*
285272
* List of instructions that call/jmp/jcc to retpoline thunks

arch/x86/tools/relocs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static const char * const sym_regex_kernel[S_NSYMTYPES] = {
6666
[S_REL] =
6767
"^(__init_(begin|end)|"
6868
"__x86_cpu_dev_(start|end)|"
69-
"(__parainstructions|__alt_instructions)(_end)?|"
69+
"__alt_instructions(_end)?|"
7070
"(__iommu_table|__apicdrivers|__smp_locks)(_end)?|"
7171
"__(start|end)_pci_.*|"
7272
#if CONFIG_FW_LOADER

0 commit comments

Comments
 (0)