code-patching.c (2f228ee1ade5d8d1f26cf94863a36c5693023c58) code-patching.c (84ecfe6f38ae4ee779ebd97ee173937fff565bf9)
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright 2008 Michael Ellerman, IBM Corporation.
4 */
5
6#include <linux/kprobes.h>
7#include <linux/mmu_context.h>
8#include <linux/random.h>

--- 32 unchanged lines hidden (view full) ---

41 return -EPERM;
42}
43
44int raw_patch_instruction(u32 *addr, ppc_inst_t instr)
45{
46 return __patch_instruction(addr, instr, addr);
47}
48
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright 2008 Michael Ellerman, IBM Corporation.
4 */
5
6#include <linux/kprobes.h>
7#include <linux/mmu_context.h>
8#include <linux/random.h>

--- 32 unchanged lines hidden (view full) ---

41 return -EPERM;
42}
43
44int raw_patch_instruction(u32 *addr, ppc_inst_t instr)
45{
46 return __patch_instruction(addr, instr, addr);
47}
48
49#ifdef CONFIG_STRICT_KERNEL_RWX
50
51struct patch_context {
52 union {
53 struct vm_struct *area;
54 struct mm_struct *mm;
55 };
56 unsigned long addr;
57 pte_t *pte;
58};

--- 144 unchanged lines hidden (view full) ---

203}
204
205static __ro_after_init DEFINE_STATIC_KEY_FALSE(poking_init_done);
206
207void __init poking_init(void)
208{
209 int ret;
210
49struct patch_context {
50 union {
51 struct vm_struct *area;
52 struct mm_struct *mm;
53 };
54 unsigned long addr;
55 pte_t *pte;
56};

--- 144 unchanged lines hidden (view full) ---

201}
202
203static __ro_after_init DEFINE_STATIC_KEY_FALSE(poking_init_done);
204
205void __init poking_init(void)
206{
207 int ret;
208
209 if (!IS_ENABLED(CONFIG_STRICT_KERNEL_RWX))
210 return;
211
211 if (mm_patch_enabled())
212 ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
213 "powerpc/text_poke_mm:online",
214 text_area_cpu_up_mm,
215 text_area_cpu_down_mm);
216 else
217 ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
218 "powerpc/text_poke:online",

--- 134 unchanged lines hidden (view full) ---

353 int err;
354 unsigned long flags;
355
356 /*
357 * During early early boot patch_instruction is called
358 * when text_poke_area is not ready, but we still need
359 * to allow patching. We just do the plain old patching
360 */
212 if (mm_patch_enabled())
213 ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
214 "powerpc/text_poke_mm:online",
215 text_area_cpu_up_mm,
216 text_area_cpu_down_mm);
217 else
218 ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
219 "powerpc/text_poke:online",

--- 134 unchanged lines hidden (view full) ---

354 int err;
355 unsigned long flags;
356
357 /*
358 * During early early boot patch_instruction is called
359 * when text_poke_area is not ready, but we still need
360 * to allow patching. We just do the plain old patching
361 */
361 if (!static_branch_likely(&poking_init_done))
362 if (!IS_ENABLED(CONFIG_STRICT_KERNEL_RWX) ||
363 !static_branch_likely(&poking_init_done))
362 return raw_patch_instruction(addr, instr);
363
364 local_irq_save(flags);
365 if (mm_patch_enabled())
366 err = __do_patch_instruction_mm(addr, instr);
367 else
368 err = __do_patch_instruction(addr, instr);
369 local_irq_restore(flags);
370
371 return err;
372}
364 return raw_patch_instruction(addr, instr);
365
366 local_irq_save(flags);
367 if (mm_patch_enabled())
368 err = __do_patch_instruction_mm(addr, instr);
369 else
370 err = __do_patch_instruction(addr, instr);
371 local_irq_restore(flags);
372
373 return err;
374}
373#else /* !CONFIG_STRICT_KERNEL_RWX */
374
375
375static int do_patch_instruction(u32 *addr, ppc_inst_t instr)
376{
377 return raw_patch_instruction(addr, instr);
378}
379
380#endif /* CONFIG_STRICT_KERNEL_RWX */
381
382__ro_after_init DEFINE_STATIC_KEY_FALSE(init_mem_is_free);
383
384int patch_instruction(u32 *addr, ppc_inst_t instr)
385{
386 /* Make sure we aren't patching a freed init section */
387 if (static_branch_likely(&init_mem_is_free) && init_section_contains(addr, 4))
388 return 0;
389

--- 124 unchanged lines hidden ---
376__ro_after_init DEFINE_STATIC_KEY_FALSE(init_mem_is_free);
377
378int patch_instruction(u32 *addr, ppc_inst_t instr)
379{
380 /* Make sure we aren't patching a freed init section */
381 if (static_branch_likely(&init_mem_is_free) && init_section_contains(addr, 4))
382 return 0;
383

--- 124 unchanged lines hidden ---