smmuv3: CMD_TLBI_NH_VA Hardcodes vmid = 0 and Misdecodes Non-Range TG = 0 (TLBI_TG_DC) for the Tested 64KB Granule
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
Start in systemc-components/smmuv3/include/smmuv3.h, reading handle_cmd_tlbi_nh_va(), handle_cmd_tlbi_nh_vaa(), decode_tlbi_tg(), and the invalidation key matching described in the issue. Check how VMID and TG = 0 are handled for 4KB, 16KB, and 64KB entries; run the linked reproducer with bash reproducer/run.sh. Done means the two failing cases invalidate the stale entries while the 4KB control still passes.
索引モデルが issue の本文から書いたものです。
説明
Environment
- Host OS / Architecture: Ubuntu 24.04.3 LTS (
x86_64) - Target repository:
qualcomm/qbox(v7.4.5, commit1dd01f4b1fbf8ecddf10093a992807369ea161ef) - Affected source file(s):
systemc-components/smmuv3/include/smmuv3.h
Description
On QBox v7.4.5, two SMMUv3 TLBI invalidation defects leave stale IOTLB entries on a 2-core Cortex-A76 platform (PE0 configuring Stage-1 CD.V=1, CD.AA64=1, CD.EPD1=1, CD.A=1 and submitting SMMUv3 commands with dmi_allow = false to isolate internal IOTLB invalidation; PE1 acting as the TBU requester):
- Non-Zero
VMIDNever Invalidated byCMD_TLBI_NH_VA(cand_tlbi_nh_va_vmid): Despite advertisingIDR0.S2P = 1andIDR0.VMID16 = 1, for a stream configured withSTE.S2VMID = 7andCD.ASID = 3, PE0 performs a Break-Before-Make remap ofIOVA 0x0fromPA_OLDtoPA_NEWusing non-rangeCMD_TLBI_NH_VA(VMID=7, ASID=3, TG=0, VA=0)+CMD_SYNC(respectingIDR3.RIL == 0per Arm IHI 0070 §4.4.1.1). Becausehandle_cmd_tlbi_nh_va()hardcodesvmid = 0, the IOTLB entry is never evicted and PE1's subsequent write (0x22222222) silently writesOLD=0x22222222while leavingNEW=0x00000000. - Standard Non-Range
TG = 0(TLBI_TG_DC) Fails on the Tested 64KB Granule (cand_tlbi_tg_dc_64k): Despite advertisingIDR5.GRAN64K = 1andIDR5.GRAN16K = 1, for a 64KB-granule stream (CD.TG0 = 1), PE0 performs a Break-Before-Make remap ofIOVA 0x0using standard non-rangeCMD_TLBI_NH_VA(TG=0, VA=0)+CMD_SYNC(which per Arm IHI 0070 §4.4.1.1 must invalidate any granule size coveringVA). Becausedecode_tlbi_tg(0)returnsCD_TG_4Kand requiresit->first.tg == CD_TG_4K, the 64KB IOTLB entry is never evicted and PE1's subsequent write (0x44444444) silently writesOLD=0x44444444while leavingNEW=0x00000000.
Meanwhile, the paired control (control_vmid0_tg4k, using VMID = 0, ASID = 3, non-range TG = 0 (TLBI_TG_DC) on a 4KB page with Break-Before-Make remap) passes 3/3 on the unmodified baseline (OLD=0x11111111 NEW=0x22222222).
Root Cause
In systemc-components/smmuv3/include/smmuv3.h:
handle_cmd_tlbi_nh_va()(lines 2855-2867) (andhandle_cmd_tlbi_nh_vaa(), lines 2870-2892) never decodesVMIDfromword0[47:32](CMD_WORD0_VMID_SHIFT) and hardcodes0iniotlb_inv_iova(0, asid, va, tg.key_tg, mask);.detail_smmuv3::decode_tlbi_tg()(lines 2788-2800) collapsesTLBI_TG_DC(0) into{PAGE_SHIFT_4K, CD_TG_4K}, andiotlb_inv_iova()/handle_cmd_tlbi_nh_vaa()/handle_cmd_tlbi_s2_ipa()require exactit->first.tg == key_tg, breaking non-range (TG = 0) invalidation for the tested 64KB granule (and by the same key-matching code, 16KB granules).
Steps to Reproduce
Standalone bare-metal reproducer files: https://gist.github.com/canxin121/5e6aa37771aa48049193b0de0198a2bc
Run the reproducer against an unmodified build of the baseline commit listed above:
bash reproducer/run.sh
Observed output on the unmodified baseline:
VP_BIN=<simulator-dir>
QBOX_HEAD=1dd01f4b1fbf8ecddf10093a992807369ea161ef (v7.4.5)
=== PHASE: BEFORE_v7.4.5 ===
[BEFORE_v7.4.5][cand_tlbi_nh_va_vmid][run 1..3] 3/3 rc=0 verdict="VERDICT=FAIL CASE=tlbi_nh_va_vmid OLD=0x22222222 NEW=0x00000000" warnings=0
[BEFORE_v7.4.5][cand_tlbi_tg_dc_64k][run 1..3] 3/3 rc=0 verdict="VERDICT=FAIL CASE=tlbi_tg_dc_64k OLD=0x44444444 NEW=0x00000000" warnings=0
[BEFORE_v7.4.5][control_vmid0_tg4k][run 1..3] 3/3 rc=0 verdict="VERDICT=PASS CASE=control_vmid0_tg4k OLD=0x11111111 NEW=0x22222222" warnings=0
Expected Behavior
Arm SMMUv3 Architecture Specification (ARM IHI 0070)
- §5.2 (
STE.S2VMID): Associates a stream's Non-secure EL1_0 translations with a 16-bit VMID (STE.S2VMID, bits[143:128]), which tags cached TLB entries for VMID-scoped invalidation commands. - §4.4.2.4 (
CMD_TLBI_NH_VA, opcode0x12):word0[47:32]=VMID(16-bit Virtual Machine ID).word0[63:48]=ASID(16-bit Address Space ID).word0[11:10]=TG(0b00= non-range / any granule, required whenIDR3.RIL == 0;0b01= 4KB;0b10= 16KB;0b11= 64KB).word1[63:12]=Address[63:12].- Invalidates Stage-1 EL1_0 TLB entries matching
(VMID, ASID)covering the target address. HardcodingVMID = 0violates §4.4.2.4 & §5.2 for every stream withSTE.S2VMID != 0.
- §4.4.1.1 ("Non-range invalidation",
TG == 0b00):- When
TG == 0b00(TLBI_TG_DC, which is the only legalTGencoding whenIDR3.RIL == 0), the command MUST invalidate any matching TLB entry coveringAddress, regardless of translation granule size (4KB, 16KB, or 64KB).
- When
- §4.4.2.3 (
CMD_TLBI_NH_VAA, opcode0x13) & §4.4.3.1 (CMD_TLBI_S2_IPA, opcode0x2A):- Share the same
VMIDandTG = 0b00invalidation semantics.
- Share the same
Paired control: 3/3 PASS paired control_vmid0_tg4k (VMID=0, ASID=3, non-range TG=0 (TLBI_TG_DC) on a 4KB page) on the unmodified baseline (rc=0, OLD=0x11111111 NEW=0x22222222, warnings=0).
Status
Confirmed on the unmodified baseline commit above. A minimal fix has been verified locally and is ready to submit as a pull request.
- 主要言語
- C++
- スター
- 115
- フォーク
- 52
- 平均マージ
- 2日 2時間
- マージ済み PR(30日)
- 13
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
qualcomm/qbox のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
docs: dynamically loaded modules must export module_register() with extern "C" — requirement is undocumented and the failure mode points elsewhere対応中かも @mansiverma897993 が 134 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 54/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 39/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 53/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
gofractally/psibase#2379 ·
メンテナーはふだん 3 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
simnJS/AnyPS5#735 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
needs-format
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
Niko1221/Strata#7719 · コメント 1 件 ·
メンテナーはふだん 4 日以内に返信
-
area:tests kind:test
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信