From: Benjamin Gray <bgray@linux.ibm.com>
To: linuxppc-dev@lists.ozlabs.org
Cc: Naveen N Rao <naveen@kernel.org>, Benjamin Gray <bgray@linux.ibm.com>
Subject: [PATCH v4 0/5] Add generic data patching functions
Date: Wed, 15 May 2024 12:44:40 +1000 [thread overview]
Message-ID: <20240515024445.236364-1-bgray@linux.ibm.com> (raw)
Currently patch_instruction() bases the write length on the value being
written. If the value looks like a prefixed instruction it writes 8 bytes,
otherwise it writes 4 bytes. This makes it potentially buggy to use for
writing arbitrary data, as if you want to write 4 bytes but it decides to
write 8 bytes it may clobber the following memory or be unaligned and
trigger an oops if it tries to cross a page boundary.
To solve this, this series pulls out the size parameter to the 'top' of
the memory patching logic, and propagates it through the various functions.
The two sizes supported are int and long; this allows for patching
instructions and pointers on both ppc32 and ppc64. On ppc32 these are the
same size, so care is taken to only use the size parameter on static
functions, so the compiler can optimise it out entirely. Unfortunately
GCC trips over its own feet here and won't optimise in a way that is
optimal for strict RWX (mpc85xx_smp_defconfig) and no RWX
(pmac32_defconfig). More details in the v2 cover letter.
Changes from v3:
* Improved the boot test. Now that alignment is enforced,
it checks the word (but not doubleword) aligned patch_ulong().
Changes from v2:
* Various changes noted on each patch
* Data patching now enforced to be aligned
* Restore page aligned flushing optimisation
Changes from v1:
* Addressed the v1 review actions
* Removed noinline (for now)
v3: https://patchwork.ozlabs.org/project/linuxppc-dev/cover/20240325055302.876434-1-bgray@linux.ibm.com/
v2: https://patchwork.ozlabs.org/project/linuxppc-dev/cover/20231016050147.115686-1-bgray@linux.ibm.com/
v1: https://patchwork.ozlabs.org/project/linuxppc-dev/cover/20230207015643.590684-1-bgray@linux.ibm.com/
Benjamin Gray (5):
powerpc/code-patching: Add generic memory patching
powerpc/code-patching: Add data patch alignment check
powerpc/64: Convert patch_instruction() to patch_u32()
powerpc/32: Convert patch_instruction() to patch_uint()
powerpc/code-patching: Add boot selftest for data patching
arch/powerpc/include/asm/code-patching.h | 37 +++++++++++++
arch/powerpc/kernel/module_64.c | 5 +-
arch/powerpc/kernel/static_call.c | 2 +-
arch/powerpc/lib/code-patching.c | 70 +++++++++++++++++++-----
arch/powerpc/lib/test-code-patching.c | 41 ++++++++++++++
arch/powerpc/platforms/powermac/smp.c | 2 +-
6 files changed, 137 insertions(+), 20 deletions(-)
--
2.45.0
next reply other threads:[~2024-05-15 2:49 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-15 2:44 Benjamin Gray [this message]
2024-05-15 2:44 ` [PATCH v4 1/5] powerpc/code-patching: Add generic memory patching Benjamin Gray
2024-08-20 7:02 ` Hari Bathini
2024-05-15 2:44 ` [PATCH v4 2/5] powerpc/code-patching: Add data patch alignment check Benjamin Gray
2024-08-20 7:03 ` Hari Bathini
2024-05-15 2:44 ` [PATCH v4 3/5] powerpc/64: Convert patch_instruction() to patch_u32() Benjamin Gray
2024-08-20 6:59 ` Hari Bathini
2024-05-15 2:44 ` [PATCH v4 4/5] powerpc/32: Convert patch_instruction() to patch_uint() Benjamin Gray
2024-08-20 7:00 ` Hari Bathini
2024-05-15 2:44 ` [PATCH v4 5/5] powerpc/code-patching: Add boot selftest for data patching Benjamin Gray
2024-08-20 7:00 ` Hari Bathini
2024-08-27 7:13 ` [PATCH v4 0/5] Add generic data patching functions Michael Ellerman
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=20240515024445.236364-1-bgray@linux.ibm.com \
--to=bgray@linux.ibm.com \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=naveen@kernel.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).