xSplice design.
RFC PATCH 1/1 xSplice design.
Hey!
Since v3 [http://lists.xen.org/archives/html/xen-devel/2015-07/msg00990.html]
- Nailed down the comments, ingested them in.
- Wrote and tested some code.
RFC v2 [http://lists.xen.org/archives/html/xen-devel/2015-05/msg02142.html]
- Ingested every review comment in.
The patches for the code are a shell - there is no patching done at all and it is very much just to test out the design and hypercalls. The hard parts are yet to come :-)
At the Seattle LinuxCon/Xen Summit I will be presenting about xSplice and referring to this URL. There is also an slot for brainstorming to talk in details about things we disagree - and there is ample time to talk during dinner. Martin who has been heavily reviewing the design will be there and I hope other folks will be there as well to shape the design and how we want this to work.
The big outstanding issues are how we want to handle preemption. That is the problem of making an hypercall and waiting for the hypervisor to do its job (and the VCPU is blocked). In the past some XSAs have come out to resolve this and I would very much like this to have it addressed at start.
I think the other issues that have been raised should also be discussed naturally, but the above is crucial (at least for me). I've attached the patches on how I thought the preemption part could be solved by having an 'worker' in hypervisor acting on the commands - and we just poll on the status to see what the hypervisor has done so far.
Lastly, I also plan to add an Wiki to outline the dependency implementation parts that so far bubbled up - I figured Wiki would be better as some folks could put their name behind it.
Now please excuse the roughness of the patch and this giant one huge having everything in it. It ought to be split in three at least: hypervisor, toolstacks (libxc and libxl) - that is to be done later.
docs/misc/xsplice.h | 80 +++ docs/misc/xsplice.markdown | 1230 +++++++++++++++++++++++++++++++++++++++++ docs/misc/xsplice_test.c | 78 +++ tools/libxc/include/xenctrl.h | 16 + tools/libxc/xc_misc.c | 183 ++++++ tools/libxc/xc_private.c | 3 + tools/misc/Makefile | 4 + tools/misc/xen-xsplice.c | 385 +++++++++++++ xen/common/Makefile | 1 + xen/common/kernel.c | 11 + xen/common/keyhandler.c | 8 +- xen/common/sysctl.c | 5 + xen/common/version.c | 5 + xen/common/xsplice.c | 405 ++++++++++++++ xen/include/public/sysctl.h | 66 +++ xen/include/public/version.h | 4 + xen/include/xen/compile.h.in | 1 + xen/include/xen/version.h | 1 + xen/include/xen/xsplice.h | 9 + 19 files changed, 2494 insertions(+), 1 deletion(-)
Konrad Rzeszutek Wilk (2):
xsplice: rfc.v3.1
xsplice: Add hook for build_id
RFC PATCH 1/2 xsplice: rfc.v3.1
*TODO*:
- XSM add
- Contributs/authors on xsplice.markdown
- Figure out the preemption method (rfc.v4 target). Talk in Seattle?
- Further work - write out an Wiki detailing what implementation pieces to be done for individual contributions. Do it before Seattle?
--- docs/misc/xsplice.h | 80 +++ docs/misc/xsplice.markdown | 1230 +++++++++++++++++++++++++++++++++++++++++ docs/misc/xsplice_test.c | 78 +++ tools/libxc/include/xenctrl.h | 16 + tools/libxc/xc_misc.c | 183 ++++++ tools/misc/Makefile | 4 + tools/misc/xen-xsplice.c | 360 ++++++++++++ xen/common/Makefile | 1 + xen/common/keyhandler.c | 8 +- xen/common/sysctl.c | 5 + xen/common/xsplice.c | 405 ++++++++++++++ xen/include/public/sysctl.h | 66 +++ xen/include/xen/xsplice.h | 9 + 13 files changed, 2444 insertions(+), 1 deletion(-) create mode 100644 docs/misc/xsplice.h create mode 100644 docs/misc/xsplice.markdown create mode 100644 docs/misc/xsplice_test.c create mode 100644 tools/misc/xen-xsplice.c create mode 100644 xen/common/xsplice.c create mode 100644 xen/include/xen/xsplice.h
docs/misc/xsplice.h new file +80 -0
@@ -0,0 +1,80 @@ + +#include <stdint.h> +#include <sys/types.h> + +#define XSPLICE_HOWTO_INLINE 0x1/* It is an inline replacement. */ +#define XSPLICE_HOWTO_RELOC_PATCH 0x2/* Add an trampoline. */ + +#define XSPLICE_HOWTO_FLAG_PC_REL 0x1/* Is PC relative. */ +#define XSPLICE_HOWOT_FLAG_SIGN 0x2/* Should the new value be treated as signed value. */ + +struct xsplice_reloc_howto { +uint32_t howto;/* XSPLICE_HOWTO_* */ +uint32_t flag;/* XSPLICE_HOWTO_FLAG_* */ +uint32_t size;/* Size, in bytes, of the item to be relocated. */ +uint32_t r_shift;/* The value the final relocation is shifted right by; used to drop unwanted data from the relocation. */ +uint64_t mask;/* Bitmask for which parts of the instruction or data are replaced with the relocated value. */ +uint8_t pad[8 ];/* Must be zero. */ +}; + +struct xsplice_symbol { +const char *name;/* The ELF name of the symbol. */ +const char *label;/* A unique xSplice name for the symbol. */ +uint8_t pad[16 ];/* Must be zero. */ +}; +#define XSPLICE_PATCH_INLINE_TEXT 0x1 +#define XSPLICE_PATCH_INLINE_DATA 0x2 +#define XSPLICE_PATCH_RELOC_TEXT 0x3 + +struct xsplice_patch { +uint32_t type;/* XSPLICE_PATCH_* .*/ +uint32_t size;/* Size of patch. */ +uint64_t addr;/* The address of the inline new code (or data). */ +void *content;/* The bytes to be installed. */ +uint8_t pad[40 ];/* Must be zero. */ +}; + +#define XSPLICE_SECTION_TEXT 0x00000001/* Section is in .text */ +#define XSPLICE_SECTION_RODATA 0x00000002/* Section is in .rodata */ +#define XSPLICE_SECTION_DATA 0x00000004/* Section is in .data */ +#define XSPLICE_SECTION_STRING 0x00000008/* Section is in .str */ + +#define XSPLICE_SECTION_TEXT_INLINE 0x00000200/* Change is to be inline. */ +#define XSPLICE_SECTION_MATCH_EXACT 0x00000400/* Must match exactly. */ +#define XSPLICE_SECTION_NO_STACKCHECK 0x00000800/* Do not check the stack. */ + +struct xsplice_section { +struct xsplice_symbol *symbol;/* The symbol associated with this change. */ +uint64_t address;/* The address of the section (if known). */ +uint32_t size;/* The size of the section. */ +uint32_t flags;/* Various XSPLICE_SECTION_* flags. */ +uint8_t pad[12 ];/* To be zero. */ +}; + +struct xsplice_reloc { +uint64_t addr;/* The address of the relocation (if known). */ +struct xsplice_symbol *symbol;/* Symbol for this relocation. */ +int64_t isns_target;/* rest of the ELF addend. This is equal to the offset against the symbol that the relocation refers to. */ +struct xsplice_reloc_howto *howto;/* Pointer to the above structure. */ +int64_t isns_added;/* ELF addend resulting from quirks of instruction one of whose operands is the relocation. For example, this is -4 on x86 pc-relative jumps. */ +uint8_t pad[24 ];/* Must be zero. */ +}; + +struct xsplice_code { +struct xsplice_reloc *relocs;/* How to patch it. */ +uint32_t n_relocs; +struct xsplice_section *sections;/* Safety data. */ +uint32_t n_sections; +struct xsplice_patch *patches;/* Patch code and data */ +uint32_t n_patches; +uint8_t pad[28 ];/* Must be zero. */ +}; +struct xsplice { +uint32_t version; +const char *name;/* A sensible name for the patch. Up to 40 characters. */ +const char *id;/* ID of the hypervisor this binary was built against. */ +uint32_t id_size; +struct xsplice_code *new;/* Pointer to the new code to be patched. */ +struct xsplice_code *old;/* Pointer to the old code to be checked against. */ +uint8_t pad[24 ];/* Must be zero. */ +};
docs/misc/xsplice.markdown new file +1230 -0
1,230 lines not on this page · raw message
docs/misc/xsplice_test.c new file +78 -0
78 lines not on this page · raw message
tools/libxc/include/xenctrl.h +16 -0
@@ -2828,6 +2828,22 @@ int xc_psr_cat_get_l3_info(xc_interface *xch, uint32_t socket, uint32_t *cos_max, uint32_t *cbm_len);#endif +int xc_xsplice_upload (xc_interface *xch, +char *id,char *payload,uint32_t size); + +int xc_xsplice_get (xc_interface *xch, +char *id, +xen_sysctl_xsplice_summary_t *summary); + +int xc_xsplice_list (xc_interface *xch,unsigned int max,unsigned int start, +xen_sysctl_xsplice_summary_t *info,unsigned int *done, +unsigned int *left); + +int xc_xsplice_apply (xc_interface *xch,char *id); +int xc_xsplice_revert (xc_interface *xch,char *id); +int xc_xsplice_unload (xc_interface *xch,char *id); +int xc_xsplice_check (xc_interface *xch,char *id); +#endif /* XENCTRL_H */ /*
tools/libxc/xc_misc.c +183 -0
189 lines not on this page · raw message
tools/misc/Makefile +4 -0
@@ -30,6 +30,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/
@@ -98,6 +99,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_libxenctrl) $(LDLIBS_libxenstore) $(APPEND_LDFLAGS)
tools/misc/xen-xsplice.c new file +360 -0
360 lines not on this page · raw message
xen/common/Makefile +1 -0
@@ -55,6 +55,7 @@ obj-y += vmap.o obj-y += vsprintf.o obj-y += wait.o obj-y += xmalloc_tlsf.o +obj-y += xsplice.o obj-bin-$(CONFIG_X86) += $(foreach n,decompress bunzip2 unxz unlzma unlzo unlz4 earlycpio,$(n).init.o)
xen/common/keyhandler.c +7 -1
@@ -18,6 +18,7 @@#include <xen/mm.h> #include <xen/watchdog.h> #include <xen/init.h> +#include <xen/xsplice.h> #include <asm/debugger.h> #include <asm/div64.h>
@@ -455,6 +456,11 @@ static struct keyhandler spinlock_reset_keyhandler = { .desc = "reset lock profile info" };#endif +static struct keyhandler xsplice_printall_keyhandler = { + .diagnostic =1 , + .u.fn = xsplice_printall, + .desc ="print splicing information" +};static void run_all_nonirq_keyhandlers (unsigned long unused) {
@@ -567,7 +573,7 @@ void __init initialize_keytable(void)register_keyhandler ('l' , &spinlock_printall_keyhandler);register_keyhandler ('L' , &spinlock_reset_keyhandler);#endif - +register_keyhandler ('x' , &xsplice_printall_keyhandler); }/*
xen/common/sysctl.c +5 -0
@@ -27,6 +27,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) {
@@ -399,6 +400,10 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) ret =sysctl_coverage_op (&op->u.coverage_op);break ;#endif +case XEN_SYSCTL_xsplice_op: + ret =xsplice_control (&op->u.xsplice); + copyback =1 ; +break ;#ifdef HAS_PCI case XEN_SYSCTL_pcitopoinfo:
xen/common/xsplice.c new file +405 -0
405 lines not on this page · raw message
xen/include/public/sysctl.h +66 -0
84 lines not on this page · raw message
xen/include/xen/xsplice.h new file +9 -0
@@ -0,0 +1,9 @@ +#ifndef __XEN_XSPLICE_H__ +#define __XEN_XSPLICE_H__ + +struct xen_sysctl_xsplice_op ; +int xsplice_control (struct xen_sysctl_xsplice_op *); + +extern void xsplice_printall (unsigned char key); + +#endif /* __XEN_XSPLICE_H__ */
Signature · 1 line
1.8.4.2
Re: [RFC PATCH v3.1 1/2] xsplice: rfc.v3.1
Thanks for the work on this. I had some comments and questions on the latest draft.
Review
Quoted 2 lines · Konrad Rzeszutek Wilk
(quoted diff) +2
-0+#define XSPLICE_HOWTO_FLAG_PC_REL 0x1 /* Is PC relative. */ +#define XSPLICE_HOWOT_FLAG_SIGN 0x2 /* Should the new value be treated as signed value. */
s/HOWOT/HOWTO/
docs/misc/xsplice.markdown line 550
Quoted 8 lines
docs/misc/xsplice.markdown new file +8
-0+struct xsplice_reloc_howto { + uint32_t howto; /* XSPLICE_HOWTO_* */ + uint32_t flag; /* XSPLICE_HOWTO_FLAG_* */ + uint32_t size; /* Size, in bytes, of the item to be relocated. */ + uint32_t r_shift; /* The value the final relocation is shifted right by; used to drop unwanted data from the relocation. */ + uint64_t mask; /* Bitmask for which parts of the instruction or data are replaced with the relocated value. */ + uint8_t pad[8]; /* Must be zero. */ +};
I'm curious how r_shift and mask are used. I'm familiar with x86 and x86_64 and I'm not sure how these fit in. Is this to support other architectures?
docs/misc/xsplice.markdown line 1047
Quoted 9 lines
docs/misc/xsplice.markdown new file +9
-0+### 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.
I'm not sure I understand the concern. At least on x86_64, there is a ton of unused virtual address space where the hypervisor image is mapped. Why not simply map memory at the end of virtual address space?
There shouldn't be a concern with 2GB jumps then.
Quoted 10 lines
docs/misc/xsplice.markdown new file +10
-0+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 " | \
docs/misc/xsplice.markdown line 1068
Quoted 10 lines
docs/misc/xsplice.markdown new file +10
-0+ 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.
Is this really necessary? The way Xen is currently compiled results in functions being aligned at 16-byte boundaries. The extra space is padded with NOPs. Even if a function is only 3 bytes, it still has at least 16 bytes of space to use.
This can be controlled with the -falign-functions option to gcc.
Also, there are ways to get a 5-byte NOP added before the function. This is what the Linux kernel does for ftrace which is what the recent Linux kernel live patching support is built on.
It seems like it would be easier to be explicit during the build process than do runtime checks to ensure there is enough space.
docs/misc/xsplice.markdown line 1075
Quoted 6 lines
docs/misc/xsplice.markdown new file +6
-0+### 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.
It would be nice to have the consistency model be more explicit.
Maybe using the terminology from this LKML post?
docs/misc/xsplice.markdown line 1100
Quoted 3 lines
docs/misc/xsplice.markdown new file +3
-0+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 have all the CPUs be lockstep.
s/randezvous/rendezvous/
docs/misc/xsplice.markdown line 1110
Quoted 5 lines
docs/misc/xsplice.markdown new file +5
-0+### 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.
Is this for correctness reasons?
I understand this would be a good idea to reduce the size of patches, but I wanted to make sure I'm not missing something.
docs/misc/xsplice.markdown line 1197
Quoted 8 lines
docs/misc/xsplice.markdown new file +8
-0+### Symbol names + + +Xen as it is now, has a couple of non-unique symbol names which will +make runtime symbol identification hard. Sometimes, static symbols +simply have the same name in C files, sometimes such symbols get +included via header files, and some C files are also compiled +multiple times and linked under different names (guest_walk.c).
I'm not sure I understand the problem with static symbols. They aren't visible outside of the .c file, so when performing the linking against the target xen image, there shouldn't be any conflicts.
JE
Re: [RFC PATCH v3.1 1/2] xsplice: rfc.v3.1
Quoted 2 lines · Johannes Erdfelt
Thanks for the work on this. I had some comments and questions on the latest draft.
Hey Johannes!
Thank you for your review!
Quoted 7 lines · Konrad Rzeszutek Wilk
Review
Quoted 2 lines
(quoted diff) +2
-0+#define XSPLICE_HOWTO_FLAG_PC_REL 0x1 /* Is PC relative. */ +#define XSPLICE_HOWOT_FLAG_SIGN 0x2 /* Should the new value be treated as signed value. */s/HOWOT/HOWTO/
Quoted 12 lines
docs/misc/xsplice.markdown line 550
Quoted 8 lines
docs/misc/xsplice.markdown new file +8
-0+struct xsplice_reloc_howto { + uint32_t howto; /* XSPLICE_HOWTO_* */ + uint32_t flag; /* XSPLICE_HOWTO_FLAG_* */ + uint32_t size; /* Size, in bytes, of the item to be relocated. */ + uint32_t r_shift; /* The value the final relocation is shifted right by; used to drop unwanted data from the relocation. */ + uint64_t mask; /* Bitmask for which parts of the instruction or data are replaced with the relocated value. */ + uint8_t pad[8]; /* Must be zero. */ +};I'm curious how
r_shiftand mask are used. I'm familiar with x86 andx86_64and I'm not sure how these fit in. Is this to support other architectures?
It is to patch up data. We can specify the exact mask for an unsigned int - so we only patch specific bits. Ditto if we want to remove certain values.
Quoted 15 lines
docs/misc/xsplice.markdown line 1047
Quoted 10 lines
docs/misc/xsplice.markdown new file +9
-0+### 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.I'm not sure I understand the concern. At least on
x86_64, there is a ton of unused virtual address space where the hypervisor image is mapped. Why not simply map memory at the end of virtual address space?
Quoted 1 line
There shouldn't be a concern with 2GB jumps then.
Correct. This is added on if the hypervisor ends up gobbling up tons of memory and having those virtual addresses eaten up.
Quoted 27 lines
Quoted 11 lines
docs/misc/xsplice.markdown new file +10
-0+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 " | \docs/misc/xsplice.markdown line 1068
Quoted 10 lines
docs/misc/xsplice.markdown new file +10
-0+ 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.Is this really necessary? The way Xen is currently compiled results in functions being aligned at 16-byte boundaries. The extra space is padded with NOPs. Even if a function is only 3 bytes, it still has at least 16 bytes of space to use.
Quoted 1 line
This can be controlled with the -falign-functions option to gcc.
Right. The 'compile-time' check can be just to make sure that the compiler is controlled by that - otherwise we will halt the compilation.
Quoted 7 lines
Also, there are ways to get a 5-byte NOP added before the function. This is what the Linux kernel does for ftrace which is what the recent Linux kernel live patching support is built on.
It seems like it would be easier to be explicit during the build process than do runtime checks to ensure there is enough space.
Correct.
Quoted 10 lines
docs/misc/xsplice.markdown line 1075
Quoted 7 lines
docs/misc/xsplice.markdown new file +6
-0+### 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.It would be nice to have the consistency model be more explicit.
Quoted 3 lines
Maybe using the terminology from this LKML post?
Certainy we can borrow.
Quoted 7 lines
docs/misc/xsplice.markdown line 1100
Quoted 4 lines
docs/misc/xsplice.markdown new file +3
-0+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 have all the CPUs be lockstep.s/randezvous/rendezvous/
Quoted 7 lines
docs/misc/xsplice.markdown line 1110
Quoted 5 lines
docs/misc/xsplice.markdown new file +5
-0+### 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.Is this for correctness reasons?
Sanity mostly. Without that having the objdump and tools to figure out what piece of code is for what would be complicated.
Quoted 5 lines
I understand this would be a good idea to reduce the size of patches, but I wanted to make sure I'm not missing something.
Quoted 12 lines
docs/misc/xsplice.markdown line 1197
Quoted 8 lines
docs/misc/xsplice.markdown new file +8
-0+### Symbol names + + +Xen as it is now, has a couple of non-unique symbol names which will +make runtime symbol identification hard. Sometimes, static symbols +simply have the same name in C files, sometimes such symbols get +included via header files, and some C files are also compiled +multiple times and linked under different names (guest_walk.c).I'm not sure I understand the problem with static symbols. They aren't visible outside of the .c file, so when performing the linking against the target xen image, there shouldn't be any conflicts.
To do run-time checking based on symbols. We may get information that we need to patch 'xen_someting_static+<0x1f>' and we have not been supplied the virtual address. As such if xen_something_static may not show up at all - and we can't patch it. We need some mechanism to tweak the build so that those symbols do bubble up.
Quoted 8 lines
JE
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [RFC PATCH v3.1 1/2] xsplice: rfc.v3.1
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 31.07.15 at 17:46, <[email protected]> wrote:
Quoted 13 lines · Johannes Erdfelt
docs/misc/xsplice.markdown line 550
Quoted 8 lines · Konrad Rzeszutek Wilk
docs/misc/xsplice.markdown new file +8
-0+struct xsplice_reloc_howto { + uint32_t howto; /* XSPLICE_HOWTO_* */ + uint32_t flag; /* XSPLICE_HOWTO_FLAG_* */ + uint32_t size; /* Size, in bytes, of the item to be relocated. */ + uint32_t r_shift; /* The value the final relocation is shifted right by; used to drop unwanted data from the relocation. */ + uint64_t mask; /* Bitmask for which parts of the instruction or data are replaced with the relocated value. */ + uint8_t pad[8]; /* Must be zero. */ +};I'm curious how
r_shiftand mask are used. I'm familiar with x86 andx86_64and I'm not sure how these fit in. Is this to support other architectures?
Quoted 3 lines
It is to patch up data. We can specify the exact mask for an unsigned int - so we only patch specific bits. Ditto if we want to remove certain values.
Still I don't see a practical use: What relocated item would (on x86) be stored starting at other than bit 0 of a byte/word? Also, wouldn't a shift count be redundant with the mask value anyway?
Jan
RFC PATCH 2/2 xsplice: Add hook for build_id
In reply to Konrad Rzeszutek Wilk--- tools/libxc/xc_private.c | 3 +++ tools/misc/xen-xsplice.c | 25 +++++++++++++++++++++++++ xen/common/kernel.c | 11 +++++++++++ xen/common/version.c | 5 +++++ xen/include/public/version.h | 4 ++++ xen/include/xen/compile.h.in | 1 + xen/include/xen/version.h | 1 + 7 files changed, 50 insertions(+)
tools/libxc/xc_private.c +3 -0
@@ -713,6 +713,9 @@ int xc_version(xc_interface *xch, int cmd, void *arg)case XENVER_commandline: sz =sizeof (xen_commandline_t);break ; +case XENVER_build_id: + sz =sizeof (xen_build_id_t); +break ;default :ERROR ("xc_version: unknown command %d\n" , cmd);return -EINVAL ;
tools/misc/xen-xsplice.c +25 -0
@@ -17,6 +17,7 @@ void show_help(void)" <id> An unique name of payload. Up to 40 characters.\n" "Commands:\n" " help display this help\n" +" build-id display build-id of hypervisor.\n" " upload <id> <file> upload file <cpuid> with <id> name\n" " list list payloads uploaded.\n" " apply <id> apply <id> patch.\n"
@@ -306,12 +307,36 @@ int action_func(int argc, char *argv[], unsigned int idx)return rc; } + +static int build_id_func (int argc,char *argv[]) +{ +xen_build_id_t build_id; + +if ( argc ) + { +show_help (); +return -1 ; + } + +memset (build_id,0 ,sizeof (*build_id)); + +if (xc_version (xch, XENVER_build_id, &build_id) <0 ) + { +printf ("Failed to get build_id: %d(%s)\n" , errno,strerror (errno)); +return -1 ; + } + +printf ("%s\n" , build_id); +return 0 ; +} +struct {const char *name;int (*function)(int argc,char *argv[]); } main_options[] = { {"help" , help_func }, {"list" , list_func }, + {"build-id" , build_id_func }, {"upload" , upload_func }, };
xen/common/kernel.c +11 -0
@@ -357,6 +357,17 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)if (copy_to_guest (arg, saved_cmdline,ARRAY_SIZE (saved_cmdline)) )return -EFAULT ;return 0 ; + +case XENVER_build_id: + { +xen_build_id_t build_id; + +memset (build_id,0 ,sizeof (build_id)); +safe_strcpy (build_id,xen_build_id ()); +if (copy_to_guest (arg, build_id,ARRAY_SIZE (build_id)) ) +return -EFAULT ; +return 0 ; + } }return -ENOSYS ;
xen/common/version.c +5 -0
@@ -55,3 +55,8 @@ const char *xen_banner(void) {return XEN_BANNER ; } + +const char *xen_build_id (void ) +{ +return XEN_BUILD_ID ; +}
xen/include/public/version.h +4 -0
@@ -83,6 +83,10 @@ typedef struct xen_feature_info xen_feature_info_t;#define XENVER_commandline 9typedef char xen_commandline_t [1024 ]; +#define XENVER_build_id 10 +typedef char xen_build_id_t [1024 ]; +#define XEN_BUILD_ID_LEN (sizeof(xen_build_id_t)) +#endif /* __XEN_PUBLIC_VERSION_H__ */ /*
xen/include/xen/compile.h.in +1 -0
@@ -10,4 +10,5 @@ #define XEN_EXTRAVERSION "@@extraversion@@" #define XEN_CHANGESET "@@changeset@@" +#define XEN_BUILD_ID "@@changeset@@" #define XEN_BANNER \
xen/include/xen/version.h +1 -0
@@ -12,5 +12,6 @@ unsigned int xen_minor_version(void);const char *xen_extra_version (void );const char *xen_changeset (void );const char *xen_banner (void ); +const char *xen_build_id (void );#endif /* __XEN_VERSION_H__ */
Signature · 1 line
1.8.4.2
Re: [RFC PATCH v3.1 2/2] xsplice: Add hook for build_id
xen/include/xen/compile.h.in line 13
Quoted 9 lines · Konrad Rzeszutek Wilk
xen/include/xen/compile.h.in +1
-0@@ -10,4 +10,5 @@ #define XEN_EXTRAVERSION "@@extraversion@@" #define XEN_CHANGESET "@@changeset@@" +#define XEN_BUILD_ID "@@changeset@@"
I am not sure putting the changeset into the build id field is sensible.
On the other hand, linking .note.gnu.build-id and exposing it as XENVER_build_id seems like a very sensible thing to do. It would probably make sense to expose it in xl info.
~Andrew
Re: [RFC PATCH v3.1 2/2] xsplice: Add hook for build_id
Quoted 9 lines · Andrew Cooper
Review
Quoted 1 line · Konrad Rzeszutek Wilk
(quoted diff) +0
-0b/xen/include/xen/compile.h.in
Quoted 6 lines
index 440ecb2..939685e 100644
xen/include/xen/compile.h.in +0
-0@@ -10,4 +10,5 @@ #define XEN_EXTRAVERSION "@@extraversion@@"
Quoted 6 lines
xen/include/xen/compile.h.in line 13
Quoted 2 lines
xen/include/xen/compile.h.in +1
-0#define XEN_CHANGESET "@@changeset@@" +#define XEN_BUILD_ID "@@changeset@@"I am not sure putting the changeset into the build id field is sensible.
Correct, it is unfinished.
Quoted 3 lines
On the other hand, linking .note.gnu.build-id and exposing it as
XENVER_build_idseems like a very sensible thing to do. It would probably make sense to expose it inxl info.
That can certainly be done.
Quoted 2 lines
~Andrew
Re: [RFC PATCH v3.1 2/2] xsplice: Add hook for build_id
In reply to Konrad Rzeszutek WilkQuoted 79 lines · Konrad Rzeszutek Wilk
Signed-off-by Konrad Rzeszutek Wilk <[email protected]>--- tools/libxc/xc_private.c | 3 +++ tools/misc/xen-xsplice.c | 25 +++++++++++++++++++++++++ xen/common/kernel.c | 11 +++++++++++ xen/common/version.c | 5 +++++ xen/include/public/version.h | 4 ++++ xen/include/xen/compile.h.in | 1 + xen/include/xen/version.h | 1 + 7 files changed, 50 insertions(+)tools/libxc/xc_private.c +3
-0@@ -713,6 +713,9 @@ int xc_version(xc_interface *xch, int cmd, void *arg)case XENVER_commandline: sz =sizeof (xen_commandline_t);break ; +case XENVER_build_id: + sz =sizeof (xen_build_id_t); +break ;default :ERROR ("xc_version: unknown command %d\n" , cmd);return -EINVAL ;tools/misc/xen-xsplice.c +25
-0@@ -17,6 +17,7 @@ void show_help(void)" <id> An unique name of payload. Up to 40 characters.\n" "Commands:\n" " help display this help\n" +" build-id display build-id of hypervisor.\n" " upload <id> <file> upload file <cpuid> with <id> name\n" " list list payloads uploaded.\n" " apply <id> apply <id> patch.\n" @@ -306,12 +307,36 @@ int action_func(int argc, char *argv[], unsigned int idx)return rc; } + +static int build_id_func (int argc,char *argv[]) +{ +xen_build_id_t build_id; + +if ( argc ) + { +show_help (); +return -1 ; + } + +memset (build_id,0 ,sizeof (*build_id)); + +if (xc_version (xch, XENVER_build_id, &build_id) <0 ) + { +printf ("Failed to get build_id: %d(%s)\n" , errno,strerror (errno)); +return -1 ; + } + +printf ("%s\n" , build_id); +return 0 ; +} +struct {const char *name;int (*function)(int argc,char *argv[]); } main_options[] = { {"help" , help_func }, {"list" , list_func }, + {"build-id" , build_id_func }, {"upload" , upload_func }, };xen/common/kernel.c +0
-0
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 366
Quoted 10 lines
xen/common/kernel.c +7
-0@@ -357,6 +357,17 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)if (copy_to_guest (arg, saved_cmdline,ARRAY_SIZE (saved_cmdline)) )return -EFAULT ;return 0 ; + +case XENVER_build_id: + { +xen_build_id_t build_id; + +memset (build_id,0 ,sizeof (build_id)); +safe_strcpy (build_id,xen_build_id ());
You seem to want to store and transfer the build_id as a string. Any reason why we don't directly expose the build_id embedded by the linker in binary format?
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 370
Quoted 4 lines
xen/common/kernel.c +4
-0+if (copy_to_guest (arg, build_id,ARRAY_SIZE (build_id)) ) +return -EFAULT ; +return 0 ; + }
We should not expose the build_id to normal guests, but only to Dom0.
A build_id uniquely identifies a specific build and I don't see how that information would be required from DomU. It might actually help an attacker to build his return-oriented programming exploit against a specific build.
The normal version numbers should be enough to know about capabilities and API.
Quoted 36 lines
xen/common/kernel.c +0
-0}return -ENOSYS ;xen/common/version.c +5
-0@@ -55,3 +55,8 @@ const char *xen_banner(void) {return XEN_BANNER ; } + +const char *xen_build_id (void ) +{ +return XEN_BUILD_ID ; +}xen/include/public/version.h +4
-0@@ -83,6 +83,10 @@ typedef struct xen_feature_info xen_feature_info_t;#define XENVER_commandline 9typedef char xen_commandline_t [1024 ]; +#define XENVER_build_id 10 +typedef char xen_build_id_t [1024 ]; +#define XEN_BUILD_ID_LEN (sizeof(xen_build_id_t)) +#endif /* __XEN_PUBLIC_VERSION_H__ */ /* xen/include/xen/compile.h.in +0
-0
xen/include/xen/compile.h.in line 13
Quoted 4 lines
xen/include/xen/compile.h.in +1
-0@@ -10,4 +10,5 @@ #define XEN_EXTRAVERSION "@@extraversion@@" #define XEN_CHANGESET "@@changeset@@" +#define XEN_BUILD_ID "@@changeset@@"
That leads to a chicken and egg problem when embedding a real build_id.
Some linker script magic seems to be required. I will try to refine
the patch.
xen/include/xen/version.h unsigned int xen_minor_version(void); · line 17
Quoted 13 lines
xen/include/xen/compile.h.in +0
-0#define XEN_BANNER \xen/include/xen/version.h +1
-0@@ -12,5 +12,6 @@ unsigned int xen_minor_version(void);const char *xen_extra_version (void );const char *xen_changeset (void );const char *xen_banner (void ); +const char *xen_build_id (void );#endif /* __XEN_VERSION_H__ */
Amazon Development Center Germany GmbH Krausenstr. 38
10117 Berlin
Geschaeftsfuehrer: Dr. Ralf Herbrich, Christian Schlaeger
Ust-ID: DE289237879
Eingetragen am Amtsgericht Charlottenburg HRB 149173 B
Re: [RFC PATCH v3.1 2/2] xsplice: Add hook for build_id
Quoted 100 lines · Martin Pohlack
Quoted 79 lines · Konrad Rzeszutek Wilk
Signed-off-by Konrad Rzeszutek Wilk <[email protected]>--- tools/libxc/xc_private.c | 3 +++ tools/misc/xen-xsplice.c | 25 +++++++++++++++++++++++++ xen/common/kernel.c | 11 +++++++++++ xen/common/version.c | 5 +++++ xen/include/public/version.h | 4 ++++ xen/include/xen/compile.h.in | 1 + xen/include/xen/version.h | 1 + 7 files changed, 50 insertions(+)tools/libxc/xc_private.c +3
-0@@ -713,6 +713,9 @@ int xc_version(xc_interface *xch, int cmd, void *arg)case XENVER_commandline: sz =sizeof (xen_commandline_t);break ; +case XENVER_build_id: + sz =sizeof (xen_build_id_t); +break ;default :ERROR ("xc_version: unknown command %d\n" , cmd);return -EINVAL ;tools/misc/xen-xsplice.c +25
-0@@ -17,6 +17,7 @@ void show_help(void)" <id> An unique name of payload. Up to 40 characters.\n" "Commands:\n" " help display this help\n" +" build-id display build-id of hypervisor.\n" " upload <id> <file> upload file <cpuid> with <id> name\n" " list list payloads uploaded.\n" " apply <id> apply <id> patch.\n" @@ -306,12 +307,36 @@ int action_func(int argc, char *argv[], unsigned int idx)return rc; } + +static int build_id_func (int argc,char *argv[]) +{ +xen_build_id_t build_id; + +if ( argc ) + { +show_help (); +return -1 ; + } + +memset (build_id,0 ,sizeof (*build_id)); + +if (xc_version (xch, XENVER_build_id, &build_id) <0 ) + { +printf ("Failed to get build_id: %d(%s)\n" , errno,strerror (errno)); +return -1 ; + } + +printf ("%s\n" , build_id); +return 0 ; +} +struct {const char *name;int (*function)(int argc,char *argv[]); } main_options[] = { {"help" , help_func }, {"list" , list_func }, + {"build-id" , build_id_func }, {"upload" , upload_func }, };xen/common/kernel.c +0
-0xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 366
Quoted 10 lines
xen/common/kernel.c +7
-0@@ -357,6 +357,17 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)if (copy_to_guest (arg, saved_cmdline,ARRAY_SIZE (saved_cmdline)) )return -EFAULT ;return 0 ; + +case XENVER_build_id: + { +xen_build_id_t build_id; + +memset (build_id,0 ,sizeof (build_id)); +safe_strcpy (build_id,xen_build_id ());You seem to want to store and transfer the
build_idas a string. Any reason why we don't directly expose thebuild_idembedded by the linker in binary format?xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 370
Quoted 4 lines
xen/common/kernel.c +4
-0+if (copy_to_guest (arg, build_id,ARRAY_SIZE (build_id)) ) +return -EFAULT ; +return 0 ; + }We should not expose the
build_idto normal guests, but only to Dom0.
Quoted 7 lines
A
build_iduniquely identifies a specific build and I don't see how that information would be required from DomU. It might actually help an attacker to build his return-oriented programming exploit against a specific build.The normal version numbers should be enough to know about capabilities and API.
It will need its own XSM hook, but need not be strictly limited to just dom0.
Quoted 39 lines
Quoted 39 lines
xen/common/kernel.c +0
-0}return -ENOSYS ;xen/common/version.c +5
-0@@ -55,3 +55,8 @@ const char *xen_banner(void) {return XEN_BANNER ; } + +const char *xen_build_id (void ) +{ +return XEN_BUILD_ID ; +}xen/include/public/version.h +4
-0@@ -83,6 +83,10 @@ typedef struct xen_feature_info xen_feature_info_t;#define XENVER_commandline 9typedef char xen_commandline_t [1024 ]; +#define XENVER_build_id 10 +typedef char xen_build_id_t [1024 ]; +#define XEN_BUILD_ID_LEN (sizeof(xen_build_id_t)) +#endif /* __XEN_PUBLIC_VERSION_H__ */ /* xen/include/xen/compile.h.in +0
-0@@ -10,4 +10,5 @@ #define XEN_EXTRAVERSION "@@extraversion@@"
Quoted 5 lines
xen/include/xen/compile.h.in line 13
Quoted 2 lines
xen/include/xen/compile.h.in +1
-0#define XEN_CHANGESET "@@changeset@@" +#define XEN_BUILD_ID "@@changeset@@"That leads to a chicken and egg problem when embedding a real
build_id.
Some linker script magic seems to be required. I will try to refine
the patch.
So funnily enough, I tried experimenting with this and it is fairly easy to get the basics done.
Further TODO which I havn't done yet is make the --build-id optional on finding a compatible ld, and some symbol magic to directly locate .note.gnu.build-id
However, this in addition to some of Konrad's original patch is a good start.
~Andrew
xen/arch/x86/Makefile +0 -0
@@ -112,7 +112,7 @@ $(TARGET)-syms: prelink.o xen.lds
$(BASEDIR)/common/symbols-dummy.o
$(@D)/.$(@F).0.o -o $(@D)/.$(@F).1
$(NM) -n $(@D)/.$(@F).1 | $(BASEDIR)/tools/symbols >$(@D)/.$(@F).1.S
$(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).1.o
- $(LD) $(LDFLAGS) -T xen.lds -N prelink.o \
+ $(LD) $(LDFLAGS) -T xen.lds -N prelink.o --build-id \
$(@D)/.$(@F).1.o -o $@
rm -f $(@D)/.$(@F).[0-9]*xen/arch/x86/xen.lds.S +7 -0
@@ -68,6 +68,13 @@ SECTIONS } :text . = ALIGN(SMP_CACHE_BYTES); + .notes : { + __start_notes = .; + *(.note.*) + __end_notes = .; + } :text + + . = ALIGN(SMP_CACHE_BYTES); .data.read_mostly : { /* Exception table */ __start___ex_table = .;
Re: [RFC PATCH v3.1 2/2] xsplice: Add hook for build_id
Quoted 191 lines · Andrew Cooper
Quoted 100 lines · Martin Pohlack
Quoted 79 lines · Konrad Rzeszutek Wilk
Signed-off-by Konrad Rzeszutek Wilk <[email protected]>--- tools/libxc/xc_private.c | 3 +++ tools/misc/xen-xsplice.c | 25 +++++++++++++++++++++++++ xen/common/kernel.c | 11 +++++++++++ xen/common/version.c | 5 +++++ xen/include/public/version.h | 4 ++++ xen/include/xen/compile.h.in | 1 + xen/include/xen/version.h | 1 + 7 files changed, 50 insertions(+)tools/libxc/xc_private.c +3
-0@@ -713,6 +713,9 @@ int xc_version(xc_interface *xch, int cmd, void *arg)case XENVER_commandline: sz =sizeof (xen_commandline_t);break ; +case XENVER_build_id: + sz =sizeof (xen_build_id_t); +break ;default :ERROR ("xc_version: unknown command %d\n" , cmd);return -EINVAL ;tools/misc/xen-xsplice.c +25
-0@@ -17,6 +17,7 @@ void show_help(void)" <id> An unique name of payload. Up to 40 characters.\n" "Commands:\n" " help display this help\n" +" build-id display build-id of hypervisor.\n" " upload <id> <file> upload file <cpuid> with <id> name\n" " list list payloads uploaded.\n" " apply <id> apply <id> patch.\n" @@ -306,12 +307,36 @@ int action_func(int argc, char *argv[], unsigned int idx)return rc; } + +static int build_id_func (int argc,char *argv[]) +{ +xen_build_id_t build_id; + +if ( argc ) + { +show_help (); +return -1 ; + } + +memset (build_id,0 ,sizeof (*build_id)); + +if (xc_version (xch, XENVER_build_id, &build_id) <0 ) + { +printf ("Failed to get build_id: %d(%s)\n" , errno,strerror (errno)); +return -1 ; + } + +printf ("%s\n" , build_id); +return 0 ; +} +struct {const char *name;int (*function)(int argc,char *argv[]); } main_options[] = { {"help" , help_func }, {"list" , list_func }, + {"build-id" , build_id_func }, {"upload" , upload_func }, };xen/common/kernel.c +0
-0xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 366
Quoted 10 lines
xen/common/kernel.c +7
-0@@ -357,6 +357,17 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)if (copy_to_guest (arg, saved_cmdline,ARRAY_SIZE (saved_cmdline)) )return -EFAULT ;return 0 ; + +case XENVER_build_id: + { +xen_build_id_t build_id; + +memset (build_id,0 ,sizeof (build_id)); +safe_strcpy (build_id,xen_build_id ());You seem to want to store and transfer the
build_idas a string. Any reason why we don't directly expose thebuild_idembedded by the linker in binary format?xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 370
Quoted 4 lines
xen/common/kernel.c +4
-0+if (copy_to_guest (arg, build_id,ARRAY_SIZE (build_id)) ) +return -EFAULT ; +return 0 ; + }We should not expose the
build_idto normal guests, but only to Dom0.Quoted 7 lines
A
build_iduniquely identifies a specific build and I don't see how that information would be required from DomU. It might actually help an attacker to build his return-oriented programming exploit against a specific build.The normal version numbers should be enough to know about capabilities and API.
It will need its own XSM hook, but need not be strictly limited to just dom0.
Quoted 39 lines
Quoted 39 lines
xen/common/kernel.c +0
-0}return -ENOSYS ;xen/common/version.c +5
-0@@ -55,3 +55,8 @@ const char *xen_banner(void) {return XEN_BANNER ; } + +const char *xen_build_id (void ) +{ +return XEN_BUILD_ID ; +}xen/include/public/version.h +4
-0@@ -83,6 +83,10 @@ typedef struct xen_feature_info xen_feature_info_t;#define XENVER_commandline 9typedef char xen_commandline_t [1024 ]; +#define XENVER_build_id 10 +typedef char xen_build_id_t [1024 ]; +#define XEN_BUILD_ID_LEN (sizeof(xen_build_id_t)) +#endif /* __XEN_PUBLIC_VERSION_H__ */ /* xen/include/xen/compile.h.in +0
-0@@ -10,4 +10,5 @@ #define XEN_EXTRAVERSION "@@extraversion@@"Quoted 5 lines
xen/include/xen/compile.h.in line 13
Quoted 2 lines
xen/include/xen/compile.h.in +1
-0#define XEN_CHANGESET "@@changeset@@" +#define XEN_BUILD_ID "@@changeset@@"That leads to a chicken and egg problem when embedding a real
build_id.
Some linker script magic seems to be required. I will try to refine
the patch.So funnily enough, I tried experimenting with this and it is fairly easy to get the basics done.
Further TODO which I havn't done yet is make the --build-id optional on finding a compatible
ld, and some symbol magic to directly locate .note.gnu.build-idHowever, this in addition to some of Konrad's original patch is a good start.
~Andrew
xen/arch/x86/Makefile +0
-0@@ -112,7 +112,7 @@ $(TARGET)-syms: prelink.o xen.lds$(BASEDIR)/common/symbols-dummy.o
$(@D)/.$(@F).0.o -o $(@D)/.$(@F).1 $(NM) -n $(@D)/.$(@F).1 | $(BASEDIR)/tools/symbols >$(@D)/.$(@F).1.S $(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).1.oxen/arch/x86/Makefile +1
-1- $(LD) $(LDFLAGS) -T xen.lds -N prelink.o \ + $(LD) $(LDFLAGS) -T xen.lds -N prelink.o --build-id \ $(@D)/.$(@F).1.o -o $@ rm -f $(@D)/.$(@F).[0-9]*xen/arch/x86/xen.lds.S +0
-0@@ -68,6 +68,13 @@ SECTIONS } :text . = ALIGN(SMP_CACHE_BYTES);
xen/arch/x86/xen.lds.S SECTIONS · line 80
Quoted 10 lines
xen/arch/x86/xen.lds.S +7
-0+ .notes : { + __start_notes = .; + *(.note.*) + __end_notes = .; + } :text + + . = ALIGN(SMP_CACHE_BYTES); .data.read_mostly : { /* Exception table */ __start___ex_table = .;
And here is my version, also on-top of Konrad's series:
----------------------------------------------------------------------
[PATCH] xsplice: Use ld-embedded build-ids
Todo:
* Should be moved to sysctl to only allow Dom0 access
* Maybe convert to binary transport to userland instead of printable form
* use ld to actually embed the build ID
* convert to textual representation in hypervisor and report in printable form
--- xen/arch/x86/Makefile | 4 ++-- xen/arch/x86/xen.lds.S | 5 +++++ xen/common/kernel.c | 33 +++++++++++++++++++++++++++++---- xen/common/version.c | 5 ----- xen/include/xen/compile.h.in | 1 - 5 files changed, 36 insertions(+), 12 deletions(-)
xen/arch/x86/Makefile +0 -0
@@ -108,11 +108,11 @@ $(TARGET)-syms: prelink.o xen.lds
$(BASEDIR)/common/symbols-dummy.o
$(BASEDIR)/common/symbols-dummy.o -o $(@D)/.$(@F).0
$(NM) -n $(@D)/.$(@F).0 | $(BASEDIR)/tools/symbols >$(@D)/.$(@F).0.S $(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).0.o
- $(LD) $(LDFLAGS) -T xen.lds -N prelink.o \
+ $(LD) $(LDFLAGS) -T xen.lds -N prelink.o --build-id=sha1 \
$(@D)/.$(@F).0.o -o $(@D)/.$(@F).1
$(NM) -n $(@D)/.$(@F).1 | $(BASEDIR)/tools/symbols >$(@D)/.$(@F).1.S $(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).1.o
- $(LD) $(LDFLAGS) -T xen.lds -N prelink.o \
+ $(LD) $(LDFLAGS) -T xen.lds -N prelink.o --build-id=sha1 \
$(@D)/.$(@F).1.o -o $@
rm -f $(@D)/.$(@F).[0-9]*
xen/arch/x86/xen.lds.S +5 -0
@@ -67,6 +67,11 @@ SECTIONS *(.rodata.*) } :text + .note.gnu.build-id : { + __note_gnu_build_id_start = .; + *(.note.gnu.build-id) + } :text + . = ALIGN(SMP_CACHE_BYTES); .data.read_mostly : { /* Exception table */
xen/common/kernel.c +6 -0
@@ -6,9 +6,11 @@#include <xen/init.h> #include <xen/lib.h> +#include <xen/elf.h> #include <xen/errno.h> #include <xen/version.h> #include <xen/sched.h> +#include <xen/types.h> #include <xen/paging.h> #include <xen/nmi.h> #include <xen/guest_access.h>
@@ -227,6 +229,10 @@ void __init do_initcalls(void)* Simple hypercalls. */ +#define NT_GNU_BUILD_ID 3 + +extern char * __note_gnu_build_id_start;/* defined in linker script */ +DO (xen_version)(int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) { switch ( cmd )
@@ -360,11 +366,30 @@ DO(xen_version)(int cmd,
XEN_GUEST_HANDLE_PARAM(void) arg)
case XENVER_build_id:
{
- xen_build_id_t build_id;
+ xen_build_id_t ascii_id;
+ Elf_Note * n = (Elf_Note *)&__note_gnu_build_id_start;
+ char * binary_id;
+ int i;+
+ memset(ascii_id, 0, sizeof(ascii_id));
+
+ /* check if we really have a build-id */
+ if ( NT_GNU_BUILD_ID != n->type )
+ return 0;
+
+ /* sanity check, name should be "GNU" for ld-generated build-id */
+ if ( 0 != strncmp(ELFNOTE_NAME(n), "GNU", n->namesz))
+ return 0;
+
+ binary_id = (char *)ELFNOTE_DESC(n);
+
+ /* convert to printable format */
+ for (i = 0; i < n->descsz && (i + 1) * 2 <sizeof(xen_build_id_t); i++)
+ {
+ snprintf(&ascii_id[i * 2], 3, "%02hhx", binary_id[i]);
+ }
- memset(build_id, 0, sizeof(build_id));
- safe_strcpy(build_id, xen_build_id());
- if ( copy_to_guest(arg, build_id, ARRAY_SIZE(build_id)) )
+ if ( copy_to_guest(arg, ascii_id, ARRAY_SIZE(ascii_id)) )
return -EFAULT;
return 0;
}xen/common/version.c +0 -5
@@ -55,8 +55,3 @@ const char *xen_banner(void) {return XEN_BANNER ; } - -const char *xen_build_id (void ) -{ -return XEN_BUILD_ID ; -}
xen/include/xen/compile.h.in +0 -1
@@ -10,5 +10,4 @@ #define XEN_EXTRAVERSION "@@extraversion@@" #define XEN_CHANGESET "@@changeset@@" -#define XEN_BUILD_ID "@@changeset@@" #define XEN_BANNER \
Signature · 8 lines
2.5.0 Amazon Development Center Germany GmbH Krausenstr. 38 10117 Berlin Geschaeftsfuehrer: Dr. Ralf Herbrich, Christian Schlaeger Ust-ID: DE289237879 Eingetragen am Amtsgericht Charlottenburg HRB 149173 B
(no subject)
Sending again without MUA-mangled patch.
Amazon Development Center Germany GmbH Krausenstr. 38
10117 Berlin
Geschaeftsfuehrer: Dr. Ralf Herbrich, Christian Schlaeger
Ust-ID: DE289237879
Eingetragen am Amtsgericht Charlottenburg HRB 149173 B
PATCH 1/1 xsplice: Use ld-embedded build-ids
In reply to Martin PohlackTodo:
* Should be moved to sysctl to only allow Dom0 access
* Maybe convert to binary transport to userland instead of printable form
* use ld to actually embed the build ID
* convert to textual representation in hypervisor and report in printable form
--- xen/arch/x86/Makefile | 4 ++-- xen/arch/x86/xen.lds.S | 5 +++++ xen/common/kernel.c | 33 +++++++++++++++++++++++++++++---- xen/common/version.c | 5 ----- xen/include/xen/compile.h.in | 1 - 5 files changed, 36 insertions(+), 12 deletions(-)
xen/arch/x86/Makefile +2 -2
@@ -108,11 +108,11 @@ $(TARGET)-syms: prelink.o xen.lds $(BASEDIR)/common/symbols-dummy.o $(BASEDIR)/common/symbols-dummy.o -o $(@D)/.$(@F).0 $(NM) -n $(@D)/.$(@F).0 | $(BASEDIR)/tools/symbols >$(@D)/.$(@F).0.S $(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).0.o - $(LD) $(LDFLAGS) -T xen.lds -N prelink.o \ + $(LD) $(LDFLAGS) -T xen.lds -N prelink.o --build-id=sha1 \ $(@D)/.$(@F).0.o -o $(@D)/.$(@F).1 $(NM) -n $(@D)/.$(@F).1 | $(BASEDIR)/tools/symbols >$(@D)/.$(@F).1.S $(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).1.o - $(LD) $(LDFLAGS) -T xen.lds -N prelink.o \ + $(LD) $(LDFLAGS) -T xen.lds -N prelink.o --build-id=sha1 \ $(@D)/.$(@F).1.o -o $@ rm -f $(@D)/.$(@F).[0-9]*
xen/arch/x86/xen.lds.S +5 -0
@@ -67,6 +67,11 @@ SECTIONS *(.rodata.*) } :text + .note.gnu.build-id : { + __note_gnu_build_id_start = .; + *(.note.gnu.build-id) + } :text + . = ALIGN(SMP_CACHE_BYTES); .data.read_mostly : { /* Exception table */
xen/common/kernel.c +29 -4
@@ -6,9 +6,11 @@#include <xen/init.h> #include <xen/lib.h> +#include <xen/elf.h> #include <xen/errno.h> #include <xen/version.h> #include <xen/sched.h> +#include <xen/types.h> #include <xen/paging.h> #include <xen/nmi.h> #include <xen/guest_access.h>
@@ -227,6 +229,10 @@ void __init do_initcalls(void)* Simple hypercalls. */ +#define NT_GNU_BUILD_ID 3 + +extern char * __note_gnu_build_id_start;/* defined in linker script */ +DO (xen_version)(int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) { switch ( cmd )
@@ -360,11 +366,30 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)case XENVER_build_id: { -xen_build_id_t build_id; +xen_build_id_t ascii_id; +Elf_Note * n = (Elf_Note *)&__note_gnu_build_id_start; +char * binary_id; +int i; + +memset (ascii_id,0 ,sizeof (ascii_id)); + +/* check if we really have a build-id */ +if (NT_GNU_BUILD_ID != n->type ) +return 0 ; + +/* sanity check, name should be "GNU" for ld-generated build-id */ +if (0 !=strncmp (ELFNOTE_NAME (n),"GNU" , n->namesz)) +return 0 ; + + binary_id = (char *)ELFNOTE_DESC (n); + +/* convert to printable format */ +for (i =0 ; i < n->descsz && (i +1 ) *2 <sizeof (xen_build_id_t); i++) + { +snprintf (&ascii_id[i *2 ],3 ,"%02hhx" , binary_id[i]); + } -memset (build_id,0 ,sizeof (build_id)); -safe_strcpy (build_id,xen_build_id ()); -if (copy_to_guest (arg, build_id,ARRAY_SIZE (build_id)) ) +if (copy_to_guest (arg, ascii_id,ARRAY_SIZE (ascii_id)) )return -EFAULT ;return 0 ; }
xen/common/version.c +0 -5
@@ -55,8 +55,3 @@ const char *xen_banner(void) {return XEN_BANNER ; } - -const char *xen_build_id (void ) -{ -return XEN_BUILD_ID ; -}
xen/include/xen/compile.h.in +0 -1
@@ -10,5 +10,4 @@ #define XEN_EXTRAVERSION "@@extraversion@@" #define XEN_CHANGESET "@@changeset@@" -#define XEN_BUILD_ID "@@changeset@@" #define XEN_BANNER \
Signature · 8 lines
2.5.0 Amazon Development Center Germany GmbH Krausenstr. 38 10117 Berlin Geschaeftsfuehrer: Dr. Ralf Herbrich, Christian Schlaeger Ust-ID: DE289237879 Eingetragen am Amtsgericht Charlottenburg HRB 149173 B
Re: [PATCH] xsplice: Use ld-embedded build-ids
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 05.08.15 at 16:09, <[email protected]> wrote:
Todo:
* Should be moved to sysctl to only allow Dom0 access
Because of?
Quoted 1 line
* Maybe convert to binary transport to userland instead of printable form
Indeed.
Quoted 5 lines
xen/common/kernel.c +0
-1@@ -360,11 +366,30 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)case XENVER_build_id: { -xen_build_id_t build_id;
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 378
Quoted 10 lines
xen/common/kernel.c +10
-0+xen_build_id_t ascii_id; +Elf_Note * n = (Elf_Note *)&__note_gnu_build_id_start; +char * binary_id; +int i; + +memset (ascii_id,0 ,sizeof (ascii_id)); + +/* check if we really have a build-id */ +if (NT_GNU_BUILD_ID != n->type ) +return 0 ;
This needs to signal an error.
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 382
Quoted 4 lines
xen/common/kernel.c +4
-0+ +/* sanity check, name should be "GNU" for ld-generated build-id */ +if (0 !=strncmp (ELFNOTE_NAME (n),"GNU" , n->namesz)) +return 0 ;
Same here.
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 390
Quoted 7 lines
xen/common/kernel.c +7
-0+ binary_id = (char *)ELFNOTE_DESC (n); + +/* convert to printable format */ +for (i =0 ; i < n->descsz && (i +1 ) *2 <sizeof (xen_build_id_t); i++) + { +snprintf (&ascii_id[i *2 ],3 ,"%02hhx" , binary_id[i]); + }
No need for the braces, and no need for the"hh" modifier.
Jan
Re: [PATCH] xsplice: Use ld-embedded build-ids
Quoted 5 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 05.08.15 at 16:09, <[email protected]> wrote:
Todo:
* Should be moved to sysctl to only allow Dom0 accessBecause of?
The discussion in this thread:
[Xen-devel] [RFC PATCH v3.1 2/2] xsplice: Add hook for build_id
was:
----------------------------------------------------------------------
Quoted 8 lines
Quoted 8 lines
Martin Pohlack:
We should not expose thebuild_idto normal guests, but only to Dom0.A
build_iduniquely identifies a specific build and I don't see how that information would be required from DomU. It might actually help an attacker to build his return-oriented programming exploit against a specific build.
Quoted 7 lines
Quoted 2 lines
The normal version numbers should be enough to know about capabilities and API.
Andrew Cooper:
It will need its own XSM hook, but need not be strictly limited to just dom0.
----------------------------------------------------------------------
Quoted 6 lines
Quoted 1 line
* Maybe convert to binary transport to userland instead of printable form
Indeed.
Quoted 2 lines
(quoted diff) +0
-0@@ -360,11 +366,30 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
Quoted 15 lines
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 378
Quoted 13 lines
xen/common/kernel.c +10
-1case XENVER_build_id: { -xen_build_id_t build_id; +xen_build_id_t ascii_id; +Elf_Note * n = (Elf_Note *)&__note_gnu_build_id_start; +char * binary_id; +int i; + +memset (ascii_id,0 ,sizeof (ascii_id)); + +/* check if we really have a build-id */ +if (NT_GNU_BUILD_ID != n->type ) +return 0 ;This needs to signal an error.
Yes, ENOSYS, (or ENOENT, ENODATA)?
Quoted 15 lines
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 382
Quoted 4 lines
xen/common/kernel.c +4
-0+ +/* sanity check, name should be "GNU" for ld-generated build-id */ +if (0 !=strncmp (ELFNOTE_NAME (n),"GNU" , n->namesz)) +return 0 ;Same here.
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 390
Quoted 7 lines
xen/common/kernel.c +7
-0+ binary_id = (char *)ELFNOTE_DESC (n); + +/* convert to printable format */ +for (i =0 ; i < n->descsz && (i +1 ) *2 <sizeof (xen_build_id_t); i++) + { +snprintf (&ascii_id[i *2 ],3 ,"%02hhx" , binary_id[i]); + }
Quoted 4 lines
No need for the braces, and no need for the"hh" modifier.
Jan
Amazon Development Center Germany GmbH Krausenstr. 38
10117 Berlin
Geschaeftsfuehrer: Dr. Ralf Herbrich, Christian Schlaeger
Ust-ID: DE289237879
Eingetragen am Amtsgericht Charlottenburg HRB 149173 B
Re: [PATCH] xsplice: Use ld-embedded build-ids
Quoted 22 lines
Quoted 1 line
Quoted 1 line · On 14.08.15 at 14:59, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 05.08.15 at 16:09, <[email protected]> wrote:
Todo:
* Should be moved to sysctl to only allow Dom0 accessBecause of?
The discussion in this thread:
[Xen-devel] [RFC PATCH v3.1 2/2] xsplice: Add hook for
build_idwas:
----------------------------------------------------------------------Quoted 8 lines
Quoted 8 lines
Martin Pohlack:
We should not expose thebuild_idto normal guests, but only to Dom0.A
build_iduniquely identifies a specific build and I don't see how that information would be required from DomU. It might actually help an attacker to build his return-oriented programming exploit against a specific build.
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
The normal version numbers should be enough to know about capabilities and API.
Andrew Cooper:
It will need its own XSM hook, but need not be strictly limited to just dom0.
----------------------------------------------------------------------
So I'm confused - I asked "why Dom0 only" and then you point me to Andrew saying it doesn't need to be Dom0 only?
Quoted 18 lines
Quoted 17 lines
Quoted 5 lines
xen/common/kernel.c +0
-1@@ -360,11 +366,30 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)case XENVER_build_id: { -xen_build_id_t build_id;xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 378
Quoted 10 lines
xen/common/kernel.c +10
-0+xen_build_id_t ascii_id; +Elf_Note * n = (Elf_Note *)&__note_gnu_build_id_start; +char * binary_id; +int i; + +memset (ascii_id,0 ,sizeof (ascii_id)); + +/* check if we really have a build-id */ +if (NT_GNU_BUILD_ID != n->type ) +return 0 ;This needs to signal an error.
Quoted 1 line
Yes, ENOSYS, (or ENOENT, ENODATA)?
Definitely not ENOSYS. ENODATA or EOPNOTSUPP.
Jan
Re: [PATCH] xsplice: Use ld-embedded build-ids
Quoted 25 lines · Jan Beulich
Quoted 25 lines
Quoted 1 line
Quoted 1 line · On 14.08.15 at 14:59, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 05.08.15 at 16:09, <[email protected]> wrote:
Todo:
* Should be moved to sysctl to only allow Dom0 accessBecause of?
The discussion in this thread:
[Xen-devel] [RFC PATCH v3.1 2/2] xsplice: Add hook for
build_idwas:
----------------------------------------------------------------------Quoted 11 lines
Quoted 10 lines
Martin Pohlack:
We should not expose thebuild_idto normal guests, but only to Dom0.A
build_iduniquely identifies a specific build and I don't see how that information would be required from DomU. It might actually help an attacker to build his return-oriented programming exploit against a specific build.The normal version numbers should be enough to know about capabilities and API.
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
Andrew Cooper:
It will need its own XSM hook, but need not be strictly limited to just dom0.
----------------------------------------------------------------------
So I'm confused - I asked "why Dom0 only" and then you point me to Andrew saying it doesn't need to be Dom0 only?
Sorry about that, my (not expressed) thinking was that we should restrict that to Dom0 for the XSM-disabled case.
Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
Quoted 5 lines
xen/common/kernel.c +0
-1@@ -360,11 +366,30 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)case XENVER_build_id: { -xen_build_id_t build_id;xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 378
Quoted 10 lines
xen/common/kernel.c +10
-0+xen_build_id_t ascii_id; +Elf_Note * n = (Elf_Note *)&__note_gnu_build_id_start; +char * binary_id; +int i; + +memset (ascii_id,0 ,sizeof (ascii_id)); + +/* check if we really have a build-id */ +if (NT_GNU_BUILD_ID != n->type ) +return 0 ;This needs to signal an error.
Quoted 6 lines
Quoted 1 line
Yes, ENOSYS, (or ENOENT, ENODATA)?
Definitely not ENOSYS. ENODATA or EOPNOTSUPP.
Jan
Amazon Development Center Germany GmbH Krausenstr. 38
10117 Berlin
Geschaeftsfuehrer: Dr. Ralf Herbrich, Christian Schlaeger
Ust-ID: DE289237879
Eingetragen am Amtsgericht Charlottenburg HRB 149173 B
Re: [PATCH] xsplice: Use ld-embedded build-ids
Quoted 30 lines · Martin Pohlack
Quoted 29 lines · Jan Beulich
Quoted 29 lines
Quoted 1 line
Quoted 1 line · On 14.08.15 at 14:59, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 05.08.15 at 16:09, <[email protected]> wrote:
Todo:
* Should be moved to sysctl to only allow Dom0 accessBecause of?
The discussion in this thread:
[Xen-devel] [RFC PATCH v3.1 2/2] xsplice: Add hook for
build_idwas:
----------------------------------------------------------------------Quoted 15 lines
Quoted 10 lines
Martin Pohlack:
We should not expose thebuild_idto normal guests, but only to Dom0.A
build_iduniquely identifies a specific build and I don't see how that information would be required from DomU. It might actually help an attacker to build his return-oriented programming exploit against a specific build.The normal version numbers should be enough to know about capabilities and API.
Andrew Cooper:
It will need its own XSM hook, but need not be strictly limited to just dom0.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
----------------------------------------------------------------------
So I'm confused - I asked "why Dom0 only" and then you point me to Andrew saying it doesn't need to be Dom0 only?
Sorry about that, my (not expressed) thinking was that we should restrict that to Dom0 for the XSM-disabled case.
That may make this more complex.
If we want to restrict it to this we may as well just stick this in sysctl and have it be part of the xsplice ops.
Let me do that.
Re: [RFC PATCH v3.1 2/2] xsplice: Add hook for build_id
In reply to Konrad Rzeszutek Wilkxen/include/xen/compile.h.in line 13
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 27.07.15 at 21:20, <[email protected]> wrote:
xen/include/xen/compile.h.in +1
-0@@ -10,4 +10,5 @@ #define XEN_EXTRAVERSION "@@extraversion@@" #define XEN_CHANGESET "@@changeset@@" +#define XEN_BUILD_ID "@@changeset@@"
How can the changset be a valid / sufficient build ID (even if maybe this is intended to only be a default / fallback)? Wasn't this meant to specifically account for rebuilds (with, say, a compiler slightly updated from the original one, and hence possibly producing slightly different code)?
Jan
Hotpatch construction and __LINE__ (was: [RFC PATCH v3.1] xSplice design.)
In reply to Konrad Rzeszutek WilkHi,
Another high-level point to think about is how we want to handle inlined __LINE__ references. This problem is related to hotpatch construction and potentially has influence on the design of the hotpatching infrastructure in Xen.
Let me try to explain the problem:
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. I believe Linux follows this approach, but the details escape me ATM.
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.
Similar considerations are true to a lesser extent for __FILE__, but I would argue that file renaming should be done outside of hotpatches.
Martin
Quoted 60 lines · Konrad Rzeszutek Wilk
Hey!
Since v3 [http://lists.xen.org/archives/html/xen-devel/2015-07/msg00990.html]
- Nailed down the comments, ingested them in.
- Wrote and tested some code.
RFC v2 [http://lists.xen.org/archives/html/xen-devel/2015-05/msg02142.html]
- Ingested every review comment in.The patches for the code are a shell - there is no patching done at all and it is very much just to test out the design and hypercalls. The hard parts are yet to come :-)
At the Seattle LinuxCon/Xen Summit I will be presenting about xSplice and referring to this URL. There is also an slot for brainstorming to talk in details about things we disagree - and there is ample time to talk during dinner. Martin who has been heavily reviewing the design will be there and I hope other folks will be there as well to shape the design and how we want this to work.
The big outstanding issues are how we want to handle preemption. That is the problem of making an hypercall and waiting for the hypervisor to do its job (and the VCPU is blocked). In the past some XSAs have come out to resolve this and I would very much like this to have it addressed at start.
I think the other issues that have been raised should also be discussed naturally, but the above is crucial (at least for me). I've attached the patches on how I thought the preemption part could be solved by having an 'worker' in hypervisor acting on the commands - and we just poll on the status to see what the hypervisor has done so far.
Lastly, I also plan to add an Wiki to outline the dependency implementation parts that so far bubbled up - I figured Wiki would be better as some folks could put their name behind it.
Now please excuse the roughness of the patch and this giant one huge having everything in it. It ought to be split in three at least: hypervisor, toolstacks (libxc and libxl) - that is to be done later.
docs/misc/xsplice.h | 80 +++ docs/misc/xsplice.markdown | 1230 +++++++++++++++++++++++++++++++++++++++++ docs/misc/xsplice_test.c | 78 +++ tools/libxc/include/xenctrl.h | 16 + tools/libxc/xc_misc.c | 183 ++++++ tools/libxc/xc_private.c | 3 + tools/misc/Makefile | 4 + tools/misc/xen-xsplice.c | 385 +++++++++++++ xen/common/Makefile | 1 + xen/common/kernel.c | 11 + xen/common/keyhandler.c | 8 +- xen/common/sysctl.c | 5 + xen/common/version.c | 5 + xen/common/xsplice.c | 405 ++++++++++++++ xen/include/public/sysctl.h | 66 +++ xen/include/public/version.h | 4 + xen/include/xen/compile.h.in | 1 + xen/include/xen/version.h | 1 + xen/include/xen/xsplice.h | 9 + 19 files changed, 2494 insertions(+), 1 deletion(-)
Quoted 4 lines
Konrad Rzeszutek Wilk (2):
xsplice: rfc.v3.1
xsplice: Add hook forbuild_id
Amazon Development Center Germany GmbH Krausenstr. 38
10117 Berlin
Geschaeftsfuehrer: Dr. Ralf Herbrich, Christian Schlaeger
Ust-ID: DE289237879
Eingetragen am Amtsgericht Charlottenburg HRB 149173 B
Re: Hotpatch construction and __LINE__
Quoted 53 lines · Martin Pohlack
Hi,
Another high-level point to think about is how we want to handle inlined
__LINE__references. This problem is related to hotpatch construction and potentially has influence on the design of the hotpatching infrastructure in Xen.Let me try to explain the problem:
We have
file1.cwith functions f1 and f2 (in that order). f2 contains aBUG()(orWARN()) 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. I believe Linux follows this approach, but the details escape me ATM.
Quoted 7 lines
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.
Similar considerations are true to a lesser extent for
__FILE__, but I would argue that file renaming should be done outside of hotpatches.
Looking at strings xen-syms, we have very few embedded __FILE__/__LINE__'s in other strings, meaning that most come from %s/%d formatting.
bug/warn/assert frames have their references in the exception table, so should be reasonably self contained to fix up.
Regular printk()s are definitely more problematic however. Their references will typically be in %rsi/%rdx and shifting any #line reference across the 256 boundary will change the encoding size of setting the print up.
Jan had a plan to make Xen read its own DWARF symbol table rather than using the current cludge we have where we partially link Xen, extract the public symbol table, rewrite symbol-offsets.c and relink it onto the end.
Perhaps there is an opportunity to piggy-back onto that and have all file/line references coming from the DWARF information. I suspect this will be similar to what Linux does, as it already has support for using its own DWARF/STABS information.
Personally, I think #2 should be avoided wherever possible. The bigger the hotpatch, the greater the opportunity for something to go wrong.
Any panic/stack trace should be able to identify exactly which Xen is running, including some hotpatch status. Hopatches will be[1] small targeted fixes, so I don't think it is unreasonable to expect someone interpreting a stack trace to need to adjust file/line references by the hotpatch delta.
~Andrew
[1] woe betide anyone attempting to use hotpatches for general software updates.
Re: Hotpatch construction and __LINE__
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 05.08.15 at 15:25, <[email protected]> wrote:
Jan had a plan to make Xen read its own DWARF symbol table rather than using the current cludge we have where we partially link Xen, extract the public symbol table, rewrite
symbol-offsets.cand relink it onto the end.
Either I mis-expressed this, or you mis-remember: I'm in no way intending to use DWARF information. What I want to use is the _full_ ELF / COFF symbol table instead of nm output (which has quite a bit of interesting information discarded).
Quoted 4 lines
Perhaps there is an opportunity to piggy-back onto that and have all file/line references coming from the DWARF information. I suspect this will be similar to what Linux does, as it already has support for using its own DWARF/STABS information.
I'm curious where you found this as I'm unaware of such functionality. Recently they even decided to discard all .eh_frame / .dwarf_frame generating annotations the compiler can't itself generate.
Jan
Re: Hotpatch construction and __LINE__
Quoted 9 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 05.08.15 at 15:25, <[email protected]> wrote:
Jan had a plan to make Xen read its own DWARF symbol table rather than using the current cludge we have where we partially link Xen, extract the public symbol table, rewrite
symbol-offsets.cand relink it onto the end.Either I mis-expressed this, or you mis-remember: I'm in no way intending to use DWARF information. What I want to use is the _full_ ELF / COFF symbol table instead of nm output (which has quite a bit of interesting information discarded).
I misremembered. Sorry.
Quoted 7 lines
Quoted 5 lines
Perhaps there is an opportunity to piggy-back onto that and have all file/line references coming from the DWARF information. I suspect this will be similar to what Linux does, as it already has support for using its own DWARF/STABS information.
I'm curious where you found this as I'm unaware of such functionality.
The x86 linker script includes the information (given appropriate CONFIG_ options), and the perf subsystem appears to have code to interpret itself.
~Andrew
Quoted 6 lines
Recently they even decided to discard all .eh_frame / .dwarf_frame generating annotations the compiler can't itself generate.
Jan
Re: Hotpatch construction and __LINE__
In reply to Martin PohlackQuoted 49 lines · Martin Pohlack
Hi,
Another high-level point to think about is how we want to handle inlined
__LINE__references. This problem is related to hotpatch construction and potentially has influence on the design of the hotpatching infrastructure in Xen.Let me try to explain the problem:
We have
file1.cwith functions f1 and f2 (in that order). f2 contains aBUG()(orWARN()) 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.
Quoted 9 lines
3. Introducing an indirection table for storing line numbers and treating that specially for binary diffing. I believe Linux follows this approach, but the details escape me ATM.
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, ASSERT, and WARN, the line number is stored in the bug frame table and as currently implemented, the build tool ignores changes to the bug frame table if there's no corresponding functional change. Which mostly fixes this issue.
Signature · 1 line
Ross Lagerwall