Skip to contentSkip to conversation

xen/dmop: Strip __XEN_TOOLS__ header guard from public API

PATCH Superseded Andrew Cooper 4 participants 19 messages Mar 10, 2021 – Mar 12, 2021

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 xen/dmop: Strip __XEN_TOOLS__ header guard from public API

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. Fix the dmop design doc to discuss both reasons behind the the ABI design.

---
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]>

v2:
* Patch dmop.pandoc as well.

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.

---
 docs/designs/dmop.pandoc         | 10 +++++++---
 tools/libs/devicemodel/private.h |  2 --
 xen/include/public/hvm/dm_op.h   |  5 -----
 3 files changed, 7 insertions(+), 10 deletions(-)
docs/designs/dmop.pandoc +7 -3
index 8e9f95af47..336be64397 100644
@@ -4,9 +4,13 @@ DMOP
 Introduction
 ------------
 
-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).
+The DMOP hypercall has a new ABI design to solve problems in the Xen
+ecosystem.  First, the ABI is fully stable, to reduce the coupling between
+device models and the version of Xen.
+
+Secondly, for device models in userspace, the ABI is designed specifically to
+allow a kernel to audit the memory ranges used, without having to know the
+internal structure of sub-ops.
 
 The problem occurs when you a device model issues an hypercall that
 includes references to user memory other than the operation structure
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
#1 lore raw

Andrew Cooper writes ("[PATCH for-4.15 v2] xen/dmop: Strip __XEN_TOOLS__ header guard from public API"):

Quoted 25 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);
       ^

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. Fix the dmop design doc to discuss both reasons behind the the ABI design.

---
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]>

Quoted 5 lines

v2:
* Patch dmop.pandoc as well.

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

I am going to stop giving acks for this kind of thing fairly shorty.

Ian.

#2 lore raw
Quoted 26 lines · Ian Jackson

Andrew Cooper writes ("[PATCH for-4.15 v2] xen/dmop: Strip __XEN_TOOLS__ header guard from public API"):

Quoted 25 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);
       ^

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. Fix the dmop design doc to discuss both reasons behind the the ABI design.

---
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]>

Quoted 8 lines
Quoted 5 lines

v2:
* Patch dmop.pandoc as well.

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

I am going to stop giving acks for this kind of thing fairly shorty.

Thanks, but you already release acked it.  This is the requested update including the documentation change.

~Andrew

#3 lore raw

Andrew Cooper writes ("Re: [PATCH for-4.15 v2] xen/dmop: Strip __XEN_TOOLS__ header guard from public API"):

Quoted 2 lines

Thanks, but you already release acked it.  This is the requested update including the documentation change.

Oh yes so I did.

Ian.

#4 lore raw
In reply to Andrew Cooper
Quoted 6 lines · Andrew Cooper
docs/designs/dmop.pandoc +0 -0
@@ -4,9 +4,13 @@ DMOP
 Introduction
 ------------
 

docs/designs/dmop.pandoc DMOP · line 13

Quoted 10 lines
docs/designs/dmop.pandoc +7 -3
-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).
+The DMOP hypercall has a new ABI design to solve problems in the Xen
+ecosystem.  First, the ABI is fully stable, to reduce the coupling between
+device models and the version of Xen.
+
+Secondly, for device models in userspace, the ABI is designed specifically to
+allow a kernel to audit the memory ranges used, without having to know the
+internal structure of sub-ops.

I appreciate the editing, but the cited points still don't justify ...

Quoted 13 lines
xen/include/public/hvm/dm_op.h +0 -3
@@ -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

xen/include/public/hvm/dm_op.h struct xen_dm_op { · line 493

Quoted 8 lines
xen/include/public/hvm/dm_op.h +0 -2
@@ -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;

... this removal: What the kernel needs for its auditing (your 2nd point) is already outside of this guarded region, as you can see from the context above. You said there was a design goal of allowing use of this interface by (and not only through) the kernel, e.g. by a kernel module (which I don't think you mean to be covered by "device models"). If that was indeed a goal (Paul - can you confirm this?), this would now want listing as a 3rd item. Without such a statement I'd call it a bug to not have the guards there, and hence might either feel tempted myself to add them back at some point, or would ack a patch doing so.

Jan

#5 lore raw
Quoted 35 lines · Jan Beulich
Quoted 6 lines · Andrew Cooper
docs/designs/dmop.pandoc +0 -0
@@ -4,9 +4,13 @@ DMOP
 Introduction
 ------------
 

docs/designs/dmop.pandoc DMOP · line 13

Quoted 10 lines
docs/designs/dmop.pandoc +7 -3
-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).
+The DMOP hypercall has a new ABI design to solve problems in the Xen
+ecosystem.  First, the ABI is fully stable, to reduce the coupling between
+device models and the version of Xen.
+
+Secondly, for device models in userspace, the ABI is designed specifically to
+allow a kernel to audit the memory ranges used, without having to know the
+internal structure of sub-ops.

I appreciate the editing, but the cited points still don't justify ...

Quoted 16 lines
xen/include/public/hvm/dm_op.h +0 -3
@@ -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;
 };
 
