hw: Avoid using inlined functions with external linkage
RFC 1/1 hw: Avoid using inlined functions with external linkage
When using Clang ("Apple clang version 14.0.0 (clang-1400.0.29.202)") and building with -Wall we get:
hw/arm/smmu-common.c:173:33: warning: static function 'smmu_hash_remove_by_asid_iova' is used in an inline function with external linkage [-Wstatic-in-inline] hw/arm/smmu-common.h:170:1: note: use 'static' to give inline function 'smmu_iotlb_inv_iova' internal linkage
void smmu_iotlb_inv_iova(SMMUState *s, int asid, dma_addr_t iova,
^
static
None of our code base require / use inlined functions with external linkage. Some places use internal inlining in the hot path. These two functions are certainly not in any hot path and don't justify any inlining.
---
RFC: Any better justification?
--- hw/arm/smmu-common.c | 10 +++++----- hw/i386/x86.c | 3 +-- 2 files changed, 6 insertions(+), 7 deletions(-)
hw/arm/smmu-common.c +5 -5
@@ -116,7 +116,7 @@ void smmu_iotlb_insert(SMMUState *bs, SMMUTransCfg *cfg, SMMUTLBEntry *new)g_hash_table_insert (bs->iotlb, key, new); } -inline void smmu_iotlb_inv_all (SMMUState *s) +void smmu_iotlb_inv_all (SMMUState *s) {trace_smmu_iotlb_inv_all ();g_hash_table_remove_all (s->iotlb);
@@ -146,7 +146,7 @@ static gboolean smmu_hash_remove_by_asid_iova(gpointer key, gpointer value, ((entry->iova & ~info->mask) == info->iova); } -inline void +void smmu_iotlb_inv_iova (SMMUState *s,int asid,dma_addr_t iova,uint8_t tg,uint64_t num_pages,uint8_t ttl) {
@@ -174,7 +174,7 @@ smmu_iotlb_inv_iova(SMMUState *s, int asid, dma_addr_t iova, &info); } -inline void smmu_iotlb_inv_asid (SMMUState *s,uint16_t asid) +void smmu_iotlb_inv_asid (SMMUState *s,uint16_t asid) {trace_smmu_iotlb_inv_asid (asid);g_hash_table_foreach_remove (s->iotlb, smmu_hash_remove_by_asid, &asid);
@@ -374,7 +374,7 @@ error:* * return 0 on success */ -inline int smmu_ptw (SMMUTransCfg *cfg,dma_addr_t iova,IOMMUAccessFlags perm, +int smmu_ptw (SMMUTransCfg *cfg,dma_addr_t iova,IOMMUAccessFlags perm,SMMUTLBEntry *tlbe,SMMUPTWEventInfo *info) {if (!cfg->aa64) {
@@ -483,7 +483,7 @@ static void smmu_unmap_notifier_range(IOMMUNotifier *n) }/* Unmap all notifiers attached to @mr */ -inline void smmu_inv_notifiers_mr (IOMMUMemoryRegion *mr) +void smmu_inv_notifiers_mr (IOMMUMemoryRegion *mr) {IOMMUNotifier *n;
hw/i386/x86.c +1 -2
@@ -64,8 +64,7 @@/* Physical Address of PVH entry point read from kernel ELF NOTE */ static size_t pvh_start_addr; -inline void init_topo_info (X86CPUTopoInfo *topo_info, -const X86MachineState *x86ms) +void init_topo_info (X86CPUTopoInfo *topo_info,const X86MachineState *x86ms) {MachineState *ms =MACHINE (x86ms);
Signature · 1 line
2.38.1
Quoted 15 lines · Philippe Mathieu-Daudé
When using Clang ("Apple clang version 14.0.0 (clang-1400.0.29.202)") and building with -Wall we get:
hw/arm/smmu-common.c:173:33: warning: static function 'smmu_hash_remove_by_asid_iova' is used in an inline function with external linkage [-Wstatic-in-inline]hw/arm/smmu-common.h:170:1: note: use 'static' to give inline function 'smmu_iotlb_inv_iova' internal linkage
void smmu_iotlb_inv_iova(SMMUState *s, int asid,dma_addr_tiova,
^
staticNone of our code base require / use inlined functions with external linkage. Some places use internal inlining in the hot path. These two functions are certainly not in any hot path and don't justify any inlining.
Quoted 4 lines
Reported-by Stefan Weil <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
RFC: Any better justification?
I don't really understand what the warning is trying to warn about, and googling didn't enlighten me. Does anybody understand it?
In any case, it does seem weird to define a function inline and also have it be defined in a C file rather than as a 'static inline' in a header file, so these are likely oversights rather than intentional.
Quoted 19 lines
--- hw/arm/smmu-common.c | 10 +++++----- hw/i386/x86.c | 3 +-- 2 files changed, 6 insertions(+), 7 deletions(-)hw/arm/smmu-common.c +1
-1@@ -116,7 +116,7 @@ void smmu_iotlb_insert(SMMUState *bs, SMMUTransCfg *cfg, SMMUTLBEntry *new)g_hash_table_insert (bs->iotlb, key, new); } -inline void smmu_iotlb_inv_all (SMMUState *s) +void smmu_iotlb_inv_all (SMMUState *s) {trace_smmu_iotlb_inv_all ();g_hash_table_remove_all (s->iotlb);
hw/arm/smmu-common.c static gboolean smmu_hash_remove_by_asid_iova(gpointer key, gpointer value, · line 151
Quoted 7 lines
hw/arm/smmu-common.c +1
-1@@ -146,7 +146,7 @@ static gboolean smmu_hash_remove_by_asid_iova(gpointer key, gpointer value, ((entry->iova & ~info->mask) == info->iova); } -inline void +void smmu_iotlb_inv_iova (SMMUState *s,int asid,dma_addr_t iova,uint8_t tg,uint64_t num_pages,uint8_t ttl)
While we're changing this, can we put the "void" on the same line as the rest of the function prototype, to match the style of these other functions ?
Quoted 11 lines
hw/arm/smmu-common.c +1
-1{@@ -174,7 +174,7 @@ smmu_iotlb_inv_iova(SMMUState *s, int asid, dma_addr_t iova, &info); } -inline void smmu_iotlb_inv_asid (SMMUState *s,uint16_t asid) +void smmu_iotlb_inv_asid (SMMUState *s,uint16_t asid) {trace_smmu_iotlb_inv_asid (asid);g_hash_table_foreach_remove (s->iotlb, smmu_hash_remove_by_asid, &asid);
hw/arm/smmu-common.c error: · line 378
Quoted 6 lines
hw/arm/smmu-common.c +1
-1@@ -374,7 +374,7 @@ error:* * return 0 on success */ -inline int smmu_ptw (SMMUTransCfg *cfg,dma_addr_t iova,IOMMUAccessFlags perm, +int smmu_ptw (SMMUTransCfg *cfg,dma_addr_t iova,IOMMUAccessFlags perm,SMMUTLBEntry *tlbe,SMMUPTWEventInfo *info)
This second line now needs re-indenting.
Quoted 16 lines
hw/arm/smmu-common.c +1
-1{if (!cfg->aa64) {@@ -483,7 +483,7 @@ static void smmu_unmap_notifier_range(IOMMUNotifier *n) }/* Unmap all notifiers attached to @mr */ -inline void smmu_inv_notifiers_mr (IOMMUMemoryRegion *mr) +void smmu_inv_notifiers_mr (IOMMUMemoryRegion *mr) {IOMMUNotifier *n;hw/i386/x86.c +0
-0
hw/i386/x86.c line 69
Quoted 8 lines
hw/i386/x86.c +1
-2@@ -64,8 +64,7 @@/* Physical Address of PVH entry point read from kernel ELF NOTE */ static size_t pvh_start_addr; -inline void init_topo_info (X86CPUTopoInfo *topo_info, -const X86MachineState *x86ms) +void init_topo_info (X86CPUTopoInfo *topo_info,const X86MachineState *x86ms) {MachineState *ms =MACHINE (x86ms);
This function is not used anywhere outside this file, so we can delete the prototype from include/hw/i386/x86.h and make the function "static void".
With those changes,
thanks
-- PMM
Quoted 42 lines · Peter Maydell
Quoted 15 lines · Philippe Mathieu-Daudé
When using Clang ("Apple clang version 14.0.0 (clang-1400.0.29.202)") and building with -Wall we get:
hw/arm/smmu-common.c:173:33: warning: static function 'smmu_hash_remove_by_asid_iova' is used in an inline function with external linkage [-Wstatic-in-inline]hw/arm/smmu-common.h:170:1: note: use 'static' to give inline function 'smmu_iotlb_inv_iova' internal linkage
void smmu_iotlb_inv_iova(SMMUState *s, int asid,dma_addr_tiova,
^
staticNone of our code base require / use inlined functions with external linkage. Some places use internal inlining in the hot path. These two functions are certainly not in any hot path and don't justify any inlining.
Quoted 4 lines
Reported-by Stefan Weil <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
RFC: Any better justification?I don't really understand what the warning is trying to warn about, and googling didn't enlighten me. Does anybody understand it?
In any case, it does seem weird to define a function inline and also have it be defined in a C file rather than as a 'static inline' in a header file, so these are likely oversights rather than intentional.
Quoted 13 lines
--- hw/arm/smmu-common.c | 10 +++++----- hw/i386/x86.c | 3 +-- 2 files changed, 6 insertions(+), 7 deletions(-)hw/i386/x86.c +0
-0@@ -64,8 +64,7 @@/* Physical Address of PVH entry point read from kernel ELF NOTE */ static size_t pvh_start_addr;
Quoted 9 lines
hw/i386/x86.c line 69
Quoted 5 lines
hw/i386/x86.c +1
-2-inline void init_topo_info (X86CPUTopoInfo *topo_info, -const X86MachineState *x86ms) +void init_topo_info (X86CPUTopoInfo *topo_info,const X86MachineState *x86ms) {MachineState *ms =MACHINE (x86ms);This function is not used anywhere outside this file, so we can delete the prototype from
include/hw/i386/x86.hand make the function "static void".
Good idea.
Quoted 2 lines
With those changes,
Reviewed-by Peter Maydell <[email protected]>
Thanks!