Skip to contentSkip to conversation

overall: Avoid using inlined functions with external linkage again

PATCH Superseded Philippe Mathieu-Daudé 3 participants 11 messages Mar 13, 2024 Arm/Amlogic Meson SoC support

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover overall: Avoid using inlined functions with external linkage again

Mostly as a C style cleanup, use -Wstatic-in-inline to avoid using inlined function with external linkage.

Philippe Mathieu-Daudé (4):
hw/arm/smmu: Avoid using inlined functions with external linkage again accel/hvf: Un-inline hvf_arch_supports_guest_debug() qtest/libqos: Un-inline size_to_prdtl()
meson: Enable -Wstatic-in-inline

 meson.build               | 1 +
 hw/arm/smmu-common.c      | 2 +-
 target/arm/hvf/hvf.c      | 2 +-
 target/i386/hvf/hvf.c     | 2 +-
 tests/qtest/libqos/ahci.c | 2 +-
 5 files changed, 5 insertions(+), 4 deletions(-)
Signature · 1 line
2.41.0
#1 lore raw

PATCH 1/4 hw/arm/smmu: Avoid using inlined functions with external linkage again

Similarly to commit 9de9fa5cf2 ("hw/arm/smmu-common: Avoid using inlined functions with external linkage"):

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, so these are likely oversights rather than intentional.

Fix:

C compiler for the host machine: clang (clang 15.0.0 "Apple clang version 15.0.0 (clang-1500.3.9.4)")
...
hw/arm/smmu-common.c:203:43: error: static function 'smmu_hash_remove_by_vmid' is used in an inline function with external linkage [-Werror,-Wstatic-in-inline]

      g_hash_table_foreach_remove(s->iotlb, smmu_hash_remove_by_vmid, &vmid);
                                            ^
  include/hw/arm/smmu-common.h:197:1: note: use 'static' to give inline function 'smmu_iotlb_inv_vmid' internal linkage
  void smmu_iotlb_inv_vmid(SMMUState *s, uint16_t vmid);
  ^
  static
  hw/arm/smmu-common.c:139:17: note: 'smmu_hash_remove_by_vmid' declared here
  static gboolean smmu_hash_remove_by_vmid(gpointer key, gpointer value,
                ^
Fixes ccc3ee3871 ("hw/arm/smmuv3: Add CMDs related to stage-2")
---
 hw/arm/smmu-common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/arm/smmu-common.c +1 -1
index 4caedb4998..c4b540656c 100644
@@ -197,7 +197,7 @@ void smmu_iotlb_inv_asid(SMMUState *s, uint16_t asid)
     g_hash_table_foreach_remove(s->iotlb, smmu_hash_remove_by_asid, &asid);
 }
 
-inline void smmu_iotlb_inv_vmid(SMMUState *s, uint16_t vmid)
+void smmu_iotlb_inv_vmid(SMMUState *s, uint16_t vmid)
 {
     trace_smmu_iotlb_inv_vmid(vmid);
     g_hash_table_foreach_remove(s->iotlb, smmu_hash_remove_by_vmid, &vmid);
Signature · 1 line
2.41.0
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH-for-9.0 1/4] hw/arm/smmu: Avoid using inlined functions with external linkage again

Quoted 24 lines · Philippe Mathieu-Daudé

Similarly to commit 9de9fa5cf2 ("hw/arm/smmu-common: Avoid using inlined functions with external linkage"):

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, so these are likely oversights rather than intentional.

Fix:

   C compiler for the host machine: clang (clang 15.0.0 "Apple clang version 15.0.0 (clang-1500.3.9.4)")
   ...
   hw/arm/smmu-common.c:203:43: error: static function 'smmu_hash_remove_by_vmid' is
   used in an inline function with external linkage [-Werror,-Wstatic-in-inline]
       g_hash_table_foreach_remove(s->iotlb, smmu_hash_remove_by_vmid, &vmid);
                                             ^
   include/hw/arm/smmu-common.h:197:1: note: use 'static' to give inline function 'smmu_iotlb_inv_vmid' internal linkage
   void smmu_iotlb_inv_vmid(SMMUState *s, uint16_t vmid);
   ^
   static
   hw/arm/smmu-common.c:139:17: note: 'smmu_hash_remove_by_vmid' declared here
   static gboolean smmu_hash_remove_by_vmid(gpointer key, gpointer value,
                 ^
Quoted 5 lines
Fixes ccc3ee3871 ("hw/arm/smmuv3: Add CMDs related to stage-2")
---
  hw/arm/smmu-common.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

r~

#3 lore raw

PATCH 2/4 accel/hvf: Un-inline hvf_arch_supports_guest_debug()

In reply to Philippe Mathieu-Daudé

See previous commit and commit 9de9fa5cf2 ("Avoid using inlined functions with external linkage") for rationale.

---
 target/arm/hvf/hvf.c  | 2 +-
 target/i386/hvf/hvf.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
target/arm/hvf/hvf.c +1 -1
index e5f0f60093..65a5601804 100644
@@ -2246,7 +2246,7 @@ void hvf_arch_update_guest_debug(CPUState *cpu)
     hvf_arch_set_traps();
 }
 
-inline bool hvf_arch_supports_guest_debug(void)
+bool hvf_arch_supports_guest_debug(void)
 {
     return true;
 }
target/i386/hvf/hvf.c +1 -1
index 11ffdd4c69..1ed8ed5154 100644
@@ -708,7 +708,7 @@ void hvf_arch_update_guest_debug(CPUState *cpu)
 {
 }
 
