From: Mostafa Saleh <smostafa@google.com>
To: Tao Tang <tangtao1634@phytium.com.cn>
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"Eric Auger" <eric.auger@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>,
qemu-devel@nongnu.org, qemu-arm@nongnu.org,
"Pierrick Bouvier" <pierrick.bouvier@oss.qualcomm.com>,
"Chao Liu" <chao.liu@processmission.com>,
"Chen Baozi" <chenbaozi@phytium.com.cn>,
"Jim MacArthur" <jim.macarthur@linaro.org>
Subject: Re: [PATCH v6 13/35] hw/arm/smmuv3: Pass sec_sid into cmdq consume path
Date: Thu, 3 Dec 2026 15:51:30 +0000 [thread overview]
Message-ID: <axGQAgs37K1ktzda@google.com> (raw)
In-Reply-To: <20261114161753.3645568-4-tangtao1634@phytium.com.cn>
On Sun, Nov 15, 2026 at 12:17:47AM +0800, Tao Tang wrote:
> 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 <tangtao1634@phytium.com.cn>
> Reviewed-by: Eric Auger <eric.auger@redhat.com>
> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> Reviewed-by: Jim MacArthur <jim.macarthur@linaro.org>
> Reviewed-by: Mostafa Saleh <smostafa@google.com>
> ---
> 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, uint32_t new_gerrorn)
> trace_smmuv3_write_gerrorn(toggled & pending, bank->gerrorn);
> }
>
> -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 = Q_CONS_ENTRY(q);
> MemTxResult ret;
> int i;
>
> - ret = dma_memory_read(&address_space_memory, addr, cmd, sizeof(Cmd),
> - MEMTXATTRS_UNSPECIFIED);
> + ret = dma_memory_read(as, addr, cmd, sizeof(Cmd), attrs);
> if (ret != MEMTX_OK) {
> return ret;
> }
> @@ -1384,14 +1384,15 @@ static void smmuv3_range_inval(SMMUState *s, Cmd *cmd, SMMUStage stage,
> }
> }
>
> -static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp)
> +static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp, SMMUSecSID sec_sid)
> {
> SMMUState *bs = ARM_SMMU(s);
> SMMUCmdError cmd_error = SMMU_CERROR_NONE;
> - SMMUSecSID sec_sid = SMMU_SEC_SID_NS;
> SMMUv3RegBank *bank = smmuv3_bank(s, sec_sid);
> SMMUQueue *q = &bank->cmdq;
> SMMUCommandType type = 0;
> + MemTxAttrs attrs = smmu_get_txattrs(sec_sid);
> + AddressSpace *as = smmu_get_address_space(bs, sec_sid);
>
> if (!smmuv3_cmdq_enabled(s, sec_sid)) {
> return 0;
> @@ -1406,19 +1407,30 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp)
> while (!smmuv3_q_empty(q)) {
> uint32_t pending = bank->gerror ^ bank->gerrorn;
> Cmd cmd;
> + SMMUSecSID ssec = SMMU_SEC_SID_NS;
ssec is overridden below, so no need to init it here.
>
> - 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));
>
> if (FIELD_EX32(pending, GERROR, CMDQ_ERR)) {
> break;
> }
>
> - if (queue_read(q, &cmd) != MEMTX_OK) {
> + if (queue_read(q, &cmd, as, attrs) != MEMTX_OK) {
> cmd_error = SMMU_CERROR_ABT;
> break;
> }
>
> + ssec = CMD_SSEC(&cmd) ? SMMU_SEC_SID_S : SMMU_SEC_SID_NS;
> + /*
> + * A command with SSec == 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 != SMMU_SEC_SID_S) {
> + cmd_error = SMMU_CERROR_ILL;
> + break;
> + }
Not all commands have this bit, AFAICT, the other possible value is
RES0, so that check won't hurt but it can be more consistent.
Thanks,
Mostafa
> +
> type = CMD_TYPE(&cmd);
>
> trace_smmuv3_cmdq_opcode(smmu_cmd_string(type));
> @@ -1438,11 +1450,6 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp)
> uint32_t sid = CMD_SID(&cmd);
> SMMUDevice *sdev = smmu_find_sdev(bs, sid);
>
> - if (CMD_SSEC(&cmd)) {
> - cmd_error = SMMU_CERROR_ILL;
> - break;
> - }
> -
> if (!sdev) {
> break;
> }
> @@ -1462,11 +1469,6 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp)
> uint8_t range = CMD_STE_RANGE(&cmd);
> SMMUSIDRange sid_range;
>
> - if (CMD_SSEC(&cmd)) {
> - cmd_error = SMMU_CERROR_ILL;
> - break;
> - }
> -
> mask = (1ULL << (range + 1)) - 1;
> sid_range.start = sid & ~mask;
> sid_range.end = sid_range.start + mask;
> @@ -1485,11 +1487,6 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp)
> uint32_t sid = CMD_SID(&cmd);
> SMMUDevice *sdev = smmu_find_sdev(bs, sid);
>
> - if (CMD_SSEC(&cmd)) {
> - cmd_error = SMMU_CERROR_ILL;
> - break;
> - }
> -
> if (!sdev) {
> break;
> }
> @@ -1713,7 +1710,7 @@ static MemTxResult smmu_writel(SMMUv3State *s, hwaddr offset,
> bank->cr[0] = data;
> bank->cr0ack = 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 = 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 = 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 = data;
> - smmuv3_cmdq_consume(s, &local_err);
> + smmuv3_cmdq_consume(s, &local_err, reg_sec_sid);
> break;
> case A_CMDQ_CONS:
> bank->cmdq.cons = 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=%d"
> smmuv3_write_gerror(uint32_t toggled, uint32_t gerror) "toggled=0x%x, new GERROR=0x%x"
> smmuv3_write_gerrorn(uint32_t acked, uint32_t gerrorn) "acked=0x%x, new GERRORN=0x%x"
> smmuv3_unhandled_cmd(uint32_t type) "Unhandled command type=%d"
> -smmuv3_cmdq_consume(uint32_t prod, uint32_t cons, uint8_t prod_wrap, uint8_t cons_wrap) "prod=%d cons=%d prod.wrap=%d cons.wrap=%d"
> +smmuv3_cmdq_consume(int sec_sid, uint32_t prod, uint32_t cons, uint8_t prod_wrap, uint8_t cons_wrap) "sec_sid=%d prod=%d cons=%d prod.wrap=%d cons.wrap=%d"
> smmuv3_cmdq_opcode(const char *opcode) "<--- %s"
> smmuv3_cmdq_consume_out(uint32_t prod, uint32_t cons, uint8_t prod_wrap, uint8_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"
> --
> 2.34.1
>
next prev parent reply other threads:[~2026-12-03 15:51 UTC|newest]
Thread overview: 71+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-14 15:46 [PATCH v6 00/35] hw/arm/smmuv3: Support Secure state for SMMUv3 Tao Tang
2026-11-14 16:05 ` [PATCH v6 27/35] hw/arm/smmuv3: Route IRQ and GERROR handling by SEC_SID Tao Tang
2026-12-03 21:06 ` Mostafa Saleh
2026-11-14 16:07 ` [PATCH v6 30/35] hw/pci: Add sec-sid property to PCIDevice Tao Tang
2026-11-14 16:07 ` [PATCH v6 31/35] hw/arm/smmuv3: Select sec-sid from PCI property and validate SECURE_IMPL Tao Tang
2026-11-14 16:07 ` [PATCH v6 34/35] hw/arm/smmuv3: Add the secure-impl property Tao Tang
2026-11-14 16:13 ` [PATCH v6 01/35] hw/arm/smmuv3: Introduce Secure registers Tao Tang
2026-11-14 16:13 ` [PATCH v6 02/35] hw/arm/smmuv3: Introduce banked registers for SMMUv3 state Tao Tang
2026-11-14 16:13 ` [PATCH v6 03/35] hw/arm/smmuv3: Thread SEC_SID through helper APIs Tao Tang
2026-11-14 16:13 ` [PATCH v6 04/35] hw/arm/smmuv3: Track SEC_SID in configs and events Tao Tang
2026-11-14 16:13 ` [PATCH v6 05/35] hw/arm/smmu-common: Add security-aware address space selector Tao Tang
2026-11-14 16:16 ` [PATCH v6 06/35] hw/arm/smmuv3: Plumb transaction attributes into config helpers Tao Tang
2026-12-03 15:47 ` Mostafa Saleh
2026-12-04 8:20 ` Eric Auger
2026-11-14 16:16 ` [PATCH v6 07/35] hw/arm/smmuv3: Reject Secure STEs with stage-2 enabled Tao Tang
2026-12-03 15:47 ` Mostafa Saleh
2026-12-04 8:24 ` Eric Auger
2026-11-14 16:16 ` [PATCH v6 08/35] hw/arm/smmu-common: Key configuration cache on SMMUDevice and SEC_SID Tao Tang
2026-11-14 16:16 ` [PATCH v6 09/35] hw/arm/smmu: Add PTE NS/NSTable helpers Tao Tang
2026-11-14 16:17 ` [PATCH v6 10/35] hw/arm/smmuv3: Store CD NSCFG in TT info Tao Tang
2026-11-14 16:17 ` [PATCH v6 11/35] hw/arm/smmu-common: Implement Secure state handling in ptw Tao Tang
2026-12-04 13:52 ` Eric Auger
2026-11-14 16:17 ` [PATCH v6 12/35] hw/arm/smmuv3: Tag IOTLB cache keys with SEC_SID Tao Tang
2026-12-03 15:48 ` Mostafa Saleh
2026-11-14 16:17 ` [PATCH v6 13/35] hw/arm/smmuv3: Pass sec_sid into cmdq consume path Tao Tang
2026-12-03 15:51 ` Mostafa Saleh [this message]
2026-11-14 16:17 ` [PATCH v6 14/35] hw/arm/smmuv3: Make evtq producer use SEC_SID Tao Tang
2026-11-14 16:17 ` [PATCH v6 15/35] hw/arm/smmuv3: Limit IOMMU notifications to Non-secure targets Tao Tang
2026-12-01 10:46 ` Jim MacArthur
2026-12-03 15:52 ` Mostafa Saleh
2026-12-04 14:43 ` Eric Auger
2026-11-14 16:17 ` [PATCH v6 16/35] hw/arm/smmuv3: Scope configuration invalidation by SEC_SID Tao Tang
2026-12-01 12:32 ` Jim MacArthur
2026-12-03 15:53 ` Mostafa Saleh
2026-12-04 15:02 ` Eric Auger
2026-12-04 15:09 ` Eric Auger
2026-11-14 16:17 ` [PATCH v6 17/35] hw/arm/smmuv3: Scope IOTLB " Tao Tang
2026-12-01 13:15 ` Jim MacArthur
2026-12-03 15:55 ` Mostafa Saleh
2026-12-04 17:15 ` Eric Auger
2026-12-04 17:43 ` Eric Auger
2026-11-14 16:17 ` [PATCH v6 18/35] hw/arm/smmuv3: Fix VMID tagging for Secure stage 1 Tao Tang
2026-12-01 13:20 ` Jim MacArthur
2026-12-03 15:56 ` Mostafa Saleh
2026-11-14 16:17 ` [PATCH v6 19/35] hw/arm/smmuv3: Keep accelerated invalidation Non-secure-only Tao Tang
2026-12-01 14:14 ` Jim MacArthur
2026-12-03 15:57 ` Mostafa Saleh
2026-11-14 16:19 ` [PATCH v6 20/35] hw/arm/smmuv3: Fix ATC invalidation command checks Tao Tang
2026-12-01 18:30 ` Jim MacArthur
2026-12-03 15:58 ` Mostafa Saleh
2026-11-14 16:19 ` [PATCH v6 21/35] hw/arm/smmuv3: Make GERROR_IRQ_CFG registers RES0 without MSI Tao Tang
2026-12-03 15:58 ` Mostafa Saleh
2026-11-14 16:19 ` [PATCH v6 22/35] hw/arm/smmuv3: Ignore CR2 writes while the SMMU is enabled Tao Tang
2026-12-03 15:58 ` Mostafa Saleh
2026-11-14 16:19 ` [PATCH v6 23/35] hw/arm/smmuv3: Guard stream table register writes Tao Tang
2026-12-03 20:09 ` Mostafa Saleh
2026-11-14 16:19 ` [PATCH v6 24/35] hw/arm/smmuv3: Guard command queue " Tao Tang
2026-11-14 16:19 ` [PATCH v6 25/35] hw/arm/smmuv3: Guard event " Tao Tang
2026-11-14 16:19 ` [PATCH v6 26/35] hw/arm/smmuv3: Determine register bank from MMIO offset Tao Tang
2026-12-03 21:05 ` Mostafa Saleh
2026-11-14 16:19 ` [PATCH v6 28/35] hw/arm/smmuv3: Implement SMMU_S_INIT register Tao Tang
2026-12-03 21:07 ` Mostafa Saleh
2026-11-14 16:19 ` [PATCH v6 29/35] hw/arm/smmuv3: Harden security checks in MMIO handlers Tao Tang
2026-12-03 21:08 ` Mostafa Saleh
2026-11-14 16:20 ` [PATCH v6 32/35] hw/arm/smmuv3: Reject IOMMU notifiers for non-NS devices Tao Tang
2026-12-03 21:09 ` Mostafa Saleh
2026-11-14 16:20 ` [PATCH v6 33/35] hw/arm/smmuv3: Initialize the Secure register bank Tao Tang
2026-12-03 21:10 ` Mostafa Saleh
2026-11-14 16:20 ` [PATCH v6 35/35] hw/arm/smmuv3: Migrate " Tao Tang
2026-12-03 9:24 ` [PATCH v6 00/35] hw/arm/smmuv3: Support Secure state for SMMUv3 Jim MacArthur
2026-12-03 9:37 ` Eric Auger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=axGQAgs37K1ktzda@google.com \
--to=smostafa@google.com \
--cc=chao.liu@processmission.com \
--cc=chenbaozi@phytium.com.cn \
--cc=eric.auger@redhat.com \
--cc=jim.macarthur@linaro.org \
--cc=peter.maydell@linaro.org \
--cc=philmd@oss.qualcomm.com \
--cc=pierrick.bouvier@oss.qualcomm.com \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=tangtao1634@phytium.com.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.