All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rishab Pradeep <rishab@rispop.dev>
To: qemu-devel@nongnu.org
Cc: qemu-riscv@nongnu.org, richard.henderson@linaro.org,
	pbonzini@redhat.com, palmer@dabbelt.com,
	alistair.francis@wdc.com, liwei1518@gmail.com,
	daniel.barboza@oss.qualcomm.com, zhiwei_liu@linux.alibaba.com,
	chao.liu@processmission.com, tarun.patanjali@utexas.edu,
	christopher.elwood2024@gmail.com,
	Rishab Pradeep <rishab@rispop.dev>
Subject: [RFC PATCH 0/2] target/riscv: Check store permission before split AMOs with Zicfiss
Date: Tue, 24 Nov 2026 01:18:34 -0600	[thread overview]
Message-ID: <20261124071836.208740-1-rishab@rispop.dev> (raw)

With Zicfiss, an ordinary AMO to a shadow-stack page must fault with a
store/AMO access fault (cause 7).  When TCG lowers the AMO to a load
followed by a store (!CF_PARALLEL), the load runs first.  That gives
the wrong cause (15) when the PTE's A bit is clear under Svade, and it
lets the load's side effects (e.g. a read watchpoint) happen when an
earlier load has left a read-permitting TLB entry for the page.

Patch 1 adds probe_access_perm(), a permission-only lookup that takes
the real access size and skips watchpoints, dirty marking and the
plugin slow path.  Patch 2 uses it from the RISC-V AMO/AMOCAS
translation, only for TBs with shadow stacks enabled and !CF_PARALLEL
(the parallel helpers already look up the store first).

Tested on RV64 system emulation (debug, ASan, UBSan build):
 - cold-TLB AMO with A=D=0 on a shadow-stack page gives cause 7
   (cause 15 on baseline), single-thread TCG
 - read watchpoint after a warming load does not stop with the
   series, and stops on baseline, single-thread TCG
 - page-crossing Zama16b, page-crossing PMP and PMP-boundary AMOs,
   single-thread TCG and MTTCG
 - unit and qtest pass
 - check-tcg: rv128-sstatus (UBSan, pmp.c) fails and the
   interruptedmemory plugin test times out, both identically on master
 - check-functional (sanitized build): 4 timeouts, and three pass with
   a longer limit.  sifive_u passes in about 5s on baseline and
   patched builds without sanitizers.  I did not run check-functional
   on a sanitized master build.

Not tested: RV32 at runtime (including the amocas.d path in
gen_cmpxchg64), and the cold-TLB A=D=0 case and the read watchpoint
under MTTCG.  riscv32-softmmu and the linux-user targets compile.

Open questions:
 - Is a permission-only helper in accel/tcg acceptable?  The
   alternative is a RISC-V-local helper built on probe_access_flags(),
   at the cost of early dirty marking.
 - The probe is a store lookup, so with hardware A/D updates it may set
   D before the AMO's load phase runs.  If that load then faults, D is
   set on a page the AMO never accessed.  I have not tested this.
 - The second-page probe for page-crossing Zama16b accesses mirrors
   what the real operation does today.  A page-crossing access
   arguably should fault, since a granule cannot cross a page.
   Enforcing that would be a separate change.

Rishab Pradeep (2):
  accel/tcg: Add probe_access_perm()
  target/riscv: Check store permission before split AMOs with Zicfiss

 accel/tcg/cputlb.c                            | 11 ++++++
 include/accel/tcg/probe.h                     | 20 ++++++++++
 target/riscv/helper.h                         |  5 +++
 .../riscv/tcg/insn_trans/trans_rvzacas.c.inc  |  2 +
 target/riscv/tcg/op_helper.c                  | 37 +++++++++++++++++++
 target/riscv/tcg/translate.c                  | 23 ++++++++++++
 6 files changed, 98 insertions(+)

-- 
2.56.0



             reply	other threads:[~2026-11-24  7:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24  7:18 Rishab Pradeep [this message]
2026-11-24  7:18 ` [RFC PATCH 1/2] accel/tcg: Add probe_access_perm() Rishab Pradeep
2026-11-24  7:18 ` [RFC PATCH 2/2] target/riscv: Check store permission before split AMOs with Zicfiss Rishab Pradeep

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=20261124071836.208740-1-rishab@rispop.dev \
    --to=rishab@rispop.dev \
    --cc=alistair.francis@wdc.com \
    --cc=chao.liu@processmission.com \
    --cc=christopher.elwood2024@gmail.com \
    --cc=daniel.barboza@oss.qualcomm.com \
    --cc=liwei1518@gmail.com \
    --cc=palmer@dabbelt.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=tarun.patanjali@utexas.edu \
    --cc=zhiwei_liu@linux.alibaba.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.