From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5FD83606A322 for ; Thu, 3 Dec 2026 15:56:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=XX1nAsmT Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xZ9AX-00032V-Vd; Thu, 03 Dec 2026 10:56:27 -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 1xZ9AC-0002rU-Pb for qemu-arm@nongnu.org; Thu, 03 Dec 2026 10:56:12 -0500 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xZ9AA-0005Yn-IH for qemu-arm@nongnu.org; Thu, 03 Dec 2026 10:56:04 -0500 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-4bb845433b8so58125e9.0 for ; Thu, 03 Dec 2026 07:56:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796313361; x=1796918161; darn=nongnu.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=dIM7OWiETBEtSw8v9LKg/n8Gqv5UhIQZu9WD3MYDoBo=; b=XX1nAsmTS63Kal/0wls3fklqBpN/8wzO6OTS6K6T0n1326KGZj8crdwlboQ2kAZSQV GzawhotitpL6V7OoMP59Bn49UBLFgzZ2sMfdrc6qYFVl3JzLLCGW1iGaUFDaBfpYnyff 0RjDDisO8VVaNL6GeUcd+4rtzbtxXJIEo1HftBIFF7TsCSLIeFvENv6L1zCAW3kbwN+n z4S8zbU0bKzqNyY7TNcjgScOsoEdTp7qj3Pe1UK3MuFjdq8/F23vZs3zV5JkP7/W1q0g 8rtT71CvJumYabt2GdkgjQr+O64s0kcVVnmkqgsWmflk8udzg6sOBf8OJDbmIu3PaprA 1JxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796313361; x=1796918161; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=dIM7OWiETBEtSw8v9LKg/n8Gqv5UhIQZu9WD3MYDoBo=; b=b4KFGFC5T3iE0YqQJAXLnFbrnhmWGH4fDPGnqI0P9SyDKvVeUzgc/PwdReo/Rkdx1m d1LKM9GQxXVJRw+sRLDx7O+bJF7lAfiL7epXPCG3LZqy/Eb9CtVHlNnALDzSmahmxCbD dci/iDTZL4YfmTfsoUrAnjt5ENn1E48MFGNTKEpFTeXN7bN+RcV+kYtRkLBS4wEeObSO XTm2Xz9fSBar5XDqI1N2S5EE8egKMKAJCQg5wxZziTYvXcN28J5B9JCGYbNa0rhSZIZs GFHqzMihP/xkoHIIYheFhRoCj2knTLLhh2S9sPJFDC3vZmSBmFFHfdf4MPq/yUj37au/ ErWw== X-Forwarded-Encrypted: i=1; AL+hErEttqSx+JwwUj4GI58/MQnfRwiBLPUIDzEjGkDrsrYJFFY4poG6DX7wy2xDBSDem35Rm1lMKup9ow==@nongnu.org X-Gm-Message-State: APuU4Z92+8rCAjDqA8BU+7ikOKuNrQn/xPTET+qkXYV7wAQT87dx2g3L METYg7W13QkhpZ3LRA/R/sgjsiyRIA6F/BRb6V+m+zes3zPq9pbC7/MTO1MpR49V+Q== X-Gm-Gg: AZFdTZeTjHYK8uNbI+ssvL0ZK2o6wbVinQJ4da0sSq2yBNlXOW+zxeXgMwGdHMQTmm7 9XM5utddXi1mKyCetYf3zqoPAt2DDN3J+7wsYh4OXO78215ctvdMW7dNBWjLGPKG3gPswVJOD9Z wFgQm4X7g6p6FMG6XaEoRCDtcQ4JfCG6YYJwyRrn3858hFwP4ktw3SIMEYZh2YFsO9IFSfBUXs9 AS4zqp+hiSINtURAYtNBT796I6J85iDLsVXHHD8t3mCGDKPIpMCBrwUYkTDpILxulT3WM3xhg4i Okql9HF5sssYtvoXmRGKvtfGTGgM8UFME766oct6LQOQHh4DpzAjqet7hIKm6EwVP0yLn+RvXHH tc97rYi834wcmZUWtDc0TzreO9aAEHuJCzRFsyo0/0wgCdvrh8caYIiHdtVpL6svT/Z9cAb22pH hgcIEfCgWVPLu/yJYwhhp8/l5FsTFWMvaPon/jYSU9NIRGB1jAaCgQvNn66GaN/FYtlo4s6NZI3 F2ITcSrpqMqE90WPh1Wo8oZvtBPx5HjaGypetoTAkO8FpMqBpV3q35qNRyx1gk6Za66zKY+cFle CyLNYUFqFtP57+S8HbPFQ6KlRs4Kh4GPT3FdHCnW0npXlQFuTU9lXFK+hHUWrRYoKT5pgQ== X-Received: by 2002:a05:600c:6387:b0:4bb:7ae3:3517 with SMTP id 5b1f17b1804b1-4bbe0fd61bamr1139875e9.4.1796313360300; Thu, 03 Dec 2026 07:56:00 -0800 (PST) Received: from google.com (160.193.189.35.bc.googleusercontent.com. [35.189.193.160]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbcf2c9e64sm89163165e9.3.2026.12.03.07.55.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 07:55:59 -0800 (PST) Date: Thu, 3 Dec 2026 15:55:52 +0000 From: Mostafa Saleh To: Tao Tang Cc: Peter Maydell , Eric Auger , Philippe =?iso-8859-1?Q?Mathieu-Daud=E9?= , qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Chao Liu , Chen Baozi , Jim MacArthur Subject: Re: [PATCH v6 17/35] hw/arm/smmuv3: Scope IOTLB invalidation by SEC_SID Message-ID: References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> <20261114161753.3645568-8-tangtao1634@phytium.com.cn> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261114161753.3645568-8-tangtao1634@phytium.com.cn> Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=smostafa@google.com; helo=mail-wm1-x32f.google.com X-Spam_score_int: -144 X-Spam_score: -14.5 X-Spam_bar: -------------- X-Spam_report: (-14.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, ENV_AND_HDR_SPF_MATCH=-0.5, FSL_HELO_FAKE=3.099, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5, USER_IN_DEF_SPF_WL=-7.5 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-arm-bounces+qemu-arm=archiver.kernel.org@nongnu.org X-Spam-Status: No, score=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Sun, Nov 15, 2026 at 12:17:51AM +0800, Tao Tang wrote: > 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, uint64_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 *cfg, SMMUTLBEntry *new, > g_hash_table_insert(bs->iotlb, key, new); > } > > +static gboolean smmu_hash_remove_by_sec_sid(gpointer key, gpointer value, > + gpointer user_data) > +{ > + SMMUIOTLBKey *iotlb_key = (SMMUIOTLBKey *)key; > + SMMUSecSID *sec_sid = (SMMUSecSID *)user_data; > + > + return SMMU_IOTLB_SEC_SID(*iotlb_key) == *sec_sid; > +} > + > void smmu_iotlb_inv_all(SMMUState *s) > { > trace_smmu_iotlb_inv_all(); > g_hash_table_remove_all(s->iotlb); > } > > +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, SMMUSecSID sec_sid) > } > > 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 = CMD_ADDR(cmd); > uint8_t type = CMD_TYPE(cmd); > @@ -1353,10 +1353,8 @@ static void smmuv3_range_inval(SMMUState *s, Cmd *cmd, SMMUStage stage, > uint64_t num_pages; > uint8_t granule; > int asid = -1; > - SMMUv3State *smmuv3 = ARM_SMMUV3(s); > > - /* Only consider VMID if stage-2 is supported. */ > - if (STAGE2_SUPPORTED(smmuv3)) { > + if (use_vmid) { > vmid = CMD_VMID(cmd); > } > > @@ -1403,6 +1401,26 @@ static void smmuv3_range_inval(SMMUState *s, Cmd *cmd, SMMUStage stage, > } > } > > +static inline bool > +smmu_cmdq_stage2_supported(SMMUv3State *s, SMMUSecSID sec_sid) > +{ > + /* IDR0.S2P: Stage 2 translation supported */ > + bool s2p = STAGE2_SUPPORTED(s); > + if (!s2p) { > + return false; > + } > + > + /* > + * For Secure Command queue, Secure stage 2 is additionally gated by SEL2 > + * (SEL2 is 0 if S2P is 0). > + */ > + if (sec_sid == SMMU_SEC_SID_S) { > + return FIELD_EX32(s->bank[SMMU_SEC_SID_S].idr[1], S_IDR1, SEL2); > + } This is never true, I'd suggest to drop it for now and make this helper simpler, but no strong opinion. > + > + return true; > +} > + > static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp, SMMUSecSID sec_sid) > { > SMMUState *bs = ARM_SMMU(s); > @@ -1412,6 +1430,7 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp, SMMUSecSID sec_sid) > SMMUCommandType type = 0; > MemTxAttrs attrs = smmu_get_txattrs(sec_sid); > AddressSpace *as = smmu_get_address_space(bs, sec_sid); > + bool queue_stage2_supported = smmu_cmdq_stage2_supported(s, sec_sid); > > 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 set it > * to -1 as the value used for stage-1 only VMIDs. > */ > - if (STAGE2_SUPPORTED(s)) { > + if (queue_stage2_supported) { > vmid = CMD_VMID(&cmd); > } > > @@ -1568,30 +1587,49 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp, SMMUSecSID sec_sid) > * If stage-2 is supported, invalidate for this VMID only, otherwise > * invalidate the whole thing. > */ > - if (STAGE2_SUPPORTED(s)) { > + if (queue_stage2_supported) { > vmid = 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 = 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 from 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 = sec_sid > SMMU_SEC_SID_S ? > + sec_sid : SMMU_SEC_SID_NS; I think the realm comments are confusing, and target_sec_sid is always NS now, so I'd suggest just to remove this for now until realms are supported and keep the switch case as it was. Thanks, Mostafa > + > + 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 = SMMU_CERROR_ILL; > break; > } > break; > + } > case SMMU_CMD_TLBI_NH_VAA: > case SMMU_CMD_TLBI_NH_VA: > if (!STAGE1_SUPPORTED(s)) { > cmd_error = 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 = 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, true); > 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, uint64_t baseaddr, uint6 > smmu_ptw_block_pte(int stage, int level, uint64_t baseaddr, uint64_t pteaddr, uint64_t pte, uint64_t iova, uint64_t gpa, int bsize_mb) "stage=%d level=%d base@=0x%"PRIx64" pte@=0x%"PRIx64" pte=0x%"PRIx64" iova=0x%"PRIx64" block address = 0x%"PRIx64" block size = %d MiB" > smmu_get_pte(uint64_t baseaddr, int index, uint64_t pteaddr, uint64_t pte) "baseaddr=0x%"PRIx64" index=0x%x, pteaddr=0x%"PRIx64", pte=0x%"PRIx64 > smmu_iotlb_inv_all(void) "IOTLB invalidate all" > +smmu_iotlb_inv_by_sec_sid(int sec_sid) "IOTLB invalidate sec_sid=%d" > smmu_iotlb_inv_asid_vmid(int sec_sid, int asid, int vmid) "IOTLB invalidate sec_sid=%d asid=%d vmid=%d" > smmu_iotlb_inv_vmid(int sec_sid, int vmid) "IOTLB invalidate sec_sid=%d vmid=%d" > smmu_iotlb_inv_vmid_s1(int sec_sid, int vmid) "IOTLB invalidate S1 sec_sid=%d vmid=%d" > @@ -60,7 +61,7 @@ smmuv3_config_cache_hit(uint32_t sid, uint32_t hits, uint32_t misses, uint32_t p > smmuv3_config_cache_miss(uint32_t sid, uint32_t hits, uint32_t misses, uint32_t perc) "Config cache MISS for sid=0x%x (hits=%d, misses=%d, hit rate=%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=%d vmid=%d asid=%d addr=0x%"PRIx64" tg=%d num_pages=0x%"PRIx64" ttl=%d leaf=%d stage=%d" > smmuv3_cmdq_tlbi_nh(int sec_sid, int vmid) "sec_sid=%d vmid=%d" > -smmuv3_cmdq_tlbi_nsnh(void) "" > +smmuv3_cmdq_tlbi_nsnh(int sec_sid, int target_sec_sid) "cmdq_sec_sid=%d target_sec_sid=%d" > smmuv3_cmdq_tlbi_nh_asid(int sec_sid, int asid) "sec_sid=%d asid=%d" > smmuv3_cmdq_tlbi_s12_vmid(int vmid) "vmid=%d" > smmuv3_notify_flag_add(const char *iommu) "ADD SMMUNotifier node for iommu mr=%s" > -- > 2.34.1 >