Skip to contentSkip to conversation

Add hypervisor sysfs-like support

PATCH Superseded Juergen Gross 3 participants 50 messages Feb 26, 2020 – Mar 25, 2020

v6 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v6 cover Add hypervisor sysfs-like support

On the 2019 Xen developer summit there was agreement that the Xen hypervisor should gain support for a hierarchical name-value store similar to the Linux kernel's sysfs.

This is a first implementation of that idea adding the basic functionality to hypervisor and tools side. The interface to any user program making use of that "xen-hypfs" is a new library "libxenhypfs" with a stable interface.

The series adds read-only nodes with buildinfo data and writable nodes with runtime parameters. xl is switched to use the new file system for modifying the runtime parameters and the old sysctl interface for that purpose is dropped.

Changes in V6:
- added new patches 1, 10, 11, 12
- addressed review comments
- modified interface for creating nodes for runtime parameters

Changes in V5:
- switched to xsm for privilege check

Changes in V4:
- former patch 2 removed as already committed
- addressed review comments

Changes in V3:
- major rework, especially by supporting binary contents of entries
- added several new patches (1, 2, 7)
- full support of all runtime parameters
- support of writing entries (especially runtime parameters)

Changes in V2:
- all comments to V1 addressed
- added man-page for xenhypfs tool
- added runtime parameter read access for string parameters

Changes in V1:
- renamed xenfs ->xenhypfs
- added writable entries support at the interface level and in the xenhypfs tool
- added runtime parameter read access (integer type only for now)
- added docs/misc/hypfs-paths.pandoc for path descriptions

Juergen Gross (12):
xen: allow only sizeof(bool) variables for boolean_param()
xen: add a generic way to include binary files as variables
docs: add feature document for Xen hypervisor sysfs-like support
xen: add basic hypervisor filesystem support
libs: add libxenhypfs
tools: add xenfs tool
xen: provide version information in hypfs
xen: add /buildinfo/config entry to hypervisor filesystem
xen: add runtime parameter access support to hypfs tools/libxl: use libxenhypfs for setting xen runtime parameters tools/libxc: remove xc_set_parameters()
xen: remove XEN_SYSCTL_set_parameter support

 .gitignore                          |   6 +
 docs/features/hypervisorfs.pandoc   |  92 ++++++
 docs/man/xenhypfs.1.pod             |  61 ++++
 docs/misc/hypfs-paths.pandoc        | 163 +++++++++++
 tools/Rules.mk                      |   8 +-
 tools/flask/policy/modules/dom0.te  |   4 +-
 tools/libs/Makefile                 |   1 +
 tools/libs/hypfs/Makefile           |  16 ++
 tools/libs/hypfs/core.c             | 540 ++++++++++++++++++++++++++++++++++++
 tools/libs/hypfs/include/xenhypfs.h |  75 +++++
 tools/libs/hypfs/libxenhypfs.map    |  10 +
 tools/libs/hypfs/xenhypfs.pc.in     |  10 +
 tools/libxc/include/xenctrl.h       |   1 -
 tools/libxc/xc_misc.c               |  21 --
 tools/libxl/Makefile                |   3 +-
 tools/libxl/libxl.c                 |  53 +++-
 tools/libxl/libxl_internal.h        |   1 +
 tools/libxl/xenlight.pc.in          |   2 +-
 tools/misc/Makefile                 |   6 +
 tools/misc/xenhypfs.c               | 189 +++++++++++++
 tools/xl/xl_misc.c                  |   1 -
 xen/arch/arm/traps.c                |   1 +
 xen/arch/arm/xen.lds.S              |  10 +-
 xen/arch/x86/hvm/asid.c             |   2 +-
 xen/arch/x86/hvm/hypercall.c        |   1 +
 xen/arch/x86/hvm/vmx/vmcs.c         |  30 +-
 xen/arch/x86/hypercall.c            |   1 +
 xen/arch/x86/pv/domain.c            |  26 +-
 xen/arch/x86/pv/hypercall.c         |   1 +
 xen/arch/x86/xen.lds.S              |  10 +-
 xen/common/Kconfig                  |  10 +
 xen/common/Makefile                 |  13 +
 xen/common/grant_table.c            |  37 ++-
 xen/common/hypfs.c                  | 377 +++++++++++++++++++++++++
 xen/common/kernel.c                 |  84 +++++-
 xen/common/sysctl.c                 |  36 ---
 xen/drivers/char/console.c          |  66 ++++-
 xen/include/Makefile                |   1 +
 xen/include/public/hypfs.h          | 127 +++++++++
 xen/include/public/sysctl.h         |  18 --
 xen/include/public/xen.h            |   1 +
 xen/include/xen/hypercall.h         |   8 +
 xen/include/xen/hypfs.h             | 105 +++++++
 xen/include/xen/kernel.h            |   3 +
 xen/include/xen/lib.h               |   1 -
 xen/include/xen/param.h             |  96 ++++---
 xen/include/xlat.lst                |   2 +
 xen/include/xsm/dummy.h             |   6 +
 xen/include/xsm/xsm.h               |   6 +
 xen/tools/binfile                   |  41 +++
 xen/xsm/dummy.c                     |   1 +
 xen/xsm/flask/Makefile              |   5 +-
 xen/xsm/flask/flask-policy.S        |  16 --
 xen/xsm/flask/hooks.c               |   9 +-
 xen/xsm/flask/policy/access_vectors |   4 +-
 55 files changed, 2243 insertions(+), 175 deletions(-)
 create mode 100644 docs/features/hypervisorfs.pandoc
 create mode 100644 docs/man/xenhypfs.1.pod
 create mode 100644 docs/misc/hypfs-paths.pandoc
 create mode 100644 tools/libs/hypfs/Makefile
 create mode 100644 tools/libs/hypfs/core.c
 create mode 100644 tools/libs/hypfs/include/xenhypfs.h
 create mode 100644 tools/libs/hypfs/libxenhypfs.map
 create mode 100644 tools/libs/hypfs/xenhypfs.pc.in
 create mode 100644 tools/misc/xenhypfs.c
 create mode 100644 xen/common/hypfs.c
 create mode 100644 xen/include/public/hypfs.h
 create mode 100644 xen/include/xen/hypfs.h
 create mode 100755 xen/tools/binfile
 delete mode 100644 xen/xsm/flask/flask-policy.S
Signature · 7 lines
2.16.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

PATCH v6 1/12 xen: allow only sizeof(bool) variables for boolean_param()

Support of other variable sizes than that of normal bool ones for boolean_parameter() don't make sense, so catch any other sized variables at build time.

Fix the one parameter using a plain int instead of bool.

---
V6:
- new patch

---
 xen/arch/x86/hvm/asid.c | 2 +-
 xen/include/xen/param.h | 8 ++++++--
 2 files changed, 7 insertions(+), 3 deletions(-)
xen/arch/x86/hvm/asid.c +1 -1
index 8e00a28443..8b5bb86dfd 100644
@@ -25,7 +25,7 @@
 #include <asm/hvm/asid.h>
 
 /* Xen command-line option to enable ASIDs */
-static int opt_asid_enabled = 1;
+static bool opt_asid_enabled = true;
 boolean_param("asid", opt_asid_enabled);
 
 /*
xen/include/xen/param.h +6 -2
index 75471eb4ad..d4578cd27f 100644
@@ -2,6 +2,8 @@
 #define _XEN_PARAM_H
 
 #include <xen/init.h>
+#include <xen/lib.h>
+#include <xen/stdbool.h>
 
 /*
  * Used for kernel command line parameter setup
@@ -46,7 +48,8 @@ extern const struct kernel_param __param_start[], __param_end[];
     __kparam __setup_##_var = \
         { .name = __setup_str_##_var, \
           .type = OPT_BOOL, \
-          .len = sizeof(_var), \
+          .len = sizeof(_var) + \
+                 BUILD_BUG_ON_ZERO(sizeof(_var) != sizeof(bool)), \
           .par.var = &_var }
 #define integer_param(_name, _var) \
     __setup_str __setup_str_##_var[] = _name; \
@@ -86,7 +89,8 @@ extern const struct kernel_param __param_start[], __param_end[];
     __rtparam __rtpar_##_var = \
         { .name = _name, \
           .type = OPT_BOOL, \
-          .len = sizeof(_var), \
+          .len = sizeof(_var) + \
+                 BUILD_BUG_ON_ZERO(sizeof(_var) != sizeof(bool)), \
           .par.var = &_var }
 #define integer_runtime_only_param(_name, _var) \
     __rtparam __rtpar_##_var = \
Signature · 7 lines
2.16.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v6 1/12
#2 lore raw

Re: [Xen-devel] [PATCH v6 01/12] xen: allow only sizeof(bool) variables for boolean_param()

Quoted 3 lines · Juergen Gross

Support of other variable sizes than that of normal bool ones for boolean_parameter() don't make sense, so catch any other sized variables at build time.

Nit: boolean_param()

xen/include/xen/param.h extern const struct kernel_param __param_start[], __param_end[]; · line 52

Quoted 7 lines
xen/include/xen/param.h +2 -1
@@ -46,7 +48,8 @@ extern const struct kernel_param __param_start[], __param_end[];
     __kparam __setup_##_var = \
         { .name = __setup_str_##_var, \
           .type = OPT_BOOL, \
-          .len = sizeof(_var), \
+          .len = sizeof(_var) + \
+                 BUILD_BUG_ON_ZERO(sizeof(_var) != sizeof(bool)), \

I was first going to suggest to see about tightening this to do an actual type check, but I think we have a number of cases where boolean_param() actually involves int8_t variables, to allow us to detect whether a command line option was used. Hence

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw

Re: [Xen-devel] [PATCH v6 01/12] xen: allow only sizeof(bool) variables for boolean_param()

In reply to Juergen Gross

Hi Juergen,

Quoted 42 lines · Juergen Gross

Support of other variable sizes than that of normal bool ones for boolean_parameter() don't make sense, so catch any other sized variables at build time.

Fix the one parameter using a plain int instead of bool.

---
V6:
- new patch

---
  xen/arch/x86/hvm/asid.c | 2 +-
  xen/include/xen/param.h | 8 ++++++--
  2 files changed, 7 insertions(+), 3 deletions(-)
xen/arch/x86/hvm/asid.c +1 -1
index 8e00a28443..8b5bb86dfd 100644
@@ -25,7 +25,7 @@
  #include <asm/hvm/asid.h>
 
  /* Xen command-line option to enable ASIDs */
-static int opt_asid_enabled = 1;
+static bool opt_asid_enabled = true;
  boolean_param("asid", opt_asid_enabled);
 
  /*
xen/include/xen/param.h +2 -0
index 75471eb4ad..d4578cd27f 100644
@@ -2,6 +2,8 @@
  #define _XEN_PARAM_H
 
  #include <xen/init.h>
+#include <xen/lib.h>
+#include <xen/stdbool.h>
 
  /*
   * Used for kernel command line parameter setup

xen/include/xen/param.h extern const struct kernel_param __param_start[], __param_end[]; · line 52

Quoted 6 lines
xen/include/xen/param.h +2 -1
@@ -46,7 +48,8 @@ extern const struct kernel_param __param_start[], __param_end[];
      __kparam __setup_##_var = \
          { .name = __setup_str_##_var, \
            .type = OPT_BOOL, \
-          .len = sizeof(_var), \
+          .len = sizeof(_var) + \
+                 BUILD_BUG_ON_ZERO(sizeof(_var) != sizeof(bool)), \

From my understanding, sizeof(bool) is not necessarily 1 (it can be greater). While this is fine to use it in Xen, I think we want it to always be one when exposed in the hypfs.

Quoted 5 lines
xen/include/xen/param.h +0 -0
            .par.var = &_var }
  #define integer_param(_name, _var) \
      __setup_str __setup_str_##_var[] = _name; \

xen/include/xen/param.h extern const struct kernel_param __param_start[], __param_end[]; · line 96

Quoted 9 lines
xen/include/xen/param.h +2 -1
@@ -86,7 +89,8 @@ extern const struct kernel_param __param_start[], __param_end[];
      __rtparam __rtpar_##_var = \
          { .name = _name, \
            .type = OPT_BOOL, \
-          .len = sizeof(_var), \
+          .len = sizeof(_var) + \
+                 BUILD_BUG_ON_ZERO(sizeof(_var) != sizeof(bool)), \
            .par.var = &_var }
  #define integer_runtime_only_param(_name, _var) \
      __rtparam __rtpar_##_var = \

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#4 lore raw

Re: [Xen-devel] [PATCH v6 01/12] xen: allow only sizeof(bool) variables for boolean_param()

Quoted 12 lines · Julien Grall

xen/include/xen/param.h extern const struct kernel_param __param_start[], __param_end[]; · line 52

Quoted 7 lines · Juergen Gross
xen/include/xen/param.h +2 -1
@@ -46,7 +48,8 @@ extern const struct kernel_param __param_start[], __param_end[];
      __kparam __setup_##_var = \
          { .name = __setup_str_##_var, \
            .type = OPT_BOOL, \
-          .len = sizeof(_var), \
+          .len = sizeof(_var) + \
+                 BUILD_BUG_ON_ZERO(sizeof(_var) != sizeof(bool)), \

From my understanding, sizeof(bool) is not necessarily 1 (it can be
greater). While this is fine to use it in Xen, I think we want it to always be one when exposed in the hypfs.

I don't think so: We want variable of type 'bool' to be updated consistently (i.e. by a write to the full variable). Hence I think sizeof(bool) is correct here. I can see though that the hypercall interface then gains a dependency on the hypervisor's representation of 'bool', but I think such ought to be taken care of in the function carrying out the write, not in the macro here.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#5 lore raw

Re: [Xen-devel] [PATCH v6 01/12] xen: allow only sizeof(bool) variables for boolean_param()

Quoted 14 lines · Jan Beulich
Quoted 12 lines · Julien Grall

xen/include/xen/param.h extern const struct kernel_param __param_start[], __param_end[]; · line 52

Quoted 7 lines · Juergen Gross
xen/include/xen/param.h +2 -1
@@ -46,7 +48,8 @@ extern const struct kernel_param __param_start[], __param_end[];
       __kparam __setup_##_var = \
           { .name = __setup_str_##_var, \
             .type = OPT_BOOL, \
-          .len = sizeof(_var), \
+          .len = sizeof(_var) + \
+                 BUILD_BUG_ON_ZERO(sizeof(_var) != sizeof(bool)), \

From my understanding, sizeof(bool) is not necessarily 1 (it can be
greater). While this is fine to use it in Xen, I think we want it to always be one when exposed in the hypfs.

Quoted 7 lines

I don't think so: We want variable of type 'bool' to be updated consistently (i.e. by a write to the full variable). Hence I think sizeof(bool) is correct here. I can see though that the hypercall interface then gains a dependency on the hypervisor's representation of 'bool', but I think such ought to be taken care of in the function carrying out the write, not in the macro here.

So you think I should special case bool entries when returning the size information? Or do you think its fine to have the hypervisor's size reported and let the lib do the size handling correctly?

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#6 lore raw

Re: [Xen-devel] [PATCH v6 01/12] xen: allow only sizeof(bool) variables for boolean_param()

Quoted 23 lines · Jürgen Groß
Quoted 14 lines · Jan Beulich
Quoted 12 lines · Julien Grall

xen/include/xen/param.h extern const struct kernel_param __param_start[], __param_end[]; · line 52

Quoted 7 lines · Juergen Gross
xen/include/xen/param.h +2 -1
@@ -46,7 +48,8 @@ extern const struct kernel_param __param_start[], __param_end[];
       __kparam __setup_##_var = \
           { .name = __setup_str_##_var, \
             .type = OPT_BOOL, \
-          .len = sizeof(_var), \
+          .len = sizeof(_var) + \
+                 BUILD_BUG_ON_ZERO(sizeof(_var) != sizeof(bool)), \

From my understanding, sizeof(bool) is not necessarily 1 (it can be
greater). While this is fine to use it in Xen, I think we want it to always be one when exposed in the hypfs.

Quoted 7 lines

I don't think so: We want variable of type 'bool' to be updated consistently (i.e. by a write to the full variable). Hence I think sizeof(bool) is correct here. I can see though that the hypercall interface then gains a dependency on the hypervisor's representation of 'bool', but I think such ought to be taken care of in the function carrying out the write, not in the macro here.

Quoted 3 lines

So you think I should special case bool entries when returning the size information? Or do you think its fine to have the hypervisor's size reported and let the lib do the size handling correctly?

Either way would be fine by me, but I think not having callers have a (required) way to know the hypervisor's sizeof(bool) would be a more clean interface overall.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#7 lore raw

Re: [Xen-devel] [PATCH v6 01/12] xen: allow only sizeof(bool) variables for boolean_param()

Quoted 24 lines · Jan Beulich
Quoted 23 lines · Jürgen Groß
Quoted 21 lines · Jan Beulich
Quoted 12 lines · Julien Grall

xen/include/xen/param.h extern const struct kernel_param __param_start[], __param_end[]; · line 52

Quoted 7 lines · Juergen Gross
xen/include/xen/param.h +2 -1
@@ -46,7 +48,8 @@ extern const struct kernel_param __param_start[], __param_end[];
        __kparam __setup_##_var = \
            { .name = __setup_str_##_var, \
              .type = OPT_BOOL, \
-          .len = sizeof(_var), \
+          .len = sizeof(_var) + \
+                 BUILD_BUG_ON_ZERO(sizeof(_var) != sizeof(bool)), \

From my understanding, sizeof(bool) is not necessarily 1 (it can be
greater). While this is fine to use it in Xen, I think we want it to always be one when exposed in the hypfs.

I don't think so: We want variable of type 'bool' to be updated consistently (i.e. by a write to the full variable). Hence I think sizeof(bool) is correct here. I can see though that the hypercall interface then gains a dependency on the hypervisor's representation of 'bool', but I think such ought to be taken care of in the function carrying out the write, not in the macro here.

Quoted 7 lines
Quoted 3 lines

So you think I should special case bool entries when returning the size information? Or do you think its fine to have the hypervisor's size reported and let the lib do the size handling correctly?

Either way would be fine by me, but I think not having callers have a (required) way to know the hypervisor's sizeof(bool) would be a more clean interface overall.

The size is reported via the dirent, so this is fine. And when you have a look into patch 5 you'll see that the writing of the bool is merged with the uint writing in the lib code. I should remove the safety check regarding sizeof(bool) matching the size reported in the dirent, however (this is a leftover I forgot to remove).

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#8 lore raw

PATCH v6 2/12 xen: add a generic way to include binary files as variables

In reply to Juergen Gross

Add a new script xen/tools/binfile for including a binary file at build time being usable via a pointer and a size variable in the hypervisor.

Make use of that generic tool in xsm.

---
V3:
- new patch

V4:
- add alignment parameter (Jan Beulich)
- use .Lend instead of . (Jan Beulich)

---
 .gitignore                   |  1 +
 xen/tools/binfile            | 41 +++++++++++++++++++++++++++++++++++++++++
 xen/xsm/flask/Makefile       |  5 ++++-
 xen/xsm/flask/flask-policy.S | 16 ----------------
 4 files changed, 46 insertions(+), 17 deletions(-)
 create mode 100755 xen/tools/binfile
 delete mode 100644 xen/xsm/flask/flask-policy.S
.gitignore +1 -0
index 4ca679ddbc..b2624df79a 100644
@@ -313,6 +313,7 @@ xen/test/livepatch/*.livepatch
 xen/tools/kconfig/.tmp_gtkcheck
 xen/tools/kconfig/.tmp_qtcheck
 xen/tools/symbols
+xen/xsm/flask/flask-policy.S
 xen/xsm/flask/include/av_perm_to_string.h
 xen/xsm/flask/include/av_permissions.h
 xen/xsm/flask/include/class_to_string.h
xen/tools/binfile new file +41 -0

41 lines not on this page · raw message

xen/xsm/flask/Makefile +4 -1
index 7c3f381287..a807521235 100644
@@ -30,6 +30,9 @@ $(AV_H_FILES): $(AV_H_DEPEND)
 obj-bin-$(CONFIG_XSM_FLASK_POLICY) += flask-policy.o
 flask-policy.o: policy.bin
 
+flask-policy.S: $(XEN_ROOT)/xen/tools/binfile
+	$(XEN_ROOT)/xen/tools/binfile -i $@ policy.bin xsm_flask_init_policy
+
 FLASK_BUILD_DIR := $(CURDIR)
 POLICY_SRC := $(FLASK_BUILD_DIR)/xenpolicy-$(XEN_FULLVERSION)
 
@@ -39,4 +42,4 @@ policy.bin: FORCE
 
 .PHONY: clean
 clean::
-	rm -f $(ALL_H_FILES) *.o $(DEPS_RM) policy.* $(POLICY_SRC)
+	rm -f $(ALL_H_FILES) *.o $(DEPS_RM) policy.* $(POLICY_SRC) flask-policy.S
xen/xsm/flask/flask-policy.S deleted +0 -16
deleted file mode 100644
index d38aa39964..0000000000
@@ -1,16 +0,0 @@
-#include <asm/asm_defns.h>
-
-        .section .init.rodata, "a", %progbits
-
-/* const unsigned char xsm_flask_init_policy[] __initconst */
-        .global xsm_flask_init_policy
-xsm_flask_init_policy:
-        .incbin "policy.bin"
-.Lend:
-
-        .type xsm_flask_init_policy, %object
-        .size xsm_flask_init_policy, . - xsm_flask_init_policy
-
-/* const unsigned int __initconst xsm_flask_init_policy_size */
-        .global xsm_flask_init_policy_size
-        ASM_INT(xsm_flask_init_policy_size, .Lend - xsm_flask_init_policy)
Signature · 7 lines
2.16.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#9 lore raw

PATCH v6 3/12 docs: add feature document for Xen hypervisor sysfs-like support

In reply to Juergen Gross

On the 2019 Xen developer summit there was agreement that the Xen hypervisor should gain support for a hierarchical name-value store similar to the Linux kernel's sysfs.

In the beginning there should only be basic support: entries can be added from the hypervisor itself only, there is a simple hypercall interface to read the data.

Add a feature document for setting the base of a discussion regarding the desired functionality and the entries to add.

---
V1:
- remove the "--" prefixes of the sub-commands of the user tool (Jan Beulich)
- rename xenfs to xenhypfs (Jan Beulich)
- add "tree" and "write" options to user tool

V2:
- move example tree to the paths description (Ian Jackson)
- specify allowed characters for keys and values (Ian Jackson)

V3:
- correct introduction (writable entries)

V4:
- add list specification
- add entry example (Julien Grall)
- correct date and Xen version (Julien Grall)
- add ARM64 as possible architecture (Julien Grall)
- add version description to the feature doc (Jan Beulich)

---
 docs/features/hypervisorfs.pandoc |  92 +++++++++++++++++++++++++++++++++
 docs/misc/hypfs-paths.pandoc      | 105 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 197 insertions(+)
 create mode 100644 docs/features/hypervisorfs.pandoc
 create mode 100644 docs/misc/hypfs-paths.pandoc
docs/features/hypervisorfs.pandoc new file +92 -0
new file mode 100644
index 0000000000..a0a0ead057
@@ -0,0 +1,92 @@
+% Hypervisor FS
+% Revision 1
+
+\clearpage
+
+# Basics
+---------------- ---------------------
+         Status: **Supported**
+
+  Architectures: all
+
+     Components: Hypervisor, toolstack
+---------------- ---------------------
+
+# Overview
+
+The Hypervisor FS is a hierarchical name-value store for reporting
+information to guests, especially dom0. It is similar to the Linux
+kernel's sysfs. Entries and directories are created by the hypervisor,
+while the toolstack is able to use a hypercall to query the entry
+values or (if allowed by the hypervisor) to modify them.
+
+# User details
+
+With:
+
+    xenhypfs ls <path>
+
+the user can list the entries of a specific path of the FS. Using:
+
+    xenhypfs cat <path>
+
+the content of an entry can be retrieved. Using:
+
+    xenhypfs write <path> <string>
+
+a writable entry can be modified. With:
+
+    xenhypfs tree
+
+the complete Hypervisor FS entry tree can be printed.
+
+The FS paths are documented in `docs/misc/hypfs-paths.pandoc`.
+
+# Technical details
+
+Access to the hypervisor filesystem is done via the stable new hypercall
+__HYPERVISOR_filesystem_op. This hypercall supports a sub-command
+XEN_HYPFS_OP_get_version which will return the highest version of the
+interface supported by the hypervisor. Additions to the interface need
+to bump the interface version. The hypervisor is required to support the
+previous interface versions, too (this implies that additions will always
+require new sub-commands in order to allow the hypervisor to decide which
+version of the interface to use).
+
+* hypercall interface specification
+    * `xen/include/public/hypfs.h`
+* hypervisor internal files
+    * `xen/include/xen/hypfs.h`
+    * `xen/common/hypfs.c`
+* `libxenhypfs`
+    * `tools/libs/libxenhypfs/*`
+* `xenhypfs`
+    * `tools/misc/xenhypfs.c`
+* path documentation
+    * `docs/misc/hypfs-paths.pandoc`
+
+# Testing
+
+Any new parameters or hardware mitigations should be verified to show up
+correctly in the filesystem.
+
+# Areas for improvement
+
+* More detailed access rights
+* Entries per domain and/or per cpupool
+
+# Known issues
+
+* None
+
+# References
+
+* None
+
+# History
+
+------------------------------------------------------------------------
+Date       Revision Version  Notes
+---------- -------- -------- -------------------------------------------
+2020-01-23 1        Xen 4.14 Document written
+---------- -------- -------- -------------------------------------------
docs/misc/hypfs-paths.pandoc new file +105 -0

105 lines not on this page · raw message

Signature · 7 lines
2.16.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v6 3/12
#10 lore raw

Re: [Xen-devel] [PATCH v6 03/12] docs: add feature document for Xen hypervisor sysfs-like support

Hi Juergen,

Quoted 45 lines · Juergen Gross

On the 2019 Xen developer summit there was agreement that the Xen hypervisor should gain support for a hierarchical name-value store similar to the Linux kernel's sysfs.

In the beginning there should only be basic support: entries can be added from the hypervisor itself only, there is a simple hypercall interface to read the data.

Add a feature document for setting the base of a discussion regarding the desired functionality and the entries to add.

---
V1:
- remove the "--" prefixes of the sub-commands of the user tool (Jan Beulich)
- rename xenfs to xenhypfs (Jan Beulich)
- add "tree" and "write" options to user tool

V2:
- move example tree to the paths description (Ian Jackson)
- specify allowed characters for keys and values (Ian Jackson)

V3:
- correct introduction (writable entries)

V4:
- add list specification
- add entry example (Julien Grall)
- correct date and Xen version (Julien Grall)
- add ARM64 as possible architecture (Julien Grall)
- add version description to the feature doc (Jan Beulich)

---
  docs/features/hypervisorfs.pandoc |  92 +++++++++++++++++++++++++++++++++
  docs/misc/hypfs-paths.pandoc      | 105 ++++++++++++++++++++++++++++++++++++++
  2 files changed, 197 insertions(+)

create mode 100644 docs/features/hypervisorfs.pandoc create mode 100644 docs/misc/hypfs-paths.pandoc

docs/features/hypervisorfs.pandoc new file +0 -0
new file mode 100644
index 0000000000..a0a0ead057

docs/features/hypervisorfs.pandoc line 8

Quoted 8 lines
docs/features/hypervisorfs.pandoc new file +8 -0
@@ -0,0 +1,92 @@
+% Hypervisor FS
+% Revision 1
+
+\clearpage
+
+# Basics
+---------------- ---------------------
+         Status: **Supported**

I think you also want to update SUPPORT.MD with the status of the feature.

Other than that:

docs/features/hypervisorfs.pandoc line 13

Quoted 5 lines
docs/features/hypervisorfs.pandoc new file +5 -0
+
+  Architectures: all
+
+     Components: Hypervisor, toolstack
+---------------- ---------------------

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#11 lore raw

Re: [Xen-devel] [PATCH v6 03/12] docs: add feature document for Xen hypervisor sysfs-like support

Quoted 44 lines · Julien Grall

Hi Juergen,

Quoted 41 lines · Juergen Gross

On the 2019 Xen developer summit there was agreement that the Xen hypervisor should gain support for a hierarchical name-value store similar to the Linux kernel's sysfs.

In the beginning there should only be basic support: entries can be added from the hypervisor itself only, there is a simple hypercall interface to read the data.

Add a feature document for setting the base of a discussion regarding the desired functionality and the entries to add.

---
V1:
- remove the "--" prefixes of the sub-commands of the user tool (Jan Beulich)
- rename xenfs to xenhypfs (Jan Beulich)
- add "tree" and "write" options to user tool

V2:
- move example tree to the paths description (Ian Jackson)
- specify allowed characters for keys and values (Ian Jackson)

V3:
- correct introduction (writable entries)

V4:
- add list specification
- add entry example (Julien Grall)
- correct date and Xen version (Julien Grall)
- add ARM64 as possible architecture (Julien Grall)
- add version description to the feature doc (Jan Beulich)
---
  docs/features/hypervisorfs.pandoc |  92
+++++++++++++++++++++++++++++++++
  docs/misc/hypfs-paths.pandoc      | 105
++++++++++++++++++++++++++++++++++++++

  2 files changed, 197 insertions(+)

  create mode 100644 docs/features/hypervisorfs.pandoc create mode 100644 docs/misc/hypfs-paths.pandoc

Quoted 16 lines
Quoted 6 lines
docs/features/hypervisorfs.pandoc new file +0 -0
new file mode 100644
index 0000000000..a0a0ead057

docs/features/hypervisorfs.pandoc line 8

Quoted 8 lines
docs/features/hypervisorfs.pandoc new file +8 -0
@@ -0,0 +1,92 @@
+% Hypervisor FS
+% Revision 1
+
+\clearpage
+
+# Basics
+---------------- ---------------------
+         Status: **Supported**

I think you also want to update SUPPORT.MD with the status of the feature.

I will send a patch doing this when all patches up to patch 6 have gone in, as those are needed at least.

Quoted 4 lines

Other than that:

Thanks

Juergen

#12 lore raw

PATCH v6 4/12 xen: add basic hypervisor filesystem support

In reply to Juergen Gross

Add the infrastructure for the hypervisor filesystem.

This includes the hypercall interface and the base functions for entry creation, deletion and modification.

In order not to have to repeat the same pattern multiple times in case adding a new node should BUG_ON() failure, the helpers for adding a node (hypfs_add_dir() and hypfs_add_leaf()) get a nofault parameter causing the BUG() in case of a failure.

When supporting writable leafs the entry's write pointer will need to be set to the function performing the write to the variable holding the content. In case there are no special constraints this will be hypfs_write_bool() for type XEN_HYPFS_TYPE_BOOL and hypfs_write_leaf() for the other entry types.

---
V1:
- rename files from filesystem.* to hypfs.*
- add dummy write entry support
- rename hypercall filesystem_op to hypfs_op
- add support for unsigned integer entries

V2:
- test new entry name to be valid

V3:
- major rework, especially by supporting binary contents of entries
- addressed all comments

V4:
- sort #includes alphabetically (Wei Liu)
- add public interface structures to xlat.lst (Jan Beulich)
- let DIRENTRY_SIZE() add 1 for trailing nul byte (Jan Beulich)
- remove hypfs_add_entry() (Jan Beulich)
- len -> ulen (Jan Beulich)
- switch sequence of tests in hypfs_get_entry_rel() (Jan Beulich)
- add const qualifier (Jan Beulich)
- return -ENOBUFS if only direntry but no entry contents are returned (Jan Beulich)
- use xmalloc() instead of xzalloc() (Jan Beulich)
- better error handling in hypfs_write_leaf() (Jan Beulich)
- return -EOPNOTSUPP for unknown sub-command (Jan Beulich)
- use plain integers for enum-like constants in public interface (Jan Beulich)
- rename XEN_HYPFS_OP_read_contents to XEN_HYPFS_OP_read (Jan Beulich)
- add some comments in include/public/hypfs.h (Jan Beulich)
- use const_char for user parameter path (Jan Beulich)
- add helpers for XEN_HYPFS_TYPE_BOOL and XEN_HYPFS_TYPE_INT entry definitions (Jan Beulich)
- make statically defined entries __read_mostly (Jan Beulich)

V5:
- switch to xsm for privilege check

V6:
- use memchr() for testing correct string length (Jan Beulich)
- reject writing to non-string leafs with wrong length (Jan Beulich)
- only support bools of natural size (Julien Grall)
- adjust blank padding in header (Jan Beulich)
- adjust comments in public header (Jan Beulich)
- rename hypfs_string_set() and add comment (Jan Beulich)
- add common HYPFS_INIT helper macro (Jan Beulich)
- really check structures added to xlat.lst (Jan Beulich)
- add missing xsm parts (Jan Beulich)

---
 tools/flask/policy/modules/dom0.te  |   2 +-
 xen/arch/arm/traps.c                |   1 +
 xen/arch/x86/hvm/hypercall.c        |   1 +
 xen/arch/x86/hypercall.c            |   1 +
 xen/arch/x86/pv/hypercall.c         |   1 +
 xen/common/Makefile                 |   1 +
 xen/common/hypfs.c                  | 349 ++++++++++++++++++++++++++++++++++++
 xen/include/Makefile                |   1 +
 xen/include/public/hypfs.h          | 127 +++++++++++++
 xen/include/public/xen.h            |   1 +
 xen/include/xen/hypercall.h         |   8 +
 xen/include/xen/hypfs.h             | 103 +++++++++++
 xen/include/xlat.lst                |   2 +
 xen/include/xsm/dummy.h             |   6 +
 xen/include/xsm/xsm.h               |   6 +
 xen/xsm/dummy.c                     |   1 +
 xen/xsm/flask/hooks.c               |   6 +
 xen/xsm/flask/policy/access_vectors |   2 +
 18 files changed, 618 insertions(+), 1 deletion(-)
 create mode 100644 xen/common/hypfs.c
 create mode 100644 xen/include/public/hypfs.h
 create mode 100644 xen/include/xen/hypfs.h
tools/flask/policy/modules/dom0.te +1 -1
index 272f6a4f75..20925e38a2 100644
@@ -11,7 +11,7 @@ allow dom0_t xen_t:xen {
 	mtrr_del mtrr_read microcode physinfo quirk writeconsole readapic
 	writeapic privprofile nonprivprofile kexec firmware sleep frequency
 	getidle debug getcpuinfo heap pm_op mca_op lockprof cpupool_op
-	getscheduler setscheduler
+	getscheduler setscheduler hypfs_op
 };
 allow dom0_t xen_t:xen2 {
 	resource_op psr_cmt_op psr_alloc pmu_ctrl get_symbol
xen/arch/arm/traps.c +1 -0
index 6f9bec22d3..87af810667 100644
@@ -1382,6 +1382,7 @@ static arm_hypercall_t arm_hypercall_table[] = {
 #ifdef CONFIG_ARGO
     HYPERCALL(argo_op, 5),
 #endif
+    HYPERCALL(hypfs_op, 5),
 };
 
 #ifndef NDEBUG
xen/arch/x86/hvm/hypercall.c +1 -0
index 33dd2d99d2..210dda4f38 100644
@@ -144,6 +144,7 @@ static const hypercall_table_t hvm_hypercall_table[] = {
 #endif
     HYPERCALL(xenpmu_op),
     COMPAT_CALL(dm_op),
+    HYPERCALL(hypfs_op),
     HYPERCALL(arch_1)
 };
 
xen/arch/x86/hypercall.c +1 -0
index 7f299d45c6..05a3f5e25b 100644
@@ -73,6 +73,7 @@ const hypercall_args_t hypercall_args_table[NR_hypercalls] =
     ARGS(hvm_op, 2),
     ARGS(dm_op, 3),
 #endif
+    ARGS(hypfs_op, 5),
     ARGS(mca, 1),
     ARGS(arch_1, 1),
 };
xen/arch/x86/pv/hypercall.c +1 -0
index 17ddf9ea1f..83907d4f00 100644
@@ -85,6 +85,7 @@ const hypercall_table_t pv_hypercall_table[] = {
     HYPERCALL(hvm_op),
     COMPAT_CALL(dm_op),
 #endif
+    HYPERCALL(hypfs_op),
     HYPERCALL(mca),
     HYPERCALL(arch_1),
 };
xen/common/Makefile +1 -0
index 2abb8250b0..3a2c1ae690 100644
@@ -10,6 +10,7 @@ obj-y += domain.o
 obj-y += event_2l.o
 obj-y += event_channel.o
 obj-y += event_fifo.o
+obj-y += hypfs.o
 obj-$(CONFIG_CRASH_DEBUG) += gdbstub.o
 obj-$(CONFIG_GRANT_TABLE) += grant_table.o
 obj-y += guestcopy.o
xen/common/hypfs.c new file +349 -0

349 lines not on this page · raw message

xen/include/Makefile +1 -0
index fde0ca0131..150ca348a1 100644
@@ -11,6 +11,7 @@ headers-y := \
     compat/event_channel.h \
     compat/features.h \
     compat/grant_table.h \
+    compat/hypfs.h \
     compat/kexec.h \
     compat/memory.h \
     compat/nmi.h \
xen/include/public/hypfs.h new file +127 -0

127 lines not on this page · raw message

xen/include/public/xen.h +1 -0
index 75b1619d0d..945ef30273 100644
@@ -130,6 +130,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_ulong_t);
 #define __HYPERVISOR_argo_op              39
 #define __HYPERVISOR_xenpmu_op            40
 #define __HYPERVISOR_dm_op                41
+#define __HYPERVISOR_hypfs_op             42
 
 /* Architecture-specific hypercall definitions. */
 #define __HYPERVISOR_arch_0               48
xen/include/xen/hypercall.h +8 -0
index ad8ad27b23..836a8b1ba8 100644
@@ -150,6 +150,14 @@ do_dm_op(
     unsigned int nr_bufs,
     XEN_GUEST_HANDLE_PARAM(xen_dm_op_buf_t) bufs);
 
+extern long
+do_hypfs_op(
+    unsigned int cmd,
+    XEN_GUEST_HANDLE_PARAM(const_char) arg1,
+    unsigned long arg2,
+    XEN_GUEST_HANDLE_PARAM(void) arg3,
+    unsigned long arg4);
+
 #ifdef CONFIG_COMPAT
 
 extern int
xen/include/xen/hypfs.h new file +103 -0

103 lines not on this page · raw message

xen/include/xlat.lst +2 -0
index 95f5e5592b..0921d4a8d0 100644
@@ -86,6 +86,8 @@
 ?	vcpu_hvm_context		hvm/hvm_vcpu.h
 ?	vcpu_hvm_x86_32			hvm/hvm_vcpu.h
 ?	vcpu_hvm_x86_64			hvm/hvm_vcpu.h
+?	hypfs_direntry			hypfs.h
+?	hypfs_dirlistentry		hypfs.h
 ?	kexec_exec			kexec.h
 !	kexec_image			kexec.h
 !	kexec_range			kexec.h
xen/include/xsm/dummy.h +6 -0
index b8e185e6fa..68b5bf8f8e 100644
@@ -433,6 +433,12 @@ static XSM_INLINE int xsm_page_offline(XSM_DEFAULT_ARG uint32_t cmd)
     return xsm_default_action(action, current->domain, NULL);
 }
 
+static XSM_INLINE int xsm_hypfs_op(XSM_DEFAULT_VOID)
+{
+    XSM_ASSERT_ACTION(XSM_PRIV);
+    return xsm_default_action(action, current->domain, NULL);
+}
+
 static XSM_INLINE long xsm_do_xsm_op(XEN_GUEST_HANDLE_PARAM(xsm_op_t) op)
 {
     return -ENOSYS;
xen/include/xsm/xsm.h +6 -0
index e22d6160b5..a80bcf3e42 100644
@@ -127,6 +127,7 @@ struct xsm_operations {
     int (*resource_setup_misc) (void);
 
     int (*page_offline)(uint32_t cmd);
+    int (*hypfs_op)(void);
 
     long (*do_xsm_op) (XEN_GUEST_HANDLE_PARAM(xsm_op_t) op);
 #ifdef CONFIG_COMPAT
@@ -536,6 +537,11 @@ static inline int xsm_page_offline(xsm_default_t def, uint32_t cmd)
     return xsm_ops->page_offline(cmd);
 }
 
+static inline int xsm_hypfs_op(xsm_default_t def)
+{
+    return xsm_ops->hypfs_op();
+}
+
 static inline long xsm_do_xsm_op (XEN_GUEST_HANDLE_PARAM(xsm_op_t) op)
 {
     return xsm_ops->do_xsm_op(op);
xen/xsm/dummy.c +1 -0
index 5705e52791..d4cce68089 100644
@@ -103,6 +103,7 @@ void __init xsm_fixup_ops (struct xsm_operations *ops)
     set_to_dummy_if_null(ops, resource_setup_misc);
 
     set_to_dummy_if_null(ops, page_offline);
+    set_to_dummy_if_null(ops, hypfs_op);
     set_to_dummy_if_null(ops, hvm_param);
     set_to_dummy_if_null(ops, hvm_control);
     set_to_dummy_if_null(ops, hvm_param_nested);
xen/xsm/flask/hooks.c +6 -0
index cf7f25cda2..e257328928 100644
@@ -1172,6 +1172,11 @@ static inline int flask_page_offline(uint32_t cmd)
     }
 }
 
+static inline int flask_hypfs_op(void)
+{
+    return domain_has_xen(current->domain, XEN__HYPFS_OP);
+}
+
 static int flask_add_to_physmap(struct domain *d1, struct domain *d2)
 {
     return domain_has_perm(d1, d2, SECCLASS_MMU, MMU__PHYSMAP);
@@ -1811,6 +1816,7 @@ static struct xsm_operations flask_ops = {
     .resource_setup_misc = flask_resource_setup_misc,
 
     .page_offline = flask_page_offline,
+    .hypfs_op = flask_hypfs_op,
     .hvm_param = flask_hvm_param,
     .hvm_control = flask_hvm_param,
     .hvm_param_nested = flask_hvm_param_nested,
xen/xsm/flask/policy/access_vectors +2 -0
index c055c14c26..c9e385fb9b 100644
@@ -67,6 +67,8 @@ class xen
     lockprof
 # XEN_SYSCTL_cpupool_op
     cpupool_op
+# hypfs hypercall
+    hypfs_op
 # XEN_SYSCTL_scheduler_op with XEN_DOMCTL_SCHEDOP_getinfo, XEN_SYSCTL_sched_id, XEN_DOMCTL_SCHEDOP_getvcpuinfo
     getscheduler
 # XEN_SYSCTL_scheduler_op with XEN_DOMCTL_SCHEDOP_putinfo, XEN_DOMCTL_SCHEDOP_putvcpuinfo
Signature · 7 lines
2.16.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#13 lore raw

Re: [Xen-devel] [PATCH v6 04/12] xen: add basic hypervisor filesystem support

Quoted 13 lines · Juergen Gross
xen/common/hypfs.c new file +10 -0
@@ -0,0 +1,349 @@
+/******************************************************************************
+ *
+ * hypfs.c
+ *
+ * Simple sysfs-like file system for the hypervisor.
+ */
+
+#include <xen/err.h>
+#include <xen/guest_access.h>
+#include <xen/hypercall.h>

xen/common/hypfs.c line 20

Quoted 10 lines
xen/common/hypfs.c new file +10 -0
+#include <xen/hypfs.h>
+#include <xen/lib.h>
+#include <xen/rwlock.h>
+#include <public/hypfs.h>
+
+#ifdef CONFIG_COMPAT
+#include <compat/hypfs.h>
+CHECK_hypfs_direntry;
+#undef CHECK_hypfs_direntry
+#define CHECK_hypfs_direntry struct xen_hypfs_direntry

I'm struggling to see why you need this #undef and #define.

xen/common/hypfs.c line 244

Quoted 12 lines
xen/common/hypfs.c new file +12 -0
+int hypfs_write_leaf(struct hypfs_entry_leaf *leaf,
+                     XEN_GUEST_HANDLE_PARAM(void) uaddr, unsigned long ulen)
+{
+    char *buf;
+    int ret;
+
+    if ( ulen > leaf->e.size )
+        return -ENOSPC;
+
+    if ( leaf->e.type != XEN_HYPFS_TYPE_STRING &&
+         leaf->e.type != XEN_HYPFS_TYPE_BLOB && ulen != leaf->e.size )
+        return -EDOM;

Why the exception of string and blob? My concern about the meaning of a partially written entry (without its size having changed) remains.

xen/common/hypfs.c line 255

Quoted 10 lines
xen/common/hypfs.c new file +10 -0
+    buf = xmalloc_array(char, ulen);
+    if ( !buf )
+        return -ENOMEM;
+
+    ret = -EFAULT;
+    if ( copy_from_guest(buf, uaddr, ulen) )
+        goto out;
+
+    ret = -EINVAL;
+    if ( leaf->e.type == XEN_HYPFS_TYPE_STRING && !memchr(buf, 0, ulen) )

This should also use the != buf + ulen - 1 form imo.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#14 lore raw

Re: [Xen-devel] [PATCH v6 04/12] xen: add basic hypervisor filesystem support

Quoted 18 lines · Jan Beulich
Quoted 17 lines · Juergen Gross
xen/common/hypfs.c new file +14 -0
@@ -0,0 +1,349 @@
+/******************************************************************************
+ *
+ * hypfs.c
+ *
+ * Simple sysfs-like file system for the hypervisor.
+ */
+
+#include <xen/err.h>
+#include <xen/guest_access.h>
+#include <xen/hypercall.h>
+#include <xen/hypfs.h>
+#include <xen/lib.h>
+#include <xen/rwlock.h>
+#include <public/hypfs.h>
Quoted 8 lines

xen/common/hypfs.c line 20

Quoted 6 lines
xen/common/hypfs.c new file +6 -0
+
+#ifdef CONFIG_COMPAT
+#include <compat/hypfs.h>
+CHECK_hypfs_direntry;
+#undef CHECK_hypfs_direntry
+#define CHECK_hypfs_direntry struct xen_hypfs_direntry

I'm struggling to see why you need this #undef and #define.

Without those I get:

In file included from /home/gross/xen/unstable/xen/include/compat/xen.h:3:0,
from /home/gross/xen/unstable/xen/include/xen/shared.h:6, from /home/gross/xen/unstable/xen/include/xen/sched.h:8, from /home/gross/xen/unstable/xen/include/asm/paging.h:29, from
/home/gross/xen/unstable/xen/include/asm/guest_access.h:1,
from
/home/gross/xen/unstable/xen/include/xen/guest_access.h:1,

                 from hypfs.c:9:
/home/gross/xen/unstable/xen/include/xen/compat.h:134:32: error: redefinition of ‘__checkFstruct_hypfs_direntry__flags’
 #define CHECK_NAME_(k, n, tag) __check ## tag ## k ## _ ## n
                                ^
/home/gross/xen/unstable/xen/include/xen/compat.h:166:34: note: in definition of macro ‘CHECK_FIELD_COMMON_’
 static inline int __maybe_unused name(k xen_ ## n *x, k compat_ ## n *c) \
                                  ^~~~
/home/gross/xen/unstable/xen/include/xen/compat.h:176:28: note: in expansion of macro ‘CHECK_NAME_’
     CHECK_FIELD_COMMON_(k, CHECK_NAME_(k, n ## __ ## f, F), n, f)
                            ^~~~~~~~~~~
/home/gross/xen/unstable/xen/include/compat/xlat.h:775:5: note: in expansion of macro ‘CHECK_FIELD_’
     CHECK_FIELD_(struct, hypfs_direntry, flags); \
     ^~~~~~~~~~~~
/home/gross/xen/unstable/xen/include/compat/xlat.h:782:5: note: in expansion of macro ‘CHECK_hypfs_direntry’
     CHECK_hypfs_direntry; \
     ^~~~~~~~~~~~~~~~~~~~

hypfs.c:19:1: note: in expansion of macro ‘CHECK_hypfs_dirlistentry’
CHECK_hypfs_dirlistentry;
^~~~~~~~~~~~~~~~~~~~~~~~
/home/gross/xen/unstable/xen/include/xen/compat.h:134:32: note: previous definition of ‘__checkFstruct_hypfs_direntry__flags’ was here

 #define CHECK_NAME_(k, n, tag) __check ## tag ## k ## _ ## n
                                ^
/home/gross/xen/unstable/xen/include/xen/compat.h:166:34: note: in definition of macro ‘CHECK_FIELD_COMMON_’
 static inline int __maybe_unused name(k xen_ ## n *x, k compat_ ## n *c) \
                                  ^~~~
/home/gross/xen/unstable/xen/include/xen/compat.h:176:28: note: in expansion of macro ‘CHECK_NAME_’
     CHECK_FIELD_COMMON_(k, CHECK_NAME_(k, n ## __ ## f, F), n, f)
                            ^~~~~~~~~~~
/home/gross/xen/unstable/xen/include/compat/xlat.h:775:5: note: in expansion of macro ‘CHECK_FIELD_’
     CHECK_FIELD_(struct, hypfs_direntry, flags); \
     ^~~~~~~~~~~~

hypfs.c:18:1: note: in expansion of macro ‘CHECK_hypfs_direntry’
CHECK_hypfs_direntry;

Quoted 17 lines

xen/common/hypfs.c line 244

Quoted 13 lines
xen/common/hypfs.c new file +12 -0
+int hypfs_write_leaf(struct hypfs_entry_leaf *leaf,
+                     XEN_GUEST_HANDLE_PARAM(void) uaddr, unsigned long ulen)
+{
+    char *buf;
+    int ret;
+
+    if ( ulen > leaf->e.size )
+        return -ENOSPC;
+
+    if ( leaf->e.type != XEN_HYPFS_TYPE_STRING &&
+         leaf->e.type != XEN_HYPFS_TYPE_BLOB && ulen != leaf->e.size )
+        return -EDOM;

Why the exception of string and blob? My concern about the meaning of a partially written entry (without its size having changed) remains.

It is perfectly valid to write a shorter string into a character array. I could drop the blob here, but in the end I think allowing for a blob to change the size should be fine.

Quoted 13 lines

xen/common/hypfs.c line 255

Quoted 11 lines
xen/common/hypfs.c new file +10 -0
+    buf = xmalloc_array(char, ulen);
+    if ( !buf )
+        return -ENOMEM;
+
+    ret = -EFAULT;
+    if ( copy_from_guest(buf, uaddr, ulen) )
+        goto out;
+
+    ret = -EINVAL;
+    if ( leaf->e.type == XEN_HYPFS_TYPE_STRING && !memchr(buf, 0, ulen) )

This should also use the != buf + ulen - 1 form imo.

I'm fine to change that, but should the hypervisor really refuse to accept a larger buffer?

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#15 lore raw

Re: [Xen-devel] [PATCH v6 04/12] xen: add basic hypervisor filesystem support

Quoted 78 lines · Jürgen Groß
Quoted 18 lines · Jan Beulich
Quoted 17 lines · Juergen Gross
xen/common/hypfs.c new file +14 -0
@@ -0,0 +1,349 @@
+/******************************************************************************
+ *
+ * hypfs.c
+ *
+ * Simple sysfs-like file system for the hypervisor.
+ */
+
+#include <xen/err.h>
+#include <xen/guest_access.h>
+#include <xen/hypercall.h>
+#include <xen/hypfs.h>
+#include <xen/lib.h>
+#include <xen/rwlock.h>
+#include <public/hypfs.h>
Quoted 8 lines

xen/common/hypfs.c line 20

Quoted 6 lines
xen/common/hypfs.c new file +6 -0
+
+#ifdef CONFIG_COMPAT
+#include <compat/hypfs.h>
+CHECK_hypfs_direntry;
+#undef CHECK_hypfs_direntry
+#define CHECK_hypfs_direntry struct xen_hypfs_direntry

I'm struggling to see why you need this #undef and #define.

Without those I get:

In file included from /home/gross/xen/unstable/xen/include/compat/xen.h:3:0,
from /home/gross/xen/unstable/xen/include/xen/shared.h:6, from /home/gross/xen/unstable/xen/include/xen/sched.h:8, from /home/gross/xen/unstable/xen/include/asm/paging.h:29, from
/home/gross/xen/unstable/xen/include/asm/guest_access.h:1,
from
/home/gross/xen/unstable/xen/include/xen/guest_access.h:1,

                  from hypfs.c:9:
/home/gross/xen/unstable/xen/include/xen/compat.h:134:32: error: 
redefinition of ‘__checkFstruct_hypfs_direntry__flags’
  #define CHECK_NAME_(k, n, tag) __check ## tag ## k ## _ ## n
                                 ^
/home/gross/xen/unstable/xen/include/xen/compat.h:166:34: note: in 
definition of macro ‘CHECK_FIELD_COMMON_’
  static inline int __maybe_unused name(k xen_ ## n *x, k compat_ ## n *c) \
                                   ^~~~
/home/gross/xen/unstable/xen/include/xen/compat.h:176:28: note: in 
expansion of macro ‘CHECK_NAME_’
      CHECK_FIELD_COMMON_(k, CHECK_NAME_(k, n ## __ ## f, F), n, f)
                             ^~~~~~~~~~~
/home/gross/xen/unstable/xen/include/compat/xlat.h:775:5: note: in 
expansion of macro ‘CHECK_FIELD_’
      CHECK_FIELD_(struct, hypfs_direntry, flags); \
      ^~~~~~~~~~~~
/home/gross/xen/unstable/xen/include/compat/xlat.h:782:5: note: in 
expansion of macro ‘CHECK_hypfs_direntry’
      CHECK_hypfs_direntry; \
      ^~~~~~~~~~~~~~~~~~~~

hypfs.c:19:1: note: in expansion of macro ‘CHECK_hypfs_dirlistentry’
CHECK_hypfs_dirlistentry;
^~~~~~~~~~~~~~~~~~~~~~~~
/home/gross/xen/unstable/xen/include/xen/compat.h:134:32: note: previous definition of ‘__checkFstruct_hypfs_direntry__flags’ was here

  #define CHECK_NAME_(k, n, tag) __check ## tag ## k ## _ ## n
                                 ^
/home/gross/xen/unstable/xen/include/xen/compat.h:166:34: note: in 
definition of macro ‘CHECK_FIELD_COMMON_’
  static inline int __maybe_unused name(k xen_ ## n *x, k compat_ ## n *c) \
                                   ^~~~
/home/gross/xen/unstable/xen/include/xen/compat.h:176:28: note: in 
expansion of macro ‘CHECK_NAME_’
      CHECK_FIELD_COMMON_(k, CHECK_NAME_(k, n ## __ ## f, F), n, f)
                             ^~~~~~~~~~~
/home/gross/xen/unstable/xen/include/compat/xlat.h:775:5: note: in 
expansion of macro ‘CHECK_FIELD_’
      CHECK_FIELD_(struct, hypfs_direntry, flags); \
      ^~~~~~~~~~~~
Quoted 2 lines

hypfs.c:18:1: note: in expansion of macro ‘CHECK_hypfs_direntry’
CHECK_hypfs_direntry;

Which suggests to me that the explicit CHECK_hypfs_direntry invocation is unneeded, as it's getting verified as part of the invocation of CHECK_hypfs_dirlistentry.

Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
xen/common/hypfs.c new file +8 -0
+int hypfs_write_leaf(struct hypfs_entry_leaf *leaf,
+                     XEN_GUEST_HANDLE_PARAM(void) uaddr, unsigned long ulen)
+{
+    char *buf;
+    int ret;
+
+    if ( ulen > leaf->e.size )
+        return -ENOSPC;
Quoted 8 lines

xen/common/hypfs.c line 244

Quoted 4 lines
xen/common/hypfs.c new file +4 -0
+
+    if ( leaf->e.type != XEN_HYPFS_TYPE_STRING &&
+         leaf->e.type != XEN_HYPFS_TYPE_BLOB && ulen != leaf->e.size )
+        return -EDOM;

Why the exception of string and blob? My concern about the meaning of a partially written entry (without its size having changed) remains.

Quoted 3 lines

It is perfectly valid to write a shorter string into a character array. I could drop the blob here, but in the end I think allowing for a blob to change the size should be fine.

But shouldn't this then also adjust the recorded size?

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
xen/common/hypfs.c new file +4 -0
+    buf = xmalloc_array(char, ulen);
+    if ( !buf )
+        return -ENOMEM;
+
Quoted 8 lines

xen/common/hypfs.c line 255

Quoted 6 lines
xen/common/hypfs.c new file +6 -0
+    ret = -EFAULT;
+    if ( copy_from_guest(buf, uaddr, ulen) )
+        goto out;
+
+    ret = -EINVAL;
+    if ( leaf->e.type == XEN_HYPFS_TYPE_STRING && !memchr(buf, 0, ulen) )

This should also use the != buf + ulen - 1 form imo.

Quoted 2 lines

I'm fine to change that, but should the hypervisor really refuse to accept a larger buffer?

To avoid ambiguity I'd prefer if the requirement was that the caller specify the length of the string (plus the nul char) rather than the size of any buffer it might be using.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#16 lore raw

Re: [Xen-devel] [PATCH v6 04/12] xen: add basic hypervisor filesystem support

Quoted 82 lines · Jan Beulich
Quoted 78 lines · Jürgen Groß
Quoted 18 lines · Jan Beulich
Quoted 17 lines · Juergen Gross
xen/common/hypfs.c new file +14 -0
@@ -0,0 +1,349 @@
+/******************************************************************************
+ *
+ * hypfs.c
+ *
+ * Simple sysfs-like file system for the hypervisor.
+ */
+
+#include <xen/err.h>
+#include <xen/guest_access.h>
+#include <xen/hypercall.h>
+#include <xen/hypfs.h>
+#include <xen/lib.h>
+#include <xen/rwlock.h>
+#include <public/hypfs.h>
Quoted 8 lines

xen/common/hypfs.c line 20

Quoted 6 lines
xen/common/hypfs.c new file +6 -0
+
+#ifdef CONFIG_COMPAT
+#include <compat/hypfs.h>
+CHECK_hypfs_direntry;
+#undef CHECK_hypfs_direntry
+#define CHECK_hypfs_direntry struct xen_hypfs_direntry

I'm struggling to see why you need this #undef and #define.

Without those I get:

In file included from /home/gross/xen/unstable/xen/include/compat/xen.h:3:0,
from /home/gross/xen/unstable/xen/include/xen/shared.h:6, from /home/gross/xen/unstable/xen/include/xen/sched.h:8, from /home/gross/xen/unstable/xen/include/asm/paging.h:29, from
/home/gross/xen/unstable/xen/include/asm/guest_access.h:1,
from
/home/gross/xen/unstable/xen/include/xen/guest_access.h:1,

                   from hypfs.c:9:
/home/gross/xen/unstable/xen/include/xen/compat.h:134:32: error:
redefinition of ‘__checkFstruct_hypfs_direntry__flags’
   #define CHECK_NAME_(k, n, tag) __check ## tag ## k ## _ ## n
                                  ^
/home/gross/xen/unstable/xen/include/xen/compat.h:166:34: note: in
definition of macro ‘CHECK_FIELD_COMMON_’
   static inline int __maybe_unused name(k xen_ ## n *x, k compat_ ## n *c) \
                                    ^~~~
/home/gross/xen/unstable/xen/include/xen/compat.h:176:28: note: in
expansion of macro ‘CHECK_NAME_’
       CHECK_FIELD_COMMON_(k, CHECK_NAME_(k, n ## __ ## f, F), n, f)
                              ^~~~~~~~~~~
/home/gross/xen/unstable/xen/include/compat/xlat.h:775:5: note: in
expansion of macro ‘CHECK_FIELD_’
       CHECK_FIELD_(struct, hypfs_direntry, flags); \
       ^~~~~~~~~~~~
/home/gross/xen/unstable/xen/include/compat/xlat.h:782:5: note: in
expansion of macro ‘CHECK_hypfs_direntry’
       CHECK_hypfs_direntry; \
       ^~~~~~~~~~~~~~~~~~~~
hypfs.c:19:1: note: in expansion of macro ‘CHECK_hypfs_dirlistentry’
   CHECK_hypfs_dirlistentry;
   ^~~~~~~~~~~~~~~~~~~~~~~~
/home/gross/xen/unstable/xen/include/xen/compat.h:134:32: note: previous
definition of ‘__checkFstruct_hypfs_direntry__flags’ was here
   #define CHECK_NAME_(k, n, tag) __check ## tag ## k ## _ ## n
                                  ^
/home/gross/xen/unstable/xen/include/xen/compat.h:166:34: note: in
definition of macro ‘CHECK_FIELD_COMMON_’
   static inline int __maybe_unused name(k xen_ ## n *x, k compat_ ## n *c) \
                                    ^~~~
/home/gross/xen/unstable/xen/include/xen/compat.h:176:28: note: in
expansion of macro ‘CHECK_NAME_’
       CHECK_FIELD_COMMON_(k, CHECK_NAME_(k, n ## __ ## f, F), n, f)
                              ^~~~~~~~~~~
/home/gross/xen/unstable/xen/include/compat/xlat.h:775:5: note: in
expansion of macro ‘CHECK_FIELD_’
       CHECK_FIELD_(struct, hypfs_direntry, flags); \
       ^~~~~~~~~~~~
Quoted 2 lines

hypfs.c:18:1: note: in expansion of macro ‘CHECK_hypfs_direntry’
CHECK_hypfs_direntry;

Quoted 3 lines

Which suggests to me that the explicit CHECK_hypfs_direntry invocation is unneeded, as it's getting verified as part of the invocation of CHECK_hypfs_dirlistentry.

Ah, right. This is working. Will change.

Quoted 18 lines
Quoted 18 lines
Quoted 17 lines

xen/common/hypfs.c line 244

Quoted 13 lines
xen/common/hypfs.c new file +12 -0
+int hypfs_write_leaf(struct hypfs_entry_leaf *leaf,
+                     XEN_GUEST_HANDLE_PARAM(void) uaddr, unsigned long ulen)
+{
+    char *buf;
+    int ret;
+
+    if ( ulen > leaf->e.size )
+        return -ENOSPC;
+
+    if ( leaf->e.type != XEN_HYPFS_TYPE_STRING &&
+         leaf->e.type != XEN_HYPFS_TYPE_BLOB && ulen != leaf->e.size )
+        return -EDOM;

Why the exception of string and blob? My concern about the meaning of a partially written entry (without its size having changed) remains.

Quoted 5 lines
Quoted 3 lines

It is perfectly valid to write a shorter string into a character array. I could drop the blob here, but in the end I think allowing for a blob to change the size should be fine.

But shouldn't this then also adjust the recorded size?

No, this is the max size of the buffer (you can have a look at patch 9 where the size is set to the provided space for custom and string parameters).

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines

xen/common/hypfs.c line 255

Quoted 11 lines
xen/common/hypfs.c new file +10 -0
+    buf = xmalloc_array(char, ulen);
+    if ( !buf )
+        return -ENOMEM;
+
+    ret = -EFAULT;
+    if ( copy_from_guest(buf, uaddr, ulen) )
+        goto out;
+
+    ret = -EINVAL;
+    if ( leaf->e.type == XEN_HYPFS_TYPE_STRING && !memchr(buf, 0, ulen) )

This should also use the != buf + ulen - 1 form imo.

Quoted 6 lines
Quoted 2 lines

I'm fine to change that, but should the hypervisor really refuse to accept a larger buffer?

To avoid ambiguity I'd prefer if the requirement was that the caller specify the length of the string (plus the nul char) rather than the size of any buffer it might be using.

Okay, I don't mind changing it then.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#17 lore raw

Re: [Xen-devel] [PATCH v6 04/12] xen: add basic hypervisor filesystem support

Quoted 111 lines · Jürgen Groß
Quoted 82 lines · Jan Beulich
Quoted 78 lines · Jürgen Groß
Quoted 18 lines · Jan Beulich
Quoted 17 lines · Juergen Gross
xen/common/hypfs.c new file +14 -0
@@ -0,0 +1,349 @@
+/******************************************************************************
+ *
+ * hypfs.c
+ *
+ * Simple sysfs-like file system for the hypervisor.
+ */
+
+#include <xen/err.h>
+#include <xen/guest_access.h>
+#include <xen/hypercall.h>
+#include <xen/hypfs.h>
+#include <xen/lib.h>
+#include <xen/rwlock.h>
+#include <public/hypfs.h>
Quoted 8 lines

xen/common/hypfs.c line 20

Quoted 6 lines
xen/common/hypfs.c new file +6 -0
+
+#ifdef CONFIG_COMPAT
+#include <compat/hypfs.h>
+CHECK_hypfs_direntry;
+#undef CHECK_hypfs_direntry
+#define CHECK_hypfs_direntry struct xen_hypfs_direntry

I'm struggling to see why you need this #undef and #define.

Without those I get:

In file included from /home/gross/xen/unstable/xen/include/compat/xen.h:3:0,
from /home/gross/xen/unstable/xen/include/xen/shared.h:6, from /home/gross/xen/unstable/xen/include/xen/sched.h:8, from /home/gross/xen/unstable/xen/include/asm/paging.h:29, from
/home/gross/xen/unstable/xen/include/asm/guest_access.h:1,
from
/home/gross/xen/unstable/xen/include/xen/guest_access.h:1,

                   from hypfs.c:9:
/home/gross/xen/unstable/xen/include/xen/compat.h:134:32: error:
redefinition of ‘__checkFstruct_hypfs_direntry__flags’
   #define CHECK_NAME_(k, n, tag) __check ## tag ## k ## _ ## n
                                  ^
/home/gross/xen/unstable/xen/include/xen/compat.h:166:34: note: in
definition of macro ‘CHECK_FIELD_COMMON_’
   static inline int __maybe_unused name(k xen_ ## n *x, k compat_ ## n *c) \
                                    ^~~~
/home/gross/xen/unstable/xen/include/xen/compat.h:176:28: note: in
expansion of macro ‘CHECK_NAME_’
       CHECK_FIELD_COMMON_(k, CHECK_NAME_(k, n ## __ ## f, F), n, f)
                              ^~~~~~~~~~~
/home/gross/xen/unstable/xen/include/compat/xlat.h:775:5: note: in
expansion of macro ‘CHECK_FIELD_’
       CHECK_FIELD_(struct, hypfs_direntry, flags); \
       ^~~~~~~~~~~~
/home/gross/xen/unstable/xen/include/compat/xlat.h:782:5: note: in
expansion of macro ‘CHECK_hypfs_direntry’
       CHECK_hypfs_direntry; \
       ^~~~~~~~~~~~~~~~~~~~
hypfs.c:19:1: note: in expansion of macro ‘CHECK_hypfs_dirlistentry’
   CHECK_hypfs_dirlistentry;
   ^~~~~~~~~~~~~~~~~~~~~~~~
/home/gross/xen/unstable/xen/include/xen/compat.h:134:32: note: previous
definition of ‘__checkFstruct_hypfs_direntry__flags’ was here
   #define CHECK_NAME_(k, n, tag) __check ## tag ## k ## _ ## n
                                  ^
/home/gross/xen/unstable/xen/include/xen/compat.h:166:34: note: in
definition of macro ‘CHECK_FIELD_COMMON_’
   static inline int __maybe_unused name(k xen_ ## n *x, k compat_ ## n *c) \
                                    ^~~~
/home/gross/xen/unstable/xen/include/xen/compat.h:176:28: note: in
expansion of macro ‘CHECK_NAME_’
       CHECK_FIELD_COMMON_(k, CHECK_NAME_(k, n ## __ ## f, F), n, f)
                              ^~~~~~~~~~~
/home/gross/xen/unstable/xen/include/compat/xlat.h:775:5: note: in
expansion of macro ‘CHECK_FIELD_’
       CHECK_FIELD_(struct, hypfs_direntry, flags); \
       ^~~~~~~~~~~~
Quoted 2 lines

hypfs.c:18:1: note: in expansion of macro ‘CHECK_hypfs_direntry’
CHECK_hypfs_direntry;

Quoted 3 lines

Which suggests to me that the explicit CHECK_hypfs_direntry invocation is unneeded, as it's getting verified as part of the invocation of CHECK_hypfs_dirlistentry.

Ah, right. This is working. Will change.

Quoted 22 lines
Quoted 21 lines
Quoted 17 lines

xen/common/hypfs.c line 244

Quoted 13 lines
xen/common/hypfs.c new file +12 -0
+int hypfs_write_leaf(struct hypfs_entry_leaf *leaf,
+                     XEN_GUEST_HANDLE_PARAM(void) uaddr, unsigned long ulen)
+{
+    char *buf;
+    int ret;
+
+    if ( ulen > leaf->e.size )
+        return -ENOSPC;
+
+    if ( leaf->e.type != XEN_HYPFS_TYPE_STRING &&
+         leaf->e.type != XEN_HYPFS_TYPE_BLOB && ulen != leaf->e.size )
+        return -EDOM;

Why the exception of string and blob? My concern about the meaning of a partially written entry (without its size having changed) remains.

It is perfectly valid to write a shorter string into a character array. I could drop the blob here, but in the end I think allowing for a blob to change the size should be fine.

Quoted 5 lines
Quoted 1 line

But shouldn't this then also adjust the recorded size?

No, this is the max size of the buffer (you can have a look at patch 9 where the size is set to the provided space for custom and string parameters).

If I'm not mistaken it is hypfs_read_leaf() which processes read requests for strings. Yet that copies entry->size bytes, not the potentially smaller strlen()-bounded payload. Things would be even worse for BLOB-type entries, where one couldn't even look for a nul terminator to determine actual payload size.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#18 lore raw

Re: [Xen-devel] [PATCH v6 04/12] xen: add basic hypervisor filesystem support

Quoted 114 lines · Jan Beulich
Quoted 113 lines · Jürgen Groß
Quoted 82 lines · Jan Beulich
Quoted 72 lines · Jürgen Groß
Quoted 18 lines · Jan Beulich
Quoted 17 lines · Juergen Gross
xen/common/hypfs.c new file +14 -0
@@ -0,0 +1,349 @@
+/******************************************************************************
+ *
+ * hypfs.c
+ *
+ * Simple sysfs-like file system for the hypervisor.
+ */
+
+#include <xen/err.h>
+#include <xen/guest_access.h>
+#include <xen/hypercall.h>
+#include <xen/hypfs.h>
+#include <xen/lib.h>
+#include <xen/rwlock.h>
+#include <public/hypfs.h>
Quoted 8 lines

xen/common/hypfs.c line 20

Quoted 6 lines
xen/common/hypfs.c new file +6 -0
+
+#ifdef CONFIG_COMPAT
+#include <compat/hypfs.h>
+CHECK_hypfs_direntry;
+#undef CHECK_hypfs_direntry
+#define CHECK_hypfs_direntry struct xen_hypfs_direntry

I'm struggling to see why you need this #undef and #define.

Without those I get:

In file included from /home/gross/xen/unstable/xen/include/compat/xen.h:3:0,
from /home/gross/xen/unstable/xen/include/xen/shared.h:6, from /home/gross/xen/unstable/xen/include/xen/sched.h:8, from /home/gross/xen/unstable/xen/include/asm/paging.h:29, from
/home/gross/xen/unstable/xen/include/asm/guest_access.h:1,
from
/home/gross/xen/unstable/xen/include/xen/guest_access.h:1,

                    from hypfs.c:9:
/home/gross/xen/unstable/xen/include/xen/compat.h:134:32: error:
redefinition of ‘__checkFstruct_hypfs_direntry__flags’
    #define CHECK_NAME_(k, n, tag) __check ## tag ## k ## _ ## n
                                   ^
/home/gross/xen/unstable/xen/include/xen/compat.h:166:34: note: in
definition of macro ‘CHECK_FIELD_COMMON_’
    static inline int __maybe_unused name(k xen_ ## n *x, k compat_ ## n *c) \
                                     ^~~~
/home/gross/xen/unstable/xen/include/xen/compat.h:176:28: note: in
expansion of macro ‘CHECK_NAME_’
        CHECK_FIELD_COMMON_(k, CHECK_NAME_(k, n ## __ ## f, F), n, f)
                               ^~~~~~~~~~~
/home/gross/xen/unstable/xen/include/compat/xlat.h:775:5: note: in
expansion of macro ‘CHECK_FIELD_’
        CHECK_FIELD_(struct, hypfs_direntry, flags); \
        ^~~~~~~~~~~~
/home/gross/xen/unstable/xen/include/compat/xlat.h:782:5: note: in
expansion of macro ‘CHECK_hypfs_direntry’
        CHECK_hypfs_direntry; \
        ^~~~~~~~~~~~~~~~~~~~
hypfs.c:19:1: note: in expansion of macro ‘CHECK_hypfs_dirlistentry’
    CHECK_hypfs_dirlistentry;
    ^~~~~~~~~~~~~~~~~~~~~~~~
/home/gross/xen/unstable/xen/include/xen/compat.h:134:32: note: previous
definition of ‘__checkFstruct_hypfs_direntry__flags’ was here
    #define CHECK_NAME_(k, n, tag) __check ## tag ## k ## _ ## n
                                   ^
/home/gross/xen/unstable/xen/include/xen/compat.h:166:34: note: in
definition of macro ‘CHECK_FIELD_COMMON_’
    static inline int __maybe_unused name(k xen_ ## n *x, k compat_ ## n *c) \
                                     ^~~~

/home/gross/xen/unstable/xen/include/xen/compat.h:176:28: note: in expansion of macro ‘CHECK_NAME_’

Quoted 8 lines
        CHECK_FIELD_COMMON_(k, CHECK_NAME_(k, n ## __ ## f, F), n, f)
                               ^~~~~~~~~~~
/home/gross/xen/unstable/xen/include/compat/xlat.h:775:5: note: in
expansion of macro ‘CHECK_FIELD_’
        CHECK_FIELD_(struct, hypfs_direntry, flags); \
        ^~~~~~~~~~~~
hypfs.c:18:1: note: in expansion of macro ‘CHECK_hypfs_direntry’
    CHECK_hypfs_direntry;
Quoted 3 lines

Which suggests to me that the explicit CHECK_hypfs_direntry invocation is unneeded, as it's getting verified as part of the invocation of CHECK_hypfs_dirlistentry.

Ah, right. This is working. Will change.

Quoted 23 lines
Quoted 18 lines
Quoted 17 lines

xen/common/hypfs.c line 244

Quoted 13 lines
xen/common/hypfs.c new file +12 -0
+int hypfs_write_leaf(struct hypfs_entry_leaf *leaf,
+                     XEN_GUEST_HANDLE_PARAM(void) uaddr, unsigned long ulen)
+{
+    char *buf;
+    int ret;
+
+    if ( ulen > leaf->e.size )
+        return -ENOSPC;
+
+    if ( leaf->e.type != XEN_HYPFS_TYPE_STRING &&
+         leaf->e.type != XEN_HYPFS_TYPE_BLOB && ulen != leaf->e.size )
+        return -EDOM;

Why the exception of string and blob? My concern about the meaning of a partially written entry (without its size having changed) remains.

Quoted 3 lines

It is perfectly valid to write a shorter string into a character array. I could drop the blob here, but in the end I think allowing for a blob to change the size should be fine.

But shouldn't this then also adjust the recorded size?

Quoted 7 lines
Quoted 3 lines

No, this is the max size of the buffer (you can have a look at patch 9 where the size is set to the provided space for custom and string parameters).

If I'm not mistaken it is hypfs_read_leaf() which processes read requests for strings. Yet that copies entry->size bytes, not the potentially smaller strlen()-bounded payload. Things would be

There is no risk of leaking problematic data here.

Quoted 2 lines

even worse for BLOB-type entries, where one couldn't even look for a nul terminator to determine actual payload size.

Right, this would probably require a blob-specific read function, in case the blob is of variable length.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#19 lore raw

Re: [Xen-devel] [PATCH v6 04/12] xen: add basic hypervisor filesystem support

Quoted 119 lines · Jürgen Groß
Quoted 118 lines · Jan Beulich
Quoted 116 lines · Jürgen Groß
Quoted 82 lines · Jan Beulich
Quoted 72 lines · Jürgen Groß
Quoted 18 lines · Jan Beulich
Quoted 17 lines · Juergen Gross
xen/common/hypfs.c new file +14 -0
@@ -0,0 +1,349 @@
+/******************************************************************************
+ *
+ * hypfs.c
+ *
+ * Simple sysfs-like file system for the hypervisor.
+ */
+
+#include <xen/err.h>
+#include <xen/guest_access.h>
+#include <xen/hypercall.h>
+#include <xen/hypfs.h>
+#include <xen/lib.h>
+#include <xen/rwlock.h>
+#include <public/hypfs.h>
Quoted 8 lines

xen/common/hypfs.c line 20

Quoted 6 lines
xen/common/hypfs.c new file +6 -0
+
+#ifdef CONFIG_COMPAT
+#include <compat/hypfs.h>
+CHECK_hypfs_direntry;
+#undef CHECK_hypfs_direntry
+#define CHECK_hypfs_direntry struct xen_hypfs_direntry

I'm struggling to see why you need this #undef and #define.

Without those I get:

In file included from /home/gross/xen/unstable/xen/include/compat/xen.h:3:0,
from /home/gross/xen/unstable/xen/include/xen/shared.h:6, from /home/gross/xen/unstable/xen/include/xen/sched.h:8, from /home/gross/xen/unstable/xen/include/asm/paging.h:29, from
/home/gross/xen/unstable/xen/include/asm/guest_access.h:1,
from
/home/gross/xen/unstable/xen/include/xen/guest_access.h:1,

                    from hypfs.c:9:
/home/gross/xen/unstable/xen/include/xen/compat.h:134:32: error:
redefinition of ‘__checkFstruct_hypfs_direntry__flags’
    #define CHECK_NAME_(k, n, tag) __check ## tag ## k ## _ ## n
                                   ^
/home/gross/xen/unstable/xen/include/xen/compat.h:166:34: note: in
definition of macro ‘CHECK_FIELD_COMMON_’
    static inline int __maybe_unused name(k xen_ ## n *x, k compat_ ## n *c) \
                                     ^~~~
/home/gross/xen/unstable/xen/include/xen/compat.h:176:28: note: in
expansion of macro ‘CHECK_NAME_’
        CHECK_FIELD_COMMON_(k, CHECK_NAME_(k, n ## __ ## f, F), n, f)
                               ^~~~~~~~~~~
/home/gross/xen/unstable/xen/include/compat/xlat.h:775:5: note: in
expansion of macro ‘CHECK_FIELD_’
        CHECK_FIELD_(struct, hypfs_direntry, flags); \
        ^~~~~~~~~~~~
/home/gross/xen/unstable/xen/include/compat/xlat.h:782:5: note: in
expansion of macro ‘CHECK_hypfs_direntry’
        CHECK_hypfs_direntry; \
        ^~~~~~~~~~~~~~~~~~~~
hypfs.c:19:1: note: in expansion of macro ‘CHECK_hypfs_dirlistentry’
    CHECK_hypfs_dirlistentry;
    ^~~~~~~~~~~~~~~~~~~~~~~~
/home/gross/xen/unstable/xen/include/xen/compat.h:134:32: note: previous
definition of ‘__checkFstruct_hypfs_direntry__flags’ was here
    #define CHECK_NAME_(k, n, tag) __check ## tag ## k ## _ ## n
                                   ^
/home/gross/xen/unstable/xen/include/xen/compat.h:166:34: note: in
definition of macro ‘CHECK_FIELD_COMMON_’
    static inline int __maybe_unused name(k xen_ ## n *x, k compat_ ## n *c) \
                                     ^~~~

/home/gross/xen/unstable/xen/include/xen/compat.h:176:28: note: in expansion of macro ‘CHECK_NAME_’

Quoted 8 lines
        CHECK_FIELD_COMMON_(k, CHECK_NAME_(k, n ## __ ## f, F), n, f)
                               ^~~~~~~~~~~
/home/gross/xen/unstable/xen/include/compat/xlat.h:775:5: note: in
expansion of macro ‘CHECK_FIELD_’
        CHECK_FIELD_(struct, hypfs_direntry, flags); \
        ^~~~~~~~~~~~
hypfs.c:18:1: note: in expansion of macro ‘CHECK_hypfs_direntry’
    CHECK_hypfs_direntry;
Quoted 3 lines

Which suggests to me that the explicit CHECK_hypfs_direntry invocation is unneeded, as it's getting verified as part of the invocation of CHECK_hypfs_dirlistentry.

Ah, right. This is working. Will change.

Quoted 18 lines
Quoted 18 lines
Quoted 17 lines

xen/common/hypfs.c line 32

Quoted 13 lines
xen/common/hypfs.c new file +12 -0
+int hypfs_write_leaf(struct hypfs_entry_leaf *leaf,
+                     XEN_GUEST_HANDLE_PARAM(void) uaddr, unsigned long ulen)
+{
+    char *buf;
+    int ret;
+
+    if ( ulen > leaf->e.size )
+        return -ENOSPC;
+
+    if ( leaf->e.type != XEN_HYPFS_TYPE_STRING &&
+         leaf->e.type != XEN_HYPFS_TYPE_BLOB && ulen != leaf->e.size )
+        return -EDOM;

Why the exception of string and blob? My concern about the meaning of a partially written entry (without its size having changed) remains.

Quoted 5 lines
Quoted 3 lines

It is perfectly valid to write a shorter string into a character array. I could drop the blob here, but in the end I think allowing for a blob to change the size should be fine.

But shouldn't this then also adjust the recorded size?

No, this is the max size of the buffer (you can have a look at patch 9 where the size is set to the provided space for custom and string parameters).

Quoted 5 lines
Quoted 3 lines

If I'm not mistaken it is hypfs_read_leaf() which processes read requests for strings. Yet that copies entry->size bytes, not the potentially smaller strlen()-bounded payload. Things would be

There is no risk of leaking problematic data here.

I didn't think of leaks, but rather of consumers looking at the size and strlen() and getting confused about the mismatch.

Jan

Quoted 9 lines
Quoted 2 lines

even worse for BLOB-type entries, where one couldn't even look for a nul terminator to determine actual payload size.

Right, this would probably require a blob-specific read function, in case the blob is of variable length.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#20 lore raw

Re: [Xen-devel] [PATCH v6 04/12] xen: add basic hypervisor filesystem support

Quoted 120 lines · Jan Beulich
Quoted 119 lines · Jürgen Groß
Quoted 118 lines · Jan Beulich
Quoted 116 lines · Jürgen Groß
Quoted 82 lines · Jan Beulich
Quoted 72 lines · Jürgen Groß
Quoted 18 lines · Jan Beulich
Quoted 17 lines · Juergen Gross
xen/common/hypfs.c new file +14 -0
@@ -0,0 +1,349 @@
+/******************************************************************************
+ *
+ * hypfs.c
+ *
+ * Simple sysfs-like file system for the hypervisor.
+ */
+
+#include <xen/err.h>
+#include <xen/guest_access.h>
+#include <xen/hypercall.h>
+#include <xen/hypfs.h>
+#include <xen/lib.h>
+#include <xen/rwlock.h>
+#include <public/hypfs.h>
Quoted 8 lines

xen/common/hypfs.c line 20

Quoted 6 lines
xen/common/hypfs.c new file +6 -0
+
+#ifdef CONFIG_COMPAT
+#include <compat/hypfs.h>
+CHECK_hypfs_direntry;
+#undef CHECK_hypfs_direntry
+#define CHECK_hypfs_direntry struct xen_hypfs_direntry

I'm struggling to see why you need this #undef and #define.

Without those I get:

In file included from /home/gross/xen/unstable/xen/include/compat/xen.h:3:0,
from /home/gross/xen/unstable/xen/include/xen/shared.h:6, from /home/gross/xen/unstable/xen/include/xen/sched.h:8, from /home/gross/xen/unstable/xen/include/asm/paging.h:29, from
/home/gross/xen/unstable/xen/include/asm/guest_access.h:1,
from
/home/gross/xen/unstable/xen/include/xen/guest_access.h:1,

                     from hypfs.c:9:
/home/gross/xen/unstable/xen/include/xen/compat.h:134:32: error:
redefinition of ‘__checkFstruct_hypfs_direntry__flags’
     #define CHECK_NAME_(k, n, tag) __check ## tag ## k ## _ ## n
                                    ^
/home/gross/xen/unstable/xen/include/xen/compat.h:166:34: note: in
definition of macro ‘CHECK_FIELD_COMMON_’
     static inline int __maybe_unused name(k xen_ ## n *x, k compat_ ## n *c) \
                                      ^~~~
/home/gross/xen/unstable/xen/include/xen/compat.h:176:28: note: in
expansion of macro ‘CHECK_NAME_’
         CHECK_FIELD_COMMON_(k, CHECK_NAME_(k, n ## __ ## f, F), n, f)
                                ^~~~~~~~~~~
/home/gross/xen/unstable/xen/include/compat/xlat.h:775:5: note: in
expansion of macro ‘CHECK_FIELD_’
         CHECK_FIELD_(struct, hypfs_direntry, flags); \
         ^~~~~~~~~~~~
/home/gross/xen/unstable/xen/include/compat/xlat.h:782:5: note: in
expansion of macro ‘CHECK_hypfs_direntry’
         CHECK_hypfs_direntry; \
         ^~~~~~~~~~~~~~~~~~~~
hypfs.c:19:1: note: in expansion of macro ‘CHECK_hypfs_dirlistentry’
     CHECK_hypfs_dirlistentry;
     ^~~~~~~~~~~~~~~~~~~~~~~~
/home/gross/xen/unstable/xen/include/xen/compat.h:134:32: note: previous
definition of ‘__checkFstruct_hypfs_direntry__flags’ was here
     #define CHECK_NAME_(k, n, tag) __check ## tag ## k ## _ ## n
                                    ^
/home/gross/xen/unstable/xen/include/xen/compat.h:166:34: note: in
definition of macro ‘CHECK_FIELD_COMMON_’
     static inline int __maybe_unused name(k xen_ ## n *x, k compat_ ## n *c) \
                                      ^~~~

/home/gross/xen/unstable/xen/include/xen/compat.h:176:28: note: in expansion of macro ‘CHECK_NAME_’

Quoted 8 lines
         CHECK_FIELD_COMMON_(k, CHECK_NAME_(k, n ## __ ## f, F), n, f)
                                ^~~~~~~~~~~
/home/gross/xen/unstable/xen/include/compat/xlat.h:775:5: note: in
expansion of macro ‘CHECK_FIELD_’
         CHECK_FIELD_(struct, hypfs_direntry, flags); \
         ^~~~~~~~~~~~
hypfs.c:18:1: note: in expansion of macro ‘CHECK_hypfs_direntry’
     CHECK_hypfs_direntry;
Quoted 3 lines

Which suggests to me that the explicit CHECK_hypfs_direntry invocation is unneeded, as it's getting verified as part of the invocation of CHECK_hypfs_dirlistentry.

Ah, right. This is working. Will change.

Quoted 18 lines
Quoted 18 lines
Quoted 17 lines

xen/common/hypfs.c line 32

Quoted 13 lines
xen/common/hypfs.c new file +12 -0
+int hypfs_write_leaf(struct hypfs_entry_leaf *leaf,
+                     XEN_GUEST_HANDLE_PARAM(void) uaddr, unsigned long ulen)
+{
+    char *buf;
+    int ret;
+
+    if ( ulen > leaf->e.size )
+        return -ENOSPC;
+
+    if ( leaf->e.type != XEN_HYPFS_TYPE_STRING &&
+         leaf->e.type != XEN_HYPFS_TYPE_BLOB && ulen != leaf->e.size )
+        return -EDOM;

Why the exception of string and blob? My concern about the meaning of a partially written entry (without its size having changed) remains.

Quoted 5 lines
Quoted 3 lines

It is perfectly valid to write a shorter string into a character array. I could drop the blob here, but in the end I think allowing for a blob to change the size should be fine.

But shouldn't this then also adjust the recorded size?

No, this is the max size of the buffer (you can have a look at patch 9 where the size is set to the provided space for custom and string parameters).

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

If I'm not mistaken it is hypfs_read_leaf() which processes read requests for strings. Yet that copies entry->size bytes, not the potentially smaller strlen()-bounded payload. Things would be

There is no risk of leaking problematic data here.

I didn't think of leaks, but rather of consumers looking at the size and strlen() and getting confused about the mismatch.

I think telling the maximum possible write length is mandatory.

So either I can add a comment to the header saying that for strings and blobs the length is the maximum value and the content is to be self-descriptive regarding its true length (which is the case for strings due to the terminating 0 byte), or I need two size fields:
one for the actual size and one for the maximum allowed size for writes (this could then replace the writable flag with "0" for "not writable").

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#21 lore raw

Re: [Xen-devel] [PATCH v6 04/12] xen: add basic hypervisor filesystem support

Quoted 27 lines · Jürgen Groß
Quoted 15 lines · Jan Beulich
Quoted 14 lines · Jürgen Groß
Quoted 13 lines · Jan Beulich
Quoted 11 lines · Jürgen Groß
Quoted 6 lines · Jan Beulich
Quoted 3 lines · Jürgen Groß

It is perfectly valid to write a shorter string into a character array. I could drop the blob here, but in the end I think allowing for a blob to change the size should be fine.

But shouldn't this then also adjust the recorded size?

No, this is the max size of the buffer (you can have a look at patch 9 where the size is set to the provided space for custom and string parameters).

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

If I'm not mistaken it is hypfs_read_leaf() which processes read requests for strings. Yet that copies entry->size bytes, not the potentially smaller strlen()-bounded payload. Things would be

There is no risk of leaking problematic data here.

I didn't think of leaks, but rather of consumers looking at the size and strlen() and getting confused about the mismatch.

I think telling the maximum possible write length is mandatory.

Quoted 7 lines

So either I can add a comment to the header saying that for strings and blobs the length is the maximum value and the content is to be self-descriptive regarding its true length (which is the case for strings due to the terminating 0 byte), or I need two size fields:
one for the actual size and one for the maximum allowed size for writes (this could then replace the writable flag with "0" for "not writable").

Personally I'd prefer the latter, but I could also live with a comment. The self-descriptive part may, for blobs or gzip-ed data, be problematic though.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#22 lore raw

PATCH v6 5/12 libs: add libxenhypfs

In reply to Juergen Gross

Add the new library libxenhypfs for access to the hypervisor filesystem.

---
V1:
- rename to libxenhypfs
- add xenhypfs_write()

V3:
- major rework due to new hypervisor interface
- add decompression capability

V4:
- add dependency to libz in pkgconfig file (Wei Liu)

---
 .gitignore                          |   2 +
 tools/Rules.mk                      |   6 +
 tools/libs/Makefile                 |   1 +
 tools/libs/hypfs/Makefile           |  16 ++
 tools/libs/hypfs/core.c             | 540 ++++++++++++++++++++++++++++++++++++
 tools/libs/hypfs/include/xenhypfs.h |  75 +++++
 tools/libs/hypfs/libxenhypfs.map    |  10 +
 tools/libs/hypfs/xenhypfs.pc.in     |  10 +
 8 files changed, 660 insertions(+)
 create mode 100644 tools/libs/hypfs/Makefile
 create mode 100644 tools/libs/hypfs/core.c
 create mode 100644 tools/libs/hypfs/include/xenhypfs.h
 create mode 100644 tools/libs/hypfs/libxenhypfs.map
 create mode 100644 tools/libs/hypfs/xenhypfs.pc.in
.gitignore +2 -0
index b2624df79a..e98c3f056d 100644
@@ -109,6 +109,8 @@ tools/libs/evtchn/headers.chk
 tools/libs/evtchn/xenevtchn.pc
 tools/libs/gnttab/headers.chk
 tools/libs/gnttab/xengnttab.pc
+tools/libs/hypfs/headers.chk
+tools/libs/hypfs/xenhypfs.pc
 tools/libs/call/headers.chk
 tools/libs/call/xencall.pc
 tools/libs/foreignmemory/headers.chk
tools/Rules.mk +6 -0
index 52f47be3f8..a04697a33c 100644
@@ -19,6 +19,7 @@ XEN_LIBXENGNTTAB   = $(XEN_ROOT)/tools/libs/gnttab
 XEN_LIBXENCALL     = $(XEN_ROOT)/tools/libs/call
 XEN_LIBXENFOREIGNMEMORY = $(XEN_ROOT)/tools/libs/foreignmemory
 XEN_LIBXENDEVICEMODEL = $(XEN_ROOT)/tools/libs/devicemodel
+XEN_LIBXENHYPFS    = $(XEN_ROOT)/tools/libs/hypfs
 XEN_LIBXC          = $(XEN_ROOT)/tools/libxc
 XEN_XENLIGHT       = $(XEN_ROOT)/tools/libxl
 # Currently libxlutil lives in the same directory as libxenlight
@@ -134,6 +135,11 @@ SHDEPS_libxendevicemodel = $(SHLIB_libxentoollog) $(SHLIB_libxentoolcore) $(SHLI
 LDLIBS_libxendevicemodel = $(SHDEPS_libxendevicemodel) $(XEN_LIBXENDEVICEMODEL)/libxendevicemodel$(libextension)
 SHLIB_libxendevicemodel  = $(SHDEPS_libxendevicemodel) -Wl,-rpath-link=$(XEN_LIBXENDEVICEMODEL)
 
+CFLAGS_libxenhypfs = -I$(XEN_LIBXENHYPFS)/include $(CFLAGS_xeninclude)
+SHDEPS_libxenhypfs = $(SHLIB_libxentoollog) $(SHLIB_libxentoolcore) $(SHLIB_xencall)
+LDLIBS_libxenhypfs = $(SHDEPS_libxenhypfs) $(XEN_LIBXENHYPFS)/libxenhypfs$(libextension)
+SHLIB_libxenhypfs  = $(SHDEPS_libxenhypfs) -Wl,-rpath-link=$(XEN_LIBXENHYPFS)
+
 # code which compiles against libxenctrl get __XEN_TOOLS__ and
 # therefore sees the unstable hypercall interfaces.
 CFLAGS_libxenctrl = -I$(XEN_LIBXC)/include $(CFLAGS_libxentoollog) $(CFLAGS_libxenforeignmemory) $(CFLAGS_libxendevicemodel) $(CFLAGS_xeninclude) -D__XEN_TOOLS__
tools/libs/Makefile +1 -0
index 88901e7341..69cdfb5975 100644
@@ -9,6 +9,7 @@ SUBDIRS-y += gnttab
 SUBDIRS-y += call
 SUBDIRS-y += foreignmemory
 SUBDIRS-y += devicemodel
+SUBDIRS-y += hypfs
 
 ifeq ($(CONFIG_RUMP),y)
 SUBDIRS-y := toolcore
tools/libs/hypfs/Makefile new file +16 -0
new file mode 100644
index 0000000000..06dd449929
@@ -0,0 +1,16 @@
+XEN_ROOT = $(CURDIR)/../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+MAJOR    = 1
+MINOR    = 0
+LIBNAME  := hypfs
+USELIBS  := toollog toolcore call
+
+APPEND_LDFLAGS += -lz
+
+SRCS-y                 += core.c
+
+include ../libs.mk
+
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_LIBXENHYPFS)/include
+$(PKG_CONFIG_LOCAL): PKG_CONFIG_CFLAGS_LOCAL = $(CFLAGS_xeninclude)
tools/libs/hypfs/core.c new file +540 -0

540 lines not on this page · raw message

tools/libs/hypfs/include/xenhypfs.h new file +75 -0

75 lines not on this page · raw message

tools/libs/hypfs/libxenhypfs.map new file +10 -0
new file mode 100644
index 0000000000..47f1edda3e
@@ -0,0 +1,10 @@
+VERS_1.0 {
+	global:
+		xenhypfs_open;
+		xenhypfs_close;
+		xenhypfs_read_raw;
+		xenhypfs_read;
+		xenhypfs_readdir;
+		xenhypfs_write;
+	local: *; /* Do not expose anything by default */
+};
tools/libs/hypfs/xenhypfs.pc.in new file +10 -0
new file mode 100644
index 0000000000..92a262c7a2
@@ -0,0 +1,10 @@
+prefix=@@prefix@@
+includedir=@@incdir@@
+libdir=@@libdir@@
+
+Name: Xenhypfs
+Description: The Xenhypfs library for Xen hypervisor
+Version: @@version@@
+Cflags: -I${includedir} @@cflagslocal@@
+Libs: @@libsflag@@${libdir} -lxenhypfs
+Requires.private: xentoolcore,xentoollog,xencall,z
Signature · 7 lines
2.16.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#23 lore raw

PATCH v6 6/12 tools: add xenfs tool

In reply to Juergen Gross

Add the xenfs tool for accessing the hypervisor filesystem.

---
V1:
- rename to xenhypfs
- don't use "--" for subcommands
- add write support

V2:
- escape non-printable characters per default with cat subcommand (Ian Jackson)
- add -b option to cat subcommand (Ian Jackson)
- add man page

V3:
- adapt to new hypfs interface

---
 .gitignore              |   1 +
 docs/man/xenhypfs.1.pod |  61 ++++++++++++++++
 tools/misc/Makefile     |   6 ++
 tools/misc/xenhypfs.c   | 189 ++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 257 insertions(+)
 create mode 100644 docs/man/xenhypfs.1.pod
 create mode 100644 tools/misc/xenhypfs.c
.gitignore +1 -0
index e98c3f056d..fd5610718d 100644
@@ -367,6 +367,7 @@ tools/libxl/test_timedereg
 tools/libxl/test_fdderegrace
 tools/firmware/etherboot/eb-roms.h
 tools/firmware/etherboot/gpxe-git-snapshot.tar.gz
+tools/misc/xenhypfs
 tools/misc/xenwatchdogd
 tools/misc/xen-hvmcrash
 tools/misc/xen-lowmemd
docs/man/xenhypfs.1.pod new file +61 -0

61 lines not on this page · raw message

tools/misc/Makefile +6 -0
index 63947bfadc..9fdb13597f 100644
@@ -24,6 +24,7 @@ INSTALL_SBIN-$(CONFIG_X86)     += xen-lowmemd
 INSTALL_SBIN-$(CONFIG_X86)     += xen-mfndump
 INSTALL_SBIN-$(CONFIG_X86)     += xen-ucode
 INSTALL_SBIN                   += xencov
+INSTALL_SBIN                   += xenhypfs
 INSTALL_SBIN                   += xenlockprof
 INSTALL_SBIN                   += xenperf
 INSTALL_SBIN                   += xenpm
@@ -86,6 +87,9 @@ xenperf: xenperf.o
 xenpm: xenpm.o
 	$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
 
+xenhypfs: xenhypfs.o
+	$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenhypfs) $(APPEND_LDFLAGS)
+
 xenlockprof: xenlockprof.o
 	$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
 
@@ -94,6 +98,8 @@ xen-hptool.o: CFLAGS += -I$(XEN_ROOT)/tools/libxc $(CFLAGS_libxencall)
 xen-hptool: xen-hptool.o
 	$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) $(APPEND_LDFLAGS)
 
+xenhypfs.o: CFLAGS += $(CFLAGS_libxenhypfs)
+
 # xen-mfndump incorrectly uses libxc internals
 xen-mfndump.o: CFLAGS += -I$(XEN_ROOT)/tools/libxc $(CFLAGS_libxencall)
 xen-mfndump: xen-mfndump.o
tools/misc/xenhypfs.c new file +189 -0

189 lines not on this page · raw message

Signature · 7 lines
2.16.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#24 lore raw

PATCH v6 7/12 xen: provide version information in hypfs

In reply to Juergen Gross

Provide version and compile information in /buildinfo/ node of the Xen hypervisor file system. As this information is accessible by dom0 only no additional security problem arises.

---
V3:
- new patch

V4:
- add __read_mostly annotations (Jan Beulich)

---
 docs/misc/hypfs-paths.pandoc | 45 ++++++++++++++++++++++++++++++++++++++++++++
 xen/common/kernel.c          | 45 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 90 insertions(+)
docs/misc/hypfs-paths.pandoc +45 -0
index b9f50f6998..e392feff27 100644
@@ -103,3 +103,48 @@ A populated Xen hypervisor file system might look like the following example:
 #### /
 
 The root of the hypervisor file system.
+
+#### /buildinfo/
+
+A directory containing static information generated while building the
+hypervisor.
+
+#### /buildinfo/changeset = STRING
+
+Git commit of the hypervisor.
+
+#### /buildinfo/compileinfo/
+
+A directory containing information about compilation of Xen.
+
+#### /buildinfo/compileinfo/compile_by = STRING
+
+Information who compiled the hypervisor.
+
+#### /buildinfo/compileinfo/compile_date = STRING
+
+Date of the hypervisor compilation.
+
+#### /buildinfo/compileinfo/compile_domain = STRING
+
+Information about the compile domain.
+
+#### /buildinfo/compileinfo/compiler = STRING
+
+The compiler used to build Xen.
+
+#### /buildinfo/version/
+
+A directory containing version information of the hypervisor.
+
+#### /buildinfo/version/extra = STRING
+
+Extra version information.
+
+#### /buildinfo/version/major = INTEGER
+
+The major version of Xen.
+
+#### /buildinfo/version/minor = INTEGER
+
+The minor version of Xen.
xen/common/kernel.c +45 -0

57 lines not on this page · raw message

Signature · 7 lines
2.16.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#25 lore raw

PATCH v6 8/12 xen: add /buildinfo/config entry to hypervisor filesystem

In reply to Juergen Gross

Add the /buildinfo/config entry to the hypervisor filesystem. This entry contains the .config file used to build the hypervisor.

---
V3:
- store data in gzip format
- use binfile mechanism to create data file
- move code to kernel.c

V6:
- add config item for the /buildinfo/config (Jan Beulich)
- make config related variables const in kernel.h (Jan Beulich)

---
 .gitignore                   |  2 ++
 docs/misc/hypfs-paths.pandoc |  4 ++++
 xen/common/Kconfig           | 10 ++++++++++
 xen/common/Makefile          | 12 ++++++++++++
 xen/common/kernel.c          | 15 +++++++++++++++
 xen/include/xen/kernel.h     |  3 +++
 6 files changed, 46 insertions(+)
.gitignore +2 -0
index fd5610718d..bc8e053ccb 100644
@@ -297,6 +297,8 @@ xen/arch/*/efi/boot.c
 xen/arch/*/efi/compat.c
 xen/arch/*/efi/efi.h
 xen/arch/*/efi/runtime.c
+xen/common/config_data.S
+xen/common/config.gz
 xen/include/headers*.chk
 xen/include/asm
 xen/include/asm-*/asm-offsets.h
docs/misc/hypfs-paths.pandoc +4 -0
index e392feff27..1faebcccbc 100644
@@ -133,6 +133,10 @@ Information about the compile domain.
 
 The compiler used to build Xen.
 
+#### /buildinfo/config = STRING
+
+The contents of the `xen/.config` file at the time of the hypervisor build.
+
 #### /buildinfo/version/
 
 A directory containing version information of the hypervisor.
xen/common/Kconfig +10 -0
index a6914fcae9..c3303c8dfe 100644
@@ -353,6 +353,16 @@ config DOM0_MEM
 
 	  Leave empty if you are not sure what to specify.
 
+config HYPFS_CONFIG
+	bool "Provide hypervisor .config via hypfs entry"
+	default y
+	---help---
+	  When enabled the contents of the .config file used to build the
+	  hypervisor are provided via the hypfs entry /buildinfo/config.
+
+	  Disable this option in case you want to spare some memory or you
+	  want to hide the .config contents from dom0.
+
 config TRACEBUFFER
 	bool "Enable tracing infrastructure" if EXPERT = "y"
 	default y
xen/common/Makefile +12 -0
index 3a2c1ae690..100babc446 100644
@@ -1,6 +1,7 @@
 obj-$(CONFIG_ARGO) += argo.o
 obj-y += bitmap.o
 obj-y += bsearch.o
+obj-$(CONFIG_HYPFS_CONFIG) += config_data.o
 obj-$(CONFIG_CORE_PARKING) += core_parking.o
 obj-y += cpu.o
 obj-$(CONFIG_DEBUG_TRACE) += debugtrace.o
@@ -73,3 +74,14 @@ subdir-$(CONFIG_UBSAN) += ubsan
 
 subdir-$(CONFIG_NEEDS_LIBELF) += libelf
 subdir-$(CONFIG_HAS_DEVICE_TREE) += libfdt
+
+config.gz: ../.config
+	gzip -c $< >$@
+
+config_data.o: config.gz
+
+config_data.S: $(XEN_ROOT)/xen/tools/binfile
+	$(XEN_ROOT)/xen/tools/binfile $@ config.gz xen_config_data
+
+clean::
+	rm config_data.S config.gz 2>/dev/null || true
xen/common/kernel.c +15 -0
index da6e4b4444..4b7bc28afb 100644
@@ -389,6 +389,16 @@ static HYPFS_STRING_INIT(compile_date, "compile_date");
 static HYPFS_STRING_INIT(compile_domain, "compile_domain");
 static HYPFS_STRING_INIT(extra, "extra");
 
+#ifdef CONFIG_HYPFS_CONFIG
+static struct hypfs_entry_leaf config = {
+    .e.type = XEN_HYPFS_TYPE_STRING,
+    .e.encoding = XEN_HYPFS_ENC_GZIP,
+    .e.name = "config",
+    .e.read = hypfs_read_leaf,
+    .content = &xen_config_data
+};
+#endif
+
 static int __init buildinfo_init(void)
 {
     hypfs_add_dir(&hypfs_root, &buildinfo, true);
@@ -414,6 +424,11 @@ static int __init buildinfo_init(void)
     hypfs_add_leaf(&version, &major, true);
     hypfs_add_leaf(&version, &minor, true);
 
+#ifdef CONFIG_HYPFS_CONFIG
+    config.e.size = xen_config_data_size;
+    hypfs_add_leaf(&buildinfo, &config, true);
+#endif
+
     return 0;
 }
 __initcall(buildinfo_init);
xen/include/xen/kernel.h +3 -0
index 548b64da9f..02e3281f52 100644
@@ -100,5 +100,8 @@ extern enum system_state {
 
 bool_t is_active_kernel_text(unsigned long addr);
 
+extern const char xen_config_data;
+extern const unsigned int xen_config_data_size;
+
 #endif /* _LINUX_KERNEL_H */
 
Signature · 7 lines
2.16.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#26 lore raw

Re: [Xen-devel] [PATCH v6 08/12] xen: add /buildinfo/config entry to hypervisor filesystem

Quoted 40 lines · Juergen Gross

Add the /buildinfo/config entry to the hypervisor filesystem. This entry contains the .config file used to build the hypervisor.

---
V3:
- store data in gzip format
- use binfile mechanism to create data file
- move code to kernel.c

V6:
- add config item for the /buildinfo/config (Jan Beulich)
- make config related variables const in kernel.h (Jan Beulich)

---
 .gitignore                   |  2 ++
 docs/misc/hypfs-paths.pandoc |  4 ++++
 xen/common/Kconfig           | 10 ++++++++++
 xen/common/Makefile          | 12 ++++++++++++
 xen/common/kernel.c          | 15 +++++++++++++++
 xen/include/xen/kernel.h     |  3 +++
 6 files changed, 46 insertions(+)
.gitignore +2 -0
index fd5610718d..bc8e053ccb 100644
@@ -297,6 +297,8 @@ xen/arch/*/efi/boot.c
 xen/arch/*/efi/compat.c
 xen/arch/*/efi/efi.h
 xen/arch/*/efi/runtime.c
+xen/common/config_data.S
+xen/common/config.gz
 xen/include/headers*.chk
 xen/include/asm
 xen/include/asm-*/asm-offsets.h
docs/misc/hypfs-paths.pandoc +0 -0
index e392feff27..1faebcccbc 100644

docs/misc/hypfs-paths.pandoc Information about the compile domain. · line 138

Quoted 6 lines
docs/misc/hypfs-paths.pandoc +3 -0
@@ -133,6 +133,10 @@ Information about the compile domain.
 
 The compiler used to build Xen.
 
+#### /buildinfo/config = STRING
+
+The contents of the `xen/.config` file at the time of the hypervisor build.

Perhaps add "..., if enabled at build time"?

Quoted 11 lines
xen/common/Makefile +1 -0
@@ -1,6 +1,7 @@
 obj-$(CONFIG_ARGO) += argo.o
 obj-y += bitmap.o
 obj-y += bsearch.o
+obj-$(CONFIG_HYPFS_CONFIG) += config_data.o
 obj-$(CONFIG_CORE_PARKING) += core_parking.o
 obj-y += cpu.o
 obj-$(CONFIG_DEBUG_TRACE) += debugtrace.o

xen/common/Makefile subdir-$(CONFIG_UBSAN) += ubsan · line 78

Quoted 5 lines
xen/common/Makefile +2 -0
@@ -73,3 +74,14 @@ subdir-$(CONFIG_UBSAN) += ubsan
 
 subdir-$(CONFIG_NEEDS_LIBELF) += libelf
 subdir-$(CONFIG_HAS_DEVICE_TREE) += libfdt
+
+config.gz: ../.config

I think this wants to use $(KCONFIG_CONFIG) now.

xen/common/Makefile subdir-$(CONFIG_UBSAN) += ubsan · line 79

Quoted 1 line
xen/common/Makefile +1 -0
+	gzip -c $< >$@

We'll want to make sure to switch this to $(if_changed ...) once available (by Anthony's series).

xen/common/Makefile subdir-$(CONFIG_UBSAN) += ubsan · line 81

Quoted 1 line
xen/common/Makefile +1 -0
+config_data.o: config.gz

Is this really needed? You need to add config.gz as a dependency ...

xen/common/Makefile subdir-$(CONFIG_UBSAN) += ubsan · line 83

Quoted 1 line
xen/common/Makefile +1 -0
+config_data.S: $(XEN_ROOT)/xen/tools/binfile

... here anyway afaict, and then preferably use ...

xen/common/Makefile subdir-$(CONFIG_UBSAN) += ubsan · line 84

Quoted 1 line
xen/common/Makefile +1 -0
+	$(XEN_ROOT)/xen/tools/binfile $@ config.gz xen_config_data

... $< here.

xen/common/Makefile subdir-$(CONFIG_UBSAN) += ubsan · line 87

Quoted 2 lines
xen/common/Makefile +2 -0
+clean::
+	rm config_data.S config.gz 2>/dev/null || true

Instead of the "|| true" elsewhere we use "rm -f".

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#27 lore raw

Re: [Xen-devel] [PATCH v6 08/12] xen: add /buildinfo/config entry to hypervisor filesystem

Quoted 42 lines · Jan Beulich
Quoted 41 lines · Juergen Gross

Add the /buildinfo/config entry to the hypervisor filesystem. This entry contains the .config file used to build the hypervisor.

---
V3:
- store data in gzip format
- use binfile mechanism to create data file
- move code to kernel.c

V6:
- add config item for the /buildinfo/config (Jan Beulich)
- make config related variables const in kernel.h (Jan Beulich)

---
  .gitignore                   |  2 ++
  docs/misc/hypfs-paths.pandoc |  4 ++++
  xen/common/Kconfig           | 10 ++++++++++
  xen/common/Makefile          | 12 ++++++++++++
  xen/common/kernel.c          | 15 +++++++++++++++
  xen/include/xen/kernel.h     |  3 +++
  6 files changed, 46 insertions(+)
.gitignore +2 -0
index fd5610718d..bc8e053ccb 100644
@@ -297,6 +297,8 @@ xen/arch/*/efi/boot.c
  xen/arch/*/efi/compat.c
  xen/arch/*/efi/efi.h
  xen/arch/*/efi/runtime.c
+xen/common/config_data.S
+xen/common/config.gz
  xen/include/headers*.chk
  xen/include/asm
  xen/include/asm-*/asm-offsets.h
docs/misc/hypfs-paths.pandoc +0 -0
index e392feff27..1faebcccbc 100644
@@ -133,6 +133,10 @@ Information about the compile domain.
 
Quoted 7 lines

docs/misc/hypfs-paths.pandoc Information about the compile domain. · line 138

Quoted 5 lines
docs/misc/hypfs-paths.pandoc +3 -0
  The compiler used to build Xen.
 
+#### /buildinfo/config = STRING
+
+The contents of the `xen/.config` file at the time of the hypervisor build.

Perhaps add "..., if enabled at build time"?

Yes.

Quoted 13 lines
Quoted 13 lines
xen/common/Makefile +1 -0
@@ -1,6 +1,7 @@
  obj-$(CONFIG_ARGO) += argo.o
  obj-y += bitmap.o
  obj-y += bsearch.o
+obj-$(CONFIG_HYPFS_CONFIG) += config_data.o
  obj-$(CONFIG_CORE_PARKING) += core_parking.o
  obj-y += cpu.o
  obj-$(CONFIG_DEBUG_TRACE) += debugtrace.o
@@ -73,3 +74,14 @@ subdir-$(CONFIG_UBSAN) += ubsan
 
Quoted 6 lines

xen/common/Makefile subdir-$(CONFIG_UBSAN) += ubsan · line 78

Quoted 4 lines
xen/common/Makefile +2 -0
  subdir-$(CONFIG_NEEDS_LIBELF) += libelf
  subdir-$(CONFIG_HAS_DEVICE_TREE) += libfdt
+
+config.gz: ../.config

I think this wants to use $(KCONFIG_CONFIG) now.

Okay.

Quoted 5 lines

xen/common/Makefile subdir-$(CONFIG_UBSAN) += ubsan · line 79

Quoted 2 lines
xen/common/Makefile +1 -0
+	gzip -c $< >$@

We'll want to make sure to switch this to $(if_changed ...) once available (by Anthony's series).

Yes.

Quoted 9 lines

xen/common/Makefile subdir-$(CONFIG_UBSAN) += ubsan · line 81

Quoted 2 lines
xen/common/Makefile +1 -0
+config_data.o: config.gz

Is this really needed? You need to add config.gz as a dependency ...

xen/common/Makefile subdir-$(CONFIG_UBSAN) += ubsan · line 83

Quoted 1 line
xen/common/Makefile +1 -0
+config_data.S: $(XEN_ROOT)/xen/tools/binfile

... here anyway afaict, and then preferably use ...

Why? config_data.S will look always the same, even if config.gz has changed. It is just the name of the file which will be put into the generated source, not its contents. Its the .o file which wants to be built again if config.gz changes, not the .S file.

Quoted 9 lines

xen/common/Makefile subdir-$(CONFIG_UBSAN) += ubsan · line 84

Quoted 2 lines
xen/common/Makefile +1 -0
+	$(XEN_ROOT)/xen/tools/binfile $@ config.gz xen_config_data

... $< here.

xen/common/Makefile subdir-$(CONFIG_UBSAN) += ubsan · line 87

Quoted 2 lines
xen/common/Makefile +2 -0
+clean::
+	rm config_data.S config.gz 2>/dev/null || true

Instead of the "|| true" elsewhere we use "rm -f".

Okay.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#28 lore raw

Re: [Xen-devel] [PATCH v6 08/12] xen: add /buildinfo/config entry to hypervisor filesystem

Quoted 7 lines · Jürgen Groß
Quoted 6 lines · Jan Beulich
Quoted 1 line · Juergen Gross

+config_data.o: config.gz

Is this really needed? You need to add config.gz as a dependency ...

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

+config_data.S: $(XEN_ROOT)/xen/tools/binfile

... here anyway afaict, and then preferably use ...

Why? config_data.S will look always the same, even if config.gz has changed. It is just the name of the file which will be put into the generated source, not its contents. Its the .o file which wants to be built again if config.gz changes, not the .S file.

Oh, right, I forgot this uses the .include directive.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#29 lore raw

PATCH v6 9/12 xen: add runtime parameter access support to hypfs

In reply to Juergen Gross

Add support to read and modify values of hypervisor runtime parameters via the hypervisor file system.

As runtime parameters can be modified via a sysctl, too, this path has to take the hypfs rw_lock as writer.

For custom runtime parameters the connection between the parameter value and the file system is done via an init function which will set the initial value (if needed) and the leaf properties.

---
V3:
- complete rework
- support custom parameters, too
- support parameter writing

V6:
- rewording in docs/misc/hypfs-paths.pandoc (Jan Beulich)
- use memchr() (Jan Beulich)
- use strlcat() (Jan Beulich)
- rework to use a custom parameter init function instead of a reference to a content variable, allowing to drop default strings
- style correction (Jan Beulich)
- dropping param_append_str() in favor of a custom function at its only use site

---
 docs/misc/hypfs-paths.pandoc |  9 +++++
 xen/arch/arm/xen.lds.S       |  5 +++
 xen/arch/x86/hvm/vmx/vmcs.c  | 30 ++++++++++++++++-
 xen/arch/x86/pv/domain.c     | 26 +++++++++++++--
 xen/arch/x86/xen.lds.S       |  5 +++
 xen/common/grant_table.c     | 37 ++++++++++++++++-----
 xen/common/hypfs.c           | 38 +++++++++++++++++++++
 xen/common/kernel.c          | 27 ++++++++++++++-
 xen/drivers/char/console.c   | 66 +++++++++++++++++++++++++++++++++----
 xen/include/xen/hypfs.h      |  4 +++
 xen/include/xen/param.h      | 78 +++++++++++++++++++++++++++++++++++++++-----
 11 files changed, 299 insertions(+), 26 deletions(-)
docs/misc/hypfs-paths.pandoc +9 -0
index 1faebcccbc..b4a5b6086e 100644
@@ -152,3 +152,12 @@ The major version of Xen.
 #### /buildinfo/version/minor = INTEGER
 
 The minor version of Xen.
+
+#### /params/
+
+A directory of runtime parameters.
+
+#### /params/*
+
+The individual parameters. The description of the different parameters can be
+found in `docs/misc/xen-command-line.pandoc`.
xen/arch/arm/xen.lds.S +5 -0
index a497f6a48d..0061a8dfea 100644
@@ -89,6 +89,11 @@ SECTIONS
        __start_schedulers_array = .;
        *(.data.schedulers)
        __end_schedulers_array = .;
+
+       . = ALIGN(8);
+       __paramhypfs_start = .;
+       *(.data.paramhypfs)
+       __paramhypfs_end = .;
        *(.data.rel)
        *(.data.rel.*)
        CONSTRUCTORS
xen/arch/x86/hvm/vmx/vmcs.c +29 -1
index 65445afeb0..3b690b05ed 100644
@@ -70,6 +70,30 @@ integer_param("ple_window", ple_window);
 static bool __read_mostly opt_ept_pml = true;
 static s8 __read_mostly opt_ept_ad = -1;
 int8_t __read_mostly opt_ept_exec_sp = -1;
+static char opt_ept_setting[16];
+
+static void update_ept_param_append(const char *str, int val)
+{
+    char *pos = opt_ept_setting + strlen(opt_ept_setting);
+
+    snprintf(pos, sizeof(opt_ept_setting) - (pos - opt_ept_setting),
+             ",%s=%d", str, val);
+}
+
+static void update_ept_param(void)
+{
+    snprintf(opt_ept_setting, sizeof(opt_ept_setting), "pml=%d", opt_ept_pml);
+    if ( opt_ept_ad >= 0 )
+        update_ept_param_append("ad", opt_ept_ad);
+    if ( opt_ept_exec_sp >= 0 )
+        update_ept_param_append("exec-sp", opt_ept_exec_sp);
+}
+
+static void __init init_ept_param(struct param_hypfs *par)
+{
+    custom_runtime_set_var(par, opt_ept_setting);
+    update_ept_param();
+}
 
 static int __init parse_ept_param(const char *s)
 {
@@ -93,6 +117,8 @@ static int __init parse_ept_param(const char *s)
         s = ss + 1;
     } while ( *ss );
 
+    update_ept_param();
+
     return rc;
 }
 custom_param("ept", parse_ept_param);
@@ -115,6 +141,8 @@ static int parse_ept_param_runtime(const char *s)
 
     opt_ept_exec_sp = val;
 
+    update_ept_param();
+
     rcu_read_lock(&domlist_read_lock);
     for_each_domain ( d )
     {
@@ -144,7 +172,7 @@ static int parse_ept_param_runtime(const char *s)
 
     return 0;
 }
-custom_runtime_only_param("ept", parse_ept_param_runtime);
+custom_runtime_only_param("ept", parse_ept_param_runtime, init_ept_param);
 
 /* Dynamic (run-time adjusted) execution control flags. */
 u32 vmx_pin_based_exec_control __read_mostly;
xen/arch/x86/pv/domain.c +24 -2
index 0b37653b12..96fae68409 100644
@@ -20,8 +20,27 @@ static __read_mostly enum {
     PCID_OFF,
     PCID_ALL,
     PCID_XPTI,
-    PCID_NOXPTI
+    PCID_NOXPTI,
+    PCID_END
 } opt_pcid = PCID_XPTI;
+static const char *opt_pcid_2_string[PCID_END] = {
+    [PCID_OFF] = "off",
+    [PCID_ALL] = "on",
+    [PCID_XPTI] = "xpti",
+    [PCID_NOXPTI] = "noxpti"
+};
+static char opt_pcid_val[7];
+
+static void update_opt_pcid(void)
+{
+    strlcpy(opt_pcid_val, opt_pcid_2_string[opt_pcid], sizeof(opt_pcid_val));
+}
+
+static void __init opt_pcid_init(struct param_hypfs *par)
+{
+    custom_runtime_set_var(par, opt_pcid_val);
+    update_opt_pcid();
+}
 
 static int parse_pcid(const char *s)
 {
@@ -55,9 +74,12 @@ static int parse_pcid(const char *s)
         break;
     }
 
+    if ( !rc )
+        update_opt_pcid();
+
     return rc;
 }
-custom_runtime_param("pcid", parse_pcid);
+custom_runtime_param("pcid", parse_pcid, opt_pcid_init);
 
 static void noreturn continue_nonidle_domain(struct vcpu *v)
 {
xen/arch/x86/xen.lds.S +5 -0
index 7f9459d683..21a37f0f57 100644
@@ -279,6 +279,11 @@ SECTIONS
        __start_schedulers_array = .;
        *(.data.schedulers)
        __end_schedulers_array = .;
+
+       . = ALIGN(8);
+       __paramhypfs_start = .;
+       *(.data.paramhypfs)
+       __paramhypfs_end = .;
   } :text
 
   DECL_SECTION(.data) {
xen/common/grant_table.c +29 -8
index bc37acae0e..2b7b3e2844 100644
@@ -85,8 +85,10 @@ struct grant_table {
     struct grant_table_arch arch;
 };
 
-static int parse_gnttab_limit(const char *param, const char *arg,
-                              unsigned int *valp)
+#define GRANT_CUSTOM_VAL_SZ  12
+
+static int parse_gnttab_limit(const char *arg, unsigned int *valp,
+                              char *parval)
 {
     const char *e;
     unsigned long val;
@@ -99,28 +101,47 @@ static int parse_gnttab_limit(const char *param, const char *arg,
         return -ERANGE;
 
     *valp = val;
+    snprintf(parval, GRANT_CUSTOM_VAL_SZ, "%lu", val);
 
     return 0;
 }
 
 unsigned int __read_mostly opt_max_grant_frames = 64;
+static char __read_mostly opt_max_grant_frames_val[GRANT_CUSTOM_VAL_SZ];
+
+static void __init gnttab_max_frames_init(struct param_hypfs *par)
+{
+    custom_runtime_set_var(par, opt_max_grant_frames_val);
+    snprintf(opt_max_grant_frames_val, GRANT_CUSTOM_VAL_SZ, "%u",
+             opt_max_grant_frames);
+}
 
 static int parse_gnttab_max_frames(const char *arg)
 {
-    return parse_gnttab_limit("gnttab_max_frames", arg,
-                              &opt_max_grant_frames);
+    return parse_gnttab_limit(arg, &opt_max_grant_frames,
+                              opt_max_grant_frames_val);
 }
-custom_runtime_param("gnttab_max_frames", parse_gnttab_max_frames);
+custom_runtime_param("gnttab_max_frames", parse_gnttab_max_frames,
+                     gnttab_max_frames_init);
 
 static unsigned int __read_mostly opt_max_maptrack_frames = 1024;
+static char __read_mostly opt_max_maptrack_frames_val[GRANT_CUSTOM_VAL_SZ];
+
+static void __init max_maptrack_frames_init(struct param_hypfs *par)
+{
+    custom_runtime_set_var(par, opt_max_maptrack_frames_val);
+    snprintf(opt_max_maptrack_frames_val, GRANT_CUSTOM_VAL_SZ, "%u",
+             opt_max_maptrack_frames);
+}
 
 static int parse_gnttab_max_maptrack_frames(const char *arg)
 {
-    return parse_gnttab_limit("gnttab_max_maptrack_frames", arg,
-                              &opt_max_maptrack_frames);
+    return parse_gnttab_limit(arg, &opt_max_maptrack_frames,
+                              opt_max_maptrack_frames_val);
 }
 custom_runtime_param("gnttab_max_maptrack_frames",
-                     parse_gnttab_max_maptrack_frames);
+                     parse_gnttab_max_maptrack_frames,
+                     max_maptrack_frames_init);
 
 #ifndef GNTTAB_MAX_VERSION
 #define GNTTAB_MAX_VERSION 2
xen/common/hypfs.c +38 -0
index e6166fe1e7..9503ef0731 100644
@@ -10,6 +10,7 @@
 #include <xen/hypercall.h>
 #include <xen/hypfs.h>
 #include <xen/lib.h>
+#include <xen/param.h>
 #include <xen/rwlock.h>
 #include <public/hypfs.h>
 
@@ -281,6 +282,33 @@ int hypfs_write_bool(struct hypfs_entry_leaf *leaf,
     return 0;
 }
 
+int hypfs_write_custom(struct hypfs_entry_leaf *leaf,
+                       XEN_GUEST_HANDLE_PARAM(void) uaddr, unsigned long ulen)
+{
+    struct param_hypfs *p;
+    char *buf;
+    int ret;
+
+    buf = xzalloc_array(char, ulen);
+    if ( !buf )
+        return -ENOMEM;
+
+    ret = -EFAULT;
+    if ( copy_from_guest(buf, uaddr, ulen) )
+        goto out;
+
+    ret = -EDOM;
+    if ( !memchr(buf, 0, ulen) )
+        goto out;
+
+    p = container_of(leaf, struct param_hypfs, hypfs);
+    ret = p->param->par.func(buf);
+
+ out:
+    xfree(buf);
+    return ret;
+}
+
 static int hypfs_write(struct hypfs_entry *entry,
                        XEN_GUEST_HANDLE_PARAM(void) uaddr, unsigned long ulen)
 {
@@ -347,3 +375,13 @@ long do_hypfs_op(unsigned int cmd,
 
     return ret;
 }
+
+void hypfs_write_lock(void)
+{
+    write_lock(&hypfs_lock);
+}
+
+void hypfs_write_unlock(void)
+{
+    write_unlock(&hypfs_lock);
+}
xen/common/kernel.c +26 -1
index 4b7bc28afb..7516242337 100644
@@ -198,7 +198,13 @@ static void __init _cmdline_parse(const char *cmdline)
 
 int runtime_parse(const char *line)
 {
-    return parse_params(line, __param_start, __param_end);
+    int ret;
+
+    hypfs_write_lock();
+    ret = parse_params(line, __param_start, __param_end);
+    hypfs_write_unlock();
+
+    return ret;
 }
 
 /**
@@ -433,6 +439,25 @@ static int __init buildinfo_init(void)
 }
 __initcall(buildinfo_init);
 
+static HYPFS_DIR_INIT(params, "params");
+
+static int __init param_init(void)
+{
+    struct param_hypfs *param;
+
+    hypfs_add_dir(&hypfs_root, &params, true);
+
+    for ( param = __paramhypfs_start; param < __paramhypfs_end; param++ )
+    {
+        if ( param->init_leaf )
+            param->init_leaf(param);
+        hypfs_add_leaf(&params, &param->hypfs, true);
+    }
+
+    return 0;
+}
+__initcall(param_init);
+
 # define DO(fn) long do_##fn
 
 #endif
xen/drivers/char/console.c +60 -6

136 lines not on this page · raw message

xen/include/xen/hypfs.h +4 -0
index 9ecc9060a3..6c1db290cb 100644
@@ -99,5 +99,9 @@ int hypfs_write_leaf(struct hypfs_entry_leaf *leaf,
                      XEN_GUEST_HANDLE_PARAM(void) uaddr, unsigned long ulen);
 int hypfs_write_bool(struct hypfs_entry_leaf *leaf,
                      XEN_GUEST_HANDLE_PARAM(void) uaddr, unsigned long ulen);
+int hypfs_write_custom(struct hypfs_entry_leaf *leaf,
+                       XEN_GUEST_HANDLE_PARAM(void) uaddr, unsigned long ulen);
+void hypfs_write_lock(void);
+void hypfs_write_unlock(void);
 
 #endif /* __XEN_HYPFS_H__ */
xen/include/xen/param.h +70 -8

127 lines not on this page · raw message

Signature · 7 lines
2.16.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#30 lore raw

Re: [Xen-devel] [PATCH v6 09/12] xen: add runtime parameter access support to hypfs

xen/arch/x86/hvm/vmx/vmcs.c integer_param("ple_window", ple_window); · line 73

Quoted 7 lines · Juergen Gross
xen/arch/x86/hvm/vmx/vmcs.c +1 -0
@@ -70,6 +70,30 @@ integer_param("ple_window", ple_window);
 static bool __read_mostly opt_ept_pml = true;
 static s8 __read_mostly opt_ept_ad = -1;
 int8_t __read_mostly opt_ept_exec_sp = -1;
+static char opt_ept_setting[16];

I don't think this is quite big enough.

xen/arch/x86/hvm/vmx/vmcs.c integer_param("ple_window", ple_window); · line 87

Quoted 13 lines
xen/arch/x86/hvm/vmx/vmcs.c +13 -0
+static void update_ept_param_append(const char *str, int val)
+{
+    char *pos = opt_ept_setting + strlen(opt_ept_setting);
+
+    snprintf(pos, sizeof(opt_ept_setting) - (pos - opt_ept_setting),
+             ",%s=%d", str, val);
+}
+
+static void update_ept_param(void)
+{
+    snprintf(opt_ept_setting, sizeof(opt_ept_setting), "pml=%d", opt_ept_pml);
+    if ( opt_ept_ad >= 0 )
+        update_ept_param_append("ad", opt_ept_ad);

This won't correctly reflect reality: If you look at vmx_init_vmcs_config(), even a negative value means "true" here, unless on a specific Atom model. I think init_ept_param() wants to have that erratum workaround logic moved there, such that you can then assme the value to be non-negative here.

xen/arch/x86/hvm/vmx/vmcs.c integer_param("ple_window", ple_window); · line 89

Quoted 2 lines
xen/arch/x86/hvm/vmx/vmcs.c +2 -0
+    if ( opt_ept_exec_sp >= 0 )
+        update_ept_param_append("exec-sp", opt_ept_exec_sp);

I agree for this one - if the value is still -1, it has neither been set nor is its value of any interest.

xen/arch/x86/hvm/vmx/vmcs.c static int __init parse_ept_param(const char *s) · line 120

Quoted 13 lines
xen/arch/x86/hvm/vmx/vmcs.c +6 -0
+static void __init init_ept_param(struct param_hypfs *par)
+{
+    custom_runtime_set_var(par, opt_ept_setting);
+    update_ept_param();
+}
 
 static int __init parse_ept_param(const char *s)
 {
@@ -93,6 +117,8 @@ static int __init parse_ept_param(const char *s)
         s = ss + 1;
     } while ( *ss );
 
+    update_ept_param();

Isn't this redundant with the use in init_ept_param() (or the other way around - there should be clear ordering between the command line parsing functions and the param-init ones, I would suppose)?

xen/arch/x86/pv/domain.c static __read_mostly enum { · line 26

Quoted 11 lines
xen/arch/x86/pv/domain.c +3 -1
@@ -20,8 +20,27 @@ static __read_mostly enum {
     PCID_OFF,
     PCID_ALL,
     PCID_XPTI,
-    PCID_NOXPTI
+    PCID_NOXPTI,
+    PCID_END
 } opt_pcid = PCID_XPTI;
+static const char *opt_pcid_2_string[PCID_END] = {

You either want another const here, or (more space efficient) you want to use const char[PCID_END][7].

xen/arch/x86/pv/domain.c static __read_mostly enum { · line 36

Quoted 10 lines
xen/arch/x86/pv/domain.c +10 -0
+    [PCID_OFF] = "off",
+    [PCID_ALL] = "on",
+    [PCID_XPTI] = "xpti",
+    [PCID_NOXPTI] = "noxpti"
+};
+static char opt_pcid_val[7];
+
+static void update_opt_pcid(void)
+{
+    strlcpy(opt_pcid_val, opt_pcid_2_string[opt_pcid], sizeof(opt_pcid_val));

Instead of copying, couldn't you make the hypfs entry point into the array above, by using custom_runtime_set_var() here?

xen/arch/x86/pv/domain.c static int parse_pcid(const char *s) · line 78

Quoted 6 lines
xen/arch/x86/pv/domain.c +2 -0
@@ -55,9 +74,12 @@ static int parse_pcid(const char *s)
         break;
     }
 
+    if ( !rc )
+        update_opt_pcid();

Personally I'd avoid the if() here - there's no harm updating the hypfs entry anyway.

Quoted 20 lines
xen/common/grant_table.c +5 -2
@@ -85,8 +85,10 @@ struct grant_table {
     struct grant_table_arch arch;
 };
 
-static int parse_gnttab_limit(const char *param, const char *arg,
-                              unsigned int *valp)
+#define GRANT_CUSTOM_VAL_SZ  12
+
+static int parse_gnttab_limit(const char *arg, unsigned int *valp,
+                              char *parval)
 {
     const char *e;
     unsigned long val;
@@ -99,28 +101,47 @@ static int parse_gnttab_limit(const char *param, const char *arg,
         return -ERANGE;
 
     *valp = val;
+    snprintf(parval, GRANT_CUSTOM_VAL_SZ, "%lu", val);

xen/common/grant_table.c static int parse_gnttab_limit(const char *param, const char *arg, · line 114

Quoted 10 lines
xen/common/grant_table.c +5 -0
 
     return 0;
 }
 
 unsigned int __read_mostly opt_max_grant_frames = 64;
+static char __read_mostly opt_max_grant_frames_val[GRANT_CUSTOM_VAL_SZ];
+
+static void __init gnttab_max_frames_init(struct param_hypfs *par)
+{
+    custom_runtime_set_var(par, opt_max_grant_frames_val);

You still use a custom string buffer here. Can this "set-var" operation record that the variable (for presentation purposes) is simply of UINT type, handing a pointer to the actual variable?

Quoted 21 lines
xen/common/hypfs.c +8 -0
@@ -10,6 +10,7 @@
 #include <xen/hypercall.h>
 #include <xen/hypfs.h>
 #include <xen/lib.h>
+#include <xen/param.h>
 #include <xen/rwlock.h>
 #include <public/hypfs.h>
 
@@ -281,6 +282,33 @@ int hypfs_write_bool(struct hypfs_entry_leaf *leaf,
     return 0;
 }
 
+int hypfs_write_custom(struct hypfs_entry_leaf *leaf,
+                       XEN_GUEST_HANDLE_PARAM(void) uaddr, unsigned long ulen)
+{
+    struct param_hypfs *p;
+    char *buf;
+    int ret;
+

xen/common/hypfs.c int hypfs_write_bool(struct hypfs_entry_leaf *leaf, · line 301

Quoted 10 lines
xen/common/hypfs.c +10 -0
+    buf = xzalloc_array(char, ulen);
+    if ( !buf )
+        return -ENOMEM;
+
+    ret = -EFAULT;
+    if ( copy_from_guest(buf, uaddr, ulen) )
+        goto out;
+
+    ret = -EDOM;
+    if ( !memchr(buf, 0, ulen) )

Once again " != buf + ulen - 1"? (EDOM also looks like an odd error code to use in this case, but I guess there's no really good one.)

Quoted 27 lines
xen/drivers/char/console.c +18 -0
@@ -75,12 +75,36 @@ enum con_timestamp_mode
     TSM_DATE_MS,       /* [YYYY-MM-DD HH:MM:SS.mmm] */
     TSM_BOOT,          /* [SSSSSS.uuuuuu] */
     TSM_RAW,           /* [XXXXXXXXXXXXXXXX] */
+    TSM_END
+};
+
+static const char *con_timestamp_mode_2_string[TSM_END] = {
+    [TSM_NONE] = "none",
+    [TSM_DATE] = "date",
+    [TSM_DATE_MS] = "datems",
+    [TSM_BOOT] = "boot",
+    [TSM_RAW] = "raw"
 };
 
 static enum con_timestamp_mode __read_mostly opt_con_timestamp_mode = TSM_NONE;
+static char con_timestamp_mode_val[7];
+
+static void update_con_timestamp_mode(void)
+{
+    strlcpy(con_timestamp_mode_val,
+            con_timestamp_mode_2_string[opt_con_timestamp_mode],
+            sizeof(con_timestamp_mode_val));
+}
+

xen/drivers/char/console.c enum con_timestamp_mode · line 107

Quoted 10 lines
xen/drivers/char/console.c +7 -1
+static void __init con_timestamp_mode_init(struct param_hypfs *par)
+{
+    custom_runtime_set_var(par, con_timestamp_mode_val);
+    update_con_timestamp_mode();
+}
 
 static int parse_console_timestamps(const char *s);
-custom_runtime_param("console_timestamps", parse_console_timestamps);
+custom_runtime_param("console_timestamps", parse_console_timestamps,
+                     con_timestamp_mode_init);

Same remark as for the PCID option, and then also for the log level ones further down. My main concern with how things are currently is that the amount of logic needed for custom params seems overly large.

xen/drivers/char/console.c extern const struct kernel_param __param_start[], __param_end[]; · line 97

Quoted 12 lines
xen/drivers/char/console.c +6 -1
@@ -79,41 +88,94 @@ extern const struct kernel_param __param_start[], __param_end[];
           .type = OPT_IGNORE }
 
 #define __rtparam         __param(__dataparam)
+#define __paramfs         static __paramhypfs \
+    __attribute__((__aligned__(sizeof(void *)))) struct param_hypfs
 
-#define custom_runtime_only_param(_name, _var) \
+#define custom_runtime_set_var(parfs, var) \
+    { \
+        (parfs)->hypfs.write_ptr = &(var); \
+        (parfs)->hypfs.e.size = sizeof(var); \

All users of this use char[]. Why sizeof() rather than strlen(), and why taking the address instead of enforcing this to be of (at least) array (potentially also "of char") type? Do you envision this to be needed for anything where the value isn't in string form, but still needs dynamically calculating? (As per above there may already be cases where non-string variables may want passing into here.)

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#31 lore raw

Re: [Xen-devel] [PATCH v6 09/12] xen: add runtime parameter access support to hypfs

Quoted 10 lines · Jan Beulich

xen/arch/x86/hvm/vmx/vmcs.c integer_param("ple_window", ple_window); · line 73

Quoted 7 lines · Juergen Gross
xen/arch/x86/hvm/vmx/vmcs.c +1 -0
@@ -70,6 +70,30 @@ integer_param("ple_window", ple_window);
  static bool __read_mostly opt_ept_pml = true;
  static s8 __read_mostly opt_ept_ad = -1;
  int8_t __read_mostly opt_ept_exec_sp = -1;
+static char opt_ept_setting[16];

I don't think this is quite big enough.

Yes, you are right.

Quoted 12 lines
Quoted 12 lines
xen/arch/x86/hvm/vmx/vmcs.c +11 -0
+static void update_ept_param_append(const char *str, int val)
+{
+    char *pos = opt_ept_setting + strlen(opt_ept_setting);
+
+    snprintf(pos, sizeof(opt_ept_setting) - (pos - opt_ept_setting),
+             ",%s=%d", str, val);
+}
+
+static void update_ept_param(void)
+{
+    snprintf(opt_ept_setting, sizeof(opt_ept_setting), "pml=%d", opt_ept_pml);
Quoted 8 lines

xen/arch/x86/hvm/vmx/vmcs.c integer_param("ple_window", ple_window); · line 87

Quoted 2 lines
xen/arch/x86/hvm/vmx/vmcs.c +2 -0
+    if ( opt_ept_ad >= 0 )
+        update_ept_param_append("ad", opt_ept_ad);

This won't correctly reflect reality: If you look at vmx_init_vmcs_config(), even a negative value means "true" here, unless on a specific Atom model. I think init_ept_param() wants to have that erratum workaround logic moved there, such that you can then assme the value to be non-negative here.

But isn't not mentioning it in the -1 case correct? -1 means: do the correct thing on the current hardware.

In case we want to report an explicit value for "ad" we should add a node for that purpose.

Quoted 18 lines

xen/arch/x86/hvm/vmx/vmcs.c integer_param("ple_window", ple_window); · line 89

Quoted 2 lines
xen/arch/x86/hvm/vmx/vmcs.c +2 -0
+    if ( opt_ept_exec_sp >= 0 )
+        update_ept_param_append("exec-sp", opt_ept_exec_sp);

I agree for this one - if the value is still -1, it has neither been set nor is its value of any interest.

Quoted 12 lines
xen/arch/x86/hvm/vmx/vmcs.c +5 -0
+static void __init init_ept_param(struct param_hypfs *par)
+{
+    custom_runtime_set_var(par, opt_ept_setting);
+    update_ept_param();
+}
 
  static int __init parse_ept_param(const char *s)
  {
@@ -93,6 +117,8 @@ static int __init parse_ept_param(const char *s)
          s = ss + 1;
      } while ( *ss );
 
Quoted 6 lines

xen/arch/x86/hvm/vmx/vmcs.c static int __init parse_ept_param(const char *s) · line 120

Quoted 1 line
xen/arch/x86/hvm/vmx/vmcs.c +1 -0
+    update_ept_param();

Isn't this redundant with the use in init_ept_param() (or the other way around - there should be clear ordering between the command line parsing functions and the param-init ones, I would suppose)?

You are right. I can drop this call, as the param-init call will come later.

Quoted 15 lines

xen/arch/x86/pv/domain.c static __read_mostly enum { · line 26

Quoted 12 lines
xen/arch/x86/pv/domain.c +3 -1
@@ -20,8 +20,27 @@ static __read_mostly enum {
      PCID_OFF,
      PCID_ALL,
      PCID_XPTI,
-    PCID_NOXPTI
+    PCID_NOXPTI,
+    PCID_END
  } opt_pcid = PCID_XPTI;
+static const char *opt_pcid_2_string[PCID_END] = {

You either want another const here, or (more space efficient) you want to use const char[PCID_END][7].

Ah, right, good idea.

Quoted 14 lines

xen/arch/x86/pv/domain.c static __read_mostly enum { · line 36

Quoted 11 lines
xen/arch/x86/pv/domain.c +10 -0
+    [PCID_OFF] = "off",
+    [PCID_ALL] = "on",
+    [PCID_XPTI] = "xpti",
+    [PCID_NOXPTI] = "noxpti"
+};
+static char opt_pcid_val[7];
+
+static void update_opt_pcid(void)
+{
+    strlcpy(opt_pcid_val, opt_pcid_2_string[opt_pcid], sizeof(opt_pcid_val));

Instead of copying, couldn't you make the hypfs entry point into the array above, by using custom_runtime_set_var() here?

Hmm, probably yes.

Quoted 10 lines

xen/arch/x86/pv/domain.c static int parse_pcid(const char *s) · line 78

Quoted 7 lines
xen/arch/x86/pv/domain.c +2 -0
@@ -55,9 +74,12 @@ static int parse_pcid(const char *s)
          break;
      }
 
+    if ( !rc )
+        update_opt_pcid();

Personally I'd avoid the if() here - there's no harm updating the hypfs entry anyway.

Okay.

Quoted 25 lines
Quoted 25 lines
xen/common/grant_table.c +5 -2
@@ -85,8 +85,10 @@ struct grant_table {
      struct grant_table_arch arch;
  };
 
-static int parse_gnttab_limit(const char *param, const char *arg,
-                              unsigned int *valp)
+#define GRANT_CUSTOM_VAL_SZ  12
+
+static int parse_gnttab_limit(const char *arg, unsigned int *valp,
+                              char *parval)
  {
      const char *e;
      unsigned long val;
@@ -99,28 +101,47 @@ static int parse_gnttab_limit(const char *param, const char *arg,
          return -ERANGE;
 
      *valp = val;
+    snprintf(parval, GRANT_CUSTOM_VAL_SZ, "%lu", val);
 
      return 0;
  }
 
Quoted 11 lines

xen/common/grant_table.c static int parse_gnttab_limit(const char *param, const char *arg, · line 114

Quoted 6 lines
xen/common/grant_table.c +5 -0
  unsigned int __read_mostly opt_max_grant_frames = 64;
+static char __read_mostly opt_max_grant_frames_val[GRANT_CUSTOM_VAL_SZ];
+
+static void __init gnttab_max_frames_init(struct param_hypfs *par)
+{
+    custom_runtime_set_var(par, opt_max_grant_frames_val);

You still use a custom string buffer here. Can this "set-var" operation record that the variable (for presentation purposes) is simply of UINT type, handing a pointer to the actual variable?

No, this would result in the need to set a custom parameter via a binary value passed in from user land. So I'd need to convert this binary into a string to be parseable by the custom function.

Quoted 28 lines
Quoted 28 lines
xen/common/hypfs.c +14 -0
@@ -10,6 +10,7 @@
  #include <xen/hypercall.h>
  #include <xen/hypfs.h>
  #include <xen/lib.h>
+#include <xen/param.h>
  #include <xen/rwlock.h>
  #include <public/hypfs.h>
 
@@ -281,6 +282,33 @@ int hypfs_write_bool(struct hypfs_entry_leaf *leaf,
      return 0;
  }
 
+int hypfs_write_custom(struct hypfs_entry_leaf *leaf,
+                       XEN_GUEST_HANDLE_PARAM(void) uaddr, unsigned long ulen)
+{
+    struct param_hypfs *p;
+    char *buf;
+    int ret;
+
+    buf = xzalloc_array(char, ulen);
+    if ( !buf )
+        return -ENOMEM;
+
+    ret = -EFAULT;
+    if ( copy_from_guest(buf, uaddr, ulen) )
Quoted 8 lines

xen/common/hypfs.c int hypfs_write_bool(struct hypfs_entry_leaf *leaf, · line 301

Quoted 4 lines
xen/common/hypfs.c +4 -0
+        goto out;
+
+    ret = -EDOM;
+    if ( !memchr(buf, 0, ulen) )

Once again " != buf + ulen - 1"? (EDOM also looks like an odd error code to use in this case, but I guess there's no really good one.)

" != buf + ulen - 1" is a logical choice with the change of patch 4.

Quoted 51 lines
Quoted 28 lines
xen/drivers/char/console.c +18 -0
@@ -75,12 +75,36 @@ enum con_timestamp_mode
      TSM_DATE_MS,       /* [YYYY-MM-DD HH:MM:SS.mmm] */
      TSM_BOOT,          /* [SSSSSS.uuuuuu] */
      TSM_RAW,           /* [XXXXXXXXXXXXXXXX] */
+    TSM_END
+};
+
+static const char *con_timestamp_mode_2_string[TSM_END] = {
+    [TSM_NONE] = "none",
+    [TSM_DATE] = "date",
+    [TSM_DATE_MS] = "datems",
+    [TSM_BOOT] = "boot",
+    [TSM_RAW] = "raw"
  };
 
  static enum con_timestamp_mode __read_mostly opt_con_timestamp_mode = TSM_NONE;
+static char con_timestamp_mode_val[7];
+
+static void update_con_timestamp_mode(void)
+{
+    strlcpy(con_timestamp_mode_val,
+            con_timestamp_mode_2_string[opt_con_timestamp_mode],
+            sizeof(con_timestamp_mode_val));
+}
+

xen/drivers/char/console.c enum con_timestamp_mode · line 107

Quoted 10 lines
xen/drivers/char/console.c +7 -1
+static void __init con_timestamp_mode_init(struct param_hypfs *par)
+{
+    custom_runtime_set_var(par, con_timestamp_mode_val);
+    update_con_timestamp_mode();
+}
 
  static int parse_console_timestamps(const char *s);
-custom_runtime_param("console_timestamps", parse_console_timestamps);
+custom_runtime_param("console_timestamps", parse_console_timestamps,
+                     con_timestamp_mode_init);

Same remark as for the PCID option, and then also for the log level ones further down. My main concern with how things are currently is that the amount of logic needed for custom params seems overly large.

Quoted 7 lines
xen/drivers/char/console.c +2 -0
@@ -79,41 +88,94 @@ extern const struct kernel_param __param_start[], __param_end[];
            .type = OPT_IGNORE }
 
  #define __rtparam         __param(__dataparam)
+#define __paramfs         static __paramhypfs \
+    __attribute__((__aligned__(sizeof(void *)))) struct param_hypfs
 
Quoted 7 lines

xen/drivers/char/console.c extern const struct kernel_param __param_start[], __param_end[]; · line 97

Quoted 5 lines
xen/drivers/char/console.c +4 -1
-#define custom_runtime_only_param(_name, _var) \
+#define custom_runtime_set_var(parfs, var) \
+    { \
+        (parfs)->hypfs.write_ptr = &(var); \
+        (parfs)->hypfs.e.size = sizeof(var); \

All users of this use char[]. Why sizeof() rather than strlen(),

That is the maximum string length. Otherwise I wouldn't know I am allowed to replace e.g. "on" by "noxpti".

Quoted 6 lines

and why taking the address instead of enforcing this to be of (at least) array (potentially also "of char") type? Do you envision this to be needed for anything where the value isn't in string form, but still needs dynamically calculating? (As per above there may already be cases where non-string variables may want passing into here.)

Ah, this is a leftover from the failed experiment to allow other types than strings. I'll change it accordingly.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#32 lore raw

Re: [Xen-devel] [PATCH v6 09/12] xen: add runtime parameter access support to hypfs

Quoted 22 lines · Jürgen Groß
Quoted 12 lines · Jan Beulich
Quoted 11 lines · Juergen Gross
xen/arch/x86/hvm/vmx/vmcs.c +11 -0
+static void update_ept_param_append(const char *str, int val)
+{
+    char *pos = opt_ept_setting + strlen(opt_ept_setting);
+
+    snprintf(pos, sizeof(opt_ept_setting) - (pos - opt_ept_setting),
+             ",%s=%d", str, val);
+}
+
+static void update_ept_param(void)
+{
+    snprintf(opt_ept_setting, sizeof(opt_ept_setting), "pml=%d", opt_ept_pml);
Quoted 8 lines

xen/arch/x86/hvm/vmx/vmcs.c integer_param("ple_window", ple_window); · line 87

Quoted 2 lines
xen/arch/x86/hvm/vmx/vmcs.c +2 -0
+    if ( opt_ept_ad >= 0 )
+        update_ept_param_append("ad", opt_ept_ad);

This won't correctly reflect reality: If you look at vmx_init_vmcs_config(), even a negative value means "true" here, unless on a specific Atom model. I think init_ept_param() wants to have that erratum workaround logic moved there, such that you can then assme the value to be non-negative here.

Quoted 2 lines

But isn't not mentioning it in the -1 case correct? -1 means: do the correct thing on the current hardware.

Well, I think the output here should represent effective settings, and a sub-item should be suppressed only if a setting has no effect at all in the current setup, like ...

Quoted 5 lines
Quoted 5 lines

xen/arch/x86/hvm/vmx/vmcs.c integer_param("ple_window", ple_window); · line 89

Quoted 2 lines
xen/arch/x86/hvm/vmx/vmcs.c +2 -0
+    if ( opt_ept_exec_sp >= 0 )
+        update_ept_param_append("exec-sp", opt_ept_exec_sp);

I agree for this one - if the value is still -1, it has neither been set nor is its value of any interest.

... here.

Quoted 36 lines
Quoted 24 lines
Quoted 24 lines
xen/common/grant_table.c +5 -2
@@ -85,8 +85,10 @@ struct grant_table {
      struct grant_table_arch arch;
  };
 
-static int parse_gnttab_limit(const char *param, const char *arg,
-                              unsigned int *valp)
+#define GRANT_CUSTOM_VAL_SZ  12
+
+static int parse_gnttab_limit(const char *arg, unsigned int *valp,
+                              char *parval)
  {
      const char *e;
      unsigned long val;
@@ -99,28 +101,47 @@ static int parse_gnttab_limit(const char *param, const char *arg,
          return -ERANGE;
 
      *valp = val;
+    snprintf(parval, GRANT_CUSTOM_VAL_SZ, "%lu", val);
 
      return 0;
  }
 
Quoted 11 lines

xen/common/grant_table.c static int parse_gnttab_limit(const char *param, const char *arg, · line 114

Quoted 6 lines
xen/common/grant_table.c +5 -0
  unsigned int __read_mostly opt_max_grant_frames = 64;
+static char __read_mostly opt_max_grant_frames_val[GRANT_CUSTOM_VAL_SZ];
+
+static void __init gnttab_max_frames_init(struct param_hypfs *par)
+{
+    custom_runtime_set_var(par, opt_max_grant_frames_val);

You still use a custom string buffer here. Can this "set-var" operation record that the variable (for presentation purposes) is simply of UINT type, handing a pointer to the actual variable?

Quoted 3 lines

No, this would result in the need to set a custom parameter via a binary value passed in from user land. So I'd need to convert this binary into a string to be parseable by the custom function.

Hmm, not very fortunate, but I can see what you're saying.

Quoted 36 lines
Quoted 27 lines
Quoted 27 lines
xen/common/hypfs.c +14 -0
@@ -10,6 +10,7 @@
  #include <xen/hypercall.h>
  #include <xen/hypfs.h>
  #include <xen/lib.h>
+#include <xen/param.h>
  #include <xen/rwlock.h>
  #include <public/hypfs.h>
 
@@ -281,6 +282,33 @@ int hypfs_write_bool(struct hypfs_entry_leaf *leaf,
      return 0;
  }
 
+int hypfs_write_custom(struct hypfs_entry_leaf *leaf,
+                       XEN_GUEST_HANDLE_PARAM(void) uaddr, unsigned long ulen)
+{
+    struct param_hypfs *p;
+    char *buf;
+    int ret;
+
+    buf = xzalloc_array(char, ulen);
+    if ( !buf )
+        return -ENOMEM;
+
+    ret = -EFAULT;
+    if ( copy_from_guest(buf, uaddr, ulen) )
Quoted 8 lines

xen/common/hypfs.c int hypfs_write_bool(struct hypfs_entry_leaf *leaf, · line 301

Quoted 4 lines
xen/common/hypfs.c +4 -0
+        goto out;
+
+    ret = -EDOM;
+    if ( !memchr(buf, 0, ulen) )

Once again " != buf + ulen - 1"? (EDOM also looks like an odd error code to use in this case, but I guess there's no really good one.)

Quoted 1 line

" != buf + ulen - 1" is a logical choice with the change of patch 4.

I'm afraid I don't understand. You want to parse a string here. The caller should tell you what the string length is (including the nul again), not what its buffer size may be.

Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
xen/common/hypfs.c +2 -0
@@ -79,41 +88,94 @@ extern const struct kernel_param __param_start[], __param_end[];
            .type = OPT_IGNORE }
 
  #define __rtparam         __param(__dataparam)
+#define __paramfs         static __paramhypfs \
+    __attribute__((__aligned__(sizeof(void *)))) struct param_hypfs
 
Quoted 7 lines

xen/common/hypfs.c extern const struct kernel_param __param_start[], __param_end[]; · line 97

Quoted 5 lines
xen/common/hypfs.c +4 -1
-#define custom_runtime_only_param(_name, _var) \
+#define custom_runtime_set_var(parfs, var) \
+    { \
+        (parfs)->hypfs.write_ptr = &(var); \
+        (parfs)->hypfs.e.size = sizeof(var); \

All users of this use char[]. Why sizeof() rather than strlen(),

Quoted 2 lines

That is the maximum string length. Otherwise I wouldn't know I am allowed to replace e.g. "on" by "noxpti".

As said elsewhere - if e.size is the buffer size, then the reading function wants adjusting, and it needs to be clarified how buffer size and payload size can be told apart for BLOBs.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#33 lore raw

Re: [Xen-devel] [PATCH v6 09/12] xen: add runtime parameter access support to hypfs

Quoted 23 lines · Jan Beulich
Quoted 22 lines · Jürgen Groß
Quoted 20 lines · Jan Beulich

xen/arch/x86/hvm/vmx/vmcs.c integer_param("ple_window", ple_window); · line 87

Quoted 13 lines · Juergen Gross
xen/arch/x86/hvm/vmx/vmcs.c +13 -0
+static void update_ept_param_append(const char *str, int val)
+{
+    char *pos = opt_ept_setting + strlen(opt_ept_setting);
+
+    snprintf(pos, sizeof(opt_ept_setting) - (pos - opt_ept_setting),
+             ",%s=%d", str, val);
+}
+
+static void update_ept_param(void)
+{
+    snprintf(opt_ept_setting, sizeof(opt_ept_setting), "pml=%d", opt_ept_pml);
+    if ( opt_ept_ad >= 0 )
+        update_ept_param_append("ad", opt_ept_ad);

This won't correctly reflect reality: If you look at vmx_init_vmcs_config(), even a negative value means "true" here, unless on a specific Atom model. I think init_ept_param() wants to have that erratum workaround logic moved there, such that you can then assme the value to be non-negative here.

Quoted 4 lines
Quoted 2 lines

But isn't not mentioning it in the -1 case correct? -1 means: do the correct thing on the current hardware.

Well, I think the output here should represent effective settings,

The minimum requirement is to reflect the effective parameters, like cmdline is doing for boot-time only parameters. With runtime parameters we had no way of telling what was set, and this is now possible.

Quoted 10 lines

and a sub-item should be suppressed only if a setting has no effect at all in the current setup, like ...

Quoted 5 lines
Quoted 5 lines

xen/arch/x86/hvm/vmx/vmcs.c integer_param("ple_window", ple_window); · line 89

Quoted 2 lines
xen/arch/x86/hvm/vmx/vmcs.c +2 -0
+    if ( opt_ept_exec_sp >= 0 )
+        update_ept_param_append("exec-sp", opt_ept_exec_sp);

I agree for this one - if the value is still -1, it has neither been set nor is its value of any interest.

... here.

I think we should not mix up specified parameters and effective settings. In case an effective setting is of common interest it should be reported via a specific node (like e.g. specific mitigation settings where the cmdline is not providing enough details).

Quoted 79 lines
Quoted 37 lines
Quoted 25 lines
Quoted 25 lines
xen/common/grant_table.c +5 -2
@@ -85,8 +85,10 @@ struct grant_table {
       struct grant_table_arch arch;
   };
 
-static int parse_gnttab_limit(const char *param, const char *arg,
-                              unsigned int *valp)
+#define GRANT_CUSTOM_VAL_SZ  12
+
+static int parse_gnttab_limit(const char *arg, unsigned int *valp,
+                              char *parval)
   {
       const char *e;
       unsigned long val;
@@ -99,28 +101,47 @@ static int parse_gnttab_limit(const char *param, const char *arg,
           return -ERANGE;
 
       *valp = val;
+    snprintf(parval, GRANT_CUSTOM_VAL_SZ, "%lu", val);
 
       return 0;
   }
 
Quoted 11 lines

xen/common/grant_table.c static int parse_gnttab_limit(const char *param, const char *arg, · line 114

Quoted 6 lines
xen/common/grant_table.c +5 -0
   unsigned int __read_mostly opt_max_grant_frames = 64;
+static char __read_mostly opt_max_grant_frames_val[GRANT_CUSTOM_VAL_SZ];
+
+static void __init gnttab_max_frames_init(struct param_hypfs *par)
+{
+    custom_runtime_set_var(par, opt_max_grant_frames_val);

You still use a custom string buffer here. Can this "set-var" operation record that the variable (for presentation purposes) is simply of UINT type, handing a pointer to the actual variable?

Quoted 3 lines

No, this would result in the need to set a custom parameter via a binary value passed in from user land. So I'd need to convert this binary into a string to be parseable by the custom function.

Hmm, not very fortunate, but I can see what you're saying.

Quoted 36 lines
Quoted 35 lines
Quoted 21 lines
xen/common/hypfs.c +8 -0
@@ -10,6 +10,7 @@
   #include <xen/hypercall.h>
   #include <xen/hypfs.h>
   #include <xen/lib.h>
+#include <xen/param.h>
   #include <xen/rwlock.h>
   #include <public/hypfs.h>
 
@@ -281,6 +282,33 @@ int hypfs_write_bool(struct hypfs_entry_leaf *leaf,
       return 0;
   }
 
+int hypfs_write_custom(struct hypfs_entry_leaf *leaf,
+                       XEN_GUEST_HANDLE_PARAM(void) uaddr, unsigned long ulen)
+{
+    struct param_hypfs *p;
+    char *buf;
+    int ret;
+

xen/common/hypfs.c int hypfs_write_bool(struct hypfs_entry_leaf *leaf, · line 301

Quoted 10 lines
xen/common/hypfs.c +10 -0
+    buf = xzalloc_array(char, ulen);
+    if ( !buf )
+        return -ENOMEM;
+
+    ret = -EFAULT;
+    if ( copy_from_guest(buf, uaddr, ulen) )
+        goto out;
+
+    ret = -EDOM;
+    if ( !memchr(buf, 0, ulen) )

Once again " != buf + ulen - 1"? (EDOM also looks like an odd error code to use in this case, but I guess there's no really good one.)

Quoted 5 lines
Quoted 1 line

" != buf + ulen - 1" is a logical choice with the change of patch 4.

I'm afraid I don't understand. You want to parse a string here. The caller should tell you what the string length is (including the nul again), not what its buffer size may be.

I agreed that changing to " != buf + ulen - 1" makes sense as I agreed already to do so in patch 4.

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines

xen/common/hypfs.c extern const struct kernel_param __param_start[], __param_end[]; · line 97

Quoted 13 lines
xen/common/hypfs.c +6 -1
@@ -79,41 +88,94 @@ extern const struct kernel_param __param_start[], __param_end[];
             .type = OPT_IGNORE }
 
   #define __rtparam         __param(__dataparam)
+#define __paramfs         static __paramhypfs \
+    __attribute__((__aligned__(sizeof(void *)))) struct param_hypfs
 
-#define custom_runtime_only_param(_name, _var) \
+#define custom_runtime_set_var(parfs, var) \
+    { \
+        (parfs)->hypfs.write_ptr = &(var); \
+        (parfs)->hypfs.e.size = sizeof(var); \

All users of this use char[]. Why sizeof() rather than strlen(),

Quoted 6 lines
Quoted 2 lines

That is the maximum string length. Otherwise I wouldn't know I am allowed to replace e.g. "on" by "noxpti".

As said elsewhere - if e.size is the buffer size, then the reading function wants adjusting, and it needs to be clarified how buffer size and payload size can be told apart for BLOBs.

Okay, I'll adjust the reading size to copy only strlen() + 1 bytes and add a comment that BLOBs need blob-specific write and read functions in the common case.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#34 lore raw

Re: [Xen-devel] [PATCH v6 09/12] xen: add runtime parameter access support to hypfs

Quoted 42 lines · Jürgen Groß
Quoted 23 lines · Jan Beulich
Quoted 22 lines · Jürgen Groß
Quoted 20 lines · Jan Beulich

xen/arch/x86/hvm/vmx/vmcs.c integer_param("ple_window", ple_window); · line 87

Quoted 13 lines · Juergen Gross
xen/arch/x86/hvm/vmx/vmcs.c +13 -0
+static void update_ept_param_append(const char *str, int val)
+{
+    char *pos = opt_ept_setting + strlen(opt_ept_setting);
+
+    snprintf(pos, sizeof(opt_ept_setting) - (pos - opt_ept_setting),
+             ",%s=%d", str, val);
+}
+
+static void update_ept_param(void)
+{
+    snprintf(opt_ept_setting, sizeof(opt_ept_setting), "pml=%d", opt_ept_pml);
+    if ( opt_ept_ad >= 0 )
+        update_ept_param_append("ad", opt_ept_ad);

This won't correctly reflect reality: If you look at vmx_init_vmcs_config(), even a negative value means "true" here, unless on a specific Atom model. I think init_ept_param() wants to have that erratum workaround logic moved there, such that you can then assme the value to be non-negative here.

Quoted 4 lines
Quoted 2 lines

But isn't not mentioning it in the -1 case correct? -1 means: do the correct thing on the current hardware.

Well, I think the output here should represent effective settings,

The minimum requirement is to reflect the effective parameters, like cmdline is doing for boot-time only parameters. With runtime parameters we had no way of telling what was set, and this is now possible.

Quoted 9 lines

and a sub-item should be suppressed only if a setting has no effect at all in the current setup, like ...

Quoted 5 lines
Quoted 5 lines

xen/arch/x86/hvm/vmx/vmcs.c integer_param("ple_window", ple_window); · line 89

Quoted 2 lines
xen/arch/x86/hvm/vmx/vmcs.c +2 -0
+    if ( opt_ept_exec_sp >= 0 )
+        update_ept_param_append("exec-sp", opt_ept_exec_sp);

I agree for this one - if the value is still -1, it has neither been set nor is its value of any interest.

Quoted 6 lines
Quoted 1 line

... here.

I think we should not mix up specified parameters and effective settings. In case an effective setting is of common interest it should be reported via a specific node (like e.g. specific mitigation settings where the cmdline is not providing enough details).

But then a boolean option that wasn't specified on the command line should produce no output at all. And hence we'd need a way to tell whether an option was set from command line for _all_ of them. I don't think this would be very helpful.

I'm curious if anyone else has any opinion either way (or yet another one) here:

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#35 lore raw

Re: [Xen-devel] [PATCH v6 09/12] xen: add runtime parameter access support to hypfs

Quoted 50 lines · Jan Beulich
Quoted 42 lines · Jürgen Groß
Quoted 23 lines · Jan Beulich
Quoted 22 lines · Jürgen Groß
Quoted 20 lines · Jan Beulich

xen/arch/x86/hvm/vmx/vmcs.c integer_param("ple_window", ple_window); · line 87

Quoted 13 lines · Juergen Gross
xen/arch/x86/hvm/vmx/vmcs.c +13 -0
+static void update_ept_param_append(const char *str, int val)
+{
+    char *pos = opt_ept_setting + strlen(opt_ept_setting);
+
+    snprintf(pos, sizeof(opt_ept_setting) - (pos - opt_ept_setting),
+             ",%s=%d", str, val);
+}
+
+static void update_ept_param(void)
+{
+    snprintf(opt_ept_setting, sizeof(opt_ept_setting), "pml=%d", opt_ept_pml);
+    if ( opt_ept_ad >= 0 )
+        update_ept_param_append("ad", opt_ept_ad);

This won't correctly reflect reality: If you look at vmx_init_vmcs_config(), even a negative value means "true" here, unless on a specific Atom model. I think init_ept_param() wants to have that erratum workaround logic moved there, such that you can then assme the value to be non-negative here.

Quoted 4 lines
Quoted 2 lines

But isn't not mentioning it in the -1 case correct? -1 means: do the correct thing on the current hardware.

Well, I think the output here should represent effective settings,

The minimum requirement is to reflect the effective parameters, like cmdline is doing for boot-time only parameters. With runtime parameters we had no way of telling what was set, and this is now possible.

Quoted 9 lines

and a sub-item should be suppressed only if a setting has no effect at all in the current setup, like ...

Quoted 5 lines
Quoted 5 lines

xen/arch/x86/hvm/vmx/vmcs.c integer_param("ple_window", ple_window); · line 89

Quoted 2 lines
xen/arch/x86/hvm/vmx/vmcs.c +2 -0
+    if ( opt_ept_exec_sp >= 0 )
+        update_ept_param_append("exec-sp", opt_ept_exec_sp);

I agree for this one - if the value is still -1, it has neither been set nor is its value of any interest.

Quoted 6 lines
Quoted 1 line

... here.

I think we should not mix up specified parameters and effective settings. In case an effective setting is of common interest it should be reported via a specific node (like e.g. specific mitigation settings where the cmdline is not providing enough details).

Quoted 4 lines

But then a boolean option that wasn't specified on the command line should produce no output at all. And hence we'd need a way to tell whether an option was set from command line for _all_ of them. I don't think this would be very helpful.

I disagree here.

This is important only for cases where the hypervisor treats the parameter as a tristate: true/false/unspecified. In all cases where the bool value is really true or false it can be reported as such.

Reporting 0/1 for e.g. "ad" if opt_ept_ad==-1 would add a latent problem if any other action would be derived from the parameter variable being -1.

So either opt_ept_ad should be modified to change it to 0/1 instead of only setting the VCMS flag, or the logic should be kept as is in this patch. IMO changing the setting of opt_ept_ad should be done in another patch if this is really wanted.

Quoted 3 lines

I'm curious if anyone else has any opinion either way (or yet another one) here:

Me too.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#36 lore raw

Re: [Xen-devel] [PATCH v6 09/12] xen: add runtime parameter access support to hypfs

Quoted 56 lines · Jürgen Groß
Quoted 50 lines · Jan Beulich
Quoted 42 lines · Jürgen Groß
Quoted 23 lines · Jan Beulich
Quoted 22 lines · Jürgen Groß
Quoted 20 lines · Jan Beulich

Review

Quoted 13 lines · Juergen Gross
(quoted diff) +13 -0
+static void update_ept_param_append(const char *str, int val)
+{
+    char *pos = opt_ept_setting + strlen(opt_ept_setting);
+
+    snprintf(pos, sizeof(opt_ept_setting) - (pos - opt_ept_setting),
+             ",%s=%d", str, val);
+}
+
+static void update_ept_param(void)
+{
+    snprintf(opt_ept_setting, sizeof(opt_ept_setting), "pml=%d", opt_ept_pml);
+    if ( opt_ept_ad >= 0 )
+        update_ept_param_append("ad", opt_ept_ad);

This won't correctly reflect reality: If you look at vmx_init_vmcs_config(), even a negative value means "true" here, unless on a specific Atom model. I think init_ept_param() wants to have that erratum workaround logic moved there, such that you can then assme the value to be non-negative here.

Quoted 4 lines
Quoted 2 lines

But isn't not mentioning it in the -1 case correct? -1 means: do the correct thing on the current hardware.

Well, I think the output here should represent effective settings,

The minimum requirement is to reflect the effective parameters, like cmdline is doing for boot-time only parameters. With runtime parameters we had no way of telling what was set, and this is now possible.

Quoted 9 lines

and a sub-item should be suppressed only if a setting has no effect at all in the current setup, like ...

Quoted 5 lines
Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+    if ( opt_ept_exec_sp >= 0 )
+        update_ept_param_append("exec-sp", opt_ept_exec_sp);

I agree for this one - if the value is still -1, it has neither been set nor is its value of any interest.

Quoted 6 lines
Quoted 1 line

... here.

I think we should not mix up specified parameters and effective settings. In case an effective setting is of common interest it should be reported via a specific node (like e.g. specific mitigation settings where the cmdline is not providing enough details).

Quoted 4 lines

But then a boolean option that wasn't specified on the command line should produce no output at all. And hence we'd need a way to tell whether an option was set from command line for _all_ of them. I don't think this would be very helpful.

Quoted 5 lines

I disagree here.

This is important only for cases where the hypervisor treats the parameter as a tristate: true/false/unspecified. In all cases where the bool value is really true or false it can be reported as such.

The problem I'm having with this is the resulting inconsistency:
When we write the variable with 0 or 1 in case we find it to be -1 after command line parsing, the externally visible effect will be different from the case where we leave it to be -1 yet still treat it as (pseudo-)boolean. This, however, is an implementation detail, while imo the hypfs presentation should not depend on such implementation details.

Quoted 6 lines

Reporting 0/1 for e.g. "ad" if opt_ept_ad==-1 would add a latent problem if any other action would be derived from the parameter variable being -1.

So either opt_ept_ad should be modified to change it to 0/1 instead of only setting the VCMS flag,

That's what I did suggest.

Quoted 3 lines

or the logic should be kept as is in this
patch. IMO changing the setting of opt_ept_ad should be done in another patch if this is really wanted.

And of course I don't mind at all doing so in a prereq patch. It's just that the patch here provides a good place _where_ to actually do such an adjustment.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#37 lore raw

Re: [Xen-devel] [PATCH v6 09/12] xen: add runtime parameter access support to hypfs

Quoted 80 lines · Jan Beulich
Quoted 56 lines · Jürgen Groß
Quoted 50 lines · Jan Beulich
Quoted 42 lines · Jürgen Groß
Quoted 23 lines · Jan Beulich
Quoted 22 lines · Jürgen Groß
Quoted 20 lines · Jan Beulich

Review

Quoted 13 lines · Juergen Gross
(quoted diff) +13 -0
+static void update_ept_param_append(const char *str, int val)
+{
+    char *pos = opt_ept_setting + strlen(opt_ept_setting);
+
+    snprintf(pos, sizeof(opt_ept_setting) - (pos - opt_ept_setting),
+             ",%s=%d", str, val);
+}
+
+static void update_ept_param(void)
+{
+    snprintf(opt_ept_setting, sizeof(opt_ept_setting), "pml=%d", opt_ept_pml);
+    if ( opt_ept_ad >= 0 )
+        update_ept_param_append("ad", opt_ept_ad);

This won't correctly reflect reality: If you look at vmx_init_vmcs_config(), even a negative value means "true" here, unless on a specific Atom model. I think init_ept_param() wants to have that erratum workaround logic moved there, such that you can then assme the value to be non-negative here.

Quoted 4 lines
Quoted 2 lines

But isn't not mentioning it in the -1 case correct? -1 means: do the correct thing on the current hardware.

Well, I think the output here should represent effective settings,

The minimum requirement is to reflect the effective parameters, like cmdline is doing for boot-time only parameters. With runtime parameters we had no way of telling what was set, and this is now possible.

Quoted 9 lines

and a sub-item should be suppressed only if a setting has no effect at all in the current setup, like ...

Quoted 5 lines
Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+    if ( opt_ept_exec_sp >= 0 )
+        update_ept_param_append("exec-sp", opt_ept_exec_sp);

I agree for this one - if the value is still -1, it has neither been set nor is its value of any interest.

Quoted 6 lines
Quoted 1 line

... here.

I think we should not mix up specified parameters and effective settings. In case an effective setting is of common interest it should be reported via a specific node (like e.g. specific mitigation settings where the cmdline is not providing enough details).

Quoted 4 lines

But then a boolean option that wasn't specified on the command line should produce no output at all. And hence we'd need a way to tell whether an option was set from command line for _all_ of them. I don't think this would be very helpful.

Quoted 5 lines

I disagree here.

This is important only for cases where the hypervisor treats the parameter as a tristate: true/false/unspecified. In all cases where the bool value is really true or false it can be reported as such.

The problem I'm having with this is the resulting inconsistency:
When we write the variable with 0 or 1 in case we find it to be -1 after command line parsing, the externally visible effect will be different from the case where we leave it to be -1 yet still treat it as (pseudo-)boolean. This, however, is an implementation detail, while imo the hypfs presentation should not depend on such implementation details.

Quoted 6 lines

Reporting 0/1 for e.g. "ad" if opt_ept_ad==-1 would add a latent problem if any other action would be derived from the parameter variable being -1.

So either opt_ept_ad should be modified to change it to 0/1 instead of only setting the VCMS flag,

That's what I did suggest.

Quoted 7 lines
Quoted 3 lines

or the logic should be kept as is in this
patch. IMO changing the setting of opt_ept_ad should be done in another patch if this is really wanted.

And of course I don't mind at all doing so in a prereq patch. It's just that the patch here provides a good place _where_ to actually do such an adjustment.

I was thinking of something like this:

xen/arch/x86/hvm/vmx/vmcs.c +4 -4
@@ -313,12 +313,12 @@ static int vmx_init_vmcs_config(void)
     {
         rdmsrl(MSR_IA32_VMX_EPT_VPID_CAP, _vmx_ept_vpid_cap);
 
+        if ( /* Work around Erratum AVR41 on Avoton processors. */
+             boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x4d &&
+             opt_ept_ad < 0 )
+            opt_ept_ad = 0;
         if ( !opt_ept_ad )
             _vmx_ept_vpid_cap &= ~VMX_EPT_AD_BIT;
-        else if ( /* Work around Erratum AVR41 on Avoton processors. */
-                  boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x4d &&
-                  opt_ept_ad < 0 )
-            _vmx_ept_vpid_cap &= ~VMX_EPT_AD_BIT;
 
         /*
          * Additional sanity checking before using EPT:

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#38 lore raw

Re: [Xen-devel] [PATCH v6 09/12] xen: add runtime parameter access support to hypfs

Quoted 100 lines · Jürgen Groß
Quoted 80 lines · Jan Beulich
Quoted 56 lines · Jürgen Groß
Quoted 50 lines · Jan Beulich
Quoted 42 lines · Jürgen Groß
Quoted 23 lines · Jan Beulich
Quoted 22 lines · Jürgen Groß
Quoted 20 lines · Jan Beulich

Review

Quoted 13 lines · Juergen Gross
(quoted diff) +13 -0
+static void update_ept_param_append(const char *str, int val)
+{
+    char *pos = opt_ept_setting + strlen(opt_ept_setting);
+
+    snprintf(pos, sizeof(opt_ept_setting) - (pos - opt_ept_setting),
+             ",%s=%d", str, val);
+}
+
+static void update_ept_param(void)
+{
+    snprintf(opt_ept_setting, sizeof(opt_ept_setting), "pml=%d", opt_ept_pml);
+    if ( opt_ept_ad >= 0 )
+        update_ept_param_append("ad", opt_ept_ad);

This won't correctly reflect reality: If you look at vmx_init_vmcs_config(), even a negative value means "true" here, unless on a specific Atom model. I think init_ept_param() wants to have that erratum workaround logic moved there, such that you can then assme the value to be non-negative here.

Quoted 4 lines
Quoted 2 lines

But isn't not mentioning it in the -1 case correct? -1 means: do the correct thing on the current hardware.

Well, I think the output here should represent effective settings,

The minimum requirement is to reflect the effective parameters, like cmdline is doing for boot-time only parameters. With runtime parameters we had no way of telling what was set, and this is now possible.

Quoted 9 lines

and a sub-item should be suppressed only if a setting has no effect at all in the current setup, like ...

Quoted 5 lines
Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+    if ( opt_ept_exec_sp >= 0 )
+        update_ept_param_append("exec-sp", opt_ept_exec_sp);

I agree for this one - if the value is still -1, it has neither been set nor is its value of any interest.

Quoted 6 lines
Quoted 1 line

... here.

I think we should not mix up specified parameters and effective settings. In case an effective setting is of common interest it should be reported via a specific node (like e.g. specific mitigation settings where the cmdline is not providing enough details).

Quoted 4 lines

But then a boolean option that wasn't specified on the command line should produce no output at all. And hence we'd need a way to tell whether an option was set from command line for _all_ of them. I don't think this would be very helpful.

Quoted 5 lines

I disagree here.

This is important only for cases where the hypervisor treats the parameter as a tristate: true/false/unspecified. In all cases where the bool value is really true or false it can be reported as such.

The problem I'm having with this is the resulting inconsistency:
When we write the variable with 0 or 1 in case we find it to be -1 after command line parsing, the externally visible effect will be different from the case where we leave it to be -1 yet still treat it as (pseudo-)boolean. This, however, is an implementation detail, while imo the hypfs presentation should not depend on such implementation details.

Quoted 6 lines

Reporting 0/1 for e.g. "ad" if opt_ept_ad==-1 would add a latent problem if any other action would be derived from the parameter variable being -1.

So either opt_ept_ad should be modified to change it to 0/1 instead of only setting the VCMS flag,

That's what I did suggest.

Quoted 7 lines
Quoted 3 lines

or the logic should be kept as is in this
patch. IMO changing the setting of opt_ept_ad should be done in another patch if this is really wanted.

And of course I don't mind at all doing so in a prereq patch. It's just that the patch here provides a good place _where_ to actually do such an adjustment.

I was thinking of something like this:

xen/arch/x86/hvm/vmx/vmcs.c +3 -0
@@ -313,12 +313,12 @@ static int vmx_init_vmcs_config(void)
      {
          rdmsrl(MSR_IA32_VMX_EPT_VPID_CAP, _vmx_ept_vpid_cap);
 
+        if ( /* Work around Erratum AVR41 on Avoton processors. */
+             boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x4d &&
+             opt_ept_ad < 0 )

xen/arch/x86/hvm/vmx/vmcs.c static int vmx_init_vmcs_config(void) · line 324

Quoted 10 lines
xen/arch/x86/hvm/vmx/vmcs.c +1 -4
+            opt_ept_ad = 0;
          if ( !opt_ept_ad )
              _vmx_ept_vpid_cap &= ~VMX_EPT_AD_BIT;
-        else if ( /* Work around Erratum AVR41 on Avoton processors. */
-                  boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x4d &&
-                  opt_ept_ad < 0 )
-            _vmx_ept_vpid_cap &= ~VMX_EPT_AD_BIT;
 
          /*
           * Additional sanity checking before using EPT:

And I was specifically hoping to avoid doing this in a non-__init function.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#39 lore raw

Re: [Xen-devel] [PATCH v6 09/12] xen: add runtime parameter access support to hypfs

Quoted 109 lines · Jan Beulich
Quoted 108 lines · Jürgen Groß
Quoted 80 lines · Jan Beulich
Quoted 56 lines · Jürgen Groß
Quoted 50 lines · Jan Beulich
Quoted 42 lines · Jürgen Groß
Quoted 23 lines · Jan Beulich
Quoted 22 lines · Jürgen Groß
Quoted 20 lines · Jan Beulich

Review

Quoted 13 lines · Juergen Gross
(quoted diff) +13 -0
+static void update_ept_param_append(const char *str, int val)
+{
+    char *pos = opt_ept_setting + strlen(opt_ept_setting);
+
+    snprintf(pos, sizeof(opt_ept_setting) - (pos - opt_ept_setting),
+             ",%s=%d", str, val);
+}
+
+static void update_ept_param(void)
+{
+    snprintf(opt_ept_setting, sizeof(opt_ept_setting), "pml=%d", opt_ept_pml);
+    if ( opt_ept_ad >= 0 )
+        update_ept_param_append("ad", opt_ept_ad);

This won't correctly reflect reality: If you look at vmx_init_vmcs_config(), even a negative value means "true" here, unless on a specific Atom model. I think init_ept_param() wants to have that erratum workaround logic moved there, such that you can then assme the value to be non-negative here.

Quoted 4 lines
Quoted 2 lines

But isn't not mentioning it in the -1 case correct? -1 means: do the correct thing on the current hardware.

Well, I think the output here should represent effective settings,

The minimum requirement is to reflect the effective parameters, like cmdline is doing for boot-time only parameters. With runtime parameters we had no way of telling what was set, and this is now possible.

Quoted 9 lines

and a sub-item should be suppressed only if a setting has no effect at all in the current setup, like ...

Quoted 5 lines
Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+    if ( opt_ept_exec_sp >= 0 )
+        update_ept_param_append("exec-sp", opt_ept_exec_sp);

I agree for this one - if the value is still -1, it has neither been set nor is its value of any interest.

Quoted 6 lines
Quoted 1 line

... here.

I think we should not mix up specified parameters and effective settings. In case an effective setting is of common interest it should be reported via a specific node (like e.g. specific mitigation settings where the cmdline is not providing enough details).

Quoted 4 lines

But then a boolean option that wasn't specified on the command line should produce no output at all. And hence we'd need a way to tell whether an option was set from command line for _all_ of them. I don't think this would be very helpful.

Quoted 5 lines

I disagree here.

This is important only for cases where the hypervisor treats the parameter as a tristate: true/false/unspecified. In all cases where the bool value is really true or false it can be reported as such.

The problem I'm having with this is the resulting inconsistency:
When we write the variable with 0 or 1 in case we find it to be -1 after command line parsing, the externally visible effect will be different from the case where we leave it to be -1 yet still treat it as (pseudo-)boolean. This, however, is an implementation detail, while imo the hypfs presentation should not depend on such implementation details.

Quoted 6 lines

Reporting 0/1 for e.g. "ad" if opt_ept_ad==-1 would add a latent problem if any other action would be derived from the parameter variable being -1.

So either opt_ept_ad should be modified to change it to 0/1 instead of only setting the VCMS flag,

That's what I did suggest.

Quoted 7 lines
Quoted 3 lines

or the logic should be kept as is in this
patch. IMO changing the setting of opt_ept_ad should be done in another patch if this is really wanted.

And of course I don't mind at all doing so in a prereq patch. It's just that the patch here provides a good place _where_ to actually do such an adjustment.

I was thinking of something like this:

xen/arch/x86/hvm/vmx/vmcs.c +4 -4
@@ -313,12 +313,12 @@ static int vmx_init_vmcs_config(void)
       {
           rdmsrl(MSR_IA32_VMX_EPT_VPID_CAP, _vmx_ept_vpid_cap);
 
+        if ( /* Work around Erratum AVR41 on Avoton processors. */
+             boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x4d &&
+             opt_ept_ad < 0 )
+            opt_ept_ad = 0;
           if ( !opt_ept_ad )
               _vmx_ept_vpid_cap &= ~VMX_EPT_AD_BIT;
-        else if ( /* Work around Erratum AVR41 on Avoton processors. */
-                  boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x4d &&
-                  opt_ept_ad < 0 )
-            _vmx_ept_vpid_cap &= ~VMX_EPT_AD_BIT;
 
Quoted 5 lines

xen/arch/x86/hvm/vmx/vmcs.c static int vmx_init_vmcs_config(void) · line 324

Quoted 2 lines
xen/arch/x86/hvm/vmx/vmcs.c +0 -0
           /*
            * Additional sanity checking before using EPT:

And I was specifically hoping to avoid doing this in a non-__init function.

Should be fairly easy (see attached patch).

Juergen

From 32f307522c2044130bb8ed66189efc411c540103 Mon Sep 17 00:00:00 2001
From: Juergen Gross <[email protected]>
Date: Fri, 6 Mar 2020 07:30:36 +0100
Subject: [PATCH] xen/vmx: let opt_ept_ad always reflect the current setting

In case opt_ept_ad has not been set explicitly by the user via command line or runtime parameter, it is treated as "no" on Avoton cpus.

Change that handling by setting opt_ept_ad to 0 for this cpu type explicitly if no user value has been set.

By putting this into the (renamed) boot time initialization of vmcs.c _vmx_cpu_up() can be made static.

---
 xen/arch/x86/hvm/vmx/vmcs.c        | 22 +++++++++++++++-------
 xen/arch/x86/hvm/vmx/vmx.c         |  4 +---
 xen/include/asm-x86/hvm/vmx/vmcs.h |  3 +--
 3 files changed, 17 insertions(+), 12 deletions(-)
xen/arch/x86/hvm/vmx/vmcs.c +15 -7
index 4c23645454..24f2bd6e43 100644
@@ -315,10 +315,6 @@ static int vmx_init_vmcs_config(void)
 
         if ( !opt_ept_ad )
             _vmx_ept_vpid_cap &= ~VMX_EPT_AD_BIT;
-        else if ( /* Work around Erratum AVR41 on Avoton processors. */
-                  boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x4d &&
-                  opt_ept_ad < 0 )
-            _vmx_ept_vpid_cap &= ~VMX_EPT_AD_BIT;
 
         /*
          * Additional sanity checking before using EPT:
@@ -652,7 +648,7 @@ void vmx_cpu_dead(unsigned int cpu)
     vmx_pi_desc_fixup(cpu);
 }
 
-int _vmx_cpu_up(bool bsp)
+static int _vmx_cpu_up(bool bsp)
 {
     u32 eax, edx;
     int rc, bios_locked, cpu = smp_processor_id();
@@ -2108,9 +2104,21 @@ static void vmcs_dump(unsigned char ch)
     printk("**************************************\n");
 }
 
-void __init setup_vmcs_dump(void)
+int __init vmx_vmcs_init(void)
 {
-    register_keyhandler('v', vmcs_dump, "dump VT-x VMCSs", 1);
+    int ret;
+
+    if ( opt_ept_ad < 0 )
+        /* Work around Erratum AVR41 on Avoton processors. */
+        opt_ept_ad = (boot_cpu_data.x86 == 6 &&
+                      boot_cpu_data.x86_model == 0x4d) ? 0 : 1;
+
+    ret = _vmx_cpu_up(true);
+
+    if ( !ret )
+        register_keyhandler('v', vmcs_dump, "dump VT-x VMCSs", 1);
+
+    return ret;
 }
 
 static void __init __maybe_unused build_assertions(void)
xen/arch/x86/hvm/vmx/vmx.c +1 -3
index d265ed46ad..d0ad2ed879 100644
@@ -2478,7 +2478,7 @@ const struct hvm_function_table * __init start_vmx(void)
 {
     set_in_cr4(X86_CR4_VMXE);
 
-    if ( _vmx_cpu_up(true) )
+    if ( vmx_vmcs_init() )
     {
         printk("VMX: failed to initialise.\n");
         return NULL;
@@ -2549,8 +2549,6 @@ const struct hvm_function_table * __init start_vmx(void)
         vmx_function_table.get_guest_bndcfgs = vmx_get_guest_bndcfgs;
     }
 
-    setup_vmcs_dump();
-
     lbr_tsx_fixup_check();
     bdf93_fixup_check();
 
xen/include/asm-x86/hvm/vmx/vmcs.h +1 -2
index be4661a929..b346a132e2 100644
@@ -21,11 +21,10 @@
 #include <asm/hvm/io.h>
 
 extern void vmcs_dump_vcpu(struct vcpu *v);
-extern void setup_vmcs_dump(void);
+extern int vmx_vmcs_init(void);
 extern int  vmx_cpu_up_prepare(unsigned int cpu);
 extern void vmx_cpu_dead(unsigned int cpu);
 extern int  vmx_cpu_up(void);
-extern int  _vmx_cpu_up(bool bsp);
 extern void vmx_cpu_down(void);
 
 struct vmcs_struct {
Signature · 1 line
2.16.4

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#40 lore raw

Re: [Xen-devel] [PATCH v6 09/12] xen: add runtime parameter access support to hypfs

Quoted 110 lines · Jürgen Groß
Quoted 109 lines · Jan Beulich
Quoted 108 lines · Jürgen Groß
Quoted 80 lines · Jan Beulich
Quoted 56 lines · Jürgen Groß
Quoted 50 lines · Jan Beulich
Quoted 42 lines · Jürgen Groß
Quoted 23 lines · Jan Beulich
Quoted 22 lines · Jürgen Groß
Quoted 20 lines · Jan Beulich

Review

Quoted 13 lines · Juergen Gross
(quoted diff) +13 -0
+static void update_ept_param_append(const char *str, int val)
+{
+    char *pos = opt_ept_setting + strlen(opt_ept_setting);
+
+    snprintf(pos, sizeof(opt_ept_setting) - (pos - opt_ept_setting),
+             ",%s=%d", str, val);
+}
+
+static void update_ept_param(void)
+{
+    snprintf(opt_ept_setting, sizeof(opt_ept_setting), "pml=%d", opt_ept_pml);
+    if ( opt_ept_ad >= 0 )
+        update_ept_param_append("ad", opt_ept_ad);

This won't correctly reflect reality: If you look at vmx_init_vmcs_config(), even a negative value means "true" here, unless on a specific Atom model. I think init_ept_param() wants to have that erratum workaround logic moved there, such that you can then assme the value to be non-negative here.

Quoted 4 lines
Quoted 2 lines

But isn't not mentioning it in the -1 case correct? -1 means: do the correct thing on the current hardware.

Well, I think the output here should represent effective settings,

The minimum requirement is to reflect the effective parameters, like cmdline is doing for boot-time only parameters. With runtime parameters we had no way of telling what was set, and this is now possible.

Quoted 9 lines

and a sub-item should be suppressed only if a setting has no effect at all in the current setup, like ...

Quoted 5 lines
Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+    if ( opt_ept_exec_sp >= 0 )
+        update_ept_param_append("exec-sp", opt_ept_exec_sp);

I agree for this one - if the value is still -1, it has neither been set nor is its value of any interest.

Quoted 6 lines
Quoted 1 line

... here.

I think we should not mix up specified parameters and effective settings. In case an effective setting is of common interest it should be reported via a specific node (like e.g. specific mitigation settings where the cmdline is not providing enough details).

Quoted 4 lines

But then a boolean option that wasn't specified on the command line should produce no output at all. And hence we'd need a way to tell whether an option was set from command line for _all_ of them. I don't think this would be very helpful.

Quoted 5 lines

I disagree here.

This is important only for cases where the hypervisor treats the parameter as a tristate: true/false/unspecified. In all cases where the bool value is really true or false it can be reported as such.

The problem I'm having with this is the resulting inconsistency:
When we write the variable with 0 or 1 in case we find it to be -1 after command line parsing, the externally visible effect will be different from the case where we leave it to be -1 yet still treat it as (pseudo-)boolean. This, however, is an implementation detail, while imo the hypfs presentation should not depend on such implementation details.

Quoted 6 lines

Reporting 0/1 for e.g. "ad" if opt_ept_ad==-1 would add a latent problem if any other action would be derived from the parameter variable being -1.

So either opt_ept_ad should be modified to change it to 0/1 instead of only setting the VCMS flag,

That's what I did suggest.

Quoted 7 lines
Quoted 3 lines

or the logic should be kept as is in this
patch. IMO changing the setting of opt_ept_ad should be done in another patch if this is really wanted.

And of course I don't mind at all doing so in a prereq patch. It's just that the patch here provides a good place _where_ to actually do such an adjustment.

I was thinking of something like this:

xen/arch/x86/hvm/vmx/vmcs.c +4 -4
@@ -313,12 +313,12 @@ static int vmx_init_vmcs_config(void)
       {
           rdmsrl(MSR_IA32_VMX_EPT_VPID_CAP, _vmx_ept_vpid_cap);
 
+        if ( /* Work around Erratum AVR41 on Avoton processors. */
+             boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x4d &&
+             opt_ept_ad < 0 )
+            opt_ept_ad = 0;
           if ( !opt_ept_ad )
               _vmx_ept_vpid_cap &= ~VMX_EPT_AD_BIT;
-        else if ( /* Work around Erratum AVR41 on Avoton processors. */
-                  boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x4d &&
-                  opt_ept_ad < 0 )
-            _vmx_ept_vpid_cap &= ~VMX_EPT_AD_BIT;
 
Quoted 7 lines
Quoted 5 lines

xen/arch/x86/hvm/vmx/vmcs.c static int vmx_init_vmcs_config(void) · line 320

Quoted 2 lines
xen/arch/x86/hvm/vmx/vmcs.c +0 -0
           /*
            * Additional sanity checking before using EPT:

And I was specifically hoping to avoid doing this in a non-__init function.

Should be fairly easy (see attached patch).

Why not put the opt_ept_ad adjustment right into start_vmx(), just like e.g. the opt_ept_exec_sp gets also done there? Pulling the setting up of the 'v' key handler risks installing it ahead of a potential future later error exit from start_vmx(). But I'm not entirely opposed to the chosen approach either - it'll be up to Kevin to judge, I guess.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#41 lore raw

Re: [Xen-devel] [PATCH v6 09/12] xen: add runtime parameter access support to hypfs

Quoted 117 lines · Jan Beulich
Quoted 116 lines · Jürgen Groß
Quoted 114 lines · Jan Beulich
Quoted 100 lines · Jürgen Groß
Quoted 80 lines · Jan Beulich
Quoted 56 lines · Jürgen Groß
Quoted 50 lines · Jan Beulich
Quoted 42 lines · Jürgen Groß
Quoted 23 lines · Jan Beulich
Quoted 22 lines · Jürgen Groß
Quoted 20 lines · Jan Beulich

Review

Quoted 13 lines · Juergen Gross
(quoted diff) +13 -0
+static void update_ept_param_append(const char *str, int val)
+{
+    char *pos = opt_ept_setting + strlen(opt_ept_setting);
+
+    snprintf(pos, sizeof(opt_ept_setting) - (pos - opt_ept_setting),
+             ",%s=%d", str, val);
+}
+
+static void update_ept_param(void)
+{
+    snprintf(opt_ept_setting, sizeof(opt_ept_setting), "pml=%d", opt_ept_pml);
+    if ( opt_ept_ad >= 0 )
+        update_ept_param_append("ad", opt_ept_ad);

This won't correctly reflect reality: If you look at vmx_init_vmcs_config(), even a negative value means "true" here, unless on a specific Atom model. I think init_ept_param() wants to have that erratum workaround logic moved there, such that you can then assme the value to be non-negative here.

Quoted 4 lines
Quoted 2 lines

But isn't not mentioning it in the -1 case correct? -1 means: do the correct thing on the current hardware.

Well, I think the output here should represent effective settings,

The minimum requirement is to reflect the effective parameters, like cmdline is doing for boot-time only parameters. With runtime parameters we had no way of telling what was set, and this is now possible.

Quoted 9 lines

and a sub-item should be suppressed only if a setting has no effect at all in the current setup, like ...

Quoted 5 lines
Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+    if ( opt_ept_exec_sp >= 0 )
+        update_ept_param_append("exec-sp", opt_ept_exec_sp);

I agree for this one - if the value is still -1, it has neither been set nor is its value of any interest.

Quoted 6 lines
Quoted 1 line

... here.

I think we should not mix up specified parameters and effective settings. In case an effective setting is of common interest it should be reported via a specific node (like e.g. specific mitigation settings where the cmdline is not providing enough details).

Quoted 4 lines

But then a boolean option that wasn't specified on the command line should produce no output at all. And hence we'd need a way to tell whether an option was set from command line for _all_ of them. I don't think this would be very helpful.

Quoted 5 lines

I disagree here.

This is important only for cases where the hypervisor treats the parameter as a tristate: true/false/unspecified. In all cases where the bool value is really true or false it can be reported as such.

The problem I'm having with this is the resulting inconsistency:
When we write the variable with 0 or 1 in case we find it to be -1 after command line parsing, the externally visible effect will be different from the case where we leave it to be -1 yet still treat it as (pseudo-)boolean. This, however, is an implementation detail, while imo the hypfs presentation should not depend on such implementation details.

Quoted 6 lines

Reporting 0/1 for e.g. "ad" if opt_ept_ad==-1 would add a latent problem if any other action would be derived from the parameter variable being -1.

So either opt_ept_ad should be modified to change it to 0/1 instead of only setting the VCMS flag,

That's what I did suggest.

Quoted 7 lines
Quoted 3 lines

or the logic should be kept as is in this
patch. IMO changing the setting of opt_ept_ad should be done in another patch if this is really wanted.

And of course I don't mind at all doing so in a prereq patch. It's just that the patch here provides a good place _where_ to actually do such an adjustment.

I was thinking of something like this:

xen/arch/x86/hvm/vmx/vmcs.c +3 -0
@@ -313,12 +313,12 @@ static int vmx_init_vmcs_config(void)
        {
            rdmsrl(MSR_IA32_VMX_EPT_VPID_CAP, _vmx_ept_vpid_cap);
 
+        if ( /* Work around Erratum AVR41 on Avoton processors. */
+             boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x4d &&
+             opt_ept_ad < 0 )

xen/arch/x86/hvm/vmx/vmcs.c static int vmx_init_vmcs_config(void) · line 324

Quoted 10 lines
xen/arch/x86/hvm/vmx/vmcs.c +1 -4
+            opt_ept_ad = 0;
            if ( !opt_ept_ad )
                _vmx_ept_vpid_cap &= ~VMX_EPT_AD_BIT;
-        else if ( /* Work around Erratum AVR41 on Avoton processors. */
-                  boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x4d &&
-                  opt_ept_ad < 0 )
-            _vmx_ept_vpid_cap &= ~VMX_EPT_AD_BIT;
 
            /*
             * Additional sanity checking before using EPT:

And I was specifically hoping to avoid doing this in a non-__init function.

Quoted 6 lines
Quoted 1 line

Should be fairly easy (see attached patch).

Why not put the opt_ept_ad adjustment right into start_vmx(), just like e.g. the opt_ept_exec_sp gets also done there? Pulling the setting up of the 'v' key handler risks installing it ahead of a potential future later error exit from start_vmx(). But I'm

Is this really problematic?

How probable is it to have a HVM domain running when an early error exit from start_vmx() happened (hint: hvm_enabled will be 0 in this case) ?

Quoted 2 lines

not entirely opposed to the chosen approach either - it'll be up to Kevin to judge, I guess.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#42 lore raw

Re: [Xen-devel] [PATCH v6 09/12] xen: add runtime parameter access support to hypfs

Quoted 118 lines · Jürgen Groß
Quoted 117 lines · Jan Beulich
Quoted 116 lines · Jürgen Groß
Quoted 114 lines · Jan Beulich
Quoted 100 lines · Jürgen Groß
Quoted 80 lines · Jan Beulich
Quoted 56 lines · Jürgen Groß
Quoted 50 lines · Jan Beulich
Quoted 42 lines · Jürgen Groß
Quoted 23 lines · Jan Beulich
Quoted 22 lines · Jürgen Groß
Quoted 20 lines · Jan Beulich
Quoted 13 lines · Juergen Gross

+static void update_ept_param_append(const char *str, int val)
+{
+ char *pos = opt_ept_setting + strlen(opt_ept_setting);
+
+ snprintf(pos, sizeof(opt_ept_setting) - (pos - opt_ept_setting),
+ ",%s=%d", str, val);
+}
+
+static void update_ept_param(void)
+{
+ snprintf(opt_ept_setting, sizeof(opt_ept_setting), "pml=%d", opt_ept_pml);
+ if ( opt_ept_ad >= 0 )
+ update_ept_param_append("ad", opt_ept_ad);

This won't correctly reflect reality: If you look at vmx_init_vmcs_config(), even a negative value means "true" here, unless on a specific Atom model. I think init_ept_param() wants to have that erratum workaround logic moved there, such that you can then assme the value to be non-negative here.

Quoted 4 lines
Quoted 2 lines

But isn't not mentioning it in the -1 case correct? -1 means: do the correct thing on the current hardware.

Well, I think the output here should represent effective settings,

The minimum requirement is to reflect the effective parameters, like cmdline is doing for boot-time only parameters. With runtime parameters we had no way of telling what was set, and this is now possible.

Quoted 9 lines

and a sub-item should be suppressed only if a setting has no effect at all in the current setup, like ...

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

+ if ( opt_ept_exec_sp >= 0 )
+ update_ept_param_append("exec-sp", opt_ept_exec_sp);

I agree for this one - if the value is still -1, it has neither been set nor is its value of any interest.

Quoted 6 lines
Quoted 1 line

... here.

I think we should not mix up specified parameters and effective settings. In case an effective setting is of common interest it should be reported via a specific node (like e.g. specific mitigation settings where the cmdline is not providing enough details).

Quoted 4 lines

But then a boolean option that wasn't specified on the command line should produce no output at all. And hence we'd need a way to tell whether an option was set from command line for _all_ of them. I don't think this would be very helpful.

Quoted 5 lines

I disagree here.

This is important only for cases where the hypervisor treats the parameter as a tristate: true/false/unspecified. In all cases where the bool value is really true or false it can be reported as such.

The problem I'm having with this is the resulting inconsistency:
When we write the variable with 0 or 1 in case we find it to be -1 after command line parsing, the externally visible effect will be different from the case where we leave it to be -1 yet still treat it as (pseudo-)boolean. This, however, is an implementation detail, while imo the hypfs presentation should not depend on such implementation details.

Quoted 6 lines

Reporting 0/1 for e.g. "ad" if opt_ept_ad==-1 would add a latent problem if any other action would be derived from the parameter variable being -1.

So either opt_ept_ad should be modified to change it to 0/1 instead of only setting the VCMS flag,

That's what I did suggest.

Quoted 7 lines
Quoted 3 lines

or the logic should be kept as is in this
patch. IMO changing the setting of opt_ept_ad should be done in another patch if this is really wanted.

And of course I don't mind at all doing so in a prereq patch. It's just that the patch here provides a good place _where_ to actually do such an adjustment.

I was thinking of something like this:

xen/arch/x86/hvm/vmx/vmcs.c +3 -0
@@ -313,12 +313,12 @@ static int vmx_init_vmcs_config(void)
        {
            rdmsrl(MSR_IA32_VMX_EPT_VPID_CAP, _vmx_ept_vpid_cap);
 
+        if ( /* Work around Erratum AVR41 on Avoton processors. */
+             boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x4d &&
+             opt_ept_ad < 0 )

xen/arch/x86/hvm/vmx/vmcs.c static int vmx_init_vmcs_config(void) · line 324

Quoted 10 lines
xen/arch/x86/hvm/vmx/vmcs.c +1 -4
+            opt_ept_ad = 0;
            if ( !opt_ept_ad )
                _vmx_ept_vpid_cap &= ~VMX_EPT_AD_BIT;
-        else if ( /* Work around Erratum AVR41 on Avoton processors. */
-                  boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x4d &&
-                  opt_ept_ad < 0 )
-            _vmx_ept_vpid_cap &= ~VMX_EPT_AD_BIT;
 
            /*
             * Additional sanity checking before using EPT:

And I was specifically hoping to avoid doing this in a non-__init function.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Should be fairly easy (see attached patch).

Why not put the opt_ept_ad adjustment right into start_vmx(), just like e.g. the opt_ept_exec_sp gets also done there? Pulling the setting up of the 'v' key handler risks installing it ahead of a potential future later error exit from start_vmx(). But I'm

Is this really problematic?

Not _really_, but still. In particular I'd prefer the 'v' key to not even be listed among 'h' key output in such a case.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#43 lore raw

Re: [Xen-devel] [PATCH v6 09/12] xen: add runtime parameter access support to hypfs

Quoted 126 lines · Jan Beulich
Quoted 125 lines · Jürgen Groß
Quoted 123 lines · Jan Beulich
Quoted 110 lines · Jürgen Groß
Quoted 109 lines · Jan Beulich
Quoted 108 lines · Jürgen Groß
Quoted 80 lines · Jan Beulich
Quoted 56 lines · Jürgen Groß
Quoted 50 lines · Jan Beulich
Quoted 42 lines · Jürgen Groß
Quoted 23 lines · Jan Beulich
Quoted 22 lines · Jürgen Groß
Quoted 20 lines · Jan Beulich

On 26.02.2020 13:47, Juergen Gross wrote:
+static void update_ept_param_append(const char *str, int val)
+{
+ char *pos = opt_ept_setting + strlen(opt_ept_setting);
+
+ snprintf(pos, sizeof(opt_ept_setting) - (pos - opt_ept_setting),
+ ",%s=%d", str, val);
+}
+
+static void update_ept_param(void)
+{
+ snprintf(opt_ept_setting, sizeof(opt_ept_setting), "pml=%d", opt_ept_pml);
+ if ( opt_ept_ad >= 0 )
+ update_ept_param_append("ad", opt_ept_ad);

This won't correctly reflect reality: If you look at
vmx_init_vmcs_config(), even a negative value means "true" here,
unless on a specific Atom model. I think init_ept_param() wants
to have that erratum workaround logic moved there, such that
you can then assme the value to be non-negative here.

Quoted 4 lines
Quoted 2 lines

But isn't not mentioning it in the -1 case correct? -1 means: do the correct thing on the current hardware.

Well, I think the output here should represent effective settings,

The minimum requirement is to reflect the effective parameters, like cmdline is doing for boot-time only parameters. With runtime parameters we had no way of telling what was set, and this is now possible.

Quoted 9 lines

and a sub-item should be suppressed only if a setting has no effect at all in the current setup, like ...

Quoted 5 lines
Quoted 5 lines

+ if ( opt_ept_exec_sp >= 0 )
+ update_ept_param_append("exec-sp", opt_ept_exec_sp);

I agree for this one - if the value is still -1, it has neither
been set nor is its value of any interest.

Quoted 6 lines
Quoted 1 line

... here.

I think we should not mix up specified parameters and effective settings. In case an effective setting is of common interest it should be reported via a specific node (like e.g. specific mitigation settings where the cmdline is not providing enough details).

Quoted 4 lines

But then a boolean option that wasn't specified on the command line should produce no output at all. And hence we'd need a way to tell whether an option was set from command line for _all_ of them. I don't think this would be very helpful.

Quoted 5 lines

I disagree here.

This is important only for cases where the hypervisor treats the parameter as a tristate: true/false/unspecified. In all cases where the bool value is really true or false it can be reported as such.

The problem I'm having with this is the resulting inconsistency:
When we write the variable with 0 or 1 in case we find it to be -1 after command line parsing, the externally visible effect will be different from the case where we leave it to be -1 yet still treat it as (pseudo-)boolean. This, however, is an implementation detail, while imo the hypfs presentation should not depend on such implementation details.

Quoted 6 lines

Reporting 0/1 for e.g. "ad" if opt_ept_ad==-1 would add a latent problem if any other action would be derived from the parameter variable being -1.

So either opt_ept_ad should be modified to change it to 0/1 instead of only setting the VCMS flag,

That's what I did suggest.

Quoted 7 lines
Quoted 3 lines

or the logic should be kept as is in this
patch. IMO changing the setting of opt_ept_ad should be done in another patch if this is really wanted.

And of course I don't mind at all doing so in a prereq patch. It's just that the patch here provides a good place _where_ to actually do such an adjustment.

I was thinking of something like this:

xen/arch/x86/hvm/vmx/vmcs.c +4 -4
@@ -313,12 +313,12 @@ static int vmx_init_vmcs_config(void)
         {
             rdmsrl(MSR_IA32_VMX_EPT_VPID_CAP, _vmx_ept_vpid_cap);
 
+        if ( /* Work around Erratum AVR41 on Avoton processors. */
+             boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x4d &&
+             opt_ept_ad < 0 )
+            opt_ept_ad = 0;
             if ( !opt_ept_ad )
                 _vmx_ept_vpid_cap &= ~VMX_EPT_AD_BIT;
-        else if ( /* Work around Erratum AVR41 on Avoton processors. */
-                  boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 0x4d &&
-                  opt_ept_ad < 0 )
-            _vmx_ept_vpid_cap &= ~VMX_EPT_AD_BIT;
 
Quoted 7 lines
Quoted 5 lines

xen/arch/x86/hvm/vmx/vmcs.c static int vmx_init_vmcs_config(void) · line 320

Quoted 2 lines
xen/arch/x86/hvm/vmx/vmcs.c +0 -0
             /*
              * Additional sanity checking before using EPT:

And I was specifically hoping to avoid doing this in a non-__init function.

Should be fairly easy (see attached patch).

Why not put the opt_ept_ad adjustment right into start_vmx(), just like e.g. the opt_ept_exec_sp gets also done there? Pulling the setting up of the 'v' key handler risks installing it ahead of a potential future later error exit from start_vmx(). But I'm

Quoted 4 lines
Quoted 1 line

Is this really problematic?

Not _really_, but still. In particular I'd prefer the 'v' key to not even be listed among 'h' key output in such a case.

Now this is an optimization for a supposedly never to happen error case only theoretically possible with future code additions.

In order to prepare for this case I don't think we should export opt_ept_ad and put the setting of it at the very first thing to do in start_vmx().

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#44 lore raw

Re: [Xen-devel] [PATCH v6 09/12] xen: add runtime parameter access support to hypfs

In reply to Juergen Gross

Hi Juergen & Jan,

Quoted 22 lines · Juergen Gross
docs/misc/hypfs-paths.pandoc +9 -0
index 1faebcccbc..b4a5b6086e 100644
@@ -152,3 +152,12 @@ The major version of Xen.
  #### /buildinfo/version/minor = INTEGER
 
  The minor version of Xen.
+
+#### /params/
+
+A directory of runtime parameters.
+
+#### /params/*
+
+The individual parameters. The description of the different parameters can be
+found in `docs/misc/xen-command-line.pandoc`.
xen/arch/arm/xen.lds.S +0 -0
index a497f6a48d..0061a8dfea 100644

xen/arch/arm/xen.lds.S SECTIONS · line 93

Quoted 5 lines
xen/arch/arm/xen.lds.S +2 -0
@@ -89,6 +89,11 @@ SECTIONS
         __start_schedulers_array = .;
         *(.data.schedulers)
         __end_schedulers_array = .;
+
+       . = ALIGN(8);

Apologies for the late answer. I noticed that Jan asked the following question on v5:

"Do you really need 8-byte alignment even on 32-bit Arm?"

We forbid unaligned access on 32-bit Arm (and unaligned access should be avoided on 64-bit), so if the structure contains a 64-bit type, then we definitely need the data to be 8-byte aligned.

What is the expected alignment of the structure?

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#45 lore raw

PATCH v6 10/12 tools/libxl: use libxenhypfs for setting xen runtime parameters

In reply to Juergen Gross

Instead of xc_set_parameters() use xenhypfs_write() for setting parameters of the hypervisor.

---
V6:
- new patch

---
 tools/Rules.mk               |  2 +-
 tools/libxl/Makefile         |  3 ++-
 tools/libxl/libxl.c          | 53 +++++++++++++++++++++++++++++++++++++++-----
 tools/libxl/libxl_internal.h |  1 +
 tools/libxl/xenlight.pc.in   |  2 +-
 tools/xl/xl_misc.c           |  1 -
 6 files changed, 52 insertions(+), 10 deletions(-)
tools/Rules.mk +1 -1
index a04697a33c..4b3fcef90b 100644
@@ -180,7 +180,7 @@ CFLAGS += -O2 -fomit-frame-pointer
 endif
 
 CFLAGS_libxenlight = -I$(XEN_XENLIGHT) $(CFLAGS_libxenctrl) $(CFLAGS_xeninclude)
-SHDEPS_libxenlight = $(SHLIB_libxenctrl) $(SHLIB_libxenstore)
+SHDEPS_libxenlight = $(SHLIB_libxenctrl) $(SHLIB_libxenstore) $(SHLIB_libxenhypfs)
 LDLIBS_libxenlight = $(SHDEPS_libxenlight) $(XEN_XENLIGHT)/libxenlight$(libextension)
 SHLIB_libxenlight  = $(SHDEPS_libxenlight) -Wl,-rpath-link=$(XEN_XENLIGHT)
 
tools/libxl/Makefile +2 -1
index 69fcf21577..a89ebab0b4 100644
@@ -20,7 +20,7 @@ LIBUUID_LIBS += -luuid
 endif
 
 LIBXL_LIBS =
-LIBXL_LIBS = $(LDLIBS_libxentoollog) $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) $(LDLIBS_libxentoolcore) $(PTYFUNCS_LIBS) $(LIBUUID_LIBS)
+LIBXL_LIBS = $(LDLIBS_libxentoollog) $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenhypfs) $(LDLIBS_libxenstore) $(LDLIBS_libxentoolcore) $(PTYFUNCS_LIBS) $(LIBUUID_LIBS)
 ifeq ($(CONFIG_LIBNL),y)
 LIBXL_LIBS += $(LIBNL3_LIBS)
 endif
@@ -33,6 +33,7 @@ CFLAGS_LIBXL += $(CFLAGS_libxentoolcore)
 CFLAGS_LIBXL += $(CFLAGS_libxenevtchn)
 CFLAGS_LIBXL += $(CFLAGS_libxenctrl)
 CFLAGS_LIBXL += $(CFLAGS_libxenguest)
+CFLAGS_LIBXL += $(CFLAGS_libxenhypfs)
 CFLAGS_LIBXL += $(CFLAGS_libxenstore)
 ifeq ($(CONFIG_LIBNL),y)
 CFLAGS_LIBXL += $(LIBNL3_CFLAGS)
tools/libxl/libxl.c +47 -6

62 lines not on this page · raw message

tools/libxl/libxl_internal.h +1 -0
index 43e5885d1e..d970e91ca0 100644
@@ -56,6 +56,7 @@
 #define XC_WANT_COMPAT_MAP_FOREIGN_API
 #include <xenctrl.h>
 #include <xenguest.h>
+#include <xenhypfs.h>
 #include <xc_dom.h>
 
 #include <xen-tools/libs.h>
tools/libxl/xenlight.pc.in +1 -1
index c0f769fd20..6b351ba096 100644
@@ -9,4 +9,4 @@ Description: The Xenlight library for Xen hypervisor
 Version: @@version@@
 Cflags: -I${includedir}
 Libs: @@libsflag@@${libdir} -lxenlight
-Requires.private: xentoollog,xenevtchn,xencontrol,xenguest,xenstore
+Requires.private: xentoollog,xenevtchn,xencontrol,xenguest,xenstore,xenhypfs
tools/xl/xl_misc.c +0 -1
index 20ed605f4f..08f0fb6dc9 100644
@@ -168,7 +168,6 @@ int main_set_parameters(int argc, char **argv)
 
     if (libxl_set_parameters(ctx, params)) {
         fprintf(stderr, "cannot set parameters: %s\n", params);
-        fprintf(stderr, "Use \"xl dmesg\" to look for possible reason.\n");
         return EXIT_FAILURE;
     }
 
Signature · 7 lines
2.16.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#46 lore raw

PATCH v6 11/12 tools/libxc: remove xc_set_parameters()

In reply to Juergen Gross

There is no user of xc_set_parameters() left, so remove it.

---
V6:
- new patch

---
 tools/libxc/include/xenctrl.h |  1 -
 tools/libxc/xc_misc.c         | 21 ---------------------
 2 files changed, 22 deletions(-)
tools/libxc/include/xenctrl.h +0 -1
index 99552a5f73..8677433c5f 100644
@@ -1226,7 +1226,6 @@ int xc_readconsolering(xc_interface *xch,
                        int clear, int incremental, uint32_t *pindex);
 
 int xc_send_debug_keys(xc_interface *xch, char *keys);
-int xc_set_parameters(xc_interface *xch, char *params);
 
 typedef struct xen_sysctl_physinfo xc_physinfo_t;
 typedef struct xen_sysctl_cputopo xc_cputopo_t;
tools/libxc/xc_misc.c +0 -21
index 093fa44081..9b66330082 100644
@@ -187,27 +187,6 @@ int xc_send_debug_keys(xc_interface *xch, char *keys)
     return ret;
 }
 
-int xc_set_parameters(xc_interface *xch, char *params)
-{
-    int ret, len = strlen(params);
-    DECLARE_SYSCTL;
-    DECLARE_HYPERCALL_BOUNCE(params, len, XC_HYPERCALL_BUFFER_BOUNCE_IN);
-
-    if ( xc_hypercall_bounce_pre(xch, params) )
-        return -1;
-
-    sysctl.cmd = XEN_SYSCTL_set_parameter;
-    set_xen_guest_handle(sysctl.u.set_parameter.params, params);
-    sysctl.u.set_parameter.size = len;
-    memset(sysctl.u.set_parameter.pad, 0, sizeof(sysctl.u.set_parameter.pad));
-
-    ret = do_sysctl(xch, &sysctl);
-
-    xc_hypercall_bounce_post(xch, params);
-
-    return ret;
-}
-
 int xc_physinfo(xc_interface *xch,
                 xc_physinfo_t *put_info)
 {
Signature · 7 lines
2.16.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#47 lore raw

PATCH v6 12/12 xen: remove XEN_SYSCTL_set_parameter support

In reply to Juergen Gross

The functionality of XEN_SYSCTL_set_parameter is available via hypfs now, so it can be removed.

This allows to remove the kernel_param structure for runtime parameters by putting the now only used structure element into the hypfs node structure of the runtime parameters.

---
V6:
- new patch

---
 tools/flask/policy/modules/dom0.te  |  2 +-
 xen/arch/arm/xen.lds.S              |  5 ----
 xen/arch/x86/xen.lds.S              |  5 ----
 xen/common/hypfs.c                  | 12 +--------
 xen/common/kernel.c                 | 11 --------
 xen/common/sysctl.c                 | 36 --------------------------
 xen/include/public/sysctl.h         | 18 -------------
 xen/include/xen/hypfs.h             |  2 --
 xen/include/xen/lib.h               |  1 -
 xen/include/xen/param.h             | 50 +++++++------------------------------
 xen/xsm/flask/hooks.c               |  3 ---
 xen/xsm/flask/policy/access_vectors |  2 --
 12 files changed, 11 insertions(+), 136 deletions(-)
tools/flask/policy/modules/dom0.te +1 -1
index 20925e38a2..0a63ce15b6 100644
@@ -16,7 +16,7 @@ allow dom0_t xen_t:xen {
 allow dom0_t xen_t:xen2 {
 	resource_op psr_cmt_op psr_alloc pmu_ctrl get_symbol
 	get_cpu_levelling_caps get_cpu_featureset livepatch_op
-	coverage_op set_parameter
+	coverage_op
 };
 
 # Allow dom0 to use all XENVER_ subops that have checks.
xen/arch/arm/xen.lds.S +0 -5
index 0061a8dfea..8bd971bd57 100644
@@ -54,11 +54,6 @@ SECTIONS
        *(.data.rel.ro)
        *(.data.rel.ro.*)
 
-       . = ALIGN(POINTER_ALIGN);
-       __param_start = .;
-       *(.data.param)
-       __param_end = .;
-
        __proc_info_start = .;
        *(.proc.info)
        __proc_info_end = .;
xen/arch/x86/xen.lds.S +0 -5
index 21a37f0f57..88f14e5e59 100644
@@ -128,11 +128,6 @@ SECTIONS
        *(.ex_table.pre)
        __stop___pre_ex_table = .;
 
-       . = ALIGN(POINTER_ALIGN);
-       __param_start = .;
-       *(.data.param)
-       __param_end = .;
-
 #if defined(CONFIG_HAS_VPCI) && defined(CONFIG_LATE_HWDOM)
        . = ALIGN(POINTER_ALIGN);
        __start_vpci_array = .;
xen/common/hypfs.c +1 -11
index 9503ef0731..f2e86e4632 100644
@@ -302,7 +302,7 @@ int hypfs_write_custom(struct hypfs_entry_leaf *leaf,
         goto out;
 
     p = container_of(leaf, struct param_hypfs, hypfs);
-    ret = p->param->par.func(buf);
+    ret = p->func(buf);
 
  out:
     xfree(buf);
@@ -375,13 +375,3 @@ long do_hypfs_op(unsigned int cmd,
 
     return ret;
 }
-
-void hypfs_write_lock(void)
-{
-    write_lock(&hypfs_lock);
-}
-
-void hypfs_write_unlock(void)
-{
-    write_unlock(&hypfs_lock);
-}
xen/common/kernel.c +0 -11
index 7516242337..876830f5fa 100644
@@ -196,17 +196,6 @@ static void __init _cmdline_parse(const char *cmdline)
     parse_params(cmdline, __setup_start, __setup_end);
 }
 
-int runtime_parse(const char *line)
-{
-    int ret;
-
-    hypfs_write_lock();
-    ret = parse_params(line, __param_start, __param_end);
-    hypfs_write_unlock();
-
-    return ret;
-}
-
 /**
  *    cmdline_parse -- parses the xen command line.
  * If CONFIG_CMDLINE is set, it would be parsed prior to @cmdline.
xen/common/sysctl.c +0 -36
index 1c6a817476..ec916424e5 100644
@@ -471,42 +471,6 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
             copyback = 1;
         break;
 
-    case XEN_SYSCTL_set_parameter:
-    {
-#define XEN_SET_PARAMETER_MAX_SIZE 1023
-        char *params;
-
-        if ( op->u.set_parameter.pad[0] || op->u.set_parameter.pad[1] ||
-             op->u.set_parameter.pad[2] )
-        {
-            ret = -EINVAL;
-            break;
-        }
-        if ( op->u.set_parameter.size > XEN_SET_PARAMETER_MAX_SIZE )
-        {
-            ret = -E2BIG;
-            break;
-        }
-        params = xmalloc_bytes(op->u.set_parameter.size + 1);
-        if ( !params )
-        {
-            ret = -ENOMEM;
-            break;
-        }
-        if ( copy_from_guest(params, op->u.set_parameter.params,
-                             op->u.set_parameter.size) )
-            ret = -EFAULT;
-        else
-        {
-            params[op->u.set_parameter.size] = 0;
-            ret = runtime_parse(params);
-        }
-
-        xfree(params);
-
-        break;
-    }
-
     default:
         ret = arch_do_sysctl(op, u_sysctl);
         copyback = 0;
xen/include/public/sysctl.h +0 -18
index 7e43bfe1bd..0d243eb30c 100644
@@ -1024,22 +1024,6 @@ struct xen_sysctl_livepatch_op {
     } u;
 };
 
-/*
- * XEN_SYSCTL_set_parameter
- *
- * Change hypervisor parameters at runtime.
- * The input string is parsed similar to the boot parameters.
- * Parameters are a single string terminated by a NUL byte of max. size
- * characters. Multiple settings can be specified by separating them
- * with blanks.
- */
-
-struct xen_sysctl_set_parameter {
-    XEN_GUEST_HANDLE_64(char) params;       /* IN: pointer to parameters. */
-    uint16_t size;                          /* IN: size of parameters. */
-    uint16_t pad[3];                        /* IN: MUST be zero. */
-};
-
 #if defined(__i386__) || defined(__x86_64__)
 /*
  * XEN_SYSCTL_get_cpu_policy (x86 specific)
@@ -1102,7 +1086,6 @@ struct xen_sysctl {
 #define XEN_SYSCTL_get_cpu_levelling_caps        25
 #define XEN_SYSCTL_get_cpu_featureset            26
 #define XEN_SYSCTL_livepatch_op                  27
-#define XEN_SYSCTL_set_parameter                 28
 #define XEN_SYSCTL_get_cpu_policy                29
     uint32_t interface_version; /* XEN_SYSCTL_INTERFACE_VERSION */
     union {
@@ -1131,7 +1114,6 @@ struct xen_sysctl {
         struct xen_sysctl_cpu_levelling_caps cpu_levelling_caps;
         struct xen_sysctl_cpu_featureset    cpu_featureset;
         struct xen_sysctl_livepatch_op      livepatch;
-        struct xen_sysctl_set_parameter     set_parameter;
 #if defined(__i386__) || defined(__x86_64__)
         struct xen_sysctl_cpu_policy        cpu_policy;
 #endif
xen/include/xen/hypfs.h +0 -2
index 6c1db290cb..84a8f9b338 100644
@@ -101,7 +101,5 @@ int hypfs_write_bool(struct hypfs_entry_leaf *leaf,
                      XEN_GUEST_HANDLE_PARAM(void) uaddr, unsigned long ulen);
 int hypfs_write_custom(struct hypfs_entry_leaf *leaf,
                        XEN_GUEST_HANDLE_PARAM(void) uaddr, unsigned long ulen);
-void hypfs_write_lock(void);
-void hypfs_write_unlock(void);
 
 #endif /* __XEN_HYPFS_H__ */
xen/include/xen/lib.h +0 -1
index 5d718bbdba..7e425e28cd 100644
@@ -75,7 +75,6 @@
 struct domain;
 
 void cmdline_parse(const char *cmdline);
-int runtime_parse(const char *line);
 int parse_bool(const char *s, const char *e);
 
 /**
xen/include/xen/param.h +9 -41

102 lines not on this page · raw message

xen/xsm/flask/hooks.c +0 -3
index e257328928..9adb69f649 100644
@@ -821,9 +821,6 @@ static int flask_sysctl(int cmd)
     case XEN_SYSCTL_coverage_op:
         return avc_current_has_perm(SECINITSID_XEN, SECCLASS_XEN2,
                                     XEN2__COVERAGE_OP, NULL);
-    case XEN_SYSCTL_set_parameter:
-        return avc_current_has_perm(SECINITSID_XEN, SECCLASS_XEN2,
-                                    XEN2__SET_PARAMETER, NULL);
 
     default:
         return avc_unknown_permission("sysctl", cmd);
xen/xsm/flask/policy/access_vectors +0 -2
index c9e385fb9b..b87c99ea98 100644
@@ -99,8 +99,6 @@ class xen2
     livepatch_op
 # XEN_SYSCTL_coverage_op
     coverage_op
-# XEN_SYSCTL_set_parameter
-    set_parameter
 }
 
 # Classes domain and domain2 consist of operations that a domain performs on
Signature · 7 lines
2.16.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v6 12/12
#48 lore raw

Re: [Xen-devel] [PATCH v6 12/12] xen: remove XEN_SYSCTL_set_parameter support

Quoted 8 lines · Juergen Gross

The functionality of XEN_SYSCTL_set_parameter is available via hypfs now, so it can be removed.

This allows to remove the kernel_param structure for runtime parameters by putting the now only used structure element into the hypfs node structure of the runtime parameters.

with one minor adjustment:

xen/include/public/sysctl.h struct xen_sysctl { · line 1105

Quoted 5 lines
xen/include/public/sysctl.h +0 -1
@@ -1102,7 +1086,6 @@ struct xen_sysctl {
 #define XEN_SYSCTL_get_cpu_levelling_caps        25
 #define XEN_SYSCTL_get_cpu_featureset            26
 #define XEN_SYSCTL_livepatch_op                  27
-#define XEN_SYSCTL_set_parameter                 28

Please follow the tmem_op example here and don't outright delete the line.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#49 lore raw

Re: [Xen-devel] [PATCH v6 12/12] xen: remove XEN_SYSCTL_set_parameter support

Quoted 13 lines · Jan Beulich
Quoted 8 lines · Juergen Gross

The functionality of XEN_SYSCTL_set_parameter is available via hypfs now, so it can be removed.

This allows to remove the kernel_param structure for runtime parameters by putting the now only used structure element into the hypfs node structure of the runtime parameters.

with one minor adjustment:

Quoted 8 lines

xen/include/public/sysctl.h struct xen_sysctl { · line 1105

Quoted 5 lines
xen/include/public/sysctl.h +0 -1
@@ -1102,7 +1086,6 @@ struct xen_sysctl {
  #define XEN_SYSCTL_get_cpu_levelling_caps        25
  #define XEN_SYSCTL_get_cpu_featureset            26
  #define XEN_SYSCTL_livepatch_op                  27
-#define XEN_SYSCTL_set_parameter                 28

Please follow the tmem_op example here and don't outright delete the line.

Okay.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel