From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794672892590614.7774468786383; Sat, 14 Nov 2026 08:14:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGNm-00088s-Do; Sat, 14 Nov 2026 11:13:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGNa-00083d-OT; Sat, 14 Nov 2026 11:13:28 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGNY-0008V1-AW; Sat, 14 Nov 2026 11:13:26 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-7 (Coremail) with UTF8SMTP id AQAAfwC3g6SdiPhqOEcqBg--.64213S2; Sun, 15 Nov 2026 00:13:17 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8Dwr3SZiPhqr9v6AA--.35633S3; Sun, 15 Nov 2026 00:13:14 +0800 (CST) From: Tao Tang To: Peter Maydell , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 01/35] hw/arm/smmuv3: Introduce Secure registers Date: Sun, 15 Nov 2026 00:13:13 +0800 Message-Id: <20261114161313.3638883-1-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8Dwr3SZiPhqr9v6AA--.35633S3 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBXgAAs7 Authentication-Results: hzbj-icmmx-7; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvJXoWxWr45uF17JFy7KrWfXw4fKrg_yoW5KF13pF WIyr1rG3yDWF42vw1fGa1UAF13Crs3Aa4xJFZFkr12ga4fWryayrW8Ka4fGr1kXFn5ZF1D GFnFva4Fg34Syr7anT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAU7a7-sFnT9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUU UUUUU Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794672893929154100 Content-Type: text/plain; charset="utf-8" The Arm SMMUv3 architecture defines a set of registers for managing Secure transactions and contexts. This patch introduces the definitions for these Secure registers within the SMMUv3 device model internal header. Signed-off-by: Tao Tang Reviewed-by: Eric Auger Reviewed-by: Pierrick Bouvier Reviewed-by: Mostafa Saleh Link: https://lore.kernel.org/qemu-devel/759ec110-365f-488b-802d-c7bb1efe30= bc@redhat.com/ Reviewed-by: Jim MacArthur --- include/hw/arm/smmuv3-common.h | 71 +++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/include/hw/arm/smmuv3-common.h b/include/hw/arm/smmuv3-common.h index 4609975edf9..63f98cdcd62 100644 --- a/include/hw/arm/smmuv3-common.h +++ b/include/hw/arm/smmuv3-common.h @@ -269,7 +269,7 @@ REG32(CD_5, 20) ((sel) ? ((cd)->word[4] =3D FIELD_DP32((cd)->word[4], CD_4, NSCFG1, (v= ))) : \ ((cd)->word[2] =3D FIELD_DP32((cd)->word[2], CD_2, NSCFG0, (v= )))) =20 -/* MMIO Registers */ +/* MMIO Registers. Shared by Non-secure/Realm/Root states. */ =20 REG32(IDR0, 0x0) FIELD(IDR0, S2P, 0 , 1) @@ -353,6 +353,7 @@ REG32(CR0, 0x20) FIELD(CR0, CMDQEN, 3, 1) =20 #define SMMU_CR0_RESERVED 0xFFFFFA20 +#define SMMU_S_CR0_RESERVED 0xFFFFFC12 =20 REG32(CR0ACK, 0x24) REG32(CR1, 0x28) @@ -411,6 +412,74 @@ REG32(EVENTQ_IRQ_CFG2, 0xbc) =20 #define A_IDREGS 0xfd0 =20 +#define SMMU_SECURE_REG_START 0x8000 /* Start of Secure-only registers */ + +REG32(S_IDR0, 0x8000) + FIELD(S_IDR0, MSI, 13, 1) + FIELD(S_IDR0, STALL_MODEL, 24, 2) +REG32(S_IDR1, 0x8004) + FIELD(S_IDR1, S_SIDSIZE, 0 , 6) + FIELD(S_IDR1, SEL2, 29, 1) + FIELD(S_IDR1, SECURE_IMPL, 31, 1) + +REG32(S_IDR2, 0x8008) +REG32(S_IDR3, 0x800c) +REG32(S_IDR4, 0x8010) + +REG32(S_CR0, 0x8020) + FIELD(S_CR0, SMMUEN, 0, 1) + FIELD(S_CR0, EVENTQEN, 2, 1) + FIELD(S_CR0, CMDQEN, 3, 1) + +REG32(S_CR0ACK, 0x8024) +REG32(S_CR1, 0x8028) +REG32(S_CR2, 0x802c) + +REG32(S_INIT, 0x803c) + FIELD(S_INIT, INV_ALL, 0, 1) + +REG32(S_GBPA, 0x8044) + FIELD(S_GBPA, ABORT, 20, 1) + FIELD(S_GBPA, UPDATE, 31, 1) + +REG32(S_IRQ_CTRL, 0x8050) + FIELD(S_IRQ_CTRL, GERROR_IRQEN, 0, 1) + FIELD(S_IRQ_CTRL, EVENTQ_IRQEN, 2, 1) + +REG32(S_IRQ_CTRLACK, 0x8054) + +REG32(S_GERROR, 0x8060) + FIELD(S_GERROR, CMDQ_ERR, 0, 1) + +#define SMMU_GERROR_IRQ_CFG0_RESERVED 0x00FFFFFFFFFFFFFC +#define SMMU_GERROR_IRQ_CFG2_RESERVED 0x000000000000003F + +#define SMMU_STRTAB_BASE_RESERVED 0x40FFFFFFFFFFFFC0 +#define SMMU_QUEUE_BASE_RESERVED 0x40FFFFFFFFFFFFFF +#define SMMU_EVENTQ_IRQ_CFG0_RESERVED 0x00FFFFFFFFFFFFFC + +REG32(S_GERRORN, 0x8064) +REG64(S_GERROR_IRQ_CFG0, 0x8068) +REG32(S_GERROR_IRQ_CFG1, 0x8070) +REG32(S_GERROR_IRQ_CFG2, 0x8074) +REG64(S_STRTAB_BASE, 0x8080) +REG32(S_STRTAB_BASE_CFG, 0x8088) + FIELD(S_STRTAB_BASE_CFG, LOG2SIZE, 0, 6) + FIELD(S_STRTAB_BASE_CFG, SPLIT, 6, 5) + FIELD(S_STRTAB_BASE_CFG, FMT, 16, 2) + +REG64(S_CMDQ_BASE, 0x8090) +REG32(S_CMDQ_PROD, 0x8098) +REG32(S_CMDQ_CONS, 0x809c) + FIELD(S_CMDQ_CONS, ERR, 24, 7) + +REG64(S_EVENTQ_BASE, 0x80a0) +REG32(S_EVENTQ_PROD, 0x80a8) +REG32(S_EVENTQ_CONS, 0x80ac) +REG64(S_EVENTQ_IRQ_CFG0, 0x80b0) +REG32(S_EVENTQ_IRQ_CFG1, 0x80b8) +REG32(S_EVENTQ_IRQ_CFG2, 0x80bc) + /* Commands */ =20 typedef enum SMMUCommandType { --=20 2.34.1 From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794672884264901.3843325765596; Sat, 14 Nov 2026 08:14:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGO5-0000Bp-8R; Sat, 14 Nov 2026 11:13:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGNy-0008VL-SY; Sat, 14 Nov 2026 11:13:50 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGNu-0001N7-Ee; Sat, 14 Nov 2026 11:13:50 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-6 (Coremail) with UTF8SMTP id AQAAfwAnnN22iPhqwhgGAg--.54857S2; Sun, 15 Nov 2026 00:13:42 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8DwFXWhiPhqsNv6AA--.30495S3; Sun, 15 Nov 2026 00:13:21 +0800 (CST) From: Tao Tang To: Peter Maydell , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 02/35] hw/arm/smmuv3: Introduce banked registers for SMMUv3 state Date: Sun, 15 Nov 2026 00:13:20 +0800 Message-Id: <20261114161320.3639148-1-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8DwFXWhiPhqsNv6AA--.30495S3 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBYAAAsF Authentication-Results: hzbj-icmmx-6; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvAXoWDCryfZFyUZF4ktr15Jw1DKFg_yoWrCrW3uo W2yr4qqw4DZw4vka48AFn5JF18tFW8Cw4qva1YqrWa9FsrKw45Kry8trs8CFyakF45XrZ7 Cw4xu3yrXFWIvFn5n29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7KY7ZEXasCq-sGcSsGvf J3UbIjqfuFe4nvWSU8nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2KfnxnUUI43ZEXa7xR_UU UUUUUUU== Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794672885929154100 Content-Type: text/plain; charset="utf-8" Rework the SMMUv3 state management by introducing a banked register structure. This is a purely mechanical refactoring with no functional changes. To support multiple security states, a new enum, SMMUSecSID, is introduced to identify each state, sticking to the spec terminology. A new structure, SMMUv3RegBank, is then defined to hold the state for a single security context. The main SMMUv3State now contains an array of these banks, indexed by SMMUSecSID. This avoids the need for separate fields for Non-secure and future Secure registers. All existing code, which handles only the Non-secure state, is updated to access its state via s->bank[SMMU_SEC_SID_NS]. A local bank helper pointer is used where it improves readability. Function signatures and logic remain untouched in this commit to isolate the structural changes and simplify review. This is the foundational step for building multi-security-state support. Signed-off-by: Tao Tang Reviewed-by: Eric Auger Reviewed-by: Pierrick Bouvier Reviewed-by: Mostafa Saleh Reviewed-by: Jim MacArthur --- hw/arm/smmuv3-internal.h | 24 ++- include/hw/arm/smmu-common.h | 6 + include/hw/arm/smmuv3.h | 30 ++- hw/arm/smmuv3-accel.c | 67 ++++--- hw/arm/smmuv3.c | 373 +++++++++++++++++++---------------- hw/arm/tegra241-cmdqv.c | 6 +- 6 files changed, 294 insertions(+), 212 deletions(-) diff --git a/hw/arm/smmuv3-internal.h b/hw/arm/smmuv3-internal.h index 0819a4b2e8d..10154ca161d 100644 --- a/hw/arm/smmuv3-internal.h +++ b/hw/arm/smmuv3-internal.h @@ -41,7 +41,9 @@ typedef enum SMMUTranslationClass { =20 static inline int smmu_enabled(SMMUv3State *s) { - return FIELD_EX32(s->cr[0], CR0, SMMUEN); + SMMUSecSID sec_sid =3D SMMU_SEC_SID_NS; + SMMUv3RegBank *bank =3D smmuv3_bank(s, sec_sid); + return FIELD_EX32(bank->cr[0], CR0, SMMUEN); } =20 /* Command Queue Entry */ @@ -69,12 +71,16 @@ static inline uint32_t smmuv3_idreg(int regoffset) =20 static inline bool smmuv3_eventq_irq_enabled(SMMUv3State *s) { - return FIELD_EX32(s->irq_ctrl, IRQ_CTRL, EVENTQ_IRQEN); + SMMUSecSID sec_sid =3D SMMU_SEC_SID_NS; + SMMUv3RegBank *bank =3D smmuv3_bank(s, sec_sid); + return FIELD_EX32(bank->irq_ctrl, IRQ_CTRL, EVENTQ_IRQEN); } =20 static inline bool smmuv3_gerror_irq_enabled(SMMUv3State *s) { - return FIELD_EX32(s->irq_ctrl, IRQ_CTRL, GERROR_IRQEN); + SMMUSecSID sec_sid =3D SMMU_SEC_SID_NS; + SMMUv3RegBank *bank =3D smmuv3_bank(s, sec_sid); + return FIELD_EX32(bank->irq_ctrl, IRQ_CTRL, GERROR_IRQEN); } =20 /* Queue Handling */ @@ -119,17 +125,23 @@ static inline void queue_cons_incr(SMMUQueue *q) =20 static inline bool smmuv3_cmdq_enabled(SMMUv3State *s) { - return FIELD_EX32(s->cr[0], CR0, CMDQEN); + SMMUSecSID sec_sid =3D SMMU_SEC_SID_NS; + SMMUv3RegBank *bank =3D smmuv3_bank(s, sec_sid); + return FIELD_EX32(bank->cr[0], CR0, CMDQEN); } =20 static inline bool smmuv3_eventq_enabled(SMMUv3State *s) { - return FIELD_EX32(s->cr[0], CR0, EVENTQEN); + SMMUSecSID sec_sid =3D SMMU_SEC_SID_NS; + SMMUv3RegBank *bank =3D smmuv3_bank(s, sec_sid); + return FIELD_EX32(bank->cr[0], CR0, EVENTQEN); } =20 static inline void smmu_write_cmdq_err(SMMUv3State *s, uint32_t err_type) { - s->cmdq.cons =3D FIELD_DP32(s->cmdq.cons, CMDQ_CONS, ERR, err_type); + SMMUSecSID sec_sid =3D SMMU_SEC_SID_NS; + SMMUv3RegBank *bank =3D smmuv3_bank(s, sec_sid); + bank->cmdq.cons =3D FIELD_DP32(bank->cmdq.cons, CMDQ_CONS, ERR, err_ty= pe); } =20 static const char *cmd_stringify[] =3D { diff --git a/include/hw/arm/smmu-common.h b/include/hw/arm/smmu-common.h index 7b975abc25a..6ea40f6b074 100644 --- a/include/hw/arm/smmu-common.h +++ b/include/hw/arm/smmu-common.h @@ -40,6 +40,12 @@ #define CACHED_ENTRY_TO_ADDR(ent, addr) ((ent)->entry.translated_addr= + \ ((addr) & (ent)->entry.addr_m= ask)) =20 +/* StreamID Security state */ +typedef enum SMMUSecSID { + SMMU_SEC_SID_NS =3D 0, + SMMU_SEC_SID_NUM, +} SMMUSecSID; + /* * Page table walk error types */ diff --git a/include/hw/arm/smmuv3.h b/include/hw/arm/smmuv3.h index d39fe8850bc..45033d26a1b 100644 --- a/include/hw/arm/smmuv3.h +++ b/include/hw/arm/smmuv3.h @@ -34,19 +34,13 @@ typedef struct SMMUQueue { uint8_t log2size; } SMMUQueue; =20 -struct SMMUv3State { - SMMUState smmu_state; - +typedef struct SMMUv3RegBank { uint32_t features; - uint8_t sid_size; uint8_t sid_split; =20 uint32_t idr[6]; - uint32_t iidr; - uint32_t aidr; uint32_t cr[3]; uint32_t cr0ack; - uint32_t statusr; uint32_t gbpa; uint32_t irq_ctrl; uint32_t gerror; @@ -61,6 +55,17 @@ struct SMMUv3State { uint32_t eventq_irq_cfg2; =20 SMMUQueue eventq, cmdq; +} SMMUv3RegBank; + +struct SMMUv3State { + SMMUState smmu_state; + + uint8_t sid_size; + uint32_t iidr; + uint32_t aidr; + uint32_t statusr; + + SMMUv3RegBank bank[SMMU_SEC_SID_NUM]; =20 qemu_irq irq[4]; QemuMutex mutex; @@ -103,7 +108,14 @@ bool smmuv3_ats_enabled(struct SMMUv3State *s); #define TYPE_ARM_SMMUV3 "arm-smmuv3" OBJECT_DECLARE_TYPE(SMMUv3State, SMMUv3Class, ARM_SMMUV3) =20 -#define STAGE1_SUPPORTED(s) FIELD_EX32(s->idr[0], IDR0, S1P) -#define STAGE2_SUPPORTED(s) FIELD_EX32(s->idr[0], IDR0, S2P) +#define STAGE1_SUPPORTED(s) \ + FIELD_EX32((s)->bank[SMMU_SEC_SID_NS].idr[0], IDR0, S1P) +#define STAGE2_SUPPORTED(s) \ + FIELD_EX32((s)->bank[SMMU_SEC_SID_NS].idr[0], IDR0, S2P) + +static inline SMMUv3RegBank *smmuv3_bank(SMMUv3State *s, SMMUSecSID sec_si= d) +{ + return &s->bank[sec_sid]; +} =20 #endif diff --git a/hw/arm/smmuv3-accel.c b/hw/arm/smmuv3-accel.c index 66e6a5011ae..91df3362215 100644 --- a/hw/arm/smmuv3-accel.c +++ b/hw/arm/smmuv3-accel.c @@ -41,6 +41,7 @@ static void smmuv3_accel_auto_finalise(SMMUv3State *s, struct iommu_hw_info_arm_smmuv3 *in= fo) { SMMUv3AccelState *accel =3D s->s_accel; + SMMUv3RegBank *bank =3D smmuv3_bank(s, SMMU_SEC_SID_NS); =20 /* * Return if 'auto' was not set for any accel SMMUv3 property, or @@ -55,23 +56,23 @@ static void smmuv3_accel_auto_finalise(SMMUv3State *s, } =20 if (s->ats =3D=3D ON_OFF_AUTO_AUTO) { - s->idr[0] =3D FIELD_DP32(s->idr[0], IDR0, ATS, - FIELD_EX32(info->idr[0], IDR0, ATS)); + bank->idr[0] =3D FIELD_DP32(bank->idr[0], IDR0, ATS, + FIELD_EX32(info->idr[0], IDR0, ATS)); } =20 if (s->ril =3D=3D ON_OFF_AUTO_AUTO) { - s->idr[3] =3D FIELD_DP32(s->idr[3], IDR3, RIL, - FIELD_EX32(info->idr[3], IDR3, RIL)); + bank->idr[3] =3D FIELD_DP32(bank->idr[3], IDR3, RIL, + FIELD_EX32(info->idr[3], IDR3, RIL)); } =20 if (s->ssidsize =3D=3D SSID_SIZE_MODE_AUTO) { - s->idr[1] =3D FIELD_DP32(s->idr[1], IDR1, SSIDSIZE, - FIELD_EX32(info->idr[1], IDR1, SSIDSIZE)); + bank->idr[1] =3D FIELD_DP32(bank->idr[1], IDR1, SSIDSIZE, + FIELD_EX32(info->idr[1], IDR1, SSIDSIZE)= ); } =20 if (s->oas =3D=3D OAS_MODE_AUTO) { - s->idr[5] =3D FIELD_DP32(s->idr[5], IDR5, OAS, - FIELD_EX32(info->idr[5], IDR5, OAS)); + bank->idr[5] =3D FIELD_DP32(bank->idr[5], IDR5, OAS, + FIELD_EX32(info->idr[5], IDR5, OAS)); } =20 accel->auto_finalised =3D true; @@ -82,21 +83,22 @@ smmuv3_accel_check_hw_compatible(SMMUv3State *s, struct iommu_hw_info_arm_smmuv3 *info, Error **errp) { + SMMUv3RegBank *bank =3D smmuv3_bank(s, SMMU_SEC_SID_NS); smmuv3_accel_auto_finalise(s, info); =20 /* QEMU SMMUv3 supports both linear and 2-level stream tables */ if (FIELD_EX32(info->idr[0], IDR0, STLEVEL) !=3D - FIELD_EX32(s->idr[0], IDR0, STLEVEL)) { + FIELD_EX32(bank->idr[0], IDR0, STLEVEL)) { error_setg(errp, "Host SMMUv3 Stream Table format mismatch " "(host STLEVEL=3D%u, QEMU STLEVEL=3D%u)", FIELD_EX32(info->idr[0], IDR0, STLEVEL), - FIELD_EX32(s->idr[0], IDR0, STLEVEL)); + FIELD_EX32(bank->idr[0], IDR0, STLEVEL)); return false; } =20 /* QEMU SMMUv3 supports only little-endian translation table walks */ if (FIELD_EX32(info->idr[0], IDR0, TTENDIAN) > - FIELD_EX32(s->idr[0], IDR0, TTENDIAN)) { + FIELD_EX32(bank->idr[0], IDR0, TTENDIAN)) { error_setg(errp, "Host SMMUv3 doesn't support Little-endian " "translation table"); return false; @@ -104,7 +106,7 @@ smmuv3_accel_check_hw_compatible(SMMUv3State *s, =20 /* QEMU SMMUv3 supports only AArch64 translation table format */ if (FIELD_EX32(info->idr[0], IDR0, TTF) < - FIELD_EX32(s->idr[0], IDR0, TTF)) { + FIELD_EX32(bank->idr[0], IDR0, TTF)) { error_setg(errp, "Host SMMUv3 doesn't support AArch64 translation " "table format"); return false; @@ -112,59 +114,59 @@ smmuv3_accel_check_hw_compatible(SMMUv3State *s, =20 /* QEMU SMMUv3 supports SIDSIZE 16 */ if (FIELD_EX32(info->idr[1], IDR1, SIDSIZE) < - FIELD_EX32(s->idr[1], IDR1, SIDSIZE)) { + FIELD_EX32(bank->idr[1], IDR1, SIDSIZE)) { error_setg(errp, "Host SMMUv3 SIDSIZE not compatible " "(host=3D%u, QEMU=3D%u)", FIELD_EX32(info->idr[1], IDR1, SIDSIZE), - FIELD_EX32(s->idr[1], IDR1, SIDSIZE)); + FIELD_EX32(bank->idr[1], IDR1, SIDSIZE)); return false; } =20 /* Check SSIDSIZE value opted-in is compatible with Host SMMUv3 SSIDSI= ZE */ if (FIELD_EX32(info->idr[1], IDR1, SSIDSIZE) < - FIELD_EX32(s->idr[1], IDR1, SSIDSIZE)) { + FIELD_EX32(bank->idr[1], IDR1, SSIDSIZE)) { error_setg(errp, "Host SMMUv3 SSIDSIZE not compatible " "(host=3D%u, QEMU=3D%u)", FIELD_EX32(info->idr[1], IDR1, SSIDSIZE), - FIELD_EX32(s->idr[1], IDR1, SSIDSIZE)); + FIELD_EX32(bank->idr[1], IDR1, SSIDSIZE)); return false; } =20 /* User can disable QEMU SMMUv3 Range Invalidation support */ if (FIELD_EX32(info->idr[3], IDR3, RIL) < - FIELD_EX32(s->idr[3], IDR3, RIL)) { + FIELD_EX32(bank->idr[3], IDR3, RIL)) { error_setg(errp, "Host SMMUv3 doesn't support Range Invalidation"); return false; } /* Check OAS value opted is compatible with Host SMMUv3 IPA */ if (FIELD_EX32(info->idr[5], IDR5, OAS) < - FIELD_EX32(s->idr[5], IDR5, OAS)) { + FIELD_EX32(bank->idr[5], IDR5, OAS)) { error_setg(errp, "Host SMMUv3 supports only %d-bit IPA, but the vS= MMU " "OAS implies %d-bit IPA", smmuv3_oas_bits(FIELD_EX32(info->idr[5], IDR5, OAS)), - smmuv3_oas_bits(FIELD_EX32(s->idr[5], IDR5, OAS))); + smmuv3_oas_bits(FIELD_EX32(bank->idr[5], IDR5, OAS))); return false; } /* Check ATS value opted is compatible with Host SMMUv3 */ if (FIELD_EX32(info->idr[0], IDR0, ATS) < - FIELD_EX32(s->idr[0], IDR0, ATS)) { + FIELD_EX32(bank->idr[0], IDR0, ATS)) { error_setg(errp, "Host SMMUv3 doesn't support Address Translation = Services"); return false; } =20 /* QEMU SMMUv3 supports GRAN4K/GRAN16K/GRAN64K translation granules */ if (FIELD_EX32(info->idr[5], IDR5, GRAN4K) !=3D - FIELD_EX32(s->idr[5], IDR5, GRAN4K)) { + FIELD_EX32(bank->idr[5], IDR5, GRAN4K)) { error_setg(errp, "Host SMMUv3 doesn't support 4K translation granu= le"); return false; } if (FIELD_EX32(info->idr[5], IDR5, GRAN16K) !=3D - FIELD_EX32(s->idr[5], IDR5, GRAN16K)) { + FIELD_EX32(bank->idr[5], IDR5, GRAN16K)) { error_setg(errp, "Host SMMUv3 doesn't support 16K translation gran= ule"); return false; } if (FIELD_EX32(info->idr[5], IDR5, GRAN64K) !=3D - FIELD_EX32(s->idr[5], IDR5, GRAN64K)) { + FIELD_EX32(bank->idr[5], IDR5, GRAN64K)) { error_setg(errp, "Host SMMUv3 doesn't support 64K translation gran= ule"); return false; } @@ -218,7 +220,8 @@ static SMMUv3AccelDevice *smmuv3_accel_get_dev(SMMUStat= e *bs, SMMUPciBus *sbus, =20 static uint32_t smmuv3_accel_gbpa_hwpt(SMMUv3State *s, SMMUv3AccelState *a= ccel) { - return FIELD_EX32(s->gbpa, GBPA, ABORT) ? + SMMUv3RegBank *bank =3D smmuv3_bank(s, SMMU_SEC_SID_NS); + return FIELD_EX32(bank->gbpa, GBPA, ABORT) ? accel->abort_hwpt_id : accel->bypass_hwpt_id; } =20 @@ -544,6 +547,8 @@ bool smmuv3_accel_alloc_veventq(SMMUv3State *s, Error *= *errp) uint32_t veventq_id; uint32_t veventq_fd; int flags; + SMMUSecSID sec_sid =3D SMMU_SEC_SID_NS; + SMMUv3RegBank *bank =3D smmuv3_bank(s, sec_sid); =20 if (!accel || !accel->viommu) { return true; @@ -560,7 +565,7 @@ bool smmuv3_accel_alloc_veventq(SMMUv3State *s, Error *= *errp) if (!iommufd_backend_alloc_veventq(accel->viommu->iommufd, accel->viommu->viommu_id, IOMMU_VEVENTQ_TYPE_ARM_SMMUV3, - 1 << s->eventq.log2size, &veventq_i= d, + 1 << bank->eventq.log2size, &vevent= q_id, &veventq_fd, errp)) { return false; } @@ -943,9 +948,10 @@ static AddressSpace *smmuv3_accel_find_add_as(PCIBus *= bus, void *opaque, =20 static inline bool smmuv3_pasid_supported(SMMUv3State *s) { + SMMUv3RegBank *bank =3D smmuv3_bank(s, SMMU_SEC_SID_NS); return s->ssidsize > SSID_SIZE_MODE_0 || (s->ssidsize =3D=3D SSID_SIZE_MODE_AUTO && - FIELD_EX32(s->idr[1], IDR1, SSIDSIZE)); + FIELD_EX32(bank->idr[1], IDR1, SSIDSIZE)); } =20 static uint64_t smmuv3_accel_get_viommu_flags(void *opaque) @@ -997,19 +1003,20 @@ void smmuv3_accel_idr_override(SMMUv3State *s) return; } =20 + SMMUv3RegBank *bank =3D smmuv3_bank(s, SMMU_SEC_SID_NS); /* Only override RIL if user explicitly set OFF */ if (s->ril =3D=3D ON_OFF_AUTO_OFF) { - s->idr[3] =3D FIELD_DP32(s->idr[3], IDR3, RIL, 0); + bank->idr[3] =3D FIELD_DP32(bank->idr[3], IDR3, RIL, 0); } =20 /* QEMU SMMUv3 has no ATS. Advertise ATS if opt-in by property */ if (s->ats =3D=3D ON_OFF_AUTO_ON) { - s->idr[0] =3D FIELD_DP32(s->idr[0], IDR0, ATS, 1); + bank->idr[0] =3D FIELD_DP32(bank->idr[0], IDR0, ATS, 1); } =20 /* Advertise 48-bit OAS in IDR5 when requested (default is 44 bits). */ if (s->oas =3D=3D OAS_MODE_48) { - s->idr[5] =3D FIELD_DP32(s->idr[5], IDR5, OAS, SMMU_IDR5_OAS_48); + bank->idr[5] =3D FIELD_DP32(bank->idr[5], IDR5, OAS, SMMU_IDR5_OAS= _48); } =20 /* @@ -1017,7 +1024,7 @@ void smmuv3_accel_idr_override(SMMUv3State *s) * has enabled it. */ if (s->ssidsize > SSID_SIZE_MODE_0) { - s->idr[1] =3D FIELD_DP32(s->idr[1], IDR1, SSIDSIZE, + bank->idr[1] =3D FIELD_DP32(bank->idr[1], IDR1, SSIDSIZE, ssidsize_mode_to_value(s->ssidsize)); } } diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index ed19536a4dc..3198fcd9eeb 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -53,6 +53,8 @@ static void smmuv3_trigger_irq(SMMUv3State *s, SMMUIrq irq, uint32_t gerror_mask) { + SMMUSecSID sec_sid =3D SMMU_SEC_SID_NS; + SMMUv3RegBank *bank =3D smmuv3_bank(s, sec_sid); =20 bool pulse =3D false; =20 @@ -68,15 +70,15 @@ static void smmuv3_trigger_irq(SMMUv3State *s, SMMUIrq = irq, break; case SMMU_IRQ_GERROR: { - uint32_t pending =3D s->gerror ^ s->gerrorn; + uint32_t pending =3D bank->gerror ^ bank->gerrorn; uint32_t new_gerrors =3D ~pending & gerror_mask; =20 if (!new_gerrors) { /* only toggle non pending errors */ return; } - s->gerror ^=3D new_gerrors; - trace_smmuv3_write_gerror(new_gerrors, s->gerror); + bank->gerror ^=3D new_gerrors; + trace_smmuv3_write_gerror(new_gerrors, bank->gerror); =20 pulse =3D smmuv3_gerror_irq_enabled(s); break; @@ -90,8 +92,10 @@ static void smmuv3_trigger_irq(SMMUv3State *s, SMMUIrq i= rq, =20 static void smmuv3_write_gerrorn(SMMUv3State *s, uint32_t new_gerrorn) { - uint32_t pending =3D s->gerror ^ s->gerrorn; - uint32_t toggled =3D s->gerrorn ^ new_gerrorn; + SMMUSecSID sec_sid =3D SMMU_SEC_SID_NS; + SMMUv3RegBank *bank =3D smmuv3_bank(s, sec_sid); + uint32_t pending =3D bank->gerror ^ bank->gerrorn; + uint32_t toggled =3D bank->gerrorn ^ new_gerrorn; =20 if (toggled & ~pending) { qemu_log_mask(LOG_GUEST_ERROR, @@ -103,9 +107,9 @@ static void smmuv3_write_gerrorn(SMMUv3State *s, uint32= _t new_gerrorn) * We do not raise any error in case guest toggles bits corresponding * to not active IRQs (CONSTRAINED UNPREDICTABLE) */ - s->gerrorn =3D new_gerrorn; + bank->gerrorn =3D new_gerrorn; =20 - trace_smmuv3_write_gerrorn(toggled & pending, s->gerrorn); + trace_smmuv3_write_gerrorn(toggled & pending, bank->gerrorn); } =20 static inline MemTxResult queue_read(SMMUQueue *q, Cmd *cmd) @@ -147,7 +151,9 @@ static MemTxResult queue_write(SMMUQueue *q, Evt *evt_i= n) =20 static MemTxResult smmuv3_write_eventq(SMMUv3State *s, Evt *evt) { - SMMUQueue *q =3D &s->eventq; + SMMUSecSID sec_sid =3D SMMU_SEC_SID_NS; + SMMUv3RegBank *bank =3D smmuv3_bank(s, sec_sid); + SMMUQueue *q =3D &bank->eventq; MemTxResult r; =20 if (!smmuv3_eventq_enabled(s)) { @@ -275,74 +281,86 @@ void smmuv3_record_event(SMMUv3State *s, SMMUEventInf= o *info) */ static void smmuv3_init_id_regs(SMMUv3State *s) { + SMMUv3RegBank *bank =3D smmuv3_bank(s, SMMU_SEC_SID_NS); + /* Based on sys property, the stages supported in smmu will be adverti= sed.*/ if (s->stage && !strcmp("2", s->stage)) { - s->idr[0] =3D FIELD_DP32(s->idr[0], IDR0, S2P, 1); + bank->idr[0] =3D FIELD_DP32(bank->idr[0], IDR0, S2P, 1); } else if (s->stage && !strcmp("nested", s->stage)) { - s->idr[0] =3D FIELD_DP32(s->idr[0], IDR0, S1P, 1); - s->idr[0] =3D FIELD_DP32(s->idr[0], IDR0, S2P, 1); + bank->idr[0] =3D FIELD_DP32(bank->idr[0], IDR0, S1P, 1); + bank->idr[0] =3D FIELD_DP32(bank->idr[0], IDR0, S2P, 1); } else { - s->idr[0] =3D FIELD_DP32(s->idr[0], IDR0, S1P, 1); - } - - s->idr[0] =3D FIELD_DP32(s->idr[0], IDR0, TTF, 2); /* AArch64 PTW only= */ - s->idr[0] =3D FIELD_DP32(s->idr[0], IDR0, COHACC, 1); /* IO coherent */ - s->idr[0] =3D FIELD_DP32(s->idr[0], IDR0, ASID16, 1); /* 16-bit ASID */ - s->idr[0] =3D FIELD_DP32(s->idr[0], IDR0, VMID16, 1); /* 16-bit VMID */ - s->idr[0] =3D FIELD_DP32(s->idr[0], IDR0, TTENDIAN, 2); /* little endi= an */ - s->idr[0] =3D FIELD_DP32(s->idr[0], IDR0, STALL_MODEL, 1); /* No stall= */ + bank->idr[0] =3D FIELD_DP32(bank->idr[0], IDR0, S1P, 1); + } + + /* AArch64 PTW only */ + bank->idr[0] =3D FIELD_DP32(bank->idr[0], IDR0, TTF, 2); + /* IO coherent */ + bank->idr[0] =3D FIELD_DP32(bank->idr[0], IDR0, COHACC, 1); + /* 16-bit ASID */ + bank->idr[0] =3D FIELD_DP32(bank->idr[0], IDR0, ASID16, 1); + /* 16-bit VMID */ + bank->idr[0] =3D FIELD_DP32(bank->idr[0], IDR0, VMID16, 1); + /* little endian */ + bank->idr[0] =3D FIELD_DP32(bank->idr[0], IDR0, TTENDIAN, 2); + /* No stall */ + bank->idr[0] =3D FIELD_DP32(bank->idr[0], IDR0, STALL_MODEL, 1); /* terminated transaction will always be aborted/error returned */ - s->idr[0] =3D FIELD_DP32(s->idr[0], IDR0, TERM_MODEL, 1); + bank->idr[0] =3D FIELD_DP32(bank->idr[0], IDR0, TERM_MODEL, 1); /* 2-level stream table supported */ - s->idr[0] =3D FIELD_DP32(s->idr[0], IDR0, STLEVEL, 1); + bank->idr[0] =3D FIELD_DP32(bank->idr[0], IDR0, STLEVEL, 1); =20 - s->idr[1] =3D FIELD_DP32(s->idr[1], IDR1, SIDSIZE, SMMU_IDR1_SIDSIZE); - s->idr[1] =3D FIELD_DP32(s->idr[1], IDR1, EVENTQS, SMMU_EVENTQS); - s->idr[1] =3D FIELD_DP32(s->idr[1], IDR1, CMDQS, SMMU_CMDQS); + bank->idr[1] =3D FIELD_DP32(bank->idr[1], IDR1, SIDSIZE, SMMU_IDR1_SID= SIZE); + bank->idr[1] =3D FIELD_DP32(bank->idr[1], IDR1, EVENTQS, SMMU_EVENTQS); + bank->idr[1] =3D FIELD_DP32(bank->idr[1], IDR1, CMDQS, SMMU_CMDQS); =20 - s->idr[3] =3D FIELD_DP32(s->idr[3], IDR3, HAD, 1); - if (FIELD_EX32(s->idr[0], IDR0, S2P)) { + bank->idr[3] =3D FIELD_DP32(bank->idr[3], IDR3, HAD, 1); + if (FIELD_EX32(bank->idr[0], IDR0, S2P)) { /* XNX is a stage-2-specific feature */ - s->idr[3] =3D FIELD_DP32(s->idr[3], IDR3, XNX, 1); + bank->idr[3] =3D FIELD_DP32(bank->idr[3], IDR3, XNX, 1); } - s->idr[3] =3D FIELD_DP32(s->idr[3], IDR3, RIL, 1); - s->idr[3] =3D FIELD_DP32(s->idr[3], IDR3, BBML, 2); + bank->idr[3] =3D FIELD_DP32(bank->idr[3], IDR3, RIL, 1); + bank->idr[3] =3D FIELD_DP32(bank->idr[3], IDR3, BBML, 2); =20 /* OAS: 44 bits */ - s->idr[5] =3D FIELD_DP32(s->idr[5], IDR5, OAS, SMMU_IDR5_OAS_44); + bank->idr[5] =3D FIELD_DP32(bank->idr[5], IDR5, OAS, SMMU_IDR5_OAS_44); /* 4K, 16K and 64K granule support */ - s->idr[5] =3D FIELD_DP32(s->idr[5], IDR5, GRAN4K, 1); - s->idr[5] =3D FIELD_DP32(s->idr[5], IDR5, GRAN16K, 1); - s->idr[5] =3D FIELD_DP32(s->idr[5], IDR5, GRAN64K, 1); + bank->idr[5] =3D FIELD_DP32(bank->idr[5], IDR5, GRAN4K, 1); + bank->idr[5] =3D FIELD_DP32(bank->idr[5], IDR5, GRAN16K, 1); + bank->idr[5] =3D FIELD_DP32(bank->idr[5], IDR5, GRAN64K, 1); s->aidr =3D 0x1; smmuv3_accel_idr_override(s); } =20 bool smmuv3_ats_enabled(SMMUv3State *s) { - return FIELD_EX32(s->idr[0], IDR0, ATS); + SMMUv3RegBank *bank =3D smmuv3_bank(s, SMMU_SEC_SID_NS); + return FIELD_EX32(bank->idr[0], IDR0, ATS); } =20 static void smmuv3_reset(SMMUv3State *s) { - s->cmdq.base =3D deposit64(s->cmdq.base, 0, 5, SMMU_CMDQS); - s->cmdq.prod =3D 0; - s->cmdq.cons =3D 0; - s->cmdq.entry_size =3D sizeof(struct Cmd); - s->eventq.base =3D deposit64(s->eventq.base, 0, 5, SMMU_EVENTQS); - s->eventq.prod =3D 0; - s->eventq.cons =3D 0; - s->eventq.entry_size =3D sizeof(struct Evt); - - s->features =3D 0; - s->sid_split =3D 0; - s->cr[0] =3D 0; - s->cr0ack =3D 0; - s->irq_ctrl =3D 0; - s->gerror =3D 0; - s->gerrorn =3D 0; + SMMUv3RegBank *bank =3D smmuv3_bank(s, SMMU_SEC_SID_NS); + + bank->cmdq.base =3D deposit64(bank->cmdq.base, 0, 5, SMMU_CMDQS); + bank->cmdq.prod =3D 0; + bank->cmdq.cons =3D 0; + bank->cmdq.entry_size =3D sizeof(struct Cmd); + bank->eventq.base =3D deposit64(bank->eventq.base, 0, 5, SMMU_EVENTQS); + bank->eventq.prod =3D 0; + bank->eventq.cons =3D 0; + bank->eventq.entry_size =3D sizeof(struct Evt); + + bank->features =3D 0; + bank->sid_split =3D 0; + bank->cr[0] =3D 0; + bank->cr0ack =3D 0; + bank->irq_ctrl =3D 0; + bank->gerror =3D 0; + bank->gerrorn =3D 0; + bank->gbpa =3D SMMU_GBPA_RESET_VAL; + s->statusr =3D 0; - s->gbpa =3D SMMU_GBPA_RESET_VAL; } =20 static int smmu_get_ste(SMMUv3State *s, dma_addr_t addr, STE *buf, @@ -456,7 +474,8 @@ static bool s2_pgtable_config_valid(uint8_t sl0, uint8_= t t0sz, uint8_t gran) static int decode_ste_s2_cfg(SMMUv3State *s, SMMUTransCfg *cfg, STE *ste) { - uint8_t oas =3D FIELD_EX32(s->idr[5], IDR5, OAS); + uint8_t oas =3D FIELD_EX32(smmuv3_bank(s, SMMU_SEC_SID_NS)->idr[5], + IDR5, OAS); =20 if (STE_S2AA64(ste) =3D=3D 0x0) { qemu_log_mask(LOG_UNIMP, @@ -574,7 +593,9 @@ static int decode_ste(SMMUv3State *s, SMMUTransCfg *cfg, STE *ste, SMMUEventInfo *event) { uint32_t config; - uint8_t oas =3D FIELD_EX32(s->idr[5], IDR5, OAS); + /* OAS field only presents on NS-IDR5 so we use hardcoded SMMU_SEC_SID= _NS */ + uint8_t oas =3D FIELD_EX32(smmuv3_bank(s, SMMU_SEC_SID_NS)->idr[5], + IDR5, OAS); int ret; =20 if (!STE_VALID(ste)) { @@ -628,7 +649,8 @@ static int decode_ste(SMMUv3State *s, SMMUTransCfg *cfg, /* Multiple context descriptors require SubstreamID support */ if ((s->ssidsize =3D=3D SSID_SIZE_MODE_0 || (s->ssidsize =3D=3D SSID_SIZE_MODE_AUTO && - !FIELD_EX32(s->idr[1], IDR1, SSIDSIZE))) && + !FIELD_EX32(smmuv3_bank(s, SMMU_SEC_SID_NS)->idr[1], + IDR1, SSIDSIZE))) && STE_S1CDMAX(ste) !=3D 0) { qemu_log_mask(LOG_UNIMP, "SMMUv3: multiple S1 context descriptors require Substream= ID support. " @@ -666,9 +688,11 @@ int smmu_find_ste(SMMUv3State *s, uint32_t sid, STE *s= te, SMMUEventInfo *event) uint32_t log2size; int strtab_size; int ret; + SMMUSecSID sec_sid =3D SMMU_SEC_SID_NS; + SMMUv3RegBank *bank =3D smmuv3_bank(s, sec_sid); =20 - trace_smmuv3_find_ste(sid, s->features, s->sid_split); - log2size =3D FIELD_EX32(s->strtab_base_cfg, STRTAB_BASE_CFG, LOG2SIZE); + trace_smmuv3_find_ste(sid, bank->features, bank->sid_split); + log2size =3D FIELD_EX32(bank->strtab_base_cfg, STRTAB_BASE_CFG, LOG2SI= ZE); /* * Check SID range against both guest-configured and implementation li= mits */ @@ -676,7 +700,7 @@ int smmu_find_ste(SMMUv3State *s, uint32_t sid, STE *st= e, SMMUEventInfo *event) event->type =3D SMMU_EVT_C_BAD_STREAMID; return -EINVAL; } - if (s->features & SMMU_FEATURE_2LVL_STE) { + if (bank->features & SMMU_FEATURE_2LVL_STE) { int l1_ste_offset, l2_ste_offset, max_l2_ste, span, i; dma_addr_t l1ptr, l2ptr; STEDesc l1std; @@ -685,11 +709,11 @@ int smmu_find_ste(SMMUv3State *s, uint32_t sid, STE *= ste, SMMUEventInfo *event) * Align strtab base address to table size. For this purpose, assu= me it * is not bounded by SMMU_IDR1_SIDSIZE. */ - strtab_size =3D MAX(6, (int)log2size - s->sid_split + L1STD_SIZE); - strtab_base =3D s->strtab_base & SMMU_BASE_ADDR_MASK & + strtab_size =3D MAX(6, (int)log2size - bank->sid_split + L1STD_SIZ= E); + strtab_base =3D bank->strtab_base & SMMU_BASE_ADDR_MASK & ~MAKE_64BIT_MASK(0, strtab_size); - l1_ste_offset =3D sid >> s->sid_split; - l2_ste_offset =3D sid & ((1 << s->sid_split) - 1); + l1_ste_offset =3D sid >> bank->sid_split; + l2_ste_offset =3D sid & ((1 << bank->sid_split) - 1); l1ptr =3D (dma_addr_t)(strtab_base + l1_ste_offset * sizeof(l1std)= ); /* TODO: guarantee 64-bit single-copy atomicity */ ret =3D dma_memory_read(&address_space_memory, l1ptr, &l1std, @@ -717,7 +741,7 @@ int smmu_find_ste(SMMUv3State *s, uint32_t sid, STE *st= e, SMMUEventInfo *event) return -EINVAL; } =20 - if (span > s->sid_split + 1) { + if (span > bank->sid_split + 1) { if (!event->inval_ste_allowed) { qemu_log_mask(LOG_GUEST_ERROR, "invalid span (0x%x)\n", span); @@ -728,9 +752,8 @@ int smmu_find_ste(SMMUv3State *s, uint32_t sid, STE *st= e, SMMUEventInfo *event) =20 max_l2_ste =3D (1 << span) - 1; l2ptr =3D l1std_l2ptr(&l1std); - l2ptr &=3D ~MAKE_64BIT_MASK(0, 6 + (span - 1)); - trace_smmuv3_find_ste_2lvl(s->strtab_base, l1ptr, l1_ste_offset, + trace_smmuv3_find_ste_2lvl(bank->strtab_base, l1ptr, l1_ste_offset, l2ptr, l2_ste_offset, max_l2_ste); if (l2_ste_offset > max_l2_ste) { qemu_log_mask(LOG_GUEST_ERROR, @@ -743,7 +766,7 @@ int smmu_find_ste(SMMUv3State *s, uint32_t sid, STE *st= e, SMMUEventInfo *event) } else { strtab_size =3D log2size + STE_SIZE; strtab_size =3D MIN(64, strtab_size); - strtab_base =3D s->strtab_base & SMMU_BASE_ADDR_MASK & + strtab_base =3D bank->strtab_base & SMMU_BASE_ADDR_MASK & ~MAKE_64BIT_MASK(0, strtab_size); addr =3D strtab_base + sid * sizeof(*ste); } @@ -762,7 +785,8 @@ static int decode_cd(SMMUv3State *s, SMMUTransCfg *cfg, int i; SMMUTranslationStatus status; SMMUTLBEntry *entry; - uint8_t oas =3D FIELD_EX32(s->idr[5], IDR5, OAS); + uint8_t oas =3D FIELD_EX32(smmuv3_bank(s, SMMU_SEC_SID_NS)->idr[5], + IDR5, OAS); =20 if (!CD_VALID(cd) || !CD_AARCH64(cd)) { goto bad_cd; @@ -1084,6 +1108,8 @@ static IOMMUTLBEntry smmuv3_translate(IOMMUMemoryRegi= on *mr, hwaddr addr, SMMUDevice *sdev =3D container_of(mr, SMMUDevice, iommu); SMMUv3State *s =3D sdev->smmu; uint32_t sid =3D smmu_get_sid(sdev); + SMMUSecSID sec_sid =3D SMMU_SEC_SID_NS; + SMMUv3RegBank *bank =3D smmuv3_bank(s, sec_sid); SMMUEventInfo event =3D {.type =3D SMMU_EVT_NONE, .sid =3D sid, .inval_ste_allowed =3D false}; @@ -1101,7 +1127,7 @@ static IOMMUTLBEntry smmuv3_translate(IOMMUMemoryRegi= on *mr, hwaddr addr, qemu_mutex_lock(&s->mutex); =20 if (!smmu_enabled(s)) { - if (FIELD_EX32(s->gbpa, GBPA, ABORT)) { + if (FIELD_EX32(bank->gbpa, GBPA, ABORT)) { status =3D SMMU_TRANS_ABORT; } else { status =3D SMMU_TRANS_DISABLE; @@ -1325,7 +1351,9 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error = **errp) { SMMUState *bs =3D ARM_SMMU(s); SMMUCmdError cmd_error =3D SMMU_CERROR_NONE; - SMMUQueue *q =3D &s->cmdq; + SMMUSecSID sec_sid =3D SMMU_SEC_SID_NS; + SMMUv3RegBank *bank =3D smmuv3_bank(s, sec_sid); + SMMUQueue *q =3D &bank->cmdq; SMMUCommandType type =3D 0; =20 if (!smmuv3_cmdq_enabled(s)) { @@ -1339,7 +1367,7 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error = **errp) */ =20 while (!smmuv3_q_empty(q)) { - uint32_t pending =3D s->gerror ^ s->gerrorn; + uint32_t pending =3D bank->gerror ^ bank->gerrorn; Cmd cmd; =20 trace_smmuv3_cmdq_consume(Q_PROD(q), Q_CONS(q), @@ -1601,29 +1629,32 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Erro= r **errp) static MemTxResult smmu_writell(SMMUv3State *s, hwaddr offset, uint64_t data, MemTxAttrs attrs) { + SMMUSecSID reg_sec_sid =3D SMMU_SEC_SID_NS; + SMMUv3RegBank *bank =3D smmuv3_bank(s, reg_sec_sid); + switch (offset) { case A_GERROR_IRQ_CFG0: - s->gerror_irq_cfg0 =3D data; + bank->gerror_irq_cfg0 =3D data; return MEMTX_OK; case A_STRTAB_BASE: - s->strtab_base =3D data; + bank->strtab_base =3D data; return MEMTX_OK; case A_CMDQ_BASE: - s->cmdq.base =3D data; - s->cmdq.log2size =3D extract64(s->cmdq.base, 0, 5); - if (s->cmdq.log2size > SMMU_CMDQS) { - s->cmdq.log2size =3D SMMU_CMDQS; + bank->cmdq.base =3D data; + bank->cmdq.log2size =3D extract64(bank->cmdq.base, 0, 5); + if (bank->cmdq.log2size > SMMU_CMDQS) { + bank->cmdq.log2size =3D SMMU_CMDQS; } return MEMTX_OK; case A_EVENTQ_BASE: - s->eventq.base =3D data; - s->eventq.log2size =3D extract64(s->eventq.base, 0, 5); - if (s->eventq.log2size > SMMU_EVENTQS) { - s->eventq.log2size =3D SMMU_EVENTQS; + bank->eventq.base =3D data; + bank->eventq.log2size =3D extract64(bank->eventq.base, 0, 5); + if (bank->eventq.log2size > SMMU_EVENTQS) { + bank->eventq.log2size =3D SMMU_EVENTQS; } return MEMTX_OK; case A_EVENTQ_IRQ_CFG0: - s->eventq_irq_cfg0 =3D data; + bank->eventq_irq_cfg0 =3D data; return MEMTX_OK; default: qemu_log_mask(LOG_UNIMP, @@ -1637,11 +1668,13 @@ static MemTxResult smmu_writel(SMMUv3State *s, hwad= dr offset, uint64_t data, MemTxAttrs attrs) { Error *local_err =3D NULL; + SMMUSecSID reg_sec_sid =3D SMMU_SEC_SID_NS; + SMMUv3RegBank *bank =3D smmuv3_bank(s, reg_sec_sid); =20 switch (offset) { case A_CR0: - s->cr[0] =3D data; - s->cr0ack =3D data & ~SMMU_CR0_RESERVED; + bank->cr[0] =3D data; + bank->cr0ack =3D data & ~SMMU_CR0_RESERVED; /* in case the command queue has been enabled */ smmuv3_cmdq_consume(s, &local_err); if (local_err) { @@ -1652,13 +1685,13 @@ static MemTxResult smmu_writel(SMMUv3State *s, hwad= dr offset, smmuv3_accel_alloc_veventq(s, &local_err); break; case A_CR1: - s->cr[1] =3D data; + bank->cr[1] =3D data; break; case A_CR2: - s->cr[2] =3D data; + bank->cr[2] =3D data; break; case A_IRQ_CTRL: - s->irq_ctrl =3D data; + bank->irq_ctrl =3D data; break; case A_GERRORN: smmuv3_write_gerrorn(s, data); @@ -1669,16 +1702,16 @@ static MemTxResult smmu_writel(SMMUv3State *s, hwad= dr offset, smmuv3_cmdq_consume(s, &local_err); break; case A_GERROR_IRQ_CFG0: /* 64b */ - s->gerror_irq_cfg0 =3D deposit64(s->gerror_irq_cfg0, 0, 32, data); + bank->gerror_irq_cfg0 =3D deposit64(bank->gerror_irq_cfg0, 0, 32, = data); break; case A_GERROR_IRQ_CFG0 + 4: - s->gerror_irq_cfg0 =3D deposit64(s->gerror_irq_cfg0, 32, 32, data); + bank->gerror_irq_cfg0 =3D deposit64(bank->gerror_irq_cfg0, 32, 32,= data); break; case A_GERROR_IRQ_CFG1: - s->gerror_irq_cfg1 =3D data; + bank->gerror_irq_cfg1 =3D data; break; case A_GERROR_IRQ_CFG2: - s->gerror_irq_cfg2 =3D data; + bank->gerror_irq_cfg2 =3D data; break; case A_GBPA: /* @@ -1687,74 +1720,75 @@ static MemTxResult smmu_writel(SMMUv3State *s, hwad= dr offset, */ if (data & R_GBPA_UPDATE_MASK) { /* Ignore update bit as write is synchronous. */ - s->gbpa =3D data & ~R_GBPA_UPDATE_MASK; + bank->gbpa =3D data & ~R_GBPA_UPDATE_MASK; smmuv3_accel_attach_gbpa_hwpt(s, &local_err); } break; case A_STRTAB_BASE: /* 64b */ - s->strtab_base =3D deposit64(s->strtab_base, 0, 32, data); + bank->strtab_base =3D deposit64(bank->strtab_base, 0, 32, data); break; case A_STRTAB_BASE + 4: - s->strtab_base =3D deposit64(s->strtab_base, 32, 32, data); + bank->strtab_base =3D deposit64(bank->strtab_base, 32, 32, data); break; case A_STRTAB_BASE_CFG: - s->strtab_base_cfg =3D data; + bank->strtab_base_cfg =3D data; if (FIELD_EX32(data, STRTAB_BASE_CFG, FMT) =3D=3D 1) { - s->sid_split =3D FIELD_EX32(data, STRTAB_BASE_CFG, SPLIT); - if (s->sid_split !=3D 6 && s->sid_split !=3D 8 && s->sid_split= !=3D 10) { + bank->sid_split =3D FIELD_EX32(data, STRTAB_BASE_CFG, SPLIT); + if (bank->sid_split !=3D 6 && bank->sid_split !=3D 8 && + bank->sid_split !=3D 10) { /* Other values are reserved, behave as 6 */ qemu_log_mask(LOG_GUEST_ERROR, "Invalid STRTAB_BASE_CFG.SPLIT=3D%u, use 6 i= nstead\n", - s->sid_split); - s->sid_split =3D 6; + bank->sid_split); + bank->sid_split =3D 6; } - s->features |=3D SMMU_FEATURE_2LVL_STE; + bank->features |=3D SMMU_FEATURE_2LVL_STE; } break; case A_CMDQ_BASE: /* 64b */ - s->cmdq.base =3D deposit64(s->cmdq.base, 0, 32, data); - s->cmdq.log2size =3D extract64(s->cmdq.base, 0, 5); - if (s->cmdq.log2size > SMMU_CMDQS) { - s->cmdq.log2size =3D SMMU_CMDQS; + bank->cmdq.base =3D deposit64(bank->cmdq.base, 0, 32, data); + bank->cmdq.log2size =3D extract64(bank->cmdq.base, 0, 5); + if (bank->cmdq.log2size > SMMU_CMDQS) { + bank->cmdq.log2size =3D SMMU_CMDQS; } break; case A_CMDQ_BASE + 4: /* 64b */ - s->cmdq.base =3D deposit64(s->cmdq.base, 32, 32, data); + bank->cmdq.base =3D deposit64(bank->cmdq.base, 32, 32, data); break; case A_CMDQ_PROD: - s->cmdq.prod =3D data; + bank->cmdq.prod =3D data; smmuv3_cmdq_consume(s, &local_err); break; case A_CMDQ_CONS: - s->cmdq.cons =3D data; + bank->cmdq.cons =3D data; break; case A_EVENTQ_BASE: /* 64b */ - s->eventq.base =3D deposit64(s->eventq.base, 0, 32, data); - s->eventq.log2size =3D extract64(s->eventq.base, 0, 5); - if (s->eventq.log2size > SMMU_EVENTQS) { - s->eventq.log2size =3D SMMU_EVENTQS; + bank->eventq.base =3D deposit64(bank->eventq.base, 0, 32, data); + bank->eventq.log2size =3D extract64(bank->eventq.base, 0, 5); + if (bank->eventq.log2size > SMMU_EVENTQS) { + bank->eventq.log2size =3D SMMU_EVENTQS; } break; case A_EVENTQ_BASE + 4: - s->eventq.base =3D deposit64(s->eventq.base, 32, 32, data); + bank->eventq.base =3D deposit64(bank->eventq.base, 32, 32, data); break; case A_EVENTQ_PROD: - s->eventq.prod =3D data; + bank->eventq.prod =3D data; break; case A_EVENTQ_CONS: - s->eventq.cons =3D data; + bank->eventq.cons =3D data; break; case A_EVENTQ_IRQ_CFG0: /* 64b */ - s->eventq_irq_cfg0 =3D deposit64(s->eventq_irq_cfg0, 0, 32, data); + bank->eventq_irq_cfg0 =3D deposit64(bank->eventq_irq_cfg0, 0, 32, = data); break; case A_EVENTQ_IRQ_CFG0 + 4: - s->eventq_irq_cfg0 =3D deposit64(s->eventq_irq_cfg0, 32, 32, data); + bank->eventq_irq_cfg0 =3D deposit64(bank->eventq_irq_cfg0, 32, 32,= data); break; case A_EVENTQ_IRQ_CFG1: - s->eventq_irq_cfg1 =3D data; + bank->eventq_irq_cfg1 =3D data; break; case A_EVENTQ_IRQ_CFG2: - s->eventq_irq_cfg2 =3D data; + bank->eventq_irq_cfg2 =3D data; break; default: qemu_log_mask(LOG_UNIMP, @@ -1798,18 +1832,21 @@ static MemTxResult smmu_write_mmio(void *opaque, hw= addr offset, uint64_t data, static MemTxResult smmu_readll(SMMUv3State *s, hwaddr offset, uint64_t *data, MemTxAttrs attrs) { + SMMUSecSID reg_sec_sid =3D SMMU_SEC_SID_NS; + SMMUv3RegBank *bank =3D smmuv3_bank(s, reg_sec_sid); + switch (offset) { case A_GERROR_IRQ_CFG0: - *data =3D s->gerror_irq_cfg0; + *data =3D bank->gerror_irq_cfg0; return MEMTX_OK; case A_STRTAB_BASE: - *data =3D s->strtab_base; + *data =3D bank->strtab_base; return MEMTX_OK; case A_CMDQ_BASE: - *data =3D s->cmdq.base; + *data =3D bank->cmdq.base; return MEMTX_OK; case A_EVENTQ_BASE: - *data =3D s->eventq.base; + *data =3D bank->eventq.base; return MEMTX_OK; default: *data =3D 0; @@ -1823,12 +1860,15 @@ static MemTxResult smmu_readll(SMMUv3State *s, hwad= dr offset, static MemTxResult smmu_readl(SMMUv3State *s, hwaddr offset, uint64_t *data, MemTxAttrs attrs) { + SMMUSecSID reg_sec_sid =3D SMMU_SEC_SID_NS; + SMMUv3RegBank *bank =3D smmuv3_bank(s, reg_sec_sid); + switch (offset) { case A_IDREGS ... A_IDREGS + 0x2f: *data =3D smmuv3_idreg(offset - A_IDREGS); return MEMTX_OK; case A_IDR0 ... A_IDR5: - *data =3D s->idr[(offset - A_IDR0) / 4]; + *data =3D bank->idr[(offset - A_IDR0) / 4]; return MEMTX_OK; case A_IIDR: *data =3D s->iidr; @@ -1837,77 +1877,77 @@ static MemTxResult smmu_readl(SMMUv3State *s, hwadd= r offset, *data =3D s->aidr; return MEMTX_OK; case A_CR0: - *data =3D s->cr[0]; + *data =3D bank->cr[0]; return MEMTX_OK; case A_CR0ACK: - *data =3D s->cr0ack; + *data =3D bank->cr0ack; return MEMTX_OK; case A_CR1: - *data =3D s->cr[1]; + *data =3D bank->cr[1]; return MEMTX_OK; case A_CR2: - *data =3D s->cr[2]; + *data =3D bank->cr[2]; return MEMTX_OK; case A_STATUSR: *data =3D s->statusr; return MEMTX_OK; case A_GBPA: - *data =3D s->gbpa; + *data =3D bank->gbpa; return MEMTX_OK; case A_IRQ_CTRL: case A_IRQ_CTRL_ACK: - *data =3D s->irq_ctrl; + *data =3D bank->irq_ctrl; return MEMTX_OK; case A_GERROR: - *data =3D s->gerror; + *data =3D bank->gerror; return MEMTX_OK; case A_GERRORN: - *data =3D s->gerrorn; + *data =3D bank->gerrorn; return MEMTX_OK; case A_GERROR_IRQ_CFG0: /* 64b */ - *data =3D extract64(s->gerror_irq_cfg0, 0, 32); + *data =3D extract64(bank->gerror_irq_cfg0, 0, 32); return MEMTX_OK; case A_GERROR_IRQ_CFG0 + 4: - *data =3D extract64(s->gerror_irq_cfg0, 32, 32); + *data =3D extract64(bank->gerror_irq_cfg0, 32, 32); return MEMTX_OK; case A_GERROR_IRQ_CFG1: - *data =3D s->gerror_irq_cfg1; + *data =3D bank->gerror_irq_cfg1; return MEMTX_OK; case A_GERROR_IRQ_CFG2: - *data =3D s->gerror_irq_cfg2; + *data =3D bank->gerror_irq_cfg2; return MEMTX_OK; case A_STRTAB_BASE: /* 64b */ - *data =3D extract64(s->strtab_base, 0, 32); + *data =3D extract64(bank->strtab_base, 0, 32); return MEMTX_OK; case A_STRTAB_BASE + 4: /* 64b */ - *data =3D extract64(s->strtab_base, 32, 32); + *data =3D extract64(bank->strtab_base, 32, 32); return MEMTX_OK; case A_STRTAB_BASE_CFG: - *data =3D s->strtab_base_cfg; + *data =3D bank->strtab_base_cfg; return MEMTX_OK; case A_CMDQ_BASE: /* 64b */ - *data =3D extract64(s->cmdq.base, 0, 32); + *data =3D extract64(bank->cmdq.base, 0, 32); return MEMTX_OK; case A_CMDQ_BASE + 4: - *data =3D extract64(s->cmdq.base, 32, 32); + *data =3D extract64(bank->cmdq.base, 32, 32); return MEMTX_OK; case A_CMDQ_PROD: - *data =3D s->cmdq.prod; + *data =3D bank->cmdq.prod; return MEMTX_OK; case A_CMDQ_CONS: - *data =3D s->cmdq.cons; + *data =3D bank->cmdq.cons; return MEMTX_OK; case A_EVENTQ_BASE: /* 64b */ - *data =3D extract64(s->eventq.base, 0, 32); + *data =3D extract64(bank->eventq.base, 0, 32); return MEMTX_OK; case A_EVENTQ_BASE + 4: /* 64b */ - *data =3D extract64(s->eventq.base, 32, 32); + *data =3D extract64(bank->eventq.base, 32, 32); return MEMTX_OK; case A_EVENTQ_PROD: - *data =3D s->eventq.prod; + *data =3D bank->eventq.prod; return MEMTX_OK; case A_EVENTQ_CONS: - *data =3D s->eventq.cons; + *data =3D bank->eventq.cons; return MEMTX_OK; default: *data =3D 0; @@ -2089,9 +2129,10 @@ static const VMStateDescription vmstate_smmuv3_queue= =3D { static bool smmuv3_gbpa_needed(void *opaque) { SMMUv3State *s =3D opaque; + SMMUv3RegBank *bank =3D smmuv3_bank(s, SMMU_SEC_SID_NS); =20 /* Only migrate GBPA if it has different reset value. */ - return s->gbpa !=3D SMMU_GBPA_RESET_VAL; + return bank->gbpa !=3D SMMU_GBPA_RESET_VAL; } =20 static const VMStateDescription vmstate_gbpa =3D { @@ -2100,7 +2141,7 @@ static const VMStateDescription vmstate_gbpa =3D { .minimum_version_id =3D 1, .needed =3D smmuv3_gbpa_needed, .fields =3D (const VMStateField[]) { - VMSTATE_UINT32(gbpa, SMMUv3State), + VMSTATE_UINT32(bank[SMMU_SEC_SID_NS].gbpa, SMMUv3State), VMSTATE_END_OF_LIST() } }; @@ -2111,27 +2152,29 @@ static const VMStateDescription vmstate_smmuv3 =3D { .minimum_version_id =3D 1, .priority =3D MIG_PRI_IOMMU, .fields =3D (const VMStateField[]) { - VMSTATE_UINT32(features, SMMUv3State), + VMSTATE_UINT32(bank[SMMU_SEC_SID_NS].features, SMMUv3State), VMSTATE_UINT8(sid_size, SMMUv3State), - VMSTATE_UINT8(sid_split, SMMUv3State), + VMSTATE_UINT8(bank[SMMU_SEC_SID_NS].sid_split, SMMUv3State), =20 - VMSTATE_UINT32_ARRAY(cr, SMMUv3State, 3), - VMSTATE_UINT32(cr0ack, SMMUv3State), + VMSTATE_UINT32_ARRAY(bank[SMMU_SEC_SID_NS].cr, SMMUv3State, 3), + VMSTATE_UINT32(bank[SMMU_SEC_SID_NS].cr0ack, SMMUv3State), VMSTATE_UINT32(statusr, SMMUv3State), - VMSTATE_UINT32(irq_ctrl, SMMUv3State), - VMSTATE_UINT32(gerror, SMMUv3State), - VMSTATE_UINT32(gerrorn, SMMUv3State), - VMSTATE_UINT64(gerror_irq_cfg0, SMMUv3State), - VMSTATE_UINT32(gerror_irq_cfg1, SMMUv3State), - VMSTATE_UINT32(gerror_irq_cfg2, SMMUv3State), - VMSTATE_UINT64(strtab_base, SMMUv3State), - VMSTATE_UINT32(strtab_base_cfg, SMMUv3State), - VMSTATE_UINT64(eventq_irq_cfg0, SMMUv3State), - VMSTATE_UINT32(eventq_irq_cfg1, SMMUv3State), - VMSTATE_UINT32(eventq_irq_cfg2, SMMUv3State), - - VMSTATE_STRUCT(cmdq, SMMUv3State, 0, vmstate_smmuv3_queue, SMMUQue= ue), - VMSTATE_STRUCT(eventq, SMMUv3State, 0, vmstate_smmuv3_queue, SMMUQ= ueue), + VMSTATE_UINT32(bank[SMMU_SEC_SID_NS].irq_ctrl, SMMUv3State), + VMSTATE_UINT32(bank[SMMU_SEC_SID_NS].gerror, SMMUv3State), + VMSTATE_UINT32(bank[SMMU_SEC_SID_NS].gerrorn, SMMUv3State), + VMSTATE_UINT64(bank[SMMU_SEC_SID_NS].gerror_irq_cfg0, SMMUv3State), + VMSTATE_UINT32(bank[SMMU_SEC_SID_NS].gerror_irq_cfg1, SMMUv3State), + VMSTATE_UINT32(bank[SMMU_SEC_SID_NS].gerror_irq_cfg2, SMMUv3State), + VMSTATE_UINT64(bank[SMMU_SEC_SID_NS].strtab_base, SMMUv3State), + VMSTATE_UINT32(bank[SMMU_SEC_SID_NS].strtab_base_cfg, SMMUv3State), + VMSTATE_UINT64(bank[SMMU_SEC_SID_NS].eventq_irq_cfg0, SMMUv3State), + VMSTATE_UINT32(bank[SMMU_SEC_SID_NS].eventq_irq_cfg1, SMMUv3State), + VMSTATE_UINT32(bank[SMMU_SEC_SID_NS].eventq_irq_cfg2, SMMUv3State), + + VMSTATE_STRUCT(bank[SMMU_SEC_SID_NS].cmdq, SMMUv3State, 0, + vmstate_smmuv3_queue, SMMUQueue), + VMSTATE_STRUCT(bank[SMMU_SEC_SID_NS].eventq, SMMUv3State, 0, + vmstate_smmuv3_queue, SMMUQueue), =20 VMSTATE_END_OF_LIST(), }, diff --git a/hw/arm/tegra241-cmdqv.c b/hw/arm/tegra241-cmdqv.c index 57041408a7f..9897b2e85e7 100644 --- a/hw/arm/tegra241-cmdqv.c +++ b/hw/arm/tegra241-cmdqv.c @@ -976,6 +976,7 @@ static void tegra241_cmdqv_init_regs(SMMUv3State *s, Te= gra241CMDQV *cmdqv) int i; long pgsize; uint32_t val; + SMMUv3RegBank *bank =3D smmuv3_bank(s, SMMU_SEC_SID_NS); =20 cmdqv->config =3D V_CONFIG_RESET; cmdqv->param =3D FIELD_DP32(0, PARAM, CMDQV_VER, CMDQV_VER); @@ -1021,8 +1022,9 @@ static void tegra241_cmdqv_init_regs(SMMUv3State *s, = Tegra241CMDQV *cmdqv) if (pgsize =3D=3D LONG_MAX) { pgsize =3D qemu_real_host_page_size(); } - val =3D FIELD_EX32(s->idr[1], IDR1, CMDQS); - s->idr[1] =3D FIELD_DP32(s->idr[1], IDR1, CMDQS, MIN(ctz64(pgsize) - 4= , val)); + val =3D FIELD_EX32(bank->idr[1], IDR1, CMDQS); + bank->idr[1] =3D FIELD_DP32(bank->idr[1], IDR1, CMDQS, + MIN(ctz64(pgsize) - 4, val)); } =20 static void tegra241_cmdqv_reset(SMMUv3State *s) --=20 2.34.1 From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794672861954439.7205876294249; Sat, 14 Nov 2026 08:14:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGNn-0008Dz-HG; Sat, 14 Nov 2026 11:13:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGNk-00085c-5A; Sat, 14 Nov 2026 11:13:36 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGNi-0000f7-49; Sat, 14 Nov 2026 11:13:35 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-7 (Coremail) with UTF8SMTP id AQAAfwCXnMCriPhqZEgqBg--.55613S2; Sun, 15 Nov 2026 00:13:31 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8DwWnSqiPhqsdv6AA--.38452S3; Sun, 15 Nov 2026 00:13:30 +0800 (CST) From: Tao Tang To: Peter Maydell , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 03/35] hw/arm/smmuv3: Thread SEC_SID through helper APIs Date: Sun, 15 Nov 2026 00:13:29 +0800 Message-Id: <20261114161329.3639254-1-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8DwWnSqiPhqsdv6AA--.38452S3 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBYAABsE Authentication-Results: hzbj-icmmx-7; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvJXoW3XrWkurWkAry5XF45ZFWkZwb_yoWxGw4xpw 4DJ3Z5KryUtFyFgFW7Jw48A3W3Xw4fKFnxJrn8Ga93C3WUAr15Xr1kG345KF9F9ry8Ca1a v3ySgF48uw42yrJanT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAU7a7-sFnT9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUU UUUUU Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794672866260154100 Extend the register and queue helper routines to accept an explicit SEC_SID argument instead of hard-coding the Non-secure bank. All existing callers are updated to pass SMMU_SEC_SID_NS, so the behavior remains identical. This prepares the code for handling additional security state banks in the future. So Non-secure state is the only state bank supported for now. Signed-off-by: Tao Tang Reviewed-by: Eric Auger Reviewed-by: Pierrick Bouvier Link: https://lore.kernel.org/qemu-devel/3097d58e-3793-4434-8beb-2e4f4c52f7= 72@redhat.com/ Reviewed-by: Jim MacArthur Reviewed-by: Mostafa Saleh --- hw/arm/smmuv3-internal.h | 21 +++++++++------------ hw/arm/smmuv3-accel.c | 4 ++-- hw/arm/smmuv3.c | 15 ++++++++------- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/hw/arm/smmuv3-internal.h b/hw/arm/smmuv3-internal.h index 10154ca161d..a88743ba9cd 100644 --- a/hw/arm/smmuv3-internal.h +++ b/hw/arm/smmuv3-internal.h @@ -39,9 +39,8 @@ typedef enum SMMUTranslationClass { SMMU_CLASS_IN, } SMMUTranslationClass; =20 -static inline int smmu_enabled(SMMUv3State *s) +static inline int smmu_enabled(SMMUv3State *s, SMMUSecSID sec_sid) { - SMMUSecSID sec_sid =3D SMMU_SEC_SID_NS; SMMUv3RegBank *bank =3D smmuv3_bank(s, sec_sid); return FIELD_EX32(bank->cr[0], CR0, SMMUEN); } @@ -69,16 +68,16 @@ static inline uint32_t smmuv3_idreg(int regoffset) return smmuv3_ids[regoffset / 4]; } =20 -static inline bool smmuv3_eventq_irq_enabled(SMMUv3State *s) +static inline bool smmuv3_eventq_irq_enabled(SMMUv3State *s, + SMMUSecSID sec_sid) { - SMMUSecSID sec_sid =3D SMMU_SEC_SID_NS; SMMUv3RegBank *bank =3D smmuv3_bank(s, sec_sid); return FIELD_EX32(bank->irq_ctrl, IRQ_CTRL, EVENTQ_IRQEN); } =20 -static inline bool smmuv3_gerror_irq_enabled(SMMUv3State *s) +static inline bool smmuv3_gerror_irq_enabled(SMMUv3State *s, + SMMUSecSID sec_sid) { - SMMUSecSID sec_sid =3D SMMU_SEC_SID_NS; SMMUv3RegBank *bank =3D smmuv3_bank(s, sec_sid); return FIELD_EX32(bank->irq_ctrl, IRQ_CTRL, GERROR_IRQEN); } @@ -123,23 +122,21 @@ static inline void queue_cons_incr(SMMUQueue *q) q->cons =3D deposit32(q->cons, 0, q->log2size + 1, q->cons + 1); } =20 -static inline bool smmuv3_cmdq_enabled(SMMUv3State *s) +static inline bool smmuv3_cmdq_enabled(SMMUv3State *s, SMMUSecSID sec_sid) { - SMMUSecSID sec_sid =3D SMMU_SEC_SID_NS; SMMUv3RegBank *bank =3D smmuv3_bank(s, sec_sid); return FIELD_EX32(bank->cr[0], CR0, CMDQEN); } =20 -static inline bool smmuv3_eventq_enabled(SMMUv3State *s) +static inline bool smmuv3_eventq_enabled(SMMUv3State *s, SMMUSecSID sec_si= d) { - SMMUSecSID sec_sid =3D SMMU_SEC_SID_NS; SMMUv3RegBank *bank =3D smmuv3_bank(s, sec_sid); return FIELD_EX32(bank->cr[0], CR0, EVENTQEN); } =20 -static inline void smmu_write_cmdq_err(SMMUv3State *s, uint32_t err_type) +static inline void smmu_write_cmdq_err(SMMUv3State *s, uint32_t err_type, + SMMUSecSID sec_sid) { - SMMUSecSID sec_sid =3D SMMU_SEC_SID_NS; SMMUv3RegBank *bank =3D smmuv3_bank(s, sec_sid); bank->cmdq.cons =3D FIELD_DP32(bank->cmdq.cons, CMDQ_CONS, ERR, err_ty= pe); } diff --git a/hw/arm/smmuv3-accel.c b/hw/arm/smmuv3-accel.c index 91df3362215..84d6718173c 100644 --- a/hw/arm/smmuv3-accel.c +++ b/hw/arm/smmuv3-accel.c @@ -323,7 +323,7 @@ bool smmuv3_accel_install_ste(SMMUv3State *s, SMMUDevic= e *sdev, int sid, * attach/alloc fails, since the Guest=E2=80=93Host SID mapping stays * valid as long as the device is behind the accelerated SMMUv3. */ - if (!smmu_enabled(s)) { + if (!smmu_enabled(s, SMMU_SEC_SID_NS)) { hwpt_id =3D smmuv3_accel_gbpa_hwpt(s, accel); } else { config =3D STE_CONFIG(&ste); @@ -558,7 +558,7 @@ bool smmuv3_accel_alloc_veventq(SMMUv3State *s, Error *= *errp) return true; } =20 - if (!smmuv3_eventq_enabled(s)) { + if (!smmuv3_eventq_enabled(s, sec_sid)) { return true; } =20 diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 3198fcd9eeb..249ffaee4d4 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -60,7 +60,7 @@ static void smmuv3_trigger_irq(SMMUv3State *s, SMMUIrq ir= q, =20 switch (irq) { case SMMU_IRQ_EVTQ: - pulse =3D smmuv3_eventq_irq_enabled(s); + pulse =3D smmuv3_eventq_irq_enabled(s, sec_sid); break; case SMMU_IRQ_PRIQ: qemu_log_mask(LOG_UNIMP, "PRI not yet supported\n"); @@ -80,7 +80,7 @@ static void smmuv3_trigger_irq(SMMUv3State *s, SMMUIrq ir= q, bank->gerror ^=3D new_gerrors; trace_smmuv3_write_gerror(new_gerrors, bank->gerror); =20 - pulse =3D smmuv3_gerror_irq_enabled(s); + pulse =3D smmuv3_gerror_irq_enabled(s, sec_sid); break; } } @@ -156,7 +156,7 @@ static MemTxResult smmuv3_write_eventq(SMMUv3State *s, = Evt *evt) SMMUQueue *q =3D &bank->eventq; MemTxResult r; =20 - if (!smmuv3_eventq_enabled(s)) { + if (!smmuv3_eventq_enabled(s, sec_sid)) { return MEMTX_ERROR; } =20 @@ -191,8 +191,9 @@ void smmuv3_propagate_event(SMMUv3State *s, Evt *evt) void smmuv3_record_event(SMMUv3State *s, SMMUEventInfo *info) { Evt evt =3D {}; + SMMUSecSID sec_sid =3D SMMU_SEC_SID_NS; =20 - if (!smmuv3_eventq_enabled(s)) { + if (!smmuv3_eventq_enabled(s, sec_sid)) { return; } =20 @@ -1126,7 +1127,7 @@ static IOMMUTLBEntry smmuv3_translate(IOMMUMemoryRegi= on *mr, hwaddr addr, =20 qemu_mutex_lock(&s->mutex); =20 - if (!smmu_enabled(s)) { + if (!smmu_enabled(s, sec_sid)) { if (FIELD_EX32(bank->gbpa, GBPA, ABORT)) { status =3D SMMU_TRANS_ABORT; } else { @@ -1356,7 +1357,7 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error = **errp) SMMUQueue *q =3D &bank->cmdq; SMMUCommandType type =3D 0; =20 - if (!smmuv3_cmdq_enabled(s)) { + if (!smmuv3_cmdq_enabled(s, sec_sid)) { return 0; } /* @@ -1616,7 +1617,7 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error = **errp) =20 if (cmd_error) { trace_smmuv3_cmdq_consume_error(smmu_cmd_string(type), cmd_error); - smmu_write_cmdq_err(s, cmd_error); + smmu_write_cmdq_err(s, cmd_error, sec_sid); smmuv3_trigger_irq(s, SMMU_IRQ_GERROR, R_GERROR_CMDQ_ERR_MASK); } =20 --=20 2.34.1 From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794672898028844.7101450948518; Sat, 14 Nov 2026 08:14:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGO7-0000Hc-Jx; Sat, 14 Nov 2026 11:13:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGO5-0000Bx-C1; Sat, 14 Nov 2026 11:13:57 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGO1-0001rN-Jv; Sat, 14 Nov 2026 11:13:56 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-7 (Coremail) with UTF8SMTP id AQAAfwAnXaW9iPhqXEkqBg--.18797S2; Sun, 15 Nov 2026 00:13:49 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8Dw9XK7iPhquNv6AA--.41302S3; Sun, 15 Nov 2026 00:13:48 +0800 (CST) From: Tao Tang To: Peter Maydell , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 04/35] hw/arm/smmuv3: Track SEC_SID in configs and events Date: Sun, 15 Nov 2026 00:13:47 +0800 Message-Id: <20261114161347.3639710-1-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8Dw9XK7iPhquNv6AA--.41302S3 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBYwAAsG Authentication-Results: hzbj-icmmx-7; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvJXoW3GF45JFW3CF4Dur4xGrWrAFb_yoW3Xryfpw 1DGrn8Kr1DtF1fZF13Xa18A3W3Xw48KrnxtryqgFyrAw4DAry7XF4DGw1Ykr909rWjva9F vayIgF43u347ArJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAU7a7-sFnT9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUU UUUUU Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794672902197154100 Content-Type: text/plain; charset="utf-8" Pass the SEC_SID explicitly to smmuv3_decode_config() so configuration decoding can be tied to the correct register bank. Plumb the SEC_SID through tracepoints and queue helpers so diagnostics and event logs always show which security interface emitted the record. To support this, the SEC_SID is placed in SMMUEventInfo so the bank is identified as soon as an event record is built. Signed-off-by: Tao Tang Reviewed-by: Eric Auger Reviewed-by: Pierrick Bouvier Reviewed-by: Jim MacArthur Reviewed-by: Mostafa Saleh --- hw/arm/smmuv3-internal.h | 3 ++- include/hw/arm/smmuv3.h | 1 + hw/arm/smmuv3-accel.c | 2 +- hw/arm/smmuv3.c | 26 +++++++++++++++----------- hw/arm/trace-events | 2 +- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/hw/arm/smmuv3-internal.h b/hw/arm/smmuv3-internal.h index a88743ba9cd..202cd533636 100644 --- a/hw/arm/smmuv3-internal.h +++ b/hw/arm/smmuv3-internal.h @@ -274,6 +274,7 @@ static inline const char *smmu_event_string(SMMUEventTy= pe type) =20 /* Encode an event record */ typedef struct SMMUEventInfo { + SMMUSecSID sec_sid; SMMUEventType type; uint32_t sid; bool recorded; @@ -365,7 +366,7 @@ typedef struct SMMUEventInfo { #define EVT_GET_SID(x) ((x)->word[1]) =20 void smmuv3_record_event(SMMUv3State *s, SMMUEventInfo *event); -void smmuv3_propagate_event(SMMUv3State *s, Evt *evt); +void smmuv3_propagate_event(SMMUv3State *s, Evt *evt, SMMUSecSID sec_sid); int smmu_find_ste(SMMUv3State *s, uint32_t sid, STE *ste, SMMUEventInfo *e= vent); =20 #define STE_SIZE 6 diff --git a/include/hw/arm/smmuv3.h b/include/hw/arm/smmuv3.h index 45033d26a1b..8cd2edc3412 100644 --- a/include/hw/arm/smmuv3.h +++ b/include/hw/arm/smmuv3.h @@ -115,6 +115,7 @@ OBJECT_DECLARE_TYPE(SMMUv3State, SMMUv3Class, ARM_SMMUV= 3) =20 static inline SMMUv3RegBank *smmuv3_bank(SMMUv3State *s, SMMUSecSID sec_si= d) { + g_assert(sec_sid < SMMU_SEC_SID_NUM); return &s->bank[sec_sid]; } =20 diff --git a/hw/arm/smmuv3-accel.c b/hw/arm/smmuv3-accel.c index 84d6718173c..e66f4970562 100644 --- a/hw/arm/smmuv3-accel.c +++ b/hw/arm/smmuv3-accel.c @@ -508,7 +508,7 @@ static void smmuv3_accel_event_read(void *opaque) if (ret > 0) { return; /* EAGAIN/EINTR */ } - smmuv3_propagate_event(s, (Evt *)&buf.vevent); + smmuv3_propagate_event(s, (Evt *)&buf.vevent, SMMU_SEC_SID_NS); } =20 static void smmuv3_accel_free_veventq(SMMUv3AccelState *accel) diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 249ffaee4d4..39b1014fd31 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -149,9 +149,9 @@ static MemTxResult queue_write(SMMUQueue *q, Evt *evt_i= n) return MEMTX_OK; } =20 -static MemTxResult smmuv3_write_eventq(SMMUv3State *s, Evt *evt) +static MemTxResult smmuv3_write_eventq(SMMUv3State *s, SMMUSecSID sec_sid, + Evt *evt) { - SMMUSecSID sec_sid =3D SMMU_SEC_SID_NS; SMMUv3RegBank *bank =3D smmuv3_bank(s, sec_sid); SMMUQueue *q =3D &bank->eventq; MemTxResult r; @@ -175,14 +175,14 @@ static MemTxResult smmuv3_write_eventq(SMMUv3State *s= , Evt *evt) return MEMTX_OK; } =20 -void smmuv3_propagate_event(SMMUv3State *s, Evt *evt) +void smmuv3_propagate_event(SMMUv3State *s, Evt *evt, SMMUSecSID sec_sid) { MemTxResult r; =20 - trace_smmuv3_propagate_event(smmu_event_string(EVT_GET_TYPE(evt)), + trace_smmuv3_propagate_event(sec_sid, smmu_event_string(EVT_GET_TYPE(e= vt)), EVT_GET_SID(evt)); QEMU_LOCK_GUARD(&s->mutex); - r =3D smmuv3_write_eventq(s, evt); + r =3D smmuv3_write_eventq(s, sec_sid, evt); if (r !=3D MEMTX_OK) { smmuv3_trigger_irq(s, SMMU_IRQ_GERROR, R_GERROR_EVENTQ_ABT_ERR_MAS= K); } @@ -191,7 +191,7 @@ void smmuv3_propagate_event(SMMUv3State *s, Evt *evt) void smmuv3_record_event(SMMUv3State *s, SMMUEventInfo *info) { Evt evt =3D {}; - SMMUSecSID sec_sid =3D SMMU_SEC_SID_NS; + SMMUSecSID sec_sid =3D info->sec_sid; =20 if (!smmuv3_eventq_enabled(s, sec_sid)) { return; @@ -271,7 +271,7 @@ void smmuv3_record_event(SMMUv3State *s, SMMUEventInfo = *info) g_assert_not_reached(); } =20 - smmuv3_propagate_event(s, &evt); + smmuv3_propagate_event(s, &evt, sec_sid); info->recorded =3D true; } =20 @@ -885,12 +885,13 @@ bad_cd: * @cfg: output translation configuration which is populated through * the different configuration decoding steps * @event: must be zero'ed by the caller + * @sec_sid: StreamID Security state * * return < 0 in case of config decoding error (@event is filled * accordingly). Return 0 otherwise. */ static int smmuv3_decode_config(IOMMUMemoryRegion *mr, SMMUTransCfg *cfg, - SMMUEventInfo *event) + SMMUEventInfo *event, SMMUSecSID sec_sid) { SMMUDevice *sdev =3D container_of(mr, SMMUDevice, iommu); uint32_t sid =3D smmu_get_sid(sdev); @@ -957,7 +958,7 @@ static SMMUTransCfg *smmuv3_get_config(SMMUDevice *sdev= , SMMUEventInfo *event) (sdev->cfg_cache_hits + sdev->cfg_cache_misses= )); cfg =3D g_new0(SMMUTransCfg, 1); =20 - if (!smmuv3_decode_config(&sdev->iommu, cfg, event)) { + if (!smmuv3_decode_config(&sdev->iommu, cfg, event, SMMU_SEC_SID_N= S)) { g_hash_table_insert(bc->configs, sdev, cfg); } else { g_free(cfg); @@ -1113,7 +1114,8 @@ static IOMMUTLBEntry smmuv3_translate(IOMMUMemoryRegi= on *mr, hwaddr addr, SMMUv3RegBank *bank =3D smmuv3_bank(s, sec_sid); SMMUEventInfo event =3D {.type =3D SMMU_EVT_NONE, .sid =3D sid, - .inval_ste_allowed =3D false}; + .inval_ste_allowed =3D false, + .sec_sid =3D sec_sid}; SMMUTranslationStatus status; SMMUTransCfg *cfg =3D NULL; IOMMUTLBEntry entry =3D { @@ -1215,7 +1217,9 @@ static void smmuv3_notify_iova(IOMMUMemoryRegion *mr, uint64_t num_pages, int stage) { SMMUDevice *sdev =3D container_of(mr, SMMUDevice, iommu); - SMMUEventInfo eventinfo =3D {.inval_ste_allowed =3D true}; + SMMUSecSID sec_sid =3D SMMU_SEC_SID_NS; + SMMUEventInfo eventinfo =3D {.sec_sid =3D sec_sid, + .inval_ste_allowed =3D true}; SMMUTransCfg *cfg =3D smmuv3_get_config(sdev, &eventinfo); IOMMUTLBEvent event; uint8_t granule; diff --git a/hw/arm/trace-events b/hw/arm/trace-events index 579d4b12c21..50fe4af07c5 100644 --- a/hw/arm/trace-events +++ b/hw/arm/trace-events @@ -41,7 +41,7 @@ smmuv3_cmdq_opcode(const char *opcode) "<--- %s" smmuv3_cmdq_consume_out(uint32_t prod, uint32_t cons, uint8_t prod_wrap, u= int8_t cons_wrap) "prod:%d, cons:%d, prod_wrap:%d, cons_wrap:%d " smmuv3_cmdq_consume_error(const char *cmd_name, uint8_t cmd_error) "Error = on %s command execution: %d" smmuv3_write_mmio(uint64_t addr, uint64_t val, unsigned size, uint32_t r) = "addr: 0x%"PRIx64" val:0x%"PRIx64" size: 0x%x(%d)" -smmuv3_propagate_event(const char *type, uint32_t sid) "%s sid=3D0x%x" +smmuv3_propagate_event(int sec_sid, const char *type, uint32_t sid) "sec_s= id=3D%d %s sid=3D0x%x" smmuv3_find_ste(uint16_t sid, uint32_t features, uint16_t sid_split) "sid= =3D0x%x features:0x%x, sid_split:0x%x" smmuv3_find_ste_2lvl(uint64_t strtab_base, uint64_t l1ptr, int l1_ste_offs= et, uint64_t l2ptr, int l2_ste_offset, int max_l2_ste) "strtab_base:0x%"PRI= x64" l1ptr:0x%"PRIx64" l1_off:0x%x, l2ptr:0x%"PRIx64" l2_off:0x%x max_l2_st= e:%d" smmuv3_get_ste(uint64_t addr) "STE addr: 0x%"PRIx64 --=20 2.34.1 From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794672873760443.82786457607483; Sat, 14 Nov 2026 08:14:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGOB-0000MK-TY; Sat, 14 Nov 2026 11:14:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGO7-0000HZ-1b; Sat, 14 Nov 2026 11:13:59 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGO5-0002Fv-G9; Sat, 14 Nov 2026 11:13:58 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-7 (Coremail) with UTF8SMTP id AQAAfwAHD5_CiPhq7kkqBg--.42919S2; Sun, 15 Nov 2026 00:13:54 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8DwR3bAiPhqudv6AA--.34439S3; Sun, 15 Nov 2026 00:13:52 +0800 (CST) From: Tao Tang To: Peter Maydell , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 05/35] hw/arm/smmu-common: Add security-aware address space selector Date: Sun, 15 Nov 2026 00:13:51 +0800 Message-Id: <20261114161351.3639925-1-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8DwR3bAiPhqudv6AA--.34439S3 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBZQAAsA Authentication-Results: hzbj-icmmx-7; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvJXoW7try7XFW3Ary5WF1DWw4UArb_yoW8ZFWxpa n7Cr95JrykKF1I9r93Xr4avFy5Wws3Gr1UJry29FyDuw17tr1fAr1UKw1YkrZrCrsYqr43 uFWxZFs5W3W5trJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAU7a7-sFnT9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUU UUUUU Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794672875939154100 Content-Type: text/plain; charset="utf-8" Introduce SMMU_SEC_SID_S to represent SEC_SID =3D=3D 1, meaning Secure. And then provide smmu_get_address_space, a SMMU instance-based address space selector. The helper returns the per-device memory or secure-memory AddressSpace selected by SEC_SID. Signed-off-by: Tao Tang Reviewed-by: Pierrick Bouvier Reviewed-by: Eric Auger Reviewed-by: Mostafa Saleh --- include/hw/arm/smmu-common.h | 3 +++ hw/arm/smmu-common.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/hw/arm/smmu-common.h b/include/hw/arm/smmu-common.h index 6ea40f6b074..9d6e2d3038f 100644 --- a/include/hw/arm/smmu-common.h +++ b/include/hw/arm/smmu-common.h @@ -43,6 +43,7 @@ /* StreamID Security state */ typedef enum SMMUSecSID { SMMU_SEC_SID_NS =3D 0, + SMMU_SEC_SID_S, SMMU_SEC_SID_NUM, } SMMUSecSID; =20 @@ -188,6 +189,8 @@ struct SMMUBaseClass { #define TYPE_ARM_SMMU "arm-smmu" OBJECT_DECLARE_TYPE(SMMUState, SMMUBaseClass, ARM_SMMU) =20 +AddressSpace *smmu_get_address_space(SMMUState *s, SMMUSecSID sec_sid); + /* Return the SMMUPciBus handle associated to a PCI bus number */ SMMUPciBus *smmu_find_smmu_pcibus(SMMUState *s, uint8_t bus_num); =20 diff --git a/hw/arm/smmu-common.c b/hw/arm/smmu-common.c index 8e40ba603d3..95ef9f50a23 100644 --- a/hw/arm/smmu-common.c +++ b/hw/arm/smmu-common.c @@ -30,6 +30,20 @@ #include "hw/arm/smmu-common.h" #include "smmu-internal.h" =20 +AddressSpace *smmu_get_address_space(SMMUState *s, SMMUSecSID sec_sid) +{ + switch (sec_sid) { + case SMMU_SEC_SID_NS: + return &s->memory_as; + case SMMU_SEC_SID_S: + g_assert(s->secure_memory); + return &s->secure_memory_as; + case SMMU_SEC_SID_NUM: + g_assert_not_reached(); + } + g_assert_not_reached(); +} + /* IOTLB Management */ =20 static guint smmu_iotlb_key_hash(gconstpointer v) --=20 2.34.1 From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794673003708311.96442378411564; Sat, 14 Nov 2026 08:16:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGQW-0004fw-Pz; Sat, 14 Nov 2026 11:16:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGQN-0004bE-OH; Sat, 14 Nov 2026 11:16:20 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGQL-0003A6-NX; Sat, 14 Nov 2026 11:16:19 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-6 (Coremail) with UTF8SMTP id AQAAfwC3mX5OifhqlRkGAg--.41929S2; Sun, 15 Nov 2026 00:16:14 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8DwR3ZLifhq0dv6AA--.34441S3; Sun, 15 Nov 2026 00:16:11 +0800 (CST) From: Tao Tang To: Peter Maydell , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 06/35] hw/arm/smmuv3: Plumb transaction attributes into config helpers Date: Sun, 15 Nov 2026 00:16:10 +0800 Message-Id: <20261114161610.3642721-1-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8DwR3ZLifhq0dv6AA--.34441S3 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBaQAAsM Authentication-Results: hzbj-icmmx-6; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvJXoWfGr4kAryDJr43JFyfuF1ftFb_yoWDuF47pr 47GF98Kw4rKFyfZF9xXF4Uu3W5X39agFs8GryDKF9Ykw1UAr1xZr1DK345CryDury8JFsr ZayIgF45ur17ArJanT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAU7a7-sFnT9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUU UUUUU Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794673005693154100 Content-Type: text/plain; charset="utf-8" Introduce helpers that derive MemTxAttrs and select an AddressSpace from SEC_SID, then pass SEC_SID through the Stream Table and Context Descriptor fetch paths. This makes reads of SMMU configuration structures use the corresponding Non-secure or Secure memory context. To support these helpers, include hw/arm/arm-security.h from smmu-common.h, making the Arm security-space definitions available to the common SMMU code. The accelerated path remains Non-secure-only and therefore passes SMMU_SEC_SID_NS explicitly. For now, the configuration cache lookup key remains based solely on the SMMUDevice pointer. It is extended with SEC_SID in a later commit. Other SEC_SID-sensitive memory accesses that still use the Non-secure address space are converted in follow-up commits. Signed-off-by: Tao Tang Reviewed-by: Pierrick Bouvier --- hw/arm/smmuv3-internal.h | 3 ++- include/hw/arm/smmu-common.h | 10 +++++++++ hw/arm/smmu-common.c | 27 ++++++++++++++++++++++ hw/arm/smmuv3-accel.c | 2 +- hw/arm/smmuv3.c | 43 ++++++++++++++++++++++-------------- 5 files changed, 66 insertions(+), 19 deletions(-) diff --git a/hw/arm/smmuv3-internal.h b/hw/arm/smmuv3-internal.h index 202cd533636..1f2f426da01 100644 --- a/hw/arm/smmuv3-internal.h +++ b/hw/arm/smmuv3-internal.h @@ -367,7 +367,8 @@ typedef struct SMMUEventInfo { =20 void smmuv3_record_event(SMMUv3State *s, SMMUEventInfo *event); void smmuv3_propagate_event(SMMUv3State *s, Evt *evt, SMMUSecSID sec_sid); -int smmu_find_ste(SMMUv3State *s, uint32_t sid, STE *ste, SMMUEventInfo *e= vent); +int smmu_find_ste(SMMUv3State *s, uint32_t sid, STE *ste, SMMUEventInfo *e= vent, + SMMUSecSID sec_sid); =20 #define STE_SIZE 6 #define L1STD_SIZE 3 diff --git a/include/hw/arm/smmu-common.h b/include/hw/arm/smmu-common.h index 9d6e2d3038f..a31ffcf6e71 100644 --- a/include/hw/arm/smmu-common.h +++ b/include/hw/arm/smmu-common.h @@ -22,6 +22,7 @@ #include "hw/core/sysbus.h" #include "hw/pci/pci.h" #include "qom/object.h" +#include "hw/arm/arm-security.h" =20 #define SMMU_PCI_BUS_MAX 256 #define SMMU_PCI_DEVFN_MAX 256 @@ -47,6 +48,9 @@ typedef enum SMMUSecSID { SMMU_SEC_SID_NUM, } SMMUSecSID; =20 +MemTxAttrs smmu_get_txattrs(SMMUSecSID sec_sid); +ARMSecuritySpace smmu_get_security_space(SMMUSecSID sec_sid); + /* * Page table walk error types */ @@ -200,6 +204,12 @@ SMMUPciBus *smmu_get_sbus(SMMUState *s, PCIBus *bus); /* Initialize SMMUDevice handle associated to a SMMUPciBus */ void smmu_init_sdev(SMMUState *s, SMMUDevice *sdev, PCIBus *bus, int devfn= ); =20 + +static inline bool smmu_sec_sid_is_secure(SMMUSecSID sec_sid) +{ + return sec_sid =3D=3D SMMU_SEC_SID_S; +} + /* Return the stream ID of an SMMU device */ static inline uint16_t smmu_get_sid(SMMUDevice *sdev) { diff --git a/hw/arm/smmu-common.c b/hw/arm/smmu-common.c index 95ef9f50a23..baa1ff571fa 100644 --- a/hw/arm/smmu-common.c +++ b/hw/arm/smmu-common.c @@ -30,6 +30,33 @@ #include "hw/arm/smmu-common.h" #include "smmu-internal.h" =20 +ARMSecuritySpace smmu_get_security_space(SMMUSecSID sec_sid) +{ + switch (sec_sid) { + case SMMU_SEC_SID_S: + return ARMSS_Secure; + case SMMU_SEC_SID_NS: + return ARMSS_NonSecure; + case SMMU_SEC_SID_NUM: + g_assert_not_reached(); + } + g_assert_not_reached(); +} + +MemTxAttrs smmu_get_txattrs(SMMUSecSID sec_sid) +{ + /* + * SMMU-originated accesses do not inherit the client requester ID, PA= SID + * or PCI address type. Only the security state is explicit here. Leave + * memory clear to preserve access behavior: it is a RAM-only filter, + * not an architectural memory type or cacheability attribute. + */ + return (MemTxAttrs) { + .secure =3D smmu_sec_sid_is_secure(sec_sid) ? 1 : 0, + .space =3D smmu_get_security_space(sec_sid), + }; +} + AddressSpace *smmu_get_address_space(SMMUState *s, SMMUSecSID sec_sid) { switch (sec_sid) { diff --git a/hw/arm/smmuv3-accel.c b/hw/arm/smmuv3-accel.c index e66f4970562..6fac9420cdf 100644 --- a/hw/arm/smmuv3-accel.c +++ b/hw/arm/smmuv3-accel.c @@ -309,7 +309,7 @@ bool smmuv3_accel_install_ste(SMMUv3State *s, SMMUDevic= e *sdev, int sid, return false; } =20 - if (smmu_find_ste(sdev->smmu, sid, &ste, &event)) { + if (smmu_find_ste(sdev->smmu, sid, &ste, &event, SMMU_SEC_SID_NS)) { /* No STE found, nothing to install */ return true; } diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 39b1014fd31..06684f07242 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -365,14 +365,15 @@ static void smmuv3_reset(SMMUv3State *s) } =20 static int smmu_get_ste(SMMUv3State *s, dma_addr_t addr, STE *buf, - SMMUEventInfo *event) + SMMUEventInfo *event, SMMUSecSID sec_sid) { + AddressSpace *as =3D smmu_get_address_space(ARM_SMMU(s), sec_sid); + MemTxAttrs txattrs =3D smmu_get_txattrs(sec_sid); int ret, i; =20 trace_smmuv3_get_ste(addr); /* TODO: guarantee 64-bit single-copy atomicity */ - ret =3D dma_memory_read(&address_space_memory, addr, buf, sizeof(*buf), - MEMTXATTRS_UNSPECIFIED); + ret =3D dma_memory_read(as, addr, buf, sizeof(*buf), txattrs); if (ret !=3D MEMTX_OK) { qemu_log_mask(LOG_GUEST_ERROR, "Cannot fetch pte at address=3D0x%"PRIx64"\n", addr); @@ -395,12 +396,15 @@ static SMMUTranslationStatus smmuv3_do_translate(SMMU= v3State *s, hwaddr addr, SMMUTranslationClass clas= s); /* @ssid > 0 not supported yet */ static int smmu_get_cd(SMMUv3State *s, STE *ste, SMMUTransCfg *cfg, - uint32_t ssid, CD *buf, SMMUEventInfo *event) + uint32_t ssid, CD *buf, SMMUEventInfo *event, + SMMUSecSID sec_sid) { dma_addr_t addr =3D STE_CTXPTR(ste); int ret, i; SMMUTranslationStatus status; SMMUTLBEntry *entry; + AddressSpace *as; + MemTxAttrs txattrs; =20 trace_smmuv3_get_cd(addr); =20 @@ -416,9 +420,10 @@ static int smmu_get_cd(SMMUv3State *s, STE *ste, SMMUT= ransCfg *cfg, addr =3D CACHED_ENTRY_TO_ADDR(entry, addr); } =20 + as =3D smmu_get_address_space(ARM_SMMU(s), sec_sid); + txattrs =3D smmu_get_txattrs(sec_sid); /* TODO: guarantee 64-bit single-copy atomicity */ - ret =3D dma_memory_read(&address_space_memory, addr, buf, sizeof(*buf), - MEMTXATTRS_UNSPECIFIED); + ret =3D dma_memory_read(as, addr, buf, sizeof(*buf), txattrs); if (ret !=3D MEMTX_OK) { qemu_log_mask(LOG_GUEST_ERROR, "Cannot fetch pte at address=3D0x%"PRIx64"\n", addr); @@ -679,18 +684,21 @@ bad_ste: * @sid: stream ID * @ste: returned stream table entry * @event: handle to an event info + * @sec_sid: StreamID Security state * * Supports linear and 2-level stream table * Return 0 on success, -EINVAL otherwise */ -int smmu_find_ste(SMMUv3State *s, uint32_t sid, STE *ste, SMMUEventInfo *e= vent) +int smmu_find_ste(SMMUv3State *s, uint32_t sid, STE *ste, SMMUEventInfo *e= vent, + SMMUSecSID sec_sid) { dma_addr_t addr, strtab_base; uint32_t log2size; int strtab_size; int ret; - SMMUSecSID sec_sid =3D SMMU_SEC_SID_NS; SMMUv3RegBank *bank =3D smmuv3_bank(s, sec_sid); + AddressSpace *as =3D smmu_get_address_space(ARM_SMMU(s), sec_sid); + MemTxAttrs txattrs =3D smmu_get_txattrs(sec_sid); =20 trace_smmuv3_find_ste(sid, bank->features, bank->sid_split); log2size =3D FIELD_EX32(bank->strtab_base_cfg, STRTAB_BASE_CFG, LOG2SI= ZE); @@ -717,8 +725,7 @@ int smmu_find_ste(SMMUv3State *s, uint32_t sid, STE *st= e, SMMUEventInfo *event) l2_ste_offset =3D sid & ((1 << bank->sid_split) - 1); l1ptr =3D (dma_addr_t)(strtab_base + l1_ste_offset * sizeof(l1std)= ); /* TODO: guarantee 64-bit single-copy atomicity */ - ret =3D dma_memory_read(&address_space_memory, l1ptr, &l1std, - sizeof(l1std), MEMTXATTRS_UNSPECIFIED); + ret =3D dma_memory_read(as, l1ptr, &l1std, sizeof(l1std), txattrs); if (ret !=3D MEMTX_OK) { qemu_log_mask(LOG_GUEST_ERROR, "Could not read L1PTR at 0X%"PRIx64"\n", l1ptr); @@ -772,7 +779,7 @@ int smmu_find_ste(SMMUv3State *s, uint32_t sid, STE *st= e, SMMUEventInfo *event) addr =3D strtab_base + sid * sizeof(*ste); } =20 - if (smmu_get_ste(s, addr, ste, event)) { + if (smmu_get_ste(s, addr, ste, event, sec_sid)) { return -EINVAL; } =20 @@ -903,7 +910,7 @@ static int smmuv3_decode_config(IOMMUMemoryRegion *mr, = SMMUTransCfg *cfg, /* ASID defaults to -1 (if s1 is not supported). */ cfg->asid =3D -1; =20 - ret =3D smmu_find_ste(s, sid, &ste, event); + ret =3D smmu_find_ste(s, sid, &ste, event, sec_sid); if (ret) { return ret; } @@ -917,7 +924,7 @@ static int smmuv3_decode_config(IOMMUMemoryRegion *mr, = SMMUTransCfg *cfg, return 0; } =20 - ret =3D smmu_get_cd(s, &ste, cfg, 0 /* ssid */, &cd, event); + ret =3D smmu_get_cd(s, &ste, cfg, 0 /* ssid */, &cd, event, sec_sid); if (ret) { return ret; } @@ -932,12 +939,14 @@ static int smmuv3_decode_config(IOMMUMemoryRegion *mr= , SMMUTransCfg *cfg, * * @sdev: SMMUDevice handle * @event: output event info + * @sec_sid: StreamID Security state * * The configuration cache contains data resulting from both STE and CD * decoding under the form of an SMMUTransCfg struct. The hash table is in= dexed * by the SMMUDevice handle. */ -static SMMUTransCfg *smmuv3_get_config(SMMUDevice *sdev, SMMUEventInfo *ev= ent) +static SMMUTransCfg *smmuv3_get_config(SMMUDevice *sdev, SMMUEventInfo *ev= ent, + SMMUSecSID sec_sid) { SMMUv3State *s =3D sdev->smmu; SMMUState *bc =3D &s->smmu_state; @@ -958,7 +967,7 @@ static SMMUTransCfg *smmuv3_get_config(SMMUDevice *sdev= , SMMUEventInfo *event) (sdev->cfg_cache_hits + sdev->cfg_cache_misses= )); cfg =3D g_new0(SMMUTransCfg, 1); =20 - if (!smmuv3_decode_config(&sdev->iommu, cfg, event, SMMU_SEC_SID_N= S)) { + if (!smmuv3_decode_config(&sdev->iommu, cfg, event, sec_sid)) { g_hash_table_insert(bc->configs, sdev, cfg); } else { g_free(cfg); @@ -1138,7 +1147,7 @@ static IOMMUTLBEntry smmuv3_translate(IOMMUMemoryRegi= on *mr, hwaddr addr, goto epilogue; } =20 - cfg =3D smmuv3_get_config(sdev, &event); + cfg =3D smmuv3_get_config(sdev, &event, sec_sid); if (!cfg) { status =3D SMMU_TRANS_ERROR; goto epilogue; @@ -1220,7 +1229,7 @@ static void smmuv3_notify_iova(IOMMUMemoryRegion *mr, SMMUSecSID sec_sid =3D SMMU_SEC_SID_NS; SMMUEventInfo eventinfo =3D {.sec_sid =3D sec_sid, .inval_ste_allowed =3D true}; - SMMUTransCfg *cfg =3D smmuv3_get_config(sdev, &eventinfo); + SMMUTransCfg *cfg =3D smmuv3_get_config(sdev, &eventinfo, sec_sid); IOMMUTLBEvent event; uint8_t granule; =20 --=20 2.34.1 From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179467303173728.473801838732356; Sat, 14 Nov 2026 08:17:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGQa-0004hL-Pn; Sat, 14 Nov 2026 11:16:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGQQ-0004bw-6j; Sat, 14 Nov 2026 11:16:25 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGQN-0003AD-TD; Sat, 14 Nov 2026 11:16:21 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-7 (Coremail) with UTF8SMTP id AQAAfwBXX59Rifhqf1MqBg--.44256S2; Sun, 15 Nov 2026 00:16:17 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8Dw43NPifhq0tv6AA--.29160S3; Sun, 15 Nov 2026 00:16:15 +0800 (CST) From: Tao Tang To: Peter Maydell , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 07/35] hw/arm/smmuv3: Reject Secure STEs with stage-2 enabled Date: Sun, 15 Nov 2026 00:16:15 +0800 Message-Id: <20261114161615.3642821-1-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8Dw43NPifhq0tv6AA--.29160S3 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBawAAsO Authentication-Results: hzbj-icmmx-7; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvJXoW7uFW5ur1kJr4fAr18WF1kGrg_yoW8WF13pr 4DGwsYgr4ftF9avFsxZ3y8Za98Wa97Jr97GFy2k3s3AFWqvr1Utr1qka45K3sxurySyFyj qayIvFyDZw4UA37anT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAU7a7-sFnT9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUU UUUUU Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794673036027154100 Content-Type: text/plain; charset="utf-8" Pass sec_sid into decode_ste() and treat a Secure STE that enables stage-2 translation as an illegal STE. The current model does not implement Secure stage-2 translation, so reject Secure STE configurations that enable stage 2 and report BAD_STE. This restriction can be relaxed when SEL2 and Secure stage-2 support are implemented. Signed-off-by: Tao Tang Reviewed-by: Pierrick Bouvier --- hw/arm/smmuv3.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 06684f07242..a5210d845a3 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -596,7 +596,7 @@ static void decode_ste_config(SMMUTransCfg *cfg, uint32= _t config) =20 /* Returns < 0 in case of invalid STE, 0 otherwise */ static int decode_ste(SMMUv3State *s, SMMUTransCfg *cfg, - STE *ste, SMMUEventInfo *event) + STE *ste, SMMUEventInfo *event, SMMUSecSID sec_sid) { uint32_t config; /* OAS field only presents on NS-IDR5 so we use hardcoded SMMU_SEC_SID= _NS */ @@ -650,6 +650,11 @@ static int decode_ste(SMMUv3State *s, SMMUTransCfg *cf= g, if (ret) { goto bad_ste; } + + /* The model does not support Secure stage-2 translation. */ + if (sec_sid =3D=3D SMMU_SEC_SID_S) { + goto bad_ste; + } } =20 /* Multiple context descriptors require SubstreamID support */ @@ -915,7 +920,7 @@ static int smmuv3_decode_config(IOMMUMemoryRegion *mr, = SMMUTransCfg *cfg, return ret; } =20 - ret =3D decode_ste(s, cfg, &ste, event); + ret =3D decode_ste(s, cfg, &ste, event, sec_sid); if (ret) { return ret; } --=20 2.34.1 From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794673036202496.48751302100425; Sat, 14 Nov 2026 08:17:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGQe-0004iZ-M5; Sat, 14 Nov 2026 11:16:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGQZ-0004go-5D; Sat, 14 Nov 2026 11:16:31 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGQW-0003AV-Nd; Sat, 14 Nov 2026 11:16:30 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-7 (Coremail) with UTF8SMTP id AQAAfwCnr8NXifhqzVMqBg--.63944S2; Sun, 15 Nov 2026 00:16:23 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8DwsHNVifhq09v6AA--.34955S3; Sun, 15 Nov 2026 00:16:21 +0800 (CST) From: Tao Tang To: Peter Maydell , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 08/35] hw/arm/smmu-common: Key configuration cache on SMMUDevice and SEC_SID Date: Sun, 15 Nov 2026 00:16:20 +0800 Message-Id: <20261114161620.3643073-1-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8DwsHNVifhq09v6AA--.34955S3 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBbQAAsI Authentication-Results: hzbj-icmmx-7; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvJXoWxtFWUZr1UCF1xJrWkKr15urg_yoWxuw4Upr WxJF98Jr4UGF1fCFs3XFWxu3W5Wwn2gr1fGryagr9YkFyqyryUAF4DK3yYk3s7CrWkJF47 ZayfWFyUCr1xA3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAU7a7-sFnT9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUU UUUUU Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794673038186154100 Content-Type: text/plain; charset="utf-8" Adapt the configuration cache to distinguish entries decoded through different SEC_SID-selected programming interfaces by introducing a composite SMMUConfigKey. The key combines SMMUDevice with SEC_SID, preventing Secure and Non-secure configuration entries from aliasing in the cache and leaving the key extensible for a future Realm SEC_SID namespace. The cache lookup, insertion, and invalidation mechanisms are updated to use this new keying infrastructure. Signed-off-by: Tao Tang Reviewed-by: Eric Auger Reviewed-by: Pierrick Bouvier Link: https://lore.kernel.org/qemu-devel/a9a840a6-c65f-4352-9a49-ddd1b5483f= 43@redhat.com/ Reviewed-by: Jim MacArthur Reviewed-by: Mostafa Saleh --- include/hw/arm/smmu-common.h | 7 ++++++ hw/arm/smmu-common.c | 45 ++++++++++++++++++++++++++++++++++-- hw/arm/smmuv3.c | 12 ++++++---- 3 files changed, 57 insertions(+), 7 deletions(-) diff --git a/include/hw/arm/smmu-common.h b/include/hw/arm/smmu-common.h index a31ffcf6e71..bd83648b14c 100644 --- a/include/hw/arm/smmu-common.h +++ b/include/hw/arm/smmu-common.h @@ -153,6 +153,11 @@ typedef struct SMMUIOTLBKey { uint8_t level; } SMMUIOTLBKey; =20 +typedef struct SMMUConfigKey { + SMMUDevice *sdev; + SMMUSecSID sec_sid; +} SMMUConfigKey; + typedef struct SMMUSIDRange { uint32_t start; uint32_t end; @@ -247,6 +252,7 @@ SMMUTLBEntry *smmu_iotlb_lookup(SMMUState *bs, SMMUTran= sCfg *cfg, void smmu_iotlb_insert(SMMUState *bs, SMMUTransCfg *cfg, SMMUTLBEntry *ent= ry); SMMUIOTLBKey smmu_get_iotlb_key(int asid, int vmid, uint64_t iova, uint8_t tg, uint8_t level); +SMMUConfigKey smmu_get_config_key(SMMUDevice *sdev, SMMUSecSID sec_sid); void smmu_iotlb_inv_all(SMMUState *s); void smmu_iotlb_inv_asid_vmid(SMMUState *s, int asid, int vmid); void smmu_iotlb_inv_vmid(SMMUState *s, int vmid); @@ -256,6 +262,7 @@ void smmu_iotlb_inv_iova(SMMUState *s, int asid, int vm= id, dma_addr_t iova, void smmu_iotlb_inv_ipa(SMMUState *s, int vmid, dma_addr_t ipa, uint8_t tg, uint64_t num_pages, uint8_t ttl); void smmu_configs_inv_sid_range(SMMUState *s, SMMUSIDRange sid_range); +void smmu_configs_inv_sdev(SMMUState *s, SMMUDevice *sdev); /* Unmap the range of all the notifiers registered to any IOMMU mr */ void smmu_inv_notifiers_all(SMMUState *s); =20 diff --git a/hw/arm/smmu-common.c b/hw/arm/smmu-common.c index baa1ff571fa..7ac07b4c260 100644 --- a/hw/arm/smmu-common.c +++ b/hw/arm/smmu-common.c @@ -30,6 +30,26 @@ #include "hw/arm/smmu-common.h" #include "smmu-internal.h" =20 +/* Configuration Cache Management */ +static guint smmu_config_key_hash(gconstpointer key) +{ + const SMMUConfigKey *k =3D key; + return g_direct_hash(k->sdev) ^ (guint)k->sec_sid; +} + +static gboolean smmu_config_key_equal(gconstpointer a, gconstpointer b) +{ + const SMMUConfigKey *ka =3D a; + const SMMUConfigKey *kb =3D b; + return ka->sdev =3D=3D kb->sdev && ka->sec_sid =3D=3D kb->sec_sid; +} + +SMMUConfigKey smmu_get_config_key(SMMUDevice *sdev, SMMUSecSID sec_sid) +{ + SMMUConfigKey key =3D {.sdev =3D sdev, .sec_sid =3D sec_sid}; + return key; +} + ARMSecuritySpace smmu_get_security_space(SMMUSecSID sec_sid) { switch (sec_sid) { @@ -270,7 +290,8 @@ static gboolean smmu_hash_remove_by_vmid_ipa(gpointer k= ey, gpointer value, static gboolean smmu_hash_remove_by_sid_range(gpointer key, gpointer value, gpointer user_= data) { - SMMUDevice *sdev =3D (SMMUDevice *)key; + SMMUConfigKey *config_key =3D (SMMUConfigKey *)key; + SMMUDevice *sdev =3D config_key->sdev; uint32_t sid =3D smmu_get_sid(sdev); SMMUSIDRange *sid_range =3D (SMMUSIDRange *)user_data; =20 @@ -288,6 +309,24 @@ void smmu_configs_inv_sid_range(SMMUState *s, SMMUSIDR= ange sid_range) &sid_range); } =20 +static gboolean smmu_hash_remove_by_sdev(gpointer key, gpointer value, + gpointer user_data) +{ + SMMUConfigKey *config_key =3D (SMMUConfigKey *)key; + SMMUDevice *target =3D (SMMUDevice *)user_data; + + if (config_key->sdev !=3D target) { + return false; + } + trace_smmu_config_cache_inv(smmu_get_sid(target)); + return true; +} + +void smmu_configs_inv_sdev(SMMUState *s, SMMUDevice *sdev) +{ + g_hash_table_foreach_remove(s->configs, smmu_hash_remove_by_sdev, sdev= ); +} + void smmu_iotlb_inv_iova(SMMUState *s, int asid, int vmid, dma_addr_t iova, uint8_t tg, uint64_t num_pages, uint8_t ttl) { @@ -983,7 +1022,9 @@ static void smmu_base_realize(DeviceState *dev, Error = **errp) error_propagate(errp, local_err); return; } - s->configs =3D g_hash_table_new_full(NULL, NULL, NULL, g_free); + s->configs =3D g_hash_table_new_full(smmu_config_key_hash, + smmu_config_key_equal, + g_free, g_free); s->iotlb =3D g_hash_table_new_full(smmu_iotlb_key_hash, smmu_iotlb_key= _equal, g_free, g_free); s->smmu_pcibus_by_busptr =3D g_hash_table_new(NULL, NULL); diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index a5210d845a3..6f81f089a57 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -948,7 +948,7 @@ static int smmuv3_decode_config(IOMMUMemoryRegion *mr, = SMMUTransCfg *cfg, * * The configuration cache contains data resulting from both STE and CD * decoding under the form of an SMMUTransCfg struct. The hash table is in= dexed - * by the SMMUDevice handle. + * by a composite key of the SMMUDevice and the sec_sid. */ static SMMUTransCfg *smmuv3_get_config(SMMUDevice *sdev, SMMUEventInfo *ev= ent, SMMUSecSID sec_sid) @@ -956,8 +956,9 @@ static SMMUTransCfg *smmuv3_get_config(SMMUDevice *sdev= , SMMUEventInfo *event, SMMUv3State *s =3D sdev->smmu; SMMUState *bc =3D &s->smmu_state; SMMUTransCfg *cfg; + SMMUConfigKey lookup_key =3D smmu_get_config_key(sdev, sec_sid); =20 - cfg =3D g_hash_table_lookup(bc->configs, sdev); + cfg =3D g_hash_table_lookup(bc->configs, &lookup_key); if (cfg) { sdev->cfg_cache_hits++; trace_smmuv3_config_cache_hit(smmu_get_sid(sdev), @@ -973,7 +974,9 @@ static SMMUTransCfg *smmuv3_get_config(SMMUDevice *sdev= , SMMUEventInfo *event, cfg =3D g_new0(SMMUTransCfg, 1); =20 if (!smmuv3_decode_config(&sdev->iommu, cfg, event, sec_sid)) { - g_hash_table_insert(bc->configs, sdev, cfg); + SMMUConfigKey *persistent_key =3D g_new(SMMUConfigKey, 1); + *persistent_key =3D lookup_key; + g_hash_table_insert(bc->configs, persistent_key, cfg); } else { g_free(cfg); cfg =3D NULL; @@ -987,8 +990,7 @@ static void smmuv3_flush_config(SMMUDevice *sdev) SMMUv3State *s =3D sdev->smmu; SMMUState *bc =3D &s->smmu_state; =20 - trace_smmu_config_cache_inv(smmu_get_sid(sdev)); - g_hash_table_remove(bc->configs, sdev); + smmu_configs_inv_sdev(bc, sdev); } =20 /* Do translation with TLB lookup. */ --=20 2.34.1 From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794673023115138.39472364292453; Sat, 14 Nov 2026 08:17:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGQk-0004qp-Ck; Sat, 14 Nov 2026 11:16:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGQg-0004km-Qe; Sat, 14 Nov 2026 11:16:39 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGQe-0003B2-FO; Sat, 14 Nov 2026 11:16:37 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-6 (Coremail) with UTF8SMTP id AQAAfwC3v1tiifhqsRkGAg--.41394S2; Sun, 15 Nov 2026 00:16:34 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8DwoHJgifhq1dv6AA--.32338S3; Sun, 15 Nov 2026 00:16:33 +0800 (CST) From: Tao Tang To: Peter Maydell , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 09/35] hw/arm/smmu: Add PTE NS/NSTable helpers Date: Sun, 15 Nov 2026 00:16:32 +0800 Message-Id: <20261114161632.3643332-1-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8DwoHJgifhq1dv6AA--.32338S3 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBbwAAsK Authentication-Results: hzbj-icmmx-6; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvJXoW7uFW7tw1rWr45Cry3CFy3Arb_yoW8Xr15p3 srKwn5Kry8Ja1xKa97Ga1SyF95Wa1rJF13GF9rZr98uan0qF1Fqr12vr4rKasrKFy8Jwnx uF4qv348WrWYqrJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAU7a7-sFnT9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUU UUUUU Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794673025873154100 Content-Type: text/plain; charset="utf-8" Add helper macros for NS and NSTable bits and group PTE attribute accessors for clarity. No functional change beyond the new helpers. Signed-off-by: Tao Tang Reviewed-by: Pierrick Bouvier Reviewed-by: Jim MacArthur Reviewed-by: Eric Auger Reviewed-by: Mostafa Saleh --- hw/arm/smmu-internal.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hw/arm/smmu-internal.h b/hw/arm/smmu-internal.h index d143d296f34..004abd58bca 100644 --- a/hw/arm/smmu-internal.h +++ b/hw/arm/smmu-internal.h @@ -58,16 +58,27 @@ ((level =3D=3D 3) && = \ ((pte & ARM_LPAE_PTE_TYPE_MASK) =3D=3D ARM_LPAE_L3_PTE_TYPE_PAGE)) =20 +/* Stage 1 attribute fields in VMSAv8-64 Block and Page descriptors */ +/* Non-secure bit */ +#define PTE_NS(pte) \ + (extract64(pte, 5, 1)) + /* access permissions */ =20 #define PTE_AP(pte) \ (extract64(pte, 6, 2)) =20 +/* Stage 1 VMSAv8-64 Table descriptor fields */ #define PTE_APTABLE(pte) \ (extract64(pte, 61, 2)) =20 +#define PTE_NSTABLE(pte) \ + (extract64(pte, 63, 1)) + +/* Access flag: defined for both Block/Page and Table descriptors. */ #define PTE_AF(pte) \ (extract64(pte, 10, 1)) + /* * TODO: At the moment all transactions are considered as privileged (EL1) * as IOMMU translation callback does not pass user/priv attributes. --=20 2.34.1 From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17946731442311000.8561518937145; Sat, 14 Nov 2026 08:19:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGSq-0007QR-9y; Sat, 14 Nov 2026 11:18:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGS7-000783-TG; Sat, 14 Nov 2026 11:18:17 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGRy-0003Dk-8W; Sat, 14 Nov 2026 11:18:05 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-6 (Coremail) with UTF8SMTP id AQAAfwBXdd6zifhqGhoGAg--.41975S2; Sun, 15 Nov 2026 00:17:55 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8DwOHSyifhq4Nv6AA--.29617S3; Sun, 15 Nov 2026 00:17:54 +0800 (CST) From: Tao Tang To: Peter Maydell , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 10/35] hw/arm/smmuv3: Store CD NSCFG in TT info Date: Sun, 15 Nov 2026 00:17:44 +0800 Message-Id: <20261114161753.3645568-1-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8DwOHSyifhq4Nv6AA--.29617S3 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBcgAAsX Authentication-Results: hzbj-icmmx-6; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvJXoW7ZF4rWF13urWDAFWkCF45Jrb_yoW8Xr1Dpa 97Crn8KrWIkF1I9r9Fyr47uasrWw4kWr4UtrW7Wr9avrZrtrZ8Jr1UK3ZYkr97urZ8KF47 uF1IvFyrJ3WUtrJanT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAU7a7-sFnT9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUU UUUUU Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794674046426154100 Content-Type: text/plain; charset="utf-8" With NSCFG definitions in place, record the per-table NSCFG bits in SMMUTransTableInfo during CD decode for later use. Signed-off-by: Tao Tang Reviewed-by: Eric Auger Reviewed-by: Pierrick Bouvier Reviewed-by: Jim MacArthur Reviewed-by: Mostafa Saleh --- include/hw/arm/smmu-common.h | 1 + hw/arm/smmuv3.c | 1 + 2 files changed, 2 insertions(+) diff --git a/include/hw/arm/smmu-common.h b/include/hw/arm/smmu-common.h index bd83648b14c..1aa4e3208da 100644 --- a/include/hw/arm/smmu-common.h +++ b/include/hw/arm/smmu-common.h @@ -83,6 +83,7 @@ typedef struct SMMUTransTableInfo { uint8_t tsz; /* input range, ie. 2^(64 -tsz)*/ uint8_t granule_sz; /* granule page shift */ bool had; /* hierarchical attribute disable */ + int nscfg; /* Non-secure attribute of Starting-level T= T */ } SMMUTransTableInfo; =20 typedef struct SMMUTLBEntry { diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 6f81f089a57..156e90f37d9 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -877,6 +877,7 @@ static int decode_cd(SMMUv3State *s, SMMUTransCfg *cfg, tt->ttb =3D CACHED_ENTRY_TO_ADDR(entry, tt->ttb); } =20 + tt->nscfg =3D CD_NSCFG(cd, i); tt->had =3D CD_HAD(cd, i); trace_smmuv3_decode_cd_tt(i, tt->tsz, tt->ttb, tt->granule_sz, tt-= >had); } --=20 2.34.1 From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794673148035341.4291124704944; Sat, 14 Nov 2026 08:19:08 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGT2-0007fS-Lg; Sat, 14 Nov 2026 11:19:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGSB-00078Q-Nq; Sat, 14 Nov 2026 11:18:17 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGS5-0003Ds-5z; Sat, 14 Nov 2026 11:18:09 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-6 (Coremail) with UTF8SMTP id AQAAfwCXn1u0ifhqHhoGAg--.42035S2; Sun, 15 Nov 2026 00:17:56 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8DwOHSyifhq4Nv6AA--.29617S4; Sun, 15 Nov 2026 00:17:55 +0800 (CST) From: Tao Tang To: Peter Maydell , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 11/35] hw/arm/smmu-common: Implement Secure state handling in ptw Date: Sun, 15 Nov 2026 00:17:45 +0800 Message-Id: <20261114161753.3645568-2-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8DwOHSyifhq4Nv6AA--.29617S4 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBdAAAsR Authentication-Results: hzbj-icmmx-6; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvAXoW3trWxCF4kJF1kurW3CFyDWrg_yoW8JFWUWo WSkr4Ygw409w13u3Wjkr18Jas7uFWvg3yrZr4Yyr4a9a17A345GFyUtwsxZa9Yq348AF4x tF93Ga1rXFy8Arn5n29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7KY7ZEXasCq-sGcSsGvf J3UbIjqfuFe4nvWSU8nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2KfnxnUUI43ZEXa7xR_UU UUUUUUU== Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794673149817154101 Content-Type: text/plain; charset="utf-8" Enhance the page table walker to correctly handle Secure and Non-secure memory accesses. This change introduces logic to select the appropriate address space and enforce architectural security policies during walks. The page table walker now correctly processes Secure Stage 1 translations. Key changes include: - The get_pte() function now uses the effective security state to fetch page-table entries from either the Secure or Non-secure address space, with explicit transaction attributes matching that address space. - The stage 1 walker tracks the security state, respecting the NSCFG and NSTable attributes. It correctly handles the hierarchical security model: if a table descriptor in a Secure walk has NSTable=3D1, all subsequent lookups for that walk are forced into the Non-secure space. This is a one-way transition, as specified by the architecture. - The final TLB entry is tagged with the correct output address space, ensuring proper memory isolation. Adapt the stage-2 walker to get_pte()'s new interface and record its Non-secure output AddressSpace. Note: We do not yet support Secure stage 2 translations. This patch only implements Secure stage 1 page-table walks. Baseline propagation of the incoming NS attribute for stage 1 bypass is handled separately in this series with ATTR_PERMS_OVR =3D=3D 0. Full ATTR_PERMS_OVR support is left for a separate series. Signed-off-by: Tao Tang Reviewed-by: Pierrick Bouvier --- include/hw/arm/smmu-common.h | 7 ++-- hw/arm/smmu-common.c | 67 ++++++++++++++++++++++++++++-------- hw/arm/smmuv3.c | 16 +++++---- 3 files changed, 66 insertions(+), 24 deletions(-) diff --git a/include/hw/arm/smmu-common.h b/include/hw/arm/smmu-common.h index 1aa4e3208da..0c5718ea684 100644 --- a/include/hw/arm/smmu-common.h +++ b/include/hw/arm/smmu-common.h @@ -224,18 +224,19 @@ static inline uint16_t smmu_get_sid(SMMUDevice *sdev) =20 /** * smmu_ptw - Perform the page table walk for a given iova / access flags - * pair, according to @cfg translation config + * pair, according to @cfg translation config and @sec_sid */ int smmu_ptw(SMMUState *bs, SMMUTransCfg *cfg, dma_addr_t iova, IOMMUAccessFlags perm, SMMUTLBEntry *tlbe, - SMMUPTWEventInfo *info); + SMMUPTWEventInfo *info, SMMUSecSID sec_sid); =20 /* * smmu_translate - Look for a translation in TLB, if not, do a PTW. * Returns NULL on PTW error or incase of TLB permission errors. */ SMMUTLBEntry *smmu_translate(SMMUState *bs, SMMUTransCfg *cfg, dma_addr_t = addr, - IOMMUAccessFlags flag, SMMUPTWEventInfo *info= ); + IOMMUAccessFlags flag, SMMUPTWEventInfo *info, + SMMUSecSID sec_sid); =20 /** * select_tt - compute which translation table shall be used according to diff --git a/hw/arm/smmu-common.c b/hw/arm/smmu-common.c index 7ac07b4c260..785309b3776 100644 --- a/hw/arm/smmu-common.c +++ b/hw/arm/smmu-common.c @@ -413,13 +413,13 @@ void smmu_iotlb_inv_vmid_s1(SMMUState *s, int vmid) * @base_addr[@index] */ static int get_pte(dma_addr_t baseaddr, uint32_t index, uint64_t *pte, - SMMUPTWEventInfo *info) + SMMUPTWEventInfo *info, AddressSpace *as, MemTxAttrs at= trs) { int ret; dma_addr_t addr =3D baseaddr + index * sizeof(*pte); =20 /* TODO: guarantee 64-bit single-copy atomicity */ - ret =3D ldq_le_dma(&address_space_memory, addr, pte, MEMTXATTRS_UNSPEC= IFIED); + ret =3D ldq_le_dma(as, addr, pte, attrs); =20 if (ret !=3D MEMTX_OK) { info->type =3D SMMU_PTW_ERR_WALK_EABT; @@ -506,7 +506,8 @@ static inline int translate_table_addr_ipa(SMMUState *b= s, asid =3D cfg->asid; cfg->stage =3D SMMU_STAGE_2; cfg->asid =3D -1; - cached_entry =3D smmu_translate(bs, cfg, addr, IOMMU_RO, info); + cached_entry =3D smmu_translate(bs, cfg, addr, IOMMU_RO, info, + SMMU_SEC_SID_NS); cfg->asid =3D asid; cfg->stage =3D SMMU_NESTED; =20 @@ -529,6 +530,7 @@ static inline int translate_table_addr_ipa(SMMUState *b= s, * @perm: access type * @tlbe: SMMUTLBEntry (out) * @info: handle to an error info + * @sec_sid: StreamID Security state * * Return 0 on success, < 0 on error. In case of error, @info is filled * and tlbe->perm is set to IOMMU_NONE. @@ -537,12 +539,16 @@ static inline int translate_table_addr_ipa(SMMUState = *bs, */ static int smmu_ptw_64_s1(SMMUState *bs, SMMUTransCfg *cfg, dma_addr_t iova, IOMMUAccessFlags perm, - SMMUTLBEntry *tlbe, SMMUPTWEventInfo *info) + SMMUTLBEntry *tlbe, SMMUPTWEventInfo *info, + SMMUSecSID sec_sid) { dma_addr_t baseaddr, indexmask; SMMUStage stage =3D cfg->stage; SMMUTransTableInfo *tt =3D select_tt(cfg, iova); uint8_t level, granule_sz, inputsize, stride; + int nscfg, current_ns; + bool sid_is_ns =3D !smmu_sec_sid_is_secure(sec_sid); + SMMUSecSID table_sec_sid; =20 if (!tt || tt->disabled) { info->type =3D SMMU_PTW_ERR_TRANSLATION; @@ -557,6 +563,7 @@ static int smmu_ptw_64_s1(SMMUState *bs, SMMUTransCfg *= cfg, =20 baseaddr =3D extract64(tt->ttb, 0, cfg->oas); baseaddr &=3D ~indexmask; + nscfg =3D tt->nscfg; =20 while (level < VMSA_LEVELS) { uint64_t subpage_size =3D 1ULL << level_shift(level, granule_sz); @@ -565,8 +572,20 @@ static int smmu_ptw_64_s1(SMMUState *bs, SMMUTransCfg = *cfg, uint64_t pte, gpa; dma_addr_t pte_addr =3D baseaddr + offset * sizeof(pte); uint8_t ap; + AddressSpace *pte_as; + MemTxAttrs pte_attrs; + SMMUSecSID cur_sec_sid; =20 - if (get_pte(baseaddr, offset, &pte, info)) { + /* + * At the starting level, fetch translation tables in NS for + * Non-secure streams or CD.NSCFGx =3D=3D 1. Once fetching in NS, + * continue the walk at subsequent levels in NS. + */ + current_ns =3D sid_is_ns || nscfg; + table_sec_sid =3D current_ns ? SMMU_SEC_SID_NS : sec_sid; + pte_as =3D smmu_get_address_space(bs, table_sec_sid); + pte_attrs =3D smmu_get_txattrs(table_sec_sid); + if (get_pte(baseaddr, offset, &pte, info, pte_as, pte_attrs)) { goto error; } trace_smmu_ptw_level(stage, level, iova, subpage_size, @@ -591,6 +610,12 @@ static int smmu_ptw_64_s1(SMMUState *bs, SMMUTransCfg = *cfg, goto error; } } + + if (!current_ns) { + nscfg =3D PTE_NSTABLE(pte); + } else { + nscfg =3D 1; + } level++; continue; } else if (is_page_pte(pte, level)) { @@ -633,6 +658,12 @@ static int smmu_ptw_64_s1(SMMUState *bs, SMMUTransCfg = *cfg, goto error; } =20 + if (current_ns) { + cur_sec_sid =3D SMMU_SEC_SID_NS; + } else { + cur_sec_sid =3D PTE_NS(pte) ? SMMU_SEC_SID_NS : SMMU_SEC_SID_S; + } + tlbe->entry.target_as =3D smmu_get_address_space(bs, cur_sec_sid); tlbe->entry.translated_addr =3D gpa; tlbe->entry.iova =3D iova & ~mask; tlbe->entry.addr_mask =3D mask; @@ -653,6 +684,7 @@ error: /** * smmu_ptw_64_s2 - VMSAv8-64 Walk of the page tables for a given ipa * for stage-2. + * @bs: smmu state which includes TLB instance * @cfg: translation config * @ipa: ipa to translate * @perm: access type @@ -664,7 +696,7 @@ error: * Upon success, @tlbe is filled with translated_addr and entry * permission rights. */ -static int smmu_ptw_64_s2(SMMUTransCfg *cfg, +static int smmu_ptw_64_s2(SMMUState *bs, SMMUTransCfg *cfg, dma_addr_t ipa, IOMMUAccessFlags perm, SMMUTLBEntry *tlbe, SMMUPTWEventInfo *info) { @@ -702,7 +734,8 @@ static int smmu_ptw_64_s2(SMMUTransCfg *cfg, dma_addr_t pte_addr =3D baseaddr + offset * sizeof(pte); uint8_t s2ap; =20 - if (get_pte(baseaddr, offset, &pte, info)) { + if (get_pte(baseaddr, offset, &pte, info, &bs->memory_as, + MEMTXATTRS_UNSPECIFIED)) { goto error; } trace_smmu_ptw_level(stage, level, ipa, subpage_size, @@ -755,6 +788,7 @@ static int smmu_ptw_64_s2(SMMUTransCfg *cfg, goto error_ipa; } =20 + tlbe->entry.target_as =3D &bs->memory_as; tlbe->entry.translated_addr =3D gpa; tlbe->entry.iova =3D ipa & ~mask; tlbe->entry.addr_mask =3D mask; @@ -796,7 +830,7 @@ static void combine_tlb(SMMUTLBEntry *tlbe, SMMUTLBEntr= y *tlbe_s2, } =20 /** - * smmu_ptw - Walk the page tables for an IOVA, according to @cfg + * smmu_ptw - Walk the page tables for an IOVA, according to @cfg and @sec= _sid * * @bs: smmu state which includes TLB instance * @cfg: translation configuration @@ -804,18 +838,20 @@ static void combine_tlb(SMMUTLBEntry *tlbe, SMMUTLBEn= try *tlbe_s2, * @perm: tentative access type * @tlbe: returned entry * @info: ptw event handle + * @sec_sid: StreamID Security state * * return 0 on success */ int smmu_ptw(SMMUState *bs, SMMUTransCfg *cfg, dma_addr_t iova, - IOMMUAccessFlags perm, SMMUTLBEntry *tlbe, SMMUPTWEventInfo *= info) + IOMMUAccessFlags perm, SMMUTLBEntry *tlbe, SMMUPTWEventInfo *= info, + SMMUSecSID sec_sid) { int ret; SMMUTLBEntry tlbe_s2; dma_addr_t ipa; =20 if (cfg->stage =3D=3D SMMU_STAGE_1) { - return smmu_ptw_64_s1(bs, cfg, iova, perm, tlbe, info); + return smmu_ptw_64_s1(bs, cfg, iova, perm, tlbe, info, sec_sid); } else if (cfg->stage =3D=3D SMMU_STAGE_2) { /* * If bypassing stage 1(or unimplemented), the input address is pa= ssed @@ -830,17 +866,17 @@ int smmu_ptw(SMMUState *bs, SMMUTransCfg *cfg, dma_ad= dr_t iova, return -EINVAL; } =20 - return smmu_ptw_64_s2(cfg, iova, perm, tlbe, info); + return smmu_ptw_64_s2(bs, cfg, iova, perm, tlbe, info); } =20 /* SMMU_NESTED. */ - ret =3D smmu_ptw_64_s1(bs, cfg, iova, perm, tlbe, info); + ret =3D smmu_ptw_64_s1(bs, cfg, iova, perm, tlbe, info, sec_sid); if (ret) { return ret; } =20 ipa =3D CACHED_ENTRY_TO_ADDR(tlbe, iova); - ret =3D smmu_ptw_64_s2(cfg, ipa, perm, &tlbe_s2, info); + ret =3D smmu_ptw_64_s2(bs, cfg, ipa, perm, &tlbe_s2, info); if (ret) { return ret; } @@ -850,7 +886,8 @@ int smmu_ptw(SMMUState *bs, SMMUTransCfg *cfg, dma_addr= _t iova, } =20 SMMUTLBEntry *smmu_translate(SMMUState *bs, SMMUTransCfg *cfg, dma_addr_t = addr, - IOMMUAccessFlags flag, SMMUPTWEventInfo *info) + IOMMUAccessFlags flag, SMMUPTWEventInfo *info, + SMMUSecSID sec_sid) { SMMUTLBEntry *cached_entry =3D NULL; SMMUTransTableInfo *tt; @@ -892,7 +929,7 @@ SMMUTLBEntry *smmu_translate(SMMUState *bs, SMMUTransCf= g *cfg, dma_addr_t addr, } =20 cached_entry =3D g_new0(SMMUTLBEntry, 1); - status =3D smmu_ptw(bs, cfg, addr, flag, cached_entry, info); + status =3D smmu_ptw(bs, cfg, addr, flag, cached_entry, info, sec_sid); if (status) { g_free(cached_entry); return NULL; diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 156e90f37d9..d4ee63e3aa6 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -393,7 +393,8 @@ static SMMUTranslationStatus smmuv3_do_translate(SMMUv3= State *s, hwaddr addr, SMMUEventInfo *event, IOMMUAccessFlags flag, SMMUTLBEntry **out_entry, - SMMUTranslationClass clas= s); + SMMUTranslationClass clas= s, + SMMUSecSID sec_sid); /* @ssid > 0 not supported yet */ static int smmu_get_cd(SMMUv3State *s, STE *ste, SMMUTransCfg *cfg, uint32_t ssid, CD *buf, SMMUEventInfo *event, @@ -410,7 +411,7 @@ static int smmu_get_cd(SMMUv3State *s, STE *ste, SMMUTr= ansCfg *cfg, =20 if (cfg->stage =3D=3D SMMU_NESTED) { status =3D smmuv3_do_translate(s, addr, cfg, event, - IOMMU_RO, &entry, SMMU_CLASS_CD); + IOMMU_RO, &entry, SMMU_CLASS_CD, sec_= sid); =20 /* Same PTW faults are reported but with CLASS =3D CD. */ if (status !=3D SMMU_TRANS_SUCCESS) { @@ -865,7 +866,8 @@ static int decode_cd(SMMUv3State *s, SMMUTransCfg *cfg, /* Translate the TTBx, from IPA to PA if nesting is enabled. */ if (cfg->stage =3D=3D SMMU_NESTED) { status =3D smmuv3_do_translate(s, tt->ttb, cfg, event, IOMMU_R= O, - &entry, SMMU_CLASS_TT); + &entry, SMMU_CLASS_TT, + SMMU_SEC_SID_NS); /* * Same PTW faults are reported but with CLASS =3D TT. * If TTBx is larger than the effective stage 1 output addres @@ -1000,7 +1002,8 @@ static SMMUTranslationStatus smmuv3_do_translate(SMMU= v3State *s, hwaddr addr, SMMUEventInfo *event, IOMMUAccessFlags flag, SMMUTLBEntry **out_entry, - SMMUTranslationClass clas= s) + SMMUTranslationClass clas= s, + SMMUSecSID sec_sid) { SMMUPTWEventInfo ptw_info =3D {}; SMMUState *bs =3D ARM_SMMU(s); @@ -1026,7 +1029,7 @@ static SMMUTranslationStatus smmuv3_do_translate(SMMU= v3State *s, hwaddr addr, cfg->stage =3D SMMU_STAGE_2; } =20 - cached_entry =3D smmu_translate(bs, cfg, addr, flag, &ptw_info); + cached_entry =3D smmu_translate(bs, cfg, addr, flag, &ptw_info, sec_si= d); =20 if (desc_s2_translation) { cfg->asid =3D asid; @@ -1172,13 +1175,14 @@ static IOMMUTLBEntry smmuv3_translate(IOMMUMemoryRe= gion *mr, hwaddr addr, } =20 status =3D smmuv3_do_translate(s, addr, cfg, &event, flag, - &cached_entry, SMMU_CLASS_IN); + &cached_entry, SMMU_CLASS_IN, sec_sid); =20 epilogue: qemu_mutex_unlock(&s->mutex); switch (status) { case SMMU_TRANS_SUCCESS: entry.perm =3D cached_entry->entry.perm; + entry.target_as =3D cached_entry->entry.target_as; entry.translated_addr =3D CACHED_ENTRY_TO_ADDR(cached_entry, addr); entry.addr_mask =3D cached_entry->entry.addr_mask; trace_smmuv3_translate_success(mr->parent_obj.name, sid, addr, --=20 2.34.1 From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794673257341334.95446860393236; Sat, 14 Nov 2026 08:20:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGT8-00085X-K5; Sat, 14 Nov 2026 11:19:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGSF-00078v-E1; Sat, 14 Nov 2026 11:18:23 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGS8-0003ET-7d; Sat, 14 Nov 2026 11:18:15 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-6 (Coremail) with UTF8SMTP id AQAAfwCXn1u8ifhqPRoGAg--.42037S2; Sun, 15 Nov 2026 00:18:04 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8DwOHSyifhq4Nv6AA--.29617S5; Sun, 15 Nov 2026 00:17:56 +0800 (CST) From: Tao Tang To: Peter Maydell , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 12/35] hw/arm/smmuv3: Tag IOTLB cache keys with SEC_SID Date: Sun, 15 Nov 2026 00:17:46 +0800 Message-Id: <20261114161753.3645568-3-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8DwOHSyifhq4Nv6AA--.29617S5 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBdgAAsT Authentication-Results: hzbj-icmmx-6; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvAXoWfZw17Zw4fWFWDGw4fCw48JFb_yoW8KFW3uo WfG3WYqr48X3W3u3WqkF4xJa42vayDtay5Zw45X3yYg3ZxKrs8tFWxKr4fXF4FqF4UAF40 9F95JFW8XFyUCr93n29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7KY7ZEXasCq-sGcSsGvf J3UbIjqfuFe4nvWSU8nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2KfnxnUUI43ZEXa7xR_UU UUUUUUU== Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794673259390154100 Content-Type: text/plain; charset="utf-8" To prevent aliasing between translations controlled through the Secure and Non-secure programming interfaces, the IOTLB lookup key must incorporate SEC_SID. This commit: - expands SMMUIOTLBKey with SEC_SID field for cache key differentiation - extends SMMUIOTLBPageInvInfo with SEC_SID for invalidation filtering - updates all IOTLB invalidation helpers (smmu_iotlb_inv_iova, smmu_iotlb_inv_ipa, smmu_iotlb_inv_asid_vmid, smmu_iotlb_inv_vmid, smmu_iotlb_inv_vmid_s1) to accept and filter by SEC_SID - plumbs SEC_SID through smmuv3_range_inval for TLB invalidation - enhances trace events to include SEC_SID for better debugging This ensures that IOTLB entries decoded through the Secure and Non-secure programming interfaces are distinct, preventing cache aliasing across SEC_SID namespaces. Signed-off-by: Tao Tang Reviewed-by: Pierrick Bouvier Reviewed-by: Eric Auger --- hw/arm/smmu-internal.h | 2 + include/hw/arm/smmu-common.h | 32 +++++++--- hw/arm/smmu-common.c | 110 +++++++++++++++++++++++------------ hw/arm/smmuv3.c | 43 +++++++++----- hw/arm/trace-events | 20 +++---- 5 files changed, 136 insertions(+), 71 deletions(-) diff --git a/hw/arm/smmu-internal.h b/hw/arm/smmu-internal.h index 004abd58bca..ce68d4b5813 100644 --- a/hw/arm/smmu-internal.h +++ b/hw/arm/smmu-internal.h @@ -144,12 +144,14 @@ static inline int pgd_concat_idx(int start_level, int= granule_sz, =20 #define SMMU_IOTLB_ASID(key) ((key).asid) #define SMMU_IOTLB_VMID(key) ((key).vmid) +#define SMMU_IOTLB_SEC_SID(key) ((key).sec_sid) =20 typedef struct SMMUIOTLBPageInvInfo { int asid; int vmid; uint64_t iova; uint64_t mask; + SMMUSecSID sec_sid; } SMMUIOTLBPageInvInfo; =20 #endif diff --git a/include/hw/arm/smmu-common.h b/include/hw/arm/smmu-common.h index 0c5718ea684..8e971c28093 100644 --- a/include/hw/arm/smmu-common.h +++ b/include/hw/arm/smmu-common.h @@ -152,6 +152,17 @@ typedef struct SMMUIOTLBKey { int vmid; uint8_t tg; uint8_t level; + /* + * We currently model one StreamWorld per SEC_SID, giving the approxim= ate + * mapping: + * + * SMMU_SEC_SID_NS -> NS-EL1 + * SMMU_SEC_SID_S -> Secure + * + * SEC_SID is not architecturally equivalent to StreamWorld. Extend th= is + * key when additional translation regimes are implemented. + */ + SMMUSecSID sec_sid; } SMMUIOTLBKey; =20 typedef struct SMMUConfigKey { @@ -250,19 +261,24 @@ SMMUDevice *smmu_find_sdev(SMMUState *s, uint32_t sid= ); #define SMMU_IOTLB_MAX_SIZE 256 =20 SMMUTLBEntry *smmu_iotlb_lookup(SMMUState *bs, SMMUTransCfg *cfg, - SMMUTransTableInfo *tt, hwaddr iova); -void smmu_iotlb_insert(SMMUState *bs, SMMUTransCfg *cfg, SMMUTLBEntry *ent= ry); + SMMUTransTableInfo *tt, hwaddr iova, + SMMUSecSID sec_sid); +void smmu_iotlb_insert(SMMUState *bs, SMMUTransCfg *cfg, SMMUTLBEntry *ent= ry, + SMMUSecSID sec_sid); SMMUIOTLBKey smmu_get_iotlb_key(int asid, int vmid, uint64_t iova, - uint8_t tg, uint8_t level); + uint8_t tg, uint8_t level, SMMUSecSID sec_= sid); SMMUConfigKey smmu_get_config_key(SMMUDevice *sdev, SMMUSecSID sec_sid); void smmu_iotlb_inv_all(SMMUState *s); -void smmu_iotlb_inv_asid_vmid(SMMUState *s, int asid, int vmid); -void smmu_iotlb_inv_vmid(SMMUState *s, int vmid); -void smmu_iotlb_inv_vmid_s1(SMMUState *s, int vmid); +void smmu_iotlb_inv_asid_vmid(SMMUState *s, int asid, int vmid, + SMMUSecSID sec_sid); +void smmu_iotlb_inv_vmid(SMMUState *s, int vmid, SMMUSecSID sec_sid); +void smmu_iotlb_inv_vmid_s1(SMMUState *s, int vmid, SMMUSecSID sec_sid); void smmu_iotlb_inv_iova(SMMUState *s, int asid, int vmid, dma_addr_t iova, - uint8_t tg, uint64_t num_pages, uint8_t ttl); + uint8_t tg, uint64_t num_pages, uint8_t ttl, + SMMUSecSID sec_sid); void smmu_iotlb_inv_ipa(SMMUState *s, int vmid, dma_addr_t ipa, uint8_t tg, - uint64_t num_pages, uint8_t ttl); + uint64_t num_pages, uint8_t ttl, + SMMUSecSID sec_sid); void smmu_configs_inv_sid_range(SMMUState *s, SMMUSIDRange sid_range); void smmu_configs_inv_sdev(SMMUState *s, SMMUDevice *sdev); /* Unmap the range of all the notifiers registered to any IOMMU mr */ diff --git a/hw/arm/smmu-common.c b/hw/arm/smmu-common.c index 785309b3776..9c172fbb765 100644 --- a/hw/arm/smmu-common.c +++ b/hw/arm/smmu-common.c @@ -100,7 +100,7 @@ static guint smmu_iotlb_key_hash(gconstpointer v) =20 /* Jenkins hash */ a =3D b =3D c =3D JHASH_INITVAL + sizeof(*key); - a +=3D key->asid + key->vmid + key->level + key->tg; + a +=3D key->asid + key->vmid + key->level + key->tg + key->sec_sid; b +=3D extract64(key->iova, 0, 32); c +=3D extract64(key->iova, 32, 32); =20 @@ -116,14 +116,15 @@ static gboolean smmu_iotlb_key_equal(gconstpointer v1= , gconstpointer v2) =20 return (k1->asid =3D=3D k2->asid) && (k1->iova =3D=3D k2->iova) && (k1->level =3D=3D k2->level) && (k1->tg =3D=3D k2->tg) && - (k1->vmid =3D=3D k2->vmid); + (k1->vmid =3D=3D k2->vmid) && (k1->sec_sid =3D=3D k2->sec_sid); } =20 SMMUIOTLBKey smmu_get_iotlb_key(int asid, int vmid, uint64_t iova, - uint8_t tg, uint8_t level) + uint8_t tg, uint8_t level, + SMMUSecSID sec_sid) { SMMUIOTLBKey key =3D {.asid =3D asid, .vmid =3D vmid, .iova =3D iova, - .tg =3D tg, .level =3D level}; + .tg =3D tg, .level =3D level, .sec_sid =3D sec_sid= }; =20 return key; } @@ -131,7 +132,8 @@ SMMUIOTLBKey smmu_get_iotlb_key(int asid, int vmid, uin= t64_t iova, static SMMUTLBEntry *smmu_iotlb_lookup_all_levels(SMMUState *bs, SMMUTransCfg *cfg, SMMUTransTableInfo *tt, - hwaddr iova) + hwaddr iova, + SMMUSecSID sec_sid) { uint8_t tg =3D (tt->granule_sz - 10) / 2; uint8_t inputsize =3D 64 - tt->tsz; @@ -145,7 +147,7 @@ static SMMUTLBEntry *smmu_iotlb_lookup_all_levels(SMMUS= tate *bs, SMMUIOTLBKey key; =20 key =3D smmu_get_iotlb_key(cfg->asid, cfg->s2cfg.vmid, - iova & ~mask, tg, level); + iova & ~mask, tg, level, sec_sid); entry =3D g_hash_table_lookup(bs->iotlb, &key); if (entry) { break; @@ -161,6 +163,7 @@ static SMMUTLBEntry *smmu_iotlb_lookup_all_levels(SMMUS= tate *bs, * @cfg: Configuration of the translation * @tt: Translation table info (granule and tsz) * @iova: IOVA address to lookup + * @sec_sid: StreamID Security state * * returns a valid entry on success, otherwise NULL. * In case of nested translation, tt can be updated to include @@ -168,11 +171,12 @@ static SMMUTLBEntry *smmu_iotlb_lookup_all_levels(SMM= UState *bs, * the IOVA granule. */ SMMUTLBEntry *smmu_iotlb_lookup(SMMUState *bs, SMMUTransCfg *cfg, - SMMUTransTableInfo *tt, hwaddr iova) + SMMUTransTableInfo *tt, hwaddr iova, + SMMUSecSID sec_sid) { SMMUTLBEntry *entry =3D NULL; =20 - entry =3D smmu_iotlb_lookup_all_levels(bs, cfg, tt, iova); + entry =3D smmu_iotlb_lookup_all_levels(bs, cfg, tt, iova, sec_sid); /* * For nested translation also try the s2 granule, as the TLB will ins= ert * it if the size of s2 tlb entry was smaller. @@ -180,18 +184,20 @@ SMMUTLBEntry *smmu_iotlb_lookup(SMMUState *bs, SMMUTr= ansCfg *cfg, if (!entry && (cfg->stage =3D=3D SMMU_NESTED) && (cfg->s2cfg.granule_sz !=3D tt->granule_sz)) { tt->granule_sz =3D cfg->s2cfg.granule_sz; - entry =3D smmu_iotlb_lookup_all_levels(bs, cfg, tt, iova); + entry =3D smmu_iotlb_lookup_all_levels(bs, cfg, tt, iova, sec_sid); } =20 if (entry) { cfg->iotlb_hits++; - trace_smmu_iotlb_lookup_hit(cfg->asid, cfg->s2cfg.vmid, iova, + trace_smmu_iotlb_lookup_hit(sec_sid, cfg->asid, + cfg->s2cfg.vmid, iova, cfg->iotlb_hits, cfg->iotlb_misses, 100 * cfg->iotlb_hits / (cfg->iotlb_hits + cfg->iotlb_misses)); } else { cfg->iotlb_misses++; - trace_smmu_iotlb_lookup_miss(cfg->asid, cfg->s2cfg.vmid, iova, + trace_smmu_iotlb_lookup_miss(sec_sid, cfg->asid, + cfg->s2cfg.vmid, iova, cfg->iotlb_hits, cfg->iotlb_misses, 100 * cfg->iotlb_hits / (cfg->iotlb_hits + cfg->iotlb_misses)= ); @@ -199,7 +205,8 @@ SMMUTLBEntry *smmu_iotlb_lookup(SMMUState *bs, SMMUTran= sCfg *cfg, return entry; } =20 -void smmu_iotlb_insert(SMMUState *bs, SMMUTransCfg *cfg, SMMUTLBEntry *new) +void smmu_iotlb_insert(SMMUState *bs, SMMUTransCfg *cfg, SMMUTLBEntry *new, + SMMUSecSID sec_sid) { SMMUIOTLBKey *key =3D g_new0(SMMUIOTLBKey, 1); uint8_t tg =3D (new->granule - 10) / 2; @@ -209,9 +216,9 @@ void smmu_iotlb_insert(SMMUState *bs, SMMUTransCfg *cfg= , SMMUTLBEntry *new) } =20 *key =3D smmu_get_iotlb_key(cfg->asid, cfg->s2cfg.vmid, new->entry.iov= a, - tg, new->level); - trace_smmu_iotlb_insert(cfg->asid, cfg->s2cfg.vmid, new->entry.iova, - tg, new->level); + tg, new->level, sec_sid); + trace_smmu_iotlb_insert(sec_sid, cfg->asid, cfg->s2cfg.vmid, + new->entry.iova, tg, new->level); g_hash_table_insert(bs->iotlb, key, new); } =20 @@ -228,26 +235,29 @@ static gboolean smmu_hash_remove_by_asid_vmid(gpointe= r key, gpointer value, SMMUIOTLBKey *iotlb_key =3D (SMMUIOTLBKey *)key; =20 return (SMMU_IOTLB_ASID(*iotlb_key) =3D=3D info->asid) && - (SMMU_IOTLB_VMID(*iotlb_key) =3D=3D info->vmid); + (SMMU_IOTLB_VMID(*iotlb_key) =3D=3D info->vmid) && + (SMMU_IOTLB_SEC_SID(*iotlb_key) =3D=3D info->sec_sid); } =20 static gboolean smmu_hash_remove_by_vmid(gpointer key, gpointer value, gpointer user_data) { - int vmid =3D *(int *)user_data; + SMMUIOTLBPageInvInfo *info =3D (SMMUIOTLBPageInvInfo *)user_data; SMMUIOTLBKey *iotlb_key =3D (SMMUIOTLBKey *)key; =20 - return SMMU_IOTLB_VMID(*iotlb_key) =3D=3D vmid; + return (SMMU_IOTLB_VMID(*iotlb_key) =3D=3D info->vmid) && + (SMMU_IOTLB_SEC_SID(*iotlb_key) =3D=3D info->sec_sid); } =20 static gboolean smmu_hash_remove_by_vmid_s1(gpointer key, gpointer value, gpointer user_data) { - int vmid =3D *(int *)user_data; + SMMUIOTLBPageInvInfo *info =3D (SMMUIOTLBPageInvInfo *)user_data; SMMUIOTLBKey *iotlb_key =3D (SMMUIOTLBKey *)key; =20 - return (SMMU_IOTLB_VMID(*iotlb_key) =3D=3D vmid) && - (SMMU_IOTLB_ASID(*iotlb_key) >=3D 0); + return (SMMU_IOTLB_VMID(*iotlb_key) =3D=3D info->vmid) && + (SMMU_IOTLB_ASID(*iotlb_key) >=3D 0) && + (SMMU_IOTLB_SEC_SID(*iotlb_key) =3D=3D info->sec_sid); } =20 static gboolean smmu_hash_remove_by_asid_vmid_iova(gpointer key, gpointer = value, @@ -264,6 +274,9 @@ static gboolean smmu_hash_remove_by_asid_vmid_iova(gpoi= nter key, gpointer value, if (info->vmid >=3D 0 && info->vmid !=3D SMMU_IOTLB_VMID(iotlb_key)) { return false; } + if (info->sec_sid !=3D SMMU_IOTLB_SEC_SID(iotlb_key)) { + return false; + } return ((info->iova & ~entry->addr_mask) =3D=3D entry->iova) || ((entry->iova & ~info->mask) =3D=3D info->iova); } @@ -283,6 +296,9 @@ static gboolean smmu_hash_remove_by_vmid_ipa(gpointer k= ey, gpointer value, if (info->vmid !=3D SMMU_IOTLB_VMID(iotlb_key)) { return false; } + if (info->sec_sid !=3D SMMU_IOTLB_SEC_SID(iotlb_key)) { + return false; + } return ((info->iova & ~entry->addr_mask) =3D=3D entry->iova) || ((entry->iova & ~info->mask) =3D=3D info->iova); } @@ -328,13 +344,17 @@ void smmu_configs_inv_sdev(SMMUState *s, SMMUDevice *= sdev) } =20 void smmu_iotlb_inv_iova(SMMUState *s, int asid, int vmid, dma_addr_t iova, - uint8_t tg, uint64_t num_pages, uint8_t ttl) + uint8_t tg, uint64_t num_pages, uint8_t ttl, + SMMUSecSID sec_sid) { /* if tg is not set we use 4KB range invalidation */ uint8_t granule =3D tg ? tg * 2 + 10 : 12; =20 + trace_smmu_iotlb_inv_iova(sec_sid, asid, iova); + if (ttl && (num_pages =3D=3D 1) && (asid >=3D 0)) { - SMMUIOTLBKey key =3D smmu_get_iotlb_key(asid, vmid, iova, tg, ttl); + SMMUIOTLBKey key =3D smmu_get_iotlb_key(asid, vmid, iova, + tg, ttl, sec_sid); =20 if (g_hash_table_remove(s->iotlb, &key)) { return; @@ -348,7 +368,8 @@ void smmu_iotlb_inv_iova(SMMUState *s, int asid, int vm= id, dma_addr_t iova, SMMUIOTLBPageInvInfo info =3D { .asid =3D asid, .iova =3D iova, .vmid =3D vmid, - .mask =3D (num_pages * 1 << granule) - 1}; + .mask =3D (num_pages * 1 << granule) - 1, + .sec_sid =3D sec_sid}; =20 g_hash_table_foreach_remove(s->iotlb, smmu_hash_remove_by_asid_vmid_iova, @@ -360,13 +381,15 @@ void smmu_iotlb_inv_iova(SMMUState *s, int asid, int = vmid, dma_addr_t iova, * in Stage-1 invalidation ASID =3D -1, means don't care. */ void smmu_iotlb_inv_ipa(SMMUState *s, int vmid, dma_addr_t ipa, uint8_t tg, - uint64_t num_pages, uint8_t ttl) + uint64_t num_pages, uint8_t ttl, + SMMUSecSID sec_sid) { uint8_t granule =3D tg ? tg * 2 + 10 : 12; int asid =3D -1; =20 if (ttl && (num_pages =3D=3D 1)) { - SMMUIOTLBKey key =3D smmu_get_iotlb_key(asid, vmid, ipa, tg, ttl); + SMMUIOTLBKey key =3D smmu_get_iotlb_key(asid, vmid, ipa, + tg, ttl, sec_sid); =20 if (g_hash_table_remove(s->iotlb, &key)) { return; @@ -376,34 +399,47 @@ void smmu_iotlb_inv_ipa(SMMUState *s, int vmid, dma_a= ddr_t ipa, uint8_t tg, SMMUIOTLBPageInvInfo info =3D { .iova =3D ipa, .vmid =3D vmid, - .mask =3D (num_pages << granule) - 1}; + .mask =3D (num_pages << granule) - 1, + .sec_sid =3D sec_sid}; =20 g_hash_table_foreach_remove(s->iotlb, smmu_hash_remove_by_vmid_ipa, &info); } =20 -void smmu_iotlb_inv_asid_vmid(SMMUState *s, int asid, int vmid) +void smmu_iotlb_inv_asid_vmid(SMMUState *s, int asid, int vmid, + SMMUSecSID sec_sid) { SMMUIOTLBPageInvInfo info =3D { .asid =3D asid, .vmid =3D vmid, + .sec_sid =3D sec_sid, }; =20 - trace_smmu_iotlb_inv_asid_vmid(asid, vmid); + trace_smmu_iotlb_inv_asid_vmid(sec_sid, asid, vmid); g_hash_table_foreach_remove(s->iotlb, smmu_hash_remove_by_asid_vmid, &= info); } =20 -void smmu_iotlb_inv_vmid(SMMUState *s, int vmid) +void smmu_iotlb_inv_vmid(SMMUState *s, int vmid, SMMUSecSID sec_sid) { - trace_smmu_iotlb_inv_vmid(vmid); - g_hash_table_foreach_remove(s->iotlb, smmu_hash_remove_by_vmid, &vmid); + SMMUIOTLBPageInvInfo info =3D { + .vmid =3D vmid, + .sec_sid =3D sec_sid, + }; + + trace_smmu_iotlb_inv_vmid(sec_sid, vmid); + g_hash_table_foreach_remove(s->iotlb, smmu_hash_remove_by_vmid, &info); } =20 -void smmu_iotlb_inv_vmid_s1(SMMUState *s, int vmid) +void smmu_iotlb_inv_vmid_s1(SMMUState *s, int vmid, SMMUSecSID sec_sid) { - trace_smmu_iotlb_inv_vmid_s1(vmid); - g_hash_table_foreach_remove(s->iotlb, smmu_hash_remove_by_vmid_s1, &vm= id); + SMMUIOTLBPageInvInfo info =3D { + .vmid =3D vmid, + .sec_sid =3D sec_sid, + }; + + trace_smmu_iotlb_inv_vmid_s1(sec_sid, vmid); + g_hash_table_foreach_remove(s->iotlb, smmu_hash_remove_by_vmid_s1, &in= fo); } =20 /* VMSAv8-64 Translation */ @@ -915,7 +951,7 @@ SMMUTLBEntry *smmu_translate(SMMUState *bs, SMMUTransCf= g *cfg, dma_addr_t addr, tt_combined.tsz =3D tt->tsz; } =20 - cached_entry =3D smmu_iotlb_lookup(bs, cfg, &tt_combined, addr); + cached_entry =3D smmu_iotlb_lookup(bs, cfg, &tt_combined, addr, sec_si= d); if (cached_entry) { if ((flag & IOMMU_WO) && !(cached_entry->entry.perm & cached_entry->parent_perm & IOMMU_WO)) { @@ -934,7 +970,7 @@ SMMUTLBEntry *smmu_translate(SMMUState *bs, SMMUTransCf= g *cfg, dma_addr_t addr, g_free(cached_entry); return NULL; } - smmu_iotlb_insert(bs, cfg, cached_entry); + smmu_iotlb_insert(bs, cfg, cached_entry, sec_sid); return cached_entry; } =20 diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index d4ee63e3aa6..63a77368035 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -633,6 +633,13 @@ static int decode_ste(SMMUv3State *s, SMMUTransCfg *cf= g, goto bad_ste; } =20 + if (smmu_sec_sid_is_secure(sec_sid) && STE_CFG_S1_TRANSLATE(config) && + STE_STRW(ste) !=3D 0) { + qemu_log_mask(LOG_UNIMP, + "SMMUv3 Secure StreamWorld is not implemented\n"); + goto bad_ste; + } + if (STAGE2_SUPPORTED(s)) { /* VMID is considered even if s2 is disabled. */ cfg->s2cfg.vmid =3D STE_S2VMID(ste); @@ -1314,7 +1321,8 @@ static void smmuv3_inv_notifiers_iova(SMMUState *s, i= nt asid, int vmid, } } =20 -static void smmuv3_range_inval(SMMUState *s, Cmd *cmd, SMMUStage stage) +static void smmuv3_range_inval(SMMUState *s, Cmd *cmd, SMMUStage stage, + SMMUSecSID sec_sid) { dma_addr_t end, addr =3D CMD_ADDR(cmd); uint8_t type =3D CMD_TYPE(cmd); @@ -1339,12 +1347,13 @@ static void smmuv3_range_inval(SMMUState *s, Cmd *c= md, SMMUStage stage) } =20 if (!tg) { - trace_smmuv3_range_inval(vmid, asid, addr, tg, 1, ttl, leaf, stage= ); + trace_smmuv3_range_inval(sec_sid, vmid, asid, addr, + tg, 1, ttl, leaf, stage); smmuv3_inv_notifiers_iova(s, asid, vmid, addr, tg, 1, stage); if (stage =3D=3D SMMU_STAGE_1) { - smmu_iotlb_inv_iova(s, asid, vmid, addr, tg, 1, ttl); + smmu_iotlb_inv_iova(s, asid, vmid, addr, tg, 1, ttl, sec_sid); } else { - smmu_iotlb_inv_ipa(s, vmid, addr, tg, 1, ttl); + smmu_iotlb_inv_ipa(s, vmid, addr, tg, 1, ttl, sec_sid); } return; } @@ -1361,13 +1370,15 @@ static void smmuv3_range_inval(SMMUState *s, Cmd *c= md, SMMUStage stage) uint64_t mask =3D dma_aligned_pow2_mask(addr, end, 64); =20 num_pages =3D (mask + 1) >> granule; - trace_smmuv3_range_inval(vmid, asid, addr, tg, num_pages, - ttl, leaf, stage); - smmuv3_inv_notifiers_iova(s, asid, vmid, addr, tg, num_pages, stag= e); + trace_smmuv3_range_inval(sec_sid, vmid, asid, addr, tg, + num_pages, ttl, leaf, stage); + smmuv3_inv_notifiers_iova(s, asid, vmid, addr, tg, + num_pages, stage); if (stage =3D=3D SMMU_STAGE_1) { - smmu_iotlb_inv_iova(s, asid, vmid, addr, tg, num_pages, ttl); + smmu_iotlb_inv_iova(s, asid, vmid, addr, tg, + num_pages, ttl, sec_sid); } else { - smmu_iotlb_inv_ipa(s, vmid, addr, tg, num_pages, ttl); + smmu_iotlb_inv_ipa(s, vmid, addr, tg, num_pages, ttl, sec_sid); } addr +=3D mask + 1; } @@ -1518,9 +1529,9 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error = **errp) vmid =3D CMD_VMID(&cmd); } =20 - trace_smmuv3_cmdq_tlbi_nh_asid(asid); + trace_smmuv3_cmdq_tlbi_nh_asid(sec_sid, asid); smmu_inv_notifiers_all(&s->smmu_state); - smmu_iotlb_inv_asid_vmid(bs, asid, vmid); + smmu_iotlb_inv_asid_vmid(bs, asid, vmid, sec_sid); if (!smmuv3_accel_issue_inv_cmd(s, &cmd, NULL, errp)) { cmd_error =3D SMMU_CERROR_ILL; break; @@ -1542,8 +1553,8 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error = **errp) */ if (STAGE2_SUPPORTED(s)) { vmid =3D CMD_VMID(&cmd); - trace_smmuv3_cmdq_tlbi_nh(vmid); - smmu_iotlb_inv_vmid_s1(bs, vmid); + trace_smmuv3_cmdq_tlbi_nh(sec_sid, vmid); + smmu_iotlb_inv_vmid_s1(bs, vmid, sec_sid); break; } QEMU_FALLTHROUGH; @@ -1563,7 +1574,7 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error = **errp) cmd_error =3D SMMU_CERROR_ILL; break; } - smmuv3_range_inval(bs, &cmd, SMMU_STAGE_1); + smmuv3_range_inval(bs, &cmd, SMMU_STAGE_1, SMMU_SEC_SID_NS); if (!smmuv3_accel_issue_inv_cmd(s, &cmd, NULL, errp)) { cmd_error =3D SMMU_CERROR_ILL; break; @@ -1580,7 +1591,7 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error = **errp) =20 trace_smmuv3_cmdq_tlbi_s12_vmid(vmid); smmu_inv_notifiers_all(&s->smmu_state); - smmu_iotlb_inv_vmid(bs, vmid); + smmu_iotlb_inv_vmid(bs, vmid, SMMU_SEC_SID_NS); break; } case SMMU_CMD_TLBI_S2_IPA: @@ -1592,7 +1603,7 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error = **errp) * As currently only either s1 or s2 are supported * we can reuse same function for s2. */ - smmuv3_range_inval(bs, &cmd, SMMU_STAGE_2); + smmuv3_range_inval(bs, &cmd, SMMU_STAGE_2, SMMU_SEC_SID_NS); break; case SMMU_CMD_ATC_INV: { diff --git a/hw/arm/trace-events b/hw/arm/trace-events index 50fe4af07c5..3cbb32e917b 100644 --- a/hw/arm/trace-events +++ b/hw/arm/trace-events @@ -19,16 +19,16 @@ smmu_ptw_page_pte(int stage, int level, uint64_t iova,= uint64_t baseaddr, uint6 smmu_ptw_block_pte(int stage, int level, uint64_t baseaddr, uint64_t ptead= dr, uint64_t pte, uint64_t iova, uint64_t gpa, int bsize_mb) "stage=3D%d le= vel=3D%d base@=3D0x%"PRIx64" pte@=3D0x%"PRIx64" pte=3D0x%"PRIx64" iova=3D0x= %"PRIx64" block address =3D 0x%"PRIx64" block size =3D %d MiB" smmu_get_pte(uint64_t baseaddr, int index, uint64_t pteaddr, uint64_t pte)= "baseaddr=3D0x%"PRIx64" index=3D0x%x, pteaddr=3D0x%"PRIx64", pte=3D0x%"PRI= x64 smmu_iotlb_inv_all(void) "IOTLB invalidate all" -smmu_iotlb_inv_asid_vmid(int asid, int vmid) "IOTLB invalidate asid=3D%d v= mid=3D%d" -smmu_iotlb_inv_vmid(int vmid) "IOTLB invalidate vmid=3D%d" -smmu_iotlb_inv_vmid_s1(int vmid) "IOTLB invalidate vmid=3D%d" -smmu_iotlb_inv_iova(int asid, uint64_t addr) "IOTLB invalidate asid=3D%d a= ddr=3D0x%"PRIx64 +smmu_iotlb_inv_asid_vmid(int sec_sid, int asid, int vmid) "IOTLB invalidat= e sec_sid=3D%d asid=3D%d vmid=3D%d" +smmu_iotlb_inv_vmid(int sec_sid, int vmid) "IOTLB invalidate sec_sid=3D%d = vmid=3D%d" +smmu_iotlb_inv_vmid_s1(int sec_sid, int vmid) "IOTLB invalidate S1 sec_sid= =3D%d vmid=3D%d" +smmu_iotlb_inv_iova(int sec_sid, int asid, uint64_t addr) "IOTLB invalidat= e sec_sid=3D%d asid=3D%d addr=3D0x%"PRIx64 smmu_configs_inv_sid_range(uint32_t start, uint32_t end) "Config cache INV= SID range from 0x%x to 0x%x" smmu_config_cache_inv(uint32_t sid) "Config cache INV for sid=3D0x%x" smmu_inv_notifiers_mr(const char *name) "iommu mr=3D%s" -smmu_iotlb_lookup_hit(int asid, int vmid, uint64_t addr, uint32_t hit, uin= t32_t miss, uint32_t p) "IOTLB cache HIT asid=3D%d vmid=3D%d addr=3D0x%"PRI= x64" hit=3D%d miss=3D%d hit rate=3D%d" -smmu_iotlb_lookup_miss(int asid, int vmid, uint64_t addr, uint32_t hit, ui= nt32_t miss, uint32_t p) "IOTLB cache MISS asid=3D%d vmid=3D%d addr=3D0x%"P= RIx64" hit=3D%d miss=3D%d hit rate=3D%d" -smmu_iotlb_insert(int asid, int vmid, uint64_t addr, uint8_t tg, uint8_t l= evel) "IOTLB ++ asid=3D%d vmid=3D%d addr=3D0x%"PRIx64" tg=3D%d level=3D%d" +smmu_iotlb_lookup_hit(int sec_sid, int asid, int vmid, uint64_t addr, uint= 32_t hit, uint32_t miss, uint32_t p) "IOTLB cache HIT sec_sid=3D%d asid=3D%= d vmid=3D%d addr=3D0x%"PRIx64" hit=3D%d miss=3D%d hit rate=3D%d" +smmu_iotlb_lookup_miss(int sec_sid, int asid, int vmid, uint64_t addr, uin= t32_t hit, uint32_t miss, uint32_t p) "IOTLB cache MISS sec_sid=3D%d asid= =3D%d vmid=3D%d addr=3D0x%"PRIx64" hit=3D%d miss=3D%d hit rate=3D%d" +smmu_iotlb_insert(int sec_sid, int asid, int vmid, uint64_t addr, uint8_t = tg, uint8_t level) "IOTLB ++ sec_sid=3D%d asid=3D%d vmid=3D%d addr=3D0x%"PR= Ix64" tg=3D%d level=3D%d" =20 # smmuv3.c smmuv3_read_mmio(uint64_t addr, uint64_t val, unsigned size, uint32_t r) "= addr: 0x%"PRIx64" val:0x%"PRIx64" size: 0x%x(%d)" @@ -57,10 +57,10 @@ smmuv3_cmdq_cfgi_ste_range(int start, int end) "start= =3D0x%x - end=3D0x%x" smmuv3_cmdq_cfgi_cd(uint32_t sid) "sid=3D0x%x" smmuv3_config_cache_hit(uint32_t sid, uint32_t hits, uint32_t misses, uint= 32_t perc) "Config cache HIT for sid=3D0x%x (hits=3D%d, misses=3D%d, hit ra= te=3D%d)" smmuv3_config_cache_miss(uint32_t sid, uint32_t hits, uint32_t misses, uin= t32_t perc) "Config cache MISS for sid=3D0x%x (hits=3D%d, misses=3D%d, hit = rate=3D%d)" -smmuv3_range_inval(int vmid, int asid, uint64_t addr, uint8_t tg, uint64_t= num_pages, uint8_t ttl, bool leaf, int stage) "vmid=3D%d asid=3D%d addr=3D= 0x%"PRIx64" tg=3D%d num_pages=3D0x%"PRIx64" ttl=3D%d leaf=3D%d stage=3D%d" -smmuv3_cmdq_tlbi_nh(int vmid) "vmid=3D%d" +smmuv3_range_inval(int sec_sid, int vmid, int asid, uint64_t addr, uint8_t= tg, uint64_t num_pages, uint8_t ttl, bool leaf, int stage) "sec_sid=3D%d v= mid=3D%d asid=3D%d addr=3D0x%"PRIx64" tg=3D%d num_pages=3D0x%"PRIx64" ttl= =3D%d leaf=3D%d stage=3D%d" +smmuv3_cmdq_tlbi_nh(int sec_sid, int vmid) "sec_sid=3D%d vmid=3D%d" smmuv3_cmdq_tlbi_nsnh(void) "" -smmuv3_cmdq_tlbi_nh_asid(int asid) "asid=3D%d" +smmuv3_cmdq_tlbi_nh_asid(int sec_sid, int asid) "sec_sid=3D%d asid=3D%d" smmuv3_cmdq_tlbi_s12_vmid(int vmid) "vmid=3D%d" smmuv3_notify_flag_add(const char *iommu) "ADD SMMUNotifier node for iommu= mr=3D%s" smmuv3_notify_flag_del(const char *iommu) "DEL SMMUNotifier node for iommu= mr=3D%s" --=20 2.34.1 From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794673134001549.4661239143244; Sat, 14 Nov 2026 08:18:54 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGSi-0007Ic-Uf; Sat, 14 Nov 2026 11:18:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGSE-00078c-21; Sat, 14 Nov 2026 11:18:18 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGS8-0003Dx-8H; Sat, 14 Nov 2026 11:18:13 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-7 (Coremail) with UTF8SMTP id AQAAfwC3vqa2ifhql1kqBg--.58977S2; Sun, 15 Nov 2026 00:17:58 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8DwOHSyifhq4Nv6AA--.29617S6; Sun, 15 Nov 2026 00:17:57 +0800 (CST) From: Tao Tang To: Peter Maydell , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 13/35] hw/arm/smmuv3: Pass sec_sid into cmdq consume path Date: Sun, 15 Nov 2026 00:17:47 +0800 Message-Id: <20261114161753.3645568-4-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8DwOHSyifhq4Nv6AA--.29617S6 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBdgABsS Authentication-Results: hzbj-icmmx-7; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvJXoWxtFW3uF15KF4UXw13Ww15Jwb_yoWxWFyUpr WDJ3sI9r18X3Z3ZF9Iv3y8uFy3J34Dtry3tr1UW3Wfu3WDAr15Xrs8Kr1ru34DGr97Aws3 Way3uan8Z3W2y37anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAU7a7-sFnT9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUU UUUUU Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794674036882154100 Content-Type: text/plain; charset="utf-8" Make smmuv3_cmdq_consume() security-state aware by passing sec_sid from smmu_writel() call sites (CR0/GERRORN/CMDQ_PROD paths), instead of hardcoding Non-secure state. The related AddressSpace and MemTxAttrs are also obtained based on sec_sid. Also move CMD_SSEC legality checking to a single early check before command dispatch: Secure commands are rejected on Non-secure queues (including future Realm queue) with CERROR_ILL. This removes duplicated per-command checks in CFGI handlers. Finally, extend cmdq trace output with sec_sid so command processing can be correlated with the correct security bank. Signed-off-by: Tao Tang Reviewed-by: Eric Auger Reviewed-by: Pierrick Bouvier Reviewed-by: Jim MacArthur Reviewed-by: Mostafa Saleh --- hw/arm/smmuv3.c | 47 +++++++++++++++++++++------------------------ hw/arm/trace-events | 2 +- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 63a77368035..55b3970bbf2 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -112,14 +112,14 @@ static void smmuv3_write_gerrorn(SMMUv3State *s, uint= 32_t new_gerrorn) trace_smmuv3_write_gerrorn(toggled & pending, bank->gerrorn); } =20 -static inline MemTxResult queue_read(SMMUQueue *q, Cmd *cmd) +static inline MemTxResult queue_read(SMMUQueue *q, Cmd *cmd, + AddressSpace *as, MemTxAttrs attrs) { dma_addr_t addr =3D Q_CONS_ENTRY(q); MemTxResult ret; int i; =20 - ret =3D dma_memory_read(&address_space_memory, addr, cmd, sizeof(Cmd), - MEMTXATTRS_UNSPECIFIED); + ret =3D dma_memory_read(as, addr, cmd, sizeof(Cmd), attrs); if (ret !=3D MEMTX_OK) { return ret; } @@ -1384,14 +1384,15 @@ static void smmuv3_range_inval(SMMUState *s, Cmd *c= md, SMMUStage stage, } } =20 -static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp) +static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp, SMMUSecSID se= c_sid) { SMMUState *bs =3D ARM_SMMU(s); SMMUCmdError cmd_error =3D SMMU_CERROR_NONE; - SMMUSecSID sec_sid =3D SMMU_SEC_SID_NS; SMMUv3RegBank *bank =3D smmuv3_bank(s, sec_sid); SMMUQueue *q =3D &bank->cmdq; SMMUCommandType type =3D 0; + MemTxAttrs attrs =3D smmu_get_txattrs(sec_sid); + AddressSpace *as =3D smmu_get_address_space(bs, sec_sid); =20 if (!smmuv3_cmdq_enabled(s, sec_sid)) { return 0; @@ -1406,19 +1407,30 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Erro= r **errp) while (!smmuv3_q_empty(q)) { uint32_t pending =3D bank->gerror ^ bank->gerrorn; Cmd cmd; + SMMUSecSID ssec =3D SMMU_SEC_SID_NS; =20 - trace_smmuv3_cmdq_consume(Q_PROD(q), Q_CONS(q), + trace_smmuv3_cmdq_consume(sec_sid, Q_PROD(q), Q_CONS(q), Q_PROD_WRAP(q), Q_CONS_WRAP(q)); =20 if (FIELD_EX32(pending, GERROR, CMDQ_ERR)) { break; } =20 - if (queue_read(q, &cmd) !=3D MEMTX_OK) { + if (queue_read(q, &cmd, as, attrs) !=3D MEMTX_OK) { cmd_error =3D SMMU_CERROR_ABT; break; } =20 + ssec =3D CMD_SSEC(&cmd) ? SMMU_SEC_SID_S : SMMU_SEC_SID_NS; + /* + * A command with SSec =3D=3D 1 is illegal on Non-secure and Realm= Command + * queues and raises CERROR_ILL, as specified by (IHI 0070G.b) 4.1= .6. + */ + if (ssec && sec_sid !=3D SMMU_SEC_SID_S) { + cmd_error =3D SMMU_CERROR_ILL; + break; + } + type =3D CMD_TYPE(&cmd); =20 trace_smmuv3_cmdq_opcode(smmu_cmd_string(type)); @@ -1438,11 +1450,6 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error= **errp) uint32_t sid =3D CMD_SID(&cmd); SMMUDevice *sdev =3D smmu_find_sdev(bs, sid); =20 - if (CMD_SSEC(&cmd)) { - cmd_error =3D SMMU_CERROR_ILL; - break; - } - if (!sdev) { break; } @@ -1462,11 +1469,6 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error= **errp) uint8_t range =3D CMD_STE_RANGE(&cmd); SMMUSIDRange sid_range; =20 - if (CMD_SSEC(&cmd)) { - cmd_error =3D SMMU_CERROR_ILL; - break; - } - mask =3D (1ULL << (range + 1)) - 1; sid_range.start =3D sid & ~mask; sid_range.end =3D sid_range.start + mask; @@ -1485,11 +1487,6 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error= **errp) uint32_t sid =3D CMD_SID(&cmd); SMMUDevice *sdev =3D smmu_find_sdev(bs, sid); =20 - if (CMD_SSEC(&cmd)) { - cmd_error =3D SMMU_CERROR_ILL; - break; - } - if (!sdev) { break; } @@ -1713,7 +1710,7 @@ static MemTxResult smmu_writel(SMMUv3State *s, hwaddr= offset, bank->cr[0] =3D data; bank->cr0ack =3D data & ~SMMU_CR0_RESERVED; /* in case the command queue has been enabled */ - smmuv3_cmdq_consume(s, &local_err); + smmuv3_cmdq_consume(s, &local_err, reg_sec_sid); if (local_err) { error_report_err(local_err); local_err =3D NULL; @@ -1736,7 +1733,7 @@ static MemTxResult smmu_writel(SMMUv3State *s, hwaddr= offset, * By acknowledging the CMDQ_ERR, SW may notify cmds can * be processed again */ - smmuv3_cmdq_consume(s, &local_err); + smmuv3_cmdq_consume(s, &local_err, reg_sec_sid); break; case A_GERROR_IRQ_CFG0: /* 64b */ bank->gerror_irq_cfg0 =3D deposit64(bank->gerror_irq_cfg0, 0, 32, = data); @@ -1794,7 +1791,7 @@ static MemTxResult smmu_writel(SMMUv3State *s, hwaddr= offset, break; case A_CMDQ_PROD: bank->cmdq.prod =3D data; - smmuv3_cmdq_consume(s, &local_err); + smmuv3_cmdq_consume(s, &local_err, reg_sec_sid); break; case A_CMDQ_CONS: bank->cmdq.cons =3D data; diff --git a/hw/arm/trace-events b/hw/arm/trace-events index 3cbb32e917b..8a14daa9252 100644 --- a/hw/arm/trace-events +++ b/hw/arm/trace-events @@ -36,7 +36,7 @@ smmuv3_trigger_irq(int irq) "irq=3D%d" smmuv3_write_gerror(uint32_t toggled, uint32_t gerror) "toggled=3D0x%x, ne= w GERROR=3D0x%x" smmuv3_write_gerrorn(uint32_t acked, uint32_t gerrorn) "acked=3D0x%x, new = GERRORN=3D0x%x" smmuv3_unhandled_cmd(uint32_t type) "Unhandled command type=3D%d" -smmuv3_cmdq_consume(uint32_t prod, uint32_t cons, uint8_t prod_wrap, uint8= _t cons_wrap) "prod=3D%d cons=3D%d prod.wrap=3D%d cons.wrap=3D%d" +smmuv3_cmdq_consume(int sec_sid, uint32_t prod, uint32_t cons, uint8_t pro= d_wrap, uint8_t cons_wrap) "sec_sid=3D%d prod=3D%d cons=3D%d prod.wrap=3D%d= cons.wrap=3D%d" smmuv3_cmdq_opcode(const char *opcode) "<--- %s" smmuv3_cmdq_consume_out(uint32_t prod, uint32_t cons, uint8_t prod_wrap, u= int8_t cons_wrap) "prod:%d, cons:%d, prod_wrap:%d, cons_wrap:%d " smmuv3_cmdq_consume_error(const char *cmd_name, uint8_t cmd_error) "Error = on %s command execution: %d" --=20 2.34.1 From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794673137698910.2300642637846; Sat, 14 Nov 2026 08:18:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGSo-0007O9-9Z; Sat, 14 Nov 2026 11:18:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGSD-00078Y-NM; Sat, 14 Nov 2026 11:18:22 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGS8-0003E1-7a; Sat, 14 Nov 2026 11:18:13 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-7 (Coremail) with UTF8SMTP id AQAAfwDHz6e3ifhquVkqBg--.31412S2; Sun, 15 Nov 2026 00:17:59 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8DwOHSyifhq4Nv6AA--.29617S7; Sun, 15 Nov 2026 00:17:58 +0800 (CST) From: Tao Tang To: Peter Maydell , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 14/35] hw/arm/smmuv3: Make evtq producer use SEC_SID Date: Sun, 15 Nov 2026 00:17:48 +0800 Message-Id: <20261114161753.3645568-5-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8DwOHSyifhq4Nv6AA--.29617S7 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBeAAAsd Authentication-Results: hzbj-icmmx-7; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvJXoW7ZF4xAFy7XF1rXF4xtryxKrg_yoW8uF48pr Z0k3s5KryFyFs3JF95Zrs5u3W7u3yIqr13GrZ7Ka45uw1UAr1aqF1UKryFkryvqrZ7J3y5 uFWxCa15Zw15t3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAU7a7-sFnT9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUU UUUUU Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794673139966154100 Content-Type: text/plain; charset="utf-8" The event queue producer path wrote entries through address_space_memory with MEMTXATTRS_UNSPECIFIED, so produced entries did not use the sec_sid-selected DMA context. Pass AddressSpace and MemTxAttrs to queue_write() based on sec_sid. Signed-off-by: Tao Tang Reviewed-by: Eric Auger Reviewed-by: Pierrick Bouvier Reviewed-by: Jim MacArthur Reviewed-by: Mostafa Saleh --- hw/arm/smmuv3.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 55b3970bbf2..f7ca3859bc2 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -129,7 +129,8 @@ static inline MemTxResult queue_read(SMMUQueue *q, Cmd = *cmd, return ret; } =20 -static MemTxResult queue_write(SMMUQueue *q, Evt *evt_in) +static MemTxResult queue_write(SMMUQueue *q, Evt *evt_in, + AddressSpace *as, MemTxAttrs attrs) { dma_addr_t addr =3D Q_PROD_ENTRY(q); MemTxResult ret; @@ -139,8 +140,7 @@ static MemTxResult queue_write(SMMUQueue *q, Evt *evt_i= n) for (i =3D 0; i < ARRAY_SIZE(evt.word); i++) { cpu_to_le32s(&evt.word[i]); } - ret =3D dma_memory_write(&address_space_memory, addr, &evt, sizeof(Evt= ), - MEMTXATTRS_UNSPECIFIED); + ret =3D dma_memory_write(as, addr, &evt, sizeof(Evt), attrs); if (ret !=3D MEMTX_OK) { return ret; } @@ -155,6 +155,9 @@ static MemTxResult smmuv3_write_eventq(SMMUv3State *s, = SMMUSecSID sec_sid, SMMUv3RegBank *bank =3D smmuv3_bank(s, sec_sid); SMMUQueue *q =3D &bank->eventq; MemTxResult r; + SMMUState *bs =3D ARM_SMMU(s); + MemTxAttrs txattrs =3D smmu_get_txattrs(sec_sid); + AddressSpace *as =3D smmu_get_address_space(bs, sec_sid); =20 if (!smmuv3_eventq_enabled(s, sec_sid)) { return MEMTX_ERROR; @@ -164,7 +167,7 @@ static MemTxResult smmuv3_write_eventq(SMMUv3State *s, = SMMUSecSID sec_sid, return MEMTX_ERROR; } =20 - r =3D queue_write(q, evt); + r =3D queue_write(q, evt, as, txattrs); if (r !=3D MEMTX_OK) { return r; } --=20 2.34.1 From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794673258053407.39129550839914; Sat, 14 Nov 2026 08:20:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGT4-0007mB-OV; Sat, 14 Nov 2026 11:19:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGSE-00078q-S5; Sat, 14 Nov 2026 11:18:22 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGS8-0003E5-AT; Sat, 14 Nov 2026 11:18:14 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-7 (Coremail) with UTF8SMTP id AQAAfwAXTaW4ifhqylkqBg--.44579S2; Sun, 15 Nov 2026 00:18:00 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8DwOHSyifhq4Nv6AA--.29617S8; Sun, 15 Nov 2026 00:17:59 +0800 (CST) From: Tao Tang To: Peter Maydell , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 15/35] hw/arm/smmuv3: Limit IOMMU notifications to Non-secure targets Date: Sun, 15 Nov 2026 00:17:49 +0800 Message-Id: <20261114161753.3645568-6-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8DwOHSyifhq4Nv6AA--.29617S8 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBegAAsf Authentication-Results: hzbj-icmmx-7; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvJXoWxWF4fKFyfZr15Jw1kXF48tFb_yoWrJFy8pr 47KrZ5urZ8Aa93Ja12vw4UCFy3Xw1qkryrtrW5WF95t3WDJryaqFWkGryYkryDCr1UZrZ3 Z3yUWF43ua17t3DanT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAU7a7-sFnT9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUU UUUUU Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794673259303154100 Content-Type: text/plain; charset="utf-8" IOMMU notifiers are supported only for Non-secure devices. Add a wrapper for full invalidation notifications and filter range notifications by the target SEC_SID before walking the registered notifier list. Keep the underlying common notifier helpers unchanged. Command handlers can then select whether to notify according to the invalidation target. Signed-off-by: Tao Tang --- hw/arm/smmuv3.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index f7ca3859bc2..ce00461210b 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -1307,10 +1307,16 @@ static void smmuv3_notify_iova(IOMMUMemoryRegion *m= r, /* invalidate an asid/vmid/iova range tuple in all mr's */ static void smmuv3_inv_notifiers_iova(SMMUState *s, int asid, int vmid, dma_addr_t iova, uint8_t tg, - uint64_t num_pages, int stage) + uint64_t num_pages, int stage, + SMMUSecSID sec_sid) { SMMUDevice *sdev; =20 + /* IOMMU notifiers are supported only for Non-secure devices. */ + if (sec_sid !=3D SMMU_SEC_SID_NS) { + return; + } + QLIST_FOREACH(sdev, &s->devices_with_notifiers, next) { IOMMUMemoryRegion *mr =3D &sdev->iommu; IOMMUNotifier *n; @@ -1324,6 +1330,14 @@ static void smmuv3_inv_notifiers_iova(SMMUState *s, = int asid, int vmid, } } =20 +static void smmuv3_inv_notifiers_all(SMMUState *s, SMMUSecSID sec_sid) +{ + /* IOMMU notifiers are supported only for Non-secure devices. */ + if (sec_sid =3D=3D SMMU_SEC_SID_NS) { + smmu_inv_notifiers_all(s); + } +} + static void smmuv3_range_inval(SMMUState *s, Cmd *cmd, SMMUStage stage, SMMUSecSID sec_sid) { @@ -1352,7 +1366,8 @@ static void smmuv3_range_inval(SMMUState *s, Cmd *cmd= , SMMUStage stage, if (!tg) { trace_smmuv3_range_inval(sec_sid, vmid, asid, addr, tg, 1, ttl, leaf, stage); - smmuv3_inv_notifiers_iova(s, asid, vmid, addr, tg, 1, stage); + smmuv3_inv_notifiers_iova(s, asid, vmid, addr, tg, 1, stage, + sec_sid); if (stage =3D=3D SMMU_STAGE_1) { smmu_iotlb_inv_iova(s, asid, vmid, addr, tg, 1, ttl, sec_sid); } else { @@ -1376,7 +1391,7 @@ static void smmuv3_range_inval(SMMUState *s, Cmd *cmd= , SMMUStage stage, trace_smmuv3_range_inval(sec_sid, vmid, asid, addr, tg, num_pages, ttl, leaf, stage); smmuv3_inv_notifiers_iova(s, asid, vmid, addr, tg, - num_pages, stage); + num_pages, stage, sec_sid); if (stage =3D=3D SMMU_STAGE_1) { smmu_iotlb_inv_iova(s, asid, vmid, addr, tg, num_pages, ttl, sec_sid); @@ -1530,7 +1545,7 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error = **errp, SMMUSecSID sec_sid) } =20 trace_smmuv3_cmdq_tlbi_nh_asid(sec_sid, asid); - smmu_inv_notifiers_all(&s->smmu_state); + smmuv3_inv_notifiers_all(bs, sec_sid); smmu_iotlb_inv_asid_vmid(bs, asid, vmid, sec_sid); if (!smmuv3_accel_issue_inv_cmd(s, &cmd, NULL, errp)) { cmd_error =3D SMMU_CERROR_ILL; @@ -1561,7 +1576,7 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error = **errp, SMMUSecSID sec_sid) } case SMMU_CMD_TLBI_NSNH_ALL: trace_smmuv3_cmdq_tlbi_nsnh(); - smmu_inv_notifiers_all(&s->smmu_state); + smmuv3_inv_notifiers_all(bs, SMMU_SEC_SID_NS); smmu_iotlb_inv_all(bs); if (!smmuv3_accel_issue_inv_cmd(s, &cmd, NULL, errp)) { cmd_error =3D SMMU_CERROR_ILL; @@ -1590,7 +1605,7 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error = **errp, SMMUSecSID sec_sid) } =20 trace_smmuv3_cmdq_tlbi_s12_vmid(vmid); - smmu_inv_notifiers_all(&s->smmu_state); + smmuv3_inv_notifiers_all(bs, SMMU_SEC_SID_NS); smmu_iotlb_inv_vmid(bs, vmid, SMMU_SEC_SID_NS); break; } --=20 2.34.1 From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794673248230696.2464597900624; Sat, 14 Nov 2026 08:20:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGT4-0007lh-OA; Sat, 14 Nov 2026 11:19:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGSC-00078V-Mh; Sat, 14 Nov 2026 11:18:18 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGS8-0003E9-9K; Sat, 14 Nov 2026 11:18:12 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-7 (Coremail) with UTF8SMTP id AQAAfwDnHKW7ifhqNFoqBg--.64095S2; Sun, 15 Nov 2026 00:18:03 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8DwOHSyifhq4Nv6AA--.29617S9; Sun, 15 Nov 2026 00:18:00 +0800 (CST) From: Tao Tang To: Peter Maydell , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 16/35] hw/arm/smmuv3: Scope configuration invalidation by SEC_SID Date: Sun, 15 Nov 2026 00:17:50 +0800 Message-Id: <20261114161753.3645568-7-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8DwOHSyifhq4Nv6AA--.29617S9 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBfAAAsZ Authentication-Results: hzbj-icmmx-7; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvJXoW3uryrCryfAw13Wr4kZFW5Wrg_yoWDWw1Upr WUWr95Gr48JF93AFsxJay8ua15JwnF9F1rKryagr95A398Ar9rZr4DG3yYkr9rGr17Xrsr ZayxWa15ZryxZF7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAU7a7-sFnT9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUU UUUUU Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794673249335154100 Content-Type: text/plain; charset="utf-8" Configuration cache entries are keyed by device and SEC_SID, but command invalidation must also select the matching security state. Add SEC_SID-aware configuration cache invalidation helpers and use the command queue state and command SSec field when processing CFGI commands. Keep full-cache invalidation available for operations that require it. Include the issuing and target SEC_SID values in the affected traces. Signed-off-by: Tao Tang --- include/hw/arm/smmu-common.h | 5 +++ hw/arm/smmu-common.c | 82 +++++++++++++++++++++++++++++++++++- hw/arm/smmuv3.c | 18 ++++---- hw/arm/trace-events | 9 ++-- 4 files changed, 100 insertions(+), 14 deletions(-) diff --git a/include/hw/arm/smmu-common.h b/include/hw/arm/smmu-common.h index 8e971c28093..49b86cede47 100644 --- a/include/hw/arm/smmu-common.h +++ b/include/hw/arm/smmu-common.h @@ -280,7 +280,12 @@ void smmu_iotlb_inv_ipa(SMMUState *s, int vmid, dma_ad= dr_t ipa, uint8_t tg, uint64_t num_pages, uint8_t ttl, SMMUSecSID sec_sid); void smmu_configs_inv_sid_range(SMMUState *s, SMMUSIDRange sid_range); +void smmu_configs_inv_sid_range_by_sec_sid(SMMUState *s, + SMMUSIDRange sid_range, + SMMUSecSID sec_sid); void smmu_configs_inv_sdev(SMMUState *s, SMMUDevice *sdev); +void smmu_configs_inv_sdev_by_sec_sid(SMMUState *s, SMMUDevice *sdev, + SMMUSecSID sec_sid); /* Unmap the range of all the notifiers registered to any IOMMU mr */ void smmu_inv_notifiers_all(SMMUState *s); =20 diff --git a/hw/arm/smmu-common.c b/hw/arm/smmu-common.c index 9c172fbb765..f6ad89208ac 100644 --- a/hw/arm/smmu-common.c +++ b/hw/arm/smmu-common.c @@ -303,6 +303,16 @@ static gboolean smmu_hash_remove_by_vmid_ipa(gpointer = key, gpointer value, ((entry->iova & ~info->mask) =3D=3D info->iova); } =20 +typedef struct SMMUConfigInvRangeInfo { + SMMUSIDRange sid_range; + SMMUSecSID sec_sid; +} SMMUConfigInvRangeInfo; + +typedef struct SMMUConfigInvSdevInfo { + SMMUDevice *sdev; + SMMUSecSID sec_sid; +} SMMUConfigInvSdevInfo; + static gboolean smmu_hash_remove_by_sid_range(gpointer key, gpointer value, gpointer user_= data) { @@ -314,7 +324,26 @@ smmu_hash_remove_by_sid_range(gpointer key, gpointer v= alue, gpointer user_data) if (sid < sid_range->start || sid > sid_range->end) { return false; } - trace_smmu_config_cache_inv(sid); + trace_smmu_config_cache_inv(config_key->sec_sid, sid); + return true; +} + +static gboolean +smmu_hash_remove_by_sid_range_sec(gpointer key, gpointer value, + gpointer user_data) +{ + SMMUConfigKey *config_key =3D (SMMUConfigKey *)key; + SMMUConfigInvRangeInfo *info =3D (SMMUConfigInvRangeInfo *)user_data; + SMMUDevice *sdev =3D config_key->sdev; + uint32_t sid =3D smmu_get_sid(sdev); + + if (config_key->sec_sid !=3D info->sec_sid) { + return false; + } + if (sid < info->sid_range.start || sid > info->sid_range.end) { + return false; + } + trace_smmu_config_cache_inv(config_key->sec_sid, sid); return true; } =20 @@ -325,6 +354,23 @@ void smmu_configs_inv_sid_range(SMMUState *s, SMMUSIDR= ange sid_range) &sid_range); } =20 +void smmu_configs_inv_sid_range_by_sec_sid(SMMUState *s, + SMMUSIDRange sid_range, + SMMUSecSID sec_sid) +{ + SMMUConfigInvRangeInfo info =3D { + .sid_range =3D sid_range, + .sec_sid =3D sec_sid, + }; + + g_assert(sec_sid < SMMU_SEC_SID_NUM); + + trace_smmu_configs_inv_sid_range_by_sec_sid(sec_sid, sid_range.start, + sid_range.end); + g_hash_table_foreach_remove(s->configs, smmu_hash_remove_by_sid_range_= sec, + &info); +} + static gboolean smmu_hash_remove_by_sdev(gpointer key, gpointer value, gpointer user_data) { @@ -334,7 +380,25 @@ static gboolean smmu_hash_remove_by_sdev(gpointer key,= gpointer value, if (config_key->sdev !=3D target) { return false; } - trace_smmu_config_cache_inv(smmu_get_sid(target)); + trace_smmu_config_cache_inv(config_key->sec_sid, + smmu_get_sid(target)); + return true; +} + +static gboolean smmu_hash_remove_by_sdev_sec(gpointer key, gpointer value, + gpointer user_data) +{ + SMMUConfigKey *config_key =3D (SMMUConfigKey *)key; + SMMUConfigInvSdevInfo *info =3D (SMMUConfigInvSdevInfo *)user_data; + + if (config_key->sdev !=3D info->sdev) { + return false; + } + if (config_key->sec_sid !=3D info->sec_sid) { + return false; + } + trace_smmu_config_cache_inv(config_key->sec_sid, + smmu_get_sid(info->sdev)); return true; } =20 @@ -343,6 +407,20 @@ void smmu_configs_inv_sdev(SMMUState *s, SMMUDevice *s= dev) g_hash_table_foreach_remove(s->configs, smmu_hash_remove_by_sdev, sdev= ); } =20 +void smmu_configs_inv_sdev_by_sec_sid(SMMUState *s, SMMUDevice *sdev, + SMMUSecSID sec_sid) +{ + SMMUConfigInvSdevInfo info =3D { + .sdev =3D sdev, + .sec_sid =3D sec_sid, + }; + + g_assert(sec_sid < SMMU_SEC_SID_NUM); + + g_hash_table_foreach_remove(s->configs, smmu_hash_remove_by_sdev_sec, + &info); +} + void smmu_iotlb_inv_iova(SMMUState *s, int asid, int vmid, dma_addr_t iova, uint8_t tg, uint64_t num_pages, uint8_t ttl, SMMUSecSID sec_sid) diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index ce00461210b..41fa7271d8d 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -998,12 +998,13 @@ static SMMUTransCfg *smmuv3_get_config(SMMUDevice *sd= ev, SMMUEventInfo *event, return cfg; } =20 -static void smmuv3_flush_config(SMMUDevice *sdev) +static void smmuv3_flush_config_by_sec_sid(SMMUDevice *sdev, + SMMUSecSID sec_sid) { SMMUv3State *s =3D sdev->smmu; SMMUState *bc =3D &s->smmu_state; =20 - smmu_configs_inv_sdev(bc, sdev); + smmu_configs_inv_sdev_by_sec_sid(bc, sdev, sec_sid); } =20 /* Do translation with TLB lookup. */ @@ -1472,12 +1473,12 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Erro= r **errp, SMMUSecSID sec_sid) break; } =20 - trace_smmuv3_cmdq_cfgi_ste(sid); + trace_smmuv3_cmdq_cfgi_ste(sec_sid, ssec, sid); if (!smmuv3_accel_install_ste(s, sdev, sid, errp)) { cmd_error =3D SMMU_CERROR_ILL; break; } - smmuv3_flush_config(sdev); + smmuv3_flush_config_by_sec_sid(sdev, ssec); =20 break; } @@ -1491,12 +1492,13 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Erro= r **errp, SMMUSecSID sec_sid) sid_range.start =3D sid & ~mask; sid_range.end =3D sid_range.start + mask; =20 - trace_smmuv3_cmdq_cfgi_ste_range(sid_range.start, sid_range.en= d); + trace_smmuv3_cmdq_cfgi_ste_range(sec_sid, ssec, + sid_range.start, sid_range.en= d); if (!smmuv3_accel_install_ste_range(s, &sid_range, errp)) { cmd_error =3D SMMU_CERROR_ILL; break; } - smmu_configs_inv_sid_range(bs, sid_range); + smmu_configs_inv_sid_range_by_sec_sid(bs, sid_range, ssec); break; } case SMMU_CMD_CFGI_CD: @@ -1518,8 +1520,8 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error = **errp, SMMUSecSID sec_sid) break; } =20 - trace_smmuv3_cmdq_cfgi_cd(sid); - smmuv3_flush_config(sdev); + trace_smmuv3_cmdq_cfgi_cd(sec_sid, ssec, sid); + smmuv3_flush_config_by_sec_sid(sdev, ssec); if (!smmuv3_accel_issue_inv_cmd(s, &cmd, sdev, errp)) { cmd_error =3D SMMU_CERROR_ILL; break; diff --git a/hw/arm/trace-events b/hw/arm/trace-events index 8a14daa9252..ea525a81b3f 100644 --- a/hw/arm/trace-events +++ b/hw/arm/trace-events @@ -24,7 +24,8 @@ smmu_iotlb_inv_vmid(int sec_sid, int vmid) "IOTLB invalid= ate sec_sid=3D%d vmid=3D%d" smmu_iotlb_inv_vmid_s1(int sec_sid, int vmid) "IOTLB invalidate S1 sec_sid= =3D%d vmid=3D%d" smmu_iotlb_inv_iova(int sec_sid, int asid, uint64_t addr) "IOTLB invalidat= e sec_sid=3D%d asid=3D%d addr=3D0x%"PRIx64 smmu_configs_inv_sid_range(uint32_t start, uint32_t end) "Config cache INV= SID range from 0x%x to 0x%x" -smmu_config_cache_inv(uint32_t sid) "Config cache INV for sid=3D0x%x" +smmu_configs_inv_sid_range_by_sec_sid(int sec_sid, uint32_t start, uint32_= t end) "Config cache INV sec_sid=3D%d SID range from 0x%x to 0x%x" +smmu_config_cache_inv(int sec_sid, uint32_t sid) "Config cache INV sec_sid= =3D%d sid=3D0x%x" smmu_inv_notifiers_mr(const char *name) "iommu mr=3D%s" smmu_iotlb_lookup_hit(int sec_sid, int asid, int vmid, uint64_t addr, uint= 32_t hit, uint32_t miss, uint32_t p) "IOTLB cache HIT sec_sid=3D%d asid=3D%= d vmid=3D%d addr=3D0x%"PRIx64" hit=3D%d miss=3D%d hit rate=3D%d" smmu_iotlb_lookup_miss(int sec_sid, int asid, int vmid, uint64_t addr, uin= t32_t hit, uint32_t miss, uint32_t p) "IOTLB cache MISS sec_sid=3D%d asid= =3D%d vmid=3D%d addr=3D0x%"PRIx64" hit=3D%d miss=3D%d hit rate=3D%d" @@ -52,9 +53,9 @@ smmuv3_translate_success(const char *n, uint16_t sid, uin= t64_t iova, uint64_t tr smmuv3_get_cd(uint64_t addr) "CD addr: 0x%"PRIx64 smmuv3_decode_cd(uint32_t oas) "oas=3D%d" smmuv3_decode_cd_tt(int i, uint32_t tsz, uint64_t ttb, uint32_t granule_sz= , bool had) "TT[%d]:tsz:%d ttb:0x%"PRIx64" granule_sz:%d had:%d" -smmuv3_cmdq_cfgi_ste(int streamid) "streamid=3D 0x%x" -smmuv3_cmdq_cfgi_ste_range(int start, int end) "start=3D0x%x - end=3D0x%x" -smmuv3_cmdq_cfgi_cd(uint32_t sid) "sid=3D0x%x" +smmuv3_cmdq_cfgi_ste(int sec_sid, int ssec, int streamid) "cmdq_sec_sid=3D= %d ssec=3D%d streamid=3D0x%x" +smmuv3_cmdq_cfgi_ste_range(int sec_sid, int ssec, int start, int end) "cmd= q_sec_sid=3D%d ssec=3D%d start=3D0x%x - end=3D0x%x" +smmuv3_cmdq_cfgi_cd(int sec_sid, int ssec, uint32_t sid) "cmdq_sec_sid=3D%= d ssec=3D%d sid=3D0x%x" smmuv3_config_cache_hit(uint32_t sid, uint32_t hits, uint32_t misses, uint= 32_t perc) "Config cache HIT for sid=3D0x%x (hits=3D%d, misses=3D%d, hit ra= te=3D%d)" smmuv3_config_cache_miss(uint32_t sid, uint32_t hits, uint32_t misses, uin= t32_t perc) "Config cache MISS for sid=3D0x%x (hits=3D%d, misses=3D%d, hit = rate=3D%d)" smmuv3_range_inval(int sec_sid, int vmid, int asid, uint64_t addr, uint8_t= tg, uint64_t num_pages, uint8_t ttl, bool leaf, int stage) "sec_sid=3D%d v= mid=3D%d asid=3D%d addr=3D0x%"PRIx64" tg=3D%d num_pages=3D0x%"PRIx64" ttl= =3D%d leaf=3D%d stage=3D%d" --=20 2.34.1 From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794673215998416.9447732527269; Sat, 14 Nov 2026 08:20:15 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGTH-00005s-Ht; Sat, 14 Nov 2026 11:19:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGSE-00078d-5o; Sat, 14 Nov 2026 11:18:22 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGS8-0003ED-90; Sat, 14 Nov 2026 11:18:13 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-6 (Coremail) with UTF8SMTP id AQAAfwDHz1u7ifhqNRoGAg--.42322S2; Sun, 15 Nov 2026 00:18:03 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8DwOHSyifhq4Nv6AA--.29617S10; Sun, 15 Nov 2026 00:18:00 +0800 (CST) From: Tao Tang To: Peter Maydell , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 17/35] hw/arm/smmuv3: Scope IOTLB invalidation by SEC_SID Date: Sun, 15 Nov 2026 00:17:51 +0800 Message-Id: <20261114161753.3645568-8-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8DwOHSyifhq4Nv6AA--.29617S10 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBfAABsY Authentication-Results: hzbj-icmmx-6; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvJXoWxKF45XrW5JF4xGr13CrykXwb_yoWfAw18pr WUur95Gr15AF93ZasrAw48ua13Xw1DKry5Kr90gF9Yya4kAryUZr4DCw15Ar95Wr15Crsx Z3yUWr45ZF17ZrJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAU7a7-sFnT9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUU UUUUU Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794673218875154100 Content-Type: text/plain; charset="utf-8" IOTLB invalidation must select the security state represented in the cache key. Add SEC_SID matching to the invalidation helpers and propagate the command queue or command-selected state through TLBI handling. Select stage-2 capability from the issuing command queue when deciding whether to match VMID, including SEL2 for the Secure command queue. Preserve full-cache invalidation for operations that require it and include SEC_SID in the affected invalidation traces. Signed-off-by: Tao Tang --- include/hw/arm/smmu-common.h | 1 + hw/arm/smmu-common.c | 18 +++++++++++ hw/arm/smmuv3.c | 62 +++++++++++++++++++++++++++++------- hw/arm/trace-events | 3 +- 4 files changed, 71 insertions(+), 13 deletions(-) diff --git a/include/hw/arm/smmu-common.h b/include/hw/arm/smmu-common.h index 49b86cede47..a21c6061808 100644 --- a/include/hw/arm/smmu-common.h +++ b/include/hw/arm/smmu-common.h @@ -269,6 +269,7 @@ SMMUIOTLBKey smmu_get_iotlb_key(int asid, int vmid, uin= t64_t iova, uint8_t tg, uint8_t level, SMMUSecSID sec_= sid); SMMUConfigKey smmu_get_config_key(SMMUDevice *sdev, SMMUSecSID sec_sid); void smmu_iotlb_inv_all(SMMUState *s); +void smmu_iotlb_inv_by_sec_sid(SMMUState *s, SMMUSecSID sec_sid); void smmu_iotlb_inv_asid_vmid(SMMUState *s, int asid, int vmid, SMMUSecSID sec_sid); void smmu_iotlb_inv_vmid(SMMUState *s, int vmid, SMMUSecSID sec_sid); diff --git a/hw/arm/smmu-common.c b/hw/arm/smmu-common.c index f6ad89208ac..0408fd25b3a 100644 --- a/hw/arm/smmu-common.c +++ b/hw/arm/smmu-common.c @@ -222,12 +222,30 @@ void smmu_iotlb_insert(SMMUState *bs, SMMUTransCfg *c= fg, SMMUTLBEntry *new, g_hash_table_insert(bs->iotlb, key, new); } =20 +static gboolean smmu_hash_remove_by_sec_sid(gpointer key, gpointer value, + gpointer user_data) +{ + SMMUIOTLBKey *iotlb_key =3D (SMMUIOTLBKey *)key; + SMMUSecSID *sec_sid =3D (SMMUSecSID *)user_data; + + return SMMU_IOTLB_SEC_SID(*iotlb_key) =3D=3D *sec_sid; +} + void smmu_iotlb_inv_all(SMMUState *s) { trace_smmu_iotlb_inv_all(); g_hash_table_remove_all(s->iotlb); } =20 +void smmu_iotlb_inv_by_sec_sid(SMMUState *s, SMMUSecSID sec_sid) +{ + g_assert(sec_sid < SMMU_SEC_SID_NUM); + + trace_smmu_iotlb_inv_by_sec_sid(sec_sid); + g_hash_table_foreach_remove(s->iotlb, smmu_hash_remove_by_sec_sid, + &sec_sid); +} + static gboolean smmu_hash_remove_by_asid_vmid(gpointer key, gpointer value, gpointer user_data) { diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 41fa7271d8d..fc5cd46d1a8 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -1340,7 +1340,7 @@ static void smmuv3_inv_notifiers_all(SMMUState *s, SM= MUSecSID sec_sid) } =20 static void smmuv3_range_inval(SMMUState *s, Cmd *cmd, SMMUStage stage, - SMMUSecSID sec_sid) + SMMUSecSID sec_sid, bool use_vmid) { dma_addr_t end, addr =3D CMD_ADDR(cmd); uint8_t type =3D CMD_TYPE(cmd); @@ -1353,10 +1353,8 @@ static void smmuv3_range_inval(SMMUState *s, Cmd *cm= d, SMMUStage stage, uint64_t num_pages; uint8_t granule; int asid =3D -1; - SMMUv3State *smmuv3 =3D ARM_SMMUV3(s); =20 - /* Only consider VMID if stage-2 is supported. */ - if (STAGE2_SUPPORTED(smmuv3)) { + if (use_vmid) { vmid =3D CMD_VMID(cmd); } =20 @@ -1403,6 +1401,26 @@ static void smmuv3_range_inval(SMMUState *s, Cmd *cm= d, SMMUStage stage, } } =20 +static inline bool +smmu_cmdq_stage2_supported(SMMUv3State *s, SMMUSecSID sec_sid) +{ + /* IDR0.S2P: Stage 2 translation supported */ + bool s2p =3D STAGE2_SUPPORTED(s); + if (!s2p) { + return false; + } + + /* + * For Secure Command queue, Secure stage 2 is additionally gated by S= EL2 + * (SEL2 is 0 if S2P is 0). + */ + if (sec_sid =3D=3D SMMU_SEC_SID_S) { + return FIELD_EX32(s->bank[SMMU_SEC_SID_S].idr[1], S_IDR1, SEL2); + } + + return true; +} + static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp, SMMUSecSID se= c_sid) { SMMUState *bs =3D ARM_SMMU(s); @@ -1412,6 +1430,7 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error = **errp, SMMUSecSID sec_sid) SMMUCommandType type =3D 0; MemTxAttrs attrs =3D smmu_get_txattrs(sec_sid); AddressSpace *as =3D smmu_get_address_space(bs, sec_sid); + bool queue_stage2_supported =3D smmu_cmdq_stage2_supported(s, sec_sid); =20 if (!smmuv3_cmdq_enabled(s, sec_sid)) { return 0; @@ -1542,7 +1561,7 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error = **errp, SMMUSecSID sec_sid) * VMID is only matched when stage 2 is supported, otherwise s= et it * to -1 as the value used for stage-1 only VMIDs. */ - if (STAGE2_SUPPORTED(s)) { + if (queue_stage2_supported) { vmid =3D CMD_VMID(&cmd); } =20 @@ -1568,30 +1587,49 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Erro= r **errp, SMMUSecSID sec_sid) * If stage-2 is supported, invalidate for this VMID only, oth= erwise * invalidate the whole thing. */ - if (STAGE2_SUPPORTED(s)) { + if (queue_stage2_supported) { vmid =3D CMD_VMID(&cmd); trace_smmuv3_cmdq_tlbi_nh(sec_sid, vmid); smmu_iotlb_inv_vmid_s1(bs, vmid, sec_sid); break; } - QEMU_FALLTHROUGH; + trace_smmuv3_cmdq_tlbi_nh(sec_sid, vmid); + smmuv3_inv_notifiers_all(bs, sec_sid); + smmu_iotlb_inv_by_sec_sid(bs, sec_sid); + if (!smmuv3_accel_issue_inv_cmd(s, &cmd, NULL, errp)) { + cmd_error =3D SMMU_CERROR_ILL; + break; + } + break; } case SMMU_CMD_TLBI_NSNH_ALL: - trace_smmuv3_cmdq_tlbi_nsnh(); - smmuv3_inv_notifiers_all(bs, SMMU_SEC_SID_NS); - smmu_iotlb_inv_all(bs); + { + /* + * CMD_TLBI_NSNH_ALL targets Non-secure entries when issued fr= om the + * Non-secure or Secure Command queue, but Realm entries when = issued + * from the Realm Command queue. + * (IHI 0070G.b) 4.4.4.1 CMD_TLBI_NSNH_ALL, Page 194 + */ + SMMUSecSID target_sec_sid =3D sec_sid > SMMU_SEC_SID_S ? + sec_sid : SMMU_SEC_SID_NS; + + trace_smmuv3_cmdq_tlbi_nsnh(sec_sid, target_sec_sid); + smmuv3_inv_notifiers_all(bs, target_sec_sid); + smmu_iotlb_inv_by_sec_sid(bs, target_sec_sid); if (!smmuv3_accel_issue_inv_cmd(s, &cmd, NULL, errp)) { cmd_error =3D SMMU_CERROR_ILL; break; } break; + } case SMMU_CMD_TLBI_NH_VAA: case SMMU_CMD_TLBI_NH_VA: if (!STAGE1_SUPPORTED(s)) { cmd_error =3D SMMU_CERROR_ILL; break; } - smmuv3_range_inval(bs, &cmd, SMMU_STAGE_1, SMMU_SEC_SID_NS); + smmuv3_range_inval(bs, &cmd, SMMU_STAGE_1, sec_sid, + queue_stage2_supported); if (!smmuv3_accel_issue_inv_cmd(s, &cmd, NULL, errp)) { cmd_error =3D SMMU_CERROR_ILL; break; @@ -1620,7 +1658,7 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error = **errp, SMMUSecSID sec_sid) * As currently only either s1 or s2 are supported * we can reuse same function for s2. */ - smmuv3_range_inval(bs, &cmd, SMMU_STAGE_2, SMMU_SEC_SID_NS); + smmuv3_range_inval(bs, &cmd, SMMU_STAGE_2, SMMU_SEC_SID_NS, tr= ue); break; case SMMU_CMD_ATC_INV: { diff --git a/hw/arm/trace-events b/hw/arm/trace-events index ea525a81b3f..4130d16fad5 100644 --- a/hw/arm/trace-events +++ b/hw/arm/trace-events @@ -19,6 +19,7 @@ smmu_ptw_page_pte(int stage, int level, uint64_t iova, u= int64_t baseaddr, uint6 smmu_ptw_block_pte(int stage, int level, uint64_t baseaddr, uint64_t ptead= dr, uint64_t pte, uint64_t iova, uint64_t gpa, int bsize_mb) "stage=3D%d le= vel=3D%d base@=3D0x%"PRIx64" pte@=3D0x%"PRIx64" pte=3D0x%"PRIx64" iova=3D0x= %"PRIx64" block address =3D 0x%"PRIx64" block size =3D %d MiB" smmu_get_pte(uint64_t baseaddr, int index, uint64_t pteaddr, uint64_t pte)= "baseaddr=3D0x%"PRIx64" index=3D0x%x, pteaddr=3D0x%"PRIx64", pte=3D0x%"PRI= x64 smmu_iotlb_inv_all(void) "IOTLB invalidate all" +smmu_iotlb_inv_by_sec_sid(int sec_sid) "IOTLB invalidate sec_sid=3D%d" smmu_iotlb_inv_asid_vmid(int sec_sid, int asid, int vmid) "IOTLB invalidat= e sec_sid=3D%d asid=3D%d vmid=3D%d" smmu_iotlb_inv_vmid(int sec_sid, int vmid) "IOTLB invalidate sec_sid=3D%d = vmid=3D%d" smmu_iotlb_inv_vmid_s1(int sec_sid, int vmid) "IOTLB invalidate S1 sec_sid= =3D%d vmid=3D%d" @@ -60,7 +61,7 @@ smmuv3_config_cache_hit(uint32_t sid, uint32_t hits, uint= 32_t misses, uint32_t p smmuv3_config_cache_miss(uint32_t sid, uint32_t hits, uint32_t misses, uin= t32_t perc) "Config cache MISS for sid=3D0x%x (hits=3D%d, misses=3D%d, hit = rate=3D%d)" smmuv3_range_inval(int sec_sid, int vmid, int asid, uint64_t addr, uint8_t= tg, uint64_t num_pages, uint8_t ttl, bool leaf, int stage) "sec_sid=3D%d v= mid=3D%d asid=3D%d addr=3D0x%"PRIx64" tg=3D%d num_pages=3D0x%"PRIx64" ttl= =3D%d leaf=3D%d stage=3D%d" smmuv3_cmdq_tlbi_nh(int sec_sid, int vmid) "sec_sid=3D%d vmid=3D%d" -smmuv3_cmdq_tlbi_nsnh(void) "" +smmuv3_cmdq_tlbi_nsnh(int sec_sid, int target_sec_sid) "cmdq_sec_sid=3D%d = target_sec_sid=3D%d" smmuv3_cmdq_tlbi_nh_asid(int sec_sid, int asid) "sec_sid=3D%d asid=3D%d" smmuv3_cmdq_tlbi_s12_vmid(int vmid) "vmid=3D%d" smmuv3_notify_flag_add(const char *iommu) "ADD SMMUNotifier node for iommu= mr=3D%s" --=20 2.34.1 From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794673183357456.0348204017723; Sat, 14 Nov 2026 08:19:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGT1-0007bd-UU; Sat, 14 Nov 2026 11:19:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGSD-00078W-Gk; Sat, 14 Nov 2026 11:18:22 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGS8-0003EO-7F; Sat, 14 Nov 2026 11:18:13 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-6 (Coremail) with UTF8SMTP id AQAAfwA3jdy7ifhqOBoGAg--.53541S2; Sun, 15 Nov 2026 00:18:03 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8DwOHSyifhq4Nv6AA--.29617S11; Sun, 15 Nov 2026 00:18:02 +0800 (CST) From: Tao Tang To: Peter Maydell , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 18/35] hw/arm/smmuv3: Fix VMID tagging for Secure stage 1 Date: Sun, 15 Nov 2026 00:17:52 +0800 Message-Id: <20261114161753.3645568-9-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8DwOHSyifhq4Nv6AA--.29617S11 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBfAACsb Authentication-Results: hzbj-icmmx-6; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvdXoWrtw4xZFWUKFyrZryrWrykXwb_yoWDKrg_ua 18twn3Wr4kAr9xXFs2krs3t3W0934kJF4xW3W0qa129F9rGFyUGwnrX3ykZr1fZFW5WFnI ywsxWr43Jwn2gjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8wcxFpf9Il3svdxBIdaVrnU Uv73VFW2AGmfu7jjvjm3AaLaJ3UjIYCTnIWjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRUUUUU UUUU= Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794673186495154100 Content-Type: text/plain; charset="utf-8" With Non-secure S2P set and Secure SEL2 clear, decode_ste() tags Secure stage-1 entries with STE.S2VMID, while CMD_TLBI_NH_ASID matches -1. The mismatch can leave stale translations cached in the IOTLB. Use the internal no-VMID value -1 for Secure stage-1 entries, keeping Non-secure VMID handling unchanged. Signed-off-by: Tao Tang --- hw/arm/smmuv3.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index fc5cd46d1a8..93d5b900806 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -643,11 +643,11 @@ static int decode_ste(SMMUv3State *s, SMMUTransCfg *c= fg, goto bad_ste; } =20 - if (STAGE2_SUPPORTED(s)) { - /* VMID is considered even if s2 is disabled. */ + if (STAGE2_SUPPORTED(s) && !smmu_sec_sid_is_secure(sec_sid)) { + /* VMID is considered even if Non-secure stage 2 is disabled. */ cfg->s2cfg.vmid =3D STE_S2VMID(ste); } else { - /* Default to -1 */ + /* No VMID tagging without stage 2 in this Security state. */ cfg->s2cfg.vmid =3D -1; } =20 --=20 2.34.1 From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794673239282545.4208656422544; Sat, 14 Nov 2026 08:20:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGT7-00080a-46; Sat, 14 Nov 2026 11:19:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGSC-00078S-EL; Sat, 14 Nov 2026 11:18:18 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGS8-0003EK-9r; Sat, 14 Nov 2026 11:18:12 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-7 (Coremail) with UTF8SMTP id AQAAfwAXH5+7ifhqaloqBg--.64105S2; Sun, 15 Nov 2026 00:18:03 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8DwOHSyifhq4Nv6AA--.29617S12; Sun, 15 Nov 2026 00:18:02 +0800 (CST) From: Tao Tang To: Peter Maydell , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 19/35] hw/arm/smmuv3: Keep accelerated invalidation Non-secure-only Date: Sun, 15 Nov 2026 00:17:53 +0800 Message-Id: <20261114161753.3645568-10-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8DwOHSyifhq4Nv6AA--.29617S12 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBfgAAsb Authentication-Results: hzbj-icmmx-7; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvJXoWxJw4UXr47CrWUtr17CrWruFg_yoWrJF1UpF 4UWwn8Wr45JasYyay2yw48uw4ft3WUKr4fGr1Yga4Syw1DAr98XrsY9r1F9r9rCr13ZrZx Z3y8Wa15Z3WjyrJanT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAU7a7-sFnT9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUU UUUUU Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794673240972154100 Content-Type: text/plain; charset="utf-8" The accelerated backend supports only the Non-secure programming interface. Filter configuration and TLB invalidations by their target SEC_SID in the command handlers before calling the backend. Keep the backend APIs unchanged. A legal ATC invalidation still targets Non-secure streams when issued from a Secure command queue. Continue forwarding Non-secure stage-1 CMD_TLBI_NH_ALL to the host. Signed-off-by: Tao Tang --- hw/arm/smmuv3.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 93d5b900806..98e45e33082 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -1493,7 +1493,8 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error = **errp, SMMUSecSID sec_sid) } =20 trace_smmuv3_cmdq_cfgi_ste(sec_sid, ssec, sid); - if (!smmuv3_accel_install_ste(s, sdev, sid, errp)) { + if (ssec =3D=3D SMMU_SEC_SID_NS && + !smmuv3_accel_install_ste(s, sdev, sid, errp)) { cmd_error =3D SMMU_CERROR_ILL; break; } @@ -1513,7 +1514,8 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error = **errp, SMMUSecSID sec_sid) =20 trace_smmuv3_cmdq_cfgi_ste_range(sec_sid, ssec, sid_range.start, sid_range.en= d); - if (!smmuv3_accel_install_ste_range(s, &sid_range, errp)) { + if (ssec =3D=3D SMMU_SEC_SID_NS && + !smmuv3_accel_install_ste_range(s, &sid_range, errp)) { cmd_error =3D SMMU_CERROR_ILL; break; } @@ -1541,7 +1543,8 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error = **errp, SMMUSecSID sec_sid) =20 trace_smmuv3_cmdq_cfgi_cd(sec_sid, ssec, sid); smmuv3_flush_config_by_sec_sid(sdev, ssec); - if (!smmuv3_accel_issue_inv_cmd(s, &cmd, sdev, errp)) { + if (ssec =3D=3D SMMU_SEC_SID_NS && + !smmuv3_accel_issue_inv_cmd(s, &cmd, sdev, errp)) { cmd_error =3D SMMU_CERROR_ILL; break; } @@ -1568,7 +1571,8 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error = **errp, SMMUSecSID sec_sid) trace_smmuv3_cmdq_tlbi_nh_asid(sec_sid, asid); smmuv3_inv_notifiers_all(bs, sec_sid); smmu_iotlb_inv_asid_vmid(bs, asid, vmid, sec_sid); - if (!smmuv3_accel_issue_inv_cmd(s, &cmd, NULL, errp)) { + if (sec_sid =3D=3D SMMU_SEC_SID_NS && + !smmuv3_accel_issue_inv_cmd(s, &cmd, NULL, errp)) { cmd_error =3D SMMU_CERROR_ILL; break; } @@ -1596,7 +1600,8 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error = **errp, SMMUSecSID sec_sid) trace_smmuv3_cmdq_tlbi_nh(sec_sid, vmid); smmuv3_inv_notifiers_all(bs, sec_sid); smmu_iotlb_inv_by_sec_sid(bs, sec_sid); - if (!smmuv3_accel_issue_inv_cmd(s, &cmd, NULL, errp)) { + if (sec_sid =3D=3D SMMU_SEC_SID_NS && + !smmuv3_accel_issue_inv_cmd(s, &cmd, NULL, errp)) { cmd_error =3D SMMU_CERROR_ILL; break; } @@ -1616,7 +1621,8 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error = **errp, SMMUSecSID sec_sid) trace_smmuv3_cmdq_tlbi_nsnh(sec_sid, target_sec_sid); smmuv3_inv_notifiers_all(bs, target_sec_sid); smmu_iotlb_inv_by_sec_sid(bs, target_sec_sid); - if (!smmuv3_accel_issue_inv_cmd(s, &cmd, NULL, errp)) { + if (target_sec_sid =3D=3D SMMU_SEC_SID_NS && + !smmuv3_accel_issue_inv_cmd(s, &cmd, NULL, errp)) { cmd_error =3D SMMU_CERROR_ILL; break; } @@ -1630,7 +1636,8 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error = **errp, SMMUSecSID sec_sid) } smmuv3_range_inval(bs, &cmd, SMMU_STAGE_1, sec_sid, queue_stage2_supported); - if (!smmuv3_accel_issue_inv_cmd(s, &cmd, NULL, errp)) { + if (sec_sid =3D=3D SMMU_SEC_SID_NS && + !smmuv3_accel_issue_inv_cmd(s, &cmd, NULL, errp)) { cmd_error =3D SMMU_CERROR_ILL; break; } --=20 2.34.1 From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794673232912960.8551920334036; Sat, 14 Nov 2026 08:20:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGU4-0000d1-Ob; Sat, 14 Nov 2026 11:20:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGTR-0000NA-6v; Sat, 14 Nov 2026 11:19:33 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGTL-0005Vs-KJ; Sat, 14 Nov 2026 11:19:25 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-7 (Coremail) with UTF8SMTP id AQAAfwBXX58FivhqKGAqBg--.44325S2; Sun, 15 Nov 2026 00:19:17 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8DwGHIDivhq7dv6AA--.27269S3; Sun, 15 Nov 2026 00:19:16 +0800 (CST) From: Tao Tang To: Peter Maydell , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 20/35] hw/arm/smmuv3: Fix ATC invalidation command checks Date: Sun, 15 Nov 2026 00:19:15 +0800 Message-Id: <20261114161915.3647430-1-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8DwGHIDivhq7dv6AA--.27269S3 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBhAAAsh Authentication-Results: hzbj-icmmx-7; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvJXoW7WFW5CF1DJr15CFW5tF48Xrb_yoW8Gw15pr 45K3s0kryrK3WfGasFya1Dua43tw48Gr1j9rWfGayfJ347AFyrGrWrKF45KFyqgFy3ZF47 Zas2qFZ7uFyjy3DanT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAU7a7-sFnT9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUU UUUUU Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794673234906154100 Content-Type: text/plain; charset="utf-8" Report CERROR_ILL for CMD_ATC_INV when SMMU_IDR0.ATS is zero, before checking the target SID or whether the issuing interface is enabled. When ATS is advertised, ignore the command if SMMUEN is clear in the issuing command queue's register bank, as required by IHI 0070G.b, section 4.5.1. Use the queue's sec_sid for this check while retaining the Non-secure target for both Non-secure and Secure command queues. Fixes: dadd1a0809b1 ("hw/arm/smmuv3: Queue helpers") Fixes: f7f5013a55a3 ("hw/arm/smmuv3-accel: Add support for ATS") Signed-off-by: Tao Tang --- hw/arm/smmuv3.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 98e45e33082..716520d5eb8 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -1669,9 +1669,20 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error= **errp, SMMUSecSID sec_sid) break; case SMMU_CMD_ATC_INV: { - SMMUDevice *sdev =3D smmu_find_sdev(bs, CMD_SID(&cmd)); + SMMUDevice *sdev; =20 - if (!sdev || !smmuv3_ats_enabled(s)) { + if (!smmuv3_ats_enabled(s)) { + cmd_error =3D SMMU_CERROR_ILL; + break; + } + + /* Check SMMUEN for the issuing command queue's security state= . */ + if (!smmu_enabled(s, sec_sid)) { + break; + } + + sdev =3D smmu_find_sdev(bs, CMD_SID(&cmd)); + if (!sdev) { trace_smmuv3_unhandled_cmd(type); break; } --=20 2.34.1 From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794673278139908.8133675443485; Sat, 14 Nov 2026 08:21:18 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGU6-0000xb-W7; Sat, 14 Nov 2026 11:20:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGTT-0000NN-Kx; Sat, 14 Nov 2026 11:19:33 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGTS-0005gY-6i; Sat, 14 Nov 2026 11:19:31 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-7 (Coremail) with UTF8SMTP id AQAAfwD3_8MMivhqhGAqBg--.63128S2; Sun, 15 Nov 2026 00:19:24 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8DwjHUKivhq9Nv6AA--.29618S3; Sun, 15 Nov 2026 00:19:23 +0800 (CST) From: Tao Tang To: Peter Maydell , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 21/35] hw/arm/smmuv3: Make GERROR_IRQ_CFG registers RES0 without MSI Date: Sun, 15 Nov 2026 00:19:22 +0800 Message-Id: <20261114161922.3647707-1-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8DwjHUKivhq9Nv6AA--.29618S3 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBhgAAsj Authentication-Results: hzbj-icmmx-7; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvJXoWxAry5Jw1kuFy8CFykGw4UArb_yoW5GFWxpr 93Awn0gw10ya1Igr9rAwn8Jw18ur93JFy3Kry5G3sxZw409rW5tF1jqFWSg34DWFykGw4D KF43urn7XrnYyw7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAU7a7-sFnT9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUU UUUUU Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794673279607154100 Content-Type: text/plain; charset="utf-8" The SMMUv3 model does not advertise MSI support, but writes to GERROR_IRQ_CFG0/1/2 were stored and could be read back. These registers must be RES0 when SMMU_IDR0.MSI is zero. Make the Non-secure and Secure GERROR_IRQ_CFG0/1/2 registers read as zero and ignore writes. This includes both 64-bit accesses to GERROR_IRQ_CFG0 and accesses to its individual 32-bit halves. Fixes: fae4be38b35d ("hw/arm/smmuv3: Implement MMIO write operations") Signed-off-by: Tao Tang Reviewed-by: Pierrick Bouvier --- hw/arm/smmuv3.c | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 716520d5eb8..144993243eb 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -1744,7 +1744,6 @@ static MemTxResult smmu_writell(SMMUv3State *s, hwadd= r offset, =20 switch (offset) { case A_GERROR_IRQ_CFG0: - bank->gerror_irq_cfg0 =3D data; return MEMTX_OK; case A_STRTAB_BASE: bank->strtab_base =3D data; @@ -1811,18 +1810,11 @@ static MemTxResult smmu_writel(SMMUv3State *s, hwad= dr offset, */ smmuv3_cmdq_consume(s, &local_err, reg_sec_sid); break; - case A_GERROR_IRQ_CFG0: /* 64b */ - bank->gerror_irq_cfg0 =3D deposit64(bank->gerror_irq_cfg0, 0, 32, = data); - break; + case A_GERROR_IRQ_CFG0: case A_GERROR_IRQ_CFG0 + 4: - bank->gerror_irq_cfg0 =3D deposit64(bank->gerror_irq_cfg0, 32, 32,= data); - break; case A_GERROR_IRQ_CFG1: - bank->gerror_irq_cfg1 =3D data; - break; case A_GERROR_IRQ_CFG2: - bank->gerror_irq_cfg2 =3D data; - break; + return MEMTX_OK; case A_GBPA: /* * If UPDATE is not set, the write is ignored. This is the only @@ -1947,7 +1939,7 @@ static MemTxResult smmu_readll(SMMUv3State *s, hwaddr= offset, =20 switch (offset) { case A_GERROR_IRQ_CFG0: - *data =3D bank->gerror_irq_cfg0; + *data =3D 0; return MEMTX_OK; case A_STRTAB_BASE: *data =3D bank->strtab_base; @@ -2014,17 +2006,11 @@ static MemTxResult smmu_readl(SMMUv3State *s, hwadd= r offset, case A_GERRORN: *data =3D bank->gerrorn; return MEMTX_OK; - case A_GERROR_IRQ_CFG0: /* 64b */ - *data =3D extract64(bank->gerror_irq_cfg0, 0, 32); - return MEMTX_OK; + case A_GERROR_IRQ_CFG0: case A_GERROR_IRQ_CFG0 + 4: - *data =3D extract64(bank->gerror_irq_cfg0, 32, 32); - return MEMTX_OK; case A_GERROR_IRQ_CFG1: - *data =3D bank->gerror_irq_cfg1; - return MEMTX_OK; case A_GERROR_IRQ_CFG2: - *data =3D bank->gerror_irq_cfg2; + *data =3D 0; return MEMTX_OK; case A_STRTAB_BASE: /* 64b */ *data =3D extract64(bank->strtab_base, 0, 32); --=20 2.34.1 From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794673261971488.2523186437737; Sat, 14 Nov 2026 08:21:01 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGU5-0000p2-V3; Sat, 14 Nov 2026 11:20:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGTW-0000PL-0d; Sat, 14 Nov 2026 11:19:40 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGTU-00067p-Jo; Sat, 14 Nov 2026 11:19:33 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-7 (Coremail) with UTF8SMTP id AQAAfwBXX8MRivhqpmAqBg--.60016S2; Sun, 15 Nov 2026 00:19:29 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8DwnnQPivhq9dv6AA--.36129S3; Sun, 15 Nov 2026 00:19:27 +0800 (CST) From: Tao Tang To: Peter Maydell , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 22/35] hw/arm/smmuv3: Ignore CR2 writes while the SMMU is enabled Date: Sun, 15 Nov 2026 00:19:27 +0800 Message-Id: <20261114161927.3647758-1-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8DwnnQPivhq9dv6AA--.36129S3 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBiAAAst Authentication-Results: hzbj-icmmx-7; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvdXoW7Jr1UtF4xCrWrKFW8ZF4rGrg_yoWDZrbEga 95t3Z5WFn2kFyfA3ZFkr42v34Sgr4rGFyDWryI9F1Yyw4kWr9rCr4DGrs5X3WfXa1jg3Wf KFsavry3GrZrWjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8wcxFpf9Il3svdxBIdaVrnU Uv73VFW2AGmfu7jjvjm3AaLaJ3UjIYCTnIWjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRUUUUU UUUU= Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794673263334154100 Content-Type: text/plain; charset="utf-8" CR2 writes currently update the register even when the SMMU is enabled. Ignore these writes after SMMUEN has been updated to one. The model acknowledges SMMUEN synchronously, so checking the selected bank's enable state is sufficient. Retain writes while it is disabled. Fixes: fae4be38b35d ("hw/arm/smmuv3: Implement MMIO write operations") Signed-off-by: Tao Tang Reviewed-by: Pierrick Bouvier --- hw/arm/smmuv3.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 144993243eb..bd680375b1b 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -1797,7 +1797,10 @@ static MemTxResult smmu_writel(SMMUv3State *s, hwadd= r offset, bank->cr[1] =3D data; break; case A_CR2: - bank->cr[2] =3D data; + if (!smmu_enabled(s, reg_sec_sid)) { + /* SMMUEN is acknowledged synchronously in this model. */ + bank->cr[2] =3D data; + } break; case A_IRQ_CTRL: bank->irq_ctrl =3D data; --=20 2.34.1 From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794673308789492.6820573879247; Sat, 14 Nov 2026 08:21:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGU8-000193-D9; Sat, 14 Nov 2026 11:20:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGTY-0000Py-Fn; Sat, 14 Nov 2026 11:19:44 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGTW-0006Di-KG; Sat, 14 Nov 2026 11:19:36 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-6 (Coremail) with UTF8SMTP id AQAAfwBHvN0UivhqwBoGAg--.54721S2; Sun, 15 Nov 2026 00:19:32 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8DwnnQSivhq9tv6AA--.36130S3; Sun, 15 Nov 2026 00:19:31 +0800 (CST) From: Tao Tang To: Peter Maydell , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 23/35] hw/arm/smmuv3: Guard stream table register writes Date: Sun, 15 Nov 2026 00:19:30 +0800 Message-Id: <20261114161930.3647973-1-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8DwnnQSivhq9tv6AA--.36130S3 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBigAAsv Authentication-Results: hzbj-icmmx-6; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvJXoWxXr4UKw1rCryUJw4xAr4Dtwb_yoW5WF4kpr Z7GwnI93y3t3WSqasxAa1Yyws8u3ykKF1UtFy7GF92vw4UJrW5XF4fXFWIqwnYqFyDtw4k Gw4ak3yfury8tFJanT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAU7a7-sFnT9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUU UUUUU Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794673310016154100 Content-Type: text/plain; charset="utf-8" STRTAB_BASE and STRTAB_BASE_CFG can currently be modified while the SMMU is enabled. Ignore their writes until SMMUEN is clear. The model updates CR0ACK synchronously with CR0, so no separate transition check is needed. Mask reserved bits in STRTAB_BASE for both 64-bit writes and writes to its 32-bit halves. Shift the mask when handling the high half. Fixes: fae4be38b35d ("hw/arm/smmuv3: Implement MMIO write operations") Signed-off-by: Tao Tang Reviewed-by: Pierrick Bouvier --- hw/arm/smmuv3.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index bd680375b1b..127be4ac8e9 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -1421,6 +1421,12 @@ smmu_cmdq_stage2_supported(SMMUv3State *s, SMMUSecSI= D sec_sid) return true; } =20 +/* Check if STRTAB_BASE register is writable */ +static bool smmu_strtab_base_writable(SMMUv3State *s, SMMUSecSID sec_sid) +{ + return !smmu_enabled(s, sec_sid); +} + static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp, SMMUSecSID se= c_sid) { SMMUState *bs =3D ARM_SMMU(s); @@ -1746,7 +1752,14 @@ static MemTxResult smmu_writell(SMMUv3State *s, hwad= dr offset, case A_GERROR_IRQ_CFG0: return MEMTX_OK; case A_STRTAB_BASE: - bank->strtab_base =3D data; + if (!smmu_strtab_base_writable(s, reg_sec_sid)) { + qemu_log_mask(LOG_GUEST_ERROR, + "STRTAB_BASE write ignored: register is RO\n"); + return MEMTX_OK; + } + + /* Clear reserved bits according to spec */ + bank->strtab_base =3D data & SMMU_STRTAB_BASE_RESERVED; return MEMTX_OK; case A_CMDQ_BASE: bank->cmdq.base =3D data; @@ -1830,12 +1843,32 @@ static MemTxResult smmu_writel(SMMUv3State *s, hwad= dr offset, } break; case A_STRTAB_BASE: /* 64b */ + if (!smmu_strtab_base_writable(s, reg_sec_sid)) { + qemu_log_mask(LOG_GUEST_ERROR, + "STRTAB_BASE write ignored: register is RO\n"); + return MEMTX_OK; + } + + data &=3D SMMU_STRTAB_BASE_RESERVED; bank->strtab_base =3D deposit64(bank->strtab_base, 0, 32, data); break; case A_STRTAB_BASE + 4: + if (!smmu_strtab_base_writable(s, reg_sec_sid)) { + qemu_log_mask(LOG_GUEST_ERROR, + "STRTAB_BASE + 4 write ignored: register is RO\n= "); + return MEMTX_OK; + } + + data &=3D SMMU_STRTAB_BASE_RESERVED >> 32; bank->strtab_base =3D deposit64(bank->strtab_base, 32, 32, data); break; case A_STRTAB_BASE_CFG: + if (!smmu_strtab_base_writable(s, reg_sec_sid)) { + qemu_log_mask(LOG_GUEST_ERROR, + "STRTAB_BASE_CFG write ignored: register is RO\n= "); + return MEMTX_OK; + } + bank->strtab_base_cfg =3D data; if (FIELD_EX32(data, STRTAB_BASE_CFG, FMT) =3D=3D 1) { bank->sid_split =3D FIELD_EX32(data, STRTAB_BASE_CFG, SPLIT); --=20 2.34.1 From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794673344084400.58934073559294; Sat, 14 Nov 2026 08:22:24 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGUO-0002YL-IM; Sat, 14 Nov 2026 11:20:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGTc-0000RL-LZ; Sat, 14 Nov 2026 11:19:47 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGTb-0006Q3-2u; Sat, 14 Nov 2026 11:19:40 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-6 (Coremail) with UTF8SMTP id AQAAfwDnBN4YivhqyRoGAg--.42231S2; Sun, 15 Nov 2026 00:19:36 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8DwnnQWivhq99v6AA--.36131S3; Sun, 15 Nov 2026 00:19:34 +0800 (CST) From: Tao Tang To: Peter Maydell , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 24/35] hw/arm/smmuv3: Guard command queue register writes Date: Sun, 15 Nov 2026 00:19:34 +0800 Message-Id: <20261114161934.3648016-1-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8DwnnQWivhq99v6AA--.36131S3 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBjAAAsp Authentication-Results: hzbj-icmmx-6; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvJXoWxXr4UKw1rAw48XFWfJFy8Grg_yoW5Xr43p3 97GrZ0grW2yrs3GF9xAay8Cr45uwn3Kry2vry7WFyrXw1UG3yYgF48Xa4fXF93XF9rAws5 trsI9a4Dur48trJanT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAU7a7-sFnT9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUU UUUUU Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794673347006154100 Content-Type: text/plain; charset="utf-8" CMDQ_BASE and CMDQ_CONS can currently be modified while the command queue is enabled. Ignore these writes while CMDQEN is set, using the model's synchronous enable and acknowledgement state. Mask reserved CMDQ_BASE bits and update the queue size when writing its low half. Use the high-half mask for writes to CMDQ_BASE + 4. Fixes: fae4be38b35d ("hw/arm/smmuv3: Implement MMIO write operations") Signed-off-by: Tao Tang Reviewed-by: Pierrick Bouvier --- hw/arm/smmuv3.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 127be4ac8e9..e5f057113e1 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -1762,7 +1762,13 @@ static MemTxResult smmu_writell(SMMUv3State *s, hwad= dr offset, bank->strtab_base =3D data & SMMU_STRTAB_BASE_RESERVED; return MEMTX_OK; case A_CMDQ_BASE: - bank->cmdq.base =3D data; + if (smmuv3_cmdq_enabled(s, reg_sec_sid)) { + qemu_log_mask(LOG_GUEST_ERROR, + "CMDQ_BASE write ignored: register is RO\n"); + return MEMTX_OK; + } + + bank->cmdq.base =3D data & SMMU_QUEUE_BASE_RESERVED; bank->cmdq.log2size =3D extract64(bank->cmdq.base, 0, 5); if (bank->cmdq.log2size > SMMU_CMDQS) { bank->cmdq.log2size =3D SMMU_CMDQS; @@ -1884,6 +1890,13 @@ static MemTxResult smmu_writel(SMMUv3State *s, hwadd= r offset, } break; case A_CMDQ_BASE: /* 64b */ + if (smmuv3_cmdq_enabled(s, reg_sec_sid)) { + qemu_log_mask(LOG_GUEST_ERROR, + "CMDQ_BASE write ignored: register is RO\n"); + return MEMTX_OK; + } + + data &=3D SMMU_QUEUE_BASE_RESERVED; bank->cmdq.base =3D deposit64(bank->cmdq.base, 0, 32, data); bank->cmdq.log2size =3D extract64(bank->cmdq.base, 0, 5); if (bank->cmdq.log2size > SMMU_CMDQS) { @@ -1891,6 +1904,13 @@ static MemTxResult smmu_writel(SMMUv3State *s, hwadd= r offset, } break; case A_CMDQ_BASE + 4: /* 64b */ + if (smmuv3_cmdq_enabled(s, reg_sec_sid)) { + qemu_log_mask(LOG_GUEST_ERROR, + "CMDQ_BASE + 4 write ignored: register is RO\n"); + return MEMTX_OK; + } + + data &=3D SMMU_QUEUE_BASE_RESERVED >> 32; bank->cmdq.base =3D deposit64(bank->cmdq.base, 32, 32, data); break; case A_CMDQ_PROD: @@ -1898,6 +1918,12 @@ static MemTxResult smmu_writel(SMMUv3State *s, hwadd= r offset, smmuv3_cmdq_consume(s, &local_err, reg_sec_sid); break; case A_CMDQ_CONS: + if (smmuv3_cmdq_enabled(s, reg_sec_sid)) { + qemu_log_mask(LOG_GUEST_ERROR, + "CMDQ_CONS write ignored: register is RO\n"); + return MEMTX_OK; + } + bank->cmdq.cons =3D data; break; case A_EVENTQ_BASE: /* 64b */ --=20 2.34.1 From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794673367005715.9243396297359; Sat, 14 Nov 2026 08:22:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGUE-0001YA-Hr; Sat, 14 Nov 2026 11:20:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGTi-0000XT-AM; Sat, 14 Nov 2026 11:19:54 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGTe-0006h5-FE; Sat, 14 Nov 2026 11:19:45 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-6 (Coremail) with UTF8SMTP id AQAAfwDHzlobivhq0BoGAg--.43029S2; Sun, 15 Nov 2026 00:19:39 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8DwBnMZivhq+Nv6AA--.26417S3; Sun, 15 Nov 2026 00:19:38 +0800 (CST) From: Tao Tang To: Peter Maydell , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 25/35] hw/arm/smmuv3: Guard event queue register writes Date: Sun, 15 Nov 2026 00:19:37 +0800 Message-Id: <20261114161937.3648060-1-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8DwBnMZivhq+Nv6AA--.26417S3 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBjgAAsr Authentication-Results: hzbj-icmmx-6; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvJXoWxXr48ArW5KrW3WFWUAFy5urg_yoWrWryxpr ZxJFy5Ka12yw4Sg3Z3Aw1DAan8Cwn7Jry7Kr9xW34UWw18urWUZa1UWFWfKFyrJF1UJw4D GrZI93Zrur15K3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAU7a7-sFnT9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUU UUUUU Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794673369069154100 Content-Type: text/plain; charset="utf-8" EVENTQ_BASE and EVENTQ_PROD can currently be modified while the event queue is enabled. Ignore these writes while EVENTQEN is set, using the model's synchronous enable and acknowledgement state. Mask reserved EVENTQ_BASE bits and update the queue size when writing its low half. Use the high-half mask for writes to EVENTQ_BASE + 4. The model does not advertise MSI support. Make EVENTQ_IRQ_CFG0/1/2 read as zero and ignore writes, including accesses to both halves of CFG0. Fixes: fae4be38b35d ("hw/arm/smmuv3: Implement MMIO write operations") Signed-off-by: Tao Tang Reviewed-by: Pierrick Bouvier --- hw/arm/smmuv3.c | 49 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index e5f057113e1..138ca178a1a 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -1775,14 +1775,19 @@ static MemTxResult smmu_writell(SMMUv3State *s, hwa= ddr offset, } return MEMTX_OK; case A_EVENTQ_BASE: - bank->eventq.base =3D data; + if (smmuv3_eventq_enabled(s, reg_sec_sid)) { + qemu_log_mask(LOG_GUEST_ERROR, + "EVENTQ_BASE write ignored: register is RO\n"); + return MEMTX_OK; + } + + bank->eventq.base =3D data & SMMU_QUEUE_BASE_RESERVED; bank->eventq.log2size =3D extract64(bank->eventq.base, 0, 5); if (bank->eventq.log2size > SMMU_EVENTQS) { bank->eventq.log2size =3D SMMU_EVENTQS; } return MEMTX_OK; case A_EVENTQ_IRQ_CFG0: - bank->eventq_irq_cfg0 =3D data; return MEMTX_OK; default: qemu_log_mask(LOG_UNIMP, @@ -1927,6 +1932,13 @@ static MemTxResult smmu_writel(SMMUv3State *s, hwadd= r offset, bank->cmdq.cons =3D data; break; case A_EVENTQ_BASE: /* 64b */ + if (smmuv3_eventq_enabled(s, reg_sec_sid)) { + qemu_log_mask(LOG_GUEST_ERROR, + "EVENTQ_BASE write ignored: register is RO\n"); + return MEMTX_OK; + } + + data &=3D SMMU_QUEUE_BASE_RESERVED; bank->eventq.base =3D deposit64(bank->eventq.base, 0, 32, data); bank->eventq.log2size =3D extract64(bank->eventq.base, 0, 5); if (bank->eventq.log2size > SMMU_EVENTQS) { @@ -1934,26 +1946,32 @@ static MemTxResult smmu_writel(SMMUv3State *s, hwad= dr offset, } break; case A_EVENTQ_BASE + 4: + if (smmuv3_eventq_enabled(s, reg_sec_sid)) { + qemu_log_mask(LOG_GUEST_ERROR, + "EVENTQ_BASE + 4 write ignored: register is RO\n= "); + return MEMTX_OK; + } + + data &=3D SMMU_QUEUE_BASE_RESERVED >> 32; bank->eventq.base =3D deposit64(bank->eventq.base, 32, 32, data); break; case A_EVENTQ_PROD: + if (smmuv3_eventq_enabled(s, reg_sec_sid)) { + qemu_log_mask(LOG_GUEST_ERROR, + "EVENTQ_PROD write ignored: register is RO\n"); + return MEMTX_OK; + } + bank->eventq.prod =3D data; break; case A_EVENTQ_CONS: bank->eventq.cons =3D data; break; - case A_EVENTQ_IRQ_CFG0: /* 64b */ - bank->eventq_irq_cfg0 =3D deposit64(bank->eventq_irq_cfg0, 0, 32, = data); - break; + case A_EVENTQ_IRQ_CFG0: case A_EVENTQ_IRQ_CFG0 + 4: - bank->eventq_irq_cfg0 =3D deposit64(bank->eventq_irq_cfg0, 32, 32,= data); - break; case A_EVENTQ_IRQ_CFG1: - bank->eventq_irq_cfg1 =3D data; - break; case A_EVENTQ_IRQ_CFG2: - bank->eventq_irq_cfg2 =3D data; - break; + return MEMTX_OK; default: qemu_log_mask(LOG_UNIMP, "%s Unexpected 32-bit access to 0x%"PRIx64" (WI)\n", @@ -2012,6 +2030,9 @@ static MemTxResult smmu_readll(SMMUv3State *s, hwaddr= offset, case A_EVENTQ_BASE: *data =3D bank->eventq.base; return MEMTX_OK; + case A_EVENTQ_IRQ_CFG0: + *data =3D 0; + return MEMTX_OK; default: *data =3D 0; qemu_log_mask(LOG_UNIMP, @@ -2107,6 +2128,12 @@ static MemTxResult smmu_readl(SMMUv3State *s, hwaddr= offset, case A_EVENTQ_CONS: *data =3D bank->eventq.cons; return MEMTX_OK; + case A_EVENTQ_IRQ_CFG0: + case A_EVENTQ_IRQ_CFG0 + 4: + case A_EVENTQ_IRQ_CFG1: + case A_EVENTQ_IRQ_CFG2: + *data =3D 0; + return MEMTX_OK; default: *data =3D 0; qemu_log_mask(LOG_UNIMP, --=20 2.34.1 From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794673363318752.0759174756881; Sat, 14 Nov 2026 08:22:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGUO-0002ZP-JX; Sat, 14 Nov 2026 11:20:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGTm-0000Yd-AR; Sat, 14 Nov 2026 11:19:57 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGTi-0006xE-E7; Sat, 14 Nov 2026 11:19:48 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-7 (Coremail) with UTF8SMTP id AQAAfwAHDcEfivhq4WEqBg--.46267S2; Sun, 15 Nov 2026 00:19:43 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8DwR3Ydivhq+dv6AA--.34443S3; Sun, 15 Nov 2026 00:19:41 +0800 (CST) From: Tao Tang To: Peter Maydell , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 26/35] hw/arm/smmuv3: Determine register bank from MMIO offset Date: Sun, 15 Nov 2026 00:19:40 +0800 Message-Id: <20261114161940.3648277-1-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8DwR3Ydivhq+dv6AA--.34443S3 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBkAAAs1 Authentication-Results: hzbj-icmmx-7; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvJXoWxKry8XFyktr47uw18AF4xWFg_yoWxXr45pr WkJryFgr1qka1SqFsxJa1UC3WrZwn2gr1ayrnxK34UC3y0yw1xXFW0934furyDuFyUArs5 WrW5Gr43WrWqy3DanT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAU7a7-sFnT9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUU UUUUU Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794674265897154100 Content-Type: text/plain; charset="utf-8" Modify the main MMIO handlers to select the target register bank from the memory-mapped offset. Offsets in the Secure register window select SMMU_SEC_SID_S and are normalized by subtracting SMMU_SECURE_REG_START. Other offsets select the Non-secure bank. Pass the selected SEC_SID to the register access helpers, where the normalized bank-local offset identifies the register. Keep bank-specific differences explicit, such as S_IDR5 being unimplemented. This patch implements Non-secure and Secure bank dispatch and prepares for later access checks; Realm and Root programming interfaces are not modeled. Signed-off-by: Tao Tang Reviewed-by: Pierrick Bouvier Reviewed-by: Jim MacArthur Reviewed-by: Eric Auger --- hw/arm/smmuv3.c | 84 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 70 insertions(+), 14 deletions(-) diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 138ca178a1a..54647964c21 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -1742,10 +1742,25 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Erro= r **errp, SMMUSecSID sec_sid) return 0; } =20 +static bool smmuv3_reg_is_raz_wi(hwaddr offset, SMMUSecSID reg_sec_sid) +{ + switch (offset) { + case A_IDR5: + case A_IIDR: + case A_STATUSR: + case A_IDREGS ... A_IDREGS + 0x2f: + return reg_sec_sid !=3D SMMU_SEC_SID_NS; + case A_AIDR: + return reg_sec_sid =3D=3D SMMU_SEC_SID_S; + default: + return false; + } +} + static MemTxResult smmu_writell(SMMUv3State *s, hwaddr offset, - uint64_t data, MemTxAttrs attrs) + uint64_t data, MemTxAttrs attrs, + SMMUSecSID reg_sec_sid) { - SMMUSecSID reg_sec_sid =3D SMMU_SEC_SID_NS; SMMUv3RegBank *bank =3D smmuv3_bank(s, reg_sec_sid); =20 switch (offset) { @@ -1798,16 +1813,20 @@ static MemTxResult smmu_writell(SMMUv3State *s, hwa= ddr offset, } =20 static MemTxResult smmu_writel(SMMUv3State *s, hwaddr offset, - uint64_t data, MemTxAttrs attrs) + uint64_t data, MemTxAttrs attrs, + SMMUSecSID reg_sec_sid) { Error *local_err =3D NULL; - SMMUSecSID reg_sec_sid =3D SMMU_SEC_SID_NS; SMMUv3RegBank *bank =3D smmuv3_bank(s, reg_sec_sid); =20 switch (offset) { case A_CR0: + if (reg_sec_sid =3D=3D SMMU_SEC_SID_S) { + data &=3D ~SMMU_S_CR0_RESERVED; + } bank->cr[0] =3D data; - bank->cr0ack =3D data & ~SMMU_CR0_RESERVED; + bank->cr0ack =3D data & ~(reg_sec_sid =3D=3D SMMU_SEC_SID_S ? + SMMU_S_CR0_RESERVED : SMMU_CR0_RESERVED); /* in case the command queue has been enabled */ smmuv3_cmdq_consume(s, &local_err, reg_sec_sid); if (local_err) { @@ -1850,7 +1869,9 @@ static MemTxResult smmu_writel(SMMUv3State *s, hwaddr= offset, if (data & R_GBPA_UPDATE_MASK) { /* Ignore update bit as write is synchronous. */ bank->gbpa =3D data & ~R_GBPA_UPDATE_MASK; - smmuv3_accel_attach_gbpa_hwpt(s, &local_err); + if (reg_sec_sid =3D=3D SMMU_SEC_SID_NS) { + smmuv3_accel_attach_gbpa_hwpt(s, &local_err); + } } break; case A_STRTAB_BASE: /* 64b */ @@ -1991,16 +2012,35 @@ static MemTxResult smmu_write_mmio(void *opaque, hw= addr offset, uint64_t data, SMMUState *sys =3D opaque; SMMUv3State *s =3D ARM_SMMUV3(sys); MemTxResult r; + SMMUSecSID reg_sec_sid =3D SMMU_SEC_SID_NS; =20 /* CONSTRAINED UNPREDICTABLE choice to have page0/1 be exact aliases */ offset &=3D ~0x10000; =20 + /* + * Dispatch the Non-secure window directly. After access validation, + * translate the Secure window to its bank-local register offsets. + */ + if (offset >=3D SMMU_SECURE_REG_START) { + reg_sec_sid =3D SMMU_SEC_SID_S; + offset -=3D SMMU_SECURE_REG_START; + } + + if (smmuv3_reg_is_raz_wi(offset, reg_sec_sid)) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: write to undefined register: bank=3D%d " + "offset=3D0x%" PRIx64 " (WI)\n", + __func__, reg_sec_sid, offset); + trace_smmuv3_write_mmio(offset, data, size, MEMTX_OK); + return MEMTX_OK; + } + switch (size) { case 8: - r =3D smmu_writell(s, offset, data, attrs); + r =3D smmu_writell(s, offset, data, attrs, reg_sec_sid); break; case 4: - r =3D smmu_writel(s, offset, data, attrs); + r =3D smmu_writel(s, offset, data, attrs, reg_sec_sid); break; default: r =3D MEMTX_ERROR; @@ -2012,9 +2052,9 @@ static MemTxResult smmu_write_mmio(void *opaque, hwad= dr offset, uint64_t data, } =20 static MemTxResult smmu_readll(SMMUv3State *s, hwaddr offset, - uint64_t *data, MemTxAttrs attrs) + uint64_t *data, MemTxAttrs attrs, + SMMUSecSID reg_sec_sid) { - SMMUSecSID reg_sec_sid =3D SMMU_SEC_SID_NS; SMMUv3RegBank *bank =3D smmuv3_bank(s, reg_sec_sid); =20 switch (offset) { @@ -2043,9 +2083,9 @@ static MemTxResult smmu_readll(SMMUv3State *s, hwaddr= offset, } =20 static MemTxResult smmu_readl(SMMUv3State *s, hwaddr offset, - uint64_t *data, MemTxAttrs attrs) + uint64_t *data, MemTxAttrs attrs, + SMMUSecSID reg_sec_sid) { - SMMUSecSID reg_sec_sid =3D SMMU_SEC_SID_NS; SMMUv3RegBank *bank =3D smmuv3_bank(s, reg_sec_sid); =20 switch (offset) { @@ -2135,6 +2175,7 @@ static MemTxResult smmu_readl(SMMUv3State *s, hwaddr = offset, *data =3D 0; return MEMTX_OK; default: + unhandled: *data =3D 0; qemu_log_mask(LOG_UNIMP, "%s unhandled 32-bit access at 0x%"PRIx64" (RAZ)\n", @@ -2149,16 +2190,31 @@ static MemTxResult smmu_read_mmio(void *opaque, hwa= ddr offset, uint64_t *data, SMMUState *sys =3D opaque; SMMUv3State *s =3D ARM_SMMUV3(sys); MemTxResult r; + SMMUSecSID reg_sec_sid =3D SMMU_SEC_SID_NS; =20 /* CONSTRAINED UNPREDICTABLE choice to have page0/1 be exact aliases */ offset &=3D ~0x10000; + if (offset >=3D SMMU_SECURE_REG_START) { + reg_sec_sid =3D SMMU_SEC_SID_S; + offset -=3D SMMU_SECURE_REG_START; + } + + if (smmuv3_reg_is_raz_wi(offset, reg_sec_sid)) { + *data =3D 0; + qemu_log_mask(LOG_GUEST_ERROR, + "%s: read from undefined register: bank=3D%d " + "offset=3D0x%" PRIx64 " (RAZ)\n", + __func__, reg_sec_sid, offset); + trace_smmuv3_read_mmio(offset, *data, size, MEMTX_OK); + return MEMTX_OK; + } =20 switch (size) { case 8: - r =3D smmu_readll(s, offset, data, attrs); + r =3D smmu_readll(s, offset, data, attrs, reg_sec_sid); break; case 4: - r =3D smmu_readl(s, offset, data, attrs); + r =3D smmu_readl(s, offset, data, attrs, reg_sec_sid); break; default: r =3D MEMTX_ERROR; --=20 2.34.1 From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794672375686828.2695138233871; Sat, 14 Nov 2026 08:06:15 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGG4-000087-07; Sat, 14 Nov 2026 11:05:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGFt-000077-6X; Sat, 14 Nov 2026 11:05:30 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGFn-00078s-9i; Sat, 14 Nov 2026 11:05:28 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-7 (Coremail) with UTF8SMTP id AQAAfwAX5KS8hvhqHC0qBg--.44419S2; Sun, 15 Nov 2026 00:05:16 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8DwFXWuhvhqkdv6AA--.30494S3; Sun, 15 Nov 2026 00:05:02 +0800 (CST) From: Tao Tang To: Peter Maydell , Leif Lindholm , Eric Auger , "Michael S . Tsirkin" , Igor Mammedov , Ani Sinha , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 27/35] hw/arm/smmuv3: Route IRQ and GERROR handling by SEC_SID Date: Sun, 15 Nov 2026 00:05:01 +0800 Message-Id: <20261114160501.3626474-1-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8DwFXWuhvhqkdv6AA--.30494S3 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBUwABs3 Authentication-Results: hzbj-icmmx-7; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvJXoWxKrWUGrykuw45ur1kuFy5CFg_yoWDJr4kpr 4qywnYgr4rKF15Xr9aga1xu3W3G34kKF1YkrWUKFWfCa4jkryYqr4DG3Wjk3yDurWkZa13 ZayfWFW8Zr1xAr7anT9S1TB71UUUUj7qnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAU7a7-sFnT9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUU UUUUU Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794672379373154100 Content-Type: text/plain; charset="utf-8" Interrupt and global error handling currently always selects the Non-secure register bank, even when the event or command originates from the Secure programming interface. This splits CMDQ_CONS.ERR from GERROR.CMDQ_ERR and prevents Secure software from acknowledging the error through S_GERRORN. Pass SEC_SID through the IRQ and GERROR helpers and all queue call sites so interrupt enable checks, global error reporting, and acknowledgement use the originating programming-interface bank. Add separate wired interrupt outputs for Secure EventQ, CMD_SYNC and GERROR. Select the output by SEC_SID, register the new outputs and wire them to the GIC on virt and sbsa-ref. Adjust the CMDQV ACPI interrupt index to account for the additional SMMU outputs. Signed-off-by: Tao Tang Reviewed-by: Pierrick Bouvier Reviewed-by: Eric Auger --- include/hw/arm/smmuv3.h | 11 ++++++++++- include/hw/arm/virt.h | 1 + hw/arm/sbsa-ref.c | 8 ++++++++ hw/arm/smmuv3.c | 41 ++++++++++++++++++++++++++++------------ hw/arm/virt-acpi-build.c | 3 ++- hw/arm/virt.c | 7 +++++++ 6 files changed, 57 insertions(+), 14 deletions(-) diff --git a/include/hw/arm/smmuv3.h b/include/hw/arm/smmuv3.h index 8cd2edc3412..cb05cb19e32 100644 --- a/include/hw/arm/smmuv3.h +++ b/include/hw/arm/smmuv3.h @@ -57,6 +57,14 @@ typedef struct SMMUv3RegBank { SMMUQueue eventq, cmdq; } SMMUv3RegBank; =20 +enum { + SMMU_IRQ_NUM_NS =3D 4, + SMMU_IRQ_S_EVTQ =3D SMMU_IRQ_NUM_NS, + SMMU_IRQ_S_CMD_SYNC, + SMMU_IRQ_S_GERROR, + SMMU_IRQ_NUM, +}; + struct SMMUv3State { SMMUState smmu_state; =20 @@ -67,7 +75,7 @@ struct SMMUv3State { =20 SMMUv3RegBank bank[SMMU_SEC_SID_NUM]; =20 - qemu_irq irq[4]; + qemu_irq irq[SMMU_IRQ_NUM]; QemuMutex mutex; char *stage; uint8_t identifier; @@ -104,6 +112,7 @@ struct SMMUv3Class { }; =20 bool smmuv3_ats_enabled(struct SMMUv3State *s); +int smmuv3_get_num_irqs(struct SMMUv3State *s); =20 #define TYPE_ARM_SMMUV3 "arm-smmuv3" OBJECT_DECLARE_TYPE(SMMUv3State, SMMUv3Class, ARM_SMMUV3) diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h index 22e66d1a113..e1ec8fe53d4 100644 --- a/include/hw/arm/virt.h +++ b/include/hw/arm/virt.h @@ -79,6 +79,7 @@ enum { VIRT_GICV5_ITS_TR_EL3, VIRT_GICV5_ITS_TR_REALM, VIRT_SMMU, + VIRT_SMMU_SECURE, VIRT_UART0, VIRT_MMIO, VIRT_RTC, diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c index 158b461eb48..ad6d0171723 100644 --- a/hw/arm/sbsa-ref.c +++ b/hw/arm/sbsa-ref.c @@ -82,6 +82,7 @@ enum { SBSA_GWDT_REFRESH, SBSA_GWDT_CONTROL, SBSA_SMMU, + SBSA_SMMU_SECURE, SBSA_UART, SBSA_RTC, SBSA_PCIE, @@ -155,6 +156,7 @@ static const int sbsa_ref_irqmap[] =3D { [SBSA_XHCI] =3D 11, [SBSA_SMMU] =3D 12, /* ... to 15 */ [SBSA_GWDT_WS0] =3D 16, + [SBSA_SMMU_SECURE] =3D 17, }; =20 static uint64_t sbsa_ref_cpu_mp_affinity(SBSAMachineState *sms, int idx) @@ -618,6 +620,7 @@ static void create_smmu(const SBSAMachineState *sms, PC= IBus *bus, { hwaddr base =3D sbsa_ref_memmap[SBSA_SMMU].base; int irq =3D sbsa_ref_irqmap[SBSA_SMMU]; + int secure_irq =3D sbsa_ref_irqmap[SBSA_SMMU_SECURE]; DeviceState *dev; int i; =20 @@ -636,6 +639,11 @@ static void create_smmu(const SBSAMachineState *sms, P= CIBus *bus, sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, qdev_get_gpio_in(sms->gic, irq + i)); } + for (i =3D SMMU_IRQ_NUM_NS; i < smmuv3_get_num_irqs(ARM_SMMUV3(dev)); = i++) { + sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, + qdev_get_gpio_in(sms->gic, + secure_irq + i - SMMU_IRQ_NUM_= NS)); + } } =20 static void create_pcie(SBSAMachineState *sms, diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 54647964c21..97a8663349e 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -49,23 +49,30 @@ * * @irq: irq type * @gerror_mask: mask of gerrors to toggle (relevant if @irq is GERROR) + * @sec_sid: security state of the programming interface */ static void smmuv3_trigger_irq(SMMUv3State *s, SMMUIrq irq, - uint32_t gerror_mask) + uint32_t gerror_mask, SMMUSecSID sec_sid) { - SMMUSecSID sec_sid =3D SMMU_SEC_SID_NS; SMMUv3RegBank *bank =3D smmuv3_bank(s, sec_sid); + int irq_index =3D irq; =20 bool pulse =3D false; =20 switch (irq) { case SMMU_IRQ_EVTQ: + if (sec_sid =3D=3D SMMU_SEC_SID_S) { + irq_index =3D SMMU_IRQ_S_EVTQ; + } pulse =3D smmuv3_eventq_irq_enabled(s, sec_sid); break; case SMMU_IRQ_PRIQ: qemu_log_mask(LOG_UNIMP, "PRI not yet supported\n"); break; case SMMU_IRQ_CMD_SYNC: + if (sec_sid =3D=3D SMMU_SEC_SID_S) { + irq_index =3D SMMU_IRQ_S_CMD_SYNC; + } pulse =3D true; break; case SMMU_IRQ_GERROR: @@ -73,6 +80,9 @@ static void smmuv3_trigger_irq(SMMUv3State *s, SMMUIrq ir= q, uint32_t pending =3D bank->gerror ^ bank->gerrorn; uint32_t new_gerrors =3D ~pending & gerror_mask; =20 + if (sec_sid =3D=3D SMMU_SEC_SID_S) { + irq_index =3D SMMU_IRQ_S_GERROR; + } if (!new_gerrors) { /* only toggle non pending errors */ return; @@ -85,14 +95,14 @@ static void smmuv3_trigger_irq(SMMUv3State *s, SMMUIrq = irq, } } if (pulse) { - trace_smmuv3_trigger_irq(irq); - qemu_irq_pulse(s->irq[irq]); + trace_smmuv3_trigger_irq(irq_index); + qemu_irq_pulse(s->irq[irq_index]); } } =20 -static void smmuv3_write_gerrorn(SMMUv3State *s, uint32_t new_gerrorn) +static void smmuv3_write_gerrorn(SMMUv3State *s, uint32_t new_gerrorn, + SMMUSecSID sec_sid) { - SMMUSecSID sec_sid =3D SMMU_SEC_SID_NS; SMMUv3RegBank *bank =3D smmuv3_bank(s, sec_sid); uint32_t pending =3D bank->gerror ^ bank->gerrorn; uint32_t toggled =3D bank->gerrorn ^ new_gerrorn; @@ -173,7 +183,7 @@ static MemTxResult smmuv3_write_eventq(SMMUv3State *s, = SMMUSecSID sec_sid, } =20 if (!smmuv3_q_empty(q)) { - smmuv3_trigger_irq(s, SMMU_IRQ_EVTQ, 0); + smmuv3_trigger_irq(s, SMMU_IRQ_EVTQ, 0, sec_sid); } return MEMTX_OK; } @@ -187,7 +197,8 @@ void smmuv3_propagate_event(SMMUv3State *s, Evt *evt, S= MMUSecSID sec_sid) QEMU_LOCK_GUARD(&s->mutex); r =3D smmuv3_write_eventq(s, sec_sid, evt); if (r !=3D MEMTX_OK) { - smmuv3_trigger_irq(s, SMMU_IRQ_GERROR, R_GERROR_EVENTQ_ABT_ERR_MAS= K); + smmuv3_trigger_irq(s, SMMU_IRQ_GERROR, + R_GERROR_EVENTQ_ABT_ERR_MASK, sec_sid); } } =20 @@ -1483,7 +1494,7 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error = **errp, SMMUSecSID sec_sid) switch (type) { case SMMU_CMD_SYNC: if (CMD_SYNC_CS(&cmd) & CMD_SYNC_SIG_IRQ) { - smmuv3_trigger_irq(s, SMMU_IRQ_CMD_SYNC, 0); + smmuv3_trigger_irq(s, SMMU_IRQ_CMD_SYNC, 0, sec_sid); } break; case SMMU_CMD_PREFETCH_CONFIG: @@ -1733,7 +1744,8 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error = **errp, SMMUSecSID sec_sid) if (cmd_error) { trace_smmuv3_cmdq_consume_error(smmu_cmd_string(type), cmd_error); smmu_write_cmdq_err(s, cmd_error, sec_sid); - smmuv3_trigger_irq(s, SMMU_IRQ_GERROR, R_GERROR_CMDQ_ERR_MASK); + smmuv3_trigger_irq(s, SMMU_IRQ_GERROR, + R_GERROR_CMDQ_ERR_MASK, sec_sid); } =20 trace_smmuv3_cmdq_consume_out(Q_PROD(q), Q_CONS(q), @@ -1849,7 +1861,7 @@ static MemTxResult smmu_writel(SMMUv3State *s, hwaddr= offset, bank->irq_ctrl =3D data; break; case A_GERRORN: - smmuv3_write_gerrorn(s, data); + smmuv3_write_gerrorn(s, data, reg_sec_sid); /* * By acknowledging the CMDQ_ERR, SW may notify cmds can * be processed again @@ -2239,11 +2251,16 @@ static const MemoryRegionOps smmu_mem_ops =3D { }, }; =20 +int smmuv3_get_num_irqs(SMMUv3State *s) +{ + return SMMU_IRQ_NUM; +} + static void smmu_init_irq(SMMUv3State *s, SysBusDevice *dev) { int i; =20 - for (i =3D 0; i < ARRAY_SIZE(s->irq); i++) { + for (i =3D 0; i < smmuv3_get_num_irqs(s); i++) { sysbus_init_irq(dev, &s->irq[i]); } } diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c index d368913e766..43529b73e4a 100644 --- a/hw/arm/virt-acpi-build.c +++ b/hw/arm/virt-acpi-build.c @@ -1169,7 +1169,8 @@ static void acpi_dsdt_add_tegra241_cmdqv(Aml *scope, = VirtMachineState *vms) sbdev =3D SYS_BUS_DEVICE(obj); base =3D platform_bus_get_mmio_addr(pbus, sbdev, 1); base +=3D vms->memmap[VIRT_PLATFORM_BUS].base; - irq =3D platform_bus_get_irqn(pbus, sbdev, NUM_SMMU_IRQS); + irq =3D platform_bus_get_irqn(pbus, sbdev, + smmuv3_get_num_irqs(ARM_SMMUV3(obj))); irq +=3D vms->irqmap[VIRT_PLATFORM_BUS]; irq +=3D ARM_SPI_BASE; =20 diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 0b11f7e328c..d1e12ae1b54 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -267,6 +267,7 @@ static const int a15irqmap[] =3D { [VIRT_UART1] =3D 8, [VIRT_ACPI_GED] =3D 9, [VIRT_GWDT_WS0] =3D 10, + [VIRT_SMMU_SECURE] =3D 11, [VIRT_MMIO] =3D 16, /* ...to 16 + NUM_VIRTIO_TRANSPORTS - 1 */ [VIRT_GIC_V2M] =3D 48, /* ...to 48 + NUM_GICV2M_SPIS - 1 */ [VIRT_SMMU] =3D 74, /* ...to 74 + NUM_SMMU_IRQS - 1 */ @@ -2069,6 +2070,7 @@ static void create_smmu(const VirtMachineState *vms, = PCIBus *bus) { VirtMachineClass *vmc =3D VIRT_MACHINE_GET_CLASS(vms); int irq =3D vms->irqmap[VIRT_SMMU]; + int secure_irq =3D vms->irqmap[VIRT_SMMU_SECURE]; int i; hwaddr base =3D vms->memmap[VIRT_SMMU].base; hwaddr size =3D vms->memmap[VIRT_SMMU].size; @@ -2095,6 +2097,11 @@ static void create_smmu(const VirtMachineState *vms,= PCIBus *bus) sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, qdev_get_gpio_in(vms->gic, irq + i)); } + for (i =3D SMMU_IRQ_NUM_NS; i < smmuv3_get_num_irqs(ARM_SMMUV3(dev)); = i++) { + sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, + qdev_get_gpio_in(vms->gic, + secure_irq + i - SMMU_IRQ_NUM_= NS)); + } create_smmuv3_dt_bindings(vms, base, size, irq); } =20 --=20 2.34.1 From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794673234220424.91372882547364; Sat, 14 Nov 2026 08:20:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGU8-00014M-1o; Sat, 14 Nov 2026 11:20:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGTn-0000Yj-To; Sat, 14 Nov 2026 11:20:02 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGTl-00078r-L2; Sat, 14 Nov 2026 11:19:51 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-6 (Coremail) with UTF8SMTP id AQAAfwBHndwiivhq4xoGAg--.53576S2; Sun, 15 Nov 2026 00:19:46 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8DwfXMhivhq+tv6AA--.39223S3; Sun, 15 Nov 2026 00:19:45 +0800 (CST) From: Tao Tang To: Peter Maydell , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 28/35] hw/arm/smmuv3: Implement SMMU_S_INIT register Date: Sun, 15 Nov 2026 00:19:44 +0800 Message-Id: <20261114161944.3648321-1-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8DwfXMhivhq+tv6AA--.39223S3 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBkgAAs3 Authentication-Results: hzbj-icmmx-6; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvJXoWxCF4UXr43Kw1rtF4UXF1fZwb_yoW5Kr4Upr WkG3s8K3yFy3WSqFsIkaykZ3Zxu3ykGFy7CrZxG34F93Wqy34qv3WDKr1akrZ8CF15Gay7 Wws3uF4DWr15X3DanT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAU7a7-sFnT9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUU UUUUU Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794674135475154100 Content-Type: text/plain; charset="utf-8" Implement read/write handlers for the SMMU_S_INIT Secure-only register. Writing INV_ALL provides a mechanism for software to perform a global invalidation of ALL caches within the SMMU, including IOTLBs and configuration caches across all security states. The MMIO dispatcher decodes the target register bank from the offset and normalizes Secure-window offsets by subtracting SMMU_SECURE_REG_START before switching on the bank-local offset. S_INIT is a Secure-only register and its A_S_INIT constant is an absolute Secure-window offset, so the handler matches it using A_S_INIT - SMMU_SECURE_REG_START and rejects accesses through Non-secure banks. Signed-off-by: Tao Tang Reviewed-by: Pierrick Bouvier Reviewed-by: Jim MacArthur --- hw/arm/smmuv3.c | 37 +++++++++++++++++++++++++++++++++++++ hw/arm/trace-events | 1 + 2 files changed, 38 insertions(+) diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 97a8663349e..5c3d8b4bd98 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -402,6 +402,23 @@ static int smmu_get_ste(SMMUv3State *s, dma_addr_t add= r, STE *buf, =20 } =20 +static void smmuv3_invalidate_all_caches(SMMUv3State *s) +{ + SMMUState *bs =3D &s->smmu_state; + QEMU_LOCK_GUARD(&s->mutex); + + trace_smmuv3_invalidate_all_caches(); + + /* Clear all cached configs including STE and CD */ + if (bs->configs) { + g_hash_table_remove_all(bs->configs); + } + + /* Invalidate all SMMU IOTLB entries */ + smmu_inv_notifiers_all(&s->smmu_state); + smmu_iotlb_inv_all(bs); +} + static SMMUTranslationStatus smmuv3_do_translate(SMMUv3State *s, hwaddr ad= dr, SMMUTransCfg *cfg, SMMUEventInfo *event, @@ -2005,7 +2022,21 @@ static MemTxResult smmu_writel(SMMUv3State *s, hwadd= r offset, case A_EVENTQ_IRQ_CFG1: case A_EVENTQ_IRQ_CFG2: return MEMTX_OK; + case A_S_INIT - SMMU_SECURE_REG_START: + if (reg_sec_sid !=3D SMMU_SEC_SID_S) { + goto unhandled; + } + if (data & R_S_INIT_INV_ALL_MASK) { + /* + * Complete synchronously, including when SMMUEN is set. Root + * and GPC are not implemented; GPCEN must gate this operation + * when that support is added. + */ + smmuv3_invalidate_all_caches(s); + } + break; default: + unhandled: qemu_log_mask(LOG_UNIMP, "%s Unexpected 32-bit access to 0x%"PRIx64" (WI)\n", __func__, offset); @@ -2186,6 +2217,12 @@ static MemTxResult smmu_readl(SMMUv3State *s, hwaddr= offset, case A_EVENTQ_IRQ_CFG2: *data =3D 0; return MEMTX_OK; + case A_S_INIT - SMMU_SECURE_REG_START: + if (reg_sec_sid !=3D SMMU_SEC_SID_S) { + goto unhandled; + } + *data =3D 0; + return MEMTX_OK; default: unhandled: *data =3D 0; diff --git a/hw/arm/trace-events b/hw/arm/trace-events index 4130d16fad5..143f91a03e2 100644 --- a/hw/arm/trace-events +++ b/hw/arm/trace-events @@ -67,6 +67,7 @@ smmuv3_cmdq_tlbi_s12_vmid(int vmid) "vmid=3D%d" smmuv3_notify_flag_add(const char *iommu) "ADD SMMUNotifier node for iommu= mr=3D%s" smmuv3_notify_flag_del(const char *iommu) "DEL SMMUNotifier node for iommu= mr=3D%s" smmuv3_inv_notifiers_iova(const char *name, int asid, int vmid, uint64_t i= ova, uint8_t tg, uint64_t num_pages, int stage) "iommu mr=3D%s asid=3D%d vm= id=3D%d iova=3D0x%"PRIx64" tg=3D%d num_pages=3D0x%"PRIx64" stage=3D%d" +smmuv3_invalidate_all_caches(void) "Invalidate all SMMU caches and TLBs" smmu_reset_exit(void) "" =20 #smmuv3-accel.c --=20 2.34.1 From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794673227911687.6796186160647; Sat, 14 Nov 2026 08:20:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGUB-0001Iw-Sl; Sat, 14 Nov 2026 11:20:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGTx-0000b7-6a; Sat, 14 Nov 2026 11:20:08 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGTt-0007R8-Og; Sat, 14 Nov 2026 11:19:59 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-7 (Coremail) with UTF8SMTP id AQAAfwCXj8MoivhqcGIqBg--.60519S2; Sun, 15 Nov 2026 00:19:52 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8DwS3Ilivhq+9v6AA--.26908S3; Sun, 15 Nov 2026 00:19:50 +0800 (CST) From: Tao Tang To: Peter Maydell , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 29/35] hw/arm/smmuv3: Harden security checks in MMIO handlers Date: Sun, 15 Nov 2026 00:19:49 +0800 Message-Id: <20261114161949.3648535-1-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8DwS3Ilivhq+9v6AA--.26908S3 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBlAAAsx Authentication-Results: hzbj-icmmx-7; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvJXoWxZryfCFWrKr15CFW3Gr15Arb_yoW5KFW3pr WkC34YgrWDG3W3Aa93tw4kAF1fK3ykWrnxJr93G34UuayUtr4rXF18C34YgFnrGFyUZan7 Wr4fAr4fCw12y3DanT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAU7a7-sFnT9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUU UUUUU Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794674129583154100 Content-Type: text/plain; charset="utf-8" This patch hardens the security validation within the main MMIO dispatcher functions (smmu_read_mmio and smmu_write_mmio). First, accesses to the Secure register space are gated by whether SECURE_IMPL is enabled. When it is disabled, all SMMU_S_* registers are read-as-zero and write-ignored. Second, the check for the input stream's security is made more robust. It now validates not only the legacy MemTxAttrs.secure bit, but also the .space field. This improves compatibility with Arm security space handling. Signed-off-by: Tao Tang Reviewed-by: Pierrick Bouvier Reviewed-by: Jim MacArthur --- hw/arm/smmuv3.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 5c3d8b4bd98..0c367dc5221 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -1455,6 +1455,12 @@ static bool smmu_strtab_base_writable(SMMUv3State *s= , SMMUSecSID sec_sid) return !smmu_enabled(s, sec_sid); } =20 +/* Check if the SMMU hardware itself implements Secure state features */ +static inline bool smmu_hw_secure_implemented(SMMUv3State *s) +{ + return FIELD_EX32(s->bank[SMMU_SEC_SID_S].idr[1], S_IDR1, SECURE_IMPL); +} + static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp, SMMUSecSID se= c_sid) { SMMUState *bs =3D ARM_SMMU(s); @@ -1771,6 +1777,37 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error= **errp, SMMUSecSID sec_sid) return 0; } =20 +/* + * Helper function for Secure register access validation. + * + * Follow S_IDR1.SECURE_IMPL accessibility rules for SMMU_S_*: + * - SECURE_IMPL =3D=3D 0: Secure state is not implemented; SMMU_S_* are = RAZ/WI to + * all accesses. + * - SECURE_IMPL =3D=3D 1: Non-secure accesses to SMMU_S_* are RAZ/WI. + */ +static bool smmu_check_secure_access(SMMUv3State *s, MemTxAttrs attrs, + hwaddr offset, bool is_read) +{ + /* Check if the access is Secure */ + if (!(attrs.space =3D=3D ARMSS_Secure || + attrs.secure =3D=3D 1)) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Non-secure %s at offset 0x%" PRIx64 "\n", + __func__, is_read ? "read" : "write", offset); + return false; + } + + /* Check if the Secure state is implemented. */ + if (!smmu_hw_secure_implemented(s)) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Secure %s at offset 0x%" PRIx64 + ": Secure state is not implemented\n", + __func__, is_read ? "read" : "write", offset); + return false; + } + return true; +} + static bool smmuv3_reg_is_raz_wi(hwaddr offset, SMMUSecSID reg_sec_sid) { switch (offset) { @@ -2065,6 +2102,11 @@ static MemTxResult smmu_write_mmio(void *opaque, hwa= ddr offset, uint64_t data, * translate the Secure window to its bank-local register offsets. */ if (offset >=3D SMMU_SECURE_REG_START) { + if (!smmu_check_secure_access(s, attrs, offset, false)) { + trace_smmuv3_write_mmio(offset, data, size, MEMTX_OK); + /* WI */ + return MEMTX_OK; + } reg_sec_sid =3D SMMU_SEC_SID_S; offset -=3D SMMU_SECURE_REG_START; } @@ -2244,6 +2286,12 @@ static MemTxResult smmu_read_mmio(void *opaque, hwad= dr offset, uint64_t *data, /* CONSTRAINED UNPREDICTABLE choice to have page0/1 be exact aliases */ offset &=3D ~0x10000; if (offset >=3D SMMU_SECURE_REG_START) { + if (!smmu_check_secure_access(s, attrs, offset, true)) { + /* RAZ */ + *data =3D 0; + trace_smmuv3_read_mmio(offset, *data, size, MEMTX_OK); + return MEMTX_OK; + } reg_sec_sid =3D SMMU_SEC_SID_S; offset -=3D SMMU_SECURE_REG_START; } --=20 2.34.1 From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17946724951401010.2175106735963; Sat, 14 Nov 2026 08:08:15 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGHl-0000kz-5p; Sat, 14 Nov 2026 11:07:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGHh-0000jn-Lo; Sat, 14 Nov 2026 11:07:21 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGHf-0000cJ-71; Sat, 14 Nov 2026 11:07:21 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-6 (Coremail) with UTF8SMTP id AQAAfwDnPNw0h_hq1RUGAg--.42170S2; Sun, 15 Nov 2026 00:07:16 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8DwKXIyh_hqltv6AA--.35761S3; Sun, 15 Nov 2026 00:07:14 +0800 (CST) From: Tao Tang To: Peter Maydell , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Michael S . Tsirkin" Cc: Pierrick Bouvier , qemu-devel@nongnu.org, qemu-arm@nongnu.org, Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 30/35] hw/pci: Add sec-sid property to PCIDevice Date: Sun, 15 Nov 2026 00:07:14 +0800 Message-Id: <20261114160714.3629275-1-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8DwKXIyh_hqltv6AA--.35761S3 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBVgAAsz Authentication-Results: hzbj-icmmx-6; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvJXoWxGrWfJr1UGFyxXF4rZF45Awb_yoWrXF43pF Z5Ca4FyrWkGa4fKwsIva1xCF1rWan7K3yYkrW29w1DCF17Ar9Yqw4YkFWY9F18urWvqF1Y 934UZFykuw1UAFJanT9S1TB71UUUUjUqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAU7a7-sFnT9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUU UUUUU Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794672498267154100 Content-Type: text/plain; charset="utf-8" Arm SMMUv3 uses a SEC_SID (StreamID Security state) to determine the security state of the programming interface that controls a transaction. The architecture explicitly states that the association between a device and its SEC_SID is a system-defined property, not something derived from the physical address space. We need a way to represent this system-defined SEC_SID for PCI devices if we want to implement SMMU's Secure state. So that SMMUv3 can select the correct register bank and configuration when handling their streams. This patch adds a new char *sec_sid field to PCIDevice, together with a "sec-sid" QOM property. The property is intended to carry the platform-defined SEC_SID for the device; for now only Non-secure and Secure security states are supported. Validate the property in the PCI setter, accepting only the case-sensitive strings "non-secure" and "secure". Reject other values with an error when the property is set, so invalid values are caught in the PCI layer before reaching an SMMU. Signed-off-by: Tao Tang Reviewed-by: Pierrick Bouvier Reviewed-by: Jim MacArthur --- include/hw/pci/pci_device.h | 3 +++ hw/pci/pci.c | 48 +++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/include/hw/pci/pci_device.h b/include/hw/pci/pci_device.h index 5cac6e16886..6e6c49fdd19 100644 --- a/include/hw/pci/pci_device.h +++ b/include/hw/pci/pci_device.h @@ -187,6 +187,9 @@ struct PCIDevice { uint32_t max_bounce_buffer_size; =20 char *sriov_pf; + + /* Arm SMMU SEC_SID */ + char *sec_sid; }; =20 static inline int pci_intx(PCIDevice *pci_dev) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index d8b117799f3..c0ca836fce9 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -51,6 +51,7 @@ #include "hw/core/boards.h" #include "hw/nvram/fw_cfg.h" #include "qapi/error.h" +#include "qapi/visitor.h" #include "qemu/cutils.h" #include "pci-internal.h" #include "qapi/qapi-builtin-type-infos.h" @@ -86,6 +87,46 @@ static const PropertyInfo prop_pci_busnr =3D { .get =3D prop_pci_busnr_get, }; =20 +static void prop_pci_sec_sid_get(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + qdev_prop_string.get(obj, v, name, opaque, errp); +} + +static void prop_pci_sec_sid_set(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + PCIDevice *dev =3D PCI_DEVICE(obj); + g_autofree char *value =3D NULL; + + if (!visit_type_str(v, name, &value, errp)) { + return; + } + + if (strcmp(value, "non-secure") && strcmp(value, "secure")) { + error_setg(errp, "Invalid %s value '%s'; " + "expected 'non-secure' or 'secure'", name, value); + return; + } + + g_free(dev->sec_sid); + dev->sec_sid =3D g_steal_pointer(&value); +} + +static void prop_pci_sec_sid_release(Object *obj, const char *name, + void *opaque) +{ + qdev_prop_string.release(obj, name, opaque); +} + +static const PropertyInfo prop_pci_sec_sid =3D { + .type =3D "str", + .qapi_type =3D &str_type_info, + .get =3D prop_pci_sec_sid_get, + .set =3D prop_pci_sec_sid_set, + .release =3D prop_pci_sec_sid_release, +}; + static const Property pci_props[] =3D { DEFINE_PROP_PCI_DEVFN("addr", PCIDevice, devfn, -1), DEFINE_PROP_STRING("romfile", PCIDevice, romfile), @@ -107,6 +148,13 @@ static const Property pci_props[] =3D { DEFINE_PROP_STRING("sriov-pf", PCIDevice, sriov_pf), DEFINE_PROP_BIT("x-pcie-ext-tag", PCIDevice, cap_present, QEMU_PCIE_EXT_TAG_BITNR, true), + + /* + * System-defined, statically configured SEC_SID for this PCI device, = used + * by Arm SMMU. Only support "non-secure" and "secure" security states. + */ + DEFINE_PROP("sec-sid", PCIDevice, sec_sid, prop_pci_sec_sid, char *), + { .name =3D "busnr", .info =3D &prop_pci_busnr }, }; =20 --=20 2.34.1 From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794672494973900.9438603868593; Sat, 14 Nov 2026 08:08:14 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGHr-0000u2-Vt; Sat, 14 Nov 2026 11:07:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGHp-0000mW-MO; Sat, 14 Nov 2026 11:07:29 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGHn-0001Mg-FW; Sat, 14 Nov 2026 11:07:29 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-7 (Coremail) with UTF8SMTP id AQAAfwC3vNA9h_hqzjEqBg--.58221S2; Sun, 15 Nov 2026 00:07:25 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8DwR3Y6h_hql9v6AA--.34438S3; Sun, 15 Nov 2026 00:07:23 +0800 (CST) From: Tao Tang To: Peter Maydell , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Michael S . Tsirkin" Cc: Pierrick Bouvier , qemu-devel@nongnu.org, qemu-arm@nongnu.org, Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 31/35] hw/arm/smmuv3: Select sec-sid from PCI property and validate SECURE_IMPL Date: Sun, 15 Nov 2026 00:07:22 +0800 Message-Id: <20261114160722.3629356-1-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8DwR3Y6h_hql9v6AA--.34438S3 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBWAAAs9 Authentication-Results: hzbj-icmmx-7; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvJXoW3KF1ktw1rXFy5WrWfCFW8tFb_yoWDWFW3pF WUAFnIqr4UGFn3AFs3tw429a15Xan7WF1rKry3Ka95C347Jr17Xr1vkw1Yvr9rWFWUZw47 ZayIgrW5Cr42y3DanT9S1TB71UUUUjUqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAU7a7-sFnT9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUU UUUUU Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794672498350154101 Content-Type: text/plain; charset="utf-8" Read each PCI device's sec-sid property in smmu-common and cache the corresponding SEC_SID in SMMUDevice::sec_sid, defaulting to Non-secure when the property is unset. The PCI property setter validates explicit values. Use sdev->sec_sid in smmuv3_translate() to select the register bank instead of hardcoding the Non-secure context. Add a SMMUv3-specific compatibility check through PCIIOMMUOps.supports_address_space(). Reject sec-sid=3Dsecure when SMMU_S_IDR1.SECURE_IMPL is 0 or SMMUv3 acceleration is enabled. Propagate errors through errp so incompatible PCI hotplug requests fail without terminating QEMU. Typically, SEC_SID is a system-defined attribute (e.g. sideband or tied-off) rather than something a PCIe endpoint can freely toggle in pre-RME scenario. So this PCI sec-sid property is used as a static platform/testing knob to drive the SMMU bank selection. Signed-off-by: Tao Tang Reviewed-by: Pierrick Bouvier --- include/hw/arm/smmu-common.h | 8 +++++ hw/arm/smmu-common.c | 65 ++++++++++++++++++++++++++++++++++++ hw/arm/smmuv3-accel.c | 2 +- hw/arm/smmuv3.c | 48 +++++++++++++++++++++++++- 4 files changed, 121 insertions(+), 2 deletions(-) diff --git a/include/hw/arm/smmu-common.h b/include/hw/arm/smmu-common.h index a21c6061808..c94bce0e04f 100644 --- a/include/hw/arm/smmu-common.h +++ b/include/hw/arm/smmu-common.h @@ -50,6 +50,8 @@ typedef enum SMMUSecSID { =20 MemTxAttrs smmu_get_txattrs(SMMUSecSID sec_sid); ARMSecuritySpace smmu_get_security_space(SMMUSecSID sec_sid); +int smmu_attrs_to_index(IOMMUMemoryRegion *iommu, MemTxAttrs attrs); +int smmu_num_indexes(IOMMUMemoryRegion *iommu); =20 /* * Page table walk error types @@ -134,6 +136,7 @@ typedef struct SMMUDevice { void *smmu; PCIBus *bus; int devfn; + SMMUSecSID sec_sid; IOMMUMemoryRegion iommu; AddressSpace as; uint32_t cfg_cache_hits; @@ -204,6 +207,8 @@ struct SMMUBaseClass { /*< public >*/ =20 DeviceRealize parent_realize; + bool (*validate_sec_sid)(struct SMMUState *s, SMMUSecSID sec_sid, + int bus_num, int devfn, Error **errp); =20 }; =20 @@ -221,6 +226,9 @@ SMMUPciBus *smmu_get_sbus(SMMUState *s, PCIBus *bus); /* Initialize SMMUDevice handle associated to a SMMUPciBus */ void smmu_init_sdev(SMMUState *s, SMMUDevice *sdev, PCIBus *bus, int devfn= ); =20 +bool smmu_supports_address_space(PCIBus *bus, void *opaque, int devfn, + Error **errp); + =20 static inline bool smmu_sec_sid_is_secure(SMMUSecSID sec_sid) { diff --git a/hw/arm/smmu-common.c b/hw/arm/smmu-common.c index 0408fd25b3a..eec270dac1d 100644 --- a/hw/arm/smmu-common.c +++ b/hw/arm/smmu-common.c @@ -21,6 +21,7 @@ #include "exec/target_page.h" #include "hw/core/cpu.h" #include "hw/pci/pci_bridge.h" +#include "hw/pci/pci_device.h" #include "hw/core/qdev-properties.h" #include "qapi/error.h" #include "qemu/jhash.h" @@ -91,6 +92,19 @@ AddressSpace *smmu_get_address_space(SMMUState *s, SMMUS= ecSID sec_sid) g_assert_not_reached(); } =20 +int smmu_attrs_to_index(IOMMUMemoryRegion *iommu, MemTxAttrs attrs) +{ + if (attrs.unspecified) { + return SMMU_SEC_SID_NS; + } + return attrs.secure ? SMMU_SEC_SID_S : SMMU_SEC_SID_NS; +} + +int smmu_num_indexes(IOMMUMemoryRegion *iommu) +{ + return SMMU_SEC_SID_NUM; +} + /* IOTLB Management */ =20 static guint smmu_iotlb_key_hash(gconstpointer v) @@ -1096,15 +1110,52 @@ SMMUPciBus *smmu_find_smmu_pcibus(SMMUState *s, uin= t8_t bus_num) return NULL; } =20 +static SMMUSecSID smmu_parse_pci_sec_sid(PCIDevice *pdev) +{ + if (!pdev || !pdev->sec_sid || + !strcmp(pdev->sec_sid, "non-secure")) { + return SMMU_SEC_SID_NS; + } + + assert(!strcmp(pdev->sec_sid, "secure")); + return SMMU_SEC_SID_S; +} + +bool smmu_supports_address_space(PCIBus *bus, void *opaque, int devfn, + Error **errp) +{ + SMMUState *s =3D opaque; + SMMUBaseClass *sbc =3D ARM_SMMU_GET_CLASS(s); + int bus_num =3D pci_bus_num(bus); + PCIDevice *pdev =3D pci_find_device(bus, bus_num, devfn); + SMMUSecSID sec_sid =3D smmu_parse_pci_sec_sid(pdev); + + return !sbc->validate_sec_sid || + sbc->validate_sec_sid(s, sec_sid, bus_num, devfn, errp); +} + void smmu_init_sdev(SMMUState *s, SMMUDevice *sdev, PCIBus *bus, int devfn) { static unsigned int index; g_autofree char *name =3D g_strdup_printf("%s-%d-%d", s->mrtypename, d= evfn, index++); + SMMUBaseClass *sbc =3D ARM_SMMU_GET_CLASS(s); + PCIDevice *pdev; + int bus_num; + sdev->smmu =3D s; sdev->bus =3D bus; sdev->devfn =3D devfn; =20 + bus_num =3D pci_bus_num(bus); + pdev =3D pci_find_device(bus, bus_num, devfn); + + sdev->sec_sid =3D smmu_parse_pci_sec_sid(pdev); + /* Also check devices realized before the SMMU was attached. */ + if (sbc->validate_sec_sid) { + sbc->validate_sec_sid(s, sdev->sec_sid, bus_num, devfn, &error_fat= al); + } + memory_region_init_iommu(&sdev->iommu, sizeof(sdev->iommu), s->mrtypename, OBJECT(s), name, UINT64_MAX); address_space_init(&sdev->as, MEMORY_REGION(&sdev->iommu), name); @@ -1129,18 +1180,32 @@ static AddressSpace *smmu_find_add_as(PCIBus *bus, = void *opaque, int devfn) { SMMUState *s =3D opaque; SMMUPciBus *sbus =3D smmu_get_sbus(s, bus); + SMMUBaseClass *sbc =3D ARM_SMMU_GET_CLASS(s); SMMUDevice *sdev; + PCIDevice *pdev; + SMMUSecSID sec_sid; + int bus_num; =20 sdev =3D sbus->pbdev[devfn]; if (!sdev) { sdev =3D sbus->pbdev[devfn] =3D g_new0(SMMUDevice, 1); smmu_init_sdev(s, sdev, bus, devfn); + } else { + bus_num =3D pci_bus_num(bus); + pdev =3D pci_find_device(bus, bus_num, devfn); + sec_sid =3D smmu_parse_pci_sec_sid(pdev); + + if (sbc->validate_sec_sid) { + sbc->validate_sec_sid(s, sec_sid, bus_num, devfn, &error_fatal= ); + } + sdev->sec_sid =3D sec_sid; } =20 return &sdev->as; } =20 static const PCIIOMMUOps smmu_ops =3D { + .supports_address_space =3D smmu_supports_address_space, .get_address_space =3D smmu_find_add_as, }; =20 diff --git a/hw/arm/smmuv3-accel.c b/hw/arm/smmuv3-accel.c index 6fac9420cdf..5a0a689ebc9 100644 --- a/hw/arm/smmuv3-accel.c +++ b/hw/arm/smmuv3-accel.c @@ -899,7 +899,7 @@ static bool smmuv3_accel_supports_as(PCIBus *bus, void = *opaque, int devfn, } return false; } - return true; + return smmu_supports_address_space(bus, opaque, devfn, errp); } /* * Find or add an address space for the given PCI device. diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 0c367dc5221..04955d0691b 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -1162,6 +1162,20 @@ static void smmuv3_fixup_event(SMMUEventInfo *event,= hwaddr iova) } } =20 +static AddressSpace *smmuv3_bypass_target_as(SMMUv3State *s, + SMMUSecSID sec_sid, + int iommu_idx) +{ + g_assert(iommu_idx >=3D SMMU_SEC_SID_NS && + iommu_idx < SMMU_SEC_SID_NUM); + + if (smmu_sec_sid_is_secure(sec_sid) && + iommu_idx =3D=3D SMMU_SEC_SID_S) { + return smmu_get_address_space(&s->smmu_state, SMMU_SEC_SID_S); + } + return smmu_get_address_space(&s->smmu_state, SMMU_SEC_SID_NS); +} + /* Entry point to SMMU, does everything. */ static IOMMUTLBEntry smmuv3_translate(IOMMUMemoryRegion *mr, hwaddr addr, IOMMUAccessFlags flag, int iommu_idx) @@ -1169,7 +1183,7 @@ static IOMMUTLBEntry smmuv3_translate(IOMMUMemoryRegi= on *mr, hwaddr addr, SMMUDevice *sdev =3D container_of(mr, SMMUDevice, iommu); SMMUv3State *s =3D sdev->smmu; uint32_t sid =3D smmu_get_sid(sdev); - SMMUSecSID sec_sid =3D SMMU_SEC_SID_NS; + SMMUSecSID sec_sid =3D sdev->sec_sid; SMMUv3RegBank *bank =3D smmuv3_bank(s, sec_sid); SMMUEventInfo event =3D {.type =3D SMMU_EVT_NONE, .sid =3D sid, @@ -1186,6 +1200,8 @@ static IOMMUTLBEntry smmuv3_translate(IOMMUMemoryRegi= on *mr, hwaddr addr, }; SMMUTLBEntry *cached_entry =3D NULL; =20 + entry.target_as =3D smmuv3_bypass_target_as(s, sec_sid, iommu_idx); + qemu_mutex_lock(&s->mutex); =20 if (!smmu_enabled(s, sec_sid)) { @@ -1461,6 +1477,32 @@ static inline bool smmu_hw_secure_implemented(SMMUv3= State *s) return FIELD_EX32(s->bank[SMMU_SEC_SID_S].idr[1], S_IDR1, SECURE_IMPL); } =20 +static bool smmuv3_validate_sec_sid(SMMUState *bs, SMMUSecSID sec_sid, + int bus_num, int devfn, Error **errp) +{ + SMMUv3State *s =3D ARM_SMMUV3(bs); + + if (sec_sid !=3D SMMU_SEC_SID_S) { + return true; + } + + if (s->accel) { + error_setg(errp, "PCI device %02x:%02x.%x: sec-sid=3Dsecure " + "is not supported with SMMUv3 acceleration", + bus_num, PCI_SLOT(devfn), PCI_FUNC(devfn)); + return false; + } + + if (!smmu_hw_secure_implemented(s)) { + error_setg(errp, "PCI device %02x:%02x.%x: sec-sid=3Dsecure " + "requires S_IDR1.SECURE_IMPL=3D1", + bus_num, PCI_SLOT(devfn), PCI_FUNC(devfn)); + return false; + } + + return true; +} + static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp, SMMUSecSID se= c_sid) { SMMUState *bs =3D ARM_SMMU(s); @@ -2567,6 +2609,7 @@ static void smmuv3_class_init(ObjectClass *klass, con= st void *data) DeviceClass *dc =3D DEVICE_CLASS(klass); ResettableClass *rc =3D RESETTABLE_CLASS(klass); SMMUv3Class *c =3D ARM_SMMUV3_CLASS(klass); + SMMUBaseClass *sbc =3D ARM_SMMU_CLASS(klass); =20 dc->vmsd =3D &vmstate_smmuv3; resettable_class_set_parent_phases(rc, NULL, NULL, smmu_reset_exit, @@ -2576,6 +2619,7 @@ static void smmuv3_class_init(ObjectClass *klass, con= st void *data) device_class_set_props(dc, smmuv3_properties); dc->hotpluggable =3D false; dc->user_creatable =3D true; + sbc->validate_sec_sid =3D smmuv3_validate_sec_sid; =20 object_class_property_set_description(klass, "accel", "Enable SMMUv3 accelerator support. Allows host SMMUv3 to be " @@ -2649,6 +2693,8 @@ static void smmuv3_iommu_memory_region_class_init(Obj= ectClass *klass, =20 imrc->translate =3D smmuv3_translate; imrc->notify_flag_changed =3D smmuv3_notify_flag_changed; + imrc->attrs_to_index =3D smmu_attrs_to_index; + imrc->num_indexes =3D smmu_num_indexes; } =20 static const TypeInfo smmuv3_type_info =3D { --=20 2.34.1 From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794673363272852.7829919969191; Sat, 14 Nov 2026 08:22:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGUN-0002SK-FM; Sat, 14 Nov 2026 11:20:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGU5-0000p7-JP; Sat, 14 Nov 2026 11:20:09 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGU4-0008SK-2a; Sat, 14 Nov 2026 11:20:09 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-7 (Coremail) with UTF8SMTP id AQAAfwD3_p41ivhqhWMqBg--.59773S2; Sun, 15 Nov 2026 00:20:05 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8DwWXUxivhq_dv6AA--.26575S3; Sun, 15 Nov 2026 00:20:02 +0800 (CST) From: Tao Tang To: Peter Maydell , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 32/35] hw/arm/smmuv3: Reject IOMMU notifiers for non-NS devices Date: Sun, 15 Nov 2026 00:20:01 +0800 Message-Id: <20261114162001.3648796-1-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8DwWXUxivhq_dv6AA--.26575S3 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBlgAAsz Authentication-Results: hzbj-icmmx-7; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvdXoW7Jry8uw1xAr1DAF1fGr18AFb_yoWDKrgEvF 4Fq3s5Ww47tF97G3ZIva1xZryFqw4rCrn8WF1xu3WxK3WDC34DXa4DA34vqa1xX34xCFy5 AFZ3uF13Jr9F9jkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8wcxFpf9Il3svdxBIdaVrnU Uv73VFW2AGmfu7jjvjm3AaLaJ3UjIYCTnIWjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRUUUUU UUUU= Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794673364756154100 Content-Type: text/plain; charset="utf-8" VFIO and vhost IOMMU notifiers currently support only the Non-secure system-memory path. Reject notifier registration for non-NS devices instead of allowing an unsupported configuration. Signed-off-by: Tao Tang Reviewed-by: Pierrick Bouvier Reviewed-by: Eric Auger --- hw/arm/smmuv3.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 04955d0691b..9ca52a10a37 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -2663,6 +2663,13 @@ static int smmuv3_notify_flag_changed(IOMMUMemoryReg= ion *iommu, SMMUv3State *s3 =3D sdev->smmu; SMMUState *s =3D &(s3->smmu_state); =20 + if (new !=3D IOMMU_NOTIFIER_NONE && sdev->sec_sid !=3D SMMU_SEC_SID_NS= ) { + error_setg(errp, + "SMMUv3 does not support IOMMU notifiers for " + "Secure devices"); + return -EINVAL; + } + if (new & IOMMU_NOTIFIER_DEVIOTLB_UNMAP) { error_setg(errp, "SMMUv3 does not support dev-iotlb yet"); return -EINVAL; --=20 2.34.1 From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794673259015630.5195970787902; Sat, 14 Nov 2026 08:20:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGUK-00027p-70; Sat, 14 Nov 2026 11:20:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGUA-0001GQ-Qo; Sat, 14 Nov 2026 11:20:15 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGU8-0000MS-Nc; Sat, 14 Nov 2026 11:20:14 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-6 (Coremail) with UTF8SMTP id AQAAfwAHXdw6ivhqCRsGAg--.41853S2; Sun, 15 Nov 2026 00:20:10 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8Dw03I2ivhq_tv6AA--.29919S3; Sun, 15 Nov 2026 00:20:06 +0800 (CST) From: Tao Tang To: Peter Maydell , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 33/35] hw/arm/smmuv3: Initialize the Secure register bank Date: Sun, 15 Nov 2026 00:20:06 +0800 Message-Id: <20261114162006.3648858-1-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8Dw03I2ivhq_tv6AA--.29919S3 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBmAAAs9 Authentication-Results: hzbj-icmmx-6; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvJXoWxGF15Gw15Kw1UCw13uw4DJwb_yoW5Ar13pF ZrAr15Kw13KFn3XwsxAay8AF43Wr4xtwn8Cr9xWF1rC345GrWUJr4DGF1Fqr9Fqr1rua12 qFySk3y5Wr45A3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAU7a7-sFnT9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUU UUUUU Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794673261354154100 Content-Type: text/plain; charset="utf-8" Initialize the Secure register bank (SMMU_SEC_SID_S) with sane default values during the SMMU's reset sequence. This change ensures that key fields, such as the Secure ID registers, GBPA reset value, and queue entry sizes, are set to a known-good state. The SECURE_IMPL attribute of the S_IDR1 register will be introduced later via device properties. This is a necessary step to prevent undefined behavior when Secure SMMU features are subsequently enabled and used by software. Signed-off-by: Tao Tang Reviewed-by: Pierrick Bouvier Reviewed-by: Jim MacArthur --- hw/arm/smmuv3.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 9ca52a10a37..b37b388c75e 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -297,6 +297,7 @@ void smmuv3_record_event(SMMUv3State *s, SMMUEventInfo = *info) static void smmuv3_init_id_regs(SMMUv3State *s) { SMMUv3RegBank *bank =3D smmuv3_bank(s, SMMU_SEC_SID_NS); + SMMUv3RegBank *sbank =3D smmuv3_bank(s, SMMU_SEC_SID_S); =20 /* Based on sys property, the stages supported in smmu will be adverti= sed.*/ if (s->stage && !strcmp("2", s->stage)) { @@ -343,7 +344,16 @@ static void smmuv3_init_id_regs(SMMUv3State *s) bank->idr[5] =3D FIELD_DP32(bank->idr[5], IDR5, GRAN4K, 1); bank->idr[5] =3D FIELD_DP32(bank->idr[5], IDR5, GRAN16K, 1); bank->idr[5] =3D FIELD_DP32(bank->idr[5], IDR5, GRAN64K, 1); + s->aidr =3D 0x1; + + /* Initialize Secure bank */ + memset(sbank->idr, 0, sizeof(sbank->idr)); + /* No stall */ + sbank->idr[0] =3D FIELD_DP32(sbank->idr[0], S_IDR0, STALL_MODEL, 1); + + sbank->idr[1] =3D FIELD_DP32(sbank->idr[1], S_IDR1, S_SIDSIZE, + SMMU_IDR1_SIDSIZE); smmuv3_accel_idr_override(s); } =20 @@ -356,6 +366,7 @@ bool smmuv3_ats_enabled(SMMUv3State *s) static void smmuv3_reset(SMMUv3State *s) { SMMUv3RegBank *bank =3D smmuv3_bank(s, SMMU_SEC_SID_NS); + SMMUv3RegBank *sbank =3D smmuv3_bank(s, SMMU_SEC_SID_S); =20 bank->cmdq.base =3D deposit64(bank->cmdq.base, 0, 5, SMMU_CMDQS); bank->cmdq.prod =3D 0; @@ -375,6 +386,24 @@ static void smmuv3_reset(SMMUv3State *s) bank->gerrorn =3D 0; bank->gbpa =3D SMMU_GBPA_RESET_VAL; =20 + sbank->cmdq.base =3D deposit64(sbank->cmdq.base, 0, 5, SMMU_CMDQS); + sbank->cmdq.prod =3D 0; + sbank->cmdq.cons =3D 0; + sbank->cmdq.entry_size =3D sizeof(struct Cmd); + sbank->eventq.base =3D deposit64(sbank->eventq.base, 0, 5, SMMU_EVENTQ= S); + sbank->eventq.prod =3D 0; + sbank->eventq.cons =3D 0; + sbank->eventq.entry_size =3D sizeof(struct Evt); + + sbank->features =3D 0; + sbank->sid_split =3D 0; + sbank->cr[0] =3D 0; + sbank->cr0ack =3D 0; + sbank->irq_ctrl =3D 0; + sbank->gerror =3D 0; + sbank->gerrorn =3D 0; + sbank->gbpa =3D SMMU_GBPA_RESET_VAL; + s->statusr =3D 0; } =20 --=20 2.34.1 From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794672495005688.703450556208; Sat, 14 Nov 2026 08:08:15 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGHz-0001Fb-Bk; Sat, 14 Nov 2026 11:07:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGHx-00019g-RX; Sat, 14 Nov 2026 11:07:37 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGHv-0001uJ-SV; Sat, 14 Nov 2026 11:07:37 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-7 (Coremail) with UTF8SMTP id AQAAfwAnL6dFh_hqAjIqBg--.61123S2; Sun, 15 Nov 2026 00:07:33 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8Dwe3VDh_hqmNv6AA--.30678S3; Sun, 15 Nov 2026 00:07:31 +0800 (CST) From: Tao Tang To: Peter Maydell , Zhao Liu , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: Pierrick Bouvier , qemu-devel@nongnu.org, qemu-arm@nongnu.org, Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 34/35] hw/arm/smmuv3: Add the secure-impl property Date: Sun, 15 Nov 2026 00:07:31 +0800 Message-Id: <20261114160731.3629605-1-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8Dwe3VDh_hqmNv6AA--.30678S3 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBWgAAs- Authentication-Results: hzbj-icmmx-7; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvJXoWxKrW5tw17Jr4rWr48Ww4DArb_yoW7Xr1DpF 4UCwn8KFWfC3WfZrsIq3WxuF15Ww4kWa15CrWxG395Za1DAr15Jw1qkryYkFWkJr4kJayS vF1xuFW8Cr48XrJanT9S1TB71UUUUjDqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAU7a7-sFnT9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUU UUUUU Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794672498287154100 Content-Type: text/plain; charset="utf-8" Add the secure-impl property and advertise the resolved value through S_IDR1.SECURE_IMPL. The default auto mode follows the availability of the Secure memory address space, allowing the SMMU to follow the machine's Secure configuration without a separate global override. Resolve auto and validate the result in smmu_validate_property(). Reject secure-impl=3Don without Secure memory or stage-1 translation support. Select the available IRQ outputs after resolving the property. Document the relationship to virt Secure configuration and explicit arm-smmuv3 device creation. Signed-off-by: Tao Tang Reviewed-by: Pierrick Bouvier Reviewed-by: Jim MacArthur --- docs/system/arm/virt.rst | 11 +++++++++++ include/hw/arm/smmuv3.h | 2 ++ hw/arm/smmuv3.c | 37 ++++++++++++++++++++++++++++++++++++- hw/core/machine.c | 1 + 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/docs/system/arm/virt.rst b/docs/system/arm/virt.rst index 5f6dd179786..1876fb02e88 100644 --- a/docs/system/arm/virt.rst +++ b/docs/system/arm/virt.rst @@ -289,6 +289,17 @@ User-creatable SMMUv3 devices -device pxb-pcie,id=3Dpcie.1,numa_node=3D1 -device arm-smmuv3,primary-bus=3Dpcie.1,id=3Dsmmuv3.1 =20 + ``secure-impl`` accepts ``on``, ``off``, or the default ``auto``. In + ``auto`` mode, the ``secure-memory`` link determines whether the Secure + programming interface is enabled. On virt, this link is controlled by the + machine's ``secure`` option. Secure support requires Secure memory and + Stage 1 support. Secure Stage 2 is not supported. + + This property also applies to user-created devices, for example:: + + -M virt,secure=3Don + -device arm-smmuv3,primary-bus=3Dpcie.0,secure-impl=3Don + *Accelerated SMMUv3 (nested translation)* =20 The ``accel=3Don`` option enables hardware-accelerated nested translation diff --git a/include/hw/arm/smmuv3.h b/include/hw/arm/smmuv3.h index cb05cb19e32..b7574107038 100644 --- a/include/hw/arm/smmuv3.h +++ b/include/hw/arm/smmuv3.h @@ -89,6 +89,8 @@ struct SMMUv3State { OnOffAuto ats; OasMode oas; SsidSizeMode ssidsize; + OnOffAuto secure_impl; + /* SMMU CMDQV extension */ OnOffAuto cmdqv; =20 diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index b37b388c75e..6a00f6b99fa 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -354,6 +354,8 @@ static void smmuv3_init_id_regs(SMMUv3State *s) =20 sbank->idr[1] =3D FIELD_DP32(sbank->idr[1], S_IDR1, S_SIDSIZE, SMMU_IDR1_SIDSIZE); + sbank->idr[1] =3D FIELD_DP32(sbank->idr[1], S_IDR1, SECURE_IMPL, + s->secure_impl =3D=3D ON_OFF_AUTO_ON); smmuv3_accel_idr_override(s); } =20 @@ -2409,7 +2411,7 @@ static const MemoryRegionOps smmu_mem_ops =3D { =20 int smmuv3_get_num_irqs(SMMUv3State *s) { - return SMMU_IRQ_NUM; + return s->secure_impl =3D=3D ON_OFF_AUTO_ON ? SMMU_IRQ_NUM : SMMU_IRQ_= NUM_NS; } =20 static void smmu_init_irq(SMMUv3State *s, SysBusDevice *dev) @@ -2442,6 +2444,32 @@ static void smmu_reset_exit(Object *obj, ResetType t= ype) =20 static bool smmu_validate_property(SMMUv3State *s, Error **errp) { + SMMUState *bs =3D ARM_SMMU(s); + bool secure_as_available =3D bs->secure_memory !=3D NULL; + + if (s->secure_impl =3D=3D ON_OFF_AUTO_AUTO) { + s->secure_impl =3D secure_as_available ? ON_OFF_AUTO_ON + : ON_OFF_AUTO_OFF; + } + + if (s->secure_impl =3D=3D ON_OFF_AUTO_ON && !secure_as_available) { + error_setg(errp, + "secure-impl=3Don requires a secure-memory address spac= e"); + return false; + } + + /* + * When SECURE_IMPL =3D=3D 1, stage 1 must be supported according to + * (IHI 0070G.b) 6.3.53 SMMU_S_IDR1, Page 442. + */ + if (s->secure_impl =3D=3D ON_OFF_AUTO_ON && + s->stage && !strcmp(s->stage, "2")) { + error_setg(errp, + "secure-impl=3Don requires stage=3D1 or stage=3Dnested= "); + return false; + } + + if (s->oas !=3D OAS_MODE_44 && s->oas !=3D OAS_MODE_48 && s->oas !=3D OAS_MODE_AUTO) { error_setg(errp, "QEMU SMMUv3 model only implements auto, " @@ -2626,6 +2654,13 @@ static const Property smmuv3_properties[] =3D { DEFINE_PROP_SSIDSIZE_MODE("ssidsize", SMMUv3State, ssidsize, SSID_SIZE_MODE_AUTO), DEFINE_PROP_ON_OFF_AUTO("cmdqv", SMMUv3State, cmdqv, ON_OFF_AUTO_AUTO), + /* + * SECURE_IMPL field in S_IDR1 register. + * Indicates whether Secure state is implemented. + * Defaults to auto. + */ + DEFINE_PROP_ON_OFF_AUTO("secure-impl", SMMUv3State, secure_impl, + ON_OFF_AUTO_AUTO), }; =20 static void smmuv3_instance_init(Object *obj) diff --git a/hw/core/machine.c b/hw/core/machine.c index ed9bf8f5008..cd69f1d9159 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -46,6 +46,7 @@ GlobalProperty hw_compat_11_1[] =3D { { "pci-ehci-usb", "x-migrate-fetch-addr-64bit", "off" }, { "pcie-root-port", "speed", "16" }, { "virtio-blk-device", "fua", "off" }, + { TYPE_ARM_SMMUV3, "secure-impl", "off" }, }; const size_t hw_compat_11_1_len =3D G_N_ELEMENTS(hw_compat_11_1); =20 --=20 2.34.1 From nobody Mon Nov 23 04:38:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794673263271789.1043242366434; Sat, 14 Nov 2026 08:21:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGUU-0003Hp-ER; Sat, 14 Nov 2026 11:20:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSGUC-0001Pk-RH; Sat, 14 Nov 2026 11:20:17 -0500 Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net ([162.243.164.118]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSGUB-0000Vi-4y; Sat, 14 Nov 2026 11:20:16 -0500 Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-7 (Coremail) with UTF8SMTP id AQAAfwBXX8M9ivhqLWQqBg--.60044S2; Sun, 15 Nov 2026 00:20:13 +0800 (CST) Received: from phytium.com.cn (unknown [218.76.62.144]) by mail (Coremail) with SMTP id AQAAf8DwOHQ6ivhq_9v6AA--.29619S3; Sun, 15 Nov 2026 00:20:10 +0800 (CST) From: Tao Tang To: Peter Maydell , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur , Tao Tang Subject: [PATCH v6 35/35] hw/arm/smmuv3: Migrate the Secure register bank Date: Sun, 15 Nov 2026 00:20:10 +0800 Message-Id: <20261114162010.3649075-1-tangtao1634@phytium.com.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8DwOHQ6ivhq_9v6AA--.29619S3 X-CM-SenderInfo: pwdqw3tdrrljuu6sx5pwlxzhxfrphubq/1tbiAQATBWr3ZUsBmgAAs- Authentication-Results: hzbj-icmmx-7; spf=neutral smtp.mail=tangtao163 4@phytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvJXoWxWF1UXrW5Aw18CFWDAr1rtFb_yoW5WF45pr n8Gwn8GryDGr43Za13Jan5CFs5Cr48WF4Ykr9rCa93K3WkJ3yaqrnIy340g34kJrWUXw47 ZF1UuF9rGr47ArJanT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAU7a7-sFnT9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUU UUUUU Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=162.243.164.118; envelope-from=tangtao1634@phytium.com.cn; helo=zg8tmtyylji0my4xnjqumte4.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1794673265389154100 Content-Type: text/plain; charset="utf-8" Add the optional smmuv3/bank_s migration subsection when secure-impl is on. Serialize the Secure control, interrupt, error, stream table and queue state using dedicated register-bank and queue descriptions. Leave the subsection absent when the Secure programming interface is disabled. Signed-off-by: Tao Tang Reviewed-by: Pierrick Bouvier Reviewed-by: Jim MacArthur --- hw/arm/smmuv3.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 6a00f6b99fa..a461da8759f 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -2568,6 +2568,54 @@ static const VMStateDescription vmstate_smmuv3_queue= =3D { }, }; =20 +static const VMStateDescription vmstate_smmuv3_secure_bank =3D { + .name =3D "smmuv3_secure_bank", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (const VMStateField[]) { + VMSTATE_UINT32(features, SMMUv3RegBank), + VMSTATE_UINT8(sid_split, SMMUv3RegBank), + VMSTATE_UINT32_ARRAY(cr, SMMUv3RegBank, 3), + VMSTATE_UINT32(cr0ack, SMMUv3RegBank), + VMSTATE_UINT32(gbpa, SMMUv3RegBank), + VMSTATE_UINT32(irq_ctrl, SMMUv3RegBank), + VMSTATE_UINT32(gerror, SMMUv3RegBank), + VMSTATE_UINT32(gerrorn, SMMUv3RegBank), + VMSTATE_UINT64(gerror_irq_cfg0, SMMUv3RegBank), + VMSTATE_UINT32(gerror_irq_cfg1, SMMUv3RegBank), + VMSTATE_UINT32(gerror_irq_cfg2, SMMUv3RegBank), + VMSTATE_UINT64(strtab_base, SMMUv3RegBank), + VMSTATE_UINT32(strtab_base_cfg, SMMUv3RegBank), + VMSTATE_UINT64(eventq_irq_cfg0, SMMUv3RegBank), + VMSTATE_UINT32(eventq_irq_cfg1, SMMUv3RegBank), + VMSTATE_UINT32(eventq_irq_cfg2, SMMUv3RegBank), + VMSTATE_STRUCT(cmdq, SMMUv3RegBank, 0, + vmstate_smmuv3_queue, SMMUQueue), + VMSTATE_STRUCT(eventq, SMMUv3RegBank, 0, + vmstate_smmuv3_queue, SMMUQueue), + VMSTATE_END_OF_LIST(), + }, +}; + +static bool smmuv3_secure_bank_needed(void *opaque) +{ + SMMUv3State *s =3D opaque; + + return s->secure_impl =3D=3D ON_OFF_AUTO_ON; +} + +static const VMStateDescription vmstate_smmuv3_bank_s =3D { + .name =3D "smmuv3/bank_s", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D smmuv3_secure_bank_needed, + .fields =3D (const VMStateField[]) { + VMSTATE_STRUCT(bank[SMMU_SEC_SID_S], SMMUv3State, 0, + vmstate_smmuv3_secure_bank, SMMUv3RegBank), + VMSTATE_END_OF_LIST(), + }, +}; + static bool smmuv3_gbpa_needed(void *opaque) { SMMUv3State *s =3D opaque; @@ -2622,6 +2670,7 @@ static const VMStateDescription vmstate_smmuv3 =3D { }, .subsections =3D (const VMStateDescription * const []) { &vmstate_gbpa, + &vmstate_smmuv3_bank_s, NULL } }; --=20 2.34.1