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 <[email protected]> --- 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); + + 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" -- 2.34.1
