Skip to contentSkip to conversation

tools/libs: Multiple fixes to header handling

PATCH In review Andrew Cooper 4 participants 18 messages Mar 5, 2021 – Mar 11, 2021

lore
Share & tools
lore
#0 lore raw

cover tools/libs: Multiple fixes to header handling

This can of worms is festering. See patch 1 for yet more issues.

Andrew Cooper (3):
tools/libxentoolcore: Fill in LIBHEADERS xen/dmop: Strip __XEN_TOOLS__ header guard from public API tools/libs: Fix headers.chk logic

 tools/libs/devicemodel/private.h | 2 --
 tools/libs/libs.mk               | 2 +-
 tools/libs/toolcore/Makefile     | 2 ++
 xen/include/public/hvm/dm_op.h   | 5 -----
 4 files changed, 3 insertions(+), 8 deletions(-)
Signature · 1 line
2.11.0
#1 lore raw

PATCH 1/3 tools/libxentoolcore: Fill in LIBHEADERS

c/s 4664034cd replaced a glob over include/*.h with an expectation that LIBHEADER was suitably set for libraries which didn't have a single, consistently named, header file.

This wasn't true for xentoolcore, which lost xentoolcore_internal.h as a consequence, and failed an API/ABI check vs 4.14

Fixes 4664034cd ("tools/libs: move official headers to common directory")

---
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Juergen Gross <[email protected]>

For 4.15. This is a regression from 4.14, even if AFAICT it only impacts the ABI checking at this point.

I *think* this is the only impacted library, but I would appreciate a second pair of eyes.

I did experiment with this:

  +ifeq ($(LIBHEADER),)
  +$(warning $(LIBNAME) - No headers)
  +endif
   LIBHEADER ?= $(LIB_FILE_NAME).h
   LIBHEADERS = $(foreach h, $(LIBHEADER), $(XEN_INCLUDE)/$(h))

which yields:

  andrewcoop@andrewcoop:/local/xen.git$ make -j4 -s -C tools/libs/
  /local/xen.git/tools/libs/toollog/../../../tools/libs/libs.mk:50: toollog - No headers
  /local/xen.git/tools/libs/evtchn/../../../tools/libs/libs.mk:50: evtchn - No headers
  /local/xen.git/tools/libs/gnttab/../../../tools/libs/libs.mk:50: gnttab - No headers
  /local/xen.git/tools/libs/call/../../../tools/libs/libs.mk:50: call - No headers
  /local/xen.git/tools/libs/foreignmemory/../../../tools/libs/libs.mk:50: foreignmemory - No headers
  /local/xen.git/tools/libs/devicemodel/../../../tools/libs/libs.mk:50: devicemodel - No headers
  ../libs.mk:50: hypfs - No headers
  /local/xen.git/tools/libs/stat/../../../tools/libs/libs.mk:50: stat - No headers
  /local/xen.git/tools/libs/stat/../../../tools/libs/libs.mk:50: stat - No headers

Headers aside for a moment, there are two bugs here. hypfs doesn't use the same include pattern as the others, and stat is entered twice.

---
 tools/libs/toolcore/Makefile | 2 ++
 1 file changed, 2 insertions(+)
tools/libs/toolcore/Makefile +2 -0
index 1cf30733c9..3550786491 100644
@@ -5,6 +5,8 @@ MAJOR	= 1
 MINOR	= 0
 AUTOINCS := $(XEN_INCLUDE)/_xentoolcore_list.h
 
+LIBHEADER := xentoolcore.h xentoolcore_internal.h
+
 SRCS-y	+= handlereg.c
 
 include $(XEN_ROOT)/tools/libs/libs.mk
Signature · 1 line
2.11.0
#2 lore raw

PATCH 1/3 tools/libxentoolcore: Fill in LIBHEADERS

Andrew Cooper writes ("[PATCH 1/3] tools/libxentoolcore: Fill in LIBHEADERS"):

Quoted 9 lines

c/s 4664034cd replaced a glob over include/*.h with an expectation that LIBHEADER was suitably set for libraries which didn't have a single, consistently named, header file.

This wasn't true for xentoolcore, which lost xentoolcore_internal.h as a consequence, and failed an API/ABI check vs 4.14

Fixes 4664034cd ("tools/libs: move official headers to common directory")
Reviewed-by on v1 1/3
#3 lore raw

Re: [PATCH 1/3] tools/libxentoolcore: Fill in LIBHEADERS

In reply to Andrew Cooper
Quoted 9 lines · Andrew Cooper

c/s 4664034cd replaced a glob over include/*.h with an expectation that LIBHEADER was suitably set for libraries which didn't have a single, consistently named, header file.

This wasn't true for xentoolcore, which lost xentoolcore_internal.h as a consequence, and failed an API/ABI check vs 4.14

Fixes 4664034cd ("tools/libs: move official headers to common directory")

Juergen

#4 lore raw

PATCH 2/3 xen/dmop: Strip __XEN_TOOLS__ header guard from public API

In reply to Andrew Cooper

Exactly as with c/s f40e1c52e4, this is inappropriate for a stable library.

That change actually broke the build with:

include/xendevicemodel.h:52:5: error: unknown type name 'ioservid_t'

       ioservid_t *id);
       ^

as libxendevicemodel.h now uses a type it can't see a typedef for. However, nothing noticed because the header.chk logic is also broken (fixed subsequently).

Strip the guard from the public header, and remove compensation from devicemodel's private.h

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Ian Jackson <[email protected]>

For 4.15. This is a build fix, even if current staging can't spot the breakage.

These two issues highlight that libxendevcemodel.h has never been checked since its introduction, because the checking logic only saw an empty file.

---
 tools/libs/devicemodel/private.h | 2 --
 xen/include/public/hvm/dm_op.h   | 5 -----
 2 files changed, 7 deletions(-)
tools/libs/devicemodel/private.h +0 -2
index c4a225f8af..c24f3396bb 100644
@@ -1,8 +1,6 @@
 #ifndef XENDEVICEMODEL_PRIVATE_H
 #define XENDEVICEMODEL_PRIVATE_H
 
-#define __XEN_TOOLS__ 1
-
 #include <xentoollog.h>
 #include <xendevicemodel.h>
 #include <xencall.h>
xen/include/public/hvm/dm_op.h +0 -5
index ef7fbc0d3d..fa3f083fed 100644
@@ -25,9 +25,6 @@
 #define __XEN_PUBLIC_HVM_DM_OP_H__
 
 #include "../xen.h"
-
-#if defined(__XEN__) || defined(__XEN_TOOLS__)
-
 #include "../event_channel.h"
 
 #ifndef uint64_aligned_t
@@ -491,8 +488,6 @@ struct xen_dm_op {
     } u;
 };
 
-#endif /* __XEN__ || __XEN_TOOLS__ */
-
 struct xen_dm_op_buf {
     XEN_GUEST_HANDLE(void) h;
     xen_ulong_t size;
Signature · 1 line
2.11.0
#5 lore raw

Re: [PATCH 2/3] xen/dmop: Strip __XEN_TOOLS__ header guard from public API

Andrew Cooper writes ("[PATCH 2/3] xen/dmop: Strip __XEN_TOOLS__ header guard from public API"):

Quoted 8 lines

Exactly as with c/s f40e1c52e4, this is inappropriate for a stable library.

That change actually broke the build with:

include/xendevicemodel.h:52:5: error: unknown type name 'ioservid_t'

       ioservid_t *id);
       ^
