Linux Trace Kernel
 help / color / mirror / Atom feed
From: Vladimir Kondratiev <Vladimir.Kondratiev@mobileye.com>
To: linux-riscv@lists.infradead.org,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Paul Walmsley <pjw@kernel.org>
Cc: linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [RFC] riscv: Can a valid LR/SC sequence have a backward branch on a failure path?
Date: Tue, 17 Nov 2026 11:52:05 +0200	[thread overview]
Message-ID: <a971d355-a7bd-41a8-83ba-a250e77f78f1@mobileye.com> (raw)

Hi all,



I have run into a question regarding LR/SC sequence constraints: can a
valid constrained LR/SC sequence contain a backward branch on a failure
path?



Consider this CAS example, where I placed the failure path before the
LR/SC sequence:



cas:

	j 1f

2:

	li a0, -1

	ret

1:

	lr.w   t0, (a0)

	bne    t0, a1, 2b

	sc.w   t0, a2, (a0)

	bnez   t0, 1b

	li     a0, 0

	ret



The rules in [1] prohibit taken backward branches within the sequence.
In this example, the backward branch (`2b`) is not taken when LR/SC
successfully completes; it is only taken on the failure path.



My context is control flow graph (CFG) analysis when detecting whether a
particular address belongs to a valid constrained LR/SC loop (where
probes must be rejected).



When scanning `bne t0, a1, 2b` in this scenario, should the scanner
treat this as an invalid sequence and stop, or should it ignore this
branch target and continue scanning forward?



[1]
https://docs.riscv.org/reference/isa/v20260120/unpriv/a-st-ext.html#sec:lrscseq



Thanks,

Vladimir

                 reply	other threads:[~2026-11-17  9:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=a971d355-a7bd-41a8-83ba-a250e77f78f1@mobileye.com \
    --to=vladimir.kondratiev@mobileye.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=palmer@dabbelt.com \
    --cc=pjw@kernel.org \
    /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