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 75E71606A32C for ; Fri, 4 Dec 2026 15:09:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=NA3YSoPi; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b=DIvEnipJ Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xZUup-0004K5-FL; Fri, 04 Dec 2026 10:09: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 1xZUul-0004JX-Ne for qemu-devel@nongnu.org; Fri, 04 Dec 2026 10:09:37 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xZUuj-0005Ns-5R for qemu-devel@nongnu.org; Fri, 04 Dec 2026 10:09:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796396972; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sq2TlXb490u5e1byhg2U+jS58bztX+/bePpnxI4zy6Y=; b=NA3YSoPic1BXdosnmmDGTrUWeJ1DfN9K3bubCkyUxlp2IpqqeBmwpe31Pp2bizPDUHq+Bx bP1VELSRZzNEXD+j99Riff1d4wFk2/nyrzbmp+E20blTC6S1ilhUSeb0/gukfgHtifFlvE YJ9WzOEGFyt/Y0h3ZREsurjxQvrGVP4= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-621-PD7jH2x2MaqM3MiEnUDQ2Q-1; Fri, 4 Dec 2026 15:09:30 +0000 X-MC-Unique: PD7jH2x2MaqM3MiEnUDQ2Q-1 X-Mimecast-MFC-AGG-ID: PD7jH2x2MaqM3MiEnUDQ2Q_1796396969 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4a20e41008cso7277145e9.1 for ; Fri, 04 Dec 2026 07:09:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1796396969; x=1797001769; darn=nongnu.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=sq2TlXb490u5e1byhg2U+jS58bztX+/bePpnxI4zy6Y=; b=DIvEnipJ9ULpKKxCJDxlnnVsO4MEwMwFjmCUAu8P8W+ExHPHSZ5yMVvt6zL1XPnM5H qlmVogBsTp26ESOQ2kDLbxv9Bj4jIN5xp4H/M1w/qMXOMVMDvXFFRPHVqcaTjvXOFmLj JdJ7F46dN6GK118i+H3fLppIsJYABu54vEjmAAtrHKRbqqrKWVbJJv2JiC7RIe7W6eV3 oNkiGejtsv2iwtWiAkcIupxarxSVE5p+7oU5A9kO/t/YaX1iq5WRQ/qHPJXJycQUMkvW 4487iQ/eFFV1rget7fuwgPDhznpAuuKc4wi02Vbm9I9jC/xgLyLi0O3DWgwov7qb/kUX DK1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796396969; x=1797001769; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=sq2TlXb490u5e1byhg2U+jS58bztX+/bePpnxI4zy6Y=; b=D5MZ+I5/8NmhhjGYmuBBolVNiH4r0tFzsOAy2R2UT2pyAIw26UTZwqJMygszU5Aa8l aThfCbTL6GvlhQZHn/o8t/LzoRGUTDCsQWUX2AffK9JHFFa47os1iEwvsVNv+t4Sa9jw NpSecq2N8JVbLNMTS/ym7qzLTPADjF3BiIInkcbUE1XFjZu3szxDbWLAWzd3ePAPAL91 f9aE40MZXC0EOYSu260n+jr1NM6F1FaEf8go1OFkA0i2Ap3BQkmlFFHNItVSGkWytqz0 RmIof1KhCtaw3vMRjwLxBjnMNHJMLPpzHgBAnyUBs153c58EwPxwiWZgQvKQ/ql3Snwb Fe2Q== X-Gm-Message-State: APuU4Z82djJkYcx1xX1ZW/KfxdugLQWVl9IoddJwouBA5Vbef5AOagLb NKYY1Y58lt1sp+qCsuBJ0XiL75TaSM2YwRC6NmsHkbui/2FZ/STFv9YOTZsTNDax99b5VmdRMGM Ns7CPsbE5g7xPuKygusm3l/QSMlhmdhRTOH21knfQGkigejAXDCc+7CM8 X-Gm-Gg: AZFdTZfeGdg4Y9i4jmvPToMAAg99HcqDXztYg++8HH/ySeUl+AO3HRd3c1alXbXI4FC F2RJSPe6V/nC6WLYkf9Ok3+kM7r1I5ZjsB1qyPZn2P/NH2mf0P0ciXgRjer0iMuaLbsW+u25V6v 3YR/aJeYDeVNle+0764yJDa0O8fhBLs7q8pJZ1HMgHYN49fNW1y8NVu5lA+CTtE+3L9//IcP+8t wcxKijsD7NgTjdQSCCYPAjyMCGW0wmAqgL1GebvLIJMgQuO05ixNZW0xRvlxj8hsbnMeB8MEYmQ tR4BShRmmIBToG74yMphXu+adiVuxJJzi5tXzoEuwM7i+KM6nPZOz8SQsnoWl/bn5lKrijL3aRg Y5ZeGImu1msXMJFUiAslDe6PleFlKj74I0aVe1WiejG+mXyO7REhMtGfCa6ESSByvcz0yYCny1e p3Xiumcuk3ApKGrWs= X-Received: by 2002:a05:600c:4595:b0:4a1:e00b:a10b with SMTP id 5b1f17b1804b1-4bbeb851335mr42803645e9.7.1796396968941; Fri, 04 Dec 2026 07:09:28 -0800 (PST) X-Received: by 2002:a05:600c:4595:b0:4a1:e00b:a10b with SMTP id 5b1f17b1804b1-4bbeb851335mr42803335e9.7.1796396968515; Fri, 04 Dec 2026 07:09:28 -0800 (PST) Received: from ?IPV6:2a01:e0a:f0e:9070:af16:8320:54ea:4bc9? ([2a01:e0a:f0e:9070:af16:8320:54ea:4bc9]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbea2acc6esm64685605e9.14.2026.12.04.07.09.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Dec 2026 07:09:27 -0800 (PST) Message-ID: Date: Fri, 4 Dec 2026 16:09:26 +0100 X-Archived-By: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 16/35] hw/arm/smmuv3: Scope configuration invalidation by SEC_SID To: Tao Tang , Peter Maydell , Eric Auger , =?UTF-8?Q?Philippe_Mathieu-Daud=C3=A9?= Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Pierrick Bouvier , Mostafa Saleh , Chao Liu , Chen Baozi , Jim MacArthur References: <20261114154623.3599750-1-tangtao1634@phytium.com.cn> <20261114161753.3645568-7-tangtao1634@phytium.com.cn> Content-Language: en-US From: Eric Auger In-Reply-To: <20261114161753.3645568-7-tangtao1634@phytium.com.cn> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=170.10.129.124; envelope-from=eauger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-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-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org X-Spam-Status: No, score=-17.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, 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_AGENT_SANE_1 autolearn=unavailable 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 11/14/26 5:17 PM, Tao Tang wrote: > 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_addr_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); > > 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) == info->iova); > } > > +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 value, 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 = (SMMUConfigKey *)key; > + SMMUConfigInvRangeInfo *info = (SMMUConfigInvRangeInfo *)user_data; > + SMMUDevice *sdev = config_key->sdev; > + uint32_t sid = smmu_get_sid(sdev); > + > + if (config_key->sec_sid != 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; > } > > @@ -325,6 +354,23 @@ void smmu_configs_inv_sid_range(SMMUState *s, SMMUSIDRange sid_range) > &sid_range); > } > > +void smmu_configs_inv_sid_range_by_sec_sid(SMMUState *s, > + SMMUSIDRange sid_range, > + SMMUSecSID sec_sid) > +{ > + SMMUConfigInvRangeInfo info = { > + .sid_range = sid_range, > + .sec_sid = 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 != 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 = (SMMUConfigKey *)key; > + SMMUConfigInvSdevInfo *info = (SMMUConfigInvSdevInfo *)user_data; > + > + if (config_key->sdev != info->sdev) { > + return false; > + } > + if (config_key->sec_sid != info->sec_sid) { > + return false; > + } > + trace_smmu_config_cache_inv(config_key->sec_sid, > + smmu_get_sid(info->sdev)); > return true; > } > > @@ -343,6 +407,20 @@ void smmu_configs_inv_sdev(SMMUState *s, SMMUDevice *sdev) > g_hash_table_foreach_remove(s->configs, smmu_hash_remove_by_sdev, sdev); > } > > +void smmu_configs_inv_sdev_by_sec_sid(SMMUState *s, SMMUDevice *sdev, > + SMMUSecSID sec_sid) > +{ > + SMMUConfigInvSdevInfo info = { > + .sdev = sdev, > + .sec_sid = sec_sid, > + }; > + > + g_assert(sec_sid < SMMU_SEC_SID_NUM); is that needed? Anyway this is shared by all cmdqv commands and not specific to the config cache invalidation, right? Eric> + > + 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 *sdev, SMMUEventInfo *event, > return cfg; > } > > -static void smmuv3_flush_config(SMMUDevice *sdev) > +static void smmuv3_flush_config_by_sec_sid(SMMUDevice *sdev, > + SMMUSecSID sec_sid) > { > SMMUv3State *s = sdev->smmu; > SMMUState *bc = &s->smmu_state; > > - smmu_configs_inv_sdev(bc, sdev); > + smmu_configs_inv_sdev_by_sec_sid(bc, sdev, sec_sid); > } > > /* Do translation with TLB lookup. */ > @@ -1472,12 +1473,12 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp, SMMUSecSID sec_sid) > break; > } > > - 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 = SMMU_CERROR_ILL; > break; > } > - smmuv3_flush_config(sdev); > + smmuv3_flush_config_by_sec_sid(sdev, ssec); > > break; > } > @@ -1491,12 +1492,13 @@ static int smmuv3_cmdq_consume(SMMUv3State *s, Error **errp, SMMUSecSID sec_sid) > sid_range.start = sid & ~mask; > sid_range.end = sid_range.start + mask; > > - trace_smmuv3_cmdq_cfgi_ste_range(sid_range.start, sid_range.end); > + trace_smmuv3_cmdq_cfgi_ste_range(sec_sid, ssec, > + sid_range.start, sid_range.end); > if (!smmuv3_accel_install_ste_range(s, &sid_range, errp)) { > cmd_error = 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; > } > > - 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 = 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 invalidate sec_sid=%d vmid=%d" > smmu_iotlb_inv_vmid_s1(int sec_sid, int vmid) "IOTLB invalidate S1 sec_sid=%d vmid=%d" > smmu_iotlb_inv_iova(int sec_sid, int asid, uint64_t addr) "IOTLB invalidate sec_sid=%d asid=%d addr=0x%"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=0x%x" > +smmu_configs_inv_sid_range_by_sec_sid(int sec_sid, uint32_t start, uint32_t end) "Config cache INV sec_sid=%d SID range from 0x%x to 0x%x" > +smmu_config_cache_inv(int sec_sid, uint32_t sid) "Config cache INV sec_sid=%d sid=0x%x" > smmu_inv_notifiers_mr(const char *name) "iommu mr=%s" > smmu_iotlb_lookup_hit(int sec_sid, int asid, int vmid, uint64_t addr, uint32_t hit, uint32_t miss, uint32_t p) "IOTLB cache HIT sec_sid=%d asid=%d vmid=%d addr=0x%"PRIx64" hit=%d miss=%d hit rate=%d" > smmu_iotlb_lookup_miss(int sec_sid, int asid, int vmid, uint64_t addr, uint32_t hit, uint32_t miss, uint32_t p) "IOTLB cache MISS sec_sid=%d asid=%d vmid=%d addr=0x%"PRIx64" hit=%d miss=%d hit rate=%d" > @@ -52,9 +53,9 @@ smmuv3_translate_success(const char *n, uint16_t sid, uint64_t iova, uint64_t tr > smmuv3_get_cd(uint64_t addr) "CD addr: 0x%"PRIx64 > smmuv3_decode_cd(uint32_t oas) "oas=%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= 0x%x" > -smmuv3_cmdq_cfgi_ste_range(int start, int end) "start=0x%x - end=0x%x" > -smmuv3_cmdq_cfgi_cd(uint32_t sid) "sid=0x%x" > +smmuv3_cmdq_cfgi_ste(int sec_sid, int ssec, int streamid) "cmdq_sec_sid=%d ssec=%d streamid=0x%x" > +smmuv3_cmdq_cfgi_ste_range(int sec_sid, int ssec, int start, int end) "cmdq_sec_sid=%d ssec=%d start=0x%x - end=0x%x" > +smmuv3_cmdq_cfgi_cd(int sec_sid, int ssec, uint32_t sid) "cmdq_sec_sid=%d ssec=%d sid=0x%x" > smmuv3_config_cache_hit(uint32_t sid, uint32_t hits, uint32_t misses, uint32_t perc) "Config cache HIT for sid=0x%x (hits=%d, misses=%d, hit rate=%d)" > 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"