Skip to content

Commit 1fc654c

Browse files
author
Ingo Molnar
committed
x86/paravirt: Standardize 'insn_buff' variable names
We currently have 6 (!) separate naming variants to name temporary instruction buffers that are used for code patching: - insnbuf - insnbuff - insn_buff - insn_buffer - ibuf - ibuffer These are used as local variables, percpu fields and function parameters. Standardize all the names to a single variant: 'insn_buff'. 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]> Cc: Thomas Gleixner <[email protected]> Signed-off-by: Ingo Molnar <[email protected]>
1 parent fc93dfd commit 1fc654c

File tree

8 files changed

+93
-96
lines changed

8 files changed

+93
-96
lines changed

arch/x86/events/intel/ds.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ static int alloc_pebs_buffer(int cpu)
337337
struct debug_store *ds = hwev->ds;
338338
size_t bsiz = x86_pmu.pebs_buffer_size;
339339
int max, node = cpu_to_node(cpu);
340-
void *buffer, *ibuffer, *cea;
340+
void *buffer, *insn_buff, *cea;
341341

342342
if (!x86_pmu.pebs)
343343
return 0;
@@ -351,12 +351,12 @@ static int alloc_pebs_buffer(int cpu)
351351
* buffer then.
352352
*/
353353
if (x86_pmu.intel_cap.pebs_format < 2) {
354-
ibuffer = kzalloc_node(PEBS_FIXUP_SIZE, GFP_KERNEL, node);
355-
if (!ibuffer) {
354+
insn_buff = kzalloc_node(PEBS_FIXUP_SIZE, GFP_KERNEL, node);
355+
if (!insn_buff) {
356356
dsfree_pages(buffer, bsiz);
357357
return -ENOMEM;
358358
}
359-
per_cpu(insn_buffer, cpu) = ibuffer;
359+
per_cpu(insn_buffer, cpu) = insn_buff;
360360
}
361361
hwev->ds_pebs_vaddr = buffer;
362362
/* Update the cpu entry area mapping */

arch/x86/include/asm/paravirt_types.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ struct pv_init_ops {
8888
* the number of bytes of code generated, as we nop pad the
8989
* rest in generic code.
9090
*/
91-
unsigned (*patch)(u8 type, void *insnbuf,
91+
unsigned (*patch)(u8 type, void *insn_buff,
9292
unsigned long addr, unsigned len);
9393
} __no_randomize_layout;
9494

@@ -370,14 +370,11 @@ extern struct paravirt_patch_template pv_ops;
370370
/* Simple instruction patching code. */
371371
#define NATIVE_LABEL(a,x,b) "\n\t.globl " a #x "_" #b "\n" a #x "_" #b ":\n\t"
372372

373-
unsigned paravirt_patch_ident_64(void *insnbuf, unsigned len);
374-
unsigned paravirt_patch_default(u8 type, void *insnbuf,
375-
unsigned long addr, unsigned len);
373+
unsigned paravirt_patch_ident_64(void *insn_buff, unsigned len);
374+
unsigned paravirt_patch_default(u8 type, void *insn_buff, unsigned long addr, unsigned len);
375+
unsigned paravirt_patch_insns(void *insn_buff, unsigned len, const char *start, const char *end);
376376

377-
unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
378-
const char *start, const char *end);
379-
380-
unsigned native_patch(u8 type, void *ibuf, unsigned long addr, unsigned len);
377+
unsigned native_patch(u8 type, void *insn_buff, unsigned long addr, unsigned len);
381378

382379
int paravirt_disable_iospace(void);
383380

arch/x86/kernel/alternative.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ static inline bool is_jmp(const u8 opcode)
275275
}
276276

