All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Auger <eauger@redhat.com>
To: "Tao Tang" <tangtao1634@phytium.com.cn>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Eric Auger" <eric.auger@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>
Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org,
	Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>,
	Mostafa Saleh <smostafa@google.com>,
	Chao Liu <chao.liu@processmission.com>,
	Chen Baozi <chenbaozi@phytium.com.cn>,
	Jim MacArthur <jim.macarthur@linaro.org>
Subject: Re: [PATCH v6 16/35] hw/arm/smmuv3: Scope configuration invalidation by SEC_SID
Date: Fri, 4 Dec 2026 16:09:26 +0100	[thread overview]
Message-ID: <a2bf4047-b389-4c4e-9ccc-4bf5232359ef@redhat.com> (raw)
In-Reply-To: <20261114161753.3645568-7-tangtao1634@phytium.com.cn>



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 <tangtao1634@phytium.com.cn>
> ---
>  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"



  parent reply	other threads:[~2026-12-04 15:09 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
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 [this message]
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=a2bf4047-b389-4c4e-9ccc-4bf5232359ef@redhat.com \
    --to=eauger@redhat.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=smostafa@google.com \
    --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.