Skip to content

Commit 35de5b0

Browse files
amlutoingomolnar
authored andcommitted
x86/asm: Stop depending on ptrace.h in alternative.h
alternative.h pulls in ptrace.h, which means that alternatives can't be used in anything referenced from ptrace.h, which is a mess. Break the dependency by pulling text patching helpers into their own header. Signed-off-by: Andy Lutomirski <luto@kernel.org> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/99b93b13f2c9eb671f5c98bba4c2cbdc061293a2.1461698311.git.luto@kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent ffc5fce commit 35de5b0

11 files changed

Lines changed: 50 additions & 33 deletions

File tree

‎arch/x86/include/asm/alternative.h‎

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include <linux/stddef.h>
66
#include <linux/stringify.h>
77
#include <asm/asm.h>
8-
#include <asm/ptrace.h>
98

109
/*
1110
* Alternative inline assembly for SMP.
@@ -233,36 +232,4 @@ static inline int alternatives_text_reserved(void *start, void *end)
233232
*/
234233
#define ASM_NO_INPUT_CLOBBER(clbr...) "i" (0) : clbr
235234

236-
struct paravirt_patch_site;
237-
#ifdef CONFIG_PARAVIRT
238-
void apply_paravirt(struct paravirt_patch_site *start,
239-
struct paravirt_patch_site *end);
240-
#else
241-
static inline void apply_paravirt(struct paravirt_patch_site *start,
242-
struct paravirt_patch_site *end)
243-
{}
244-
#define __parainstructions NULL
245-
#define __parainstructions_end NULL
246-
#endif
247-
248-
extern void *text_poke_early(void *addr, const void *opcode, size_t len);
249-
250-
/*
251-
* Clear and restore the kernel write-protection flag on the local CPU.
252-
* Allows the kernel to edit read-only pages.
253-
* Side-effect: any interrupt handler running between save and restore will have
254-
* the ability to write to read-only pages.
255-
*
256-
* Warning:
257-
* Code patching in the UP case is safe if NMIs and MCE handlers are stopped and
258-
* no thread can be preempted in the instructions being modified (no iret to an
259-
* invalid instruction possible) or if the instructions are changed from a
260-
* consistent state to another consistent state atomically.
261-
* On the local CPU you need to be protected again NMI or MCE handlers seeing an
262-
* inconsistent instruction while you patch.
263-
*/
264-
extern void *text_poke(void *addr, const void *opcode, size_t len);
265-
extern int poke_int3_handler(struct pt_regs *regs);
266-
extern void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler);
267-
268235
#endif /* _ASM_X86_ALTERNATIVE_H */

‎arch/x86/include/asm/kgdb.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* Copyright (C) 2008 Wind River Systems, Inc.
77
*/
88

9+
#include <asm/ptrace.h>
10+
911
/*
1012
* BUFMAX defines the maximum number of characters in inbound/outbound
1113
* buffers at least NUMREGBYTES*2 are needed for register packets

‎arch/x86/include/asm/setup.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define COMMAND_LINE_SIZE 2048
77

88
#include <linux/linkage.h>
9+
#include <asm/page_types.h>
910

1011
#ifdef __i386__
1112

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#ifndef _ASM_X86_TEXT_PATCHING_H
2+
#define _ASM_X86_TEXT_PATCHING_H
3+
4+
#include <linux/types.h>
5+
#include <linux/stddef.h>
6+
#include <asm/ptrace.h>
7+
8+
struct paravirt_patch_site;
9+
#ifdef CONFIG_PARAVIRT
10+
void apply_paravirt(struct paravirt_patch_site *start,
11+
struct paravirt_patch_site *end);
12+
#else
13+
static inline void apply_paravirt(struct paravirt_patch_site *start,
14+
struct paravirt_patch_site *end)
15+
{}
16+
#define __parainstructions NULL
17+
#define __parainstructions_end NULL
18+
#endif
19+
20+
extern void *text_poke_early(void *addr, const void *opcode, size_t len);
21+
22+
/*
23+
* Clear and restore the kernel write-protection flag on the local CPU.
24+
* Allows the kernel to edit read-only pages.
25+
* Side-effect: any interrupt handler running between save and restore will have
26+
* the ability to write to read-only pages.
27+
*
28+
* Warning:
29+
* Code patching in the UP case is safe if NMIs and MCE handlers are stopped and
30+
* no thread can be preempted in the instructions being modified (no iret to an
31+
* invalid instruction possible) or if the instructions are changed from a
32+
* consistent state to another consistent state atomically.
33+
* On the local CPU you need to be protected again NMI or MCE handlers seeing an
34+
* inconsistent instruction while you patch.
35+
*/
36+
extern void *text_poke(void *addr, const void *opcode, size_t len);
37+
extern int poke_int3_handler(struct pt_regs *regs);
38+
extern void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler);
39+
40+
#endif /* _ASM_X86_TEXT_PATCHING_H */

‎arch/x86/kernel/alternative.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/stop_machine.h>
1212
#include <linux/slab.h>
1313
#include <linux/kdebug.h>
14+
#include <asm/text-patching.h>
1415
#include <asm/alternative.h>
1516
#include <asm/sections.h>
1617
#include <asm/pgtable.h>

‎arch/x86/kernel/jump_label.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/cpu.h>
1414
#include <asm/kprobes.h>
1515
#include <asm/alternative.h>
16+
#include <asm/text-patching.h>
1617

1718
#ifdef HAVE_JUMP_LABEL
1819

‎arch/x86/kernel/kgdb.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include <linux/uaccess.h>
4646
#include <linux/memory.h>
4747

48+
#include <asm/text-patching.h>
4849
#include <asm/debugreg.h>
4950
#include <asm/apicdef.h>
5051
#include <asm/apic.h>

‎arch/x86/kernel/kprobes/core.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include <linux/ftrace.h>
5252
#include <linux/frame.h>
5353

54+
#include <asm/text-patching.h>
5455
#include <asm/cacheflush.h>
5556
#include <asm/desc.h>
5657
#include <asm/pgtable.h>

‎arch/x86/kernel/kprobes/opt.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <linux/kallsyms.h>
3030
#include <linux/ftrace.h>
3131

32+
#include <asm/text-patching.h>
3233
#include <asm/cacheflush.h>
3334
#include <asm/desc.h>
3435
#include <asm/pgtable.h>

‎arch/x86/kernel/module.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <linux/jump_label.h>
3232
#include <linux/random.h>
3333

34+
#include <asm/text-patching.h>
3435
#include <asm/page.h>
3536
#include <asm/pgtable.h>
3637
#include <asm/setup.h>

0 commit comments

Comments
 (0)