Linux-RISC-V Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: 袁晓峰 <yuanxiaofeng@eswincomputing.com>
To: "Vladimir Kondratiev" <vladimir.kondratiev@mobileye.com>
Cc: "Paul Walmsley" <pjw@kernel.org>,
	"Palmer Dabbelt" <palmer@dabbelt.com>,
	"Albert Ou" <aou@eecs.berkeley.edu>,
	"Alexandre Ghiti" <alex@ghiti.fr>,
	"Masami Hiramatsu" <mhiramat@kernel.org>,
	"Oleg Nesterov" <oleg@redhat.com>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Guo Ren" <guoren@kernel.org>,
	"Pekka Enberg" <penberg@kernel.org>,
	"Patrick Stählin" <me@packi.ch>,
	linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
	linux-trace-kernel@vger.kernel.org,
	"Palmer Dabbelt" <palmerdabbelt@google.com>,
	Sashiko <sashiko-bot@kernel.org>,
	"Nam Cao" <namcao@linutronix.de>
Subject: Re: [PATCH v4 0/3] riscv: probes: reject probes inside an LR/SC sequence
Date: Wed, 18 Nov 2026 18:52:56 +0800 (GMT+08:00)	[thread overview]
Message-ID: <178ccbf1.a40.1a1ee49cebb.Coremail.yuanxiaofeng@eswincomputing.com> (raw)
In-Reply-To: <20261115-probes-in-lrsc-v4-0-48b9b036bd1d@mobileye.com>

​Hi Vladimir, Nam, Masami,




Thanks for driving this. Nam,Masami and I worked on the same problem in 
an earlier series [1], which Nam reviewed over several revisions and Masami 
acked on the detection side. Vladimir, your forward scan also covers uprobes 
and does not suffer from the lone-lr false rejection that our window-based check had, 
so your approach is the better base; I would rather continue the fix on top of
your series than push ours.




For what it is worth, I applied the v4 probe logic and the 3/3 test to a
clean tree and the kprobes KUnit passes (pass:2 fail:0), so this is not
about breakage -- just a few things from our experience that may be worth
aligning.




1) Window size




   Spec 13.3 defines the constrained LR/SC loop as the LR/SC sequence plus
   the code to retry it, at most 16 instructions in total. That leaves at
   most 14 instructions between the lr and the sc (fewer once the retry
   branch is counted). RISCV_LRSC_MAX_BODY=16 is larger than that; could we
   align the bound with the spec? We had an off-by-one round on this with Nam
   in our series.




2) Test structure




   Among Nam's comments on ours was the "coupled" offsets[] + reject[] table;
   the separate allowed[]/rejected[] arrays you adopted came out of that
   discussion.




   Three smaller things:




   - KUNIT_EXPECT_LT(ret, 0) also accepts -EILSEQ (or any other negative
     error), so it can pass even when the LR/SC rejection did not happen.
     -EINVAL would pin the specific reason.
   - There is no allow-direction boundary, so a window that is too wide
     would still pass. A case just outside the (spec-correct) window,
     expected to be accepted, would pin the bound from both sides.
   - The max-length case is lr + 16 nops + sc, which is neither a loop nor
     within the 16-instruction spec bound. A real loop (lr + 13 instructions
     + sc + retry branch) would test what the spec actually constrains.




3) Decode OOB read (patch 1/3)




   We also sent a standalone fix for this earlier [2]. Your one-line
   &p->opcode change is equivalent and smaller, so please go with yours.




We are still learning and have certainly missed things here. Nam, Masami -
since you both reviewed our earlier series, would you mind taking a look at
this one too?




[1] https://lore.kernel.org/linux-riscv/20261019134121.1763-1-yuanxiaofeng@eswincomputing.com/
[2] https://lore.kernel.org/linux-riscv/20261021100058.322-1-yuanxiaofeng@eswincomputing.com/




Thanks,
Xiaofeng




