From: Sven Schnelle <svens@stackframe.org>
To: Rolf Eike Beer <eike-kernel@sf-tec.de>
Cc: deller@gmx.de, linux-parisc@vger.kernel.org,
linux-parisc-owner@vger.kernel.org
Subject: Re: [PATCH 1/6] parisc: add support for patching multiple words
Date: Wed, 29 May 2019 19:49:36 +0200 [thread overview]
Message-ID: <20190529174936.GB15295@t470p.stackframe.org> (raw)
In-Reply-To: <60af38a74323a665da28f2de08529a23@sf-tec.de>
Hi,
On Tue, May 28, 2019 at 10:19:11AM +0200, Rolf Eike Beer wrote:
> Sven Schnelle wrote:
> > add patch_text_multiple() which allows to patch multiple
> > text words in memory. This can be used to copy functions.
> > +void __patch_text(void *addr, u32 insn);
> > +void __patch_text_multiple(void *addr, u32 *insn, int len);
>
> A signed length always looks suspicious to me.
Agreed. Will change.
> > + p = fixmap = patch_map(addr, FIX_TEXT_POKE0, &mapped);
> > +
> > + while (len > 0) {
> > + *p++ = *insn++;
> > + addr += 4;
> > + len -= sizeof(u32);
>
> I wonder if this can't just use memcpy inside the pages?
I think using memcpy here makes things just more complicated and harder to read.
We would need to extract the amount of bytes to copy, and call memcpy multiple
times. As this code is not performance critical and usually only copies only
a few bytes i doubt that it's worth the effort.
> If not there should be a comment describing what's going on here.
Is it that complicated? It's just a copy loop like in every C beginner book,
the only things that makes things more complicated is the need to remap when
crossing a page.
> Another nitpick: the "+4" and "-sizeof(u32)" are just the same at the end,
> but why do they use entirely different wording? What do we need "addr" for
> anyway, one could just look at "p" which would cross a page boundary at the
> same time, no?
You can't, because of the patch_map() call below which updates the fixed mapping.
That call needs the real virtual address, while *p holds the virtual address of
the fixed mapping for patching.
> > + if (len && !((unsigned long)addr & ~PAGE_MASK)) {
> > + /*
> > + * We're crossing a page boundary, so
> > + * need to remap
> > + */
> > + flush_kernel_vmap_range((void *)fixmap,
> > + (p-fixmap) * sizeof(*p));
> > + if (mapped)
> > + patch_unmap(FIX_TEXT_POKE0);
> > + p = fixmap = patch_map(addr, FIX_TEXT_POKE0, &mapped);
> > + }
> > + }
> > +
Regards
Sven
next prev parent reply other threads:[~2019-05-29 17:49 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-27 19:04 [PATCH 0/6] Dynamic FTRACE for PA-RISC Sven Schnelle
2019-05-27 19:04 ` [PATCH 1/6] parisc: add support for patching multiple words Sven Schnelle
2019-05-28 8:19 ` Rolf Eike Beer
2019-05-29 17:49 ` Sven Schnelle [this message]
2019-05-29 17:58 ` Rolf Eike Beer
2019-05-29 18:18 ` Sven Schnelle
2019-05-27 19:04 ` [PATCH 2/6] parisc: add spinlock to patch function Sven Schnelle
2019-05-27 19:04 ` [PATCH 3/6] parisc: add WARN_ON() to clear_fixmap Sven Schnelle
2019-05-27 19:04 ` [PATCH 4/6] parisc: use pr_debug() in kernel/module.c Sven Schnelle
2019-05-28 8:24 ` Rolf Eike Beer
2019-05-29 17:54 ` Sven Schnelle
2019-05-27 19:04 ` [PATCH 5/6] compiler.h: add CC_USING_PATCHABLE_FUNCTION_ENTRY Sven Schnelle
2019-05-27 19:04 ` [PATCH 6/6] parisc: add dynamic ftrace Sven Schnelle
2019-05-28 8:26 ` Rolf Eike Beer
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=20190529174936.GB15295@t470p.stackframe.org \
--to=svens@stackframe.org \
--cc=deller@gmx.de \
--cc=eike-kernel@sf-tec.de \
--cc=linux-parisc-owner@vger.kernel.org \
--cc=linux-parisc@vger.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).