Skip to contentSkip to conversation

tools: add support for domain specific Xenstore features

PATCH In review Juergen Gross 2 participants 4 messages Jul 31, 2025

lore
Share & tools
lore
#0 lore raw

v3 cover tools: add support for domain specific Xenstore features

Add support for limiting the optional Xenstore features via domain configuration. This will be needed when adding features like limiting the scope of Xenstore watch events.

This patch series is handling only the xl/libxl side, libxenstore and C Xenstore (xenstored and xenstore-stubdom). Oxenstored is not covered.

Changes in V2:
- added Jason's Reviewed-by: tags
- a small fix of patch 4

Changes in V3:
- patches 1-5 have gone in already
- 2 fixes in patch

Juergen Gross (2):
tools/xl: add available Xenstore features to xl info output
tools: allow to limit xenstore features via guest config

 docs/man/xl.cfg.5.pod.in             | 36 ++++++++++++++++++++++++++++
 tools/golang/xenlight/helpers.gen.go |  2 ++
 tools/golang/xenlight/types.gen.go   |  1 +
 tools/include/libxl.h                |  6 +++++
 tools/libs/light/libxl_dom.c         | 17 ++++++++++++-
 tools/libs/light/libxl_types.idl     |  1 +
 tools/xl/Makefile                    |  3 ++-
 tools/xl/xl_info.c                   | 22 +++++++++++++++++
 tools/xl/xl_parse.c                  |  3 +++
 9 files changed, 89 insertions(+), 2 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v3 1/2 tools/xl: add available Xenstore features to xl info output

Add the Xenstore feature value to the output of "xl info" in order to prepare for a future capability to limit Xenstore features visible by a guest.

---
 tools/xl/Makefile  |  3 ++-
 tools/xl/xl_info.c | 22 ++++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)
tools/xl/Makefile +2 -1
index d742e96a5b..ad577cdd70 100644
@@ -13,6 +13,7 @@ LDFLAGS += $(PTHREAD_LDFLAGS)
 
 CFLAGS_XL += $(CFLAGS_libxenlight)
 CFLAGS_XL += $(CFLAGS_libxenutil)
+CFLAGS_XL += $(CFLAGS_libxenstore)
 CFLAGS_XL += -Wshadow
 
 XL_OBJS-$(CONFIG_X86) = xl_psr.o
@@ -32,7 +33,7 @@ $(XL_OBJS): CFLAGS += -include $(XEN_ROOT)/tools/config.h # libxl_json.h needs i
 all: xl
 
 xl: $(XL_OBJS)
-	$(CC) $(LDFLAGS) -o $@ $(XL_OBJS) $(LDLIBS_libxenutil) $(LDLIBS_libxenlight) $(LDLIBS_libxentoollog) -lyajl $(APPEND_LDFLAGS)
+	$(CC) $(LDFLAGS) -o $@ $(XL_OBJS) $(LDLIBS_libxenutil) $(LDLIBS_libxenlight) $(LDLIBS_libxentoollog) $(LDLIBS_libxenstore) -lyajl $(APPEND_LDFLAGS)
 
 .PHONY: install
 install: all
tools/xl/xl_info.c +22 -0
index 72e87eac46..eb019e3ee9 100644
@@ -28,6 +28,7 @@
 #include <libxl_utils.h>
 #include <libxlutil.h>
 #include <xen-tools/arm-arch-capabilities.h>
+#include <xenstore.h>
 
 #include "xl.h"
 #include "xl_utils.h"
@@ -333,6 +334,25 @@ static void output_topologyinfo(void)
     return;
 }
 
+static void output_xenstore_info(void)
+{
+    struct xs_handle *xsh;
+    unsigned int features = 0;
+
+    xsh = xs_open(0);
+    if (!xsh) {
+        fprintf(stderr, "xs_open failed.\n");
+        return;
+    }
+
+    /* Ignore error, default to "0" for features. */
+    xs_get_features_supported(xsh, &features);
+
+    maybe_printf("xenstore_features      : 0x%08x\n", features);
+
+    xs_close(xsh);
+}
+
 static void print_info(int numa)
 {
     output_nodeinfo();
@@ -345,6 +365,8 @@ static void print_info(int numa)
     }
     output_xeninfo();
 
+    output_xenstore_info();
+
     maybe_printf("xend_config_format     : 4\n");
 
     return;
Signature · 1 line
2.43.0
#2 lore raw

PATCH v3 2/2 tools: allow to limit xenstore features via guest config

In reply to Juergen Gross

Add a guest config parameter "xenstore_feature_mask" allowing to limit the Xenstore features the guest can see and use. This can be needed in order to allow migrating a guest to a host running a Xenstore version providing less features than the source host.

---
V2:
- fix typo (Jason Andryuk)
V3:
- use LOGED for error logging (Anthony Perard)
- don't leak vm_path in case of error (Anthony Perard)

---
 docs/man/xl.cfg.5.pod.in             | 36 ++++++++++++++++++++++++++++
 tools/golang/xenlight/helpers.gen.go |  2 ++
 tools/golang/xenlight/types.gen.go   |  1 +
 tools/include/libxl.h                |  6 +++++
 tools/libs/light/libxl_dom.c         | 17 ++++++++++++-
 tools/libs/light/libxl_types.idl     |  1 +
 tools/xl/xl_parse.c                  |  3 +++
 7 files changed, 65 insertions(+), 1 deletion(-)
docs/man/xl.cfg.5.pod.in +36 -0
index 5362fb0e9a..f0c920b39d 100644
@@ -714,6 +714,42 @@ If this option is not specified then it will default to B<false>.
 
 =back
 