Quoted 15 lines

xen/include/public/hvm/dm_op.h struct xen_dm_op { · line 493

Quoted 5 lines
xen/include/public/hvm/dm_op.h +0 -2
-#endif /* __XEN__ || __XEN_TOOLS__ */
-
 struct xen_dm_op_buf {
     XEN_GUEST_HANDLE(void) h;
     xen_ulong_t size;

... this removal: What the kernel needs for its auditing (your 2nd point) is already outside of this guarded region, as you can see from the context above. You said there was a design goal of allowing use of this interface by (and not only through) the kernel, e.g. by a kernel module (which I don't think you mean to be covered by "device models"). If that was indeed a goal (Paul - can you confirm this?), this would now want listing as a 3rd item. Without such a statement I'd call it a bug to not have the guards there, and hence might either feel tempted myself to add them back at some point, or would ack a patch doing so.

Xen has absolutely no business dictating stuff like this.  It is an internal and opaque property of the domain if the hypercalls happen to originate from logic in user mode or kernel mode.  Stubdomains would fall into the same "kernel" category as xengt in the dom0 i915 driver.

However, the actual bug I'm trying to fix with this is the need for userspace, which doesn't link against libxc, to do

#define __XEN_TOOLS__
#include <xendevicemodel.h>

to be able to use the libxendevicemodel stable library.

The __XEN_TOOLS__ guard is buggy even ignoring the kernel device model aspect.

~Andrew

#6 lore raw
Quoted 52 lines · Andrew Cooper
Quoted 35 lines · Jan Beulich
Quoted 6 lines · Andrew Cooper
docs/designs/dmop.pandoc +0 -0
@@ -4,9 +4,13 @@ DMOP
 Introduction
 ------------
 

docs/designs/dmop.pandoc DMOP · line 13

Quoted 10 lines
docs/designs/dmop.pandoc +7 -3
-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).
+The DMOP hypercall has a new ABI design to solve problems in the Xen
+ecosystem.  First, the ABI is fully stable, to reduce the coupling between
+device models and the version of Xen.
+
+Secondly, for device models in userspace, the ABI is designed specifically to
+allow a kernel to audit the memory ranges used, without having to know the
+internal structure of sub-ops.

I appreciate the editing, but the cited points still don't justify ...

Quoted 16 lines
xen/include/public/hvm/dm_op.h +0 -3
@@ -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;
 };
 
Quoted 15 lines

xen/include/public/hvm/dm_op.h struct xen_dm_op { · line 493

Quoted 5 lines
xen/include/public/hvm/dm_op.h +0 -2
-#endif /* __XEN__ || __XEN_TOOLS__ */
-
 struct xen_dm_op_buf {
     XEN_GUEST_HANDLE(void) h;
     xen_ulong_t size;

... this removal: What the kernel needs for its auditing (your 2nd point) is already outside of this guarded region, as you can see from the context above. You said there was a design goal of allowing use of this interface by (and not only through) the kernel, e.g. by a kernel module (which I don't think you mean to be covered by "device models"). If that was indeed a goal (Paul - can you confirm this?), this would now want listing as a 3rd item. Without such a statement I'd call it a bug to not have the guards there, and hence might either feel tempted myself to add them back at some point, or would ack a patch doing so.

Quoted 4 lines

Xen has absolutely no business dictating stuff like this.  It is an internal and opaque property of the domain if the hypercalls happen to originate from logic in user mode or kernel mode.  Stubdomains would fall into the same "kernel" category as xengt in the dom0 i915 driver.

There's imo a good reason to prevent kernel to use e.g. sysctl and domctl. Those are unstable interfaces, yes, but still.

Quoted 10 lines

However, the actual bug I'm trying to fix with this is the need for userspace, which doesn't link against libxc, to do

#define __XEN_TOOLS__
#include <xendevicemodel.h>

to be able to use the libxendevicemodel stable library.

The __XEN_TOOLS__ guard is buggy even ignoring the kernel device model aspect.

Aiui to address this all that would be needed would be to move the one typedef out of the guarded region.

Jan

#7 lore raw
In reply to Andrew Cooper
Quoted 52 lines · Andrew Cooper
Quoted 35 lines · Jan Beulich
Quoted 6 lines · Andrew Cooper
docs/designs/dmop.pandoc +0 -0
@@ -4,9 +4,13 @@ DMOP
 Introduction
 ------------
 

docs/designs/dmop.pandoc DMOP · line 13

Quoted 10 lines
docs/designs/dmop.pandoc +7 -3
-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).
+The DMOP hypercall has a new ABI design to solve problems in the Xen
+ecosystem.  First, the ABI is fully stable, to reduce the coupling between
+device models and the version of Xen.
+
+Secondly, for device models in userspace, the ABI is designed specifically to
+allow a kernel to audit the memory ranges used, without having to know the
+internal structure of sub-ops.

I appreciate the editing, but the cited points still don't justify ...

Quoted 16 lines
xen/include/public/hvm/dm_op.h +0 -3
@@ -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;
 };
 
Quoted 15 lines

xen/include/public/hvm/dm_op.h struct xen_dm_op { · line 493

Quoted 5 lines
xen/include/public/hvm/dm_op.h +0 -2
-#endif /* __XEN__ || __XEN_TOOLS__ */
-
 struct xen_dm_op_buf {
     XEN_GUEST_HANDLE(void) h;
     xen_ulong_t size;

... this removal: What the kernel needs for its auditing (your 2nd point) is already outside of this guarded region, as you can see from the context above. You said there was a design goal of allowing use of this interface by (and not only through) the kernel, e.g. by a kernel module (which I don't think you mean to be covered by "device models"). If that was indeed a goal (Paul - can you confirm this?), this would now want listing as a 3rd item. Without such a statement I'd call it a bug to not have the guards there, and hence might either feel tempted myself to add them back at some point, or would ack a patch doing so.

Quoted 1 line

Xen has absolutely no business dictating stuff like this.

Actually there's no "dictating" here anyway: People are free to clone the headers and omit the guards anyway. Outside of our own build system they really mainly serve a documentation purpose.

Quoted 8 lines

  It is an
internal and opaque property of the domain if the hypercalls happen to originate from logic in user mode or kernel mode.  Stubdomains would fall into the same "kernel" category as xengt in the dom0 i915 driver.

However, the actual bug I'm trying to fix with this is the need for userspace, which doesn't link against libxc, to do

Quoted 7 lines

#define __XEN_TOOLS__
#include <xendevicemodel.h>

to be able to use the libxendevicemodel stable library.

The __XEN_TOOLS__ guard is buggy even ignoring the kernel device model aspect.

Depends on what __XEN_TOOLS__ really means - to guard things accessible to any part of the tool stack, or to guard unstable interfaces only.

Jan

#8 lore raw
Quoted 52 lines · Jan Beulich
Quoted 51 lines · Andrew Cooper
Quoted 50 lines · Jan Beulich
Quoted 6 lines · Andrew Cooper
docs/designs/dmop.pandoc +0 -0
@@ -4,9 +4,13 @@ DMOP
 Introduction
 ------------
 

docs/designs/dmop.pandoc DMOP · line 13

Quoted 10 lines
docs/designs/dmop.pandoc +7 -3
-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).
+The DMOP hypercall has a new ABI design to solve problems in the Xen
+ecosystem.  First, the ABI is fully stable, to reduce the coupling between
+device models and the version of Xen.
+
+Secondly, for device models in userspace, the ABI is designed specifically to
+allow a kernel to audit the memory ranges used, without having to know the
+internal structure of sub-ops.

I appreciate the editing, but the cited points still don't justify ...

Quoted 13 lines
xen/include/public/hvm/dm_op.h +0 -3
@@ -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

xen/include/public/hvm/dm_op.h struct xen_dm_op { · line 493

Quoted 8 lines
xen/include/public/hvm/dm_op.h +0 -2
@@ -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;

... this removal: What the kernel needs for its auditing (your 2nd point) is already outside of this guarded region, as you can see from the context above. You said there was a design goal of allowing use of this interface by (and not only through) the kernel, e.g. by a kernel module (which I don't think you mean to be covered by "device models"). If that was indeed a goal (Paul - can you confirm this?), this would now want listing as a 3rd item. Without such a statement I'd call it a bug to not have the guards there, and hence might either feel tempted myself to add them back at some point, or would ack a patch doing so.

Quoted 3 lines
Quoted 1 line

Xen has absolutely no business dictating stuff like this.

Actually there's no "dictating" here anyway: People are free to clone the headers and omit the guards anyway.

That is somewhere between busywork and just plain rude to 3rd parties. "here are some headers but you need to unbreak them locally before use".

Quoted 2 lines

Outside of our own build
system they really mainly serve a documentation purpose.

Header guards are not documentation - they are active attempt to segregate hypercalls by "who we think is supposed to use them".

MiniOS, which uses this header within our build system, is not a part of the toolstack, and should not need to define __XEN_TOOLS__ to be able to use stable-ABI hypercalls.

Equally, the fact that libxendevicemodel's private.h needed to define __XEN_TOOLS__ demonstrates the problem - dm_op.h (the structs and defines - not just the types) are necessary to use the ioctl() on /dev/xen/devicemodel in the first place.

Quoted 11 lines
Quoted 11 lines

  It is an
internal and opaque property of the domain if the hypercalls happen to originate from logic in user mode or kernel mode.  Stubdomains would fall into the same "kernel" category as xengt in the dom0 i915 driver.

However, the actual bug I'm trying to fix with this is the need for userspace, which doesn't link against libxc, to do

#define __XEN_TOOLS__
#include <xendevicemodel.h>

Quoted 6 lines
Quoted 4 lines

to be able to use the libxendevicemodel stable library.

The __XEN_TOOLS__ guard is buggy even ignoring the kernel device model aspect.

Depends on what __XEN_TOOLS__ really means - to guard things accessible to any part of the tool stack, or to guard unstable interfaces only.

As far as I'm concerned, __XEN_TOOLS__ should always have been spelled __XEN_UNSTABLE_ABI__.

For better or worse, the fact that we currently do have unstable interfaces, which aren't in an obvious namespace such as xen/public/unstable/, means that there is some value in some form of protection to prevent users from inadvertently using an interface which will explode on them with a mismatched hypervisor.

From numerous complains and problems from donwstreams, we are deliberately taking steps to stabilise the interfaces, specifically to decouple the software in domains from the version of the hypervisor.

dmop was the first serious crack at this, and all these patches from me are literally trying to get https://github.com/xapi-project/varstored
(which is a trivial IO port device model for UEFI secure variables) onto fully stable hypercalls, so it doesn't need rebuilding simply because Xen changed.

Relatedly, xenstored.  At the moment, xenstored (which requires one bit of information per domain via its final unstable hypercall) breaks whenever the domctl and sysctl interface versions change, despite the fact that the ABI hasn't actually changed in years and years AFAICT.

xenstored is arguably classified as "toolstack", while varstored (or its stubdomain equivalent) is not.  Neither should be forced to jump through hoops to see stable API/ABIs, even after they've included the appropriate headers.

~Andrew

Acked-by
#9 lore raw
Quoted 57 lines · Andrew Cooper
Quoted 52 lines · Jan Beulich
Quoted 51 lines · Andrew Cooper
Quoted 50 lines · Jan Beulich
Quoted 6 lines · Andrew Cooper
docs/designs/dmop.pandoc +0 -0
@@ -4,9 +4,13 @@ DMOP
 Introduction
 ------------
 

docs/designs/dmop.pandoc DMOP · line 13

Quoted 10 lines
docs/designs/dmop.pandoc +7 -3
-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).
+The DMOP hypercall has a new ABI design to solve problems in the Xen
+ecosystem.  First, the ABI is fully stable, to reduce the coupling between
+device models and the version of Xen.
+
+Secondly, for device models in userspace, the ABI is designed specifically to
+allow a kernel to audit the memory ranges used, without having to know the
+internal structure of sub-ops.

I appreciate the editing, but the cited points still don't justify ...

Quoted 13 lines
xen/include/public/hvm/dm_op.h +0 -3
@@ -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

xen/include/public/hvm/dm_op.h struct xen_dm_op { · line 493

Quoted 8 lines
xen/include/public/hvm/dm_op.h +0 -2
@@ -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;

... this removal: What the kernel needs for its auditing (your 2nd point) is already outside of this guarded region, as you can see from the context above. You said there was a design goal of allowing use of this interface by (and not only through) the kernel, e.g. by a kernel module (which I don't think you mean to be covered by "device models"). If that was indeed a goal (Paul - can you confirm this?), this would now want listing as a 3rd item. Without such a statement I'd call it a bug to not have the guards there, and hence might either feel tempted myself to add them back at some point, or would ack a patch doing so.

Quoted 3 lines
Quoted 1 line

Xen has absolutely no business dictating stuff like this.

Actually there's no "dictating" here anyway: People are free to clone the headers and omit the guards anyway.

Quoted 7 lines

That is somewhere between busywork and just plain rude to 3rd parties. "here are some headers but you need to unbreak them locally before use".

Quoted 2 lines

Outside of our own build
system they really mainly serve a documentation purpose.

Header guards are not documentation

And I didn't say so - I said they server a documentation purpose.

Quoted 6 lines

- they are active attempt to
segregate hypercalls by "who we think is supposed to use them".

MiniOS, which uses this header within our build system, is not a part of the toolstack, and should not need to define __XEN_TOOLS__ to be able to use stable-ABI hypercalls.

I've not been able to spot a definition of __XEN_TOOLS__ in the mini-os sources. Are you perhaps referring to tool stack libraries getting built also for it?

Quoted 4 lines

Equally, the fact that libxendevicemodel's private.h needed to define __XEN_TOOLS__ demonstrates the problem - dm_op.h (the structs and defines - not just the types) are necessary to use the ioctl() on /dev/xen/devicemodel in the first place.

But this library _is_ part of the tool stack. Looks like it really boils down to ...

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

  It is an
internal and opaque property of the domain if the hypercalls happen to originate from logic in user mode or kernel mode.  Stubdomains would fall into the same "kernel" category as xengt in the dom0 i915 driver.

However, the actual bug I'm trying to fix with this is the need for userspace, which doesn't link against libxc, to do

#define __XEN_TOOLS__
#include <xendevicemodel.h>

to be able to use the libxendevicemodel stable library.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

The __XEN_TOOLS__ guard is buggy even ignoring the kernel device model aspect.

Depends on what __XEN_TOOLS__ really means - to guard things accessible to any part of the tool stack, or to guard unstable interfaces only.

As far as I'm concerned, __XEN_TOOLS__ should always have been spelled __XEN_UNSTABLE_ABI__.

... this. If you added half a sentence to this effect to the description, you may feel free to add

I still would appreciate if you also added the kernel (module) aspect to the doc change.

Jan

#10 lore raw
Quoted 68 lines · Jan Beulich
Quoted 54 lines · Andrew Cooper
Quoted 53 lines · Jan Beulich
Quoted 52 lines · Andrew Cooper
Quoted 35 lines · Jan Beulich
Quoted 6 lines · Andrew Cooper
docs/designs/dmop.pandoc +0 -0
@@ -4,9 +4,13 @@ DMOP
 Introduction
 ------------
 

docs/designs/dmop.pandoc DMOP · line 13

Quoted 10 lines
docs/designs/dmop.pandoc +7 -3
-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).
+The DMOP hypercall has a new ABI design to solve problems in the Xen
+ecosystem.  First, the ABI is fully stable, to reduce the coupling between
+device models and the version of Xen.
+
+Secondly, for device models in userspace, the ABI is designed specifically to
+allow a kernel to audit the memory ranges used, without having to know the
+internal structure of sub-ops.

I appreciate the editing, but the cited points still don't justify ...

Quoted 16 lines
xen/include/public/hvm/dm_op.h +0 -3
@@ -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;
 };
 
Quoted 15 lines

xen/include/public/hvm/dm_op.h struct xen_dm_op { · line 493

Quoted 5 lines
xen/include/public/hvm/dm_op.h +0 -2
-#endif /* __XEN__ || __XEN_TOOLS__ */
-
 struct xen_dm_op_buf {
     XEN_GUEST_HANDLE(void) h;
     xen_ulong_t size;

... this removal: What the kernel needs for its auditing (your 2nd point) is already outside of this guarded region, as you can see from the context above. You said there was a design goal of allowing use of this interface by (and not only through) the kernel, e.g. by a kernel module (which I don't think you mean to be covered by "device models"). If that was indeed a goal (Paul - can you confirm this?), this would now want listing as a 3rd item. Without such a statement I'd call it a bug to not have the guards there, and hence might either feel tempted myself to add them back at some point, or would ack a patch doing so.

Xen has absolutely no business dictating stuff like this.

Quoted 8 lines
Quoted 2 lines

Actually there's no "dictating" here anyway: People are free to clone the headers and omit the guards anyway.

That is somewhere between busywork and just plain rude to 3rd parties. "here are some headers but you need to unbreak them locally before use".

Quoted 2 lines

Outside of our own build
system they really mainly serve a documentation purpose.

Header guards are not documentation

And I didn't say so - I said they server a documentation purpose.

Quoted 3 lines

- they are active attempt to
segregate hypercalls by "who we think is supposed to use them".

Quoted 6 lines
Quoted 3 lines

MiniOS, which uses this header within our build system, is not a part of the toolstack, and should not need to define __XEN_TOOLS__ to be able to use stable-ABI hypercalls.

I've not been able to spot a definition of __XEN_TOOLS__ in the mini-os sources. Are you perhaps referring to tool stack libraries getting built also for it?

Things in stubdom/ which include xenctrl.h get __XEN_TOOLS__ set behind the scenes, which is the only way that including libxendevicemodel.h worked before last week.

Quoted 25 lines
Quoted 5 lines

Equally, the fact that libxendevicemodel's private.h needed to define __XEN_TOOLS__ demonstrates the problem - dm_op.h (the structs and defines - not just the types) are necessary to use the ioctl() on /dev/xen/devicemodel in the first place.

But this library _is_ part of the tool stack. Looks like it really boils down to ...

Quoted 17 lines
Quoted 17 lines
Quoted 8 lines

  It is an
internal and opaque property of the domain if the hypercalls happen to originate from logic in user mode or kernel mode.  Stubdomains would fall into the same "kernel" category as xengt in the dom0 i915 driver.

However, the actual bug I'm trying to fix with this is the need for userspace, which doesn't link against libxc, to do

Quoted 7 lines

#define __XEN_TOOLS__
#include <xendevicemodel.h>

to be able to use the libxendevicemodel stable library.

The __XEN_TOOLS__ guard is buggy even ignoring the kernel device model aspect.

Depends on what __XEN_TOOLS__ really means - to guard things accessible to any part of the tool stack, or to guard unstable interfaces only.

Quoted 8 lines
Quoted 2 lines

As far as I'm concerned, __XEN_TOOLS__ should always have been spelled __XEN_UNSTABLE_ABI__.

... this. If you added half a sentence to this effect to the description, you may feel free to add

I still would appreciate if you also added the kernel (module) aspect to the doc change.

Thanks, will do, and I'll post a v3 just to check that everyone is happy.

However, having laid things out in this way today, it occurs to me that we should consider further cleanup as well.

I do agree that code wanting to use the libxendevicemodel.h API almost certainly don't want/need the dmop ABI.  (i.e. an individual consumer will want one, or the other, but almost certainly not both together).

Should libxendevicemodel.h really be including dm_op.h?  AFAICT, it is only the ioserverid_t typedef which is API shared between the two contexts, and we can trivially typedef that locally.

This is something which we should either do now, or not at all.

~Andrew

#11 lore raw
Quoted 8 lines · Andrew Cooper

However, having laid things out in this way today, it occurs to me that we should consider further cleanup as well.

I do agree that code wanting to use the libxendevicemodel.h API almost certainly don't want/need the dmop ABI.  (i.e. an individual consumer will want one, or the other, but almost certainly not both together).

Should libxendevicemodel.h really be including dm_op.h?

I was indeed wondering.

Quoted 3 lines

  AFAICT, it is
only the ioserverid_t typedef which is API shared between the two contexts, and we can trivially typedef that locally.

Hmm, a local typedef isn't nice - there should be one central point. Granted there's no risk for this to change in anywhere halfway foreseeable future, but still. Also neither C89 nor C99 allow a typedef to be repeated - in those versions we'd then rely on an extension.

Quoted 1 line

This is something which we should either do now, or not at all.

Well, yes, would be better.

Jan

#12 lore raw
Quoted 11 lines · Jan Beulich
Quoted 8 lines · Andrew Cooper

However, having laid things out in this way today, it occurs to me that we should consider further cleanup as well.

I do agree that code wanting to use the libxendevicemodel.h API almost certainly don't want/need the dmop ABI.  (i.e. an individual consumer will want one, or the other, but almost certainly not both together).

Should libxendevicemodel.h really be including dm_op.h?

I was indeed wondering.

Quoted 8 lines
Quoted 3 lines

  AFAICT, it is
only the ioserverid_t typedef which is API shared between the two contexts, and we can trivially typedef that locally.

Hmm, a local typedef isn't nice - there should be one central point. Granted there's no risk for this to change in anywhere halfway foreseeable future, but still. Also neither C89 nor C99 allow a typedef to be repeated - in those versions we'd then rely on an extension.

I wonder if we're depending on that extension elsewhere.  As far as the stable libraries go, we are dependent on a Linux or BSD environment currently.

Alternatively we can drop the typedef and use uint16_t instead without breaking things in practice.  (As long as we make the change in 4.15 and we lose the wiggle room afforded us by the entire interface being behind __XEN_TOOLS__ previously).

Thoughts?  I can't think of any ifdefary which would help, and swapping to uint16_t would reduce the use of an improperly namespaced identifier.

~Andrew

#13 lore raw
Quoted 21 lines · Andrew Cooper
Quoted 11 lines · Jan Beulich
Quoted 8 lines · Andrew Cooper

However, having laid things out in this way today, it occurs to me that we should consider further cleanup as well.

I do agree that code wanting to use the libxendevicemodel.h API almost certainly don't want/need the dmop ABI.  (i.e. an individual consumer will want one, or the other, but almost certainly not both together).

Should libxendevicemodel.h really be including dm_op.h?

I was indeed wondering.

Quoted 8 lines
Quoted 3 lines

  AFAICT, it is
only the ioserverid_t typedef which is API shared between the two contexts, and we can trivially typedef that locally.

Hmm, a local typedef isn't nice - there should be one central point. Granted there's no risk for this to change in anywhere halfway foreseeable future, but still. Also neither C89 nor C99 allow a typedef to be repeated - in those versions we'd then rely on an extension.

Quoted 3 lines

I wonder if we're depending on that extension elsewhere.  As far as the stable libraries go, we are dependent on a Linux or BSD environment currently.

Right, but we'd like the headers to be consumable by any environment.

Quoted 7 lines

Alternatively we can drop the typedef and use uint16_t instead without breaking things in practice.  (As long as we make the change in 4.15 and we lose the wiggle room afforded us by the entire interface being behind __XEN_TOOLS__ previously).

Thoughts?  I can't think of any ifdefary which would help, and swapping to uint16_t would reduce the use of an improperly namespaced identifier.

I'm not outright against, but this might inspire people to use uint16_t elsewhere too, when they should use the typedef. How about a transient #define (suitably commented)?

Jan

#14 lore raw
Quoted 31 lines · Jan Beulich
Quoted 15 lines · Andrew Cooper
Quoted 14 lines · Jan Beulich
Quoted 8 lines · Andrew Cooper

However, having laid things out in this way today, it occurs to me that we should consider further cleanup as well.

I do agree that code wanting to use the libxendevicemodel.h API almost certainly don't want/need the dmop ABI.  (i.e. an individual consumer will want one, or the other, but almost certainly not both together).

Should libxendevicemodel.h really be including dm_op.h?

I was indeed wondering.

Quoted 3 lines

  AFAICT, it is
only the ioserverid_t typedef which is API shared between the two contexts, and we can trivially typedef that locally.

Quoted 8 lines
Quoted 5 lines

Hmm, a local typedef isn't nice - there should be one central point. Granted there's no risk for this to change in anywhere halfway foreseeable future, but still. Also neither C89 nor C99 allow a typedef to be repeated - in those versions we'd then rely on an extension.

I wonder if we're depending on that extension elsewhere.  As far as the stable libraries go, we are dependent on a Linux or BSD environment currently.

Right, but we'd like the headers to be consumable by any environment.

Quoted 5 lines

Alternatively we can drop the typedef and use uint16_t instead without breaking things in practice.  (As long as we make the change in 4.15 and we lose the wiggle room afforded us by the entire interface being behind __XEN_TOOLS__ previously).

Quoted 5 lines
Quoted 2 lines

Thoughts?  I can't think of any ifdefary which would help, and swapping to uint16_t would reduce the use of an improperly namespaced identifier.

I'm not outright against, but this might inspire people to use uint16_t elsewhere too, when they should use the typedef. How about a transient #define (suitably commented)?

Having actually experimented, it is more complicated.

/local/xen.git/tools/libs/devicemodel/../../../tools/include/xendevicemodel.h:283:45:
error: array type has incomplete element type ‘struct xen_dm_op_modified_memory_extent’
     struct xen_dm_op_modified_memory_extent extents[], uint32_t nr);

so the dm_op include is necessary to use the libxendevicemodel API.

Also hvmmem_type_t and evtchn_port_t get used.

~Andrew

#15 lore raw
In reply to Andrew Cooper
Quoted 10 lines · Andrew Cooper
Quoted 9 lines · Jan Beulich
Quoted 8 lines · Andrew Cooper

However, having laid things out in this way today, it occurs to me that we should consider further cleanup as well.

I do agree that code wanting to use the libxendevicemodel.h API almost certainly don't want/need the dmop ABI.  (i.e. an individual consumer will want one, or the other, but almost certainly not both together).

Should libxendevicemodel.h really be including dm_op.h?

FTR, this is xendevicemodel.h. Just saying because it took me a bit to find the header. I'm dense today.

Quoted 15 lines
Quoted 10 lines

I was indeed wondering.

Quoted 3 lines

  AFAICT, it is
only the ioserverid_t typedef which is API shared between the two contexts, and we can trivially typedef that locally.

Hmm, a local typedef isn't nice - there should be one central point. Granted there's no risk for this to change in anywhere halfway foreseeable future, but still. Also neither C89 nor C99 allow a typedef to be repeated - in those versions we'd then rely on an extension.

I wonder if we're depending on that extension elsewhere.  As far as the stable libraries go, we are dependent on a Linux or BSD environment currently.

Quoted 7 lines

Alternatively we can drop the typedef and use uint16_t instead without breaking things in practice.  (As long as we make the change in 4.15 and we lose the wiggle room afforded us by the entire interface being behind __XEN_TOOLS__ previously).

Thoughts?  I can't think of any ifdefary which would help, and swapping to uint16_t would reduce the use of an improperly namespaced identifier.

I don't see much problem in switching to uint16_t, it's likely what should have been used from the start in order to avoid bits of dm_op.h leaking into xendevicemodel.h. Or alternatively a new type that maps to uint16_t if we think that would be more descriptive from a header
PoV: server_t or some such.

At the end of day it should be an opaque handler from the caller PoV, or is it expected that the ioserverid_t obtained from xendevicemodel will be used as a parameter to other libraries?

If you end up changing the type to uint16_t it might help to expand the parameter name to server_id or some such, as an id parameter with type uint16_t is kind of ambiguous. We already have some comment blocks to describe the purpose of the parameters, so I don't think it's a big deal if you also leave then as 'id'.

Thanks, Roger.

#16 lore raw
In reply to Andrew Cooper
Quoted 4 lines · Andrew Cooper
Quoted 2 lines · Jan Beulich

Depends on what __XEN_TOOLS__ really means - to guard things accessible to any part of the tool stack, or to guard unstable interfaces only.

Quoted 8 lines

As far as I'm concerned, __XEN_TOOLS__ should always have been spelled __XEN_UNSTABLE_ABI__.

For better or worse, the fact that we currently do have unstable interfaces, which aren't in an obvious namespace such as xen/public/unstable/, means that there is some value in some form of protection to prevent users from inadvertently using an interface which will explode on them with a mismatched hypervisor.

I think using __XEN_UNSTABLE_ABI__ would be way clearer than __XEN_TOOLS__, or even placing those in a separate directory as you mention.

Thanks, Roger.

#17 lore raw
Quoted 7 lines · Roger Pau Monné
Quoted 6 lines · Andrew Cooper
Quoted 2 lines · Jan Beulich

Depends on what __XEN_TOOLS__ really means - to guard things accessible to any part of the tool stack, or to guard unstable interfaces only.

As far as I'm concerned, __XEN_TOOLS__ should always have been spelled __XEN_UNSTABLE_ABI__.

Quoted 8 lines
Quoted 5 lines

For better or worse, the fact that we currently do have unstable interfaces, which aren't in an obvious namespace such as xen/public/unstable/, means that there is some value in some form of protection to prevent users from inadvertently using an interface which will explode on them with a mismatched hypervisor.

I think using __XEN_UNSTABLE_ABI__ would be way clearer than __XEN_TOOLS__, or even placing those in a separate directory as you mention.

I plan to submit a rename for 4.16.

I don't expect I'll have much luck arguing for a release ack at this point, and isn't totally risk-free.

Re-laying-out the headers is far more invasive, and was also a trick I was planning to pull when we've got a rough plan for the other ABI improvements agreed.

~Andrew

#18 lore raw

Andrew Cooper writes ("Re: [PATCH for-4.15 v2] xen/dmop: Strip __XEN_TOOLS__ header guard from public API"):

Quoted 4 lines · Roger Pau Monné
Quoted 3 lines

I think using __XEN_UNSTABLE_ABI__ would be way clearer than __XEN_TOOLS__, or even placing those in a separate directory as you mention.

+1

Quoted 1 line

I plan to submit a rename for 4.16.

+1

Quoted 2 lines

I don't expect I'll have much luck arguing for a release ack at this point, and isn't totally risk-free.

Indeed, I think the value for 4.15 would be very limited and I wouldn't want the churn.

Thanks,
Ian.