-inline bool hvf_arch_supports_guest_debug(void)
+bool hvf_arch_supports_guest_debug(void)
 {
     return false;
 }
Signature · 1 line
2.41.0
Reviewed-by on v1 2/4
#5 lore raw

Re: [PATCH-for-9.0 2/4] accel/hvf: Un-inline hvf_arch_supports_guest_debug()

In reply to Philippe Mathieu-Daudé
Quoted 8 lines · Philippe Mathieu-Daudé

See previous commit and commit 9de9fa5cf2 ("Avoid using inlined functions with external linkage") for rationale.

---
  target/arm/hvf/hvf.c  | 2 +-
  target/i386/hvf/hvf.c | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)

r~

#6 lore raw

PATCH 3/4 qtest/libqos: Un-inline size_to_prdtl()

In reply to Philippe Mathieu-Daudé

See previous commit and commit 9de9fa5cf2 ("Avoid using inlined functions with external linkage") for rationale.

---
 tests/qtest/libqos/ahci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qtest/libqos/ahci.c +1 -1
index a2c94c6e06..135b23ffd9 100644
@@ -662,7 +662,7 @@ unsigned ahci_pick_cmd(AHCIQState *ahci, uint8_t port)
     g_assert_not_reached();
 }
 
-inline unsigned size_to_prdtl(unsigned bytes, unsigned bytes_per_prd)
+unsigned size_to_prdtl(unsigned bytes, unsigned bytes_per_prd)
 {
     /* Each PRD can describe up to 4MiB */
     g_assert_cmphex(bytes_per_prd, <=, 4096 * 1024);
Signature · 1 line
2.41.0
#7 lore raw

Re: [PATCH-for-9.0 3/4] qtest/libqos: Un-inline size_to_prdtl()

Quoted 14 lines · Philippe Mathieu-Daudé

See previous commit and commit 9de9fa5cf2 ("Avoid using inlined functions with external linkage") for rationale.

---
 tests/qtest/libqos/ahci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qtest/libqos/ahci.c +0 -0
index a2c94c6e06..135b23ffd9 100644

tests/qtest/libqos/ahci.c unsigned ahci_pick_cmd(AHCIQState *ahci, uint8_t port) · line 668

Quoted 8 lines
tests/qtest/libqos/ahci.c +1 -1
@@ -662,7 +662,7 @@ unsigned ahci_pick_cmd(AHCIQState *ahci, uint8_t port)
     g_assert_not_reached();
 }
 
-inline unsigned size_to_prdtl(unsigned bytes, unsigned bytes_per_prd)
+unsigned size_to_prdtl(unsigned bytes, unsigned bytes_per_prd)
 {
     /* Each PRD can describe up to 4MiB */
     g_assert_cmphex(bytes_per_prd, <=, 4096 * 1024);

It looks like this function is only used in this file, so we could make it static ?

-- PMM

#8 lore raw

Re: [PATCH-for-9.0 3/4] qtest/libqos: Un-inline size_to_prdtl()

Quoted 18 lines · Peter Maydell
Quoted 17 lines · Philippe Mathieu-Daudé

See previous commit and commit 9de9fa5cf2 ("Avoid using inlined functions with external linkage") for rationale.

---
  tests/qtest/libqos/ahci.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tests/qtest/libqos/ahci.c +0 -0
index a2c94c6e06..135b23ffd9 100644
@@ -662,7 +662,7 @@ unsigned ahci_pick_cmd(AHCIQState *ahci, uint8_t port)
      g_assert_not_reached();
  }
 
Quoted 8 lines

tests/qtest/libqos/ahci.c unsigned ahci_pick_cmd(AHCIQState *ahci, uint8_t port) · line 668

Quoted 5 lines
tests/qtest/libqos/ahci.c +1 -1
-inline unsigned size_to_prdtl(unsigned bytes, unsigned bytes_per_prd)
+unsigned size_to_prdtl(unsigned bytes, unsigned bytes_per_prd)
  {
      /* Each PRD can describe up to 4MiB */
      g_assert_cmphex(bytes_per_prd, <=, 4096 * 1024);

It looks like this function is only used in this file, so we could make it static ?

Eh I did check for that, but sure how I missed it...

#9 lore raw

PATCH 4/4 meson: Enable -Wstatic-in-inline

In reply to Philippe Mathieu-Daudé

Compilers are clever enough to inline code when necessary.

The only case we accept an inline function is static in header (we use C, not C++).

Add the -Wstatic-in-inline CPPFLAG to prevent public and inline function to be added in the code base.

---
 meson.build | 1 +
 1 file changed, 1 insertion(+)
meson.build +1 -0
index b375248a76..f57397aa53 100644
@@ -591,6 +591,7 @@ warn_flags = [
   '-Wold-style-definition',
   '-Wredundant-decls',
   '-Wshadow=local',
+  '-Wstatic-in-inline',
   '-Wstrict-prototypes',
   '-Wtype-limits',
   '-Wundef',
Signature · 1 line
2.41.0
Reviewed-by on v1 4/4
#10 lore raw

Re: [PATCH-for-9.0 4/4] meson: Enable -Wstatic-in-inline

Quoted 5 lines · Philippe Mathieu-Daudé

Compilers are clever enough to inline code when necessary.

The only case we accept an inline function is static in header (we use C, not C++).

Quoted 7 lines

Add the -Wstatic-in-inline CPPFLAG to prevent public and inline function to be added in the code base.

---
  meson.build | 1 +
  1 file changed, 1 insertion(+)

r~