Quoted 6 lines

as libxendevicemodel.h now uses a type it can't see a typedef for. However, nothing noticed because the header.chk logic is also broken (fixed subsequently).

Strip the guard from the public header, and remove compensation from devicemodel's private.h

#6 lore raw

Re: [PATCH 2/3] xen/dmop: Strip __XEN_TOOLS__ header guard from public API

In reply to Andrew Cooper
Quoted 11 lines · Andrew Cooper

Exactly as with c/s f40e1c52e4, this is inappropriate for a stable library.

That change actually broke the build with:

include/xendevicemodel.h:52:5: error: unknown type name 'ioservid_t'

       ioservid_t *id);
       ^

as libxendevicemodel.h now uses a type it can't see a typedef for. However, nothing noticed because the header.chk logic is also broken (fixed subsequently).

While I agree up to here, ...

Quoted 2 lines

Strip the guard from the public header, and remove compensation from devicemodel's private.h

... I'm unconvinced that entirely dropping the guard from the public header is wanted (or needed): We use these to make clear that in particular kernels aren't supposed to make use of the enclosed entities. If a type needs exposing, it (and only it) wants moving ou of the guarded region imo.

Jan

#7 lore raw

Re: [PATCH 2/3] xen/dmop: Strip __XEN_TOOLS__ header guard from public API

Quoted 14 lines · Jan Beulich
Quoted 11 lines · Andrew Cooper

Exactly as with c/s f40e1c52e4, this is inappropriate for a stable library.

That change actually broke the build with:

include/xendevicemodel.h:52:5: error: unknown type name 'ioservid_t'

       ioservid_t *id);
       ^

as libxendevicemodel.h now uses a type it can't see a typedef for. However, nothing noticed because the header.chk logic is also broken (fixed subsequently).

While I agree up to here, ...

Quoted 7 lines
Quoted 2 lines

Strip the guard from the public header, and remove compensation from devicemodel's private.h

... I'm unconvinced that entirely dropping the guard from the public header is wanted (or needed): We use these to make clear that in particular kernels aren't supposed to make use of the enclosed entities. If a type needs exposing, it (and only it) wants moving ou of the guarded region imo.

DMOP was invented specifically so a kernel module (i915, for Intel gVT-g) was independent of the domctl ABI version.

Improving the life of dom0 userspace was an intended consequence, but not the driving force behind the change.

Exactly the same is true for stubdoms currently, and I am very serious about purging unstable interfaces eventually.

~Andrew

#8 lore raw

Re: [PATCH 2/3] xen/dmop: Strip __XEN_TOOLS__ header guard from public API

Quoted 23 lines · Andrew Cooper
Quoted 14 lines · Jan Beulich
Quoted 11 lines · Andrew Cooper

Exactly as with c/s f40e1c52e4, this is inappropriate for a stable library.

That change actually broke the build with:

include/xendevicemodel.h:52:5: error: unknown type name 'ioservid_t'

       ioservid_t *id);
       ^

as libxendevicemodel.h now uses a type it can't see a typedef for. However, nothing noticed because the header.chk logic is also broken (fixed subsequently).

While I agree up to here, ...

Quoted 7 lines
Quoted 2 lines

Strip the guard from the public header, and remove compensation from devicemodel's private.h

... I'm unconvinced that entirely dropping the guard from the public header is wanted (or needed): We use these to make clear that in particular kernels aren't supposed to make use of the enclosed entities. If a type needs exposing, it (and only it) wants moving ou of the guarded region imo.

Quoted 5 lines

DMOP was invented specifically so a kernel module (i915, for Intel gVT-g) was independent of the domctl ABI version.

Improving the life of dom0 userspace was an intended consequence, but not the driving force behind the change.

This is news to me - so far it had been my understanding that it was introduced to have a way for the kernel to audit and hand on requests to the hypervisor without needing to know all the inner details. I wasn't even aware a kernel module was using any of these.

Jan

#9 lore raw

Re: [PATCH 2/3] xen/dmop: Strip __XEN_TOOLS__ header guard from public API

Quoted 27 lines · Jan Beulich
Quoted 26 lines · Andrew Cooper
Quoted 14 lines · Jan Beulich
Quoted 11 lines · Andrew Cooper

Exactly as with c/s f40e1c52e4, this is inappropriate for a stable library.

That change actually broke the build with:

include/xendevicemodel.h:52:5: error: unknown type name 'ioservid_t'

       ioservid_t *id);
       ^

as libxendevicemodel.h now uses a type it can't see a typedef for. However, nothing noticed because the header.chk logic is also broken (fixed subsequently).

While I agree up to here, ...

Quoted 7 lines
Quoted 2 lines

Strip the guard from the public header, and remove compensation from devicemodel's private.h

... I'm unconvinced that entirely dropping the guard from the public header is wanted (or needed): We use these to make clear that in particular kernels aren't supposed to make use of the enclosed entities. If a type needs exposing, it (and only it) wants moving ou of the guarded region imo.

DMOP was invented specifically so a kernel module (i915, for Intel gVT-g) was independent of the domctl ABI version.

Quoted 8 lines
Quoted 2 lines

Improving the life of dom0 userspace was an intended consequence, but not the driving force behind the change.

This is news to me - so far it had been my understanding that it was introduced to have a way for the kernel to audit and hand on requests to the hypervisor without needing to know all the inner details. I wasn't even aware a kernel module was using any of these.

And indeed, quote from docs/designs/dmop.markdown:

"The aim of DMOP is to prevent a compromised device model from
compromising domains other than the one it is providing emulation for (which is therefore likely already compromised)."

And it goes on discussing only the purpose that I've been aware of.

Jan

#10 lore raw

Re: [PATCH 2/3] xen/dmop: Strip __XEN_TOOLS__ header guard from public API

Quoted 34 lines · Jan Beulich
Quoted 26 lines · Jan Beulich
Quoted 25 lines · Andrew Cooper
Quoted 14 lines · Jan Beulich
Quoted 11 lines · Andrew Cooper

