Skip to contentSkip to conversation

xen/arm: mark handle_linux_pci_domain() __init

PATCH Superseded Stewart Hildebrand 4 participants 12 messages Oct 14, 2022 – Oct 21, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/arm: mark handle_linux_pci_domain() __init

---
 xen/arch/arm/domain_build.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/arm/domain_build.c +2 -2
index b975d0b309..9fa283d694 100644
@@ -1051,8 +1051,8 @@ static void __init assign_static_memory_11(struct domain *d,
  * The current heuristic assumes that a device is a host bridge
  * if the type is "pci" and then parent type is not "pci".
  */
-static int handle_linux_pci_domain(struct kernel_info *kinfo,
-                                   const struct dt_device_node *node)
+static int __init handle_linux_pci_domain(struct kernel_info *kinfo,
+                                          const struct dt_device_node *node)
 {
     uint16_t segment;
     int res;
Signature · 1 line
2.38.0
#2 lore raw

Hi,

Quoted 4 lines · Jan Beulich
Quoted 1 line · Stewart Hildebrand

I guess a non-empty description and a Fixes: tag would be nice.

+1. I am actually quite interested to understand how this was spotted.

The build system should check that any function/data in domain_build.c are part of the __init section. So I guess the compiler you are using doesn't inline the function?

If so, I am actually surprised you are the first one spotted this... We are building on various distribution without any issues (?). I would be interested to know the compiler version and maybe we could add it in the CI.

Cheers,

Signature · 1 line
Julien Grall
#3 lore raw
Quoted 7 lines · Julien Grall

Hi,

Quoted 4 lines · Jan Beulich
Quoted 1 line · Stewart Hildebrand

I guess a non-empty description and a Fixes: tag would be nice.

Okay, I will send a v2 with the following description:
All functions in domain_build.c should be marked __init. This was spotted when building the hypervisor with -Og.

Fixes 1050a7b91c xen/arm: add pci-domain for disabled devices
Quoted 10 lines

+1. I am actually quite interested to understand how this was spotted.

The build system should check that any function/data in domain_build.c are part of the __init section. So I guess the compiler you are using doesn't inline the function?

If so, I am actually surprised you are the first one spotted this... We are building on various distribution without any issues (?). I would be interested to know the compiler version and maybe we could add it in the CI.

I added -Og to the make command line so it takes precedence over the default -O1/-O2:

$ make EXTRA_CFLAGS_XEN_CORE="-Og" XEN_TARGET_ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- dist-xen -j $(nproc)

Indeed, I did observe the build error:
Error: size of arch/arm/domain_build.o:.text is 0x00000008

I used this rune to reveal the culprit:

$ aarch64-none-linux-gnu-objdump -d xen/arch/arm/domain_build.o | head

xen/arch/arm/domain_build.o:     file format elf64-littleaarch64

Disassembly of section .text:

0000000000000000 <handle_linux_pci_domain>:
    0:   52800000        mov     w0, #0x0                        // #0 4:   d65f03c0        ret

I am using this toolchain: https://developer.arm.com/-/media/Files/downloads/gnu/11.3.rel1/binrel/arm-gnu-toolchain-11.3.rel1-x86_64-aarch64-none-linux-gnu.tar.xz

Further, there were two more build errors observed when building with -Og:
arch/arm/domain_build.c: In function ‘make_cpus_node’:
arch/arm/domain_build.c:2013:12: error: ‘clock_valid’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 2013 |         if ( clock_valid )
      |            ^

arch/arm/efi/boot.c: In function ‘efi_start’:
arch/arm/efi/boot.c:1464:9: error: ‘argc’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 1464 |         efi_arch_handle_cmdline(argc ? *argv : NULL, options, name.s);
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I assume these uninitialized use errors can simply be fixed by initializing the respective variables to false/0, but a second opinion would certainly be helpful.

#4 lore raw

Hi Stewart,

Quoted 40 lines · Stewart Hildebrand
Quoted 7 lines · Julien Grall

Hi,

Quoted 4 lines · Jan Beulich
Quoted 1 line · Stewart Hildebrand

I guess a non-empty description and a Fixes: tag would be nice.

Okay, I will send a v2 with the following description:
All functions in domain_build.c should be marked __init. This was spotted when building the hypervisor with -Og.

Fixes 1050a7b91c xen/arm: add pci-domain for disabled devices
Quoted 10 lines

+1. I am actually quite interested to understand how this was spotted.

The build system should check that any function/data in domain_build.c are part of the __init section. So I guess the compiler you are using doesn't inline the function?

If so, I am actually surprised you are the first one spotted this... We are building on various distribution without any issues (?). I would be interested to know the compiler version and maybe we could add it in the CI.

I added -Og to the make command line so it takes precedence over the default -O1/-O2:

$ make EXTRA_CFLAGS_XEN_CORE="-Og" XEN_TARGET_ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- dist-xen -j $(nproc)

Indeed, I did observe the build error:
Error: size of arch/arm/domain_build.o:.text is 0x00000008

I used this rune to reveal the culprit:

$ aarch64-none-linux-gnu-objdump -d xen/arch/arm/domain_build.o | head

xen/arch/arm/domain_build.o:     file format elf64-littleaarch64

Quoted 7 lines

Disassembly of section .text:

0000000000000000 <handle_linux_pci_domain>:
    0:   52800000        mov     w0, #0x0                        // #0 4:   d65f03c0        ret

I am using this toolchain: https://developer.arm.com/-/media/Files/downloads/gnu/11.3.rel1/binrel/arm-gnu-toolchain-11.3.rel1-x86_64-aarch64-none-linux-gnu.tar.xz

Thanks for the details. I guess the '-Og' is the culprint.

Quoted 6 lines

Further, there were two more build errors observed when building with -Og:
arch/arm/domain_build.c: In function ‘make_cpus_node’:
arch/arm/domain_build.c:2013:12: error: ‘clock_valid’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
 2013 |         if ( clock_valid )
      |            ^

I think this is a false positive because 'clock_valid' is set at the same time as 'compatible'. The latter is check that is not NULL just after it is set.

In general, I tend to prefer if variable are not initialized (unless strictly necessary) because we can take advantage of the compiler to spot any issue.

In this case, it should not be a big problem because the default value (false) would be sensible here.

Quoted 6 lines

arch/arm/efi/boot.c: In function ‘efi_start’:
arch/arm/efi/boot.c:1464:9: error: ‘argc’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
 1464 |         efi_arch_handle_cmdline(argc ? *argv : NULL, options,
name.s);
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I am a bit puzzled why it warn on this line but not few lines above where it is already used.

This function is a bit difficult to read. AFAIU, the code look like:

if ( use_cfg_file )
{
argc = ...
}

/* do something common */

if ( use_cfg_file )
efi_arch_handle_cmd(argc, ...);

The GCC with -Og is probably not capable to detect that argc will always be used when 'use_cfg_file'.

The "do something common" is two lines. So I am tempted to suggest to just duplicate those two lines. This could also allow us to move all the code in the ifs (nearly 100 lines over the two ifs!) in a separate function.

But I think Jan (the maintainer of the code) may not be happy with that). So short of a second better suggestion, initializing 'argc' to 0 (?) and a comment explaining this is to silence the compiler may be the way to go.

Cheers,

Signature · 1 line
Julien Grall
#5 lore raw
Quoted 10 lines · Julien Grall
Quoted 6 lines · Stewart Hildebrand

arch/arm/efi/boot.c: In function ‘efi_start’:
arch/arm/efi/boot.c:1464:9: error: ‘argc’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
 1464 |         efi_arch_handle_cmdline(argc ? *argv : NULL, options,
name.s);
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I am a bit puzzled why it warn on this line but not few lines above where it is already used.

Same here. Plus it ought to warn for argv then too, I think.

Quoted 15 lines

This function is a bit difficult to read. AFAIU, the code look like:

if ( use_cfg_file )

{
    argc = ...
}

/* do something common */

if ( use_cfg_file )
efi_arch_handle_cmd(argc, ...);

The GCC with -Og is probably not capable to detect that argc will always be used when 'use_cfg_file'.

Quoted 6 lines

The "do something common" is two lines. So I am tempted to suggest to just duplicate those two lines. This could also allow us to move all the code in the ifs (nearly 100 lines over the two ifs!) in a separate function.

But I think Jan (the maintainer of the code) may not be happy with that).

