Skip to contentSkip to conversation

xSplice v1 design and implementation.

PATCH Superseded Konrad Rzeszutek Wilk 13 participants 190 messages Mar 24, 2016 – Apr 22, 2016 2 messages not in the archive Arm/actions semi architecture Page 1 of 2

v5 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 xSplice v1 design and implementation.

Hey!

Changelog:
v4: http://lists.xen.org/archives/html/xen-devel/2016-03/msg01776.html
- Lots of review. Lots of rework. Some patches checked in.
v3: http://www.gossamer-threads.com/lists/xen/devel/418262

    and 
    http://lists.xenproject.org/archives/html/xen-devel/2016-02/msg04106.html

- Act on all reviews.
- Redo the flow of patches
v2: http://lists.xen.org/archives/html/xen-devel/2016-01/msg01597.html
- Updated code/docs/design with review comments.
- Make xen also have an PT_NOTE
- Added more of Ross's patches
- Combined build-id patchset with this.
(since the RFC and the Seattle Xen presentation)
- Finished off some of the work around the build-id.
- Settled on the preemption mechanism.
- Cleaned the patches a lot up, broke them up to easy
review for maintainers.
v1: http://lists.xenproject.org/archives/html/xen-devel/2015-09/msg02116.html
- Put all the design comments in the code
Prototype: http://lists.xenproject.org/archives/html/xen-devel/2015-10/msg02595.html
[Posting by Ross]
- Took all reviews into account.
- Redid the patches

GIT TREE:
------------------------
git://xenbits.xen.org/people/konradwilk/xen.git xsplice.v5

*Tools Maintainers*
------------------------

Two of the patches have been reviewed and have an Ack by toolstack maintainers:

xen-xsplice: Tool to manipulate xsplice payloads
libxc: Implementation of XEN_XSPLICE_op in libxc

The other two need an Ack:
libxl: info: Display build_id of the hypervisor using XEN_VERSION_build_id libxc/libxl/python/xenstat/ocaml: Use new XEN_VERSION hypercall [This one has an Ack from George]

*Hypervisor Maintainers*
------------------------

The rest of the patches (24! of them) need Acks and Reviews...

Daniel has Acked the XSM checks in the hypervisor patches.

*What is xSplice?*
------------------------

A mechanism to binarily patch the running hypervisor with new opcodes that have come about due to primarily security updates.

*What will this patchset do once I've it*
------------------------

Patch the hypervisor.

*Why are you emailing me?*
------------------------

Please please review as many patches as possible.

*OK, what do you have?*
------------------------

They are located at a git tree:
git://xenbits.xen.org/people/konradwilk/xen.git xsplice.v5

(Copying from Ross's email):

Much of the work is implementing a basic version of the Linux kernel module loader. The code:
* Loading of xSplice ELF payloads.
* Copying allocated sections into a new executable region of memory.
* Resolving symbols.
* Applying relocations.
* Patching of altinstructions.
* Special handling of bug frames and exception tables.
* Unloading of xSplice ELF payloads.
* Compiling a sample xSplice ELF payload
* Resolving symbols
* Using build-id dependencies
* Support for shadow variable framework
* Support for executing ELF payload functions on load/unload.

The other main bit of this work is applying and reverting the patches safely. As implemented, the code is patched with each CPU waiting in the return-to-guest path (i.e. with no stack) or on the cpu-idle path which appears to be the safest way of patching. While it is safe we should still (in the next wave of patches) to verify to not patch cetain critical sections (say the code doing the patching)

All of the following should work:
* Applying patches safely.
* Reverting patches safely.
* Replacing patches safely (e.g. reverting any applied patches and applying a new patch).
* Bug frames as part of modules. This means adding or
changing WARN, ASSERT, BUG, and run_in_exception_handler works correctly. Line number only changes _are ignored_.
* Exception tables as part of modules. E.g. wrmsr_safe and copy_to_user work correctly when used in a patch module.
* Stacking of patches on top of each other
* Resolving symbols (even of patches)

*Limitations*
------------------------

The above is enough to fully implement an update system where multiple source patches are combined (using combinediff) and built into a single binary which then atomically replaces any existing loaded patches
(this is why Ross added a REPLACE operation). This is the approach used by kPatch and kGraft.

Multiple completely independent patches can also be loaded but unexpected interactions may occur.

As it stands, the patches are statically linked which means that independent patches cannot be linked against one another (e.g. if one introduces a new symbol). Using the combinediff approach above fixes this.

Backtraces containing functions from a patch module do not show the symbol name.

There is no checking that a patch which is loaded is built for the correct hypervisor (need to use build-id).

Binary patching works at the function level.

*Testing*
------------------------

You can use the example code included in this patchset:

# xl info | grep extra
xen_extra              : -unstable
# xen-xsplice load /usr/lib/debug/xen_hello_world.xsplice
Uploading /usr/lib/debug/xen_hello_world.xsplice (2071 bytes)
Performing check: completed
Performing apply:. completed
# xl info | grep extra
xen_extra              : Hello World
# xen-xsplice revert xen_hello_world
Performing revert:. completed
# xen-xsplice unload xen_hello_world
Performing unload: completed
# xl info | grep extra
xen_extra              : -unstable

Or you can use git://xenbits.xen.org/people/konradwilk/xsplice-build-tools.git
which generates the ELF payloads.

This link has a nice description of how to use the tool:
http://lists.xenproject.org/archives/html/xen-devel/2015-10/msg02595.html

 .gitignore                                   |    5 +
 Config.mk                                    |   12 +
 MAINTAINERS                                  |   10 +
 docs/misc/xsplice.markdown                   | 1127 ++++++++++++++++++
 tools/flask/policy/policy/modules/xen/xen.te |    9 +-
 tools/libxc/include/xenctrl.h                |   94 +-
 tools/libxc/xc_core.c                        |   35 +-
 tools/libxc/xc_dom_boot.c                    |   12 +-
 tools/libxc/xc_domain.c                      |    3 +-
 tools/libxc/xc_misc.c                        |  337 ++++++
 tools/libxc/xc_private.c                     |   53 +-
 tools/libxc/xc_private.h                     |    7 +-
 tools/libxc/xc_resume.c                      |    3 +-
 tools/libxc/xc_sr_save.c                     |    9 +-
 tools/libxc/xg_save_restore.h                |    6 +-
 tools/libxl/libxl.c                          |   96 +-
 tools/libxl/libxl.h                          |    6 +
 tools/libxl/libxl_types.idl                  |    1 +
 tools/libxl/xl_cmdimpl.c                     |    1 +
 tools/misc/Makefile                          |    4 +
 tools/misc/xen-xsplice.c                     |  463 ++++++++
 tools/ocaml/libs/xc/xenctrl_stubs.c          |   39 +-
 tools/python/xen/lowlevel/xc/xc.c            |   30 +-
 tools/xenstat/libxenstat/src/xenstat.c       |   12 +-
 tools/xentrace/xenctx.c                      |    3 +-
 xen/Makefile                                 |    2 +
 xen/arch/arm/Makefile                        |    7 +-
 xen/arch/arm/setup.c                         |    4 +
 xen/arch/arm/traps.c                         |   40 +-
 xen/arch/arm/xen.lds.S                       |   14 +-
 xen/arch/arm/xsplice.c                       |   75 ++
 xen/arch/x86/Makefile                        |   45 +-
 xen/arch/x86/alternative.c                   |   20 +-
 xen/arch/x86/boot/mkelf32.c                  |  137 ++-
 xen/arch/x86/domain.c                        |    4 +
 xen/arch/x86/extable.c                       |   40 +-
 xen/arch/x86/hvm/hvm.c                       |    1 +
 xen/arch/x86/hvm/svm/svm.c                   |    2 +
 xen/arch/x86/hvm/vmx/vmcs.c                  |    2 +
 xen/arch/x86/setup.c                         |   13 +
 xen/arch/x86/test/Makefile                   |   90 ++
 xen/arch/x86/test/xen_bye_world.c            |   34 +
 xen/arch/x86/test/xen_bye_world_func.c       |   25 +
 xen/arch/x86/test/xen_hello_world.c          |   65 ++
 xen/arch/x86/test/xen_hello_world_func.c     |   26 +
 xen/arch/x86/test/xen_replace_world.c        |   35 +
 xen/arch/x86/test/xen_replace_world_func.c   |   25 +
 xen/arch/x86/traps.c                         |   45 +-
 xen/arch/x86/x86_64/compat/entry.S           |    2 +
 xen/arch/x86/x86_64/entry.S                  |    2 +
 xen/arch/x86/xen.lds.S                       |   23 +
 xen/arch/x86/xsplice.c                       |  298 +++++
 xen/common/Kconfig                           |   16 +
 xen/common/Makefile                          |    4 +
 xen/common/compat/kernel.c                   |    2 +
 xen/common/kernel.c                          |  217 +++-
 xen/common/symbols.c                         |   44 +-
 xen/common/sysctl.c                          |    7 +
 xen/common/version.c                         |   67 ++
 xen/common/virtual_region.c                  |  160 +++
 xen/common/vmap.c                            |   33 +-
 xen/common/vsprintf.c                        |   15 +-
 xen/common/xsplice.c                         | 1575 ++++++++++++++++++++++++++
 xen/common/xsplice_elf.c                     |  398 +++++++
 xen/common/xsplice_shadow.c                  |  109 ++
 xen/include/asm-arm/nmi.h                    |   13 +
 xen/include/asm-x86/alternative.h            |    6 +
 xen/include/asm-x86/uaccess.h                |    5 +
 xen/include/asm-x86/x86_64/page.h            |    2 +
 xen/include/public/arch-arm.h                |    2 +
 xen/include/public/sysctl.h                  |  167 +++
 xen/include/public/version.h                 |   73 +-
 xen/include/public/xen.h                     |    1 +
 xen/include/xen/hypercall.h                  |    4 +
 xen/include/xen/symbols.h                    |   11 +
 xen/include/xen/version.h                    |    6 +
 xen/include/xen/virtual_region.h             |   48 +
 xen/include/xen/vmap.h                       |   14 +
 xen/include/xen/xsplice.h                    |  131 +++
 xen/include/xen/xsplice_elf.h                |   56 +
 xen/include/xen/xsplice_patch.h              |   95 ++
 xen/include/xsm/dummy.h                      |   21 +
 xen/include/xsm/xsm.h                        |    6 +
 xen/xsm/dummy.c                              |    1 +
 xen/xsm/flask/hooks.c                        |   44 +
 xen/xsm/flask/policy/access_vectors          |   25 +-
 86 files changed, 6547 insertions(+), 284 deletions(-)

Konrad Rzeszutek Wilk (18):
HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane. libxc/libxl/python/xenstat/ocaml: Use new XEN_VERSION hypercall
arm/x86: Use struct virtual_region to do bug, symbol, and (x86) exception tables lookup.
vmap: Add vmalloc_cb and vfree_cb
xsplice: Design document
xen/xsplice: Hypervisor implementation of XEN_XSPLICE_op
libxc: Implementation of XEN_XSPLICE_op in libxc
xen-xsplice: Tool to manipulate xsplice payloads x86/xen_hello_world.xsplice: Test payload for patching 'xen_extra_version'. x86, xsplice: Print payload's symbol name and payload name in backtraces
build_id: Provide ld-embedded build-ids
HYPERCALL_version_op: Add VERSION_build_id to retrieve build-id.
libxl: info: Display build_id of the hypervisor using XEN_VERSION_build_id
xsplice: Print build_id in keyhandler and on bootup.
xsplice: Stacking build-id dependency checking. xsplice/xen_replace_world: Test-case for XSPLICE_ACTION_REPLACE
xsplice: Print dependency and payloads build_id in the keyhandler. MAINTAINERS/xsplice: Add myself and Ross as the maintainers.

Ross Lagerwall (10):
xsplice: Add helper elf routines
xsplice: Implement payload loading
xsplice: Implement support for applying/reverting/replacing patches. xsplice,symbols: Implement symbol name resolution on address.
xsplice: Add .xsplice.hooks functions and test-case
xsplice: Add support for bug frames.
xsplice: Add support for exception tables.
xsplice: Add support for alternatives
xsplice: Prevent duplicate payloads from being loaded.
xsplice: Add support for shadow variables.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#1 lore raw

PATCH v5 1/28 HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

This hypercall mirrors the XENVER_ in that it has similar functionality. However it is designed differently:
- No compat layer. The data structures are the same size on 32 as on 64-bit.
- The hypercall accepts three arguments - the command, pointer to an buffer, and the length of the buffer.
- Each sub-ops can be "probed" for size by returning the size of buffer that will be needed - if the buffer is NULL.
- Subops can complete even if the buffer is too small - truncated data will be filled and hypercall will return -ENOBUFS.
- VERSION_commandline, VERSION_changeset are privileged.
- There is no XENVER_compile_info equivalent.
- The hypercall can return -EPERM and toolstack/OSes are expected to deal with. However there are three subops: XEN_VERSION_version, XEN_VERSION_platform_parameters and XEN_VERSION_get_features that will always return an value as guests cannot survive without them.

While we combine some of the common code between XENVER_ and VERSION_ take the liberty of moving pae_extended_cr3 in x86 area.

---
Cc: Daniel De Graaf <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>

v1-v3: Was not part of the series.
v4: New posting.
v5: Remove memset and use {}. Tweak copy_to_guest and capabilities_info,
add ASSERT(sz) per Andrew's review. Add cached=1 back in. Per Jan, s/VERSION_OP/VERSION/, squash size check with do_version_op, update the comments. Dropped Andrew's Review-by. Ate newlines. Added initcall to guard against garbage being set in cached data. Folded code populating cache in __init. s/char/char[]/ in public.h
---

---
 tools/flask/policy/policy/modules/xen/xen.te |   7 +-
 xen/arch/arm/traps.c                         |   1 +
 xen/arch/x86/hvm/hvm.c                       |   1 +
 xen/arch/x86/x86_64/compat/entry.S           |   2 +
 xen/arch/x86/x86_64/entry.S                  |   2 +
 xen/common/compat/kernel.c                   |   2 +
 xen/common/kernel.c                          | 213 ++++++++++++++++++++++-----
 xen/include/public/arch-arm.h                |   2 +
 xen/include/public/version.h                 |  70 ++++++++-
 xen/include/public/xen.h                     |   1 +
 xen/include/xen/hypercall.h                  |   4 +
 xen/include/xsm/dummy.h                      |  21 +++
 xen/include/xsm/xsm.h                        |   6 +
 xen/xsm/dummy.c                              |   1 +
 xen/xsm/flask/hooks.c                        |  35 +++++
 xen/xsm/flask/policy/access_vectors          |  21 ++-
 16 files changed, 346 insertions(+), 43 deletions(-)
tools/flask/policy/policy/modules/xen/xen.te +5 -2
index e174e48..7e69ce9 100644
@@ -74,11 +74,12 @@ allow dom0_t xen_t:xen2 {
     get_symbol
 };
 
-# Allow dom0 to use all XENVER_ subops that have checks.
+# Allow dom0 to use all XENVER_ subops and VERSION subops that have checks.
 # Note that dom0 is part of domain_type so this has duplicates.
 allow dom0_t xen_t:version {
     xen_extraversion xen_compile_info xen_capabilities
     xen_changeset xen_pagesize xen_guest_handle xen_commandline
+    extraversion capabilities changeset pagesize guest_handle commandline
 };
 
 allow dom0_t xen_t:mmu memorymap;
@@ -145,10 +146,12 @@ if (guest_writeconsole) {
 # pmu_ctrl is for)
 allow domain_type xen_t:xen2 pmu_use;
 
-# For normal guests all possible except XENVER_commandline.
+# For normal guests all possible except XENVER_commandline, VERSION_changeset,
+# and VERSION_commandline
 allow domain_type xen_t:version {
     xen_extraversion xen_compile_info xen_capabilities
     xen_changeset xen_pagesize xen_guest_handle
+    extraversion capabilities pagesize guest_handle
 };
 
 ###############################################################################
xen/arch/arm/traps.c +1 -0
index 83744e8..31d2115 100644
@@ -1235,6 +1235,7 @@ static arm_hypercall_t arm_hypercall_table[] = {
     HYPERCALL(multicall, 2),
     HYPERCALL(platform_op, 1),
     HYPERCALL_ARM(vcpu_op, 3),
+    HYPERCALL(version_op, 3),
 };
 
 #ifndef NDEBUG
xen/arch/x86/hvm/hvm.c +1 -0
index 80d59ff..f16b590 100644
@@ -5322,6 +5322,7 @@ static const struct {
     COMPAT_CALL(platform_op),
     COMPAT_CALL(mmuext_op),
     HYPERCALL(xenpmu_op),
+    HYPERCALL(version_op),
     HYPERCALL(arch_1)
 };
 
xen/arch/x86/x86_64/compat/entry.S +2 -0
index 33e2c12..fd25e84 100644
@@ -394,6 +394,7 @@ ENTRY(compat_hypercall_table)
         .quad do_tmem_op
         .quad do_ni_hypercall           /* reserved for XenClient */
         .quad do_xenpmu_op              /* 40 */
+        .quad do_version_op
         .rept __HYPERVISOR_arch_0-((.-compat_hypercall_table)/8)
         .quad compat_ni_hypercall
         .endr
@@ -445,6 +446,7 @@ ENTRY(compat_hypercall_args_table)
         .byte 1 /* do_tmem_op               */
         .byte 0 /* reserved for XenClient   */
         .byte 2 /* do_xenpmu_op             */  /* 40 */
+        .byte 3 /* do_version_op            */
         .rept __HYPERVISOR_arch_0-(.-compat_hypercall_args_table)
         .byte 0 /* compat_ni_hypercall      */
         .endr
xen/arch/x86/x86_64/entry.S +2 -0
index 07ef096..b0e7257 100644
@@ -730,6 +730,7 @@ ENTRY(hypercall_table)
         .quad do_tmem_op
         .quad do_ni_hypercall       /* reserved for XenClient */
         .quad do_xenpmu_op          /* 40 */
+        .quad do_version_op
         .rept __HYPERVISOR_arch_0-((.-hypercall_table)/8)
         .quad do_ni_hypercall
         .endr
@@ -781,6 +782,7 @@ ENTRY(hypercall_args_table)
         .byte 1 /* do_tmem_op           */
         .byte 0 /* reserved for XenClient */
         .byte 2 /* do_xenpmu_op         */  /* 40 */
+        .byte 3 /* do_version_op        */
         .rept __HYPERVISOR_arch_0-(.-hypercall_args_table)
         .byte 0 /* do_ni_hypercall      */
         .endr
xen/common/compat/kernel.c +2 -0
index df93fdd..7a7ca53 100644
@@ -39,6 +39,8 @@ CHECK_TYPE(capabilities_info);
 
 CHECK_TYPE(domain_handle);
 
+CHECK_TYPE(version_op_val);
+
 #define xennmi_callback compat_nmi_callback
 #define xennmi_callback_t compat_nmi_callback_t
 
xen/common/kernel.c +176 -37

241 lines not on this page · raw message

xen/include/public/arch-arm.h +2 -0
index 870bc3b..5f90718 100644
@@ -128,6 +128,8 @@
  *    * VCPUOP_register_vcpu_info
  *    * VCPUOP_register_runstate_memory_area
  *
+ *  HYPERVISOR_version_op
+ *   All generic sub-operations
  *
  * Other notes on the ARM ABI:
  *
xen/include/public/version.h +69 -1

82 lines not on this page · raw message

xen/include/public/xen.h +1 -0
index 64ba7ab..1a99929 100644
@@ -115,6 +115,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_ulong_t);
 #define __HYPERVISOR_tmem_op              38
 #define __HYPERVISOR_xc_reserved_op       39 /* reserved for XenClient */
 #define __HYPERVISOR_xenpmu_op            40
+#define __HYPERVISOR_version_op           41 /* supersedes xen_version (17) */
 
 /* Architecture-specific hypercall definitions. */
 #define __HYPERVISOR_arch_0               48
xen/include/xen/hypercall.h +4 -0
index 0c8ae0e..e8d2b81 100644
@@ -147,6 +147,10 @@ do_xenoprof_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg);
 extern long
 do_xenpmu_op(unsigned int op, XEN_GUEST_HANDLE_PARAM(xen_pmu_params_t) arg);
 
+extern long
+do_version_op(unsigned int cmd,
+    XEN_GUEST_HANDLE_PARAM(void) arg, unsigned int len);
+
 #ifdef CONFIG_COMPAT
 
 extern int
xen/include/xsm/dummy.h +21 -0
index abbe282..e5dad35 100644
@@ -751,3 +751,24 @@ static XSM_INLINE int xsm_xen_version (XSM_DEFAULT_ARG uint32_t op)
         return xsm_default_action(XSM_PRIV, current->domain, NULL);
     }
 }
+
+static XSM_INLINE int xsm_version_op (XSM_DEFAULT_ARG uint32_t op)
+{
+    XSM_ASSERT_ACTION(XSM_OTHER);
+    switch ( op )
+    {
+    case XEN_VERSION_version:
+    case XEN_VERSION_platform_parameters:
+    case XEN_VERSION_get_features:
+        /* These MUST always be accessible to any guest by default. */
+        return 0;
+    case XEN_VERSION_extraversion:
+    case XEN_VERSION_capabilities:
+    case XEN_VERSION_pagesize:
+    case XEN_VERSION_guest_handle:
+        /* These can be accessible to a guest. */
+        return xsm_default_action(XSM_HOOK, current->domain, NULL);
+    default:
+        return xsm_default_action(XSM_PRIV, current->domain, NULL);
+    }
+}
xen/include/xsm/xsm.h +6 -0
index 5ecbee0..ac80472 100644
@@ -194,6 +194,7 @@ struct xsm_operations {
     int (*pmu_op) (struct domain *d, unsigned int op);
 #endif
     int (*xen_version) (uint32_t cmd);
+    int (*version_op) (uint32_t cmd);
 };
 
 #ifdef CONFIG_XSM
@@ -737,6 +738,11 @@ static inline int xsm_xen_version (xsm_default_t def, uint32_t op)
     return xsm_ops->xen_version(op);
 }
 
+static inline int xsm_version_op (xsm_default_t def, uint32_t op)
+{
+    return xsm_ops->version_op(op);
+}
+
 #endif /* XSM_NO_WRAPPERS */
 
 #ifdef CONFIG_MULTIBOOT
xen/xsm/dummy.c +1 -0
index 9791ad4..776dd09 100644
@@ -163,4 +163,5 @@ void xsm_fixup_ops (struct xsm_operations *ops)
     set_to_dummy_if_null(ops, pmu_op);
 #endif
     set_to_dummy_if_null(ops, xen_version);
+    set_to_dummy_if_null(ops, version_op);
 }
xen/xsm/flask/hooks.c +35 -0
index 2069cb3..1eaec58 100644
@@ -1658,6 +1658,40 @@ static int flask_xen_version (uint32_t op)
     }
 }
 
+static int flask_version_op (uint32_t op)
+{
+    u32 dsid = domain_sid(current->domain);
+
+    switch ( op )
+    {
+    case XEN_VERSION_version:
+    case XEN_VERSION_platform_parameters:
+    case XEN_VERSION_get_features:
+        /* These MUST always be accessible to any guest by default. */
+        return 0;
+    case XEN_VERSION_extraversion:
+        return avc_has_perm(dsid, SECINITSID_XEN, SECCLASS_VERSION,
+                            VERSION__EXTRAVERSION, NULL);
+    case XEN_VERSION_capabilities:
+        return avc_has_perm(dsid, SECINITSID_XEN, SECCLASS_VERSION,
+                            VERSION__CAPABILITIES, NULL);
+    case XEN_VERSION_changeset:
+        return avc_has_perm(dsid, SECINITSID_XEN, SECCLASS_VERSION,
+                            VERSION__CHANGESET, NULL);
+    case XEN_VERSION_pagesize:
+        return avc_has_perm(dsid, SECINITSID_XEN, SECCLASS_VERSION,
+                            VERSION__PAGESIZE, NULL);
+    case XEN_VERSION_guest_handle:
+        return avc_has_perm(dsid, SECINITSID_XEN, SECCLASS_VERSION,
+                            VERSION__GUEST_HANDLE, NULL);
+    case XEN_VERSION_commandline:
+        return avc_has_perm(dsid, SECINITSID_XEN, SECCLASS_VERSION,
+                            VERSION__COMMANDLINE, NULL);
+    default:
+        return -EPERM;
+    }
+}
+
 long do_flask_op(XEN_GUEST_HANDLE_PARAM(xsm_op_t) u_flask_op);
 int compat_flask_op(XEN_GUEST_HANDLE_PARAM(xsm_op_t) u_flask_op);
 
@@ -1797,6 +1831,7 @@ static struct xsm_operations flask_ops = {
     .pmu_op = flask_pmu_op,
 #endif
     .xen_version = flask_xen_version,
+    .version_op = flask_version_op,
 };
 
 static __init void flask_init(void)
xen/xsm/flask/policy/access_vectors +18 -3
index badcf1c..56600bb 100644
@@ -496,12 +496,14 @@ class security
     del_ocontext
 }
 
-# Class version is used to describe the XENVER_ hypercall.
+# Class version is used to describe the XENVER_ and VERSION hypercall.
 # Almost all sub-ops are described here - in the default case all of them should
-# be allowed except the XENVER_commandline.
+# be allowed except the XENVER_commandline, VERSION_commandline, and
+# VERSION_changeset.
 #
 # The ones that are omitted are XENVER_version, XENVER_platform_parameters,
-# and XENVER_get_features  - as they MUST always be returned to a guest.
+# XENVER_get_features, XEN_VERSION_version, XEN_VERSION_platform_parameters,
+# and XEN_VERSION_get_features - as they MUST always be returned to a guest.
 #
 class version
 {
@@ -519,4 +521,17 @@ class version
     xen_guest_handle
 # Xen command line.
     xen_commandline
+# --- VERSION hypercall ---
+# Extra informations (-unstable).
+    extraversion
+# Such as "xen-3.0-x86_64 xen-3.0-x86_32p hvm-3.0-x86_32 hvm-3.0-x86_32p hvm-3.0-x86_64".
+    capabilities
+# Source code changeset.
+    changeset
+# Page size the hypervisor uses.
+    pagesize
+# An value that the control stack can choose.
+    guest_handle
+# Xen command line.
+    commandline
 }
Signature · 7 lines
2.5.0


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Reviewed-by on v5 1/28
#2 lore raw

Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Quoted 6 lines · Konrad Rzeszutek Wilk

This hypercall mirrors the XENVER_ in that it has similar functionality. However it is designed differently:
- No compat layer. The data structures are the same size on 32 as on 64-bit.
- The hypercall accepts three arguments - the command, pointer to an buffer, and the length of the buffer.

"a buffer"

Quoted 18 lines
xen/common/kernel.c +18 -0
+/* Computed by kernel_cache_init. */
+static xen_capabilities_info_t __read_mostly cached_cap;
+static unsigned int __read_mostly cached_cap_len;
+
+/*
+ * Similar to HYPERVISOR_xen_version but with a sane interface
+ * (has a length, one can probe for the length) and with one less sub-ops:
+ * missing XENVER_compile_info.
+ */
+DO(version_op)(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg,
+               unsigned int len)
+{
+    union {
+        xen_version_op_val_t val;
+        xen_feature_info_t fi;
+    } u = {};
+    unsigned int sz = 0;
+    const void *ptr = NULL;

xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 419

Quoted 10 lines
xen/common/kernel.c +10 -0
+    int rc = xsm_version_op(XSM_OTHER, cmd);
+
+    /* We can safely return -EPERM! */
+    if ( rc )
+        return rc;
+
+    /*
+     * The HYPERVISOR_xen_version differs in that some return the value,
+     * and some copy it on back on argument. We follow the same rule for all
+     * sub-ops: return 0 on success, positive value of bytes returned, and

You can't return both 0 and a positive number for success. I would recommend "return the number of bytes written, or negative errno on failure".

Other than these, LGTM.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#3 lore raw

Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Quoted 39 lines · Andrew Cooper
Quoted 1 line · Konrad Rzeszutek Wilk

This hypercall mirrors the XENVER_ in that it has similar

functionality.

Quoted 5 lines

However it is designed differently:
- No compat layer. The data structures are the same size on 32 as on 64-bit.
- The hypercall accepts three arguments - the command, pointer to an buffer, and the length of the buffer.

"a buffer"

xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)

Quoted 7 lines
xen/common/kernel.c +7 -0
+/* Computed by kernel_cache_init. */
+static xen_capabilities_info_t __read_mostly cached_cap;
+static unsigned int __read_mostly cached_cap_len;
+
+/*
+ * Similar to HYPERVISOR_xen_version but with a sane interface
+ * (has a length, one can probe for the length) and with one less

sub-ops:

Quoted 9 lines

+ * missing XENVER_compile_info.
+ */

xen/common/kernel.c +7 -0
+DO(version_op)(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg,
+               unsigned int len)
+{
+    union {
+        xen_version_op_val_t val;
+        xen_feature_info_t fi;
+    } u = {};

xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)

Quoted 10 lines
xen/common/kernel.c +10 -0
+    unsigned int sz = 0;
+    const void *ptr = NULL;
+    int rc = xsm_version_op(XSM_OTHER, cmd);
+
+    /* We can safely return -EPERM! */
+    if ( rc )
+        return rc;
+
+    /*
+     * The HYPERVISOR_xen_version differs in that some return the

value,

Quoted 8 lines
Quoted 1 line

+ * and some copy it on back on argument. We follow the same rule

for all

Quoted 1 line

+ * sub-ops: return 0 on success, positive value of bytes

returned, and

You can't return both 0 and a positive number for success. I would recommend "return the number of bytes written, or negative errno on failure".

Thanks!

And Argh!

I neglected to change the name of kernel_cache_init as Jan requested.

Quoted 4 lines

Other than these, LGTM.

Yeey!

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Acked-by Daniel De Graaf Reviewed-by Andrew Cooper
#4 lore raw

Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Quoted 5 lines

Thanks!

And Argh!

I neglected to change the name of kernel_cache_init as Jan requested.

Jan, here is an updated patch. I changed the name to capabilities_cache_init. Sorry about that!

From e766ddb37acda16c3adbd65179d532b9381bda8e Mon Sep 17 00:00:00 2001
From: Konrad Rzeszutek Wilk <[email protected]>
Date: Tue, 22 Mar 2016 16:53:19 -0400
Subject: [PATCH] HYPERCALL_version_op. New hypercall mirroring XENVER_ but
sane.

This hypercall mirrors the XENVER_ in that it has similar functionality. However it is designed differently:
- No compat layer. The data structures are the same size on 32 as on 64-bit.
- The hypercall accepts three arguments - the command, pointer to an buffer, and the length of the buffer.
- Each sub-ops can be "probed" for size by returning the size of buffer that will be needed - if the buffer is NULL.
- Subops can complete even if the buffer is too small - truncated data will be filled and hypercall will return -ENOBUFS.
- VERSION_commandline, VERSION_changeset are privileged.
- There is no XENVER_compile_info equivalent.
- The hypercall can return -EPERM and toolstack/OSes are expected to deal with. However there are three subops: XEN_VERSION_version, XEN_VERSION_platform_parameters and XEN_VERSION_get_features that will always return an value as guests cannot survive without them.

While we combine some of the common code between XENVER_ and VERSION_ take the liberty of moving pae_extended_cr3 in x86 area.

---
Cc: Daniel De Graaf <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>

v1-v3: Was not part of the series.
v4: New posting.
v5: Remove memset and use {}. Tweak copy_to_guest and capabilities_info,
add ASSERT(sz) per Andrew's review. Add cached=1 back in. Per Jan, s/VERSION_OP/VERSION/, squash size check with do_version_op, update the comments. Dropped Andrew's Review-by. Ate newlines. Added initcall to guard against garbage being set in cached data. Folded code populating cache in __init. s/char/char[]/ in public.h
---

---
 tools/flask/policy/policy/modules/xen/xen.te |   7 +-
 xen/arch/arm/traps.c                         |   1 +
 xen/arch/x86/hvm/hvm.c                       |   1 +
 xen/arch/x86/x86_64/compat/entry.S           |   2 +
 xen/arch/x86/x86_64/entry.S                  |   2 +
 xen/common/compat/kernel.c                   |   2 +
 xen/common/kernel.c                          | 213 ++++++++++++++++++++++-----
 xen/include/public/arch-arm.h                |   2 +
 xen/include/public/version.h                 |  70 ++++++++-
 xen/include/public/xen.h                     |   1 +
 xen/include/xen/hypercall.h                  |   4 +
 xen/include/xsm/dummy.h                      |  21 +++
 xen/include/xsm/xsm.h                        |   6 +
 xen/xsm/dummy.c                              |   1 +
 xen/xsm/flask/hooks.c                        |  35 +++++
 xen/xsm/flask/policy/access_vectors          |  21 ++-
 16 files changed, 346 insertions(+), 43 deletions(-)
tools/flask/policy/policy/modules/xen/xen.te +5 -2
index e174e48..7e69ce9 100644
@@ -74,11 +74,12 @@ allow dom0_t xen_t:xen2 {
     get_symbol
 };
 
-# Allow dom0 to use all XENVER_ subops that have checks.
+# Allow dom0 to use all XENVER_ subops and VERSION subops that have checks.
 # Note that dom0 is part of domain_type so this has duplicates.
 allow dom0_t xen_t:version {
     xen_extraversion xen_compile_info xen_capabilities
     xen_changeset xen_pagesize xen_guest_handle xen_commandline
+    extraversion capabilities changeset pagesize guest_handle commandline
 };
 
 allow dom0_t xen_t:mmu memorymap;
@@ -145,10 +146,12 @@ if (guest_writeconsole) {
 # pmu_ctrl is for)
 allow domain_type xen_t:xen2 pmu_use;
 
-# For normal guests all possible except XENVER_commandline.
+# For normal guests all possible except XENVER_commandline, VERSION_changeset,
+# and VERSION_commandline
 allow domain_type xen_t:version {
     xen_extraversion xen_compile_info xen_capabilities
     xen_changeset xen_pagesize xen_guest_handle
+    extraversion capabilities pagesize guest_handle
 };
 
 ###############################################################################
xen/arch/arm/traps.c +1 -0
index 83744e8..31d2115 100644
@@ -1235,6 +1235,7 @@ static arm_hypercall_t arm_hypercall_table[] = {
     HYPERCALL(multicall, 2),
     HYPERCALL(platform_op, 1),
     HYPERCALL_ARM(vcpu_op, 3),
+    HYPERCALL(version_op, 3),
 };
 
 #ifndef NDEBUG
xen/arch/x86/hvm/hvm.c +1 -0
index 80d59ff..f16b590 100644
@@ -5322,6 +5322,7 @@ static const struct {
     COMPAT_CALL(platform_op),
     COMPAT_CALL(mmuext_op),
     HYPERCALL(xenpmu_op),
+    HYPERCALL(version_op),
     HYPERCALL(arch_1)
 };
 
xen/arch/x86/x86_64/compat/entry.S +2 -0
index 33e2c12..fd25e84 100644
@@ -394,6 +394,7 @@ ENTRY(compat_hypercall_table)
         .quad do_tmem_op
         .quad do_ni_hypercall           /* reserved for XenClient */
         .quad do_xenpmu_op              /* 40 */
+        .quad do_version_op
         .rept __HYPERVISOR_arch_0-((.-compat_hypercall_table)/8)
         .quad compat_ni_hypercall
         .endr
@@ -445,6 +446,7 @@ ENTRY(compat_hypercall_args_table)
         .byte 1 /* do_tmem_op               */
         .byte 0 /* reserved for XenClient   */
         .byte 2 /* do_xenpmu_op             */  /* 40 */
+        .byte 3 /* do_version_op            */
         .rept __HYPERVISOR_arch_0-(.-compat_hypercall_args_table)
         .byte 0 /* compat_ni_hypercall      */
         .endr
xen/arch/x86/x86_64/entry.S +2 -0
index 07ef096..b0e7257 100644
@@ -730,6 +730,7 @@ ENTRY(hypercall_table)
         .quad do_tmem_op
         .quad do_ni_hypercall       /* reserved for XenClient */
         .quad do_xenpmu_op          /* 40 */
+        .quad do_version_op
         .rept __HYPERVISOR_arch_0-((.-hypercall_table)/8)
         .quad do_ni_hypercall
         .endr
@@ -781,6 +782,7 @@ ENTRY(hypercall_args_table)
         .byte 1 /* do_tmem_op           */
         .byte 0 /* reserved for XenClient */
         .byte 2 /* do_xenpmu_op         */  /* 40 */
+        .byte 3 /* do_version_op        */
         .rept __HYPERVISOR_arch_0-(.-hypercall_args_table)
         .byte 0 /* do_ni_hypercall      */
         .endr
xen/common/compat/kernel.c +2 -0
index df93fdd..7a7ca53 100644
@@ -39,6 +39,8 @@ CHECK_TYPE(capabilities_info);
 
 CHECK_TYPE(domain_handle);
 
+CHECK_TYPE(version_op_val);
+
 #define xennmi_callback compat_nmi_callback
 #define xennmi_callback_t compat_nmi_callback_t
 
xen/common/kernel.c +176 -37

241 lines not on this page · raw message

xen/include/public/arch-arm.h +2 -0
index 870bc3b..5f90718 100644
@@ -128,6 +128,8 @@
  *    * VCPUOP_register_vcpu_info
  *    * VCPUOP_register_runstate_memory_area
  *
+ *  HYPERVISOR_version_op
+ *   All generic sub-operations
  *
  * Other notes on the ARM ABI:
  *
xen/include/public/version.h +69 -1

82 lines not on this page · raw message

xen/include/public/xen.h +1 -0
index 64ba7ab..1a99929 100644
@@ -115,6 +115,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_ulong_t);
 #define __HYPERVISOR_tmem_op              38
 #define __HYPERVISOR_xc_reserved_op       39 /* reserved for XenClient */
 #define __HYPERVISOR_xenpmu_op            40
+#define __HYPERVISOR_version_op           41 /* supersedes xen_version (17) */
 
 /* Architecture-specific hypercall definitions. */
 #define __HYPERVISOR_arch_0               48
xen/include/xen/hypercall.h +4 -0
index 0c8ae0e..e8d2b81 100644
@@ -147,6 +147,10 @@ do_xenoprof_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg);
 extern long
 do_xenpmu_op(unsigned int op, XEN_GUEST_HANDLE_PARAM(xen_pmu_params_t) arg);
 
+extern long
+do_version_op(unsigned int cmd,
+    XEN_GUEST_HANDLE_PARAM(void) arg, unsigned int len);
+
 #ifdef CONFIG_COMPAT
 
 extern int
xen/include/xsm/dummy.h +21 -0
index abbe282..e5dad35 100644
@@ -751,3 +751,24 @@ static XSM_INLINE int xsm_xen_version (XSM_DEFAULT_ARG uint32_t op)
         return xsm_default_action(XSM_PRIV, current->domain, NULL);
     }
 }
+
+static XSM_INLINE int xsm_version_op (XSM_DEFAULT_ARG uint32_t op)
+{
+    XSM_ASSERT_ACTION(XSM_OTHER);
+    switch ( op )
+    {
+    case XEN_VERSION_version:
+    case XEN_VERSION_platform_parameters:
+    case XEN_VERSION_get_features:
+        /* These MUST always be accessible to any guest by default. */
+        return 0;
+    case XEN_VERSION_extraversion:
+    case XEN_VERSION_capabilities:
+    case XEN_VERSION_pagesize:
+    case XEN_VERSION_guest_handle:
+        /* These can be accessible to a guest. */
+        return xsm_default_action(XSM_HOOK, current->domain, NULL);
+    default:
+        return xsm_default_action(XSM_PRIV, current->domain, NULL);
+    }
+}
xen/include/xsm/xsm.h +6 -0
index 5ecbee0..ac80472 100644
@@ -194,6 +194,7 @@ struct xsm_operations {
     int (*pmu_op) (struct domain *d, unsigned int op);
 #endif
     int (*xen_version) (uint32_t cmd);
+    int (*version_op) (uint32_t cmd);
 };
 
 #ifdef CONFIG_XSM
@@ -737,6 +738,11 @@ static inline int xsm_xen_version (xsm_default_t def, uint32_t op)
     return xsm_ops->xen_version(op);
 }
 
+static inline int xsm_version_op (xsm_default_t def, uint32_t op)
+{
+    return xsm_ops->version_op(op);
+}
+
 #endif /* XSM_NO_WRAPPERS */
 
 #ifdef CONFIG_MULTIBOOT
xen/xsm/dummy.c +1 -0
index 9791ad4..776dd09 100644
@@ -163,4 +163,5 @@ void xsm_fixup_ops (struct xsm_operations *ops)
     set_to_dummy_if_null(ops, pmu_op);
 #endif
     set_to_dummy_if_null(ops, xen_version);
+    set_to_dummy_if_null(ops, version_op);
 }
xen/xsm/flask/hooks.c +35 -0
index 2069cb3..1eaec58 100644
@@ -1658,6 +1658,40 @@ static int flask_xen_version (uint32_t op)
     }
 }
 
+static int flask_version_op (uint32_t op)
+{
+    u32 dsid = domain_sid(current->domain);
+
+    switch ( op )
+    {
+    case XEN_VERSION_version:
+    case XEN_VERSION_platform_parameters:
+    case XEN_VERSION_get_features:
+        /* These MUST always be accessible to any guest by default. */
+        return 0;
+    case XEN_VERSION_extraversion:
+        return avc_has_perm(dsid, SECINITSID_XEN, SECCLASS_VERSION,
+                            VERSION__EXTRAVERSION, NULL);
+    case XEN_VERSION_capabilities:
+        return avc_has_perm(dsid, SECINITSID_XEN, SECCLASS_VERSION,
+                            VERSION__CAPABILITIES, NULL);
+    case XEN_VERSION_changeset:
+        return avc_has_perm(dsid, SECINITSID_XEN, SECCLASS_VERSION,
+                            VERSION__CHANGESET, NULL);
+    case XEN_VERSION_pagesize:
+        return avc_has_perm(dsid, SECINITSID_XEN, SECCLASS_VERSION,
+                            VERSION__PAGESIZE, NULL);
+    case XEN_VERSION_guest_handle:
+        return avc_has_perm(dsid, SECINITSID_XEN, SECCLASS_VERSION,
+                            VERSION__GUEST_HANDLE, NULL);
+    case XEN_VERSION_commandline:
+        return avc_has_perm(dsid, SECINITSID_XEN, SECCLASS_VERSION,
+                            VERSION__COMMANDLINE, NULL);
+    default:
+        return -EPERM;
+    }
+}
+
 long do_flask_op(XEN_GUEST_HANDLE_PARAM(xsm_op_t) u_flask_op);
 int compat_flask_op(XEN_GUEST_HANDLE_PARAM(xsm_op_t) u_flask_op);
 
@@ -1797,6 +1831,7 @@ static struct xsm_operations flask_ops = {
     .pmu_op = flask_pmu_op,
 #endif
     .xen_version = flask_xen_version,
+    .version_op = flask_version_op,
 };
 
 static __init void flask_init(void)
xen/xsm/flask/policy/access_vectors +18 -3
index badcf1c..56600bb 100644
@@ -496,12 +496,14 @@ class security
     del_ocontext
 }
 
-# Class version is used to describe the XENVER_ hypercall.
+# Class version is used to describe the XENVER_ and VERSION hypercall.
 # Almost all sub-ops are described here - in the default case all of them should
-# be allowed except the XENVER_commandline.
+# be allowed except the XENVER_commandline, VERSION_commandline, and
+# VERSION_changeset.
 #
 # The ones that are omitted are XENVER_version, XENVER_platform_parameters,
-# and XENVER_get_features  - as they MUST always be returned to a guest.
+# XENVER_get_features, XEN_VERSION_version, XEN_VERSION_platform_parameters,
+# and XEN_VERSION_get_features - as they MUST always be returned to a guest.
 #
 class version
 {
@@ -519,4 +521,17 @@ class version
     xen_guest_handle
 # Xen command line.
     xen_commandline
+# --- VERSION hypercall ---
+# Extra informations (-unstable).
+    extraversion
+# Such as "xen-3.0-x86_64 xen-3.0-x86_32p hvm-3.0-x86_32 hvm-3.0-x86_32p hvm-3.0-x86_64".
+    capabilities
+# Source code changeset.
+    changeset
+# Page size the hypervisor uses.
+    pagesize
+# An value that the control stack can choose.
+    guest_handle
+# Xen command line.
+    commandline
 }
Signature · 7 lines
2.4.3


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#5 lore raw

Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 24.03.16 at 22:30, <[email protected]> wrote:

From: Konrad Rzeszutek Wilk <[email protected]>
Date: Tue, 22 Mar 2016 16:53:19 -0400
Subject: [PATCH] HYPERCALL_version_op. New hypercall mirroring XENVER_ but
sane.

This hypercall mirrors the XENVER_ in that it has similar functionality. However it is designed differently:
- No compat layer. The data structures are the same size on 32 as on 64-bit.
- The hypercall accepts three arguments - the command, pointer to an buffer, and the length of the buffer.
- Each sub-ops can be "probed" for size by returning the size of buffer that will be needed - if the buffer is NULL.
- Subops can complete even if the buffer is too small - truncated data will be filled and hypercall will return -ENOBUFS.
- VERSION_commandline, VERSION_changeset are privileged.
- There is no XENVER_compile_info equivalent.
- The hypercall can return -EPERM and toolstack/OSes are expected to deal with. However there are three subops: XEN_VERSION_version, XEN_VERSION_platform_parameters and XEN_VERSION_get_features that will always return an value as guests cannot survive without them.

Quoted 7 lines

While we combine some of the common code between XENVER_ and VERSION_ take the liberty of moving pae_extended_cr3 in x86 area.

This last line doesn't seem to match up with ...

Quoted 6 lines

v1-v3: Was not part of the series.
v4: New posting.
v5: Remove memset and use {}. Tweak copy_to_guest and capabilities_info,
add ASSERT(sz) per Andrew's review. Add cached=1 back in. Per Jan, s/VERSION_OP/VERSION/, squash size check with do_version_op, update the comments. Dropped Andrew's Review-by. Ate newlines.

... the middle sentence here.

xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 412

Quoted 12 lines
xen/common/kernel.c +12 -0
+DO(version_op)(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg,
+               unsigned int len)
+{
+    union {
+        xen_version_op_val_t val;
+        xen_feature_info_t fi;
+    } u = {};
+    unsigned int sz = 0;
+    const void *ptr = NULL;
+    int rc = xsm_version_op(XSM_OTHER, cmd);
+
+    /* We can safely return -EPERM! */

So what again was this comment supposed to tell us?

xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 417

Quoted 5 lines
xen/common/kernel.c +5 -0
+    if ( rc )
+        return rc;
+
+    /*
+     * The HYPERVISOR_xen_version differs in that some return the value,

I think there's a "subop" missing somewhere.

xen/common/kernel.c DO(ni_hypercall)(void) · line 549

Quoted 4 lines
xen/common/kernel.c +4 -0
+static int __init capabilities_cache_init(void)
+{
+    /*
+     * Pre-allocate the cache so we do not have to worry about

"Pre-fill" or "Pre-populate"?

xen/include/public/version.h line 33

Quoted 7 lines
xen/include/public/version.h +0 -1
@@ -30,7 +30,14 @@
 
 #include "xen.h"
 
-/* NB. All ops return zero on success, except XENVER_{version,pagesize} */

Perhaps this comment doesn't belong here anymore, but I don't think it should be deleted altogether.

xen/include/public/version.h line 35

Quoted 3 lines
xen/include/public/version.h +3 -0
+/*
+ * There are two hypercalls mentioned in here. The XENVER_ are for
+ * HYPERCALL_xen_version (17), while VERSION_ are for the

XEN_VERSION_

xen/include/public/version.h typedef struct xen_feature_info xen_feature_info_t; · line 101

Quoted 9 lines
xen/include/public/version.h +5 -0
@@ -87,6 +94,67 @@ typedef struct xen_feature_info xen_feature_info_t;
 #define XENVER_commandline 9
 typedef char xen_commandline_t[1024];
 
+/*
+ * The HYPERCALL_version_op has a set of sub-ops which mirror the
+ * sub-ops of HYPERCALL_xen_version. However this hypercall differs
+ * radically from the former:
+ *  - It returns the amount of bytes returned.

"returns ... returned" is a little strange. Perhaps "returns ... copied"?

xen/include/public/version.h typedef struct xen_feature_info xen_feature_info_t; · line 105

Quoted 4 lines
xen/include/public/version.h +4 -0
+ *  - It will return -XEN_EPERM if the guest is not permitted
+ *    (Albeit XEN_VERSION_version, XEN_VERSION_platform_parameters, and
+ *    XEN_VERSION_get_features will always return an value as guest cannot
+ *    survive without this information).

Isn't there an object missing here, to say what is not permitted?

xen/include/public/version.h typedef struct xen_feature_info xen_feature_info_t; · line 111

Quoted 6 lines
xen/include/public/version.h +6 -0
+ *  - It will return the requested data in arg.
+ *  - It requires an third argument (len) for the length of the
+ *    arg. Naturally the arg has to fit the requested data otherwise
+ *    -XEN_ENOBUFS is returned.
+ *
+ * It also offers an mechanism to probe for the amount of bytes an

... a mechanism ...

xen/include/public/version.h typedef struct xen_feature_info xen_feature_info_t; · line 112

Quoted 1 line
xen/include/public/version.h +1 -0
+ * sub-op will require. Having the arg have an NULL handle will

... a NULL ...

xen/include/public/version.h typedef struct xen_feature_info xen_feature_info_t; · line 114

Quoted 2 lines
xen/include/public/version.h +2 -0
+ * return the number of bytes requested for the operation. Or an
+ * negative value if an error is encountered.

... a negative ...

Since they're all cosmetic, if you take care of all of them, feel free to stick my ack on the result.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#6 lore raw

Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 30.03.16 at 17:43, <[email protected]> wrote:

Since they're all cosmetic, if you take care of all of them, feel free to stick my ack on the result.

Actually - no, please don't. While the patch is fine content wise then from my perspective, I'm still lacking a convincing argument of why this new hypercall is needed in the first place. If others are convinced by the argumentation between (mostly, iirc) you and Andrew, I'm not going to stand in the way, but I'm also not going to approve of the code addition without being myself convinced.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#7 lore raw

Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Quoted 11 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 30.03.16 at 17:43, <[email protected]> wrote:

Since they're all cosmetic, if you take care of all of them, feel free to stick my ack on the result.

Actually - no, please don't. While the patch is fine content wise then from my perspective, I'm still lacking a convincing argument of why this new hypercall is needed in the first place. If others are convinced by the argumentation between (mostly, iirc) you and Andrew, I'm not going to stand in the way, but I'm also not going to approve of the code addition without being myself convinced.

Damm. I pushed the patch in yesterday in 'staging'!

We can always revert them..

"Others" being other maintainers I presume?

The underlaying reason for me doing this is to expose the build-id.

It (build-id) originally was in sysctl, then folks wanted it in XENVER_. Got it working in there as sub-ops, but Andrew last minute decided that it should not really be there but in a new hypercall that can do three arguments (the length) and be able to return -EPERM. A sane one, not the cobbled up XENVER one.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#8 lore raw

Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 31.03.16 at 13:43, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 30.03.16 at 17:43, <[email protected]> wrote:

Since they're all cosmetic, if you take care of all of them, feel free to stick my ack on the result.

Actually - no, please don't. While the patch is fine content wise then from my perspective, I'm still lacking a convincing argument of why this new hypercall is needed in the first place. If others are convinced by the argumentation between (mostly, iirc) you and Andrew, I'm not going to stand in the way, but I'm also not going to approve of the code addition without being myself convinced.

Quoted 5 lines

Damm. I pushed the patch in yesterday in 'staging'!

We can always revert them..

"Others" being other maintainers I presume?

Any one of the REST maintainers, yes.

Quoted 7 lines

The underlaying reason for me doing this is to expose the build-id.

It (build-id) originally was in sysctl, then folks wanted it in XENVER_. Got it working in there as sub-ops, but Andrew last minute decided that it should not really be there but in a new hypercall that can do three arguments (the length) and be able to return -EPERM. A sane one, not the cobbled up XENVER one.

Well, -EPERM is now possible with the old one too. And nothing in that existing interface prevents a length to be passed in/out for new sub-ops. Nor do I really see anything truly insane with that existing interface.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#9 lore raw

REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Quoted 14 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 31.03.16 at 13:43, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 30.03.16 at 17:43, <[email protected]> wrote:

Since they're all cosmetic, if you take care of all of them, feel free to stick my ack on the result.

Actually - no, please don't. While the patch is fine content wise then from my perspective, I'm still lacking a convincing argument of why this new hypercall is needed in the first place. If others are convinced by the argumentation between (mostly, iirc) you and Andrew, I'm not going to stand in the way, but I'm also not going to approve of the code addition without being myself convinced.

Quoted 7 lines
Quoted 5 lines

Damm. I pushed the patch in yesterday in 'staging'!

We can always revert them..

"Others" being other maintainers I presume?

Any one of the REST maintainers, yes.

Changing the title to get their attention.

Quoted 5 lines
Quoted 5 lines

The underlaying reason for me doing this is to expose the build-id.

It (build-id) originally was in sysctl, then folks wanted it in XENVER_. Got it working in there as sub-ops, but Andrew last minute decided that

Here is the link to v3 which had it in XENVER_ subops:
http://lists.xen.org/archives/html/xen-devel/2016-02/msg04110.html

And this one v5 (in case folks had deleted this thread, v4 is almost the same except it had VERSION instead of XEN_VERSION):
http://lists.xen.org/archives/html/xen-devel/2016-03/msg03302.html

Quoted 7 lines
Quoted 3 lines

it should not really be there but in a new hypercall that can do three arguments (the length) and be able to return -EPERM. A sane one, not the cobbled up XENVER one.

Well, -EPERM is now possible with the old one too. And nothing in that existing interface prevents a length to be passed in/out for new sub-ops. Nor do I really see anything truly insane with

We cannot expand the hypercall to have three arguments - it MUST have two (as you had pointed out earlier). The length must be jammed in the sub-ops:

/* Return value is the number of bytes written, or XEN_Exx on error.
* Calling with empty parameter returns the size of build_id. */

#define XENVER_build_id 10

struct xen_build_id {
        uint32_t        len; /* IN: size of buf[]. */
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
        unsigned char   buf[];

#elif defined(__GNUC__)
unsigned char buf[1]; /* OUT: Variable length buffer with build_id. */
#endif
};
typedef struct xen_build_id xen_build_id_t;

Quoted 4 lines

that existing interface.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#10 lore raw

REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 31.03.16 at 15:28, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 31.03.16 at 13:43, <[email protected]> wrote:

it should not really be there but in a new hypercall that can do three arguments (the length) and be able to return -EPERM. A sane one, not the cobbled up XENVER one.

Quoted 7 lines
Quoted 3 lines

Well, -EPERM is now possible with the old one too. And nothing in that existing interface prevents a length to be passed in/out for new sub-ops. Nor do I really see anything truly insane with

We cannot expand the hypercall to have three arguments - it MUST have two (as you had pointed out earlier). The length must be jammed in the sub-ops:

Right, that's what I had implied.

Jan

Quoted 8 lines

/* Return value is the number of bytes written, or XEN_Exx on error.
* Calling with empty parameter returns the size of build_id. */

#define XENVER_build_id 10

struct xen_build_id {
        uint32_t        len; /* IN: size of buf[]. */
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
        unsigned char   buf[];
Quoted 11 lines

#elif defined(__GNUC__)
unsigned char buf[1]; /* OUT: Variable length buffer with
build_id. */
#endif
};
typedef struct xen_build_id xen_build_id_t;

Quoted 4 lines

that existing interface.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#11 lore raw

REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

In reply to Konrad Rzeszutek Wilk
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 31.03.16 at 15:28, <[email protected]> wrote:
Quoted 16 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 31.03.16 at 13:43, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 30.03.16 at 17:43, <[email protected]> wrote:

Since they're all cosmetic, if you take care of all of them, feel free to stick my ack on the result.

Actually - no, please don't. While the patch is fine content wise then from my perspective, I'm still lacking a convincing argument of why this new hypercall is needed in the first place. If others are convinced by the argumentation between (mostly, iirc) you and Andrew, I'm not going to stand in the way, but I'm also not going to approve of the code addition without being myself convinced.

Damm. I pushed the patch in yesterday in 'staging'!

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

We can always revert them..

"Others" being other maintainers I presume?

Any one of the REST maintainers, yes.

Changing the title to get their attention.

Yet nothing has happened, so I think the patch needs to be reverted (at least for the time being).

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#12 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Quoted 20 lines · Jan Beulich
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 31.03.16 at 15:28, <[email protected]> wrote:
Quoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 31.03.16 at 13:43, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 30.03.16 at 17:43, <[email protected]> wrote:

Since they're all cosmetic, if you take care of all of them, feel free to stick my ack on the result.

Actually - no, please don't. While the patch is fine content wise then from my perspective, I'm still lacking a convincing argument of why this new hypercall is needed in the first place. If others are convinced by the argumentation between (mostly, iirc) you and Andrew, I'm not going to stand in the way, but I'm also not going to approve of the code addition without being myself convinced.

Damm. I pushed the patch in yesterday in 'staging'!

We can always revert them..

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

"Others" being other maintainers I presume?

Any one of the REST maintainers, yes.

Changing the title to get their attention.

Yet nothing has happened, so I think the patch needs to be reverted (at least for the time being).

Wait what?!

The natural consensus mechanism we use is lazy. If nobody objects then it is Acked.

Anyhow pinged Ian Jackson on IRC.

Quoted 3 lines

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#13 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Quoted 28 lines
Quoted 1 line
Quoted 1 line · On 08.04.16 at 19:09, <[email protected]> wrote:
Quoted 26 lines · Jan Beulich
Quoted 25 lines
Quoted 1 line
Quoted 1 line · On 31.03.16 at 15:28, <[email protected]> wrote:
Quoted 14 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 31.03.16 at 13:43, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 30.03.16 at 17:43, <[email protected]> wrote:

Since they're all cosmetic, if you take care of all of them, feel free to stick my ack on the result.

Actually - no, please don't. While the patch is fine content wise then from my perspective, I'm still lacking a convincing argument of why this new hypercall is needed in the first place. If others are convinced by the argumentation between (mostly, iirc) you and Andrew, I'm not going to stand in the way, but I'm also not going to approve of the code addition without being myself convinced.

Quoted 7 lines
Quoted 5 lines

Damm. I pushed the patch in yesterday in 'staging'!

We can always revert them..

"Others" being other maintainers I presume?

Any one of the REST maintainers, yes.

Changing the title to get their attention.

Quoted 7 lines
Quoted 2 lines

Yet nothing has happened, so I think the patch needs to be reverted (at least for the time being).

Wait what?!

The natural consensus mechanism we use is lazy. If nobody objects then it is Acked.

Since when can patches go in without any ack(s) of relevant maintainers?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#14 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Quoted 31 lines · Jan Beulich
Quoted 31 lines
Quoted 1 line
Quoted 1 line · On 08.04.16 at 19:09, <[email protected]> wrote:
Quoted 28 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 31.03.16 at 15:28, <[email protected]> wrote:
Quoted 16 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 31.03.16 at 13:43, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 30.03.16 at 17:43, <[email protected]> wrote:

Since they're all cosmetic, if you take care of all of them, feel free to stick my ack on the result.

Actually - no, please don't. While the patch is fine content wise then from my perspective, I'm still lacking a convincing argument of why this new hypercall is needed in the first place. If others are convinced by the argumentation between (mostly, iirc) you and Andrew, I'm not going to stand in the way, but I'm also not going to approve of the code addition without being myself convinced.

Damm. I pushed the patch in yesterday in 'staging'!

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

We can always revert them..

"Others" being other maintainers I presume?

Any one of the REST maintainers, yes.

Changing the title to get their attention.

Yet nothing has happened, so I think the patch needs to be reverted (at least for the time being).

Quoted 8 lines
Quoted 4 lines

Wait what?!

The natural consensus mechanism we use is lazy. If nobody objects then it is Acked.

Since when can patches go in without any ack(s) of relevant maintainers?

Urgh, at the risk of pointing out the obvious -- it does seem to have your ack...

Wei.

Quoted 2 lines

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#15 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Quoted 37 lines · Wei Liu
Quoted 36 lines · Jan Beulich
Quoted 35 lines
Quoted 1 line
Quoted 1 line · On 08.04.16 at 19:09, <[email protected]> wrote:
Quoted 20 lines · Jan Beulich
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 31.03.16 at 15:28, <[email protected]> wrote:
Quoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 31.03.16 at 13:43, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 30.03.16 at 17:43, <[email protected]> wrote:

Since they're all cosmetic, if you take care of all of them, feel free to stick my ack on the result.

Actually - no, please don't. While the patch is fine content wise then from my perspective, I'm still lacking a convincing argument of why this new hypercall is needed in the first place. If others are convinced by the argumentation between (mostly, iirc) you and Andrew, I'm not going to stand in the way, but I'm also not going to approve of the code addition without being myself convinced.

Damm. I pushed the patch in yesterday in 'staging'!

We can always revert them..

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

"Others" being other maintainers I presume?

Any one of the REST maintainers, yes.

Changing the title to get their attention.

Yet nothing has happened, so I think the patch needs to be reverted (at least for the time being).

Wait what?!

The natural consensus mechanism we use is lazy. If nobody objects then it is Acked.

Quoted 6 lines
Quoted 3 lines

Since when can patches go in without any ack(s) of relevant maintainers?

Urgh, at the risk of pointing out the obvious -- it does seem to have your ack...

Which was given at night before Jan retracted it in the morning.

This feels like one of those Catch-22 :-)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#16 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Quoted 42 lines · Konrad Rzeszutek Wilk
Quoted 41 lines · Wei Liu
Quoted 39 lines · Jan Beulich
Quoted 28 lines
Quoted 1 line
Quoted 1 line · On 08.04.16 at 19:09, <[email protected]> wrote:
Quoted 26 lines · Jan Beulich
Quoted 25 lines
Quoted 1 line
Quoted 1 line · On 31.03.16 at 15:28, <[email protected]> wrote:
Quoted 14 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 31.03.16 at 13:43, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 30.03.16 at 17:43, <[email protected]> wrote:

Since they're all cosmetic, if you take care of all of them, feel free to stick my ack on the result.

Actually - no, please don't. While the patch is fine content wise then from my perspective, I'm still lacking a convincing argument of why this new hypercall is needed in the first place. If others are convinced by the argumentation between (mostly, iirc) you and Andrew, I'm not going to stand in the way, but I'm also not going to approve of the code addition without being myself convinced.

Quoted 7 lines
Quoted 5 lines

Damm. I pushed the patch in yesterday in 'staging'!

We can always revert them..

"Others" being other maintainers I presume?

Any one of the REST maintainers, yes.

Changing the title to get their attention.

Quoted 7 lines
Quoted 2 lines

Yet nothing has happened, so I think the patch needs to be reverted (at least for the time being).

Wait what?!

The natural consensus mechanism we use is lazy. If nobody objects then it is Acked.

Since when can patches go in without any ack(s) of relevant maintainers?

Quoted 6 lines
Quoted 2 lines

Urgh, at the risk of pointing out the obvious -- it does seem to have your ack...

Which was given at night before Jan retracted it in the morning.

This feels like one of those Catch-22 :-)

Ah, OK then, so Jan has a point. This needs to be properly discussed and refereed.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#17 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

In reply to Konrad Rzeszutek Wilk

Konrad Rzeszutek Wilk writes ("Re: REST MAINTAINERS feedback requested Was:Re: [Xen-devel] [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane."):

Quoted 5 lines · Jan Beulich
Quoted 2 lines

Yet nothing has happened, so I think the patch needs to be reverted (at least for the time being).

Wait what?!

I'm sorry that I didn't understand that we were being asked for a second opinion about this disagreement. I'm afriad that the original email wasn't really comprehensible to me as a summary of the disagreement.

Would someone please summarise ? Especially, since Jan is AFAICT saying that this new hypercall is not needed, it would be helpful to know why those who think it is needed want it.

In the meantime I think it would be best to avoid churn by leaving the patch in tree for now. I promise that I won't let those "facts on the ground" influence my views about whether this hypercall is needed.

Thanks,
Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#18 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Quoted 5 lines · Ian Jackson

Konrad Rzeszutek Wilk writes ("Re: REST MAINTAINERS feedback requested Was:Re: [Xen-devel] [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane."):

Quoted 4 lines · Jan Beulich
Quoted 2 lines

Yet nothing has happened, so I think the patch needs to be reverted (at least for the time being).

Wait what?!

Quoted 8 lines

I'm sorry that I didn't understand that we were being asked for a second opinion about this disagreement. I'm afriad that the original email wasn't really comprehensible to me as a summary of the disagreement.

Would someone please summarise ? Especially, since Jan is AFAICT saying that this new hypercall is not needed, it would be helpful to know why those who think it is needed want it.

The new hypercall is very definitely needed, which is why I requested it during earlier revisions of the xsplice series.

The interface for the old version was sufficiently useless that build_id can't be added to it. (Specifically, there is no ability to return varialble length data). Also, by its design, it has some unreasonably-short limits on extraversion and changesetinfo, both of which could do with being longer for distros trying to encode "delta from upstream" information.

The new hypercall has a ration interface where you don't blindly trust that the caller passed you a pointer to a suitably-sized structure.

I am very much +10 keep to the patch.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#19 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 08.04.16 at 19:41, <[email protected]> wrote:
Quoted 1 line · Ian Jackson

Konrad Rzeszutek Wilk writes ("Re: REST MAINTAINERS feedback requested

Was:Re: [Xen-devel] [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane."):

Quoted 4 lines
Quoted 4 lines · Jan Beulich
Quoted 2 lines

Yet nothing has happened, so I think the patch needs to be reverted (at least for the time being).

Wait what?!

Quoted 8 lines

I'm sorry that I didn't understand that we were being asked for a second opinion about this disagreement. I'm afriad that the original email wasn't really comprehensible to me as a summary of the disagreement.

Would someone please summarise ? Especially, since Jan is AFAICT saying that this new hypercall is not needed, it would be helpful to know why those who think it is needed want it.

Quoted 6 lines

The new hypercall is very definitely needed, which is why I requested it during earlier revisions of the xsplice series.

The interface for the old version was sufficiently useless that build_id can't be added to it. (Specifically, there is no ability to return varialble length data).

This is simply not true: The hypercall being passed a void handle, everything can be arranged for without introducing a new hypercall.

Quoted 7 lines

Also, by its design, it has some
unreasonably-short limits on extraversion and changesetinfo, both of which could do with being longer for distros trying to encode "delta from upstream" information.

The new hypercall has a ration interface where you don't blindly trust that the caller passed you a pointer to a suitably-sized structure.

While the new one is indeed slightly neater, that's not sufficient for such redundancy imo. That's the whole reason for withdrawing my ack _without_ making it an explicit NAK.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#20 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Jan Beulich writes ("Re: REST MAINTAINERS feedback requested Was:Re: [Xen-devel] [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane."):

Quoted 8 lines · On 08.04.16 at 19:41, <[email protected]> wrote:
Quoted 3 lines

The interface for the old version was sufficiently useless that build_id can't be added to it. (Specifically, there is no ability to return varialble length data).

This is simply not true: The hypercall being passed a void handle, everything can be arranged for without introducing a new hypercall.

I'm trying to understand what your alternative suggestion is. Could you please be more explicit ?

I'm reading xen/include/public/version.h. (Sadly it doesn't have the API doc markup.) AFAICT there is a XENVER_xxxx sub-op namespace which permits extensions to the XENVER hypercall.

But does that permit the caller to specify their buffer size ?

Quoted 2 lines
Quoted 2 lines

The new hypercall has a ration interface where you don't blindly trust that the caller passed you a pointer to a suitably-sized structure.

Ie I think ^ this is for me a key question.

Quoted 3 lines

While the new one is indeed slightly neater, that's not sufficient for such redundancy imo. That's the whole reason for withdrawing my ack _without_ making it an explicit NAK.

I don't think I would be content with simply adding a new sub-op with bigger fixed-length fields.

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#21 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Quoted 10 lines · Ian Jackson

Jan Beulich writes ("Re: REST MAINTAINERS feedback requested Was:Re: [Xen-devel] [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane."):

Quoted 8 lines · On 08.04.16 at 19:41, <[email protected]> wrote:
Quoted 3 lines

The interface for the old version was sufficiently useless that build_id can't be added to it. (Specifically, there is no ability to return varialble length data).

This is simply not true: The hypercall being passed a void handle, everything can be arranged for without introducing a new hypercall.

Quoted 8 lines

I'm trying to understand what your alternative suggestion is. Could you please be more explicit ?

I'm reading xen/include/public/version.h. (Sadly it doesn't have the API doc markup.) AFAICT there is a XENVER_xxxx sub-op namespace which permits extensions to the XENVER hypercall.

But does that permit the caller to specify their buffer size ?

Only via the sub-op parameters itself. As in you cannot expand the amount of parameters the XENVER_hypercall can do (which is two - subops number and the pointer to arguments).

Quoted 4 lines
Quoted 3 lines
Quoted 3 lines

The new hypercall has a ration interface where you don't blindly trust that the caller passed you a pointer to a suitably-sized structure.

Quoted 8 lines

Ie I think ^ this is for me a key question.

Quoted 3 lines

While the new one is indeed slightly neater, that's not sufficient for such redundancy imo. That's the whole reason for withdrawing my ack _without_ making it an explicit NAK.

I don't think I would be content with simply adding a new sub-op with bigger fixed-length fields.

It was variable-ish.

The new-subop (xsplice.v3) ended up 'lets-try-this-size' subop. Meaning:

/* Return value is the number of bytes written, or XEN_Exx on error.
* Calling with empty parameter returns the size of build_id. */

#define XENVER_build_id 10

struct xen_build_id {
        uint32_t        len; /* IN: size of buf[]. */
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
        unsigned char   buf[];

#elif defined(__GNUC__)
unsigned char buf[1]; /* OUT: Variable length buffer with build_id. */
#endif
};

When constructing this in libxl we could do:

xen_build_id_t *build_id;

 	ret= xc_version(ctx->xch, XENVER_build_id, NULL);
	if ( ret != -ENOSYS && ret > 0 )
            build_id = libxl__zalloc(gc, ret + sizeof(*build_id));
            build_id->len = info->pagesize - sizeof(*build_id);
 	    ret= xc_version(ctx->xch, XENVER_build_id, build_id);
            .. parse it...
        }

For the default case, ret would be 20, which meant the structure had to be 24 bytes. 4 bytes were for 'len' (which had the value of 20) and the rest inside the build_id were to be filled with the hypervisor.

For glory details:
http://xenbits.xen.org/gitweb/?p=people/konradwilk/xen.git;a=commitdiff;h=63681414ede6e38c1910077d7a225e0d67f0ff2e;hp=37efc2ac64b9ecf0cd49fb65aa7c7659467c9318
and
http://xenbits.xen.org/gitweb/?p=people/konradwilk/xen.git;a=commitdiff;h=176c63f3c0db430c70c28fe81cb8d039ae459c66;hp=63681414ede6e38c1910077d7a225e0d67f0ff2e

(albeit we first tried with the default 1020 bytes we have on the stack).

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#22 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Konrad Rzeszutek Wilk writes ("Re: REST MAINTAINERS feedback requested Was:Re: [Xen-devel] [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane."):

Quoted 5 lines · Ian Jackson
Quoted 2 lines

I don't think I would be content with simply adding a new sub-op with bigger fixed-length fields.

It was variable-ish.

...

Quoted 2 lines

/* Return value is the number of bytes written, or XEN_Exx on error.
* Calling with empty parameter returns the size of build_id. */

...

Quoted 5 lines

#define XENVER_build_id 10

struct xen_build_id {
        uint32_t        len; /* IN: size of buf[]. */
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
        unsigned char   buf[];

This is pretty ugly but tolerable.

The comment introducing the new HYPERCALL_version_op mentions some other differences with HYPERCALL_xen_version, which seem to suggest other deficiencies in the latter. Those deficiencies, together with the ugliness of the above, would tend to suggest to me that a cleaner new interface is warranted.

But to an extent some of this conversation seems to be on matters of taste.

Jan, what is the downside of introducing a new hypercall ?

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#23 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Quoted 21 lines
Quoted 1 line
Quoted 1 line · On 11.04.16 at 16:22, <[email protected]> wrote:

Konrad Rzeszutek Wilk writes ("Re: REST MAINTAINERS feedback requested Was:Re: [Xen-devel] [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane."):

Quoted 5 lines · Ian Jackson
Quoted 2 lines

I don't think I would be content with simply adding a new sub-op with bigger fixed-length fields.

It was variable-ish.

...

Quoted 2 lines

/* Return value is the number of bytes written, or XEN_Exx on error.
* Calling with empty parameter returns the size of build_id. */

...

Quoted 5 lines

#define XENVER_build_id 10

struct xen_build_id {
        uint32_t        len; /* IN: size of buf[]. */
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
        unsigned char   buf[];

This is pretty ugly but tolerable.

Quoted 8 lines

The comment introducing the new HYPERCALL_version_op mentions some other differences with HYPERCALL_xen_version, which seem to suggest other deficiencies in the latter. Those deficiencies, together with the ugliness of the above, would tend to suggest to me that a cleaner new interface is warranted.

But to an extent some of this conversation seems to be on matters of taste.

Agreed.

Quoted 1 line

Jan, what is the downside of introducing a new hypercall ?

Duplicate code effectively doing the same thing.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#24 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Jan Beulich writes ("Re: REST MAINTAINERS feedback requested Was:Re: [Xen-devel] [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane."):

Quoted 9 lines · On 11.04.16 at 16:22, <[email protected]> wrote:
Quoted 2 lines

But to an extent some of this conversation seems to be on matters of taste.

Agreed.

Quoted 1 line

Jan, what is the downside of introducing a new hypercall ?

Duplicate code effectively doing the same thing.

I agree that duplication is bad, all other things being equal.

But any improvement from an old API to a new one necessarily involves providing a dual facility during a transition period.

I don't see an explicit deprecation in the patch that is in tree, but it seems to me to be intended (and, perhaps, implied). Certainly if we are going to permit these strings etc. to be bigger than fits in the old hypercall, the old hypercall needs to be deprecated on the grounds that it can provide incomplete or inaccurate information.

Does this way of looking at it help ?

Thanks,
Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#25 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Quoted 11 lines · Ian Jackson

Jan Beulich writes ("Re: REST MAINTAINERS feedback requested Was:Re: [Xen-devel] [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane."):

Quoted 9 lines · On 11.04.16 at 16:22, <[email protected]> wrote:
Quoted 2 lines

But to an extent some of this conversation seems to be on matters of taste.

Agreed.

Quoted 1 line

Jan, what is the downside of introducing a new hypercall ?

Duplicate code effectively doing the same thing.

Quoted 7 lines

I agree that duplication is bad, all other things being equal.

But any improvement from an old API to a new one necessarily involves providing a dual facility during a transition period.

I don't see an explicit deprecation in the patch that is in tree, but it seems to me to be intended (and, perhaps, implied). Certainly if

I tried it at some point by adding the suffix 'compat' to it.

The compat layer did not like the extra compat string and all kinds of compilation issues arose. I put it on the backburner.

Quoted 3 lines

we are going to permit these strings etc. to be bigger than fits in the old hypercall, the old hypercall needs to be deprecated on the grounds that it can provide incomplete or inaccurate information.

The build-id in Config.mk is set to use sha1. Which produces 20 bytes. You (or anybody else) can modify Config.mk to modify --build-id as per man ld (there is an uuid or md5 or):

"0xhexstring" to use a chosen bit string specified as an even number of hexadecimal
digits ("-" and ":" characters between digit pairs are ignored)."

which does not impose any limits. Albeit 2967 characters of 0xdeadbeef is all I seem to be able jam on the line. Weird. Anyhow:

build_id : deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeefdeadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeefdeadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeefdeadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeefdeadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeefdeadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeefdeadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeefdeadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeefdeadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeefdeadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeefdeadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeefdeadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeefdeadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeefdeadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeefdeadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeefdeadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeef0000deadbeefdeadbeef0000deadbeef0000deadbeef0000dead

is possible.

Quoted 5 lines

Does this way of looking at it help ?

Thanks,
Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#26 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 11.04.16 at 18:53, <[email protected]> wrote:
Quoted 5 lines · Ian Jackson

Jan Beulich writes ("Re: REST MAINTAINERS feedback requested Was:Re:
Certainly if
we are going to permit these strings etc. to be bigger than fits in the old hypercall, the old hypercall needs to be deprecated on the grounds that it can provide incomplete or inaccurate information.

The build-id in Config.mk is set to use sha1. Which produces 20 bytes. You (or anybody else) can modify Config.mk to modify --build-id as per man ld (there is an uuid or md5 or):

Quoted 5 lines

"0xhexstring" to use a chosen bit string specified as an even number of
hexadecimal
digits ("-" and ":" characters between digit pairs are ignored)."

which does not impose any limits.

This has nothing to do with the discussion here, imo. The new build-id sub-op can, as said numerous times before, easily have a buffer length communicated.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#27 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

In reply to Ian Jackson
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 11.04.16 at 18:25, <[email protected]> wrote:

Jan Beulich writes ("Re: REST MAINTAINERS feedback requested Was:Re:
[Xen-devel] [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane."):

Quoted 6 lines · On 11.04.16 at 16:22, <[email protected]> wrote:
Quoted 2 lines

But to an extent some of this conversation seems to be on matters of taste.

Agreed.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Jan, what is the downside of introducing a new hypercall ?

Duplicate code effectively doing the same thing.

I agree that duplication is bad, all other things being equal.

But any improvement from an old API to a new one necessarily involves providing a dual facility during a transition period.

Except that, at least for most sub-ops, the new one doesn't really provide much advantage, and hence dealing with the lack of size for those sub-ops where it matters within the existing hypercall (perhaps by adding one or two new sub-ops) would limit duplication quite a bit.

Quoted 7 lines

I don't see an explicit deprecation in the patch that is in tree, but it seems to me to be intended (and, perhaps, implied). Certainly if we are going to permit these strings etc. to be bigger than fits in the old hypercall, the old hypercall needs to be deprecated on the grounds that it can provide incomplete or inaccurate information.

Does this way of looking at it help ?

If that means you approve of the introduction of the new hypercall, yes. After all the goal of this whole discussion is to determine whether another maintainer is willing to provide a replacement ack for the withdrawn one.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#28 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Jan Beulich writes ("Re: REST MAINTAINERS feedback requested Was:Re: [Xen-devel] [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane."):

Quoted 9 lines · On 11.04.16 at 18:25, <[email protected]> wrote:
Quoted 2 lines

But any improvement from an old API to a new one necessarily involves providing a dual facility during a transition period.

Except that, at least for most sub-ops, the new one doesn't really provide much advantage, and hence dealing with the lack of size for those sub-ops where it matters within the existing hypercall (perhaps by adding one or two new sub-ops) would limit duplication quite a bit.

ISTM that the lower duplication (which in principle is an advantage which will be time limited if we are ever able to completely remove teh old hypercall) comes with the cost of (in the long term) increased mess in this particular subop.

Is that right ? Obviously this cost is not very significant. But maybe the duplication isn't that significant either. I was kind of expecting to find stronger arguments on both sides in this discussion...

Andrew, can you please confirm what you think of Jan's suggestion to instead add a new sub-op where the sub-op structure contains a guest-provided length field ? Are there other reasons to want to introduce a new hypercall ?

Quoted 6 lines
Quoted 6 lines

I don't see an explicit deprecation in the patch that is in tree, but it seems to me to be intended (and, perhaps, implied). Certainly if we are going to permit these strings etc. to be bigger than fits in the old hypercall, the old hypercall needs to be deprecated on the grounds that it can provide incomplete or inaccurate information.

Quoted 6 lines
Quoted 1 line

Does this way of looking at it help ?

If that means you approve of the introduction of the new hypercall, yes. After all the goal of this whole discussion is to determine whether another maintainer is willing to provide a replacement ack for the withdrawn one.

Err. Well, I am still asking questions. When I said "does that help" I was meaning something like "does that help bring you closer to agreement with Andrew". But I don't want to focus on procedure here.

If we're going to have the argument over this bike shed I'd like to figure out what colour I myself prefer :-). But I need to know what the reasons are behind people's preferences.

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#29 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 11.04.16 at 19:13, <[email protected]> wrote:

Jan Beulich writes ("Re: REST MAINTAINERS feedback requested Was:Re:
[Xen-devel] [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane."):

Quoted 9 lines · On 11.04.16 at 18:25, <[email protected]> wrote:
Quoted 2 lines

But any improvement from an old API to a new one necessarily involves providing a dual facility during a transition period.

Except that, at least for most sub-ops, the new one doesn't really provide much advantage, and hence dealing with the lack of size for those sub-ops where it matters within the existing hypercall (perhaps by adding one or two new sub-ops) would limit duplication quite a bit.

Quoted 4 lines

ISTM that the lower duplication (which in principle is an advantage which will be time limited if we are ever able to completely remove teh old hypercall) comes with the cost of (in the long term) increased mess in this particular subop.

We cannot, ever, remove a not toolstack limited hypercall completely (or if, then only by Kconfig option so that people knowing none of the guests they care about use such deprecated ones).

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

I don't see an explicit deprecation in the patch that is in tree, but it seems to me to be intended (and, perhaps, implied). Certainly if we are going to permit these strings etc. to be bigger than fits in the old hypercall, the old hypercall needs to be deprecated on the grounds that it can provide incomplete or inaccurate information.

Does this way of looking at it help ?

Quoted 8 lines
Quoted 4 lines

If that means you approve of the introduction of the new hypercall, yes. After all the goal of this whole discussion is to determine whether another maintainer is willing to provide a replacement ack for the withdrawn one.

Err. Well, I am still asking questions. When I said "does that help" I was meaning something like "does that help bring you closer to agreement with Andrew". But I don't want to focus on procedure here.

Oh, well, in that case the answer is "no". Bike shed issue or not, having to maintain two pieces of code with similar functionality is undesirable. And it's not like we didn't have any XSA for that (apparently trivial) piece of code already.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#30 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

In reply to Ian Jackson
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 11.04.16 at 19:13, <[email protected]> wrote:

Jan Beulich writes ("Re: REST MAINTAINERS feedback requested Was:Re:
[Xen-devel] [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane."):

Quoted 9 lines · On 11.04.16 at 18:25, <[email protected]> wrote:
Quoted 2 lines

But any improvement from an old API to a new one necessarily involves providing a dual facility during a transition period.

Except that, at least for most sub-ops, the new one doesn't really provide much advantage, and hence dealing with the lack of size for those sub-ops where it matters within the existing hypercall (perhaps by adding one or two new sub-ops) would limit duplication quite a bit.

ISTM that the lower duplication (which in principle is an advantage which will be time limited if we are ever able to completely remove teh old hypercall) comes with the cost of (in the long term) increased mess in this particular subop.

Quoted 4 lines

Is that right ? Obviously this cost is not very significant. But maybe the duplication isn't that significant either. I was kind of expecting to find stronger arguments on both sides in this discussion...

If, btw, the cost of having to read the length argument from guest memory was deemed undesirable, we'd certainly have the option of specifying it to be passed through, say, the high half of the current "cmd" parameter.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#31 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

On Mon, Apr 11, 2016 at 6:46 PM, Jan Beulich <[email protected]> wrote:
[snip]

Quoted 8 lines
Quoted 4 lines

ISTM that the lower duplication (which in principle is an advantage which will be time limited if we are ever able to completely remove teh old hypercall) comes with the cost of (in the long term) increased mess in this particular subop.

We cannot, ever, remove a not toolstack limited hypercall completely (or if, then only by Kconfig option so that people knowing none of the guests they care about use such deprecated ones).

We need to keep the hypercall around and functioning for ABI compatibility, but we could at least remove it from the public headers and point people to using the new one instead. (Discussion about the merit of this idea below.)

[snip]

Quoted 10 lines
Quoted 9 lines

ISTM that the lower duplication (which in principle is an advantage which will be time limited if we are ever able to completely remove teh old hypercall) comes with the cost of (in the long term) increased mess in this particular subop.

Is that right ? Obviously this cost is not very significant. But maybe the duplication isn't that significant either. I was kind of expecting to find stronger arguments on both sides in this discussion...

Quoted 4 lines

If, btw, the cost of having to read the length argument from guest memory was deemed undesirable, we'd certainly have the option of specifying it to be passed through, say, the high half of the current "cmd" parameter.

OK, so here are the options I see:

1. Use the existing hypercall with the existing call semantics for build-id -- i.e., require the caller to have a large but fixed-length buffer (maybe 1024 or 2048).

2. Use the existing hypercall but wedge in different calling semantics for the build-id subop. We could have just that subop pay attention to an extra argument as a length, for example, and return an error if the length is too short. Or we could make essentially a flag that asks, "How much space if I were to execute this subop for real?"

3. We could use a new hypercall only for new functionality, with the proposed new semantics. This would at minimum be build-id, but probably also extraversion, compileinfo, changeset, maybe capabilities_info.

4. Have the new hypercall replace the old hypercall. The new hypercall will duplicate all the functionality of the old hypercall. Deprecate the hypercall for a release or two, then remove it from the public headers (although keep the code, because we need to maintain backwards compatibility).

Honestly I still don't quite understand what the problem is with #1 -- if build-id is mainly meant to be a UUID or a hash of the build to make sure that you're applying the right hotfix (please correct me if I'm wrong here -- I haven't had time to actually follow the patch series), 256 bytes should be enough for a properly hashed build, and 2048 should be more than enough. Requiring the caller to have a 2048-byte buffer before calling doesn't really seem like that much of a hardship to me. Basically:

a. It's nicer to have arbitrary-length strings (2-4), but reasonably large fixed-length ones aren't awful (1)

b. It's nicer for hypercall consumers to have a single hypercall with consistent semantics (1,4), but having two hypercalls (3) or a single one with inconsistent semantics (2) aren't that bad either.

c. It's nicer for hypervisor maintainers to have a single place to support any given bit of functionality (1-3), but having a slightly duplicated functionality that only has to be supported in an ABI backwards-compatible manner isn't that bad either (4).

This does seem to me an awful lot like a bike shed. :-) All of the options (1-4) seem perfectly fine to me. FWIW my preferred color would probably be 1 because it's the easiest and least inconsistent with the current state of things. My least favorite would be 3, because although each individual piece of information is only in one place, the path to get there is duplicated; both the kernel developer and the hypervisor developer are forced to continue to deal with both.

-George

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#32 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Quoted 38 lines · George Dunlap

On Mon, Apr 11, 2016 at 6:46 PM, Jan Beulich <[email protected]> wrote:
[snip]

Quoted 8 lines
Quoted 4 lines

ISTM that the lower duplication (which in principle is an advantage which will be time limited if we are ever able to completely remove teh old hypercall) comes with the cost of (in the long term) increased mess in this particular subop.

We cannot, ever, remove a not toolstack limited hypercall completely (or if, then only by Kconfig option so that people knowing none of the guests they care about use such deprecated ones).

We need to keep the hypercall around and functioning for ABI compatibility, but we could at least remove it from the public headers and point people to using the new one instead. (Discussion about the merit of this idea below.)

[snip]

Quoted 10 lines
Quoted 9 lines

ISTM that the lower duplication (which in principle is an advantage which will be time limited if we are ever able to completely remove teh old hypercall) comes with the cost of (in the long term) increased mess in this particular subop.

Is that right ? Obviously this cost is not very significant. But maybe the duplication isn't that significant either. I was kind of expecting to find stronger arguments on both sides in this discussion...

Quoted 4 lines

If, btw, the cost of having to read the length argument from guest memory was deemed undesirable, we'd certainly have the option of specifying it to be passed through, say, the high half of the current "cmd" parameter.

OK, so here are the options I see:

1. Use the existing hypercall with the existing call semantics for build-id -- i.e., require the caller to have a large but fixed-length buffer (maybe 1024 or 2048).

Quoted 5 lines

2. Use the existing hypercall but wedge in different calling semantics for the build-id subop. We could have just that subop pay attention to an extra argument as a length, for example, and return an error if the length is too short. Or we could make essentially a flag that asks, "How much space if I were to execute this subop for real?"

You can't wedge in the extra argument. Tried that an Jan pointed out that we clobber it (specifically we clobber any non-used arguments).

Quoted 11 lines

3. We could use a new hypercall only for new functionality, with the proposed new semantics. This would at minimum be build-id, but probably also extraversion, compileinfo, changeset, maybe capabilities_info.

4. Have the new hypercall replace the old hypercall. The new hypercall will duplicate all the functionality of the old hypercall. Deprecate the hypercall for a release or two, then remove it from the public headers (although keep the code, because we need to maintain backwards compatibility).

5). Stick the build-id in the xsplice sysctl. Or just in the sysctl.

Quoted 17 lines

Honestly I still don't quite understand what the problem is with #1 -- if build-id is mainly meant to be a UUID or a hash of the build to make sure that you're applying the right hotfix (please correct me if I'm wrong here -- I haven't had time to actually follow the patch series), 256 bytes should be enough for a properly hashed build, and 2048 should be more than enough. Requiring the caller to have a 2048-byte buffer before calling doesn't really seem like that much of a hardship to me. Basically:

a. It's nicer to have arbitrary-length strings (2-4), but reasonably large fixed-length ones aren't awful (1)

b. It's nicer for hypercall consumers to have a single hypercall with consistent semantics (1,4), but having two hypercalls (3) or a single one with inconsistent semantics (2) aren't that bad either.

Quoted 6 lines

c. It's nicer for hypervisor maintainers to have a single place to support any given bit of functionality (1-3), but having a slightly duplicated functionality that only has to be supported in an ABI backwards-compatible manner isn't that bad either (4).

This does seem to me an awful lot like a bike shed. :-) All of the

This is really past bike shedding - all the bikes shed have been already built (for all those options).

Quoted 7 lines

options (1-4) seem perfectly fine to me. FWIW my preferred color would probably be 1 because it's the easiest and least inconsistent with the current state of things. My least favorite would be 3, because although each individual piece of information is only in one place, the path to get there is duplicated; both the kernel developer and the hypervisor developer are forced to continue to deal with both.

The state is that 1-3 have been Nacked by Andrew, 4 has been Nacked by Jan. And 5) (the original way) was way way back Nacked as well.

I believe this conversation is to break a tie-breaker between maintainers. (See http://www.xenproject.org/governance.html, Refereeing).

That is any of the REST maintainers or Project Leads will override the Nack/Acks. Granted, Jan, me, and Andrew are excluded as we are most certainly not neutral. That means Ian, Tim, and Keir.

And then we all can go to the pub.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#33 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Quoted 5 lines · Konrad Rzeszutek Wilk
Quoted 5 lines

3. We could use a new hypercall only for new functionality, with the proposed new semantics. This would at minimum be build-id, but probably also extraversion, compileinfo, changeset, maybe capabilities_info.

Quoted 7 lines
Quoted 5 lines

4. Have the new hypercall replace the old hypercall. The new hypercall will duplicate all the functionality of the old hypercall. Deprecate the hypercall for a release or two, then remove it from the public headers (although keep the code, because we need to maintain backwards compatibility).

5). Stick the build-id in the xsplice sysctl. Or just in the sysctl.

Which is somewhat similar to #3, except that instead of being in its own hypercall, it's with a bunch of other related functionality. I'd be OK with that color too; it's not a great color but I think it's better than 3. :-)

Quoted 4 lines
Quoted 1 line

This does seem to me an awful lot like a bike shed. :-) All of the

This is really past bike shedding - all the bikes shed have been already built (for all those options).

You mean, the shed already has 3 layers of paint, a layer of wallpaper, and a layer of plastic siding? :-)

Quoted 9 lines
Quoted 7 lines

options (1-4) seem perfectly fine to me. FWIW my preferred color would probably be 1 because it's the easiest and least inconsistent with the current state of things. My least favorite would be 3, because although each individual piece of information is only in one place, the path to get there is duplicated; both the kernel developer and the hypervisor developer are forced to continue to deal with both.

Quoted 3 lines

The state is that 1-3 have been Nacked by Andrew, 4 has been Nacked by Jan. And 5) (the original way) was way way back Nacked as well.

There's a difference between "I think this other way is better" and "I am absolutely opposed to this".

Well we know which option Andy prefers, but are there other options that Andy is not absolutely opposed to? And we don't know anything about which option Jan prefers at all, except that it's not #4.

-George

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#34 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Quoted 20 lines · George Dunlap
Quoted 5 lines · Konrad Rzeszutek Wilk
Quoted 5 lines

3. We could use a new hypercall only for new functionality, with the proposed new semantics. This would at minimum be build-id, but probably also extraversion, compileinfo, changeset, maybe capabilities_info.

Quoted 7 lines
Quoted 5 lines

4. Have the new hypercall replace the old hypercall. The new hypercall will duplicate all the functionality of the old hypercall. Deprecate the hypercall for a release or two, then remove it from the public headers (although keep the code, because we need to maintain backwards compatibility).

5). Stick the build-id in the xsplice sysctl. Or just in the sysctl.

Which is somewhat similar to #3, except that instead of being in its own hypercall, it's with a bunch of other related functionality. I'd be OK with that color too; it's not a great color but I think it's better than 3. :-)

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

This does seem to me an awful lot like a bike shed. :-) All of the

This is really past bike shedding - all the bikes shed have been already built (for all those options).

You mean, the shed already has 3 layers of paint, a layer of wallpaper, and a layer of plastic siding? :-)

<laughs>
Yes. Very much so!

Quoted 14 lines
Quoted 10 lines
Quoted 8 lines

options (1-4) seem perfectly fine to me. FWIW my preferred color would probably be 1 because it's the easiest and least inconsistent with the current state of things. My least favorite would be 3, because although each individual piece of information is only in one place, the path to get there is duplicated; both the kernel developer and the hypervisor developer are forced to continue to deal with both.

Quoted 3 lines

The state is that 1-3 have been Nacked by Andrew, 4 has been Nacked by Jan. And 5) (the original way) was way way back Nacked as well.

Quoted 6 lines

There's a difference between "I think this other way is better" and "I am absolutely opposed to this".

Well we know which option Andy prefers, but are there other options that Andy is not absolutely opposed to? And we don't know anything about which option Jan prefers at all, except that it's not #4.

/me nods. Thank you for pointing that out.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#35 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

In reply to George Dunlap
Quoted 9 lines
Quoted 1 line
Quoted 1 line

George Dunlap <[email protected]> 04/12/16 4:38 PM >>>

Quoted 6 lines · Konrad Rzeszutek Wilk

options (1-4) seem perfectly fine to me. FWIW my preferred color would probably be 1 because it's the easiest and least inconsistent with the current state of things. My least favorite would be 3, because although each individual piece of information is only in one place, the path to get there is duplicated; both the kernel developer and the hypervisor developer are forced to continue to deal with both.

Quoted 3 lines

The state is that 1-3 have been Nacked by Andrew, 4 has been Nacked by Jan. And 5) (the original way) was way way back Nacked as well.

No, I only withdrew my ack. Hence an ack from another REST maintainer would suffice for it to stay in as it is now.

Quoted 6 lines

There's a difference between "I think this other way is better" and "I am absolutely opposed to this".

Well we know which option Andy prefers, but are there other options that Andy is not absolutely opposed to? And we don't know anything about which option Jan prefers at all, except that it's not #4.

As said in another reply - a suitable variant of 2.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#36 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

In reply to George Dunlap

George Dunlap writes ("Re: [Xen-devel] REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane."):

Quoted 3 lines

Well we know which option Andy prefers, but are there other options that Andy is not absolutely opposed to? And we don't know anything about which option Jan prefers at all, except that it's not #4.

Let me go a bit further than George.

It's clear that there are various options, most of which are tolerable. Buit if I'm trying to help referee a disagreement between Andrew and Jan I would prefer to be choosing between Andrew's preferred answer and Jan's preferred answer.

Jan: AFAICT it's clear that you would still like the current patch reverted. Can you please say what, if anything, you would like to replace it with ?

Thanks,
Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#37 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Quoted 8 lines
Quoted 1 line
Quoted 1 line

Ian Jackson <[email protected]> 04/12/16 6:47 PM >>>

George Dunlap writes ("Re: [Xen-devel] REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ >but sane."):

Quoted 3 lines

Well we know which option Andy prefers, but are there other options that Andy is not absolutely opposed to? And we don't know anything about which option Jan prefers at all, except that it's not #4.

Let me go a bit further than George.

Quoted 8 lines

It's clear that there are various options, most of which are tolerable. Buit if I'm trying to help referee a disagreement between Andrew and Jan I would prefer to be choosing between Andrew's preferred answer and Jan's preferred answer.

Jan: AFAICT it's clear that you would still like the current patch reverted. Can you please say what, if anything, you would like to replace it with ?

That patch doesn't need replacing by anything. It's the follow-up patch adding support to retrieve the build-id which would need a replacement, and several options have been put on the table. As mentioned before, I'd prefer the variant of the new sub-op getting added to the existing version hypercall, with the needed length argument passed either via a structure element, with the structure pointed to by the 2nd hypercall argument, or with the high bits of the first hypercall argument re-purposed to allow (and for this sub-op require) holding a length. Which of these two sub-options is chosen I don't really care much.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#38 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Jan Beulich writes ("Re: [Xen-devel] REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane."):

Quoted 8 lines

George Dunlap <[email protected]> 04/12/16 11:58 AM >>>

Quoted 5 lines

2. Use the existing hypercall but wedge in different calling semantics for the build-id subop. We could have just that subop pay attention to an extra argument as a length, for example, and return an error if the length is too short. Or we could make essentially a flag that asks, "How much space if I were to execute this subop for real?"

A suitable variant of this is what I've been arguing for.

Earlier I wrote:

It's clear that there are various options, most of which are tolerable. Buit if I'm trying to help referee a disagreement between Andrew and Jan I would prefer to be choosing between Andrew's preferred answer and Jan's preferred answer.

So as I see it we have two options actually seriously proposed:
Andrew's new hypercall, and Jan's additional argument (in the struct, seems to be what Jan is mainly suggesting).

The new hypercall is neater but more new code - and involves a deprecation plan; the additional argument is more messy but less duplication.

I think either of these options is tolerable. I don't see the need to look further.

Frankly, I find the choice difficult. But the bikeshed has to be painted /some/ colour and we should make these decisions in a sensible way and that means I and George (who've been called on to help decide) need to put forward an opinion.

On balance I think I prefer Jan's suggestion, mostly on the grounds that in case of dispute, disagreement, or uncertainty, it is (all other things being equal) better to make smaller changes. And if this hypercall becomes _too_ much of a mess we can always replace it later along the lines that Andrew suggests.

I look forward to hearing from George.

Thanks,
Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#39 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Quoted 33 lines · Ian Jackson

Jan Beulich writes ("Re: [Xen-devel] REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane."):

Quoted 8 lines

George Dunlap <[email protected]> 04/12/16 11:58 AM >>>

Quoted 5 lines

2. Use the existing hypercall but wedge in different calling semantics for the build-id subop. We could have just that subop pay attention to an extra argument as a length, for example, and return an error if the length is too short. Or we could make essentially a flag that asks, "How much space if I were to execute this subop for real?"

A suitable variant of this is what I've been arguing for.

Earlier I wrote:

It's clear that there are various options, most of which are tolerable. Buit if I'm trying to help referee a disagreement between Andrew and Jan I would prefer to be choosing between Andrew's preferred answer and Jan's preferred answer.

So as I see it we have two options actually seriously proposed:
Andrew's new hypercall, and Jan's additional argument (in the struct, seems to be what Jan is mainly suggesting).

The new hypercall is neater but more new code - and involves a deprecation plan; the additional argument is more messy but less duplication.

I think either of these options is tolerable. I don't see the need to look further.

Frankly, I find the choice difficult. But the bikeshed has to be painted /some/ colour and we should make these decisions in a sensible way and that means I and George (who've been called on to help decide) need to put forward an opinion.

Quoted 5 lines

On balance I think I prefer Jan's suggestion, mostly on the grounds that in case of dispute, disagreement, or uncertainty, it is (all other things being equal) better to make smaller changes. And if this hypercall becomes _too_ much of a mess we can always replace it later along the lines that Andrew suggests.

I'm a bit torn here. I think on the whole, I agree with Ian's approach that if there is disagreement, then the more conservative approach should be taken. And if we were discussing an uncommitted patch about which no consensus had been reached, I would second his suggestion.

On the other hand, I think there's a bit of a faulty interpretation of the procedure here. Jan reviewed the patch thoroughly and then acked it; on the basis of that, Konrad legitimately checked it in. After it was checked in Jan said, "I've changed my mind and withdraw my Ack"; and the assumption of the subsequent conversation was that an ack *can* be withdrawn after it has been legitimately checked in, and that if no other Ack is supplied, then it must be reverted.

I don't think that's a correct interpretation of the rules. Reviewers in general, and maintainers in particular, should make reasonably sure that they mean the Ack before they give it; and if they change their mind after it has been legitimately checked in, then it's now up to them to make the change they want to see according to the regular procedure. That is, if Jan wants it reverted, he needs to post a patch reverting it and get Acks from the appropriate maintainers; and the discussion needs to be around Jan's reversion being accepted, not about Konrad's original patch continuing to be accepted. (Obvious exceptions can be made in the case of emergencies like build breakages.)

Normally it's best to try to come to agreement instead of falling back to rule lawyering; and in any case it's always easier to talk about the rules when we're not trying to sort out a specific situation. But since we've failed to reach a genuine agreement, in this case I think the rule lawyering is probably a legitimate way to resolve the issue.

Thoughts?

-George

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#40 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Quoted 9 lines
Quoted 1 line
Quoted 1 line

George Dunlap <[email protected]> 04/14/16 5:16 PM >>>

On the other hand, I think there's a bit of a faulty interpretation of the procedure here. Jan reviewed the patch thoroughly and then acked it; on the basis of that, Konrad legitimately checked it in. After it was checked in Jan said, "I've changed my mind and withdraw my Ack"; and the assumption of the subsequent conversation was that an ack *can* be withdrawn after it has been legitimately checked in, and that if no other Ack is supplied, then it must be reverted.

Quoted 11 lines

I don't think that's a correct interpretation of the rules. Reviewers in general, and maintainers in particular, should make reasonably sure that they mean the Ack before they give it; and if they change their mind after it has been legitimately checked in, then it's now up to them to make the change they want to see according to the regular procedure. That is, if Jan wants it reverted, he needs to post a patch reverting it and get Acks from the appropriate maintainers; and the discussion needs to be around Jan's reversion being accepted, not about Konrad's original patch continuing to be accepted. (Obvious exceptions can be made in the case of emergencies like build breakages.)

Fundamentally I agree, but I think there's more to this than just following a set of rules. For example, please don't forget the time pressure due to the (at that time) rapidly approaching freeze date. And then, mistakes happen, and so I made a mistake here by sending the ack a few hours too early.

What is really hard to understand to me is why it is so difficult to just get a refereeing opinion on the actual interface change. IMO we don't really need to discuss rules and processes, the question is as simple as "Do we want/need this new interface?"

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#41 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Quoted 21 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line

George Dunlap <[email protected]> 04/14/16 5:16 PM >>>

On the other hand, I think there's a bit of a faulty interpretation of the procedure here. Jan reviewed the patch thoroughly and then acked it; on the basis of that, Konrad legitimately checked it in. After it was checked in Jan said, "I've changed my mind and withdraw my Ack"; and the assumption of the subsequent conversation was that an ack *can* be withdrawn after it has been legitimately checked in, and that if no other Ack is supplied, then it must be reverted.

Quoted 11 lines

I don't think that's a correct interpretation of the rules. Reviewers in general, and maintainers in particular, should make reasonably sure that they mean the Ack before they give it; and if they change their mind after it has been legitimately checked in, then it's now up to them to make the change they want to see according to the regular procedure. That is, if Jan wants it reverted, he needs to post a patch reverting it and get Acks from the appropriate maintainers; and the discussion needs to be around Jan's reversion being accepted, not about Konrad's original patch continuing to be accepted. (Obvious exceptions can be made in the case of emergencies like build breakages.)

Quoted 5 lines

Fundamentally I agree, but I think there's more to this than just following a set of rules. For example, please don't forget the time pressure due to the (at that time) rapidly approaching freeze date. And then, mistakes happen, and so I made a mistake here by sending the ack a few hours too early.

Sure, mistakes happen; but I hope it's not being to controversial to say that in general, the procedure should be arranged such that the person who makes the mistake is the one who has to do deal with the most consequences from the mistake, not the people around him. I mean, if you asked a bartender for a bottle of beer, and after he'd already opened it you said, "Oh sorry, I actually wanted a cider", it would be fair enough for the bartender to ask you to pay for the beer, rather than eating it*, wouldn't it? :-)

Quoted 4 lines

What is really hard to understand to me is why it is so difficult to just get a refereeing opinion on the actual interface change. IMO we don't really need to discuss rules and processes, the question is as simple as "Do we want/need this new interface?"

Well Ian and I have already given our opinions -- Ian thinks moving to a clean interface and deprecating the old one is in general a good thing, and doesn't look too painful in this case. I don't really see a problem with using a large fixed size, but I don't fundamentally see a problem with moving to a new clean interface either. Given that Andy has a strong aversion to the way things are, if you had only a mild distaste rather than a strong objection to the new hypercall, it would probably make sense to go with the new hypercall.

If you do have a strong objection, then maybe we could try to convince Andy to accept adding subops with different calling semantics to the existing hypercall. But I would still think the burden of persuasion is primarily on you.

-George

* In this context "eating" something means just accepting the loss of the thing yourself. For instance, if you bought two tickets to a concert but couldn't convince anyone to go with you, you'd say you had to "eat the other ticket". Here it means the bartender throws the beer away and accepts the loss himself.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#42 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Quoted 29 lines
Quoted 1 line
Quoted 1 line

George Dunlap <[email protected]> 04/14/16 6:20 PM >>>

Quoted 21 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line

George Dunlap <[email protected]> 04/14/16 5:16 PM >>>

On the other hand, I think there's a bit of a faulty interpretation of the procedure here. Jan reviewed the patch thoroughly and then acked it; on the basis of that, Konrad legitimately checked it in. After it was checked in Jan said, "I've changed my mind and withdraw my Ack"; and the assumption of the subsequent conversation was that an ack *can* be withdrawn after it has been legitimately checked in, and that if no other Ack is supplied, then it must be reverted.

Quoted 11 lines

I don't think that's a correct interpretation of the rules. Reviewers in general, and maintainers in particular, should make reasonably sure that they mean the Ack before they give it; and if they change their mind after it has been legitimately checked in, then it's now up to them to make the change they want to see according to the regular procedure. That is, if Jan wants it reverted, he needs to post a patch reverting it and get Acks from the appropriate maintainers; and the discussion needs to be around Jan's reversion being accepted, not about Konrad's original patch continuing to be accepted. (Obvious exceptions can be made in the case of emergencies like build breakages.)

Quoted 5 lines

Fundamentally I agree, but I think there's more to this than just following a set of rules. For example, please don't forget the time pressure due to the (at that time) rapidly approaching freeze date. And then, mistakes happen, and so I made a mistake here by sending the ack a few hours too early.

Quoted 8 lines

Sure, mistakes happen; but I hope it's not being to controversial to say that in general, the procedure should be arranged such that the person who makes the mistake is the one who has to do deal with the most consequences from the mistake, not the people around him. I mean, if you asked a bartender for a bottle of beer, and after he'd already opened it you said, "Oh sorry, I actually wanted a cider", it would be fair enough for the bartender to ask you to pay for the beer, rather than eating it*, wouldn't it? :-)

Sure. And I think that's what I've done. I suggested to revert the thing, collecting opinions either direction. I just didn't post a revert patch, as I think that makes little sense - a revert is a mechanical operation, which doesn't need people looking at the actual patch.

Quoted 9 lines

Well Ian and I have already given our opinions -- Ian thinks moving to a clean interface and deprecating the old one is in general a good thing, and doesn't look too painful in this case. I don't really see a problem with using a large fixed size, but I don't fundamentally see a problem with moving to a new clean interface either. Given that Andy has a strong aversion to the way things are, if you had only a mild distaste rather than a strong objection to the new hypercall, it would probably make sense to go with the new hypercall.

Quoted 4 lines

If you do have a strong objection, then maybe we could try to convince Andy to accept adding subops with different calling semantics to the existing hypercall. But I would still think the burden of persuasion is primarily on you.

I do not have a strong objection, or else I would have converted my ack
into a nak instead of just withdrawing it. I just dislike the duplication, and hence I'm not happy with me now being the one having approved it to go in. Hence the request for a replacement ack (or whatever else referee decision).

And btw., considering that Konrad has already posted a revert patch, and I have ack-ed that one, this could now go in right away (and the discussion could either be settled or start over).

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#43 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Quoted 9 lines · Jan Beulich
Quoted 8 lines

Sure, mistakes happen; but I hope it's not being to controversial to say that in general, the procedure should be arranged such that the person who makes the mistake is the one who has to do deal with the most consequences from the mistake, not the people around him. I mean, if you asked a bartender for a bottle of beer, and after he'd already opened it you said, "Oh sorry, I actually wanted a cider", it would be fair enough for the bartender to ask you to pay for the beer, rather than eating it*, wouldn't it? :-)

Quoted 4 lines

Sure. And I think that's what I've done. I suggested to revert the thing, collecting opinions either direction. I just didn't post a revert patch, as I think that makes little sense - a revert is a mechanical operation, which doesn't need people looking at the actual patch.

You don't need people to review the content of the actual patch, but it provides a standardized way to have a discussion about the patch, and it makes it clear what the procedure is for having it applied. You don't need any technical code review for adding or removing maintainers either, but we ask people to send patches to the MAINTAINERS file anyway, because it provides a structured way to have an open discussion and make a decision.

When Konrad asked for further input on the patch and then didn't get any in a few days, you responded, "It looks like it will have to be reverted then." As I've said, I think that's the wrong way round -- it's not that the commit is reverted unless someone else acks it; it's that the commit stays unless someone acks your reversion. If you had posted a patch (probably RFC) requesting to revert the change in favor of a different one, then it would have been more obvious that the burden was on you to get the reversion Acked, rather than on Konrad to get the existing commit re-acked.

Quoted 14 lines
Quoted 9 lines

Well Ian and I have already given our opinions -- Ian thinks moving to a clean interface and deprecating the old one is in general a good thing, and doesn't look too painful in this case. I don't really see a problem with using a large fixed size, but I don't fundamentally see a problem with moving to a new clean interface either. Given that Andy has a strong aversion to the way things are, if you had only a mild distaste rather than a strong objection to the new hypercall, it would probably make sense to go with the new hypercall.

Quoted 4 lines

If you do have a strong objection, then maybe we could try to convince Andy to accept adding subops with different calling semantics to the existing hypercall. But I would still think the burden of persuasion is primarily on you.

Quoted 5 lines

I do not have a strong objection, or else I would have converted my ack
into a nak instead of just withdrawing it. I just dislike the duplication, and hence I'm not happy with me now being the one having approved it to go in. Hence the request for a replacement ack (or whatever else referee decision).

Well this makes it sound like you're saying that you were asking us to save you from having to appear to have approved of a patch that you didn't like. Which doesn't sound very nice. :-)

But I wonder if something slightly different is going on. Forgive me for trying to guess at motivations here, but I think it may be helpful. I'm often in the situation where my gut objects to a patch that other coders I respect think is fine; and often a few years down the road, I look back and agree that it's fine as well. In other words, I know that sometimes my own objections turn out to be unreasonable; and that in any case, working with other people you sometimes have to compromise. But on the other hand, I've also had the experience of giving in and accepting patches that later I regret, or that other people come back and say, "This was a terrible idea, you should have stood up for it more."

So in the moment -- particularly, as you say, under time pressure -- how do you determine if objecting to the patch is being unreasonable and obstructive, or if assenting to the patch is failing your duty as a maintainer to prevent bad code, and is a decision you'll regret later?

Was it perhaps actually the case that your internal reasoning was along the lines of, "Actually, adding a new hypercall seems like a bad idea. But since Andrew strongly disagrees, maybe I'm being unreasonable. Or, maybe it really is a bad idea and he's being unreasonable. Why don't I ask the REST maintainers to look at it; if they Ack it, then I'm probably being too conservative; if they don't, then I'm probably justified in objecting to it"?

If so, we should probably find a better way for maintainers to ask for additional feedback in those situations. :-) I'd certainly appreciate that at times.

If that's not the case, and you genuinely only have a mild dislike for the hypercall, then there are a couple of things to say about that. The first is that given the circumstances, it seems to me that giving the Ack was not only reasonable, but the right thing to do. An Ack doesn't mean, "I think this is a good idea", but it means "Given all considerations, I think this should be in the tree." And given that Andrew had strong objections to the other solutions, and you only had a distaste for this one, this is obviously the solution to choose. Acking a patch on the basis that you don't really like it but it's the best compromise with the other maintainers is perfectly reasonable.

Secondly, I can certainly see that you might be a bit embarrased about having your name on a patch you dislike, but... well, you did in fact approve it going in. :-) Maybe that was because you were in haste, and you regret it, but that's an accurate record of what happened. Stand up and take responsibility for your actions. :-)

Quoted 3 lines

And btw., considering that Konrad has already posted a revert patch, and I have ack-ed that one, this could now go in right away (and the discussion could either be settled or start over).

Yes, unless someone objects to that patch then we have a clear way forward, and we're just discussing principles for future reference at this point.

-George

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#44 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Quoted 11 lines
Quoted 1 line
Quoted 1 line

George Dunlap <[email protected]> 04/15/16 1:23 PM >>>

Quoted 9 lines · Jan Beulich
Quoted 8 lines

Sure, mistakes happen; but I hope it's not being to controversial to say that in general, the procedure should be arranged such that the person who makes the mistake is the one who has to do deal with the most consequences from the mistake, not the people around him. I mean, if you asked a bartender for a bottle of beer, and after he'd already opened it you said, "Oh sorry, I actually wanted a cider", it would be fair enough for the bartender to ask you to pay for the beer, rather than eating it*, wouldn't it? :-)

Quoted 1 line
Quoted 1 line

Sure. And I think that's what I've done.

To be fair, I think this was too broad a statement: I had indeed asked Konrad to collect the replacement ack. Yet on second thought I really can't see what's wrong with withdraing an ack - just like a patch can be withdrawn, that should be possible for an ack too. And if the patch has already gone in, no matter whether the patch itself or the ack got withdrawn, the patch imo should then be reverted. I agree that's not something spelled out anywhere, so my opinion here is based on solely general considerations of mine.

Quoted 9 lines

When Konrad asked for further input on the patch and then didn't get any in a few days, you responded, "It looks like it will have to be reverted then." As I've said, I think that's the wrong way round -- it's not that the commit is reverted unless someone else acks it; it's that the commit stays unless someone acks your reversion. If you had posted a patch (probably RFC) requesting to revert the change in favor of a different one, then it would have been more obvious that the burden was on you to get the reversion Acked, rather than on Konrad to get the existing commit re-acked.

I agree on the process aspect (albeit among the few cases where things needed reverting, I think there was a non-negligible amount of such where the revert was requested quite informally), but that's relatively moot with me not agreeing on the premises it builds upon.

Quoted 20 lines
Quoted 14 lines
Quoted 9 lines

Well Ian and I have already given our opinions -- Ian thinks moving to a clean interface and deprecating the old one is in general a good thing, and doesn't look too painful in this case. I don't really see a problem with using a large fixed size, but I don't fundamentally see a problem with moving to a new clean interface either. Given that Andy has a strong aversion to the way things are, if you had only a mild distaste rather than a strong objection to the new hypercall, it would probably make sense to go with the new hypercall.

Quoted 4 lines

If you do have a strong objection, then maybe we could try to convince Andy to accept adding subops with different calling semantics to the existing hypercall. But I would still think the burden of persuasion is primarily on you.

Quoted 5 lines

I do not have a strong objection, or else I would have converted my ack
into a nak instead of just withdrawing it. I just dislike the duplication, and hence I'm not happy with me now being the one having approved it to go in. Hence the request for a replacement ack (or whatever else referee decision).

Quoted 3 lines

Well this makes it sound like you're saying that you were asking us to save you from having to appear to have approved of a patch that you didn't like. Which doesn't sound very nice. :-)

I'm sorry if it's being understood that way. My intention really was to avoid the revert in case a replacement ack can be obtained. Otherwise, following my way of thinking outlined above, the patch should have been reverted right away. Yet I seem to be the only one here thinking this way...

Quoted 18 lines

But I wonder if something slightly different is going on. Forgive me for trying to guess at motivations here, but I think it may be helpful. I'm often in the situation where my gut objects to a patch that other coders I respect think is fine; and often a few years down the road, I look back and agree that it's fine as well. In other words, I know that sometimes my own objections turn out to be unreasonable; and that in any case, working with other people you sometimes have to compromise. But on the other hand, I've also had the experience of giving in and accepting patches that later I regret, or that other people come back and say, "This was a terrible idea, you should have stood up for it more."

So in the moment -- particularly, as you say, under time pressure -- how do you determine if objecting to the patch is being unreasonable and obstructive, or if assenting to the patch is failing your duty as a maintainer to prevent bad code, and is a decision you'll regret later?

Quoted 7 lines

Was it perhaps actually the case that your internal reasoning was along the lines of, "Actually, adding a new hypercall seems like a bad idea. But since Andrew strongly disagrees, maybe I'm being unreasonable. Or, maybe it really is a bad idea and he's being unreasonable. Why don't I ask the REST maintainers to look at it; if they Ack it, then I'm probably being too conservative; if they don't, then I'm probably justified in objecting to it"?

Well, not really. My main problem here (and not just here) is that often I end up reviewing patches for being done correctly, but ignore the question of "Do we need this in the first place?" This has happened to me more often earlier on, but it continues to happen from time to time, like on this occasion.

Quoted 3 lines

If so, we should probably find a better way for maintainers to ask for additional feedback in those situations. :-) I'd certainly appreciate that at times.

Well, the main problem I'm seeing here that the current set of REST maintainers makes it very hard to get _any_ kind of feedback without explicitly asking and pinging for it. I sincerely hope that this will change with the pending committership and maintainership adjustments. My general understanding here is that it shouldn't be really necessary to explicitly ask for a second opinion - after all maintainers get Cc-ed on patches for the reason of seeking their input. And the question of replacing an existing public interface with a slightly different new one, even more so with no obvious route of deprecating the old one, is something that any one of the REST maintainers should really have an opinion on imo.

Quoted 10 lines

If that's not the case, and you genuinely only have a mild dislike for the hypercall, then there are a couple of things to say about that. The first is that given the circumstances, it seems to me that giving the Ack was not only reasonable, but the right thing to do. An Ack doesn't mean, "I think this is a good idea", but it means "Given all considerations, I think this should be in the tree." And given that Andrew had strong objections to the other solutions, and you only had a distaste for this one, this is obviously the solution to choose. Acking a patch on the basis that you don't really like it but it's the best compromise with the other maintainers is perfectly reasonable.

Taking a strictly formal perspective, there was no disagreement between maintainers, since I've been the only one of those currently named under REST involved in the discussion. Which is part of the problem, as said above. And Andrew's strong objection was, in my view, based on not very convincing arguments. Hence I couldn't really see myself making a reasonable compromise here.

Quoted 5 lines

Secondly, I can certainly see that you might be a bit embarrased about having your name on a patch you dislike, but... well, you did in fact approve it going in. :-) Maybe that was because you were in haste, and you regret it, but that's an accurate record of what happened. Stand up and take responsibility for your actions. :-)

Which is why - see above - I didn't revert it right away.

Quoted 7 lines
Quoted 3 lines

And btw., considering that Konrad has already posted a revert patch, and I have ack-ed that one, this could now go in right away (and the discussion could either be settled or start over).

Yes, unless someone objects to that patch then we have a clear way forward, and we're just discussing principles for future reference at this point.

Agreed. As said in reply to Ian - perhaps worth taking some time at the hackathon.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#45 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane. [and 1 more messages]

In reply to George Dunlap

George Dunlap writes ("Re: [Xen-devel] REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane."):

Quoted 8 lines

On the other hand, I think there's a bit of a faulty interpretation of the procedure here. Jan reviewed the patch thoroughly and then acked it; on the basis of that, Konrad legitimately checked it in. After it was checked in Jan said, "I've changed my mind and withdraw my Ack"; and the assumption of the subsequent conversation was that an ack *can* be withdrawn after it has been legitimately checked in, and that if no other Ack is supplied, then it must be reverted.

Quoted 6 lines

I don't think that's a correct interpretation of the rules. Reviewers in general, and maintainers in particular, should make reasonably sure that they mean the Ack before they give it; and if they change their mind after it has been legitimately checked in, then it's now up to them to make the change they want to see according to the regular procedure.

For the record, I agree completely with George here. I was expecting that the next step would be to for Jan to post patches to revert the extra hypercall and replace it with something else.

Jan Beulich writes ("Re: [Xen-devel] REST MAINTAINERS feedback requested Was:

Quoted 3 lines

And btw., considering that Konrad has already posted a revert patch, and I have ack-ed that one, this could now go in right away (and the discussion could either be settled or start over).

I don't see that patch you describe in my inbox, but maybe I have missed it.

If that reversion is proposed, following a request for a 2nd/3rd opinion from me and George, and given the discussion so far, I think that patch ought to have been CC'd to me and George.

I don't think it would be appropriate to commit a revert except as part of a series which introduces an replacement way of providing the needed functionality - at least, enough functionality that in practice a plausibly long build-id can be retrieved.

If you want the original reverted, I think it is up to you, Jan, to provide (or procure) such a replacement.

Thanks,
Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#46 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane. [and 1 more messages]

Quoted 20 lines · Ian Jackson

George Dunlap writes ("Re: [Xen-devel] REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane."):

Quoted 8 lines

On the other hand, I think there's a bit of a faulty interpretation of the procedure here. Jan reviewed the patch thoroughly and then acked it; on the basis of that, Konrad legitimately checked it in. After it was checked in Jan said, "I've changed my mind and withdraw my Ack"; and the assumption of the subsequent conversation was that an ack *can* be withdrawn after it has been legitimately checked in, and that if no other Ack is supplied, then it must be reverted.

Quoted 6 lines

I don't think that's a correct interpretation of the rules. Reviewers in general, and maintainers in particular, should make reasonably sure that they mean the Ack before they give it; and if they change their mind after it has been legitimately checked in, then it's now up to them to make the change they want to see according to the regular procedure.

For the record, I agree completely with George here. I was expecting that the next step would be to for Jan to post patches to revert the extra hypercall and replace it with something else.

Quoted 7 lines

Jan Beulich writes ("Re: [Xen-devel] REST MAINTAINERS feedback requested Was:

Quoted 3 lines

And btw., considering that Konrad has already posted a revert patch, and I have ack-ed that one, this could now go in right away (and the discussion could either be settled or start over).

I don't see that patch you describe in my inbox, but maybe I have missed it.

It is part of my series. This is the revert (there are two of them)

http://lists.xen.org/archives/html/xen-devel/2016-04/msg01913.html
http://lists.xen.org/archives/html/xen-devel/2016-04/msg01926.html

And then these two patches add build-id using the XENVER hypercall:

http://lists.xen.org/archives/html/xen-devel/2016-04/msg01923.html
http://lists.xen.org/archives/html/xen-devel/2016-04/msg01902.html

Quoted 4 lines

If that reversion is proposed, following a request for a 2nd/3rd opinion from me and George, and given the discussion so far, I think that patch ought to have been CC'd to me and George.

Argh, I probably missed you and George on them. My apologies!

Quoted 11 lines

I don't think it would be appropriate to commit a revert except as part of a series which introduces an replacement way of providing the needed functionality - at least, enough functionality that in practice a plausibly long build-id can be retrieved.

If you want the original reverted, I think it is up to you, Jan, to provide (or procure) such a replacement.

Thanks,
Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#47 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane. [and 1 more messages]

In reply to Ian Jackson
Quoted 8 lines
Quoted 1 line
Quoted 1 line

Ian Jackson <[email protected]> 04/14/16 8:12 PM >>>

Jan Beulich writes ("Re: [Xen-devel] REST MAINTAINERS feedback requested Was:

Quoted 3 lines

And btw., considering that Konrad has already posted a revert patch, and I have ack-ed that one, this could now go in right away (and the discussion could either be settled or start over).

I don't see that patch you describe in my inbox, but maybe I have missed it.

Patches 1 and 2 of the most recent v8.1 series.

Quoted 8 lines

If that reversion is proposed, following a request for a 2nd/3rd opinion from me and George, and given the discussion so far, I think that patch ought to have been CC'd to me and George.

I don't think it would be appropriate to commit a revert except as part of a series which introduces an replacement way of providing the needed functionality - at least, enough functionality that in practice a plausibly long build-id can be retrieved.

For one, the revert wouldn't revert that functionality, as that didn't even go in yet.

Quoted 2 lines

If you want the original reverted, I think it is up to you, Jan, to provide (or procure) such a replacement.

And with that (albeit not just because of it not being in yet at all), I don't see why this would be the case. I think there's some general disagreement here, which with the hackathon around the corner we probably should just get sorted out in person there.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#48 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

In reply to George Dunlap
Quoted 7 lines
Quoted 1 line
Quoted 1 line

George Dunlap <[email protected]> 04/12/16 11:58 AM >>>

Quoted 5 lines · Jan Beulich
Quoted 4 lines

ISTM that the lower duplication (which in principle is an advantage which will be time limited if we are ever able to completely remove teh old hypercall) comes with the cost of (in the long term) increased mess in this particular subop.

Quoted 8 lines
Quoted 3 lines

We cannot, ever, remove a not toolstack limited hypercall completely (or if, then only by Kconfig option so that people knowing none of the guests they care about use such deprecated ones).

We need to keep the hypercall around and functioning for ABI compatibility, but we could at least remove it from the public headers and point people to using the new one instead. (Discussion about the merit of this idea below.)

Please don't forget that guests use this to be deprecated hypercall as one of the cheapest possible ways to call into the hypervisor just to get events delivered. I'm afraid the new hypercall would mean (slightly) more overhead. In fact I'm afraid the addition of the XSM call to the old one already had some of this effect namely when XSM is enabled: Konrad - was this considered when you added that?

Quoted 5 lines

OK, so here are the options I see:

1. Use the existing hypercall with the existing call semantics for build-id -- i.e., require the caller to have a large but fixed-length buffer (maybe 1024 or 2048).

I think it was explained even on this thread that a fixed size may indeed not be suitable here.

Quoted 5 lines

2. Use the existing hypercall but wedge in different calling semantics for the build-id subop. We could have just that subop pay attention to an extra argument as a length, for example, and return an error if the length is too short. Or we could make essentially a flag that asks, "How much space if I were to execute this subop for real?"

A suitable variant of this is what I've been arguing for.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#49 lore raw

Re: REST MAINTAINERS feedback requested Was:Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Quoted 16 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line

George Dunlap <[email protected]> 04/12/16 11:58 AM >>>

Quoted 5 lines · Jan Beulich
Quoted 4 lines

ISTM that the lower duplication (which in principle is an advantage which will be time limited if we are ever able to completely remove teh old hypercall) comes with the cost of (in the long term) increased mess in this particular subop.

Quoted 8 lines
Quoted 3 lines

We cannot, ever, remove a not toolstack limited hypercall completely (or if, then only by Kconfig option so that people knowing none of the guests they care about use such deprecated ones).

We need to keep the hypercall around and functioning for ABI compatibility, but we could at least remove it from the public headers and point people to using the new one instead. (Discussion about the merit of this idea below.)

Quoted 6 lines

Please don't forget that guests use this to be deprecated hypercall as one of the cheapest possible ways to call into the hypervisor just to get events delivered. I'm afraid the new hypercall would mean (slightly) more overhead. In fact I'm afraid the addition of the XSM call to the old one already had some of this effect namely when XSM is enabled: Konrad - was this considered when you added that?

Yes, and I raised it up as well :-)

However, now that we dropped the XSM checks for some of the sub-ops, it is pointless to do the XSM checks for them (they just do function functions calls that end up with return 0).

I can most certainly add back the mask of flags - so only specific sub-ops go through the XSM check. Let me write a patch for this and send it out for review shortly.

Quoted 16 lines
Quoted 6 lines

OK, so here are the options I see:

1. Use the existing hypercall with the existing call semantics for build-id -- i.e., require the caller to have a large but fixed-length buffer (maybe 1024 or 2048).

I think it was explained even on this thread that a fixed size may indeed not be suitable here.

Quoted 5 lines

2. Use the existing hypercall but wedge in different calling semantics for the build-id subop. We could have just that subop pay attention to an extra argument as a length, for example, and return an error if the length is too short. Or we could make essentially a flag that asks, "How much space if I were to execute this subop for real?"

Quoted 4 lines

A suitable variant of this is what I've been arguing for.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#50 lore raw

Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

In reply to Jan Beulich
Quoted 11 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 30.03.16 at 17:43, <[email protected]> wrote:

Since they're all cosmetic, if you take care of all of them, feel free to stick my ack on the result.

Actually - no, please don't. While the patch is fine content wise then from my perspective, I'm still lacking a convincing argument of why this new hypercall is needed in the first place. If others are convinced by the argumentation between (mostly, iirc) you and Andrew, I'm not going to stand in the way, but I'm also not going to approve of the code addition without being myself convinced.

I don't see in this patch a justification for why Konrad (and/or Andrew) think the new version is needed, nor do I see in this particular thread why Jan thinks it's not necessary, so I don't really know what's going on. I'm happy to give my opinion of someone wants to catch me up.

-George

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#51 lore raw

Re: [PATCH v5 01/28] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.

Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 08.04.16 at 19:24, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 30.03.16 at 17:43, <[email protected]> wrote:

Since they're all cosmetic, if you take care of all of them, feel free to stick my ack on the result.

Actually - no, please don't. While the patch is fine content wise then from my perspective, I'm still lacking a convincing argument of why this new hypercall is needed in the first place. If others are convinced by the argumentation between (mostly, iirc) you and Andrew, I'm not going to stand in the way, but I'm also not going to approve of the code addition without being myself convinced.

Quoted 5 lines

I don't see in this patch a justification for why Konrad (and/or Andrew) think the new version is needed, nor do I see in this particular thread why Jan thinks it's not necessary, so I don't really know what's going on. I'm happy to give my opinion of someone wants to catch me up.

Well, the hypercall is redundant with an existing one, and the semantics needed for adding the build-id sub-op don't really require this new hypercall either. So it not adding new functionality, I think it simply needs to be demonstrated that the new variant is needed, not that it's not needed.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#52 lore raw

PATCH v5 2/28 libxc/libxl/python/xenstat/ocaml: Use new XEN_VERSION hypercall

In reply to Konrad Rzeszutek Wilk

We change the xen_version libxc code to use the new hypercall. Which of course means every user in the code base has to be changed over.

It is important to note that the xc_version_op has a different return semantic than the previous one. It returns negative values on error (like the old one), but it also returns an positive value on success (unlike the old one). The positive value is the number of bytes copied in.

Note that both Ocaml and xenstat use tabs instead of four spaces so they look quite odd.

---
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: David Scott <[email protected]>
Cc: George Dunlap <[email protected]>

v4: New patch.
- Use xc_version_op_val_t instead of uint32 or such
- Make sure to check ret < 0 instead of ret (as it returns the size) - in Ocaml code. Found by Andrew.
- Update comment for xc_version to mention the return the size
v5: Wei's review, s/VERSION_OP/VERSION/

---
 tools/libxc/include/xenctrl.h          | 32 +++++++++++++-
 tools/libxc/xc_core.c                  | 35 +++++++--------
 tools/libxc/xc_dom_boot.c              | 12 +++++-
 tools/libxc/xc_domain.c                |  3 +-
 tools/libxc/xc_private.c               | 53 ++++-------------------
 tools/libxc/xc_private.h               |  7 +--
 tools/libxc/xc_resume.c                |  3 +-
 tools/libxc/xc_sr_save.c               |  9 ++--
 tools/libxc/xg_save_restore.h          |  6 ++-
 tools/libxl/libxl.c                    | 79 ++++++++++++++++++++++------------
 tools/ocaml/libs/xc/xenctrl_stubs.c    | 39 +++++++----------
 tools/python/xen/lowlevel/xc/xc.c      | 30 +++++++------
 tools/xenstat/libxenstat/src/xenstat.c | 12 +++---
 tools/xentrace/xenctx.c                |  3 +-
 14 files changed, 177 insertions(+), 146 deletions(-)
tools/libxc/include/xenctrl.h +31 -1
index 150d727..a9e4dc1 100644
@@ -1477,7 +1477,37 @@ int xc_tbuf_set_evt_mask(xc_interface *xch, uint32_t mask);
 int xc_domctl(xc_interface *xch, struct xen_domctl *domctl);
 int xc_sysctl(xc_interface *xch, struct xen_sysctl *sysctl);
 
-int xc_version(xc_interface *xch, int cmd, void *arg);
+/**
+ * This function returns the size of buffer to be allocated for
+ * the cmd. The cmd are XEN_VERSION_*.
+ */
+ssize_t xc_version_len(xc_interface *xch, unsigned int cmd);
+
+/**
+ * This function retrieves the information from the version_op hypercall.
+ * The len is the size of the arg buffer. If arg is NULL, will not
+ * perform hypercall - instead will just return the size of arg
+ * buffer that is needed.
+ *
+ * Note that prior to Xen 4.7 this would return 0 for success and
+ * negative value (-1) for error (with the error in errno). In Xen 4.7
+ * and later for success it will return an positive value which is the
+ * number of bytes copied in arg.
+ *
+ * It can also return -1 with various errno values:
+ *  - EPERM - not permitted.
+ *  - ENOBUFS - the len was to short, output in arg truncated.
+ *  - ENOSYS - not implemented.
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm cmd XEN_VERSION_* value
+ * @param arg Pointer to xen_version_op_buf_t or xen_version_op_val_t
+ * @param len Size of arg
+ * @return size of bytes copied in arg on success, -1 on failure (and
+ * errno will contain the error)
+ *
+ */
+int xc_version(xc_interface *xch, unsigned int cmd, void *arg, size_t len);
 
 int xc_flask_op(xc_interface *xch, xen_flask_op_t *op);
 
tools/libxc/xc_core.c +18 -17
index d792566..cfeba6b 100644
@@ -270,42 +270,43 @@ elfnote_fill_xen_version(xc_interface *xch,
                          *xen_version)
 {
     int rc;
+    xen_version_op_val_t val = 0;
     memset(xen_version, 0, sizeof(*xen_version));
 
-    rc = xc_version(xch, XENVER_version, NULL);
+    rc = xc_version(xch, XEN_VERSION_version, &val, sizeof(val));
     if ( rc < 0 )
         return rc;
-    xen_version->major_version = rc >> 16;
-    xen_version->minor_version = rc & ((1 << 16) - 1);
+    xen_version->major_version = val >> 16;
+    xen_version->minor_version = val & ((1 << 16) - 1);
 
-    rc = xc_version(xch, XENVER_extraversion,
-                    &xen_version->extra_version);
+    rc = xc_version(xch, XEN_VERSION_extraversion,
+                    xen_version->extra_version,
+                    sizeof(xen_version->extra_version));
     if ( rc < 0 )
         return rc;
 
-    rc = xc_version(xch, XENVER_compile_info,
-                    &xen_version->compile_info);
+    rc = xc_version(xch, XEN_VERSION_capabilities,
+                    xen_version->capabilities,
+                    sizeof(xen_version->capabilities));
     if ( rc < 0 )
         return rc;
 
-    rc = xc_version(xch,
-                    XENVER_capabilities, &xen_version->capabilities);
+    rc = xc_version(xch, XEN_VERSION_changeset, xen_version->changeset,
+                    sizeof(xen_version->changeset));
     if ( rc < 0 )
         return rc;
 
-    rc = xc_version(xch, XENVER_changeset, &xen_version->changeset);
+    rc = xc_version(xch, XEN_VERSION_platform_parameters,
+                    &xen_version->platform_parameters,
+                    sizeof(xen_version->platform_parameters));
     if ( rc < 0 )
         return rc;
 
-    rc = xc_version(xch, XENVER_platform_parameters,
-                    &xen_version->platform_parameters);
+    val = 0;
+    rc = xc_version(xch, XEN_VERSION_pagesize, &val, sizeof(val));
     if ( rc < 0 )
         return rc;
-
-    rc = xc_version(xch, XENVER_pagesize, NULL);
-    if ( rc < 0 )
-        return rc;
-    xen_version->pagesize = rc;
+    xen_version->pagesize = val;
 
     return 0;
 }
tools/libxc/xc_dom_boot.c +10 -2
index 791041b..bbff72e 100644
@@ -112,11 +112,19 @@ int xc_dom_compat_check(struct xc_dom_image *dom)
 
 int xc_dom_boot_xen_init(struct xc_dom_image *dom, xc_interface *xch, domid_t domid)
 {
+    xen_version_op_val_t val = 0;
+
+    if ( xc_version(xch, XEN_VERSION_version, &val, sizeof(val)) < 0 )
+    {
+        xc_dom_panic(xch, XC_INTERNAL_ERROR, "can't get Xen version!");
+        return -1;
+    }
+    dom->xen_version = val;
     dom->xch = xch;
     dom->guest_domid = domid;
 
-    dom->xen_version = xc_version(xch, XENVER_version, NULL);
-    if ( xc_version(xch, XENVER_capabilities, &dom->xen_caps) < 0 )
+    if ( xc_version(xch, XEN_VERSION_capabilities, dom->xen_caps,
+                    sizeof(dom->xen_caps)) < 0 )
     {
         xc_dom_panic(xch, XC_INTERNAL_ERROR, "can't get xen capabilities");
         return -1;
tools/libxc/xc_domain.c +2 -1
index 050216e..9ebd1d6 100644
@@ -2084,7 +2084,8 @@ int xc_map_domain_meminfo(xc_interface *xch, int domid,
     _di.guest_width = minfo->guest_width;
 
     /* Get page table levels (see get_platform_info() in xg_save_restore.h */
-    if ( xc_version(xch, XENVER_capabilities, &xen_caps) )
+    if ( xc_version(xch, XEN_VERSION_capabilities, xen_caps,
+                    sizeof(xen_caps)) < 0 )
     {
         PERROR("Could not get Xen capabilities (for page table levels)");
         return -1;
tools/libxc/xc_private.c +9 -44

67 lines not on this page · raw message

tools/libxc/xc_private.h +4 -3
index aa8daf1..5be8fdd 100644
@@ -214,11 +214,12 @@ void xc__hypercall_buffer_cache_release(xc_interface *xch);
  * Hypercall interfaces.
  */
 
-static inline int do_xen_version(xc_interface *xch, int cmd, xc_hypercall_buffer_t *dest)
+static inline long do_version_op(xc_interface *xch, int cmd,
+                                 xc_hypercall_buffer_t *dest, ssize_t len)
 {
     DECLARE_HYPERCALL_BUFFER_ARGUMENT(dest);
-    return xencall2(xch->xcall, __HYPERVISOR_xen_version,
-                    cmd, HYPERCALL_BUFFER_AS_ARG(dest));
+    return xencall3(xch->xcall, __HYPERVISOR_version_op,
+                    cmd, HYPERCALL_BUFFER_AS_ARG(dest), len);
 }
 
 static inline int do_physdev_op(xc_interface *xch, int cmd, void *op, size_t len)
tools/libxc/xc_resume.c +2 -1
index e692b81..5bf4cf0 100644
@@ -56,7 +56,8 @@ static int modify_returncode(xc_interface *xch, uint32_t domid)
             return 0;
 
         /* HVM guests have host address width. */
-        if ( xc_version(xch, XENVER_capabilities, &caps) != 0 )
+        if ( xc_version(xch, XEN_VERSION_capabilities, caps,
+                        sizeof(caps)) < 0 )
         {
             PERROR("Could not get Xen capabilities");
             return -1;
tools/libxc/xc_sr_save.c +5 -4
index 388ae7f..7f1818c 100644
@@ -9,7 +9,7 @@
 static int write_headers(struct xc_sr_context *ctx, uint16_t guest_type)
 {
     xc_interface *xch = ctx->xch;
-    int32_t xen_version = xc_version(xch, XENVER_version, NULL);
+    xen_version_op_val_t xen_version;
     struct xc_sr_ihdr ihdr =
         {
             .marker  = IHDR_MARKER,
@@ -21,15 +21,16 @@ static int write_headers(struct xc_sr_context *ctx, uint16_t guest_type)
         {
             .type       = guest_type,
             .page_shift = XC_PAGE_SHIFT,
-            .xen_major  = (xen_version >> 16) & 0xffff,
-            .xen_minor  = (xen_version)       & 0xffff,
         };
 
-    if ( xen_version < 0 )
+    if ( xc_version(xch, XEN_VERSION_version, &xen_version,
+                    sizeof(xen_version)) < 0 )
     {
         PERROR("Unable to obtain Xen Version");
         return -1;
     }
+    dhdr.xen_major = (xen_version >> 16) & 0xffff;
+    dhdr.xen_minor = (xen_version)       & 0xffff;
 
     if ( write_exact(ctx->fd, &ihdr, sizeof(ihdr)) )
     {
tools/libxc/xg_save_restore.h +4 -2
index 303081d..007875f 100644
@@ -57,10 +57,12 @@ static inline int get_platform_info(xc_interface *xch, uint32_t dom,
     xen_capabilities_info_t xen_caps = "";
     xen_platform_parameters_t xen_params;
 
-    if (xc_version(xch, XENVER_platform_parameters, &xen_params) != 0)
+    if (xc_version(xch, XEN_VERSION_platform_parameters, &xen_params,
+                   sizeof(xen_params)) < 0)
         return 0;
 
-    if (xc_version(xch, XENVER_capabilities, &xen_caps) != 0)
+    if (xc_version(xch, XEN_VERSION_capabilities, xen_caps,
+                   sizeof(xen_caps)) < 0)
         return 0;
 
     if (xc_maximum_ram_page(xch, max_mfn))
tools/libxl/libxl.c +51 -28

101 lines not on this page · raw message

tools/ocaml/libs/xc/xenctrl_stubs.c +16 -23
index 74928e9..4ac5dce 100644
@@ -853,21 +853,21 @@ CAMLprim value stub_xc_version_version(value xch)
 	CAMLparam1(xch);
 	CAMLlocal1(result);
 	xen_extraversion_t extra;
-	long packed;
+	xen_version_op_val_t packed;
 	int retval;
 
 	caml_enter_blocking_section();
-	packed = xc_version(_H(xch), XENVER_version, NULL);
+	retval = xc_version(_H(xch), XEN_VERSION_version, &packed, sizeof(packed));
 	caml_leave_blocking_section();
 
-	if (packed < 0)
+	if (retval < 0)
 		failwith_xc(_H(xch));
 
 	caml_enter_blocking_section();
-	retval = xc_version(_H(xch), XENVER_extraversion, &extra);
+	retval = xc_version(_H(xch), XEN_VERSION_extraversion, &extra, sizeof(extra));
 	caml_leave_blocking_section();
 
-	if (retval)
+	if (retval < 0)
 		failwith_xc(_H(xch));
 
 	result = caml_alloc_tuple(3);
@@ -884,37 +884,28 @@ CAMLprim value stub_xc_version_compile_info(value xch)
 {
 	CAMLparam1(xch);
 	CAMLlocal1(result);
-	xen_compile_info_t ci;
-	int retval;
-
-	caml_enter_blocking_section();
-	retval = xc_version(_H(xch), XENVER_compile_info, &ci);
-	caml_leave_blocking_section();
-
-	if (retval)
-		failwith_xc(_H(xch));
 
 	result = caml_alloc_tuple(4);
 
-	Store_field(result, 0, caml_copy_string(ci.compiler));
-	Store_field(result, 1, caml_copy_string(ci.compile_by));
-	Store_field(result, 2, caml_copy_string(ci.compile_domain));
-	Store_field(result, 3, caml_copy_string(ci.compile_date));
+	Store_field(result, 0, caml_copy_string(""));
+	Store_field(result, 1, caml_copy_string(""));
+	Store_field(result, 2, caml_copy_string(""));
+	Store_field(result, 3, caml_copy_string(""));
 
 	CAMLreturn(result);
 }
 
 
-static value xc_version_single_string(value xch, int code, void *info)
+static value xc_version_single_string(value xch, int code, void *info, ssize_t len)
 {
 	CAMLparam1(xch);
 	int retval;
 
 	caml_enter_blocking_section();
-	retval = xc_version(_H(xch), code, info);
+	retval = xc_version(_H(xch), code, info, len);
 	caml_leave_blocking_section();
 
-	if (retval)
+	if (retval < 0)
 		failwith_xc(_H(xch));
 
 	CAMLreturn(caml_copy_string((char *)info));
@@ -925,7 +916,8 @@ CAMLprim value stub_xc_version_changeset(value xch)
 {
 	xen_changeset_info_t ci;
 
-	return xc_version_single_string(xch, XENVER_changeset, &ci);
+	return xc_version_single_string(xch, XEN_VERSION_changeset,
+					&ci, sizeof(ci));
 }
 
 
@@ -933,7 +925,8 @@ CAMLprim value stub_xc_version_capabilities(value xch)
 {
 	xen_capabilities_info_t ci;
 
-	return xc_version_single_string(xch, XENVER_capabilities, &ci);
+	return xc_version_single_string(xch, XEN_VERSION_capabilities,
+					&ci, sizeof(ci));
 }
 
 
tools/python/xen/lowlevel/xc/xc.c +18 -12
index c40a4e9..5854ddc 100644
@@ -1204,34 +1204,40 @@ static PyObject *pyxc_xeninfo(XcObject *self)
     xen_capabilities_info_t xen_caps;
     xen_platform_parameters_t p_parms;
     xen_commandline_t xen_commandline;
-    long xen_version;
-    long xen_pagesize;
+    xen_version_op_val_t xen_version;
+    xen_version_op_val_t xen_pagesize;
     char str[128];
 
-    xen_version = xc_version(self->xc_handle, XENVER_version, NULL);
-
-    if ( xc_version(self->xc_handle, XENVER_extraversion, &xen_extra) != 0 )
+    if ( xc_version(self->xc_handle, XEN_VERSION_version, &xen_version,
+                    sizeof(xen_version)) < 0 )
         return pyxc_error_to_exception(self->xc_handle);
 
-    if ( xc_version(self->xc_handle, XENVER_compile_info, &xen_cc) != 0 )
+    if ( xc_version(self->xc_handle, XEN_VERSION_extraversion, &xen_extra,
+                    sizeof(xen_extra)) < 0 )
         return pyxc_error_to_exception(self->xc_handle);
 
-    if ( xc_version(self->xc_handle, XENVER_changeset, &xen_chgset) != 0 )
+    memset(&xen_cc, 0, sizeof(xen_cc));
+
+    if ( xc_version(self->xc_handle, XEN_VERSION_changeset, &xen_chgset,
+                    sizeof(xen_chgset)) < 0 )
         return pyxc_error_to_exception(self->xc_handle);
 
-    if ( xc_version(self->xc_handle, XENVER_capabilities, &xen_caps) != 0 )
+    if ( xc_version(self->xc_handle, XEN_VERSION_capabilities, &xen_caps,
+                    sizeof(xen_caps)) < 0 )
         return pyxc_error_to_exception(self->xc_handle);
 
-    if ( xc_version(self->xc_handle, XENVER_platform_parameters, &p_parms) != 0 )
+    if ( xc_version(self->xc_handle, XEN_VERSION_platform_parameters,
+                    &p_parms, sizeof(p_parms)) < 0 )
         return pyxc_error_to_exception(self->xc_handle);
 
-    if ( xc_version(self->xc_handle, XENVER_commandline, &xen_commandline) != 0 )
+    if ( xc_version(self->xc_handle, XEN_VERSION_commandline,
+                    &xen_commandline, sizeof(xen_commandline)) < 0 )
         return pyxc_error_to_exception(self->xc_handle);
 
     snprintf(str, sizeof(str), "virt_start=0x%"PRI_xen_ulong, p_parms.virt_start);
 
-    xen_pagesize = xc_version(self->xc_handle, XENVER_pagesize, NULL);
-    if (xen_pagesize < 0 )
+    if ( xc_version(self->xc_handle, XEN_VERSION_pagesize, &xen_pagesize,
+                    sizeof(xen_pagesize)) < 0 )
         return pyxc_error_to_exception(self->xc_handle);
 
     return Py_BuildValue("{s:i,s:i,s:s,s:s,s:i,s:s,s:s,s:s,s:s,s:s,s:s,s:s}",
tools/xenstat/libxenstat/src/xenstat.c +5 -7
index 3495f3f..efb68b5 100644
@@ -621,20 +621,18 @@ unsigned long long xenstat_network_tdrop(xenstat_network * network)
 /* Collect Xen version information */
 static int xenstat_collect_xen_version(xenstat_node * node)
 {
-	long vnum = 0;
+	xen_version_op_val_t vnum = 0;
 	xen_extraversion_t version;
 
 	/* Collect Xen version information if not already collected */
 	if (node->handle->xen_version[0] == '\0') {
 		/* Get the Xen version number and extraversion string */
-		vnum = xc_version(node->handle->xc_handle,
-			XENVER_version, NULL);
-
-		if (vnum < 0)
+		if (xc_version(node->handle->xc_handle,
+			       XEN_VERSION_version, &vnum, sizeof(vnum)) < 0)
 			return 0;
 
-		if (xc_version(node->handle->xc_handle, XENVER_extraversion,
-			&version) < 0)
+		if (xc_version(node->handle->xc_handle, XEN_VERSION_extraversion,
+			       &version, sizeof(version)) < 0)
 			return 0;
 		/* Format the version information as a string and store it */
 		snprintf(node->handle->xen_version, VERSION_SIZE, "%ld.%ld%s",
tools/xentrace/xenctx.c +2 -1
index e647179..cd280fc 100644
@@ -1000,7 +1000,8 @@ static void dump_ctx(int vcpu)
             guest_word_size = (cpuctx.msr_efer & 0x400) ? 8 :
                 guest_protected_mode ? 4 : 2;
             /* HVM guest context records are always host-sized */
-            if (xc_version(xenctx.xc_handle, XENVER_capabilities, &xen_caps) != 0) {
+            if (xc_version(xenctx.xc_handle, XEN_VERSION_capabilities,
+                           &xen_caps, sizeof(xen_caps)) < 0) {
                 perror("xc_version");
                 return;
             }
Signature · 7 lines
2.5.0


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Acked-by on v5 2/28
#53 lore raw

Re: [PATCH v5 02/28] libxc/libxl/python/xenstat/ocaml: Use new XEN_VERSION hypercall

On Thu, Mar 24, 2016 at 04:00:14PM -0400, Konrad Rzeszutek Wilk wrote:
[...]

tools/libxl/libxl.c libxl_numainfo *libxl_get_numainfo(libxl_ctx *ctx, int *nr) · line 5216

Quoted 2 lines
tools/libxl/libxl.c +2 -0
+
+static int libxl__xc_version_wrapper(libxl__gc *gc, unsigned int cmd, char *buf, ssize_t len, char **dst)

Please wrap this long line.

tools/libxl/libxl.c libxl_numainfo *libxl_get_numainfo(libxl_ctx *ctx, int *nr) · line 5228

Quoted 12 lines
tools/libxl/libxl.c +12 -0
+{
+    int r;
+
+    r = xc_version(CTX->xch, cmd, buf, len);
+    if ( r == -EPERM )
+    {
+        buf[0] = '\0';
+    }
+    else if ( r < 0 )
+    {
+        return r;
+    }
      if (r == -EPERM) {
          buf[0] = '\0';
      } else if (r < 0) {
          return r;
      }

You seem to have mixed different coding styles ...

With those nits fixed:

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#54 lore raw

Re: [PATCH v5 02/28] libxc/libxl/python/xenstat/ocaml: Use new XEN_VERSION hypercall

Quoted 27 lines · Wei Liu

On Thu, Mar 24, 2016 at 04:00:14PM -0400, Konrad Rzeszutek Wilk wrote:
[...]

tools/libxl/libxl.c libxl_numainfo *libxl_get_numainfo(libxl_ctx *ctx, int *nr) · line 5216

Quoted 2 lines
tools/libxl/libxl.c +2 -0
+
+static int libxl__xc_version_wrapper(libxl__gc *gc, unsigned int cmd, char *buf, ssize_t len, char **dst)

Please wrap this long line.

tools/libxl/libxl.c libxl_numainfo *libxl_get_numainfo(libxl_ctx *ctx, int *nr) · line 5228

Quoted 12 lines
tools/libxl/libxl.c +12 -0
+{
+    int r;
+
+    r = xc_version(CTX->xch, cmd, buf, len);
+    if ( r == -EPERM )
+    {
+        buf[0] = '\0';
+    }
+    else if ( r < 0 )
+    {
+        return r;
+    }
      if (r == -EPERM) {
          buf[0] = '\0';
      } else if (r < 0) {
          return r;
      }
Quoted 1 line

You seem to have mixed different coding styles ...

Duh! Yes!

Quoted 4 lines

With those nits fixed:

Thank you!

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#55 lore raw

PATCH v5 3/28 arm/x86: Use struct virtual_region to do bug, symbol, and (x86) exception tables lookup.

In reply to Konrad Rzeszutek Wilk

During execution of the hypervisor we have two regions of executable code - stext -> _etext, and _sinittext -> _einitext.

The later is not needed after bootup.

We also have various built-in macros and functions to search in between those two swaths depending on the state of the system.

That is either for bug_frames, exceptions (x86) or symbol names for the instruction.

With xSplice in the picture - we need a mechansim for new payloads to searched as well for all of this.

Originally we had extra 'if (xsplice)...' but that gets a bit tiring and does not hook up nicely.

This 'struct virtual_region' and virtual_region_list provide a mechanism to search for the bug_frames, exception table, and symbol names entries without having various calls in other sub-components in the system.

Code which wishes to participate in bug_frames and exception table entries search has to only use two public APIs:
- register_virtual_region
- unregister_virtual_region

to let the core code know.

If the ->lookup_symbol is not then the default internal symbol lookup mechanism is used.

---
Cc: Stefano Stabellini <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>

v4: New patch.
v5:
- Rename to virtual_region.
- Ditch the 'skip' function.
- Remove the _stext.
- Use RCU lists.
- Add a search function.
- Remove extern, add rcu_read_lock. remove __ from name.
---

---
 xen/arch/arm/setup.c             |   4 +
 xen/arch/arm/traps.c             |  39 ++++++----
 xen/arch/x86/extable.c           |  12 ++-
 xen/arch/x86/setup.c             |   6 ++
 xen/arch/x86/traps.c             |  40 ++++++----
 xen/common/Makefile              |   1 +
 xen/common/symbols.c             |  11 ++-
 xen/common/virtual_region.c      | 160 +++++++++++++++++++++++++++++++++++++++
 xen/include/xen/symbols.h        |   9 +++
 xen/include/xen/virtual_region.h |  48 ++++++++++++
 10 files changed, 293 insertions(+), 37 deletions(-)
 create mode 100644 xen/common/virtual_region.c
 create mode 100644 xen/include/xen/virtual_region.h
xen/arch/arm/setup.c +4 -0
index 6d205a9..09ff1ea 100644
@@ -34,6 +34,7 @@
 #include <xen/keyhandler.h>
 #include <xen/cpu.h>
 #include <xen/pfn.h>
+#include <xen/virtual_region.h>
 #include <xen/vmap.h>
 #include <xen/libfdt/libfdt.h>
 #include <xen/acpi.h>
@@ -860,6 +861,9 @@ void __init start_xen(unsigned long boot_phys_offset,
 
     system_state = SYS_STATE_active;
 
+    /* Must be done past setting system_state. */
+    unregister_init_virtual_region();
+
     domain_unpause_by_systemcontroller(dom0);
 
     /* Switch on to the dynamically allocated stack for the idle vcpu
xen/arch/arm/traps.c +24 -15
index 31d2115..2097f69 100644
@@ -31,6 +31,7 @@
 #include <xen/softirq.h>
 #include <xen/domain_page.h>
 #include <xen/perfc.h>
+#include <xen/virtual_region.h>
 #include <public/sched.h>
 #include <public/xen.h>
 #include <asm/debugger.h>
@@ -101,6 +102,8 @@ integer_param("debug_stack_lines", debug_stack_lines);
 
 void init_traps(void)
 {
+    setup_virtual_regions();
+
     /* Setup Hyp vector base */
     WRITE_SYSREG((vaddr_t)hyp_traps_vector, VBAR_EL2);
 
@@ -1077,27 +1080,33 @@ void do_unexpected_trap(const char *msg, struct cpu_user_regs *regs)
 
 int do_bug_frame(struct cpu_user_regs *regs, vaddr_t pc)
 {
-    const struct bug_frame *bug;
+    const struct bug_frame *bug = NULL;
     const char *prefix = "", *filename, *predicate;
     unsigned long fixup;
-    int id, lineno;
-    static const struct bug_frame *const stop_frames[] = {
-        __stop_bug_frames_0,
-        __stop_bug_frames_1,
-        __stop_bug_frames_2,
-        NULL
-    };
+    int id = -1, lineno;
+    struct virtual_region *region;
 
-    for ( bug = __start_bug_frames, id = 0; stop_frames[id]; ++bug )
+    region = search_for_text(pc);
+    if ( region )
     {
-        while ( unlikely(bug == stop_frames[id]) )
-            ++id;
+        for ( id = 0; id < BUGFRAME_NR; id++ )
+        {
+            const struct bug_frame *b;
+            unsigned int i;
 
-        if ( ((vaddr_t)bug_loc(bug)) == pc )
-            break;
+            for ( i = 0, b = region->frame[id].bugs;
+                  i < region->frame[id].n_bugs; b++, i++ )
+            {
+                if ( ((vaddr_t)bug_loc(b)) == pc )
+                {
+                    bug = b;
+                    goto found;
+                }
+            }
+        }
     }
-
-    if ( !stop_frames[id] )
+ found:
+    if ( !bug )
         return -ENOENT;
 
     /* WARN, BUG or ASSERT: decode the filename pointer and line number. */
xen/arch/x86/extable.c +9 -3
index 89b5bcb..c6c367a 100644
@@ -1,10 +1,12 @@
 
-#include <xen/config.h>
 #include <xen/init.h>
+#include <xen/list.h>
 #include <xen/perfc.h>
+#include <xen/rcupdate.h>
 #include <xen/sort.h>
 #include <xen/spinlock.h>
 #include <asm/uaccess.h>
+#include <xen/virtual_region.h>
 
 #define EX_FIELD(ptr, field) ((unsigned long)&(ptr)->field + (ptr)->field)
 
@@ -80,8 +82,12 @@ search_one_table(const struct exception_table_entry *first,
 unsigned long
 search_exception_table(unsigned long addr)
 {
-    return search_one_table(
-        __start___ex_table, __stop___ex_table-1, addr);
+    struct virtual_region *region = search_for_text(addr);
+
+    if ( region && region->ex )
+        return search_one_table(region->ex, region->ex_end-1, addr);
+
+    return 0;
 }
 
 unsigned long
xen/arch/x86/setup.c +6 -0
index ee65f55..c8a5adb 100644
@@ -26,6 +26,7 @@
 #include <xen/pfn.h>
 #include <xen/nodemask.h>
 #include <xen/tmem_xen.h>
+#include <xen/virtual_region.h>
 #include <xen/watchdog.h>
 #include <public/version.h>
 #include <compat/platform.h>
@@ -514,6 +515,9 @@ static void noinline init_done(void)
 
     system_state = SYS_STATE_active;
 
+    /* MUST be done prior to removing .init data. */
+    unregister_init_virtual_region();
+
     domain_unpause_by_systemcontroller(hardware_domain);
 
     /* Zero the .init code and data. */
@@ -616,6 +620,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)
     smp_prepare_boot_cpu();
     sort_exception_tables();
 
+    setup_virtual_regions();
+
     /* Full exception support from here on in. */
 
     loader = (mbi->flags & MBI_LOADERNAME)
xen/arch/x86/traps.c +24 -16
index 6fbb1cf..6c73198 100644
@@ -48,6 +48,7 @@
 #include <xen/kexec.h>
 #include <xen/trace.h>
 #include <xen/paging.h>
+#include <xen/virtual_region.h>
 #include <xen/watchdog.h>
 #include <asm/system.h>
 #include <asm/io.h>
@@ -1132,18 +1133,12 @@ static int emulate_forced_invalid_op(struct cpu_user_regs *regs)
 
 void do_invalid_op(struct cpu_user_regs *regs)
 {
-    const struct bug_frame *bug;
+    const struct bug_frame *bug = NULL;
     u8 bug_insn[2];
     const char *prefix = "", *filename, *predicate, *eip = (char *)regs->eip;
     unsigned long fixup;
-    int id, lineno;
-    static const struct bug_frame *const stop_frames[] = {
-        __stop_bug_frames_0,
-        __stop_bug_frames_1,
-        __stop_bug_frames_2,
-        __stop_bug_frames_3,
-        NULL
-    };
+    int id = -1, lineno;
+    struct virtual_region *region;
 
     DEBUGGER_trap_entry(TRAP_invalid_op, regs);
 
@@ -1160,16 +1155,29 @@ void do_invalid_op(struct cpu_user_regs *regs)
          memcmp(bug_insn, "\xf\xb", sizeof(bug_insn)) )
         goto die;
 
-    for ( bug = __start_bug_frames, id = 0; stop_frames[id]; ++bug )
+    region = search_for_text(regs->eip);
+    if ( region )
     {
-        while ( unlikely(bug == stop_frames[id]) )
-            ++id;
-        if ( bug_loc(bug) == eip )
-            break;
+        for ( id = 0; id < BUGFRAME_NR; id++ )
+        {
+            const struct bug_frame *b;
+            unsigned int i;
+
+            for ( i = 0, b = region->frame[id].bugs;
+                  i < region->frame[id].n_bugs; b++, i++ )
+            {
+                if ( bug_loc(b) == eip )
+                {
+                    bug = b;
+                    goto found;
+                }
+            }
+        }
     }
-    if ( !stop_frames[id] )
-        goto die;
 
+ found:
+    if ( !bug )
+        goto die;
     eip += sizeof(bug_insn);
     if ( id == BUGFRAME_run_fn )
     {
xen/common/Makefile +1 -0
index 77de27e..e43ec49 100644
@@ -51,6 +51,7 @@ obj-y += time.o
 obj-y += timer.o
 obj-y += trace.o
 obj-y += version.o
+obj-y += virtual_region.o
 obj-y += vm_event.o
 obj-y += vmap.o
 obj-y += vsprintf.o
xen/common/symbols.c +8 -3
index a59c59d..92fb0ee 100644
@@ -17,6 +17,7 @@
 #include <xen/lib.h>
 #include <xen/string.h>
 #include <xen/spinlock.h>
+#include <xen/virtual_region.h>
 #include <public/platform.h>
 #include <xen/guest_access.h>
 
@@ -97,8 +98,7 @@ static unsigned int get_symbol_offset(unsigned long pos)
 
 bool_t is_active_kernel_text(unsigned long addr)
 {
-    return (is_kernel_text(addr) ||
-            (system_state < SYS_STATE_active && is_kernel_inittext(addr)));
+    return !!search_for_text(addr);
 }
 
 const char *symbols_lookup(unsigned long addr,
@@ -108,13 +108,18 @@ const char *symbols_lookup(unsigned long addr,
 {
     unsigned long i, low, high, mid;
     unsigned long symbol_end = 0;
+    struct virtual_region *region;
 
     namebuf[KSYM_NAME_LEN] = 0;
     namebuf[0] = 0;
 
-    if (!is_active_kernel_text(addr))
+    region = search_for_text(addr);
+    if (!region)
         return NULL;
 
+    if (region->symbols_lookup)
+        return region->symbols_lookup(addr, symbolsize, offset, namebuf);
+
         /* do a binary search on the sorted symbols_addresses array */
     low = 0;
     high = symbols_num_syms;
xen/common/virtual_region.c new file +160 -0

160 lines not on this page · raw message

xen/include/xen/symbols.h +9 -0
index 1fa0537..f58e611 100644
@@ -5,6 +5,15 @@
 
 #define KSYM_NAME_LEN 127
 
+/*
+ * Typedef for the callback functions that symbols_lookup
+ * can call if virtual_region_list has an callback for it.
+ */
+typedef const char *symbols_lookup_t(unsigned long addr,
+                                     unsigned long *symbolsize,
+                                     unsigned long *offset,
+                                     char *namebuf);
+
 /* Lookup an address. */
 const char *symbols_lookup(unsigned long addr,
                            unsigned long *symbolsize,
xen/include/xen/virtual_region.h new file +48 -0

48 lines not on this page · raw message

Signature · 7 lines
2.5.0


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#56 lore raw

Re: [PATCH v5 03/28] arm/x86: Use struct virtual_region to do bug, symbol, and (x86) exception tables lookup.

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 24.03.16 at 21:00, <[email protected]> wrote:
xen/arch/arm/traps.c +1 -3
@@ -1077,27 +1080,33 @@ void do_unexpected_trap(const char *msg, struct cpu_user_regs *regs)
 
 int do_bug_frame(struct cpu_user_regs *regs, vaddr_t pc)
 {
-    const struct bug_frame *bug;
+    const struct bug_frame *bug = NULL;
     const char *prefix = "", *filename, *predicate;
     unsigned long fixup;
-    int id, lineno;
-    static const struct bug_frame *const stop_frames[] = {

xen/arch/arm/traps.c void do_unexpected_trap(const char *msg, struct cpu_user_regs *regs) · line 1089

Quoted 10 lines
xen/arch/arm/traps.c +3 -6
-        __stop_bug_frames_0,
-        __stop_bug_frames_1,
-        __stop_bug_frames_2,
-        NULL
-    };
+    int id = -1, lineno;
+    struct virtual_region *region;
 
-    for ( bug = __start_bug_frames, id = 0; stop_frames[id]; ++bug )
+    region = search_for_text(pc);

find_text_region() maybe? And "virtual_region" then perhaps could also become "text_region"?

Quoted 7 lines
xen/common/virtual_region.c new file +4 -0
@@ -0,0 +1,160 @@
+/*
+ * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
+ *
+ */

xen/common/virtual_region.c line 14

Quoted 10 lines
xen/common/virtual_region.c new file +10 -0
+
+#include <xen/init.h>
+#include <xen/kernel.h>
+#include <xen/rcupdate.h>
+#include <xen/spinlock.h>
+#include <xen/virtual_region.h>
+
+#ifdef CONFIG_X86
+#include <asm/uaccess.h>
+#endif

I can't spot what code below needs this.

xen/common/virtual_region.c line 23

Quoted 8 lines
xen/common/virtual_region.c new file +8 -0
+static struct virtual_region core = {
+    .list = LIST_HEAD_INIT(core.list),
+    .start = (unsigned long)_stext,
+    .end = (unsigned long)_etext,
+#ifdef CONFIG_X86
+    .ex = (struct exception_table_entry *)__start___ex_table,
+    .ex_end = (struct exception_table_entry *)__stop___ex_table,
+#endif

And I continue to be unhappy about these #ifdef-s, the more that I think that ARM is more the exception than the norm in not needing these tables. Couldn't the arch pass the two pointers to setup_virtual_regions() instead?

xen/common/virtual_region.c line 55

Quoted 1 line
xen/common/virtual_region.c new file +1 -0
+struct virtual_region* search_for_text(unsigned long addr)

I think I had said before that this should return a pointer to const. And the * also is still misplaced.

xen/common/virtual_region.c line 61

Quoted 6 lines
xen/common/virtual_region.c new file +6 -0
+{
+    struct virtual_region *region;
+
+    rcu_read_lock(&rcu_virtual_region_lock);
+
+    list_for_each_entry_rcu( region, &virtual_region_list, list )

Inconsistent style: Either you need another blank ahead of the opening paren, or you don't need any immediately inside.

xen/common/virtual_region.c line 81

Quoted 8 lines
xen/common/virtual_region.c new file +8 -0
+int register_virtual_region(struct virtual_region *r)
+{
+    ASSERT(!local_irq_is_enabled());
+
+    list_add_tail_rcu(&r->list, &virtual_region_list);
+
+    return 0;
+}

Is it really useful for this function to return non-void?

xen/include/xen/virtual_region.h line 7

Quoted 10 lines
xen/include/xen/virtual_region.h new file +7 -0
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
+ *
+ */
+
+#ifndef __XEN_VIRTUAL_REGION_LIST__
+#define __XEN_VIRTUAL_REGION_LIST__

Still inconsistent with the header's name.

xen/include/xen/virtual_region.h line 20

Quoted 9 lines
xen/include/xen/virtual_region.h new file +9 -0
+struct virtual_region
+{
+    struct list_head list;
+    unsigned long start;        /* Virtual address start. */
+    unsigned long end;          /* Virtual address start. */
+
+    /*
+     * If this is NULL the default lookup mechanism is used.
+     */

Still wrongly a multi line comment.

xen/include/xen/virtual_region.h line 29

Quoted 9 lines
xen/include/xen/virtual_region.h new file +9 -0
+    symbols_lookup_t *symbols_lookup;
+
+    struct {
+        const struct bug_frame *bugs; /* The pointer to array of bug frames. */
+        ssize_t n_bugs;         /* The number of them. */
+    } frame[BUGFRAME_NR];
+
+    struct exception_table_entry *ex;
+    struct exception_table_entry *ex_end;

So you nicely constified "bugs", but what about these two?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#57 lore raw

PATCH v5 4/28 vmap: Add vmalloc_cb and vfree_cb

In reply to Konrad Rzeszutek Wilk

For those users who want to supply their own vmap callback. To be called _after_ the pages have been allocated and the vmap API is ready to hand out virtual addresses.

Instead of using the vmap ones it can call the callback which will be responsible for generating the virtual address.

This allows users (such as xSplice) to provide their own mechanism to set the page flags.
The users (such as patch titled "xsplice: Implement payload loading") can wrap the calls to __vmap to accomplish this.

We also provide a mechanism for the calleer to squirrel the MFN array in case they want to modify the virtual addresses easily.

We also provide the free-ing code path - to use the vunmap_cb to take care of tearing down the virtual addresses.

---
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Tim Deegan <[email protected]>

v4: New patch.
v5: Update per Jan's comments.
---

---
 xen/common/vmap.c      | 33 ++++++++++++++++++++++++++-------
 xen/include/xen/vmap.h | 14 ++++++++++++++
 2 files changed, 40 insertions(+), 7 deletions(-)
xen/common/vmap.c +26 -7
index 134eda0..08e7859 100644
@@ -216,7 +216,7 @@ void vunmap(const void *va)
     vm_free(va);
 }
 
-void *vmalloc(size_t size)
+void *vmalloc_cb(size_t size, vmap_cb_t *vmap_cb, mfn_t **mfn_array)
 {
     mfn_t *mfn;
     size_t pages, i;
@@ -238,11 +238,15 @@ void *vmalloc(size_t size)
         mfn[i] = _mfn(page_to_mfn(pg));
     }
 
-    va = vmap(mfn, pages);
+    va = vmap_cb ? vmap_cb(mfn, pages) : vmap(mfn, pages);
     if ( va == NULL )
         goto error;
 
-    xfree(mfn);
+    if ( mfn_array )
+        *mfn_array = mfn;
+    else
+        xfree(mfn);
+
     return va;
 
  error:
@@ -252,6 +256,11 @@ void *vmalloc(size_t size)
     return NULL;
 }
 
+void *vmalloc(size_t size)
+{
+    return vmalloc_cb(size, NULL, NULL);
+}
+
 void *vzalloc(size_t size)
 {
     void *p = vmalloc(size);
@@ -266,16 +275,15 @@ void *vzalloc(size_t size)
     return p;
 }
 
-void vfree(void *va)
+void vfree_cb(void *va, unsigned int pages, vfree_cb_t *vfree_cb_fnc)
 {
-    unsigned int i, pages;
+    unsigned int i;
     struct page_info *pg;
     PAGE_LIST_HEAD(pg_list);
 
     if ( !va )
         return;
 
-    pages = vm_size(va);
     ASSERT(pages);
 
     for ( i = 0; i < pages; i++ )
@@ -285,9 +293,20 @@ void vfree(void *va)
         ASSERT(page);
         page_list_add(page, &pg_list);
     }
-    vunmap(va);
+    if ( !vfree_cb_fnc )
+        vunmap(va);
+    else
+        vfree_cb_fnc(va, pages);
 
     while ( (pg = page_list_remove_head(&pg_list)) != NULL )
         free_domheap_page(pg);
 }
+
+void vfree(void *va)
+{
+    if ( !va )
+        return;
+
+    vfree_cb(va, vm_size(va), NULL);
+}
 #endif
xen/include/xen/vmap.h +14 -0
index 5671ac8..02cadb3 100644
@@ -12,9 +12,23 @@ void *__vmap(const mfn_t *mfn, unsigned int granularity,
 void *vmap(const mfn_t *mfn, unsigned int nr);
 void vunmap(const void *);
 void *vmalloc(size_t size);
+
+/*
+ * Callback for vmalloc_cb to use when vmap-ing.
+ */
+typedef void *(vmap_cb_t)(const mfn_t *mfn, unsigned int pages);
+void *vmalloc_cb(size_t size, vmap_cb_t *vmap_cb, mfn_t **);
+
 void *vzalloc(size_t size);
 void vfree(void *va);
 
+/*
+ * Callback for vfree to use an equivalent of vmap_cb_t
+ * when tearing down.
+ */
+typedef void (vfree_cb_t)(void *va, unsigned int pages);
+void vfree_cb(void *va, unsigned int pages, vfree_cb_t *vfree_cb_fnc);
+
 void __iomem *ioremap(paddr_t, size_t);
 
 static inline void iounmap(void __iomem *va)
Signature · 7 lines
2.5.0


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#58 lore raw

Re: [PATCH v5 04/28] vmap: Add vmalloc_cb and vfree_cb

xen/common/vmap.c void *vzalloc(size_t size) · line 278

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 24.03.16 at 21:00, <[email protected]> wrote:
xen/common/vmap.c +1 -1
@@ -266,16 +275,15 @@ void *vzalloc(size_t size)
     return p;
 }
 
-void vfree(void *va)
+void vfree_cb(void *va, unsigned int pages, vfree_cb_t *vfree_cb_fnc)

Just to repeat: This "caller provides size" worries me, the more that this doesn't mirror anything the allocation side does. Would you mind providing a case where using vm_size() instead is not correct?

xen/include/xen/vmap.h void *__vmap(const mfn_t *mfn, unsigned int granularity, · line 18

Quoted 10 lines
xen/include/xen/vmap.h +4 -0
@@ -12,9 +12,23 @@ void *__vmap(const mfn_t *mfn, unsigned int granularity,
 void *vmap(const mfn_t *mfn, unsigned int nr);
 void vunmap(const void *);
 void *vmalloc(size_t size);
+
+/*
+ * Callback for vmalloc_cb to use when vmap-ing.
+ */

Comment style.

xen/include/xen/vmap.h void *__vmap(const mfn_t *mfn, unsigned int granularity, · line 19

Quoted 1 line
xen/include/xen/vmap.h +1 -0
+typedef void *(vmap_cb_t)(const mfn_t *mfn, unsigned int pages);

Stray parentheses (again).

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#59 lore raw

Re: [PATCH v5 04/28] vmap: Add vmalloc_cb and vfree_cb

Quoted 11 lines · Jan Beulich

xen/common/vmap.c void *vzalloc(size_t size) · line 278

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 24.03.16 at 21:00, <[email protected]> wrote:
xen/common/vmap.c +1 -1
@@ -266,16 +275,15 @@ void *vzalloc(size_t size)
     return p;
 }
 
-void vfree(void *va)
+void vfree_cb(void *va, unsigned int pages, vfree_cb_t *vfree_cb_fnc)

Just to repeat: This "caller provides size" worries me, the more that this doesn't mirror anything the allocation side does. Would you mind providing a case where using vm_size() instead is not correct?

When the virtual addresses (to which we will stitch the pages allocated by vmalloc) are not allocated (provided?) by vmap.

vm_size() will be very unhappy if that virtual address it is provided with are not from the 'vmap' pool and will return 0.

Quoted 14 lines

xen/include/xen/vmap.h void *__vmap(const mfn_t *mfn, unsigned int granularity, · line 18

Quoted 11 lines
xen/include/xen/vmap.h +4 -0
@@ -12,9 +12,23 @@ void *__vmap(const mfn_t *mfn, unsigned int granularity,
 void *vmap(const mfn_t *mfn, unsigned int nr);
 void vunmap(const void *);
 void *vmalloc(size_t size);
+
+/*
+ * Callback for vmalloc_cb to use when vmap-ing.
+ */

Comment style.

Quoted 3 lines

xen/include/xen/vmap.h void *__vmap(const mfn_t *mfn, unsigned int granularity, · line 19

Quoted 1 line
xen/include/xen/vmap.h +1 -0
+typedef void *(vmap_cb_t)(const mfn_t *mfn, unsigned int pages);

Stray parentheses (again).

<sigh> I swore I fixed it and then did a pass through the rest to fix others!

But a grep tells me:

+typedef void *(vmap_cb_t)(const mfn_t *mfn, unsigned int pages); +typedef void (vfree_cb_t)(void *va, unsigned int pages); +typedef int (find_space_t)(size_t, unsigned long *, unsigned long *); +typedef void (*xsplice_loadcall_t)(void);
+typedef void (*xsplice_unloadcall_t)(void);

I need to fix those. Sorry about that - I really though I had them fixed.

Quoted 3 lines

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#60 lore raw

Re: [PATCH v5 04/28] vmap: Add vmalloc_cb and vfree_cb

Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 30.03.16 at 18:44, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich

xen/common/vmap.c void *vzalloc(size_t size) · line 278

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 24.03.16 at 21:00, <[email protected]> wrote:
xen/common/vmap.c +1 -1
@@ -266,16 +275,15 @@ void *vzalloc(size_t size)
     return p;
 }
 
-void vfree(void *va)
+void vfree_cb(void *va, unsigned int pages, vfree_cb_t *vfree_cb_fnc)

Just to repeat: This "caller provides size" worries me, the more that this doesn't mirror anything the allocation side does. Would you mind providing a case where using vm_size() instead is not correct?

Quoted 5 lines

When the virtual addresses (to which we will stitch the pages allocated by vmalloc) are not allocated (provided?) by vmap.

vm_size() will be very unhappy if that virtual address it is provided with are not from the 'vmap' pool and will return 0.

Hmm, okay, I now see that I got mislead by "This allows users (such as xSplice) to provide their own mechanism to set the page flags", which suggested to me that all you want is control over those flags. Now that I look again I realize that I could have easily spotted the actual intention right away. If all you really want to re-use from the existing vmalloc() is the allocation mechanism of the set of pages, then no, I don't think this should be done by playing with vmalloc(). Just have your caller do that allocation itself.

If, otoh, you left that VA management to (an extended version of) vmap(), by e.g. allowing the caller to request allocation from a different VA range (much like iirc x86-64 Linux handles its modules address range allocation), things would be different. After all the VA management is the important part here, while the backing memory allocation is just a trivial auxiliary operation.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#61 lore raw

Re: [PATCH v5 04/28] vmap: Add vmalloc_cb and vfree_cb

Quoted 17 lines · Jan Beulich
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 30.03.16 at 18:44, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich

xen/common/vmap.c void *vzalloc(size_t size) · line 278

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 24.03.16 at 21:00, <[email protected]> wrote:
xen/common/vmap.c +1 -1
@@ -266,16 +275,15 @@ void *vzalloc(size_t size)
     return p;
 }
 
-void vfree(void *va)
+void vfree_cb(void *va, unsigned int pages, vfree_cb_t *vfree_cb_fnc)

Just to repeat: This "caller provides size" worries me, the more that this doesn't mirror anything the allocation side does. Would you mind providing a case where using vm_size() instead is not correct?

When the virtual addresses (to which we will stitch the pages allocated by vmalloc) are not allocated (provided?) by vmap.

Quoted 6 lines
Quoted 2 lines

vm_size() will be very unhappy if that virtual address it is provided with are not from the 'vmap' pool and will return 0.

Hmm, okay, I now see that I got mislead by "This allows users (such as xSplice) to provide their own mechanism to set the page flags", which suggested to me that all you want is control over those flags.

Sorry about that! That was the initial part which didn't work out as the displacement from kernel virtual address ranges to vmap ones was 34-bits. And that broke ELF relocations which were 32-bit!

Quoted 5 lines

Now that I look again I realize that I could have easily spotted the actual intention right away. If all you really want to re-use from the existing vmalloc() is the allocation mechanism of the set of pages, then no, I don't think this should be done by playing with vmalloc(). Just have your caller do that allocation itself.

Like it was in v4 :-)

I will drop this and rework the patch that does the backing memory operation to use its own version.

Quoted 10 lines

If, otoh, you left that VA management to (an extended version of) vmap(), by e.g. allowing the caller to request allocation from a different VA range (much like iirc x86-64 Linux handles its modules address range allocation), things would be different. After all the VA management is the important part here, while the backing memory allocation is just a trivial auxiliary operation.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#62 lore raw

PATCH v5 5/28 xsplice: Design document

In reply to Konrad Rzeszutek Wilk

A mechanism is required to binarily patch the running hypervisor with new opcodes that have come about due to primarily security updates.

This document describes the design of the API that would allow us to upload to the hypervisor binary patches.

This document has been shaped by the input from:
Martin Pohlack <[email protected]>
Jan Beulich <[email protected]>

Thank you!

Input-from: Martin Pohlack <[email protected]>
Input-from: Jan Beulich <[email protected]>

---
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Tim Deegan <[email protected]>

v1-2: review
v3: Split document in v1 and v2 (todo) to simplify implementation goals.
- Add const on some structures. Truncate size to uint16_t where it makes sense.
- Convert 'id' to 'name', Add Ross's comments about what is implemented.
- Wei's and Ross's reviews.
- Jan's review comments.
- Jan's review comments.
s/int32_t state/uint32_t state/ now that return code is in seperate field (rc). Add various other types, such as R_X86_64_PC64 in the list. Mention the need for compiler check.
v4:
- Drop the LOADED->CHECKED state and go directly to CHECKED state. Drop LOADED.
v5: Julien mentioned ARM 32-bit would not use ELF64, so make the .xsplice.func
use uintXX_t types instead of ELF ones. Remove the OUT on idx subfield. Mention that 'nr' being zero can be used for probing the number of payloads. Update what 'idx' means.

---
 docs/misc/xsplice.markdown | 1039 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 1039 insertions(+)
 create mode 100644 docs/misc/xsplice.markdown
docs/misc/xsplice.markdown new file +1039 -0
new file mode 100644
index 0000000..a5303f0
@@ -0,0 +1,1039 @@
+# xSplice Design v1
+
+## Rationale
+
+A mechanism is required to binarily patch the running hypervisor with new
+opcodes that have come about due to primarily security updates.
+
+This document describes the design of the API that would allow us to
+upload to the hypervisor binary patches.
+
+The document is split in four sections:
+
+ * Detailed descriptions of the problem statement.
+ * Design of the data structures.
+ * Design of the hypercalls.
+ * Implementation notes that should be taken into consideration.
+
+
+## Glossary
+
+ * splice - patch in the binary code with new opcodes
+ * trampoline - a jump to a new instruction.
+ * payload - telemetries of the old code along with binary blob of the new
+   function (if needed).
+ * reloc - telemetries contained in the payload to construct proper trampoline.
+
+## History
+
+The document has gone under various reviews and only covers v1 design.
+
+The end of the document has a section titled `Not Yet Done` which
+outlines ideas and design for the future version of this work.
+
+## Multiple ways to patch
+
+The mechanism needs to be flexible to patch the hypervisor in multiple ways
+and be as simple as possible. The compiled code is contiguous in memory with
+no gaps - so we have no luxury of 'moving' existing code and must either
+insert a trampoline to the new code to be executed - or only modify in-place
+the code if there is sufficient space. The placement of new code has to be done
+by hypervisor and the virtual address for the new code is allocated dynamically.
+
+This implies that the hypervisor must compute the new offsets when splicing
+in the new trampoline code. Where the trampoline is added (inside
+the function we are patching or just the callers?) is also important.
+
+To lessen the amount of code in hypervisor, the consumer of the API
+is responsible for identifying which mechanism to employ and how many locations
+to patch. Combinations of modifying in-place code, adding trampoline, etc
+has to be supported. The API should allow read/write any memory within
+the hypervisor virtual address space.
+
+We must also have a mechanism to query what has been applied and a mechanism
+to revert it if needed.
+
+## Workflow
+
+The expected workflows of higher-level tools that manage multiple patches
+on production machines would be:
+
+ * The first obvious task is loading all available / suggested
+   hotpatches when they are available.
+ * Whenever new hotpatches are installed, they should be loaded too.
+ * One wants to query which modules have been loaded at runtime.
+ * If unloading is deemed safe (see unloading below), one may want to
+   support a workflow where a specific hotpatch is marked as bad and
+   unloaded.
+
+## Patching code
+
+The first mechanism to patch that comes in mind is in-place replacement.
+That is replace the affected code with new code. Unfortunately the x86
+ISA is variable size which places limits on how much space we have available
+to replace the instructions. That is not a problem if the change is smaller
+than the original opcode and we can fill it with nops. Problems will
+appear if the replacement code is longer.
+
+The second mechanism is by ti replace the call or jump to the
+old function with the address of the new function.
+
+A third mechanism is to add a jump to the new function at the
+start of the old function. N.B. The Xen hypervisor implements the third
+mechanism. See `Trampoline (e9 opcode)` section for more details.
+
+### Example of trampoline and in-place splicing
+
+As example we will assume the hypervisor does not have XSA-132 (see
+*domctl/sysctl: don't leak hypervisor stack to toolstacks*
+4ff3449f0e9d175ceb9551d3f2aecb59273f639d) and we would like to binary patch
+the hypervisor with it. The original code looks as so:
+
+<pre>
+   48 89 e0                  mov    %rsp,%rax  
+   48 25 00 80 ff ff         and    $0xffffffffffff8000,%rax  
+</pre>
+
+while the new patched hypervisor would be:
+
+<pre>
+   48 c7 45 b8 00 00 00 00   movq   $0x0,-0x48(%rbp)  
+   48 c7 45 c0 00 00 00 00   movq   $0x0,-0x40(%rbp)  
+   48 c7 45 c8 00 00 00 00   movq   $0x0,-0x38(%rbp)  
+   48 89 e0                  mov    %rsp,%rax  
+   48 25 00 80 ff ff         and    $0xffffffffffff8000,%rax  
+</pre>
+
+This is inside the arch_do_domctl. This new change adds 21 extra
+bytes of code which alters all the offsets inside the function. To alter
+these offsets and add the extra 21 bytes of code we might not have enough
+space in .text to squeeze this in.
+
+As such we could simplify this problem by only patching the site
+which calls arch_do_domctl:
+
+<pre>
+do_domctl:  
+ e8 4b b1 05 00          callq  ffff82d08015fbb9 <arch_do_domctl>  
+</pre>
+
+with a new address for where the new `arch_do_domctl` would be (this
+area would be allocated dynamically).
+
+Astute readers will wonder what we need to do if we were to patch `do_domctl`
+- which is not called directly by hypervisor but on behalf of the guests via
+the `compat_hypercall_table` and `hypercall_table`.
+Patching the offset in `hypercall_table` for `do_domctl:
+(ffff82d080103079 <do_domctl>:)
+
+<pre>
+
+ ffff82d08024d490:   79 30  
+ ffff82d08024d492:   10 80 d0 82 ff ff   
+
+</pre>
+
+with the new address where the new `do_domctl` is possible. The other
+place where it is used is in `hvm_hypercall64_table` which would need
+to be patched in a similar way. This would require an in-place splicing
+of the new virtual address of `arch_do_domctl`.
+
+In summary this example patched the callee of the affected function by
+ * allocating memory for the new code to live in,
+ * changing the virtual address in all the functions which called the old
+   code (computing the new offset, patching the callq with a new callq).
+ * changing the function pointer tables with the new virtual address of
+   the function (splicing in the new virtual address). Since this table
+   resides in the .rodata section we would need to temporarily change the
+   page table permissions during this part.
+
+However it has drawbacks - the safety checks which have to make sure
+the function is not on the stack - must also check every caller. For some
+patches this could mean - if there were an sufficient large amount of
+callers - that we would never be able to apply the update.
+
+Having the patching done at predetermined instances where the stacks
+are not deep mostly solves this problem.
+
+### Example of different trampoline patching.
+
+An alternative mechanism exists where we can insert a trampoline in the
+existing function to be patched to jump directly to the new code. This
+lessens the locations to be patched to one but it puts pressure on the
+CPU branching logic (I-cache, but it is just one unconditional jump).
+
+For this example we will assume that the hypervisor has not been compiled
+with fe2e079f642effb3d24a6e1a7096ef26e691d93e (XSA-125: *pre-fill structures
+for certain HYPERVISOR_xen_version sub-ops*) which mem-sets an structure
+in `xen_version` hypercall. This function is not called **anywhere** in
+the hypervisor (it is called by the guest) but referenced in the
+`compat_hypercall_table` and `hypercall_table` (and indirectly called
+from that). Patching the offset in `hypercall_table` for the old
+`do_xen_version` (ffff82d080112f9e <do_xen_version>)
+
+</pre>
+ ffff82d08024b270 <hypercall_table>:   
+ ...  
+ ffff82d08024b2f8:   9e 2f 11 80 d0 82 ff ff  
+
+</pre>
+
+with the new address where the new `do_xen_version` is possible. The other
+place where it is used is in `hvm_hypercall64_table` which would need
+to be patched in a similar way. This would require an in-place splicing
+of the new virtual address of `do_xen_version`.
+
+An alternative solution would be to patch insert a trampoline in the
+old `do_xen_version' function to directly jump to the new `do_xen_version`.
+
+<pre>
+ ffff82d080112f9e do_xen_version:  
+ ffff82d080112f9e:       48 c7 c0 da ff ff ff    mov    $0xffffffffffffffda,%rax  
+ ffff82d080112fa5:       83 ff 09                cmp    $0x9,%edi  
+ ffff82d080112fa8:       0f 87 24 05 00 00       ja     ffff82d0801134d2 ; do_xen_version+0x534  
+</pre>
+
+with:
+
+<pre>
+ ffff82d080112f9e do_xen_version:  
+ ffff82d080112f9e:       e9 XX YY ZZ QQ          jmpq   [new do_xen_version]  
+</pre>
+
+which would lessen the amount of patching to just one location.
+
+In summary this example patched the affected function to jump to the
+new replacement function which required:
+ * allocating memory for the new code to live in,
+ * inserting trampoline with new offset in the old function to point to the
+   new function.
+ * Optionally we can insert in the old function a trampoline jump to an function
+   providing an BUG_ON to catch errant code.
+
+The disadvantage of this are that the unconditional jump will consume a small
+I-cache penalty. However the simplicity of the patching and higher chance
+of passing safety checks make this a worthwhile option.
+
+This patching has a similar drawback as inline patching - the safety
+checks have to make sure the function is not on the stack. However
+since we are replacing at a higher level (a full function as opposed
+to various offsets within functions) the checks are simpler.
+
+Having the patching done at predetermined instances where the stacks
+are not deep mostly solves this problem as well.
+
+### Security
+
+With this method we can re-write the hypervisor - and as such we **MUST** be
+diligent in only allowing certain guests to perform this operation.
+
+Furthermore with SecureBoot or tboot, we **MUST** also verify the signature
+of the payload to be certain it came from a trusted source and integrity
+was intact.
+
+As such the hypercall **MUST** support an XSM policy to limit what the guest
+is allowed to invoke. If the system is booted with signature checking the
+signature checking will be enforced.
+
+## Design of payload format
+
+The payload **MUST** contain enough data to allow us to apply the update
+and also safely reverse it. As such we **MUST** know:
+
+ * The locations in memory to be patched. This can be determined dynamically
+   via symbols or via virtual addresses.
+ * The new code that will be patched in.
+
+This binary format can be constructed using an custom binary format but
+there are severe disadvantages of it:
+
+ * The format might need to be changed and we need an mechanism to accommodate
+   that.
+ * It has to be platform agnostic.
+ * Easily constructed using existing tools.
+
+As such having the payload in an ELF file is the sensible way. We would be
+carrying the various sets of structures (and data) in the ELF sections under
+different names and with definitions.
+
+Note that every structure has padding. This is added so that the hypervisor
+can re-use those fields as it sees fit.
+
+Earlier design attempted to ineptly explain the relations of the ELF sections
+to each other without using proper ELF mechanism (sh_info, sh_link, data
+structures using Elf types, etc). This design will explain the structures
+and how they are used together and not dig in the ELF format - except mention
+that the section names should match the structure names.
+
+The xSplice payload is a relocatable ELF binary. A typical binary would have:
+
+ * One or more .text sections.
+ * Zero or more read-only data sections.
+ * Zero or more data sections.
+ * Relocations for each of these sections.
+
+It may also have some architecture-specific sections. For example:
+
+ * Alternatives instructions.
+ * Bug frames.
+ * Exception tables.
+ * Relocations for each of these sections.
+
+The xSplice core code loads the payload as a standard ELF binary, relocates it
+and handles the architecture-specifc sections as needed. This process is much
+like what the Linux kernel module loader does.
+
+The payload contains a section (xsplice_patch_func) with an array of structures
+describing the functions to be patched:
+
+<pre>
+struct xsplice_patch_func {  
+    const char *name;  
+    uint64_t new_addr;  
+    uint64_t old_addr;  
+    uint32_t new_size;  
+    uint32_t old_size;  
+    uint8_t pad[32];  
+};  
+</pre>
+
+The size of the structure is 64 bytes.
+
+* `name` is the symbol name of the old function. Only used if `old_addr` is
+   zero, otherwise will be used during dynamic linking (when hypervisor loads
+   the payload).
+
+* `old_addr` is the address of the function to be patched and is filled in at
+  payload generation time if hypervisor function address is known. If unknown,
+  the value *MUST* be zero and the hypervisor will attempt to resolve the address.
+
+* `new_addr` is the address of the function that is replacing the old
+  function. The address is filled in during relocation. The value **MUST** be
+  the address of the new function in the file.
+
+* `old_size` and `new_size` contain the sizes of the respective functions in bytes.
+   The value of `old_size` **MUST** not be zero.
+
+* `pad` **MUST** be zero.
+
+The size of the `xsplice_patch_func` array is determined from the ELF section
+size.
+
+When applying the patch the hypervisor iterates over each `xsplice_patch_func`
+structure and the core code inserts a trampoline at `old_addr` to `new_addr`.
+
+When reverting a patch, the hypervisor iterates over each `xsplice_patch_func`
+and the core code copies the data from the undo buffer (private internal copy)
+to `old_addr`.
+
+## Hypercalls
+
+We will employ the sub operations of the system management hypercall (sysctl).
+There are to be four sub-operations:
+
+ * upload the payloads.
+ * listing of payloads summary uploaded and their state.
+ * getting an particular payload summary and its state.
+ * command to apply, delete, or revert the payload.
+
+Most of the actions are asynchronous therefore the caller is responsible
+to verify that it has been applied properly by retrieving the summary of it
+and verifying that there are no error codes associated with the payload.
+
+We **MUST** make some of them asynchronous due to the nature of patching
+it requires every physical CPU to be lock-step with each other.
+The patching mechanism while an implementation detail, is not an short
+operation and as such the design **MUST** assume it will be an long-running
+operation.
+
+The sub-operations will spell out how preemption is to be handled (if at all).
+
+Furthermore it is possible to have multiple different payloads for the same
+function. As such an unique name per payload has to be visible to allow proper manipulation.
+
+The hypercall is part of the `xen_sysctl`. The top level structure contains
+one uint32_t to determine the sub-operations and one padding field which
+*MUST* always be zero.
+
+<pre>
+struct xen_sysctl_xsplice_op {  
+    uint32_t cmd;                   /* IN: XEN_SYSCTL_XSPLICE_*. */  
+    uint32_t pad;                   /* IN: Always zero. */  
+	union {  
+          ... see below ...  
+        } u;  
+};  
+
+</pre>
+while the rest of hypercall specific structures are part of the this structure.
+
+### Basic type: struct xen_xsplice_name
+
+Most of the hypercalls employ an shared structure called `struct xen_xsplice_name`
+which contains:
+
+ * `name` - pointer where the string for the name is located.
+ * `size` - the size of the string
+ * `pad` - padding - to be zero.
+
+The structure is as follow:
+
+<pre>
+/*  
+ *  Uniquely identifies the payload.  Should be human readable.  
+ * Includes the NUL terminator  
+ */  
+#define XEN_XSPLICE_NAME_SIZE 128  
+struct xen_xsplice_name {  
+    XEN_GUEST_HANDLE_64(char) name;         /* IN, pointer to name. */  
+    uint16_t size;                          /* IN, size of name. May be upto   
+                                               XEN_XSPLICE_NAME_SIZE. */  
+    uint16_t pad[3];                        /* IN: MUST be zero. */ 
+};  
+</pre>
+
+### XEN_SYSCTL_XSPLICE_UPLOAD (0)
+
+Upload a payload to the hypervisor. The payload is verified
+against basic checks and if there are any issues the proper return code
+will be returned. The payload is not applied at this time - that is
+controlled by *XEN_SYSCTL_XSPLICE_ACTION*.
+
+The caller provides:
+
+ * A `struct xen_xsplice_name` called `name` which has the unique name.
+ * `size` the size of the ELF payload (in bytes).
+ * `payload` the virtual address of where the ELF payload is.
+
+The `name` could be an UUID that stays fixed forever for a given
+payload. It can be embedded into the ELF payload at creation time
+and extracted by tools.
+
+The return value is zero if the payload was succesfully uploaded.
+Otherwise an -XEN_EXX return value is provided. Duplicate `name` are not supported.
+
+The `payload` is the ELF payload as mentioned in the `Payload format` section.
+
+The structure is as follow:
+
+<pre>
+struct xen_sysctl_xsplice_upload {  
+    xen_xsplice_name_t name;            /* IN, name of the patch. */  
+    uint64_t size;                      /* IN, size of the ELF file. */  
+    XEN_GUEST_HANDLE_64(uint8) payload; /* IN: ELF file. */  
+};  
+</pre>
+
+### XEN_SYSCTL_XSPLICE_GET (1)
+
+Retrieve an status of an specific payload. This caller provides:
+
+ * A `struct xen_xsplice_name` called `name` which has the unique name.
+ * A `struct xen_xsplice_status` structure. The member values will
+   be over-written upon completion.
+
+Upon completion the `struct xen_xsplice_status` is updated.
+
+ * `status` - indicates the current status of the payload:
+   * *XSPLICE_STATUS_CHECKED*  (1) loaded and the ELF payload safety checks passed.
+   * *XSPLICE_STATUS_APPLIED* (2) loaded, checked, and applied.
+   *  No other value is possible.
+ * `rc` - -XEN_EXX type errors encountered while performing the last
+   XSPLICE_ACTION_* operation. The normal values can be zero or -XEN_EAGAIN which
+   respectively mean: success or operation in progress. Other values
+   imply an error occurred. If there is an error in `rc`, `status` will **NOT**
+   have changed.
+
+The return value of the hypercall is zero on success and -XEN_EXX on failure.
+(Note that the `rc`` value can be different from the return value, as in
+rc=-XEN_EAGAIN and return value can be 0).
+
+For example, supposing there is an payload:
+
+<pre>
+ status: XSPLICE_STATUS_CHECKED
+ rc: 0
+</pre>
+
+We apply an action - XSPLICE_ACTION_REVERT - to revert it (which won't work
+as we have not even applied it. Afterwards we will have:
+
+<pre>
+ status: XSPLICE_STATUS_CHECKED
+ rc: -XEN_EINVAL
+</pre>
+
+It has failed but it remains loaded.
+
+This operation is synchronous and does not require preemption.
+
+The structure is as follow:
+
+<pre>
+struct xen_xsplice_status {  
+#define XSPLICE_STATUS_CHECKED      1  
+#define XSPLICE_STATUS_APPLIED      2  
+    uint32_t state;                 /* OUT: XSPLICE_STATE_*. */  
+    int32_t rc;                     /* OUT: 0 if no error, otherwise -XEN_EXX. */  
+};  
+
+struct xen_sysctl_xsplice_get {  
+    xen_xsplice_name_t name;        /* IN, the name of the payload. */  
+    xen_xsplice_status_t status;    /* IN/OUT: status of the payload. */  
+};  
+</pre>
+
+### XEN_SYSCTL_XSPLICE_LIST (2)
+
+Retrieve an array of abbreviated status and names of payloads that are loaded in the
+hypervisor.
+
+The caller provides:
+
+ * `version`. Version of the payload. Caller should re-use the field provided by
+    the hypervisor. If the value differs the data is stale.
+ * `idx` index iterator. The index into the hypervisor's payload count. It is
+    recommended that on first invocation zero be used so that `nr` (which the
+    hypervisor will update with the remaining payload count) be provided.
+    Also the hypervisor will provide `version` with the most current value.
+ * `nr` the max number of entries to populate. Can be zero which will result
+    in the hypercall being a probing one and return the number of payloads
+    (and update the `version`).
+ * `pad` - *MUST* be zero.
+ * `status` virtual address of where to write `struct xen_xsplice_status`
+   structures. Caller *MUST* allocate up to `nr` of them.
+ * `name` - virtual address of where to write the unique name of the payload.
+   Caller *MUST* allocate up to `nr` of them. Each *MUST* be of
+   **XEN_XSPLICE_NAME_SIZE** size. Note that **XEN_XSPLICE_NAME_SIZE** includes
+   the NUL terminator.
+ * `len` - virtual address of where to write the length of each unique name
+   of the payload. Caller *MUST* allocate up to `nr` of them. Each *MUST* be
+   of sizeof(uint32_t) (4 bytes).
+
+If the hypercall returns an positive number, it is the number (upto `nr`
+provided to the hypercall) of the payloads returned, along with `nr` updated
+with the number of remaining payloads, `version` updated (it may be the same
+across hypercalls - if it varies the data is stale and further calls could
+fail). The `status`, `name`, and `len`' are updated at their designed index
+value (`idx`) with the returned value of data.
+
+If the hypercall returns -XEN_E2BIG the `nr` is too big and should be
+lowered.
+
+If the hypercall returns an zero value there are no more payloads.
+
+Note that due to the asynchronous nature of hypercalls the control domain might
+have added or removed a number of payloads making this information stale. It is
+the responsibility of the toolstack to use the `version` field to check
+between each invocation. if the version differs it should discard the stale
+data and start from scratch. It is OK for the toolstack to use the new
+`version` field.
+
+The `struct xen_xsplice_status` structure contains an status of payload which includes:
+
+ * `status` - indicates the current status of the payload:
+   * *XSPLICE_STATUS_CHECKED*  (1) loaded and the ELF payload safety checks passed.
+   * *XSPLICE_STATUS_APPLIED* (2) loaded, checked, and applied.
+   *  No other value is possible.
+ * `rc` - -XEN_EXX type errors encountered while performing the last
+   XSPLICE_ACTION_* operation. The normal values can be zero or -XEN_EAGAIN which
+   respectively mean: success or operation in progress. Other values
+   imply an error occurred. If there is an error in `rc`, `status` will **NOT**
+   have changed.
+
+The structure is as follow:
+
+<pre>
+struct xen_sysctl_xsplice_list {  
+    uint32_t version;                       /* OUT: Hypervisor stamps value.
+                                               If varies between calls, we are  
+                                               getting stale data. */  
+    uint32_t idx;                           /* IN: Index into hypervisor array.
+                                               Should be between [0, nr). */
+    uint32_t nr;                            /* IN: How many status, names, and len  
+                                               should be filled out. Can be zero to get  
+                                               amount of payloads and version.  
+                                               OUT: How many payloads left. */  
+    uint32_t pad;                           /* IN: Must be zero. */  
+    XEN_GUEST_HANDLE_64(xen_xsplice_status_t) status;  /* OUT. Must have enough  
+                                               space allocate for nr of them. */  
+    XEN_GUEST_HANDLE_64(char) id;           /* OUT: Array of names. Each member  
+                                               MUST XEN_XSPLICE_NAME_SIZE in size.  
+                                               Must have nr of them. */  
+    XEN_GUEST_HANDLE_64(uint32) len;        /* OUT: Array of lengths of name's.  
+                                               Must have nr of them. */  
+};  
+</pre>
+
+### XEN_SYSCTL_XSPLICE_ACTION (3)
+
+Perform an operation on the payload structure referenced by the `name` field.
+The operation request is asynchronous and the status should be retrieved
+by using either **XEN_SYSCTL_XSPLICE_GET** or **XEN_SYSCTL_XSPLICE_LIST** hypercall.
+
+The caller provides:
+
+ * A 'struct xen_xsplice_name` `name` containing the unique name.
+ * `cmd` the command requested:
+  * *XSPLICE_ACTION_CHECK* (1) check that the payload will apply properly.
+    This also verfies the payload - which may require SecureBoot firmware
+    calls. This is the initial state an payload is in.
+  * *XSPLICE_ACTION_UNLOAD* (2) unload the payload.
+   Any further hypercalls against the `name` will result in failure unless
+   **XEN_SYSCTL_XSPLICE_UPLOAD** hypercall is perfomed with same `name`.
+  * *XSPLICE_ACTION_REVERT* (3) revert the payload. If the operation takes
+  more time than the upper bound of time the `rc` in `xen_xsplice_status'
+  retrieved via **XEN_SYSCTL_XSPLICE_GET** will be -XEN_EBUSY.
+  * *XSPLICE_ACTION_APPLY* (4) apply the payload. If the operation takes
+  more time than the upper bound of time the `rc` in `xen_xsplice_status'
+  retrieved via **XEN_SYSCTL_XSPLICE_GET** will be -XEN_EBUSY.
+  * *XSPLICE_ACTION_REPLACE* (5) revert all applied payloads and apply this
+  payload. If the operation takes more time than the upper bound of time
+  the `rc` in `xen_xsplice_status' retrieved via **XEN_SYSCTL_XSPLICE_GET**
+  will be -XEN_EBUSY.
+ * `time` the upper bound of time (ms) the cmd should take. Zero means infinite.
+   If within the time the operation does not succeed the operation would go in
+   error state.
+ * `pad` - *MUST* be zero.
+
+The return value will be zero unless the provided fields are incorrect.
+
+The structure is as follow:
+
+<pre>
+#define XSPLICE_ACTION_CHECK   1  
+#define XSPLICE_ACTION_UNLOAD  2  
+#define XSPLICE_ACTION_REVERT  3  
+#define XSPLICE_ACTION_APPLY   4  
+#define XSPLICE_ACTION_REPLACE 5  
+struct xen_sysctl_xsplice_action {  
+    xen_xsplice_name_t name;                /* IN, name of the patch. */  
+    uint32_t cmd;                           /* IN: XSPLICE_ACTION_* */  
+    uint32_t time;                          /* IN: Zero if no timeout. */   
+                                            /* Or upper bound of time (ms) */   
+                                            /* for operation to take. */  
+};  
+
+</pre>
+
+## State diagrams of XSPLICE_ACTION commands.
+
+There is a strict ordering state of what the commands can be.
+The XSPLICE_ACTION prefix has been dropped to easy reading and
+does not include the XSPLICE_STATES:
+
+<pre>
+              /->\  
+              \  /  
+ UNLOAD <--- CHECK ---> REPLACE|APPLY --> REVERT --\  
+                \                                  |  
+                 \-------------------<-------------/  
+
+</pre>
+## State transition table of XSPLICE_ACTION commands and XSPLICE_STATUS.
+
+Note that:
+
+ - The CHECKED state is the starting one achieved with *XEN_SYSCTL_XSPLICE_UPLOAD* hypercall.
+ - The REVERT operation on success will automatically move to the CHECKED state.
+ - There are two STATES: CHECKED and APPLIED.
+ - There are five actions (aka commands): CHECK, APPLY, REPLACE, REVERT, and UNLOAD.
+
+The state transition table of valid states and action states:
+
+<pre>
+
++---------+---------+--------------------------------+-------+--------+
+| ACTION  | Current | Result                         | Next STATE:    |
+| ACTION  | STATE   |                                |CHECKED|APPLIED |
++---------+----------+-------------------------------+-------+--------+
+| CHECK   | CHECKED | Check payload (once more, no)  |   x   |        |
+|         |         | errors)                        |       |        |
++---------+---------+--------------------------------+-------+--------+
+| CHECK   | CHECKED | Check payload (once more, with |       |        |
+|         |         | errors)                        |       |        |
++---------+---------+--------------------------------+-------+--------+
+| UNLOAD  | CHECKED | Unload payload. Always works.  |       |        |
+|         |         | No next states.                |       |        |
++---------+---------+--------------------------------+-------+--------+
+| APPLY   | CHECKED | Apply payload (success).       |       |   x    |
++---------+---------+--------------------------------+-------+--------+
+| APPLY   | CHECKED | Apply payload (error|timeout)  |   x   |        |
++---------+---------+--------------------------------+-------+--------+
+| REPLACE | CHECKED | Revert payloads and apply new  |       |   x    |
+|         |         | payload with success.          |       |        |
++---------+---------+--------------------------------+-------+--------+
+| REPLACE | CHECKED | Revert payloads and apply new  |   x   |        |
+|         |         | payload with error.            |       |        |
++---------+---------+--------------------------------+-------+--------+
+| REVERT  | APPLIED | Revert payload (success).      |   x   |        |
++---------+---------+--------------------------------+-------+--------+
+| REVERT  | APPLIED | Revert payload (error|timeout) |       |   x    |
++---------+---------+--------------------------------+-------+--------+
+</pre>
+
+All the other state transitions are invalid.
+
+## Sequence of events.
+
+The normal sequence of events is to:
+
+ 1. *XEN_SYSCTL_XSPLICE_UPLOAD* to upload the payload. If there are errors *STOP* here.
+ 2. *XEN_SYSCTL_XSPLICE_GET* to check the `->rc`. If *-XEN_EAGAIN* spin. If zero go to next step.
+ 3. *XEN_SYSCTL_XSPLICE_ACTION* with *XSPLICE_ACTION_APPLY* to apply the patch.
+ 4. *XEN_SYSCTL_XSPLICE_GET* to check the `->rc`. If in *-XEN_EAGAIN* spin. If zero exit with success.
+
+
+## Addendum
+
+Implementation quirks should not be discussed in a design document.
+
+However these observations can provide aid when developing against this
+document.
+
+
+### Alternative assembler
+
+Alternative assembler is a mechanism to use different instructions depending
+on what the CPU supports. This is done by providing multiple streams of code
+that can be patched in - or if the CPU does not support it - padded with
+`nop` operations. The alternative assembler macros cause the compiler to
+expand the code to place a most generic code in place - emit a special
+ELF .section header to tag this location. During run-time the hypervisor
+can leave the areas alone or patch them with an better suited opcodes.
+
+Note that patching functions that copy to or from guest memory requires
+to support alternative support. For example this can be due to SMAP
+(specifically *stac* and *clac* operations) which is enabled on Broadwell
+and later architectures. It may be related to other alternative instructions.
+
+### When to patch
+
+During the discussion on the design two candidates bubbled where
+the call stack for each CPU would be deterministic. This would
+minimize the chance of the patch not being applied due to safety
+checks failing. Safety checks such as not patching code which
+is on the stack - which can lead to corruption.
+
+#### Rendezvous code instead of stop_machine for patching
+
+The hypervisor's time rendezvous code runs synchronously across all CPUs
+every second. Using the stop_machine to patch can stall the time rendezvous
+code and result in NMI. As such having the patching be done at the tail
+of rendezvous code should avoid this problem.
+
+However the entrance point for that code is
+do_softirq->timer_softirq_action->time_calibration
+which ends up calling on_selected_cpus on remote CPUs.
+
+The remote CPUs receive CALL_FUNCTION_VECTOR IPI and execute the
+desired function.
+
+#### Before entering the guest code.
+
+Before we call VMXResume we check whether any soft IRQs need to be executed.
+This is a good spot because all Xen stacks are effectively empty at
+that point.
+
+To randezvous all the CPUs an barrier with an maximum timeout (which
+could be adjusted), combined with forcing all other CPUs through the
+hypervisor with IPIs, can be utilized to execute lockstep instructions
+on all CPUs.
+
+The approach is similar in concept to stop_machine and the time rendezvous
+but is time-bound. However the local CPU stack is much shorter and
+a lot more deterministic.
+
+This is implemented in the Xen Project hypervisor.
+
+### Compiling the hypervisor code
+
+Hotpatch generation often requires support for compiling the target
+with -ffunction-sections / -fdata-sections.  Changes would have to
+be done to the linker scripts to support this.
+
+### Generation of xSplice ELF payloads
+
+The design of that is not discussed in this design.
+
+This is implemented in a seperate tool which lives in a seperate
+GIT repo.
+
+Currently it resides at https://github.com/rosslagerwall/xsplice-build
+
+### Exception tables and symbol tables growth
+
+We may need support for adapting or augmenting exception tables if
+patching such code.  Hotpatches may need to bring their own small
+exception tables (similar to how Linux modules support this).
+
+If supporting hotpatches that introduce additional exception-locations
+is not important, one could also change the exception table in-place
+and reorder it afterwards.
+
+As found almost every patch (XSA) to a non-trivial function requires
+additional entries in the exception table and/or the bug frames.
+
+This is implemented in the Xen Project hypervisor.
+
+### .rodata sections
+
+The patching might require strings to be updated as well. As such we must be
+also able to patch the strings as needed. This sounds simple - but the compiler
+has a habit of coalescing strings that are the same - which means if we in-place
+alter the strings - other users will be inadvertently affected as well.
+
+This is also where pointers to functions live - and we may need to patch this
+as well. And switch-style jump tables.
+
+To guard against that we must be prepared to do patching similar to
+trampoline patching or in-line depending on the flavour. If we can
+do in-line patching we would need to:
+
+ * alter `.rodata` to be writeable.
+ * inline patch.
+ * alter `.rodata` to be read-only.
+
+If are doing trampoline patching we would need to:
+
+ * allocate a new memory location for the string.
+ * all locations which use this string will have to be updated to use the
+   offset to the string.
+ * mark the region RO when we are done.
+
+The trampoline patching is implemented in the Xen Project hypervisor.
+
+### .bss and .data sections.
+
+In place patching writable data is not suitable as it is unclear what should be done
+depending on the current state of data. As such it should not be attempted.
+
+However, functions which are being patched can bring in changes to strings
+(.data or .rodata section changes), or even to .bss sections.
+
+As such the ELF payload can introduce new .rodata, .bss, and .data sections.
+Patching in the new function will end up also patching in the new .rodata
+section and the new function will reference the new string in the new
+.rodata section.
+
+This is implemented in the Xen Project hypervisor.
+
+### Security
+
+Only the privileged domain should be allowed to do this operation.
+
+
+# Not Yet Done
+
+This is for further development of xSplice.
+
+## Goals
+
+The implementation must also have a mechanism for:
+
+ *  An dependency mechanism for the payloads. To use that information to load:
+    - The appropiate payload. To verify that payload is built against the
+      hypervisor. This can be done via the `build-id`
+      or via providing an copy of the old code - so that the hypervisor can
+       verify it against the code in memory.
+    - To construct an appropiate order of payloads to load in case they
+      depend on each other.
+ * Be able to lookup in the Xen hypervisor the symbol names of functions from the ELF payload.
+ * Be able to patch .rodata, .bss, and .data sections.
+ * Further safety checks (blacklist of which functions cannot be patched, check
+   the stack, make sure the payload is built with same compiler as hypervisor).
+ * NOP out the code sequence if `new_size` is zero.
+ * Deal with other relocation types:  R_X86_64_[8,16,32,32S], R_X86_64_PC[8,16,64] in payload file.
+
+### xSplice interdependencies
+
+xSplice patches interdependencies are tricky.
+
+There are the ways this can be addressed:
+ * A single large patch that subsumes and replaces all previous ones.
+   Over the life-time of patching the hypervisor this large patch
+   grows to accumulate all the code changes.
+ * Hotpatch stack - where an mechanism exists that loads the hotpatches
+   in the same order they were built in. We would need an build-id
+   of the hypevisor to make sure the hot-patches are build against the
+   correct build.
+ * Payload containing the old code to check against that. That allows
+   the hotpatches to be loaded indepedently (if they don't overlap) - or
+   if the old code also containst previously patched code - even if they
+   overlap.
+
+The disadvantage of the first large patch is that it can grow over
+time and not provide an bisection mechanism to identify faulty patches.
+
+The hot-patch stack puts stricts requirements on the order of the patches
+being loaded and requires an hypervisor build-id to match against.
+
+The old code allows much more flexibility and an additional guard,
+but is more complex to implement.
+
+### Handle inlined __LINE__
+
+This problem is related to hotpatch construction
+and potentially has influence on the design of the hotpatching
+infrastructure in Xen.
+
+For example:
+
+We have file1.c with functions f1 and f2 (in that order).  f2 contains a
+BUG() (or WARN()) macro and at that point embeds the source line number
+into the generated code for f2.
+
+Now we want to hotpatch f1 and the hotpatch source-code patch adds 2
+lines to f1 and as a consequence shifts out f2 by two lines.  The newly
+constructed file1.o will now contain differences in both binary
+functions f1 (because we actually changed it with the applied patch) and
+f2 (because the contained BUG macro embeds the new line number).
+
+Without additional information, an algorithm comparing file1.o before
+and after hotpatch application will determine both functions to be
+changed and will have to include both into the binary hotpatch.
+
+Options:
+
+1. Transform source code patches for hotpatches to be line-neutral for
+   each chunk.  This can be done in almost all cases with either
+   reformatting of the source code or by introducing artificial
+   preprocessor "#line n" directives to adjust for the introduced
+   differences.
+
+   This approach is low-tech and simple.  Potentially generated
+   backtraces and existing debug information refers to the original
+   build and does not reflect hotpatching state except for actually
+   hotpatched functions but should be mostly correct.
+
+2. Ignoring the problem and living with artificially large hotpatches
+   that unnecessarily patch many functions.
+
+   This approach might lead to some very large hotpatches depending on
+   content of specific source file.  It may also trigger pulling in
+   functions into the hotpatch that cannot reasonable be hotpatched due
+   to limitations of a hotpatching framework (init-sections, parts of
+   the hotpatching framework itself, ...) and may thereby prevent us
+   from patching a specific problem.
+
+   The decision between 1. and 2. can be made on a patch--by-patch
+   basis.
+
+3. Introducing an indirection table for storing line numbers and
+   treating that specially for binary diffing. Linux may follow
+   this approach.
+
+   We might either use this indirection table for runtime use and patch
+   that with each hotpatch (similarly to exception tables) or we might
+   purely use it when building hotpatches to ignore functions that only
+   differ at exactly the location where a line-number is embedded.
+
+For BUG(), WARN(), etc., the line number is embedded into the bug frame, not
+the function itself.
+
+Similar considerations are true to a lesser extent for __FILE__, but it
+could be argued that file renaming should be done outside of hotpatches.
+
+## Signature checking requirements.
+
+The signature checking requires that the layout of the data in memory
+**MUST** be same for signature to be verified. This means that the payload
+data layout in ELF format **MUST** match what the hypervisor would be
+expecting such that it can properly do signature verification.
+
+The signature is based on the all of the payloads continuously laid out
+in memory. The signature is to be appended at the end of the ELF payload
+prefixed with the string '~Module signature appended~\n', followed by
+an signature header then followed by the signature, key identifier, and signers
+name.
+
+Specifically the signature header would be:
+
+<pre>
+#define PKEY_ALGO_DSA       0  
+#define PKEY_ALGO_RSA       1  
+
+#define PKEY_ID_PGP         0 /* OpenPGP generated key ID */  
+#define PKEY_ID_X509        1 /* X.509 arbitrary subjectKeyIdentifier */  
+
+#define HASH_ALGO_MD4          0  
+#define HASH_ALGO_MD5          1  
+#define HASH_ALGO_SHA1         2  
+#define HASH_ALGO_RIPE_MD_160  3  
+#define HASH_ALGO_SHA256       4  
+#define HASH_ALGO_SHA384       5  
+#define HASH_ALGO_SHA512       6  
+#define HASH_ALGO_SHA224       7  
+#define HASH_ALGO_RIPE_MD_128  8  
+#define HASH_ALGO_RIPE_MD_256  9  
+#define HASH_ALGO_RIPE_MD_320 10  
+#define HASH_ALGO_WP_256      11  
+#define HASH_ALGO_WP_384      12  
+#define HASH_ALGO_WP_512      13  
+#define HASH_ALGO_TGR_128     14  
+#define HASH_ALGO_TGR_160     15  
+#define HASH_ALGO_TGR_192     16  
+
+
+struct elf_payload_signature {  
+	u8	algo;		/* Public-key crypto algorithm PKEY_ALGO_*. */  
+	u8	hash;		/* Digest algorithm: HASH_ALGO_*. */  
+	u8	id_type;	/* Key identifier type PKEY_ID*. */  
+	u8	signer_len;	/* Length of signer's name */  
+	u8	key_id_len;	/* Length of key identifier */  
+	u8	__pad[3];  
+	__be32	sig_len;	/* Length of signature data */  
+};
+
+</pre>
+(Note that this has been borrowed from Linux module signature code.).
+
+
+### .bss and .data sections.
+
+In place patching writable data is not suitable as it is unclear what should be done
+depending on the current state of data. As such it should not be attempted.
+
+That said we should provide hook functions so that the existing data
+can be changed during payload application.
+
+
+### Inline patching
+
+The hypervisor should verify that the in-place patching would fit within
+the code or data.
+
+### Trampoline (e9 opcode)
+
+The e9 opcode used for jmpq uses a 32-bit signed displacement. That means
+we are limited to up to 2GB of virtual address to place the new code
+from the old code. That should not be a problem since Xen hypervisor has
+a very small footprint.
+
+However if we need - we can always add two trampolines. One at the 2GB
+limit that calls the next trampoline.
+
+Please note there is a small limitation for trampolines in
+function entries: The target function (+ trailing padding) must be able
+to accomodate the trampoline. On x86 with +-2 GB relative jumps,
+this means 5 bytes are required.
+
+Depending on compiler settings, there are several functions in Xen that
+are smaller (without inter-function padding).
+
+<pre> 
+readelf -sW xen-syms | grep " FUNC " | \
+    awk '{ if ($3 < 5) print $3, $4, $5, $8 }'
+
+...
+3 FUNC LOCAL wbinvd_ipi
+3 FUNC LOCAL shadow_l1_index
+...
+</pre>
+A compile-time check for, e.g., a minimum alignment of functions or a
+runtime check that verifies symbol size (+ padding to next symbols) for
+that in the hypervisor is advised.
+
+The tool for generating payloads currently does perform a compile-time
+check to ensure that the function to be replaced is large enough.
+
Signature · 7 lines
2.5.0


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#63 lore raw

Re: [PATCH v5 05/28] xsplice: Design document

docs/misc/xsplice.markdown line 552

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 24.03.16 at 21:00, <[email protected]> wrote:
docs/misc/xsplice.markdown new file +6 -0
+struct xen_sysctl_xsplice_list {  
+    uint32_t version;                       /* OUT: Hypervisor stamps value.
+                                               If varies between calls, we are  
+                                               getting stale data. */  
+    uint32_t idx;                           /* IN: Index into hypervisor array.
+                                               Should be between [0, nr). */

This is now actively wrong, when comparing with the implementation in the next patch, namely

            if ( list->idx > i++ )
                continue;

E.g. on some subsequent invocation you might have idx=55 and nr=32, making you populate array slots [0,31] with data for payloads [55,86]. Why don't you just say "Index into hypervisor list"?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#64 lore raw

Re: [PATCH v5 05/28] xsplice: Design document

Quoted 11 lines · Jan Beulich

docs/misc/xsplice.markdown line 552

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 24.03.16 at 21:00, <[email protected]> wrote:
docs/misc/xsplice.markdown new file +6 -0
+struct xen_sysctl_xsplice_list {  
+    uint32_t version;                       /* OUT: Hypervisor stamps value.
+                                               If varies between calls, we are  
+                                               getting stale data. */  
+    uint32_t idx;                           /* IN: Index into hypervisor array.
+                                               Should be between [0, nr). */

This is now actively wrong, when comparing with the implementation in the next patch, namely

Quoted 7 lines
            if ( list->idx > i++ )
                continue;

E.g. on some subsequent invocation you might have idx=55 and nr=32, making you populate array slots [0,31] with data for payloads [55,86]. Why don't you just say "Index into hypervisor list"?

/me smacks himself in the head.

Yes.

Updated it to say that and also updated the hypervisor patch (sysctl.h)

Quoted 2 lines

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#65 lore raw

PATCH v5 6/28 xen/xsplice: Hypervisor implementation of XEN_XSPLICE_op

In reply to Konrad Rzeszutek Wilk

The implementation does not actually do any patching.

It just adds the framework for doing the hypercalls, keeping track of ELF payloads, and the basic operations:
- query which payloads exist,
- query for specific payloads,
- check*1, apply*1, replace*1, and unload payloads.

*1: Which of course in this patch are nops.

The functionality is disabled on ARM until all arch components are implemented.

Also by default it is disabled until the implementation is in place.

We also use recursive spinlocks to so that the find_payload function does not need to have a 'lock' and 'non-lock' variant.

---
Cc: Daniel De Graaf <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Wei Liu <[email protected]>

v2: Rebased on keyhandler: rework keyhandler infrastructure
v3: Fixed XSM.
- Removed REVERTED state.
Split status and error code.
Add REPLACE action.
Separate payload data from the payload structure. s/XSPLICE_ID_../XSPLICE_NAME_../
- Add xsplice and CONFIG_XSPLICE build toption.
Fix code per Jan's review.
Update the sysctl.h (change bits to enum like)
- Rebase on Kconfig changes.
- Add missing pad checks. Re-order keyhandler.h to build on ARM.
- Rebase on build: hook the schedulers into Kconfig
- s/id/name/; s/payload_list_lock/payload_lock/
- Put #ifdef CONFIG_XSPLICE in header file per Doug review.
- Andrew review:
- use recursive spinlocks, change name to xsplice_op, sprinkle new-lines, add local variable block, include state diagram, squash two goto labels, use vzalloc instead of alloc_xenheap_pages.
- change 'state' from int32 to uint32_t
- remove the err label out of xsplice_upload
- use void* instaed of uint8_t
- move code around to make it easier to read.
- Add vmap.h to compiler under ARM.
- Add missing Copyright in header file
- Dropped LOADED state, make the payload go in CHECKED.
v4: Made it only work on x86 per Julien's (ARM) maintainer request.
v5: Dropped the load->check state example in sysctl.h
Made the ->nr=0 call work. Remove rc=0 in lots of cases. Update header from design doc.

---
 tools/flask/policy/policy/modules/xen/xen.te |   1 +
 xen/common/Kconfig                           |  12 +
 xen/common/Makefile                          |   1 +
 xen/common/sysctl.c                          |   7 +
 xen/common/xsplice.c                         | 406 +++++++++++++++++++++++++++
 xen/include/public/sysctl.h                  | 167 +++++++++++
 xen/include/xen/xsplice.h                    |  35 +++
 xen/xsm/flask/hooks.c                        |   6 +
 xen/xsm/flask/policy/access_vectors          |   2 +
 9 files changed, 637 insertions(+)
 create mode 100644 xen/common/xsplice.c
 create mode 100644 xen/include/xen/xsplice.h
tools/flask/policy/policy/modules/xen/xen.te +1 -0
index 7e69ce9..68ef6de 100644
@@ -72,6 +72,7 @@ allow dom0_t xen_t:xen2 {
 allow dom0_t xen_t:xen2 {
     pmu_ctrl
     get_symbol
+    xsplice_op
 };
 
 # Allow dom0 to use all XENVER_ subops and VERSION subops that have checks.
xen/common/Kconfig +12 -0
index 3522ecb..d80dddb 100644
@@ -182,4 +182,16 @@ config SCHED_DEFAULT
 
 endmenu
 
+# Enable/Disable xsplice support
+config XSPLICE
+	bool "xSplice live patching support"
+	default n
+	depends on X86
+	---help---
+	  Allows a running Xen hypervisor to be dynamically patched using
+	  binary patches without rebooting. This is primarily used to binarily
+	  patch in the field an hypervisor with XSA fixes.
+
+	  If unsure, say Y.
+
 endmenu
xen/common/Makefile +1 -0
index e43ec49..1e4bc70 100644
@@ -58,6 +58,7 @@ obj-y += vsprintf.o
 obj-y += wait.o
 obj-$(CONFIG_XENOPROF) += xenoprof.o
 obj-y += xmalloc_tlsf.o
+obj-$(CONFIG_XSPLICE) += xsplice.o
 
 obj-bin-$(CONFIG_X86) += $(foreach n,decompress bunzip2 unxz unlzma unlzo unlz4 earlycpio,$(n).init.o)
 
xen/common/sysctl.c +7 -0
index 253b7c8..0fac940 100644
@@ -28,6 +28,7 @@
 #include <xsm/xsm.h>
 #include <xen/pmstat.h>
 #include <xen/gcov.h>
+#include <xen/xsplice.h>
 
 long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
 {
@@ -460,6 +461,12 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
         ret = tmem_control(&op->u.tmem_op);
         break;
 
+    case XEN_SYSCTL_xsplice_op:
+        ret = xsplice_op(&op->u.xsplice);
+        if ( ret != -EOPNOTSUPP )
+            copyback = 1;
+        break;
+
     default:
         ret = arch_do_sysctl(op, u_sysctl);
         copyback = 0;
xen/common/xsplice.c new file +406 -0

406 lines not on this page · raw message

xen/include/public/sysctl.h +167 -0

185 lines not on this page · raw message

xen/include/xen/xsplice.h new file +35 -0
new file mode 100644
index 0000000..5c84851
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
+ *
+ */
+
+#ifndef __XEN_XSPLICE_H__
+#define __XEN_XSPLICE_H__
+
+struct xen_sysctl_xsplice_op;
+
+#ifdef CONFIG_XSPLICE
+
+int xsplice_op(struct xen_sysctl_xsplice_op *);
+
+#else
+
+#include <xen/errno.h> /* For -EOPNOTSUPP */
+static inline int xsplice_op(struct xen_sysctl_xsplice_op *op)
+{
+    return -EOPNOTSUPP;
+}
+
+#endif /* CONFIG_XSPLICE */
+
+#endif /* __XEN_XSPLICE_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/xsm/flask/hooks.c +6 -0
index 1eaec58..3ef0441 100644
@@ -808,6 +808,12 @@ static int flask_sysctl(int cmd)
     case XEN_SYSCTL_tmem_op:
         return domain_has_xen(current->domain, XEN__TMEM_CONTROL);
 
+#ifdef CONFIG_XSPLICE
+    case XEN_SYSCTL_xsplice_op:
+        return avc_current_has_perm(SECINITSID_XEN, SECCLASS_XEN2,
+                                    XEN2__XSPLICE_OP, NULL);
+#endif
+
     default:
         printk("flask_sysctl: Unknown op %d\n", cmd);
         return -EPERM;
xen/xsm/flask/policy/access_vectors +2 -0
index 56600bb..1c59b58 100644
@@ -93,6 +93,8 @@ class xen2
     pmu_ctrl
 # PMU use (domains, including unprivileged ones, will be using this operation)
     pmu_use
+# XEN_SYSCTL_xsplice_op
+    xsplice_op
 }
 
 # Classes domain and domain2 consist of operations that a domain performs on
Signature · 7 lines
2.5.0


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#66 lore raw

Re: [PATCH v5 06/28] xen/xsplice: Hypervisor implementation of XEN_XSPLICE_op

Quoted 22 lines
Quoted 1 line
Quoted 1 line · On 24.03.16 at 21:00, <[email protected]> wrote:
xen/common/xsplice.c new file +21 -0
+static struct payload *find_payload(const xen_xsplice_name_t *name)
+{
+    struct payload *data, *found = NULL;
+    char n[XEN_XSPLICE_NAME_SIZE];
+    int rc;
+
+    rc = verify_name(name);
+    if ( rc )
+        return ERR_PTR(rc);
+
+    if ( __copy_from_guest(n, name->name, name->size) )
+        return ERR_PTR(-EFAULT);
+
+    if ( n[name->size - 1] )
+        return ERR_PTR(-EINVAL);
+
+    spin_lock_recursive(&payload_lock);
+
+    list_for_each_entry ( data, &payload_list, list )
+    {
+        if ( !strcmp(data->name, n) )

xen/common/xsplice.c line 100

Quoted 10 lines
xen/common/xsplice.c new file +10 -0
+        {
+            found = data;
+            break;
+        }
+    }
+
+    spin_unlock_recursive(&payload_lock);
+
+    return found;
+}

So I've mentioned this before: Dropping the lock here means the caller may (in general) not de-reference the returned pointer. While it's only xsplice_upload() that calls this with the lock not held, and that function indeed doesn't de-ref the pointer, it's still racy: Two xsplice_upload() invocations for identically named payloads would then possibly insert both instead of one of them detecting the collision reliably. Hence I think all callers need to hold the lock, and hence the need for a recursive lock goes away.

Quoted 13 lines
xen/common/xsplice.c new file +13 -0
+static int xsplice_upload(xen_sysctl_xsplice_upload_t *upload)
+{
+    struct payload *data;
+    int rc;
+
+    rc = verify_payload(upload);
+    if ( rc )
+        return rc;
+
+    data = find_payload(&upload->name);
+    if ( data && !IS_ERR(data) /* Found. */ )
+        return -EEXIST;
+

xen/common/xsplice.c line 134

Quoted 10 lines
xen/common/xsplice.c new file +10 -0
+    if ( IS_ERR(data) )
+        return PTR_ERR(data);
+
+    data = xzalloc(struct payload);
+    if ( !data )
+        return -ENOMEM;
+
+    rc = -EFAULT;
+    if ( __copy_from_guest(data->name, upload->name.name, upload->name.size) )
+        goto out;

You're reading the string from guest memory a second time here, invalidating the verification done earlier.

Quoted 22 lines
xen/common/xsplice.c new file +21 -0
+static int xsplice_list(xen_sysctl_xsplice_list_t *list)
+{
+    xen_xsplice_status_t status;
+    struct payload *data;
+    unsigned int idx = 0, i = 0;
+    int rc = 0;
+
+    if ( list->nr > 1024 )
+        return -E2BIG;
+
+    if ( list->pad )
+        return -EINVAL;
+
+    if ( list->nr &&
+         (!guest_handle_okay(list->status, list->nr) ||
+          !guest_handle_okay(list->name, XEN_XSPLICE_NAME_SIZE * list->nr) ||
+          !guest_handle_okay(list->len, list->nr)) )
+        return -EINVAL;
+
+    spin_lock_recursive(&payload_lock);
+    if ( list->idx > payload_cnt )
Quoted 1 line

= ?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#67 lore raw

PATCH v5 7/28 libxc: Implementation of XEN_XSPLICE_op in libxc

In reply to Konrad Rzeszutek Wilk

The underlaying toolstack code to do the basic operations when using the XEN_XSPLICE_op syscalls:
- upload the payload,
- get status of an payload,
- list all the payloads,
- apply, check, replace, and revert the payload.

---
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Wei Liu <[email protected]>

v2: Actually set zero for the _pad entries.
v3: Split status into state and error code.
Add REPLACE action.
- Use timeout and utilize pads.
- Update per Wei's review.
- Extra space slipped in, remove it
v4: Add Wei's review, update comment and Ack.

---
 tools/libxc/include/xenctrl.h |  62 ++++++++
 tools/libxc/xc_misc.c         | 337 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 399 insertions(+)
tools/libxc/include/xenctrl.h +62 -0
index a9e4dc1..65b4758 100644
@@ -2561,6 +2561,68 @@ int xc_psr_cat_get_l3_info(xc_interface *xch, uint32_t socket,
                            bool *cdp_enabled);
 #endif
 
+int xc_xsplice_upload(xc_interface *xch,
+                      char *name, unsigned char *payload, uint32_t size);
+
+int xc_xsplice_get(xc_interface *xch,
+                   char *name,
+                   xen_xsplice_status_t *status);
+
+/*
+ * The heart of this function is to get an array of xen_xsplice_status_t.
+ *
+ * However it is complex because it has to deal with the hypervisor
+ * returning some of the requested data or data being stale
+ * (another hypercall might alter the list).
+ *
+ * The parameters that the function expects to contain data from
+ * the hypervisor are: 'info', 'name', and 'len'. The 'done' and
+ * 'left' are also updated with the number of entries filled out
+ * and respectively the number of entries left to get from hypervisor.
+ *
+ * It is expected that the caller of this function will take the
+ * 'left' and use the value for 'start'. This way we have an
+ * cursor in the array. Note that the 'info','name', and 'len' will
+ * be updated at the subsequent calls.
+ *
+ * The 'max' is to be provided by the caller with the maximum
+ * number of entries that 'info', 'name', and 'len' arrays can
+ * be filled up with.
+ *
+ * Each entry in the 'name' array is expected to be of XEN_XSPLICE_NAME_SIZE
+ * length.
+ *
+ * Each entry in the 'info' array is expected to be of xen_xsplice_status_t
+ * structure size.
+ *
+ * Each entry in the 'len' array is expected to be of uint32_t size.
+ *
+ * The return value is zero if the hypercall completed successfully.
+ * Note that the return value is _not_ the amount of entries filled
+ * out - that is saved in 'done'.
+ *
+ * If there was an error performing the operation, the return value
+ * will contain an negative -EXX type value. The 'done' and 'left'
+ * will contain the number of entries that had been succesfully
+ * retrieved (if any).
+ */
+int xc_xsplice_list(xc_interface *xch, unsigned int max, unsigned int start,
+                    xen_xsplice_status_t *info, char *name,
+                    uint32_t *len, unsigned int *done,
+                    unsigned int *left);
+
+/*
+ * The operations are asynchronous and the hypervisor may take a while
+ * to complete them. The `timeout` offers an option to expire the
+ * operation if it could not be completed within the specified time
+ * (in ms). Value of 0 means let hypervisor decide the best timeout.
+ */
+int xc_xsplice_apply(xc_interface *xch, char *name, uint32_t timeout);
+int xc_xsplice_revert(xc_interface *xch, char *name, uint32_t timeout);
+int xc_xsplice_unload(xc_interface *xch, char *name, uint32_t timeout);
+int xc_xsplice_check(xc_interface *xch, char *name, uint32_t timeout);
+int xc_xsplice_replace(xc_interface *xch, char *name, uint32_t timeout);
+
 /* Compat shims */
 #include "xenctrl_compat.h"
 
tools/libxc/xc_misc.c +337 -0

343 lines not on this page · raw message

Signature · 7 lines
2.5.0


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#68 lore raw

PATCH v5 8/28 xen-xsplice: Tool to manipulate xsplice payloads

In reply to Konrad Rzeszutek Wilk

A simple tool that allows an system admin to perform basic xsplice operations:

- Upload a xsplice file (with an unique name)
- List all the xsplice payloads loaded.
- Apply, revert, replace, or unload the payload using the unique name.
- Do all two - upload, and apply the payload in one go (load). Also will use the name of the file as the <name>

---
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Wei Liu <[email protected]>

v2:
- Removed REVERTED state.
- Fixed bugs handling XSPLICE_STATUS_PROGRESS.
- Split status into state and error.
Add REPLACE action.
v3:
- Utilize the timeout and use the default one (let the hypervisor pick it).
- Change the s/all/load and infer the <id> from name of file.
- s/id/name/
- Don't use hypercall buffer in upload_func, instead do it in libxc
- Remove the debug printk.
- Remove goto's (per Wei's review)
- Use fprintf(stderr in error paths.
- Add local variable block.
- Syntax, expand comment, and don't overwrite rc if xc_xsplice_upload failed.
v4:
- Remove LOADED state. Only have CHECKED state.

---
 .gitignore               |   1 +
 tools/misc/Makefile      |   4 +
 tools/misc/xen-xsplice.c | 463 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 468 insertions(+)
 create mode 100644 tools/misc/xen-xsplice.c
.gitignore +1 -0
index b40453e..b9c9550 100644
@@ -181,6 +181,7 @@ tools/misc/xc_shadow
 tools/misc/xen_cpuperf
 tools/misc/xen-detect
 tools/misc/xen-tmem-list-parse
+tools/misc/xen-xsplice
 tools/misc/xenperf
 tools/misc/xenpm
 tools/misc/xen-hvmctx
tools/misc/Makefile +4 -0
index a2ef0ec..e1956f6 100644
@@ -31,6 +31,7 @@ INSTALL_SBIN                   += xenlockprof
 INSTALL_SBIN                   += xenperf
 INSTALL_SBIN                   += xenpm
 INSTALL_SBIN                   += xenwatchdogd
+INSTALL_SBIN                   += xen-xsplice
 INSTALL_SBIN += $(INSTALL_SBIN-y)
 
 # Everything to be installed in a private bin/
@@ -99,6 +100,9 @@ xen-mfndump: xen-mfndump.o
 xenwatchdogd: xenwatchdogd.o
 	$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
 
+xen-xsplice: xen-xsplice.o
+	$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
+
 xen-lowmemd: xen-lowmemd.o
 	$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(LDLIBS_libxenstore) $(APPEND_LDFLAGS)
 
tools/misc/xen-xsplice.c new file +463 -0

463 lines not on this page · raw message

Signature · 7 lines
2.5.0


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#69 lore raw

PATCH v5 9/28 xsplice: Add helper elf routines

In reply to Konrad Rzeszutek Wilk

From: Ross Lagerwall <[email protected]>

Add Elf routines and data structures in preparation for loading an xSplice payload.

We make an assumption that the max number of sections an ELF payload can have is 64. We can in future make this be dependent on the names of the sections and verifying against a list, but for right now this suffices.

Also we a whole lot of checks to make sure that the ELF payload file is not corrupted nor that the offsets point past the file.

For most of the checks we print an message if the hypervisor is built with debug enabled.

---
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Tim Deegan <[email protected]>

v2: - With the #define ELFSIZE in the ARM file we can use the common
#defines instead of using #ifdef CONFIG_ARM_32. Moved to another
patch.
- Add checks for ELF file.
- Add name to be printed.
- Add len for easier ELF checks.
- Expand on the checks. Add macro.
v3: Remove the return_ macro
- Add return_ macro back but make it depend on debug=y
- Per Andrew review: add local variable. Fix memory leak in elf_resolve_sections, Remove macro and use dprintk. Fix alignment. Use void* instead of uint8_t to handle raw payload.
v4 - Fix memory leak in elf_get_sym
- Add XSPLICE to printk/dprintk
v5: Sprinkle newlines.

---
 xen/common/Makefile           |   1 +
 xen/common/xsplice_elf.c      | 294 ++++++++++++++++++++++++++++++++++++++++++
 xen/include/xen/xsplice.h     |   3 +
 xen/include/xen/xsplice_elf.h |  51 ++++++++
 4 files changed, 349 insertions(+)
 create mode 100644 xen/common/xsplice_elf.c
 create mode 100644 xen/include/xen/xsplice_elf.h
xen/common/Makefile +1 -0
index 1e4bc70..afd84b6 100644
@@ -59,6 +59,7 @@ obj-y += wait.o
 obj-$(CONFIG_XENOPROF) += xenoprof.o
 obj-y += xmalloc_tlsf.o
 obj-$(CONFIG_XSPLICE) += xsplice.o
+obj-$(CONFIG_XSPLICE) += xsplice_elf.o
 
 obj-bin-$(CONFIG_X86) += $(foreach n,decompress bunzip2 unxz unlzma unlzo unlz4 earlycpio,$(n).init.o)
 
xen/common/xsplice_elf.c new file +294 -0

294 lines not on this page · raw message

xen/include/xen/xsplice.h +3 -0
index 5c84851..00482d0 100644
@@ -10,6 +10,9 @@ struct xen_sysctl_xsplice_op;
 
 #ifdef CONFIG_XSPLICE
 
+/* Convenience define for printk. */
+#define XSPLICE "xsplice: "
+
 int xsplice_op(struct xen_sysctl_xsplice_op *);
 
 #else
xen/include/xen/xsplice_elf.h new file +51 -0

51 lines not on this page · raw message

Signature · 7 lines
2.5.0


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#70 lore raw

Re: [PATCH v5 09/28] xsplice: Add helper elf routines

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 24.03.16 at 21:00, <[email protected]> wrote:
xen/common/xsplice_elf.c new file +5 -0
@@ -0,0 +1,294 @@
+/*
+ * Copyright (C) 2016 Citrix Systems R&D Ltd.
+ */
+
+#include <xen/errno.h>

xen/common/xsplice_elf.c line 15

Quoted 10 lines
xen/common/xsplice_elf.c new file +10 -0
+#include <xen/lib.h>
+#include <xen/xsplice_elf.h>
+#include <xen/xsplice.h>
+
+struct xsplice_elf_sec *xsplice_elf_sec_by_name(const struct xsplice_elf *elf,
+                                                const char *name)
+{
+    unsigned int i;
+
+    for ( i = 0; i < elf->hdr->e_shnum; i++ )

Unless you do something unusual (which would be undesirable), useful ELF section number start from 1.

xen/common/xsplice_elf.c line 29

Quoted 6 lines
xen/common/xsplice_elf.c new file +6 -0
+static int elf_resolve_sections(struct xsplice_elf *elf, const void *data)
+{
+    struct xsplice_elf_sec *sec;
+    unsigned int i;
+
+    /* xsplice_elf_load sanity checked e_shnum checked. */

redundant "checked"

xen/common/xsplice_elf.c line 40

Quoted 11 lines
xen/common/xsplice_elf.c new file +11 -0
+    sec = xmalloc_array(struct xsplice_elf_sec, elf->hdr->e_shnum);
+    if ( !sec )
+    {
+        printk(XENLOG_ERR "%s%s: Could not allocate memory for section table!\n",
+               XSPLICE, elf->name);
+        return -ENOMEM;
+    }
+
+    elf->sec = sec;
+
+    /* N.B. We also will ingest SHN_UNDEF sections. */

Because of? The meaning of the fields in the 0-th section header is different from that of ordinary ones.

xen/common/xsplice_elf.c line 43

Quoted 3 lines
xen/common/xsplice_elf.c new file +3 -0
+    for ( i = 0; i < elf->hdr->e_shnum; i++ )
+    {
+        ssize_t delta = elf->hdr->e_shoff + i * elf->hdr->e_shentsize;

Why ssize_t? (This anyway should be a suitable ELF type.)

xen/common/xsplice_elf.c line 48

Quoted 5 lines
xen/common/xsplice_elf.c new file +5 -0
+
+        if ( delta + sizeof(Elf_Shdr) > elf->len )
+        {
+            dprintk(XENLOG_DEBUG, "%s%s: Section header [%d] is past end of payload!\n",
+                    XSPLICE, elf->name, i);

XSPLICE is a string literal, so should be prepended to the format string instead of forced through %s. And %u please for unsigned arguments.

Also this check doesn't need doing inside the loop - you can simply check once (using e_shnum) that the entire section table is valid.

xen/common/xsplice_elf.c line 52

Quoted 4 lines
xen/common/xsplice_elf.c new file +4 -0
+            return -EINVAL;
+        }
+
+        sec[i].sec = (Elf_Shdr *)(data + delta);

Pointless cast bogusly casting away constness.

xen/common/xsplice_elf.c line 55

Quoted 3 lines
xen/common/xsplice_elf.c new file +3 -0
+        delta = sec[i].sec->sh_offset;
+
+        if ( delta > elf->len )

This is relevant only for sections having non-zero size. And then you of course need to take size into account when dong the bounds check.

Quoted 7 lines
xen/common/xsplice_elf.c new file +7 -0
+        {
+            dprintk(XENLOG_DEBUG, "%s%s: Section [%d] data is past end of payload!\n",
+                    XSPLICE, elf->name, i);
+            return -EINVAL;
+        }
+
+        sec[i].data = data + delta;

xen/common/xsplice_elf.c line 72

Quoted 10 lines
xen/common/xsplice_elf.c new file +10 -0
+        /* Name is populated in xsplice_elf_sections_name. */
+        sec[i].name = NULL;
+
+        if ( sec[i].sec->sh_type == SHT_SYMTAB )
+        {
+            if ( elf->symtab )
+            {
+                dprintk(XENLOG_DEBUG, "%s%s: Multiple symbol tables!\n",
+                        XSPLICE, elf->name);
+                return -EINVAL;

There's nothing invalid about this, it's simply unsupported by the implementation (read: a better error code please).

Quoted 20 lines
xen/common/xsplice_elf.c new file +9 -0
+            }
+
+            elf->symtab = &sec[i];
+
+            /*
+             * elf->symtab->sec->sh_link would point to the right section
+             * but we hadn't finished parsing all the sections.
+             */
+            if ( elf->symtab->sec->sh_link > elf->hdr->e_shnum )

=

xen/common/xsplice_elf.c new file +8 -0
+            {
+                dprintk(XENLOG_DEBUG, "%s%s: Symbol table idx (%d) to strtab past end (%d)\n",
+                        XSPLICE, elf->name, elf->symtab->sec->sh_link,
+                        elf->hdr->e_shnum);
+                return -EINVAL;
+            }
+        }
+    }

xen/common/xsplice_elf.c line 99

Quoted 10 lines
xen/common/xsplice_elf.c new file +10 -0
+
+    if ( !elf->symtab )
+    {
+        dprintk(XENLOG_DEBUG, "%s%s: No symbol table found!\n",
+                XSPLICE, elf->name);
+        return -EINVAL;
+    }
+
+    /* There can be multiple SHT_STRTAB so pick the right one. */
+    elf->strtab = &sec[elf->symtab->sec->sh_link];

How about checking this really is a SHT_STRTAB section?

xen/common/xsplice_elf.c line 102

Quoted 2 lines
xen/common/xsplice_elf.c new file +2 -0
+    if ( !elf->symtab->sec->sh_size || !elf->symtab->sec->sh_entsize ||
+         elf->symtab->sec->sh_entsize != sizeof(Elf_Sym) )

The first sh_entsize check is redundant with the second, and the second is too strict (< suffices).

Also shouldn't the string table section also have at least non-zero size? And its first and last bytes be NUL?

xen/common/xsplice_elf.c line 122

Quoted 11 lines
xen/common/xsplice_elf.c new file +11 -0
+static int elf_resolve_section_names(struct xsplice_elf *elf, const void *data)
+{
+    const char *shstrtab;
+    unsigned int i;
+    unsigned int offset, delta;
+
+    /*
+     * The elf->sec[0 -> e_shnum] structures have been verified by
+     * elf_resolve_sections. Find file offset for section string table.
+     */
+    offset =  elf->sec[elf->hdr->e_shstrndx].sec->sh_offset;

Truncating the value on 64-bit ELF.

xen/common/xsplice_elf.c line 131

Quoted 8 lines
xen/common/xsplice_elf.c new file +8 -0
+    if ( offset > elf->len )
+    {
+        dprintk(XENLOG_DEBUG, "%s%s: shstrtab section offset (%u) past end of payload!\n",
+                XSPLICE, elf->name, elf->hdr->e_shstrndx);
+        return -EINVAL;
+    }
+
+    shstrtab = (data + offset);

Pointless parentheses.

Quoted 1 line

+ /* We could ignore the first as it is reserved.. */

Double full stop.

xen/common/xsplice_elf.c line 138

Quoted 5 lines
xen/common/xsplice_elf.c new file +5 -0
+    for ( i = 0; i < elf->hdr->e_shnum; i++ )
+    {
+        delta = elf->sec[i].sec->sh_name;
+
+        if ( offset + delta > elf->len )

This is too weak: After having bounds checked the string table section to be inside the image, you now need to bounds check the string offset to be inside the string table. Also it seems (just like above) you no-where check that the referenced section actually is a string table.

Quoted 21 lines
xen/common/xsplice_elf.c new file +21 -0
+static int elf_get_sym(struct xsplice_elf *elf, const void *data)
+{
+    struct xsplice_elf_sec *symtab_sec, *strtab_sec;
+    struct xsplice_elf_sym *sym;
+    unsigned int i, delta, offset, nsym;
+
+    symtab_sec = elf->symtab;
+    strtab_sec = elf->strtab;
+
+    /* Pointers arithmetic to get file offset. */
+    offset = strtab_sec->data - data;
+
+    ASSERT(offset == strtab_sec->sec->sh_offset);
+
+    /* symtab_sec->data was computed in elf_resolve_sections. */
+    ASSERT((symtab_sec->sec->sh_offset + data) == symtab_sec->data);
+
+    /* No need to check values as elf_resolve_sections did it. */
+    nsym = symtab_sec->sec->sh_size / symtab_sec->sec->sh_entsize;
+
+    sym = xmalloc_array(struct xsplice_elf_sym, nsym);

xen/common/xsplice_elf.c line 181

Quoted 10 lines
xen/common/xsplice_elf.c new file +10 -0
+    if ( !sym )
+    {
+        printk(XENLOG_ERR "%s%s: Could not allocate memory for symbols\n",
+               XSPLICE, elf->name);
+        return -ENOMEM;
+    }
+
+    /* So we don't leak memory. */
+    elf->sym = sym;
+    for ( i = 0; i < nsym; i++ )

As with sections, the 0th symbol table entry is special too.

xen/common/xsplice_elf.c line 185

Quoted 4 lines
xen/common/xsplice_elf.c new file +4 -0
+    {
+        Elf_Sym *s;
+
+        if ( i * sizeof(Elf_Sym) > elf->len )

Considering that we know the symbol table section is within bounds, I don't think this check does any good. Plus it ought to be adding 1 to i and take the section file offset into account.

xen/common/xsplice_elf.c line 194

Quoted 9 lines
xen/common/xsplice_elf.c new file +9 -0
+        {
+            dprintk(XENLOG_DEBUG, "%s%s: Symbol header [%d] is past end of  payload!\n",
+                    XSPLICE, elf->name, i);
+            return -EINVAL;
+        }
+
+        s = &((Elf_Sym *)symtab_sec->data)[i];
+
+        /* If st->name is STN_UNDEF is zero, the check will always be true. */

Odd double use of "is".

xen/common/xsplice_elf.c line 198

Quoted 4 lines
xen/common/xsplice_elf.c new file +4 -0
+        delta = s->st_name;
+
+        /* Offset has been computed earlier. */
+        if ( offset + delta > elf->len )

This should again check against the string table size and again use >= .

xen/common/xsplice_elf.c line 207

Quoted 9 lines
xen/common/xsplice_elf.c new file +9 -0
+        {
+            dprintk(XENLOG_DEBUG, "%s%s: Symbol [%u] data is past end of payload!\n",
+                    XSPLICE, elf->name, i);
+            return -EINVAL;
+        }
+
+        sym[i].sym = s;
+        if ( s->st_name == STN_UNDEF )
+            sym[i].name = NULL;

I don't think this is a good idea - since the first byte of a string table needs to be NUL, you can as well just point there (without any need for a conditional).

xen/common/xsplice_elf.c line 209

Quoted 2 lines
xen/common/xsplice_elf.c new file +2 -0
+        else
+            sym[i].name = data + ( delta + offset );

Stray blanks.

xen/common/xsplice_elf.c line 218

Quoted 3 lines
xen/common/xsplice_elf.c new file +3 -0
+static int xsplice_header_check(const struct xsplice_elf *elf)
+{
+    if ( sizeof(*elf->hdr) >= elf->len )

Strictly speaking just > .

Quoted 23 lines
xen/common/xsplice_elf.c new file +15 -0
+    {
+        dprintk(XENLOG_DEBUG, "%s%s: Section header is bigger than payload!\n",
+                XSPLICE, elf->name);
+        return -EINVAL;
+    }
+
+    if ( elf->hdr->e_shstrndx == SHN_UNDEF )
+    {
+        dprintk(XENLOG_DEBUG, "%s%s: Section name idx is undefined!?\n",
+                XSPLICE, elf->name);
+        return -EINVAL;
+    }
+
+    /* Check that section name index is within the sections. */
+    if ( elf->hdr->e_shstrndx > elf->hdr->e_shnum )

=

xen/common/xsplice_elf.c new file +5 -0
+    {
+        dprintk(XENLOG_DEBUG, "%s%s: Section name idx (%d) is past end of  sections (%d)!\n",
+                XSPLICE, elf->name, elf->hdr->e_shstrndx, elf->hdr->e_shnum);
+        return -EINVAL;
+    }

xen/common/xsplice_elf.c line 248

Quoted 10 lines
xen/common/xsplice_elf.c new file +10 -0
+
+    if ( elf->hdr->e_shnum > 64 )
+    {
+        dprintk(XENLOG_DEBUG, "%s%s: Too many (%d) sections!\n",
+                XSPLICE, elf->name, elf->hdr->e_shnum);
+        return -EINVAL;
+    }
+
+    return 0;
+}

Assuming there are no further checks hidden in other patches, I'm afraid there's quite a bit of stuff missing - there are plenty of other header fields most if not all of which need sanity checking.

Quoted 25 lines
xen/common/xsplice_elf.c new file +25 -0
+int xsplice_elf_load(struct xsplice_elf *elf, void *data)
+{
+    int rc;
+
+    elf->hdr = data;
+
+    rc = xsplice_header_check(elf);
+    if ( rc )
+        return rc;
+
+    rc = elf_resolve_sections(elf, data);
+    if ( rc )
+        return rc;
+
+    rc = elf_resolve_section_names(elf, data);
+    if ( rc )
+        return rc;
+
+    rc = elf_get_sym(elf, data);
+    if ( rc )
+        return rc;
+
+    return 0;
+}
+

xen/common/xsplice_elf.c line 284

Quoted 10 lines
xen/common/xsplice_elf.c new file +10 -0
+void xsplice_elf_free(struct xsplice_elf *elf)
+{
+    xfree(elf->sec);
+    elf->sec = NULL;
+    xfree(elf->sym);
+    elf->sym = NULL;
+    elf->nsym = 0;
+    elf->name = NULL;
+    elf->len = 0;
+}

Instead of zeroing these fields, wouldn't it make sense to simply xfree(elf) as the last action here?

Quoted 6 lines
xen/include/xen/xsplice_elf.h new file +3 -0
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2016 Citrix Systems R&D Ltd.
+ */

xen/include/xen/xsplice_elf.h line 13

Quoted 10 lines
xen/include/xen/xsplice_elf.h new file +10 -0
+
+#ifndef __XEN_XSPLICE_ELF_H__
+#define __XEN_XSPLICE_ELF_H__
+
+#include <xen/types.h>
+#include <xen/elfstructs.h>
+
+/* The following describes an Elf file as consumed by xSplice. */
+struct xsplice_elf_sec {
+    Elf_Shdr *sec;                 /* Hooked up in elf_resolve_sections. */

const?

xen/include/xen/xsplice_elf.h line 21

Quoted 8 lines
xen/include/xen/xsplice_elf.h new file +8 -0
+    const char *name;              /* Human readable name hooked in
+                                      elf_resolve_section_names. */
+    const void *data;              /* Pointer to the section (done by
+                                      elf_resolve_sections). */
+};
+
+struct xsplice_elf_sym {
+    Elf_Sym *sym;

const?

xen/include/xen/xsplice_elf.h line 27

Quoted 6 lines
xen/include/xen/xsplice_elf.h new file +6 -0
+    const char *name;
+};
+
+struct xsplice_elf {
+    const char *name;              /* Pointer to payload->name. */
+    ssize_t len;                   /* Length of the ELF file. */

Why ssize_t?

xen/include/xen/xsplice_elf.h line 33

Quoted 6 lines
xen/include/xen/xsplice_elf.h new file +6 -0
+    Elf_Ehdr *hdr;                 /* ELF file. */
+    struct xsplice_elf_sec *sec;   /* Array of sections, allocated by us. */
+    struct xsplice_elf_sym *sym;   /* Array of symbols , allocated by us. */
+    unsigned int nsym;
+    struct xsplice_elf_sec *symtab;/* Pointer to .symtab section - aka to sec[x]. */
+    struct xsplice_elf_sec *strtab;/* Pointer to .strtab section - aka to sec[y]. */

Many times - const?

xen/include/xen/xsplice_elf.h line 37

Quoted 4 lines
xen/include/xen/xsplice_elf.h new file +4 -0
+};
+
+struct xsplice_elf_sec *xsplice_elf_sec_by_name(const struct xsplice_elf *elf,
+                                                const char *name);

const (return value)?

xen/include/xen/xsplice_elf.h line 38

Quoted 1 line
xen/include/xen/xsplice_elf.h new file +1 -0
+int xsplice_elf_load(struct xsplice_elf *elf, void *data);

const (second parameter)?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#71 lore raw

Re: [PATCH v5 09/28] xsplice: Add helper elf routines

Quoted 2 lines
Quoted 2 lines
(quoted diff) +2 -0
+static int elf_resolve_sections(struct xsplice_elf *elf, const void *data)
+{

.. snip..

Quoted 6 lines
Quoted 1 line

+ /* N.B. We also will ingest SHN_UNDEF sections. */

Because of? The meaning of the fields in the 0-th section header is different from that of ordinary ones.

Quoted 1 line

+ for ( i = 0; i < elf->hdr->e_shnum; i++ )

The reason for this is not obvious .. In the payload loading patch I iterate over each elf->sec (starting at zero) and immediately dereference the sh_type:

	if ( (elf->sec[i].sec->sh_flags .. )

As you can imagine if I don't set elf->sec[0].sec this blows up. Hence the odd start at zero.

However one can as well just fix the loop in 'move_payload' to start at 1 instead of 0 - which is what I did.

Quoted 190 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+    {
+        ssize_t delta = elf->hdr->e_shoff + i * elf->hdr->e_shentsize;

Why ssize_t? (This anyway should be a suitable ELF type.)

xen/common/xsplice_elf.c line 48

Quoted 5 lines
xen/common/xsplice_elf.c new file +5 -0
+
+        if ( delta + sizeof(Elf_Shdr) > elf->len )
+        {
+            dprintk(XENLOG_DEBUG, "%s%s: Section header [%d] is past end of payload!\n",
+                    XSPLICE, elf->name, i);

XSPLICE is a string literal, so should be prepended to the format string instead of forced through %s. And %u please for unsigned arguments.

Also this check doesn't need doing inside the loop - you can simply check once (using e_shnum) that the entire section table is valid.

xen/common/xsplice_elf.c line 52

Quoted 4 lines
xen/common/xsplice_elf.c new file +4 -0
+            return -EINVAL;
+        }
+
+        sec[i].sec = (Elf_Shdr *)(data + delta);

Pointless cast bogusly casting away constness.

xen/common/xsplice_elf.c line 55

Quoted 3 lines
xen/common/xsplice_elf.c new file +3 -0
+        delta = sec[i].sec->sh_offset;
+
+        if ( delta > elf->len )

This is relevant only for sections having non-zero size. And then you of course need to take size into account when dong the bounds check.

Quoted 7 lines
xen/common/xsplice_elf.c new file +7 -0
+        {
+            dprintk(XENLOG_DEBUG, "%s%s: Section [%d] data is past end of payload!\n",
+                    XSPLICE, elf->name, i);
+            return -EINVAL;
+        }
+
+        sec[i].data = data + delta;

xen/common/xsplice_elf.c line 72

Quoted 10 lines
xen/common/xsplice_elf.c new file +10 -0
+        /* Name is populated in xsplice_elf_sections_name. */
+        sec[i].name = NULL;
+
+        if ( sec[i].sec->sh_type == SHT_SYMTAB )
+        {
+            if ( elf->symtab )
+            {
+                dprintk(XENLOG_DEBUG, "%s%s: Multiple symbol tables!\n",
+                        XSPLICE, elf->name);
+                return -EINVAL;

There's nothing invalid about this, it's simply unsupported by the implementation (read: a better error code please).

Quoted 20 lines
xen/common/xsplice_elf.c new file +9 -0
+            }
+
+            elf->symtab = &sec[i];
+
+            /*
+             * elf->symtab->sec->sh_link would point to the right section
+             * but we hadn't finished parsing all the sections.
+             */
+            if ( elf->symtab->sec->sh_link > elf->hdr->e_shnum )

=

xen/common/xsplice_elf.c new file +8 -0
+            {
+                dprintk(XENLOG_DEBUG, "%s%s: Symbol table idx (%d) to strtab past end (%d)\n",
+                        XSPLICE, elf->name, elf->symtab->sec->sh_link,
+                        elf->hdr->e_shnum);
+                return -EINVAL;
+            }
+        }
+    }

xen/common/xsplice_elf.c line 99

Quoted 10 lines
xen/common/xsplice_elf.c new file +10 -0
+
+    if ( !elf->symtab )
+    {
+        dprintk(XENLOG_DEBUG, "%s%s: No symbol table found!\n",
+                XSPLICE, elf->name);
+        return -EINVAL;
+    }
+
+    /* There can be multiple SHT_STRTAB so pick the right one. */
+    elf->strtab = &sec[elf->symtab->sec->sh_link];

How about checking this really is a SHT_STRTAB section?

xen/common/xsplice_elf.c line 102

Quoted 2 lines
xen/common/xsplice_elf.c new file +2 -0
+    if ( !elf->symtab->sec->sh_size || !elf->symtab->sec->sh_entsize ||
+         elf->symtab->sec->sh_entsize != sizeof(Elf_Sym) )

The first sh_entsize check is redundant with the second, and the second is too strict (< suffices).

Also shouldn't the string table section also have at least non-zero size? And its first and last bytes be NUL?

xen/common/xsplice_elf.c line 122

Quoted 11 lines
xen/common/xsplice_elf.c new file +11 -0
+static int elf_resolve_section_names(struct xsplice_elf *elf, const void *data)
+{
+    const char *shstrtab;
+    unsigned int i;
+    unsigned int offset, delta;
+
+    /*
+     * The elf->sec[0 -> e_shnum] structures have been verified by
+     * elf_resolve_sections. Find file offset for section string table.
+     */
+    offset =  elf->sec[elf->hdr->e_shstrndx].sec->sh_offset;

Truncating the value on 64-bit ELF.

xen/common/xsplice_elf.c line 131

Quoted 8 lines
xen/common/xsplice_elf.c new file +8 -0
+    if ( offset > elf->len )
+    {
+        dprintk(XENLOG_DEBUG, "%s%s: shstrtab section offset (%u) past end of payload!\n",
+                XSPLICE, elf->name, elf->hdr->e_shstrndx);
+        return -EINVAL;
+    }
+
+    shstrtab = (data + offset);

Pointless parentheses.

Quoted 1 line

+ /* We could ignore the first as it is reserved.. */

Double full stop.

xen/common/xsplice_elf.c line 138

Quoted 5 lines
xen/common/xsplice_elf.c new file +5 -0
+    for ( i = 0; i < elf->hdr->e_shnum; i++ )
+    {
+        delta = elf->sec[i].sec->sh_name;
+
+        if ( offset + delta > elf->len )

This is too weak: After having bounds checked the string table section to be inside the image, you now need to bounds check the string offset to be inside the string table. Also it seems (just like above) you no-where check that the referenced section actually is a string table.

Quoted 21 lines
xen/common/xsplice_elf.c new file +21 -0
+static int elf_get_sym(struct xsplice_elf *elf, const void *data)
+{
+    struct xsplice_elf_sec *symtab_sec, *strtab_sec;
+    struct xsplice_elf_sym *sym;
+    unsigned int i, delta, offset, nsym;
+
+    symtab_sec = elf->symtab;
+    strtab_sec = elf->strtab;
+
+    /* Pointers arithmetic to get file offset. */
+    offset = strtab_sec->data - data;
+
+    ASSERT(offset == strtab_sec->sec->sh_offset);
+
+    /* symtab_sec->data was computed in elf_resolve_sections. */
+    ASSERT((symtab_sec->sec->sh_offset + data) == symtab_sec->data);
+
+    /* No need to check values as elf_resolve_sections did it. */
+    nsym = symtab_sec->sec->sh_size / symtab_sec->sec->sh_entsize;
+
+    sym = xmalloc_array(struct xsplice_elf_sym, nsym);

xen/common/xsplice_elf.c line 181

Quoted 10 lines
xen/common/xsplice_elf.c new file +10 -0
+    if ( !sym )
+    {
+        printk(XENLOG_ERR "%s%s: Could not allocate memory for symbols\n",
+               XSPLICE, elf->name);
+        return -ENOMEM;
+    }
+
+    /* So we don't leak memory. */
+    elf->sym = sym;
+    for ( i = 0; i < nsym; i++ )

As with sections, the 0th symbol table entry is special too.

xen/common/xsplice_elf.c line 185

Quoted 4 lines
xen/common/xsplice_elf.c new file +4 -0
+    {
+        Elf_Sym *s;
+
+        if ( i * sizeof(Elf_Sym) > elf->len )

Considering that we know the symbol table section is within bounds, I don't think this check does any good. Plus it ought to be adding 1 to i and take the section file offset into account.

xen/common/xsplice_elf.c line 194

Quoted 9 lines
xen/common/xsplice_elf.c new file +9 -0
+        {
+            dprintk(XENLOG_DEBUG, "%s%s: Symbol header [%d] is past end of  payload!\n",
+                    XSPLICE, elf->name, i);
+            return -EINVAL;
+        }
+
+        s = &((Elf_Sym *)symtab_sec->data)[i];
+
+        /* If st->name is STN_UNDEF is zero, the check will always be true. */

Odd double use of "is".

Quoted 6 lines

xen/common/xsplice_elf.c line 198

Quoted 4 lines
xen/common/xsplice_elf.c new file +4 -0
+        delta = s->st_name;
+
+        /* Offset has been computed earlier. */
+        if ( offset + delta > elf->len )

This should again check against the string table size and again use >= .

I reworked this a bit (borrowed your idea of checking the full size of the section before the loop) - which removes the need to check the offset.

What I ended up is something much simpler (as I know the offset is OK - I just need to check that the delta is within the section):

	if ( delta && (delta > strtab_sec->sec->sec_sh_size) )
		..

The offset gets (in the new patchset) checked in elf_resolve_section.

Albeit I am not sure about the >= instead of >, .. I need to think of that.

.. snip..

Quoted 5 lines
Quoted 5 lines
xen/common/xsplice_elf.c new file +5 -0
+void xsplice_elf_free(struct xsplice_elf *elf)
+{
+    xfree(elf->sec);
+    elf->sec = NULL;
+    xfree(elf->sym);
Quoted 8 lines

xen/common/xsplice_elf.c line 284

Quoted 5 lines
xen/common/xsplice_elf.c new file +5 -0
+    elf->sym = NULL;
+    elf->nsym = 0;
+    elf->name = NULL;
+    elf->len = 0;
+}

Instead of zeroing these fields, wouldn't it make sense to simply xfree(elf) as the last action here?

The struct xsplice_elf is allocated on the stack (in the next patch).

Quoted 2 lines
Quoted 2 lines
xen/include/xen/xsplice_elf.h new file +0 -0

.. snip..

Quoted 4 lines

xen/include/xen/xsplice_elf.h line 21

Quoted 2 lines
xen/include/xen/xsplice_elf.h new file +2 -0
+struct xsplice_elf_sym {
+    Elf_Sym *sym;

const?

.. this is much harder. I end up computing the values for these symbols and have to write to this this structure a couple of times (at worst).

Quoted 9 lines

xen/include/xen/xsplice_elf.h line 27

Quoted 7 lines
xen/include/xen/xsplice_elf.h new file +6 -0
+    const char *name;
+};
+
+struct xsplice_elf {
+    const char *name;              /* Pointer to payload->name. */
+    ssize_t len;                   /* Length of the ELF file. */

Why ssize_t?

Made it 'size_t'

Quoted 9 lines

xen/include/xen/xsplice_elf.h line 33

Quoted 7 lines
xen/include/xen/xsplice_elf.h new file +6 -0
+    Elf_Ehdr *hdr;                 /* ELF file. */
+    struct xsplice_elf_sec *sec;   /* Array of sections, allocated by us. */
+    struct xsplice_elf_sym *sym;   /* Array of symbols , allocated by us. */
+    unsigned int nsym;
+    struct xsplice_elf_sec *symtab;/* Pointer to .symtab section - aka to sec[x]. */
+    struct xsplice_elf_sec *strtab;/* Pointer to .strtab section - aka to sec[y]. */

Many times - const?

I have made the symtab and strtab const, but the 'sec' and 'sym' I can't easily. There are many instances where I poke in the section (like for ELF relocations) and have to modify this.

I can do some casting but it gets a bit .. messy.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#72 lore raw

Re: [PATCH v5 09/28] xsplice: Add helper elf routines

Quoted 9 lines
Quoted 5 lines

xen/include/xen/xsplice_elf.h line 21

Quoted 3 lines

Konrad Rzeszutek Wilk <[email protected]> 04/06/16 3:40 AM >>>

xen/include/xen/xsplice_elf.h new file +2 -0
+struct xsplice_elf_sym {
+    Elf_Sym *sym;

const?

.. this is much harder. I end up computing the values for these symbols and have to write to this this structure a couple of times (at worst).

So I've intentionally added question marks to many of these comments, as there certainly may be reasons to better not make some of the items const. It just generally seemed in many cases that what gets pointed to has no reason to get altered after initial setup.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
xen/include/xen/xsplice_elf.h new file +6 -0
+    Elf_Ehdr *hdr;                 /* ELF file. */
+    struct xsplice_elf_sec *sec;   /* Array of sections, allocated by us. */
+    struct xsplice_elf_sym *sym;   /* Array of symbols , allocated by us. */
+    unsigned int nsym;
+    struct xsplice_elf_sec *symtab;/* Pointer to .symtab section - aka to sec[x]. */
+    struct xsplice_elf_sec *strtab;/* Pointer to .strtab section - aka to sec[y]. */
Quoted 5 lines
Quoted 1 line

Many times - const?

I have made the symtab and strtab const, but the 'sec' and 'sym' I can't easily. There are many instances where I poke in the section (like for ELF relocations) and have to modify this.

When processing relocations shouldn't need to modify symbols, and you also shouldn't need to modify section metadata - only section contents itself should be altered.

Quoted 1 line

I can do some casting but it gets a bit .. messy.

One thing should be very clear: No casts should be added which cast away constness.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#73 lore raw

PATCH v5 10/28 xsplice: Implement payload loading

In reply to Konrad Rzeszutek Wilk

From: Ross Lagerwall <[email protected]>

Add support for loading xsplice payloads. This is somewhat similar to the Linux kernel module loader, implementing the following steps:
- Verify the elf file.
- Parse the elf file.
- Allocate a region of memory mapped within a free area of [xen_virt_end, XEN_VIRT_END].
- Copy allocated sections into the new region. Split them in three regions - .text, .data, and .rodata. MUST have at least .text.
- Resolve section symbols. All other symbols must be absolute addresses. (Note that patch titled "xsplice,symbols: Implement symbol name resolution on address" implements that)
- Perform relocations.
- Secure the the regions (.text,.data,.rodata) with proper permissions.

We capitalize on the vmalloc callback API (see patch titled:
"vmap: Add vmalloc_cb and vfree_cb") to allocate a region of memory within the [xen_virt_end, XEN_VIRT_END] for the code.

---
Cc: Stefano Stabellini <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>

v2: - Change the 'xsplice_patch_func' structure layout/size.
- Add more error checking. Fix memory leak.
- Move elf_resolve and elf_perform relocs in elf file.
- Print the payload address and pages in keyhandler.
v3:
- Make it build under ARM
- Build it without using the return_ macro.
- Add fixes from Ross.
- Add the _return macro back - but only use it during debug builds.
- Remove the macro, prefix arch_ on arch specific calls.
v4:
- Move alloc_payload to arch specific file.
- Use void* instead of uint8_t, use const
- Add copyrights
- Unroll the vmap code to add ASSERT. Change while to not incur potential long error loop
- Use vmalloc/vfree cb APIs
- Secure .text pages to be RX instead of RWX.
v5:
- Fix allocation of virtual addresses only allowing one page to be allocated.
- Create .text, .data, and .rodata regions with different permissions.
- Make the find_space_t not a typedef to pointer to a function.
- Allocate memory in here.
---

---
 xen/arch/arm/Makefile             |   1 +
 xen/arch/arm/xsplice.c            |  55 ++++++++
 xen/arch/x86/Makefile             |   1 +
 xen/arch/x86/setup.c              |   7 +
 xen/arch/x86/xsplice.c            | 258 +++++++++++++++++++++++++++++++++++++
 xen/common/xsplice.c              | 262 +++++++++++++++++++++++++++++++++++++-
 xen/common/xsplice_elf.c          |  91 +++++++++++++
 xen/include/asm-x86/x86_64/page.h |   2 +
 xen/include/xen/xsplice.h         |  46 +++++++
 xen/include/xen/xsplice_elf.h     |   5 +
 10 files changed, 725 insertions(+), 3 deletions(-)
 create mode 100644 xen/arch/arm/xsplice.c
 create mode 100644 xen/arch/x86/xsplice.c
xen/arch/arm/Makefile +1 -0
index 0328b50..eae5cb3 100644
@@ -40,6 +40,7 @@ obj-y += device.o
 obj-y += decode.o
 obj-y += processor.o
 obj-y += smc.o
+obj-$(CONFIG_XSPLICE) += xsplice.o
 
 #obj-bin-y += ....o
 
xen/arch/arm/xsplice.c new file +55 -0

55 lines not on this page · raw message

xen/arch/x86/Makefile +1 -0
index 729065b..8a6a7d5 100644
@@ -64,6 +64,7 @@ obj-y += vm_event.o
 obj-y += xstate.o
 
 obj-$(crash_debug) += gdbstub.o
+obj-$(CONFIG_XSPLICE) += xsplice.o
 
 x86_emulate.o: x86_emulate/x86_emulate.c x86_emulate/x86_emulate.h
 
xen/arch/x86/setup.c +7 -0
index c8a5adb..b306da8 100644
@@ -100,6 +100,9 @@ unsigned long __read_mostly xen_phys_start;
 
 unsigned long __read_mostly xen_virt_end;
 
+unsigned long __read_mostly avail_virt_start;
+unsigned long __read_mostly avail_virt_end;
+
 DEFINE_PER_CPU(struct tss_struct, init_tss);
 
 char __section(".bss.stack_aligned") cpu0_stack[STACK_SIZE];
@@ -1211,6 +1214,10 @@ void __init noreturn __start_xen(unsigned long mbi_p)
                    ~((1UL << L2_PAGETABLE_SHIFT) - 1);
     destroy_xen_mappings(xen_virt_end, XEN_VIRT_START + BOOTSTRAP_MAP_BASE);
 
+    avail_virt_start = xen_virt_end;
+    avail_virt_end = XEN_VIRT_END - NR_CPUS * PAGE_SIZE;
+    BUG_ON(avail_virt_end <= avail_virt_start);
+
     /*
      * If not using 2M mappings to gain suitable pagetable permissions
      * directly from the relocation above, remap the code/data
xen/arch/x86/xsplice.c new file +258 -0

258 lines not on this page · raw message

xen/common/xsplice.c +259 -3

316 lines not on this page · raw message

xen/common/xsplice_elf.c +91 -0

97 lines not on this page · raw message

xen/include/asm-x86/x86_64/page.h +2 -0
index 86abb94..a854e05 100644
@@ -38,6 +38,8 @@
 #include <xen/pdx.h>
 
 extern unsigned long xen_virt_end;
+extern unsigned long avail_virt_start;
+extern unsigned long avail_virt_end;
 
 #define spage_to_pdx(spg) (((spg) - spage_table)<<(SUPERPAGE_SHIFT-PAGE_SHIFT))
 #define pdx_to_spage(pdx) (spage_table + ((pdx)>>(SUPERPAGE_SHIFT-PAGE_SHIFT)))
xen/include/xen/xsplice.h +46 -0

58 lines not on this page · raw message

xen/include/xen/xsplice_elf.h +5 -0
index e2dea18..f6ffcbe 100644
@@ -15,6 +15,8 @@ struct xsplice_elf_sec {
                                       elf_resolve_section_names. */
     const void *data;              /* Pointer to the section (done by
                                       elf_resolve_sections). */
+    uint8_t *load_addr;            /* A pointer to the allocated destination.
+                                      Done by load_payload_data. */
 };
 
 struct xsplice_elf_sym {
@@ -38,6 +40,9 @@ struct xsplice_elf_sec *xsplice_elf_sec_by_name(const struct xsplice_elf *elf,
 int xsplice_elf_load(struct xsplice_elf *elf, void *data);
 void xsplice_elf_free(struct xsplice_elf *elf);
 
+int xsplice_elf_resolve_symbols(struct xsplice_elf *elf);
+int xsplice_elf_perform_relocs(struct xsplice_elf *elf);
+
 #endif /* __XEN_XSPLICE_ELF_H__ */
 
 /*
Signature · 7 lines
2.5.0


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#74 lore raw

Re: [PATCH v5 10/28] xsplice: Implement payload loading

Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 24.03.16 at 21:00, <[email protected]> wrote:
xen/arch/x86/setup.c +3 -0
@@ -100,6 +100,9 @@ unsigned long __read_mostly xen_phys_start;
 
 unsigned long __read_mostly xen_virt_end;
 
+unsigned long __read_mostly avail_virt_start;
+unsigned long __read_mostly avail_virt_end;
+
 DEFINE_PER_CPU(struct tss_struct, init_tss);
 
 char __section(".bss.stack_aligned") cpu0_stack[STACK_SIZE];

xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p) · line 1219

Quoted 6 lines
xen/arch/x86/setup.c +3 -0
@@ -1211,6 +1214,10 @@ void __init noreturn __start_xen(unsigned long mbi_p)
                    ~((1UL << L2_PAGETABLE_SHIFT) - 1);
     destroy_xen_mappings(xen_virt_end, XEN_VIRT_START + BOOTSTRAP_MAP_BASE);
 
+    avail_virt_start = xen_virt_end;
+    avail_virt_end = XEN_VIRT_END - NR_CPUS * PAGE_SIZE;
+    BUG_ON(avail_virt_end <= avail_virt_start);

Is there a specific reason this needs to be here? I'd prefer the two symbols above to become static in the file really using them, and their initialization then be done there too (in an initcall function perhaps).

Quoted 9 lines
xen/arch/x86/setup.c +9 -0
+int arch_xsplice_verify_elf(const struct xsplice_elf *elf, void *data)
+{
+
+    Elf_Ehdr *hdr = data;
+
+    if ( !IS_ELF(*hdr) )
+    {
+        printk(XENLOG_ERR "%s%s: Not an ELF payload!\n", XSPLICE, elf->name);
+        return -EINVAL;

xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p)

Quoted 10 lines
xen/arch/x86/setup.c +10 -0
+    }
+
+    if ( elf->len < (sizeof *hdr) ||
+         !IS_ELF(*hdr) ||
+         hdr->e_ident[EI_CLASS] != ELFCLASS64 ||
+         hdr->e_ident[EI_DATA] != ELFDATA2LSB ||
+         hdr->e_ident[EI_OSABI] != ELFOSABI_SYSV ||
+         hdr->e_machine != EM_X86_64 ||
+         hdr->e_type != ET_REL ||
+         hdr->e_phnum != 0 )

Ah, some of the checks missing from the previous patch are here! But many don't belong here - perhaps everything but the e_machine check. And even that could be abstracted out so that it can be done in common code.

xen/arch/x86/setup.c

Quoted 5 lines
xen/arch/x86/setup.c +5 -0
+int arch_xsplice_perform_rel(struct xsplice_elf *elf,
+                             const struct xsplice_elf_sec *base,
+                             const struct xsplice_elf_sec *rela)
+{
+    dprintk(XENLOG_ERR, "%s%s: SHR_REL relocation unsupported\n",

SHR? DYM SHT?

xen/arch/x86/setup.c

Quoted 5 lines
xen/arch/x86/setup.c +5 -0
+int arch_xsplice_perform_rela(struct xsplice_elf *elf,
+                              const struct xsplice_elf_sec *base,
+                              const struct xsplice_elf_sec *rela)
+{
+    Elf_RelA *r;

const (and also perhaps better to move down into the for() scope)

xen/arch/x86/setup.c

Quoted 6 lines
xen/arch/x86/setup.c +6 -0
+    unsigned int symndx, i;
+    uint64_t val;
+    uint8_t *dest;
+
+    if ( !rela->sec->sh_entsize || !rela->sec->sh_size ||
+         rela->sec->sh_entsize != sizeof(Elf_RelA) )

Needless redundancy and too strict a check again. Also sh_size should be a multiple of sh_entsize.

xen/arch/x86/setup.c

Quoted 2 lines
xen/arch/x86/setup.c +2 -0
+    {
+        dprintk(XENLOG_DEBUG, "%s%s: Section relative header is corrupted!\n",

"Section relative"? DYM "Relocation section"? And perhaps the base section name should be printed as well.

xen/arch/x86/setup.c

Quoted 7 lines
xen/arch/x86/setup.c +7 -0
+                XSPLICE, elf->name);
+        return -EINVAL;
+    }
+
+    for ( i = 0; i < (rela->sec->sh_size / rela->sec->sh_entsize); i++ )
+    {
+        r = (Elf_RelA *)(rela->data + i * rela->sec->sh_entsize);

Pointless cast bogusly casting away constness.

Quoted 1 line

+ if ( (unsigned long)r > (unsigned long)(elf->hdr + elf->len) )

        if ( (unsigned long)(r + 1) > (unsigned long)elf->hdr + elf->len )
Quoted 10 lines
xen/arch/x86/setup.c +8 -0
+        {
+            dprintk(XENLOG_DEBUG, "%s%s: Relative entry %u in %s is past end!\n",
+                    XSPLICE, elf->name, i, rela->name);
+            return -EINVAL;
+        }
+
+        symndx = ELF64_R_SYM(r->r_info);
+        if ( symndx > elf->nsym )

= (I'm afraid I'll give up pointing out all these off-by-ones - there's

just too many of them. One of you will need to go through all of the code and audit all the checks to actually be correct.)

xen/arch/x86/setup.c

Quoted 7 lines
xen/arch/x86/setup.c +7 -0
+        {
+            dprintk(XENLOG_DEBUG, "%s%s: Relative symbol wants symbol@%u which is past end!\n",
+                    XSPLICE, elf->name, symndx);
+            return -EINVAL;
+        }
+
+        dest = base->load_addr + r->r_offset;

Missing sanity check on r_offset.

xen/arch/x86/setup.c

Quoted 5 lines
xen/arch/x86/setup.c +5 -0
+        val = r->r_addend + elf->sym[symndx].sym->st_value;
+
+        switch ( ELF64_R_TYPE(r->r_info) )
+        {
+            case R_X86_64_NONE:

Too deep indentation.

Quoted 8 lines
xen/arch/x86/setup.c +8 -0
+                break;
+
+            case R_X86_64_64:
+                *(uint64_t *)dest = val;
+                break;
+
+            case R_X86_64_PLT32:
+                /*

xen/arch/x86/setup.c

Quoted 10 lines
xen/arch/x86/setup.c +10 -0
+                 * Xen uses -fpic which normally uses PLT relocations
+                 * except that it sets visibility to hidden which means
+                 * that they are not used.  However, when gcc cannot
+                 * inline memcpy it emits memcpy with default visibility
+                 * which then creates a PLT relocation.  It can just be
+                 * treated the same as R_X86_64_PC32.
+                 */
+                /* Fall through */
+
+            case R_X86_64_PC32:

No need for this second comment or the blank line.

Quoted 1 line

+ *(uint32_t *)dest = val - (uint64_t)dest;

We're dealing with signed quantities here, and the reduction in width requires checking that no truncation occurs.

xen/arch/x86/setup.c

Quoted 5 lines
xen/arch/x86/setup.c +5 -0
+                break;
+
+            default:
+                printk(XENLOG_ERR "%s%s: Unhandled relocation %lu\n",
+                       XSPLICE, elf->name, ELF64_R_TYPE(r->r_info));

Some rate limiting mechanism needs to be used here.

Quoted 1 line

+static find_space_t *find_space_fnc = NULL;

Pointless initializer.

xen/arch/x86/setup.c

Quoted 8 lines
xen/arch/x86/setup.c +8 -0
+void arch_xsplice_register_find_space(find_space_t *cb)
+{
+    ASSERT(!find_space_fnc);
+
+    find_space_fnc = cb;
+}
+
+static void* xsplice_map_rwx(const mfn_t *mfn, unsigned int pages)

Misplaced *.

xen/arch/x86/setup.c

Quoted 8 lines
xen/arch/x86/setup.c +8 -0
+{
+    unsigned long cur;
+    unsigned long start, end;
+
+    start = (unsigned long)avail_virt_start;
+    end = start + pages * PAGE_SIZE;
+
+    ASSERT(find_space_fnc);

I don't think this is a good idea: If not set, we'll immediately have a security issue. Either explicitly return NULL if this is NULL, or make it point to a dummy (returning an error) until registered.

Quoted 1 line

+ if ( find_space_fnc(pages, &start, &end) )

Why both start and end? The latter should be derivable from start and pages.

Quoted 10 lines
xen/arch/x86/setup.c +10 -0
+        return NULL;
+
+    if ( end >= avail_virt_end )
+        return NULL;
+
+    for ( cur = start; pages--; ++mfn, cur += PAGE_SIZE )
+    {
+        /*
+         * We would like to to RX, but we need to copy data in it first.
+         * See arch_xsplice_secure for how we lockdown.

xen/arch/x86/setup.c

Quoted 10 lines
xen/arch/x86/setup.c +10 -0
+         */
+        if ( map_pages_to_xen(cur, mfn_x(*mfn), 1, PAGE_HYPERVISOR_RWX) )
+        {
+            if ( cur != start )
+                destroy_xen_mappings(start, cur);
+            return NULL;
+        }
+    }
+
+    return (void*)start;

Missing blank.

xen/arch/x86/setup.c

Quoted 2 lines
xen/arch/x86/setup.c +2 -0
+int arch_xsplice_secure(void *va, unsigned int pages, enum va_type type,
+                        const mfn_t *mfn)

This and other functions around here: Why arch_*? What prevents them being put in common code?

xen/arch/x86/setup.c struct payload { · line 40

Quoted 13 lines
xen/arch/x86/setup.c +9 -0
@@ -28,6 +29,15 @@ struct payload {
     uint32_t state;                      /* One of the XSPLICE_STATE_*. */
     int32_t rc;                          /* 0 or -XEN_EXX. */
     struct list_head list;               /* Linked to 'payload_list'. */
+    void *text_addr;                     /* Virtual address of .text. */
+    size_t text_size;                    /* .. and its size. */
+    void *rw_addr;                       /* Virtual address of .data. */
+    size_t rw_size;                      /* .. and its size (if any). */
+    void *ro_addr;                       /* Virtual address of .rodata. */
+    size_t ro_size;                      /* .. and its size (if any). */
+    size_t payload_pages;                /* Nr of the pages for the text_addr;
+                                            rw_addr, and ro_addr (if any) */
+    mfn_t *mfn;                          /* Array of MFNs of the pages. */

const (several times)?

Quoted 26 lines
xen/arch/x86/setup.c +26 -0
+static void calc_section(struct xsplice_elf_sec *sec, size_t *size)
+{
+    size_t align_size = ROUNDUP(*size, sec->sec->sh_addralign);
+
+    sec->sec->sh_entsize = align_size;
+    *size = sec->sec->sh_size + align_size;
+}
+
+static int find_hole(size_t pages, unsigned long *hole_start,
+                     unsigned long *hole_end)
+{
+    struct payload *data, *data2;
+
+    spin_lock_recursive(&payload_lock);
+    list_for_each_entry ( data, &payload_list, list )
+    {
+        list_for_each_entry ( data2, &payload_list, list )
+        {
+            unsigned long start, end;
+
+            start = (unsigned long)data2->text_addr;
+            end = start + data2->payload_pages * PAGE_SIZE;
+            if ( *hole_end > start && *hole_start < end )
+            {
+                *hole_start = end;
+                *hole_end = end + pages * PAGE_SIZE;

xen/arch/x86/setup.c struct payload {

Quoted 10 lines
xen/arch/x86/setup.c +10 -0
+                break;
+            }
+        }
+        if ( &data2->list == &payload_list )
+            break;
+    }
+    spin_unlock_recursive(&payload_lock);
+
+    return 0;
+}

How will the caller know you didn't find a hole? If via the value pointed to by the two function arguments, what use is the return value?

Also - how well will this O(n^2) lookup work once there are enough payloads? I think this calls for the alternative vmap() extension I've been suggesting earlier.

Quoted 21 lines
xen/arch/x86/setup.c +21 -0
+static int move_payload(struct payload *payload, struct xsplice_elf *elf)
+{
+    uint8_t *buf;
+    unsigned int i;
+    size_t size = 0;
+
+    /* Compute text regions. */
+    for ( i = 0; i < elf->hdr->e_shnum; i++ )
+    {
+        if ( (elf->sec[i].sec->sh_flags & (SHF_ALLOC|SHF_EXECINSTR)) ==
+             (SHF_ALLOC|SHF_EXECINSTR) )
+            calc_section(&elf->sec[i], &payload->text_size);
+    }
+
+    /* Compute rw data. */
+    for ( i = 0; i < elf->hdr->e_shnum; i++ )
+    {
+        if ( (elf->sec[i].sec->sh_flags & SHF_ALLOC) &&
+             !(elf->sec[i].sec->sh_flags & SHF_EXECINSTR) &&
+             (elf->sec[i].sec->sh_flags & SHF_WRITE) )
+            calc_section(&elf->sec[i], &payload->rw_size);

xen/arch/x86/setup.c

Quoted 10 lines
xen/arch/x86/setup.c +10 -0
+    }
+
+    /* Compute ro data. */
+    for ( i = 0; i < elf->hdr->e_shnum; i++ )
+    {
+        if ( (elf->sec[i].sec->sh_flags & SHF_ALLOC) &&
+             !(elf->sec[i].sec->sh_flags & SHF_EXECINSTR) &&
+             !(elf->sec[i].sec->sh_flags & SHF_WRITE) )
+            calc_section(&elf->sec[i], &payload->ro_size);
+    }

So you handle X, W, and r/o, but you do nothing for WX. If you don#t want to allow for this, you need to error out if there's any such section.

xen/arch/x86/setup.c

Quoted 12 lines
xen/arch/x86/setup.c +12 -0
+    /*
+     * Total of all three regions - RX, RW, and RO. We have to have
+     * keep them in seperate pages so we PAGE_ALIGN the RX and RW to have
+     * them on seperate pages. The last one will by default fall on its
+     * own page.
+     */
+     size = PAGE_ALIGN(payload->text_size) + PAGE_ALIGN(payload->rw_size) +
+            payload->ro_size;
+
+    size = PFN_UP(size);
+    buf = arch_xsplice_alloc_payload(size, &payload->mfn);
+    if ( !buf ) {

Coding style.

Quoted 14 lines
xen/arch/x86/setup.c +14 -0
+        printk(XENLOG_ERR "%s%s: Could not allocate memory for payload!\n",
+               XSPLICE, elf->name);
+        return -ENOMEM;
+    }
+
+    payload->payload_pages = size;
+    payload->text_addr = buf;
+    payload->rw_addr = payload->text_addr + PAGE_ALIGN(payload->text_size);
+    payload->ro_addr = payload->rw_addr + PAGE_ALIGN(payload->rw_size);
+
+    for ( i = 0; i < elf->hdr->e_shnum; i++ )
+    {
+        if ( elf->sec[i].sec->sh_flags & SHF_ALLOC )
+        {

xen/arch/x86/setup.c

Quoted 10 lines
xen/arch/x86/setup.c +10 -0
+            if ( (elf->sec[i].sec->sh_flags & SHF_EXECINSTR) )
+                 buf = payload->text_addr;
+            else if ( (elf->sec[i].sec->sh_flags & SHF_WRITE) )
+                buf = payload->rw_addr;
+             else
+                buf = payload->ro_addr;
+
+            elf->sec[i].load_addr = buf + elf->sec[i].sec->sh_entsize;
+
+            /* Don't copy NOBITS - such as BSS. */

Not copying is correct, but you need to zero these.

xen/arch/x86/setup.c

Quoted 5 lines
xen/arch/x86/setup.c +5 -0
+            if ( elf->sec[i].sec->sh_type != SHT_NOBITS )
+            {
+                memcpy(elf->sec[i].load_addr, elf->sec[i].data,
+                       elf->sec[i].sec->sh_size);
+                dprintk(XENLOG_DEBUG, "%s%s: Loaded %s at 0x%p\n", XSPLICE,

0x%p is bogus.

xen/arch/x86/setup.c

Quoted 9 lines
xen/arch/x86/setup.c +9 -0
+static int secure_payload(struct payload *payload, struct xsplice_elf *elf)
+{
+    int rc;
+    unsigned int text_pages, rw_pages, ro_pages;
+
+    ASSERT(payload->mfn);
+
+    text_pages = PFN_UP(payload->text_size);
+    ASSERT(text_pages);

Where is the earlier check that allows you to ASSERT() here? I anyway wonder whether requiring non-empty .text is really necessary / useful.

xen/arch/x86/setup.c

Quoted 8 lines
xen/arch/x86/setup.c +8 -0
+static int load_payload_data(struct payload *payload, void *raw, ssize_t len)
+{
+    struct xsplice_elf elf;
+    int rc = 0;
+
+    memset(&elf, 0, sizeof(elf));
+    elf.name = payload->name;
+    elf.len = len;

Perhaps better done via initializer?

xen/arch/x86/setup.c static void xsplice_printall(unsigned char key) · line 638

Quoted 7 lines
xen/arch/x86/setup.c +1 -2
@@ -382,8 +635,9 @@ static void xsplice_printall(unsigned char key)
     }
 
     list_for_each_entry ( data, &payload_list, list )
-        printk(" name=%s state=%s(%d)\n", data->name,
-               state2str(data->state), data->state);
+        printk(" name=%s state=%s(%d) %p (.data=%p, .rodata=%p) using %zu pages.\n",

No full stop at the end of log messages please.

Quoted 6 lines
xen/common/xsplice_elf.c +0 -0
@@ -213,6 +213,97 @@ static int elf_get_sym(struct xsplice_elf *elf, const 
 void *data)
     return 0;
 }

xen/common/xsplice_elf.c static int elf_get_sym(struct xsplice_elf *elf, const · line 225

Quoted 10 lines
xen/common/xsplice_elf.c +9 -0
 
+int xsplice_elf_resolve_symbols(struct xsplice_elf *elf)
+{
+    unsigned int i;
+
+    /*
+     * The first entry of an ELF symbol table is the "undefined symbol index".
+     * aka reserved so we skip it.
+     */
+    ASSERT( elf->sym );

Stray blanks.

xen/common/xsplice_elf.c static int elf_get_sym(struct xsplice_elf *elf, const void *data) · line 231

Quoted 7 lines
xen/common/xsplice_elf.c +7 -0
+    for ( i = 1; i < elf->nsym; i++ )
+    {
+        uint16_t idx = elf->sym[i].sym->st_shndx;
+
+        switch ( idx )
+        {
+            case SHN_COMMON:

Too deep indentation.

xen/common/xsplice_elf.c static int elf_get_sym(struct xsplice_elf *elf, const void *data) · line 244

Quoted 13 lines
xen/common/xsplice_elf.c +13 -0
+                printk(XENLOG_ERR "%s%s: Unexpected common symbol: %s\n",
+                       XSPLICE, elf->name, elf->sym[i].name);
+                return -EINVAL;
+                break;
+
+            case SHN_UNDEF:
+                printk(XENLOG_ERR "%s%s: Unknown symbol: %s\n",
+                       XSPLICE, elf->name, elf->sym[i].name);
+                return -ENOENT;
+                break;
+
+            case SHN_ABS:
+                dprintk(XENLOG_DEBUG, "%s%s: Absolute symbol: %s => 0x%"PRIx64"\n",

%# instead of 0x% please.

xen/common/xsplice_elf.c static int elf_get_sym(struct xsplice_elf *elf, const void *data) · line 250

Quoted 6 lines
xen/common/xsplice_elf.c +6 -0
+                      XSPLICE, elf->name, elf->sym[i].name,
+                      elf->sym[i].sym->st_value);
+                break;
+
+            default:
+                if ( elf->sec[idx].sec->sh_flags & SHF_ALLOC )

What if idx is beyond the range of valid section index, namely another of the unhandled values in the reserved range?

xen/common/xsplice_elf.c static int elf_get_sym(struct xsplice_elf *elf, const void *data) · line 257

Quoted 7 lines
xen/common/xsplice_elf.c +7 -0
+                {
+                    elf->sym[i].sym->st_value +=
+                        (unsigned long)elf->sec[idx].load_addr;
+                    if ( elf->sym[i].name )
+                        printk(XENLOG_DEBUG "%s%s: Symbol resolved: %s => 0x%"PRIx64"(%s)\n",
+                               XSPLICE, elf->name, elf->sym[i].name,
+                               (uint64_t)elf->sym[i].sym->st_value,

Instead of casts like this, please introduce ELF-specific format macros.

Quoted 7 lines
xen/common/xsplice_elf.c +7 -0
+int xsplice_elf_perform_relocs(struct xsplice_elf *elf)
+{
+    struct xsplice_elf_sec *rela, *base;
+    unsigned int i;
+    int rc;
+
+    /*

xen/common/xsplice_elf.c static int elf_get_sym(struct xsplice_elf *elf, const void *data) · line 282

Quoted 10 lines
xen/common/xsplice_elf.c +10 -0
+     * The first entry of an ELF symbol table is the "undefined symbol index".
+     * aka reserved so we skip it.
+     */
+    ASSERT( elf->sym );
+    for ( i = 1; i < elf->hdr->e_shnum; i++ )
+    {
+        rela = &elf->sec[i];
+
+        if ( (rela->sec->sh_type != SHT_RELA ) &&
+             (rela->sec->sh_type != SHT_REL ) )

Stray blanks.

Quoted 6 lines
xen/common/xsplice_elf.c +6 -0
+            continue;
+
+         /* Is it a valid relocation section? */
+         if ( rela->sec->sh_info >= elf->hdr->e_shnum )
+            continue;
+

xen/common/xsplice_elf.c static int elf_get_sym(struct xsplice_elf *elf, const void *data) · line 298

Quoted 10 lines
xen/common/xsplice_elf.c +10 -0
+         base = &elf->sec[rela->sec->sh_info];
+
+         /* Don't relocate non-allocated sections. */
+         if ( !(base->sec->sh_flags & SHF_ALLOC) )
+            continue;
+
+        if ( elf->sec[i].sec->sh_type == SHT_RELA )
+            rc = arch_xsplice_perform_rela(elf, base, rela);
+        else /* SHT_REL */
+            rc = arch_xsplice_perform_rel(elf, base, rela);

Please at least validate sh_link somewhere above.

xen/include/xen/xsplice_elf.h struct xsplice_elf_sec { · line 19

Quoted 8 lines
xen/include/xen/xsplice_elf.h +2 -0
@@ -15,6 +15,8 @@ struct xsplice_elf_sec {
                                       elf_resolve_section_names. */
     const void *data;              /* Pointer to the section (done by
                                       elf_resolve_sections). */
+    uint8_t *load_addr;            /* A pointer to the allocated destination.
+                                      Done by load_payload_data. */

void perhaps? And const?

xen/include/xen/xsplice_elf.h struct xsplice_elf_sec *xsplice_elf_sec_by_name(const struct xsplice_elf *elf, · line 44

Quoted 6 lines
xen/include/xen/xsplice_elf.h +2 -0
@@ -38,6 +40,9 @@ struct xsplice_elf_sec *xsplice_elf_sec_by_name(const struct xsplice_elf *elf,
 int xsplice_elf_load(struct xsplice_elf *elf, void *data);
 void xsplice_elf_free(struct xsplice_elf *elf);
 
+int xsplice_elf_resolve_symbols(struct xsplice_elf *elf);
+int xsplice_elf_perform_relocs(struct xsplice_elf *elf);

const?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#75 lore raw

Re: [PATCH v5 10/28] xsplice: Implement payload loading

Quoted 3 lines

Also - how well will this O(n^2) lookup work once there are enough payloads? I think this calls for the alternative vmap() extension I've been suggesting earlier.

Could you elaborate on the vmap extension a bit please?

Your earlier email seems to say: drop the vmap API and just allocate the underlaying pages yourself.

Such as:
http://xenbits.xen.org/gitweb/?p=people/konradwilk/xen.git;a=blobdiff;f=xen/common/xsplice.c;h=fbd6129bd362a9034db9da495c5cd5e80c367541;hp=125d9b8eee995c7321dce4baa866d4bcac8eaa36;hb=b9bba0be36caf2e00734689765f15f2b8a529bb0;hpb=d8f5dba5e0ac65163576db65ae92e3e59a5dedd1

(see the alloc_payload function)?

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#76 lore raw

Re: [PATCH v5 10/28] xsplice: Implement payload loading

Quoted 9 lines
Quoted 4 lines
Quoted 1 line · On 31.03.16 at 23:26, <[email protected]> wrote:

Also - how well will this O(n^2) lookup work once there are enough
payloads? I think this calls for the alternative vmap() extension I've been suggesting earlier.

Could you elaborate on the vmap extension a bit please?

Your earlier email seems to say: drop the vmap API and just allocate the underlaying pages yourself.

Actually I had also said in that earlier mail: "If, otoh, you left that VA management to (an extended version of) vmap(), by e.g. allowing the caller to request allocation from a different VA range (much like iirc x86-64 Linux handles its modules address range allocation), things would be different. After all the VA management is the important part here, while the backing memory allocation is just a trivial auxiliary operation."

I.e. elaboration here really just consists of the referral to the respective Linux approach.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#77 lore raw

Re: [PATCH v5 10/28] xsplice: Implement payload loading

Quoted 18 lines · Jan Beulich
Quoted 9 lines
Quoted 4 lines
Quoted 1 line · On 31.03.16 at 23:26, <[email protected]> wrote:

Also - how well will this O(n^2) lookup work once there are enough
payloads? I think this calls for the alternative vmap() extension I've been suggesting earlier.

Could you elaborate on the vmap extension a bit please?

Your earlier email seems to say: drop the vmap API and just allocate the underlaying pages yourself.

Actually I had also said in that earlier mail: "If, otoh, you left that VA management to (an extended version of) vmap(), by e.g. allowing the caller to request allocation from a different VA range (much like iirc x86-64 Linux handles its modules address range allocation), things would be different. After all the VA management is the important part here, while the backing memory allocation is just a trivial auxiliary operation."

Quoted 2 lines

I.e. elaboration here really just consists of the referral to the respective Linux approach.

I am in need here of guidance I am afraid.

Let me explain (did this in IRC but this will have a broader scope):

In Linux we have the 'struct vm_area' which internally contains the start and end address (amongst other things). The callers usually use __vmalloc_node_range to an provide those addresses. Internally the vmalloc API allocates the 'struct vm_area' from the normal SLAB allocator. Vmalloc API also has an vmap block area (allocated within vmalloc area) which is a red and black tree for all the users of its API. When vm_size() is called this tree is searched to find the 'vm_area' for the provided virtual address. There is a lot of code in this. Copying it and jamming does not look easy so it would be better to take concepts of this an implement this..

On Xen we setup a bitmap that covers the full vmalloc area (128MB on my 4GB box, but can go up to 64GB) - the 128MB vmalloc area requires about 32K bits.

For every allocation we "waste" an page (and a bit) so that there is a gap. This gap is needed when trying to to determine the size of the allocated region - when scanning the bitmap we can easily figure out the cleared bit which is akin to a fencepost.

To make Xen's vmalloc API be generic I need to wholesale make it able to deal with virtual addresses that are not part of its space (as in not in VMAP_VIRT_START to vm_top). At the start I the input to vm_size() needs to get the size of the virtual address (either the ones from the vmalloc areas or the ones provided earlier by vmalloc_cb).

One easy mechanism is to embedded an array of simplified 'struct vm_area' structure:

struct vm_area {
	unsigned long va;
}

for every slot in the VMAP_VIRT_START area (that is have 32K entries). The vm_size and all the rest can check for this array if the virtual address provided is not within the vmalloc virtual addresses. If there is a match we just need to consult the vm_bitmap at the same index and figure out where the empty bit is set.
The downside is that I've to walk the full array (32K entries).

But when you think about it - most of the time we use normal vmalloc addresses and only in exceptional cases do we need the alternate ones. And the only reason to keep track of it is to know the size.

The easier way would be to track them via a linked list:

struct vm_area {
	struct list_head list;
	unsigned long va;
	size_t nr;
}

And vm_size, vm_index, etc would consult this list for the virtual address and could get the proper information. (See inline patch)

But if we are doing that this, then why even put it in the vmalloc API? Why not track all of this with the user of this? (like it was done in v4 of this patch series?)

Please advise.

From a0e3015bbf4d99fc8e5428634dc3b281cf8eedb7 Mon Sep 17 00:00:00 2001
From: Konrad Rzeszutek Wilk <[email protected]>
Date: Mon, 14 Mar 2016 12:02:05 -0400
Subject: [PATCH] vmap: Add vmalloc_cb

For those users who want to supply their own vmap callback. This callback will be called _after_ the pages have been allocated and instead of using the vmap internal API, it will call the callback which will be responsible for providing the virtual addresses.

The vmap API also keeps track of this virtual address (along with the size) so that vunmap, vm_size, and vm_free can operate on these virtual addresses.

This allows users (such as xSplice) to provide their own mechanism to change the the page flags, and also use virtual addresses closer to the hypervisor virtual addresses (at least on x86).

The users (such as patch titled "xsplice: Implement payload loading") can wrap the calls to __vmap for this.

Note that the displacement of the hypervisor virtual addresses to the vmalloc (on x86) is more than 32-bits - which means that ELF relocations (which are limited to 32-bits) - won't work (we truncate the 34 and 33th bit). Hence we cannot use on vmalloc virtual addresses but must supply our own ranges.

---
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Tim Deegan <[email protected]>

v4: New patch.
v5: Update per Jan's comments.
v6: Drop the stray parentheses on typedefs.
Ditch the vunmap callback. Stash away the virtual addresses in lists.
---

---
 xen/common/vmap.c      | 80 ++++++++++++++++++++++++++++++++++++++++++++++++--
 xen/include/xen/vmap.h |  5 ++++
 2 files changed, 82 insertions(+), 3 deletions(-)
xen/common/vmap.c +77 -3
index 134eda0..0289e22 100644
@@ -19,6 +19,16 @@ static unsigned int __read_mostly vm_end;
 /* lowest known clear bit in the bitmap */
 static unsigned int vm_low;
 
+static LIST_HEAD(vm_area_list);
+
+struct vm_area {
+    struct list_head list;
+    void *va;
+    unsigned int pages;
+};
+
+static DEFINE_SPINLOCK(vm_area_lock);
+
 void __init vm_init(void)
 {
     unsigned int i, nr;
@@ -146,12 +156,34 @@ static unsigned int vm_index(const void *va)
            test_bit(idx, vm_bitmap) ? idx : 0;
 }
 
+static const struct vm_area *vm_find(const void *va)
+{
+    const struct vm_area *found = NULL, *vm;
+
+    spin_lock(&vm_area_lock);
+    list_for_each_entry( vm, &vm_area_list, list )
+    {
+        if ( vm->va != va )
+            continue;
+        found = vm;
+        break;
+    }
+    spin_unlock(&vm_area_lock);
+
+    return found;
+}
+
 static unsigned int vm_size(const void *va)
 {
     unsigned int start = vm_index(va), end;
 
     if ( !start )
+    {
+        const struct vm_area *vm = vm_find(va);
+        if ( vm )
+            return vm->pages;
         return 0;
+    }
 
     end = find_next_zero_bit(vm_bitmap, vm_top, start + 1);
 
@@ -164,6 +196,16 @@ void vm_free(const void *va)
 
     if ( !bit )
     {
+        struct vm_area *vm = (struct vm_area *)vm_find(va);
+
+        if ( vm )
+        {
+            spin_lock(&vm_area_lock);
+            list_del(&vm->list);
+            spin_unlock(&vm_area_lock);
+            xfree(vm);
+            return;
+        }
         WARN_ON(va != NULL);
         return;
     }
@@ -216,12 +258,13 @@ void vunmap(const void *va)
     vm_free(va);
 }
 
-void *vmalloc(size_t size)
+void *vmalloc_cb(size_t size, vmap_cb_t *vmap_cb, mfn_t **mfn_array)
 {
     mfn_t *mfn;
     size_t pages, i;
     struct page_info *pg;
     void *va;
+    struct vm_area *vm = NULL;
 
     ASSERT(size);
 
@@ -230,6 +273,17 @@ void *vmalloc(size_t size)
     if ( mfn == NULL )
         return NULL;
 
+    if ( vmap_cb )
+    {
+        vm = xmalloc(struct vm_area);
+
+        if ( !vm )
+        {
+            xfree(mfn);
+            return NULL;
+        }
+    }
+
     for ( i = 0; i < pages; i++ )
     {
         pg = alloc_domheap_page(NULL, 0);
@@ -238,20 +292,40 @@ void *vmalloc(size_t size)
         mfn[i] = _mfn(page_to_mfn(pg));
     }
 
-    va = vmap(mfn, pages);
+    va = vmap_cb ? vmap_cb(mfn, pages) : vmap(mfn, pages);
     if ( va == NULL )
         goto error;
 
-    xfree(mfn);
+    if ( vm )
+    {
+        vm->va = va;
+        vm->pages = pages;
+
+        spin_lock(&vm_area_lock);
+        list_add(&vm->list, &vm_area_list);
+        spin_unlock(&vm_area_lock);
+    }
+    if ( mfn_array )
+        *mfn_array = mfn;
+    else
+        xfree(mfn);
+
     return va;
 
  error:
     while ( i-- )
         free_domheap_page(mfn_to_page(mfn_x(mfn[i])));
     xfree(mfn);
+    if ( vm )
+        xfree(vm);
     return NULL;
 }
 
+void *vmalloc(size_t size)
+{
+    return vmalloc_cb(size, NULL, NULL);
+}
+
 void *vzalloc(size_t size)
 {
     void *p = vmalloc(size);
xen/include/xen/vmap.h +5 -0
index 5671ac8..6cd0707 100644
@@ -12,6 +12,11 @@ void *__vmap(const mfn_t *mfn, unsigned int granularity,
 void *vmap(const mfn_t *mfn, unsigned int nr);
 void vunmap(const void *);
 void *vmalloc(size_t size);
+
+/* Callback for vmalloc_cb to use when vmap-ing. */
+typedef void *vmap_cb_t(const mfn_t *mfn, unsigned int pages);
+void *vmalloc_cb(size_t size, vmap_cb_t *vmap_cb, mfn_t **);
+
 void *vzalloc(size_t size);
 void vfree(void *va);
 
Signature · 7 lines
2.5.0


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#78 lore raw

Re: [PATCH v5 10/28] xsplice: Implement payload loading

Quoted 78 lines · Konrad Rzeszutek Wilk
Quoted 18 lines · Jan Beulich
Quoted 9 lines
Quoted 4 lines
Quoted 1 line · On 31.03.16 at 23:26, <[email protected]> wrote:

Also - how well will this O(n^2) lookup work once there are enough
payloads? I think this calls for the alternative vmap() extension I've been suggesting earlier.

Could you elaborate on the vmap extension a bit please?

Your earlier email seems to say: drop the vmap API and just allocate the underlaying pages yourself.

Actually I had also said in that earlier mail: "If, otoh, you left that VA management to (an extended version of) vmap(), by e.g. allowing the caller to request allocation from a different VA range (much like iirc x86-64 Linux handles its modules address range allocation), things would be different. After all the VA management is the important part here, while the backing memory allocation is just a trivial auxiliary operation."

Quoted 2 lines

I.e. elaboration here really just consists of the referral to the respective Linux approach.

I am in need here of guidance I am afraid.

Let me explain (did this in IRC but this will have a broader scope):

In Linux we have the 'struct vm_area' which internally contains the start and end address (amongst other things). The callers usually use __vmalloc_node_range to an provide those addresses. Internally the vmalloc API allocates the 'struct vm_area' from the normal SLAB allocator. Vmalloc API also has an vmap block area (allocated within vmalloc area) which is a red and black tree for all the users of its API. When vm_size() is called this tree is searched to find the 'vm_area' for the provided virtual address. There is a lot of code in this. Copying it and jamming does not look easy so it would be better to take concepts of this an implement this..

On Xen we setup a bitmap that covers the full vmalloc area (128MB on my 4GB box, but can go up to 64GB) - the 128MB vmalloc area requires about 32K bits.

For every allocation we "waste" an page (and a bit) so that there is a gap. This gap is needed when trying to to determine the size of the allocated region - when scanning the bitmap we can easily figure out the cleared bit which is akin to a fencepost.

To make Xen's vmalloc API be generic I need to wholesale make it able to deal with virtual addresses that are not part of its space (as in not in VMAP_VIRT_START to vm_top). At the start I the input to vm_size() needs to get the size of the virtual address (either the ones from the vmalloc areas or the ones provided earlier by vmalloc_cb).

One easy mechanism is to embedded an array of simplified 'struct vm_area' structure:

struct vm_area {
	unsigned long va;
}

for every slot in the VMAP_VIRT_START area (that is have 32K entries). The vm_size and all the rest can check for this array if the virtual address provided is not within the vmalloc virtual addresses. If there is a match we just need to consult the vm_bitmap at the same index and figure out where the empty bit is set.
The downside is that I've to walk the full array (32K entries).

But when you think about it - most of the time we use normal vmalloc addresses and only in exceptional cases do we need the alternate ones. And the only reason to keep track of it is to know the size.

The easier way would be to track them via a linked list:

struct vm_area {
	struct list_head list;
	unsigned long va;
	size_t nr;
}
Quoted 7 lines

And vm_size, vm_index, etc would consult this list for the virtual address and could get the proper information. (See inline patch)

But if we are doing that this, then why even put it in the vmalloc API? Why not track all of this with the user of this? (like it was done in v4 of this patch series?)

Please advise.

I re-read your previous email and I think you were leaning towards not even having a callback but rather supplying the virtual address to the vmalloc APIs and it tracking it afterwards. Like this:

From 738ed247bf214a061c6822ad183c365a4f5731b9 Mon Sep 17 00:00:00 2001
From: Konrad Rzeszutek Wilk <[email protected]>
Date: Mon, 14 Mar 2016 12:02:05 -0400
Subject: [PATCH] vmap: Add vmalloc_range

For those users who want to supply their own virtual address for which to allocate the underlaying pages.

The vmap API also keeps track of this virtual address (along with the size) so that vunmap, vm_size, and vm_free can operate on these virtual addresses.

This allows users (such as xSplice) to provide their own mechanism to change the the page flags, and also use virtual addresses closer to the hypervisor virtual addresses (at least on x86) while not having to deal with the allocation of pages.

For example of users, see patch titled "xsplice: Implement payload loading".

Note that the displacement of the hypervisor virtual addresses to the vmalloc (on x86) is more than 32-bits - which means that ELF relocations (which are limited to 32-bits) - won't work (we truncate the 34 and 33th bit). Hence we cannot use on vmalloc virtual addresses but must supply our own ranges.

---
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Tim Deegan <[email protected]>

v4: New patch.
v5: Update per Jan's comments.
v6: Drop the stray parentheses on typedefs.
Ditch the vunmap callback. Stash away the virtual addresses in lists. Ditch the vmap callback. Just provide virtual address.
---

---
 xen/common/vmap.c      | 104 +++++++++++++++++++++++++++++++++++++++++++++++++
 xen/include/xen/vmap.h |  10 +++++
 2 files changed, 114 insertions(+)
xen/common/vmap.c +104 -0
index 134eda0..b63886b 100644
@@ -19,6 +19,10 @@ static unsigned int __read_mostly vm_end;
 /* lowest known clear bit in the bitmap */
 static unsigned int vm_low;
 
+static LIST_HEAD(vm_area_list);
+
+static DEFINE_SPINLOCK(vm_area_lock);
+
 void __init vm_init(void)
 {
     unsigned int i, nr;
@@ -146,12 +150,34 @@ static unsigned int vm_index(const void *va)
            test_bit(idx, vm_bitmap) ? idx : 0;
 }
 
+static const struct vm_area *vm_find(const void *va)
+{
+    const struct vm_area *found = NULL, *vm;
+
+    spin_lock(&vm_area_lock);
+    list_for_each_entry( vm, &vm_area_list, list )
+    {
+        if ( vm->va != va )
+            continue;
+        found = vm;
+        break;
+    }
+    spin_unlock(&vm_area_lock);
+
+    return found;
+}
+
 static unsigned int vm_size(const void *va)
 {
     unsigned int start = vm_index(va), end;
 
     if ( !start )
+    {
+        const struct vm_area *vm = vm_find(va);
+        if ( vm )
+            return vm->pages;
         return 0;
+    }
 
     end = find_next_zero_bit(vm_bitmap, vm_top, start + 1);
 
@@ -164,6 +190,17 @@ void vm_free(const void *va)
 
     if ( !bit )
     {
+        struct vm_area *vm = (struct vm_area *)vm_find(va);
+
+        if ( vm )
+        {
+            spin_lock(&vm_area_lock);
+            list_del(&vm->list);
+            spin_unlock(&vm_area_lock);
+            xfree(vm->mfn);
+            xfree(vm);
+            return;
+        }
         WARN_ON(va != NULL);
         return;
     }
@@ -199,6 +236,23 @@ void *__vmap(const mfn_t *mfn, unsigned int granularity,
     return va;
 }
 
+static bool_t vmap_range(const mfn_t *mfn, unsigned long va, unsigned int nr)
+{
+    unsigned long cur = va;
+
+    for ( ; va && nr--; ++mfn, cur += PAGE_SIZE )
+    {
+        if ( map_pages_to_xen(cur, mfn_x(*mfn), 1, PAGE_HYPERVISOR) )
+        {
+            if ( cur != va )
+                destroy_xen_mappings(va, cur);
+            return 0;
+        }
+    }
+
+    return 1;
+}
+
 void *vmap(const mfn_t *mfn, unsigned int nr)
 {
     return __vmap(mfn, 1, nr, 1, PAGE_HYPERVISOR);
@@ -216,6 +270,56 @@ void vunmap(const void *va)
     vm_free(va);
 }
 
+struct vm_area *vmalloc_range(size_t size, unsigned long start)
+{
+    mfn_t *mfn;
+    size_t pages, i;
+    struct page_info *pg;
+    struct vm_area *vm = NULL;
+
+    ASSERT(size);
+
+    pages = PFN_UP(size);
+    mfn = xmalloc_array(mfn_t, pages);
+    if ( mfn == NULL )
+        return NULL;
+
+    vm = xmalloc(struct vm_area);
+    if ( !vm )
+    {
+        xfree(mfn);
+        return NULL;
+    }
+    vm->mfn = mfn;
+
+    for ( i = 0; i < pages; i++ )
+    {
+        pg = alloc_domheap_page(NULL, 0);
+        if ( pg == NULL )
+            goto error;
+        mfn[i] = _mfn(page_to_mfn(pg));
+    }
+
+    if ( !vmap_range(mfn, start, pages) )
+        goto error;
+
+    vm->va = (void *)start;
+    vm->pages = pages;
+
+    spin_lock(&vm_area_lock);
+    list_add(&vm->list, &vm_area_list);
+    spin_unlock(&vm_area_lock);
+
+    return vm;
+
+ error:
+    while ( i-- )
+        free_domheap_page(mfn_to_page(mfn_x(mfn[i])));
+    xfree(vm->mfn);
+    xfree(vm);
+    return NULL;
+}
+
 void *vmalloc(size_t size)
 {
     mfn_t *mfn;
xen/include/xen/vmap.h +10 -0
index 5671ac8..4c9a350 100644
@@ -12,6 +12,16 @@ void *__vmap(const mfn_t *mfn, unsigned int granularity,
 void *vmap(const mfn_t *mfn, unsigned int nr);
 void vunmap(const void *);
 void *vmalloc(size_t size);
+
+struct vm_area {
+    struct list_head list;
+    mfn_t *mfn;
+    void *va;
+    unsigned int pages;
+};
+
+struct vm_area *vmalloc_range(size_t size, unsigned long start);
+
 void *vzalloc(size_t size);
 void vfree(void *va);
 
Signature · 7 lines
2.5.0


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#79 lore raw

Re: [PATCH v5 10/28] xsplice: Implement payload loading

In reply to Konrad Rzeszutek Wilk
Quoted 88 lines
Quoted 1 line
Quoted 1 line · On 04.04.16 at 21:44, <[email protected]> wrote:
Quoted 18 lines · Jan Beulich
Quoted 9 lines
Quoted 4 lines
Quoted 1 line · On 31.03.16 at 23:26, <[email protected]> wrote:

Also - how well will this O(n^2) lookup work once there are enough
payloads? I think this calls for the alternative vmap() extension I've been suggesting earlier.

Could you elaborate on the vmap extension a bit please?

Your earlier email seems to say: drop the vmap API and just allocate the underlaying pages yourself.

Actually I had also said in that earlier mail: "If, otoh, you left that VA management to (an extended version of) vmap(), by e.g. allowing the caller to request allocation from a different VA range (much like iirc x86-64 Linux handles its modules address range allocation), things would be different. After all the VA management is the important part here, while the backing memory allocation is just a trivial auxiliary operation."

Quoted 2 lines

I.e. elaboration here really just consists of the referral to the respective Linux approach.

I am in need here of guidance I am afraid.

Let me explain (did this in IRC but this will have a broader scope):

In Linux we have the 'struct vm_area' which internally contains the start and end address (amongst other things). The callers usually use __vmalloc_node_range
to an provide those addresses. Internally the vmalloc API allocates the 'struct vm_area' from the normal SLAB allocator. Vmalloc API also has an vmap block area (allocated within vmalloc area) which is a red and black tree
for all the users of its API. When vm_size() is called this tree is searched to find the 'vm_area' for the provided virtual address. There is a lot of code in this. Copying it and jamming does not look easy so it would be better to take concepts of this an implement this..

On Xen we setup a bitmap that covers the full vmalloc area (128MB on my 4GB box, but can go up to 64GB) - the 128MB vmalloc area requires about 32K bits.

For every allocation we "waste" an page (and a bit) so that there is a gap. This gap is needed when trying to to determine the size of the allocated region - when scanning the bitmap we can easily figure out the cleared bit which is akin to a fencepost.

To make Xen's vmalloc API be generic I need to wholesale make it able to deal with virtual addresses that are not part of its space (as in not in VMAP_VIRT_START to vm_top). At the start I the input to vm_size() needs to get the size of the virtual address (either the ones from the vmalloc areas or the ones provided earlier by vmalloc_cb).

One easy mechanism is to embedded an array of simplified 'struct vm_area' structure:

struct vm_area {
	unsigned long va;
}

for every slot in the VMAP_VIRT_START area (that is have 32K entries). The vm_size and all the rest can check for this array if the virtual address provided is not within the vmalloc virtual addresses. If there is a match we just need to consult the vm_bitmap at the same index and figure out where the empty bit is set.
The downside is that I've to walk the full array (32K entries).

But when you think about it - most of the time we use normal vmalloc addresses
and only in exceptional cases do we need the alternate ones. And the only reason
to keep track of it is to know the size.

The easier way would be to track them via a linked list:

struct vm_area {
	struct list_head list;
	unsigned long va;
	size_t nr;
}

And vm_size, vm_index, etc would consult this list for the virtual address and
could get the proper information. (See inline patch)

Quoted 6 lines

But if we are doing that this, then why even put it in the vmalloc API? Why not
track all of this with the user of this? (like it was done in v4 of this patch series?)

Please advise.

Well, I certainly didn't think of it getting done that way. To me the most natural generalization would be for an arch to register one or more secondary ranges (which could even get referred to by an enum) at boot time (or maybe that could even be arranged for at compile time, i.e. no active registration necessary), with each such area getting the same data structures set up as is being done right now for the "base" VA range.

But if that's too cumbersome for now, I'm certainly fine with xSplice code dealing with the VA management itself. We can always add such an extension later (and then make xSplice use it).

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#80 lore raw

Re: [PATCH v5 10/28] xsplice: Implement payload loading

Quoted 7 lines
Quoted 1 line

Please advise.

Well, I certainly didn't think of it getting done that way. To me the most natural generalization would be for an arch to register one or more secondary ranges (which could even get referred to by an enum) at boot time (or maybe that could even be arranged for at compile time, i.e. no active registration necessary), with each such

The start of this region - xen_virt_end is computed during boottime so part of this is will be runtime.

Quoted 2 lines

area getting the same data structures set up as is being done right now for the "base" VA range.

That actually ended up pretty simple. It won't compile for ARM yet, see below please.

Quoted 4 lines

But if that's too cumbersome for now, I'm certainly fine with xSplice code dealing with the VA management itself. We can always add such an extension later (and then make xSplice use it).

From 45906039b18f1995b26c97b560244ac90308597f Mon Sep 17 00:00:00 2001
From: Konrad Rzeszutek Wilk <[email protected]>
Date: Mon, 14 Mar 2016 12:02:05 -0400
Subject: [RFC PATCH] vmap: Add vmalloc_type WIP

TODO:
- Check what happens on !CONFIG_XSPLICE
- Move arch specific to arch specific (and make it compile under ARM)

For those users who want to use the virtual addresses that are in the hypervisor's virtual address space - this new function allows that. Along with providing the underlaying MFNs for the user's (such as changing page table permissions).

Implementation wise the vmap API keeps track of two virtual address regions now:
a) VMAP_VIRT_START
b) xen_virt_end up to XEN_VIRT_END (minus some other space).

The a) one is the default one and the existing behavior for users of vmalloc, vmap, etc is the same.

If however one wishes to use the b) one only has to use the vmalloc_type API on these virtual addresses.

This allows users (such as xSplice) to provide their own mechanism to change the the page flags, and also use virtual addresses closer to the hypervisor virtual addresses (at least on x86) while not having to deal with the allocation of pages.

For example of users, see patch titled "xsplice: Implement payload loading", where we parse the payload's ELF relocations - which is defined to be signed 32-bit (so max displacement is 2GB virtual spacE). The displacement of the hypervisor virtual addresses to the vmalloc (on x86) is more than 32-bits - which means that ELF relocations would truncate the 34 and 33th bit. Hence this alternate API

Since there is only one user of this - it is conditional on CONFIG_XSPLICE - and the generic vmalloc code had added checks in case the b) range has not been initialized.

---
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Tim Deegan <[email protected]>

v4: New patch.
v5: Update per Jan's comments.
v6: Drop the stray parentheses on typedefs.
Ditch the vunmap callback. Stash away the virtual addresses in lists. Ditch the vmap callback. Just provide virtual address. Ditch the vmalloc_range. Allocate on startup the vmalloc[XEN_VIRT] ranges.
---

---
 xen/arch/x86/mm.c                 |   2 +-
 xen/arch/x86/setup.c              |   3 +
 xen/common/vmap.c                 | 194 +++++++++++++++++++++++++-------------
 xen/drivers/acpi/osl.c            |   2 +-
 xen/include/asm-x86/x86_64/page.h |   2 +
 xen/include/xen/vmap.h            |  15 ++-
 6 files changed, 148 insertions(+), 70 deletions(-)
xen/arch/x86/mm.c +1 -1
index bca7532..6fa9208 100644
@@ -6124,7 +6124,7 @@ void __iomem *ioremap(paddr_t pa, size_t len)
         unsigned int offs = pa & (PAGE_SIZE - 1);
         unsigned int nr = PFN_UP(offs + len);
 
-        va = __vmap(&mfn, nr, 1, 1, PAGE_HYPERVISOR_NOCACHE) + offs;
+        va = __vmap(&mfn, nr, 1, 1, PAGE_HYPERVISOR_NOCACHE, VMAP_VIRT) + offs;
     }
 
     return (void __force __iomem *)va;
xen/arch/x86/setup.c +3 -0
index 0b4f94f..9b502b6 100644
@@ -100,6 +100,9 @@ unsigned long __read_mostly xen_phys_start;
 
 unsigned long __read_mostly xen_virt_end;
 
+unsigned long __read_mostly avail_virt_start;
+unsigned long __read_mostly avail_virt_end;
+
 DEFINE_PER_CPU(struct tss_struct, init_tss);
 
 char __section(".bss.stack_aligned") cpu0_stack[STACK_SIZE];
xen/common/vmap.c +128 -66

345 lines not on this page · raw message

xen/drivers/acpi/osl.c +1 -1
index 8a28d87..66bec78 100644
@@ -97,7 +97,7 @@ acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
 		if (IS_ENABLED(CONFIG_X86) && !((phys + size - 1) >> 20))
 			return __va(phys);
 		return __vmap(&mfn, PFN_UP(offs + size), 1, 1,
-			      ACPI_MAP_MEM_ATTR) + offs;
+			      ACPI_MAP_MEM_ATTR, VMAP_VIRT) + offs;
 	}
 	return __acpi_map_table(phys, size);
 }
xen/include/asm-x86/x86_64/page.h +2 -0
index 86abb94..a854e05 100644
@@ -38,6 +38,8 @@
 #include <xen/pdx.h>
 
 extern unsigned long xen_virt_end;
+extern unsigned long avail_virt_start;
+extern unsigned long avail_virt_end;
 
 #define spage_to_pdx(spg) (((spg) - spage_table)<<(SUPERPAGE_SHIFT-PAGE_SHIFT))
 #define pdx_to_spage(pdx) (spage_table + ((pdx)>>(SUPERPAGE_SHIFT-PAGE_SHIFT)))
xen/include/xen/vmap.h +13 -2
index 5671ac8..492d3e7 100644
@@ -4,14 +4,25 @@
 #include <xen/mm.h>
 #include <asm/page.h>
 
+/* These two functions operate only on VMAP_VIRT address space. */
 void *vm_alloc(unsigned int nr, unsigned int align);
 void vm_free(const void *);
 
-void *__vmap(const mfn_t *mfn, unsigned int granularity,
-             unsigned int nr, unsigned int align, unsigned int flags);
+enum vmap_type {
+    VMAP_VIRT,
+    XEN_VIRT,
+    VMAP_TYPE_MAX,
+};
+
+void *__vmap(const mfn_t *mfn, unsigned int granularity, unsigned int nr,
+             unsigned int align, unsigned int flags, enum vmap_type);
 void *vmap(const mfn_t *mfn, unsigned int nr);
 void vunmap(const void *);
+/* Only operates on VMAP_VIRT. */
 void *vmalloc(size_t size);
+
+void *vmalloc_type(size_t size, enum vmap_type type, mfn_t **mfn_array);
+
 void *vzalloc(size_t size);
 void vfree(void *va);
 
Signature · 7 lines
2.4.3


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#81 lore raw

Re: [PATCH v5 10/28] xsplice: Implement payload loading

Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 05.04.16 at 17:50, <[email protected]> wrote:

That actually ended up pretty simple. It won't compile for ARM yet, see below please.

This comes pretty close. A few minor comments below.

xen/arch/x86/setup.c unsigned long __read_mostly xen_phys_start; · line 104

Quoted 8 lines
xen/arch/x86/setup.c +2 -0
@@ -100,6 +100,9 @@ unsigned long __read_mostly xen_phys_start;
 
 unsigned long __read_mostly xen_virt_end;
 
+unsigned long __read_mostly avail_virt_start;
+unsigned long __read_mostly avail_virt_end;

These now appear to be unused.

Quoted 43 lines
xen/arch/x86/setup.c +21 -9
-void __init vm_init(void)
+void __init vm_init_type(enum vmap_type type)
 {
     unsigned int i, nr;
     unsigned long va;
+    void *end;
+
+    if ( type == VMAP_VIRT )
+    {
+        vm_base[VMAP_VIRT] = (void *)VMAP_VIRT_START;
+        end = arch_vmap_virt_end();
+    }
+    else
+    {
+        vm_base[XEN_VIRT] = (void *)xen_virt_end;
+        end = (void *)(XEN_VIRT_END - NR_CPUS * PAGE_SIZE);
 
-    vm_base = (void *)VMAP_VIRT_START;
-    vm_end = PFN_DOWN(arch_vmap_virt_end() - vm_base);
-    vm_low = PFN_UP((vm_end + 7) / 8);
-    nr = PFN_UP((vm_low + 7) / 8);
-    vm_top = nr * PAGE_SIZE * 8;
+        BUG_ON(end <= vm_base[XEN_VIRT]);
+    }
+    vm_end[type] = PFN_DOWN(end - vm_base[type]);
+    vm_low[type]= PFN_UP((vm_end[type] + 7) / 8);
+    nr = PFN_UP((vm_low[type] + 7) / 8);
+    vm_top[type] = nr * PAGE_SIZE * 8;
 
-    for ( i = 0, va = (unsigned long)vm_bitmap; i < nr; ++i, va += PAGE_SIZE )
+    for ( i = 0, va = (unsigned long)vm_bitmap(type); i < nr; ++i, va += PAGE_SIZE )
     {
         struct page_info *pg = alloc_domheap_page(NULL, 0);
 
         map_pages_to_xen(va, page_to_mfn(pg), 1, PAGE_HYPERVISOR);
         clear_page((void *)va);
     }
-    bitmap_fill(vm_bitmap, vm_low);
+    bitmap_fill(vm_bitmap(type), vm_low[type]);
 
     /* Populate page tables for the bitmap if necessary. */
-    populate_pt_range(va, 0, vm_low - nr);
+    populate_pt_range(va, 0, vm_low[type] - nr);

xen/arch/x86/setup.c unsigned long __read_mostly xen_phys_start;

Quoted 10 lines
xen/arch/x86/setup.c +7 -1
 }
 
-void *vm_alloc(unsigned int nr, unsigned int align)
+void __init vm_init(void)
+{
+    vm_init_type(VMAP_VIRT);
+#ifdef CONFIG_XSPLICE
+    vm_init_type(XEN_VIRT);
+#endif
+}

I think we should leave it to the arch to call vm_init_type() for the non-default type(s) it cares about, namely allowing for this to be done at a different (later) time. Which means vm_init() could simply become an inline/macro wrapper of vm_init_type(VMAP_VIRT).

xen/arch/x86/setup.c

Quoted 4 lines
xen/arch/x86/setup.c +4 -0
+void *vm_alloc(unsigned int nr, unsigned int align)
+{
+    return vm_alloc_type(nr, align, VMAP_VIRT);
+}

Inline/macro wrapper?

xen/arch/x86/setup.c

Quoted 4 lines
xen/arch/x86/setup.c +4 -0
+void vm_free(const void *va)
+{
+    vm_free_type(va, VMAP_VIRT);
+}

Again.

xen/arch/x86/setup.c

Quoted 13 lines

void vunmap(const void *va)
{

xen/arch/x86/setup.c +11 -0
+    enum vmap_type type = VMAP_VIRT;
+    unsigned int size = vm_size(va, type);
+#ifndef _PAGE_NONE
+    unsigned long addr;
+#endif
+
+    if ( !size )
+    {
+        type = XEN_VIRT;
+        size = vm_size(va, type);
+    }

I don't think such automatic fallback should be tried - the caller ought to know which region it mapped, so it could call vunmap_type().

Quoted 4 lines
xen/arch/x86/setup.c +0 -0
@@ -238,11 +288,15 @@ void *vmalloc(size_t size)
         mfn[i] = _mfn(page_to_mfn(pg));
     }
 

xen/arch/x86/setup.c void *vmalloc(size_t size) · line 298

Quoted 10 lines
xen/arch/x86/setup.c +5 -2
-    va = vmap(mfn, pages);
+    va = __vmap(mfn, 1, pages, 1, PAGE_HYPERVISOR, type);
     if ( va == NULL )
         goto error;
 
-    xfree(mfn);
+    if ( mfn_array )
+        *mfn_array = mfn;
+    else
+        xfree(mfn);

What's this? I certainly assumed this wouldn't be needed anymore now.

xen/arch/x86/setup.c void vfree(void *va) · line 339

Quoted 8 lines
xen/arch/x86/setup.c +3 -1
@@ -275,7 +334,10 @@ void vfree(void *va)
     if ( !va )
         return;
 
-    pages = vm_size(va);
+    pages = vm_size(va, VMAP_VIRT);
+    if ( !pages )
+        pages = vm_size(va, XEN_VIRT);

Same comment as as for vunmap().

xen/arch/x86/setup.c void vfree(void *va)

Quoted 5 lines
xen/arch/x86/setup.c +5 -0
+enum vmap_type {
+    VMAP_VIRT,
+    XEN_VIRT,
+    VMAP_TYPE_MAX,
+};

I think these would benefit from using a common prefix, e.g.

enum vmap_type {
VMAP_DEFAULT,
VMAP_XEN,
VMAP_nr
};

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#82 lore raw

Re: [PATCH v5 10/28] xsplice: Implement payload loading

Quoted 5 lines
Quoted 5 lines
xen/common/vmap.c +4 -1
-void *vm_alloc(unsigned int nr, unsigned int align)
+void __init vm_init(void)
+{
+    vm_init_type(VMAP_VIRT);
+#ifdef CONFIG_XSPLICE
Quoted 8 lines

xen/common/vmap.c line 64

Quoted 3 lines
xen/common/vmap.c +3 -0
+    vm_init_type(XEN_VIRT);
+#endif
+}

I think we should leave it to the arch to call vm_init_type() for the non-default type(s) it cares about, namely allowing for this to be done at a different (later) time. Which means vm_init() could simply become an inline/macro wrapper of vm_init_type(VMAP_VIRT).

Yup, and then I've an arch_xsplice_init which nicely calls vm_init_type for the VMAP_VIRT_XEN.

Quoted 15 lines

xen/common/vmap.c void *vm_alloc(unsigned int nr, unsigned int align) · line 162

Quoted 5 lines
xen/common/vmap.c +4 -0
+void *vm_alloc(unsigned int nr, unsigned int align)
+{
+    return vm_alloc_type(nr, align, VMAP_VIRT);
+}

Inline/macro wrapper?

xen/common/vmap.c void vm_free(const void *va) · line 220

Quoted 4 lines
xen/common/vmap.c +4 -0
+void vm_free(const void *va)
+{
+    vm_free_type(va, VMAP_VIRT);
+}

Again.

Quoted 16 lines

xen/common/vmap.c void *__vmap(const mfn_t *mfn, unsigned int granularity, · line 258

Quoted 13 lines

void vunmap(const void *va)
{

xen/common/vmap.c +11 -0
+    enum vmap_type type = VMAP_VIRT;
+    unsigned int size = vm_size(va, type);
+#ifndef _PAGE_NONE
+    unsigned long addr;
+#endif
+
+    if ( !size )
+    {
+        type = XEN_VIRT;
+        size = vm_size(va, type);
+    }

I don't think such automatic fallback should be tried - the caller ought to know which region it mapped, so it could call vunmap_type().

OK.

Quoted 10 lines
Quoted 10 lines
xen/common/vmap.c +1 -1
@@ -238,11 +288,15 @@ void *vmalloc(size_t size)
         mfn[i] = _mfn(page_to_mfn(pg));
     }
 
-    va = vmap(mfn, pages);
+    va = __vmap(mfn, 1, pages, 1, PAGE_HYPERVISOR, type);
     if ( va == NULL )
         goto error;
 
Quoted 8 lines

xen/common/vmap.c void *vmalloc(size_t size) · line 298

Quoted 5 lines
xen/common/vmap.c +4 -1
-    xfree(mfn);
+    if ( mfn_array )
+        *mfn_array = mfn;
+    else
+        xfree(mfn);

What's this? I certainly assumed this wouldn't be needed anymore now.

I still need the MFNs so I can change the page table attributes once I've finished copying the ELF.

I can walk the virtual addresses and gather them from the PTE, but I figured it would be easier to have them stashed away somewhere?

Quoted 20 lines

xen/common/vmap.c void vfree(void *va) · line 339

Quoted 9 lines
xen/common/vmap.c +3 -1
@@ -275,7 +334,10 @@ void vfree(void *va)
     if ( !va )
         return;
 
-    pages = vm_size(va);
+    pages = vm_size(va, VMAP_VIRT);
+    if ( !pages )
+        pages = vm_size(va, XEN_VIRT);

Same comment as as for vunmap().

xen/include/xen/vmap.h line 15

Quoted 5 lines
xen/include/xen/vmap.h +5 -0
+enum vmap_type {
+    VMAP_VIRT,
+    XEN_VIRT,
+    VMAP_TYPE_MAX,
+};

I think these would benefit from using a common prefix, e.g.

Quoted 5 lines

enum vmap_type {
VMAP_DEFAULT,
VMAP_XEN,
VMAP_nr
};

Thanks!

Quoted 2 lines

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#83 lore raw

Re: [PATCH v5 10/28] xsplice: Implement payload loading

Quoted 14 lines · Konrad Rzeszutek Wilk
Quoted 5 lines
Quoted 5 lines
xen/common/vmap.c +4 -1
-void *vm_alloc(unsigned int nr, unsigned int align)
+void __init vm_init(void)
+{
+    vm_init_type(VMAP_VIRT);
+#ifdef CONFIG_XSPLICE
Quoted 8 lines

xen/common/vmap.c line 64

Quoted 3 lines
xen/common/vmap.c +3 -0
+    vm_init_type(XEN_VIRT);
+#endif
+}

I think we should leave it to the arch to call vm_init_type() for the non-default type(s) it cares about, namely allowing for this to be done at a different (later) time. Which means vm_init() could simply become an inline/macro wrapper of vm_init_type(VMAP_VIRT).

Quoted 10 lines

Yup, and then I've an arch_xsplice_init which nicely calls vm_init_type for the VMAP_VIRT_XEN.

Quoted 7 lines

xen/common/vmap.c void *vm_alloc(unsigned int nr, unsigned int align) · line 162

Quoted 5 lines
xen/common/vmap.c +4 -0
+void *vm_alloc(unsigned int nr, unsigned int align)
+{
+    return vm_alloc_type(nr, align, VMAP_VIRT);
+}

Inline/macro wrapper?

I would prefer to have this inside the common/vmap.c file as I would need to expose vm_alloc_type in the header file - which is really not to be used by users of the vmalloc API.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#84 lore raw

Re: [PATCH v5 10/28] xsplice: Implement payload loading

Quoted 9 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

Konrad Rzeszutek Wilk <[email protected]> 04/05/16 7:49 PM >>>

Quoted 6 lines · Konrad Rzeszutek Wilk
Quoted 6 lines

xen/common/vmap.c void *vm_alloc(unsigned int nr, unsigned int align) · line 162

Quoted 4 lines
xen/common/vmap.c +4 -0
+void *vm_alloc(unsigned int nr, unsigned int align)
+{
+    return vm_alloc_type(nr, align, VMAP_VIRT);
+}

Inline/macro wrapper?

Quoted 3 lines

I would prefer to have this inside the common/vmap.c file as I would need to expose vm_alloc_type in the header file - which is really not to be used by users of the vmalloc API.

If you don't expose it, how would xSplice be able to make use of it? But yes, if indeed that would become the only reason preventing something to be static, then it probably shouldn't become an inline wrapper.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#85 lore raw

Re: [PATCH v5 10/28] xsplice: Implement payload loading

In reply to Konrad Rzeszutek Wilk
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

Konrad Rzeszutek Wilk <[email protected]> 04/05/16 6:46 PM >>>

xen/common/vmap.c +4 -0
+    if ( mfn_array )
+        *mfn_array = mfn;
+    else
+        xfree(mfn);
Quoted 8 lines
Quoted 2 lines

What's this? I certainly assumed this wouldn't be needed anymore now.

I still need the MFNs so I can change the page table attributes once I've finished copying the ELF.

I can walk the virtual addresses and gather them from the PTE, but I figured it would be easier to have them stashed away somewhere?

Both alternatives aren't really neat, but I think exposing the MFN list via the vmalloc interface is the uglier variant. I.e. I'd prefer doing it Linux'es way, perhaps even having a specialized sibling to map_pages_to_xen() which only alters attributes without changing the frame numbers.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#86 lore raw

PATCH v5 11/28 xsplice: Implement support for applying/reverting/replacing patches.

In reply to Konrad Rzeszutek Wilk

From: Ross Lagerwall <[email protected]>

Implement support for the apply, revert and replace actions.

To perform and action on a payload, the hypercall sets up a data structure to schedule the work. A hook is added in all the return-to-guest paths to check for work to do and execute it if needed. In this way, patches can be applied with all CPUs idle and without stacks. The first CPU to do_xsplice() becomes the master and triggers a reschedule softirq to trigger all the other CPUs to enter do_xsplice() with no stack. Once all CPUs have rendezvoused, all CPUs disable IRQs and NMIs are ignored. The system is then quiscient and the master performs the action. After this, all CPUs enable IRQs and NMIs are re-enabled.

Note that it is unsafe to patch do_nmi and the xSplice internal functions. Patching functions on NMI/MCE path is liable to end in disaster.

The action to perform is one of:
- APPLY: For each function in the module, store the first 5 bytes of the old function and replace it with a jump to the new function.
- REVERT: Copy the previously stored bytes into the first 5 bytes of the old function.
- REPLACE: Revert each applied module and then apply the new module.

To prevent a deadlock with any other barrier in the system, the master will wait for up to 30ms before timing out.
Measurements found that the patch application to take about 100 μs on a 72 CPU system, whether idle or fully loaded.

We also add an BUILD_ON to make sure that the size of the structure of the payload is not inadvertly changed.

Lastly we unroll the 'vmap_to_page' on x86 as inside the macro there is a posibility of a NULL pointer. Hence we unroll it with extra ASSERTS. Note that asserts on non-debug builds are compiled out hence the extra checks that will just return (and leak memory).

We also add BUILD_BUG for the structure - and to make sure that the offsets are correct on both 32 and 64-bit hypervisors (ARM32 and ARM64).

--
Cc: Stefano Stabellini <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Boris Ostrovsky <[email protected]>
Cc: Suravee Suthikulpanit <[email protected]>
Cc: Jun Nakajima <[email protected]>
Cc: Kevin Tian <[email protected]>

v2: - Pluck the 'struct xsplice_patch_func' in this patch.
- Modify code per review comments.
- Add more data in the keyboard handler.
- Redo the patching code, split it in functions.
v3: - Add return_ macro for debug builds.
- Move s/payload_list_lock/payload_list/ to earlier patch
- Remove const and use ELF types for xsplice_patch_func
- Add check routine to do simple sanity checks for various
sections.
- s/%p/PRIx64/ as ARM builds complain.
- Move code around. Add more dprintk. Add XSPLICE in front of all
printks/dprintk.
Put the NMIs back if we fail patching.
Add per-cpu to lessen contention for global structure.
Extract from xsplice_do_single patching code into xsplice_do_action
Squash xsplice_do_single and check_for_xsplice_work together to
have all rendezvous in one place.
Made XSPLICE_ACTION_REPLACE work again (wrong list iterator) s/find_special_sections/prepare_payload/
Use list_del_init and INIT_LIST_HEAD for applied_list
v4:
- Add comment, adjust spacing for "Timed out on CPU semaphore"
- Added CR0.WP manipulations when altering the .text of hypervisor.
- Added fix from Andrew for CR0.WP manipulation.
v5: - Made xsplice_patch_func use uintXX_t instead of ELF_ types to easy
making it work under ARM (32bit). Add more BUILD-BUG-ON checks.
- Add more BUILD_ON checks. Sprinkle newlines. Sprinkle newlines. Sprinkle newlines. Sprinkle newlines.
---

---
 docs/misc/xsplice.markdown  |   3 +-
 xen/arch/arm/xsplice.c      |  20 ++
 xen/arch/x86/domain.c       |   4 +
 xen/arch/x86/hvm/svm/svm.c  |   2 +
 xen/arch/x86/hvm/vmx/vmcs.c |   2 +
 xen/arch/x86/xsplice.c      |  40 ++++
 xen/common/xsplice.c        | 461 +++++++++++++++++++++++++++++++++++++++++++-
 xen/include/asm-arm/nmi.h   |  13 ++
 xen/include/xen/xsplice.h   |  31 ++-
 9 files changed, 565 insertions(+), 11 deletions(-)
docs/misc/xsplice.markdown +2 -1
index a5303f0..28140dd 100644
@@ -841,7 +841,8 @@ The implementation must also have a mechanism for:
  * Be able to lookup in the Xen hypervisor the symbol names of functions from the ELF payload.
  * Be able to patch .rodata, .bss, and .data sections.
  * Further safety checks (blacklist of which functions cannot be patched, check
-   the stack, make sure the payload is built with same compiler as hypervisor).
+   the stack, make sure the payload is built with same compiler as hypervisor,
+   and NMI/MCE handlers and do_nmi for right now - until an safe solution is found).
  * NOP out the code sequence if `new_size` is zero.
  * Deal with other relocation types:  R_X86_64_[8,16,32,32S], R_X86_64_PC[8,16,64] in payload file.
 
xen/arch/arm/xsplice.c +20 -0
index e9c49ab..4fb19b3 100644
@@ -6,6 +6,26 @@
 #include <xen/xsplice_elf.h>
 #include <xen/xsplice.h>
 
+void arch_xsplice_patching_enter(void)
+{
+}
+
+void arch_xsplice_patching_leave(void)
+{
+}
+
+void arch_xsplice_apply_jmp(struct xsplice_patch_func *func)
+{
+}
+
+void arch_xsplice_revert_jmp(struct xsplice_patch_func *func)
+{
+}
+
+void arch_xsplice_post_action(void)
+{
+}
+
 int arch_xsplice_verify_elf(const struct xsplice_elf *elf, void *data)
 {
     return -ENOSYS;
xen/arch/x86/domain.c +4 -0
index 6ec7554..c63ee21 100644
@@ -36,6 +36,7 @@
 #include <xen/cpu.h>
 #include <xen/wait.h>
 #include <xen/guest_access.h>
+#include <xen/xsplice.h>
 #include <public/sysctl.h>
 #include <public/hvm/hvm_vcpu.h>
 #include <asm/regs.h>
@@ -120,6 +121,7 @@ static void idle_loop(void)
         (*pm_idle)();
         do_tasklet();
         do_softirq();
+        check_for_xsplice_work(); /* Must be last. */
     }
 }
 
@@ -136,6 +138,7 @@ void startup_cpu_idle_loop(void)
 
 static void noreturn continue_idle_domain(struct vcpu *v)
 {
+    check_for_xsplice_work();
     reset_stack_and_jump(idle_loop);
 }
 
@@ -143,6 +146,7 @@ static void noreturn continue_nonidle_domain(struct vcpu *v)
 {
     check_wakeup_from_wait();
     mark_regs_dirty(guest_cpu_user_regs());
+    check_for_xsplice_work();
     reset_stack_and_jump(ret_from_intr);
 }
 
xen/arch/x86/hvm/svm/svm.c +2 -0
index 7634c3f..bbb0a73 100644
@@ -26,6 +26,7 @@
 #include <xen/hypercall.h>
 #include <xen/domain_page.h>
 #include <xen/xenoprof.h>
+#include <xen/xsplice.h>
 #include <asm/current.h>
 #include <asm/io.h>
 #include <asm/paging.h>
@@ -1096,6 +1097,7 @@ static void noreturn svm_do_resume(struct vcpu *v)
 
     hvm_do_resume(v);
 
+    check_for_xsplice_work();
     reset_stack_and_jump(svm_asm_do_resume);
 }
 
xen/arch/x86/hvm/vmx/vmcs.c +2 -0
index 8284281..ec454dd 100644
@@ -25,6 +25,7 @@
 #include <xen/kernel.h>
 #include <xen/keyhandler.h>
 #include <xen/vm_event.h>
+#include <xen/xsplice.h>
 #include <asm/current.h>
 #include <asm/cpufeature.h>
 #include <asm/processor.h>
@@ -1722,6 +1723,7 @@ void vmx_do_resume(struct vcpu *v)
     }
 
     hvm_do_resume(v);
+    check_for_xsplice_work();
     reset_stack_and_jump(vmx_asm_do_vmentry);
 }
 
xen/arch/x86/xsplice.c +40 -0
index 7149540..1f77bd8 100644
@@ -10,6 +10,46 @@
 #include <xen/xsplice_elf.h>
 #include <xen/xsplice.h>
 
+#define PATCH_INSN_SIZE 5
+
+void arch_xsplice_patching_enter(void)
+{
+    /* Disable WP to allow changes to read-only pages. */
+    write_cr0(read_cr0() & ~X86_CR0_WP);
+}
+
+void arch_xsplice_patching_leave(void)
+{
+    /* Reinstate WP. */
+    write_cr0(read_cr0() | X86_CR0_WP);
+}
+
+void arch_xsplice_apply_jmp(struct xsplice_patch_func *func)
+{
+    uint32_t val;
+    uint8_t *old_ptr;
+
+    BUILD_BUG_ON(PATCH_INSN_SIZE > sizeof(func->undo));
+    BUILD_BUG_ON(PATCH_INSN_SIZE != (1 + sizeof val));
+
+    old_ptr = (uint8_t *)func->old_addr;
+    memcpy(func->undo, old_ptr, PATCH_INSN_SIZE);
+
+    *old_ptr++ = 0xe9; /* Relative jump */
+    val = func->new_addr - func->old_addr - PATCH_INSN_SIZE;
+    memcpy(old_ptr, &val, sizeof val);
+}
+
+void arch_xsplice_revert_jmp(struct xsplice_patch_func *func)
+{
+    memcpy((void *)func->old_addr, func->undo, PATCH_INSN_SIZE);
+}
+
+void arch_xsplice_post_action(void)
+{
+    cpuid_eax(0);
+}
+
 int arch_xsplice_verify_elf(const struct xsplice_elf *elf, void *data)
 {
 
xen/common/xsplice.c +452 -9

556 lines not on this page · raw message

xen/include/asm-arm/nmi.h +13 -0
index a60587e..82aff35 100644
@@ -4,6 +4,19 @@
 #define register_guest_nmi_callback(a)  (-ENOSYS)
 #define unregister_guest_nmi_callback() (-ENOSYS)
 
+typedef int (*nmi_callback_t)(const struct cpu_user_regs *regs, int cpu);
+
+/**
+ * set_nmi_callback
+ *
+ * Set a handler for an NMI. Only one handler may be
+ * set. Return the old nmi callback handler.
+ */
+static inline nmi_callback_t set_nmi_callback(nmi_callback_t callback)
+{
+    return NULL;
+}
+
 #endif /* ASM_NMI_H */
 /*
  * Local variables:
xen/include/xen/xsplice.h +30 -1
index 74850ea..00b3cb2 100644
@@ -11,12 +11,30 @@ struct xsplice_elf_sec;
 struct xsplice_elf_sym;
 struct xen_sysctl_xsplice_op;
 
+#include <xen/elfstructs.h>
+/*
+ * The structure which defines the patching. This is what the hypervisor
+ * expects in the '.xsplice.func' section of the ELF file.
+ *
+ * This MUST be in sync with what the tools generate.
+ */
+struct xsplice_patch_func {
+    const char *name;
+    uint64_t new_addr;
+    uint64_t old_addr;
+    uint32_t new_size;
+    uint32_t old_size;
+    uint8_t undo[8];
+    uint8_t pad[24];
+};
+
 #ifdef CONFIG_XSPLICE
 
 /* Convenience define for printk. */
 #define XSPLICE "xsplice: "
 
 int xsplice_op(struct xen_sysctl_xsplice_op *);
+void check_for_xsplice_work(void);
 
 /* Arch hooks. */
 int arch_xsplice_verify_elf(const struct xsplice_elf *elf, void *data);
@@ -61,6 +79,17 @@ void arch_xsplice_free_payload(void *va, unsigned int pages);
 typedef int (find_space_t)(size_t, unsigned long *, unsigned long *);
 void arch_xsplice_register_find_space(find_space_t *cb);
 
+/*
+ * These functions are called around the critical region patching live code,
+ * for an architecture to take make appropratie global state adjustments.
+ */
+void arch_xsplice_patching_enter(void);
+void arch_xsplice_patching_leave(void);
+
+void arch_xsplice_apply_jmp(struct xsplice_patch_func *func);
+void arch_xsplice_revert_jmp(struct xsplice_patch_func *func);
+void arch_xsplice_post_action(void);
+
 #else
 
 #include <xen/errno.h> /* For -EOPNOTSUPP */
@@ -68,7 +97,7 @@ static inline int xsplice_op(struct xen_sysctl_xsplice_op *op)
 {
     return -EOPNOTSUPP;
 }
-
+static inline void check_for_xsplice_work(void) { };
 #endif /* CONFIG_XSPLICE */
 
 #endif /* __XEN_XSPLICE_H__ */
Signature · 7 lines
2.5.0


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#87 lore raw

Re: [PATCH v5 11/28] xsplice: Implement support for applying/reverting/replacing patches.

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 24.03.16 at 21:00, <[email protected]> wrote:

From: Ross Lagerwall <[email protected]>

Implement support for the apply, revert and replace actions.

To perform and action on a payload, the hypercall sets up a data structure to schedule the work. A hook is added in all the return-to-guest paths to check for work to do and execute it if needed.

Looking at the diffstat alone I cannot see this being the case. Perhaps it's just the description here which needs to become more precise.

Quoted 10 lines

In this way, patches can be applied with all CPUs idle and without stacks. The first CPU to do_xsplice() becomes the master and triggers a reschedule softirq to trigger all the other CPUs to enter do_xsplice() with no stack. Once all CPUs have rendezvoused, all CPUs disable IRQs and NMIs are ignored. The system is then quiscient and the master performs the action. After this, all CPUs enable IRQs and NMIs are re-enabled.

Note that it is unsafe to patch do_nmi and the xSplice internal functions. Patching functions on NMI/MCE path is liable to end in disaster.

So what measures are (planned to be) taken to make sure this doesn't happen by accident?

Quoted 11 lines

The action to perform is one of:
- APPLY: For each function in the module, store the first 5 bytes of the old function and replace it with a jump to the new function.
- REVERT: Copy the previously stored bytes into the first 5 bytes of the old function.
- REPLACE: Revert each applied module and then apply the new module.

To prevent a deadlock with any other barrier in the system, the master will wait for up to 30ms before timing out.
Measurements found that the patch application to take about 100 μs on a 72 CPU system, whether idle or fully loaded.

That's for an individual patch I suppose? What if REPLACE has to revert dozens or hundreds of patches?

Quoted 7 lines

We also add an BUILD_ON to make sure that the size of the structure of the payload is not inadvertly changed.

Lastly we unroll the 'vmap_to_page' on x86 as inside the macro there is a posibility of a NULL pointer. Hence we unroll it with extra ASSERTS. Note that asserts on non-debug builds are compiled out hence the extra checks that will just return (and leak memory).

I'm afraid I can't really make sense of this: What does "unroll" mean here? There's no loop involved. And where's that potential for NULL?

docs/misc/xsplice.markdown The implementation must also have a mechanism for: · line 845

Quoted 9 lines
docs/misc/xsplice.markdown +2 -1
@@ -841,7 +841,8 @@ The implementation must also have a mechanism for:
  * Be able to lookup in the Xen hypervisor the symbol names of functions from the ELF payload.
  * Be able to patch .rodata, .bss, and .data sections.
  * Further safety checks (blacklist of which functions cannot be patched, check
-   the stack, make sure the payload is built with same compiler as hypervisor).
+   the stack, make sure the payload is built with same compiler as hypervisor,
+   and NMI/MCE handlers and do_nmi for right now - until an safe solution is found).

The whole thing doesn't parse anymore for me with the addition, so I can't really conclude what you mean to say here (and hence whether that addresses the earlier question).

Quoted 9 lines
docs/misc/xsplice.markdown +1 -0
@@ -120,6 +121,7 @@ static void idle_loop(void)
         (*pm_idle)();
         do_tasklet();
         do_softirq();
+        check_for_xsplice_work(); /* Must be last. */
     }
 }
 

docs/misc/xsplice.markdown void startup_cpu_idle_loop(void) · line 143

Quoted 6 lines
docs/misc/xsplice.markdown +1 -0
@@ -136,6 +138,7 @@ void startup_cpu_idle_loop(void)
 
 static void noreturn continue_idle_domain(struct vcpu *v)
 {
+    check_for_xsplice_work();
     reset_stack_and_jump(idle_loop);
 }

The placement here kind of contradicts the comment right above. And anyway - why in both places? And why here and not in common code, e.g. in do_softirq(), or - considering the further addition below - inside reset_stack_and_jump() _after_ having reset the stack (after all by doing it up front you do not really meet your goal of doing the action "without stacks")?

docs/misc/xsplice.markdown void startup_cpu_idle_loop(void)

Quoted 3 lines
docs/misc/xsplice.markdown +3 -0
+void arch_xsplice_apply_jmp(struct xsplice_patch_func *func)
+{
+    uint32_t val;

The way it's being used below, it clearly should be int32_t.

docs/misc/xsplice.markdown

Quoted 6 lines
docs/misc/xsplice.markdown +6 -0
+    uint8_t *old_ptr;
+
+    BUILD_BUG_ON(PATCH_INSN_SIZE > sizeof(func->undo));
+    BUILD_BUG_ON(PATCH_INSN_SIZE != (1 + sizeof val));
+
+    old_ptr = (uint8_t *)func->old_addr;

(Considering this cast, the "old_addr" member should be unsigned long (or void *), not uint64_t: The latest on ARM32 such would otherwise cause problems.)

Also - where is the verification that
func->old_size >= PATCH_INSN_SIZE?

Quoted 1 line

+void arch_xsplice_revert_jmp(struct xsplice_patch_func *func)

const

Quoted 13 lines
xen/common/xsplice.c +1 -0
@@ -3,6 +3,7 @@
  *
  */
 
+#include <xen/cpu.h>
 #include <xen/err.h>
 #include <xen/guest_access.h>
 #include <xen/keyhandler.h>
@@ -11,17 +12,29 @@
 #include <xen/mm.h>
 #include <xen/sched.h>

xen/common/xsplice.c line 23

Quoted 10 lines
xen/common/xsplice.c +3 -0
 #include <xen/smp.h>
+#include <xen/softirq.h>
 #include <xen/spinlock.h>
 #include <xen/vmap.h>
+#include <xen/wait.h>
 #include <xen/xsplice_elf.h>
 #include <xen/xsplice.h>
 
 #include <asm/event.h>
+#include <asm/nmi.h>

Urgh?

xen/common/xsplice.c line 35

Quoted 12 lines
xen/common/xsplice.c +7 -0
 #include <public/sysctl.h>
 
+/*
+ * Protects against payload_list operations and also allows only one
+ * caller in schedule_work.
+ */
 static DEFINE_SPINLOCK(payload_lock);
 static LIST_HEAD(payload_list);
 
+/*
+ * Patches which have been applied.
+ */

Comment style.

xen/common/xsplice.c struct payload { · line 64

Quoted 4 lines
xen/common/xsplice.c +4 -0
+struct xsplice_work
+{
+    atomic_t semaphore;          /* Used for rendezvous. First to grab it will
+                                    do the patching. */

"First to grab it" doesn't seem to make sense for an atomic_t variable.

xen/common/xsplice.c struct payload { · line 71

Quoted 7 lines
xen/common/xsplice.c +7 -0
+    atomic_t irq_semaphore;      /* Used to signal all IRQs disabled. */
+    uint32_t timeout;                    /* Timeout to do the operation. */
+    struct payload *data;        /* The payload on which to act. */
+    volatile bool_t do_work;     /* Signals work to do. */
+    volatile bool_t ready;       /* Signals all CPUs synchronized. */
+    uint32_t cmd;                /* Action request: XSPLICE_ACTION_* */
+};

Please can you do without fixed size types when the fixed size isn't really a requirement?

xen/common/xsplice.c struct payload { · line 77

Quoted 5 lines
xen/common/xsplice.c +5 -0
+/* There can be only one outstanding patching action. */
+static struct xsplice_work xsplice_work;
+
+/* Indicate whether the CPU needs to consult xsplice_work structure. */
+static DEFINE_PER_CPU(bool_t, work_to_do);

Peeking ahead to the uses of this, I can't see why this is needed alongside xsplice_work.do_work.

xen/common/xsplice.c static int secure_payload(struct payload *payload, struct xsplice_elf *elf) · line 335

Quoted 6 lines
xen/common/xsplice.c +2 -0
@@ -296,6 +331,77 @@ static int secure_payload(struct payload *payload, struct xsplice_elf *elf)
     return rc;
 }
 
+static int check_special_sections(struct payload *payload,
+                                  struct xsplice_elf *elf)

const (twice, but the first parameter appears to be unused anyway)

xen/common/xsplice.c static int secure_payload(struct payload *payload, struct xsplice_elf *elf) · line 342

Quoted 7 lines
xen/common/xsplice.c +7 -0
+{
+    unsigned int i;
+    static const char *const names[] = { ".xsplice.funcs" };
+
+    for ( i = 0; i < ARRAY_SIZE(names); i++ )
+    {
+        struct xsplice_elf_sec *sec;

const

Quoted 4 lines
xen/common/xsplice.c +4 -0
+        sec = xsplice_elf_sec_by_name(elf, names[i]);
+        if ( !sec )
+        {
+            printk(XENLOG_ERR "%s%s: %s is missing!\n",

xen/common/xsplice.c static int secure_payload(struct payload *payload, struct xsplice_elf *elf) · line 357

Quoted 10 lines
xen/common/xsplice.c +10 -0
+                   XSPLICE, elf->name, names[i]);
+            return -EINVAL;
+        }
+
+        if ( !sec->sec->sh_size )
+            return -EINVAL;
+    }
+
+    return 0;
+}

So you check for there being one such section. Is having multiple of them okay / meaningful?

xen/common/xsplice.c static int secure_payload(struct payload *payload, struct xsplice_elf *elf) · line 364

Quoted 6 lines
xen/common/xsplice.c +6 -0
+static int prepare_payload(struct payload *payload,
+                           struct xsplice_elf *elf)
+{
+    struct xsplice_elf_sec *sec;
+    unsigned int i;
+    struct xsplice_patch_func *f;

const (multiple times, and I'm not going to further make this remark:
Please deal with this throughout the series)

xen/common/xsplice.c static int secure_payload(struct payload *payload, struct xsplice_elf *elf) · line 367

Quoted 2 lines
xen/common/xsplice.c +2 -0
+    sec = xsplice_elf_sec_by_name(elf, ".xsplice.funcs");
+    if ( sec )

Assuming check_special_sections() got invoked before you get here, why the conditional?

xen/common/xsplice.c static int secure_payload(struct payload *payload, struct xsplice_elf *elf) · line 377

Quoted 10 lines
xen/common/xsplice.c +10 -0
+    {
+        if ( sec->sec->sh_size % sizeof *payload->funcs )
+        {
+            dprintk(XENLOG_DEBUG, "%s%s: Wrong size of .xsplice.funcs!\n",
+                    XSPLICE, elf->name);
+            return -EINVAL;
+        }
+
+        payload->funcs = (struct xsplice_patch_func *)sec->load_addr;
+        payload->nfuncs = sec->sec->sh_size / (sizeof *payload->funcs);

Since this repeats (so far I thought this was more like a mistake), and despite being a matter of taste to some degree - may I ask that the canonical sizeof() be used, instead of (sizeof ...) or whatever else variants?

xen/common/xsplice.c static int secure_payload(struct payload *payload, struct xsplice_elf *elf) · line 386

Quoted 9 lines
xen/common/xsplice.c +9 -0
+    }
+
+    for ( i = 0; i < payload->nfuncs; i++ )
+    {
+        unsigned int j;
+
+        f = &(payload->funcs[i]);
+
+        if ( !f->new_addr || !f->old_addr || !f->old_size || !f->new_size )

Isn't new_size == 0 a particularly easy to deal with case?

Quoted 24 lines
xen/common/xsplice.c +20 -0
@@ -499,6 +614,321 @@ static int xsplice_list(xen_sysctl_xsplice_list_t *list)
     return rc ? : idx;
 }
 
+/*
+ * The following functions get the CPUs into an appropriate state and
+ * apply (or revert) each of the payload's functions. This is needed
+ * for XEN_SYSCTL_XSPLICE_ACTION operation (see xsplice_action).
+ */
+
+static int apply_payload(struct payload *data)
+{
+    unsigned int i;
+
+    dprintk(XENLOG_DEBUG, "%s%s: Applying %u functions.\n", XSPLICE,
+            data->name, data->nfuncs);
+
+    arch_xsplice_patching_enter();
+
+    for ( i = 0; i < data->nfuncs; i++ )
+        arch_xsplice_apply_jmp(&data->funcs[i]);
+
+    arch_xsplice_patching_leave();
+

xen/common/xsplice.c static int xsplice_list(xen_sysctl_xsplice_list_t *list) · line 646

Quoted 10 lines
xen/common/xsplice.c +10 -0
+    list_add_tail(&data->applied_list, &applied_list);
+
+    return 0;
+}
+
+/*
+ * This function is executed having all other CPUs with no stack (we may
+ * have cpu_idle on it) and IRQs disabled.
+ */
+static int revert_payload(struct payload *data)

Wouldn't the same comment apply to apply_payload()? I.e. is it useful to have here but not there (i.e. isn't the comment ahead of xsplice_do_action() sufficient)?

xen/common/xsplice.c static int xsplice_list(xen_sysctl_xsplice_list_t *list) · line 676

Quoted 8 lines
xen/common/xsplice.c +8 -0
+static void xsplice_do_action(void)
+{
+    int rc;
+    struct payload *data, *other, *tmp;
+
+    data = xsplice_work.data;
+    /* Now this function should be the only one on any stack.
+     * No need to lock the payload list or applied list. */

Comment style.

Quoted 10 lines
xen/common/xsplice.c +10 -0
+    switch ( xsplice_work.cmd )
+    {
+    case XSPLICE_ACTION_APPLY:
+        rc = apply_payload(data);
+        if ( rc == 0 )
+            data->state = XSPLICE_STATE_APPLIED;
+        break;
+
+    case XSPLICE_ACTION_REVERT:
+        rc = revert_payload(data);

xen/common/xsplice.c static int xsplice_list(xen_sysctl_xsplice_list_t *list) · line 696

Quoted 10 lines
xen/common/xsplice.c +10 -0
+        if ( rc == 0 )
+            data->state = XSPLICE_STATE_CHECKED;
+        break;
+
+    case XSPLICE_ACTION_REPLACE:
+        rc = 0;
+        /* N.B: Use 'applied_list' member, not 'list'. */
+        list_for_each_entry_safe_reverse ( other, tmp, &applied_list, applied_list )
+        {
+            other->rc = revert_payload(other);

Why does this set ->rc, but the two earlier ones only set the local variable?

xen/common/xsplice.c static int xsplice_list(xen_sysctl_xsplice_list_t *list) · line 706

Quoted 10 lines
xen/common/xsplice.c +10 -0
+            if ( other->rc == 0 )
+                other->state = XSPLICE_STATE_CHECKED;
+            else
+            {
+                rc = -EINVAL;
+                break;
+            }
+        }
+
+        if ( rc != -EINVAL )

Perhaps better "rc == 0"?

xen/common/xsplice.c static int xsplice_list(xen_sysctl_xsplice_list_t *list) · line 719

Quoted 13 lines
xen/common/xsplice.c +13 -0
+        {
+            rc = apply_payload(data);
+            if ( rc == 0 )
+                data->state = XSPLICE_STATE_APPLIED;
+        }
+        break;
+
+    default:
+        rc = -EINVAL;
+        break;
+    }
+
+    data->rc = rc;

Oh, here it is. But why would an xsplice_work.cmd (which probably shouldn't make it here anyway) mark the payload having an error? It didn't change state or anything after all.

xen/common/xsplice.c static int xsplice_list(xen_sysctl_xsplice_list_t *list) · line 724

Quoted 3 lines
xen/common/xsplice.c +3 -0
+/*
+ * MUST be holding the payload_lock.
+ */

comment style (another comment I'm not going to repeat any further)

xen/common/xsplice.c static int xsplice_list(xen_sysctl_xsplice_list_t *list) · line 729

Quoted 5 lines
xen/common/xsplice.c +5 -0
+static int schedule_work(struct payload *data, uint32_t cmd, uint32_t timeout)
+{
+    unsigned int cpu;
+
+    ASSERT(spin_is_locked(&payload_lock));

Also the comment above is clearly redundant with this ASSERT().

Quoted 12 lines
xen/common/xsplice.c +12 -0
+    /* Fail if an operation is already scheduled. */
+    if ( xsplice_work.do_work )
+        return -EBUSY;
+
+    if ( !get_cpu_maps() )
+    {
+        printk(XENLOG_ERR "%s%s: unable to get cpu_maps lock!\n",
+               XSPLICE, data->name);
+        return -EBUSY;
+    }
+
+    xsplice_work.cmd = cmd;

xen/common/xsplice.c static int xsplice_list(xen_sysctl_xsplice_list_t *list) · line 752

Quoted 10 lines
xen/common/xsplice.c +10 -0
+    xsplice_work.data = data;
+    xsplice_work.timeout = timeout ?: MILLISECS(30);
+
+    dprintk(XENLOG_DEBUG, "%s%s: timeout is %"PRI_stime"ms\n",
+            XSPLICE, data->name, xsplice_work.timeout / MILLISECS(1));
+
+    /*
+     * Once the patching has been completed, the semaphore value will
+     * be num_online_cpus()-1.
+     */

Is this comment really useful? I.e. is that final value meaningful for anything?

xen/common/xsplice.c static int xsplice_list(xen_sysctl_xsplice_list_t *list) · line 763

Quoted 11 lines
xen/common/xsplice.c +11 -0
+    atomic_set(&xsplice_work.semaphore, -1);
+    atomic_set(&xsplice_work.irq_semaphore, -1);
+
+    xsplice_work.ready = 0;
+    smp_wmb();
+    xsplice_work.do_work = 1;
+    smp_wmb();
+    /*
+     * Above smp_wmb() gives us an compiler barrier, as we MUST do this
+     * after setting the global structure.
+     */

"a compiler barrier"

xen/common/xsplice.c static int xsplice_list(xen_sysctl_xsplice_list_t *list) · line 780

Quoted 5 lines
xen/common/xsplice.c +5 -0
+static int mask_nmi_callback(const struct cpu_user_regs *regs, int cpu)
+{
+    /* TODO: Handle missing NMI/MCE.*/
+    return 1;
+}

Aren't we in common code here?

xen/common/xsplice.c static int xsplice_list(xen_sysctl_xsplice_list_t *list) · line 817

Quoted 4 lines
xen/common/xsplice.c +4 -0
+void check_for_xsplice_work(void)
+{
+    unsigned int cpu = smp_processor_id();
+    nmi_callback_t saved_nmi_callback;

This again looks very x86-ish.

xen/common/xsplice.c static int xsplice_list(xen_sysctl_xsplice_list_t *list) · line 826

Quoted 9 lines
xen/common/xsplice.c +9 -0
+    s_time_t timeout;
+    unsigned long flags;
+
+    /* Fast path: no work to do. */
+    if ( !per_cpu(work_to_do, cpu ) )
+        return;
+
+    /* In case we aborted, other CPUs can skip right away. */
+    if ( (!xsplice_work.do_work) )

Stray parentheses.

Quoted 11 lines
xen/common/xsplice.c +11 -0
+    {
+        per_cpu(work_to_do, cpu) = 0;
+        return;
+    }
+
+    ASSERT(local_irq_is_enabled());
+
+    /* Set at -1, so will go up to num_online_cpus - 1. */
+    if ( atomic_inc_and_test(&xsplice_work.semaphore) )
+    {
+        struct payload *p;

xen/common/xsplice.c static int xsplice_list(xen_sysctl_xsplice_list_t *list) · line 847

Quoted 10 lines
xen/common/xsplice.c +10 -0
+        unsigned int total_cpus;
+
+        p = xsplice_work.data;
+        if ( !get_cpu_maps() )
+        {
+            printk(XENLOG_ERR "%s%s: CPU%u - unable to get cpu_maps lock!\n",
+                   XSPLICE, p->name, cpu);
+            per_cpu(work_to_do, cpu) = 0;
+            xsplice_work.data->rc = -EBUSY;
+            xsplice_work.do_work = 0;

On x86 such possibly simultaneous accesses may be okay, but is that universally the case? Wouldn't it better be only the monarch which updates shared data?

xen/common/xsplice.c static int xsplice_list(xen_sysctl_xsplice_list_t *list) · line 850

Quoted 3 lines
xen/common/xsplice.c +3 -0
+            /*
+             * Do NOT decrement semaphore down - as that may cause the other
+             * CPU (which may be at this exact moment checking the ASSERT)

Which ASSERT()? (I guess the one a few lines up - but does that matter?)

xen/common/xsplice.c static int xsplice_list(xen_sysctl_xsplice_list_t *list) · line 858

Quoted 8 lines
xen/common/xsplice.c +8 -0
+             * to assume the role of master and then needlessly time out
+             * out (as do_work is zero).
+             */
+            return;
+        }
+
+        barrier(); /* MUST do it after get_cpu_maps. */
+        total_cpus = num_online_cpus() - 1;

Considering this the variable (and earlier function parameter) is misnamed.

xen/common/xsplice.c static int xsplice_list(xen_sysctl_xsplice_list_t *list) · line 862

Quoted 3 lines
xen/common/xsplice.c +3 -0
+        if ( total_cpus )
+        {
+            dprintk(XENLOG_DEBUG, "%s%s: CPU%u - IPIing the %u CPUs\n",

Not being a native speaker, I've previously observed too many articles - the "the" here again looks quite odd, or there is an "other" missing.

xen/common/xsplice.c static int xsplice_list(xen_sysctl_xsplice_list_t *list) · line 873

Quoted 11 lines
xen/common/xsplice.c +11 -0
+                    XSPLICE, p->name, cpu, total_cpus);
+            smp_call_function(reschedule_fn, NULL, 0);
+        }
+
+        timeout = xsplice_work.timeout + NOW();
+        if ( xsplice_do_wait(&xsplice_work.semaphore, timeout, total_cpus,
+                             "Timed out on CPU semaphore") )
+            goto abort;
+
+        /* "Mask" NMIs. */
+        saved_nmi_callback = set_nmi_callback(mask_nmi_callback);

So what if an NMI got raised on a remote CPU right before you set this? I.e. doesn't this need to move earlier?

xen/common/xsplice.c static int xsplice_list(xen_sysctl_xsplice_list_t *list) · line 881

Quoted 7 lines
xen/common/xsplice.c +7 -0
+        /* All CPUs are waiting, now signal to disable IRQs. */
+        xsplice_work.ready = 1;
+        smp_wmb();
+
+        atomic_inc(&xsplice_work.irq_semaphore);
+        if ( !xsplice_do_wait(&xsplice_work.irq_semaphore, timeout, total_cpus,
+                              "Timed out on IRQ semaphore") )

I'd prefer if the common parts of that message moved into xsplice_do_wait() - no reason to have more string literal space occupied than really needed. Also, looking back, the respective function parameter could do with a more descriptive name.

And then - does it make sense to wait the perhaps full 30ms on this second step? Rendezvoused CPUs should react rather quickly to the signal to disable interrupts.

xen/common/xsplice.c static int xsplice_list(xen_sysctl_xsplice_list_t *list) · line 887

Quoted 6 lines
xen/common/xsplice.c +6 -0
+        {
+            local_irq_save(flags);
+            /* Do the patching. */
+            xsplice_do_action();
+            /* To flush out pipeline. */
+            arch_xsplice_post_action();

The comment needs to become more generic, and maybe the function name more specific.

xen/common/xsplice.c static int xsplice_list(xen_sysctl_xsplice_list_t *list) · line 896

Quoted 9 lines
xen/common/xsplice.c +9 -0
+            local_irq_restore(flags);
+        }
+        set_nmi_callback(saved_nmi_callback);
+
+ abort:
+        per_cpu(work_to_do, cpu) = 0;
+        xsplice_work.do_work = 0;
+
+        smp_wmb(); /* Synchronize with waiting CPUs. */

What "synchronization" does this barrier do?

xen/common/xsplice.c static int xsplice_list(xen_sysctl_xsplice_list_t *list) · line 825

Quoted 1 line
xen/common/xsplice.c +1 -0
+        ASSERT(local_irq_is_enabled());

Is there really anything between the earlier identical ASSERT() and this one which could leave interrupts off?

xen/common/xsplice.c static int xsplice_list(xen_sysctl_xsplice_list_t *list) · line 902

Quoted 4 lines
xen/common/xsplice.c +4 -0
+        put_cpu_maps();
+
+        printk(XENLOG_INFO "%s%s finished with rc=%d\n", XSPLICE,
+               p->name, p->rc);

And no record left of what was done with that payload?

xen/common/xsplice.c static int xsplice_list(xen_sysctl_xsplice_list_t *list) · line 910

Quoted 8 lines
xen/common/xsplice.c +8 -0
+    }
+    else
+    {
+        /* Wait for all CPUs to rendezvous. */
+        while ( xsplice_work.do_work && !xsplice_work.ready )
+        {
+            cpu_relax();
+            smp_rmb();

What is the barrier doing inside this and the other loop below?

xen/common/xsplice.c static void xsplice_printall(unsigned char key) · line 1074

Quoted 13 lines
xen/common/xsplice.c +5 -0
@@ -635,15 +1063,30 @@ static void xsplice_printall(unsigned char key)
     }
 
     list_for_each_entry ( data, &payload_list, list )
+    {
         printk(" name=%s state=%s(%d) %p (.data=%p, .rodata=%p) using %zu pages.\n",
                data->name, state2str(data->state), data->state, data->text_addr,
                data->rw_addr, data->ro_addr, data->payload_pages);
 
+        for ( i = 0; i < data->nfuncs; i++ )
+        {
+            struct xsplice_patch_func *f = &(data->funcs[i]);
+            printk("    %s patch 0x%"PRIx64"(%u) with 0x%"PRIx64"(%u)\n",

%# again please.

xen/common/xsplice.c static void xsplice_printall(unsigned char key) · line 1076

Quoted 2 lines
xen/common/xsplice.c +2 -0
+                   f->name, f->old_addr, f->old_size, f->new_addr, f->new_size);
+            if ( !(i % 100) )

Using a power of 2 in situations like this is going to produce both smaller and faster code (the faster aspect may not matter here, but anyway). Also I don't think you want to do this on the first iteration.

xen/common/xsplice.c static void xsplice_printall(unsigned char key) · line 1077

Quoted 1 line
xen/common/xsplice.c +1 -0
+                process_pending_softirqs();

With a lock held?

xen/common/xsplice.c static void xsplice_printall(unsigned char key) · line 1088

Quoted 5 lines
xen/common/xsplice.c +3 -0
 static int __init xsplice_init(void)
 {
+    BUILD_BUG_ON( sizeof(struct xsplice_patch_func) != 64 );
+    BUILD_BUG_ON( offsetof(struct xsplice_patch_func, new_addr) != 8 );
+    BUILD_BUG_ON( offsetof(struct xsplice_patch_func, new_size) != 24 );

What assumptions get broken if these sizes change?

xen/include/xen/xsplice.h struct xsplice_elf_sec; · line 19

Quoted 12 lines
xen/include/xen/xsplice.h +6 -0
@@ -11,12 +11,30 @@ struct xsplice_elf_sec;
 struct xsplice_elf_sym;
 struct xen_sysctl_xsplice_op;
 
+#include <xen/elfstructs.h>
+/*
+ * The structure which defines the patching. This is what the hypervisor
+ * expects in the '.xsplice.func' section of the ELF file.
+ *
+ * This MUST be in sync with what the tools generate.

In which case this need to be part of the public interface, I would say.

xen/include/xen/xsplice.h struct xsplice_elf_sec; · line 27

Quoted 8 lines
xen/include/xen/xsplice.h +8 -0
+ */
+struct xsplice_patch_func {
+    const char *name;
+    uint64_t new_addr;
+    uint64_t old_addr;
+    uint32_t new_size;
+    uint32_t old_size;
+    uint8_t undo[8];

Shouldn't the size of this array be a per-arch constant?

xen/include/xen/xsplice.h struct xsplice_elf_sec; · line 28

Quoted 1 line
xen/include/xen/xsplice.h +1 -0
+    uint8_t pad[24];

What is this padding field good for?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#88 lore raw

Re: [PATCH v5 11/28] xsplice: Implement support for applying/reverting/replacing patches.

Hey Jan,

Thank you for your review!
Please see below my answers.

Ross,

Could you answer one question below please.

Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 24.03.16 at 21:00, <[email protected]> wrote:

From: Ross Lagerwall <[email protected]>

Implement support for the apply, revert and replace actions.

Quoted 7 lines
Quoted 3 lines

To perform and action on a payload, the hypercall sets up a data structure to schedule the work. A hook is added in all the return-to-guest paths to check for work to do and execute it if needed.

Looking at the diffstat alone I cannot see this being the case. Perhaps it's just the description here which needs to become more precise.

s/all the/common/ ?

Quoted 9 lines
Quoted 9 lines

In this way, patches can be applied with all CPUs idle and without stacks. The first CPU to do_xsplice() becomes the master and triggers a reschedule softirq to trigger all the other CPUs to enter do_xsplice() with no stack. Once all CPUs have rendezvoused, all CPUs disable IRQs and NMIs are ignored. The system is then quiscient and the master performs the action. After this, all CPUs enable IRQs and NMIs are re-enabled.

Quoted 5 lines
Quoted 2 lines

Note that it is unsafe to patch do_nmi and the xSplice internal functions. Patching functions on NMI/MCE path is liable to end in disaster.

So what measures are (planned to be) taken to make sure this doesn't happen by accident?

None in this patch.

Please keep in mind that this issue is not only a problem with xSplice but also with alternative assembler patching.

I haven't figured out a nice way to take care of this and was hoping to brainstorm that. For right now this part is left out as 'TODO'.

Quoted 8 lines
Quoted 8 lines

The action to perform is one of:
- APPLY: For each function in the module, store the first 5 bytes of the old function and replace it with a jump to the new function.
- REVERT: Copy the previously stored bytes into the first 5 bytes of the old function.
- REPLACE: Revert each applied module and then apply the new module.

Quoted 7 lines
Quoted 4 lines

To prevent a deadlock with any other barrier in the system, the master will wait for up to 30ms before timing out.
Measurements found that the patch application to take about 100 μs on a 72 CPU system, whether idle or fully loaded.

That's for an individual patch I suppose? What if REPLACE has to revert dozens or hundreds of patches?

The user-space can change the timeout to a larger value.

Quoted 11 lines
Quoted 8 lines

We also add an BUILD_ON to make sure that the size of the structure of the payload is not inadvertly changed.

Lastly we unroll the 'vmap_to_page' on x86 as inside the macro there is a posibility of a NULL pointer. Hence we unroll it with extra ASSERTS. Note that asserts on non-debug builds are compiled out hence the extra checks that will just return (and leak memory).

I'm afraid I can't really make sense of this: What does "unroll" mean here? There's no loop involved. And where's that potential for NULL?

That is a very stale comment. That should have been deleted!

Quoted 14 lines

docs/misc/xsplice.markdown The implementation must also have a mechanism for: · line 845

Quoted 10 lines
docs/misc/xsplice.markdown +2 -1
@@ -841,7 +841,8 @@ The implementation must also have a mechanism for:
  * Be able to lookup in the Xen hypervisor the symbol names of functions from the ELF payload.
  * Be able to patch .rodata, .bss, and .data sections.
  * Further safety checks (blacklist of which functions cannot be patched, check
-   the stack, make sure the payload is built with same compiler as hypervisor).
+   the stack, make sure the payload is built with same compiler as hypervisor,
+   and NMI/MCE handlers and do_nmi for right now - until an safe solution is found).

The whole thing doesn't parse anymore for me with the addition, so I can't really conclude what you mean to say here (and hence whether that addresses the earlier question).

It is adding handling of NMI/MCE on the 'TODO' list so that I don't forget about it.

Quoted 11 lines
Quoted 11 lines
docs/misc/xsplice.markdown +1 -0
@@ -120,6 +121,7 @@ static void idle_loop(void)
         (*pm_idle)();
         do_tasklet();
         do_softirq();
+        check_for_xsplice_work(); /* Must be last. */
     }
 }
 
@@ -136,6 +138,7 @@ void startup_cpu_idle_loop(void)
 
Quoted 12 lines

docs/misc/xsplice.markdown void startup_cpu_idle_loop(void) · line 143

Quoted 5 lines
docs/misc/xsplice.markdown +1 -0
 static void noreturn continue_idle_domain(struct vcpu *v)
 {
+    check_for_xsplice_work();
     reset_stack_and_jump(idle_loop);
 }

The placement here kind of contradicts the comment right above. And anyway - why in both places? And why here and not in common code, e.g. in do_softirq(), or - considering the further addition below - inside reset_stack_and_jump() _after_ having reset the stack (after all by doing it up front you do not really meet your goal of doing the action "without stacks")?

Ross?

Quoted 18 lines

docs/misc/xsplice.markdown void startup_cpu_idle_loop(void)

Quoted 4 lines
docs/misc/xsplice.markdown +3 -0
+void arch_xsplice_apply_jmp(struct xsplice_patch_func *func)
+{
+    uint32_t val;

The way it's being used below, it clearly should be int32_t.

docs/misc/xsplice.markdown

Quoted 6 lines
docs/misc/xsplice.markdown +6 -0
+    uint8_t *old_ptr;
+
+    BUILD_BUG_ON(PATCH_INSN_SIZE > sizeof(func->undo));
+    BUILD_BUG_ON(PATCH_INSN_SIZE != (1 + sizeof val));
+
+    old_ptr = (uint8_t *)func->old_addr;

(Considering this cast, the "old_addr" member should be unsigned long (or void *), not uint64_t: The latest on ARM32 such would otherwise cause problems.)

Quoted 2 lines

Also - where is the verification that
func->old_size >= PATCH_INSN_SIZE?

Missing..
..snip..

Quoted 8 lines

docs/misc/xsplice.markdown

Quoted 5 lines
docs/misc/xsplice.markdown +5 -0
+/* There can be only one outstanding patching action. */
+static struct xsplice_work xsplice_work;
+
+/* Indicate whether the CPU needs to consult xsplice_work structure. */
+static DEFINE_PER_CPU(bool_t, work_to_do);

Peeking ahead to the uses of this, I can't see why this is needed alongside xsplice_work.do_work.

Andrew asked for this - he noticed that we pound on the xsplice_work structure quite often across a lot of CPUs. Instead of pounding on the same cache line - we could just read from a per-cpu cache line. Hence this addition.

Quoted 29 lines

docs/misc/xsplice.markdown static int secure_payload(struct payload *payload, struct xsplice_elf *elf) · line 335

Quoted 7 lines
docs/misc/xsplice.markdown +2 -0
@@ -296,6 +331,77 @@ static int secure_payload(struct payload *payload, struct xsplice_elf *elf)
     return rc;
 }
 
+static int check_special_sections(struct payload *payload,
+                                  struct xsplice_elf *elf)

const (twice, but the first parameter appears to be unused anyway)

docs/misc/xsplice.markdown static int secure_payload(struct payload *payload, struct xsplice_elf *elf) · line 342

Quoted 7 lines
docs/misc/xsplice.markdown +7 -0
+{
+    unsigned int i;
+    static const char *const names[] = { ".xsplice.funcs" };
+
+    for ( i = 0; i < ARRAY_SIZE(names); i++ )
+    {
+        struct xsplice_elf_sec *sec;

const

Quoted 9 lines
docs/misc/xsplice.markdown +9 -0
+        sec = xsplice_elf_sec_by_name(elf, names[i]);
+        if ( !sec )
+        {
+            printk(XENLOG_ERR "%s%s: %s is missing!\n",
+                   XSPLICE, elf->name, names[i]);
+            return -EINVAL;
+        }
+
+        if ( !sec->sec->sh_size )
Quoted 8 lines

docs/misc/xsplice.markdown static int secure_payload(struct payload *payload, struct xsplice_elf *elf) · line 356

Quoted 5 lines
docs/misc/xsplice.markdown +5 -0
+            return -EINVAL;
+    }
+
+    return 0;
+}

So you check for there being one such section. Is having multiple of them okay / meaningful?

/me blinks. You can have multiple ELF sections with the same name? I will double-check the spec over the weekend to see.

.. snip..

Quoted 5 lines

docs/misc/xsplice.markdown static int secure_payload(struct payload *payload, struct xsplice_elf *elf) · line 358

Quoted 2 lines
docs/misc/xsplice.markdown +2 -0
+    sec = xsplice_elf_sec_by_name(elf, ".xsplice.funcs");
+    if ( sec )

Assuming check_special_sections() got invoked before you get here, why the conditional?

Andrew asked for it. Albeit it is pointless as 'check_special_sections' will bail halt the process if this section is not found.

Quoted 12 lines

docs/misc/xsplice.markdown static int secure_payload(struct payload *payload, struct xsplice_elf *elf) · line 368

Quoted 11 lines
docs/misc/xsplice.markdown +10 -0
+    {
+        if ( sec->sec->sh_size % sizeof *payload->funcs )
+        {
+            dprintk(XENLOG_DEBUG, "%s%s: Wrong size of .xsplice.funcs!\n",
+                    XSPLICE, elf->name);
+            return -EINVAL;
+        }
+
+        payload->funcs = (struct xsplice_patch_func *)sec->load_addr;
+        payload->nfuncs = sec->sec->sh_size / (sizeof *payload->funcs);
Quoted 4 lines

Since this repeats (so far I thought this was more like a mistake), and despite being a matter of taste to some degree - may I ask that the canonical sizeof() be used, instead of (sizeof ...) or whatever else variants?

Sure. I will convert Ross's use of it.

Quoted 12 lines

docs/misc/xsplice.markdown static int secure_payload(struct payload *payload, struct xsplice_elf *elf) · line 377

Quoted 10 lines
docs/misc/xsplice.markdown +9 -0
+    }
+
+    for ( i = 0; i < payload->nfuncs; i++ )
+    {
+        unsigned int j;
+
+        f = &(payload->funcs[i]);
+
+        if ( !f->new_addr || !f->old_addr || !f->old_size || !f->new_size )

Isn't new_size == 0 a particularly easy to deal with case?

To NOP func? No. I would have to include the headers for the nop[] in the arch xSplice and expand on its patching (or expose the text_poke code).

That will grow this patch which is big enough. I don't mind doing it in further patches (and I believe it is mentioned as a TODO in the design doc so that I won't forget).

.. snip..

Quoted 23 lines

docs/misc/xsplice.markdown static int secure_payload(struct payload *payload, struct xsplice_elf *elf) · line 383

Quoted 6 lines
docs/misc/xsplice.markdown +6 -0
+    case XSPLICE_ACTION_REPLACE:
+        rc = 0;
+        /* N.B: Use 'applied_list' member, not 'list'. */
+        list_for_each_entry_safe_reverse ( other, tmp, &applied_list, applied_list )
+        {
+            other->rc = revert_payload(other);

Why does this set ->rc, but the two earlier ones only set the local variable?

docs/misc/xsplice.markdown static int secure_payload(struct payload *payload, struct xsplice_elf *elf) · line 393

Quoted 10 lines
docs/misc/xsplice.markdown +10 -0
+            if ( other->rc == 0 )
+                other->state = XSPLICE_STATE_CHECKED;
+            else
+            {
+                rc = -EINVAL;
+                break;
+            }
+        }
+
+        if ( rc != -EINVAL )

Perhaps better "rc == 0"?

Quoted 16 lines

docs/misc/xsplice.markdown static int secure_payload(struct payload *payload, struct xsplice_elf *elf) · line 406

Quoted 13 lines
docs/misc/xsplice.markdown +13 -0
+        {
+            rc = apply_payload(data);
+            if ( rc == 0 )
+                data->state = XSPLICE_STATE_APPLIED;
+        }
+        break;
+
+    default:
+        rc = -EINVAL;
+        break;
+    }
+
+    data->rc = rc;

Oh, here it is. But why would an xsplice_work.cmd (which probably shouldn't make it here anyway) mark the payload having an error?

In xsplice_action() we set data->rc to -EAGAIN right before we kick of the schedule_work(). That way the user can check the 'status' of the patching as we attempt to do it.

But once the patching has been complete we MUST set it to zero (or to an error if the patching failed).

Quoted 1 line

It didn't change state or anything after all.

.. snip..

Quoted 12 lines
Quoted 12 lines
docs/misc/xsplice.markdown +12 -0
+void check_for_xsplice_work(void)
+{
+    /* Set at -1, so will go up to num_online_cpus - 1. */
+    if ( atomic_inc_and_test(&xsplice_work.semaphore) )
+    {
+        struct payload *p;
+        unsigned int total_cpus;
+
+        p = xsplice_work.data;
+        if ( !get_cpu_maps() )
+        {
+            printk(XENLOG_ERR "%s%s: CPU%u - unable to get cpu_maps lock!\n",
Quoted 8 lines

docs/misc/xsplice.markdown

Quoted 4 lines
docs/misc/xsplice.markdown +4 -0
+                   XSPLICE, p->name, cpu);
+            per_cpu(work_to_do, cpu) = 0;
+            xsplice_work.data->rc = -EBUSY;
+            xsplice_work.do_work = 0;

On x86 such possibly simultaneous accesses may be okay, but is that universally the case? Wouldn't it better be only the monarch which updates shared data?

Monarch? Oh you mean arch specific code path?

Quoted 7 lines

docs/misc/xsplice.markdown

Quoted 4 lines
docs/misc/xsplice.markdown +3 -0
+            /*
+             * Do NOT decrement semaphore down - as that may cause the other
+             * CPU (which may be at this exact moment checking the ASSERT)

Which ASSERT()? (I guess the one a few lines up - but does that matter?)

It messed me up when I was working on it so thought I would leave that in here in case anybody wants to modify the code. Or more likely - if I rework this code that I will recall this.

Quoted 5 lines

docs/misc/xsplice.markdown

Quoted 2 lines
docs/misc/xsplice.markdown +2 -0
+        /* "Mask" NMIs. */
+        saved_nmi_callback = set_nmi_callback(mask_nmi_callback);

So what if an NMI got raised on a remote CPU right before you set this? I.e. doesn't this need to move earlier?

Hmm. Yes we should. Thanks!

Quoted 9 lines

docs/misc/xsplice.markdown

Quoted 8 lines
docs/misc/xsplice.markdown +7 -0
+        /* All CPUs are waiting, now signal to disable IRQs. */
+        xsplice_work.ready = 1;
+        smp_wmb();
+
+        atomic_inc(&xsplice_work.irq_semaphore);
+        if ( !xsplice_do_wait(&xsplice_work.irq_semaphore, timeout, total_cpus,
+                              "Timed out on IRQ semaphore") )
Quoted 8 lines

I'd prefer if the common parts of that message moved into xsplice_do_wait() - no reason to have more string literal space occupied than really needed. Also, looking back, the respective function parameter could do with a more descriptive name.

And then - does it make sense to wait the perhaps full 30ms on this second step? Rendezvoused CPUs should react rather quickly to the signal to disable interrupts.

We don't reset the timeout - the timeout is for both calls to xsplice_do_wait.

Quoted 10 lines

docs/misc/xsplice.markdown

Quoted 7 lines
docs/misc/xsplice.markdown +6 -0
+        {
+            local_irq_save(flags);
+            /* Do the patching. */
+            xsplice_do_action();
+            /* To flush out pipeline. */
+            arch_xsplice_post_action();

The comment needs to become more generic, and maybe the function name more specific.

Serialize CPUs? Flush CPU pipeline? Flush CPU i-cache?

Quoted 12 lines

docs/misc/xsplice.markdown

Quoted 10 lines
docs/misc/xsplice.markdown +9 -0
+            local_irq_restore(flags);
+        }
+        set_nmi_callback(saved_nmi_callback);
+
+ abort:
+        per_cpu(work_to_do, cpu) = 0;
+        xsplice_work.do_work = 0;
+
+        smp_wmb(); /* Synchronize with waiting CPUs. */

What "synchronization" does this barrier do?

For the ->do_work being set to zero - as they are reading and reading it.

Quoted 5 lines
Quoted 2 lines

+ ASSERT(local_irq_is_enabled());

Is there really anything between the earlier identical ASSERT() and this one which could leave interrupts off?

The patching calls (in later patches) - the load and unload hooks. Those could inadvertly enabled interrupts.

Quoted 7 lines

docs/misc/xsplice.markdown

Quoted 5 lines
docs/misc/xsplice.markdown +4 -0
+        put_cpu_maps();
+
+        printk(XENLOG_INFO "%s%s finished with rc=%d\n", XSPLICE,
+               p->name, p->rc);

And no record left of what was done with that payload?

? But it does. The rc is mentioned.. Or are you saying that it should also say whether it was applied/reverted/replaced, etc?

Quoted 11 lines

docs/misc/xsplice.markdown

Quoted 9 lines
docs/misc/xsplice.markdown +8 -0
+    }
+    else
+    {
+        /* Wait for all CPUs to rendezvous. */
+        while ( xsplice_work.do_work && !xsplice_work.ready )
+        {
+            cpu_relax();
+            smp_rmb();

What is the barrier doing inside this and the other loop below?

The goal is to get the updated value from ->do_work and ->ready.

That is to do the same thing we do with frontend and backends - sync out the rp/rc so that the other end can read it the updated value.

.. snip..

Quoted 7 lines

docs/misc/xsplice.markdown

Quoted 5 lines

static int __init xsplice_init(void)
{

docs/misc/xsplice.markdown +3 -0
+    BUILD_BUG_ON( sizeof(struct xsplice_patch_func) != 64 );
+    BUILD_BUG_ON( offsetof(struct xsplice_patch_func, new_addr) != 8 );
+    BUILD_BUG_ON( offsetof(struct xsplice_patch_func, new_size) != 24 );

What assumptions get broken if these sizes change?

I think you mean the offsets? They can change. I added them to make sure that on 32-bit hypervisor (ARM) the offsets would be the same as on 64-bit hypervisor (x86).

The size however MUST remain the same - otherwise the toolstack won't produce proper payloads anymore.

Quoted 7 lines
Quoted 7 lines
xen/include/xen/xsplice.h +0 -0
@@ -11,12 +11,30 @@ struct xsplice_elf_sec;
 struct xsplice_elf_sym;
 struct xen_sysctl_xsplice_op;
 
Quoted 9 lines

xen/include/xen/xsplice.h struct xsplice_elf_sec; · line 19

Quoted 6 lines
xen/include/xen/xsplice.h +6 -0
+#include <xen/elfstructs.h>
+/*
+ * The structure which defines the patching. This is what the hypervisor
+ * expects in the '.xsplice.func' section of the ELF file.
+ *
+ * This MUST be in sync with what the tools generate.

In which case this need to be part of the public interface, I would say.

Ah yes. Where should it go? sysctl.h is where the XSPLICE ops are - or should this have it is own public/xsplice.h header file?

Quoted 11 lines

xen/include/xen/xsplice.h struct xsplice_elf_sec; · line 27

Quoted 9 lines
xen/include/xen/xsplice.h +8 -0
+ */
+struct xsplice_patch_func {
+    const char *name;
+    uint64_t new_addr;
+    uint64_t old_addr;
+    uint32_t new_size;
+    uint32_t old_size;
+    uint8_t undo[8];

Shouldn't the size of this array be a per-arch constant?

Yes.

Quoted 4 lines

xen/include/xen/xsplice.h struct xsplice_elf_sec; · line 28

Quoted 2 lines
xen/include/xen/xsplice.h +1 -0
+    uint8_t pad[24];

What is this padding field good for?

I want the size of the structure to be exactly 64-bytes across all architectures. That way I don't have to mess with compat layer or have the design doc be different for ARM vs x86.

It gives us enough of space to stash other 'private' fields we may want or even expand this structure in the future and fill it out with extra fields. ARgh, but for that we need a version field somewhere... Maybe another section .xsplice_version which just has a value of 1?

However the one thing I am not sure about is the padding.

The 'const char *name' on 32-bit ARM will be 4 bytes hence it will insert 4 byte padding (at least that is what pahole tells me, and the BUILD_BUG_ON confirms). But if I built with clang or other compiler it may very well ignore me.

Any suggestions? I could do:

struct xsplice_patch_func {
    const char *name;
#ifdef CONFIG_32
    uint32_t _name_pad;
#endif
    uint64_t new_addr;
    uint64_t old_addr;
    uint32_t new_size;
    uint32_t old_size;
    uint8_t undo[8];
    uint8_t pad[24];
}

But that is not very nice.

Also if we make this a public header I can't very well expose the 'undo' internals - it ought to be opaque. Ideas?

Thanks!

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#89 lore raw

Re: [PATCH v5 11/28] xsplice: Implement support for applying/reverting/replacing patches.

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 01.04.16 at 23:04, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 24.03.16 at 21:00, <[email protected]> wrote:

From: Ross Lagerwall <[email protected]>

Implement support for the apply, revert and replace actions.

To perform and action on a payload, the hypercall sets up a data structure to schedule the work. A hook is added in all the return-to-guest paths to check for work to do and execute it if needed.

Quoted 5 lines
Quoted 3 lines

Looking at the diffstat alone I cannot see this being the case. Perhaps it's just the description here which needs to become more precise.

s/all the/common/ ?

Considering that non of the entry.S files get touched, I think it's the "return-to-guest paths" part which is wrong.

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

In this way, patches can be applied with all CPUs idle and without stacks. The first CPU to do_xsplice() becomes the master and triggers a reschedule softirq to trigger all the other CPUs to enter do_xsplice() with no stack. Once all CPUs have rendezvoused, all CPUs disable IRQs and NMIs are ignored. The system is then quiscient and the master performs the action. After this, all CPUs enable IRQs and NMIs are re-enabled.

Note that it is unsafe to patch do_nmi and the xSplice internal functions. Patching functions on NMI/MCE path is liable to end in disaster.

Quoted 7 lines
Quoted 2 lines

So what measures are (planned to be) taken to make sure this doesn't happen by accident?

None in this patch.

Please keep in mind that this issue is not only a problem with xSplice but also with alternative assembler patching.

Except that an issue there would cause only a boot failure, which would be unlikely to re-occur on the next boot attempt. Whereas things going wrong at runtime would likely mean worse consequences.

Quoted 2 lines

I haven't figured out a nice way to take care of this and was hoping to brainstorm that. For right now this part is left out as 'TODO'.

That's what I've assumed, which is fine for the moment. Just maybe make this more explicit by adding (to the above) something like "For now this needs to be ensured by the people creating patches."

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines

The action to perform is one of:
- APPLY: For each function in the module, store the first 5 bytes of the old function and replace it with a jump to the new function.
- REVERT: Copy the previously stored bytes into the first 5 bytes of the old function.
- REPLACE: Revert each applied module and then apply the new module.

To prevent a deadlock with any other barrier in the system, the master will wait for up to 30ms before timing out.
Measurements found that the patch application to take about 100 μs on a 72 CPU system, whether idle or fully loaded.

Quoted 4 lines
Quoted 2 lines

That's for an individual patch I suppose? What if REPLACE has to revert dozens or hundreds of patches?

The user-space can change the timeout to a larger value.

The question wasn't about the timeout expiring, but about the latency of the operation (and the resulting effect on the system).

Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
docs/misc/xsplice.markdown +0 -0
@@ -841,7 +841,8 @@ The implementation must also have a mechanism for:
  * Be able to lookup in the Xen hypervisor the symbol names of functions from the ELF payload.
  * Be able to patch .rodata, .bss, and .data sections.
Quoted 8 lines

docs/misc/xsplice.markdown The implementation must also have a mechanism for: · line 845

Quoted 4 lines
docs/misc/xsplice.markdown +2 -1
  * Further safety checks (blacklist of which functions cannot be patched, check
-   the stack, make sure the payload is built with same compiler as hypervisor).
+   the stack, make sure the payload is built with same compiler as hypervisor,
+   and NMI/MCE handlers and do_nmi for right now - until an safe solution is found).

The whole thing doesn't parse anymore for me with the addition, so I can't really conclude what you mean to say here (and hence whether that addresses the earlier question).

Quoted 2 lines

It is adding handling of NMI/MCE on the 'TODO' list so that I don't forget about it.

Please try to re-word the addition then to make the result readable again.

Quoted 9 lines
Quoted 8 lines

docs/misc/xsplice.markdown The implementation must also have a mechanism for:

Quoted 5 lines
docs/misc/xsplice.markdown +5 -0
+/* There can be only one outstanding patching action. */
+static struct xsplice_work xsplice_work;
+
+/* Indicate whether the CPU needs to consult xsplice_work structure. */
+static DEFINE_PER_CPU(bool_t, work_to_do);

Peeking ahead to the uses of this, I can't see why this is needed alongside xsplice_work.do_work.

Quoted 4 lines

Andrew asked for this - he noticed that we pound on the xsplice_work structure quite often across a lot of CPUs. Instead of pounding on the same cache line - we could just read from a per-cpu cache line. Hence this addition.

Then please make the comment say so in a more explicit way.

Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
docs/misc/xsplice.markdown +9 -0
+        sec = xsplice_elf_sec_by_name(elf, names[i]);
+        if ( !sec )
+        {
+            printk(XENLOG_ERR "%s%s: %s is missing!\n",
+                   XSPLICE, elf->name, names[i]);
+            return -EINVAL;
+        }
+
+        if ( !sec->sec->sh_size )
Quoted 8 lines

docs/misc/xsplice.markdown

Quoted 5 lines
docs/misc/xsplice.markdown +5 -0
+            return -EINVAL;
+    }
+
+    return 0;
+}

So you check for there being one such section. Is having multiple of them okay / meaningful?

Quoted 2 lines

/me blinks. You can have multiple ELF sections with the same name? I will double-check the spec over the weekend to see.

Of course you can. Remember me telling you that using section names for identification is a bad idea (even if widely done that way)? That's precisely because section names in the spec serve no meaning other than making sections identifiable to the human eye. For certain sections there's a more or less strict convention on what their names should be, but that's all there is to names. Section types and attributes really are what describe their purposes.

And even if that really was forbidden by the spec, you'd still need to make sure the binary meets the spec.

Quoted 8 lines
Quoted 5 lines

docs/misc/xsplice.markdown

Quoted 2 lines
docs/misc/xsplice.markdown +2 -0
+    sec = xsplice_elf_sec_by_name(elf, ".xsplice.funcs");
+    if ( sec )

Assuming check_special_sections() got invoked before you get here, why the conditional?

Andrew asked for it. Albeit it is pointless as 'check_special_sections' will bail halt the process if this section is not found.

It's not clear why he would have wanted the check here. Imo, if anything this should be an ASSERT() then.

Quoted 12 lines
Quoted 11 lines

docs/misc/xsplice.markdown

Quoted 9 lines
docs/misc/xsplice.markdown +9 -0
+    }
+
+    for ( i = 0; i < payload->nfuncs; i++ )
+    {
+        unsigned int j;
+
+        f = &(payload->funcs[i]);
+
+        if ( !f->new_addr || !f->old_addr || !f->old_size || !f->new_size )

Isn't new_size == 0 a particularly easy to deal with case?

Quoted 8 lines

To NOP func? No. I would have to include the headers for the nop[] in the arch xSplice
and expand on its patching (or expose the text_poke code).

That will grow this patch which is big enough. I don't mind doing it in further patches
(and I believe it is mentioned as a TODO in the design doc so that I won't forget).

That's fine, except for one aspect: The error value resulting from
this: EINVAL is appropriate only for invalid input. When valid input just doesn't get handled suitably, EOPNOTSUPP or some such should be used instead.

Quoted 10 lines
Quoted 9 lines

docs/misc/xsplice.markdown

Quoted 6 lines
docs/misc/xsplice.markdown +6 -0
+    default:
+        rc = -EINVAL;
+        break;
+    }
+
+    data->rc = rc;

Oh, here it is. But why would an xsplice_work.cmd (which probably shouldn't make it here anyway) mark the payload having an error?

Quoted 6 lines

In xsplice_action() we set data->rc to -EAGAIN right before we kick of the schedule_work(). That way the user can check the 'status' of the patching as we attempt to do it.

But once the patching has been complete we MUST set it to zero (or to an error if the patching failed).

Okay, makes sense. But I realize a word was missing from my reply. I meant "But why would an invalid xsplice_work.cmd (which probably shouldn't make it here anyway) mark the payload having an error?"

I.e. the question particularly is about the default case (with the suggestion to just ditch it, or make in an ASSERT_UNREACHABLE()).

Quoted 23 lines
Quoted 1 line

It didn't change state or anything after all.

.. snip..

Quoted 12 lines
Quoted 12 lines
docs/misc/xsplice.markdown +12 -0
+void check_for_xsplice_work(void)
+{
+    /* Set at -1, so will go up to num_online_cpus - 1. */
+    if ( atomic_inc_and_test(&xsplice_work.semaphore) )
+    {
+        struct payload *p;
+        unsigned int total_cpus;
+
+        p = xsplice_work.data;
+        if ( !get_cpu_maps() )
+        {
+            printk(XENLOG_ERR "%s%s: CPU%u - unable to get cpu_maps lock!\n",
Quoted 8 lines

docs/misc/xsplice.markdown

Quoted 4 lines
docs/misc/xsplice.markdown +4 -0
+                   XSPLICE, p->name, cpu);
+            per_cpu(work_to_do, cpu) = 0;
+            xsplice_work.data->rc = -EBUSY;
+            xsplice_work.do_work = 0;

On x86 such possibly simultaneous accesses may be okay, but is that universally the case? Wouldn't it better be only the monarch which updates shared data?

Quoted 1 line

Monarch? Oh you mean arch specific code path?

Oh, I think you call it "master" elsewhere. IA64 terminology which I came to like.

Quoted 13 lines
Quoted 13 lines

docs/misc/xsplice.markdown

Quoted 7 lines
docs/misc/xsplice.markdown +7 -0
+        /* All CPUs are waiting, now signal to disable IRQs. */
+        xsplice_work.ready = 1;
+        smp_wmb();
+
+        atomic_inc(&xsplice_work.irq_semaphore);
+        if ( !xsplice_do_wait(&xsplice_work.irq_semaphore, timeout, total_cpus,
+                              "Timed out on IRQ semaphore") )

I'd prefer if the common parts of that message moved into xsplice_do_wait() - no reason to have more string literal space occupied than really needed. Also, looking back, the respective function parameter could do with a more descriptive name.

Quoted 6 lines
Quoted 3 lines

And then - does it make sense to wait the perhaps full 30ms on this second step? Rendezvoused CPUs should react rather quickly to the signal to disable interrupts.

We don't reset the timeout - the timeout is for both calls to xsplice_do_wait.

I understand that's the way it's right now, but that's what I'm putting under question. Rendezvousing CPUs is quite a bit more at risk of taking some time compared to having already rendezvoused CPUs disable their IRQs.

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
docs/misc/xsplice.markdown +6 -0
+        {
+            local_irq_save(flags);
+            /* Do the patching. */
+            xsplice_do_action();
+            /* To flush out pipeline. */
+            arch_xsplice_post_action();
Quoted 4 lines
Quoted 2 lines

The comment needs to become more generic, and maybe the function name more specific.

Serialize CPUs? Flush CPU pipeline? Flush CPU i-cache?

Perhaps mention all of these as examples of what may need doing in that hook.

Quoted 12 lines
Quoted 11 lines

docs/misc/xsplice.markdown

Quoted 9 lines
docs/misc/xsplice.markdown +9 -0
+            local_irq_restore(flags);
+        }
+        set_nmi_callback(saved_nmi_callback);
+
+ abort:
+        per_cpu(work_to_do, cpu) = 0;
+        xsplice_work.do_work = 0;
+
+        smp_wmb(); /* Synchronize with waiting CPUs. */

What "synchronization" does this barrier do?

Quoted 1 line

For the ->do_work being set to zero - as they are reading and reading it.

But barriers don't do any synchronization, they only guarantee certain ordering requirements. I.e. a comment on a barrier would normally indicate which operations it is that it enforces ordering for.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

+ ASSERT(local_irq_is_enabled());

Is there really anything between the earlier identical ASSERT() and this one which could leave interrupts off?

The patching calls (in later patches) - the load and unload hooks. Those could inadvertly enabled interrupts.

In which case the ASSERT() would better be placed right after those hooks (and get added alongside adding the hooks, which is pending a decision on whether those should stay anyway).

Quoted 9 lines
Quoted 6 lines

docs/misc/xsplice.markdown

Quoted 4 lines
docs/misc/xsplice.markdown +4 -0
+        put_cpu_maps();
+
+        printk(XENLOG_INFO "%s%s finished with rc=%d\n", XSPLICE,
+               p->name, p->rc);

And no record left of what was done with that payload?

? But it does. The rc is mentioned.. Or are you saying that it should also say whether it was applied/reverted/replaced, etc?

Yes, exactly.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
docs/misc/xsplice.markdown +8 -0
+    }
+    else
+    {
+        /* Wait for all CPUs to rendezvous. */
+        while ( xsplice_work.do_work && !xsplice_work.ready )
+        {
+            cpu_relax();
+            smp_rmb();
Quoted 6 lines
Quoted 1 line

What is the barrier doing inside this and the other loop below?

The goal is to get the updated value from ->do_work and ->ready.

That is to do the same thing we do with frontend and backends - sync out the rp/rc so that the other end can read it the updated value.

But that's guaranteed already by cpu_relax() being a barrier (see other loops in the code base invoking cpu_relax()). You have no ordering requirement here, all you want is that the compiler not move the two reads out of the loop.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

static int __init xsplice_init(void)
{

docs/misc/xsplice.markdown +3 -0
+    BUILD_BUG_ON( sizeof(struct xsplice_patch_func) != 64 );
+    BUILD_BUG_ON( offsetof(struct xsplice_patch_func, new_addr) != 8 );
+    BUILD_BUG_ON( offsetof(struct xsplice_patch_func, new_size) != 24 );
Quoted 8 lines
Quoted 1 line

What assumptions get broken if these sizes change?

I think you mean the offsets? They can change. I added them to make sure that on 32-bit hypervisor (ARM) the offsets would be the same as on 64-bit hypervisor (x86).

The size however MUST remain the same - otherwise the toolstack won't produce proper payloads anymore.

Well, that's a very bad thing then imo. You'd better version the structure instead.

Quoted 16 lines
Quoted 6 lines
Quoted 6 lines
xen/include/xen/xsplice.h +0 -0
@@ -11,12 +11,30 @@ struct xsplice_elf_sec;
 struct xsplice_elf_sym;
 struct xen_sysctl_xsplice_op;
 
Quoted 9 lines

xen/include/xen/xsplice.h struct xsplice_elf_sec; · line 19

Quoted 6 lines
xen/include/xen/xsplice.h +6 -0
+#include <xen/elfstructs.h>
+/*
+ * The structure which defines the patching. This is what the hypervisor
+ * expects in the '.xsplice.func' section of the ELF file.
+ *
+ * This MUST be in sync with what the tools generate.

In which case this need to be part of the public interface, I would say.

Quoted 2 lines

Ah yes. Where should it go? sysctl.h is where the XSPLICE ops are - or should this have it is own public/xsplice.h header file?

If it's just this, then I don't think a separate header is warranted, and hence putting it in sysctl.h would seem fine to me.

Quoted 7 lines
Quoted 3 lines

xen/include/xen/xsplice.h struct xsplice_elf_sec; · line 28

Quoted 1 line
xen/include/xen/xsplice.h +1 -0
+    uint8_t pad[24];

What is this padding field good for?

I want the size of the structure to be exactly 64-bytes across all architectures. That way I don't have to mess with compat layer or have the design doc be different for ARM vs x86.

For avoiding the compat layer, guaranteeing same size is not sufficient anyway. And the design doc doesn't need to mention structure sizes at all.

Quoted 28 lines

It gives us enough of space to stash other 'private' fields we may want or even expand this structure in the future and fill it out with extra fields. ARgh, but for that we need a version field somewhere... Maybe another section .xsplice_version which just has a value of 1?

However the one thing I am not sure about is the padding.

The 'const char *name' on 32-bit ARM will be 4 bytes hence it will insert 4 byte padding (at least that is what pahole tells me, and the BUILD_BUG_ON confirms). But if I built with clang or other compiler it may very well ignore me.

Any suggestions? I could do:

struct xsplice_patch_func {
    const char *name;
#ifdef CONFIG_32
    uint32_t _name_pad;
#endif
    uint64_t new_addr;
    uint64_t old_addr;
    uint32_t new_size;
    uint32_t old_size;
    uint8_t undo[8];
    uint8_t pad[24];
}
Quoted 1 line

But that is not very nice.

Indeed. Perhaps a union, but I'm questioning the need of uniformity across architectures in the first place.

Quoted 2 lines

Also if we make this a public header I can't very well expose the 'undo' internals - it ought to be opaque. Ideas?

Split it, and link the image provided structure from the internally used one. Or have the internally used one be a superset of the one coming from the image, and simply copy the data (at once allowing you to discard the respective section after loading the image).

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#90 lore raw

Re: [PATCH v5 11/28] xsplice: Implement support for applying/reverting/replacing patches.

Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

So you check for there being one such section. Is having multiple of them okay / meaningful?

/me blinks. You can have multiple ELF sections with the same name? I will double-check the spec over the weekend to see.

Quoted 8 lines

Of course you can. Remember me telling you that using section names for identification is a bad idea (even if widely done that way)? That's precisely because section names in the spec serve no meaning other than making sections identifiable to the human eye. For certain sections there's a more or less strict convention on what their names should be, but that's all there is to names. Section types and attributes really are what describe their purposes.

This is going to take a bit of time to get right I am afraid. (The checks are easy - but make sure the payload files that are generated are doing the right thing).

Quoted 3 lines

And even if that really was forbidden by the spec, you'd still need to make sure the binary meets the spec.

Yes.

Quoted 21 lines
Quoted 21 lines
Quoted 20 lines
Quoted 6 lines
xen/common/xsplice.c +6 -0
+void check_for_xsplice_work(void)
+{
+    /* Set at -1, so will go up to num_online_cpus - 1. */
+    if ( atomic_inc_and_test(&xsplice_work.semaphore) )
+    {
+        struct payload *p;

xen/common/xsplice.c static int xsplice_list(xen_sysctl_xsplice_list_t *list) · line 847

Quoted 10 lines
xen/common/xsplice.c +10 -0
+        unsigned int total_cpus;
+
+        p = xsplice_work.data;
+        if ( !get_cpu_maps() )
+        {
+            printk(XENLOG_ERR "%s%s: CPU%u - unable to get cpu_maps lock!\n",
+                   XSPLICE, p->name, cpu);
+            per_cpu(work_to_do, cpu) = 0;
+            xsplice_work.data->rc = -EBUSY;
+            xsplice_work.do_work = 0;

On x86 such possibly simultaneous accesses may be okay, but is that universally the case? Wouldn't it better be only the monarch which updates shared data?

Quoted 5 lines
Quoted 1 line

Monarch? Oh you mean arch specific code path?

Oh, I think you call it "master" elsewhere. IA64 terminology which I came to like.

The master CPU is the one updating it.

Quoted 17 lines
Quoted 17 lines
Quoted 16 lines

xen/common/xsplice.c static int xsplice_list(xen_sysctl_xsplice_list_t *list) · line 881

Quoted 7 lines
xen/common/xsplice.c +7 -0
+        /* All CPUs are waiting, now signal to disable IRQs. */
+        xsplice_work.ready = 1;
+        smp_wmb();
+
+        atomic_inc(&xsplice_work.irq_semaphore);
+        if ( !xsplice_do_wait(&xsplice_work.irq_semaphore, timeout, total_cpus,
+                              "Timed out on IRQ semaphore") )

I'd prefer if the common parts of that message moved into xsplice_do_wait() - no reason to have more string literal space occupied than really needed. Also, looking back, the respective function parameter could do with a more descriptive name.

And then - does it make sense to wait the perhaps full 30ms on this second step? Rendezvoused CPUs should react rather quickly to the signal to disable interrupts.

Quoted 7 lines
Quoted 2 lines

We don't reset the timeout - the timeout is for both calls to xsplice_do_wait.

I understand that's the way it's right now, but that's what I'm putting under question. Rendezvousing CPUs is quite a bit more at risk of taking some time compared to having already rendezvoused CPUs disable their IRQs.

Yes. I could expand the timeout, but maybe have some reset (add more timeout) once CPUs come along?

Quoted 12 lines
Quoted 12 lines
Quoted 7 lines

xen/common/xsplice.c static void xsplice_printall(unsigned char key) · line 1088

Quoted 5 lines

static int __init xsplice_init(void)
{

xen/common/xsplice.c +3 -0
+    BUILD_BUG_ON( sizeof(struct xsplice_patch_func) != 64 );
+    BUILD_BUG_ON( offsetof(struct xsplice_patch_func, new_addr) != 8 );
+    BUILD_BUG_ON( offsetof(struct xsplice_patch_func, new_size) != 24 );

What assumptions get broken if these sizes change?

I think you mean the offsets? They can change. I added them to make sure that on 32-bit hypervisor (ARM) the offsets would be the same as on 64-bit hypervisor (x86).

Quoted 5 lines
Quoted 2 lines

The size however MUST remain the same - otherwise the toolstack won't produce proper payloads anymore.

Well, that's a very bad thing then imo. You'd better version the structure instead.

Andrew reminded me that we also will have build-ids. Those by nature imply a version. That is the payload won't ever apply against a different type hypervisor.

But I still added a version field in the struct so when we get the 'checking the old code' we have a mechanism to select -build-id or the newer way.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#91 lore raw

Re: [PATCH v5 11/28] xsplice: Implement support for applying/reverting/replacing patches.

Quoted 21 lines
Quoted 21 lines
Quoted 20 lines · On 07.04.16 at 05:05, <[email protected]> wrote:
Quoted 8 lines

xen/common/xsplice.c static int xsplice_list(xen_sysctl_xsplice_list_t *list) · line 881

Quoted 7 lines
xen/common/xsplice.c +7 -0
+        /* All CPUs are waiting, now signal to disable IRQs. */
+        xsplice_work.ready = 1;
+        smp_wmb();
+
+        atomic_inc(&xsplice_work.irq_semaphore);
+        if ( !xsplice_do_wait(&xsplice_work.irq_semaphore, timeout, total_cpus,
+                              "Timed out on IRQ semaphore") )
Quoted 8 lines

I'd prefer if the common parts of that message moved into xsplice_do_wait() - no reason to have more string literal space occupied than really needed. Also, looking back, the respective function parameter could do with a more descriptive name.

And then - does it make sense to wait the perhaps full 30ms on this second step? Rendezvoused CPUs should react rather quickly to the signal to disable interrupts.

We don't reset the timeout - the timeout is for both calls to xsplice_do_wait.

Quoted 7 lines
Quoted 4 lines

I understand that's the way it's right now, but that's what I'm putting under question. Rendezvousing CPUs is quite a bit more at risk of taking some time compared to having already rendezvoused CPUs disable their IRQs.

Yes. I could expand the timeout, but maybe have some reset (add more timeout) once CPUs come along?

Expand the timeout? Add more timeout? I don't understand. My point was about shortening the timeout on the second step.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#92 lore raw

Re: [PATCH v5 11/28] xsplice: Implement support for applying/reverting/replacing patches.

Quoted 26 lines · Jan Beulich
Quoted 26 lines
Quoted 25 lines
Quoted 14 lines · On 07.04.16 at 05:05, <[email protected]> wrote:
Quoted 13 lines

xen/common/xsplice.c static int xsplice_list(xen_sysctl_xsplice_list_t *list) · line 881

Quoted 7 lines
xen/common/xsplice.c +7 -0
+        /* All CPUs are waiting, now signal to disable IRQs. */
+        xsplice_work.ready = 1;
+        smp_wmb();
+
+        atomic_inc(&xsplice_work.irq_semaphore);
+        if ( !xsplice_do_wait(&xsplice_work.irq_semaphore, timeout, total_cpus,
+                              "Timed out on IRQ semaphore") )

I'd prefer if the common parts of that message moved into xsplice_do_wait() - no reason to have more string literal space occupied than really needed. Also, looking back, the respective function parameter could do with a more descriptive name.

Quoted 6 lines
Quoted 3 lines

And then - does it make sense to wait the perhaps full 30ms on this second step? Rendezvoused CPUs should react rather quickly to the signal to disable interrupts.

We don't reset the timeout - the timeout is for both calls to xsplice_do_wait.

I understand that's the way it's right now, but that's what I'm putting under question. Rendezvousing CPUs is quite a bit more at risk of taking some time compared to having already rendezvoused CPUs disable their IRQs.

Quoted 5 lines
Quoted 2 lines

Yes. I could expand the timeout, but maybe have some reset (add more timeout) once CPUs come along?

Expand the timeout? Add more timeout? I don't understand. My point was about shortening the timeout on the second step.

By how much?

The clock (timeout) starts ticking the moment the schedule_work is called - to quiten all the CPUs. Adding an acceleration once they have passed the #1 stage is modifying the semantics of the timeout ("well, it was 30ms, but once it goes over phase #1 it is shorten by half (or is it a quarter?").

Should we expose both timeouts to the sysctl so that the user can customize the acceleration ratio?

Perhaps we can fiddle with this later?

Quoted 3 lines

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#93 lore raw

Re: [PATCH v5 11/28] xsplice: Implement support for applying/reverting/replacing patches.

Quoted 29 lines
Quoted 1 line
Quoted 1 line · On 09.04.16 at 16:42, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines · On 07.04.16 at 05:05, <[email protected]> wrote:
Quoted 6 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+        /* All CPUs are waiting, now signal to disable IRQs. */
+        xsplice_work.ready = 1;
+        smp_wmb();
+
+        atomic_inc(&xsplice_work.irq_semaphore);
+        if ( !xsplice_do_wait(&xsplice_work.irq_semaphore, timeout, 

total_cpus,

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 7 lines
Quoted 7 lines
Quoted 1 line

+ "Timed out on IRQ semaphore") )

I'd prefer if the common parts of that message moved into xsplice_do_wait() - no reason to have more string literal space occupied than really needed. Also, looking back, the respective function parameter could do with a more descriptive name.

Quoted 6 lines
Quoted 3 lines

And then - does it make sense to wait the perhaps full 30ms on this second step? Rendezvoused CPUs should react rather quickly to the signal to disable interrupts.

We don't reset the timeout - the timeout is for both calls to xsplice_do_wait.

I understand that's the way it's right now, but that's what I'm putting under question. Rendezvousing CPUs is quite a bit more at risk of taking some time compared to having already rendezvoused CPUs disable their IRQs.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Yes. I could expand the timeout, but maybe have some reset (add more timeout) once CPUs come along?

Expand the timeout? Add more timeout? I don't understand. My point was about shortening the timeout on the second step.

By how much?

1ms would seem more than enough to me at a first glance.

Quoted 10 lines

The clock (timeout) starts ticking the moment the schedule_work is called - to quiten all the CPUs. Adding an acceleration once they have passed the #1 stage is modifying the semantics of the timeout ("well, it was 30ms, but once it goes over phase #1 it is shorten by half (or is it a quarter?").

Should we expose both timeouts to the sysctl so that the user can customize the acceleration ratio?

Perhaps we can fiddle with this later?

Sure. It was just a thought, not an immediate requirement.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#94 lore raw

Re: [PATCH v5 11/28] xsplice: Implement support for applying/reverting/replacing patches.

In reply to Jan Beulich
Quoted 2 lines

That's for an individual patch I suppose? What if REPLACE has to revert dozens or hundreds of patches?

I don't know. That is sometihng I need to figure out. I also need to test this out on the 8 socket machine..

Quoted 6 lines

xen/arch/x86/xsplice.c line 29

Quoted 3 lines
xen/arch/x86/xsplice.c +3 -0
+void arch_xsplice_apply_jmp(struct xsplice_patch_func *func)
+{
+    uint32_t val;

The way it's being used below, it clearly should be int32_t.

Quoted 10 lines

xen/arch/x86/xsplice.c line 35

Quoted 6 lines
xen/arch/x86/xsplice.c +6 -0
+    uint8_t *old_ptr;
+
+    BUILD_BUG_ON(PATCH_INSN_SIZE > sizeof(func->undo));
+    BUILD_BUG_ON(PATCH_INSN_SIZE != (1 + sizeof val));
+
+    old_ptr = (uint8_t *)func->old_addr;

(Considering this cast, the "old_addr" member should be unsigned long (or void *), not uint64_t: The latest on ARM32 such would otherwise cause problems.)

I has to be uint8_t to make the single byte modifications. Keep also in mind that this file is only for x86.

Quoted 3 lines

Also - where is the verification that
func->old_size >= PATCH_INSN_SIZE?

I made a 'arch_xsplice_verify_func' to have per-architecture check for that.
..

Quoted 9 lines
Quoted 9 lines
xen/common/xsplice.c +9 -0
+        sec = xsplice_elf_sec_by_name(elf, names[i]);
+        if ( !sec )
+        {
+            printk(XENLOG_ERR "%s%s: %s is missing!\n",
+                   XSPLICE, elf->name, names[i]);
+            return -EINVAL;
+        }
+
+        if ( !sec->sec->sh_size )
Quoted 8 lines

xen/common/xsplice.c static int secure_payload(struct payload *payload, struct xsplice_elf *elf) · line 357

Quoted 5 lines
xen/common/xsplice.c +5 -0
+            return -EINVAL;
+    }
+
+    return 0;
+}

So you check for there being one such section. Is having multiple of them okay / meaningful?

I've been going back on this. I think at this point I will say no. I am going to look at what is involved in this in later versions.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#95 lore raw

Re: [PATCH v5 11/28] xsplice: Implement support for applying/reverting/replacing patches.

Quoted 12 lines
Quoted 11 lines

xen/arch/x86/xsplice.c line 35

Quoted 7 lines · On 07.04.16 at 05:09, <[email protected]> wrote:
xen/arch/x86/xsplice.c +6 -0
+    uint8_t *old_ptr;
+
+    BUILD_BUG_ON(PATCH_INSN_SIZE > sizeof(func->undo));
+    BUILD_BUG_ON(PATCH_INSN_SIZE != (1 + sizeof val));
+
+    old_ptr = (uint8_t *)func->old_addr;

(Considering this cast, the "old_addr" member should be unsigned long (or void *), not uint64_t: The latest on ARM32 such would otherwise cause problems.)

Quoted 2 lines

I has to be uint8_t to make the single byte modifications. Keep also in mind that this file is only for x86.

old_addr can't reasonably be uint8_t, so I can only assume you're mixing up things here. (And yes, I do realize this is x86 code, but my reference to ARM32 was only mean to say that there you'll need to do something similar, and casting uint64_t to whatever kind of pointer type is not going to work without compiler warning.)

Quoted 24 lines
Quoted 2 lines

Also - where is the verification that
func->old_size >= PATCH_INSN_SIZE?

I made a 'arch_xsplice_verify_func' to have per-architecture check for that.
..

Quoted 9 lines
Quoted 9 lines
xen/common/xsplice.c +9 -0
+        sec = xsplice_elf_sec_by_name(elf, names[i]);
+        if ( !sec )
+        {
+            printk(XENLOG_ERR "%s%s: %s is missing!\n",
+                   XSPLICE, elf->name, names[i]);
+            return -EINVAL;
+        }
+
+        if ( !sec->sec->sh_size )
Quoted 8 lines

xen/common/xsplice.c static int secure_payload(struct payload *payload, struct xsplice_elf *elf) · line 357

Quoted 5 lines
xen/common/xsplice.c +5 -0
+            return -EINVAL;
+    }
+
+    return 0;
+}

So you check for there being one such section. Is having multiple of them okay / meaningful?

Quoted 2 lines

I've been going back on this. I think at this point I will say no. I am going to look at what is involved in this in later versions.

And check for there being exactly one for now, I then assume?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#96 lore raw

Re: [PATCH v5 11/28] xsplice: Implement support for applying/reverting/replacing patches.

Quoted 12 lines · Jan Beulich
Quoted 12 lines
Quoted 11 lines

xen/arch/x86/xsplice.c line 35

Quoted 7 lines · On 07.04.16 at 05:09, <[email protected]> wrote:
xen/arch/x86/xsplice.c +6 -0
+    uint8_t *old_ptr;
+
+    BUILD_BUG_ON(PATCH_INSN_SIZE > sizeof(func->undo));
+    BUILD_BUG_ON(PATCH_INSN_SIZE != (1 + sizeof val));
+
+    old_ptr = (uint8_t *)func->old_addr;

(Considering this cast, the "old_addr" member should be unsigned long (or void *), not uint64_t: The latest on ARM32 such would otherwise cause problems.)

Quoted 8 lines
Quoted 2 lines

I has to be uint8_t to make the single byte modifications. Keep also in mind that this file is only for x86.

old_addr can't reasonably be uint8_t, so I can only assume you're mixing up things here. (And yes, I do realize this is x86 code, but my reference to ARM32 was only mean to say that there you'll need to do something similar, and casting uint64_t to whatever kind of pointer type is not going to work without compiler warning.)

Way back .. when we spoke about the .xsplice.funcs structure you recommended to make the types be either uintXX specific or Elf types. I choose Elf types but then we realized that ARM32 hypervisor would be involved which of course would have a different size of the structure. So I went with uintXXX to save a bit of headache (specifically those BUILD_BUG_ON checks).

I can't see making the old_addr be unsigned long or void *, which means going back to Elf types. And for ARM32 I will have to deal with a different structure size.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#97 lore raw

Re: [PATCH v5 11/28] xsplice: Implement support for applying/reverting/replacing patches.

Quoted 30 lines · Konrad Rzeszutek Wilk
Quoted 12 lines · Jan Beulich
Quoted 12 lines
Quoted 11 lines

xen/arch/x86/xsplice.c line 35

Quoted 7 lines · On 07.04.16 at 05:09, <[email protected]> wrote:
xen/arch/x86/xsplice.c +6 -0
+    uint8_t *old_ptr;
+
+    BUILD_BUG_ON(PATCH_INSN_SIZE > sizeof(func->undo));
+    BUILD_BUG_ON(PATCH_INSN_SIZE != (1 + sizeof val));
+
+    old_ptr = (uint8_t *)func->old_addr;

(Considering this cast, the "old_addr" member should be unsigned long (or void *), not uint64_t: The latest on ARM32 such would otherwise cause problems.)

Quoted 8 lines
Quoted 2 lines

I has to be uint8_t to make the single byte modifications. Keep also in mind that this file is only for x86.

old_addr can't reasonably be uint8_t, so I can only assume you're mixing up things here. (And yes, I do realize this is x86 code, but my reference to ARM32 was only mean to say that there you'll need to do something similar, and casting uint64_t to whatever kind of pointer type is not going to work without compiler warning.)

Way back .. when we spoke about the .xsplice.funcs structure you recommended to make the types be either uintXX specific or Elf types. I choose Elf types but then we realized that ARM32 hypervisor would be involved which of course would have a different size of the structure. So I went with uintXXX to save a bit of headache (specifically those BUILD_BUG_ON checks).

Quoted 3 lines

I can't see making the old_addr be unsigned long or void *, which means going back to Elf types. And for ARM32 I will have to deal with a different structure size.

Oh gosh, that is going to be problem with our headers as I would be now exposing the 'xsplice_patch_func' structure in a public header which would depend on Elf_X types.

And we do not expose those. Moving the whole elfstructs.h to public directory is a bit .. harsh.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#98 lore raw

Re: [PATCH v5 11/28] xsplice: Implement support for applying/reverting/replacing patches.

Quoted 32 lines
Quoted 1 line
Quoted 1 line · On 10.04.16 at 04:45, <[email protected]> wrote:
Quoted 30 lines · Konrad Rzeszutek Wilk
Quoted 12 lines · Jan Beulich
Quoted 12 lines
Quoted 11 lines

xen/arch/x86/xsplice.c line 35

Quoted 7 lines · On 07.04.16 at 05:09, <[email protected]> wrote:
xen/arch/x86/xsplice.c +6 -0
+    uint8_t *old_ptr;
+
+    BUILD_BUG_ON(PATCH_INSN_SIZE > sizeof(func->undo));
+    BUILD_BUG_ON(PATCH_INSN_SIZE != (1 + sizeof val));
+
+    old_ptr = (uint8_t *)func->old_addr;

(Considering this cast, the "old_addr" member should be unsigned long (or void *), not uint64_t: The latest on ARM32 such would otherwise cause problems.)

Quoted 8 lines
Quoted 2 lines

I has to be uint8_t to make the single byte modifications. Keep also in mind that this file is only for x86.

old_addr can't reasonably be uint8_t, so I can only assume you're mixing up things here. (And yes, I do realize this is x86 code, but my reference to ARM32 was only mean to say that there you'll need to do something similar, and casting uint64_t to whatever kind of pointer type is not going to work without compiler warning.)

Way back .. when we spoke about the .xsplice.funcs structure you recommended to make the types be either uintXX specific or Elf types. I choose Elf types but then we realized that ARM32 hypervisor would be involved which of course would have a different size of the structure. So I went with uintXXX to save a bit of headache (specifically those BUILD_BUG_ON checks).

Quoted 7 lines
Quoted 3 lines

I can't see making the old_addr be unsigned long or void *, which means going back to Elf types. And for ARM32 I will have to deal with a different structure size.

Oh gosh, that is going to be problem with our headers as I would be now exposing the 'xsplice_patch_func' structure in a public header which would depend on Elf_X types.

So how about uintptr_t? Not exactly the thing we do in public headers already, but at least a possibility. Or else maybe xen_ulong_t, albeit on ARM32 that again won't cast well to pointer types.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#99 lore raw

Re: [PATCH v5 11/28] xsplice: Implement support for applying/reverting/replacing patches.

Quoted 37 lines · Jan Beulich
Quoted 37 lines
Quoted 2 lines
Quoted 2 lines · On 10.04.16 at 04:45, <[email protected]> wrote:
Quoted 33 lines · Konrad Rzeszutek Wilk
Quoted 12 lines · Jan Beulich
Quoted 12 lines
Quoted 11 lines

Review

Quoted 7 lines · On 07.04.16 at 05:09, <[email protected]> wrote:
(quoted diff) +6 -0
+    uint8_t *old_ptr;
+
+    BUILD_BUG_ON(PATCH_INSN_SIZE > sizeof(func->undo));
+    BUILD_BUG_ON(PATCH_INSN_SIZE != (1 + sizeof val));
+
+    old_ptr = (uint8_t *)func->old_addr;

(Considering this cast, the "old_addr" member should be unsigned long (or void *), not uint64_t: The latest on ARM32 such would otherwise cause problems.)

Quoted 8 lines
Quoted 2 lines

I has to be uint8_t to make the single byte modifications. Keep also in mind that this file is only for x86.

old_addr can't reasonably be uint8_t, so I can only assume you're mixing up things here. (And yes, I do realize this is x86 code, but my reference to ARM32 was only mean to say that there you'll need to do something similar, and casting uint64_t to whatever kind of pointer type is not going to work without compiler warning.)

Way back .. when we spoke about the .xsplice.funcs structure you recommended to make the types be either uintXX specific or Elf types. I choose Elf types but then we realized that ARM32 hypervisor would be involved which of course would have a different size of the structure. So I went with uintXXX to save a bit of headache (specifically those BUILD_BUG_ON checks).

I can't see making the old_addr be unsigned long or void *, which means going back to Elf types. And for ARM32 I will have to deal with a different structure size.

Quoted 8 lines
Quoted 3 lines

Oh gosh, that is going to be problem with our headers as I would be now exposing the 'xsplice_patch_func' structure in a public header which would depend on Elf_X types.

So how about uintptr_t? Not exactly the thing we do in public headers already, but at least a possibility. Or else maybe xen_ulong_t, albeit on ARM32 that again won't cast well to pointer types.

I ended up (see v7 patches) making it uint64_t in public and in the private void*.

Quoted 3 lines

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#100 lore raw

Is: ARM maintainers advice ..Was:Re: [PATCH v5 11/28] xsplice: Implement support for applying/reverting/replacing patches.

In reply to Konrad Rzeszutek Wilk
Quoted 30 lines · Konrad Rzeszutek Wilk
Quoted 12 lines · Jan Beulich
Quoted 12 lines
Quoted 11 lines

xen/arch/x86/xsplice.c line 35

Quoted 7 lines · On 07.04.16 at 05:09, <[email protected]> wrote:
xen/arch/x86/xsplice.c +6 -0
+    uint8_t *old_ptr;
+
+    BUILD_BUG_ON(PATCH_INSN_SIZE > sizeof(func->undo));
+    BUILD_BUG_ON(PATCH_INSN_SIZE != (1 + sizeof val));
+
+    old_ptr = (uint8_t *)func->old_addr;

(Considering this cast, the "old_addr" member should be unsigned long (or void *), not uint64_t: The latest on ARM32 such would otherwise cause problems.)

Quoted 8 lines
Quoted 2 lines

I has to be uint8_t to make the single byte modifications. Keep also in mind that this file is only for x86.

old_addr can't reasonably be uint8_t, so I can only assume you're mixing up things here. (And yes, I do realize this is x86 code, but my reference to ARM32 was only mean to say that there you'll need to do something similar, and casting uint64_t to whatever kind of pointer type is not going to work without compiler warning.)

Way back .. when we spoke about the .xsplice.funcs structure you recommended to make the types be either uintXX specific or Elf types. I choose Elf types but then we realized that ARM32 hypervisor would be involved which of course would have a different size of the structure. So I went with uintXXX to save a bit of headache (specifically those BUILD_BUG_ON checks).

Quoted 3 lines

I can't see making the old_addr be unsigned long or void *, which means going back to Elf types. And for ARM32 I will have to deal with a different structure size.

CC-ing Stefano and Julien here to advise. I ended up exposing the ABI part in sysctl.h (and design document as):

#define XSPLICE_PAYLOAD_VERSION 1
/*
* .xsplice.funcs structure layout defined in the Payload format
* section in the xSplice design document.
*
* The size should be exactly 64 bytes.
*/
struct xsplice_patch_func {
const char *name; /* Name of function to be patched. */
uint64_t new_addr;
uint64_t old_addr; /* Can be zero and name will be looked up. */
uint32_t new_size;
uint32_t old_size;
uint8_t version; /* MUST be XSPLICE_PAYLOAD_VERSION. */
uint8_t pad[31]; /* MUST be zero filled. */
};
typedef struct xsplice_patch_func xsplice_patch_func_t;

Which looks nice.

When the ELF file is loaded we load it as this structure:

[x86]
#ifndef CONFIG_ARM

struct xsplice_patch_func_internal {
    const char *name;
    void *new_addr;
    void *old_addr;
    uint32_t new_size;
    uint32_t old_size;
    uint8_t version;
    union {
        uint8_t undo[8];
        uint8_t pad[31];
    } u;
};
#else
[ARM]
struct xsplice_patch_func_internal {
    const char *name;
    uint32_t _pad0;
    void *new_addr;
    uint32_t _pad1;
    void *old_addr;
    uint32_t _pad2;
    uint32_t new_size;
    uint32_t old_size;
    uint8_t version;
    union {
        uint8_t pad[31];
    } u;
};

#endif

That allows the size and offsets to be the same. I checked under ARM32 builds:

struct xsplice_patch_func_internal {

    const char  *              name;                 /*     0     4 */
    uint32_t                   _pad0;                /*     4     4 */
    void *                     new_addr;             /*     8     4 */
    uint32_t                   _pad1;                /*    12     4 */
    void *                     old_addr;             /*    16     4 */
    uint32_t                   _pad2;                /*    20     4 */
    uint32_t                   new_size;             /*    24     4 */
    uint32_t                   old_size;             /*    28     4 */
    uint8_t                    version;              /*    32     1 */
    union {
        uint8_t            pad[31];              /*          31 */
    } u;                                             /*    33    31 */
    /* --- cacheline 1 boundary (64 bytes) --- */

    /* size: 64, cachelines: 1, members: 10 */
};

So it all looks correct. (and I can cast the old_addr to uint8_t). Naturally we can expand the pad[] to hold whatever is needed when implementing xSplice under ARM

However I would appreciate advise from ARM folks if I made some wrong assumptions..

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#101 lore raw

Re: Is: ARM maintainers advice ..Was:Re: [PATCH v5 11/28] xsplice: Implement support for applying/reverting/replacing patches.

Quoted 115 lines · Konrad Rzeszutek Wilk
Quoted 30 lines · Konrad Rzeszutek Wilk
Quoted 12 lines · Jan Beulich
Quoted 12 lines
Quoted 11 lines

xen/arch/x86/xsplice.c line 35

Quoted 7 lines · On 07.04.16 at 05:09, <[email protected]> wrote:
xen/arch/x86/xsplice.c +6 -0
+    uint8_t *old_ptr;
+
+    BUILD_BUG_ON(PATCH_INSN_SIZE > sizeof(func->undo));
+    BUILD_BUG_ON(PATCH_INSN_SIZE != (1 + sizeof val));
+
+    old_ptr = (uint8_t *)func->old_addr;

(Considering this cast, the "old_addr" member should be unsigned long (or void *), not uint64_t: The latest on ARM32 such would otherwise cause problems.)

Quoted 8 lines
Quoted 2 lines

I has to be uint8_t to make the single byte modifications. Keep also in mind that this file is only for x86.

old_addr can't reasonably be uint8_t, so I can only assume you're mixing up things here. (And yes, I do realize this is x86 code, but my reference to ARM32 was only mean to say that there you'll need to do something similar, and casting uint64_t to whatever kind of pointer type is not going to work without compiler warning.)

Way back .. when we spoke about the .xsplice.funcs structure you recommended to make the types be either uintXX specific or Elf types. I choose Elf types but then we realized that ARM32 hypervisor would be involved which of course would have a different size of the structure. So I went with uintXXX to save a bit of headache (specifically those BUILD_BUG_ON checks).

Quoted 3 lines

I can't see making the old_addr be unsigned long or void *, which means going back to Elf types. And for ARM32 I will have to deal with a different structure size.

CC-ing Stefano and Julien here to advise. I ended up exposing the ABI part in sysctl.h (and design document as):

#define XSPLICE_PAYLOAD_VERSION 1
/*
* .xsplice.funcs structure layout defined in the Payload format
* section in the xSplice design document.
*
* The size should be exactly 64 bytes.
*/
struct xsplice_patch_func {
const char *name; /* Name of function to be patched. */
uint64_t new_addr;
uint64_t old_addr; /* Can be zero and name will be looked up. */
uint32_t new_size;
uint32_t old_size;
uint8_t version; /* MUST be XSPLICE_PAYLOAD_VERSION. */
uint8_t pad[31]; /* MUST be zero filled. */
};
typedef struct xsplice_patch_func xsplice_patch_func_t;

Which looks nice.

When the ELF file is loaded we load it as this structure:

[x86]
#ifndef CONFIG_ARM

struct xsplice_patch_func_internal {
    const char *name;
    void *new_addr;
    void *old_addr;
    uint32_t new_size;
    uint32_t old_size;
    uint8_t version;
    union {
        uint8_t undo[8];
        uint8_t pad[31];
    } u;
};
#else
[ARM]
struct xsplice_patch_func_internal {
    const char *name;
    uint32_t _pad0;
    void *new_addr;
    uint32_t _pad1;
    void *old_addr;
    uint32_t _pad2;
    uint32_t new_size;
    uint32_t old_size;
    uint8_t version;
    union {
        uint8_t pad[31];
    } u;
};

#endif

That allows the size and offsets to be the same. I checked under ARM32 builds:

struct xsplice_patch_func_internal {

    const char  *              name;                 /*     0     4 */
    uint32_t                   _pad0;                /*     4     4 */
    void *                     new_addr;             /*     8     4 */
    uint32_t                   _pad1;                /*    12     4 */
    void *                     old_addr;             /*    16     4 */
    uint32_t                   _pad2;                /*    20     4 */
    uint32_t                   new_size;             /*    24     4 */
    uint32_t                   old_size;             /*    28     4 */
    uint8_t                    version;              /*    32     1 */
    union {
        uint8_t            pad[31];              /*          31 */
    } u;                                             /*    33    31 */
    /* --- cacheline 1 boundary (64 bytes) --- */

    /* size: 64, cachelines: 1, members: 10 */
};
Quoted 6 lines

So it all looks correct. (and I can cast the old_addr to uint8_t). Naturally we can expand the pad[] to hold whatever is needed when implementing xSplice under ARM

However I would appreciate advise from ARM folks if I made some wrong assumptions..

It looks good. I take that ARM64 will be like x86. In that case, instead of #ifdef'ing x86 or ARM, I would #ifdef BITS_PER_LONG or POINTER_ALIGN.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#102 lore raw

Is: ARM maintainers advice ..Was:Re: [PATCH v5 11/28] xsplice: Implement support for applying/reverting/replacing patches.

In reply to Konrad Rzeszutek Wilk
Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 10.04.16 at 21:47, <[email protected]> wrote:

That allows the size and offsets to be the same. I checked under ARM32 builds:

struct xsplice_patch_func_internal {

    const char  *              name;                 /*     0     4 */
    uint32_t                   _pad0;                /*     4     4 */
    void *                     new_addr;             /*     8     4 */
    uint32_t                   _pad1;                /*    12     4 */
    void *                     old_addr;             /*    16     4 */
    uint32_t                   _pad2;                /*    20     4 */
    uint32_t                   new_size;             /*    24     4 */
    uint32_t                   old_size;             /*    28     4 */
    uint8_t                    version;              /*    32     1 */
    union {
        uint8_t            pad[31];              /*          31 */
    } u;                                             /*    33    31 */
    /* --- cacheline 1 boundary (64 bytes) --- */

    /* size: 64, cachelines: 1, members: 10 */
};
Quoted 3 lines

So it all looks correct. (and I can cast the old_addr to uint8_t). Naturally we can expand the pad[] to hold whatever is needed when implementing xSplice under ARM

I still don't get: Why is it so important for this structure to have the same size and layout across architectures?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#103 lore raw

Re: Is: ARM maintainers advice ..Was:Re: [PATCH v5 11/28] xsplice: Implement support for applying/reverting/replacing patches.

Quoted 23 lines · Jan Beulich
Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 10.04.16 at 21:47, <[email protected]> wrote:

That allows the size and offsets to be the same. I checked under ARM32 builds:

struct xsplice_patch_func_internal {

    const char  *              name;                 /*     0     4 */
    uint32_t                   _pad0;                /*     4     4 */
    void *                     new_addr;             /*     8     4 */
    uint32_t                   _pad1;                /*    12     4 */
    void *                     old_addr;             /*    16     4 */
    uint32_t                   _pad2;                /*    20     4 */
    uint32_t                   new_size;             /*    24     4 */
    uint32_t                   old_size;             /*    28     4 */
    uint8_t                    version;              /*    32     1 */
    union {
        uint8_t            pad[31];              /*          31 */
    } u;                                             /*    33    31 */
    /* --- cacheline 1 boundary (64 bytes) --- */

    /* size: 64, cachelines: 1, members: 10 */
};
Quoted 6 lines
Quoted 3 lines

So it all looks correct. (and I can cast the old_addr to uint8_t). Naturally we can expand the pad[] to hold whatever is needed when implementing xSplice under ARM

I still don't get: Why is it so important for this structure to have the same size and layout across architectures?

I have a very bad taste from the blkif.h struct request where the structure size is 112 or 108 depending on the 32 vs 64.

Having the same offsets for variables should make it easier for the tools to generate the payload much simpler without having to worry about the sizes or offset. Also it means that the common code BUILT_IN_BUG can be generic across ARM and x86.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#104 lore raw

Re: Is: ARM maintainers advice ..Was:Re: [PATCH v5 11/28] xsplice: Implement support for applying/reverting/replacing patches.

Quoted 29 lines
Quoted 1 line
Quoted 1 line · On 11.04.16 at 17:50, <[email protected]> wrote:
Quoted 27 lines · Jan Beulich
Quoted 26 lines
Quoted 1 line
Quoted 1 line · On 10.04.16 at 21:47, <[email protected]> wrote:

That allows the size and offsets to be the same. I checked under ARM32 builds:

struct xsplice_patch_func_internal {

    const char  *              name;                 /*     0     4 */
    uint32_t                   _pad0;                /*     4     4 */
    void *                     new_addr;             /*     8     4 */
    uint32_t                   _pad1;                /*    12     4 */
    void *                     old_addr;             /*    16     4 */
    uint32_t                   _pad2;                /*    20     4 */
    uint32_t                   new_size;             /*    24     4 */
    uint32_t                   old_size;             /*    28     4 */
    uint8_t                    version;              /*    32     1 */
    union {
        uint8_t            pad[31];              /*          31 */
    } u;                                             /*    33    31 */
    /* --- cacheline 1 boundary (64 bytes) --- */

    /* size: 64, cachelines: 1, members: 10 */
};

So it all looks correct. (and I can cast the old_addr to uint8_t). Naturally we can expand the pad[] to hold whatever is needed when implementing xSplice under ARM

Quoted 5 lines
Quoted 2 lines

I still don't get: Why is it so important for this structure to have the same size and layout across architectures?

I have a very bad taste from the blkif.h struct request where the structure size is 112 or 108 depending on the 32 vs 64.

The two have very little - if anything - in common imo.

Quoted 4 lines

Having the same offsets for variables should make it easier for the tools to generate the payload much simpler without having to worry about the sizes or offset. Also it means that the common code BUILT_IN_BUG can be generic across ARM and x86.

None of this seems overly hard to retain even when the structure size wasn't consistent - just that you couldn't use a literal 64 anymore, for example.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#105 lore raw

PATCH v5 12/28 x86/xen_hello_world.xsplice: Test payload for patching 'xen_extra_version'.

In reply to Konrad Rzeszutek Wilk

This change demonstrates how to generate an xSplice ELF payload.

The idea here is that we want to patch in the hypervisor the 'xen_version_extra' function with an function that will return 'Hello World'. The 'xl info | grep extraversion' will reflect the new value after the patching.

To generate this ELF payload file we need:
- C code of the new code (xen_hello_world_func.c).
- C code generating the .xsplice.funcs structure (xen_hello_world.c)
- The address of the old code (xen_extra_version). We retrieve it by using 'nm --defined' on xen-syms.
- The size of the new and old code for which we use nm --defined -S on our code and xen-syms respectively.

There are two C files and one header files generated during build. One could make this one C file if the size of the newly patched function size was known in advance (or an random value was choosen).

There is also a strict order of compiling:
1) xen_hello_world_func.c
2) config.h - extract the size of the new function, the old function and the old function address.
3) xen_hello_world.c - which contains the .xsplice.funcs structure.
4) Link the object files in an xen_hello_world.xsplice file.

The use-case is simple:

$xen-xsplice load /usr/lib/debug/xen_hello_world.xsplice $xen-xsplice list
ID | status
----------------------------------------+------------
xen_hello_world APPLIED
$xl info | grep extra
xen_extra : Hello World
$xen-xsplice revert xen_hello_world
Performing revert: completed
$xen-xsplice unload xen_hello_world
Performing unload: completed
$xl info | grep extra
xen_extra : -unstable

---
Cc: Stefano Stabellini <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>

v2: Do it using hypervisor Makefiles
v3: Remove the stale linker file.
Add Copyright and local definition block
s/name/xen_hello_world_name/

---
 .gitignore                               |  2 ++
 docs/misc/xsplice.markdown               | 36 ++++++++++++++++++++++
 xen/Makefile                             |  2 ++
 xen/arch/arm/Makefile                    |  4 +++
 xen/arch/x86/Makefile                    |  6 ++++
 xen/arch/x86/test/Makefile               | 53 ++++++++++++++++++++++++++++++++
 xen/arch/x86/test/xen_hello_world.c      | 30 ++++++++++++++++++
 xen/arch/x86/test/xen_hello_world_func.c | 23 ++++++++++++++
 8 files changed, 156 insertions(+)
 create mode 100644 xen/arch/x86/test/Makefile
 create mode 100644 xen/arch/x86/test/xen_hello_world.c
 create mode 100644 xen/arch/x86/test/xen_hello_world_func.c
.gitignore +2 -0
index b9c9550..8dc76b5 100644
@@ -245,6 +245,8 @@ xen/arch/x86/efi.lds
 xen/arch/x86/efi/check.efi
 xen/arch/x86/efi/disabled
 xen/arch/x86/efi/mkreloc
+xen/arch/x86/test/config.h
+xen/arch/x86/test/xen_hello_world.xsplice
 xen/arch/*/efi/boot.c
 xen/arch/*/efi/compat.c
 xen/arch/*/efi/efi.h
docs/misc/xsplice.markdown +36 -0
index 28140dd..a498a61 100644
@@ -321,11 +321,47 @@ size.
 
 When applying the patch the hypervisor iterates over each `xsplice_patch_func`
 structure and the core code inserts a trampoline at `old_addr` to `new_addr`.
+The `new_addr` is altered when the ELF payload is loaded.
 
 When reverting a patch, the hypervisor iterates over each `xsplice_patch_func`
 and the core code copies the data from the undo buffer (private internal copy)
 to `old_addr`.
 
+### Example
+
+A simple example of what a payload file can be:
+
+<pre>
+/* MUST be in sync with hypervisor. */  
+struct xsplice_patch_func {  
+    const char *name;  
+    uint64_t new_addr;  
+    uint64_t old_addr;  
+    uint32_t new_size;  
+    uint32_t old_size;  
+    uint8_t pad[32];  
+};  
+
+/* Our replacement function for xen_extra_version. */  
+const char *xen_hello_world(void)  
+{  
+    return "Hello World";  
+}  
+
+static unsigned char name[] = "xen_hello_world";  
+
+struct xsplice_patch_func xsplice_hello_world = {  
+    .name = name,  
+    .new_addr = (unsigned long)(xen_hello_world),  
+    .old_addr = 0xffff82d08013963c, /* Extracted from xen-syms. */  
+    .new_size = 13, /* To be be computed by scripts. */  
+    .old_size = 13, /* -----------""---------------  */  
+} __attribute__((__section__(".xsplice.funcs")));  
+
+</pre>
+
+Code must be compiled with -fPIC.
+
 ## Hypercalls
 
 We will employ the sub operations of the system management hypercall (sysctl).
xen/Makefile +2 -0
index c908544..2be7deb 100644
@@ -75,6 +75,7 @@ _install: $(TARGET)$(CONFIG_XEN_INSTALL_SUFFIX)
 			echo 'EFI installation only partially done (EFI_VENDOR not set)' >&2; \
 		fi; \
 	fi
+	$(MAKE) -f $(BASEDIR)/Rules.mk -C arch/$(TARGET_ARCH) install
 
 .PHONY: _uninstall
 _uninstall: D=$(DESTDIR)
@@ -92,6 +93,7 @@ _uninstall:
 	rm -f $(D)$(EFI_DIR)/$(T)-$(XEN_VERSION).efi
 	rm -f $(D)$(EFI_DIR)/$(T).efi
 	rm -f $(D)$(EFI_MOUNTPOINT)/efi/$(EFI_VENDOR)/$(T)-$(XEN_FULLVERSION).efi
+	$(MAKE) -f $(BASEDIR)/Rules.mk -C arch/$(TARGET_ARCH) uninstall
 
 .PHONY: _debug
 _debug:
xen/arch/arm/Makefile +4 -0
index eae5cb3..17e9e3a 100644
@@ -57,6 +57,10 @@ ifeq ($(CONFIG_ARM_64),y)
 	ln -sf $(notdir $@)  ../../$(notdir $@).efi
 endif
 
+install:
+
+uninstall:
+
 $(TARGET).axf: $(TARGET)-syms
 	# XXX: VE model loads by VMA so instead of
 	# making a proper ELF we link with LMA == VMA and adjust crudely
xen/arch/x86/Makefile +6 -0
index 8a6a7d5..d9416d1 100644
@@ -75,7 +75,12 @@ efi-y := $(shell if [ ! -r $(BASEDIR)/include/xen/compile.h -o \
 $(TARGET): $(TARGET)-syms $(efi-y) boot/mkelf32
 	./boot/mkelf32 $(TARGET)-syms $(TARGET) 0x100000 \
 	`$(NM) -nr $(TARGET)-syms | head -n 1 | sed -e 's/^\([^ ]*\).*/0x\1/'`
+	$(MAKE) -f $(BASEDIR)/Rules.mk -C test
 
+install:
+	$(MAKE) -f $(BASEDIR)/Rules.mk -C test install
+uninstall:
+	$(MAKE) -f $(BASEDIR)/Rules.mk -C test uninstall
 
 ALL_OBJS := $(BASEDIR)/arch/x86/boot/built_in.o $(BASEDIR)/arch/x86/efi/built_in.o $(ALL_OBJS)
 
@@ -179,3 +184,4 @@ clean::
 	rm -f $(BASEDIR)/.xen-syms.[0-9]* boot/.*.d
 	rm -f $(BASEDIR)/.xen.efi.[0-9]* efi/*.o efi/.*.d efi/*.efi efi/disabled efi/mkreloc
 	rm -f boot/reloc.S boot/reloc.lnk boot/reloc.bin
+	$(MAKE) -f $(BASEDIR)/Rules.mk -C test clean
xen/arch/x86/test/Makefile new file +53 -0

53 lines not on this page · raw message

xen/arch/x86/test/xen_hello_world.c new file +30 -0
new file mode 100644
index 0000000..f6ac098
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
+ *
+ */
+
+#include <xen/config.h>
+#include <xen/types.h>
+#include <xen/xsplice.h>
+#include "config.h"
+
+static char xen_hello_world_name[] = "xen_hello_world";
+extern const char *xen_hello_world(void);
+
+struct xsplice_patch_func __section(".xsplice.funcs") xsplice_xen_hello_world = {
+    .name = xen_hello_world_name,
+    .new_addr = (unsigned long)(xen_hello_world),
+    .old_addr = OLD_CODE,
+    .new_size = NEW_CODE_SZ,
+    .old_size = OLD_CODE_SZ,
+};
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/arch/x86/test/xen_hello_world_func.c new file +23 -0
new file mode 100644
index 0000000..81380a6
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
+ *
+ */
+
+#include <xen/config.h>
+#include <xen/types.h>
+
+/* Our replacement function for xen_extra_version. */
+const char *xen_hello_world(void)
+{
+    return "Hello World";
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Signature · 7 lines
2.5.0


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#106 lore raw

Re: [PATCH v5 12/28] x86/xen_hello_world.xsplice: Test payload for patching 'xen_extra_version'.

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 24.03.16 at 21:00, <[email protected]> wrote:
xen/Makefile +1 -0
@@ -75,6 +75,7 @@ _install: $(TARGET)$(CONFIG_XEN_INSTALL_SUFFIX)
 			echo 'EFI installation only partially done (EFI_VENDOR not set)' >&2; \
 		fi; \
 	fi
+	$(MAKE) -f $(BASEDIR)/Rules.mk -C arch/$(TARGET_ARCH) install
 
 .PHONY: _uninstall
 _uninstall: D=$(DESTDIR)

xen/Makefile _uninstall: · line 96

Quoted 4 lines
xen/Makefile +1 -0
@@ -92,6 +93,7 @@ _uninstall:
 	rm -f $(D)$(EFI_DIR)/$(T)-$(XEN_VERSION).efi
 	rm -f $(D)$(EFI_DIR)/$(T).efi
 	rm -f $(D)$(EFI_MOUNTPOINT)/efi/$(EFI_VENDOR)/$(T)-$(XEN_FULLVERSION).efi
+	$(MAKE) -f $(BASEDIR)/Rules.mk -C arch/$(TARGET_ARCH) uninstall

Pretty certainly stray changes, or they'd need a really good explanation.

xen/arch/x86/Makefile efi-y := $(shell if [ ! -r $(BASEDIR)/include/xen/compile.h -o \ · line 83

Quoted 12 lines
xen/arch/x86/Makefile +5 -0
@@ -75,7 +75,12 @@ efi-y := $(shell if [ ! -r $(BASEDIR)/include/xen/compile.h -o \
 $(TARGET): $(TARGET)-syms $(efi-y) boot/mkelf32
 	./boot/mkelf32 $(TARGET)-syms $(TARGET) 0x100000 \
 	`$(NM) -nr $(TARGET)-syms | head -n 1 | sed -e 's/^\([^ ]*\).*/0x\1/'`
+	$(MAKE) -f $(BASEDIR)/Rules.mk -C test
 
+install:
+	$(MAKE) -f $(BASEDIR)/Rules.mk -C test install
+uninstall:
+	$(MAKE) -f $(BASEDIR)/Rules.mk -C test uninstall

Tests or examples should not be built by default.

xen/arch/x86/test/xen_hello_world.c line 6

Quoted 9 lines
xen/arch/x86/test/xen_hello_world.c new file +6 -0
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
+ *
+ */
+
+#include <xen/config.h>

Another of these things needing taking care of throughout the entire series.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#107 lore raw

Re: [PATCH v5 12/28] x86/xen_hello_world.xsplice: Test payload for patching 'xen_extra_version'.

Quoted 9 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 24.03.16 at 21:00, <[email protected]> wrote:
xen/Makefile +1 -0
@@ -75,6 +75,7 @@ _install: $(TARGET)$(CONFIG_XEN_INSTALL_SUFFIX)
 			echo 'EFI installation only partially done (EFI_VENDOR not set)' >&2; \
 		fi; \
 	fi
+	$(MAKE) -f $(BASEDIR)/Rules.mk -C arch/$(TARGET_ARCH) install
 
Quoted 10 lines

xen/Makefile _uninstall: · line 96

Quoted 7 lines
xen/Makefile +1 -0
 .PHONY: _uninstall
 _uninstall: D=$(DESTDIR)
@@ -92,6 +93,7 @@ _uninstall:
 	rm -f $(D)$(EFI_DIR)/$(T)-$(XEN_VERSION).efi
 	rm -f $(D)$(EFI_DIR)/$(T).efi
 	rm -f $(D)$(EFI_MOUNTPOINT)/efi/$(EFI_VENDOR)/$(T)-$(XEN_FULLVERSION).efi
+	$(MAKE) -f $(BASEDIR)/Rules.mk -C arch/$(TARGET_ARCH) uninstall

Pretty certainly stray changes, or they'd need a really good explanation.

It is used to remove the test-cases. Perhaps it should be called 'uninstall-tests' ? I will skip this for right now - and figure out later how to make the OSSTest harvest these.

Quoted 9 lines
Quoted 9 lines
xen/arch/x86/Makefile +1 -0
@@ -75,7 +75,12 @@ efi-y := $(shell if [ ! -r $(BASEDIR)/include/xen/compile.h -o \
 $(TARGET): $(TARGET)-syms $(efi-y) boot/mkelf32
 	./boot/mkelf32 $(TARGET)-syms $(TARGET) 0x100000 \
 	`$(NM) -nr $(TARGET)-syms | head -n 1 | sed -e 's/^\([^ ]*\).*/0x\1/'`
+	$(MAKE) -f $(BASEDIR)/Rules.mk -C test
 
Quoted 6 lines

xen/arch/x86/Makefile efi-y := $(shell if [ ! -r $(BASEDIR)/include/xen/compile.h -o \ · line 83

Quoted 4 lines
xen/arch/x86/Makefile +4 -0
+install:
+	$(MAKE) -f $(BASEDIR)/Rules.mk -C test install
+uninstall:
+	$(MAKE) -f $(BASEDIR)/Rules.mk -C test uninstall

Tests or examples should not be built by default.

I can certainly make a seperate top destination called 'test' that will take care of this? Or should it be called 'xsplice' ? 'xsplice-test' ?

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#108 lore raw

Re: [PATCH v5 12/28] x86/xen_hello_world.xsplice: Test payload for patching 'xen_extra_version'.

Quoted 18 lines
Quoted 1 line
Quoted 1 line

Konrad Rzeszutek Wilk <[email protected]> 04/06/16 4:05 AM >>>

Quoted 9 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 24.03.16 at 21:00, <[email protected]> wrote:
xen/arch/x86/Makefile +1 -0
@@ -75,7 +75,12 @@ efi-y := $(shell if [ ! -r $(BASEDIR)/include/xen/compile.h -o \
 $(TARGET): $(TARGET)-syms $(efi-y) boot/mkelf32
 	./boot/mkelf32 $(TARGET)-syms $(TARGET) 0x100000 \
 	`$(NM) -nr $(TARGET)-syms | head -n 1 | sed -e 's/^\([^ ]*\).*/0x\1/'`
+	$(MAKE) -f $(BASEDIR)/Rules.mk -C test
 
Quoted 6 lines

xen/arch/x86/Makefile efi-y := $(shell if [ ! -r $(BASEDIR)/include/xen/compile.h -o \ · line 83

Quoted 4 lines
xen/arch/x86/Makefile +4 -0
+install:
+	$(MAKE) -f $(BASEDIR)/Rules.mk -C test install
+uninstall:
+	$(MAKE) -f $(BASEDIR)/Rules.mk -C test uninstall

Tests or examples should not be built by default.

Quoted 2 lines

I can certainly make a seperate top destination called 'test' that will take care of this? Or should it be called 'xsplice' ? 'xsplice-test' ?

The top level one would (imo naturally) be "tests", as there could be more than just the xSplice one(s).

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#109 lore raw

PATCH v5 13/28 xsplice, symbols: Implement symbol name resolution on address.

In reply to Konrad Rzeszutek Wilk

From: Ross Lagerwall <[email protected]>

If in the payload we do not have the old_addr we can resolve the virtual address based on the UNDEFined symbols.

We also use an boolean flag: new_symbol to track symbols. The usual case this is used is by:

* A payload may introduce a new symbol
* A payload may override an existing symbol (introduced in Xen or another payload)
* Overriding symbols must exist in the symtab for backtraces.
* A payload must always link against the object which defines the new symbol.

Considering that payloads may be loaded in any order it would be incorrect to link against a payload which simply overrides a symbol because you could end up with a chain of jumps which is inefficient and may result in the expected function not being executed.

Also we include a local definition block in the symbols.c file.

---
Cc: Keir Fraser <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>

v1: Ross original version.
v2: Include test-case and document update.
v2: s/size_t/ssize_t/
Include core_text_size, core_text calculation
v4: Cast on dprintk to uint64_t to make ELF 32bit build.

---
 xen/arch/x86/Makefile               |   6 +-
 xen/arch/x86/test/Makefile          |   4 +-
 xen/arch/x86/test/xen_hello_world.c |   5 +-
 xen/common/symbols.c                |  33 ++++++++
 xen/common/xsplice.c                | 160 ++++++++++++++++++++++++++++++++++++
 xen/common/xsplice_elf.c            |  21 ++++-
 xen/include/xen/symbols.h           |   2 +
 xen/include/xen/xsplice.h           |   8 ++
 8 files changed, 229 insertions(+), 10 deletions(-)
xen/arch/x86/Makefile +4 -2
index d9416d1..a1ef24b 100644
@@ -113,12 +113,14 @@ $(TARGET)-syms: prelink.o xen.lds $(BASEDIR)/common/symbols-dummy.o
 	$(LD) $(LDFLAGS) -T xen.lds -N prelink.o \
 	    $(BASEDIR)/common/symbols-dummy.o -o $(@D)/.$(@F).0
 	$(NM) -pa --format=sysv $(@D)/.$(@F).0 \
-		| $(BASEDIR)/tools/symbols --sysv --sort >$(@D)/.$(@F).0.S
+		| $(BASEDIR)/tools/symbols --all-symbols --sysv --sort \
+		>$(@D)/.$(@F).0.S
 	$(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).0.o
 	$(LD) $(LDFLAGS) -T xen.lds -N prelink.o \
 	    $(@D)/.$(@F).0.o -o $(@D)/.$(@F).1
 	$(NM) -pa --format=sysv $(@D)/.$(@F).1 \
-		| $(BASEDIR)/tools/symbols --sysv --sort --warn-dup >$(@D)/.$(@F).1.S
+		| $(BASEDIR)/tools/symbols --all-symbols --sysv --sort --warn-dup \
+		>$(@D)/.$(@F).1.S
 	$(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).1.o
 	$(LD) $(LDFLAGS) -T xen.lds -N prelink.o \
 	    $(@D)/.$(@F).1.o -o $@
xen/arch/x86/test/Makefile +1 -3
index 7a364c1..22fcb14 100644
@@ -35,14 +35,12 @@ clean::
 # the last entry in the build target.
 #
 .PHONY: config.h
-config.h: OLD_CODE=$(call CODE_ADDR,$(BASEDIR)/xen-syms,xen_extra_version)
 config.h: OLD_CODE_SZ=$(call CODE_SZ,$(BASEDIR)/xen-syms,xen_extra_version)
 config.h: NEW_CODE_SZ=$(call CODE_SZ,$<,xen_hello_world)
 config.h: xen_hello_world_func.o
 	(set -e; \
 	 echo "#define NEW_CODE_SZ $(NEW_CODE_SZ)"; \
-	 echo "#define OLD_CODE_SZ $(OLD_CODE_SZ)"; \
-	 echo "#define OLD_CODE $(OLD_CODE)") > $@
+	 echo "#define OLD_CODE_SZ $(OLD_CODE_SZ)") > $@
 
 .PHONY: xsplice
 xsplice: config.h
xen/arch/x86/test/xen_hello_world.c +4 -1
index f6ac098..243eb3f 100644
@@ -11,10 +11,13 @@
 static char xen_hello_world_name[] = "xen_hello_world";
 extern const char *xen_hello_world(void);
 
+/* External symbol. */
+extern const char *xen_extra_version(void);
+
 struct xsplice_patch_func __section(".xsplice.funcs") xsplice_xen_hello_world = {
     .name = xen_hello_world_name,
     .new_addr = (unsigned long)(xen_hello_world),
-    .old_addr = OLD_CODE,
+    .old_addr = (unsigned long)(xen_extra_version),
     .new_size = NEW_CODE_SZ,
     .old_size = OLD_CODE_SZ,
 };
xen/common/symbols.c +33 -0
index 92fb0ee..329eba2 100644
@@ -207,3 +207,36 @@ int xensyms_read(uint32_t *symnum, char *type,
 
     return 0;
 }
+
+uint64_t symbols_lookup_by_name(const char *symname)
+{
+    uint32_t symnum = 0;
+    uint64_t addr = 0, outaddr = 0;
+    int rc;
+    char type;
+    char name[KSYM_NAME_LEN + 1] = {0};
+
+    do {
+        rc = xensyms_read(&symnum, &type, &addr, name);
+        if ( rc )
+            break;
+
+        if ( !strcmp(name, symname) )
+        {
+            outaddr = addr;
+            break;
+        }
+    } while ( name[0] != '\0' );
+
+    return outaddr;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/common/xsplice.c +160 -0

205 lines not on this page · raw message

xen/common/xsplice_elf.c +17 -4
index e5c0b12..248e3f3 100644
@@ -4,6 +4,7 @@
 
 #include <xen/errno.h>
 #include <xen/lib.h>
+#include <xen/symbols.h>
 #include <xen/xsplice_elf.h>
 #include <xen/xsplice.h>
 
@@ -235,15 +236,27 @@ int xsplice_elf_resolve_symbols(struct xsplice_elf *elf)
                 break;
 
             case SHN_UNDEF:
-                printk(XENLOG_ERR "%s%s: Unknown symbol: %s\n",
-                       XSPLICE, elf->name, elf->sym[i].name);
-                return -ENOENT;
+                elf->sym[i].sym->st_value = symbols_lookup_by_name(elf->sym[i].name);
+                if ( !elf->sym[i].sym->st_value )
+                {
+                    elf->sym[i].sym->st_value =
+                        xsplice_symbols_lookup_by_name(elf->sym[i].name);
+                    if ( !elf->sym[i].sym->st_value )
+                    {
+                        printk(XENLOG_ERR "%s%s: Unknown symbol: %s\n",
+                               XSPLICE, elf->name, elf->sym[i].name);
+                        return -ENOENT;
+                    }
+                }
+                dprintk(XENLOG_DEBUG, "%s%s: Undefined symbol resolved: %s => 0x%"PRIx64"\n",
+                       XSPLICE, elf->name, elf->sym[i].name,
+                       (uint64_t)elf->sym[i].sym->st_value);
                 break;
 
             case SHN_ABS:
                 dprintk(XENLOG_DEBUG, "%s%s: Absolute symbol: %s => 0x%"PRIx64"\n",
                       XSPLICE, elf->name, elf->sym[i].name,
-                      elf->sym[i].sym->st_value);
+                      (uint64_t)elf->sym[i].sym->st_value);
                 break;
 
             default:
xen/include/xen/symbols.h +2 -0
index f58e611..d679aa9 100644
@@ -23,4 +23,6 @@ const char *symbols_lookup(unsigned long addr,
 int xensyms_read(uint32_t *symnum, char *type,
                  uint64_t *address, char *name);
 
+uint64_t symbols_lookup_by_name(const char *symname);
+
 #endif /*_XEN_SYMBOLS_H*/
xen/include/xen/xsplice.h +8 -0
index 00b3cb2..8bc55f3 100644
@@ -33,8 +33,16 @@ struct xsplice_patch_func {
 /* Convenience define for printk. */
 #define XSPLICE "xsplice: "
 
+struct xsplice_symbol {
+    const char *name;
+    uint64_t value;
+    ssize_t size;
+    bool_t new_symbol;
+};
+
 int xsplice_op(struct xen_sysctl_xsplice_op *);
 void check_for_xsplice_work(void);
+uint64_t xsplice_symbols_lookup_by_name(const char *symname);
 
 /* Arch hooks. */
 int arch_xsplice_verify_elf(const struct xsplice_elf *elf, void *data);
Signature · 7 lines
2.5.0


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#110 lore raw

Re: [PATCH v5 13/28] xsplice, symbols: Implement symbol name resolution on address.

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 24.03.16 at 21:00, <[email protected]> wrote:
xen/arch/x86/Makefile +0 -0
@@ -113,12 +113,14 @@ $(TARGET)-syms: prelink.o xen.lds $(BASEDIR)/common/symbols-dummy.o
 	$(LD) $(LDFLAGS) -T xen.lds -N prelink.o \
 	    $(BASEDIR)/common/symbols-dummy.o -o $(@D)/.$(@F).0
 	$(NM) -pa --format=sysv $(@D)/.$(@F).0 \

xen/arch/x86/Makefile $(TARGET)-syms: prelink.o xen.lds $(BASEDIR)/common/symbols-dummy.o · line 123

Quoted 10 lines
xen/arch/x86/Makefile +4 -2
-		| $(BASEDIR)/tools/symbols --sysv --sort >$(@D)/.$(@F).0.S
+		| $(BASEDIR)/tools/symbols --all-symbols --sysv --sort \
+		>$(@D)/.$(@F).0.S
 	$(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).0.o
 	$(LD) $(LDFLAGS) -T xen.lds -N prelink.o \
 	    $(@D)/.$(@F).0.o -o $(@D)/.$(@F).1
 	$(NM) -pa --format=sysv $(@D)/.$(@F).1 \
-		| $(BASEDIR)/tools/symbols --sysv --sort --warn-dup >$(@D)/.$(@F).1.S
+		| $(BASEDIR)/tools/symbols --all-symbols --sysv --sort --warn-dup \
+		>$(@D)/.$(@F).1.S

This addition should be dependent on CONFIG_XSPLICE, not the least because I expect it to bloat the symbol table quite a bit. And then - how come this is needed here, but not in the xen.efi rule?

xen/arch/x86/Makefile $(TARGET)-syms: prelink.o xen.lds $(BASEDIR)/common/symbols-dummy.o · line 124

Quoted 1 line
xen/arch/x86/Makefile +1 -0
+uint64_t symbols_lookup_by_name(const char *symname)

I don't think such a function can reasonably return other than void * or unsigned long.

xen/arch/x86/Makefile $(TARGET)-syms: prelink.o xen.lds $(BASEDIR)/common/symbols-dummy.o

Quoted 6 lines
xen/arch/x86/Makefile +6 -0
+{
+    uint32_t symnum = 0;
+    uint64_t addr = 0, outaddr = 0;
+    int rc;
+    char type;
+    char name[KSYM_NAME_LEN + 1] = {0};

This and likely addr's initializer seem pointless. (And it's questionable whether you really need both addr and outaddr.)

Quoted 4 lines
xen/arch/x86/Makefile +4 -0
+    do {
+        rc = xensyms_read(&symnum, &type, &addr, name);
+        if ( rc )
+            break;

xen/arch/x86/Makefile

Quoted 10 lines
xen/arch/x86/Makefile +10 -0
+
+        if ( !strcmp(name, symname) )
+        {
+            outaddr = addr;
+            break;
+        }
+    } while ( name[0] != '\0' );
+
+    return outaddr;
+}

Huh - a brute force linear lookup. We've got some 7,000 symbols right now, and I think we can't expect that to go down.

Quoted 14 lines
xen/arch/x86/Makefile +14 -0
+uint64_t xsplice_symbols_lookup_by_name(const char *symname)
+{
+    struct payload *data;
+    unsigned int i;
+    uint64_t value = 0;
+
+    spin_lock_recursive(&payload_lock);
+
+    list_for_each_entry ( data, &payload_list, list )
+    {
+        for ( i = 0; i < data->nsyms; i++ )
+        {
+            if ( !data->symtab[i].new_symbol )
+                continue;

xen/arch/x86/Makefile

Quoted 10 lines
xen/arch/x86/Makefile +10 -0
+
+            if ( !strcmp(data->symtab[i].name, symname) )
+            {
+                value = data->symtab[i].value;
+                goto out;
+            }
+        }
+    }
+
+out:

Label indentation.

xen/arch/x86/Makefile static int prepare_payload(struct payload *payload, · line 439

Quoted 12 lines
xen/arch/x86/Makefile +8 -0
@@ -397,8 +429,126 @@ static int prepare_payload(struct payload *payload,
         for ( j = 0; j < 24; j++ )
             if ( f->pad[j] )
                 return -EINVAL;
+
+        /* Lookup function's old address if not already resolved. */
+        if ( !f->old_addr )
+        {
+            f->old_addr = symbols_lookup_by_name(f->name);
+            if ( !f->old_addr )
+            {
+                f->old_addr = xsplice_symbols_lookup_by_name(f->name);

This returns with the lock not held - can you really rely on the symbol staying around?

xen/arch/x86/Makefile static int prepare_payload(struct payload *payload, · line 443

Quoted 4 lines
xen/arch/x86/Makefile +4 -0
+                if ( !f->old_addr )
+                {
+                    printk(XENLOG_ERR "%s%s: Could not resolve old address of %s\n",
+                           XSPLICE, elf->name, f->name);

Any log messages not rate limited by default need careful consideration. I don't think this is one which needs to be XENLOG_ERR, even if the condition is an error one.

xen/arch/x86/Makefile static int prepare_payload(struct payload *payload, · line 445

Quoted 2 lines
xen/arch/x86/Makefile +2 -0
+static bool_t is_core_symbol(const struct xsplice_elf *elf,
+                             const struct xsplice_elf_sym *sym)

What does "core" here mean?

xen/arch/x86/Makefile static int prepare_payload(struct payload *payload, · line 454

Quoted 9 lines
xen/arch/x86/Makefile +9 -0
+{
+    if ( sym->sym->st_shndx == SHN_UNDEF ||
+         sym->sym->st_shndx >= elf->hdr->e_shnum )
+        return 0;
+
+    return !!( (elf->sec[sym->sym->st_shndx].sec->sh_flags & SHF_ALLOC) &&
+               (ELF64_ST_TYPE(sym->sym->st_info) == STT_OBJECT ||
+                ELF64_ST_TYPE(sym->sym->st_info) == STT_FUNC) );
+}

How does the symbol type matter? Don't you rather mean to ignore static symbols? Or maybe even just section ones?

Also - stray blanks and !!.

Quoted 15 lines
xen/arch/x86/Makefile +15 -0
+static int build_symbol_table(struct payload *payload,
+                              const struct xsplice_elf *elf)
+{
+    unsigned int i, j, nsyms = 0;
+    size_t strtab_len = 0;
+    struct xsplice_symbol *symtab;
+    char *strtab;
+
+    ASSERT(payload->nfuncs);
+
+    /* Recall that section @0 is always NULL. */
+    for ( i = 1; i < elf->nsym; i++ )
+    {
+        if ( is_core_symbol(elf, elf->sym + i) )
+        {

xen/arch/x86/Makefile static int prepare_payload(struct payload *payload, · line 479

Quoted 10 lines
xen/arch/x86/Makefile +10 -0
+            nsyms++;
+            strtab_len += strlen(elf->sym[i].name) + 1;
+        }
+    }
+
+    symtab = xmalloc_array(struct xsplice_symbol, nsyms);
+    if ( !symtab )
+        return -ENOMEM;
+
+    strtab = xmalloc_bytes(strtab_len);

xmalloc_array(char, strtab_len);

xen/arch/x86/Makefile static int prepare_payload(struct payload *payload, · line 484

Quoted 5 lines
xen/arch/x86/Makefile +5 -0
+    if ( !strtab )
+    {
+        xfree(symtab);
+        return -ENOMEM;
+    }

To limit the number of return paths, could I talk you into doing both allocations and only then checking both return values?

Quoted 37 lines
xen/arch/x86/Makefile +37 -0
+    nsyms = 0;
+    strtab_len = 0;
+    for ( i = 1; i < elf->nsym; i++ )
+    {
+        if ( is_core_symbol(elf, elf->sym + i) )
+        {
+            symtab[nsyms].name = strtab + strtab_len;
+            symtab[nsyms].size = elf->sym[i].sym->st_size;
+            symtab[nsyms].value = elf->sym[i].sym->st_value;
+            symtab[nsyms].new_symbol = 0; /* To be checked below. */
+            strtab_len += strlcpy(strtab + strtab_len, elf->sym[i].name,
+                                  KSYM_NAME_LEN) + 1;
+            nsyms++;
+        }
+    }
+
+    for ( i = 0; i < nsyms; i++ )
+    {
+        bool_t found = 0;
+
+        for ( j = 0; j < payload->nfuncs; j++ )
+        {
+            if ( symtab[i].value == payload->funcs[j].new_addr )
+            {
+                found = 1;
+                break;
+            }
+        }
+
+        if ( !found )
+        {
+            if ( xsplice_symbols_lookup_by_name(symtab[i].name) )
+            {
+                printk(XENLOG_ERR "%s%s: duplicate new symbol: %s\n",
+                       XSPLICE, elf->name, symtab[i].name);
+                xfree(symtab);
+                xfree(strtab);

xen/arch/x86/Makefile static int prepare_payload(struct payload *payload, · line 531

Quoted 10 lines
xen/arch/x86/Makefile +10 -0
+                return -EEXIST;
+            }
+            symtab[i].new_symbol = 1;
+            dprintk(XENLOG_DEBUG, "%s%s: new symbol %s\n",
+                    XSPLICE, elf->name, symtab[i].name);
+        }
+        else
+        {
+            dprintk(XENLOG_DEBUG, "%s%s: overriding symbol %s\n",
+                    XSPLICE, elf->name, symtab[i].name);

Since you don't do anything here - how is this an override of some sort?

Quoted 19 lines
xen/arch/x86/Makefile +12 -3
@@ -235,15 +236,27 @@ int xsplice_elf_resolve_symbols(struct xsplice_elf  *elf)
                 break;
 
             case SHN_UNDEF:
-                printk(XENLOG_ERR "%s%s: Unknown symbol: %s\n",
-                       XSPLICE, elf->name, elf->sym[i].name);
-                return -ENOENT;
+                elf->sym[i].sym->st_value = symbols_lookup_by_name(elf->sym[i].name);
+                if ( !elf->sym[i].sym->st_value )
+                {
+                    elf->sym[i].sym->st_value =
+                        xsplice_symbols_lookup_by_name(elf->sym[i].name);
+                    if ( !elf->sym[i].sym->st_value )
+                    {
+                        printk(XENLOG_ERR "%s%s: Unknown symbol: %s\n",
+                               XSPLICE, elf->name, elf->sym[i].name);
+                        return -ENOENT;
+                    }
+                }

xen/arch/x86/Makefile int xsplice_elf_resolve_symbols(struct xsplice_elf *elf) · line 259

Quoted 10 lines
xen/arch/x86/Makefile +4 -1
+                dprintk(XENLOG_DEBUG, "%s%s: Undefined symbol resolved: %s => 0x%"PRIx64"\n",
+                       XSPLICE, elf->name, elf->sym[i].name,
+                       (uint64_t)elf->sym[i].sym->st_value);
                 break;
 
             case SHN_ABS:
                 dprintk(XENLOG_DEBUG, "%s%s: Absolute symbol: %s => 0x%"PRIx64"\n",
                       XSPLICE, elf->name, elf->sym[i].name,
-                      elf->sym[i].sym->st_value);
+                      (uint64_t)elf->sym[i].sym->st_value);

This change does not seem to belong here.

xen/include/xen/xsplice.h struct xsplice_patch_func { · line 39

Quoted 10 lines
xen/include/xen/xsplice.h +4 -0
@@ -33,8 +33,16 @@ struct xsplice_patch_func {
 /* Convenience define for printk. */
 #define XSPLICE "xsplice: "
 
+struct xsplice_symbol {
+    const char *name;
+    uint64_t value;
+    ssize_t size;

While mentioned in the revision log - why signed?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#111 lore raw

Re: [PATCH v5 13/28] xsplice, symbols: Implement symbol name resolution on address.

Quoted 13 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 24.03.16 at 21:00, <[email protected]> wrote:
xen/arch/x86/Makefile +2 -1
@@ -113,12 +113,14 @@ $(TARGET)-syms: prelink.o xen.lds $(BASEDIR)/common/symbols-dummy.o
 	$(LD) $(LDFLAGS) -T xen.lds -N prelink.o \
 	    $(BASEDIR)/common/symbols-dummy.o -o $(@D)/.$(@F).0
 	$(NM) -pa --format=sysv $(@D)/.$(@F).0 \
-		| $(BASEDIR)/tools/symbols --sysv --sort >$(@D)/.$(@F).0.S
+		| $(BASEDIR)/tools/symbols --all-symbols --sysv --sort \
+		>$(@D)/.$(@F).0.S
 	$(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).0.o
 	$(LD) $(LDFLAGS) -T xen.lds -N prelink.o \
 	    $(@D)/.$(@F).0.o -o $(@D)/.$(@F).1
Quoted 8 lines

xen/arch/x86/Makefile $(TARGET)-syms: prelink.o xen.lds $(BASEDIR)/common/symbols-dummy.o · line 123

Quoted 4 lines
xen/arch/x86/Makefile +2 -1
 	$(NM) -pa --format=sysv $(@D)/.$(@F).1 \
-		| $(BASEDIR)/tools/symbols --sysv --sort --warn-dup >$(@D)/.$(@F).1.S
+		| $(BASEDIR)/tools/symbols --all-symbols --sysv --sort --warn-dup \
+		>$(@D)/.$(@F).1.S

This addition should be dependent on CONFIG_XSPLICE, not the least because I expect it to bloat the symbol table quite a bit. And then - how come this is needed here, but not in the xen.efi rule?

I added it to xen.efi rule and got:

home/konrad/xen/xen/.xen.efi.0s.S: Assembler messages:
/home/konrad/xen/xen/.xen.efi.0s.S:21: Warning: value 0x7d2f80000543 truncated to 0x80000543 /home/konrad/xen/xen/.xen.efi.0s.S:22: Warning: value 0x7d2f800008b2 truncated to 0x800008b2 /home/konrad/xen/xen/.xen.efi.0s.S:23: Warning: value 0x7d2f800008b4 truncated to 0x800008b4 /home/konrad/xen/xen/.xen.efi.0s.S:24: Warning: value 0x7d2f800008b9 truncated to 0x800008b9 /home/konrad/xen/xen/.xen.efi.0s.S:25: Warning: value 0x7d2f8000103f truncated to 0x8000103f /home/konrad/xen/xen/.xen.efi.0s.S:26: Warning: value 0x7d2f80001043 truncated to 0x80001043 /home/konrad/xen/xen/.xen.efi.0s.S:27: Warning: value 0x7d2f80001047 truncated to 0x80001047 /home/konrad/xen/xen/.xen.efi.0s.S:6746: Warning: value 0x100650000 truncated to 0x650000

and so on.. Not sure why. The xen.efi file boots thought?

Quoted 17 lines
Quoted 4 lines
xen/arch/x86/Makefile +3 -0
+        rc = xensyms_read(&symnum, &type, &addr, name);
 
+        if ( rc )
+            break;

xen/arch/x86/Makefile $(TARGET)-syms: prelink.o xen.lds $(BASEDIR)/common/symbols-dummy.o

Quoted 10 lines
xen/arch/x86/Makefile +10 -0
+
+        if ( !strcmp(name, symname) )
+        {
+            outaddr = addr;
+            break;
+        }
+    } while ( name[0] != '\0' );
+
+    return outaddr;
+}

Huh - a brute force linear lookup. We've got some 7,000 symbols right now, and I think we can't expect that to go down.

I left it as such. I will need to redo this as the xensyms_read is not the best for this and this will need to be redone to be much faster.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#112 lore raw

Re: [PATCH v5 13/28] xsplice, symbols: Implement symbol name resolution on address.

Quoted 44 lines
Quoted 1 line
Quoted 1 line · On 07.04.16 at 05:14, <[email protected]> wrote:
Quoted 13 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 24.03.16 at 21:00, <[email protected]> wrote:
xen/arch/x86/Makefile +2 -1
@@ -113,12 +113,14 @@ $(TARGET)-syms: prelink.o xen.lds $(BASEDIR)/common/symbols-dummy.o
 	$(LD) $(LDFLAGS) -T xen.lds -N prelink.o \
 	    $(BASEDIR)/common/symbols-dummy.o -o $(@D)/.$(@F).0
 	$(NM) -pa --format=sysv $(@D)/.$(@F).0 \
-		| $(BASEDIR)/tools/symbols --sysv --sort >$(@D)/.$(@F).0.S
+		| $(BASEDIR)/tools/symbols --all-symbols --sysv --sort \
+		>$(@D)/.$(@F).0.S
 	$(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).0.o
 	$(LD) $(LDFLAGS) -T xen.lds -N prelink.o \
 	    $(@D)/.$(@F).0.o -o $(@D)/.$(@F).1
Quoted 8 lines

xen/arch/x86/Makefile $(TARGET)-syms: prelink.o xen.lds $(BASEDIR)/common/symbols-dummy.o · line 123

Quoted 4 lines
xen/arch/x86/Makefile +2 -1
 	$(NM) -pa --format=sysv $(@D)/.$(@F).1 \
-		| $(BASEDIR)/tools/symbols --sysv --sort --warn-dup >$(@D)/.$(@F).1.S
+		| $(BASEDIR)/tools/symbols --all-symbols --sysv --sort --warn-dup \
+		>$(@D)/.$(@F).1.S

This addition should be dependent on CONFIG_XSPLICE, not the least because I expect it to bloat the symbol table quite a bit. And then - how come this is needed here, but not in the xen.efi rule?

I added it to xen.efi rule and got:

home/konrad/xen/xen/.xen.efi.0s.S: Assembler messages:
/home/konrad/xen/xen/.xen.efi.0s.S:21: Warning: value 0x7d2f80000543 truncated to 0x80000543 /home/konrad/xen/xen/.xen.efi.0s.S:22: Warning: value 0x7d2f800008b2 truncated to 0x800008b2 /home/konrad/xen/xen/.xen.efi.0s.S:23: Warning: value 0x7d2f800008b4 truncated to 0x800008b4 /home/konrad/xen/xen/.xen.efi.0s.S:24: Warning: value 0x7d2f800008b9 truncated to 0x800008b9 /home/konrad/xen/xen/.xen.efi.0s.S:25: Warning: value 0x7d2f8000103f truncated to 0x8000103f /home/konrad/xen/xen/.xen.efi.0s.S:26: Warning: value 0x7d2f80001043 truncated to 0x80001043 /home/konrad/xen/xen/.xen.efi.0s.S:27: Warning: value 0x7d2f80001047 truncated to 0x80001047 /home/konrad/xen/xen/.xen.efi.0s.S:6746: Warning: value 0x100650000 truncated to 0x650000

Quoted 1 line

and so on.. Not sure why. The xen.efi file boots thought?

It's the kallsyms symbol table that suffers, so the image booting fine is not really surprising. But we'd need to understand what specific data objects these warnings originate from - perhaps linker generated symbols not sitting inside sections?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#113 lore raw

Re: [PATCH v5 13/28] xsplice, symbols: Implement symbol name resolution on address.

Quoted 44 lines · Jan Beulich
Quoted 44 lines
Quoted 1 line
Quoted 1 line · On 07.04.16 at 05:14, <[email protected]> wrote:
Quoted 13 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 24.03.16 at 21:00, <[email protected]> wrote:
xen/arch/x86/Makefile +2 -1
@@ -113,12 +113,14 @@ $(TARGET)-syms: prelink.o xen.lds $(BASEDIR)/common/symbols-dummy.o
 	$(LD) $(LDFLAGS) -T xen.lds -N prelink.o \
 	    $(BASEDIR)/common/symbols-dummy.o -o $(@D)/.$(@F).0
 	$(NM) -pa --format=sysv $(@D)/.$(@F).0 \
-		| $(BASEDIR)/tools/symbols --sysv --sort >$(@D)/.$(@F).0.S
+		| $(BASEDIR)/tools/symbols --all-symbols --sysv --sort \
+		>$(@D)/.$(@F).0.S
 	$(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).0.o
 	$(LD) $(LDFLAGS) -T xen.lds -N prelink.o \
 	    $(@D)/.$(@F).0.o -o $(@D)/.$(@F).1
Quoted 8 lines

xen/arch/x86/Makefile $(TARGET)-syms: prelink.o xen.lds $(BASEDIR)/common/symbols-dummy.o · line 123

Quoted 4 lines
xen/arch/x86/Makefile +2 -1
 	$(NM) -pa --format=sysv $(@D)/.$(@F).1 \
-		| $(BASEDIR)/tools/symbols --sysv --sort --warn-dup >$(@D)/.$(@F).1.S
+		| $(BASEDIR)/tools/symbols --all-symbols --sysv --sort --warn-dup \
+		>$(@D)/.$(@F).1.S

This addition should be dependent on CONFIG_XSPLICE, not the least because I expect it to bloat the symbol table quite a bit. And then - how come this is needed here, but not in the xen.efi rule?

I added it to xen.efi rule and got:

home/konrad/xen/xen/.xen.efi.0s.S: Assembler messages:
/home/konrad/xen/xen/.xen.efi.0s.S:21: Warning: value 0x7d2f80000543 truncated to 0x80000543 /home/konrad/xen/xen/.xen.efi.0s.S:22: Warning: value 0x7d2f800008b2 truncated to 0x800008b2 /home/konrad/xen/xen/.xen.efi.0s.S:23: Warning: value 0x7d2f800008b4 truncated to 0x800008b4 /home/konrad/xen/xen/.xen.efi.0s.S:24: Warning: value 0x7d2f800008b9 truncated to 0x800008b9 /home/konrad/xen/xen/.xen.efi.0s.S:25: Warning: value 0x7d2f8000103f truncated to 0x8000103f /home/konrad/xen/xen/.xen.efi.0s.S:26: Warning: value 0x7d2f80001043 truncated to 0x80001043 /home/konrad/xen/xen/.xen.efi.0s.S:27: Warning: value 0x7d2f80001047 truncated to 0x80001047 /home/konrad/xen/xen/.xen.efi.0s.S:6746: Warning: value 0x100650000 truncated to 0x650000

Quoted 6 lines
Quoted 1 line

and so on.. Not sure why. The xen.efi file boots thought?

It's the kallsyms symbol table that suffers, so the image booting fine is not really surprising. But we'd need to understand what specific data objects these warnings originate from - perhaps linker generated symbols not sitting inside sections?

From the .xen.efi.0s.S:
.globl symbols_offsets
ALGN
symbols_offsets:

#endif
	PTR	0x544 - SYMBOLS_ORIGIN
	PTR	0xa01 - SYMBOLS_ORIGIN
	PTR	0xa03 - SYMBOLS_ORIGIN
	PTR	0xa08 - SYMBOLS_ORIGIN
	PTR	0x118e - SYMBOLS_ORIGIN
	PTR	0x1192 - SYMBOLS_ORIGIN
	PTR	0x1196 - SYMBOLS_ORIGIN
	PTR	0xffff82d080100000 - SYMBOLS_ORIGIN
	PTR	0xffff82d080100000 - SYMBOLS_ORIGIN

which corresponds to:

multiboot1_header_start|0000000000000544|   ?  |                  | |     |
multiboot1_header_start|0000000000000a01|   ?  |                  | |     |
multiboot1_header_start|0000000000000a03|   ?  |                  | |     |
multiboot1_header_start|0000000000000a08|   ?  |                  | |     |
multiboot1_header_start|000000000000118e|   ?  |                  | |     |
multiboot1_header_start|0000000000001192|   ?  |                  | |     |
multiboot1_header_start|0000000000001196|   ?  |                  | |     |

which is also found:
multiboot1_header_start|ffff82d080100008| t | | | |

Quoted 3 lines

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel