hw/arm/smmu: Add invalidating function of config data
PATCH v2 1/1 hw/arm/smmu: Add invalidating function of config data
Uniform the removal judgement of g_hash_table_foreach_remove(), previous name seems to perform the actual action while it just returns a Boolean.
---
v2: - move smmuv3_invalidate_ste() to smmu_hash_remove_by_sid_range()
- add function smmu_configs_inv_sid_range()
v1: - Rename smmuv3_invalidate_ste to smmuv3_hash_remove_by_sid_range
--- hw/arm/smmu-common.c | 21 +++++++++++++++++++++ hw/arm/smmu-internal.h | 5 ----- hw/arm/smmuv3.c | 17 +---------------- hw/arm/trace-events | 1 + include/hw/arm/smmu-common.h | 6 ++++++ 5 files changed, 29 insertions(+), 21 deletions(-)
hw/arm/smmu-common.c +21 -0
@@ -225,6 +225,27 @@ static gboolean smmu_hash_remove_by_vmid_ipa(gpointer key, gpointer value, ((entry->iova & ~info->mask) == info->iova); } +static gboolean +smmu_hash_remove_by_sid_range (gpointer key,gpointer value,gpointer user_data) +{ +SMMUDevice *sdev = (SMMUDevice *)key; +uint32_t sid =smmu_get_sid (sdev); +SMMUSIDRange *sid_range = (SMMUSIDRange *)user_data; + +if (sid < sid_range->start || sid > sid_range->end) { +return false; + } +trace_smmuv3_config_cache_inv (sid); +return true; +} + +void smmu_configs_inv_sid_range (SMMUState *s,SMMUSIDRange sid_range) +{ +trace_smmu_configs_inv_sid_range (sid_range.start, sid_range.end); +g_hash_table_foreach_remove (s->configs, smmu_hash_remove_by_sid_range, + &sid_range); +} +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) {
hw/arm/smmu-internal.h +0 -5
@@ -141,9 +141,4 @@ typedef struct SMMUIOTLBPageInvInfo { uint64_t mask; } SMMUIOTLBPageInvInfo; -typedef struct SMMUSIDRange { -uint32_t start; -uint32_t end; -}SMMUSIDRange ; -#endif
hw/arm/smmuv3.c +1 -16
@@ -1277,20 +1277,6 @@ static void smmuv3_range_inval(SMMUState *s, Cmd *cmd, SMMUStage stage) } } -static gboolean -smmuv3_invalidate_ste (gpointer key,gpointer value,gpointer user_data) -{ -SMMUDevice *sdev = (SMMUDevice *)key; -uint32_t sid =smmu_get_sid (sdev); -SMMUSIDRange *sid_range = (SMMUSIDRange *)user_data; - -if (sid < sid_range->start || sid > sid_range->end) { -return false; - } -trace_smmuv3_config_cache_inv (sid); -return true; -} -static int smmuv3_cmdq_consume (SMMUv3State *s) {SMMUState *bs =ARM_SMMU (s);
@@ -1373,8 +1359,7 @@ static int smmuv3_cmdq_consume(SMMUv3State *s) sid_range.end = sid_range.start + mask;trace_smmuv3_cmdq_cfgi_ste_range (sid_range.start, sid_range.end); -g_hash_table_foreach_remove (bs->configs, smmuv3_invalidate_ste, - &sid_range); +smmu_configs_inv_sid_range (bs, sid_range);break ; }case SMMU_CMD_CFGI_CD :
hw/arm/trace-events +1 -0
@@ -15,6 +15,7 @@ smmu_iotlb_inv_asid_vmid(int asid, int vmid) "IOTLB invalidate asid=%d vmid=%d" smmu_iotlb_inv_vmid(int vmid) "IOTLB invalidate vmid=%d" smmu_iotlb_inv_vmid_s1(int vmid) "IOTLB invalidate vmid=%d" smmu_iotlb_inv_iova(int asid, uint64_t addr) "IOTLB invalidate 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_inv_notifiers_mr(const char *name) "iommu mr=%s" smmu_iotlb_lookup_hit(int asid, int vmid, uint64_t addr, uint32_t hit, uint32_t miss, uint32_t p) "IOTLB cache HIT asid=%d vmid=%d addr=0x%"PRIx64" hit=%d miss=%d hit rate=%d" smmu_iotlb_lookup_miss(int asid, int vmid, uint64_t addr, uint32_t hit, uint32_t miss, uint32_t p) "IOTLB cache MISS asid=%d vmid=%d addr=0x%"PRIx64" hit=%d miss=%d hit rate=%d"
include/hw/arm/smmu-common.h +6 -0
@@ -142,6 +142,11 @@ typedef struct SMMUIOTLBKey {uint8_t level; } SMMUIOTLBKey; +typedef struct SMMUSIDRange { +uint32_t start; +uint32_t end; +}SMMUSIDRange ; +struct SMMUState {/* <private> */ SysBusDevice dev;
@@ -219,6 +224,7 @@ 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);void smmu_iotlb_inv_ipa (SMMUState *s,int vmid,dma_addr_t ipa,uint8_t tg,uint64_t num_pages,uint8_t ttl); +void smmu_configs_inv_sid_range (SMMUState *s,SMMUSIDRange sid_range);/* Unmap the range of all the notifiers registered to any IOMMU mr */ void smmu_inv_notifiers_all (SMMUState *s);
Signature · 1 line
2.47.1
Hi,
Quoted 2 lines · JianChunfu
Uniform the removal judgement of
g_hash_table_foreach_remove(), previous name seems to perform the actual action while it just returns a Boolean.
I had difficulties to understand the commit msg.
IIUC you meant smmuv3_invalidate_ste() name is not self explanatory and you would prefer to use a similar terminology as the one being used for other hash table matching functions, ie. "remove_by" and introduce a helper that invokes the g_hash_table_foreach_remove with the renamed function. + add "No functional change intended".
Quoted 23 lines
Signed-off-by JianChunfu <[email protected]>---
v2: - movesmmuv3_invalidate_ste()tosmmu_hash_remove_by_sid_range()
- add functionsmmu_configs_inv_sid_range()
v1: - Renamesmmuv3_invalidate_stetosmmuv3_hash_remove_by_sid_range--- hw/arm/smmu-common.c | 21 +++++++++++++++++++++ hw/arm/smmu-internal.h | 5 ----- hw/arm/smmuv3.c | 17 +---------------- hw/arm/trace-events | 1 + include/hw/arm/smmu-common.h | 6 ++++++ 5 files changed, 29 insertions(+), 21 deletions(-)hw/arm/smmu-common.c +1
-0@@ -225,6 +225,27 @@ static gboolean smmu_hash_remove_by_vmid_ipa(gpointer key, gpointer value, ((entry->iova & ~info->mask) == info->iova); } +static gboolean
hw/arm/smmu-common.c static gboolean smmu_hash_remove_by_vmid_ipa(gpointer key, gpointer value, · line 238
Quoted 10 lines
hw/arm/smmu-common.c +10
-0+smmu_hash_remove_by_sid_range(gpointer key, gpointer value, gpointer user_data) +{ + SMMUDevice *sdev = (SMMUDevice *)key; +uint32_t sid =smmu_get_sid (sdev); +SMMUSIDRange *sid_range = (SMMUSIDRange *)user_data; + +if (sid < sid_range->start || sid > sid_range->end) { +return false; + } +trace_smmuv3_config_cache_inv (sid);
now the code has been moved to smmu-common, would be better to rename the trace into
trace_smmu_config_cache_inv and move it into the
# smmu-common.c section in trace-events.
Quoted 91 lines
hw/arm/smmu-common.c +10
-0+return true; +} + +void smmu_configs_inv_sid_range (SMMUState *s,SMMUSIDRange sid_range) +{ +trace_smmu_configs_inv_sid_range (sid_range.start, sid_range.end); +g_hash_table_foreach_remove (s->configs, smmu_hash_remove_by_sid_range, + &sid_range); +} +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) {hw/arm/smmu-internal.h +0
-5@@ -141,9 +141,4 @@ typedef struct SMMUIOTLBPageInvInfo { uint64_t mask; } SMMUIOTLBPageInvInfo; -typedef struct SMMUSIDRange { -uint32_t start; -uint32_t end; -}SMMUSIDRange ; -#endif hw/arm/smmuv3.c +1
-16@@ -1277,20 +1277,6 @@ static void smmuv3_range_inval(SMMUState *s, Cmd *cmd, SMMUStage stage) } } -static gboolean -smmuv3_invalidate_ste (gpointer key,gpointer value,gpointer user_data) -{ -SMMUDevice *sdev = (SMMUDevice *)key; -uint32_t sid =smmu_get_sid (sdev); -SMMUSIDRange *sid_range = (SMMUSIDRange *)user_data; - -if (sid < sid_range->start || sid > sid_range->end) { -return false; - } -trace_smmuv3_config_cache_inv (sid); -return true; -} -static int smmuv3_cmdq_consume (SMMUv3State *s) {SMMUState *bs =ARM_SMMU (s);@@ -1373,8 +1359,7 @@ static int smmuv3_cmdq_consume(SMMUv3State *s) sid_range.end = sid_range.start + mask;trace_smmuv3_cmdq_cfgi_ste_range (sid_range.start, sid_range.end); -g_hash_table_foreach_remove (bs->configs, smmuv3_invalidate_ste, - &sid_range); +smmu_configs_inv_sid_range (bs, sid_range);break ; }case SMMU_CMD_CFGI_CD :hw/arm/trace-events +1
-0@@ -15,6 +15,7 @@ smmu_iotlb_inv_asid_vmid(int asid, int vmid) "IOTLB invalidate asid=%d vmid=%d" smmu_iotlb_inv_vmid(int vmid) "IOTLB invalidate vmid=%d" smmu_iotlb_inv_vmid_s1(int vmid) "IOTLB invalidate vmid=%d" smmu_iotlb_inv_iova(int asid, uint64_t addr) "IOTLB invalidate 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_inv_notifiers_mr(const char *name) "iommu mr=%s" smmu_iotlb_lookup_hit(int asid, int vmid, uint64_t addr, uint32_t hit, uint32_t miss, uint32_t p) "IOTLB cache HIT asid=%d vmid=%d addr=0x%"PRIx64" hit=%d miss=%d hit rate=%d" smmu_iotlb_lookup_miss(int asid, int vmid, uint64_t addr, uint32_t hit, uint32_t miss, uint32_t p) "IOTLB cache MISS asid=%d vmid=%d addr=0x%"PRIx64" hit=%d miss=%d hit rate=%d"include/hw/arm/smmu-common.h +5
-0@@ -142,6 +142,11 @@ typedef struct SMMUIOTLBKey {uint8_t level; } SMMUIOTLBKey; +typedef struct SMMUSIDRange { +uint32_t start; +uint32_t end; +}SMMUSIDRange ; +struct SMMUState {/* <private> */ SysBusDevice dev;
include/hw/arm/smmu-common.h void smmu_iotlb_inv_iova(SMMUState *s, int asid, int vmid, dma_addr_t iova, · line 230
Quoted 7 lines
include/hw/arm/smmu-common.h +1
-0@@ -219,6 +224,7 @@ 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);void smmu_iotlb_inv_ipa (SMMUState *s,int vmid,dma_addr_t ipa,uint8_t tg,uint64_t num_pages,uint8_t ttl); +void smmu_configs_inv_sid_range (SMMUState *s,SMMUSIDRange sid_range);/* Unmap the range of all the notifiers registered to any IOMMU mr */ void smmu_inv_notifiers_all (SMMUState *s);
Otherwise it looks good.
Thanks
Eric