Indeed. Even if it's only two statements now, my view is that we ought to avoid such code duplication.

Further I wonder whether the call to efi_check_dt_boot() shouldn't actually live in an "else" to the 2nd if(). It would be at least questionable if parts of the modules were described by the .cfg file and other parts by DT (which in turn makes assumptions about the relative placement of those modules wrt xen.efi on the EFI partition, when I'd expect it to be self-contained).

Quoted 3 lines

So short of a second better suggestion, initializing 'argc' to 0 (?) and a comment explaining this is to silence the compiler may be the way to go.

I'd prefer if we avoided that, not the least because this could then trip (good) static checkers to report written-but-never-used instances. What I might accept (albeit that doesn't address said concern) is an "else" to the first if() setting argc and argv (accompanied by a suitable comment, down the road perhaps including a SAF-<nnn>-false-positive marker).

Jan

#6 lore raw

PATCH v2 1/1 xen/arm: mark handle_linux_pci_domain() __init

In reply to Stewart Hildebrand

All functions in domain_build.c should be marked __init. This was spotted when building the hypervisor with -Og.

Fixes 1050a7b91c xen/arm: add pci-domain for disabled devices

---
v1 -> v2:
Add Fixes: tag
Add patch description

---
 xen/arch/arm/domain_build.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/arm/domain_build.c +2 -2
index 61cda8e843..fc2961895b 100644
@@ -1051,8 +1051,8 @@ static void __init assign_static_memory_11(struct domain *d,
  * The current heuristic assumes that a device is a host bridge
  * if the type is "pci" and then parent type is not "pci".
  */
-static int handle_linux_pci_domain(struct kernel_info *kinfo,
-                                   const struct dt_device_node *node)
+static int __init handle_linux_pci_domain(struct kernel_info *kinfo,
+                                          const struct dt_device_node *node)
 {
     uint16_t segment;
     int res;
Signature · 1 line
2.38.0
Acked-by on v2 1/1
#7 lore raw

Hi Stewart,

I nearly missed this one because it was threaded under v1. In the future, would you be able to send new version in a separate thread? This makes easier to track it.

Quoted 5 lines · Stewart Hildebrand

All functions in domain_build.c should be marked __init. This was spotted when building the hypervisor with -Og.

Fixes 1050a7b91c xen/arm: add pci-domain for disabled devices

Henry, this patch is fixing a potential build failure on some compiler (at the moment we are relying on the compiler to inline handle_linux_pci_domain). AFAIU, the problem was introduced in Xen 4.17. Would you be happy if we include it in the release?

Cheers,

Quoted 24 lines

---
v1 -> v2:
Add Fixes: tag
Add patch description

---
  xen/arch/arm/domain_build.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/arm/domain_build.c +2 -2
index 61cda8e843..fc2961895b 100644
@@ -1051,8 +1051,8 @@ static void __init assign_static_memory_11(struct domain *d,
   * The current heuristic assumes that a device is a host bridge
   * if the type is "pci" and then parent type is not "pci".
   */
-static int handle_linux_pci_domain(struct kernel_info *kinfo,
-                                   const struct dt_device_node *node)
+static int __init handle_linux_pci_domain(struct kernel_info *kinfo,
+                                          const struct dt_device_node *node)
  {
      uint16_t segment;
      int res;
Signature · 1 line
Julien Grall
#8 lore raw
Quoted 1 line · Julien Grall

Hi Stewart,

Hi Julien,

Quoted 3 lines

I nearly missed this one because it was threaded under v1. In the future, would you be able to send new version in a separate thread? This makes easier to track it.

I will keep this in mind for next time.

Quoted 5 lines · Stewart Hildebrand
Quoted 4 lines

All functions in domain_build.c should be marked __init. This was spotted when building the hypervisor with -Og.

Fixes 1050a7b91c xen/arm: add pci-domain for disabled devices

I missed parenthesis and quotes around the referenced commit. To keep it in the same format as other Fixes: tags, can you please add during commit (pending release ack)?

Quoted 38 lines
Quoted 1 line

Henry, this patch is fixing a potential build failure on some compiler (at the moment we are relying on the compiler to inline handle_linux_pci_domain). AFAIU, the problem was introduced in Xen 4.17. Would you be happy if we include it in the release?

Cheers,

Quoted 24 lines

---
v1 -> v2:
   Add Fixes: tag
   Add patch description
---
  xen/arch/arm/domain_build.c | 4 ++--

  1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/arm/domain_build.c +2 -2
index 61cda8e843..fc2961895b 100644
@@ -1051,8 +1051,8 @@ static void __init assign_static_memory_11(struct domain *d,
    * The current heuristic assumes that a device is a host bridge
    * if the type is "pci" and then parent type is not "pci".
    */
-static int handle_linux_pci_domain(struct kernel_info *kinfo,
-                                   const struct dt_device_node *node)
+static int __init handle_linux_pci_domain(struct kernel_info *kinfo,
+                                          const struct dt_device_node *node)
   {
       uint16_t segment;
       int res;
Signature · 1 line
Julien Grall
#9 lore raw
Quoted 11 lines · Stewart Hildebrand
Quoted 1 line · Julien Grall

Hi Stewart,

Hi Julien,

Quoted 3 lines

I nearly missed this one because it was threaded under v1. In the future, would you be able to send new version in a separate thread? This makes easier to track it.

I will keep this in mind for next time.

Quoted 7 lines
Quoted 5 lines · Stewart Hildebrand
Quoted 4 lines

All functions in domain_build.c should be marked __init. This was spotted when building the hypervisor with -Og.

Fixes 1050a7b91c xen/arm: add pci-domain for disabled devices

I missed parenthesis and quotes around the referenced commit. To keep it in the same format as other Fixes: tags, can you please add during commit (pending release ack)?

Will do.

Cheers,

Signature · 1 line
Julien Grall
#10 lore raw
Quoted 13 lines · Julien Grall
Quoted 12 lines · Stewart Hildebrand
Quoted 1 line · Julien Grall

Hi Stewart,

Hi Julien,

Quoted 3 lines

I nearly missed this one because it was threaded under v1. In the future, would you be able to send new version in a separate thread? This makes easier to track it.

I will keep this in mind for next time.

Quoted 1 line · Stewart Hildebrand
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines

All functions in domain_build.c should be marked __init. This was spotted when building the hypervisor with -Og.

Fixes 1050a7b91c xen/arm: add pci-domain for disabled devices

I missed parenthesis and quotes around the referenced commit. To keep it in the same format as other Fixes: tags, can you please add during commit (pending release ack)?

Will do.

The commit ID was also too short. Xen (and Linux) moved to 12 characters because 10 is not enough anymore to uniquely distinguish a commit.

You can ask git to change its default value by adding the following lines in either the global config or per-repo one:

[core]

        abbrev = 12

It is now committed.

Cheers,

Signature · 1 line
Julien Grall
#11 lore raw
In reply to Julien Grall

Hi Julien,

Quoted 17 lines

-----Original Message-----
From: Julien Grall <[email protected]>
Subject: Re: [PATCH v2] xen/arm: mark handle_linux_pci_domain() __init

Hi Stewart,

I nearly missed this one because it was threaded under v1. In the future, would you be able to send new version in a separate thread? This makes easier to track it.

Quoted 5 lines · Stewart Hildebrand

All functions in domain_build.c should be marked __init. This was spotted when building the hypervisor with -Og.

Fixes 1050a7b91c xen/arm: add pci-domain for disabled devices
Quoted 6 lines

Henry, this patch is fixing a potential build failure on some compiler (at the moment we are relying on the compiler to inline handle_linux_pci_domain). AFAIU, the problem was introduced in Xen 4.17. Would you be happy if we include it in the release?

Of course. Thanks for the ping :)

Kind regards,
Henry

Quoted 31 lines

Cheers,

xen/arch/arm/domain_build.c static void __init assign_static_memory_11(struct

Quoted 14 lines

---
v1 -> v2:
Add Fixes: tag
Add patch description

---
  xen/arch/arm/domain_build.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/arm/domain_build.c +0 -0
index 61cda8e843..fc2961895b 100644
@@ -1051,8 +1051,8 @@ static void __init assign_static_memory_11(struct

domain *d,

xen/arch/arm/domain_build.c static void __init assign_static_memory_11(struct domain *d, · line 1058

Quoted 10 lines
xen/arch/arm/domain_build.c +2 -2
   * The current heuristic assumes that a device is a host bridge
   * if the type is "pci" and then parent type is not "pci".
   */
-static int handle_linux_pci_domain(struct kernel_info *kinfo,
-                                   const struct dt_device_node *node)
+static int __init handle_linux_pci_domain(struct kernel_info *kinfo,
+                                          const struct dt_device_node *node)
  {
      uint16_t segment;
      int res;

--
Julien Grall