+=head3 Xenstore related settings
+
+=over 4
+
+=item B<xenstore_feature_mask=NUMBER>
+
+Specify which Xenstore features are visible for the guest.
+
+This might be needed when a guest should be able to be migrated to a host
+running a Xenstore implementation with less features than the one the guest
+is created on.
+
+The visible features are specified via a binary or of the following
+values:
+
+=over 4
+
+=item B<0x00000001>
+
+Xenstore is capable to reconnect to a guest.
+
+=item B<0x00000002>
+
+Xenstore will present an error value in case it disconnects due to an error
+condition.
+
+=back
+
+The features supported by the running Xenstore instance can be retrieved
+via the B<xl info> command in dom0.
+
+The default value is B<0xffffffff>, meaning that all possible Xenstore
+features are visible by the guest.
+
+=back
+
 =head2 Devices
 
 The following options define the paravirtual, emulated and physical
tools/golang/xenlight/helpers.gen.go +2 -0
index b43aad7d00..667030cbd7 100644
@@ -1175,6 +1175,7 @@ return fmt.Errorf("converting field Vpmu: %v", err)
 if err := x.TrapUnmappedAccesses.fromC(&xc.trap_unmapped_accesses);err != nil {
 return fmt.Errorf("converting field TrapUnmappedAccesses: %v", err)
 }
+x.XenstoreFeatureMask = uint32(xc.xenstore_feature_mask)
 
  return nil}
 
@@ -1710,6 +1711,7 @@ return fmt.Errorf("converting field Vpmu: %v", err)
 if err := x.TrapUnmappedAccesses.toC(&xc.trap_unmapped_accesses); err != nil {
 return fmt.Errorf("converting field TrapUnmappedAccesses: %v", err)
 }
+xc.xenstore_feature_mask = C.uint32_t(x.XenstoreFeatureMask)
 
  return nil
  }
tools/golang/xenlight/types.gen.go +1 -0
index 4777f528b5..e26b3cdfc7 100644
@@ -608,6 +608,7 @@ Altp2MCount uint32
 VmtraceBufKb int
 Vpmu Defbool
 TrapUnmappedAccesses Defbool
+XenstoreFeatureMask uint32
 }
 
 type DomainBuildInfoTypeUnion interface {
tools/include/libxl.h +6 -0
index d6b6e5d2dd..185f74d8a8 100644
@@ -654,6 +654,12 @@
  */
 #define LIBXL_HAVE_DT_OVERLAY_DOMAIN 1
 
+/*
+ * LIBXL_HAVE_XENSTORE_FEATURE_MASK indicates the presence of
+ * xenstore_feature_mask in struct libxl_domain_build_info.
+ */
+#define LIBXL_HAVE_XENSTORE_FEATURE_MASK 1
+
 /*
  * libxl memory management
  *
tools/libs/light/libxl_dom.c +16 -1
index a61085ca3b..05ebc69534 100644
@@ -494,9 +494,24 @@ retry_transaction:
     if (!xs_transaction_end(ctx->xsh, t, 0))
         if (errno == EAGAIN)
             goto retry_transaction;
+
+    if (info->xenstore_feature_mask != ~0U) {
+        unsigned int features;
+
+        if (xs_get_features_supported(ctx->xsh, &features) &&
+            !xs_set_features_domain(ctx->xsh, domid,
+                                    features & info->xenstore_feature_mask)) {
+            LOGED(ERROR, domid, "Failed to set Xenstore features");
+            rc = ERROR_FAIL;
+            goto out;
+        }
+    }
+
     xs_introduce_domain(ctx->xsh, domid, state->store_mfn, state->store_port);
+
+ out:
     free(vm_path);
-    return 0;
+    return rc;
 }
 
 static int set_vnuma_info(libxl__gc *gc, uint32_t domid,
tools/libs/light/libxl_types.idl +1 -0
index fe251649f3..a6030a2dbd 100644
@@ -739,6 +739,7 @@ libxl_domain_build_info = Struct("domain_build_info",[
 
     ("vpmu", libxl_defbool),
     ("trap_unmapped_accesses", libxl_defbool),
+    ("xenstore_feature_mask", uint32, {'init_val': '~0U'}),
 
     ], dir=DIR_IN,
        copy_deprecated_fn="libxl__domain_build_info_copy_deprecated",
tools/xl/xl_parse.c +3 -0
index 28cdbf07c2..90c9386f5b 100644
@@ -1409,6 +1409,9 @@ void parse_config_data(const char *config_source,
     if (!xlu_cfg_get_string (config, "pool", &buf, 0))
         xlu_cfg_replace_string(config, "pool", &c_info->pool_name, 0);
 
+    if (!xlu_cfg_get_long (config, "xenstore_feature_mask", &l, 0))
+        b_info->xenstore_feature_mask = l;
+
     libxl_domain_build_info_init_type(b_info, c_info->type);
 
     if (b_info->type == LIBXL_DOMAIN_TYPE_PVH) {
Signature · 1 line
2.43.0
Reviewed-by on v3 2/2
#3 lore raw

Re: [PATCH v3 2/2] tools: allow to limit xenstore features via guest config

Quoted 8 lines · Juergen Gross

Add a guest config parameter "xenstore_feature_mask" allowing to limit the Xenstore features the guest can see and use. This can be needed in order to allow migrating a guest to a host running a Xenstore version providing less features than the source host.

Quoted 6 lines

---
V2:
- fix typo (Jason Andryuk)
V3:
- use LOGED for error logging (Anthony Perard)
- don't leak vm_path in case of error (Anthony Perard)

Thanks,

Signature · 1 line
Anthony PERARD