RISC-V vle8ff vl truncation when a plugin instruments memory ops
Hi,
I'd like the community's take on an interaction between RISC-V vector fault-only-first loads and plugin memory callbacks — whether it's considered a bug or expected, and whether our prototype fix is on the right track.
When a plugin registers a vcpu_mem callback, vle8ff.v in a scan/strlen loop runs ~16x more often than with the plugin disabled. Reproduced on master (v11.1.0-rc3) with a minimal counting plugin + an inline-asm vle8ff guest loop: vle8ff executions go from 32M (callbacks off) to 512M (callbacks on), and total insns from ~234M to ~3594M.
The cause, as far as we can tell: vext_ldff() decides vl by probing each element and truncating at the first fault. That probe goes through probe_access_flags(), which — under a memory-observing plugin — returns a non-zero "not plain RAM" flag (TLB_MMIO via force_mmio in system mode — added by 6d03226b42 — or TLB_FORCE_SLOW in user mode). Since vext_ldff() treats any flag other than TLB_WATCHPOINT as "this element faults", the second element (i=1) is reported faulting and vl is truncated to 1. The loaded data stays correct, but the scan degenerates to 1 byte/iter.
Only fault-only-first seems affected: an ordinary load uses the probe result only to pick fast vs slow path, and the slow path still reads the data correctly (and is where the callback fires). Only FOF uses the probe result as a semantic input (it decides vl).
Our prototype: route the semantic probes inside vext_ldff() through probe_access_full_mmu() (which probes with check_mem_cbs=false), while leaving the plain-load path on probe_access_flags() so plugin observation of real loads/stores is unchanged. Concretely this meant an ignore_plugin bool on the RISC-V probe_pages() helper, plus a user-mode counterpart of probe_access_full_mmu() (it only existed in system mode). With it, the vle8ff count is identical with/without callbacks (32M both ways). A self-contained reproducer is ready.
Three quick questions:
1. Is the vl truncation under a memory-observing plugin a bug, or is reflecting force_mmio/TLB_FORCE_SLOW into the FOF probe intentional?
2. If a bug, is probe_access_full_mmu() at the FOF call sites the preferred layer, or should probe_access_flags() itself not fold plugin-induced force-slow into its returned flags?
3. Is an RFC patch + reproducer welcome?
I noticed target/i386/tcg/access.c already works around the same force-slow (the "No haddr means probe_access wants to force slow path" comment, and issue #2489), which is why I wanted to ask before posting.
Thanks,
Liang Li
信息安全声明:本邮件包含信息归发件人所在组织所有,发件人所在组织对该邮件拥有所有权利。请接收者注意保密,未经发件人书面许可,不得向任何第三方组织和个人透露本邮件所含信息。
Information Security Notice: The information contained in this mail is solely property of the sender's organization.This mail communication is confidential.Recipients named above are obligated to maintain secrecy and are not permitted to disclose the contents of this communication to others.