The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
To: "Barry Song (Xiaomi)" <baohua@kernel.org>
Cc: akpm@linux-foundation.org, linux-mm@kvack.org, x86@kernel.org,
	 linux-arm-kernel@lists.infradead.org, surenb@google.com,
	liam@infradead.org, vbabka@kernel.org,  shakeel.butt@linux.dev,
	david@kernel.org, linux-kernel@vger.kernel.org,
	 zhanghongru@xiaomi.com, willy@infradead.org,
	zhangbo56@xiaomi.com
Subject: Re: [RFC PATCH v1 1/2] x86/mm: use VMA lock for kernel faults on user addresses
Date: Mon, 3 Aug 2026 16:18:21 +0100	[thread overview]
Message-ID: <anCu3DOrXDeMrwi5@lucifer> (raw)
In-Reply-To: <20260802074018.73887-2-baohua@kernel.org>

On Sun, Aug 02, 2026 at 03:40:17PM +0800, Barry Song (Xiaomi) wrote:
> Use the VMA lock for kernel faults on user addresses. This also
> makes the existing code below meaningful:
>
>   /* Quick path to respond to signals */
>   if (fault_signal_pending(fault, regs)) {
>           if (!user_mode(regs))
>                   kernelmode_fixup_or_oops(regs, error_code, address,
>                                            SIGBUS, BUS_ADRERR,
>                                            ARCH_DEFAULT_PKEY);
>           return;
>   }

Hmm yeah :)

Bit weird it uses user_mode(regs) and the early exit uses the just-set
'flags & FAULT_FLAG_USER' too.

Some horrible duplication here too... the user_mod_regs() etc. code is just
duplicated in the mmap lock path.

I think you mentioned it on Suren/Dave's series but vma_start_read_unlocked()
would avoid all this and could lead to a nicely red patch.

>
> Right now, the code above is dead because !user_mode always
> takes the mmap_lock path.
>
> Co-developed-by: Bo Zhang <zhangbo56@xiaomi.com>
> Signed-off-by: Bo Zhang <zhangbo56@xiaomi.com>
> Signed-off-by: Barry Song (Xiaomi) <baohua@kernel.org>
> ---
>  arch/x86/mm/fault.c | 3 ---
>  1 file changed, 3 deletions(-)
>
> diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
> index 45b99c3b1442..c22b74e0eeaf 100644
> --- a/arch/x86/mm/fault.c
> +++ b/arch/x86/mm/fault.c
> @@ -1328,9 +1328,6 @@ void do_user_addr_fault(struct pt_regs *regs,
>  	}
>  #endif
>
> -	if (!(flags & FAULT_FLAG_USER))
> -		goto lock_mmap;
> -

I'm not sure why kernel faults of userland memory were excluded initially
(Suren?)

Given that it's OK to take the mmap lock here and we're necessarily in process
context anyway surely it's OK to take the VMA lock?

It looks fine to me but want Suren's input.

Also given vma_start_read_unlocked() is coming maybe that's better for a
cleanup.

And finally - Willy is working on a grand clean up of this stuff _I think_ so
you probably should coordinate with him also?

>  	vma = lock_vma_under_rcu(mm, address);
>  	if (!vma)
>  		goto lock_mmap;
> --
> 2.39.3 (Apple Git-146)
>

--
Cheers, Lorenzo

  reply	other threads:[~2026-08-03 15:18 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-02  7:40 [RFC PATCH v1 0/2] mm: use VMA lock for kernel faults on user addresses Barry Song (Xiaomi)
2026-08-02  7:40 ` [RFC PATCH v1 1/2] x86/mm: " Barry Song (Xiaomi)
2026-08-03 15:18   ` Lorenzo Stoakes (ARM) [this message]
2026-08-03 15:47     ` Suren Baghdasaryan
2026-08-03 22:37     ` Barry Song
2026-08-02  7:40 ` [RFC PATCH v1 2/2] arm64/mm: " Barry Song (Xiaomi)
2026-08-02  8:49   ` Barry Song
2026-08-03 15:32     ` Lorenzo Stoakes (ARM)

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=anCu3DOrXDeMrwi5@lucifer \
    --to=ljs@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=david@kernel.org \
    --cc=liam@infradead.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=shakeel.butt@linux.dev \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    --cc=willy@infradead.org \
    --cc=x86@kernel.org \
    --cc=zhangbo56@xiaomi.com \
    --cc=zhanghongru@xiaomi.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