linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Marco Elver <elver@google.com>
To: Zhenhua Huang <quic_zhenhuah@quicinc.com>
Cc: catalin.marinas@arm.com, will@kernel.org, glider@google.com,
	 dvyukov@google.com, akpm@linux-foundation.org,
	robin.murphy@arm.com,  mark.rutland@arm.com, jianyong.wu@arm.com,
	james.morse@arm.com,  wangkefeng.wang@huawei.com,
	linux-arm-kernel@lists.infradead.org,
	 kasan-dev@googlegroups.com, linux-mm@kvack.org,
	quic_pkondeti@quicinc.com,  quic_guptap@quicinc.com,
	quic_tingweiz@quicinc.com
Subject: Re: [PATCH v5] mm,kfence: decouple kfence from page granularity mapping judgement
Date: Mon, 13 Mar 2023 10:49:04 +0100	[thread overview]
Message-ID: <CANpmjNN6sQ+sWBVxn+Oy5Z8VBCAquVUvYwXC1MGKOr7AFkHa3w@mail.gmail.com> (raw)
In-Reply-To: <8b44b20d-675c-25d0-6ddb-9b02da1c72d2@quicinc.com>

On Mon, 13 Mar 2023 at 10:05, Zhenhua Huang <quic_zhenhuah@quicinc.com> wrote:
>
> Thanks Marco!
>
> On 2023/3/13 15:50, Marco Elver wrote:
> > On Mon, 13 Mar 2023 at 06:04, Zhenhua Huang <quic_zhenhuah@quicinc.com> wrote:
> >>
> >> Kfence only needs its pool to be mapped as page granularity, previous
> >> judgement was a bit over protected. From [1], Mark suggested to "just
> >> map the KFENCE region a page granularity". So I decouple it from judgement
> >> and do page granularity mapping for kfence pool only.
> >>
> >> Page granularity mapping in theory cost more(2M per 1GB) memory on arm64
> >> platform. Like what I've tested on QEMU(emulated 1GB RAM) with
> >> gki_defconfig, also turning off rodata protection:
> >> Before:
> >> [root@liebao ]# cat /proc/meminfo
> >> MemTotal:         999484 kB
> >> After:
> >> [root@liebao ]# cat /proc/meminfo
> >> MemTotal:        1001480 kB
> >>
> >> To implement this, also relocate the kfence pool allocation before the
> >> linear mapping setting up, arm64_kfence_alloc_pool is to allocate phys
> >> addr, __kfence_pool is to be set after linear mapping set up.
> >
> > This patch still breaks the late-init capabilities that Kefeng pointed out.
> >
> > I think the only viable option is:
> >
> >   1. If KFENCE early init is requested on arm64, do what you're doing here.
> >
> >   2. If KFENCE is compiled in, but not enabled, do what was done
> > before, so it can be enabled late.
>
> I'm fine with above solution as well. The Disadvantage is if we want to
> dynamically disable kfence through kfence_sample_interval, it must be
> mapped into page granularity still.
>
> >
> > Am I missing an option?
> >
>
> Another option is what Kefeng firstly thought and I had proposed on
> comments of patchsetV3, actually I wanted to do in an separate patch:

Please do it in the same patch (or patch series), otherwise we end up
with a regression.

> "
> So how about we raise another change, like you mentioned bootargs
> indicating to use late init of b33f778bba5e ("kfence: alloc kfence_pool

Please avoid introducing another bootarg just for this. It will
confuse users and will cause serious annoyance (bad UX).

> after system startup").
> 1. in arm64_kfence_alloc_pool():
>     if (!kfence_sample_interval && !using_late_init)
>               return 0;
>     else
>               allocate pool

The whole point of late allocation was that the entire pool is _not_
allocated until it's needed (during late init). So for space-conscious
users, this option is actually worse.

> 2. also do the check in late allocation,like
>     if (do_allocation_late && !using_late_init)
>               BUG();

BUG() needs to be avoided. Just because a user used the system wrong,
should not cause it to crash (WARN instead)... but I'd really prefer
you avoid introducing another boot arg, because it'll lead to bad UX.

> "
> The thought is to allocate pool early as well if we need to
> using_late_init.
>
> Kefeng, Marco,
>
> How's your idea?

I recommend that you just make can_set_direct_map() conditional on
KFENCE being initialized early or not. With rodata protection most
arm64 kernels likely pay the page granular direct map cost anyway. And
for your special usecase where you want to optimize memory use, but
know that KFENCE is enabled, it'll result in the savings you desire.

Thanks,
-- Marco


  reply	other threads:[~2023-03-13  9:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-13  5:03 Zhenhua Huang
2023-03-13  7:50 ` Marco Elver
2023-03-13  9:05   ` Zhenhua Huang
2023-03-13  9:49     ` Marco Elver [this message]
2023-03-13 10:27       ` 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=CANpmjNN6sQ+sWBVxn+Oy5Z8VBCAquVUvYwXC1MGKOr7AFkHa3w@mail.gmail.com \
    --to=elver@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=catalin.marinas@arm.com \
    --cc=dvyukov@google.com \
    --cc=glider@google.com \
    --cc=james.morse@arm.com \
    --cc=jianyong.wu@arm.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=mark.rutland@arm.com \
    --cc=quic_guptap@quicinc.com \
    --cc=quic_pkondeti@quicinc.com \
    --cc=quic_tingweiz@quicinc.com \
    --cc=quic_zhenhuah@quicinc.com \
    --cc=robin.murphy@arm.com \
    --cc=wangkefeng.wang@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox