From: Benjamin Gray <bgray@linux.ibm.com>
To: Christophe Leroy <christophe.leroy@csgroup.eu>,
"linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>
Cc: "ajd@linux.ibm.com" <ajd@linux.ibm.com>,
"peterz@infradead.org" <peterz@infradead.org>,
"npiggin@gmail.com" <npiggin@gmail.com>,
"ardb@kernel.org" <ardb@kernel.org>,
"jbaron@akamai.com" <jbaron@akamai.com>,
"rostedt@goodmis.org" <rostedt@goodmis.org>,
"jpoimboe@kernel.org" <jpoimboe@kernel.org>
Subject: Re: [PATCH 1/6] powerpc/code-patching: Implement generic text patching function
Date: Mon, 19 Sep 2022 16:49:13 +1000 [thread overview]
Message-ID: <ff06e95c7f85f0b33e3573c46f9d9fe7ddffba2d.camel@linux.ibm.com> (raw)
In-Reply-To: <4c19a0fa-6af0-e71a-deaf-b150eeec6381@csgroup.eu>
On Mon, 2022-09-19 at 06:04 +0000, Christophe Leroy wrote:
> With CONFIG_STRICT_KERNEL_RWX, this patches causes a 15% time
> increase
> for activation/deactivation of ftrace.
It's possible that new alignment check is the cause. I'll see
> Without CONFIG_STRICT_KERNEL_RWX, it doesn't build.
Yup, fixed for v2
> > +static int __patch_text(void *dest, const void *src, size_t size,
> > bool is_exec, void *exec_addr)
>
> Is 'text' a good name ? For me text mean executable code. Should it
> be
> __patch_memory() ?
Well patching regular memory is just a normal store. Text to me implies
its non-writeable. Though __patch_memory would be fine.
> Why pass src as a void * ? This forces data to go via the stack.
> Can't
> you pass it as a 'long' ?
Probably, I wasn't aware that it would make a difference. I prefer
pointers in general for their semantic meaning, but will change if it
affects param passing.
> > + if (virt_to_pfn(dest) != virt_to_pfn(dest + size - 1))
> > + return -EFAULT;
>
> Why do you need that new check ?
If the patch crosses a page boundary then letting it happen is
unpredictable. Though perhaps this requirement can just be put as a
comment, or require that patches be aligned to the patch size.
> > + case 8:
> > + __put_kernel_nofault(dest, src, u64,
> > failed);
> > + break;
>
> Is case 8 needed for PPC32 ?
I don't have a particular need for it, but the underlying
__put_kernel_nofault is capable of it so I included it.
> > + }
>
> Do you catch it when size if none of 1,2,4,8 ?
>
Not yet. Perhaps I should wrap patch_text_data in a macro that checks
the size with BUILD_BUG_ON? I'd rather not check at runtime.
> > +
> > + asm ("dcbst 0, %0; sync" :: "r" (dest));
>
> Maybe write it in C:
>
> dcbst(dest);
> mb(); /* sync */
>
> > +
> > + if (is_exec)
> > + asm ("icbi 0,%0; sync; isync" :: "r" (exec_addr));
>
> Same, can be:
>
> if (is_exec) {
> icbi(exec_addr);
> mb(); /* sync */
> isync();
> }
>
> Or keep it flat:
>
> if (!is_exec)
> return 0;
>
> icbi(exec_addr);
> mb(); /* sync */
> isync();
>
> return 0;
Will try this.
> > +static int do_patch_text(void *dest, const void *src, size_t size,
> > bool is_exec)
> > +{
> > + int err;
> > + pte_t *pte;
> > + u32 *patch_addr;
> > +
> > + pte = start_text_patch(dest, &patch_addr);
> > + err = __patch_text(patch_addr, src, size, is_exec, dest);
> > + finish_text_patch(pte);
>
> Why do you need to split this function in three parts ? I can't see
> the
> added value, all it does is reduce readability.
It made it more readable to me, so the __patch_text didn't get buried.
It also made it easier to do the refactoring, and potentially add code
patching variants that use the poke area but not __patch_text. I'll
remove it for v2 though given this is the only use right now.
> Did you check the impact of calling __this_cpu_read() twice ?
I wasn't concerned about performance, but given I'll merge it back
again it will only be read once in v2 again.
> > +void *patch_memory(void *dest, const void *src, size_t size)
>
> What is this function used for ?
>
Build failure apparently :)
It's removed in v2.
>
next prev parent reply other threads:[~2022-09-19 6:50 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-16 6:23 [PATCH 0/6] Out-of-line static calls for powerpc64 ELF V2 Benjamin Gray
2022-09-16 6:23 ` [PATCH 1/6] powerpc/code-patching: Implement generic text patching function Benjamin Gray
2022-09-16 9:39 ` kernel test robot
2022-09-16 11:16 ` kernel test robot
2022-09-19 6:04 ` Christophe Leroy
2022-09-19 6:49 ` Benjamin Gray [this message]
2022-09-19 7:16 ` Christophe Leroy
2022-09-20 2:32 ` Benjamin Gray
2022-09-20 5:44 ` Christophe Leroy
2022-09-20 7:01 ` Benjamin Gray
2022-09-19 6:38 ` Christophe Leroy
2022-09-20 1:49 ` Benjamin Gray
2022-09-16 6:23 ` [PATCH 2/6] powerpc/module: Handle caller-saved TOC in module linker Benjamin Gray
2022-09-19 6:09 ` Christophe Leroy
2022-09-16 6:23 ` [PATCH 3/6] powerpc/module: Optimise nearby branches in ELF V2 ABI stub Benjamin Gray
2022-09-19 6:11 ` Christophe Leroy
2022-09-16 6:23 ` [PATCH 4/6] static_call: Move static call selftest to static_call_selftest.c Benjamin Gray
2022-09-20 4:30 ` Andrew Donnellan
2022-09-16 6:23 ` [PATCH 5/6] powerpc/64: Add support for out-of-line static calls Benjamin Gray
2022-09-16 8:32 ` kernel test robot
2022-09-16 6:23 ` [PATCH 6/6] powerpc/64: Add tests " Benjamin Gray
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=ff06e95c7f85f0b33e3573c46f9d9fe7ddffba2d.camel@linux.ibm.com \
--to=bgray@linux.ibm.com \
--cc=ajd@linux.ibm.com \
--cc=ardb@kernel.org \
--cc=christophe.leroy@csgroup.eu \
--cc=jbaron@akamai.com \
--cc=jpoimboe@kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=npiggin@gmail.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.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).