From: Mark Rutland <mark.rutland@arm.com>
To: Linus Walleij <linus.walleij@linaro.org>,
Ard Biesheuvel <ardb@kernel.org>
Cc: Clement LE GOFFIC <clement.legoffic@foss.st.com>,
Russell King <linux@armlinux.org.uk>,
"Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>,
Kees Cook <kees@kernel.org>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
Mark Brown <broonie@kernel.org>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
linux-stm32@st-md-mailman.stormreply.com,
Antonio Borneo <antonio.borneo@foss.st.com>
Subject: Re: Crash on armv7-a using KASAN
Date: Thu, 17 Oct 2024 11:09:59 +0100 [thread overview]
Message-ID: <ZxDh9biUbf9W8gNN@J2N7QTR9R3> (raw)
In-Reply-To: <CACRpkda8tO=QLF_zznoNjdNfNZJVntY_3+247E=qK6zNqRnVSA@mail.gmail.com>
On Wed, Oct 16, 2024 at 09:00:22PM +0200, Linus Walleij wrote:
> On Wed, Oct 16, 2024 at 10:55 AM Mark Rutland <mark.rutland@arm.com> wrote:
>
> > I believe that's necessary for the lazy TLB switch, at least for SMP:
> >
> > // CPU 0 // CPU 1
> >
> > << switches to task X's mm >>
> >
> > << creates kthread task Y >>
> > << maps task Y's new stack >>
> > << maps task Y's new shadow >>
> >
> > // Y switched out
> > context_switch(..., Y, ..., ...);
> >
> > // Switch from X to Y
> > context_switch(..., X, Y, ...) {
> > // prev = X
> > // next = Y
> >
> > if (!next->mm) {
> > // Y has no mm
> > // No switch_mm() here
> > // ... so no check_vmalloc_seq()
> > } else {
> > // not taken
> > }
> >
> > ...
> >
> > // X's mm still lacks Y's stack + shadow here
> >
> > switch_to(prev, next, prev);
> > }
> >
> > ... so probably worth a comment that we're faulting in the new
> > stack+shadow for for lazy tlb when switching to a task with no mm?
>
> Switching to a task with no mm == switching to a kernel daemon.
A common misconception, but not always true:
* A kernel thread can have an mm: see kthread_use_mm() and
kthread_unuse_mm().
* A user thread can lose its mm while exiting: see how do_exit() calls
exit_mm(), and how hte task remains preemptible for a while
thereafter.
... so we really do just mean "a task with no mm".
> And those only use the kernel memory and relies on that always
> being mapped in any previous mm context, right.
A task with no mm only uses kernel memory. Anything it uses must be
mapped in init_mm, but *might* not have been copied into every other mm,
and hence might not be in the previous mm context as per the example
above.
> But where do we put that comment? In kernel/sched/core.c
> context_switch()?
I was trying to suggest we update the existing comment in switch_to() to
be more explicit. e.g. expand the existing comment:
@
@ Do a dummy read from the new stack while running from the old one so
@ that we can rely on do_translation_fault() to fix up any stale PMD
@ entries covering the vmalloc region.
@
... with:
@
@ For a non-lazy mm switch, check_vmalloc_seq() has ensured that
@ that the active mm's page tables have mappings for the prev
@ task's stack and the next task's stack.
@
@ For a lazy mm switch the active mm's page tables have mappings
@ for the prev task's stack but might not have mappings for the
@ new taks stack. Do a dummy read from the new stack while
@ running from the old stack so that we can rely on
@ do_translation_fault() to fix up any stale PMD entries
@ covering the vmalloc region.
@
Ard, does that sound good to you?
Mark.
next prev parent reply other threads:[~2024-10-17 11:01 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-14 13:19 Crash on armv7-a using KASAN Clement LE GOFFIC
2024-10-15 7:55 ` Linus Walleij
2024-10-15 10:35 ` Clement LE GOFFIC
2024-10-15 10:28 ` Mark Rutland
2024-10-15 13:51 ` Linus Walleij
2024-10-15 14:00 ` Mark Rutland
2024-10-15 14:22 ` Ard Biesheuvel
2024-10-15 14:35 ` Mark Rutland
2024-10-15 14:44 ` Ard Biesheuvel
2024-10-15 14:55 ` Linus Walleij
2024-10-15 15:26 ` Mark Rutland
2024-10-15 16:07 ` Ard Biesheuvel
2024-10-15 16:27 ` Mark Rutland
2024-10-15 17:28 ` Ard Biesheuvel
2024-10-15 20:55 ` Linus Walleij
2024-10-15 21:24 ` Linus Walleij
2024-10-16 8:55 ` Mark Rutland
2024-10-16 19:00 ` Linus Walleij
2024-10-17 10:09 ` Mark Rutland [this message]
2024-10-17 10:31 ` Ard Biesheuvel
2024-10-15 14:40 ` Linus Walleij
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=ZxDh9biUbf9W8gNN@J2N7QTR9R3 \
--to=mark.rutland@arm.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=antonio.borneo@foss.st.com \
--cc=ardb@kernel.org \
--cc=broonie@kernel.org \
--cc=clement.legoffic@foss.st.com \
--cc=kees@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=linux@armlinux.org.uk \
--cc=rmk+kernel@armlinux.org.uk \
/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