277277
static void __init_or_module
278-
recompute_jump(struct alt_instr *a, u8 *orig_insn, u8 *repl_insn, u8 *insnbuf)
278+
recompute_jump(struct alt_instr *a, u8 *orig_insn, u8 *repl_insn, u8 *insn_buff)
279279
{
280280
u8 *next_rip, *tgt_rip;
281281
s32 n_dspl, o_dspl;
@@ -284,7 +284,7 @@ recompute_jump(struct alt_instr *a, u8 *orig_insn, u8 *repl_insn, u8 *insnbuf)
284284
if (a->replacementlen != 5)
285285
return;
286286

287-
o_dspl = *(s32 *)(insnbuf + 1);
287+
o_dspl = *(s32 *)(insn_buff + 1);
288288

289289
/* next_rip of the replacement JMP */
290290
next_rip = repl_insn + a->replacementlen;
@@ -310,18 +310,18 @@ recompute_jump(struct alt_instr *a, u8 *orig_insn, u8 *repl_insn, u8 *insnbuf)
310310
two_byte_jmp:
311311
n_dspl -= 2;
312312

313-
insnbuf[0] = 0xeb;
314-
insnbuf[1] = (s8)n_dspl;
315-
add_nops(insnbuf + 2, 3);
313+
insn_buff[0] = 0xeb;
314+
insn_buff[1] = (s8)n_dspl;
315+
add_nops(insn_buff + 2, 3);
316316

317317
repl_len = 2;
318318
goto done;
319319

320320
five_byte_jmp:
321321
n_dspl -= 5;
322322

323-
insnbuf[0] = 0xe9;
324-
*(s32 *)&insnbuf[1] = n_dspl;
323+
insn_buff[0] = 0xe9;
324+
*(s32 *)&insn_buff[1] = n_dspl;
325325

326326
repl_len = 5;
327327

@@ -368,7 +368,7 @@ void __init_or_module noinline apply_alternatives(struct alt_instr *start,
368368
{
369369
struct alt_instr *a;
370370
u8 *instr, *replacement;
371-
u8 insnbuf[MAX_PATCH_LEN];
371+
u8 insn_buff[MAX_PATCH_LEN];
372372

373373
DPRINTK("alt table %px, -> %px", start, end);
374374
/*
@@ -381,11 +381,11 @@ void __init_or_module noinline apply_alternatives(struct alt_instr *start,
381381
* order.
382382
*/
383383
for (a = start; a < end; a++) {
384-
int insnbuf_sz = 0;
384+
int insn_buff_sz = 0;
385385

386386
instr = (u8 *)&a->instr_offset + a->instr_offset;
387387
replacement = (u8 *)&a->repl_offset + a->repl_offset;
388-
BUG_ON(a->instrlen > sizeof(insnbuf));
388+
BUG_ON(a->instrlen > sizeof(insn_buff));
389389
BUG_ON(a->cpuid >= (NCAPINTS + NBUGINTS) * 32);
390390
if (!boot_cpu_has(a->cpuid)) {
391391
if (a->padlen > 1)
@@ -403,33 +403,33 @@ void __init_or_module noinline apply_alternatives(struct alt_instr *start,
403403
DUMP_BYTES(instr, a->instrlen, "%px: old_insn: ", instr);
404404
DUMP_BYTES(replacement, a->replacementlen, "%px: rpl_insn: ", replacement);
405405

406-
memcpy(insnbuf, replacement, a->replacementlen);
407-
insnbuf_sz = a->replacementlen;
406+
memcpy(insn_buff, replacement, a->replacementlen);
407+
insn_buff_sz = a->replacementlen;
408408

409409
/*
410410
* 0xe8 is a relative jump; fix the offset.
411411
*
412412
* Instruction length is checked before the opcode to avoid
413413
* accessing uninitialized bytes for zero-length replacements.
414414
*/
415-
if (a->replacementlen == 5 && *insnbuf == 0xe8) {
416-
*(s32 *)(insnbuf + 1) += replacement - instr;
415+
if (a->replacementlen == 5 && *insn_buff == 0xe8) {
416+
*(s32 *)(insn_buff + 1) += replacement - instr;
417417
DPRINTK("Fix CALL offset: 0x%x, CALL 0x%lx",
418-
*(s32 *)(insnbuf + 1),
419-
(unsigned long)instr + *(s32 *)(insnbuf + 1) + 5);
418+
*(s32 *)(insn_buff + 1),
419+
(unsigned long)instr + *(s32 *)(insn_buff + 1) + 5);
420420
}
421421

422422
if (a->replacementlen && is_jmp(replacement[0]))
423-
recompute_jump(a, instr, replacement, insnbuf);
423+
recompute_jump(a, instr, replacement, insn_buff);
424424

425425
if (a->instrlen > a->replacementlen) {
426-
add_nops(insnbuf + a->replacementlen,
426+
add_nops(insn_buff + a->replacementlen,
427427
a->instrlen - a->replacementlen);
428-
insnbuf_sz += a->instrlen - a->replacementlen;
428+
insn_buff_sz += a->instrlen - a->replacementlen;
429429
}
430-
DUMP_BYTES(insnbuf, insnbuf_sz, "%px: final_insn: ", instr);
430+
DUMP_BYTES(insn_buff, insn_buff_sz, "%px: final_insn: ", instr);
431431

432-
text_poke_early(instr, insnbuf, insnbuf_sz);
432+
text_poke_early(instr, insn_buff, insn_buff_sz);
433433
}
434434
}
435435

@@ -591,22 +591,22 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
591591
struct paravirt_patch_site *end)
592592
{
593593
struct paravirt_patch_site *p;
594-
char insnbuf[MAX_PATCH_LEN];
594+
char insn_buff[MAX_PATCH_LEN];
595595

596596
for (p = start; p < end; p++) {
597597
unsigned int used;
598598

599599
BUG_ON(p->len > MAX_PATCH_LEN);
600600
/* prep the buffer with the original instructions */
601-
memcpy(insnbuf, p->instr, p->len);
602-
used = pv_ops.init.patch(p->instrtype, insnbuf,
601+
memcpy(insn_buff, p->instr, p->len);
602+
used = pv_ops.init.patch(p->instrtype, insn_buff,
603603
(unsigned long)p->instr, p->len);
604604

605605
BUG_ON(used > p->len);
606606

607607
/* Pad the rest with nops */
608-
add_nops(insnbuf + used, p->len - used);
609-
text_poke_early(p->instr, insnbuf, p->len);
608+
add_nops(insn_buff + used, p->len - used);
609+
text_poke_early(p->instr, insn_buff, p->len);
610610
}
611611
}
612612
extern struct paravirt_patch_site __start_parainstructions[],

arch/x86/kernel/kprobes/opt.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op,
431431
void arch_optimize_kprobes(struct list_head *oplist)
432432
{
433433
struct optimized_kprobe *op, *tmp;
434-
u8 insn_buf[RELATIVEJUMP_SIZE];
434+
u8 insn_buff[RELATIVEJUMP_SIZE];
435435

436436
list_for_each_entry_safe(op, tmp, oplist, list) {
437437
s32 rel = (s32)((long)op->optinsn.insn -
@@ -443,10 +443,10 @@ void arch_optimize_kprobes(struct list_head *oplist)
443443
memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
444444
RELATIVE_ADDR_SIZE);
445445

446-
insn_buf[0] = RELATIVEJUMP_OPCODE;
447-
*(s32 *)(&insn_buf[1]) = rel;
446+
insn_buff[0] = RELATIVEJUMP_OPCODE;
447+
*(s32 *)(&insn_buff[1]) = rel;
448448

449-
text_poke_bp(op->kp.addr, insn_buf, RELATIVEJUMP_SIZE,
449+
text_poke_bp(op->kp.addr, insn_buff, RELATIVEJUMP_SIZE,
450450
op->optinsn.insn);
451451

452452
list_del_init(&op->list);
@@ -456,12 +456,12 @@ void arch_optimize_kprobes(struct list_head *oplist)
456456
/* Replace a relative jump with a breakpoint (int3). */
457457
void arch_unoptimize_kprobe(struct optimized_kprobe *op)
458458
{
459-
u8 insn_buf[RELATIVEJUMP_SIZE];
459+
u8 insn_buff[RELATIVEJUMP_SIZE];
460460

461461
/* Set int3 to first byte for kprobes */
462-
insn_buf[0] = BREAKPOINT_INSTRUCTION;
463-
memcpy(insn_buf + 1, op->optinsn.copied_insn, RELATIVE_ADDR_SIZE);
464-
text_poke_bp(op->kp.addr, insn_buf, RELATIVEJUMP_SIZE,
462+
insn_buff[0] = BREAKPOINT_INSTRUCTION;
463+
memcpy(insn_buff + 1, op->optinsn.copied_insn, RELATIVE_ADDR_SIZE);
464+
text_poke_bp(op->kp.addr, insn_buff, RELATIVEJUMP_SIZE,
465465
op->optinsn.insn);
466466
}
467467

arch/x86/kernel/paravirt.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ struct branch {
7070
u32 delta;
7171
} __attribute__((packed));
7272

73-
static unsigned paravirt_patch_call(void *insnbuf, const void *target,
73+
static unsigned paravirt_patch_call(void *insn_buff, const void *target,
7474
unsigned long addr, unsigned len)
7575
{
7676
const int call_len = 5;
77-
struct branch *b = insnbuf;
77+
struct branch *b = insn_buff;
7878
unsigned long delta = (unsigned long)target - (addr+call_len);
7979

8080
if (len < call_len) {
@@ -97,10 +97,10 @@ u64 notrace _paravirt_ident_64(u64 x)
9797
return x;
9898
}
9999

100-
static unsigned paravirt_patch_jmp(void *insnbuf, const void *target,
100+
static unsigned paravirt_patch_jmp(void *insn_buff, const void *target,
101101
unsigned long addr, unsigned len)
102102
{
103-
struct branch *b = insnbuf;
103+
struct branch *b = insn_buff;
104104
unsigned long delta = (unsigned long)target - (addr+5);
105105

106106
if (len < 5) {
@@ -125,7 +125,7 @@ void __init native_pv_lock_init(void)
125125
static_branch_disable(&virt_spin_lock_key);
126126
}
127127

128-
unsigned paravirt_patch_default(u8 type, void *insnbuf,
128+
unsigned paravirt_patch_default(u8 type, void *insn_buff,
129129
unsigned long addr, unsigned len)
130130
{
131131
/*
@@ -137,36 +137,36 @@ unsigned paravirt_patch_default(u8 type, void *insnbuf,
137137

138138
if (opfunc == NULL)
139139
/* If there's no function, patch it with a ud2a (BUG) */
140-
ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
140+
ret = paravirt_patch_insns(insn_buff, len, ud2a, ud2a+sizeof(ud2a));
141141
else if (opfunc == _paravirt_nop)
142142
ret = 0;
143143

144144
#ifdef CONFIG_PARAVIRT_XXL
145145
/* identity functions just return their single argument */
146146
else if (opfunc == _paravirt_ident_64)
147-
ret = paravirt_patch_ident_64(insnbuf, len);
147+
ret = paravirt_patch_ident_64(insn_buff, len);
148148

149149
else if (type == PARAVIRT_PATCH(cpu.iret) ||
150150
type == PARAVIRT_PATCH(cpu.usergs_sysret64))
151151
/* If operation requires a jmp, then jmp */
152-
ret = paravirt_patch_jmp(insnbuf, opfunc, addr, len);
152+
ret = paravirt_patch_jmp(insn_buff, opfunc, addr, len);
153153
#endif
154154
else
155155
/* Otherwise call the function. */
156-
ret = paravirt_patch_call(insnbuf, opfunc, addr, len);
156+
ret = paravirt_patch_call(insn_buff, opfunc, addr, len);
157157

158158
return ret;
159159
}
160160

161-
unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
161+
unsigned paravirt_patch_insns(void *insn_buff, unsigned len,
162162
const char *start, const char *end)
163163
{
164164
unsigned insn_len = end - start;
165165

166166
/* Alternative instruction is too large for the patch site and we cannot continue: */
167167
BUG_ON(insn_len > len || start == NULL);
168168

169-
memcpy(insnbuf, start, insn_len);
169+
memcpy(insn_buff, start, insn_len);
170170

171171
return insn_len;
172172
}

arch/x86/kernel/paravirt_patch.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
#define PEND(d, m) \
1111
(PSTART(d, m) + sizeof(patch_data_##d.m))
1212

13-
#define PATCH(d, m, ibuf, len) \
14-
paravirt_patch_insns(ibuf, len, PSTART(d, m), PEND(d, m))
13+
#define PATCH(d, m, insn_buff, len) \
14+
paravirt_patch_insns(insn_buff, len, PSTART(d, m), PEND(d, m))
1515

16-
#define PATCH_CASE(ops, m, data, ibuf, len) \
16+
#define PATCH_CASE(ops, m, data, insn_buff, len) \
1717
case PARAVIRT_PATCH(ops.m): \
18-
return PATCH(data, ops##_##m, ibuf, len)
18+
return PATCH(data, ops##_##m, insn_buff, len)
1919

2020
#ifdef CONFIG_PARAVIRT_XXL
2121
struct patch_xxl {
@@ -57,10 +57,10 @@ static const struct patch_xxl patch_data_xxl = {
5757
# endif
5858
};
5959

60-
unsigned int paravirt_patch_ident_64(void *insnbuf, unsigned int len)
60+
unsigned int paravirt_patch_ident_64(void *insn_buff, unsigned int len)
6161
{
6262
#ifdef CONFIG_X86_64
63-
return PATCH(xxl, mov64, insnbuf, len);
63+
return PATCH(xxl, mov64, insn_buff, len);
6464
#endif
6565
return 0;
6666
}
@@ -83,44 +83,44 @@ static const struct patch_lock patch_data_lock = {
8383
};
8484
#endif /* CONFIG_PARAVIRT_SPINLOCKS */
8585

86-
unsigned int native_patch(u8 type, void *ibuf, unsigned long addr,
86+
unsigned int native_patch(u8 type, void *insn_buff, unsigned long addr,
8787
unsigned int len)
8888
{
8989
switch (type) {
9090

9191
#ifdef CONFIG_PARAVIRT_XXL
92-
PATCH_CASE(irq, restore_fl, xxl, ibuf, len);
93-
PATCH_CASE(irq, save_fl, xxl, ibuf, len);
94-
PATCH_CASE(irq, irq_enable, xxl, ibuf, len);
95-
PATCH_CASE(irq, irq_disable, xxl, ibuf, len);
92+
PATCH_CASE(irq, restore_fl, xxl, insn_buff, len);
93+
PATCH_CASE(irq, save_fl, xxl, insn_buff, len);
94+
PATCH_CASE(irq, irq_enable, xxl, insn_buff, len);
95+
PATCH_CASE(irq, irq_disable, xxl, insn_buff, len);
9696

97-
PATCH_CASE(mmu, read_cr2, xxl, ibuf, len);
98-
PATCH_CASE(mmu, read_cr3, xxl, ibuf, len);
99-
PATCH_CASE(mmu, write_cr3, xxl, ibuf, len);
97+
PATCH_CASE(mmu, read_cr2, xxl, insn_buff, len);
98+
PATCH_CASE(mmu, read_cr3, xxl, insn_buff, len);
99+
PATCH_CASE(mmu, write_cr3, xxl, insn_buff, len);
100100

101101
# ifdef CONFIG_X86_64
102-
PATCH_CASE(cpu, usergs_sysret64, xxl, ibuf, len);
103-
PATCH_CASE(cpu, swapgs, xxl, ibuf, len);
104-
PATCH_CASE(cpu, wbinvd, xxl, ibuf, len);
102+
PATCH_CASE(cpu, usergs_sysret64, xxl, insn_buff, len);
103+
PATCH_CASE(cpu, swapgs, xxl, insn_buff, len);
104+
PATCH_CASE(cpu, wbinvd, xxl, insn_buff, len);
105105
# else
106-
PATCH_CASE(cpu, iret, xxl, ibuf, len);
106+
PATCH_CASE(cpu, iret, xxl, insn_buff, len);
107107
# endif
108108
#endif
109109

110110
#ifdef CONFIG_PARAVIRT_SPINLOCKS
111111
case PARAVIRT_PATCH(lock.queued_spin_unlock):
112112
if (pv_is_native_spin_unlock())
113-
return PATCH(lock, queued_spin_unlock, ibuf, len);
113+
return PATCH(lock, queued_spin_unlock, insn_buff, len);
114114
break;
115115

116116
case PARAVIRT_PATCH(lock.vcpu_is_preempted):
117117
if (pv_is_native_vcpu_is_preempted())
118-
return PATCH(lock, vcpu_is_preempted, ibuf, len);
118+
return PATCH(lock, vcpu_is_preempted, insn_buff, len);
119119
break;
120120
#endif
121121
default:
122122
break;
123123
}
124124

125-
return paravirt_patch_default(type, ibuf, addr, len);
125+
return paravirt_patch_default(type, insn_buff, addr, len);
126126
}

0 commit comments

Comments
 (0)