linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To: Mike Rapoport <rppt@kernel.org>
Cc: linux-kernel@vger.kernel.org, Andi Kleen <ak@linux.intel.com>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	"open list:MEMORY MANAGEMENT" <linux-mm@kvack.org>
Subject: Re: [PATCH v4 3/7] vmalloc: Add text_alloc() and text_free()
Date: Sat, 25 Jul 2020 02:31:12 +0300	[thread overview]
Message-ID: <20200724233112.GA1903189@linux.intel.com> (raw)
In-Reply-To: <20200724101302.GF927924@kernel.org>

On Fri, Jul 24, 2020 at 01:13:02PM +0300, Mike Rapoport wrote:
> On Fri, Jul 24, 2020 at 01:28:35AM +0300, Jarkko Sakkinen wrote:
> > On Sat, Jul 18, 2020 at 07:23:59PM +0300, Mike Rapoport wrote:
> > > On Fri, Jul 17, 2020 at 06:04:17AM +0300, Jarkko Sakkinen wrote:
> > > > Introduce functions for allocating memory for dynamic trampolines, such
> > > > as kprobes. An arch can promote the availability of these functions with
> > > > CONFIG_ARCH_HAS_TEXT_ALLOC. Provide default/fallback implementation
> > > > wrapping module_alloc() and module_memfree().
> > > > 
> > > > Cc: Andi Kleen <ak@linux.intel.com>
> > > > Cc: Masami Hiramatsu <mhiramat@kernel.org>
> > > > Suggested-by: Peter Zijlstra <peterz@infradead.org>
> > > > Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > > > ---
> > > >  include/linux/vmalloc.h | 23 +++++++++++++++++++++++
> > > >  1 file changed, 23 insertions(+)
> > > > 
> > > > diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
> > > > index 0221f852a7e1..e981436e30b6 100644
> > > > --- a/include/linux/vmalloc.h
> > > > +++ b/include/linux/vmalloc.h
> > > > @@ -9,6 +9,7 @@
> > > >  #include <asm/page.h>		/* pgprot_t */
> > > >  #include <linux/rbtree.h>
> > > >  #include <linux/overflow.h>
> > > > +#include <linux/moduleloader.h>
> > > >  
> > > >  #include <asm/vmalloc.h>
> > > >  
> > > > @@ -249,4 +250,26 @@ pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)
> > > >  int register_vmap_purge_notifier(struct notifier_block *nb);
> > > >  int unregister_vmap_purge_notifier(struct notifier_block *nb);
> > > >  
> > > > +#ifdef CONFIG_ARCH_HAS_TEXT_ALLOC
> > > > +/*
> > > > + * Allocate memory to be used for dynamic trampoline code.
> > > > + */
> > > > +void *text_alloc(unsigned long size);
> > > > +
> > > > +/*
> > > > + * Free memory returned from text_alloc().
> > > > + */
> > > > +void text_free(void *region);
> > > > +#else
> > > > +static inline void *text_alloc(unsigned long size)
> > > > +{
> > > > +	return module_alloc(size);
> > > > +}
> > > > +
> > > > +static inline void text_free(void *region)
> > > > +{
> > > > +	module_memfree(region);
> > > > +}
> > > 
> > > Using module_alloc() as the default implementation of generic
> > > text_alloc() does not sound right to me.
> > > 
> > > I would suggest rename module_alloc() to text_alloc() on x86, as Peter
> > > proposed and then add text_alloc_kprobes() that can be overridden by the
> > > architectures. x86 could use text_alloc(), arm64 vmalloc() with options
> > > of their choice and the fallback would remain module_alloc(). Something
> > > like (untested) patch below:
> > 
> > I'm not exactly sure which of the below is relevant as the patch set
> > includes the exact same changes with maybe different phrasing:
> 
> The difference in parsing is what differentiates semantically clean code
> from duct tape.
> 
> As several people pointed out, a single text_alloc(), and apprently a
> single ARCH_HAS_TEXT_ALLOC, would not fit all architectures and some
> ground work required to implement a generic text allocation.
> 
> Your patch works aroung this for x86 with broken semantics of
> text_alloc() when ARCH_HAS_TEXT_ALLOC is not defined.
> 
> My suggestion does not make text_alloc() a special case of
> module_alloc() but rather makes text_alloc_kprobes() to fallback to
> module_alloc() when architecture does not provide its implementation.

OK, I see your point now. I'll response in detail to v5 comments.

Thank you.

/Jarkko

  reply	other threads:[~2020-07-24 23:31 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-17  3:04 [PATCH v4 0/7] arch/x86: kprobes: Remove MODULES dependency Jarkko Sakkinen
2020-07-17  3:04 ` [PATCH v4 1/7] module: Add lock_modules() and unlock_modules() Jarkko Sakkinen
2020-07-17  3:04 ` [PATCH v4 2/7] kprobes: Use " Jarkko Sakkinen
2020-07-17  3:04 ` [PATCH v4 3/7] vmalloc: Add text_alloc() and text_free() Jarkko Sakkinen
2020-07-17  5:33   ` kernel test robot
2020-07-17  5:33   ` kernel test robot
2020-07-17  8:52   ` Masami Hiramatsu
2020-07-23 22:24     ` Jarkko Sakkinen
2020-07-18 16:23   ` Mike Rapoport
2020-07-20 12:01     ` Masami Hiramatsu
2020-07-23 22:28     ` Jarkko Sakkinen
2020-07-24 10:13       ` Mike Rapoport
2020-07-24 23:31         ` Jarkko Sakkinen [this message]
2020-07-24 23:40           ` Jarkko Sakkinen
2020-07-17  3:04 ` [PATCH v4 4/7] arch/x86: Implement " Jarkko Sakkinen
2020-07-17  3:04 ` [PATCH v4 5/7] arch/x86: kprobes: Use text_alloc() in alloc_insn_page() Jarkko Sakkinen
2020-07-23 22:16   ` Jarkko Sakkinen
2020-07-17  3:04 ` [PATCH v4 6/7] kprobes: Use text_alloc() and text_free() Jarkko Sakkinen
2020-07-17  3:04 ` [PATCH v4 7/7] kprobes: Flag out CONFIG_MODULES dependent code Jarkko Sakkinen

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=20200724233112.GA1903189@linux.intel.com \
    --to=jarkko.sakkinen@linux.intel.com \
    --cc=ak@linux.intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhiramat@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rppt@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).