smmuv3: CMD_TLBI_NH_VA Hardcodes vmid = 0 and Misdecodes Non-Range TG = 0 (TLBI_TG_DC) for the Tested 64KB Granule

Abierto
#175 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
58/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
cpp
Área
backend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Environment

  • Host OS / Architecture: Ubuntu 24.04.3 LTS (x86_64)
  • Target repository: qualcomm/qbox (v7.4.5, commit 1dd01f4b1fbf8ecddf10093a992807369ea161ef)
  • 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):

  1. Non-Zero VMID Never Invalidated by CMD_TLBI_NH_VA (cand_tlbi_nh_va_vmid): Despite advertising IDR0.S2P = 1 and IDR0.VMID16 = 1, for a stream configured with STE.S2VMID = 7 and CD.ASID = 3, PE0 performs a Break-Before-Make remap of IOVA 0x0 from PA_OLD to PA_NEW using non-range CMD_TLBI_NH_VA(VMID=7, ASID=3, TG=0, VA=0) + CMD_SYNC (respecting IDR3.RIL == 0 per Arm IHI 0070 §4.4.1.1). Because handle_cmd_tlbi_nh_va() hardcodes vmid = 0, the IOTLB entry is never evicted and PE1's subsequent write (0x22222222) silently writes OLD=0x22222222 while leaving NEW=0x00000000.
  2. Standard Non-Range TG = 0 (TLBI_TG_DC) Fails on the Tested 64KB Granule (cand_tlbi_tg_dc_64k): Despite advertising IDR5.GRAN64K = 1 and IDR5.GRAN16K = 1, for a 64KB-granule stream (CD.TG0 = 1), PE0 performs a Break-Before-Make remap of IOVA 0x0 using standard non-range CMD_TLBI_NH_VA(TG=0, VA=0) + CMD_SYNC (which per Arm IHI 0070 §4.4.1.1 must invalidate any granule size covering VA). Because decode_tlbi_tg(0) returns CD_TG_4K and requires it->first.tg == CD_TG_4K, the 64KB IOTLB entry is never evicted and PE1's subsequent write (0x44444444) silently writes OLD=0x44444444 while leaving NEW=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:

  1. handle_cmd_tlbi_nh_va() (lines 2855-2867) (and handle_cmd_tlbi_nh_vaa(), lines 2870-2892) never decodes VMID from word0[47:32] (CMD_WORD0_VMID_SHIFT) and hardcodes 0 in iotlb_inv_iova(0, asid, va, tg.key_tg, mask);.
  2. detail_smmuv3::decode_tlbi_tg() (lines 2788-2800) collapses TLBI_TG_DC (0) into {PAGE_SHIFT_4K, CD_TG_4K}, and iotlb_inv_iova() / handle_cmd_tlbi_nh_vaa() / handle_cmd_tlbi_s2_ipa() require exact it->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, opcode 0x12):
    • 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 when IDR3.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. Hardcoding VMID = 0 violates §4.4.2.4 & §5.2 for every stream with STE.S2VMID != 0.
  • §4.4.1.1 ("Non-range invalidation", TG == 0b00):
    • When TG == 0b00 (TLBI_TG_DC, which is the only legal TG encoding when IDR3.RIL == 0), the command MUST invalidate any matching TLB entry covering Address, regardless of translation granule size (4KB, 16KB, or 64KB).
  • §4.4.2.3 (CMD_TLBI_NH_VAA, opcode 0x13) & §4.4.3.1 (CMD_TLBI_S2_IPA, opcode 0x2A):
    • Share the same VMID and TG = 0b00 invalidation semantics.

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.

Lenguaje dominante
C++
Estrellas
115
Forks
52
Merge medio
2 d 2 h
PR fusionados (30 d)
13

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de qualcomm/qbox

Todos los issues de qualcomm/qbox

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.