Exactly as with c/s f40e1c52e4, this is inappropriate for a stable library.

That change actually broke the build with:

include/xendevicemodel.h:52:5: error: unknown type name 'ioservid_t'

       ioservid_t *id);
       ^

as libxendevicemodel.h now uses a type it can't see a typedef for. However, nothing noticed because the header.chk logic is also broken (fixed subsequently).

While I agree up to here, ...

Quoted 7 lines
Quoted 2 lines

Strip the guard from the public header, and remove compensation from devicemodel's private.h

... I'm unconvinced that entirely dropping the guard from the public header is wanted (or needed): We use these to make clear that in particular kernels aren't supposed to make use of the enclosed entities. If a type needs exposing, it (and only it) wants moving ou of the guarded region imo.

DMOP was invented specifically so a kernel module (i915, for Intel gVT-g) was independent of the domctl ABI version.

Quoted 7 lines
Quoted 2 lines

Improving the life of dom0 userspace was an intended consequence, but not the driving force behind the change.

This is news to me - so far it had been my understanding that it was introduced to have a way for the kernel to audit and hand on requests to the hypervisor without needing to know all the inner details. I wasn't even aware a kernel module was using any of these.

Quoted 8 lines

And indeed, quote from docs/designs/dmop.markdown:

"The aim of DMOP is to prevent a compromised device model from
compromising domains other than the one it is providing emulation for (which is therefore likely already compromised)."

And it goes on discussing only the purpose that I've been aware of.

The use in the dom0 kernel wasn't kept secret in the slightest.  It was discussed on at the time, and at dev summits.

But upstream tends to only remember/care about the bits which pertain directly to upstream, and the design particulars of the DMOP ABI were specifically for userspace.

~Andrew

#11 lore raw

Re: [PATCH 2/3] xen/dmop: Strip __XEN_TOOLS__ header guard from public API

Andrew Cooper writes ("Re: [PATCH 2/3] xen/dmop: Strip __XEN_TOOLS__ header guard from public API"):

Quoted 2 lines

The use in the dom0 kernel wasn't kept secret in the slightest.  It was discussed on at the time, and at dev summits.

No-one is accusing anyone of keeping anything secret.

Quoted 2 lines

But upstream tends to only remember/care about the bits which pertain directly to upstream,

I would prefer to say that upstream only tends to remember things which are WRITTEN DOWN.

Ian.

#12 lore raw

Re: [PATCH 2/3] xen/dmop: Strip __XEN_TOOLS__ header guard from public API

In reply to Jan Beulich

Jan Beulich writes ("Re: [PATCH 2/3] xen/dmop: Strip __XEN_TOOLS__ header guard from public API"):

Quoted 5 lines

This is news to me - so far it had been my understanding that it was introduced to have a way for the kernel to audit and hand on requests to the hypervisor without needing to know all the inner details. I wasn't even aware a kernel module was using any of these.

Quite so.

Ian.

#13 lore raw

PATCH 3/3 tools/libs: Fix headers.chk logic

In reply to Andrew Cooper

c/s 4664034cd dropped the $(LIBHEADERSGLOB) dependency for the headers.chk rule, without replacing it.

As headers.chk uses $^, a typical build looks like:

  andrewcoop@andrewcoop:/local/xen.git$ make -C tools/libs/devicemodel/
  make: Entering directory '/local/xen.git/tools/libs/devicemodel'
  for i in ; do \
      gcc -x c -ansi -Wall -Werror
      -I/local/xen.git/tools/libs/devicemodel/../../../tools/include \
            -S -o /dev/null $i || exit 1; \
      echo $i; \
  done >headers.chk.new
  mv headers.chk.new headers.chk

i.e. with an empty for loop, and checking only the $(AUTOINCS).

Reinsert a $(LIBHEADERS) dependency.

Fixes 4664034cd ("tools/libs: move official headers to common directory")

---
CC: Juergen Gross <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>

---
 tools/libs/libs.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libs/libs.mk +1 -1
index a68cec244c..2d973ccb95 100644
@@ -76,7 +76,7 @@ else
 .PHONY: headers.chk
 endif
 
-headers.chk: $(AUTOINCS)
+headers.chk: $(LIBHEADERS) $(AUTOINCS)
 
 headers.lst: FORCE
 	@{ set -e; $(foreach h,$(LIBHEADERS),echo $(h);) } > [email protected]
Signature · 1 line
2.11.0
#14 lore raw

