mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrey Ryabinin <ryabinin.a.a@gmail.com>
To: Andrey Konovalov <andreyknvl@gmail.com>,
	Baoquan He <bhe@redhat.com>,
	snovitoll@gmail.com
Cc: glider@google.com, dvyukov@google.com, elver@google.com,
	linux-mm@kvack.org, vincenzo.frascino@arm.com,
	akpm@linux-foundation.org, kasan-dev@googlegroups.com,
	linux-kernel@vger.kernel.org, kexec@lists.infradead.org,
	sj@kernel.org, lorenzo.stoakes@oracle.com,
	christophe.leroy@csgroup.eu
Subject: Re: [PATCH v3 00/12] mm/kasan: make kasan=on|off work for all three modes
Date: Fri, 5 Sep 2025 19:12:01 +0200	[thread overview]
Message-ID: <75a2eb31-3636-44d4-b2c9-3a24646499a4@gmail.com> (raw)
In-Reply-To: <CA+fCnZf2fGTQ6PpoKxDqkOtwcdwyPYx2cFwQw+3xAjOVxjoh6w@mail.gmail.com>

On 9/4/25 4:58 PM, Andrey Konovalov wrote:
> On Thu, Sep 4, 2025 at 10:11 AM Baoquan He <bhe@redhat.com> wrote:
>>
>>> If so, would it help if we make the kasan.vmalloc command-line
>>> parameter work with the non-HW_TAGS modes (and make it do the same
>>> thing as disabling CONFIG_KASAN_VMALLOC)?
>>>
>>> What I don't like about introducing kasan=off for non-HW_TAGS modes is
>>> that this parameter does not actually disable KASAN. It just
>>> suppresses KASAN code for mapping proper shadow memory. But the
>>> compiler-added instrumentation is still executing (and I suspect this
>>> might break the inline instrumentation mode).
>>
>> I may not follow your saying it doesn't disable KASAN. In this patchset,
>> not only do I disable the code for mapping shadow memory, but also I
>> skip any KASAN checking. Please see change of check_region_inline() in
>> mm/kasan/generic.c and kasan_check_range() in mm/kasan/sw_tags.c. It
>> will skip any KASAN checking when accessing memory.
>>
>> Yeah, the compiler added instrumentation will be called, but the if
>> (!kasan_enabled()) checking will decide if going further into KASAN code
>> or just return directly.
> 
> This all is true for the outline instrumentation mode.
> 
> However, with the inline instrumentation, check_region_inline() is not
> called (in many cases, at least) and instead the compiler embeds the
> instructions to calculate the shadow memory address and check its
> value directly (this is why we have CONFIG_KASAN_SHADOW_OFFSET, whose
> value has to be known at compile time).
> 
>> I tried inline mode on x86_64 and arm64, it
>> works well when one reviewer said inline mode could cost much more
>> memory, I don't see any breakage w or w/o kasan=off when this patchset
>> applied..
> 
> This is interesting. I guess what happens is that we still have the
> early shadow memory mapped so the shadow memory accesses inserted by
> the inline instrumentation do not crash.
> 
> But have you tried running kasan=off + CONFIG_KASAN_STACK=y +
> CONFIG_VMAP_STACK=y (+ CONFIG_KASAN_VMALLOC=y)? I would expect this
> should causes crashes, as the early shadow is mapped as read-only and
> the inline stack instrumentation will try writing into it (or do the
> writes into the early shadow somehow get ignored?..).
> 

It's not read-only, otherwise we would crash very early before full shadow
setup and won't be able to boot at all. So writes still happen, and shadow
checked, but reports are disabled.

So the patchset should work, but it's a little bit odd feature. With kasan=off we still
pay x2-x3 performance penalty of compiler instrumentation and get nothing in return.
So the usecase for this is if you don't want to compile and manage additional kernel binary
(with CONFIG_KASAN=n) and don't care about performance at all.

  reply	other threads:[~2025-09-05 17:12 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-20  5:34 Baoquan He
2025-08-20  5:34 ` [PATCH v3 01/12] mm/kasan: add conditional checks in functions to return directly if kasan is disabled Baoquan He
2025-08-20  5:34 ` [PATCH v3 02/12] mm/kasan: move kasan= code to common place Baoquan He
2025-08-20  5:34 ` [PATCH v3 03/12] mm/kasan/sw_tags: don't initialize kasan if it's disabled Baoquan He
2025-08-20  5:34 ` [PATCH v3 04/12] arch/arm: " Baoquan He
2025-08-20  5:34 ` [PATCH v3 05/12] arch/arm64: " Baoquan He
2025-08-20  5:34 ` [PATCH v3 06/12] arch/loongarch: " Baoquan He
2025-08-20  5:34 ` [PATCH v3 07/12] arch/powerpc: " Baoquan He
2025-08-20  5:34 ` [PATCH v3 08/12] arch/riscv: " Baoquan He
2025-08-20  5:34 ` [PATCH v3 09/12] arch/x86: " Baoquan He
2025-08-20  5:34 ` [PATCH v3 10/12] arch/xtensa: " Baoquan He
2025-08-20  5:34 ` [PATCH v3 11/12] arch/um: " Baoquan He
2025-08-20  5:34 ` [PATCH v3 12/12] mm/kasan: make kasan=on|off take effect for all three modes Baoquan He
2025-09-03 13:22 ` [PATCH v3 00/12] mm/kasan: make kasan=on|off work " Andrey Konovalov
2025-09-04  8:11   ` Baoquan He
2025-09-04 14:58     ` Andrey Konovalov
2025-09-05 17:12       ` Andrey Ryabinin [this message]
2025-09-05 18:08         ` Andrey Konovalov
2025-09-05 19:13           ` Christophe Leroy
2025-09-05 19:44             ` Andrey Konovalov
2025-09-05 20:34         ` Andrey Konovalov
2025-09-06 13:25           ` Andrey Konovalov
2025-09-15  5:37             ` Baoquan He
2025-09-15  9:05           ` Baoquan He
2025-09-23 17:49             ` Andrey Konovalov
2025-09-24  2:35               ` Baoquan He
2025-09-24 21:07                 ` Sabyrzhan Tasbolatov
2025-09-25  6:20                   ` Baoquan He
2025-10-14  5:27                     ` Sabyrzhan Tasbolatov
2025-10-14  9:14                       ` Baoquan He

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=75a2eb31-3636-44d4-b2c9-3a24646499a4@gmail.com \
    --to=ryabinin.a.a@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=andreyknvl@gmail.com \
    --cc=bhe@redhat.com \
    --cc=christophe.leroy@csgroup.eu \
    --cc=dvyukov@google.com \
    --cc=elver@google.com \
    --cc=glider@google.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=kexec@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=sj@kernel.org \
    --cc=snovitoll@gmail.com \
    --cc=vincenzo.frascino@arm.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

all inboxes | Powered by JetHome®