On 2/21/26 2:18 AM, Tao Tang wrote:
Modify the main MMIO handlers (smmu_write_mmio, smmu_read_mmio) to determine the security state of the target register based on its memory-mapped offset.By checking if the offset is within the secure register space (>= SMMU_SECURE_REG_START), the handlers can deduce the register's SEC_SID (reg_sec_sid). This SID is then passed down to the register access helper functions (smmu_writel, smmu_readl, etc.). Inside these helpers, the switch statement now operates on a masked, relative offset: uint32_t reg_offset = offset & 0xfff; switch (reg_offset) { ... } This design leverages a key feature of the SMMU specification: registers with the same function across different 3 security states (Non-secure, Secure, Realm) share the same relative offset. This avoids significant code duplication. The reg_sec_sid passed from the MMIO handler determines which security bank to operate on, while the masked offset identifies the specific register within that bank. It is important to distinguish between the security state of the register itself and the security state of the access. A higher-privilege security state is permitted to access registers belonging to a lower-privilege state, but the reverse is not allowed. This patch lays the groundwork for enforcing such rules. For future compatibility with Realm states, the logic in the else block corresponding to the secure offset check: if (offset >= SMMU_SECURE_REG_START) { reg_sec_sid = SMMU_SEC_SID_S; } else { /* Future Realm handling */ } will need to be expanded. Signed-off-by: Tao Tang <[email protected]> --- hw/arm/smmuv3.c | 57 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 18 deletions(-)
Reviewed-by: Pierrick Bouvier <[email protected]>