Re: [PATCH 3/3] tools/libs: Fix headers.chk logic

Quoted 17 lines · Andrew Cooper

c/s 4664034cd dropped the $(LIBHEADERSGLOB) dependency for the headers.chk rule, without replacing it.

As headers.chk uses $^, a typical build looks like:

  andrewcoop@andrewcoop:/local/xen.git$ make -C tools/libs/devicemodel/
  make: Entering directory '/local/xen.git/tools/libs/devicemodel'
  for i in ; do \
      gcc -x c -ansi -Wall -Werror
      -I/local/xen.git/tools/libs/devicemodel/../../../tools/include \
            -S -o /dev/null $i || exit 1; \
      echo $i; \
  done >headers.chk.new
  mv headers.chk.new headers.chk

i.e. with an empty for loop, and checking only the $(AUTOINCS).

Quoted 8 lines

Reinsert a $(LIBHEADERS) dependency.

Fixes 4664034cd ("tools/libs: move official headers to common directory")

---
CC: Juergen Gross <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>

Apologies - I totally messed up the CC list here.

For 4.15.  Regression from 4.14, in some build-time checking logic.

~Andrew

Quoted 17 lines
---
 tools/libs/libs.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libs/libs.mk +1 -1
index a68cec244c..2d973ccb95 100644
@@ -76,7 +76,7 @@ else
 .PHONY: headers.chk
 endif
 
-headers.chk: $(AUTOINCS)
+headers.chk: $(LIBHEADERS) $(AUTOINCS)
 
 headers.lst: FORCE
 	@{ set -e; $(foreach h,$(LIBHEADERS),echo $(h);) } > [email protected]
#15 lore raw

Re: [PATCH 3/3] tools/libs: Fix headers.chk logic

Andrew Cooper writes ("Re: [PATCH 3/3] tools/libs: Fix headers.chk logic"):

Quoted 16 lines · Andrew Cooper
Quoted 15 lines

c/s 4664034cd dropped the $(LIBHEADERSGLOB) dependency for the headers.chk rule, without replacing it.

As headers.chk uses $^, a typical build looks like:

  andrewcoop@andrewcoop:/local/xen.git$ make -C tools/libs/devicemodel/
  make: Entering directory '/local/xen.git/tools/libs/devicemodel'
  for i in ; do \
      gcc -x c -ansi -Wall -Werror
      -I/local/xen.git/tools/libs/devicemodel/../../../tools/include \
            -S -o /dev/null $i || exit 1; \
      echo $i; \
  done >headers.chk.new
  mv headers.chk.new headers.chk
Quoted 3 lines
Quoted 3 lines

i.e. with an empty for loop, and checking only the $(AUTOINCS).

Reinsert a $(LIBHEADERS) dependency.

Reviewed-by on v1 3/3
#16 lore raw

Re: [PATCH 3/3] tools/libs: Fix headers.chk logic

In reply to Andrew Cooper
Quoted 15 lines · Andrew Cooper

c/s 4664034cd dropped the $(LIBHEADERSGLOB) dependency for the headers.chk rule, without replacing it.

As headers.chk uses $^, a typical build looks like:

   andrewcoop@andrewcoop:/local/xen.git$ make -C tools/libs/devicemodel/
   make: Entering directory '/local/xen.git/tools/libs/devicemodel'
   for i in ; do \
       gcc -x c -ansi -Wall -Werror
       -I/local/xen.git/tools/libs/devicemodel/../../../tools/include \
             -S -o /dev/null $i || exit 1; \
       echo $i; \
   done >headers.chk.new
   mv headers.chk.new headers.chk
Quoted 6 lines

i.e. with an empty for loop, and checking only the $(AUTOINCS).

Reinsert a $(LIBHEADERS) dependency.

Fixes 4664034cd ("tools/libs: move official headers to common directory")

Juergen

#17 lore raw

Re: Ping [PATCH for-4.15 0/3] tools/libs: Multiple fixes to header handling

In reply to Andrew Cooper
Quoted 6 lines · Andrew Cooper

This can of worms is festering. See patch 1 for yet more issues.

Andrew Cooper (3):
tools/libxentoolcore: Fill in LIBHEADERS xen/dmop: Strip __XEN_TOOLS__ header guard from public API tools/libs: Fix headers.chk logic

Ping for acks/otherwise on patches 1 and 3?  (They're already R-A'd)

Given their simplicity, as well as being regression fixes for build-time checks, I'll commit them tomorrow unless any objections are raised.

~Andrew