mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Björn Töpel" <bjorn@kernel.org>
To: Samuel Holland <samuel.holland@sifive.com>,
	Paul Walmsley <paul.walmsley@sifive.com>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Alexandre Ghiti <alex@ghiti.fr>,
	linux-riscv@lists.infradead.org, Guo Ren <guoren@kernel.org>
Cc: "Björn Töpel" <bjorn@rivosinc.com>,
	"Masami Hiramatsu" <mhiramat@kernel.org>,
	"Oleg Nesterov" <oleg@redhat.com>,
	"Peter Zijlstra" <peterz@infradead.org>,
	linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH fixes] riscv: uprobes: Add missing fence.i after building the XOL buffer
Date: Sat, 19 Apr 2025 12:18:51 +0200	[thread overview]
Message-ID: <87ikn0tpx0.fsf@all.your.base.are.belong.to.us> (raw)
In-Reply-To: <b864fc90-1297-4e1d-8487-61049e23e405@sifive.com>

Samuel Holland <samuel.holland@sifive.com> writes:

> Hi Björn,
>
> On 2025-04-17 2:49 AM, Björn Töpel wrote:
>> From: Björn Töpel <bjorn@rivosinc.com>
>> 
>> The XOL (execute out-of-line) buffer is used to single-step the
>> replaced instruction(s) for uprobes. The RISC-V port was missing a
>> proper fence.i (i$ flushing) after constructing the XOL buffer, which
>> can result in incorrect execution of stale/broken instructions.
>> 
>> This was found running the BPF selftests "test_progs:
>> uprobe_autoattach, attach_probe" on the Spacemit K1/X60, where the
>> uprobes tests randomly blew up.
>> 
>> Fixes: 74784081aac8 ("riscv: Add uprobes supported")
>> Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
>> ---
>>  arch/riscv/kernel/probes/uprobes.c | 9 +--------
>>  1 file changed, 1 insertion(+), 8 deletions(-)
>> 
>> diff --git a/arch/riscv/kernel/probes/uprobes.c b/arch/riscv/kernel/probes/uprobes.c
>> index 4b3dc8beaf77..4faef92dd771 100644
>> --- a/arch/riscv/kernel/probes/uprobes.c
>> +++ b/arch/riscv/kernel/probes/uprobes.c
>> @@ -176,13 +176,6 @@ void arch_uprobe_copy_ixol(struct page *page, unsigned long vaddr,
>>  		*(uprobe_opcode_t *)dst = __BUG_INSN_32;
>>  	}
>>  
>> +	flush_icache_range((unsigned long)dst, (unsigned long)dst + len);
>
> This works because flush_icache_range currently ignores the range, but
> semantically is not quite right, because of the line just above the context that
> increments dst. If the range was respected, this would only flush the ebreak,
> not the preceding single-stepped instruction.

Indeed! That was sloppy! I'll spin a v2!

Thank you!
Björn

      reply	other threads:[~2025-04-19 10:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-17  7:49 Björn Töpel
2025-04-18  9:57 ` Guo Ren
2025-04-18 16:18 ` Samuel Holland
2025-04-19 10:18   ` Björn Töpel [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=87ikn0tpx0.fsf@all.your.base.are.belong.to.us \
    --to=bjorn@kernel.org \
    --cc=alex@ghiti.fr \
    --cc=bjorn@rivosinc.com \
    --cc=guoren@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=oleg@redhat.com \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.com \
    --cc=peterz@infradead.org \
    --cc=samuel.holland@sifive.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®