From: Jordan Niethe <jniethe5@gmail.com>
To: linuxppc-dev@lists.ozlabs.org
Cc: Jordan Niethe <jniethe5@gmail.com>, cmr@bluescreens.de
Subject: [PATCH v7 3/5] powerpc: Rework and improve STRICT_KERNEL_RWX patching
Date: Wed, 10 Nov 2021 11:37:15 +1100 [thread overview]
Message-ID: <20211110003717.1150965-4-jniethe5@gmail.com> (raw)
In-Reply-To: <20211110003717.1150965-1-jniethe5@gmail.com>
From: "Christopher M. Riedl" <cmr@bluescreens.de>
Rework code-patching with STRICT_KERNEL_RWX to prepare for a later patch
which uses a temporary mm for patching under the Book3s64 Radix MMU.
Make improvements by adding a WARN_ON when the patchsite doesn't match
after patching and return the error from __patch_instruction() properly.
Signed-off-by: Christopher M. Riedl <cmr@bluescreens.de>
Signed-off-by: Jordan Niethe <jniethe5@gmail.com>
---
v7: still pass addr to map_patch_area()
---
arch/powerpc/lib/code-patching.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c
index 29a30c3068ff..d586bf9c7581 100644
--- a/arch/powerpc/lib/code-patching.c
+++ b/arch/powerpc/lib/code-patching.c
@@ -75,6 +75,7 @@ static inline void stop_using_temp_mm(struct temp_mm_state prev_state)
}
static DEFINE_PER_CPU(struct vm_struct *, text_poke_area);
+static DEFINE_PER_CPU(unsigned long, cpu_patching_addr);
static int text_area_cpu_up(unsigned int cpu)
{
@@ -87,6 +88,7 @@ static int text_area_cpu_up(unsigned int cpu)
return -1;
}
this_cpu_write(text_poke_area, area);
+ this_cpu_write(cpu_patching_addr, (unsigned long)area->addr);
return 0;
}
@@ -172,11 +174,10 @@ static inline int unmap_patch_area(unsigned long addr)
static int do_patch_instruction(u32 *addr, struct ppc_inst instr)
{
- int err;
+ int err, rc = 0;
u32 *patch_addr = NULL;
unsigned long flags;
unsigned long text_poke_addr;
- unsigned long kaddr = (unsigned long)addr;
/*
* During early early boot patch_instruction is called
@@ -188,15 +189,13 @@ static int do_patch_instruction(u32 *addr, struct ppc_inst instr)
local_irq_save(flags);
- text_poke_addr = (unsigned long)__this_cpu_read(text_poke_area)->addr;
- if (map_patch_area(addr, text_poke_addr)) {
- err = -1;
+ text_poke_addr = __this_cpu_read(cpu_patching_addr);
+ err = map_patch_area(addr, text_poke_addr);
+ if (err)
goto out;
- }
-
- patch_addr = (u32 *)(text_poke_addr + (kaddr & ~PAGE_MASK));
- __patch_instruction(addr, instr, patch_addr);
+ patch_addr = (u32 *)(text_poke_addr | offset_in_page(addr));
+ rc = __patch_instruction(addr, instr, patch_addr);
err = unmap_patch_area(text_poke_addr);
if (err)
@@ -204,8 +203,9 @@ static int do_patch_instruction(u32 *addr, struct ppc_inst instr)
out:
local_irq_restore(flags);
+ WARN_ON(!ppc_inst_equal(ppc_inst_read(addr), instr));
- return err;
+ return rc ? rc : err;
}
#else /* !CONFIG_STRICT_KERNEL_RWX */
--
2.25.1
next prev parent reply other threads:[~2021-11-10 0:40 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-10 0:37 [PATCH v7 0/5] Use per-CPU temporary mappings for patching on Radix MMU Jordan Niethe
2021-11-10 0:37 ` [PATCH v7 1/5] powerpc: Allow clearing and restoring registers independent of saved breakpoint state Jordan Niethe
2021-11-10 0:37 ` [PATCH v7 2/5] powerpc/64s: Introduce temporary mm for Radix MMU Jordan Niethe
2021-11-10 0:37 ` Jordan Niethe [this message]
2022-03-12 7:30 ` [PATCH v7 3/5] powerpc: Rework and improve STRICT_KERNEL_RWX patching Christophe Leroy
2022-03-14 23:01 ` Jordan Niethe
2021-11-10 0:37 ` [PATCH v7 4/5] powerpc: Use WARN_ON and fix check in poking_init Jordan Niethe
2021-11-10 0:37 ` [PATCH v7 5/5] powerpc/64s: Initialize and use a temporary mm for patching on Radix Jordan Niethe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211110003717.1150965-4-jniethe5@gmail.com \
--to=jniethe5@gmail.com \
--cc=cmr@bluescreens.de \
--cc=linuxppc-dev@lists.ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).