Linux-RISC-V Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Nam Cao <namcao@linutronix.de>
To: Xiaofeng Yuan <yuanxiaofeng@eswincomputing.com>,
	Paul Walmsley <pjw@kernel.org>,
	Palmer Dabbelt <palmer@dabbelt.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>,
	linux-riscv@lists.infradead.org,
	Xiaofeng Yuan <yuanxiaofeng@eswincomputing.com>
Subject: Re: [PATCH v4 2/2] riscv: kprobes: add KUnit test for LR/SC sequence rejection
Date: Tue, 22 Sep 2026 15:46:42 +0200	[thread overview]
Message-ID: <87se31e6v1.fsf@yellow.woof> (raw)
In-Reply-To: <20260828091202.1124-3-yuanxiaofeng@eswincomputing.com>

Xiaofeng Yuan <yuanxiaofeng@eswincomputing.com> writes:
> +SYM_FUNC_START(test_kprobes_lrsc)
> +	li a0, 1
> +1:
> +	lr.w a1, 0(x0)

It would be nice to place this instruction right at the beginning (ditch
the "li a0, 1"), so we can test that it is not wrongly skipped.

> +.Llrsc_inside:

Shouldn't the lr.w instruction be rejected as well?

> +	addi a1, a1, 1
> +	sc.w a2, a1, 0(x0)
> +	bnez a2, 1b
> +.Llrsc_after:
> +	li a0, KPROBE_TEST_MAGIC

We don't need to return KPROBE_TEST_MAGIC for this test case.

> +	ret
> +SYM_FUNC_END(test_kprobes_lrsc)
> +
> +.section .rodata
> +SYM_DATA_START(test_kprobes_lrsc_offsets)
> +	RISCV_PTR .Llrsc_inside - test_kprobes_lrsc
> +	RISCV_PTR .Llrsc_after - test_kprobes_lrsc

Why do we do the subtraction here, only to do the reverse addition in
test_kprobe_lrsc()?

> +SYM_DATA_END(test_kprobes_lrsc_offsets)
> +
>  .section .rodata
>  SYM_DATA_START(test_kprobes_addresses)
>  	RISCV_PTR test_kprobes_add_addr1
> diff --git a/arch/riscv/kernel/tests/kprobes/test-kprobes.c b/arch/riscv/kernel/tests/kprobes/test-kprobes.c
> index 027424a3ff..25bd103e20 100644
> --- a/arch/riscv/kernel/tests/kprobes/test-kprobes.c
> +++ b/arch/riscv/kernel/tests/kprobes/test-kprobes.c
> @@ -43,8 +43,27 @@ static void test_kprobe_riscv(struct kunit *test)
>  	kfree(kp);
>  }
>  
> +static void test_kprobe_lrsc(struct kunit *test)
> +{
> +	struct kprobe kp = {};
> +
> +	kp.pre_handler = kprobe_dummy_handler;
> +
> +	/* a probe inside an LR/SC sequence must be rejected */
> +	kp.addr = (kprobe_opcode_t *)((unsigned long)test_kprobes_lrsc +
> +				      test_kprobes_lrsc_offsets[0]);
> +	KUNIT_EXPECT_LT(test, register_kprobe(&kp), 0);
> +
> +	/* a probe right after the sequence must be accepted */
> +	kp.addr = (kprobe_opcode_t *)((unsigned long)test_kprobes_lrsc +
> +				      test_kprobes_lrsc_offsets[1]);
> +	KUNIT_EXPECT_EQ(test, 0, register_kprobe(&kp));
> +	unregister_kprobe(&kp);
> +}

We should have at least 4 checks: right before, first inside, last
inside, right after.

Nam

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  reply	other threads:[~2026-09-22 13:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-28  9:12 [PATCH v4 0/2] riscv: kprobes: reject probes inside LR/SC sequences Xiaofeng Yuan
2026-08-28  9:12 ` [PATCH v4 1/2] riscv: probes: reject kprobes " Xiaofeng Yuan
2026-09-22 13:37   ` Nam Cao
2026-08-28  9:12 ` [PATCH v4 2/2] riscv: kprobes: add KUnit test for LR/SC sequence rejection Xiaofeng Yuan
2026-09-22 13:46   ` Nam Cao [this message]
2026-09-20  8:02 ` [PATCH v4 0/2] riscv: kprobes: reject probes inside LR/SC sequences Xiaofeng Yuan
2026-09-22 15:40 ` Nam Cao

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=87se31e6v1.fsf@yellow.woof \
    --to=namcao@linutronix.de \
    --cc=aou@eecs.berkeley.edu \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=pjw@kernel.org \
    --cc=yuanxiaofeng@eswincomputing.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