xSplice v1 design and implementation.
PATCH v6 1/1 xSplice v1 design and implementation.
Hey!
Changelog:
v5: http://lists.xen.org/archives/html/xen-devel/2016-03/msg03286.html
- Acked on ALL comments from Jan, mentioned which ones this one does not have (ran out of time).
- test on 8 socket machine with tons of patches
- check the ELF types, not just the names,
- improve the symbol lookup - don't do linear lookup,
- handle multiple same sections (same names) or maybe not?
- resolve whether ELF Note should be in .note or .rodata by default
- figure out why EFI build with --all-symbols spews errors
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
*Tools Maintainers*
All patches acked and have not changed since v5 posting.
*Hypervisor Maintainers*
All the XSM parts have been Acked.
The patch related to VERSION_build_id has been Acked:
HYPERCALL_version_op: Add VERSION_build_id to retrieve build-id.
The rest of the patches need Acks.
There are two ARM related patches:
arm/x86: Use struct virtual_region to do bug, symbol, and (x86) exception tables lookup. arm/x86/vmap: Add vmalloc_type and vm_init_type
Patchset has been tested on ARM (tweaking the Kconfig to build xSplice and then booting and using it under ARM CubieTruck), ARM64 (only built it), and x86 (legacy, my EFI box has issues)
*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.v6
(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 | 1108 +++++++++++++++++++ tools/flask/policy/policy/modules/xen/xen.te | 2 + tools/libxc/include/xenctrl.h | 62 ++ tools/libxc/xc_misc.c | 337 ++++++ tools/libxl/libxl.c | 18 +- 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 ++++++++ xen/Makefile | 8 +- xen/arch/arm/Makefile | 5 +- xen/arch/arm/kernel.c | 2 +- xen/arch/arm/mm.c | 2 +- xen/arch/arm/setup.c | 4 + xen/arch/arm/traps.c | 39 +- xen/arch/arm/xen.lds.S | 16 +- xen/arch/arm/xsplice.c | 88 ++ xen/arch/x86/Makefile | 53 +- xen/arch/x86/alternative.c | 37 +- xen/arch/x86/boot/mkelf32.c | 129 ++- xen/arch/x86/domain.c | 2 + xen/arch/x86/extable.c | 41 +- xen/arch/x86/mm.c | 2 +- xen/arch/x86/setup.c | 6 + xen/arch/x86/test/Makefile | 81 ++ xen/arch/x86/test/xen_bye_world.c | 35 + xen/arch/x86/test/xen_bye_world_func.c | 24 + xen/arch/x86/test/xen_hello_world.c | 33 + xen/arch/x86/test/xen_hello_world_func.c | 38 + xen/arch/x86/test/xen_replace_world.c | 34 + xen/arch/x86/test/xen_replace_world_func.c | 24 + xen/arch/x86/traps.c | 51 +- xen/arch/x86/xen.lds.S | 27 + xen/arch/x86/xsplice.c | 274 +++++ xen/common/Kconfig | 16 + xen/common/Makefile | 3 + xen/common/kernel.c | 4 + xen/common/symbols.c | 43 +- xen/common/sysctl.c | 7 + xen/common/version.c | 70 ++ xen/common/virtual_region.c | 148 +++ xen/common/vmap.c | 160 +-- xen/common/vsprintf.c | 19 +- xen/common/xsplice.c | 1530 ++++++++++++++++++++++++++ xen/common/xsplice_elf.c | 480 ++++++++ xen/drivers/acpi/osl.c | 2 +- xen/include/asm-x86/alternative.h | 4 + xen/include/asm-x86/current.h | 10 +- xen/include/asm-x86/nmi.h | 4 +- xen/include/asm-x86/uaccess.h | 2 + xen/include/public/sysctl.h | 166 +++ xen/include/public/version.h | 3 + xen/include/xen/symbols.h | 11 + xen/include/xen/version.h | 6 + xen/include/xen/virtual_region.h | 47 + xen/include/xen/vmap.h | 47 +- xen/include/xen/xsplice.h | 138 +++ xen/include/xen/xsplice_elf.h | 56 + xen/include/xen/xsplice_patch.h | 25 + xen/xsm/flask/hooks.c | 9 + xen/xsm/flask/policy/access_vectors | 4 + 65 files changed, 5915 insertions(+), 183 deletions(-)
Konrad Rzeszutek Wilk (15):
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
arm/x86: Use struct virtual_region to do bug, symbol, and (x86) exception tables lookup.
x86: Alter nmi_callback_t typedef
arm/x86/vmap: Add vmalloc_type and vm_init_type x86/xen_hello_world.xsplice: Test payload for patching 'xen_extra_version'.
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 MAINTAINERS/xsplice: Add myself and Ross as the maintainers.
Ross Lagerwall (9):
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. x86, xsplice: Print payload's symbol name and payload name in backtraces
xsplice: Add support for bug frames.
xsplice: Add support for exception tables.
xsplice: Add support for alternatives
xsplice: Prevent duplicate payloads from being loaded.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v6 1/24 xsplice: Design document
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.
v6: Update what 'idx' means again!
Move the "Interdependencies section" to make it easier to in the design doc the movement of text (when the patch implements it).
Add also 'version' field to payload.
---
--- docs/misc/xsplice.markdown | 1044 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1044 insertions(+) create mode 100644 docs/misc/xsplice.markdown
docs/misc/xsplice.markdown new file +1044 -0
@@ -0,0 +1,1044 @@ +# 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 version; + uint8_t pad[31]; +}; +</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. + +* `version` is to be one. + +* `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`. +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`. + +## 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 list. */ + 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. + +## TODO Goals + +The implementation must also have a mechanism for (in no particular order): + + * 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. + * Deal with NMI/MCE checks during patching instead of ignoring them. + * Further safety checks (blacklist of which functions cannot be patched, check + the stack, make sure the payload is built with same compiler as hypervisor). + Specifically we want to make sure that xSplice codepaths cannot be patched. + * 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. + * 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. + +### 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. + +### 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. + +## 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
Re: [PATCH v6 01/24] xsplice: Design document
Konrad Rzeszutek Wilk writes ("[PATCH v6 01/24] xsplice: Design document"):
Quoted 5 lines
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.
Much of this is very full of hypervisor innards of which I understand only the basic principles. But the idea and approach seems sound, and I have read the key parts of the document.
Thanks,
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v6 2/24 xen/xsplice: Hypervisor implementation of XEN_XSPLICE_op
In reply to Konrad Rzeszutek WilkThe 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.
v6: Update what 'idx' means. Don't drop lock in find_payload. Make
find_name copy data.
---
--- 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 | 403 +++++++++++++++++++++++++++ xen/include/public/sysctl.h | 166 +++++++++++ xen/include/xen/xsplice.h | 35 +++ xen/xsm/flask/hooks.c | 6 + xen/xsm/flask/policy/access_vectors | 2 + 9 files changed, 633 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
@@ -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
@@ -188,4 +188,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
@@ -57,6 +57,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
@@ -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 +403 -0
403 lines not on this page · raw message
xen/include/public/sysctl.h +166 -0
184 lines not on this page · raw message
xen/include/xen/xsplice.h new file +35 -0
@@ -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
@@ -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
@@ -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
Re: [PATCH v6 02/24] xen/xsplice: Hypervisor implementation of XEN_XSPLICE_op
Quoted 14 lines · Konrad Rzeszutek Wilk
xen/common/xsplice.c new file +14
-0+static int xsplice_upload (xen_sysctl_xsplice_upload_t *upload) +{ +struct payload *data =NULL , *found; +char n[XEN_XSPLICE_NAME_SIZE ]; +int rc; + + rc =verify_payload (upload, n); +if ( rc ) +return rc; + +spin_lock (&payload_lock); + + found =find_payload (n); +if ( found && !IS_ERR (found)/* Found. */ )
xen/common/xsplice.c line 121
Quoted 10 lines
xen/common/xsplice.c new file +10
-0+ { + rc = -EEXIST ; + goto out; + } + +if (IS_ERR (found) ) + { + rc =PTR_ERR (found); + goto out; + }
This logic chain can be simplified to
if ( IS_ERR(found) )
{
rc = PTR_ERR(found);
goto out;
}
else if ( found )
{
rc = -EEXISTS;
goto out;
}xen/common/xsplice.c line 373
Quoted 3 lines
xen/common/xsplice.c new file +3
-0+static void xsplice_printall (unsigned char key) +{ +struct payload *data;
printk("'%u' pressed - Dumping all xsplice patches\n", key);
to match other keyhandlers, and give some context to a bunch of lines starting " name=...".
Quoted 14 lines
xen/common/xsplice.c new file +14
-0+ +if ( !spin_trylock (&payload_lock) ) + { +printk ("Lock held. Try again.\n" ); +return ; + } + + list_for_each_entry ( data, &payload_list, list ) +printk (" name=%s state=%s(%d)\n" , data->name, +state2str (data->state), data->state); + +spin_unlock (&payload_lock); +} +
<snip>
Quoted 16 lines
xen/include/xen/xsplice.h new file +10
-0@@ -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 ; +
xen/include/xen/xsplice.h line 20
Quoted 10 lines
xen/include/xen/xsplice.h new file +10
-0+#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 ;
-ENOSYS, as this disables all xsplice functionality, and matches the existing behaviour for missing SYSCTL_ ops.
Quoted 20 lines
xen/include/xen/xsplice.h new file +15
-0+} + +#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 +0
-0
xen/xsm/flask/hooks.c static int flask_sysctl(int cmd) · line 815
Quoted 8 lines
xen/xsm/flask/hooks.c +5
-0@@ -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
The case statement should not be conditional. Otherwise, a toolstack issuing an xsplice_op against a hypervisor with xsplice compiled out will hit the "Unknown op" below.
Given that XEN2__XSPLICE_OP unconditionally exists, I would just drop the #ifdef's completely, and accept that if this permissions check ends up passing, the actual xsplice_op handler will fail.
No major problems, so with these fixed, Reviewed-by: Andrew Cooper <[email protected]>
xen/xsm/flask/hooks.c static int flask_sysctl(int cmd) · line 819
Quoted 4 lines
xen/xsm/flask/hooks.c +1
-0+default :printk ("flask_sysctl: Unknown op %d\n" , cmd);return -EPERM ;
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 02/24] xen/xsplice: Hypervisor implementation of XEN_XSPLICE_op
In reply to Konrad Rzeszutek WilkQuoted 11 lines
xen/common/xsplice.c new file +11
-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 )
xen/common/xsplice.c line 200
Quoted 10 lines
xen/common/xsplice.c new file +10
-0+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 (&payload_lock); +if ( list->idx >= payload_cnt )
This should have && payload_cnt.
On startup payload_cnt is zero and the toolstack will start with list->idx=0 as well. Which will lead to the '=' and .. well we get an -EINVAL when trying xen-xsplice list when there are no patches.
Above change was introduced in v6 and I hadn't caught it before posting as my tests go straight in patching the hypervisor, not listing the state when there is nothing there :-)
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v6 3/24 libxc: Implementation of XEN_XSPLICE_op in libxc
In reply to Konrad Rzeszutek WilkThe 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
@@ -2620,6 +2620,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
Re: [PATCH v6 03/24] libxc: Implementation of XEN_XSPLICE_op in libxc
Quoted 11 lines · Konrad Rzeszutek Wilk
tools/libxc/xc_misc.c +3
-0@@ -693,6 +693,343 @@ int xc_hvm_inject_trap(return rc; } +int xc_xsplice_upload(xc_interface *xch, + char *name, + unsigned char *payload,
tools/libxc/xc_misc.c int xc_hvm_inject_trap( · line 708
Quoted 10 lines
tools/libxc/xc_misc.c +10
-0+ uint32_t size) +{ +int rc; +DECLARE_SYSCTL ; +DECLARE_HYPERCALL_BUFFER (char, local); +DECLARE_HYPERCALL_BOUNCE (name,0 /* later */ ,XC_HYPERCALL_BUFFER_BOUNCE_IN ); +xen_xsplice_name_t def_name = { .pad = {0 ,0 ,0 } }; + +if ( !name || !payload ) +return -1 ;
Its reasonable to trust (or assert()) that these pointers are not NULL.
Please however don't return -1 without setting errno. We already have too many "failed: Success" cases in libxc. If you do want to keep this, then EINVAL.
tools/libxc/xc_misc.c int xc_hvm_inject_trap( · line 711
Quoted 3 lines
tools/libxc/xc_misc.c +3
-0+ + def_name.size =strlen (name) +1 ; +if ( def_name.size >XEN_XSPLICE_NAME_SIZE )
errno = EINVAL
Quoted 32 lines
tools/libxc/xc_misc.c +32
-0+return -1 ; + +HYPERCALL_BOUNCE_SET_SIZE (name, def_name.size); + +if (xc_hypercall_bounce_pre (xch, name) ) +return -1 ; + + local =xc_hypercall_buffer_alloc (xch, local, size); +if ( !local ) + { +xc_hypercall_bounce_post (xch, name); +return -1 ; + } +memcpy (local, payload, size); + + sysctl.cmd = XEN_SYSCTL_xsplice_op; + sysctl.u.xsplice.cmd =XEN_SYSCTL_XSPLICE_UPLOAD ; + sysctl.u.xsplice.pad =0 ; + sysctl.u.xsplice.u.upload.size = size; +set_xen_guest_handle (sysctl.u.xsplice.u.upload.payload, local); + + sysctl.u.xsplice.u.upload.name = def_name; +set_xen_guest_handle (sysctl.u.xsplice.u.upload.name.name, name); + + rc =do_sysctl (xch, &sysctl); + +xc_hypercall_buffer_free (xch, local); +xc_hypercall_bounce_post (xch, name); + +return rc; +} +
tools/libxc/xc_misc.c int xc_hvm_inject_trap( · line 753
Quoted 10 lines
tools/libxc/xc_misc.c +10
-0+int xc_xsplice_get (xc_interface *xch, +char *name, +xen_xsplice_status_t *status) +{ +int rc; +DECLARE_SYSCTL ; +DECLARE_HYPERCALL_BOUNCE (name,0 /*adjust later */ ,XC_HYPERCALL_BUFFER_BOUNCE_IN ); +xen_xsplice_name_t def_name = { .pad = {0 ,0 ,0 } }; + +if ( !name )
EINVAL
tools/libxc/xc_misc.c int xc_hvm_inject_trap( · line 711
Quoted 4 lines
tools/libxc/xc_misc.c +4
-0+return -1 ; + + def_name.size =strlen (name) +1 ; +if ( def_name.size >XEN_XSPLICE_NAME_SIZE )
EINVAL
Quoted 72 lines
tools/libxc/xc_misc.c +72
-0+return -1 ; + +HYPERCALL_BOUNCE_SET_SIZE (name, def_name.size); + +if (xc_hypercall_bounce_pre (xch, name) ) +return -1 ; + + sysctl.cmd = XEN_SYSCTL_xsplice_op; + sysctl.u.xsplice.cmd =XEN_SYSCTL_XSPLICE_GET ; + sysctl.u.xsplice.pad =0 ; + + sysctl.u.xsplice.u.get.status.state =0 ; + sysctl.u.xsplice.u.get.status.rc =0 ; + + sysctl.u.xsplice.u.get.name = def_name; +set_xen_guest_handle (sysctl.u.xsplice.u.get.name.name, name); + + rc =do_sysctl (xch, &sysctl); + +xc_hypercall_bounce_post (xch, name); + +memcpy (status, &sysctl.u.xsplice.u.get.status,sizeof (*status)); + +return rc; +} + +/* +* 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) +{ +int rc; +DECLARE_SYSCTL ;
tools/libxc/xc_misc.c int xc_hvm_inject_trap( · line 839
Quoted 10 lines
tools/libxc/xc_misc.c +10
-0+/* The sizes are adjusted later - hence zero. */ +DECLARE_HYPERCALL_BOUNCE (info,0 ,XC_HYPERCALL_BUFFER_BOUNCE_OUT ); +DECLARE_HYPERCALL_BOUNCE (name,0 ,XC_HYPERCALL_BUFFER_BOUNCE_OUT ); +DECLARE_HYPERCALL_BOUNCE (len,0 ,XC_HYPERCALL_BUFFER_BOUNCE_OUT ); +uint32_t max_batch_sz, nr; +uint32_t version =0 , retries =0 ; +uint32_t adjust =0 ; +ssize_t sz; + +if ( !max || !info || !name || !len )
EINVAL
Quoted 135 lines
tools/libxc/xc_misc.c +135
-0+return -1 ; + + sysctl.cmd = XEN_SYSCTL_xsplice_op; + sysctl.u.xsplice.cmd =XEN_SYSCTL_XSPLICE_LIST ; + sysctl.u.xsplice.pad =0 ; + sysctl.u.xsplice.u.list.version =0 ; + sysctl.u.xsplice.u.list.idx = start; + sysctl.u.xsplice.u.list.pad =0 ; + + max_batch_sz = max; +/* Convience value. */ + sz =sizeof (*name) *XEN_XSPLICE_NAME_SIZE ; + *done =0 ; + *left =0 ; +do { +/* +* The first time we go in this loop our 'max' may be bigger +* than what the hypervisor is comfortable with - hence the first +* couple of loops may adjust the number of entries we will +* want filled (tracked by 'nr'). +* +* N.B. This is a do { } while loop and the right hand side of +* the conditional when adjusting will evaluate to false (as +* *left is set to zero before the loop. Hence we need this +* adjust - even if we reset it at the start of the loop. +*/ +if ( adjust ) + adjust =0 ;/* Used when adjusting the 'max_batch_sz' or 'retries'. */ + + nr =min (max - *done, max_batch_sz); + + sysctl.u.xsplice.u.list.nr = nr; +/* Fix the size (may vary between hypercalls). */ +HYPERCALL_BOUNCE_SET_SIZE (info, nr *sizeof (*info)); +HYPERCALL_BOUNCE_SET_SIZE (name, nr * nr); +HYPERCALL_BOUNCE_SET_SIZE (len, nr *sizeof (*len)); +/* Move the pointer to proper offset into 'info'. */ + (HYPERCALL_BUFFER (info))->ubuf = info + *done; + (HYPERCALL_BUFFER (name))->ubuf = name + (sz * *done); + (HYPERCALL_BUFFER (len))->ubuf = len + *done; +/* Allocate memory. */ + rc =xc_hypercall_bounce_pre (xch, info); +if ( rc ) +break ; + + rc =xc_hypercall_bounce_pre (xch, name); +if ( rc ) +break ; + + rc =xc_hypercall_bounce_pre (xch, len); +if ( rc ) +break ; + +set_xen_guest_handle (sysctl.u.xsplice.u.list.status, info); +set_xen_guest_handle (sysctl.u.xsplice.u.list.name, name); +set_xen_guest_handle (sysctl.u.xsplice.u.list.len, len); + + rc =do_sysctl (xch, &sysctl); +/* +* From here on we MUST call xc_hypercall_bounce. If rc < 0 we +* end up doing it (outside the loop), so using a break is OK. +*/ +if ( rc <0 && errno ==E2BIG ) + { +if ( max_batch_sz <=1 ) +break ; + max_batch_sz >>=1 ; + adjust =1 ;/* For the loop conditional to let us loop again. */ +/* No memory leaks! */ +xc_hypercall_bounce_post (xch, info); +xc_hypercall_bounce_post (xch, name); +xc_hypercall_bounce_post (xch, len); +continue ; + } +else if ( rc <0 )/* For all other errors we bail out. */ +break ; + +if ( !version ) + version = sysctl.u.xsplice.u.list.version; + +if ( sysctl.u.xsplice.u.list.version != version ) + { +/* We could make this configurable as parameter? */ +if ( retries++ >3 ) + { + rc =-1 ; + errno =EBUSY ; +break ; + } + *done =0 ;/* Retry from scratch. */ + version = sysctl.u.xsplice.u.list.version; + adjust =1 ;/* And make sure we continue in the loop. */ +/* No memory leaks. */ +xc_hypercall_bounce_post (xch, info); +xc_hypercall_bounce_post (xch, name); +xc_hypercall_bounce_post (xch, len); +continue ; + } + +/* We should never hit this, but just in case. */ +if ( rc > nr ) + { + errno =EOVERFLOW ;/* Overflow! */ + rc =-1 ; +break ; + } + *left = sysctl.u.xsplice.u.list.nr;/* Total remaining count. */ +/* Copy only up 'rc' of data' - we could add 'min(rc,nr) if desired. */ +HYPERCALL_BOUNCE_SET_SIZE (info, (rc *sizeof (*info))); +HYPERCALL_BOUNCE_SET_SIZE (name, (rc * sz)); +HYPERCALL_BOUNCE_SET_SIZE (len, (rc *sizeof (*len))); +/* Bounce the data and free the bounce buffer. */ +xc_hypercall_bounce_post (xch, info); +xc_hypercall_bounce_post (xch, name); +xc_hypercall_bounce_post (xch, len); +/* And update how many elements of info we have copied into. */ + *done += rc; +/* Update idx. */ + sysctl.u.xsplice.u.list.idx = *done; + }while ( adjust || (*done < max && *left !=0 ) ); + +if ( rc <0 ) + { +xc_hypercall_bounce_post (xch, len); +xc_hypercall_bounce_post (xch, name); +xc_hypercall_bounce_post (xch, info); + } + +return rc >0 ?0 : rc; +} + +static int _xc_xsplice_action (xc_interface *xch, +char *name, +unsigned int action, +uint32_t timeout)
tools/libxc/xc_misc.c int xc_hvm_inject_trap( · line 984
Quoted 10 lines
tools/libxc/xc_misc.c +10
-0+{ +int rc; +DECLARE_SYSCTL ; +/* The size is figured out when we strlen(name) */ +DECLARE_HYPERCALL_BOUNCE (name,0 ,XC_HYPERCALL_BUFFER_BOUNCE_IN ); +xen_xsplice_name_t def_name = { .pad = {0 ,0 ,0 } }; + + def_name.size =strlen (name) +1 ; + +if ( def_name.size >XEN_XSPLICE_NAME_SIZE )
EINVAL
Quoted 9 lines
tools/libxc/xc_misc.c +9
-0+return -1 ; + +HYPERCALL_BOUNCE_SET_SIZE (name, def_name.size); + +if (xc_hypercall_bounce_pre (xch, name) ) +return -1 ; + + sysctl.cmd = XEN_SYSCTL_xsplice_op; + sysctl.u.xsplice.cmd =XEN_SYSCTL_XSPLICE_ACTION ;
tools/libxc/xc_misc.c int xc_hvm_inject_trap( · line 1003
Quoted 10 lines
tools/libxc/xc_misc.c +10
-0+ sysctl.u.xsplice.pad =0 ; + sysctl.u.xsplice.u.action.cmd = action; + sysctl.u.xsplice.u.action.timeout = timeout; + + sysctl.u.xsplice.u.action.name = def_name; +set_xen_guest_handle (sysctl.u.xsplice.u.action.name.name, name); + + rc =do_sysctl (xch, &sysctl); + +xc_hypercall_bounce_post (xch, name);
Xen doesn't write to name at all, does it? (further suggested by BOUNCE_IN).
If not, you should s/char *name/const &/g across this patch
Otherwise, no major problems. With these fixed, Reviewed-by: Andrew Cooper <[email protected]>
tools/libxc/xc_misc.c int xc_hvm_inject_trap( · line 742
Quoted 3 lines
tools/libxc/xc_misc.c +3
-0+ +return rc; +}
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v6 4/24 xen-xsplice: Tool to manipulate xsplice payloads
In reply to Konrad Rzeszutek WilkA 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
@@ -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
@@ -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
PATCH v6 5/24 arm/x86: Use struct virtual_region to do bug, symbol, and (x86) exception tables lookup.
In reply to Konrad Rzeszutek WilkDuring 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.
v6: s/search_for_text/find_text_region/.
- Drop the uaccess.h need. Make setup_virtual_regions accept two parameters. Remove #ifdef.
- Constify struct exception_table_entry.
- Remove some newlines.
- Change header file guard #define to proper 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 | 148 +++++++++++++++++++++++++++++++++++++++ xen/include/xen/symbols.h | 9 +++ xen/include/xen/virtual_region.h | 47 +++++++++++++ 10 files changed, 280 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
@@ -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
@@ -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 (NULL ,NULL ); +/* 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; +const struct virtual_region *region; -for ( bug = __start_bug_frames, id =0 ; stop_frames[id]; ++bug ) + region =find_text_region (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
@@ -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); +const struct virtual_region *region =find_text_region (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
@@ -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 (__start___ex_table, __stop___ex_table); +/* Full exception support from here on in. */ loader = (mbi->flags &MBI_LOADERNAME )
xen/arch/x86/traps.c +24 -16
@@ -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; +const 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 =find_text_region (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
@@ -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
@@ -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 !!find_text_region (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 ; +const struct virtual_region *region; namebuf[KSYM_NAME_LEN ] =0 ; namebuf[0 ] =0 ; -if (!is_active_kernel_text (addr)) + region =find_text_region (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 +148 -0
148 lines not on this page · raw message
xen/include/xen/symbols.h +9 -0
@@ -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 +47 -0
47 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
Re: [PATCH v6 05/24] arm/x86: Use struct virtual_region to do bug, symbol, and (x86) exception tables lookup.
xen/arch/x86/extable.c search_one_table(const struct exception_table_entry *first, · line 88
Quoted 10 lines · Konrad Rzeszutek Wilk
xen/arch/x86/extable.c +4
-2@@ -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); +const struct virtual_region *region =find_text_region (addr); + +if ( region && region->ex ) +return search_one_table (region->ex, region->ex_end-1 , addr);
As you are moving the line, style for "end - 1".
xen/common/virtual_region.c line 96
Quoted 9 lines
xen/common/virtual_region.c new file +9
-0+void unregister_virtual_region (struct virtual_region *r) +{ +/* Expected to be called from xSplice - which has IRQs disabled. */ +ASSERT (!local_irq_is_enabled ()); + +remove_virtual_region (r); +} + +void unregister_init_virtual_region (void )
__init
Quoted 12 lines
xen/include/xen/virtual_region.h new file +6
-0@@ -0,0 +1,47 @@ +/* +* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. +* +*/ + +#ifndef __XEN_VIRTUAL_REGION__
xen/include/xen/virtual_region.h line 16
Quoted 10 lines
xen/include/xen/virtual_region.h new file +10
-0+#define __XEN_VIRTUAL_REGION__ + +#include <xen/list.h> +#include <xen/symbols.h> + +struct virtual_region +{ +struct list_head list; +unsigned long start;/* Virtual address start. */ +unsigned long end;/* Virtual address start. */
Both start eh?
No major issues. Once fixed, Reviewed-by: Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 05/24] arm/x86: Use struct virtual_region to do bug, symbol, and (x86) exception tables lookup.
In reply to Konrad Rzeszutek WilkHi Konrad,
Quoted 5 lines · 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.
Quoted 7 lines
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
NIT: s/mechansim/mechanism/
Quoted 15 lines
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' andvirtual_region_listprovide a mechanism to search for thebug_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_framesand exception table entries search has to only use two public APIs:
-register_virtual_region
-unregister_virtual_region
Quoted 7 lines
to let the core code know.
If the ->lookup_symbol is not then the default internal symbol lookup mechanism is used.
Suggested-by Andrew Cooper <[email protected]>Signed-off-by Konrad Rzeszutek Wilk <[email protected]>
For the ARM parts:
Regards,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH v6 6/24 x86: Alter nmi_callback_t typedef
In reply to Konrad Rzeszutek WilkDrop paranthesis and function pointer on nmi_callback_t typedef.
Make it more inline with how x86 maintainers want function typedefs to be.
---
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Tim Deegan <[email protected]>
v6: New in patchset.
---
--- xen/arch/x86/alternative.c | 2 +- xen/arch/x86/traps.c | 6 +++--- xen/include/asm-x86/nmi.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-)
xen/arch/x86/alternative.c +1 -1
@@ -192,7 +192,7 @@ static void __init apply_alternatives(struct alt_instr *start, struct alt_instrvoid __init alternative_instructions (void ) { -nmi_callback_t saved_nmi_callback; +nmi_callback_t *saved_nmi_callback;arch_init_ideal_nops ();
xen/arch/x86/traps.c +3 -3
@@ -3523,7 +3523,7 @@ static int dummy_nmi_callback(const struct cpu_user_regs *regs, int cpu)return 0 ; } -static nmi_callback_t nmi_callback = dummy_nmi_callback; +static nmi_callback_t *nmi_callback = dummy_nmi_callback;void do_nmi (const struct cpu_user_regs *regs) {
@@ -3553,9 +3553,9 @@ void do_nmi(const struct cpu_user_regs *regs) } } -nmi_callback_t set_nmi_callback (nmi_callback_t callback) +nmi_callback_t *set_nmi_callback (nmi_callback_t *callback) { -nmi_callback_t old_nmi_callback = nmi_callback; +nmi_callback_t *old_nmi_callback = nmi_callback; nmi_callback = callback;
xen/include/asm-x86/nmi.h +2 -2
@@ -12,7 +12,7 @@ extern bool_t opt_watchdog;/* Watchdog force parameter from the command line */ extern bool_t watchdog_force; -typedef int (*nmi_callback_t )(const struct cpu_user_regs *regs,int cpu); +typedef int nmi_callback_t (const struct cpu_user_regs *regs,int cpu);/** * set_nmi_callback
@@ -20,7 +20,7 @@ typedef int (*nmi_callback_t)(const struct cpu_user_regs *regs, int cpu);* Set a handler for an NMI. Only one handler may be * set. Return the old nmi callback handler. */ -nmi_callback_t set_nmi_callback (nmi_callback_t callback); +nmi_callback_t *set_nmi_callback (nmi_callback_t *callback);/** * unset_nmi_callback
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v6 06/24] x86: Alter nmi_callback_t typedef
Konrad Rzeszutek Wilk writes ("[PATCH v6 06/24] x86: Alter nmi_callback_t typedef"):
Quoted 4 lines
Drop paranthesis and function pointer on
nmi_callback_ttypedef.Make it more inline with how x86 maintainers want function typedefs to be.
I have no opinion on this patch. I guess it was CC'd to me due to some quirk of the way MAINTAINERS works.
IMO it needs an ack from the x86 maintainers (only).
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 06/24] x86: Alter nmi_callback_t typedef
In reply to Konrad Rzeszutek WilkQuoted 6 lines · Konrad Rzeszutek Wilk
Drop paranthesis and function pointer on
nmi_callback_ttypedef.Make it more inline with how x86 maintainers want function typedefs to be.
Signed-off-by Konrad Rzeszutek Wilk <[email protected]>
I don't see the point, but this doesn't introduce any problems.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 06/24] x86: Alter nmi_callback_t typedef
Quoted 9 lines · Andrew Cooper
Quoted 6 lines · Konrad Rzeszutek Wilk
Drop paranthesis and function pointer on
nmi_callback_ttypedef.Make it more inline with how x86 maintainers want function typedefs to be.
Signed-off-by Konrad Rzeszutek Wilk <[email protected]>I don't see the point, but this doesn't introduce any problems.
Jan (on my patches) noticied that I had added a lot of function pointers on the typedefs and wanted it to be dropped.
Since I am going to use one of these typedefs I figured I would preempt his keenly sense and have the typedef already worked out.
Quoted 2 lines
Acked-by Andrew Cooper <[email protected]>
Oh, and it can go in now!
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v6 7/24 arm/x86/vmap: Add vmalloc_type and vm_init_type
In reply to Konrad Rzeszutek WilkFor those users who want to use the virtual addresses that are in the hypervisor's virtual address space - these two new functions allow 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) Any provided virtual address space (need start and end).
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 vm_init_type to initalize and the vmalloc_type to utilize it.
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
We also add add extra 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]>
Cc: Stefano Stabellini <[email protected]>
Cc: Julien Grall <[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. Require users of alternative virtual address to call vmap_init_type first.
---
--- xen/arch/arm/kernel.c | 2 +- xen/arch/arm/mm.c | 2 +- xen/arch/x86/mm.c | 2 +- xen/common/vmap.c | 160 ++++++++++++++++++++++++++++--------------------- xen/drivers/acpi/osl.c | 2 +- xen/include/xen/vmap.h | 47 ++++++++++++--- 6 files changed, 134 insertions(+), 81 deletions(-)
xen/arch/arm/kernel.c +1 -1
@@ -299,7 +299,7 @@ static __init int kernel_decompress(struct bootmodule *mod)return -ENOMEM ; } mfn =_mfn (page_to_mfn (pages)); - output =__vmap (&mfn,1 << kernel_order_out,1 ,1 ,PAGE_HYPERVISOR ); + output =__vmap (&mfn,1 << kernel_order_out,1 ,1 ,PAGE_HYPERVISOR ,VMAP_DEFAULT ); rc =perform_gunzip (output, input, size);clean_dcache_va_range (output, output_size);
xen/arch/arm/mm.c +1 -1
@@ -804,7 +804,7 @@ void *ioremap_attr(paddr_t pa, size_t len, unsigned int attributes)mfn_t mfn =_mfn (PFN_DOWN (pa));unsigned int offs = pa & (PAGE_SIZE -1 );unsigned int nr =PFN_UP (offs + len); -void *ptr =__vmap (&mfn, nr,1 ,1 , attributes); +void *ptr =__vmap (&mfn, nr,1 ,1 , attributes,VMAP_DEFAULT );if ( ptr ==NULL )return NULL ;
xen/arch/x86/mm.c +1 -1
@@ -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_DEFAULT ) + offs; }return (void __force __iomem *)va;
xen/common/vmap.c +91 -69
323 lines not on this page · raw message
xen/drivers/acpi/osl.c +1 -1
@@ -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_DEFAULT ) + offs; }return __acpi_map_table (phys, size); }
xen/include/xen/vmap.h +39 -8
65 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
Re: [PATCH v6 07/24] arm/x86/vmap: Add vmalloc_type and vm_init_type
Quoted 41 lines · Konrad Rzeszutek Wilk
For those users who want to use the virtual addresses that are in the hypervisor's virtual address space - these two new functions allow 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) Any provided virtual address space (need start and end).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
vm_init_typeto initalize and thevmalloc_typeto utilize it.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
We also add add extra checks in case the b) range has not been initialized.
Signed-off-by Konrad Rzeszutek Wilk <[email protected]>Suggested-by Jan Beulich <[email protected]>---
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Julien Grall <[email protected]>
Quoted 7 lines
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 thevmalloc_range. Require users of alternative virtual address to callvmap_init_typefirst.
(For anyone else wishing to review this, git diff --color-words makes it a far easier job)
This is definitely an improvement over previous versions, and in principle looks fine, with moderate issue.
xen/include/xen/vmap.h line 11
Quoted 13 lines
xen/include/xen/vmap.h +5
-0@@ -4,16 +4,44 @@#include <xen/mm.h> #include <asm/page.h> +enum vmap_type { +VMAP_DEFAULT , +VMAP_XEN , + VMAP_nr, +};
These really arn't types of vmap. They are just different regions to try and use; the underlying infrastructure is still all the same.
I would recommend "enum vmap_region" instead, as well as VMAP_REGION_NR to avoid having a mixed-case constant.
xen/include/xen/vmap.h line 17
Quoted 6 lines
xen/include/xen/vmap.h +6
-0+ +void vm_free_type (const void *,enum vmap_type ); +void vunmap_type (const void *,enum vmap_type ); +void *vmalloc_type (size_t size,enum vmap_type type,mfn_t **mfn_array); +void vm_init_type (enum vmap_type type,void *start,void *end); +void vfree_type (void *va,enum vmap_type type);
Exposing the type (/region) parameter is quite unsafe, when mixed with the va. What happens if someone passes in a va for one region, with a VMAP_$other ?
How likely are we to gain a 3rd region? My gut feeling is that it would be safer to hide all of the type/region bits in vmap.c (other than perhaps the _init() calls), and expose $VMAP_FOO_xen() functions in the API.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 07/24] arm/x86/vmap: Add vmalloc_type and vm_init_type
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 08.04.16 at 16:22, <[email protected]> wrote:
xen/include/xen/vmap.h line 17
Quoted 5 lines · Konrad Rzeszutek Wilk
xen/include/xen/vmap.h +5
-0+void vm_free_type (const void *,enum vmap_type ); +void vunmap_type (const void *,enum vmap_type ); +void *vmalloc_type (size_t size,enum vmap_type type,mfn_t **mfn_array); +void vm_init_type (enum vmap_type type,void *start,void *end); +void vfree_type (void *va,enum vmap_type type);Exposing the type (/region) parameter is quite unsafe, when mixed with the va. What happens if someone passes in a va for one region, with a VMAP_$other ?
Good point, and the type can really be inferred from the VA. Just that how this got done originally was a little unclean for my taste.
Quoted 3 lines
How likely are we to gain a 3rd region? My gut feeling is that it would be safer to hide all of the type/region bits in
vmap.c(other than perhaps the_init()calls), and expose $VMAP_FOO_xen() functions in the API.
Well, while I can't give a concrete example, I do think that it's not that unlikely for there to appear a 3rd region at some point.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 07/24] arm/x86/vmap: Add vmalloc_type and vm_init_type
Quoted 12 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 08.04.16 at 16:22, <[email protected]> wrote:
xen/include/xen/vmap.h line 17
Quoted 5 lines · Konrad Rzeszutek Wilk
xen/include/xen/vmap.h +5
-0+void vm_free_type (const void *,enum vmap_type ); +void vunmap_type (const void *,enum vmap_type ); +void *vmalloc_type (size_t size,enum vmap_type type,mfn_t **mfn_array); +void vm_init_type (enum vmap_type type,void *start,void *end); +void vfree_type (void *va,enum vmap_type type);Exposing the type (/region) parameter is quite unsafe, when mixed with the va. What happens if someone passes in a va for one region, with a VMAP_$other ?
Quoted 2 lines
Good point, and the type can really be inferred from the VA. Just that how this got done originally was a little unclean for my taste.
OK, then let just expose the vmalloc_xen, and vfree_xen along with vmap_init_type.
The rest will be part of the vmalloc.c file.
Albeit I will leave __vmap with the type..
Quoted 10 lines
Quoted 4 lines
How likely are we to gain a 3rd region? My gut feeling is that it would be safer to hide all of the type/region bits in
vmap.c(other than perhaps the_init()calls), and expose $VMAP_FOO_xen() functions in the API.Well, while I can't give a concrete example, I do think that it's not that unlikely for there to appear a 3rd region at some point.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 07/24] arm/x86/vmap: Add vmalloc_type and vm_init_type
In reply to Konrad Rzeszutek WilkHi Konrad,
Quoted 10 lines · Konrad Rzeszutek Wilk
For those users who want to use the virtual addresses that are in the hypervisor's virtual address space - these two new functions allow 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) Any provided virtual address space (need start and end).
Quoted 5 lines
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
vm_init_typeto initalize and thevmalloc_typeto utilize it.
NIT: s/initalize/initialize/
Quoted 7 lines
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.
Quoted 6 lines
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
NIT: Missing full stop.
Quoted 5 lines
We also add add extra checks in case the b) range has not been initialized.
Signed-off-by Konrad Rzeszutek Wilk <[email protected]>Suggested-by Jan Beulich <[email protected]>
For the ARM parts:
Regards,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH v6 8/24 xsplice: Add helper elf routines
In reply to Konrad Rzeszutek WilkFrom: 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.
v6: Squash the ELF header checks from 'xsplice: Implement payload loading' here,
Do better job at checking string sections and the users of them (sh_size), Use XSPLICE as a string literal,
Move some checks outside the loop,
Make sure that SHT_STRTAB are really what they say
Sprinkle consts.
---
--- xen/common/Makefile | 1 + xen/common/xsplice_elf.c | 348 ++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/xsplice.h | 3 + xen/include/xen/xsplice_elf.h | 51 +++++++ 4 files changed, 403 insertions(+) create mode 100644 xen/common/xsplice_elf.c create mode 100644 xen/include/xen/xsplice_elf.h
xen/common/Makefile +1 -0
@@ -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 +348 -0
348 lines not on this page · raw message
xen/include/xen/xsplice.h +3 -0
@@ -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
Re: [PATCH v6 08/24] xsplice: Add helper elf routines
Konrad Rzeszutek Wilk writes ("[PATCH v6 08/24] xsplice: Add helper elf routines"):
Quoted 5 lines
From: Ross Lagerwall <[email protected]>
Add Elf routines and data structures in preparation for loading an xSplice payload.
Quoted 7 lines
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.
This is good, but: ideally I would like to avoid conducting a detailed security review of this code.
My understanding of this is that the purpose of this machinery is to supply binary runtime patches to the hypervisor. So I think someone who can inject malicious xsplice payloads can already control the host. Is that right ?
If so then bugs in this loader cannot be any security impact.
It might be worth mentioning somewhere that this loader must not be used for xsplice payloads for guest kernels.
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 08/24] xsplice: Add helper elf routines
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 07.04.16 at 18:19, <[email protected]> wrote:
Konrad Rzeszutek Wilk writes ("[PATCH v6 08/24] xsplice: Add helper elf routines"):
Quoted 5 lines
From: Ross Lagerwall <[email protected]>
Add Elf routines and data structures in preparation for loading an xSplice payload.
Quoted 7 lines
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.
This is good, but: ideally I would like to avoid conducting a detailed security review of this code.
Quoted 6 lines
My understanding of this is that the purpose of this machinery is to supply binary runtime patches to the hypervisor. So I think someone who can inject malicious xsplice payloads can already control the host. Is that right ?
If so then bugs in this loader cannot be any security impact.
Well, in a way this depends on re-visiting the position we take related to heavy disaggregation, which I mean to put up as a subject on the hackathon.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 08/24] xsplice: Add helper elf routines
In reply to Ian JacksonQuoted 13 lines · Ian Jackson
Konrad Rzeszutek Wilk writes ("[PATCH v6 08/24] xsplice: Add helper elf routines"):
Quoted 5 lines
From: Ross Lagerwall <[email protected]>
Add Elf routines and data structures in preparation for loading an xSplice payload.
Quoted 7 lines
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.
Quoted 7 lines
This is good, but: ideally I would like to avoid conducting a detailed security review of this code.
My understanding of this is that the purpose of this machinery is to supply binary runtime patches to the hypervisor. So I think someone who can inject malicious xsplice payloads can already control the host. Is that right ?
Correct.
Quoted 2 lines
If so then bugs in this loader cannot be any security impact.
I agree.
The reason for the checks is so Xen doesn't accidentally fall over a malformed ELF. Earlier versions of this patch were a bit too lax in trusting the integrity of the ELF image for my liking, which is why I specifically asked for better verification.
Quoted 2 lines
It might be worth mentioning somewhere that this loader must not be used for xsplice payloads for guest kernels.
I don't see how this is related. If the host admin wanted to patch guest kernels without using the kernels internal self-patching mechanism, it would be infinitely easier to do the patching from dom0, using toolstack mapping powers.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Ian Jackson
Acked-byRe: [PATCH v6 08/24] xsplice: Add helper elf routines
Andrew Cooper writes ("Re: [PATCH v6 08/24] xsplice: Add helper elf routines"):
Quoted 7 lines · Ian Jackson
Quoted 4 lines
My understanding of this is that the purpose of this machinery is to supply binary runtime patches to the hypervisor. So I think someone who can inject malicious xsplice payloads can already control the host. Is that right ?
Correct.
OK, good, then from my point of view:
Quoted 7 lines
Quoted 2 lines
It might be worth mentioning somewhere that this loader must not be used for xsplice payloads for guest kernels.
I don't see how this is related. If the host admin wanted to patch guest kernels without using the kernels internal self-patching mechanism, it would be infinitely easier to do the patching from dom0, using toolstack mapping powers.
Well, maybe. I was worried about someone trying to make this ELF xsplice code dynamically patch a guest kernel at load time. That might seem like a convenient idea to them. But if you think it's not likely, then fine.
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 08/24] xsplice: Add helper elf routines
In reply to Ian JacksonQuoted 14 lines · Ian Jackson
Konrad Rzeszutek Wilk writes ("[PATCH v6 08/24] xsplice: Add helper elf routines"):
Quoted 5 lines
From: Ross Lagerwall <[email protected]>
Add Elf routines and data structures in preparation for loading an xSplice payload.
Quoted 7 lines
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.
Quoted 7 lines
This is good, but: ideally I would like to avoid conducting a detailed security review of this code.
My understanding of this is that the purpose of this machinery is to supply binary runtime patches to the hypervisor. So I think someone who can inject malicious xsplice payloads can already control the host. Is that right ?
<nods>The payload could be just fine from an ELF perspective and insert an patch that immediately calls BUG_ON().
Quoted 2 lines
If so then bugs in this loader cannot be any security impact.
Yes.
Quoted 3 lines
It might be worth mentioning somewhere that this loader must not be used for xsplice payloads for guest kernels.
How "fun" would that be! Also I do want signature checking on the payloads so at least we would only load ones that are trusted from a vendor. But that is v2 goal.
Quoted 2 lines
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 08/24] xsplice: Add helper elf routines
In reply to Konrad Rzeszutek WilkQuoted 9 lines · Konrad Rzeszutek Wilk
xen/common/xsplice_elf.c new file +9
-0+static int elf_resolve_sections (struct xsplice_elf *elf,const void *data) +{ +struct xsplice_elf_sec *sec; +unsigned int i; +Elf_Off delta; +int rc; + +/* xsplice_elf_load sanity checked e_shnum. */ + sec = xmalloc_array(struct xsplice_elf_sec, elf->hdr->e_shnum);
xen/common/xsplice_elf.c line 63
Quoted 10 lines
xen/common/xsplice_elf.c new file +10
-0+if ( !sec ) + { + printk(XENLOG_ERR XSPLICE"%s: Could not allocate memory for section table!\n", + elf->name); +return -ENOMEM ; + } + + elf->sec = sec; + + delta = elf->hdr->e_shoff + elf->hdr->e_shnum * elf->hdr->e_shentsize;
Have we verified any of these to be sane yet? (i.e. what about calculation overflow?)
(Edit: e_shnum yes, e_shentsize and e_shoff look to be no)
xen/common/xsplice_elf.c line 69
Quoted 6 lines
xen/common/xsplice_elf.c new file +6
-0+if ( delta >= elf->len ) + { +dprintk (XENLOG_DEBUG ,XSPLICE "%s: Section table is past end of payload!\n" , + elf->name); +return -EINVAL ; + }
(Mis)-alignment
Quoted 11 lines
xen/common/xsplice_elf.c new file +11
-0+static int elf_get_sym (struct xsplice_elf *elf,const void *data) +{ +const 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;
xen/common/xsplice_elf.c line 217
Quoted 10 lines
xen/common/xsplice_elf.c new file +10
-0+ +/* Checked already in elf_resolve_sections, but just in case. */ +ASSERT (offset == strtab_sec->sec->sh_offset); +ASSERT (offset < elf->len && (offset + strtab_sec->sec->sh_size <= elf->len)); + +/* 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;
Has anything checked sh_entsize for being 0 or -1 ?
Being unsigned, -1 cant happen, but nothing checks got being nonzero.
With these things fixed, Reviewed-by: Andrew
Cooper<[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 08/24] xsplice: Add helper elf routines
Quoted 24 lines · Andrew Cooper
Quoted 9 lines · Konrad Rzeszutek Wilk
xen/common/xsplice_elf.c new file +9
-0+static int elf_resolve_sections (struct xsplice_elf *elf,const void *data) +{ +struct xsplice_elf_sec *sec; +unsigned int i; +Elf_Off delta; +int rc; + +/* xsplice_elf_load sanity checked e_shnum. */ + sec = xmalloc_array(struct xsplice_elf_sec, elf->hdr->e_shnum);xen/common/xsplice_elf.c line 63
Quoted 10 lines
xen/common/xsplice_elf.c new file +10
-0+if ( !sec ) + { + printk(XENLOG_ERR XSPLICE"%s: Could not allocate memory for section table!\n", + elf->name); +return -ENOMEM ; + } + + elf->sec = sec; + + delta = elf->hdr->e_shoff + elf->hdr->e_shnum * elf->hdr->e_shentsize;Have we verified any of these to be sane yet? (i.e. what about calculation overflow?)
Quoted 1 line
(Edit:
e_shnumyes,e_shentsizeande_shofflook to be no)
e_shentsize is uint16_te_shoff is uint64_t or uint32_t.
Where you think a check against UINT_MAX/ULONG_MAX for the e_shoff?
Quoted 2 lines
Quoted 2 lines
+ if ( delta >=
elf->len)
This should have been >
As I found out some linkers are happy to place that whole section table at the end of the file. Which means that this checks gets triggered.
Quoted 24 lines
xen/common/xsplice_elf.c line 69
Quoted 5 lines
xen/common/xsplice_elf.c new file +5
-0+ { +dprintk (XENLOG_DEBUG ,XSPLICE "%s: Section table is past end of payload!\n" , + elf->name); +return -EINVAL ; + }(Mis)-alignment
Quoted 15 lines
xen/common/xsplice_elf.c new file +15
-0+static int elf_get_sym (struct xsplice_elf *elf,const void *data) +{ +const 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; + +/* Checked already in elf_resolve_sections, but just in case. */ +ASSERT (offset == strtab_sec->sec->sh_offset); +ASSERT (offset < elf->len && (offset + strtab_sec->sec->sh_size <= elf->len));
Quoted 8 lines
xen/common/xsplice_elf.c line 217
Quoted 6 lines
xen/common/xsplice_elf.c new file +6
-0+ +/* 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;Has anything checked
sh_entsizefor being 0 or -1 ?
Let me double-check.
Quoted 5 lines
Being unsigned, -1 cant happen, but nothing checks got being nonzero.
With these things fixed, Reviewed-by: Andrew
Cooper<[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 08/24] xsplice: Add helper elf routines
Quoted 24 lines · Konrad Rzeszutek Wilk
Quoted 23 lines · Andrew Cooper
Quoted 9 lines · Konrad Rzeszutek Wilk
xen/common/xsplice_elf.c new file +9
-0+static int elf_resolve_sections (struct xsplice_elf *elf,const void *data) +{ +struct xsplice_elf_sec *sec; +unsigned int i; +Elf_Off delta; +int rc; + +/* xsplice_elf_load sanity checked e_shnum. */ + sec = xmalloc_array(struct xsplice_elf_sec, elf->hdr->e_shnum);xen/common/xsplice_elf.c line 63
Quoted 10 lines
xen/common/xsplice_elf.c new file +10
-0+if ( !sec ) + { + printk(XENLOG_ERR XSPLICE"%s: Could not allocate memory for section table!\n", + elf->name); +return -ENOMEM ; + } + + elf->sec = sec; + + delta = elf->hdr->e_shoff + elf->hdr->e_shnum * elf->hdr->e_shentsize;Have we verified any of these to be sane yet? (i.e. what about calculation overflow?)
Quoted 5 lines
Quoted 1 line
(Edit:
e_shnumyes,e_shentsizeande_shofflook to be no)
e_shentsizeisuint16_te_shoffisuint64_toruint32_t.Where you think a check against UINT_MAX/ULONG_MAX for the
e_shoff?
e_shoff needs checking to be within elf->len alone, before a calculation involving e_shoff is checked against elf->len.
Specifically, if it were say (uint64_t)-1 in the elf header, then this calculation would overflow and the check below would pass.
Similarly, something should check e_shentsize against an exact value, given that its size is used to infer the layout of the section header fields.
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
+ if ( delta >=
elf->len)This should have been >
As I found out some linkers are happy to place that whole section table at the end of the file. Which means that this checks gets triggered.
This is normal. Traditionally, program headers live at the start of the image, and section headers at the end.
The spec doesn't enforce this however.
Quoted 30 lines
Quoted 22 lines
xen/common/xsplice_elf.c line 69
Quoted 5 lines
xen/common/xsplice_elf.c new file +5
-0+ { +dprintk (XENLOG_DEBUG ,XSPLICE "%s: Section table is past end of payload!\n" , + elf->name); +return -EINVAL ; + }(Mis)-alignment
Quoted 14 lines
xen/common/xsplice_elf.c new file +14
-0+static int elf_get_sym (struct xsplice_elf *elf,const void *data) +{ +const 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; + +/* Checked already in elf_resolve_sections, but just in case. */ +ASSERT (offset == strtab_sec->sec->sh_offset);Quoted 8 lines
xen/common/xsplice_elf.c line 217
Quoted 7 lines
xen/common/xsplice_elf.c new file +7
-0+ASSERT (offset < elf->len && (offset + strtab_sec->sec->sh_size <= elf->len)); + +/* 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;Has anything checked
sh_entsizefor being 0 or -1 ?
Quoted 1 line
Let me double-check.
Git grep says elf_resolve_sections() has
if ( !elf->symtab->sec->sh_size ||
elf->symtab->sec->sh_entsize < sizeof(Elf_Sym) )
{
dprintk(XENLOG_DEBUG, XSPLICE "%s: Symbol table header is
corrupted!\n",
elf->name);
return -EINVAL;
}I would check for !=, rather than <
Nothing good can come of having sh_entsize being bigger than what we expect an Elf_Sym to be.
Also be aware that Elf_Sym.sh_entsize and Ehdr.e_shentsize appear to be multiple locations containing the same information. I would also cross check them.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 08/24] xsplice: Add helper elf routines
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 09.04.16 at 00:10, <[email protected]> wrote:
Quoted 5 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Andrew Cooper
Quoted 1 line · Konrad Rzeszutek Wilk
+ nsym =
symtab_sec->sec->sh_size/symtab_sec->sec->sh_entsize;Has anything checked
sh_entsizefor being 0 or -1 ?Let me double-check.
Git grep says
elf_resolve_sections()hasif ( !elf->symtab->sec->sh_size || elf->symtab->sec->sh_entsize < sizeof(Elf_Sym) ) { dprintk(XENLOG_DEBUG, XSPLICE "%s: Symbol table header is corrupted!\n", elf->name); return -EINVAL; }
Quoted 4 lines
I would check for !=, rather than <
Nothing good can come of having
sh_entsizebeing bigger than what we expect anElf_Symto be.
The whole purpose of recording the section table entry size is such that the structure could eventually get extended without breaking existing consumers. Hence != is not what the standard suggests to be used.
Quoted 3 lines
Also be aware that Elf_Sym.sh_entsize and Ehdr.e_shentsize appear to be multiple locations containing the same information. I would also cross check them.
You mean Elf_Section.sh_entsize, which has a completely different purpose (see e.g. relocation sections).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v6 9/24 xsplice: Implement payload loading
In reply to Konrad Rzeszutek WilkFrom: 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.
v6: Drop parentheses on typedefs.
- s/an xSplice/a xSplice/
- Rebase on "vmap: Add vmalloc_cb"
- Rebase on "vmap: Add vmalloc_type and vm_init_type"
- s/uint8_t/void/ on load_addr
- Set xsplice_elf on stack without using memset.
---
--- xen/arch/arm/Makefile | 1 + xen/arch/arm/xsplice.c | 55 ++++++++++ xen/arch/x86/Makefile | 1 + xen/arch/x86/xsplice.c | 199 +++++++++++++++++++++++++++++++++++ xen/common/xsplice.c | 238 +++++++++++++++++++++++++++++++++++++++++- xen/common/xsplice_elf.c | 118 +++++++++++++++++++++ xen/include/xen/xsplice.h | 30 ++++++ xen/include/xen/xsplice_elf.h | 5 + 8 files changed, 644 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
@@ -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
@@ -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/xsplice.c new file +199 -0
199 lines not on this page · raw message
xen/common/xsplice.c +235 -3
295 lines not on this page · raw message
xen/common/xsplice_elf.c +118 -0
133 lines not on this page · raw message
xen/include/xen/xsplice.h +30 -0
@@ -6,6 +6,9 @@#ifndef __XEN_XSPLICE_H__#define __XEN_XSPLICE_H__ +struct xsplice_elf ; +struct xsplice_elf_sec ; +struct xsplice_elf_sym ;struct xen_sysctl_xsplice_op ;#ifdef CONFIG_XSPLICE
@@ -15,6 +18,33 @@ struct xen_sysctl_xsplice_op;int xsplice_op (struct xen_sysctl_xsplice_op *); +/* Arch hooks. */ +int arch_xsplice_verify_elf (const struct xsplice_elf *elf); +int arch_xsplice_perform_rel (struct xsplice_elf *elf, +const struct xsplice_elf_sec *base, +const struct xsplice_elf_sec *rela); +int arch_xsplice_perform_rela (struct xsplice_elf *elf, +const struct xsplice_elf_sec *base, +const struct xsplice_elf_sec *rela); +enum va_type { +XSPLICE_VA_RX ,/* .text */ +XSPLICE_VA_RW ,/* .data */ +XSPLICE_VA_RO ,/* .rodata */ +}; + +#include <xen/mm.h> +void *arch_xsplice_alloc_payload (unsigned int pages,mfn_t **mfn); + +/* +* Function to secure the allocate pages (from arch_xsplice_alloc_payload) +* with the right page permissions. +*/ +int arch_xsplice_secure (void *va,unsigned int pages,enum va_type types, +const mfn_t *mfn); + +void arch_xsplice_free_payload (void *va); + +void arch_xsplice_init (void );#else #include <xen/errno.h> /* For -EOPNOTSUPP */
xen/include/xen/xsplice_elf.h +5 -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). */ +void *load_addr;/* A pointer to the allocated destination. +Done by load_payload_data. */ };struct xsplice_elf_sym {
@@ -38,6 +40,9 @@ const struct xsplice_elf_sec *xsplice_elf_sec_by_name(const struct xsplice_elf *int xsplice_elf_load (struct xsplice_elf *elf,const 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
Re: [PATCH v6 09/24] xsplice: Implement payload loading
Quoted 16 lines · Konrad Rzeszutek Wilk
xen/arch/x86/xsplice.c new file +10
-0@@ -0,0 +1,199 @@ +/* +* Copyright (C) 2016 Citrix Systems R&D Ltd. +*/ + +#include <xen/errno.h> +#include <xen/lib.h> +#include <xen/mm.h> +#include <xen/pfn.h> +#include <xen/vmap.h> +#include <xen/xsplice_elf.h>
xen/arch/x86/xsplice.c line 20
Quoted 10 lines
xen/arch/x86/xsplice.c new file +10
-0+#include <xen/xsplice.h> + +int arch_xsplice_verify_elf (const struct xsplice_elf *elf) +{ + +const Elf_Ehdr *hdr = elf->hdr; + +if ( hdr->e_machine !=EM_X86_64 ) + { + printk(XENLOG_ERR XSPLICE "%s: Invalid ELF payload!\n", elf->name);
Would be nicer as "Unsupported ELF Machine type %u".
Quoted 19 lines
xen/arch/x86/xsplice.c new file +19
-0+return -EOPNOTSUPP ; + } + +return 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 ,XSPLICE "%s: SHT_REL relocation unsupported\n" , + elf->name); +return -ENOSYS ; +} + +int arch_xsplice_perform_rela (struct xsplice_elf *elf, +const struct xsplice_elf_sec *base, +const struct xsplice_elf_sec *rela) +{
xen/arch/x86/xsplice.c line 49
Quoted 10 lines
xen/arch/x86/xsplice.c new file +10
-0+const Elf_RelA *r; +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) ) + { +dprintk (XENLOG_DEBUG ,XSPLICE "%s: Section relative header is corrupted!\n" , + elf->name);
XENLOG_ERR surely? (and the other examples).
Quoted 30 lines
xen/arch/x86/xsplice.c new file +30
-0+/* +* Once the resolving symbols, performing relocations, etc is complete +* we secure the memory by putting in the proper page table attributes +* for the desired type. +*/ +int arch_xsplice_secure (void *va,unsigned int pages,enum va_type type, +const mfn_t *mfn) +{ +unsigned long cur; +unsigned long start = (unsigned long )va; +int flag; + +ASSERT (va); +ASSERT (pages); + +if ( type ==XSPLICE_VA_RX ) + flag =PAGE_HYPERVISOR_RX ; +else if ( type ==XSPLICE_VA_RW ) + flag =PAGE_HYPERVISOR_RW ; +else + flag =PAGE_HYPERVISOR_RO ; + +/* +* We could walk the pagetable and do the pagetable manipulations +* (strip the _PAGE_RW), which would mean also not needing the mfn +* array, but there are no generic code for this yet (TODO). +* +* For right now tear down the pagetables and recreate them. +*/ +destroy_xen_mappings (start, start + pages *PAGE_SIZE );
xen/arch/x86/xsplice.c line 170
Quoted 10 lines
xen/arch/x86/xsplice.c new file +10
-0+ +for ( cur = start; pages--; ++mfn, cur +=PAGE_SIZE ) + { +if (map_pages_to_xen (cur,mfn_x (*mfn),1 , flag) ) + { +if ( cur != start ) +destroy_xen_mappings (start, cur); +return -EINVAL ; + } + }
:) Much nicer than before.
Quoted 5 lines
xen/arch/x86/xsplice.c new file +5
-0+ +return 0 ; +} + +void arch_xsplice_free_payload (void *va)
xen/arch/x86/xsplice.c line 185
Quoted 10 lines
xen/arch/x86/xsplice.c new file +10
-0+{ +vfree_type (va,VMAP_XEN ); +} + +void arch_xsplice_init (void ) +{ +void *start, *end; + + start = (void *)xen_virt_end; + end = (void *)(XEN_VIRT_END -NR_CPUS *PAGE_SIZE );
Another TODO for the future. Make a constant to cover the VA space occupied by the per-cpu stubs.
Quoted 9 lines
xen/arch/x86/xsplice.c new file +5
-0@@ -276,6 +374,26 @@ static int xsplice_header_check(const struct xsplice_elf *elf)return -EOPNOTSUPP ; } +if ( !IS_ELF (*hdr) ) + { + printk(XENLOG_ERR XSPLICE "%s: Not an ELF payload!\n", elf->name); +return -EINVAL ; + }
xen/arch/x86/xsplice.c static int xsplice_header_check(const struct xsplice_elf *elf) · line 391
Quoted 10 lines
xen/arch/x86/xsplice.c new file +10
-0+ +if ( hdr->e_ident[EI_CLASS ] !=ELFCLASS64 || + hdr->e_ident[EI_DATA ] !=ELFDATA2LSB || + hdr->e_ident[EI_OSABI ] !=ELFOSABI_SYSV || + hdr->e_type !=ET_REL || + hdr->e_phnum !=0 ) + { + printk(XENLOG_ERR XSPLICE "%s: Invalid ELF payload!\n", elf->name); +return -EOPNOTSUPP ; + }
This hunk up to this point is a rebasing error over the previous patch. These two checks are currently duplicated. (Clearly making doubly sure it is a valid ELF payload ;p).
With these minor bits fixed, Reviewed-by: Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 09/24] xsplice: Implement payload loading
Quoted 8 lines
Quoted 8 lines
xen/arch/x86/xsplice.c new file +8
-0+int arch_xsplice_perform_rela (struct xsplice_elf *elf, +const struct xsplice_elf_sec *base, +const struct xsplice_elf_sec *rela) +{ +const Elf_RelA *r; +unsigned int symndx, i; +uint64_t val; +uint8_t *dest;
Quoted 8 lines
xen/arch/x86/xsplice.c line 49
Quoted 6 lines
xen/arch/x86/xsplice.c new file +6
-0+ +if ( !rela->sec->sh_entsize || !rela->sec->sh_size || + rela->sec->sh_entsize !=sizeof (Elf_RelA) ) + { +dprintk (XENLOG_DEBUG ,XSPLICE "%s: Section relative header is corrupted!\n" , + elf->name);
XENLOG_ERRsurely? (and the other examples).
Yes! I modified all of those that return an error. One of them I made an printk (the one about more than 64 sections).
Quoted 54 lines
Quoted 31 lines
xen/arch/x86/xsplice.c new file +30
-0+/* +* Once the resolving symbols, performing relocations, etc is complete +* we secure the memory by putting in the proper page table attributes +* for the desired type. +*/ +int arch_xsplice_secure (void *va,unsigned int pages,enum va_type type, +const mfn_t *mfn) +{ +unsigned long cur; +unsigned long start = (unsigned long )va; +int flag; + +ASSERT (va); +ASSERT (pages); + +if ( type ==XSPLICE_VA_RX ) + flag =PAGE_HYPERVISOR_RX ; +else if ( type ==XSPLICE_VA_RW ) + flag =PAGE_HYPERVISOR_RW ; +else + flag =PAGE_HYPERVISOR_RO ; + +/* +* We could walk the pagetable and do the pagetable manipulations +* (strip the _PAGE_RW), which would mean also not needing the mfn +* array, but there are no generic code for this yet (TODO). +* +* For right now tear down the pagetables and recreate them. +*/ +destroy_xen_mappings (start, start + pages *PAGE_SIZE );xen/arch/x86/xsplice.c line 170
Quoted 10 lines
xen/arch/x86/xsplice.c new file +10
-0+ +for ( cur = start; pages--; ++mfn, cur +=PAGE_SIZE ) + { +if (map_pages_to_xen (cur,mfn_x (*mfn),1 , flag) ) + { +if ( cur != start ) +destroy_xen_mappings (start, cur); +return -EINVAL ; + } + }:) Much nicer than before.
Quoted 10 lines
xen/arch/x86/xsplice.c new file +10
-0+ +return 0 ; +} + +void arch_xsplice_free_payload (void *va) +{ +vfree_type (va,VMAP_XEN ); +} + +void arch_xsplice_init (void )
Quoted 8 lines
xen/arch/x86/xsplice.c line 185
Quoted 5 lines
xen/arch/x86/xsplice.c new file +5
-0+{ +void *start, *end; + + start = (void *)xen_virt_end; + end = (void *)(XEN_VIRT_END -NR_CPUS *PAGE_SIZE );Another TODO for the future. Make a constant to cover the VA space occupied by the per-cpu stubs.
Wrote it down in my TODO. Thanks.
Quoted 16 lines
Quoted 16 lines
xen/common/xsplice_elf.c +11
-0@@ -276,6 +374,26 @@ static int xsplice_header_check(const struct xsplice_elf *elf)return -EOPNOTSUPP ; } +if ( !IS_ELF (*hdr) ) + { + printk(XENLOG_ERR XSPLICE "%s: Not an ELF payload!\n", elf->name); +return -EINVAL ; + } + +if ( hdr->e_ident[EI_CLASS ] !=ELFCLASS64 || + hdr->e_ident[EI_DATA ] !=ELFDATA2LSB || + hdr->e_ident[EI_OSABI ] !=ELFOSABI_SYSV || + hdr->e_type !=ET_REL || + hdr->e_phnum !=0 )
Quoted 8 lines
xen/arch/x86/xsplice.c line 22
Quoted 4 lines
xen/arch/x86/xsplice.c new file +4
-0+ { + printk(XENLOG_ERR XSPLICE "%s: Invalid ELF payload!\n", elf->name); +return -EOPNOTSUPP ; + }This hunk up to this point is a rebasing error over the previous patch. These two checks are currently duplicated. (Clearly making doubly sure it is a valid ELF payload ;p).
Eww. Thanks for noticing!
Quoted 3 lines
With these minor bits fixed, Reviewed-by: Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 09/24] xsplice: Implement payload loading
Quoted 18 lines
Quoted 9 lines
Quoted 9 lines · On 08.04.16 at 23:10, <[email protected]> wrote:
xen/arch/x86/xsplice.c new file +8
-0+int arch_xsplice_perform_rela (struct xsplice_elf *elf, +const struct xsplice_elf_sec *base, +const struct xsplice_elf_sec *rela) +{ +const Elf_RelA *r; +unsigned int symndx, i; +uint64_t val; +uint8_t *dest;Quoted 8 lines
xen/arch/x86/xsplice.c line 49
Quoted 6 lines
xen/arch/x86/xsplice.c new file +6
-0+ +if ( !rela->sec->sh_entsize || !rela->sec->sh_size || + rela->sec->sh_entsize !=sizeof (Elf_RelA) ) + { +dprintk (XENLOG_DEBUG ,XSPLICE "%s: Section relative header is corrupted!\n" , + elf->name);
XENLOG_ERRsurely? (and the other examples).
Quoted 2 lines
Yes! I modified all of those that return an error. One of them I made an printk (the one about more than 64 sections).
Why would that be any worse than other check failures? I think these log messages should all be issued consistently.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 09/24] xsplice: Implement payload loading
Quoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 17 lines
Quoted 5 lines · On 08.04.16 at 23:10, <[email protected]> wrote:
xen/arch/x86/xsplice.c new file +4
-0+int arch_xsplice_perform_rela (struct xsplice_elf *elf, +const struct xsplice_elf_sec *base, +const struct xsplice_elf_sec *rela) +{xen/arch/x86/xsplice.c line 49
Quoted 10 lines
xen/arch/x86/xsplice.c new file +10
-0+const Elf_RelA *r; +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) ) + { +dprintk (XENLOG_DEBUG ,XSPLICE "%s: Section relative header is corrupted!\n" , + elf->name);
XENLOG_ERRsurely? (and the other examples).
Quoted 5 lines
Quoted 2 lines
Yes! I modified all of those that return an error. One of them I made an printk (the one about more than 64 sections).
Why would that be any worse than other check failures? I think these log messages should all be issued consistently.
OK, so all be printk instead of dprintk?
Quoted 3 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 09/24] xsplice: Implement payload loading
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 09.04.16 at 00:45, <[email protected]> wrote:
Quoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 17 lines
Quoted 5 lines · On 08.04.16 at 23:10, <[email protected]> wrote:
xen/arch/x86/xsplice.c new file +4
-0+int arch_xsplice_perform_rela (struct xsplice_elf *elf, +const struct xsplice_elf_sec *base, +const struct xsplice_elf_sec *rela) +{xen/arch/x86/xsplice.c line 49
Quoted 10 lines
xen/arch/x86/xsplice.c new file +10
-0+const Elf_RelA *r; +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) ) + { +dprintk (XENLOG_DEBUG ,XSPLICE "%s: Section relative header is corrupted!\n" , + elf->name);
XENLOG_ERRsurely? (and the other examples).
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Yes! I modified all of those that return an error. One of them I made an printk (the one about more than 64 sections).
Why would that be any worse than other check failures? I think these log messages should all be issued consistently.
OK, so all be printk instead of dprintk?
Rather the other way around I would say.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 09/24] xsplice: Implement payload loading
Quoted 23 lines · Jan Beulich
Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 09.04.16 at 00:45, <[email protected]> wrote:
Quoted 21 lines · Jan Beulich
Quoted 20 lines
Quoted 9 lines
Quoted 9 lines · On 08.04.16 at 23:10, <[email protected]> wrote:
xen/arch/x86/xsplice.c new file +8
-0+int arch_xsplice_perform_rela (struct xsplice_elf *elf, +const struct xsplice_elf_sec *base, +const struct xsplice_elf_sec *rela) +{ +const Elf_RelA *r; +unsigned int symndx, i; +uint64_t val; +uint8_t *dest;Quoted 8 lines
xen/arch/x86/xsplice.c line 49
Quoted 6 lines
xen/arch/x86/xsplice.c new file +6
-0+ +if ( !rela->sec->sh_entsize || !rela->sec->sh_size || + rela->sec->sh_entsize !=sizeof (Elf_RelA) ) + { +dprintk (XENLOG_DEBUG ,XSPLICE "%s: Section relative header is corrupted!\n" , + elf->name);
XENLOG_ERRsurely? (and the other examples).Yes! I modified all of those that return an error. One of them I made an printk (the one about more than 64 sections).
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Why would that be any worse than other check failures? I think these log messages should all be issued consistently.
OK, so all be printk instead of dprintk?
Rather the other way around I would say.
Back to dprintk(XENLOG_DEBUG for all of them then.
Quoted 3 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 09/24] xsplice: Implement payload loading
Quoted 24 lines · Konrad Rzeszutek Wilk
Quoted 23 lines · Jan Beulich
Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 09.04.16 at 00:45, <[email protected]> wrote:
Quoted 21 lines · Jan Beulich
Quoted 20 lines
Quoted 9 lines
Quoted 9 lines · On 08.04.16 at 23:10, <[email protected]> wrote:
(quoted diff) +8
-0+int arch_xsplice_perform_rela(struct xsplice_elf *elf, + const struct xsplice_elf_sec *base, + const struct xsplice_elf_sec *rela) +{ + const Elf_RelA *r; + unsigned int symndx, i; + uint64_t val; + uint8_t *dest;Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ + if ( !rela->sec->sh_entsize || !rela->sec->sh_size || + rela->sec->sh_entsize != sizeof(Elf_RelA) ) + { + dprintk(XENLOG_DEBUG, XSPLICE "%s: Section relative header is corrupted!\n", + elf->name);
XENLOG_ERRsurely? (and the other examples).Yes! I modified all of those that return an error. One of them I made an printk (the one about more than 64 sections).
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Why would that be any worse than other check failures? I think these log messages should all be issued consistently.
OK, so all be printk instead of dprintk?
Rather the other way around I would say.
Back to dprintk(XENLOG_DEBUG for all of them then.
The one question I have is - what shall we do in the field? Where the hypervisor is not built with debug=y and all the dprintk are gone. Some of these would be beneficial to the consumer (like the corruptions)?
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 09/24] xsplice: Implement payload loading
In reply to Konrad Rzeszutek WilkQuoted 25 lines
Quoted 1 line
Quoted 1 line · On 09.04.16 at 02:37, <[email protected]> wrote:
Quoted 23 lines · Jan Beulich
Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 09.04.16 at 00:45, <[email protected]> wrote:
Quoted 21 lines · Jan Beulich
Quoted 20 lines
Quoted 9 lines
Quoted 9 lines · On 08.04.16 at 23:10, <[email protected]> wrote:
(quoted diff) +8
-0+int arch_xsplice_perform_rela(struct xsplice_elf *elf, + const struct xsplice_elf_sec *base, + const struct xsplice_elf_sec *rela) +{ + const Elf_RelA *r; + unsigned int symndx, i; + uint64_t val; + uint8_t *dest;Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ + if ( !rela->sec->sh_entsize || !rela->sec->sh_size || + rela->sec->sh_entsize != sizeof(Elf_RelA) ) + { + dprintk(XENLOG_DEBUG, XSPLICE "%s: Section relative header is corrupted!\n", + elf->name);
XENLOG_ERRsurely? (and the other examples).Yes! I modified all of those that return an error. One of them I made an printk (the one about more than 64 sections).
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Why would that be any worse than other check failures? I think these log messages should all be issued consistently.
OK, so all be printk instead of dprintk?
Rather the other way around I would say.
Back to dprintk(XENLOG_DEBUG for all of them then.
I don't see why dprintk() can't be used with log levels other than debug, as suggested by (I think) Andrew above.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 09/24] xsplice: Implement payload loading
Quoted 28 lines · Jan Beulich
Quoted 28 lines
Quoted 1 line
Quoted 1 line · On 09.04.16 at 02:37, <[email protected]> wrote:
Quoted 26 lines · Jan Beulich
Quoted 26 lines
Quoted 1 line
Quoted 1 line · On 09.04.16 at 00:45, <[email protected]> wrote:
Quoted 23 lines · Jan Beulich
Quoted 18 lines
Quoted 9 lines
Quoted 9 lines · On 08.04.16 at 23:10, <[email protected]> wrote:
(quoted diff) +8
-0+int arch_xsplice_perform_rela(struct xsplice_elf *elf, + const struct xsplice_elf_sec *base, + const struct xsplice_elf_sec *rela) +{ + const Elf_RelA *r; + unsigned int symndx, i; + uint64_t val; + uint8_t *dest;Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ + if ( !rela->sec->sh_entsize || !rela->sec->sh_size || + rela->sec->sh_entsize != sizeof(Elf_RelA) ) + { + dprintk(XENLOG_DEBUG, XSPLICE "%s: Section relative header is corrupted!\n", + elf->name);
XENLOG_ERRsurely? (and the other examples).Quoted 2 lines
Yes! I modified all of those that return an error. One of them I made an printk (the one about more than 64 sections).
Why would that be any worse than other check failures? I think these log messages should all be issued consistently.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
OK, so all be printk instead of dprintk?
Rather the other way around I would say.
Back to dprintk(XENLOG_DEBUG for all of them then.
I don't see why
dprintk()can't be used with log levels other than debug, as suggested by (I think) Andrew above.
OK, let me make them dprintk(XENLOG_ERROR
Quoted 3 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 09/24] xsplice: Implement payload loading
Quoted 31 lines · Konrad Rzeszutek Wilk
Quoted 30 lines · Jan Beulich
Quoted 30 lines
Quoted 1 line
Quoted 1 line · On 09.04.16 at 02:37, <[email protected]> wrote:
Quoted 28 lines · Jan Beulich
Quoted 27 lines
Quoted 1 line
Quoted 1 line · On 09.04.16 at 00:45, <[email protected]> wrote:
Quoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 17 lines
Quoted 5 lines · On 08.04.16 at 23:10, <[email protected]> wrote:
(quoted diff) +4
-0+int arch_xsplice_perform_rela(struct xsplice_elf *elf, + const struct xsplice_elf_sec *base, + const struct xsplice_elf_sec *rela) +{Review
Quoted 10 lines
(quoted diff) +10
-0+ const Elf_RelA *r; + 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) ) + { + dprintk(XENLOG_DEBUG, XSPLICE "%s: Section relative header is corrupted!\n", + elf->name);
XENLOG_ERRsurely? (and the other examples).Quoted 5 lines
Quoted 2 lines
Yes! I modified all of those that return an error. One of them I made an printk (the one about more than 64 sections).
Why would that be any worse than other check failures? I think these log messages should all be issued consistently.
OK, so all be printk instead of dprintk?
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Rather the other way around I would say.
Back to dprintk(XENLOG_DEBUG for all of them then.
I don't see why
dprintk()can't be used with log levels other than debug, as suggested by (I think) Andrew above.OK, let me make them dprintk(XENLOG_ERROR
I've pretty much modified most of them to that, the exceptions are these:
+ dprintk(XENLOG_DEBUG, XSPLICE "%s: Loaded %s at 0x%p\n",
+ dprintk(XENLOG_DEBUG, XSPLICE "%s: Resolved old address %s => %p\n",
+ dprintk(XENLOG_DEBUG, XSPLICE "%s: Already loaded as %s!\n",
+ dprintk(XENLOG_DEBUG, XSPLICE "%s: new symbol %s\n",
+ dprintk(XENLOG_DEBUG, XSPLICE "%s: overriding symbol %s\n",
+ dprintk(XENLOG_DEBUG, XSPLICE "%s: Applying %u functions.\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: Reverting.\n", data->name); + dprintk(XENLOG_DEBUG, XSPLICE "%s: timeout is %"PRI_stime"ms\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: CPU%u - IPIing the other %u CPUs\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: Undefined symbol resolved: %s => %#"PRIxElfAddr"\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: Absolute symbol: %s => %#"PRIxElfAddr"\n",
+ dprintk(XENLOG_DEBUG, XSPLICE "%s: Symbol resolved: %s => %#"PRIxElfAddr"(%s)\n",
And then these are printk variants:
+ printk(XENLOG_ERR XSPLICE "%s: Overflow in relocation %u in %s for %s!\n",
+ printk(XENLOG_ERR XSPLICE "%s: Unhandled relocation %lu\n",
+ printk(XENLOG_ERR XSPLICE "%s: Could not allocate memory for payload!\n",
+ printk(XENLOG_ERR XSPLICE "%s: %s is missing!\n", + printk(XENLOG_ERR XSPLICE "%s: %s is empty!\n", + printk(XENLOG_ERR XSPLICE "%s: %s was seen more than once!\n",
+ printk(XENLOG_ERR XSPLICE "%s: Could not resolve old address of %s\n",
+ printk(XENLOG_ERR XSPLICE "%s: duplicate new symbol: %s\n",
+ printk(XENLOG_ERR XSPLICE "%s: unable to get cpu_maps lock!\n",
+ printk(XENLOG_ERR XSPLICE "%s: Timed out on %s semaphore %u/%u\n",
+ printk(XENLOG_ERR XSPLICE "%s: CPU%u - unable to get cpu_maps lock!\n",
+ printk(XENLOG_INFO XSPLICE "%s finished %s with rc=%d\n", + printk(XENLOG_INFO XSPLICE ": build-id: %*phN\n", len, binary_id); + printk(XENLOG_ERR XSPLICE"%s: Could not allocate memory for section table!\n", + printk(XENLOG_ERR XSPLICE "%s: Could not allocate memory for symbols\n",
+ printk(XENLOG_ERR XSPLICE "%s: Unexpected common symbol: %s\n",
+ printk(XENLOG_ERR XSPLICE "%s: Unknown symbol: %s\n",
We can change some of those to dprintk if folks want that.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 09/24] xsplice: Implement payload loading
Quoted 79 lines
Quoted 1 line
Quoted 1 line · On 11.04.16 at 18:34, <[email protected]> wrote:
Quoted 5 lines · Konrad Rzeszutek Wilk
Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 09.04.16 at 02:37, <[email protected]> wrote:
Quoted 2 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 09.04.16 at 00:45, <[email protected]> wrote:
On Fri, Apr 08, 2016 at 03:18:09PM -0600, Jan Beulich wrote:
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines · On 08.04.16 at 23:10, <[email protected]> wrote:
(quoted diff) +5
-0+int arch_xsplice_perform_rela(struct xsplice_elf *elf, + const struct xsplice_elf_sec *base, + const struct xsplice_elf_sec *rela) +{ + const Elf_RelA *r;Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Review
Quoted 8 lines
(quoted diff) +8
-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) ) + { + dprintk(XENLOG_DEBUG, XSPLICE "%s: Section relative header iscorrupted!\n",
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
+
elf->name);
XENLOG_ERRsurely? (and the other examples).Yes! I modified all of those that return an error. One of them I made an printk (the one about more than 64 sections).
Why would that be any worse than other check failures? I think these log messages should all be issued consistently.
OK, so all be printk instead of dprintk?
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Rather the other way around I would say.
Back to dprintk(XENLOG_DEBUG for all of them then.
I don't see why
dprintk()can't be used with log levels other than debug, as suggested by (I think) Andrew above.OK, let me make them dprintk(XENLOG_ERROR
I've pretty much modified most of them to that, the exceptions are these:
(quoted diff) +12
-0+ dprintk(XENLOG_DEBUG, XSPLICE "%s: Loaded %s at 0x%p\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: Resolved old address %s => %p\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: Already loaded as %s!\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: new symbol %s\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: overriding symbol %s\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: Applying %u functions.\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: Reverting.\n", data->name); + dprintk(XENLOG_DEBUG, XSPLICE "%s: timeout is %"PRI_stime"ms\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: CPU%u - IPIing the other %u CPUs\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: Undefined symbol resolved: %s => %#"PRIxElfAddr"\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: Absolute symbol: %s => %#"PRIxElfAddr"\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: Symbol resolved: %s => %#"PRIxElfAddr"(%s)\n",And then these are printk variants:
(quoted diff) +17
-0+ printk(XENLOG_ERR XSPLICE "%s: Overflow in relocation %u in %s for %s!\n", + printk(XENLOG_ERR XSPLICE "%s: Unhandled relocation %lu\n", + printk(XENLOG_ERR XSPLICE "%s: Could not allocate memory for payload!\n", + printk(XENLOG_ERR XSPLICE "%s: %s is missing!\n", + printk(XENLOG_ERR XSPLICE "%s: %s is empty!\n", + printk(XENLOG_ERR XSPLICE "%s: %s was seen more than once!\n", + printk(XENLOG_ERR XSPLICE "%s: Could not resolve old address of %s\n", + printk(XENLOG_ERR XSPLICE "%s: duplicate new symbol: %s\n", + printk(XENLOG_ERR XSPLICE "%s: unable to get cpu_maps lock!\n", + printk(XENLOG_ERR XSPLICE "%s: Timed out on %s semaphore %u/%u\n", + printk(XENLOG_ERR XSPLICE "%s: CPU%u - unable to get cpu_maps lock!\n", + printk(XENLOG_INFO XSPLICE "%s finished %s with rc=%d\n", + printk(XENLOG_INFO XSPLICE ": build-id: %*phN\n", len, binary_id); + printk(XENLOG_ERR XSPLICE"%s: Could not allocate memory for section table!\n", + printk(XENLOG_ERR XSPLICE "%s: Could not allocate memory for symbols\n", + printk(XENLOG_ERR XSPLICE "%s: Unexpected common symbol: %s\n", + printk(XENLOG_ERR XSPLICE "%s: Unknown symbol: %s\n",
Quoted 1 line
We can change some of those to dprintk if folks want that.
So as mentioned before I'd again like to ask for consistency: I cannot really see the criteria by which some of these use dprintk() vs printk(). The main aspect here is: If things go severely wrong, will the console be spammed? And the second one: Which of these are really useful in the field?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 09/24] xsplice: Implement payload loading
Quoted 80 lines · Jan Beulich
Quoted 80 lines
Quoted 1 line
Quoted 1 line · On 11.04.16 at 18:34, <[email protected]> wrote:
Quoted 5 lines · Konrad Rzeszutek Wilk
Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 09.04.16 at 02:37, <[email protected]> wrote:
Quoted 2 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 09.04.16 at 00:45, <[email protected]> wrote:
On Fri, Apr 08, 2016 at 03:18:09PM -0600, Jan Beulich wrote:
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines · On 08.04.16 at 23:10, <[email protected]> wrote:
(quoted diff) +5
-0+int arch_xsplice_perform_rela(struct xsplice_elf *elf, + const struct xsplice_elf_sec *base, + const struct xsplice_elf_sec *rela) +{ + const Elf_RelA *r;Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Review
Quoted 8 lines
(quoted diff) +8
-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) ) + { + dprintk(XENLOG_DEBUG, XSPLICE "%s: Section relative header iscorrupted!\n",
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
+
elf->name);
XENLOG_ERRsurely? (and the other examples).Yes! I modified all of those that return an error. One of them I made an printk (the one about more than 64 sections).
Why would that be any worse than other check failures? I think these log messages should all be issued consistently.
OK, so all be printk instead of dprintk?
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Rather the other way around I would say.
Back to dprintk(XENLOG_DEBUG for all of them then.
I don't see why
dprintk()can't be used with log levels other than debug, as suggested by (I think) Andrew above.OK, let me make them dprintk(XENLOG_ERROR
I've pretty much modified most of them to that, the exceptions are these:
(quoted diff) +12
-0+ dprintk(XENLOG_DEBUG, XSPLICE "%s: Loaded %s at 0x%p\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: Resolved old address %s => %p\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: Already loaded as %s!\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: new symbol %s\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: overriding symbol %s\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: Applying %u functions.\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: Reverting.\n", data->name); + dprintk(XENLOG_DEBUG, XSPLICE "%s: timeout is %"PRI_stime"ms\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: CPU%u - IPIing the other %u CPUs\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: Undefined symbol resolved: %s => %#"PRIxElfAddr"\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: Absolute symbol: %s => %#"PRIxElfAddr"\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: Symbol resolved: %s => %#"PRIxElfAddr"(%s)\n",And then these are printk variants:
(quoted diff) +17
-0+ printk(XENLOG_ERR XSPLICE "%s: Overflow in relocation %u in %s for %s!\n", + printk(XENLOG_ERR XSPLICE "%s: Unhandled relocation %lu\n", + printk(XENLOG_ERR XSPLICE "%s: Could not allocate memory for payload!\n", + printk(XENLOG_ERR XSPLICE "%s: %s is missing!\n", + printk(XENLOG_ERR XSPLICE "%s: %s is empty!\n", + printk(XENLOG_ERR XSPLICE "%s: %s was seen more than once!\n", + printk(XENLOG_ERR XSPLICE "%s: Could not resolve old address of %s\n", + printk(XENLOG_ERR XSPLICE "%s: duplicate new symbol: %s\n", + printk(XENLOG_ERR XSPLICE "%s: unable to get cpu_maps lock!\n", + printk(XENLOG_ERR XSPLICE "%s: Timed out on %s semaphore %u/%u\n", + printk(XENLOG_ERR XSPLICE "%s: CPU%u - unable to get cpu_maps lock!\n", + printk(XENLOG_INFO XSPLICE "%s finished %s with rc=%d\n", + printk(XENLOG_INFO XSPLICE ": build-id: %*phN\n", len, binary_id); + printk(XENLOG_ERR XSPLICE"%s: Could not allocate memory for section table!\n", + printk(XENLOG_ERR XSPLICE "%s: Could not allocate memory for symbols\n", + printk(XENLOG_ERR XSPLICE "%s: Unexpected common symbol: %s\n", + printk(XENLOG_ERR XSPLICE "%s: Unknown symbol: %s\n",
Quoted 6 lines
Quoted 1 line
We can change some of those to dprintk if folks want that.
So as mentioned before I'd again like to ask for consistency: I cannot really see the criteria by which some of these use
dprintk()vsprintk(). The main aspect here is: If things go severely wrong, will the console be spammed? And the second one: Which of these
If the system admin continously tried to unload and load the patchset then we certainly would spam.
But the 'loading' is (or ought to) be a single event. The applying or reverting may be done more often.
As such I would say that the operations that are tied to apply/reverting should go through printk - to at least leave breadcrumbs if things fall apart. I would say:
printk(XENLOG_ERR XSPLICE "%s: unable to get cpu_maps lock!\n", printk(XENLOG_ERR XSPLICE "%s: Timed out on %s semaphore %u/%u\n",
printk(XENLOG_ERR XSPLICE "%s: CPU%u - unable to get cpu_maps lock!\n",
printk(XENLOG_INFO XSPLICE "%s finished %s with rc=%d\n", printk(XENLOG_INFO XSPLICE ": build-id: %*phN\n", len, binary_id);
dprintk(XENLOG_DEBUG, XSPLICE "%s: Applying %u functions.\n", dprintk(XENLOG_DEBUG, XSPLICE "%s: Reverting.\n", data->name); dprintk(XENLOG_DEBUG, XSPLICE "%s: timeout is %"PRI_stime"ms\n",
dprintk(XENLOG_DEBUG, XSPLICE "%s: CPU%u - IPIing the other %u CPUs\n",
Should be come printk. And make them INFO (except on errors - they should be ERR).
Then comes the question of payloads loading. In the fields all the dprintk are gone - and that is exactly where the payloads would be used. And that is the only _way_ to actually test the payload. But if you don't have dprintk and something goes wrong you only get -EINVAL.
As such I would think that all of the dprintk that deal with the payload should be made printk. So these:
+ dprintk(XENLOG_ERR, XSPLICE "%s: Unsupported ELF Machine type!\n",
+ dprintk(XENLOG_ERR, XSPLICE "%s: SHT_REL relocation unsupported\n",
+ dprintk(XENLOG_ERR, XSPLICE "%s: Section relative header is corrupted!\n",
+ dprintk(XENLOG_ERR, XSPLICE "%s: Relative entry %u in %s is past end!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Relative symbol wants symbol@%u which is past end!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: No WX sections!\n", elf->name); + dprintk(XENLOG_DEBUG, XSPLICE "%s: Loaded %s at 0x%p\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Wrong size of .xsplice.funcs!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Wrong version (%u). Expected %d!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Address or size fields are zero!\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: Resolved old address %s => %p\n",
+ dprintk(XENLOG_DEBUG, XSPLICE "%s: Already loaded as %s!\n",
+ dprintk(XENLOG_ERR, XSPLICE "%s: Wrong size of .bug_frames.%u!\n",
+ dprintk(XENLOG_ERR, XSPLICE "%s: Wrong size of .alt_instr (exp:%lu vs %lu)!\n",
+ dprintk(XENLOG_ERR, XSPLICE "%s Alt patching outside payload: 0x%lx!\n",
+ dprintk(XENLOG_ERR, XSPLICE "%s: Wrong size of .ex_table (exp:%lu vs %lu)!\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: new symbol %s\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: overriding symbol %s\n",
+ dprintk(XENLOG_ERR, "%s%s: check against %s build-id failed!\n",
+ dprintk(XENLOG_ERR, "%s%s: can't unload. Top is %s!\n",
+ dprintk(XENLOG_ERR, XSPLICE "%s: Section table is past end of payload!\n",
+ dprintk(XENLOG_ERR, XSPLICE "%s: Section [%u] data is past end of payload!\n",
+ dprintk(XENLOG_ERR, XSPLICE "%s: Unsupported multiple symbol tables!\n",
+ dprintk(XENLOG_ERR, XSPLICE "%s: No symbol table found!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Symbol table header is corrupted!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: String table section is corrupted\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Section string table is corrupted\n",
+ dprintk(XENLOG_ERR, XSPLICE "%s: shstrtab [%u] data is past end of payload!\n",
+ dprintk(XENLOG_ERR, XSPLICE "%s: Symbol [%u] data is past end of payload!\n",
+ dprintk(XENLOG_ERR, XSPLICE "%s: Unknown type=%#"PRIx16"\n",
+ dprintk(XENLOG_ERR, XSPLICE "%s: Relative link of %s is incorrect (%d, expected=%d)\n",
+ dprintk(XENLOG_ERR, XSPLICE "%s: Section header is bigger than payload!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Not an ELF payload!\n", elf->name); + dprintk(XENLOG_ERR, XSPLICE "%s: Invalid ELF payload!\n", elf->name); + dprintk(XENLOG_ERR, XSPLICE "%s: Section name idx is undefined!?\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Section name idx (%u) is past end of sections (%u)!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Too many (%u) sections!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Bogus e_shoff!\n", elf->name); + dprintk(XENLOG_ERR, XSPLICE "%s: Section header size is %u! Expected %zu!?\n",
Should be printk.
Which would leave almost no dprintks in the code.
but some of them are chatty.
+ dprintk(XENLOG_DEBUG, XSPLICE "%s: Loaded %s at 0x%p\n",
+ dprintk(XENLOG_DEBUG, XSPLICE "%s: Resolved old address %s => %p\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: new symbol %s\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: overriding symbol %s\n",
+ dprintk(XENLOG_DEBUG, XSPLICE "%s: Symbol resolved: %s => %#"PRIxElfAddr"(%s)\n",
+ dprintk(XENLOG_DEBUG, XSPLICE "%s: Undefined symbol resolved: %s => %#"PRIxElfAddr"\n",
+ dprintk(XENLOG_DEBUG, XSPLICE "%s: Absolute symbol: %s => %#"PRIxElfAddr"\n",
and those could certainly be printk(XENLOG_DEBUG' perhaps? Or leave them as dprintk?
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 09/24] xsplice: Implement payload loading
Quoted 21 lines
Quoted 1 line
Quoted 1 line · On 11.04.16 at 19:08, <[email protected]> wrote:
If the system admin continously tried to unload and load the patchset then we certainly would spam.
But the 'loading' is (or ought to) be a single event. The applying or reverting may be done more often.
As such I would say that the operations that are tied to apply/reverting should go through printk - to at least leave breadcrumbs if things fall apart. I would say:
printk(XENLOG_ERR XSPLICE "%s: unable to get
cpu_mapslock!\n", printk(XENLOG_ERR XSPLICE "%s: Timed out on %s semaphore %u/%u\n",
printk(XENLOG_ERR XSPLICE "%s: CPU%u - unable to getcpu_mapslock!\n",
printk(XENLOG_INFO XSPLICE "%s finished %s with rc=%d\n",printk(XENLOG_INFO XSPLICE ": build-id: %*phN\n", len, binary_id);
dprintk(XENLOG_DEBUG, XSPLICE "%s: Applying %u functions.\n",dprintk(XENLOG_DEBUG, XSPLICE "%s: Reverting.\n", data->name); dprintk(XENLOG_DEBUG, XSPLICE "%s: timeout is %"PRI_stime"ms\n",
dprintk(XENLOG_DEBUG, XSPLICE "%s: CPU%u - IPIing the other %u CPUs\n",
Quoted 2 lines
Should be come printk. And make them INFO (except on errors - they should be ERR).
Especially for the last one I don't see what use this has outside of debugging activities. For the others a primary question is: Can any of these occur more than once for a single operation (hypercall)?
Quoted 48 lines
Then comes the question of payloads loading. In the fields all the dprintk are gone - and that is exactly where the payloads would be used. And that is the only _way_ to actually test the payload. But if you don't have dprintk and something goes wrong you only get
-EINVAL.As such I would think that all of the dprintk that deal with the payload should be made printk. So these:
(quoted diff) +39
-0+ dprintk(XENLOG_ERR, XSPLICE "%s: Unsupported ELF Machine type!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: SHT_REL relocation unsupported\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Section relative header is corrupted!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Relative entry %u in %s is past end!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Relative symbol wants symbol@%u which is past end!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: No WX sections!\n", elf->name); + dprintk(XENLOG_DEBUG, XSPLICE "%s: Loaded %s at 0x%p\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Wrong size of .xsplice.funcs!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Wrong version (%u). Expected %d!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Address or size fields are zero!\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: Resolved old address %s => %p\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: Already loaded as %s!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Wrong size of .bug_frames.%u!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Wrong size of .alt_instr (exp:%lu vs %lu)!\n", + dprintk(XENLOG_ERR, XSPLICE "%s Alt patching outside payload: 0x%lx!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Wrong size of .ex_table (exp:%lu vs %lu)!\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: new symbol %s\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: overriding symbol %s\n", + dprintk(XENLOG_ERR, "%s%s: check against %s build-id failed!\n", + dprintk(XENLOG_ERR, "%s%s: can't unload. Top is %s!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Section table is past end of payload!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Section [%u] data is past end of payload!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Unsupported multiple symbol tables!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: No symbol table found!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Symbol table header is corrupted!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: String table section is corrupted\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Section string table is corrupted\n", + dprintk(XENLOG_ERR, XSPLICE "%s: shstrtab [%u] data is past end of payload!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Symbol [%u] data is past end of payload!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Unknown type=%#"PRIx16"\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Relative link of %s is incorrect (%d, expected=%d)\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Section header is bigger than payload!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Not an ELF payload!\n", elf->name); + dprintk(XENLOG_ERR, XSPLICE "%s: Invalid ELF payload!\n", elf->name); + dprintk(XENLOG_ERR, XSPLICE "%s: Section name idx is undefined!?\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Section name idx (%u) is past end of sections (%u)!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Too many (%u) sections!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Bogus e_shoff!\n", elf->name); + dprintk(XENLOG_ERR, XSPLICE "%s: Section header size is %u! Expected %zu!?\n",
Quoted 1 line
Should be printk.
I disagree - issues with the payload image should be diagnosed using user space tools. I.e. I'd rather question whether many of the above shouldn't go away altogether.
Quoted 12 lines
Which would leave almost no dprintks in the code.
but some of them are chatty.
+ dprintk(XENLOG_DEBUG, XSPLICE "%s: Loaded %s at 0x%p\n",
+ dprintk(XENLOG_DEBUG, XSPLICE "%s: Resolved old address %s => %p\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: new symbol %s\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: overriding symbol %s\n",+ dprintk(XENLOG_DEBUG, XSPLICE "%s: Symbol resolved: %s => %#"PRIxElfAddr"(%s)\n",
(quoted diff) +2
-0+ dprintk(XENLOG_DEBUG, XSPLICE "%s: Undefined symbol resolved: %s => %#"PRIxElfAddr"\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: Absolute symbol: %s => %#"PRIxElfAddr"\n",
Quoted 2 lines
and those could certainly be printk(XENLOG_DEBUG' perhaps? Or leave them as dprintk?
Afaic - leave as many dprintk() as possible.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 09/24] xsplice: Implement payload loading
Quoted 21 lines · Jan Beulich
Quoted 21 lines
Quoted 1 line
Quoted 1 line · On 11.04.16 at 19:08, <[email protected]> wrote:
If the system admin continously tried to unload and load the patchset then we certainly would spam.
But the 'loading' is (or ought to) be a single event. The applying or reverting may be done more often.
As such I would say that the operations that are tied to apply/reverting should go through printk - to at least leave breadcrumbs if things fall apart. I would say:
printk(XENLOG_ERR XSPLICE "%s: unable to get
cpu_mapslock!\n", printk(XENLOG_ERR XSPLICE "%s: Timed out on %s semaphore %u/%u\n",
printk(XENLOG_ERR XSPLICE "%s: CPU%u - unable to getcpu_mapslock!\n",
printk(XENLOG_INFO XSPLICE "%s finished %s with rc=%d\n",printk(XENLOG_INFO XSPLICE ": build-id: %*phN\n", len, binary_id);
dprintk(XENLOG_DEBUG, XSPLICE "%s: Applying %u functions.\n",dprintk(XENLOG_DEBUG, XSPLICE "%s: Reverting.\n", data->name); dprintk(XENLOG_DEBUG, XSPLICE "%s: timeout is %"PRI_stime"ms\n",
dprintk(XENLOG_DEBUG, XSPLICE "%s: CPU%u - IPIing the other %u CPUs\n",
Quoted 5 lines
Quoted 2 lines
Should be come printk. And make them INFO (except on errors - they should be ERR).
Especially for the last one I don't see what use this has outside of debugging activities. For the others a primary question is: Can any
True, last one is very much debug.
Quoted 1 line
of these occur more than once for a single operation (hypercall)?
The apply/replace hypercall can
dprintk(XENLOG_DEBUG, XSPLICE "%s: timeout is %"PRI_stime"ms\n", dprintk(XENLOG_DEBUG, XSPLICE "%s: Applying %u functions.\n",
printk(XENLOG_INFO XSPLICE "%s finished %s with rc=%d\n",
The replace can trigger a lot of "Reverting".. And one "Applying"
The uploading can trigger tons of them if payload is buggy.
The 'get' and 'list' are silent.
Quoted 49 lines
Quoted 49 lines
Then comes the question of payloads loading. In the fields all the dprintk are gone - and that is exactly where the payloads would be used. And that is the only _way_ to actually test the payload. But if you don't have dprintk and something goes wrong you only get
-EINVAL.As such I would think that all of the dprintk that deal with the payload should be made printk. So these:
(quoted diff) +39
-0+ dprintk(XENLOG_ERR, XSPLICE "%s: Unsupported ELF Machine type!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: SHT_REL relocation unsupported\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Section relative header is corrupted!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Relative entry %u in %s is past end!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Relative symbol wants symbol@%u which is past end!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: No WX sections!\n", elf->name); + dprintk(XENLOG_DEBUG, XSPLICE "%s: Loaded %s at 0x%p\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Wrong size of .xsplice.funcs!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Wrong version (%u). Expected %d!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Address or size fields are zero!\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: Resolved old address %s => %p\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: Already loaded as %s!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Wrong size of .bug_frames.%u!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Wrong size of .alt_instr (exp:%lu vs %lu)!\n", + dprintk(XENLOG_ERR, XSPLICE "%s Alt patching outside payload: 0x%lx!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Wrong size of .ex_table (exp:%lu vs %lu)!\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: new symbol %s\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: overriding symbol %s\n", + dprintk(XENLOG_ERR, "%s%s: check against %s build-id failed!\n", + dprintk(XENLOG_ERR, "%s%s: can't unload. Top is %s!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Section table is past end of payload!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Section [%u] data is past end of payload!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Unsupported multiple symbol tables!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: No symbol table found!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Symbol table header is corrupted!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: String table section is corrupted\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Section string table is corrupted\n", + dprintk(XENLOG_ERR, XSPLICE "%s: shstrtab [%u] data is past end of payload!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Symbol [%u] data is past end of payload!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Unknown type=%#"PRIx16"\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Relative link of %s is incorrect (%d, expected=%d)\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Section header is bigger than payload!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Not an ELF payload!\n", elf->name); + dprintk(XENLOG_ERR, XSPLICE "%s: Invalid ELF payload!\n", elf->name); + dprintk(XENLOG_ERR, XSPLICE "%s: Section name idx is undefined!?\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Section name idx (%u) is past end of sections (%u)!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Too many (%u) sections!\n", + dprintk(XENLOG_ERR, XSPLICE "%s: Bogus e_shoff!\n", elf->name); + dprintk(XENLOG_ERR, XSPLICE "%s: Section header size is %u! Expected %zu!?\n",
Quoted 5 lines
Quoted 1 line
Should be printk.
I disagree - issues with the payload image should be diagnosed using user space tools. I.e. I'd rather question whether many of the above shouldn't go away altogether.
Lets wait with the deletion part. They will be useful when doing the ARM part.
So all related to 'upload' should be dprintk.
Quoted 13 lines
Quoted 13 lines
Which would leave almost no dprintks in the code.
but some of them are chatty.
+ dprintk(XENLOG_DEBUG, XSPLICE "%s: Loaded %s at 0x%p\n",
+ dprintk(XENLOG_DEBUG, XSPLICE "%s: Resolved old address %s => %p\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: new symbol %s\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: overriding symbol %s\n",+ dprintk(XENLOG_DEBUG, XSPLICE "%s: Symbol resolved: %s => %#"PRIxElfAddr"(%s)\n",
(quoted diff) +2
-0+ dprintk(XENLOG_DEBUG, XSPLICE "%s: Undefined symbol resolved: %s => %#"PRIxElfAddr"\n", + dprintk(XENLOG_DEBUG, XSPLICE "%s: Absolute symbol: %s => %#"PRIxElfAddr"\n",
Quoted 4 lines
Quoted 2 lines
and those could certainly be printk(XENLOG_DEBUG' perhaps? Or leave them as dprintk?
Afaic - leave as many
dprintk()as possible.
OK, dprintk it is.
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 09/24] xsplice: Implement payload loading
Quoted 38 lines · Konrad Rzeszutek Wilk
Quoted 21 lines · Jan Beulich
Quoted 21 lines
Quoted 1 line
Quoted 1 line · On 11.04.16 at 19:08, <[email protected]> wrote:
If the system admin continously tried to unload and load the patchset then we certainly would spam.
But the 'loading' is (or ought to) be a single event. The applying or reverting may be done more often.
As such I would say that the operations that are tied to apply/reverting should go through printk - to at least leave breadcrumbs if things fall apart. I would say:
printk(XENLOG_ERR XSPLICE "%s: unable to get
cpu_mapslock!\n", printk(XENLOG_ERR XSPLICE "%s: Timed out on %s semaphore %u/%u\n",
printk(XENLOG_ERR XSPLICE "%s: CPU%u - unable to getcpu_mapslock!\n",
printk(XENLOG_INFO XSPLICE "%s finished %s with rc=%d\n",printk(XENLOG_INFO XSPLICE ": build-id: %*phN\n", len, binary_id);
dprintk(XENLOG_DEBUG, XSPLICE "%s: Applying %u functions.\n",dprintk(XENLOG_DEBUG, XSPLICE "%s: Reverting.\n", data->name); dprintk(XENLOG_DEBUG, XSPLICE "%s: timeout is %"PRI_stime"ms\n",
dprintk(XENLOG_DEBUG, XSPLICE "%s: CPU%u - IPIing the other %u CPUs\n",Quoted 5 lines
Quoted 2 lines
Should be come printk. And make them INFO (except on errors - they should be ERR).
Especially for the last one I don't see what use this has outside of debugging activities. For the others a primary question is: Can any
True, last one is very much debug.
Quoted 1 line
of these occur more than once for a single operation (hypercall)?
The apply/replace hypercall can
dprintk(XENLOG_DEBUG, XSPLICE "%s: timeout is %"PRI_stime"ms\n", dprintk(XENLOG_DEBUG, XSPLICE "%s: Applying %u functions.\n",
printk(XENLOG_INFO XSPLICE "%s finished %s with rc=%d\n",
Quoted 5 lines
The replace can trigger a lot of "Reverting".. And one "Applying"
The uploading can trigger tons of them if payload is buggy.
The 'get' and 'list' are silent.
With that in mind the series only has these be printk:
[konrad@char xen]$ git diff origin/staging.. | grep printk | grep -v dprintk | grep XEN > /tmp/z
+ printk(XENLOG_INFO XSPLICE "%s: Applying %u functions.\n",
+ printk(XENLOG_INFO XSPLICE "%s: Reverting.\n", data->name);
+ printk(XENLOG_ERR XSPLICE "%s: unable to get cpu_maps lock!\n",
+ printk(XENLOG_ERR XSPLICE "%s: Timed out on %s semaphore %u/%u\n",
+ printk(XENLOG_ERR XSPLICE "%s: CPU%u - unable to get cpu_maps lock!\n",
+ printk(XENLOG_INFO XSPLICE "%s finished %s with rc=%d\n",
+ printk(XENLOG_INFO XSPLICE ": build-id: %*phN\n", len, binary_id);
while the rest are in dprintk with XENLOG_DEBUG (10), XENLOG_ERR (47) levels.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 09/24] xsplice: Implement payload loading
In reply to Konrad Rzeszutek WilkHi Konrad,
Quoted 16 lines · 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.
Quoted 6 lines
We capitalize on the vmalloc callback API (see patch titled:
"vmap: Addvmalloc_cbandvfree_cb") to allocate a region of memory within the [xen_virt_end,XEN_VIRT_END] for the code.Signed-off-by Ross Lagerwall <[email protected]>Signed-off-by Konrad Rzeszutek Wilk <[email protected]>
For the ARM bits:
Regards,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH v6 10/24 xsplice: Implement support for applying/reverting/replacing patches.
In reply to Konrad Rzeszutek WilkFrom: 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 the reset_stack_and_jump to check for work and execute it if needed (specifically we check an per-cpu flag to make this as quick as possible).
In this way, patches can be applied with all CPUs idle and without stacks. The first CPU to run check_for_xsplice_work() becomes the master and triggers a reschedule softirq to trigger all the other CPUs to enter check_for_xsplice_work() 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. This is not addressed in this patch and is mentioned in the design doc as a further TODO.
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 and that the offsets are correct on both 32 and 64-bit hypervisor (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.
v6: Rebase on "arm/x86: Alter nmi_callback_t typedef"
- Drop the recursive spinlock usage.
- Move NMI callbacks in arch specific.
- Fold the 'check_for_xsplice_work' in reset_stack_and_jump
- Add arch specific check for .xsplice.funcs.
- Seperate external and internal structure of .xsplice.funcs.
- Changed per Jan's review
- Modified the .xsplice.funcs checks
---
--- xen/arch/arm/xsplice.c | 33 +++ xen/arch/x86/domain.c | 2 + xen/arch/x86/xsplice.c | 75 +++++++ xen/common/xsplice.c | 453 +++++++++++++++++++++++++++++++++++++++- xen/include/asm-x86/current.h | 10 +- xen/include/xen/xsplice.h | 42 +++- xen/include/xen/xsplice_patch.h | 25 +++ 7 files changed, 629 insertions(+), 11 deletions(-) create mode 100644 xen/include/xen/xsplice_patch.h
xen/arch/arm/xsplice.c +33 -0
@@ -6,6 +6,39 @@#include <xen/xsplice_elf.h> #include <xen/xsplice.h> +void arch_xsplice_patching_enter (void ) +{ +} + +void arch_xsplice_patching_leave (void ) +{ +} + +int arch_xsplice_verify_func (const struct xsplice_patch_func_internal *func) +{ +return -ENOSYS ; +} + +void arch_xsplice_apply_jmp (struct xsplice_patch_func_internal *func) +{ +} + +void arch_xsplice_revert_jmp (const struct xsplice_patch_func_internal *func) +{ +} + +void arch_xsplice_post_action (void ) +{ +} + +void arch_xsplice_mask (void ) +{ +} + +void arch_xsplice_unmask (void ) +{ +} +int arch_xsplice_verify_elf (const struct xsplice_elf *elf) {return -ENOSYS ;
xen/arch/x86/domain.c +2 -0
@@ -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. */ } }
xen/arch/x86/xsplice.c +75 -0
81 lines not on this page · raw message
xen/common/xsplice.c +444 -9
548 lines not on this page · raw message
xen/include/asm-x86/current.h +9 -1
@@ -86,10 +86,18 @@ static inline struct cpu_info *get_cpu_info(void)unsigned long get_stack_trace_bottom (unsigned long sp);unsigned long get_stack_dump_bottom (unsigned long sp); +#ifdef CONFIG_XSPLICE +# define __CHECK_FOR_XSPLICE_WORK "call check_for_xsplice_work;" +#else +# define __CHECK_FOR_XSPLICE_WORK "" +#endif +#define reset_stack_and_jump (__fn) \ ({ \ __asm__ __volatile__ ( \ - "mov %0,%%"__OP"sp; jmp %c1" \ + "mov %0,%%"__OP"sp;" \ + __CHECK_FOR_XSPLICE_WORK \ + "jmp %c1" \ : : "r" (guest_cpu_user_regs()), "i" (__fn) : "memory" ); \ unreachable(); \ })
xen/include/xen/xsplice.h +41 -1
66 lines not on this page · raw message
xen/include/xen/xsplice_patch.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* Copyright (C) 2016 Citrix Systems R&D Ltd. +*/ + +#ifndef __XEN_XSPLICE_PATCH_H__ +#define __XEN_XSPLICE_PATCH_H__ + +#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. */ +}; + +#endif /* __XEN_XSPLICE_PATCH_H__ */
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v6 10/24] xsplice: Implement support for applying/reverting/replacing patches.
Hi Konrad,
Quoted 34 lines · 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 the
reset_stack_and_jumpto check for work and execute it if needed (specifically we check an per-cpu flag to make this as quick as possible).In this way, patches can be applied with all CPUs idle and without stacks. The first CPU to run
check_for_xsplice_work()becomes the master and triggers a reschedule softirq to trigger all the other CPUs to entercheck_for_xsplice_work()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_nmiand the xSplice internal functions. Patching functions on NMI/MCE path is liable to end in disaster. This is not addressed in this patch and is mentioned in the design doc as a further TODO.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 6 lines
We also add an
BUILD_ONto make sure that the size of the structure of the payload is not inadvertly changed and that the offsets are correct on both 32 and 64-bit hypervisor (ARM32 and ARM64).Signed-off-by Ross Lagerwall <[email protected]>Signed-off-by Konrad Rzeszutek Wilk <[email protected]>
For the ARM bits:
Regards,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v6 10/24] xsplice: Implement support for applying/reverting/replacing patches.
In reply to Konrad Rzeszutek WilkReview
Quoted 2 lines · Konrad Rzeszutek Wilk
(quoted diff) +2
-0+void arch_xsplice_post_action(void) +{
/* Serialise the CPU pipeline. */
Otherwise it makes one wonder what a cpuid instruction has to do with xsplicing.
Quoted 13 lines
xen/common/xsplice.c +2
-0@@ -11,17 +12,29 @@#include <xen/mm.h> #include <xen/sched.h> #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>
xen/common/xsplice.c line 29
Quoted 10 lines
xen/common/xsplice.c +5
-0#include <xen/xsplice.h> +#include <xen/xsplice_patch.h> #include <asm/event.h> #include <public/sysctl.h> +/* +* Protects against payload_list operations and also allows only one +* caller in schedule_work. +*/
This comment looks like it should be part of a previous patch.
Quoted 21 lines
xen/common/xsplice.c +8
-0static DEFINE_SPINLOCK (payload_lock);static LIST_HEAD (payload_list); +/* +* Patches which have been applied. +*/ +static LIST_HEAD (applied_list); +static unsigned int payload_cnt;static unsigned int payload_version =1 ;@@ -37,9 +50,35 @@ struct payload {size_t ro_size;/* .. and its size (if any). */ size_t pages;/* Total pages for [text,rw,ro]_addr */ mfn_t *mfn;/* The MFNs backing these pages. */ +struct list_head applied_list;/* Linked to 'applied_list'. */ +struct xsplice_patch_func_internal *funcs;/* The array of functions to patch. */ +unsigned int nfuncs;/* Nr of functions to patch. */ char name[XEN_XSPLICE_NAME_SIZE ];/* Name of it. */ };
xen/common/xsplice.c struct payload { · line 68
Quoted 10 lines
xen/common/xsplice.c +10
-0+/* Defines an outstanding patching action. */ +struct xsplice_work +{ +atomic_t semaphore;/* Used for rendezvous. */ +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. */ +unsigned int cmd;/* Action request: XSPLICE_ACTION_* */
Alignment.
Quoted 27 lines
xen/common/xsplice.c +27
-0+static int schedule_work (struct payload *data,uint32_t cmd,uint32_t timeout) +{ +unsigned int cpu; + +ASSERT (spin_is_locked (&payload_lock)); + +/* Fail if an operation is already scheduled. */ +if ( xsplice_work.do_work ) +return -EBUSY ; + +if ( !get_cpu_maps () ) + { + printk(XENLOG_ERR XSPLICE "%s: unable to get cpu_maps lock!\n", + data->name); +return -EBUSY ; + } + + xsplice_work.cmd = cmd; + xsplice_work.data = data; + xsplice_work.timeout = timeout ?:MILLISECS (30 ); + +dprintk (XENLOG_DEBUG ,XSPLICE "%s: timeout is %" PRI_stime"ms\n" , + data->name, xsplice_work.timeout /MILLISECS (1 )); + +atomic_set (&xsplice_work.semaphore,-1 ); +atomic_set (&xsplice_work.irq_semaphore,-1 ); +
xen/common/xsplice.c static int xsplice_list(xen_sysctl_xsplice_list_t *list) · line 736
Quoted 10 lines
xen/common/xsplice.c +10
-0+ xsplice_work.ready =0 ; +smp_wmb (); + xsplice_work.do_work =1 ; +smp_wmb (); +/* +* Above smp_wmb() gives us a compiler barrier, as we MUST do this +* after setting the global structure. +*/ +for_each_online_cpu ( cpu ) +per_cpu (work_to_do ,cpu ) =1 ;
This should be in reschedule_fn() to avoid dirtying the cachelines on the current cpu and have them read by other cpus.
xen/common/xsplice.c static int xsplice_list(xen_sysctl_xsplice_list_t *list) · line 745
Quoted 9 lines
xen/common/xsplice.c +9
-0+ +put_cpu_maps (); + +return 0 ; +} + +static void reschedule_fn (void *unused) +{ +smp_mb ();/* Synchronize with setting do_work */
You don't need the barrier here, but you do need...
Quoted 36 lines
xen/common/xsplice.c +36
-0+raise_softirq (SCHEDULE_SOFTIRQ ); +} + +static int xsplice_spin (atomic_t *counter,s_time_t timeout, +unsigned int cpus,const char *s) +{ +int rc =0 ; + +while (atomic_read (counter) != cpus &&NOW () < timeout ) +cpu_relax (); + +/* Log & abort. */ +if (atomic_read (counter) != cpus ) + { + printk(XENLOG_ERR XSPLICE "%s: Timed out on %s semaphore %u/%u\n", + xsplice_work.data->name, s, atomic_read(counter), cpus); + rc = -EBUSY ; + xsplice_work.data->rc = rc; + xsplice_work.do_work =0 ; +smp_wmb (); + } + +return rc; +} + +/* +* The main function which manages the work of quiescing the system and +* patching code. +*/ +void check_for_xsplice_work (void ) +{ +#define ACTION (x) [XSPLICE_ACTION_##x] = #x +static const char *const names[] = { +ACTION (APPLY ), +ACTION (REVERT ), +ACTION (REPLACE ),
xen/common/xsplice.c static int xsplice_list(xen_sysctl_xsplice_list_t *list) · line 791
Quoted 10 lines
xen/common/xsplice.c +10
-0+ }; +unsigned int cpu =smp_processor_id (); +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. */
... an smp_rmb() here.
Quoted 18 lines
xen/common/xsplice.c +18
-0+if ( !xsplice_work.do_work ) + { +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; +unsigned int cpus; + + p = xsplice_work.data; +if ( !get_cpu_maps () ) + { + printk(XENLOG_ERR XSPLICE "%s: CPU%u - unable to get cpu_maps lock!\n",
xen/common/xsplice.c static int xsplice_list(xen_sysctl_xsplice_list_t *list) · line 819
Quoted 10 lines
xen/common/xsplice.c +10
-0+ p->name, cpu); +per_cpu (work_to_do, cpu) =0 ; + xsplice_work.data->rc = -EBUSY ; + xsplice_work.do_work =0 ; +/* +* Do NOT decrement semaphore down - as that may cause the other +* CPU (which may be at this ready to increment it) +* to assume the role of master and then needlessly time out +* out (as do_work is zero). +*/
smp_wmb();
Quoted 76 lines
xen/common/xsplice.c +68
-0+return ; + } +/* "Mask" NMIs. */ +arch_xsplice_mask (); + +barrier ();/* MUST do it after get_cpu_maps. */ + cpus =num_online_cpus () -1 ; + +if ( cpus ) + { +dprintk (XENLOG_DEBUG ,XSPLICE "%s: CPU%u - IPIing the other %u CPUs\n" , + p->name, cpu, cpus); +smp_call_function (reschedule_fn,NULL ,0 ); + } + + timeout = xsplice_work.timeout +NOW (); +if (xsplice_spin (&xsplice_work.semaphore, timeout, cpus,"CPU" ) ) + goto abort; + +/* All CPUs are waiting, now signal to disable IRQs. */ + xsplice_work.ready =1 ; +smp_wmb (); + +atomic_inc (&xsplice_work.irq_semaphore); +if ( !xsplice_spin (&xsplice_work.irq_semaphore, timeout, cpus,"IRQ" ) ) + { +local_irq_save (flags); +/* Do the patching. */ +xsplice_do_action (); +/* Flush the CPU i-cache via CPUID instruction (on x86). */ +arch_xsplice_post_action (); +local_irq_restore (flags); + } +arch_xsplice_unmask (); + + abort: +per_cpu (work_to_do, cpu) =0 ; + xsplice_work.do_work =0 ; + +smp_wmb ();/* MUST complete writes before put_cpu_maps(). */ + +put_cpu_maps (); + + printk(XENLOG_INFO XSPLICE "%s finished %s with rc=%d\n", + p->name, names[xsplice_work.cmd], p->rc); + } +else + { +/* Wait for all CPUs to rendezvous. */ +while ( xsplice_work.do_work && !xsplice_work.ready ) +cpu_relax (); + +/* Disable IRQs and signal. */ +local_irq_save (flags); +atomic_inc (&xsplice_work.irq_semaphore); + +/* Wait for patching to complete. */ +while ( xsplice_work.do_work ) +cpu_relax (); + +/* To flush out pipeline. */ +arch_xsplice_post_action (); +local_irq_restore (flags); + +per_cpu (work_to_do, cpu) =0 ; + } +} +xen/include/xen/xsplice.h +0
-0@@ -11,12 +11,37 @@ struct xsplice_elf_sec;struct xsplice_elf_sym ;struct xen_sysctl_xsplice_op ;
xen/include/xen/xsplice.h struct xsplice_elf_sec; · line 23
Quoted 10 lines
xen/include/xen/xsplice.h +8
-0+#include <xen/elfstructs.h> #ifdef CONFIG_XSPLICE +/* +* 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. We expose +* for the tools the 'struct xsplice_patch_func' which does not have +* platform specific entries.
Shouldn't this be somewhere in the public API then? even if it is explicitly declared as unstable due to xpatches needing to be rebuilt from exact source?
Quoted 10 lines
xen/include/xen/xsplice_patch.h new file +4
-0@@ -0,0 +1,25 @@ +/* +* Copyright (C) 2016 Citrix Systems R&D Ltd. +*/ +
xen/include/xen/xsplice_patch.h line 14
Quoted 10 lines
xen/include/xen/xsplice_patch.h new file +10
-0+#ifndef __XEN_XSPLICE_PATCH_H__ +#define __XEN_XSPLICE_PATCH_H__ + +#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. +*/
Ditto, wrt the public API.
~Andrew
xen/include/xen/xsplice_patch.h line 25
Quoted 11 lines
xen/include/xen/xsplice_patch.h new file +11
-0+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. */ +}; + +#endif /* __XEN_XSPLICE_PATCH_H__ */
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v6 11/24 x86/xen_hello_world.xsplice: Test payload for patching 'xen_extra_version'.
In reply to Konrad Rzeszutek WilkThis 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 extraxen_extra : Hello World
$xen-xsplice revert xen_hello_world
Performing revert: completed
$xen-xsplice unload xen_hello_world
Performing unload: completed
$xl info | grep extraxen_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/
v6: Remove the 'install', and 'uninstall' destinations.
Remove xen/config.h from files.
---
--- .gitignore | 2 ++ docs/misc/xsplice.markdown | 35 +++++++++++++++++++++++++ xen/Makefile | 8 ++++-- xen/arch/arm/Makefile | 2 ++ xen/arch/x86/Makefile | 4 +++ xen/arch/x86/test/Makefile | 44 ++++++++++++++++++++++++++++++++ xen/arch/x86/test/xen_hello_world.c | 30 ++++++++++++++++++++++ xen/arch/x86/test/xen_hello_world_func.c | 22 ++++++++++++++++ 8 files changed, 145 insertions(+), 2 deletions(-) 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
@@ -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 +35 -0
@@ -330,6 +330,41 @@ 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 of .xsplice.funcs + +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 +6 -2
@@ -39,8 +39,8 @@ dist: install build install:: include/config/auto.conf -.PHONY: build install uninstall clean distclean cscope TAGS tags MAP gtags -build install uninstall debug clean distclean cscope TAGS tags MAP gtags:: +.PHONY: build install uninstall clean distclean cscope TAGS tags MAP gtags test +build install uninstall debug clean distclean cscope TAGS tags MAP gtags test:: ifneq ($(XEN_TARGET_ARCH),x86_32) $(MAKE) -f Rules.mk _$@ else
@@ -76,6 +76,10 @@ _install: $(TARGET)$(CONFIG_XEN_INSTALL_SUFFIX) fi; \ fi +.PHONY: _test +_test: + $(MAKE) -f $(BASEDIR)/Rules.mk -C arch/$(TARGET_ARCH) test + .PHONY: _uninstall _uninstall: D=$(DESTDIR) _uninstall: T=$(notdir $(TARGET))
xen/arch/arm/Makefile +2 -0
@@ -57,6 +57,8 @@ ifeq ($(CONFIG_ARM_64),y) ln -sf $(notdir $@) ../../$(notdir $@).efi endif +test: + $(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 +4 -0
@@ -76,6 +76,9 @@ $(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/'` +.PHONY: test +test: + $(MAKE) -f $(BASEDIR)/Rules.mk -C test xsplice ALL_OBJS := $(BASEDIR)/arch/x86/boot/built_in.o $(BASEDIR)/arch/x86/efi/built_in.o $(ALL_OBJS)
@@ -179,3 +182,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 +44 -0
44 lines not on this page · raw message
xen/arch/x86/test/xen_hello_world.c new file +30 -0
@@ -0,0 +1,30 @@ +/* +* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. +* +*/ + +#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 = { + .version = XSPLICE_PAYLOAD_VERSION, + .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 +22 -0
@@ -0,0 +1,22 @@ +/* +* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. +* +*/ + +#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
Re: [PATCH v6 11/24] x86/xen_hello_world.xsplice: Test payload for patching 'xen_extra_version'.
Hi Konrad,
Quoted 45 lines · 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_worldAPPLIED
$xl info | grep extraxen_extra: Hello World
$xen-xsplice revertxen_hello_world
Performing revert: completed
$xen-xsplice unloadxen_hello_world
Performing unload: completed
$xl info | grep extraxen_extra: -unstable
Quoted 1 line
Signed-off-by Konrad Rzeszutek Wilk <[email protected]>
For the ARM bits:
Regards,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v6 11/24] x86/xen_hello_world.xsplice: Test payload for patching 'xen_extra_version'.
In reply to Konrad Rzeszutek WilkQuoted 45 lines · 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_worldAPPLIED
$xl info | grep extraxen_extra: Hello World
$xen-xsplice revertxen_hello_world
Performing revert: completed
$xen-xsplice unloadxen_hello_world
Performing unload: completed
$xl info | grep extraxen_extra: -unstable
Quoted 8 lines
Signed-off-by Konrad Rzeszutek Wilk <[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]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 11/24] x86/xen_hello_world.xsplice: Test payload for patching 'xen_extra_version'.
In reply to Konrad Rzeszutek WilkQuoted 20 lines
docs/misc/xsplice.markdown +12
-0@@ -330,6 +330,41 @@ 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 of .xsplice.funcs + +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;
docs/misc/xsplice.markdown When reverting a patch, the hypervisor iterates over each `xsplice_patch_func` · line 354
Quoted 10 lines
docs/misc/xsplice.markdown +10
-0+ 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";
Which really ought to be 'xen_extra_version' as that is what we are patching.
So changed that, along with:
Quoted 6 lines
xen/arch/x86/test/xen_hello_world.c new file +0
-0
xen/arch/x86/test/xen_hello_world.c line 10
Quoted 10 lines
xen/arch/x86/test/xen_hello_world.c new file +10
-0@@ -0,0 +1,30 @@ +/* +* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. +* +*/ + +#include <xen/types.h> +#include <xen/xsplice.h> +#include "config.h" + +static char xen_hello_world_name[] ="xen_hello_world" ;
This to be 'xen_extra_version' and named the variable 'patch_this_fnc'
It has no bearing on the test-case at all, just a minor cosmetic item hence retained the Reviewed-by.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v6 12/24 xsplice, symbols: Implement symbol name resolution on address.
In reply to Konrad Rzeszutek WilkFrom: 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.
v6: Rebase where the spinlock is no more recursive. Drop the spinlock
usage in xsplice_symbols_lookup_by_name
---
--- xen/arch/x86/Makefile | 16 +++- xen/arch/x86/test/Makefile | 4 +- xen/arch/x86/test/xen_hello_world.c | 5 +- xen/common/symbols.c | 32 ++++++++ xen/common/xsplice.c | 156 +++++++++++++++++++++++++++++++++++- xen/common/xsplice_elf.c | 20 ++++- xen/include/xen/symbols.h | 2 + xen/include/xen/xsplice.h | 8 ++ 8 files changed, 231 insertions(+), 12 deletions(-)
xen/arch/x86/Makefile +12 -4
@@ -72,6 +72,12 @@ efi-y := $(shell if [ ! -r $(BASEDIR)/include/xen/compile.h -o \ -O $(BASEDIR)/include/xen/compile.h ]; then \ echo '$(TARGET).efi'; fi) +ifdef CONFIG_XSPLICE +all_symbols = --all-symbols +else +all_symbols = +endif + $(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/'`
@@ -111,12 +117,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 $@
@@ -140,14 +148,14 @@ $(TARGET).efi: prelink-efi.o efi.lds efi/relocs-dummy.o $(BASEDIR)/common/symbol $(BASEDIR)/common/symbols-dummy.o -o $(@D)/.$(@F).$(base).0 &&) : $(guard) efi/mkreloc $(foreach base,$(VIRT_BASE) $(ALT_BASE),$(@D)/.$(@F).$(base).0) >$(@D)/.$(@F).0r.S $(guard) $(NM) -pa --format=sysv $(@D)/.$(@F).$(VIRT_BASE).0 \ - | $(guard) $(BASEDIR)/tools/symbols --sysv --sort >$(@D)/.$(@F).0s.S + | $(guard) $(BASEDIR)/tools/symbols $(all_symbols) --sysv --sort >$(@D)/.$(@F).0s.S $(guard) $(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).0r.o $(@D)/.$(@F).0s.o $(foreach base, $(VIRT_BASE) $(ALT_BASE), \ $(guard) $(LD) $(call EFI_LDFLAGS,$(base)) -T efi.lds -N $< \ $(@D)/.$(@F).0r.o $(@D)/.$(@F).0s.o -o $(@D)/.$(@F).$(base).1 &&) : $(guard) efi/mkreloc $(foreach base,$(VIRT_BASE) $(ALT_BASE),$(@D)/.$(@F).$(base).1) >$(@D)/.$(@F).1r.S $(guard) $(NM) -pa --format=sysv $(@D)/.$(@F).$(VIRT_BASE).1 \ - | $(guard) $(BASEDIR)/tools/symbols --sysv --sort >$(@D)/.$(@F).1s.S + | $(guard) $(BASEDIR)/tools/symbols $(all_symbols) --sysv --sort >$(@D)/.$(@F).1s.S $(guard) $(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).1r.o $(@D)/.$(@F).1s.o $(guard) $(LD) $(call EFI_LDFLAGS,$(VIRT_BASE)) -T efi.lds -N $< \ $(@D)/.$(@F).1r.o $(@D)/.$(@F).1s.o -o $@
xen/arch/x86/test/Makefile +1 -3
@@ -26,14 +26,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
@@ -10,11 +10,14 @@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 = { .version = XSPLICE_PAYLOAD_VERSION, .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 +32 -0
@@ -207,3 +207,35 @@ int xensyms_read(uint32_t *symnum, char *type,return 0 ; } + +unsigned long symbols_lookup_by_name (const char *symname) +{ +char name[KSYM_NAME_LEN +1 ] = {0 }; +uint32_t symnum; +char type; +uint64_t addr; +int rc; + +do { + + rc =xensyms_read (&symnum, &type, &addr, name); +if ( rc ) +return rc; + +if ( !strcmp (name, symname) ) +return addr; + + }while ( name[0 ] !='\0' ); + +return 0 ; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
xen/common/xsplice.c +155 -1
204 lines not on this page · raw message
xen/common/xsplice_elf.c +17 -3
@@ -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>
@@ -274,9 +275,22 @@ int xsplice_elf_resolve_symbols(struct xsplice_elf *elf)break ;case SHN_UNDEF : - printk(XENLOG_ERR XSPLICE "%s: Unknown symbol: %s\n", - elf->name, elf->sym[i].name); - rc = -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 XSPLICE "%s: Unknown symbol: %s\n", + elf->name, elf->sym[i].name); + rc = -ENOENT ; +break ; + } + } +dprintk (XENLOG_DEBUG ,XSPLICE "%s: Undefined symbol resolved: %s => %#" PRIx64"\n" , + elf->name, elf->sym[i].name, + (uint64_t )elf->sym[i].sym->st_value);break ;case SHN_ABS :
xen/include/xen/symbols.h +2 -0
@@ -23,4 +23,6 @@ const char *symbols_lookup(unsigned long addr,int xensyms_read (uint32_t *symnum,char *type,uint64_t *address,char *name); +unsigned long symbols_lookup_by_name (const char *symname); +#endif /*_XEN_SYMBOLS_H*/
xen/include/xen/xsplice.h +8 -0
@@ -40,8 +40,16 @@ struct xsplice_patch_func_internal {/* Convenience define for printk. */ #define XSPLICE "xsplice: " +struct xsplice_symbol { +const char *name; +uint64_t value; +size_t size; +bool_t new_symbol; +}; +int xsplice_op (struct xen_sysctl_xsplice_op *);void check_for_xsplice_work (void ); +unsigned long xsplice_symbols_lookup_by_name (const char *symname);/* Arch hooks. */ int arch_xsplice_verify_elf (const struct xsplice_elf *elf);
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v6 12/24] xsplice, symbols: Implement symbol name resolution on address.
xen/common/xsplice.c static int prepare_payload(struct payload *payload, · line 429
Quoted 2 lines · Konrad Rzeszutek Wilk
xen/common/xsplice.c +2
-0+static bool_t is_payload_symbol (const struct xsplice_elf *elf, +const struct xsplice_elf_sym *sym)
Just one alignment nit.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v6 13/24 x86, xsplice: Print payload's symbol name and payload name in backtraces
In reply to Konrad Rzeszutek WilkFrom: Ross Lagerwall <[email protected]>
Naturally the backtrace is presented when an instruction hits an bug_frame or %p is used.
The payloads do not support bug_frames yet - however the functions the payloads call could hit an BUG() or WARN().
The traps.c has logic to scan for it this - and eventually it will find the correct bug_frame and the walk the stack using %p to print the backtrace. For %p and symbols to print a string - the 'is_active_kernel_text' is consulted which uses an 'struct virtual_region'.
Therefore we register our start->end addresses so that 'is_active_kernel_text' will include our payload address.
We also register our symbol lookup table function so that it can scan the list of payloads and retrieve the correct name.
Lastly we change vsprintf to take into account s and namebuf. For core code they are the same, but for payloads they are different. This gets us:
Xen call trace:
[<ffff82d080a00041>] revert_hook+0x31/0x35 [xen_hello_world] [<ffff82d0801431bd>] xsplice.c#revert_payload+0x86/0xc6 [<ffff82d080143502>] check_for_xsplice_work+0x233/0x3cd [<ffff82d08017a0b2>] domain.c#continue_idle_domain+0x9/0x1f
Which is great if payloads have similar or same symbol names.
---
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Tim Deegan <[email protected]>
v2: Add missing full stop.
v3: s/module/payload/
v4: Expand comment and include registration of 'virtual_region'
Redo the vsprintf handling of payload name.
Drop the ->skip function
v6: Add comment explaining the purpose behind the strcmp.
Redid per Jan's review.
---
--- xen/common/vsprintf.c | 19 +++++++++++++++-- xen/common/xsplice.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 2 deletions(-)
xen/common/vsprintf.c +17 -2
@@ -20,6 +20,7 @@#include <xen/symbols.h> #include <xen/lib.h> #include <xen/sched.h> +#include <xen/xsplice.h> #include <asm/div64.h> #include <asm/page.h>
@@ -331,16 +332,23 @@ static char *pointer(char *str, char *end, const char **fmt_ptr, {unsigned long sym_size, sym_offset;char namebuf[KSYM_NAME_LEN +1 ]; +bool_t payload =0 ;/* Advance parents fmt string, as we have consumed 's' or 'S' */ ++*fmt_ptr; s =symbols_lookup ((unsigned long )arg, &sym_size, &sym_offset, namebuf); - -/* If the symbol is not found, fall back to printing the address */ +/* If the symbol is not found, fall back to printing the address. */ if ( !s )break ; +/* +* namebuf contents and s for core hypervisor are same but for xSplice +* payloads they differ (namebuf contains the name of the payload). +*/ +if (strncmp (namebuf, s,KSYM_NAME_LEN ) ) + payload =1 ; +/* Print symbol name */ str =string (str, end, s,-1 ,-1 ,0 );
@@ -354,6 +362,13 @@ static char *pointer(char *str, char *end, const char **fmt_ptr, str =number (str, end, sym_size,16 ,-1 ,-1 ,SPECIAL ); } +if ( payload ) + { + str =string (str, end," [" ,-1 ,-1 ,0 ); + str =string (str, end, namebuf,-1 ,-1 ,0 ); + str =string (str, end,"]" ,-1 ,-1 ,0 ); + } +return str; }
xen/common/xsplice.c +59 -0
102 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
Re: [PATCH v6 13/24] x86, xsplice: Print payload's symbol name and payload name in backtraces
Quoted 29 lines · Konrad Rzeszutek Wilk
From: Ross Lagerwall <[email protected]>
Naturally the backtrace is presented when an instruction hits an
bug_frameor %p is used.The payloads do not support
bug_framesyet - however the functions the payloads call could hit anBUG()orWARN().The
traps.chas logic to scan for it this - and eventually it will find the correctbug_frameand the walk the stack using %p to print the backtrace. For %p and symbols to print a string - the 'is_active_kernel_text' is consulted which uses an 'structvirtual_region'.Therefore we register our
start->endaddresses so that 'is_active_kernel_text' will include our payload address.We also register our symbol lookup table function so that it can scan the list of payloads and retrieve the correct name.
Lastly we change vsprintf to take into account s and namebuf. For core code they are the same, but for payloads they are different. This gets us:
Xen call trace:
[<ffff82d080a00041>] revert_hook+0x31/0x35 [xen_hello_world] [<ffff82d0801431bd>] xsplice.c#revert_payload+0x86/0xc6 [<ffff82d080143502>] check_for_xsplice_work+0x233/0x3cd [<ffff82d08017a0b2>] domain.c#continue_idle_domain+0x9/0x1f
Quoted 4 lines
Which is great if payloads have similar or same symbol names.
Signed-off-by Ross Lagerwall <[email protected]>Signed-off-by Konrad Rzeszutek Wilk <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v6 14/24 xsplice: Add support for bug frames.
In reply to Konrad Rzeszutek WilkFrom: Ross Lagerwall <[email protected]>
Add support for handling bug frames contained with xsplice modules. If a trap occurs search either the kernel bug table or an applied payload's bug table depending on the instruction pointer.
---
Cc: Keir Fraser <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
v2:- s/module/payload/
- add build time check in case amount of bug frames expands.
- add define for the number of bug-frames.
v3:
- add missing BUGFRAME_NR, squash s/core_size/core/ in earlier patch.
- Moved code around.
- Changed per Andrew's recommendation.
- Fixed style changes.
- Made it compile under ARM (PRIu32,PRIu64)
v4: Use 'struct virtual_region'
- Rip more of the is_active_text code.
- Use one function for the ->skip
- Include test-case
v5: Rip out the ->skip function.
---
--- xen/arch/x86/traps.c | 5 +++-- xen/common/xsplice.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/xsplice.h | 5 +++++ 3 files changed, 54 insertions(+), 2 deletions(-)
xen/arch/x86/traps.c +3 -2
@@ -50,6 +50,7 @@#include <xen/paging.h> #include <xen/virtual_region.h> #include <xen/watchdog.h> +#include <xen/xsplice.h> #include <asm/system.h> #include <asm/io.h> #include <asm/atomic.h>
@@ -1190,7 +1191,7 @@ void do_invalid_op(struct cpu_user_regs *regs)/* WARN, BUG or ASSERT: decode the filename pointer and line number. */ filename =bug_ptr (bug); -if ( !is_kernel (filename) ) +if ( !is_kernel (filename) && !is_patch (filename) ) goto die; fixup =strlen (filename);if ( fixup >50 )
@@ -1217,7 +1218,7 @@ void do_invalid_op(struct cpu_user_regs *regs)case BUGFRAME_assert:/* ASSERT: decode the predicate string pointer. */ predicate =bug_msg (bug); -if ( !is_kernel (predicate) ) +if ( !is_kernel (predicate) && !is_patch (predicate) ) predicate ="<unknown>" ; printk("Assertion '%s' failed at %s%s:%d\n",
xen/common/xsplice.c +46 -0
58 lines not on this page · raw message
xen/include/xen/xsplice.h +5 -0
@@ -49,6 +49,7 @@ struct xsplice_symbol {int xsplice_op (struct xen_sysctl_xsplice_op *);void check_for_xsplice_work (void ); +bool_t is_patch (const void *addr);unsigned long xsplice_symbols_lookup_by_name (const char *symname);/* Arch hooks. */
@@ -101,6 +102,10 @@ static inline int xsplice_op(struct xen_sysctl_xsplice_op *op)return -EOPNOTSUPP ; }static inline void check_for_xsplice_work (void ) { }; +static inline bool_t is_patch (const void *addr) +{ +return 0 ; +}#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
Re: [PATCH v6 14/24] xsplice: Add support for bug frames.
Quoted 8 lines · Konrad Rzeszutek Wilk
xen/common/xsplice.c +0
-0@@ -124,6 +124,28 @@ static int verify_payload(const xen_sysctl_xsplice_upload_t *upload, char *n)return 0 ; }
xen/common/xsplice.c static int verify_payload(const xen_sysctl_xsplice_upload_t *upload, char *n) · line 136
Quoted 10 lines
xen/common/xsplice.c +10
-0+bool_t is_patch (const void *ptr) +{ +struct payload *data; + +/* +* No locking since this list is only ever changed during apply or revert +* context. +*/ + list_for_each_entry ( data, &applied_list, applied_list ) + {
This needs to include a text check, even if it should have no current users.
Otherwise, Reviewed-by: Andrew Cooper <[email protected]>
Quoted 5 lines
xen/common/xsplice.c +5
-0+if ( ptr >= data->rw_addr && + ptr < (data->rw_addr + data->rw_size) ) +return 1 ; + + if ( ptr >= data->ro_addr &&
xen/common/xsplice.c static int verify_payload(const xen_sysctl_xsplice_upload_t *upload, char *n) · line 151
Quoted 10 lines
xen/common/xsplice.c +7
-0+ ptr < (data->ro_addr + data->ro_size) ) +return 1 ; + } + +return 0 ; +} +unsigned long xsplice_symbols_lookup_by_name (const char *symname) {struct payload *data;
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v6 15/24 xsplice: Add support for exception tables.
In reply to Konrad Rzeszutek WilkFrom: Ross Lagerwall <[email protected]>
Add support for exception tables contained within xSplice payloads. If an exception occurs search either the main exception table or a particular active payload's exception table depending on the instruction pointer.
Also we add an test-case to make sure we have an exception that is handled.
To not grow the code-base if xSplice is not compiled in we add certain #define to help in determining if code needs to be __init or not.
---
Cc: Keir Fraser <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
v3:
- s/module/payload/
- sanity checks.
- Move code around.
- s/module/payload/
v4: Use 'struct virtual_region'
v5:
- Expand test-case.
- Deal with struct exception_table_entry being const.
v6:
- Make the code have __init if not compiled with xSplice
- Remove not needed declarations.
---
--- xen/arch/x86/extable.c | 31 ++++++++++++++++++------------- xen/arch/x86/test/xen_hello_world_func.c | 11 +++++++++++ xen/common/xsplice.c | 25 +++++++++++++++++++++++++ xen/include/asm-x86/uaccess.h | 2 ++ xen/include/xen/xsplice.h | 17 +++++++++++++++++ 5 files changed, 73 insertions(+), 13 deletions(-)
xen/arch/x86/extable.c +18 -13
@@ -7,6 +7,7 @@#include <xen/spinlock.h> #include <asm/uaccess.h> #include <xen/virtual_region.h> +#include <xen/xsplice.h> #define EX_FIELD (ptr, field) ((unsigned long)&(ptr)->field + (ptr)->field)
@@ -20,7 +21,7 @@ static inline unsigned long ex_cont(const struct exception_table_entry *x)return EX_FIELD (x, cont); } -static int __init cmp_ex (const void *a,const void *b) +static int __INIT cmp_ex(const void *a, const void *b) {const struct exception_table_entry *l = a, *r = b;unsigned long lip =ex_addr (l);
@@ -35,7 +36,7 @@ static int __init cmp_ex(const void *a, const void *b) }#ifndef swap_ex -static void __init swap_ex (void *a,void *b,int size) +static void __INIT swap_ex(void *a, void *b, int size) {struct exception_table_entry *l = a, *r = b, tmp;long delta = b - a;
@@ -48,19 +49,23 @@ static void __init swap_ex(void *a, void *b, int size) }#endif -void __init sort_exception_tables (void ) +void __INIT sort_exception_table(struct exception_table_entry *start, +struct exception_table_entry *stop) { -sort (__start___ex_table, __stop___ex_table - __start___ex_table, -sizeof (struct exception_table_entry ), cmp_ex, swap_ex); -sort (__start___pre_ex_table, - __stop___pre_ex_table - __start___pre_ex_table, +sort (start, stop - start,sizeof (struct exception_table_entry ), cmp_ex, swap_ex); } -static inline unsigned long -search_one_table (const struct exception_table_entry *first, -const struct exception_table_entry *last, -unsigned long value) +void __init sort_exception_tables (void ) +{ +sort_exception_table (__start___ex_table, __stop___ex_table); +sort_exception_table (__start___pre_ex_table, __stop___pre_ex_table); +} + +unsigned long +search_one_extable (const struct exception_table_entry *first, +const struct exception_table_entry *last, +unsigned long value) {const struct exception_table_entry *mid;long diff;
@@ -85,7 +90,7 @@ search_exception_table(unsigned long addr)const struct virtual_region *region =find_text_region (addr);if ( region && region->ex ) -return search_one_table (region->ex, region->ex_end-1 , addr); +return search_one_extable (region->ex, region->ex_end-1 , addr);return 0 ; }
@@ -94,7 +99,7 @@ unsigned long search_pre_exception_table(struct cpu_user_regs *regs) {unsigned long addr = (unsigned long )regs->eip; -unsigned long fixup =search_one_table ( +unsigned long fixup =search_one_extable ( __start___pre_ex_table, __stop___pre_ex_table-1 , addr);if ( fixup ) {
xen/arch/x86/test/xen_hello_world_func.c +11 -0
@@ -5,9 +5,20 @@#include <xen/types.h> +static unsigned long *non_canonical_addr = (unsigned long *)(1UL <<48 ); +/* Our replacement function for xen_extra_version. */ const char *xen_hello_world (void ) { +unsigned long tmp =0xdeadbeef ; +int rc; +/* +* Any BUG, or WARN_ON will contain symbol and payload name. Furthermore +* exceptions will be caught and processed properly. +*/ + rc =__get_user (tmp, non_canonical_addr); +BUG_ON (rc != -EFAULT ); +return "Hello World" ; }
xen/common/xsplice.c +25 -0
@@ -525,6 +525,31 @@ static int prepare_payload(struct payload *payload,sizeof (*region->frame[i].bugs); } +#ifdef CONFIG_X86 + sec =xsplice_elf_sec_by_name (elf,".ex_table" ); +if ( sec ) + { +struct exception_table_entry *s, *e; + +if ( !sec->sec->sh_size || + (sec->sec->sh_size %sizeof (*region->ex)) ) + { +dprintk (XENLOG_DEBUG ,XSPLICE "%s: Wrong size of .ex_table (exp:%lu vs %lu)!\n" , + elf->name,sizeof (*region->ex), + sec->sec->sh_size); +return -EINVAL ; + } + + s = sec->load_addr; + e = sec->load_addr + sec->sec->sh_size; + +sort_exception_table (s ,e); + + region->ex = (const struct exception_table_entry *)s; + region->ex_end = (const struct exception_table_entry *)e; + } +#endif +return 0 ; }
xen/include/asm-x86/uaccess.h +2 -0
@@ -277,5 +277,7 @@ extern struct exception_table_entry __stop___pre_ex_table[];extern unsigned long search_exception_table (unsigned long );extern void sort_exception_tables (void ); +extern void sort_exception_table (struct exception_table_entry *start, +struct exception_table_entry *stop);#endif /* __X86_UACCESS_H__ */
xen/include/xen/xsplice.h +17 -0
@@ -37,6 +37,15 @@ struct xsplice_patch_func_internal { } u; }; +/* +* We use alternative and exception table code - which by default are __init +* only, however we need them during runtime. These macros allows us to build +* the image with these functions built-in. (See the #else below). +*/ +#define __INITCONST +#define __INITDATA +#define __INIT +/* Convenience define for printk. */ #define XSPLICE "xsplice: "
@@ -96,6 +105,14 @@ void arch_xsplice_mask(void);void arch_xsplice_unmask (void );#else +/* +* If not compiling with xSplice certain functionality should stay as +* __init. +*/ +#define __INITCONST __initconst +#define __INITDATA __initdata +#define __INIT __init +#include <xen/errno.h> /* For -EOPNOTSUPP */ static inline int xsplice_op (struct xen_sysctl_xsplice_op *op) {
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v6 15/24] xsplice: Add support for exception tables.
Quoted 4 lines · Konrad Rzeszutek Wilk
xen/arch/x86/extable.c +0
-0@@ -48,19 +49,23 @@ static void __init swap_ex(void *a, void *b, int size) }#endif
xen/arch/x86/extable.c static void __init swap_ex(void *a, void *b, int size) · line 56
Quoted 10 lines
xen/arch/x86/extable.c +3
-5-void __init sort_exception_tables (void ) +void __INIT sort_exception_table(struct exception_table_entry *start, +struct exception_table_entry *stop) { -sort (__start___ex_table, __stop___ex_table - __start___ex_table, -sizeof (struct exception_table_entry ), cmp_ex, swap_ex); -sort (__start___pre_ex_table, - __stop___pre_ex_table - __start___pre_ex_table, +sort (start, stop - start,sizeof (struct exception_table_entry ), cmp_ex, swap_ex);
This reminds me that Xen's heapsort implementation is buggy.
By shear luck, it does end up in the correct order, but in O(N^2) time.
I will submit a separate bugfix patch.
Quoted 42 lines
xen/arch/x86/extable.c +12
-6} -static inline unsigned long -search_one_table (const struct exception_table_entry *first, -const struct exception_table_entry *last, -unsigned long value) +void __init sort_exception_tables (void ) +{ +sort_exception_table (__start___ex_table, __stop___ex_table); +sort_exception_table (__start___pre_ex_table, __stop___pre_ex_table); +} + +unsigned long +search_one_extable (const struct exception_table_entry *first, +const struct exception_table_entry *last, +unsigned long value) {const struct exception_table_entry *mid;long diff;@@ -85,7 +90,7 @@ search_exception_table(unsigned long addr)const struct virtual_region *region =find_text_region (addr);if ( region && region->ex ) -return search_one_table (region->ex, region->ex_end-1 , addr); +return search_one_extable (region->ex, region->ex_end-1 , addr);return 0 ; }@@ -94,7 +99,7 @@ unsigned long search_pre_exception_table(struct cpu_user_regs *regs) {unsigned long addr = (unsigned long )regs->eip; -unsigned long fixup =search_one_table ( +unsigned long fixup =search_one_extable ( __start___pre_ex_table, __stop___pre_ex_table-1 , addr);if ( fixup ) {xen/arch/x86/test/xen_hello_world_func.c +0
-0
xen/arch/x86/test/xen_hello_world_func.c line 8
Quoted 4 lines
xen/arch/x86/test/xen_hello_world_func.c +1
-0@@ -5,9 +5,20 @@#include <xen/types.h> +static unsigned long *non_canonical_addr = (unsigned long *)(1UL <<48 );
I would recommend a more visible hex constant, both for the unlikely case of patching being broken and Xen actually barfing, and because this particular non-canonical address will no longer be non-canonical when 5 level paging appears.
how about 0xdead000000000000ULL ?
xen/arch/x86/test/xen_hello_world_func.c line 13
Quoted 5 lines
xen/arch/x86/test/xen_hello_world_func.c +2
-0+/* Our replacement function for xen_extra_version. */ const char *xen_hello_world (void ) { +unsigned long tmp =0xdeadbeef ;
No need to initialise.
Quoted 31 lines
xen/arch/x86/test/xen_hello_world_func.c +8
-0+int rc; +/* +* Any BUG, or WARN_ON will contain symbol and payload name. Furthermore +* exceptions will be caught and processed properly. +*/ + rc =__get_user (tmp, non_canonical_addr); +BUG_ON (rc != -EFAULT ); +return "Hello World" ; }xen/common/xsplice.c +12
-0@@ -525,6 +525,31 @@ static int prepare_payload(struct payload *payload,sizeof (*region->frame[i].bugs); } +#ifdef CONFIG_X86 + sec =xsplice_elf_sec_by_name (elf,".ex_table" ); +if ( sec ) + { +struct exception_table_entry *s, *e; + +if ( !sec->sec->sh_size || + (sec->sec->sh_size %sizeof (*region->ex)) ) + { +dprintk (XENLOG_DEBUG ,XSPLICE "%s: Wrong size of .ex_table (exp:%lu vs %lu)!\n" , + elf->name,sizeof (*region->ex), + sec->sec->sh_size);
xen/common/xsplice.c static int prepare_payload(struct payload *payload, · line 549
Quoted 10 lines
xen/common/xsplice.c +10
-0+return -EINVAL ; + } + + s = sec->load_addr; + e = sec->load_addr + sec->sec->sh_size; + +sort_exception_table (s ,e); + + region->ex = (const struct exception_table_entry *)s; + region->ex_end = (const struct exception_table_entry *)e;
These casts should not be needed at all.
Quoted 25 lines
xen/common/xsplice.c +3
-0+ } +#endif +return 0 ; }xen/include/asm-x86/uaccess.h +2
-0@@ -277,5 +277,7 @@ extern struct exception_table_entry __stop___pre_ex_table[];extern unsigned long search_exception_table (unsigned long );extern void sort_exception_tables (void ); +extern void sort_exception_table (struct exception_table_entry *start, +struct exception_table_entry *stop);#endif /* __X86_UACCESS_H__ */ xen/include/xen/xsplice.h +0
-0@@ -37,6 +37,15 @@ struct xsplice_patch_func_internal { } u; };
xen/include/xen/xsplice.h struct xsplice_patch_func_internal { · line 48
Quoted 10 lines
xen/include/xen/xsplice.h +9
-0+/* +* We use alternative and exception table code - which by default are __init +* only, however we need them during runtime. These macros allows us to build +* the image with these functions built-in. (See the #else below). +*/ +#define __INITCONST +#define __INITDATA +#define __INIT +
This isn't very nice, but is probably the best we can do for 4.7
It would be nice to have things like __maybe_init(CONFIG_XSPLICE) , but then negations get hard (and perhaps this needs more thought).
No major issues, so with the identified things fixed, Reviewed-by:
Andrew Cooper <[email protected]>
Quoted 8 lines
xen/include/xen/xsplice.h +1
-0/* Convenience define for printk. */ #define XSPLICE "xsplice: "@@ -96,6 +105,14 @@ void arch_xsplice_mask(void);void arch_xsplice_unmask (void );#else +/*
xen/include/xen/xsplice.h void arch_xsplice_mask(void); · line 118
Quoted 10 lines
xen/include/xen/xsplice.h +7
-0+* If not compiling with xSplice certain functionality should stay as +* __init. +*/ +#define __INITCONST __initconst +#define __INITDATA __initdata +#define __INIT __init +#include <xen/errno.h> /* For -EOPNOTSUPP */ static inline int xsplice_op (struct xen_sysctl_xsplice_op *op) {
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v6 16/24 xsplice: Add support for alternatives
In reply to Konrad Rzeszutek WilkFrom: Ross Lagerwall <[email protected]>
Add support for applying alternative sections within xsplice payload. At payload load time, apply an alternative sections that are found.
Also we add an test-case exercising a rather useless alternative (patching a NOP with a NOP) - but it does exercise the code-path.
---
Cc: Keir Fraser <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
v2: Make a new alternative function that does not ASSERT on IRQs and
don't disable IRQs in the code when loading payload.
v4: Include test-case
Include check for size of alternatives and that it is not a 0 size section.
v6: Add #define INIT to preserve __initness on alternative code.
Double check that alt_instr are only patching payload code.
---
--- xen/arch/x86/Makefile | 2 +- xen/arch/x86/alternative.c | 35 ++++++++++++++++++++++---------- xen/arch/x86/test/xen_hello_world_func.c | 5 +++++ xen/common/xsplice.c | 34 +++++++++++++++++++++++++++++++ xen/include/asm-x86/alternative.h | 4 ++++ 5 files changed, 68 insertions(+), 12 deletions(-)
xen/arch/x86/Makefile +1 -1
@@ -6,7 +6,7 @@ subdir-y += mm subdir-$(CONFIG_XENOPROF) += oprofile subdir-y += x86_64 -obj-bin-y += alternative.init.o +obj-bin-y += alternative.o obj-y += apic.o obj-y += bitops.o obj-bin-y += bzimage.init.o
xen/arch/x86/alternative.c +24 -11
@@ -22,13 +22,14 @@#include <asm/system.h> #include <asm/traps.h> #include <asm/nmi.h> +#include <xen/xsplice.h> #define MAX_PATCH_LEN (255-1)extern struct alt_instr __alt_instructions[], __alt_instructions_end[];#ifdef K8_NOP1 -static const unsigned char k8nops[]__initconst = { +static const unsigned char k8nops[] __INITCONST = {K8_NOP1 ,K8_NOP2 , K8_NOP3,
@@ -52,7 +53,7 @@ static const unsigned char * const k8_nops[ASM_NOP_MAX+1] __initconstrel = {#endif #ifdef P6_NOP1 -static const unsigned char p6nops[]__initconst = { +static const unsigned char p6nops[] __INITCONST = {P6_NOP1 ,P6_NOP2 , P6_NOP3,
@@ -75,7 +76,7 @@ static const unsigned char * const p6_nops[ASM_NOP_MAX+1] __initconstrel = { };#endif -static const unsigned char *const *ideal_nops__initdata = k8_nops; +static const unsigned char * const *ideal_nops __INITDATA = k8_nops;static int __init mask_nmi_callback (const struct cpu_user_regs *regs,int cpu) {
@@ -100,7 +101,7 @@ static void __init arch_init_ideal_nops(void) }/* Use this to add nops to a buffer, then text_poke the whole buffer. */ -static void __init add_nops (void *insns,unsigned int len) +static void __INIT add_nops(void *insns, unsigned int len) {while ( len >0 ) {
@@ -114,7 +115,7 @@ static void __init add_nops(void *insns, unsigned int len) }/* -* text_poke_early - Update instructions on a live kernel at boot time +* text_poke - Update instructions on a live kernel or non-executed code. * @addr: address to modify * @opcode: source of the copy * @len: length to copy
@@ -125,9 +126,10 @@ static void __init add_nops(void *insns, unsigned int len)* instructions. And on the local CPU you need to be protected again NMI or MCE * handlers seeing an inconsistent instruction while you patch. * -* This routine is called with local interrupt disabled. +* You should run this with interrupts disabled or on code that has never +* been executed. */ -static void *__init text_poke_early (void *addr,const void *opcode,size_t len) +static void *__INIT text_poke(void *addr, const void *opcode, size_t len) {memcpy (addr, opcode, len);sync_core ();
@@ -142,15 +144,13 @@ static void *__init text_poke_early(void *addr, const void *opcode, size_t len)* APs have less capabilities than the boot processor are not handled. * Tough. Make sure you disable such features by hand. */ -static void __init apply_alternatives (struct alt_instr *start,struct alt_instr *end) +void __INIT apply_alternatives_nocheck(struct alt_instr *start, struct alt_instr *end) {struct alt_instr *a;u8 *instr, *replacement;u8 insnbuf[MAX_PATCH_LEN ];unsigned long cr0 =read_cr0 (); -ASSERT (!local_irq_is_enabled ()); -printk (KERN_INFO "alt table %p -> %p\n" , start, end);/* Disable WP to allow application of alternatives to read-only pages. */
@@ -183,13 +183,26 @@ static void __init apply_alternatives(struct alt_instr *start, struct alt_instradd_nops (insnbuf + a->replacementlen, a->instrlen - a->replacementlen); -text_poke_early (instr, insnbuf, a->instrlen); +text_poke (instr, insnbuf, a->instrlen); }/* Reinstate WP. */ write_cr0 (cr0); } +#undef __INIT +#undef __INITCONST +#undef __INITDATA +/* +* This routine is called with local interrupt disabled and used during +* bootup. +*/ +void __init apply_alternatives (struct alt_instr *start,struct alt_instr *end) +{ +ASSERT (!local_irq_is_enabled ()); +apply_alternatives_nocheck (start, end); +} +void __init alternative_instructions (void ) {nmi_callback_t *saved_nmi_callback;
xen/arch/x86/test/xen_hello_world_func.c +5 -0
@@ -3,6 +3,9 @@* */ +#include <asm/alternative.h> +#include <asm/nops.h> +#include <asm/uaccess.h> #include <xen/types.h> static unsigned long *non_canonical_addr = (unsigned long *)(1UL <<48 );
@@ -12,6 +15,8 @@ const char *xen_hello_world(void) {unsigned long tmp =0xdeadbeef ;int rc; + +alternative (ASM_NOP1 ,ASM_NOP1 ,X86_FEATURE_NX );/* * Any BUG, or WARN_ON will contain symbol and payload name. Furthermore * exceptions will be caught and processed properly.
xen/common/xsplice.c +34 -0
@@ -526,6 +526,39 @@ static int prepare_payload(struct payload *payload, }#ifdef CONFIG_X86 + sec =xsplice_elf_sec_by_name (elf,".altinstructions" ); +if ( sec ) + { +struct alt_instr *a, *start, *end; + +if ( !sec->sec->sh_size || + (sec->sec->sh_size %sizeof (*a)) ) + { +dprintk (XENLOG_DEBUG ,XSPLICE "%s: Wrong size of .alt_instr (exp:%lu vs %lu)!\n" , + elf->name,sizeof (*a), + sec->sec->sh_size); +return -EINVAL ; + } + + start = (struct alt_instr *)sec->load_addr; + end = (struct alt_instr *)(sec->load_addr + sec->sec->sh_size); + +for ( a = start; a < end; a++ ) + { +unsigned long instr = (unsigned long )(&a->instr_offset + a->instr_offset); +unsigned long replacement = (unsigned long )(&a->repl_offset + a->repl_offset); + +if ( (instr < region->start && instr >= region->end) || + (replacement < region->start && replacement >= region->end) ) + { +dprintk (XENLOG_DEBUG ,XSPLICE "%s Alt patching outside payload: 0x%lx!\n" , + elf->name, instr); +return -EINVAL ; + } + } +apply_alternatives_nocheck (start, end); + } + sec =xsplice_elf_sec_by_name (elf,".ex_table" );if ( sec ) {
@@ -548,6 +581,7 @@ static int prepare_payload(struct payload *payload, region->ex = (const struct exception_table_entry *)s; region->ex_end = (const struct exception_table_entry *)e; } +#endif return 0 ;
xen/include/asm-x86/alternative.h +4 -0
@@ -23,6 +23,10 @@ struct alt_instr {u8 replacementlen;/* length of new instruction, <= instrlen */ }; +/* Similar to apply_alternatives except it can be run with IRQs enabled. */ +extern void apply_alternatives_nocheck (struct alt_instr *start, +struct alt_instr *end); +extern void apply_alternatives (struct alt_instr *start,struct alt_instr *end);extern void alternative_instructions (void );#define OLDINSTR (oldinstr) "661:\n\t" oldinstr "\n662:\n"
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v6 16/24] xsplice: Add support for alternatives
Quoted 37 lines · Konrad Rzeszutek Wilk
From: Ross Lagerwall <[email protected]>
Add support for applying alternative sections within xsplice payload. At payload load time, apply an alternative sections that are found.
Also we add an test-case exercising a rather useless alternative (patching a NOP with a NOP) - but it does exercise the code-path.
Signed-off-by Ross Lagerwall <[email protected]>Signed-off-by Konrad Rzeszutek Wilk <[email protected]>---
Cc: Keir Fraser <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>v2: Make a new alternative function that does not ASSERT on IRQs and
don't disable IRQs in the code when loading payload.
v4: Include test-case
Include check for size of alternatives and that it is not a 0 size section.
v6: Add #define INIT to preserve__initnesson alternative code.
Double check thatalt_instrare only patching payload code.
------ xen/arch/x86/Makefile | 2 +- xen/arch/x86/alternative.c | 35 ++++++++++++++++++++++---------- xen/arch/x86/test/xen_hello_world_func.c | 5 +++++ xen/common/xsplice.c | 34 +++++++++++++++++++++++++++++++ xen/include/asm-x86/alternative.h | 4 ++++ 5 files changed, 68 insertions(+), 12 deletions(-)xen/arch/x86/Makefile +0
-0
xen/arch/x86/Makefile subdir-y += mm · line 9
Quoted 5 lines
xen/arch/x86/Makefile +1
-1@@ -6,7 +6,7 @@ subdir-y += mm subdir-$(CONFIG_XENOPROF) += oprofile subdir-y += x86_64 -obj-bin-y += alternative.init.o +obj-bin-y += alternative.o
You want to keep this as alternative.init.o if not CONFIG_XSPLICE
xen/arch/x86/Makefile static void *__init text_poke_early(void *addr, const void *opcode, size_t len) · line 152
Quoted 11 lines
xen/arch/x86/Makefile +1
-1@@ -142,15 +144,13 @@ static void *__init text_poke_early(void *addr, const void *opcode, size_t len) * APs have less capabilities than the boot processor are not handled. * Tough. Make sure you disable such features by hand. */ -static void __init apply_alternatives(struct alt_instr *start, struct alt_instr *end) +void __INIT apply_alternatives_nocheck(struct alt_instr *start, struct alt_instr *end) { struct alt_instr *a; u8 *instr, *replacement; u8 insnbuf[MAX_PATCH_LEN]; unsigned long cr0 = read_cr0();
The cr0 adjustment of WP should also move from the nocheck() to the plain variant. This avoid temporisingly disabling WP on the CPU setting up the patch, before the payload is "secured".
Quoted 11 lines
xen/arch/x86/Makefile +0
-3- ASSERT(!local_irq_is_enabled()); - printk(KERN_INFO "alt table %p -> %p\n", start, end); /* Disable WP to allow application of alternatives to read-only pages. */@@ -183,13 +183,26 @@ static void __init apply_alternatives(struct alt_instr *start, struct alt_instr add_nops(insnbuf + a->replacementlen, a->instrlen - a->replacementlen); - text_poke_early(instr, insnbuf, a->instrlen);
xen/arch/x86/Makefile static void __init apply_alternatives(struct alt_instr *start, struct alt_instr · line 195
Quoted 10 lines
xen/arch/x86/Makefile +4
-0+ text_poke(instr, insnbuf, a->instrlen); } /* Reinstate WP. */ write_cr0(cr0); } +#undef __INIT +#undef __INITCONST +#undef __INITDATA
Why these undefs?
Quoted 28 lines
xen/arch/x86/Makefile +10
-0+/* + * This routine is called with local interrupt disabled and used during + * bootup. + */ +void __init apply_alternatives(struct alt_instr *start, struct alt_instr *end) +{ + ASSERT(!local_irq_is_enabled()); + apply_alternatives_nocheck(start, end); +} + void __init alternative_instructions(void) { nmi_callback_t *saved_nmi_callback;xen/arch/x86/test/xen_hello_world_func.c +3
-0@@ -3,6 +3,9 @@* */ +#include <asm/alternative.h> +#include <asm/nops.h> +#include <asm/uaccess.h> #include <xen/types.h> static unsigned long *non_canonical_addr = (unsigned long *)(1UL <<48 );
xen/arch/x86/test/xen_hello_world_func.c const char *xen_hello_world(void) · line 19
Quoted 5 lines
xen/arch/x86/test/xen_hello_world_func.c +2
-0@@ -12,6 +15,8 @@ const char *xen_hello_world(void) {unsigned long tmp =0xdeadbeef ;int rc; + +alternative (ASM_NOP1 ,ASM_NOP1 ,X86_FEATURE_NX );
NX is very definitely not always available. Use LM instead, and leave a comment saying that LM will always be available on Xen.
With these fixed, Reviewed-by: Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 16/24] xsplice: Add support for alternatives
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 08.04.16 at 19:34, <[email protected]> wrote:
Quoted 6 lines · Konrad Rzeszutek Wilk
xen/arch/x86/Makefile +0
-0@@ -6,7 +6,7 @@ subdir-y += mm subdir-$(CONFIG_XENOPROF) += oprofile subdir-y += x86_64
Quoted 4 lines
xen/arch/x86/Makefile subdir-y += mm · line 9
Quoted 2 lines
xen/arch/x86/Makefile +1
-1-obj-bin-y += alternative.init.o +obj-bin-y += alternative.oYou want to keep this as alternative.init.o if not
CONFIG_XSPLICE
And add to obj-y instead of obj-bin-y when CONFIG_XSPLICE.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v6 17/24 build_id: Provide ld-embedded build-ids
In reply to Konrad Rzeszutek WilkThis patch enables the Elf to be built with the build-id and provide in the Xen hypervisor the code to extract it.
One can also retrieve the value of the build-id by doing 'readelf -n xen-syms'.
For EFI builds we re-use the same build-id that the xen-syms was built with.
The version of ld that first implemented --build-id is v2.18. We check for to see if the linker supports the --build-id parameter and if so use it.
For x86 we have two binaries - the xen-syms and the xen - an smaller version with lots of sections removed. To make it possible for readelf -n xen we also modify mkelf32 and xen.lds.S to include the PT_NOTE ELF section.
The EFI binary is more complicated. Having any non-recognizable sections (.note, .data.note, etc) causes the boot to hang. Moving the .note in the .data section makes it work. It is also worth noting that the PE/COFF does not have any "comment" sections to the author.
Lastly, we MUST call --binary-id=sha1 on all linker invocation so that symbol offsets don't changes (which means we have multiple binary ids - except that the last one is the final one). Without this change, the symbol table embedded in Xen are incorrect - some of the values it contains are offset by the size of the included build id. This obviously causes problems when resolving symbols.
---
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: Rebase it on Martin's initial patch
v2: Move it to XENVER hypercall
v3: Fix EFI building (Ross's fix)
Don't use the third argument for length.
Use new structure for XENVER_build_id with variable buf. Include Ross's fix.
Include detection of bin-utils for build-id support, add probing for size, and return -EPERM for XSM denied calls. Build xen_build_id under ARM, required adding ELFSIZE in proper file. Rebase on top XSM version class.
v4:
Include the build-id .note in the xen ELF binary. s/build_id/build_id_linker/
For EFI build, moved the --build-id values in .data section Rebase on staging.
Split patch in two. Always do --build-id call. Include the .note in .rodata. USe const void * and ssize_t
Use -S to make build_id.o and objcopy differently (Andrew suggested)
v5: Put back the #ifdef LOCK_PROFILE on ARM. (Bad change). Move the _erodata
around. s/ssize_t/unsigned int/
v6: Redid it per Jan's review.
---
--- Config.mk | 11 ++++ xen/arch/arm/Makefile | 2 +- xen/arch/arm/xen.lds.S | 16 +++++- xen/arch/x86/Makefile | 30 +++++++++-- xen/arch/x86/boot/mkelf32.c | 129 +++++++++++++++++++++++++++++++++++++++----- xen/arch/x86/xen.lds.S | 27 ++++++++++ xen/common/version.c | 51 ++++++++++++++++++ xen/include/xen/version.h | 1 + 8 files changed, 245 insertions(+), 22 deletions(-)
Config.mk +11 -0
@@ -126,6 +126,17 @@ endef check-$(gcc) = $(call cc-ver-check,CC,0x040100,"Xen requires at least gcc-4.1") $(eval $(check-y)) +ld-ver-build-id = $(shell $(1) --build-id 2>&1 | \ + grep -q unrecognized && echo n || echo y) + +export XEN_HAS_BUILD_ID ?= n +ifeq ($(call ld-ver-build-id,$(LD)),n) +build_id_linker := +else +CFLAGS += -DBUILD_ID +build_id_linker := --build-id=sha1 +endif + # as-insn: Check whether assembler supports an instruction. # Usage: cflags-y += $(call as-insn "insn",option-yes,option-no) as-insn = $(if $(shell echo 'void _(void) { asm volatile ( $(2) ); }' \
xen/arch/arm/Makefile +1 -1
@@ -92,7 +92,7 @@ $(TARGET)-syms: prelink.o xen.lds $(BASEDIR)/common/symbols-dummy.o $(NM) -pa --format=sysv $(@D)/.$(@F).1 \ | $(BASEDIR)/tools/symbols --sysv --sort >$(@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_linker) \ $(@D)/.$(@F).1.o -o $@ rm -f $(@D)/.$(@F).[0-9]*
xen/arch/arm/xen.lds.S +14 -2
@@ -22,6 +22,9 @@ OUTPUT_ARCH(FORMAT) PHDRS { text PT_LOAD /* XXX should be AT ( XEN_PHYS_START ) */ ; +#if defined(BUILD_ID) + note PT_NOTE ; +#endif } SECTIONS {
@@ -57,10 +60,19 @@ SECTIONS *(.lockprofile.data) __lock_profile_end = .; #endif - - _erodata = .; /* End of read-only data */ } :text +#if defined(BUILD_ID) + .note : { + __note_gnu_build_id_start = .; + *(.note.gnu.build-id) + __note_gnu_build_id_end = .; + *(.note) + *(.note.*) + } :note :text +#endif + _erodata = .; /* End of read-only data */ + .data : { /* Data */ . = ALIGN(PAGE_SIZE); *(.data.page_aligned)
xen/arch/x86/Makefile +25 -5
@@ -72,6 +72,12 @@ efi-y := $(shell if [ ! -r $(BASEDIR)/include/xen/compile.h -o \ -O $(BASEDIR)/include/xen/compile.h ]; then \ echo '$(TARGET).efi'; fi) +ifneq ($(build_id_linker),) +num_phdrs = --notes +else +num_phdrs = +endif + ifdef CONFIG_XSPLICE all_symbols = --all-symbols else
@@ -80,7 +86,8 @@ endif $(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/'` + `$(NM) -nr $(TARGET)-syms | head -n 1 | sed -e 's/^\([^ ]*\).*/0x\1/'` \ + $(num_phdrs) .PHONY: test test:
@@ -114,22 +121,28 @@ $(BASEDIR)/common/symbols-dummy.o: $(MAKE) -f $(BASEDIR)/Rules.mk -C $(BASEDIR)/common symbols-dummy.o $(TARGET)-syms: prelink.o xen.lds $(BASEDIR)/common/symbols-dummy.o - $(LD) $(LDFLAGS) -T xen.lds -N prelink.o \ + $(LD) $(LDFLAGS) -T xen.lds -N prelink.o $(build_id_linker) \ $(BASEDIR)/common/symbols-dummy.o -o $(@D)/.$(@F).0 $(NM) -pa --format=sysv $(@D)/.$(@F).0 \ | $(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 \ + $(LD) $(LDFLAGS) -T xen.lds -N prelink.o $(build_id_linker) \ $(@D)/.$(@F).0.o -o $(@D)/.$(@F).1 $(NM) -pa --format=sysv $(@D)/.$(@F).1 \ | $(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 \ + $(LD) $(LDFLAGS) -T xen.lds -N prelink.o $(build_id_linker) \ $(@D)/.$(@F).1.o -o $@ rm -f $(@D)/.$(@F).[0-9]* +notes.o: $(TARGET)-syms + $(OBJCOPY) -O binary --only-section=.note $(BASEDIR)/xen-syms [email protected] + $(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 \ + --rename-section=.data=.note.gnu.build-id -S [email protected] $@ + rm -f [email protected] + EFI_LDFLAGS = $(patsubst -m%,-mi386pep,$(LDFLAGS)) --subsystem=10 EFI_LDFLAGS += --image-base=$(1) --stack=0,0 --heap=0,0 --strip-debug EFI_LDFLAGS += --section-alignment=0x200000 --file-alignment=0x20
@@ -142,6 +155,13 @@ $(TARGET).efi: VIRT_BASE = 0x$(shell $(NM) efi/relocs-dummy.o | sed -n 's, A VIR $(TARGET).efi: ALT_BASE = 0x$(shell $(NM) efi/relocs-dummy.o | sed -n 's, A ALT_START$$,,p') # Don't use $(wildcard ...) here - at least make 3.80 expands this too early! $(TARGET).efi: guard = $(if $(shell echo efi/dis* | grep disabled),:) +ifneq ($(build_id_linker),) +$(TARGET).efi: notes.o +notes_file := notes.o +else +notes_file := +endif + $(TARGET).efi: prelink-efi.o efi.lds efi/relocs-dummy.o $(BASEDIR)/common/symbols-dummy.o efi/mkreloc $(foreach base, $(VIRT_BASE) $(ALT_BASE), \ $(guard) $(LD) $(call EFI_LDFLAGS,$(base)) -T efi.lds -N $< efi/relocs-dummy.o \
@@ -158,7 +178,7 @@ $(TARGET).efi: prelink-efi.o efi.lds efi/relocs-dummy.o $(BASEDIR)/common/symbol | $(guard) $(BASEDIR)/tools/symbols $(all_symbols) --sysv --sort >$(@D)/.$(@F).1s.S $(guard) $(MAKE) -f $(BASEDIR)/Rules.mk $(@D)/.$(@F).1r.o $(@D)/.$(@F).1s.o $(guard) $(LD) $(call EFI_LDFLAGS,$(VIRT_BASE)) -T efi.lds -N $< \ - $(@D)/.$(@F).1r.o $(@D)/.$(@F).1s.o -o $@ + $(@D)/.$(@F).1r.o $(@D)/.$(@F).1s.o $(notes_file) -o $@ if $(guard) false; then rm -f $@; echo 'EFI support disabled'; fi rm -f $(@D)/.$(@F).[0-9]*
xen/arch/x86/boot/mkelf32.c +115 -14
205 lines not on this page · raw message
xen/arch/x86/xen.lds.S +27 -0
@@ -31,6 +31,9 @@ OUTPUT_ARCH(i386:x86-64) PHDRS { text PT_LOAD ; +#if defined(BUILD_ID) && !defined(EFI) + note PT_NOTE ; +#endif } SECTIONS {
@@ -78,6 +81,19 @@ SECTIONS *(.rodata) *(.rodata.*) +#if defined(BUILD_ID) && defined(EFI) +/* + * No mechanism to put an PT_NOTE in the EFI file - so put + * it in .data section. + */ + . = ALIGN(4); + + __note_gnu_build_id_start = .; + *(.note.gnu.build-id) + __note_gnu_build_id_end = .; + *(.note) + *(.note.*) +#endif . = ALIGN(8); /* Exception table */
@@ -99,6 +115,17 @@ SECTIONS _erodata = .; } :text +#if defined(BUILD_ID) && !defined(EFI) + . = ALIGN(4); + .note : { + __note_gnu_build_id_start = .; + *(.note.gnu.build-id) + __note_gnu_build_id_end = .; + *(.note) + *(.note.*) + } :note :text +#endif + #ifdef EFI . = ALIGN(MB(2)); #else
xen/common/version.c +51 -0
61 lines not on this page · raw message
xen/include/xen/version.h +1 -0
@@ -13,5 +13,6 @@ const char *xen_extra_version(void);const char *xen_changeset (void );const char *xen_banner (void );const char *xen_deny (void ); +int xen_build_id (const void **p,unsigned int *len);#endif /* __XEN_VERSION_H__ */
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v6 17/24] build_id: Provide ld-embedded build-ids
Hi Konrad,
Quoted 31 lines · Konrad Rzeszutek Wilk
This patch enables the Elf to be built with the build-id and provide in the Xen hypervisor the code to extract it.
One can also retrieve the value of the build-id by doing 'readelf -n xen-syms'.
For EFI builds we re-use the same build-id that the xen-syms was built with.
The version of ld that first implemented --build-id is v2.18. We check for to see if the linker supports the --build-id parameter and if so use it.
For x86 we have two binaries - the xen-syms and the xen - an smaller version with lots of sections removed. To make it possible for readelf -n xen we also modify mkelf32 and
xen.lds.Sto include thePT_NOTEELF section.The EFI binary is more complicated. Having any non-recognizable sections (.note, .data.note, etc) causes the boot to hang. Moving the .note in the .data section makes it work. It is also worth noting that the PE/COFF does not have any "comment" sections to the author.
Lastly, we MUST call --binary-id=sha1 on all linker invocation so that symbol offsets don't changes (which means we have multiple binary ids - except that the last one is the final one). Without this change, the symbol table embedded in Xen are incorrect - some of the values it contains are offset by the size of the included build id. This obviously causes problems when resolving symbols.
Quoted 3 lines
Suggested-by Andrew Cooper <[email protected]>Signed-off-by Martin Pohlack <[email protected]>Signed-off-by Konrad Rzeszutek Wilk <[email protected]>
For the ARM bits:
Regards,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v6 17/24] build_id: Provide ld-embedded build-ids
In reply to Konrad Rzeszutek Wilkxen/arch/x86/Makefile $(BASEDIR)/common/symbols-dummy.o: · line 143
Quoted 5 lines · Konrad Rzeszutek Wilk
xen/arch/x86/Makefile +4
-0+notes.o: $(TARGET)-syms + $(OBJCOPY) -O binary --only-section=.note $(BASEDIR)/xen-syms [email protected] + $(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 \ + --rename-section=.data=.note.gnu.build-id -S [email protected] $@
This should just rename to .note. Notes other than build-id might be present.
Is the specific name important for anything?
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 17/24] build_id: Provide ld-embedded build-ids
Quoted 11 lines · Andrew Cooper
xen/arch/x86/Makefile $(BASEDIR)/common/symbols-dummy.o: · line 143
Quoted 5 lines · Konrad Rzeszutek Wilk
xen/arch/x86/Makefile +4
-0+notes.o: $(TARGET)-syms + $(OBJCOPY) -O binary --only-section=.note $(BASEDIR)/xen-syms [email protected] + $(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 \ + --rename-section=.data=.note.gnu.build-id -S [email protected] $@This should just rename to .note. Notes other than build-id might be present.
Is the specific name important for anything?
No. Well it can't be .rodata.note as I found out. Linker (mingw64) ignores it for some oddball reason. Or maybe I messed up.
Anyhow I simplified it a bit since this objcopy effectivly squashes all .note when handing it for EFI builds (but not for ELF). So made it uniform across ARM and x86.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v6 18/24 HYPERCALL_version_op: Add VERSION_build_id to retrieve build-id.
In reply to Konrad Rzeszutek WilkThe VERSION hypercall provides the flexibility to expose the size of the build-id (so the callers can allocate the proper size before trying to retrieve it). It also allows in one nice swoop to retrieve the hypervisor build-id in the provided buffer.
---
Cc: Daniel De Graaf <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Wei Liu <[email protected]>
v4: New patch.
v5: Rebase - s/VERSION_OP/VERSION/
v6: Add Jan's Ack [provided the version_ops replacement does not need to
be reverted].
---
--- tools/flask/policy/policy/modules/xen/xen.te | 1 + xen/common/kernel.c | 4 ++++ xen/include/public/version.h | 3 +++ xen/xsm/flask/hooks.c | 3 +++ xen/xsm/flask/policy/access_vectors | 2 ++ 5 files changed, 13 insertions(+)
tools/flask/policy/policy/modules/xen/xen.te +1 -0
@@ -81,6 +81,7 @@ 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 + build_id }; allow dom0_t xen_t:mmu memorymap;
xen/common/kernel.c +4 -0
@@ -474,6 +474,10 @@ DO(version_op)(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg, ptr = saved_cmdline;break ; +case XEN_VERSION_build_id: + rc =xen_build_id (&ptr, &sz); +break ; +default : rc = -ENOSYS ; }
xen/include/public/version.h +3 -0
@@ -157,6 +157,9 @@ DEFINE_XEN_GUEST_HANDLE(xen_version_op_val_t);/* arg = char[]. Contains NUL terminated utf-8 string. */ #define XEN_VERSION_commandline 9 +/* arg = void. Contains binary value of hypervisor build-id. */ +#define XEN_VERSION_build_id 10 +#endif /* __XEN_PUBLIC_VERSION_H__ */ /*
xen/xsm/flask/hooks.c +3 -0
@@ -1693,6 +1693,9 @@ static int flask_version_op (uint32_t op)case XEN_VERSION_commandline:return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION ,VERSION__COMMANDLINE ,NULL ); +case XEN_VERSION_build_id: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__BUILD_ID ,NULL );default :return -EPERM ; }
xen/xsm/flask/policy/access_vectors +2 -0
@@ -536,4 +536,6 @@ class version guest_handle # Xen command line. commandline +# Build id of the hypervisor + build_id }
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v6 18/24] HYPERCALL_version_op: Add VERSION_build_id to retrieve build-id.
Quoted 9 lines · Konrad Rzeszutek Wilk
The VERSION hypercall provides the flexibility to expose the size of the build-id (so the callers can allocate the proper size before trying to retrieve it). It also allows in one nice swoop to retrieve the hypervisor build-id in the provided buffer.
Signed-off-by Konrad Rzeszutek Wilk <[email protected]>Acked-by Daniel De Graaf <[email protected]>Acked-by Jan Beulich <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v6 19/24 libxl: info: Display build_id of the hypervisor using XEN_VERSION_build_id
In reply to Konrad Rzeszutek WilkIf the hypervisor is built with we will display it.
---
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Wei Liu <[email protected]>
v2: Include HAVE_*, use libxl_zalloc, s/rc/ret/
v3: Retry with different size if 1020 is not enough.
v4: Use VERSION_OP subops instead of the XENVER_ subops
v5: Change it per Wei's review. s/VERSION_OP/VERSION/
And actually use the proper Style!
---
--- tools/libxl/libxl.c | 18 ++++++++++++++++-- tools/libxl/libxl.h | 6 ++++++ tools/libxl/libxl_types.idl | 1 + tools/libxl/xl_cmdimpl.c | 1 + 4 files changed, 24 insertions(+), 2 deletions(-)
tools/libxl/libxl.c +16 -2
@@ -5364,6 +5364,7 @@ const libxl_version_info* libxl_get_version_info(libxl_ctx *ctx)GC_INIT (ctx);char *buf;xen_version_op_val_t val =0 ; +int r;libxl_version_info *info = &ctx->version_info;if (info->xen_version_extra !=NULL )
@@ -5406,8 +5407,21 @@ const libxl_version_info* libxl_get_version_info(libxl_ctx *ctx) info->virt_start = val; - (void )libxl__xc_version_wrapper (gc, XEN_VERSION_commandline, buf, - info->pagesize, &info->commandline); +if (libxl__xc_version_wrapper (gc, XEN_VERSION_commandline, buf, + info->pagesize, &info->commandline) <0 ) + goto out; + + r =xc_version (ctx->xch, XEN_VERSION_build_id, buf, info->pagesize); +if (r <0 ) { + info->build_id =libxl__strdup (NOGC ,"" ); + }else if (r >0 ) { +unsigned int i; + + info->build_id =libxl__zalloc (NOGC , (r *2 ) +1 ); + +for (i =0 ; i < r; i++) +snprintf (&info->build_id[i *2 ],3 ,"%02hhx" , buf[i]); + } out:GC_FREE ;return info;
tools/libxl/libxl.h +6 -0
@@ -247,6 +247,12 @@#define LIBXL_HAVE_APIC_ASSIST 1/* +* LIBXL_HAVE_BUILD_ID means that libxl_version_info has the extra +* field for the hypervisor build_id. +*/ +#define LIBXL_HAVE_BUILD_ID 1 + +/* * libxl ABI compatibility * * The only guarantee which libxl makes regarding ABI compatibility
tools/libxl/libxl_types.idl +1 -0
@@ -365,6 +365,7 @@ libxl_version_info = Struct("version_info", [ ("virt_start", uint64), ("pagesize", integer), ("commandline", string), + ("build_id", string), ], dir=DIR_OUT) libxl_domain_create_info = Struct("domain_create_info",[
tools/libxl/xl_cmdimpl.c +1 -0
@@ -5915,6 +5915,7 @@ static void output_xeninfo(void)printf ("cc_compile_by : %s\n" , info->compile_by);printf ("cc_compile_domain : %s\n" , info->compile_domain);printf ("cc_compile_date : %s\n" , info->compile_date); +printf ("build_id : %s\n" , info->build_id);return ; }
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH v6 20/24 xsplice: Print build_id in keyhandler and on bootup.
In reply to Konrad Rzeszutek WilkAs it should be an useful debug mechanism.
--
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Tim Deegan <[email protected]>
v2: s/char */const void *
v5: s/ssize_t/unsigned int/
v6: Remove pointless initializers, use string literal instead of %s,
add Jan's Ack.
---
--- xen/common/xsplice.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
xen/common/xsplice.c +12 -0
@@ -16,6 +16,7 @@#include <xen/spinlock.h> #include <xen/string.h> #include <xen/symbols.h> +#include <xen/version.h> #include <xen/virtual_region.h> #include <xen/vmap.h> #include <xen/wait.h>
@@ -1331,8 +1332,13 @@ static const char *state2str(uint32_t state)static void xsplice_printall (unsigned char key) {struct payload *data; +const void *binary_id =NULL ; +unsigned int len =0 ;unsigned int i; +if ( !xen_build_id (&binary_id, &len) ) +printk ("build-id: %*phN\n" , len, binary_id); +if ( !spin_trylock (&payload_lock) ) {printk ("Lock held. Try again.\n" );
@@ -1365,11 +1371,17 @@ static void xsplice_printall(unsigned char key)static int __init xsplice_init (void ) { +const void *binary_id; +unsigned int len; +BUILD_BUG_ON (sizeof (struct xsplice_patch_func ) !=64 );BUILD_BUG_ON (sizeof (struct xsplice_patch_func_internal ) !=64 );BUILD_BUG_ON ( offsetof(struct xsplice_patch_func , new_addr) !=8 );BUILD_BUG_ON ( offsetof(struct xsplice_patch_func , new_size) !=24 ); +if ( !xen_build_id (&binary_id, &len) ) + printk(XENLOG_INFO XSPLICE ": build-id: %*phN\n", len, binary_id); +register_keyhandler ('x' , xsplice_printall,"print xsplicing info" ,1 );arch_xsplice_init ();
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v6 20/24] xsplice: Print build_id in keyhandler and on bootup.
Quoted 4 lines · Konrad Rzeszutek Wilk
As it should be an useful debug mechanism.
Signed-off-by Konrad Rzeszutek Wilk <[email protected]>Acked-by Jan Beulich <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v6 21/24 xsplice: Stacking build-id dependency checking.
In reply to Konrad Rzeszutek WilkWe now expect that the ELF payloads be built with the --build-id.
Also the .xsplice.deps section has to have the contents of the hypervisor (or a preceding payload) build-id.
We already have the code to verify the Elf_Note build-id so export parts of it.
This dependency means the hypervisor MUST be compiled with --build-id - so we gate the build of xSplice on the availability of said functionality.
This does not impact the ordering of how the payloads can be loaded, but it does enforce an STRICT ordering when the payloads are applied. Also the REPLACE is special - we need to check that its dependency against the hypervisor - not the last applied patch.
To make this easier to test we also add an extra test-case to be used - which can only be applied on top of the xen_hello_world payload.
As in, one can apply xen_hello_world and then xen_bye_world on top of that. Not the other way.
We also print the dependency and payloads build_in the keyhandler.
---
Cc: Keir Fraser <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
v3: First time included.
v4: Andrew fix against the build_id.o mutilations.
Andrew fix to not include extra symbols in binary.id
v5: s/ssize_t/unsigned int/
v6: s/an NT_GNU../a NT_GNU/
- Squash "xsplice: Print dependency and payloads build_id in the keyhandler" in this patch.
- Add in xen_build_id_check size of section for better checking.
---
--- .gitignore | 1 + Config.mk | 1 + docs/misc/xsplice.markdown | 99 ++++++++++++++++++---------- xen/arch/x86/test/Makefile | 41 ++++++++++-- xen/arch/x86/test/xen_bye_world.c | 35 ++++++++++ xen/arch/x86/test/xen_bye_world_func.c | 24 +++++++ xen/common/Kconfig | 6 +- xen/common/version.c | 43 ++++++++---- xen/common/xsplice.c | 116 ++++++++++++++++++++++++++++++++- xen/include/xen/version.h | 5 ++ 10 files changed, 317 insertions(+), 54 deletions(-) create mode 100644 xen/arch/x86/test/xen_bye_world.c create mode 100644 xen/arch/x86/test/xen_bye_world_func.c
.gitignore +1 -0
@@ -247,6 +247,7 @@ 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/x86/test/xen_bye_world.xsplice xen/arch/*/efi/boot.c xen/arch/*/efi/compat.c xen/arch/*/efi/efi.h
Config.mk +1 -0
@@ -134,6 +134,7 @@ ifeq ($(call ld-ver-build-id,$(LD)),n) build_id_linker := else CFLAGS += -DBUILD_ID +export XEN_HAS_BUILD_ID=y build_id_linker := --build-id=sha1 endif
docs/misc/xsplice.markdown +64 -35
129 lines not on this page · raw message
xen/arch/x86/test/Makefile +36 -5
68 lines not on this page · raw message
xen/arch/x86/test/xen_bye_world.c new file +35 -0
@@ -0,0 +1,35 @@ +/* +* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. +* +*/ + +#include <xen/types.h> +#include <xen/xsplice_patch.h> +#include <xen/xsplice.h> +#include "config.h" +#include <xen/lib.h> + +static char xen_bye_world_name[] ="xen_bye_world" ; +extern const char *xen_bye_world (void ); + +/* External symbol. */ +extern const char *xen_extra_version (void ); + +struct xsplice_patch_func __section(".xsplice.funcs") xsplice_xen_bye_world = { + .version = XSPLICE_PAYLOAD_VERSION, + .name = xen_bye_world_name, + .new_addr = (unsigned long)(xen_bye_world), + .old_addr = (unsigned long)(xen_extra_version), + .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_bye_world_func.c new file +24 -0
@@ -0,0 +1,24 @@ +/* +* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. +* +*/ + +#include <xen/types.h> +#include <asm/nops.h> +#include <asm/alternative.h> + +/* Our replacement function for xen_hello_world. */ +const char *xen_bye_world (void ) +{ +return "Bye World!" ; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
xen/common/Kconfig +5 -1
@@ -60,6 +60,10 @@ config HAS_GDBSX config HAS_IOPORTS bool +config HAS_BUILD_ID + string + option env="XEN_HAS_BUILD_ID" + # Enable/Disable kexec support config KEXEC bool "kexec support"
@@ -192,7 +196,7 @@ endmenu config XSPLICE bool "xSplice live patching support" default n - depends on X86 + depends on X86 && HAS_BUILD_ID = "y" ---help--- Allows a running Xen hypervisor to be dynamically patched using binary patches without rebooting. This is primarily used to binarily
xen/common/version.c +31 -12
58 lines not on this page · raw message
xen/common/xsplice.c +115 -1
188 lines not on this page · raw message
xen/include/xen/version.h +5 -0
@@ -1,6 +1,9 @@#ifndef __XEN_VERSION_H__#define __XEN_VERSION_H__ +#include <xen/types.h> +#include <xen/elfstructs.h> +const char *xen_compile_date (void );const char *xen_compile_time (void );const char *xen_compile_by (void );
@@ -14,5 +17,7 @@ const char *xen_changeset(void);const char *xen_banner (void );const char *xen_deny (void );int xen_build_id (const void **p,unsigned int *len); +int xen_build_id_check (const Elf_Note *n,unsigned int n_sz, +const void **p,unsigned int *len);#endif /* __XEN_VERSION_H__ */
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v6 21/24] xsplice: Stacking build-id dependency checking.
Config.mk ifeq ($(call ld-ver-build-id,$(LD)),n) · line 139
Quoted 11 lines · Konrad Rzeszutek Wilk
Config.mk +1
-0@@ -134,6 +134,7 @@ ifeq ($(call ld-ver-build-id,$(LD)),n) build_id_linker := else CFLAGS += -DBUILD_ID +export XEN_HAS_BUILD_ID=y build_id_linker := --build-id=sha1 endif
This hunk looks like it wants to be in patch 17, with its counterpart export.
Quoted 11 lines
Config.mk +2
-1@@ -28,15 +31,43 @@ clean:: .PHONY: config.h 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 +config.h: xen_hello_world_func.o xen_bye_world_func.o (set -e; \ echo "#define NEW_CODE_SZ $(NEW_CODE_SZ)"; \ echo "#define OLD_CODE_SZ $(OLD_CODE_SZ)") > $@ +#
Config.mk clean:: · line 49
Quoted 10 lines
Config.mk +10
-0+# This target is only accessible if CONFIG_XSPLICE is defined, which +# depends on $(build_id_linker) being available. Hence we do not +# need any checks. +# +.PHONY: notes.o +notes.o: + $(OBJCOPY) -O binary --only-section=.note $(BASEDIR)/xen-syms [email protected] + $(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 \ + --rename-section=.data=.xsplice.depends -S [email protected] $@ + rm -f [email protected]
Can you not use the notes.o generated alongside xen-syms ?
Config.mk static int check_special_sections(const struct xsplice_elf *elf) · line 442
Quoted 6 lines
Config.mk +2
-0@@ -427,6 +438,8 @@ static int check_special_sections(const struct xsplice_elf *elf) return 0; } +#define NT_GNU_BUILD_ID 3 +
This, being a defacto standard, should probably be in elfstruct.h
Otherwise, Reviewed-by: Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 21/24] xsplice: Stacking build-id dependency checking.
Quoted 15 lines · Andrew Cooper
Config.mk ifeq ($(call ld-ver-build-id,$(LD)),n) · line 139
Quoted 11 lines · Konrad Rzeszutek Wilk
Config.mk +1
-0@@ -134,6 +134,7 @@ ifeq ($(call ld-ver-build-id,$(LD)),n) build_id_linker := else CFLAGS += -DBUILD_ID +export XEN_HAS_BUILD_ID=y build_id_linker := --build-id=sha1 endifThis hunk looks like it wants to be in patch 17, with its counterpart export.
Except that we don't use it in patch #17. We end up exposing it here and using it in the Kconfig file to modify whether xSplice can be built.
Quoted 11 lines
Quoted 11 lines
Config.mk +1
-1@@ -28,15 +31,43 @@ clean:: .PHONY: config.h 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 +config.h: xen_hello_world_func.o xen_bye_world_func.o (set -e; \ echo "#define NEW_CODE_SZ $(NEW_CODE_SZ)"; \ echo "#define OLD_CODE_SZ $(OLD_CODE_SZ)") > $@
Quoted 13 lines
Config.mk clean:: · line 49
Quoted 11 lines
Config.mk +11
-0+# +# This target is only accessible if CONFIG_XSPLICE is defined, which +# depends on $(build_id_linker) being available. Hence we do not +# need any checks. +# +.PHONY: notes.o +notes.o: + $(OBJCOPY) -O binary --only-section=.note $(BASEDIR)/xen-syms [email protected] + $(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 \ + --rename-section=.data=.xsplice.depends -S [email protected] $@ + rm -f [email protected]Can you not use the notes.o generated alongside xen-syms ?
I need to tweak the file. That is the .note ends up being renamed to .xsplice.depends.
If operate on the one in arch/x86/notes.o I can mess things up. I could operate on the notes.o.bin - but that gets deleted during the build.
Hence this.
Quoted 9 lines
Config.mk static int check_special_sections(const struct xsplice_elf *elf) · line 442
Quoted 7 lines
Config.mk +2
-0@@ -427,6 +438,8 @@ static int check_special_sections(const struct xsplice_elf *elf) return 0; } +#define NT_GNU_BUILD_ID 3 +This, being a defacto standard, should probably be in
elfstruct.h
That is prob
Quoted 2 lines
Otherwise, Reviewed-by: Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v6 22/24 xsplice/xen_replace_world: Test-case for XSPLICE_ACTION_REPLACE
In reply to Konrad Rzeszutek WilkWith this third payload one can do:
-bash-4.1# xen-xsplice load xen_hello_world.xsplice Uploading xen_hello_world.xsplice (10148 bytes) Performing check: completed
Performing apply:. completed
[xen_hello_world depends on hypervisor build-id]
-bash-4.1# xen-xsplice load xen_bye_world.xsplice
Uploading xen_bye_world.xsplice (7076 bytes)
Performing check: completed
Performing apply:. completed
[xen_bye_world depends on xen_hello_world build-id] -bash-4.1# xen-xsplice upload xen_replace_world xen_replace_world.xsplice Uploading xen_replace_world.xsplice (7148 bytes)
-bash-4.1# xen-xsplice list
ID | status
----------------------------------------+------------
xen_hello_world | APPLIED xen_bye_world | APPLIED xen_replace_world | CHECKED
-bash-4.1# xen-xsplice replace xen_replace_world
Performing replace:. completed
-bash-4.1# xl info | grep extraxen_extra : Hello Again World!
-bash-4.1# xen-xsplice list
ID | status
----------------------------------------+------------
xen_hello_world | CHECKED xen_bye_world | CHECKED xen_replace_world | APPLIED
and revert both of the previous payloads and apply the xen_replace_world.
All the magic of this is in the Makefile - we extract the build-id from the hypervisor (xen-syms) and jam it in the xen_replace_world as .xsplice.depends.
---
Cc: Keir Fraser <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
v4: New. Make the objcopy use -S to strip the name.
---
--- .gitignore | 1 + xen/arch/x86/test/Makefile | 8 +++++++ xen/arch/x86/test/xen_replace_world.c | 34 ++++++++++++++++++++++++++++++ xen/arch/x86/test/xen_replace_world_func.c | 24 +++++++++++++++++++++ 4 files changed, 67 insertions(+) create mode 100644 xen/arch/x86/test/xen_replace_world.c create mode 100644 xen/arch/x86/test/xen_replace_world_func.c
.gitignore +1 -0
@@ -248,6 +248,7 @@ xen/arch/x86/efi/mkreloc xen/arch/x86/test/config.h xen/arch/x86/test/xen_hello_world.xsplice xen/arch/x86/test/xen_bye_world.xsplice +xen/arch/x86/test/xen_replace_world.xsplice xen/arch/*/efi/boot.c xen/arch/*/efi/compat.c xen/arch/*/efi/efi.h
xen/arch/x86/test/Makefile +8 -0
@@ -7,15 +7,18 @@ CODE_SZ=$(shell nm --defined -S $(1) | grep $(2) | awk '{ print "0x"$$2}') XSPLICE := xen_hello_world.xsplice XSPLICE_BYE := xen_bye_world.xsplice +XSPLICE_REPLACE := xen_replace_world.xsplice default: xsplice install: xsplice $(INSTALL_DATA) $(XSPLICE) $(DESTDIR)$(DEBUG_DIR)/$(XSPLICE) $(INSTALL_DATA) $(XSPLICE_BYE) $(DESTDIR)$(DEBUG_DIR)/$(XSPLICE_BYE) + $(INSTALL_DATA) $(XSPLICE_REPLACE) $(DESTDIR)$(DEBUG_DIR)/$(XSPLICE_REPLACE) uninstall: rm -f $(DESTDIR)$(DEBUG_DIR)/$(XSPLICE) rm -f $(DESTDIR)$(DEBUG_DIR)/$(XSPLICE_BYE) + rm -f $(DESTDIR)$(DEBUG_DIR)/$(XSPLICE_REPLACE) .PHONY: clean clean::
@@ -71,3 +74,8 @@ xsplice: config.h notes.o $(MAKE) -f $(BASEDIR)/Rules.mk hello_world_notes.o $(LD) $(LDFLAGS) $(build_id_linker) -r -o $(XSPLICE_BYE) \ xen_bye_world_func.o xen_bye_world.o hello_world_notes.o + $(MAKE) -f $(BASEDIR)/Rules.mk xen_replace_world_func.o + $(MAKE) -f $(BASEDIR)/Rules.mk xen_replace_world.o + $(LD) $(LDFLAGS) $(build_id_linker) -r -o $(XSPLICE_REPLACE) \ + xen_replace_world_func.o \ + xen_replace_world.o notes.o
xen/arch/x86/test/xen_replace_world.c new file +34 -0
@@ -0,0 +1,34 @@ +/* +* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. +* +*/ + +#include <xen/types.h> +#include <xen/xsplice_patch.h> +#include <xen/xsplice.h> +#include "config.h" +#include <xen/lib.h> + +static char xen_replace_world_name[] ="xen_replace_world" ; +extern const char *xen_replace_world (void ); + +/* External symbol. */ +extern const char *xen_extra_version (void ); + +struct xsplice_patch_func __section(".xsplice.funcs") xsplice_xen_replace_world = { + .name = xen_replace_world_name, + .new_addr = (unsigned long)(xen_replace_world), + .old_addr = (unsigned long)(xen_extra_version), + .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_replace_world_func.c new file +24 -0
@@ -0,0 +1,24 @@ +/* +* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. +* +*/ + +#include <xen/types.h> +#include <asm/nops.h> +#include <asm/alternative.h> + +/* Our replacement function for xen_hello_world. */ +const char *xen_replace_world (void ) +{ +return "Hello Again 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
Re: [PATCH v6 22/24] xsplice/xen_replace_world: Test-case for XSPLICE_ACTION_REPLACE
Quoted 32 lines · Konrad Rzeszutek Wilk
With this third payload one can do:
-bash-4.1# xen-xsplice load xen_hello_world.xsplice Uploading xen_hello_world.xsplice (10148 bytes) Performing check: completed
Performing apply:. completed[
xen_hello_worlddepends on hypervisor build-id]
-bash-4.1# xen-xsplice load xen_bye_world.xsplice
Uploading xen_bye_world.xsplice (7076 bytes)
Performing check: completed
Performing apply:. completed
[xen_bye_worlddepends onxen_hello_worldbuild-id] -bash-4.1# xen-xsplice uploadxen_replace_worldxen_replace_world.xsplice Uploading xen_replace_world.xsplice (7148 bytes)
-bash-4.1# xen-xsplice list
ID | status
----------------------------------------+------------xen_hello_world | APPLIED xen_bye_world | APPLIED xen_replace_world | CHECKED-bash-4.1# xen-xsplice replace
xen_replace_world
Performing replace:. completed
-bash-4.1# xl info | grep extraxen_extra: Hello Again World!
-bash-4.1# xen-xsplice list
ID | status
----------------------------------------+------------xen_hello_world | CHECKED xen_bye_world | CHECKED xen_replace_world | APPLIED
Quoted 8 lines
and revert both of the previous payloads and apply the
xen_replace_world.All the magic of this is in the
Makefile- we extract the build-id from the hypervisor (xen-syms) and jam it in thexen_replace_worldas .xsplice.depends.Signed-off-by Konrad Rzeszutek Wilk <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v6 23/24 xsplice: Prevent duplicate payloads from being loaded.
In reply to Konrad Rzeszutek WilkFrom: Ross Lagerwall <[email protected]>
---
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Tim Deegan <[email protected]>
v6: Drop recursive lock - also now the caller is holding the lock
Move the code up in the code above.
---
--- xen/common/xsplice.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
xen/common/xsplice.c +16 -0
@@ -512,7 +512,9 @@ static int prepare_payload(struct payload *payload, sec =xsplice_elf_sec_by_name (elf,".note.gnu.build-id" );if ( sec ) { +struct payload *data; n = sec->load_addr; +if ( sec->sec->sh_size <=sizeof (*n) )return -EINVAL ;
@@ -522,6 +524,20 @@ static int prepare_payload(struct payload *payload,if ( !payload->id.len || !payload->id.p )return -EINVAL ; + +/* Make sure it is not a duplicate. */ + list_for_each_entry ( data, &payload_list, list ) + { +/* No way _this_ payload is on the list. */ +ASSERT (data != payload); +if ( data->id.len && + !memcmp (data->id.p, payload->id.p, data->id.len) ) + { +dprintk (XENLOG_DEBUG ,XSPLICE "%s: Already loaded as %s!\n" , + elf->name, data->name); +return -EEXIST ; + } + } } sec =xsplice_elf_sec_by_name (elf,".xsplice.depends" );
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v6 23/24] xsplice: Prevent duplicate payloads from being loaded.
Konrad Rzeszutek Wilk writes ("[PATCH v6 23/24] xsplice: Prevent duplicate payloads from being loaded."):
Quoted 4 lines
From: Ross Lagerwall <[email protected]>
Signed-off-by Ross Lagerwall <[email protected]>Signed-off-by Konrad Rzeszutek Wilk <[email protected]>
I'm not sure why I'm CC'd here, but: given that the xsplice system only has to deal with trusted payloads (at least, this is, AIUI, after the signature check), there is no security impact and apart from that I don't really have a worry.
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 23/24] xsplice: Prevent duplicate payloads from being loaded.
In reply to Konrad Rzeszutek WilkQuoted 4 lines · Konrad Rzeszutek Wilk
From: Ross Lagerwall <[email protected]>
Signed-off-by Ross Lagerwall <[email protected]>Signed-off-by Konrad Rzeszutek Wilk <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v6 24/24 MAINTAINERS/xsplice: Add myself and Ross as the maintainers.
In reply to Konrad Rzeszutek WilkIf you have a patch for xSplice send it our way!
---
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Tim Deegan <[email protected]>
v5: Sort them F: fields (Jan)
---
--- MAINTAINERS | 10 ++++++++++ 1 file changed, 10 insertions(+)
MAINTAINERS +10 -0
@@ -436,6 +436,16 @@ F: xen/include/xsm/ F: xen/xsm/ F: docs/misc/xsm-flask.txt +XSPLICE +M: Konrad Rzeszutek Wilk <[email protected]> +M: Ross Lagerwall <[email protected]> +S: Supported +F: docs/misc/xsplice.markdown +F: tools/misc/xen-xsplice.c +F: xen/arch/*/xsplice* +F: xen/common/xsplice* +F: xen/include/xen/xsplice* + THE REST M: Ian Jackson <[email protected]> M: Jan Beulich <[email protected]>
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v6 24/24] MAINTAINERS/xsplice: Add myself and Ross as the maintainers.
Quoted 4 lines · Konrad Rzeszutek Wilk
If you have a patch for xSplice send it our way!
Signed-off-by Ross Lagerwall <[email protected]>Signed-off-by Konrad Rzeszutek Wilk <[email protected]>
(FWIW)
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel