Skip to contentSkip to conversation

xen/arm: acpi: Include header file for version number

PATCH In review Leo Yan 4 participants 14 messages Sep 6, 2022 – Sep 7, 2022

lore
Share & tools
lore

Leo Yan

author
#0 lore raw

PATCH 1/1 xen/arm: acpi: Include header file for version number

On Arm64 Linux kernel prints log for Xen version number:

  [    0.000000] Xen XEN_VERSION.XEN_SUBVERSION support found

Because the header file "xen/compile.h" is missed, XEN_VERSION and XEN_SUBVERSION are not defined, thus compiler directly uses the string "XEN_VERSION" and "XEN_SUBVERSION" in the compatible string.

This patch includes the header "xen/compile.h" which defines macros for XEN_VERSION and XEN_SUBVERSION, thus Xen can pass the version number via hypervisor node.

---
 xen/arch/arm/acpi/domain_build.c | 1 +
 1 file changed, 1 insertion(+)
xen/arch/arm/acpi/domain_build.c +1 -0
index bbdc90f92c..2649e11fd4 100644
@@ -9,6 +9,7 @@
  * GNU General Public License for more details.
  */
 
+#include <xen/compile.h>
 #include <xen/mm.h>
 #include <xen/sched.h>
 #include <xen/acpi.h>
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw

Hi Leo,

Quoted 10 lines · Leo Yan

On Arm64 Linux kernel prints log for Xen version number:

 [    0.000000] Xen XEN_VERSION.XEN_SUBVERSION support found

Because the header file "xen/compile.h" is missed, XEN_VERSION and XEN_SUBVERSION are not defined, thus compiler directly uses the string "XEN_VERSION" and "XEN_SUBVERSION" in the compatible string.

Quoted 5 lines

This patch includes the header "xen/compile.h" which defines macros for XEN_VERSION and XEN_SUBVERSION, thus Xen can pass the version number via hypervisor node.

Very nice finding and side effect from stringify.

Cheers
Bertrand

Quoted 19 lines

---
xen/arch/arm/acpi/domain_build.c | 1 +

1 file changed, 1 insertion(+)
xen/arch/arm/acpi/domain_build.c +1 -0
index bbdc90f92c..2649e11fd4 100644
@@ -9,6 +9,7 @@
 * GNU General Public License for more details.
 */
 
+#include <xen/compile.h>
 #include <xen/mm.h>
 #include <xen/sched.h>
 #include <xen/acpi.h>
Signature · 1 line
2.34.1
author
#2 lore raw
Quoted 16 lines · Bertrand Marquis

Hi Leo,

Quoted 14 lines · Leo Yan

On Arm64 Linux kernel prints log for Xen version number:

 [    0.000000] Xen XEN_VERSION.XEN_SUBVERSION support found

Because the header file "xen/compile.h" is missed, XEN_VERSION and XEN_SUBVERSION are not defined, thus compiler directly uses the string "XEN_VERSION" and "XEN_SUBVERSION" in the compatible string.

This patch includes the header "xen/compile.h" which defines macros for XEN_VERSION and XEN_SUBVERSION, thus Xen can pass the version number via hypervisor node.

Quoted 5 lines
Quoted 1 line

Very nice finding and side effect from stringify.

Thanks for review, Bertrand.

#3 lore raw
In reply to Leo Yan

Hi Leo,

Quoted 8 lines · Leo Yan

On Arm64 Linux kernel prints log for Xen version number:

   [    0.000000] Xen XEN_VERSION.XEN_SUBVERSION support found

Because the header file "xen/compile.h" is missed, XEN_VERSION and XEN_SUBVERSION are not defined, thus compiler directly uses the string "XEN_VERSION" and "XEN_SUBVERSION" in the compatible string.

Quoted 5 lines

This patch includes the header "xen/compile.h" which defines macros for XEN_VERSION and XEN_SUBVERSION, thus Xen can pass the version number via hypervisor node.

AFAICT, the problem was introduced when we split the ACPI code from arch/domain_build.c. So I would add the following tag:

Fixes 5d797ee199b3 ("xen/arm: split domain_build.c")

Now, this means we shipped Xen for ~4 years with the wrong compatible. The compatible is meant to indicate the Xen version. However, I don't think this is used for anything other than printing the version on the console.

Also, the problem occurs only when using ACPI. This is still in tech preview, so I think we don't need to document the issue in the documentation (we can easily break ABI).

xen/arch/arm/acpi/domain_build.c line 12

Quoted 13 lines
---
  xen/arch/arm/acpi/domain_build.c | 1 +
  1 file changed, 1 insertion(+)
xen/arch/arm/acpi/domain_build.c +1 -0
index bbdc90f92c..2649e11fd4 100644
@@ -9,6 +9,7 @@
   * GNU General Public License for more details.
   */
 
+#include <xen/compile.h>

So this is fixing the immediate problem. Given the subtlety of the bug, I think it would be good to also harden the code at the same time.

I can see two way to do that:
1) Dropping the use of __stringify
2) Check if XEN_VERSION and XEN_SUBVERSION are defined

The latter is probably lightweight. This could be added right next to acpi_make_hypervisor_node() for clarify.

Something like:

#ifndef XEN_VERSION

# error "XEN_VERSION is not defined"
#endif

#ifndef XEN_SUBVERSION

# error "XEN_SUBVERSION is not defined"
#endif

Could you have a look?

xen/arch/arm/acpi/domain_build.c line 15

Quoted 3 lines
xen/arch/arm/acpi/domain_build.c +0 -0
  #include <xen/mm.h>
  #include <xen/sched.h>
  #include <xen/acpi.h>

Cheers,

Signature · 1 line
Julien Grall
#4 lore raw

Hi Julien,

Quoted 23 lines · Julien Grall

Hi Leo,

Quoted 9 lines · Leo Yan

On Arm64 Linux kernel prints log for Xen version number:

  [    0.000000] Xen XEN_VERSION.XEN_SUBVERSION support found

Because the header file "xen/compile.h" is missed, XEN_VERSION and XEN_SUBVERSION are not defined, thus compiler directly uses the string "XEN_VERSION" and "XEN_SUBVERSION" in the compatible string. This patch includes the header "xen/compile.h" which defines macros for XEN_VERSION and XEN_SUBVERSION, thus Xen can pass the version number via hypervisor node.

AFAICT, the problem was introduced when we split the ACPI code from arch/domain_build.c. So I would add the following tag:

Fixes 5d797ee199b3 ("xen/arm: split domain_build.c")

Now, this means we shipped Xen for ~4 years with the wrong compatible. The compatible is meant to indicate the Xen version. However, I don't think this is used for anything other than printing the version on the console.

Also, the problem occurs only when using ACPI. This is still in tech preview, so I think we don't need to document the issue in the documentation (we can easily break ABI).

Quoted 13 lines

xen/arch/arm/acpi/domain_build.c line 11

Quoted 11 lines
---
 xen/arch/arm/acpi/domain_build.c | 1 +
 1 file changed, 1 insertion(+)
xen/arch/arm/acpi/domain_build.c +0 -0
index bbdc90f92c..2649e11fd4 100644
@@ -9,6 +9,7 @@
  * GNU General Public License for more details.
  */
 +#include <xen/compile.h>

So this is fixing the immediate problem. Given the subtlety of the bug, I think it would be good to also harden the code at the same time.

I think we should commit the patch as is and harden the code in a subsequent patch.

Quoted 10 lines

I can see two way to do that:
1) Dropping the use of __stringify
2) Check if XEN_VERSION and XEN_SUBVERSION are defined

The latter is probably lightweight. This could be added right next to acpi_make_hypervisor_node() for clarify.

Something like:

#ifndef XEN_VERSION

Quoted 8 lines
# error "XEN_VERSION is not defined"
#endif

#ifndef XEN_SUBVERSION

# error "XEN_SUBVERSION is not defined"
#endif

Could you have a look?

There are actually several places in the code where we use the stringify system. Would it make sense to actually have a string version provided in compile.h and use it instead ?

Otherwise if we start adding those kinds of checks, we will have to add them in at least 3 places in xen code.

Cheers
Bertrand

Quoted 9 lines

xen/arch/arm/acpi/domain_build.c line 15

Quoted 4 lines
xen/arch/arm/acpi/domain_build.c +0 -0
 #include <xen/mm.h>
 #include <xen/sched.h>
 #include <xen/acpi.h>

Cheers,

Signature · 1 line
Julien Grall
#5 lore raw
Quoted 37 lines · Bertrand Marquis
Quoted 23 lines · Julien Grall

Hi Leo,

Quoted 9 lines · Leo Yan

On Arm64 Linux kernel prints log for Xen version number:

   [    0.000000] Xen XEN_VERSION.XEN_SUBVERSION support found

Because the header file "xen/compile.h" is missed, XEN_VERSION and XEN_SUBVERSION are not defined, thus compiler directly uses the string "XEN_VERSION" and "XEN_SUBVERSION" in the compatible string. This patch includes the header "xen/compile.h" which defines macros for XEN_VERSION and XEN_SUBVERSION, thus Xen can pass the version number via hypervisor node.

AFAICT, the problem was introduced when we split the ACPI code from arch/domain_build.c. So I would add the following tag:

Fixes 5d797ee199b3 ("xen/arm: split domain_build.c")

Now, this means we shipped Xen for ~4 years with the wrong compatible. The compatible is meant to indicate the Xen version. However, I don't think this is used for anything other than printing the version on the console.

Also, the problem occurs only when using ACPI. This is still in tech preview, so I think we don't need to document the issue in the documentation (we can easily break ABI).

Quoted 13 lines

xen/arch/arm/acpi/domain_build.c line 11

Quoted 11 lines
---
  xen/arch/arm/acpi/domain_build.c | 1 +
  1 file changed, 1 insertion(+)
xen/arch/arm/acpi/domain_build.c +0 -0
index bbdc90f92c..2649e11fd4 100644
@@ -9,6 +9,7 @@
   * GNU General Public License for more details.
   */
  +#include <xen/compile.h>

So this is fixing the immediate problem. Given the subtlety of the bug, I think it would be good to also harden the code at the same time.

Quoted 1 line

I think we should commit the patch as is and harden the code in a subsequent patch.

I thought about this. However, if we do the hardening in the same patch, then it makes a lot easier to confirm that the patch works when ingested in downstream code or backported.

Quoted 14 lines
Quoted 14 lines

I can see two way to do that:
1) Dropping the use of __stringify
2) Check if XEN_VERSION and XEN_SUBVERSION are defined

The latter is probably lightweight. This could be added right next to acpi_make_hypervisor_node() for clarify.

Something like:

#ifndef XEN_VERSION

# error "XEN_VERSION is not defined"
#endif
Quoted 8 lines
Quoted 5 lines

#ifndef XEN_SUBVERSION

# error "XEN_SUBVERSION is not defined"
#endif

Could you have a look?

There are actually several places in the code where we use the stringify system. Would it make sense to actually have a string version provided in compile.h and use it instead ?

I think so.

Quoted 2 lines

Otherwise if we start adding those kinds of checks, we will have to add them in at least 3 places in xen code.

The solution I proposed above is easy to implement right now. My gut feeling is tweaking __stringify (or else) will take a bit more time.

If you (or Leo) can come up with a solution quickly then fine. Otherwise, I think we still want some hardening for backporting purpose.

Cheers,

Signature · 1 line
Julien Grall
#6 lore raw

Hi Julien,

Quoted 66 lines · Julien Grall
Quoted 36 lines · Bertrand Marquis
Quoted 23 lines · Julien Grall

Hi Leo,

Quoted 9 lines · Leo Yan

On Arm64 Linux kernel prints log for Xen version number:

  [    0.000000] Xen XEN_VERSION.XEN_SUBVERSION support found

Because the header file "xen/compile.h" is missed, XEN_VERSION and XEN_SUBVERSION are not defined, thus compiler directly uses the string "XEN_VERSION" and "XEN_SUBVERSION" in the compatible string. This patch includes the header "xen/compile.h" which defines macros for XEN_VERSION and XEN_SUBVERSION, thus Xen can pass the version number via hypervisor node.

AFAICT, the problem was introduced when we split the ACPI code from arch/domain_build.c. So I would add the following tag:

Fixes 5d797ee199b3 ("xen/arm: split domain_build.c")

Now, this means we shipped Xen for ~4 years with the wrong compatible. The compatible is meant to indicate the Xen version. However, I don't think this is used for anything other than printing the version on the console.

Also, the problem occurs only when using ACPI. This is still in tech preview, so I think we don't need to document the issue in the documentation (we can easily break ABI).

Quoted 13 lines

xen/arch/arm/acpi/domain_build.c line 11

Quoted 11 lines
---
 xen/arch/arm/acpi/domain_build.c | 1 +
 1 file changed, 1 insertion(+)
xen/arch/arm/acpi/domain_build.c +0 -0
index bbdc90f92c..2649e11fd4 100644
@@ -9,6 +9,7 @@
  * GNU General Public License for more details.
  */
 +#include <xen/compile.h>

So this is fixing the immediate problem. Given the subtlety of the bug, I think it would be good to also harden the code at the same time.

Quoted 1 line

I think we should commit the patch as is and harden the code in a subsequent patch.

I thought about this. However, if we do the hardening in the same patch, then it makes a lot easier to confirm that the patch works when ingested in downstream code or backported.

Quoted 13 lines
Quoted 13 lines

I can see two way to do that:
1) Dropping the use of __stringify
2) Check if XEN_VERSION and XEN_SUBVERSION are defined

The latter is probably lightweight. This could be added right next to acpi_make_hypervisor_node() for clarify.

Something like:

#ifndef XEN_VERSION

# error "XEN_VERSION is not defined"
#endif
Quoted 7 lines
Quoted 5 lines

#ifndef XEN_SUBVERSION

# error "XEN_SUBVERSION is not defined"
#endif

Could you have a look?

There are actually several places in the code where we use the stringify system. Would it make sense to actually have a string version provided in compile.h and use it instead ?

Quoted 7 lines

I think so.

Quoted 1 line

Otherwise if we start adding those kinds of checks, we will have to add them in at least 3 places in xen code.

The solution I proposed above is easy to implement right now. My gut feeling is tweaking __stringify (or else) will take a bit more time.

If you (or Leo) can come up with a solution quickly then fine. Otherwise, I think we still want some hardening for backporting purpose.

I think a define in compile.h using stringify is the easiest solution:

#define XEN_STR_VERSION "__stringify(XEN_VERSION)"."__stringify(XEN_SUBVERSION)”

And then change the code in the following source code to use it:
arch/arm/domain_build.c
arch/arm/acpi/domain_build.c
common/efi/boot.c

@Leo: tell me if you need help or want me to do it

Cheers
Bertrand

Quoted 5 lines

Cheers,

Signature · 1 line
Julien Grall
#7 lore raw
Quoted 7 lines · Bertrand Marquis
Quoted 5 lines
Quoted 1 line

Otherwise if we start adding those kinds of checks, we will have to add them in at least 3 places in xen code.

The solution I proposed above is easy to implement right now. My gut feeling is tweaking __stringify (or else) will take a bit more time.

If you (or Leo) can come up with a solution quickly then fine. Otherwise, I think we still want some hardening for backporting purpose.

I think a define in compile.h using stringify is the easiest solution:

Ah! I thought you were suggesting to tweak __stringify. This is ...

Quoted 7 lines

#define XEN_STR_VERSION "__stringify(XEN_VERSION)"."__stringify(XEN_SUBVERSION)”

And then change the code in the following source code to use it:
arch/arm/domain_build.c
arch/arm/acpi/domain_build.c
common/efi/boot.c

... much better.

Cheers,

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

On 07/09/2022 09:53, Bertrand Marquis wrote:

Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Quoted 1 line

Otherwise if we start adding those kinds of checks, we will have to add them in at least 3 places in xen code.

The solution I proposed above is easy to implement right now. My gut feeling is tweaking __stringify (or else) will take a bit more time.

If you (or Leo) can come up with a solution quickly then fine. Otherwise, I think we still want some hardening for backporting purpose.

I think a define in compile.h using stringify is the easiest solution:

Ah! I thought you were suggesting to tweak __stringify. This is ...

Also possible but a bit more tricky

Quoted 1 line
Quoted 1 line

#define XEN_STR_VERSION "__stringify(XEN_VERSION)"."__stringify(XEN_SUBVERSION)”

Quotes at beginning and end should not be there.

Quoted 6 lines
Quoted 4 lines

And then change the code in the following source code to use it:
arch/arm/domain_build.c
arch/arm/acpi/domain_build.c
common/efi/boot.c

... much better.

Thanks :-)

Bertrand

Quoted 5 lines

Cheers,

Signature · 1 line
Julien Grall
#9 lore raw
Quoted 9 lines · Bertrand Marquis
Quoted 9 lines · Julien Grall
Quoted 6 lines · Bertrand Marquis
Quoted 5 lines
Quoted 1 line

Otherwise if we start adding those kinds of checks, we will have to add them in at least 3 places in xen code.

The solution I proposed above is easy to implement right now. My gut feeling is tweaking __stringify (or else) will take a bit more time.

If you (or Leo) can come up with a solution quickly then fine. Otherwise, I think we still want some hardening for backporting purpose.

I think a define in compile.h using stringify is the easiest solution:

Quoted 7 lines
Quoted 1 line

Ah! I thought you were suggesting to tweak __stringify. This is ...

Also possible but a bit more tricky

Quoted 1 line
Quoted 1 line

#define XEN_STR_VERSION "__stringify(XEN_VERSION)"."__stringify(XEN_SUBVERSION)”

Quotes at beginning and end should not be there.

I have to admit that I dislike the STR infix. I'd prefer a suffixed variant (e.g. XEN_VERSION_STRING) or one omitting "string" altogether, e.g. XEN_FULL_VERSION (albeit I see "full" as being potentially ambiguous here, since one might expect that to include XEN_EXTRAVERSION as well then).

Jan

#10 lore raw

Hi Jan,

Quoted 16 lines · Jan Beulich
Quoted 13 lines · Bertrand Marquis
Quoted 10 lines · Julien Grall
Quoted 6 lines · Bertrand Marquis
Quoted 5 lines
Quoted 1 line

Otherwise if we start adding those kinds of checks, we will have to add them in at least 3 places in xen code.

The solution I proposed above is easy to implement right now. My gut feeling is tweaking __stringify (or else) will take a bit more time.

If you (or Leo) can come up with a solution quickly then fine. Otherwise, I think we still want some hardening for backporting purpose.

I think a define in compile.h using stringify is the easiest solution:

Ah! I thought you were suggesting to tweak __stringify. This is ...

Also possible but a bit more tricky

Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line

#define XEN_STR_VERSION "__stringify(XEN_VERSION)"."__stringify(XEN_SUBVERSION)”

Quotes at beginning and end should not be there.

I have to admit that I dislike the STR infix. I'd prefer a suffixed variant (e.g. XEN_VERSION_STRING) or one omitting "string" altogether, e.g. XEN_FULL_VERSION (albeit I see "full" as being potentially ambiguous here, since one might expect that to include XEN_EXTRAVERSION as well then).

Version is a value so here I though it made sense to distinguish that one as it is a string representation of it.

XEN_VERSION_STRING is ok I think.

I generally dislike anything named FULL, EXTRA, BASE or other which are just unclear.

Bertrand

Quoted 2 lines

Jan

author
#11 lore raw

On Wed, Sep 07, 2022 at 10:05:54AM +0000, Bertrand Marquis wrote:

[...]

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Quoted 1 line

I think a define in compile.h using stringify is the easiest solution:

Ah! I thought you were suggesting to tweak __stringify. This is ...

Also possible but a bit more tricky

Quoted 1 line
Quoted 1 line

#define XEN_STR_VERSION "__stringify(XEN_VERSION)"."__stringify(XEN_SUBVERSION)”

Just remind, We need to define XEN_VERSION_STRING in compile.h.in rather than in compile.h, something like:

  #define XEN_VERSION_STRING @@version@@.@@subversion@@
Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Quotes at beginning and end should not be there.

I have to admit that I dislike the STR infix. I'd prefer a suffixed variant (e.g. XEN_VERSION_STRING) or one omitting "string" altogether, e.g. XEN_FULL_VERSION (albeit I see "full" as being potentially ambiguous here, since one might expect that to include XEN_EXTRAVERSION as well then).

Quoted 5 lines

Version is a value so here I though it made sense to distinguish that one as it is a string representation of it.

XEN_VERSION_STRING is ok I think.

I generally dislike anything named FULL, EXTRA, BASE or other which are just unclear.

XEN_VERSION_STRING is good for me.

Hi Bertrand, just let me know if you prefer to cook your own patch for this (essentially this idea is coming from you) or you want me to follow up for a new patch? Either way is fine for me.

Thanks,
Leo

#12 lore raw

Hi Leo,

Quoted 10 lines · Leo Yan

On Wed, Sep 07, 2022 at 10:05:54AM +0000, Bertrand Marquis wrote:

[...]

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line

I think a define in compile.h using stringify is the easiest solution:

Ah! I thought you were suggesting to tweak __stringify. This is ...

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Also possible but a bit more tricky

Quoted 1 line
Quoted 1 line

#define XEN_STR_VERSION "__stringify(XEN_VERSION)"."__stringify(XEN_SUBVERSION)”

Just remind, We need to define XEN_VERSION_STRING in compile.h.in rather than in compile.h, something like:

#define XEN_VERSION_STRING @@version@@.@@subversion@@

Very true but you will need the quotes here

Quoted 13 lines
Quoted 13 lines
Quoted 7 lines
Quoted 2 lines

Quotes at beginning and end should not be there.

I have to admit that I dislike the STR infix. I'd prefer a suffixed variant (e.g. XEN_VERSION_STRING) or one omitting "string" altogether, e.g. XEN_FULL_VERSION (albeit I see "full" as being potentially ambiguous here, since one might expect that to include XEN_EXTRAVERSION as well then).

Version is a value so here I though it made sense to distinguish that one as it is a string representation of it.

XEN_VERSION_STRING is ok I think.

Quoted 7 lines
Quoted 1 line

I generally dislike anything named FULL, EXTRA, BASE or other which are just unclear.

XEN_VERSION_STRING is good for me.

Hi Bertrand, just let me know if you prefer to cook your own patch for this (essentially this idea is coming from you) or you want me to follow up for a new patch? Either way is fine for me.

Please push a new patch and add:

Cheers
Bertrand

Quoted 3 lines

Thanks,
Leo

author
#13 lore raw

On Wed, Sep 07, 2022 at 11:12:24AM +0000, Bertrand Marquis wrote:

[...]

Quoted 6 lines
Quoted 4 lines

Just remind, We need to define XEN_VERSION_STRING in compile.h.in rather than in compile.h, something like:

#define XEN_VERSION_STRING @@version@@.@@subversion@@

Very true but you will need the quotes here

Yeah.

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 6 lines
Quoted 1 line

Quotes at beginning and end should not be there.

I have to admit that I dislike the STR infix. I'd prefer a suffixed variant (e.g. XEN_VERSION_STRING) or one omitting "string" altogether, e.g. XEN_FULL_VERSION (albeit I see "full" as being potentially ambiguous here, since one might expect that to include XEN_EXTRAVERSION as well then).

Version is a value so here I though it made sense to distinguish that one as it is a string representation of it.

XEN_VERSION_STRING is ok I think.

I generally dislike anything named FULL, EXTRA, BASE or other which are just unclear.

Quoted 8 lines
Quoted 5 lines

XEN_VERSION_STRING is good for me.

Hi Bertrand, just let me know if you prefer to cook your own patch for this (essentially this idea is coming from you) or you want me to follow up for a new patch? Either way is fine for me.

Please push a new patch and add:

Sure, will do.

Thanks all for suggestions.

Leo