> -----原始邮件-----
> 发件人: "Vladimir Kondratiev" <vladimir.kondratiev@mobileye.com>
> 发送时间:2026-11-15 20:37:32 (星期日)
> 收件人: "Paul Walmsley" <pjw@kernel.org>, "Palmer Dabbelt" <palmer@dabbelt.com>, "Albert Ou" <aou@eecs.berkeley.edu>, "Alexandre Ghiti" <alex@ghiti.fr>, "Masami Hiramatsu" <mhiramat@kernel.org>, "Oleg Nesterov" <oleg@redhat.com>, "Peter Zijlstra" <peterz@infradead.org>, "Guo Ren" <guoren@kernel.org>, "Pekka Enberg" <penberg@kernel.org>, "Patrick Stählin" <me@packi.ch>
> 抄送: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, "Palmer Dabbelt" <palmerdabbelt@google.com>, "Vladimir Kondratiev" <vladimir.kondratiev@mobileye.com>, Sashiko <sashiko-bot@kernel.org>, "Xiaofeng Yuan" <yuanxiaofeng@eswincomputing.com>
> 主题: [PATCH v4 0/3] riscv: probes: reject probes inside an LR/SC sequence
> 
> Patch 1 fixes page fault reported by sashiko-bot@kernel.org that
> existed before this patch series
> 
> Patch 2 rejects probes inside the LR/SC sequence. This commit was
> initially submitted as patch 1 of the series [1].
> Detaching it from that series because it is not depending on other stuff.
> 
> Patch 3 adds KUnit test, suggested by
> Xiaofeng Yuan <yuanxiaofeng@eswincomputing.com> in [2]
> 
> [1] https://patch.msgid.link/20261110-lrsc-only-v6-0-bafc3cc0fcae@mobileye.com
> [2] https://lore.kernel.org/linux-riscv/20261019134121.1763-3-yuanxiaofeng@eswincomputing.com/
> 
> ---
> Changes in v4:
> - Add KUnit test as suggested by Guo Ren <guoren@kernel.org>, based on
>   work by Xiaofeng Yuan <yuanxiaofeng@eswincomputing.com>
> - Scan for SC up to maximum possible sequence length. SPU does not know
>   about symbols, it is not correct to stop scanning at the end of
>   symbol. Globally visible symbol placed within LR/SC sequence should
>   not turn probe within the sequence into acceptable.
> - Link to v3: https://patch.msgid.link/20261112-probes-in-lrsc-v3-0-a95089852a17@mobileye.com
> 
> Changes in v3:
> - Fix lr/sc loop detection logic for lr at probe position
> - Add "Fixes" trailers as suggested by sashiko-bot@kernel.org
> - Link to v2: https://patch.msgid.link/20261111-probes-in-lrsc-v2-0-b2525b7e1e8e@mobileye.com
> 
> Changes in v2:
> - Allow kprobe on the LR itself unless it is part of the LR/SC loop.
> - Fix error (reported by sashiko-bot@kernel.org) where
>   arch_prepare_kprobe() returns -EILSEQ for LR/SC probes.
>   Make codes returned by arch_check_kprobe to indicate -EINVAL
>   if probe falls within the LR/SC loop, consistent with the case when
>   INSN_REJECTED returned by riscv_probe_decode_insn
> - add patch fixing out-of-bounds read in riscv_probe_decode_insn()
>   reported by sashiko-bot@kernel.org (as patch 1)
> - Link to v1: https://patch.msgid.link/20261111-probes-in-lrsc-v1-1-4f99ddea5f68@mobileye.com
> 
> To: Paul Walmsley <pjw@kernel.org>
> To: Palmer Dabbelt <palmer@dabbelt.com>
> To: Albert Ou <aou@eecs.berkeley.edu>
> To: Alexandre Ghiti <alex@ghiti.fr>
> To: Masami Hiramatsu <mhiramat@kernel.org>
> To: Oleg Nesterov <oleg@redhat.com>
> To: Peter Zijlstra <peterz@infradead.org>
> To: Guo Ren <guoren@kernel.org>
> To: Pekka Enberg <penberg@kernel.org>
> To: Patrick Stählin <me@packi.ch>
> Cc: linux-riscv@lists.infradead.org
> Cc: linux-kernel@vger.kernel.org
> Cc: linux-trace-kernel@vger.kernel.org
> Cc: Palmer Dabbelt <palmerdabbelt@google.com>
> Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
> 
> ---
> Vladimir Kondratiev (3):
>       riscv: kprobes: fix out-of-bounds read in riscv_probe_decode_insn
>       riscv: probes: reject probes inside an LR/SC sequence
>       riscv: kprobes: add KUnit test for LR/SC sequence rejection
> 
>  arch/riscv/include/asm/insn.h                      | 28 +++++++
>  arch/riscv/kernel/probes/decode-insn.c             | 91 ++++++++++++++++++++++
>  arch/riscv/kernel/probes/decode-insn.h             |  7 ++
>  arch/riscv/kernel/probes/kprobes.c                 | 28 +++++--
>  arch/riscv/kernel/probes/uprobes.c                 | 31 ++++++++
>  arch/riscv/kernel/tests/kprobes/test-kprobes-asm.S | 58 ++++++++++++++
>  arch/riscv/kernel/tests/kprobes/test-kprobes.c     | 32 ++++++++
>  arch/riscv/kernel/tests/kprobes/test-kprobes.h     |  6 ++
>  8 files changed, 274 insertions(+), 7 deletions(-)
> ---
> base-commit: c03c1a14507dfaf8b856c2608f9ac216021fc222
> change-id: 20261111-probes-in-lrsc-4ccde6cbf436
> 
> Best regards,
> --  
> Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

      parent reply	other threads:[~2026-11-18 10:53 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-15 12:37 [PATCH v4 0/3] riscv: probes: reject probes inside an LR/SC sequence Vladimir Kondratiev
2026-11-15 12:37 ` [PATCH v4 1/3] riscv: kprobes: fix out-of-bounds read in riscv_probe_decode_insn Vladimir Kondratiev
2026-11-15 12:37 ` [PATCH v4 2/3] riscv: probes: reject probes inside an LR/SC sequence Vladimir Kondratiev
2026-11-15 18:37   ` kernel test robot
2026-11-15 20:12   ` kernel test robot
2026-11-15 12:37 ` [PATCH v4 3/3] riscv: kprobes: add KUnit test for LR/SC sequence rejection Vladimir Kondratiev
2026-11-18 10:52 ` 袁晓峰 [this message]

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=178ccbf1.a40.1a1ee49cebb.Coremail.yuanxiaofeng@eswincomputing.com \
    --to=yuanxiaofeng@eswincomputing.com \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=guoren@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=me@packi.ch \
    --cc=mhiramat@kernel.org \
    --cc=namcao@linutronix.de \
    --cc=oleg@redhat.com \
    --cc=palmer@dabbelt.com \
    --cc=palmerdabbelt@google.com \
    --cc=penberg@kernel.org \
    --cc=peterz@infradead.org \
    --cc=pjw@kernel.org \
    --cc=sashiko-bot@kernel.org \
    --cc=vladimir.kondratiev@mobileye.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