linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marco Elver <elver@google.com>
To: Hyeonggon Yoo <42.hyeyoo@gmail.com>,
	Muchun Song <songmuchun@bytedance.com>
Cc: Alexander Potapenko <glider@google.com>,
	Dmitry Vyukov <dvyukov@google.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm/kfence: reset PG_slab and memcg_data before freeing __kfence_pool
Date: Thu, 5 May 2022 09:12:14 +0200	[thread overview]
Message-ID: <CANpmjNN5B5xjcTfcAF78d9Bpxqypt8p=OHTLU+QHbtV6vJJjeg@mail.gmail.com> (raw)
In-Reply-To: <20220505070105.1835745-1-42.hyeyoo@gmail.com>

On Thu, 5 May 2022 at 09:01, Hyeonggon Yoo <42.hyeyoo@gmail.com> wrote:
>
> When kfence fails to initialize kfence pool, it frees the pool.
> But it does not reset PG_slab flag and memcg_data of struct page.
>
> Below is a BUG because of this. Let's fix it by resetting PG_slab
> and memcg_data before free.
>
> [    0.089149] BUG: Bad page state in process swapper/0  pfn:3d8e06
> [    0.089149] page:ffffea46cf638180 refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x3d8e06
> [    0.089150] memcg:ffffffff94a475d1
> [    0.089150] flags: 0x17ffffc0000200(slab|node=0|zone=2|lastcpupid=0x1fffff)
> [    0.089151] raw: 0017ffffc0000200 ffffea46cf638188 ffffea46cf638188 0000000000000000
> [    0.089152] raw: 0000000000000000 0000000000000000 00000000ffffffff ffffffff94a475d1
> [    0.089152] page dumped because: page still charged to cgroup
> [    0.089153] Modules linked in:
> [    0.089153] CPU: 0 PID: 0 Comm: swapper/0 Tainted: G    B   W         5.18.0-rc1+ #965
> [    0.089154] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-2 04/01/2014
> [    0.089154] Call Trace:
> [    0.089155]  <TASK>
> [    0.089155]  dump_stack_lvl+0x49/0x5f
> [    0.089157]  dump_stack+0x10/0x12
> [    0.089158]  bad_page.cold+0x63/0x94
> [    0.089159]  check_free_page_bad+0x66/0x70
> [    0.089160]  __free_pages_ok+0x423/0x530
> [    0.089161]  __free_pages_core+0x8e/0xa0
> [    0.089162]  memblock_free_pages+0x10/0x12
> [    0.089164]  memblock_free_late+0x8f/0xb9
> [    0.089165]  kfence_init+0x68/0x92
> [    0.089166]  start_kernel+0x789/0x992
> [    0.089167]  x86_64_start_reservations+0x24/0x26
> [    0.089168]  x86_64_start_kernel+0xa9/0xaf
> [    0.089170]  secondary_startup_64_no_verify+0xd5/0xdb
> [    0.089171]  </TASK>

This is probably:

Fixes: 0ce20dd84089 ("mm: add Kernel Electric-Fence infrastructure")

> Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com>
> ---
>  mm/kfence/core.c | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/mm/kfence/core.c b/mm/kfence/core.c
> index a203747ad2c0..2ab3d473321e 100644
> --- a/mm/kfence/core.c
> +++ b/mm/kfence/core.c
> @@ -642,6 +642,13 @@ static bool __init kfence_init_pool_early(void)
>          * fails for the first page, and therefore expect addr==__kfence_pool in
>          * most failure cases.
>          */
> +       for (char *p = (char *)addr; p < __kfence_pool + KFENCE_POOL_SIZE; p += PAGE_SIZE) {
> +               struct page *page;
> +
> +               page = virt_to_page(p);

#ifdef CONFIG_MEMCG

> +               page->memcg_data = 0;

#endif

> +               __ClearPageSlab(page);

We're now using __folio_set_slab(), so I'm guessing this should be
__folio_clear_slab()?

> +       }
>         memblock_free_late(__pa(addr), KFENCE_POOL_SIZE - (addr - (unsigned long)__kfence_pool));
>         __kfence_pool = NULL;
>         return false;
> --
> 2.32.0
>

  reply	other threads:[~2022-05-05  7:12 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-05  7:01 [PATCH] mm/kfence: reset PG_slab and memcg_data before freeing __kfence_pool Hyeonggon Yoo
2022-05-05  7:12 ` Marco Elver [this message]
2022-05-05  7:19   ` Marco Elver
2022-05-05  7:27     ` Hyeonggon Yoo
2022-05-05  7:39 ` [PATCH v2] " Hyeonggon Yoo
2022-05-05  8:25   ` Marco Elver
2022-05-05  9:07   ` Muchun Song
2022-05-05 10:13   ` [PATCH v3] " Hyeonggon Yoo
2022-05-05 10:54     ` Muchun Song
2022-05-05 11:33       ` Hyeonggon Yoo
2022-05-05 12:00         ` Muchun Song
2022-05-05 10:57 ` [PATCH] " kernel test robot

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='CANpmjNN5B5xjcTfcAF78d9Bpxqypt8p=OHTLU+QHbtV6vJJjeg@mail.gmail.com' \
    --to=elver@google.com \
    --cc=42.hyeyoo@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=dvyukov@google.com \
    --cc=glider@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=songmuchun@bytedance.com \
    /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).