All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mark Rutland <mark.rutland@arm.com>
To: Zhenhua Huang <quic_zhenhuah@quicinc.com>
Cc: Marco Elver <elver@google.com>,
	catalin.marinas@arm.com, will@kernel.org, glider@google.com,
	akpm@linux-foundation.org, linux-arm-kernel@lists.infradead.org,
	linux-mm@kvack.org
Subject: Re: [PATCH] mm: kfence: export kfence_enabled as global variables
Date: Tue, 7 Feb 2023 10:48:22 +0000	[thread overview]
Message-ID: <Y+IsdrvDNILA59UN@FVFF77S0Q05N> (raw)
In-Reply-To: <b223194c-63b3-d2eb-d450-10550bd12998@quicinc.com>

On Tue, Feb 07, 2023 at 03:46:53PM +0800, Zhenhua Huang wrote:
> Thanks Marco!
> 
> On 2023/2/7 15:19, Marco Elver wrote:
> > On Tue, 7 Feb 2023 at 07:15, Zhenhua Huang <quic_zhenhuah@quicinc.com> wrote:
> > > 
> > > Export the variable to ease the judgement of whether kfence enabled
> > > at runtime. It should be more precise than through kernel config
> > > "CONFIG_KFENCE".
> > > 
> > > For example We can disable kfence at runtime using bootargs
> > > "kfence.sample_interval=0" but CONFIG_KFENCE enabled.
> > > It was false positive.
> > > 
> > > Signed-off-by: Zhenhua Huang <quic_zhenhuah@quicinc.com>
> > > ---
> > >   arch/arm64/mm/pageattr.c | 3 ++-
> > >   include/linux/kfence.h   | 2 ++
> > >   mm/kfence/core.c         | 2 +-
> > >   3 files changed, 5 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/arch/arm64/mm/pageattr.c b/arch/arm64/mm/pageattr.c
> > > index 79dd201..208d780 100644
> > > --- a/arch/arm64/mm/pageattr.c
> > > +++ b/arch/arm64/mm/pageattr.c
> > > @@ -7,6 +7,7 @@
> > >   #include <linux/module.h>
> > >   #include <linux/sched.h>
> > >   #include <linux/vmalloc.h>
> > > +#include <linux/kfence.h>
> > > 
> > >   #include <asm/cacheflush.h>
> > >   #include <asm/set_memory.h>
> > > @@ -27,7 +28,7 @@ bool can_set_direct_map(void)
> > >           * protect/unprotect single pages.
> > >           */
> > >          return (rodata_enabled && rodata_full) || debug_pagealloc_enabled() ||
> > > -               IS_ENABLED(CONFIG_KFENCE);
> > > +               kfence_enabled;
> > 
> > Unfortunately this won't work, because it's possible to enable KFENCE
> > after the kernel has booted with e.g.: echo 100 >
> > /sys/module/kfence/parameters/sample_interval
> Yeah, got it. Thanks for catching it.
> > 
> > What is the problem you have encountered? Is the page-granular direct
> > map causing issues?
> We're working on a low memory target, page-granular mapping costed more (2M
> per 1GB) memory. Due to GKI constraints, it is not easy to disable
> CONFIG_KFENCE. So my intention was to move the judgement to runtime
> configurable w/ CONFIG_KFENCE on...
> 
> Do you have any further suggestion/proposal on this? Many Thanks!

Just to check, the cost is because we're mapping *all* of memory at page
granulatrity, right? If we were to just map the KFENCE region a page
granularity, would that be a sufficient saving? 

We didn't do that so far because it was simpler to just map everything at page
granularity (and that's also required by rodata_full, which I though android
used?).

If it's really important (and rodata_full isn't being used), we could try to do
that.

To do that we'd need to choose the KFENCE region *before* arm64 creates the
fine-grain translation tables, which probable needs an arch_ hook.

Thanks,
Mark.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

WARNING: multiple messages have this Message-ID (diff)
From: Mark Rutland <mark.rutland@arm.com>
To: Zhenhua Huang <quic_zhenhuah@quicinc.com>
Cc: Marco Elver <elver@google.com>,
	catalin.marinas@arm.com, will@kernel.org, glider@google.com,
	akpm@linux-foundation.org, linux-arm-kernel@lists.infradead.org,
	linux-mm@kvack.org
Subject: Re: [PATCH] mm: kfence: export kfence_enabled as global variables
Date: Tue, 7 Feb 2023 10:48:22 +0000	[thread overview]
Message-ID: <Y+IsdrvDNILA59UN@FVFF77S0Q05N> (raw)
In-Reply-To: <b223194c-63b3-d2eb-d450-10550bd12998@quicinc.com>

On Tue, Feb 07, 2023 at 03:46:53PM +0800, Zhenhua Huang wrote:
> Thanks Marco!
> 
> On 2023/2/7 15:19, Marco Elver wrote:
> > On Tue, 7 Feb 2023 at 07:15, Zhenhua Huang <quic_zhenhuah@quicinc.com> wrote:
> > > 
> > > Export the variable to ease the judgement of whether kfence enabled
> > > at runtime. It should be more precise than through kernel config
> > > "CONFIG_KFENCE".
> > > 
> > > For example We can disable kfence at runtime using bootargs
> > > "kfence.sample_interval=0" but CONFIG_KFENCE enabled.
> > > It was false positive.
> > > 
> > > Signed-off-by: Zhenhua Huang <quic_zhenhuah@quicinc.com>
> > > ---
> > >   arch/arm64/mm/pageattr.c | 3 ++-
> > >   include/linux/kfence.h   | 2 ++
> > >   mm/kfence/core.c         | 2 +-
> > >   3 files changed, 5 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/arch/arm64/mm/pageattr.c b/arch/arm64/mm/pageattr.c
> > > index 79dd201..208d780 100644
> > > --- a/arch/arm64/mm/pageattr.c
> > > +++ b/arch/arm64/mm/pageattr.c
> > > @@ -7,6 +7,7 @@
> > >   #include <linux/module.h>
> > >   #include <linux/sched.h>
> > >   #include <linux/vmalloc.h>
> > > +#include <linux/kfence.h>
> > > 
> > >   #include <asm/cacheflush.h>
> > >   #include <asm/set_memory.h>
> > > @@ -27,7 +28,7 @@ bool can_set_direct_map(void)
> > >           * protect/unprotect single pages.
> > >           */
> > >          return (rodata_enabled && rodata_full) || debug_pagealloc_enabled() ||
> > > -               IS_ENABLED(CONFIG_KFENCE);
> > > +               kfence_enabled;
> > 
> > Unfortunately this won't work, because it's possible to enable KFENCE
> > after the kernel has booted with e.g.: echo 100 >
> > /sys/module/kfence/parameters/sample_interval
> Yeah, got it. Thanks for catching it.
> > 
> > What is the problem you have encountered? Is the page-granular direct
> > map causing issues?
> We're working on a low memory target, page-granular mapping costed more (2M
> per 1GB) memory. Due to GKI constraints, it is not easy to disable
> CONFIG_KFENCE. So my intention was to move the judgement to runtime
> configurable w/ CONFIG_KFENCE on...
> 
> Do you have any further suggestion/proposal on this? Many Thanks!

Just to check, the cost is because we're mapping *all* of memory at page
granulatrity, right? If we were to just map the KFENCE region a page
granularity, would that be a sufficient saving? 

We didn't do that so far because it was simpler to just map everything at page
granularity (and that's also required by rodata_full, which I though android
used?).

If it's really important (and rodata_full isn't being used), we could try to do
that.

To do that we'd need to choose the KFENCE region *before* arm64 creates the
fine-grain translation tables, which probable needs an arch_ hook.

Thanks,
Mark.


  parent reply	other threads:[~2023-02-07 10:49 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-07  6:15 [PATCH] mm: kfence: export kfence_enabled as global variables Zhenhua Huang
2023-02-07  6:15 ` Zhenhua Huang
2023-02-07  7:19 ` Marco Elver
2023-02-07  7:19   ` Marco Elver
2023-02-07  7:46   ` Zhenhua Huang
2023-02-07  7:46     ` Zhenhua Huang
2023-02-07 10:28     ` Alexander Potapenko
2023-02-07 10:28       ` Alexander Potapenko
2023-02-07 10:42       ` Zhenhua Huang
2023-02-07 10:42         ` Zhenhua Huang
2023-02-07 10:48     ` Mark Rutland [this message]
2023-02-07 10:48       ` Mark Rutland
2023-02-07 12:35       ` Zhenhua Huang
2023-02-07 12:35         ` Zhenhua Huang

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=Y+IsdrvDNILA59UN@FVFF77S0Q05N \
    --to=mark.rutland@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=catalin.marinas@arm.com \
    --cc=elver@google.com \
    --cc=glider@google.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=quic_zhenhuah@quicinc.com \
    --cc=will@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.