xSplice v1 design and implementation.
PATCH v4 1/1 xSplice v1 design and implementation.
Hey!
Changelog:
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
*Flow of patches*
The first five patches add the neccessary components that have been requested by Andrew. There are also four fixes I've included.
I was not sure if it made sense to split it of as a standalone patchset (similar to how I did it in v3) or just include it in this patchset. To make it easier for folks to see the whole thing I've just included them in this giant patchset:
compat/x86: Remove unncessary #define.
libxc: Remove dead code (XENVER_capabilities)
xsm/xen_version: Add XSM for the xen_version hypercall HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane. libxc/libxl/python/xenstat: Use new XEN_VERSION_OP hypercall x86/arm: Add BUGFRAME_NR define and BUILD checks.
arm/x86: Use struct virtual_region to do bug, symbol, and (x86) exception tables
vmap: Make the while loop less fishy.
vmap: ASSERT on NULL.
vmap: Add vmalloc_cb and vfree_cb
Since they are generic and touch ARM and x86 they have been tested on x86 (legacy and EFI) and on ARM (CubieTruck). Actually the whole branch has been tested on those three platforms.
*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.v4
(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 | 3 + Config.mk | 12 + MAINTAINERS | 10 + docs/misc/xsplice.markdown | 1115 +++++++++++++++++++ tools/flask/policy/policy/modules/xen/xen.te | 21 + tools/libxc/include/xenctrl.h | 86 +- tools/libxc/xc_core.c | 35 +- tools/libxc/xc_dom_boot.c | 12 +- tools/libxc/xc_dom_x86.c | 7 - tools/libxc/xc_domain.c | 3 +- tools/libxc/xc_misc.c | 337 ++++++ tools/libxc/xc_private.c | 53 +- tools/libxc/xc_private.h | 7 +- tools/libxc/xc_resume.c | 3 +- tools/libxc/xc_sr_save.c | 9 +- tools/libxc/xg_save_restore.h | 6 +- tools/libxl/libxl.c | 94 +- tools/libxl/libxl.h | 5 + tools/libxl/libxl_types.idl | 1 + tools/libxl/xl_cmdimpl.c | 1 + tools/misc/Makefile | 4 + tools/misc/xen-xsplice.c | 463 ++++++++ tools/ocaml/libs/xc/xenctrl_stubs.c | 39 +- tools/python/xen/lowlevel/xc/xc.c | 30 +- tools/xenstat/libxenstat/src/xenstat.c | 12 +- tools/xentrace/xenctx.c | 3 +- xen/Makefile | 2 + xen/arch/arm/Makefile | 7 +- xen/arch/arm/traps.c | 46 +- xen/arch/arm/xen.lds.S | 20 +- xen/arch/arm/xsplice.c | 76 ++ xen/arch/x86/Makefile | 45 +- xen/arch/x86/alternative.c | 20 +- xen/arch/x86/boot/mkelf32.c | 137 ++- xen/arch/x86/domain.c | 4 + xen/arch/x86/extable.c | 44 +- xen/arch/x86/hvm/hvm.c | 1 + xen/arch/x86/hvm/svm/svm.c | 2 + xen/arch/x86/hvm/vmx/vmcs.c | 2 + xen/arch/x86/setup.c | 10 +- xen/arch/x86/test/Makefile | 87 ++ xen/arch/x86/test/xen_bye_world.c | 35 + xen/arch/x86/test/xen_bye_world_func.c | 25 + xen/arch/x86/test/xen_hello_world.c | 54 + xen/arch/x86/test/xen_hello_world_func.c | 26 + xen/arch/x86/test/xen_replace_world.c | 35 + xen/arch/x86/test/xen_replace_world_func.c | 25 + xen/arch/x86/traps.c | 51 +- xen/arch/x86/x86_64/compat/entry.S | 2 + xen/arch/x86/x86_64/entry.S | 2 + xen/arch/x86/xen.lds.S | 23 + xen/arch/x86/xsplice.c | 295 +++++ xen/common/Kconfig | 16 + xen/common/Makefile | 4 + xen/common/bug_ex_symbols.c | 119 +++ xen/common/compat/kernel.c | 4 +- xen/common/kernel.c | 328 +++++- xen/common/symbols.c | 62 +- xen/common/sysctl.c | 7 + xen/common/version.c | 82 ++ xen/common/vmap.c | 45 +- xen/common/vsprintf.c | 15 +- xen/common/xsplice.c | 1476 ++++++++++++++++++++++++++ xen/common/xsplice_elf.c | 385 +++++++ xen/common/xsplice_shadow.c | 109 ++ xen/include/asm-arm/bug.h | 2 + xen/include/asm-arm/nmi.h | 13 + xen/include/asm-x86/alternative.h | 6 + xen/include/asm-x86/bug.h | 3 +- xen/include/asm-x86/uaccess.h | 5 + xen/include/asm-x86/x86_64/page.h | 2 + xen/include/public/arch-arm.h | 3 + xen/include/public/sysctl.h | 169 +++ xen/include/public/version.h | 75 +- xen/include/public/xen.h | 1 + xen/include/xen/bug_ex_symbols.h | 74 ++ xen/include/xen/hypercall.h | 4 + xen/include/xen/kernel.h | 2 + xen/include/xen/symbols.h | 11 + xen/include/xen/version.h | 6 + xen/include/xen/vmap.h | 14 + xen/include/xen/xsplice.h | 129 +++ xen/include/xen/xsplice_elf.h | 56 + xen/include/xen/xsplice_patch.h | 95 ++ xen/include/xsm/dummy.h | 41 + xen/include/xsm/xsm.h | 12 + xen/xsm/dummy.c | 2 + xen/xsm/flask/hooks.c | 91 ++ xen/xsm/flask/policy/access_vectors | 52 + xen/xsm/flask/policy/security_classes | 1 + 90 files changed, 6661 insertions(+), 307 deletions(-)
Konrad Rzeszutek Wilk (24):
compat/x86: Remove unncessary #define.
libxc: Remove dead code (XENVER_capabilities)
xsm/xen_version: Add XSM for the xen_version hypercall HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane. libxc/libxl/python/xenstat: Use new XEN_VERSION_OP hypercall x86/arm: Add BUGFRAME_NR define and BUILD checks.
arm/x86: Use struct virtual_region to do bug, symbol, and (x86) exception tables
vmap: Make the while loop less fishy.
vmap: ASSERT on NULL.
vmap: Add vmalloc_cb and vfree_cb
xsplice: Design document
xen/xsplice: Hypervisor implementation of XEN_XSPLICE_op
libxc: Implementation of XEN_XSPLICE_op in libxc
xen-xsplice: Tool to manipulate xsplice payloads x86/xen_hello_world.xsplice: Test payload for patching 'xen_extra_version'. xsplice,symbols: Implement symbol name resolution on address.
build_id: Provide ld-embedded build-ids
HYPERCALL_version_op: Add VERSION_OP_build_id to retrieve build-id.
libxl: info: Display build_id of the hypervisor using XEN_VERSION_OP_build_id
xsplice: Print build_id in keyhandler and on bootup.
xsplice: Stacking build-id dependency checking. xsplice/xen_replace_world: Test-case for XSPLICE_ACTION_REPLACE
xsplice: Print dependency and payloads build_id in the keyhandler. MAINTAINERS/xsplice: Add myself and Ross as the maintainers.
Ross Lagerwall (10):
xsplice: Add helper elf routines
xsplice: Implement payload loading
xsplice: Implement support for applying/reverting/replacing patches. x86, xsplice: Print payload's symbol name and payload name in backtraces
xsplice: Add .xsplice.hooks functions and test-case
xsplice: Add support for bug frames.
xsplice: Add support for exception tables.
xsplice: Add support for alternatives
xsplice: Prevent duplicate payloads to be loaded.
xsplice: Add support for shadow variables.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v4 1/34 compat/x86: Remove unncessary #define.
It is not used.
---
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Tim Deegan <[email protected]>
---
--- xen/common/compat/kernel.c | 1 - 1 file changed, 1 deletion(-)
xen/common/compat/kernel.c +0 -1
@@ -18,7 +18,6 @@ asm(".file \"" __FILE__ "\"");extern xen_commandline_t saved_cmdline; -#define xen_extraversion compat_extraversion#define xen_extraversion_t compat_extraversion_t#define xen_compile_info compat_compile_info
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v4 01/34] compat/x86: Remove unncessary #define.
Quoted 3 lines · Konrad Rzeszutek Wilk
It is not used.
Signed-off-by Konrad Rzeszutek Wilk <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 01/34] compat/x86: Remove unncessary #define.
In reply to Konrad Rzeszutek WilkQuoted 2 lines
Quoted 1 line
Quoted 1 line · On 15.03.16 at 18:56, <[email protected]> wrote:
It is not used.
Consistently please - either keep them all (just to cover the case that they might get used) or remove them all: xen_compile_info, xen_changeset_info, etc are all unused too. Otoh xennmi_callback is used, but xennmi_callback_t isn't. Which to me suggests that we should leave this alone.
Jan
Quoted 12 lines
xen/common/compat/kernel.c +0
-1@@ -18,7 +18,6 @@ asm(".file \"" __FILE__ "\"");extern xen_commandline_t saved_cmdline; -#define xen_extraversion compat_extraversion#define xen_extraversion_t compat_extraversion_t#define xen_compile_info compat_compile_infoSignature · 1 line
2.5.0
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Konrad Rzeszutek Wilk
Reviewed-by Andrew CooperRe: [PATCH v4 01/34] compat/x86: Remove unncessary #define.
Quoted 8 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 15.03.16 at 18:56, <[email protected]> wrote:
It is not used.
Consistently please - either keep them all (just to cover the case that they might get used) or remove them all:
xen_compile_info,xen_changeset_info, etc are all unused too. Otohxennmi_callbackis used, butxennmi_callback_tisn't. Which to me suggests that we should leave this alone.
Oddly enough taking an cleaver to it was OK.
From 7e3ed6faed6e083f27ad6be947ac528c3eaba9a1 Mon Sep 17 00:00:00 2001
From: Konrad Rzeszutek Wilk <[email protected]>
Date: Wed, 2 Mar 2016 12:50:32 -0500
Subject: [PATCH v4 02/35] compat/x86: Remove unncessary #defines.
They are not used.
---
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Tim Deegan <[email protected]>
v2: Remove a lot more of them.
---
--- xen/common/compat/kernel.c | 8 -------- 1 file changed, 8 deletions(-)
xen/common/compat/kernel.c +0 -8
@@ -18,30 +18,22 @@ asm(".file \"" __FILE__ "\"");extern xen_commandline_t saved_cmdline; -#define xen_extraversion compat_extraversion#define xen_extraversion_t compat_extraversion_t -#define xen_compile_info compat_compile_info#define xen_compile_info_t compat_compile_info_tCHECK_TYPE (capabilities_info); -#define xen_platform_parameters compat_platform_parameters#define xen_platform_parameters_t compat_platform_parameters_t#undef HYPERVISOR_VIRT_START#define HYPERVISOR_VIRT_START HYPERVISOR_COMPAT_VIRT_START(current->domain) -#define xen_changeset_info compat_changeset_info#define xen_changeset_info_t compat_changeset_info_t -#define xen_feature_info compat_feature_info#define xen_feature_info_t compat_feature_info_tCHECK_TYPE (domain_handle); -#define xennmi_callback compat_nmi_callback -#define xennmi_callback_t compat_nmi_callback_t -#ifdef COMPAT_VM_ASSIST_VALID #undef VM_ASSIST_VALID#define VM_ASSIST_VALID COMPAT_VM_ASSIST_VALID
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v4 01/34] compat/x86: Remove unncessary #define.
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 17.03.16 at 01:44, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 15.03.16 at 18:56, <[email protected]> wrote:
It is not used.
Consistently please - either keep them all (just to cover the case that they might get used) or remove them all:
xen_compile_info,xen_changeset_info, etc are all unused too. Otohxennmi_callbackis used, butxennmi_callback_tisn't. Which to me suggests that we should leave this alone.
Quoted 8 lines
Oddly enough taking an cleaver to it was OK.
From
7e3ed6faed6e083f27ad6be947ac528c3eaba9a1Mon Sep 17 00:00:00 2001
From: Konrad Rzeszutek Wilk <[email protected]>
Date: Wed, 2 Mar 2016 12:50:32 -0500
Subject: [PATCH v4 02/35] compat/x86: Remove unncessary #defines.They are not used.
This now goes too far.
Quoted 2 lines
Signed-off-by Konrad Rzeszutek Wilk <[email protected]>Reviewed-by Andrew Cooper <[email protected]>
Hence this can't stay.
Quoted 7 lines
---
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Tim Deegan <[email protected]>v2: Remove a lot more of them.
(Side note: Not only this time round I notice versioning mixup in your patches: The subject says v4 here, yet the update to it above says v2. In the previous round of the xSplice series - v3 - I seem to recall there were patches showing a "history" up to something like v9. I think in cases of such heavy mixing it should be the patch with the oldest history that determines the version of the entire series.)
Quoted 19 lines
xen/common/compat/kernel.c +0
-3@@ -18,30 +18,22 @@ asm(".file \"" __FILE__ "\"");extern xen_commandline_t saved_cmdline; -#define xen_extraversion compat_extraversion#define xen_extraversion_t compat_extraversion_t -#define xen_compile_info compat_compile_info#define xen_compile_info_t compat_compile_info_tCHECK_TYPE (capabilities_info); -#define xen_platform_parameters compat_platform_parameters#define xen_platform_parameters_t compat_platform_parameters_t#undef HYPERVISOR_VIRT_START#define HYPERVISOR_VIRT_START HYPERVISOR_COMPAT_VIRT_START(current->domain)
xen/common/compat/kernel.c asm(".file \"" __FILE__ "\""); · line 43
Quoted 10 lines
xen/common/compat/kernel.c +0
-4-#define xen_changeset_info compat_changeset_info#define xen_changeset_info_t compat_changeset_info_t -#define xen_feature_info compat_feature_info#define xen_feature_info_t compat_feature_info_tCHECK_TYPE (domain_handle); -#define xennmi_callback compat_nmi_callback -#define xennmi_callback_t compat_nmi_callback_t
The former definitely is being used; not getting a compilation error here is not a sign of things being right. That's another reason why - as I had suggested already - we'd probably better leave things as they are: Introduction of uses of the now removed identifiers might otherwise break compat code without anyone noticing right away.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v4 2/34 libxc: Remove dead code (XENVER_capabilities)
In reply to Konrad Rzeszutek WilkThe 'caps' is not used anywhere in there.
---
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Wei Liu <[email protected]>
---
--- tools/libxc/xc_dom_x86.c | 7 ------- 1 file changed, 7 deletions(-)
tools/libxc/xc_dom_x86.c +0 -7
@@ -1259,7 +1259,6 @@ static int meminit_hvm(struct xc_dom_image *dom)unsigned long target_pages = dom->target_pages;unsigned long cur_pages, cur_pfn;int rc; -xen_capabilities_info_t caps;unsigned long stat_normal_pages =0 , stat_2mb_pages =0 , stat_1gb_pages =0 ;unsigned int memflags =0 ;
@@ -1339,12 +1338,6 @@ static int meminit_hvm(struct xc_dom_image *dom) goto error_out; } -if (xc_version (xch, XENVER_capabilities, &caps) !=0 ) - { -DOMPRINTF ("Could not get Xen capabilities" ); - goto error_out; - } - dom->p2m_size = p2m_size; dom->p2m_host =xc_dom_malloc (dom,sizeof (xen_pfn_t) * dom->p2m_size);
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v4 02/34] libxc: Remove dead code (XENVER_capabilities)
Quoted 3 lines · Konrad Rzeszutek Wilk
The 'caps' is not used anywhere in there.
Signed-off-by Konrad Rzeszutek Wilk <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 02/34] libxc: Remove dead code (XENVER_capabilities)
Quoted 6 lines · Andrew Cooper
Quoted 3 lines · Konrad Rzeszutek Wilk
The 'caps' is not used anywhere in there.
Signed-off-by Konrad Rzeszutek Wilk <[email protected]>Reviewed-by Andrew Cooper <[email protected]>
And the winnner for fastest review time goes to Andrew.
"In less than 60 seconds and he pounces on the patch! He tags it!!! And off he goes for the next one!"
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 02/34] libxc: Remove dead code (XENVER_capabilities)
In reply to Konrad Rzeszutek WilkQuoted 8 lines · Konrad Rzeszutek Wilk
The 'caps' is not used anywhere in there.
Signed-off-by Konrad Rzeszutek Wilk <[email protected]>---
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Wei Liu <[email protected]>
Quoted 33 lines
---
--- tools/libxc/xc_dom_x86.c | 7 ------- 1 file changed, 7 deletions(-)tools/libxc/xc_dom_x86.c +0
-7@@ -1259,7 +1259,6 @@ static int meminit_hvm(struct xc_dom_image *dom)unsigned long target_pages = dom->target_pages;unsigned long cur_pages, cur_pfn;int rc; -xen_capabilities_info_t caps;unsigned long stat_normal_pages =0 , stat_2mb_pages =0 , stat_1gb_pages =0 ;unsigned int memflags =0 ;@@ -1339,12 +1338,6 @@ static int meminit_hvm(struct xc_dom_image *dom) goto error_out; } -if (xc_version (xch, XENVER_capabilities, &caps) !=0 ) - { -DOMPRINTF ("Could not get Xen capabilities" ); - goto error_out; - } - dom->p2m_size = p2m_size; dom->p2m_host =xc_dom_malloc (dom,sizeof (xen_pfn_t) * dom->p2m_size);Signature · 1 line
2.5.0
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v4 3/34 xsm/xen_version: Add XSM for the xen_version hypercall
In reply to Konrad Rzeszutek WilkAll of XENVER_* have now an XSM check for their sub-ops.
The subop for XENVER_commandline is now a priviliged operation. To not break guests we still return an string - but it is just '<denied>\0'.
The rest: XENVER_[version|extraversion|capabilities| parameters|get_features|page_size|guest_handle|changeset| compile_info] behave as before - allowed by default for all guests if using the XSM default policy or with the dummy one.
The admin can choose to change the sub-ops to be denied as they see fit.
Also we add a local variable block.
---
Cc: Daniel De Graaf <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Wei Liu <[email protected]>
v2: Do XSM check for all the XENVER_ ops.
v3: Add empty data conditions.
v4: Return <denied> for priv subops.
v5: Move extraversion from priv to normal. Drop the XSM check
for the non-priv subops.
v6: Add +1 for strlen(xen_deny()) to include NULL. Move changeset,
compile_info to non-priv subops.
v7: Remove the \0 on xen_deny()
v8: Add new XSM domain for xenver hypercall. Add all subops to it.
v9: Remove the extra line, Add Ack from Daniel
v10: Rename the XSM from xen_version_op to xsm_xen_version.
Prefix the types with 'xen' to distinguish it from another hypercall performing similar operation. Removed Ack from Daniel as it was so large. Add local variable block.
--- tools/flask/policy/policy/modules/xen/xen.te | 15 ++++++++ xen/common/kernel.c | 53 +++++++++++++++++++++------- xen/common/version.c | 15 ++++++++ xen/include/xen/version.h | 2 +- xen/include/xsm/dummy.h | 22 ++++++++++++ xen/include/xsm/xsm.h | 5 +++ xen/xsm/dummy.c | 1 + xen/xsm/flask/hooks.c | 43 ++++++++++++++++++++++ xen/xsm/flask/policy/access_vectors | 28 +++++++++++++++ xen/xsm/flask/policy/security_classes | 1 + 10 files changed, 172 insertions(+), 13 deletions(-)
tools/flask/policy/policy/modules/xen/xen.te +15 -0
@@ -73,6 +73,15 @@ allow dom0_t xen_t:xen2 { pmu_ctrl get_symbol }; + +# Allow dom0 to use all XENVER_ subops +# Note that dom0 is part of domain_type so this has duplicates. +allow dom0_t xen_t:version { + xen_version xen_extraversion xen_compile_info xen_capabilities + xen_changeset xen_platform_parameters xen_get_features xen_pagesize + xen_guest_handle xen_commandline +}; + allow dom0_t xen_t:mmu memorymap; # Allow dom0 to use these domctls on itself. For domctls acting on other
@@ -137,6 +146,12 @@ if (guest_writeconsole) { # pmu_ctrl is for) allow domain_type xen_t:xen2 pmu_use; +# For normal guests all except XENVER_commandline +allow domain_type xen_t:version { + xen_version xen_extraversion xen_compile_info xen_capabilities + xen_changeset xen_platform_parameters xen_get_features xen_pagesize + xen_guest_handle +}; ############################################################################### # # Domain creation
xen/common/kernel.c +41 -12
121 lines not on this page · raw message
xen/common/version.c +15 -0
@@ -55,3 +55,18 @@ const char *xen_banner(void) {return XEN_BANNER ; } + +const char *xen_deny (void ) +{ +return "<denied>" ; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
xen/include/xen/version.h +1 -1
@@ -12,5 +12,5 @@ unsigned int xen_minor_version(void);const char *xen_extra_version (void );const char *xen_changeset (void );const char *xen_banner (void ); - +const char *xen_deny (void );#endif /* __XEN_VERSION_H__ */
xen/include/xsm/dummy.h +22 -0
@@ -727,3 +727,25 @@ static XSM_INLINE int xsm_pmu_op (XSM_DEFAULT_ARG struct domain *d, unsigned int }#endif /* CONFIG_X86 */ + +#include <public/version.h> +static XSM_INLINE int xsm_xen_version (XSM_DEFAULT_ARG uint32_t op) +{ +XSM_ASSERT_ACTION (XSM_OTHER ); +switch ( op ) + { +case XENVER_version: +case XENVER_extraversion: +case XENVER_compile_info: +case XENVER_capabilities: +case XENVER_changeset: +case XENVER_platform_parameters: +case XENVER_get_features: +case XENVER_pagesize: +case XENVER_guest_handle: +/* These MUST always be accessible to any guest by default. */ +return xsm_default_action (XSM_HOOK , current->domain,NULL ); +default : +return xsm_default_action (XSM_PRIV , current->domain,NULL ); + } +}
xen/include/xsm/xsm.h +5 -0
@@ -193,6 +193,7 @@ struct xsm_operations {int (*ioport_mapping) (struct domain *d,uint32_t s,uint32_t e,uint8_t allow);int (*pmu_op) (struct domain *d,unsigned int op);#endif +int (*xen_version) (uint32_t cmd); };#ifdef CONFIG_XSM
@@ -731,6 +732,10 @@ static inline int xsm_pmu_op (xsm_default_t def, struct domain *d, unsigned int#endif /* CONFIG_X86 */ +static inline int xsm_xen_version (xsm_default_t def,uint32_t op) +{ +return xsm_ops->xen_version (op); +}#endif /* XSM_NO_WRAPPERS */ #ifdef CONFIG_MULTIBOOT
xen/xsm/dummy.c +1 -0
@@ -162,4 +162,5 @@ void xsm_fixup_ops (struct xsm_operations *ops)set_to_dummy_if_null (ops, ioport_mapping);set_to_dummy_if_null (ops, pmu_op);#endif +set_to_dummy_if_null (ops, xen_version); }
xen/xsm/flask/hooks.c +43 -0
61 lines not on this page · raw message
xen/xsm/flask/policy/access_vectors +28 -0
@@ -495,3 +495,31 @@ class security # remove ocontext label definitions for resources del_ocontext } + +# Class version is used to describe the XENVER_ hypercall. +# Each sub-ops is described here - in the default case all of them should +# be allowed except the XENVER_commandline. +# +class version +{ +# Often called by PV kernels to force an callback. + xen_version +# Extra informations (-unstable). + xen_extraversion +# Compile information of the hypervisor. + xen_compile_info +# Such as "xen-3.0-x86_64 xen-3.0-x86_32p hvm-3.0-x86_32 hvm-3.0-x86_32p hvm-3.0-x86_64". + xen_capabilities +# Such as the virtual address of where the hypervisor resides. + xen_platform_parameters +# Source code changeset. + xen_changeset +# The features the hypervisor supports. + xen_get_features +# Page size the hypervisor uses. + xen_pagesize +# An value that the control stack can choose. + xen_guest_handle +# Xen command line. + xen_commandline +}
xen/xsm/flask/policy/security_classes +1 -0
@@ -18,5 +18,6 @@ class shadow class event class grant class security +class version # FLASK
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v4 03/34] xsm/xen_version: Add XSM for the xen_version hypercall
xen/common/kernel.c void __init do_initcalls(void) · line 227
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 15.03.16 at 18:56, <[email protected]> wrote:
xen/common/kernel.c +0
-1@@ -223,12 +224,15 @@ void __init do_initcalls(void)/* * Simple hypercalls. */ -DO (xen_version)(int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg)
Please retain the blank line, as it relates to more than just this one function.
xen/common/kernel.c void __init do_initcalls(void) · line 236
Quoted 9 lines
xen/common/kernel.c +4
-0{ +bool_t deny = !!xsm_xen_version (XSM_OTHER , cmd); +switch ( cmd ) {case XENVER_version: +if ( deny ) +return 0 ;return (xen_major_version () <<16 ) |xen_minor_version ();
To be honest, I'm now rather uncertain about this one: If a guest can't figure out the hypervisor version, how would it be able to adjust its behavior accordingly (e.g. use deprecated hypercalls as needed)? IOW, other than for most/all other stuff here (the get-features and platform-parameters sub-ops may be considered similar to this one, see also below), I don't think allowing the "permitted" default to be overridden makes sense here.
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 283
Quoted 6 lines
xen/common/kernel.c +2
-0@@ -274,6 +279,9 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) .virt_start = HYPERVISOR_VIRT_START }; +if ( deny ) + params.virt_start =0 ;
Guests may (validly imo) assume to get a valid address here. If you mean to not expose the non-constant address in the compat mode case, I could accept that. But you would then need to set the ABI mandated __HYPERVISOR_COMPAT_VIRT_START (and retain the constant value in the non-compat case). Our old 32-bit PV guests would crash extremely early on boot if they got back zero here (that's for 2.6.30 and later, and I think both you and Citrix had derived some of their kernels from our 2.6.32 based one).
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 314
Quoted 6 lines
xen/common/kernel.c +2
-0@@ -302,6 +310,8 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)switch ( fi.submap_idx ) {case 0 : +if ( deny ) +break ;
I think if to be put here at all, this should go ahead of the switch(), so that guests wouldn't be able to guess from the valid index values which features may be available. And of course you should clear fi.submap if you deny access, instead of leaving in it what has been there before.
Quoted 7 lines
xen/common/kernel.c +4
-2case XENVER_guest_handle: -if (copy_to_guest (arg, current->domain->handle, -ARRAY_SIZE (current->domain->handle)) ) + { +xen_domain_handle_t hdl; +ssize_t len; +
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 373
Quoted 10 lines
xen/common/kernel.c +8
-0+if ( deny ) + { + len =sizeof (hdl); +memset (&hdl,0 , len); + }else + len =ARRAY_SIZE (current->domain->handle); + +if (copy_to_guest (arg, deny ? hdl : current->domain->handle, len ) )return -EFAULT ;return 0 ;
What is this "len" handling here about? Aren't both the same type and hence size? Perhaps, if you feel unsure about that, simply add a respective BUILD_BUG_ON()?
xen/include/xen/version.h unsigned int xen_minor_version(void); · line 16
Quoted 9 lines
xen/include/xen/version.h +1
-1@@ -12,5 +12,5 @@ unsigned int xen_minor_version(void);const char *xen_extra_version (void );const char *xen_changeset (void );const char *xen_banner (void ); - +const char *xen_deny (void );#endif /* __XEN_VERSION_H__ */
Please retain the blank line.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 03/34] xsm/xen_version: Add XSM for the xen_version hypercall
Quoted 10 lines · Jan Beulich
Review void __init do_initcalls(void) · line 227
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 15.03.16 at 18:56, <[email protected]> wrote:
(quoted diff) +0
-1@@ -223,12 +224,15 @@ void __init do_initcalls(void) /* * Simple hypercalls. */ - DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)Please retain the blank line, as it relates to more than just this one function.
Done! (stray change).
Quoted 11 lines
Review void __init do_initcalls(void) · line 236
Quoted 10 lines
(quoted diff) +4
-0{ + bool_t deny = !!xsm_xen_version(XSM_OTHER, cmd); + switch ( cmd ) { case XENVER_version: + if ( deny ) + return 0; return (xen_major_version() << 16) | xen_minor_version();
Quoted 7 lines
To be honest, I'm now rather uncertain about this one: If a guest can't figure out the hypervisor version, how would it be able to adjust its behavior accordingly (e.g. use deprecated hypercalls as needed)? IOW, other than for most/all other stuff here (the get-features and platform-parameters sub-ops may be considered similar to this one, see also below), I don't think allowing the "permitted" default to be overridden makes sense here.
I don't want to crash old guests or lead them astray. Removed the 'deny' here. Also removed the XSM checks for this sub-op (and the others below) as they are ignored.
Quoted 5 lines
Quoted 5 lines
(quoted diff) +0
-0@@ -274,6 +279,9 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) .virt_start = HYPERVISOR_VIRT_START };
Quoted 11 lines
Review DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 283
Quoted 2 lines
(quoted diff) +2
-0+ if ( deny ) + params.virt_start = 0;Guests may (validly imo) assume to get a valid address here. If you mean to not expose the non-constant address in the compat mode case, I could accept that. But you would then need to set the ABI mandated
__HYPERVISOR_COMPAT_VIRT_START(and retain the constant value in the non-compat case). Our old 32-bit PV guests would crash extremely early on boot if they got back zero here (that's for 2.6.30 and later, and I think both you and Citrix had derived some of their kernels from our 2.6.32 based one).
OK. Let me also relax this one and always return a value.
Quoted 9 lines
Review DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 314
Quoted 7 lines
(quoted diff) +2
-0@@ -302,6 +310,8 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) switch ( fi.submap_idx ) { case 0: + if ( deny ) + break;I think if to be put here at all, this should go ahead of the
switch(),
I am OK not acking on the XSM check. It really throws a wrench in Linux (upstream Linux hangs when initializing the XenBus frontend driver).
Quoted 18 lines
so that guests wouldn't be able to guess from the valid index values which features may be available. And of course you should clear fi.submap if you deny access, instead of leaving in it what has been there before.
Quoted 13 lines
(quoted diff) +10
-2case XENVER_guest_handle: - if ( copy_to_guest(arg, current->domain->handle, - ARRAY_SIZE(current->domain->handle)) ) + { + xen_domain_handle_t hdl; + ssize_t len; + + if ( deny ) + { + len = sizeof(hdl); + memset(&hdl, 0, len); + } else + len = ARRAY_SIZE(current->domain->handle);
Quoted 8 lines
Review
Quoted 4 lines
(quoted diff) +2
-0+ + if ( copy_to_guest(arg, deny ? hdl : current->domain->handle, len ) ) return -EFAULT; return 0;What is this "len" handling here about? Aren't both the same type and hence size? Perhaps, if you feel unsure about that, simply add a respective
BUILD_BUG_ON()?
Yes they are. Used a BUILD_BUG_ON just in case somebody mucks around.
Quoted 12 lines
xen/include/xen/version.h unsigned int xen_minor_version(void); · line 16
Quoted 10 lines
xen/include/xen/version.h +1
-1@@ -12,5 +12,5 @@ unsigned int xen_minor_version(void);const char *xen_extra_version (void );const char *xen_changeset (void );const char *xen_banner (void ); - +const char *xen_deny (void );#endif /* __XEN_VERSION_H__ */ Please retain the blank line.
Yes.
Quoted 3 lines
Jan
Inline is what the patch now looks like:
From 0d5d62a9f15b8306e0c62fb00af193a733af435c Mon Sep 17 00:00:00 2001
From: Konrad Rzeszutek Wilk <[email protected]>
Date: Fri, 11 Mar 2016 21:40:43 -0500
Subject: [PATCH] xsm/xen_version: Add XSM for most of xen_version hypercall
Most of XENVER_* have now an XSM check for their sub-ops.
The subop for XENVER_commandline is now a priviliged operation. To not break guests we still return an string - but it is just '<denied>\0'.
The XENVER_[version|parameters|get_features] - will always return an value to the guest.
The rest: XENVER_[extraversion|capabilities|page_size| guest_handle|changeset| compile_info] behave as before - allowed by default for all guests if using the XSM default policy or with the dummy one. And if the system admin wants to curtail access to some of them - they can do that now with a non-default XSM policy.
Also we add a local variable block.
---
Cc: Daniel De Graaf <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Wei Liu <[email protected]>
v2: Do XSM check for all the XENVER_ ops.
- Add empty data conditions.
- Return <denied> for priv subops.
- Move extraversion from priv to normal. Drop the XSM check for the non-priv subops.
v3:
- Add +1 for strlen(xen_deny()) to include NULL. Move changeset, compile_info to non-priv subops.
- Remove the \0 on xen_deny()
- Add new XSM domain for xenver hypercall. Add all subops to it.
- Remove the extra line, Add Ack from Daniel
v4:
- Rename the XSM from xen_version_op to xsm_xen_version. Prefix the types with 'xen' to distinguish it from another hypercall performing similar operation. Removed Ack from Daniel as it was so large. Add local variable block.
v5:
- Make XENVER_platform_parameters,get_features,version be excluded from the XSM check per Jan's review. Add BUILD_BUG_CHECK and fix odd line removals.
--- tools/flask/policy/policy/modules/xen/xen.te | 14 +++++++++ xen/common/kernel.c | 43 +++++++++++++++++++++------- xen/common/version.c | 15 ++++++++++ xen/include/xen/version.h | 1 + xen/include/xsm/dummy.h | 24 ++++++++++++++++ xen/include/xsm/xsm.h | 5 ++++ xen/xsm/dummy.c | 1 + xen/xsm/flask/hooks.c | 39 +++++++++++++++++++++++++ xen/xsm/flask/policy/access_vectors | 25 ++++++++++++++++ xen/xsm/flask/policy/security_classes | 1 + 10 files changed, 157 insertions(+), 11 deletions(-)
tools/flask/policy/policy/modules/xen/xen.te +14 -0
@@ -73,6 +73,14 @@ allow dom0_t xen_t:xen2 { pmu_ctrl get_symbol }; + +# Allow dom0 to use all XENVER_ subops that have checks. +# Note that dom0 is part of domain_type so this has duplicates. +allow dom0_t xen_t:version { + xen_extraversion xen_compile_info xen_capabilities + xen_changeset xen_pagesize xen_guest_handle xen_commandline +}; + allow dom0_t xen_t:mmu memorymap; # Allow dom0 to use these domctls on itself. For domctls acting on other
@@ -137,6 +145,12 @@ if (guest_writeconsole) { # pmu_ctrl is for) allow domain_type xen_t:xen2 pmu_use; +# For normal guests all possible except XENVER_commandline. +allow domain_type xen_t:version { + xen_extraversion xen_compile_info xen_capabilities + xen_changeset xen_pagesize xen_guest_handle +}; + ############################################################################### # # Domain creation
xen/common/kernel.c +32 -11
94 lines not on this page · raw message
xen/common/version.c +15 -0
@@ -55,3 +55,18 @@ const char *xen_banner(void) {return XEN_BANNER ; } + +const char *xen_deny (void ) +{ +return "<denied>" ; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
xen/include/xen/version.h +1 -0
@@ -12,5 +12,6 @@ unsigned int xen_minor_version(void);const char *xen_extra_version (void );const char *xen_changeset (void );const char *xen_banner (void ); +const char *xen_deny (void );#endif /* __XEN_VERSION_H__ */
xen/include/xsm/dummy.h +24 -0
@@ -727,3 +727,27 @@ static XSM_INLINE int xsm_pmu_op (XSM_DEFAULT_ARG struct domain *d, unsigned int }#endif /* CONFIG_X86 */ + +#include <public/version.h> +static XSM_INLINE int xsm_xen_version (XSM_DEFAULT_ARG uint32_t op) +{ +XSM_ASSERT_ACTION (XSM_OTHER ); +switch ( op ) + { +case XENVER_version: +case XENVER_platform_parameters: +case XENVER_get_features: +/* The sub-ops ignores the permission check and returns data. */ +return 0 ; +case XENVER_extraversion: +case XENVER_compile_info: +case XENVER_capabilities: +case XENVER_changeset: +case XENVER_pagesize: +case XENVER_guest_handle: +/* These MUST always be accessible to any guest by default. */ +return xsm_default_action (XSM_HOOK , current->domain,NULL ); +default : +return xsm_default_action (XSM_PRIV , current->domain,NULL ); + } +}
xen/include/xsm/xsm.h +5 -0
@@ -193,6 +193,7 @@ struct xsm_operations {int (*ioport_mapping) (struct domain *d,uint32_t s,uint32_t e,uint8_t allow);int (*pmu_op) (struct domain *d,unsigned int op);#endif +int (*xen_version) (uint32_t cmd); };#ifdef CONFIG_XSM
@@ -731,6 +732,10 @@ static inline int xsm_pmu_op (xsm_default_t def, struct domain *d, unsigned int#endif /* CONFIG_X86 */ +static inline int xsm_xen_version (xsm_default_t def,uint32_t op) +{ +return xsm_ops->xen_version (op); +}#endif /* XSM_NO_WRAPPERS */ #ifdef CONFIG_MULTIBOOT
xen/xsm/dummy.c +1 -0
@@ -162,4 +162,5 @@ void xsm_fixup_ops (struct xsm_operations *ops)set_to_dummy_if_null (ops, ioport_mapping);set_to_dummy_if_null (ops, pmu_op);#endif +set_to_dummy_if_null (ops, xen_version); }
xen/xsm/flask/hooks.c +39 -0
@@ -26,6 +26,7 @@#include <public/xen.h> #include <public/physdev.h> #include <public/platform.h> +#include <public/version.h> #include <public/xsm/flask_op.h>
@@ -1620,6 +1621,43 @@ static int flask_pmu_op (struct domain *d, unsigned int op) }#endif /* CONFIG_X86 */ +static int flask_xen_version (uint32_t op) +{ +u32 dsid =domain_sid (current->domain); + +switch ( op ) + { +case XENVER_version: +case XENVER_platform_parameters: +case XENVER_get_features: +/* The sub-ops ignore the permission check and always return data. */ +return 0 ; +case XENVER_extraversion: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__XEN_EXTRAVERSION ,NULL ); +case XENVER_compile_info: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__XEN_COMPILE_INFO ,NULL ); +case XENVER_capabilities: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__XEN_CAPABILITIES ,NULL ); +case XENVER_changeset: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__XEN_CHANGESET ,NULL ); +case XENVER_pagesize: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__XEN_PAGESIZE ,NULL ); +case XENVER_guest_handle: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__XEN_GUEST_HANDLE ,NULL ); +case XENVER_commandline: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__XEN_COMMANDLINE ,NULL ); +default : +return -EPERM ; + } +} +long do_flask_op (XEN_GUEST_HANDLE_PARAM (xsm_op_t) u_flask_op);int compat_flask_op (XEN_GUEST_HANDLE_PARAM (xsm_op_t) u_flask_op);
@@ -1758,6 +1796,7 @@ static struct xsm_operations flask_ops = { .ioport_mapping = flask_ioport_mapping, .pmu_op = flask_pmu_op, #endif + .xen_version = flask_xen_version, };static __init void flask_init (void )
xen/xsm/flask/policy/access_vectors +25 -0
@@ -495,3 +495,28 @@ class security # remove ocontext label definitions for resources del_ocontext } + +# Class version is used to describe the XENVER_ hypercall. +# Almost all sub-ops are described here - in the default case all of them should +# be allowed except the XENVER_commandline. +# +# The ones that are omitted are XENVER_version, XENVER_platform_parameters, +# and XENVER_get_features - as they MUST always be returned to a guest. +# +class version +{ +# Extra informations (-unstable). + xen_extraversion +# Compile information of the hypervisor. + xen_compile_info +# Such as "xen-3.0-x86_64 xen-3.0-x86_32p hvm-3.0-x86_32 hvm-3.0-x86_32p hvm-3.0-x86_64". + xen_capabilities +# Source code changeset. + xen_changeset +# Page size the hypervisor uses. + xen_pagesize +# An value that the control stack can choose. + xen_guest_handle +# Xen command line. + xen_commandline +}
xen/xsm/flask/policy/security_classes +1 -0
@@ -18,5 +18,6 @@ class shadow class event class grant class security +class version # FLASK
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v4 03/34] xsm/xen_version: Add XSM for the xen_version hypercall
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 18.03.16 at 18:26, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
Review void __init do_initcalls(void) · line 227
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 15.03.16 at 18:56, <[email protected]> wrote:
(quoted diff) +0
-1@@ -223,12 +224,15 @@ void __init do_initcalls(void) /* * Simple hypercalls. */ - DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)Please retain the blank line, as it relates to more than just this one function.
Quoted 1 line
Done! (stray change).
Considering this I'm not puzzled by ...
Quoted 8 lines
case
XENVER_guest_handle:xen/common/kernel.c +5
-2-if (copy_to_guest (arg, current->domain->handle, -ARRAY_SIZE (current->domain->handle)) ) + { +xen_domain_handle_t hdl; + +if ( deny ) +memset (&hdl,0 ,ARRAY_SIZE (hdl));
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 367
Quoted 10 lines
xen/common/kernel.c +6
-1+ +BUILD_BUG_ON (ARRAY_SIZE (current->domain->handle) !=ARRAY_SIZE (hdl)); + +if (copy_to_guest (arg, deny ? hdl : current->domain->handle, +ARRAY_SIZE (hdl) ) )return -EFAULT ;return 0 ; - + }case XENVER_commandline:
... this.
Quoted 7 lines
xen/include/xsm/dummy.h +1
-0@@ -727,3 +727,27 @@ static XSM_INLINE int xsm_pmu_op (XSM_DEFAULT_ARG struct domain *d, unsigned int }#endif /* CONFIG_X86 */ +
xen/include/xsm/dummy.h static XSM_INLINE int xsm_pmu_op (XSM_DEFAULT_ARG struct domain *d, unsigned int · line 740
Quoted 10 lines
xen/include/xsm/dummy.h +10
-0+#include <public/version.h> +static XSM_INLINE int xsm_xen_version (XSM_DEFAULT_ARG uint32_t op) +{ +XSM_ASSERT_ACTION (XSM_OTHER ); +switch ( op ) + { +case XENVER_version: +case XENVER_platform_parameters: +case XENVER_get_features: +/* The sub-ops ignores the permission check and returns data. */
ignore ... and return ...
With those minor things addressed I think the patch can have my ack.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Konrad Rzeszutek Wilk
Acked-by Jan BeulichRe: [PATCH v4 03/34] xsm/xen_version: Add XSM for the xen_version hypercall
Quoted 29 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 18.03.16 at 18:26, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
Review void __init do_initcalls(void) · line 227
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 15.03.16 at 18:56, <[email protected]> wrote:
(quoted diff) +0
-1@@ -223,12 +224,15 @@ void __init do_initcalls(void) /* * Simple hypercalls. */ - DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)Please retain the blank line, as it relates to more than just this one function.
Quoted 1 line
Done! (stray change).
Considering this I'm not puzzled by ...
Quoted 12 lines
case
XENVER_guest_handle:(quoted diff) +9
-2- if ( copy_to_guest(arg, current->domain->handle, - ARRAY_SIZE(current->domain->handle)) ) + { + xen_domain_handle_t hdl; + + if ( deny ) + memset(&hdl, 0, ARRAY_SIZE(hdl)); + + BUILD_BUG_ON(ARRAY_SIZE(current->domain->handle) != ARRAY_SIZE(hdl)); + + if ( copy_to_guest(arg, deny ? hdl : current->domain->handle,
Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +2
-1+ ARRAY_SIZE(hdl) ) ) return -EFAULT; return 0; - + } case XENVER_commandline:... this.
Wow. That is some sharp eyes!
Quoted 21 lines
Quoted 8 lines
xen/include/xsm/dummy.h +1
-0@@ -727,3 +727,27 @@ static XSM_INLINE int xsm_pmu_op (XSM_DEFAULT_ARG struct domain *d, unsigned int }#endif /* CONFIG_X86 */ +xen/include/xsm/dummy.h static XSM_INLINE int xsm_pmu_op (XSM_DEFAULT_ARG struct domain *d, unsigned int · line 740
Quoted 10 lines
xen/include/xsm/dummy.h +10
-0+#include <public/version.h> +static XSM_INLINE int xsm_xen_version (XSM_DEFAULT_ARG uint32_t op) +{ +XSM_ASSERT_ACTION (XSM_OTHER ); +switch ( op ) + { +case XENVER_version: +case XENVER_platform_parameters: +case XENVER_get_features: +/* The sub-ops ignores the permission check and returns data. */ ignore ... and return ...
Quoted 1 line
With those minor things addressed I think the patch can have my ack.
Thank you!
Now I just need Daniel's Ack again.
From 1ccf59abdd2cd9228f0159dce77fe404d98c7300 Mon Sep 17 00:00:00 2001
From: Konrad Rzeszutek Wilk <[email protected]>
Date: Fri, 11 Mar 2016 21:40:43 -0500
Subject: [PATCH] xsm/xen_version: Add XSM for most of xen_version hypercall
Most of XENVER_* have now an XSM check for their sub-ops.
The subop for XENVER_commandline is now a priviliged operation. To not break guests we still return an string - but it is just '<denied>\0'.
The XENVER_[version|platform_parameters|get_features] - will always return an value to the guest.
The rest: XENVER_[extraversion|capabilities|page_size| guest_handle|changeset| compile_info] behave as before - allowed by default for all guests if using the XSM default policy or with the dummy one. And if the system admin wants to curtail access to some of them - they can do that now with a non-default XSM policy.
Also we add a local variable block.
---
Cc: Daniel De Graaf <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Wei Liu <[email protected]>
v2: Do XSM check for all the XENVER_ ops.
- Add empty data conditions.
- Return <denied> for priv subops.
- Move extraversion from priv to normal. Drop the XSM check for the non-priv subops.
v3:
- Add +1 for strlen(xen_deny()) to include NULL. Move changeset, compile_info to non-priv subops.
- Remove the \0 on xen_deny()
- Add new XSM domain for xenver hypercall. Add all subops to it.
- Remove the extra line, Add Ack from Daniel
v4:
- Rename the XSM from xen_version_op to xsm_xen_version. Prefix the types with 'xen' to distinguish it from another hypercall performing similar operation. Removed Ack from Daniel as it was so large. Add local variable block.
v5:
- Make XENVER_platform_parameters,get_features,version be excluded from the XSM check per Jans' review. Add BUILD_BUG_CHECK and fix odd line removals. Remove stray changes and fix spelling.
--- tools/flask/policy/policy/modules/xen/xen.te | 14 ++++++++++ xen/common/kernel.c | 42 +++++++++++++++++++++------- xen/common/version.c | 15 ++++++++++ xen/include/xen/version.h | 1 + xen/include/xsm/dummy.h | 24 ++++++++++++++++ xen/include/xsm/xsm.h | 6 ++++ xen/xsm/dummy.c | 1 + xen/xsm/flask/hooks.c | 39 ++++++++++++++++++++++++++ xen/xsm/flask/policy/access_vectors | 25 +++++++++++++++++ xen/xsm/flask/policy/security_classes | 1 + 10 files changed, 158 insertions(+), 10 deletions(-)
tools/flask/policy/policy/modules/xen/xen.te +14 -0
@@ -73,6 +73,14 @@ allow dom0_t xen_t:xen2 { pmu_ctrl get_symbol }; + +# Allow dom0 to use all XENVER_ subops that have checks. +# Note that dom0 is part of domain_type so this has duplicates. +allow dom0_t xen_t:version { + xen_extraversion xen_compile_info xen_capabilities + xen_changeset xen_pagesize xen_guest_handle xen_commandline +}; + allow dom0_t xen_t:mmu memorymap; # Allow dom0 to use these domctls on itself. For domctls acting on other
@@ -137,6 +145,12 @@ if (guest_writeconsole) { # pmu_ctrl is for) allow domain_type xen_t:xen2 pmu_use; +# For normal guests all possible except XENVER_commandline. +allow domain_type xen_t:version { + xen_extraversion xen_compile_info xen_capabilities + xen_changeset xen_pagesize xen_guest_handle +}; + ############################################################################### # # Domain creation
xen/common/kernel.c +32 -10
94 lines not on this page · raw message
xen/common/version.c +15 -0
@@ -55,3 +55,18 @@ const char *xen_banner(void) {return XEN_BANNER ; } + +const char *xen_deny (void ) +{ +return "<denied>" ; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
xen/include/xen/version.h +1 -0
@@ -12,5 +12,6 @@ unsigned int xen_minor_version(void);const char *xen_extra_version (void );const char *xen_changeset (void );const char *xen_banner (void ); +const char *xen_deny (void );#endif /* __XEN_VERSION_H__ */
xen/include/xsm/dummy.h +24 -0
@@ -727,3 +727,27 @@ static XSM_INLINE int xsm_pmu_op (XSM_DEFAULT_ARG struct domain *d, unsigned int }#endif /* CONFIG_X86 */ + +#include <public/version.h> +static XSM_INLINE int xsm_xen_version (XSM_DEFAULT_ARG uint32_t op) +{ +XSM_ASSERT_ACTION (XSM_OTHER ); +switch ( op ) + { +case XENVER_version: +case XENVER_platform_parameters: +case XENVER_get_features: +/* These sub-ops ignore the permission checks and return data. */ +return 0 ; +case XENVER_extraversion: +case XENVER_compile_info: +case XENVER_capabilities: +case XENVER_changeset: +case XENVER_pagesize: +case XENVER_guest_handle: +/* These MUST always be accessible to any guest by default. */ +return xsm_default_action (XSM_HOOK , current->domain,NULL ); +default : +return xsm_default_action (XSM_PRIV , current->domain,NULL ); + } +}
xen/include/xsm/xsm.h +6 -0
@@ -193,6 +193,7 @@ struct xsm_operations {int (*ioport_mapping) (struct domain *d,uint32_t s,uint32_t e,uint8_t allow);int (*pmu_op) (struct domain *d,unsigned int op);#endif +int (*xen_version) (uint32_t cmd); };#ifdef CONFIG_XSM
@@ -731,6 +732,11 @@ static inline int xsm_pmu_op (xsm_default_t def, struct domain *d, unsigned int#endif /* CONFIG_X86 */ +static inline int xsm_xen_version (xsm_default_t def,uint32_t op) +{ +return xsm_ops->xen_version (op); +} +#endif /* XSM_NO_WRAPPERS */ #ifdef CONFIG_MULTIBOOT
xen/xsm/dummy.c +1 -0
@@ -162,4 +162,5 @@ void xsm_fixup_ops (struct xsm_operations *ops)set_to_dummy_if_null (ops, ioport_mapping);set_to_dummy_if_null (ops, pmu_op);#endif +set_to_dummy_if_null (ops, xen_version); }
xen/xsm/flask/hooks.c +39 -0
@@ -26,6 +26,7 @@#include <public/xen.h> #include <public/physdev.h> #include <public/platform.h> +#include <public/version.h> #include <public/xsm/flask_op.h>
@@ -1620,6 +1621,43 @@ static int flask_pmu_op (struct domain *d, unsigned int op) }#endif /* CONFIG_X86 */ +static int flask_xen_version (uint32_t op) +{ +u32 dsid =domain_sid (current->domain); + +switch ( op ) + { +case XENVER_version: +case XENVER_platform_parameters: +case XENVER_get_features: +/* These sub-ops ignore the permission checks and return data. */ +return 0 ; +case XENVER_extraversion: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__XEN_EXTRAVERSION ,NULL ); +case XENVER_compile_info: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__XEN_COMPILE_INFO ,NULL ); +case XENVER_capabilities: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__XEN_CAPABILITIES ,NULL ); +case XENVER_changeset: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__XEN_CHANGESET ,NULL ); +case XENVER_pagesize: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__XEN_PAGESIZE ,NULL ); +case XENVER_guest_handle: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__XEN_GUEST_HANDLE ,NULL ); +case XENVER_commandline: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__XEN_COMMANDLINE ,NULL ); +default : +return -EPERM ; + } +} +long do_flask_op (XEN_GUEST_HANDLE_PARAM (xsm_op_t) u_flask_op);int compat_flask_op (XEN_GUEST_HANDLE_PARAM (xsm_op_t) u_flask_op);
@@ -1758,6 +1796,7 @@ static struct xsm_operations flask_ops = { .ioport_mapping = flask_ioport_mapping, .pmu_op = flask_pmu_op, #endif + .xen_version = flask_xen_version, };static __init void flask_init (void )
xen/xsm/flask/policy/access_vectors +25 -0
@@ -495,3 +495,28 @@ class security # remove ocontext label definitions for resources del_ocontext } + +# Class version is used to describe the XENVER_ hypercall. +# Almost all sub-ops are described here - in the default case all of them should +# be allowed except the XENVER_commandline. +# +# The ones that are omitted are XENVER_version, XENVER_platform_parameters, +# and XENVER_get_features - as they MUST always be returned to a guest. +# +class version +{ +# Extra informations (-unstable). + xen_extraversion +# Compile information of the hypervisor. + xen_compile_info +# Such as "xen-3.0-x86_64 xen-3.0-x86_32p hvm-3.0-x86_32 hvm-3.0-x86_32p hvm-3.0-x86_64". + xen_capabilities +# Source code changeset. + xen_changeset +# Page size the hypervisor uses. + xen_pagesize +# An value that the control stack can choose. + xen_guest_handle +# Xen command line. + xen_commandline +}
xen/xsm/flask/policy/security_classes +1 -0
@@ -18,5 +18,6 @@ class shadow class event class grant class security +class version # FLASK
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Daniel De Graaf
Acked-byRe: [PATCH v4 03/34] xsm/xen_version: Add XSM for the xen_version hypercall
Quoted 88 lines · Konrad Rzeszutek Wilk
Quoted 29 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 18.03.16 at 18:26, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
Review void __init do_initcalls(void) · line 227
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 15.03.16 at 18:56, <[email protected]> wrote:
(quoted diff) +0
-1@@ -223,12 +224,15 @@ void __init do_initcalls(void) /* * Simple hypercalls. */ - DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)Please retain the blank line, as it relates to more than just this one function.
Quoted 1 line
Done! (stray change).
Considering this I'm not puzzled by ...
Quoted 12 lines
case
XENVER_guest_handle:xen/common/kernel.c +9
-2-if (copy_to_guest (arg, current->domain->handle, -ARRAY_SIZE (current->domain->handle)) ) + { +xen_domain_handle_t hdl; + +if ( deny ) +memset (&hdl,0 ,ARRAY_SIZE (hdl)); + +BUILD_BUG_ON (ARRAY_SIZE (current->domain->handle) !=ARRAY_SIZE (hdl)); + + if ( copy_to_guest(arg, deny ? hdl : current->domain->handle,Quoted 8 lines
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 368
Quoted 6 lines
xen/common/kernel.c +2
-1+ ARRAY_SIZE(hdl) ) )return -EFAULT ;return 0 ; - + }case XENVER_commandline:... this.
Wow. That is some sharp eyes!
Quoted 21 lines
Quoted 8 lines
xen/include/xsm/dummy.h +1
-0@@ -727,3 +727,27 @@ static XSM_INLINE int xsm_pmu_op (XSM_DEFAULT_ARG struct domain *d, unsigned int }#endif /* CONFIG_X86 */ +xen/include/xsm/dummy.h static XSM_INLINE int xsm_pmu_op (XSM_DEFAULT_ARG struct domain *d, unsigned int · line 740
Quoted 10 lines
xen/include/xsm/dummy.h +10
-0+#include <public/version.h> +static XSM_INLINE int xsm_xen_version (XSM_DEFAULT_ARG uint32_t op) +{ +XSM_ASSERT_ACTION (XSM_OTHER ); +switch ( op ) + { +case XENVER_version: +case XENVER_platform_parameters: +case XENVER_get_features: +/* The sub-ops ignores the permission check and returns data. */ ignore ... and return ...
Quoted 1 line
With those minor things addressed I think the patch can have my ack.
Thank you!
Now I just need Daniel's Ack again.
Quoted 1 line
From
1ccf59abdd2cd9228f0159dce77fe404d98c7300Mon Sep 17 00:00:00 2001From: Konrad Rzeszutek Wilk <[email protected]>
Date: Fri, 11 Mar 2016 21:40:43 -0500
Subject: [PATCH] xsm/xen_version: Add XSM for most ofxen_versionhypercallMost of XENVER_* have now an XSM check for their sub-ops.
The subop for
XENVER_commandlineis now a priviliged operation. To not break guests we still return an string - but it is just '<denied>\0'.The XENVER_[version|platform_parameters|get_features] - will always return an value to the guest.
The rest: XENVER_[extraversion|capabilities|page_size| guest_handle|changeset|
compile_info] behave as before - allowed by default for all guests if using the XSM default policy or with the dummy one. And if the system admin wants to curtail access to some of them - they can do that now with a non-default XSM policy.
Quoted 4 lines
Also we add a local variable block.
Signed-off-by Konrad Rzeszutek Wilk <[email protected]>Acked-by Jan Beulich <[email protected]>
Replied to the wrong email before; this one is actually:
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 03/34] xsm/xen_version: Add XSM for the xen_version hypercall
In reply to Konrad Rzeszutek WilkQuoted 11 lines · Konrad Rzeszutek Wilk
All of XENVER_* have now an XSM check for their sub-ops.
The subop for
XENVER_commandlineis now a priviliged operation. To not break guests we still return an string - but it is just '<denied>\0'.The rest: XENVER_[version|extraversion|capabilities| parameters|get_features|page_size|guest_handle|changeset|
compile_info] behave as before - allowed by default for all guests if using the XSM default policy or with the dummy one.
Quoted 6 lines
The admin can choose to change the sub-ops to be denied as they see fit.
Also we add a local variable block.
Signed-off-by Konrad Rzeszutek Wilk <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 03/34] xsm/xen_version: Add XSM for the xen_version hypercall
In reply to Konrad Rzeszutek WilkQuoted 425 lines · Konrad Rzeszutek Wilk
All of XENVER_* have now an XSM check for their sub-ops.
The subop for
XENVER_commandlineis now a priviliged operation. To not break guests we still return an string - but it is just '<denied>\0'.The rest: XENVER_[version|extraversion|capabilities| parameters|get_features|page_size|guest_handle|changeset|
compile_info] behave as before - allowed by default for all guests if using the XSM default policy or with the dummy one.The admin can choose to change the sub-ops to be denied as they see fit.
Also we add a local variable block.
Signed-off-by Konrad Rzeszutek Wilk <[email protected]>---
Cc: Daniel De Graaf <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Wei Liu <[email protected]>v2: Do XSM check for all the
XENVER_ops.
v3: Add empty data conditions.
v4: Return <denied> for priv subops.
v5: Move extraversion from priv to normal. Drop the XSM check
for the non-priv subops.
v6: Add +1 for strlen(xen_deny()) to include NULL. Move changeset,
compile_infoto non-priv subops.
v7: Remove the \0 onxen_deny()
v8: Add new XSM domain for xenver hypercall. Add all subops to it.
v9: Remove the extra line, Add Ack from Daniel
v10: Rename the XSM fromxen_version_optoxsm_xen_version.
Prefix the types with 'xen' to distinguish it from another hypercall performing similar operation. Removed Ack from Daniel as it was so large. Add local variable block.--- tools/flask/policy/policy/modules/xen/xen.te | 15 ++++++++ xen/common/kernel.c | 53 +++++++++++++++++++++------- xen/common/version.c | 15 ++++++++ xen/include/xen/version.h | 2 +- xen/include/xsm/dummy.h | 22 ++++++++++++ xen/include/xsm/xsm.h | 5 +++ xen/xsm/dummy.c | 1 + xen/xsm/flask/hooks.c | 43 ++++++++++++++++++++++ xen/xsm/flask/policy/access_vectors | 28 +++++++++++++++ xen/xsm/flask/policy/security_classes | 1 + 10 files changed, 172 insertions(+), 13 deletions(-)tools/flask/policy/policy/modules/xen/xen.te +15
-0@@ -73,6 +73,15 @@ allow dom0_t xen_t:xen2 { pmu_ctrl get_symbol }; + +# Allow dom0 to use all XENVER_ subops +# Note that dom0 is part of domain_type so this has duplicates. +allow dom0_t xen_t:version { + xen_version xen_extraversion xen_compile_info xen_capabilities + xen_changeset xen_platform_parameters xen_get_features xen_pagesize + xen_guest_handle xen_commandline +}; + allow dom0_t xen_t:mmu memorymap; # Allow dom0 to use these domctls on itself. For domctls acting on other@@ -137,6 +146,12 @@ if (guest_writeconsole) { # pmu_ctrl is for) allow domain_type xen_t:xen2 pmu_use; +# For normal guests all except XENVER_commandline +allow domain_type xen_t:version { + xen_version xen_extraversion xen_compile_info xen_capabilities + xen_changeset xen_platform_parameters xen_get_features xen_pagesize + xen_guest_handle +}; ############################################################################### # # Domain creationxen/common/kernel.c +41
-12@@ -13,6 +13,7 @@#include <xen/nmi.h> #include <xen/guest_access.h> #include <xen/hypercall.h> +#include <xsm/xsm.h> #include <asm/current.h> #include <public/nmi.h> #include <public/version.h> @@ -223,12 +224,15 @@ void __init do_initcalls(void)/* * Simple hypercalls. */ -DO (xen_version)(int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) { +bool_t deny = !!xsm_xen_version (XSM_OTHER , cmd); +switch ( cmd ) {case XENVER_version: +if ( deny ) +return 0 ;return (xen_major_version () <<16 ) |xen_minor_version ();case XENVER_extraversion:@@ -236,7 +240,7 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)xen_extraversion_t extraversion;memset (extraversion,0 ,sizeof (extraversion)); -safe_strcpy (extraversion,xen_extra_version ()); +safe_strcpy (extraversion, deny ?xen_deny () :xen_extra_version ());if (copy_to_guest (arg, extraversion,ARRAY_SIZE (extraversion)) )return -EFAULT ;return 0 ;@@ -247,10 +251,10 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)xen_compile_info_t info;memset (&info,0 ,sizeof (info)); -safe_strcpy (info.compiler,xen_compiler ()); -safe_strcpy (info.compile_by,xen_compile_by ()); -safe_strcpy (info.compile_domain,xen_compile_domain ()); -safe_strcpy (info.compile_date,xen_compile_date ()); +safe_strcpy (info.compiler, deny ?xen_deny () :xen_compiler ()); +safe_strcpy (info.compile_by, deny ?xen_deny () :xen_compile_by ()); +safe_strcpy (info.compile_domain, deny ?xen_deny () :xen_compile_domain ()); +safe_strcpy (info.compile_date, deny ?xen_deny () :xen_compile_date ());if (copy_to_guest (arg, &info,1 ) )return -EFAULT ;return 0 ;@@ -261,7 +265,8 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)xen_capabilities_info_t info;memset (info,0 ,sizeof (info)); -arch_get_xen_caps (&info); +if ( !deny ) +arch_get_xen_caps (&info);if (copy_to_guest (arg, info,ARRAY_SIZE (info)) )return -EFAULT ;@@ -274,6 +279,9 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) .virt_start = HYPERVISOR_VIRT_START }; +if ( deny ) + params.virt_start =0 ; +if (copy_to_guest (arg, ¶ms,1 ) )return -EFAULT ;return 0 ;@@ -285,7 +293,7 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)xen_changeset_info_t chgset;memset (chgset,0 ,sizeof (chgset)); -safe_strcpy (chgset,xen_changeset ()); +safe_strcpy (chgset, deny ?xen_deny () :xen_changeset ());if (copy_to_guest (arg, chgset,ARRAY_SIZE (chgset)) )return -EFAULT ;return 0 ;@@ -302,6 +310,8 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)switch ( fi.submap_idx ) {case 0 : +if ( deny ) +break ; fi.submap = (1U << XENFEAT_memory_op_vnode_supported);if (VM_ASSIST (d, pae_extended_cr3) ) fi.submap |= (1U << XENFEAT_pae_pgdir_above_4gb);@@ -342,19 +352,38 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) }case XENVER_pagesize: +if ( deny ) +return 0 ;return (!guest_handle_is_null (arg) ? -EINVAL :PAGE_SIZE );case XENVER_guest_handle: -if (copy_to_guest (arg, current->domain->handle, -ARRAY_SIZE (current->domain->handle)) ) + { +xen_domain_handle_t hdl; +ssize_t len; + +if ( deny ) + { + len =sizeof (hdl); +memset (&hdl,0 , len); + }else + len =ARRAY_SIZE (current->domain->handle); + +if (copy_to_guest (arg, deny ? hdl : current->domain->handle, len ) )return -EFAULT ;return 0 ; - + }case XENVER_commandline: -if (copy_to_guest (arg, saved_cmdline,ARRAY_SIZE (saved_cmdline)) ) + { +size_t len =ARRAY_SIZE (saved_cmdline); + +if ( deny ) + len =strlen (xen_deny ()) +1 ; + +if (copy_to_guest (arg, deny ?xen_deny () : saved_cmdline, len) )return -EFAULT ;return 0 ; } + }return -ENOSYS ; }xen/common/version.c +15
-0@@ -55,3 +55,18 @@ const char *xen_banner(void) {return XEN_BANNER ; } + +const char *xen_deny (void ) +{ +return "<denied>" ; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/ xen/include/xen/version.h +1
-1@@ -12,5 +12,5 @@ unsigned int xen_minor_version(void);const char *xen_extra_version (void );const char *xen_changeset (void );const char *xen_banner (void ); - +const char *xen_deny (void );#endif /* __XEN_VERSION_H__ */ xen/include/xsm/dummy.h +22
-0@@ -727,3 +727,25 @@ static XSM_INLINE int xsm_pmu_op (XSM_DEFAULT_ARG struct domain *d, unsigned int }#endif /* CONFIG_X86 */ + +#include <public/version.h> +static XSM_INLINE int xsm_xen_version (XSM_DEFAULT_ARG uint32_t op) +{ +XSM_ASSERT_ACTION (XSM_OTHER ); +switch ( op ) + { +case XENVER_version: +case XENVER_extraversion: +case XENVER_compile_info: +case XENVER_capabilities: +case XENVER_changeset: +case XENVER_platform_parameters: +case XENVER_get_features: +case XENVER_pagesize: +case XENVER_guest_handle: +/* These MUST always be accessible to any guest by default. */ +return xsm_default_action (XSM_HOOK , current->domain,NULL ); +default : +return xsm_default_action (XSM_PRIV , current->domain,NULL ); + } +}xen/include/xsm/xsm.h +5
-0@@ -193,6 +193,7 @@ struct xsm_operations {int (*ioport_mapping) (struct domain *d,uint32_t s,uint32_t e,uint8_t allow);int (*pmu_op) (struct domain *d,unsigned int op);#endif +int (*xen_version) (uint32_t cmd); };#ifdef CONFIG_XSM @@ -731,6 +732,10 @@ static inline int xsm_pmu_op (xsm_default_t def, struct domain *d, unsigned int#endif /* CONFIG_X86 */ +static inline int xsm_xen_version (xsm_default_t def,uint32_t op) +{ +return xsm_ops->xen_version (op); +}#endif /* XSM_NO_WRAPPERS */ #ifdef CONFIG_MULTIBOOT xen/xsm/dummy.c +1
-0@@ -162,4 +162,5 @@ void xsm_fixup_ops (struct xsm_operations *ops)set_to_dummy_if_null (ops, ioport_mapping);set_to_dummy_if_null (ops, pmu_op);#endif +set_to_dummy_if_null (ops, xen_version); }xen/xsm/flask/hooks.c +43
-0@@ -26,6 +26,7 @@#include <public/xen.h> #include <public/physdev.h> #include <public/platform.h> +#include <public/version.h> #include <public/xsm/flask_op.h> @@ -1620,6 +1621,47 @@ static int flask_pmu_op (struct domain *d, unsigned int op) }#endif /* CONFIG_X86 */ +static int flask_xen_version (uint32_t op) +{ +u32 dsid =domain_sid (current->domain); + +switch ( op ) + { +case XENVER_version: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__XEN_VERSION ,NULL ); +case XENVER_extraversion: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__XEN_EXTRAVERSION ,NULL ); +case XENVER_compile_info: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__XEN_COMPILE_INFO ,NULL ); +case XENVER_capabilities: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__XEN_CAPABILITIES ,NULL ); +case XENVER_changeset: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__XEN_CHANGESET ,NULL ); +case XENVER_platform_parameters: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__XEN_PLATFORM_PARAMETERS ,NULL ); +case XENVER_get_features: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__XEN_GET_FEATURES ,NULL ); +case XENVER_pagesize: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__XEN_PAGESIZE ,NULL ); +case XENVER_guest_handle: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__XEN_GUEST_HANDLE ,NULL ); +case XENVER_commandline: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__XEN_COMMANDLINE ,NULL ); +default : +return -EPERM ; + } +} +long do_flask_op (XEN_GUEST_HANDLE_PARAM (xsm_op_t) u_flask_op);int compat_flask_op (XEN_GUEST_HANDLE_PARAM (xsm_op_t) u_flask_op);@@ -1758,6 +1800,7 @@ static struct xsm_operations flask_ops = { .ioport_mapping = flask_ioport_mapping, .pmu_op = flask_pmu_op, #endif + .xen_version = flask_xen_version, };static __init void flask_init (void )xen/xsm/flask/policy/access_vectors +28
-0@@ -495,3 +495,31 @@ class security # remove ocontext label definitions for resources del_ocontext } + +# Class version is used to describe the XENVER_ hypercall. +# Each sub-ops is described here - in the default case all of them should +# be allowed except the XENVER_commandline. +# +class version +{ +# Often called by PV kernels to force an callback. + xen_version +# Extra informations (-unstable). + xen_extraversion +# Compile information of the hypervisor. + xen_compile_info +# Such as "xen-3.0-x86_64 xen-3.0-x86_32p hvm-3.0-x86_32 hvm-3.0-x86_32p hvm-3.0-x86_64". + xen_capabilities +# Such as the virtual address of where the hypervisor resides. + xen_platform_parameters +# Source code changeset. + xen_changeset +# The features the hypervisor supports. + xen_get_features +# Page size the hypervisor uses. + xen_pagesize +# An value that the control stack can choose. + xen_guest_handle +# Xen command line. + xen_commandline +}xen/xsm/flask/policy/security_classes +0
-0
xen/xsm/flask/policy/security_classes class shadow · line 23
Quoted 6 lines
xen/xsm/flask/policy/security_classes +1
-0@@ -18,5 +18,6 @@ class shadow class event class grant class security +class version # FLASK
Can we have more meaningful name for XSM class. "version" doesn't seem to be informative enough to convey the message as to why we need it to be secure. (Is it a resource, or domain specific or event or...)
My suggestion would be xenmetainfo or something more meaningful.
Anshul
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 03/34] xsm/xen_version: Add XSM for the xen_version hypercall
Quoted 10 lines
Quoted 10 lines
xen/xsm/flask/policy/security_classes +1
-0@@ -18,5 +18,6 @@ class shadow class event class grant class security +class version
Quoted 5 lines
xen/xsm/flask/policy/security_classes class shadow · line 23
Quoted 2 lines
xen/xsm/flask/policy/security_classes +0
-0# FLASKCan we have more meaningful name for XSM class. "version" doesn't seem to be informative enough to convey the message as to why we need it to be secure. (Is it a resource, or domain specific or event or...)
Heya!
1). Please trim your replies.
2). The patch is already in the tree.
3). If you prefer a different name - by all means please submit a patch for that.
I am all up for it.
Quoted 2 lines
My suggestion would be xenmetainfo or something more meaningful.
/me blinks
Metainfo? I am not sure how one is suppose to associate that with features that the hypervisor is exposing to guests.
Quoted 3 lines
Anshul
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v4 4/34 HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.
In reply to Konrad Rzeszutek WilkThis hypercall mirrors the XENVER_ in that it has similar functionality. However it is designed differently:
- No compat layer. The data structures are the same size on 32 as on 64-bit.
- The hypercall accepts three arguments - the command, pointer to an buffer, and the length of the buffer.
- Each sub-ops can be "probed" for size by returning the size of buffer that will be needed - if the buffer is NULL.
- Subops can complete even if the buffer is too slow - truncated data will be filled and hypercall will return -ENOBUFS.
- VERSION_OP_commandline, VERSION_OP_changeset are privileged.
- There are no XENVER_compile_info equivalent.
- The hypercall can return -EPERM and toolstack/OSes are expected to deal with it.
---
Cc: Daniel De Graaf <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
---
--- tools/flask/policy/policy/modules/xen/xen.te | 9 +- xen/arch/arm/traps.c | 1 + xen/arch/x86/hvm/hvm.c | 1 + xen/arch/x86/x86_64/compat/entry.S | 2 + xen/arch/x86/x86_64/entry.S | 2 + xen/common/compat/kernel.c | 3 + xen/common/kernel.c | 265 +++++++++++++++++++++++---- xen/include/public/arch-arm.h | 3 + xen/include/public/version.h | 72 +++++++- xen/include/public/xen.h | 1 + xen/include/xen/hypercall.h | 4 + xen/include/xsm/dummy.h | 19 ++ xen/include/xsm/xsm.h | 7 + xen/xsm/dummy.c | 1 + xen/xsm/flask/hooks.c | 39 ++++ xen/xsm/flask/policy/access_vectors | 24 ++- 16 files changed, 410 insertions(+), 43 deletions(-)
tools/flask/policy/policy/modules/xen/xen.te +7 -2
@@ -74,12 +74,14 @@ allow dom0_t xen_t:xen2 { get_symbol }; -# Allow dom0 to use all XENVER_ subops +# Allow dom0 to use all XENVER_ subops and VERSION_OP subops # Note that dom0 is part of domain_type so this has duplicates. allow dom0_t xen_t:version { xen_version xen_extraversion xen_compile_info xen_capabilities xen_changeset xen_platform_parameters xen_get_features xen_pagesize xen_guest_handle xen_commandline + version extraversion capabilities changeset platform_parameters + get_features pagesize guest_handle commandline }; allow dom0_t xen_t:mmu memorymap;
@@ -146,11 +148,14 @@ if (guest_writeconsole) { # pmu_ctrl is for) allow domain_type xen_t:xen2 pmu_use; -# For normal guests all except XENVER_commandline +# For normal guests all except XENVER_commandline, VERSION_OP_changeset, +# and VERSION_OP_commandline allow domain_type xen_t:version { xen_version xen_extraversion xen_compile_info xen_capabilities xen_changeset xen_platform_parameters xen_get_features xen_pagesize xen_guest_handle + version extraversion capabilities platform_parameters + get_features pagesize guest_handle }; ############################################################################### #
xen/arch/arm/traps.c +1 -0
@@ -1235,6 +1235,7 @@ static arm_hypercall_t arm_hypercall_table[] = {HYPERCALL (multicall,2 ),HYPERCALL (platform_op,1 ),HYPERCALL_ARM (vcpu_op,3 ), + HYPERCALL(version_op, 3), };#ifndef NDEBUG
xen/arch/x86/hvm/hvm.c +1 -0
@@ -5332,6 +5332,7 @@ static const struct {COMPAT_CALL (platform_op),COMPAT_CALL (mmuext_op),HYPERCALL (xenpmu_op), +HYPERCALL (version_op), HYPERCALL(arch_1) };
xen/arch/x86/x86_64/compat/entry.S +2 -0
@@ -391,6 +391,7 @@ ENTRY(compat_hypercall_table) .quad do_tmem_op .quad do_ni_hypercall /* reserved for XenClient */ .quad do_xenpmu_op /* 40 */ + .quad do_version_op .rept __HYPERVISOR_arch_0-((.-compat_hypercall_table)/8) .quad compat_ni_hypercall .endr
@@ -442,6 +443,7 @@ ENTRY(compat_hypercall_args_table) .byte 1 /* do_tmem_op */ .byte 0 /* reserved for XenClient */ .byte 2 /* do_xenpmu_op */ /* 40 */ + .byte 3 /* do_version_op */ .rept __HYPERVISOR_arch_0-(.-compat_hypercall_args_table) .byte 0 /* compat_ni_hypercall */ .endr
xen/arch/x86/x86_64/entry.S +2 -0
@@ -727,6 +727,7 @@ ENTRY(hypercall_table) .quad do_tmem_op .quad do_ni_hypercall /* reserved for XenClient */ .quad do_xenpmu_op /* 40 */ + .quad do_version_op .rept __HYPERVISOR_arch_0-((.-hypercall_table)/8) .quad do_ni_hypercall .endr
@@ -778,6 +779,7 @@ ENTRY(hypercall_args_table) .byte 1 /* do_tmem_op */ .byte 0 /* reserved for XenClient */ .byte 2 /* do_xenpmu_op */ /* 40 */ + .byte 3 /* do_version_op */ .rept __HYPERVISOR_arch_0-(.-hypercall_args_table) .byte 0 /* do_ni_hypercall */ .endr
xen/common/compat/kernel.c +3 -0
@@ -38,6 +38,9 @@ CHECK_TYPE(capabilities_info);CHECK_TYPE (domain_handle); +CHECK_TYPE (version_op_buf); +CHECK_TYPE (version_op_val); +#define xennmi_callback compat_nmi_callback#define xennmi_callback_t compat_nmi_callback_t
xen/common/kernel.c +227 -38
289 lines not on this page · raw message
xen/include/public/arch-arm.h +3 -0
@@ -128,6 +128,9 @@* * VCPUOP_register_vcpu_info * * VCPUOP_register_runstate_memory_area * +* HYPERVISOR_version_op +* All generic sub-operations +* * * Other notes on the ARM ABI: *
xen/include/public/version.h +71 -1
84 lines not on this page · raw message
xen/include/public/xen.h +1 -0
@@ -115,6 +115,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_ulong_t);#define __HYPERVISOR_tmem_op 38#define __HYPERVISOR_xc_reserved_op 39/* reserved for XenClient */ #define __HYPERVISOR_xenpmu_op 40 +#define __HYPERVISOR_version_op 41/* supersedes xen_version (17) */ /* Architecture-specific hypercall definitions. */ #define __HYPERVISOR_arch_0 48
xen/include/xen/hypercall.h +4 -0
@@ -143,6 +143,10 @@ do_xenoprof_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg);extern long do_xenpmu_op (unsigned int op,XEN_GUEST_HANDLE_PARAM (xen_pmu_params_t) arg); +extern long +do_version_op (unsigned int cmd, +XEN_GUEST_HANDLE_PARAM (void ) arg,unsigned int len); +#ifdef CONFIG_COMPAT extern int
xen/include/xsm/dummy.h +19 -0
@@ -749,3 +749,22 @@ static XSM_INLINE int xsm_xen_version (XSM_DEFAULT_ARG uint32_t op)return xsm_default_action (XSM_PRIV , current->domain,NULL ); } } + +static XSM_INLINE int xsm_version_op (XSM_DEFAULT_ARG uint32_t op) +{ +XSM_ASSERT_ACTION (XSM_OTHER ); +switch ( op ) + { +case XEN_VERSION_OP_version: +case XEN_VERSION_OP_extraversion: +case XEN_VERSION_OP_capabilities: +case XEN_VERSION_OP_platform_parameters: +case XEN_VERSION_OP_get_features: +case XEN_VERSION_OP_pagesize: +case XEN_VERSION_OP_guest_handle: +/* These MUST always be accessible to any guest by default. */ +return xsm_default_action (XSM_HOOK , current->domain,NULL ); +default : +return xsm_default_action (XSM_PRIV , current->domain,NULL ); + } +}
xen/include/xsm/xsm.h +7 -0
@@ -194,6 +194,7 @@ struct xsm_operations {int (*pmu_op) (struct domain *d,unsigned int op);#endif int (*xen_version) (uint32_t cmd); +int (*version_op) (uint32_t cmd); };#ifdef CONFIG_XSM
@@ -736,6 +737,12 @@ static inline int xsm_xen_version (xsm_default_t def, uint32_t op) {return xsm_ops->xen_version (op); } + +static inline int xsm_version_op (xsm_default_t def,uint32_t op) +{ +return xsm_ops->version_op (op); +} +#endif /* XSM_NO_WRAPPERS */ #ifdef CONFIG_MULTIBOOT
xen/xsm/dummy.c +1 -0
@@ -163,4 +163,5 @@ void xsm_fixup_ops (struct xsm_operations *ops)set_to_dummy_if_null (ops, pmu_op);#endif set_to_dummy_if_null (ops, xen_version); +set_to_dummy_if_null (ops, version_op); }
xen/xsm/flask/hooks.c +39 -0
@@ -1662,6 +1662,44 @@ static int flask_xen_version (uint32_t op) } } +static int flask_version_op (uint32_t op) +{ +u32 dsid =domain_sid (current->domain); + +switch ( op ) + { +case XEN_VERSION_OP_version: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__VERSION ,NULL ); +case XEN_VERSION_OP_extraversion: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__EXTRAVERSION ,NULL ); +case XEN_VERSION_OP_capabilities: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__CAPABILITIES ,NULL ); +case XEN_VERSION_OP_changeset: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__CHANGESET ,NULL ); +case XEN_VERSION_OP_platform_parameters: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__PLATFORM_PARAMETERS ,NULL ); +case XEN_VERSION_OP_get_features: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__GET_FEATURES ,NULL ); +case XEN_VERSION_OP_pagesize: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__PAGESIZE ,NULL ); +case XEN_VERSION_OP_guest_handle: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__GUEST_HANDLE ,NULL ); +case XEN_VERSION_OP_commandline: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__COMMANDLINE ,NULL ); +default : +return -EPERM ; + } +} +long do_flask_op (XEN_GUEST_HANDLE_PARAM (xsm_op_t) u_flask_op);int compat_flask_op (XEN_GUEST_HANDLE_PARAM (xsm_op_t) u_flask_op);
@@ -1801,6 +1839,7 @@ static struct xsm_operations flask_ops = { .pmu_op = flask_pmu_op, #endif .xen_version = flask_xen_version, + .version_op = flask_version_op, };static __init void flask_init (void )
xen/xsm/flask/policy/access_vectors +22 -2
@@ -496,9 +496,10 @@ class security del_ocontext } -# Class version is used to describe the XENVER_ hypercall. +# Class version is used to describe the XENVER_ and VERSION_OP hypercall. # Each sub-ops is described here - in the default case all of them should -# be allowed except the XENVER_commandline. +# be allowed except the XENVER_commandline, VERSION_OP_commandline, and +# VERSION_OP_changeset. # class version {
@@ -522,4 +523,23 @@ class version xen_guest_handle # Xen command line. xen_commandline + +# Often called by PV kernels to force an callback. + version +# Extra informations (-unstable). + extraversion +# Such as "xen-3.0-x86_64 xen-3.0-x86_32p hvm-3.0-x86_32 hvm-3.0-x86_32p hvm-3.0-x86_64". + capabilities +# Such as the virtual address of where the hypervisor resides. + platform_parameters +# Source code changeset. + changeset +# The features the hypervisor supports. + get_features +# Page size the hypervisor uses. + pagesize +# An value that the control stack can choose. + guest_handle +# Xen command line. + commandline }
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v4 04/34] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 404
Quoted 11 lines · Konrad Rzeszutek Wilk
xen/common/kernel.c +7
-0@@ -388,6 +395,188 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)return -ENOSYS ; } +static const char *capabilities_info (ssize_t *len) +{ +static xen_capabilities_info_t cached_cap; +static unsigned int cached_cap_len; +static bool_t cached; + +if ( cached )
I am surprised that Coverity didn't complain about this being unused...
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 413
Quoted 9 lines
xen/common/kernel.c +9
-0+ { + *len = cached_cap_len; +return cached_cap; + } +arch_get_xen_caps (&cached_cap); + cached_cap_len =strlen (cached_cap) +1 ; + + *len = cached_cap_len; +return cached_cap;
You can turn the logic around as
if ( unliklely(!cached) )
{
arch_get_xen_caps(&cached_cap);
cached_cap_len = strlen(cached_cap) + 1;
cached = 1;
}and have a single return path.
Quoted 53 lines
xen/common/kernel.c +53
-0+} + +static int size_of_subops_data (unsigned int cmd,ssize_t *sz) +{ +int rc =0 ; +/* Compute size. */ +switch ( cmd ) + { +case XEN_VERSION_OP_version: + *sz =sizeof (xen_version_op_val_t); +break ; + +case XEN_VERSION_OP_extraversion: + *sz =strlen (xen_extra_version ()) +1 ; +break ; + +case XEN_VERSION_OP_capabilities: +capabilities_info (sz); +break ; + +case XEN_VERSION_OP_platform_parameters: + *sz =sizeof (xen_version_op_val_t); +break ; + +case XEN_VERSION_OP_changeset: + *sz =strlen (xen_changeset ()) +1 ; +break ; + +case XEN_VERSION_OP_get_features: + *sz =sizeof (xen_feature_info_t); +break ; + +case XEN_VERSION_OP_pagesize: + *sz =sizeof (xen_version_op_val_t); +break ; + +case XEN_VERSION_OP_guest_handle: + *sz =ARRAY_SIZE (current->domain->handle); +break ; + +case XEN_VERSION_OP_commandline: + *sz =ARRAY_SIZE (saved_cmdline); +break ; + +default : + rc = -ENOSYS ; + } + +return rc; +} + +/* +* Similar to HYPERVISOR_xen_version but with a sane interface
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 476
Quoted 10 lines
xen/common/kernel.c +10
-0+* (has a length, one can probe for the length) and with one less sub-ops: +* missing XENVER_compile_info. +*/ +DO (version_op)(unsigned int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg, +unsigned int len) +{ +union { +xen_version_op_val_t n; +xen_feature_info_t fi; + } u;
= {}; and you can forgo the explicit memset() below.
Quoted 5 lines
xen/common/kernel.c +5
-0+ssize_t sz =0 ; +const void *ptr =NULL ; +int rc =xsm_version_op (XSM_OTHER , cmd); + +/* We can safely return -EPERM! */
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 491
Quoted 10 lines
xen/common/kernel.c +10
-0+if ( rc ) +return rc; + + rc =size_of_subops_data (cmd, &sz); +if ( rc ) +return rc; + +/* Some of the subops may have no data. */ +if ( !sz ) +return 0 ;
Really? I would have thought it would be reasonable to assert that either sz != 0 after the rc != 0 return.
Quoted 7 lines
xen/common/kernel.c +7
-0+/* +* This hypercall also allows the client to probe. If it provides +* a NULL arg we will return the size of the space it has to +* allocate for the specific sub-op. +*/ +if (guest_handle_is_null (arg) ) +return sz;
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 508
Quoted 10 lines
xen/common/kernel.c +10
-0+ +memset (&u,0 ,sizeof (u)); +/* +* The HYPERVISOR_xen_version differs in that some return the value, +* and some copy it on back on argument. We follow the same rule for all +* sub-ops: return 0 on success, positive value of bytes returned, and +* always copy the result in arg. Yeey sanity! +*/ + + rc =0 ;
rc is guaranteed to be 0 at this point.
Quoted 47 lines
xen/common/kernel.c +47
-0+switch ( cmd ) + { +case XEN_VERSION_OP_version: + u.n = (xen_major_version () <<16 ) |xen_minor_version (); +break ; + +case XEN_VERSION_OP_extraversion: + ptr =xen_extra_version (); +break ; + +case XEN_VERSION_OP_capabilities: + ptr =capabilities_info (&sz); +break ; + +case XEN_VERSION_OP_platform_parameters: + u.n =HYPERVISOR_VIRT_START ; +break ; + +case XEN_VERSION_OP_changeset: + ptr =xen_changeset (); +break ; + +case XEN_VERSION_OP_get_features: +if (copy_from_guest (&u.fi, arg,1 ) ) + { + rc = -EFAULT ; +break ; + } + rc =get_features (current->domain, &u.fi); +break ; + +case XEN_VERSION_OP_pagesize: + u.n =PAGE_SIZE ; +break ; + +case XEN_VERSION_OP_guest_handle: + ptr = current->domain->handle; +break ; + +case XEN_VERSION_OP_commandline: + ptr = saved_cmdline; +break ; + +default : + rc = -ENOSYS ; + } +
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 565
Quoted 10 lines
xen/common/kernel.c +10
-0+if ( !rc ) + { +ssize_t bytes; + +if ( sz > len ) + bytes = len; +else + bytes = sz; + +if (copy_to_guest (arg, ptr ? ptr : &u, bytes) )
Can be shortened to ptr ?: &u
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 574
Quoted 9 lines
xen/common/kernel.c +9
-0+ rc = -EFAULT ; + } +if ( !rc ) + { +/* +* We return len (truncate) worth of data even if we fail. +*/ +if ( sz > len ) + rc = -ENOBUFS ;
This needs to be in the previous if() clause to avoid overriding -EFAULT with -ENOBUFS.
Quoted 13 lines
xen/include/public/version.h +13
-0+ +/* +* The HYPERCALL_version_op has a set of sub-ops which mirror the +* sub-ops of HYPERCALL_xen_version. However this hypercall differs +* radically from the former: +* - It returns the amount of bytes returned. +* - It will return -XEN_EPERM if the guest is not permitted. +* - It will return the requested data in arg. +* - It requires an third argument (len) for the length of the +* arg. Naturally the arg has to fit the requested data otherwise +* -XEN_ENOBUFS is returned. +* +* It also offers an mechanism to probe for the amount of bytes an
xen/include/public/version.h typedef struct xen_feature_info xen_feature_info_t; · line 121
Quoted 10 lines
xen/include/public/version.h +10
-0+* sub-op will require. Having the arg have an NULL pointer will +* return the number of bytes requested for the operation. Or an +* negative value if an error is encountered. +*/ + +typedef uint64_t xen_version_op_val_t ; +DEFINE_XEN_GUEST_HANDLE (xen_version_op_val_t); + +typedef unsigned char xen_version_op_buf_t []; +DEFINE_XEN_GUEST_HANDLE (xen_version_op_buf_t);
Strictly speaking this should be a void* guest handle, as not all data is returned via this mechanism is unsigned char.
xen/include/public/version.h typedef struct xen_feature_info xen_feature_info_t; · line 133
Quoted 12 lines
xen/include/public/version.h +12
-0+ +/* arg == version_op_val_t. Encoded as major:minor (31..16:15..0) */ +#define XEN_VERSION_OP_version 0 + +/* arg == version_op_buf. */ +#define XEN_VERSION_OP_extraversion 1 + +/* arg == version_op_buf */ +#define XEN_VERSION_OP_capabilities 3 + +/* arg == version_op_buf */ +#define XEN_VERSION_OP_changeset 4
Might be worth stating that these return NUL terminated utf-8 strings?
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 04/34] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.
.. snip ..
Quoted 21 lines
Quoted 21 lines
xen/common/kernel.c +21
-0+case XEN_VERSION_OP_guest_handle: + *sz =ARRAY_SIZE (current->domain->handle); +break ; + +case XEN_VERSION_OP_commandline: + *sz =ARRAY_SIZE (saved_cmdline); +break ; + +default : + rc = -ENOSYS ; + } + +return rc; +} + +/* +* Similar to HYPERVISOR_xen_version but with a sane interface +* (has a length, one can probe for the length) and with one less sub-ops: +* missing XENVER_compile_info. +*/ +DO(version_op)(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) arg,
Quoted 8 lines
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 476
Quoted 6 lines
xen/common/kernel.c +6
-0+ unsigned int len) +{ +union { +xen_version_op_val_t n; +xen_feature_info_t fi; + } u;= {}; and you can forgo the explicit
memset()below.
Done!
Quoted 11 lines
Quoted 11 lines
xen/common/kernel.c +10
-0+ssize_t sz =0 ; +const void *ptr =NULL ; +int rc =xsm_version_op (XSM_OTHER , cmd); + +/* We can safely return -EPERM! */ +if ( rc ) +return rc; + + rc =size_of_subops_data (cmd, &sz); +if ( rc )
Quoted 8 lines
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 491
Quoted 5 lines
xen/common/kernel.c +5
-0+return rc; + +/* Some of the subops may have no data. */ +if ( !sz ) +return 0 ;Really? I would have thought it would be reasonable to assert that either sz != 0 after the rc != 0 return.
Commandline and guest_handle may be empty. Ah they aren't as they are array.
ARRAY_SIZE(saved_commandline) is always 1024. Ugh.
.. snip..
Quoted 5 lines
Quoted 5 lines
xen/common/kernel.c +5
-0+ +if ( !rc ) + { +ssize_t bytes; +
Quoted 12 lines
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 565
Quoted 6 lines
xen/common/kernel.c +6
-0+if ( sz > len ) + bytes = len; +else + bytes = sz; + +if (copy_to_guest (arg, ptr ? ptr : &u, bytes) )Can be shortened to ptr ?: &u
Quoted 3 lines
xen/common/kernel.c +3
-0+ rc = -EFAULT ; + } +if ( !rc )
^^^^^^^^^ - here
Quoted 9 lines
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 574
Quoted 6 lines
xen/common/kernel.c +6
-0+ { +/* +* We return len (truncate) worth of data even if we fail. +*/ +if ( sz > len ) + rc = -ENOBUFS ;This needs to be in the previous
if()clause to avoid overriding-EFAULTwith-ENOBUFS.
That is exactly why it is in its own 'if ( !rc )' - so it won't overwrite -EFAULT. See above for 'here'
Quoted 19 lines
Quoted 19 lines
xen/include/public/version.h +18
-0+ +/* +* The HYPERCALL_version_op has a set of sub-ops which mirror the +* sub-ops of HYPERCALL_xen_version. However this hypercall differs +* radically from the former: +* - It returns the amount of bytes returned. +* - It will return -XEN_EPERM if the guest is not permitted. +* - It will return the requested data in arg. +* - It requires an third argument (len) for the length of the +* arg. Naturally the arg has to fit the requested data otherwise +* -XEN_ENOBUFS is returned. +* +* It also offers an mechanism to probe for the amount of bytes an +* sub-op will require. Having the arg have an NULL pointer will +* return the number of bytes requested for the operation. Or an +* negative value if an error is encountered. +*/ +
Quoted 8 lines
xen/include/public/version.h typedef struct xen_feature_info xen_feature_info_t; · line 121
Quoted 5 lines
xen/include/public/version.h +5
-0+typedef uint64_t xen_version_op_val_t ; +DEFINE_XEN_GUEST_HANDLE (xen_version_op_val_t); + +typedef unsigned char xen_version_op_buf_t []; +DEFINE_XEN_GUEST_HANDLE (xen_version_op_buf_t);Strictly speaking this should be a void* guest handle, as not all data is returned via this mechanism is unsigned char.
Done!
Quoted 15 lines
xen/include/public/version.h typedef struct xen_feature_info xen_feature_info_t; · line 133
Quoted 13 lines
xen/include/public/version.h +12
-0+ +/* arg == version_op_val_t. Encoded as major:minor (31..16:15..0) */ +#define XEN_VERSION_OP_version 0 + +/* arg == version_op_buf. */ +#define XEN_VERSION_OP_extraversion 1 + +/* arg == version_op_buf */ +#define XEN_VERSION_OP_capabilities 3 + +/* arg == version_op_buf */ +#define XEN_VERSION_OP_changeset 4Might be worth stating that these return NUL terminated utf-8 strings?
Done!
Quoted 2 lines
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 04/34] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.
Quoted 26 lines
Quoted 5 lines
Quoted 5 lines
(quoted diff) +5
-0+ + if ( !rc ) + { + ssize_t bytes; +Quoted 12 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ if ( sz > len ) + bytes = len; + else + bytes = sz; + + if ( copy_to_guest(arg, ptr ? ptr : &u, bytes) )Can be shortened to ptr ?: &u
Quoted 3 lines
(quoted diff) +3
-0+ rc = -EFAULT; + } + if ( !rc )^^^^^^^^^ - hereQuoted 7 lines
Quoted 6 lines
(quoted diff) +6
-0+ { + /* + * We return len (truncate) worth of data even if we fail. + */ + if ( sz > len ) + rc = -ENOBUFS;
Quoted 5 lines
Quoted 2 lines
This needs to be in the previous
if()clause to avoid overriding-EFAULTwith-ENOBUFS.That is exactly why it is in its own 'if ( !rc )' - so it won't overwrite
-EFAULT. See above for 'here'
All changes incorporated. This is what the patch ends up looking:
From 534f9277aebb9b89b937a79dd33c0a7016ce00a2 Mon Sep 17 00:00:00 2001
From: Konrad Rzeszutek Wilk <[email protected]>
Date: Wed, 16 Mar 2016 15:48:56 -0400
Subject: [PATCH v4 05/35] HYPERCALL_version_op. New hypercall mirroring
XENVER_ but sane.
This hypercall mirrors the XENVER_ in that it has similar functionality. However it is designed differently:
- No compat layer. The data structures are the same size on 32 as on 64-bit.
- The hypercall accepts three arguments - the command, pointer to an buffer, and the length of the buffer.
- Each sub-ops can be "probed" for size by returning the size of buffer that will be needed - if the buffer is NULL.
- Subops can complete even if the buffer is too slow - truncated data will be filled and hypercall will return -ENOBUFS.
- VERSION_OP_commandline, VERSION_OP_changeset are privileged.
- There are no XENVER_compile_info equivalent.
- The hypercall can return -EPERM and toolstack/OSes are expected to deal with it.
---
Cc: Daniel De Graaf <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
v2: Remove memset and use {}. Tweak copy_to_guest and capabilities_info,
add ASSERT(sz) per Andrew's review.
---
--- tools/flask/policy/policy/modules/xen/xen.te | 9 +- xen/arch/arm/traps.c | 1 + xen/arch/x86/hvm/hvm.c | 1 + xen/arch/x86/x86_64/compat/entry.S | 2 + xen/arch/x86/x86_64/entry.S | 2 + xen/common/compat/kernel.c | 3 + xen/common/kernel.c | 259 +++++++++++++++++++++++---- xen/include/public/arch-arm.h | 3 + xen/include/public/version.h | 72 +++++++- xen/include/public/xen.h | 1 + xen/include/xen/hypercall.h | 4 + xen/include/xsm/dummy.h | 19 ++ xen/include/xsm/xsm.h | 7 + xen/xsm/dummy.c | 1 + xen/xsm/flask/hooks.c | 39 ++++ xen/xsm/flask/policy/access_vectors | 24 ++- 16 files changed, 404 insertions(+), 43 deletions(-)
tools/flask/policy/policy/modules/xen/xen.te +7 -2
@@ -74,12 +74,14 @@ allow dom0_t xen_t:xen2 { get_symbol }; -# Allow dom0 to use all XENVER_ subops +# Allow dom0 to use all XENVER_ subops and VERSION_OP subops # Note that dom0 is part of domain_type so this has duplicates. allow dom0_t xen_t:version { xen_version xen_extraversion xen_compile_info xen_capabilities xen_changeset xen_platform_parameters xen_get_features xen_pagesize xen_guest_handle xen_commandline + version extraversion capabilities changeset platform_parameters + get_features pagesize guest_handle commandline }; allow dom0_t xen_t:mmu memorymap;
@@ -146,11 +148,14 @@ if (guest_writeconsole) { # pmu_ctrl is for) allow domain_type xen_t:xen2 pmu_use; -# For normal guests all except XENVER_commandline +# For normal guests all except XENVER_commandline, VERSION_OP_changeset, +# and VERSION_OP_commandline allow domain_type xen_t:version { xen_version xen_extraversion xen_compile_info xen_capabilities xen_changeset xen_platform_parameters xen_get_features xen_pagesize xen_guest_handle + version extraversion capabilities platform_parameters + get_features pagesize guest_handle }; ############################################################################### #
xen/arch/arm/traps.c +1 -0
@@ -1235,6 +1235,7 @@ static arm_hypercall_t arm_hypercall_table[] = {HYPERCALL (multicall,2 ),HYPERCALL (platform_op,1 ),HYPERCALL_ARM (vcpu_op,3 ), + HYPERCALL(version_op, 3), };#ifndef NDEBUG
xen/arch/x86/hvm/hvm.c +1 -0
@@ -5332,6 +5332,7 @@ static const struct {COMPAT_CALL (platform_op),COMPAT_CALL (mmuext_op),HYPERCALL (xenpmu_op), +HYPERCALL (version_op), HYPERCALL(arch_1) };
xen/arch/x86/x86_64/compat/entry.S +2 -0
@@ -395,6 +395,7 @@ ENTRY(compat_hypercall_table) .quad do_tmem_op .quad do_ni_hypercall /* reserved for XenClient */ .quad do_xenpmu_op /* 40 */ + .quad do_version_op .rept __HYPERVISOR_arch_0-((.-compat_hypercall_table)/8) .quad compat_ni_hypercall .endr
@@ -446,6 +447,7 @@ ENTRY(compat_hypercall_args_table) .byte 1 /* do_tmem_op */ .byte 0 /* reserved for XenClient */ .byte 2 /* do_xenpmu_op */ /* 40 */ + .byte 3 /* do_version_op */ .rept __HYPERVISOR_arch_0-(.-compat_hypercall_args_table) .byte 0 /* compat_ni_hypercall */ .endr
xen/arch/x86/x86_64/entry.S +2 -0
@@ -731,6 +731,7 @@ ENTRY(hypercall_table) .quad do_tmem_op .quad do_ni_hypercall /* reserved for XenClient */ .quad do_xenpmu_op /* 40 */ + .quad do_version_op .rept __HYPERVISOR_arch_0-((.-hypercall_table)/8) .quad do_ni_hypercall .endr
@@ -782,6 +783,7 @@ ENTRY(hypercall_args_table) .byte 1 /* do_tmem_op */ .byte 0 /* reserved for XenClient */ .byte 2 /* do_xenpmu_op */ /* 40 */ + .byte 3 /* do_version_op */ .rept __HYPERVISOR_arch_0-(.-hypercall_args_table) .byte 0 /* do_ni_hypercall */ .endr
xen/common/compat/kernel.c +3 -0
@@ -34,6 +34,9 @@ CHECK_TYPE(capabilities_info);CHECK_TYPE (domain_handle); +CHECK_TYPE (version_op_buf); +CHECK_TYPE (version_op_val); +#ifdef COMPAT_VM_ASSIST_VALID #undef VM_ASSIST_VALID#define VM_ASSIST_VALID COMPAT_VM_ASSIST_VALID
xen/common/kernel.c +221 -38
283 lines not on this page · raw message
xen/include/public/arch-arm.h +3 -0
@@ -128,6 +128,9 @@* * VCPUOP_register_vcpu_info * * VCPUOP_register_runstate_memory_area * +* HYPERVISOR_version_op +* All generic sub-operations +* * * Other notes on the ARM ABI: *
xen/include/public/version.h +71 -1
84 lines not on this page · raw message
xen/include/public/xen.h +1 -0
@@ -115,6 +115,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_ulong_t);#define __HYPERVISOR_tmem_op 38#define __HYPERVISOR_xc_reserved_op 39/* reserved for XenClient */ #define __HYPERVISOR_xenpmu_op 40 +#define __HYPERVISOR_version_op 41/* supersedes xen_version (17) */ /* Architecture-specific hypercall definitions. */ #define __HYPERVISOR_arch_0 48
xen/include/xen/hypercall.h +4 -0
@@ -147,6 +147,10 @@ do_xenoprof_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg);extern long do_xenpmu_op (unsigned int op,XEN_GUEST_HANDLE_PARAM (xen_pmu_params_t) arg); +extern long +do_version_op (unsigned int cmd, +XEN_GUEST_HANDLE_PARAM (void ) arg,unsigned int len); +#ifdef CONFIG_COMPAT extern int
xen/include/xsm/dummy.h +19 -0
@@ -749,3 +749,22 @@ static XSM_INLINE int xsm_xen_version (XSM_DEFAULT_ARG uint32_t op)return xsm_default_action (XSM_PRIV , current->domain,NULL ); } } + +static XSM_INLINE int xsm_version_op (XSM_DEFAULT_ARG uint32_t op) +{ +XSM_ASSERT_ACTION (XSM_OTHER ); +switch ( op ) + { +case XEN_VERSION_OP_version: +case XEN_VERSION_OP_extraversion: +case XEN_VERSION_OP_capabilities: +case XEN_VERSION_OP_platform_parameters: +case XEN_VERSION_OP_get_features: +case XEN_VERSION_OP_pagesize: +case XEN_VERSION_OP_guest_handle: +/* These MUST always be accessible to any guest by default. */ +return xsm_default_action (XSM_HOOK , current->domain,NULL ); +default : +return xsm_default_action (XSM_PRIV , current->domain,NULL ); + } +}
xen/include/xsm/xsm.h +7 -0
@@ -194,6 +194,7 @@ struct xsm_operations {int (*pmu_op) (struct domain *d,unsigned int op);#endif int (*xen_version) (uint32_t cmd); +int (*version_op) (uint32_t cmd); };#ifdef CONFIG_XSM
@@ -736,6 +737,12 @@ static inline int xsm_xen_version (xsm_default_t def, uint32_t op) {return xsm_ops->xen_version (op); } + +static inline int xsm_version_op (xsm_default_t def,uint32_t op) +{ +return xsm_ops->version_op (op); +} +#endif /* XSM_NO_WRAPPERS */ #ifdef CONFIG_MULTIBOOT
xen/xsm/dummy.c +1 -0
@@ -163,4 +163,5 @@ void xsm_fixup_ops (struct xsm_operations *ops)set_to_dummy_if_null (ops, pmu_op);#endif set_to_dummy_if_null (ops, xen_version); +set_to_dummy_if_null (ops, version_op); }
xen/xsm/flask/hooks.c +39 -0
@@ -1662,6 +1662,44 @@ static int flask_xen_version (uint32_t op) } } +static int flask_version_op (uint32_t op) +{ +u32 dsid =domain_sid (current->domain); + +switch ( op ) + { +case XEN_VERSION_OP_version: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__VERSION ,NULL ); +case XEN_VERSION_OP_extraversion: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__EXTRAVERSION ,NULL ); +case XEN_VERSION_OP_capabilities: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__CAPABILITIES ,NULL ); +case XEN_VERSION_OP_changeset: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__CHANGESET ,NULL ); +case XEN_VERSION_OP_platform_parameters: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__PLATFORM_PARAMETERS ,NULL ); +case XEN_VERSION_OP_get_features: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__GET_FEATURES ,NULL ); +case XEN_VERSION_OP_pagesize: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__PAGESIZE ,NULL ); +case XEN_VERSION_OP_guest_handle: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__GUEST_HANDLE ,NULL ); +case XEN_VERSION_OP_commandline: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__COMMANDLINE ,NULL ); +default : +return -EPERM ; + } +} +long do_flask_op (XEN_GUEST_HANDLE_PARAM (xsm_op_t) u_flask_op);int compat_flask_op (XEN_GUEST_HANDLE_PARAM (xsm_op_t) u_flask_op);
@@ -1801,6 +1839,7 @@ static struct xsm_operations flask_ops = { .pmu_op = flask_pmu_op, #endif .xen_version = flask_xen_version, + .version_op = flask_version_op, };static __init void flask_init (void )
xen/xsm/flask/policy/access_vectors +22 -2
@@ -496,9 +496,10 @@ class security del_ocontext } -# Class version is used to describe the XENVER_ hypercall. +# Class version is used to describe the XENVER_ and VERSION_OP hypercall. # Each sub-ops is described here - in the default case all of them should -# be allowed except the XENVER_commandline. +# be allowed except the XENVER_commandline, VERSION_OP_commandline, and +# VERSION_OP_changeset. # class version {
@@ -522,4 +523,23 @@ class version xen_guest_handle # Xen command line. xen_commandline + +# Often called by PV kernels to force an callback. + version +# Extra informations (-unstable). + extraversion +# Such as "xen-3.0-x86_64 xen-3.0-x86_32p hvm-3.0-x86_32 hvm-3.0-x86_32p hvm-3.0-x86_64". + capabilities +# Such as the virtual address of where the hypervisor resides. + platform_parameters +# Source code changeset. + changeset +# The features the hypervisor supports. + get_features +# Page size the hypervisor uses. + pagesize +# An value that the control stack can choose. + guest_handle +# Xen command line. + commandline }
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v4 04/34] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 407
Quoted 10 lines · Konrad Rzeszutek Wilk
xen/common/kernel.c +10
-0+static const char *capabilities_info (ssize_t *len) +{ +static xen_capabilities_info_t cached_cap; +static unsigned int cached_cap_len; +static bool_t cached; + +if (unlikely (!cached) ) + { +arch_get_xen_caps (&cached_cap); + cached_cap_len =strlen (cached_cap) +1 ;
cached = 1;
With this coherency bug fixed, Reviewed-by: Andrew Cooper <[email protected]>
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 412
Quoted 5 lines
xen/common/kernel.c +5
-0+ } + + *len = cached_cap_len; +return cached_cap; +}
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 04/34] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.
In reply to Konrad Rzeszutek WilkQuoted 13 lines
Subject: [PATCH v4 05/35]
HYPERCALL_version_op. New hypercall mirroring
XENVER_but sane.This hypercall mirrors the
XENVER_in that it has similar functionality. However it is designed differently:
- No compat layer. The data structures are the same size on 32 as on 64-bit.
- The hypercall accepts three arguments - the command, pointer to an buffer, and the length of the buffer.
- Each sub-ops can be "probed" for size by returning the size of buffer that will be needed - if the buffer is NULL.
- Subops can complete even if the buffer is too slow - truncated data will be filled and hypercall will return-ENOBUFS.
s/too slow/too small/ ?
Quoted 1 line
-
VERSION_OP_commandline,VERSION_OP_changesetare privileged.
Aiui this is no difference to the old one anymore if we assume patches get committed in the order they're being presented in this series.
Quoted 4 lines
xen/common/kernel.c +0
-0@@ -221,6 +221,47 @@ void __init do_initcalls(void)
xen/common/kernel.c void __init do_initcalls(void) · line 231
Quoted 10 lines
xen/common/kernel.c +8
-0#endif +static int get_features (struct domain *d,xen_feature_info_t *fi) +{ +switch ( fi->submap_idx ) + { +case 0 : + fi->submap = (1U << XENFEAT_memory_op_vnode_supported); +if (VM_ASSIST (d, pae_extended_cr3) ) + fi->submap |= (1U << XENFEAT_pae_pgdir_above_4gb);
Since you already move this code, I think the two lines above would better go into the x86-specific section below.
Quoted 39 lines
xen/common/kernel.c +1
-29@@ -302,50 +343,16 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)case XENVER_get_features: {xen_feature_info_t fi; -struct domain *d = current->domain;if (copy_from_guest (&fi, arg,1 ) )return -EFAULT ; -switch ( fi.submap_idx ) +if ( !deny ) { -case 0 : -if ( deny ) -break ; - fi.submap = (1U << XENFEAT_memory_op_vnode_supported); -if (VM_ASSIST (d, pae_extended_cr3) ) - fi.submap |= (1U << XENFEAT_pae_pgdir_above_4gb); -if (paging_mode_translate (d) ) - fi.submap |= - (1U << XENFEAT_writable_page_tables) | - (1U << XENFEAT_auto_translated_physmap); -if (is_hardware_domain (d) ) - fi.submap |=1U << XENFEAT_dom0; -#ifdef CONFIG_X86 -switch ( d->guest_type ) - { -case guest_type_pv: - fi.submap |= (1U << XENFEAT_mmu_pt_update_preserve_ad) | - (1U << XENFEAT_highmem_assist) | - (1U << XENFEAT_gnttab_map_avail_bits); -break ; -case guest_type_pvh: - fi.submap |= (1U << XENFEAT_hvm_safe_pvclock) | - (1U << XENFEAT_supervisor_mode_kernel) | - (1U << XENFEAT_hvm_callback_vector); -break ; -case guest_type_hvm: - fi.submap |= (1U << XENFEAT_hvm_safe_pvclock) |
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 353
Quoted 10 lines
xen/common/kernel.c +2
-8- (1U << XENFEAT_hvm_callback_vector) | - (1U << XENFEAT_hvm_pirqs); - break; - } -#endif -break ; -default : -return -EINVAL ; +int rc =get_features (current->domain, &fi); +if ( rc )
Blank line between declaration(s) and statement(s) please.
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) · line 399
Quoted 6 lines
xen/common/kernel.c +1
-0@@ -388,6 +395,182 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)return -ENOSYS ; } +static const char *capabilities_info (ssize_t *len)
Why ssize_t?
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 400
Quoted 2 lines
xen/common/kernel.c +2
-0+{ +static xen_capabilities_info_t cached_cap;
__read_mostly?
Quoted 23 lines
xen/common/kernel.c +23
-0+static int size_of_subops_data (unsigned int cmd,ssize_t *sz) +{ +int rc =0 ; +/* Compute size. */ +switch ( cmd ) + { +case XEN_VERSION_OP_version: + *sz =sizeof (xen_version_op_val_t); +break ; + +case XEN_VERSION_OP_extraversion: + *sz =strlen (xen_extra_version ()) +1 ; +break ; + +case XEN_VERSION_OP_capabilities: +capabilities_info (sz); +break ; + +case XEN_VERSION_OP_platform_parameters: + *sz =sizeof (xen_version_op_val_t); +break ; + +case XEN_VERSION_OP_changeset:
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 446
Quoted 10 lines
xen/common/kernel.c +10
-0+ *sz =strlen (xen_changeset ()) +1 ; +break ; + +case XEN_VERSION_OP_get_features: + *sz =sizeof (xen_feature_info_t); +break ; + +case XEN_VERSION_OP_pagesize: + *sz =sizeof (xen_version_op_val_t); +break ;
Please combine all the cases producing this value.
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 453
Quoted 6 lines
xen/common/kernel.c +6
-0+case XEN_VERSION_OP_guest_handle: + *sz =ARRAY_SIZE (current->domain->handle); +break ; + +case XEN_VERSION_OP_commandline: + *sz =ARRAY_SIZE (saved_cmdline);
strlen()?
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 472
Quoted 5 lines
xen/common/kernel.c +5
-0+DO (version_op)(unsigned int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg, +unsigned int len) +{ +union { +xen_version_op_val_t n;
Would "v" or "val" be the more natural name here?
Quoted 66 lines
xen/common/kernel.c +66
-0+xen_feature_info_t fi; + } u = {}; +ssize_t sz =0 ; +const void *ptr =NULL ; +int rc =xsm_version_op (XSM_OTHER , cmd); + +/* We can safely return -EPERM! */ +if ( rc ) +return rc; + + rc =size_of_subops_data (cmd, &sz); +if ( rc ) +return rc; + +ASSERT (sz); +/* +* This hypercall also allows the client to probe. If it provides +* a NULL arg we will return the size of the space it has to +* allocate for the specific sub-op. +*/ +if (guest_handle_is_null (arg) ) +return sz; + +/* +* The HYPERVISOR_xen_version differs in that some return the value, +* and some copy it on back on argument. We follow the same rule for all +* sub-ops: return 0 on success, positive value of bytes returned, and +* always copy the result in arg. Yeey sanity! +*/ + +switch ( cmd ) + { +case XEN_VERSION_OP_version: + u.n = (xen_major_version () <<16 ) |xen_minor_version (); +break ; + +case XEN_VERSION_OP_extraversion: + ptr =xen_extra_version (); +break ; + +case XEN_VERSION_OP_capabilities: + ptr =capabilities_info (&sz); +break ; + +case XEN_VERSION_OP_platform_parameters: + u.n =HYPERVISOR_VIRT_START ; +break ; + +case XEN_VERSION_OP_changeset: + ptr =xen_changeset (); +break ; + +case XEN_VERSION_OP_get_features: +if (copy_from_guest (&u.fi, arg,1 ) ) + { + rc = -EFAULT ; +break ; + } + rc =get_features (current->domain, &u.fi); +break ; + +case XEN_VERSION_OP_pagesize: + u.n =PAGE_SIZE ; +break ; + +case XEN_VERSION_OP_guest_handle:
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 548
Quoted 10 lines
xen/common/kernel.c +10
-0+ ptr = current->domain->handle; +break ; + +case XEN_VERSION_OP_commandline: + ptr = saved_cmdline; +break ; + +default : + rc = -ENOSYS ; + }
Seeing this long switch() a second time I wonder why size_of_subops_data() doesn't just get folded here, with the null handle being taken care of below instead of above.
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 557
Quoted 8 lines
xen/common/kernel.c +8
-0+if ( !rc ) + { +ssize_t bytes; + +if ( sz > len ) + bytes = len; +else + bytes = sz;
min() (for which sz and bytes being "unsigned int" would help)?
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 568
Quoted 10 lines
xen/common/kernel.c +10
-0+if (copy_to_guest (arg, ptr ? : &u, bytes) ) + rc = -EFAULT ; + } +if ( !rc ) + { +/* +* We return len (truncate) worth of data even if we fail. +*/ +if ( sz > len ) + rc = -ENOBUFS ;
Perhaps worth moving this up into the previous if(), such that -EFAULT would also take precedence over -ENOBUFS?
Quoted 9 lines
xen/common/kernel.c +5
-0@@ -87,6 +95,68 @@ typedef struct xen_feature_info xen_feature_info_t;#define XENVER_commandline 9typedef char xen_commandline_t [1024 ]; + + +/* +* The HYPERCALL_version_op has a set of sub-ops which mirror the +* sub-ops of HYPERCALL_xen_version. However this hypercall differs
xen/common/kernel.c typedef struct xen_feature_info xen_feature_info_t; · line 112
Quoted 10 lines
xen/common/kernel.c +10
-0+* radically from the former: +* - It returns the amount of bytes returned. +* - It will return -XEN_EPERM if the guest is not permitted. +* - It will return the requested data in arg. +* - It requires an third argument (len) for the length of the +* arg. Naturally the arg has to fit the requested data otherwise +* -XEN_ENOBUFS is returned. +* +* It also offers an mechanism to probe for the amount of bytes an +* sub-op will require. Having the arg have an NULL pointer will
s/pointer/handle/
xen/common/kernel.c typedef struct xen_feature_info xen_feature_info_t; · line 121
Quoted 9 lines
xen/common/kernel.c +9
-0+* return the number of bytes requested for the operation. Or an +* negative value if an error is encountered. +*/ + +typedef uint64_t xen_version_op_val_t ; +DEFINE_XEN_GUEST_HANDLE (xen_version_op_val_t); + +typedef void xen_version_op_buf_t ; +DEFINE_XEN_GUEST_HANDLE (xen_version_op_buf_t);
Are these actually useful for anything? And for the various strings, wouldn't a "char" handle be more natural?
xen/common/kernel.c typedef struct xen_feature_info xen_feature_info_t; · line 122
Quoted 1 line
xen/common/kernel.c +1
-0+/* arg == version_op_val_t. Encoded as major:minor (31..16:15..0) */
Please make explicit that 63...32 are zero (or whatever they really are).
Quoted 4 lines
xen/common/kernel.c +4
-0+#define XEN_VERSION_OP_version 0 + +/* arg == version_op_buf. Contains NUL terminated utf-8 string. */ +#define XEN_VERSION_OP_extraversion 1
xen/common/kernel.c typedef struct xen_feature_info xen_feature_info_t; · line 136
Quoted 10 lines
xen/common/kernel.c +10
-0+ +/* arg == version_op_buf. Contains NUL terminated utf-8 string. */ +#define XEN_VERSION_OP_capabilities 3 + +/* arg == version_op_buf. Contains NUL terminated utf-8 string. */ +#define XEN_VERSION_OP_changeset 4 + +/* +* arg == xen_version_op_val_t. Contains the virtual address +* of the hypervisor encoded as [63..0].
I'd say the encoding info here is unnecessary and could - just like you already do for pagesize below - be omitted.
Quoted 13 lines
xen/common/kernel.c +13
-0+*/ +#define XEN_VERSION_OP_platform_parameters 5 + +/* +* arg = xen_feature_info_t - shares the same structure +* as the XENVER_get_features. +*/ +#define XEN_VERSION_OP_get_features 6 + +/* arg == xen_version_op_val_t. */ +#define XEN_VERSION_OP_pagesize 7 + +/* arg == version_op_buf.
xen/common/kernel.c typedef struct xen_feature_info xen_feature_info_t; · line 159
Quoted 10 lines
xen/common/kernel.c +9
-0+* +* The toolstack fills it out for guest consumption. It is intended to hold +* the UUID of the guest. +*/ +#define XEN_VERSION_OP_guest_handle 8 + +/* arg = version_op_buf. Contains NUL terminated utf-8 string. */ +#define XEN_VERSION_OP_commandline 9 +#endif /* __XEN_PUBLIC_VERSION_H__ */
Would leaving out the _OP and _op everywhere result in any name collisions with the old one?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 04/34] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.
. snip..
Quoted 5 lines
Quoted 1 line
-
VERSION_OP_commandline,VERSION_OP_changesetare privileged.Aiui this is no difference to the old one anymore if we assume patches get committed in the order they're being presented in this series.
The old one (XENVER) would disallow XENVER_cmdline for guests. The rest are allowed.
.. snip..
Quoted 22 lines
Quoted 9 lines
(quoted diff) +5
-0@@ -87,6 +95,68 @@ typedef struct xen_feature_info xen_feature_info_t; #define XENVER_commandline 9 typedef char xen_commandline_t[1024]; + + +/* + * The HYPERCALL_version_op has a set of sub-ops which mirror the + * sub-ops of HYPERCALL_xen_version. However this hypercall differsReview typedef struct xen_feature_info xen_feature_info_t; · line 112
Quoted 10 lines
(quoted diff) +10
-0+ * radically from the former: + * - It returns the amount of bytes returned. + * - It will return -XEN_EPERM if the guest is not permitted. + * - It will return the requested data in arg. + * - It requires an third argument (len) for the length of the + * arg. Naturally the arg has to fit the requested data otherwise + * -XEN_ENOBUFS is returned. + * + * It also offers an mechanism to probe for the amount of bytes an + * sub-op will require. Having the arg have an NULL pointer wills/pointer/handle/
Quoted 11 lines
Review typedef struct xen_feature_info xen_feature_info_t; · line 121
Quoted 9 lines
(quoted diff) +9
-0+ * return the number of bytes requested for the operation. Or an + * negative value if an error is encountered. + */ + +typedef uint64_t xen_version_op_val_t; +DEFINE_XEN_GUEST_HANDLE(xen_version_op_val_t); + +typedef void xen_version_op_buf_t; +DEFINE_XEN_GUEST_HANDLE(xen_version_op_buf_t);Are these actually useful for anything? And for the various strings,
The xen_version_op_val_t is definitly used by the toolstack.
Quoted 1 line
wouldn't a "char" handle be more natural?
Heh. It was char[] before but Andrew liked it as void.
The xen_version_op_buf_t is not used but I do reference it below in comment. Let me put s/arg == version_op_buf/arg == char/ ?
Let me do that.
Quoted 42 lines
Review typedef struct xen_feature_info xen_feature_info_t; · line 122
Quoted 2 lines
(quoted diff) +1
-0+/* arg == version_op_val_t. Encoded as major:minor (31..16:15..0) */Please make explicit that 63...32 are zero (or whatever they really are).
Quoted 4 lines
(quoted diff) +4
-0+#define XEN_VERSION_OP_version 0 + +/* arg == version_op_buf. Contains NUL terminated utf-8 string. */ +#define XEN_VERSION_OP_extraversion 1Review typedef struct xen_feature_info xen_feature_info_t; · line 136
Quoted 10 lines
(quoted diff) +10
-0+ +/* arg == version_op_buf. Contains NUL terminated utf-8 string. */ +#define XEN_VERSION_OP_capabilities 3 + +/* arg == version_op_buf. Contains NUL terminated utf-8 string. */ +#define XEN_VERSION_OP_changeset 4 + +/* + * arg == xen_version_op_val_t. Contains the virtual address + * of the hypervisor encoded as [63..0].I'd say the encoding info here is unnecessary and could - just like you already do for pagesize below - be omitted.
Quoted 18 lines
(quoted diff) +18
-0+ */ +#define XEN_VERSION_OP_platform_parameters 5 + +/* + * arg = xen_feature_info_t - shares the same structure + * as the XENVER_get_features. + */ +#define XEN_VERSION_OP_get_features 6 + +/* arg == xen_version_op_val_t. */ +#define XEN_VERSION_OP_pagesize 7 + +/* arg == version_op_buf. + * + * The toolstack fills it out for guest consumption. It is intended to hold + * the UUID of the guest. + */ +#define XEN_VERSION_OP_guest_handle 8
Quoted 8 lines
Review typedef struct xen_feature_info xen_feature_info_t; · line 159
Quoted 5 lines
(quoted diff) +4
-0+ +/* arg = version_op_buf. Contains NUL terminated utf-8 string. */ +#define XEN_VERSION_OP_commandline 9 + #endif /* __XEN_PUBLIC_VERSION_H__ */Would leaving out the
_OPand_opeverywhere result in any name collisions with the old one?
It worked out fine. Made it XEN_VERSION_[..]
See inline new patch:
From aa7ba11778dd3ffb2a53ebf6123ddfb196f203d8 Mon Sep 17 00:00:00 2001
From: Konrad Rzeszutek Wilk <[email protected]>
Date: Fri, 18 Mar 2016 13:41:07 -0400
Subject: [PATCH] HYPERCALL_version_op. New hypercall mirroring XENVER_ but
sane.
This hypercall mirrors the XENVER_ in that it has similar functionality. However it is designed differently:
- No compat layer. The data structures are the same size on 32 as on 64-bit.
- The hypercall accepts three arguments - the command, pointer to an buffer, and the length of the buffer.
- Each sub-ops can be "probed" for size by returning the size of buffer that will be needed - if the buffer is NULL.
- Subops can complete even if the buffer is too small - truncated data will be filled and hypercall will return -ENOBUFS.
- VERSION_commandline, VERSION_changeset are privileged.
- There is no XENVER_compile_info equivalent.
- The hypercall can return -EPERM and toolstack/OSes are expected to deal with it.
While we combine some of the common code between XENVER_ and VERSION_ take the liberty of moving pae_extended_cr3 in x86 area.
---
Cc: Daniel De Graaf <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
v1-v3: Was not part of the series.
v4: New posting.
v5: Remove memset and use {}. Tweak copy_to_guest and capabilities_info,
add ASSERT(sz) per Andrew's review. Add cached=1 back in. Per Jan, s/VERSION_OP/VERSION/, squash size check with do_version_op, update the comments. Dropped Andrew's Review-by.
---
--- tools/flask/policy/policy/modules/xen/xen.te | 9 +- xen/arch/arm/traps.c | 1 + xen/arch/x86/hvm/hvm.c | 1 + xen/arch/x86/x86_64/compat/entry.S | 2 + xen/arch/x86/x86_64/entry.S | 2 + xen/common/compat/kernel.c | 2 + xen/common/kernel.c | 209 ++++++++++++++++++++++----- xen/include/public/arch-arm.h | 3 + xen/include/public/version.h | 70 ++++++++- xen/include/public/xen.h | 1 + xen/include/xen/hypercall.h | 4 + xen/include/xsm/dummy.h | 19 +++ xen/include/xsm/xsm.h | 7 + xen/xsm/dummy.c | 1 + xen/xsm/flask/hooks.c | 39 +++++ xen/xsm/flask/policy/access_vectors | 24 ++- 16 files changed, 352 insertions(+), 42 deletions(-)
tools/flask/policy/policy/modules/xen/xen.te +7 -2
@@ -74,11 +74,13 @@ allow dom0_t xen_t:xen2 { get_symbol }; -# Allow dom0 to use all XENVER_ subops that have checks. +# Allow dom0 to use all XENVER_ subops that have checks and VERSION subops # Note that dom0 is part of domain_type so this has duplicates. allow dom0_t xen_t:version { xen_extraversion xen_compile_info xen_capabilities xen_changeset xen_pagesize xen_guest_handle xen_commandline + version extraversion capabilities changeset platform_parameters + get_features pagesize guest_handle commandline }; allow dom0_t xen_t:mmu memorymap;
@@ -145,10 +147,13 @@ if (guest_writeconsole) { # pmu_ctrl is for) allow domain_type xen_t:xen2 pmu_use; -# For normal guests all possible except XENVER_commandline. +# For normal guests all possible except XENVER_commandline, VERSION_changeset, +# and VERSION_commandline allow domain_type xen_t:version { xen_extraversion xen_compile_info xen_capabilities xen_changeset xen_pagesize xen_guest_handle + version extraversion capabilities platform_parameters + get_features pagesize guest_handle }; ###############################################################################
xen/arch/arm/traps.c +1 -0
@@ -1235,6 +1235,7 @@ static arm_hypercall_t arm_hypercall_table[] = {HYPERCALL (multicall,2 ),HYPERCALL (platform_op,1 ),HYPERCALL_ARM (vcpu_op,3 ), + HYPERCALL(version_op, 3), };#ifndef NDEBUG
xen/arch/x86/hvm/hvm.c +1 -0
@@ -5322,6 +5322,7 @@ static const struct {COMPAT_CALL (platform_op),COMPAT_CALL (mmuext_op),HYPERCALL (xenpmu_op), +HYPERCALL (version_op), HYPERCALL(arch_1) };
xen/arch/x86/x86_64/compat/entry.S +2 -0
@@ -394,6 +394,7 @@ ENTRY(compat_hypercall_table) .quad do_tmem_op .quad do_ni_hypercall /* reserved for XenClient */ .quad do_xenpmu_op /* 40 */ + .quad do_version_op .rept __HYPERVISOR_arch_0-((.-compat_hypercall_table)/8) .quad compat_ni_hypercall .endr
@@ -445,6 +446,7 @@ ENTRY(compat_hypercall_args_table) .byte 1 /* do_tmem_op */ .byte 0 /* reserved for XenClient */ .byte 2 /* do_xenpmu_op */ /* 40 */ + .byte 3 /* do_version_op */ .rept __HYPERVISOR_arch_0-(.-compat_hypercall_args_table) .byte 0 /* compat_ni_hypercall */ .endr
xen/arch/x86/x86_64/entry.S +2 -0
@@ -730,6 +730,7 @@ ENTRY(hypercall_table) .quad do_tmem_op .quad do_ni_hypercall /* reserved for XenClient */ .quad do_xenpmu_op /* 40 */ + .quad do_version_op .rept __HYPERVISOR_arch_0-((.-hypercall_table)/8) .quad do_ni_hypercall .endr
@@ -781,6 +782,7 @@ ENTRY(hypercall_args_table) .byte 1 /* do_tmem_op */ .byte 0 /* reserved for XenClient */ .byte 2 /* do_xenpmu_op */ /* 40 */ + .byte 3 /* do_version_op */ .rept __HYPERVISOR_arch_0-(.-hypercall_args_table) .byte 0 /* do_ni_hypercall */ .endr
xen/common/compat/kernel.c +2 -0
@@ -39,6 +39,8 @@ CHECK_TYPE(capabilities_info);CHECK_TYPE (domain_handle); +CHECK_TYPE (version_op_val); +#define xennmi_callback compat_nmi_callback#define xennmi_callback_t compat_nmi_callback_t
xen/common/kernel.c +172 -37
231 lines not on this page · raw message
xen/include/public/arch-arm.h +3 -0
@@ -128,6 +128,9 @@* * VCPUOP_register_vcpu_info * * VCPUOP_register_runstate_memory_area * +* HYPERVISOR_version_op +* All generic sub-operations +* * * Other notes on the ARM ABI: *
xen/include/public/version.h +69 -1
82 lines not on this page · raw message
xen/include/public/xen.h +1 -0
@@ -115,6 +115,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_ulong_t);#define __HYPERVISOR_tmem_op 38#define __HYPERVISOR_xc_reserved_op 39/* reserved for XenClient */ #define __HYPERVISOR_xenpmu_op 40 +#define __HYPERVISOR_version_op 41/* supersedes xen_version (17) */ /* Architecture-specific hypercall definitions. */ #define __HYPERVISOR_arch_0 48
xen/include/xen/hypercall.h +4 -0
@@ -147,6 +147,10 @@ do_xenoprof_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg);extern long do_xenpmu_op (unsigned int op,XEN_GUEST_HANDLE_PARAM (xen_pmu_params_t) arg); +extern long +do_version_op (unsigned int cmd, +XEN_GUEST_HANDLE_PARAM (void ) arg,unsigned int len); +#ifdef CONFIG_COMPAT extern int
xen/include/xsm/dummy.h +19 -0
@@ -751,3 +751,22 @@ static XSM_INLINE int xsm_xen_version (XSM_DEFAULT_ARG uint32_t op)return xsm_default_action (XSM_PRIV , current->domain,NULL ); } } + +static XSM_INLINE int xsm_version_op (XSM_DEFAULT_ARG uint32_t op) +{ +XSM_ASSERT_ACTION (XSM_OTHER ); +switch ( op ) + { +case XEN_VERSION_version: +case XEN_VERSION_extraversion: +case XEN_VERSION_capabilities: +case XEN_VERSION_platform_parameters: +case XEN_VERSION_get_features: +case XEN_VERSION_pagesize: +case XEN_VERSION_guest_handle: +/* These MUST always be accessible to any guest by default. */ +return xsm_default_action (XSM_HOOK , current->domain,NULL ); +default : +return xsm_default_action (XSM_PRIV , current->domain,NULL ); + } +}
xen/include/xsm/xsm.h +7 -0
@@ -194,6 +194,7 @@ struct xsm_operations {int (*pmu_op) (struct domain *d,unsigned int op);#endif int (*xen_version) (uint32_t cmd); +int (*version_op) (uint32_t cmd); };#ifdef CONFIG_XSM
@@ -736,6 +737,12 @@ static inline int xsm_xen_version (xsm_default_t def, uint32_t op) {return xsm_ops->xen_version (op); } + +static inline int xsm_version_op (xsm_default_t def,uint32_t op) +{ +return xsm_ops->version_op (op); +} +#endif /* XSM_NO_WRAPPERS */ #ifdef CONFIG_MULTIBOOT
xen/xsm/dummy.c +1 -0
@@ -163,4 +163,5 @@ void xsm_fixup_ops (struct xsm_operations *ops)set_to_dummy_if_null (ops, pmu_op);#endif set_to_dummy_if_null (ops, xen_version); +set_to_dummy_if_null (ops, version_op); }
xen/xsm/flask/hooks.c +39 -0
@@ -1658,6 +1658,44 @@ static int flask_xen_version (uint32_t op) } } +static int flask_version_op (uint32_t op) +{ +u32 dsid =domain_sid (current->domain); + +switch ( op ) + { +case XEN_VERSION_version: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__VERSION ,NULL ); +case XEN_VERSION_extraversion: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__EXTRAVERSION ,NULL ); +case XEN_VERSION_capabilities: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__CAPABILITIES ,NULL ); +case XEN_VERSION_changeset: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__CHANGESET ,NULL ); +case XEN_VERSION_platform_parameters: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__PLATFORM_PARAMETERS ,NULL ); +case XEN_VERSION_get_features: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__GET_FEATURES ,NULL ); +case XEN_VERSION_pagesize: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__PAGESIZE ,NULL ); +case XEN_VERSION_guest_handle: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__GUEST_HANDLE ,NULL ); +case XEN_VERSION_commandline: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__COMMANDLINE ,NULL ); +default : +return -EPERM ; + } +} +long do_flask_op (XEN_GUEST_HANDLE_PARAM (xsm_op_t) u_flask_op);int compat_flask_op (XEN_GUEST_HANDLE_PARAM (xsm_op_t) u_flask_op);
@@ -1797,6 +1835,7 @@ static struct xsm_operations flask_ops = { .pmu_op = flask_pmu_op, #endif .xen_version = flask_xen_version, + .version_op = flask_version_op, };static __init void flask_init (void )
xen/xsm/flask/policy/access_vectors +22 -2
@@ -496,9 +496,10 @@ class security del_ocontext } -# Class version is used to describe the XENVER_ hypercall. +# Class version is used to describe the XENVER_ and VERSION hypercall. # Almost all sub-ops are described here - in the default case all of them should -# be allowed except the XENVER_commandline. +# be allowed except the XENVER_commandline, VERSION_commandline, and +# VERSION_changeset. # # The ones that are omitted are XENVER_version, XENVER_platform_parameters, # and XENVER_get_features - as they MUST always be returned to a guest.
@@ -519,4 +520,23 @@ class version xen_guest_handle # Xen command line. xen_commandline +# --- VERSION hypercall --- +# Often called by PV kernels to force an callback. + version +# Extra informations (-unstable). + extraversion +# Such as "xen-3.0-x86_64 xen-3.0-x86_32p hvm-3.0-x86_32 hvm-3.0-x86_32p hvm-3.0-x86_64". + capabilities +# Such as the virtual address of where the hypervisor resides. + platform_parameters +# Source code changeset. + changeset +# The features the hypervisor supports. + get_features +# Page size the hypervisor uses. + pagesize +# An value that the control stack can choose. + guest_handle +# Xen command line. + commandline }
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v4 04/34] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines · On 18.03.16 at 20:22, <[email protected]> wrote:
+ * return the number of bytes requested for the operation. Or an
+ * negative value if an error is encountered.
+ */Quoted 8 lines
xen/include/public/version.h typedef struct xen_feature_info xen_feature_info_t;
Quoted 6 lines
xen/include/public/version.h +6
-0+ +typedef uint64_t xen_version_op_val_t ; +DEFINE_XEN_GUEST_HANDLE (xen_version_op_val_t); + +typedef void xen_version_op_buf_t ; +DEFINE_XEN_GUEST_HANDLE (xen_version_op_buf_t);Are these actually useful for anything? And for the various strings,
Quoted 5 lines
The
xen_version_op_val_tis definitly used by the toolstack.Quoted 1 line
wouldn't a "char" handle be more natural?
Heh. It was char[] before but Andrew liked it as void.
But that was because you used it for non string types too, wasn't it?
Quoted 6 lines
xen/common/kernel.c +2
-0@@ -380,6 +388,133 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)return -ENOSYS ; } +static const char *capabilities_info (unsigned int *len) +{
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 402
Quoted 10 lines
xen/common/kernel.c +10
-0+static xen_capabilities_info_t __read_mostly cached_cap; +static unsigned int __read_mostly cached_cap_len; +static bool_t cached; + +if (unlikely (!cached) ) + { +arch_get_xen_caps (&cached_cap); + cached_cap_len =strlen (cached_cap) +1 ; + cached =1 ; + }
I'm sorry for noticing this only now, but without any locking this is
unsafe: x86's arch_get_xen_caps() using safe_strcat() to fill the buffer, simultaneous invocations would possibly produce garbled output to all (i.e. also subsequently started) guests. Either use a real lock here, or make the guard a tristate one, which gets transitioned e.g. from 0 to -1 by the first one coming here (doing the initialization), with everyone else waiting for it to become +1 (to which the initializing party sets it once it is done).
Quoted 39 lines
xen/common/kernel.c +39
-0+DO (version_op)(unsigned int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg, +unsigned int len) +{ +union { +xen_version_op_val_t val; +xen_feature_info_t fi; + } u = {}; +unsigned int sz =0 ; +const void *ptr =NULL ; +int rc =xsm_version_op (XSM_OTHER , cmd); + +/* We can safely return -EPERM! */ +if ( rc ) +return rc; + +/* +* The HYPERVISOR_xen_version differs in that some return the value, +* and some copy it on back on argument. We follow the same rule for all +* sub-ops: return 0 on success, positive value of bytes returned, and +* always copy the result in arg. Yeey sanity! +*/ +switch ( cmd ) + { +case XEN_VERSION_version: + sz =sizeof (xen_version_op_val_t); + u.val = (xen_major_version () <<16 ) |xen_minor_version (); +break ; + +case XEN_VERSION_extraversion: + sz =strlen (xen_extra_version ()) +1 ; + ptr =xen_extra_version (); +break ; + +case XEN_VERSION_capabilities: + ptr =capabilities_info (&sz); +break ; + +case XEN_VERSION_changeset: + sz =strlen (xen_changeset ()) +1 ;
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 461
Quoted 10 lines
xen/common/kernel.c +10
-0+ ptr =xen_changeset (); +break ; + +case XEN_VERSION_platform_parameters: + sz =sizeof (xen_version_op_val_t); + u.val =HYPERVISOR_VIRT_START ; +break ; + +case XEN_VERSION_get_features: +if (copy_from_guest (&u.fi, arg,1 ) )
Afaict this is incompatible with the null handle check further down (i.e. you also need to check for a null handle here).
xen/include/public/arch-arm.h line 135
Quoted 11 lines
xen/include/public/arch-arm.h +3
-0@@ -128,6 +128,9 @@* * VCPUOP_register_vcpu_info * * VCPUOP_register_runstate_memory_area * +* HYPERVISOR_version_op +* All generic sub-operations +* * * Other notes on the ARM ABI:
I don't think the extra almost blank line is warranted here.
Quoted 8 lines
xen/include/public/version.h +1
-1@@ -30,7 +30,15 @@#include "xen.h" -/* NB. All ops return zero on success, except XENVER_{version,pagesize} */ +/*
xen/include/public/version.h line 43
Quoted 10 lines
xen/include/public/version.h +8
-0+* There are two hypercalls mentioned in here. The XENVER_ are for +* HYPERCALL_xen_version (17), while VERSION_ are for the +* HYPERCALL_version_op (41). +* +* The subops are very similar except that the later hypercall has a +* sane interface. +*/ +/* arg == NULL; returns major:minor (16:16). */
Nor is the extra blank one here.
xen/include/public/version.h typedef struct xen_feature_info xen_feature_info_t; · line 101
Quoted 8 lines
xen/include/public/version.h +4
-0@@ -87,6 +95,66 @@ typedef struct xen_feature_info xen_feature_info_t;#define XENVER_commandline 9typedef char xen_commandline_t [1024 ]; + + +/* +* The HYPERCALL_version_op has a set of sub-ops which mirror the
And three consecutive blank lines are too much in any event. (If for no other reason that because that provides extremely bad patch context if a later change happened right next to these three lines.)
xen/include/public/version.h typedef struct xen_feature_info xen_feature_info_t; · line 153
Quoted 7 lines
xen/include/public/version.h +7
-0+/* +* arg == char. +* +* The toolstack fills it out for guest consumption. It is intended to hold +* the UUID of the guest. +*/ +#define XEN_VERSION_guest_handle 8
So this is the place where I agree with Andrew char is not an appropriate type. A void or uint8 handle seems like what you want here.
Quoted 13 lines
xen/include/xsm/dummy.h +7
-0@@ -751,3 +751,22 @@ static XSM_INLINE int xsm_xen_version (XSM_DEFAULT_ARG uint32_t op)return xsm_default_action (XSM_PRIV , current->domain,NULL ); } } + +static XSM_INLINE int xsm_version_op (XSM_DEFAULT_ARG uint32_t op) +{ +XSM_ASSERT_ACTION (XSM_OTHER ); +switch ( op ) + { +case XEN_VERSION_version:
xen/include/xsm/dummy.h static XSM_INLINE int xsm_xen_version (XSM_DEFAULT_ARG uint32_t op) · line 770
Quoted 10 lines
xen/include/xsm/dummy.h +10
-0+case XEN_VERSION_extraversion: +case XEN_VERSION_capabilities: +case XEN_VERSION_platform_parameters: +case XEN_VERSION_get_features: +case XEN_VERSION_pagesize: +case XEN_VERSION_guest_handle: +/* These MUST always be accessible to any guest by default. */ +return xsm_default_action (XSM_HOOK , current->domain,NULL ); +default : +return xsm_default_action (XSM_PRIV , current->domain,NULL );
Considering that we seem to have settled on some exceptions here for the change adding XSM check to the legacy version op, do you really think going with no exception at all here is the right approach? Because if we do, that'll prevent guests getting fully converted over to the new interface. Of course, we could also make this conversion specifically a non-goal, and omit e.g. XEN_VERSION_VERSION from this new interface.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 04/34] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.
Quoted 13 lines · Jan Beulich
Quoted 13 lines
Quoted 12 lines
xen/include/public/version.h typedef struct xen_feature_info xen_feature_info_t;
Quoted 10 lines · On 18.03.16 at 20:22, <[email protected]> wrote:
+ * return the number of bytes requested for the operation. Or an
+ * negative value if an error is encountered.
+ */xen/include/public/version.h +6
-0+ +typedef uint64_t xen_version_op_val_t ; +DEFINE_XEN_GUEST_HANDLE (xen_version_op_val_t); + +typedef void xen_version_op_buf_t ; +DEFINE_XEN_GUEST_HANDLE (xen_version_op_buf_t);Are these actually useful for anything? And for the various strings,
Quoted 8 lines
Quoted 5 lines
The
xen_version_op_val_tis definitly used by the toolstack.Quoted 1 line
wouldn't a "char" handle be more natural?
Heh. It was char[] before but Andrew liked it as void.
But that was because you used it for non string types too, wasn't it?
Yes. For the build-id which is a binary blob. And as you noticed - also the domain handle which can be anything.
Quoted 18 lines
Quoted 7 lines
xen/common/kernel.c +2
-0@@ -380,6 +388,133 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)return -ENOSYS ; } +static const char *capabilities_info (unsigned int *len) +{xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 402
Quoted 10 lines
xen/common/kernel.c +10
-0+static xen_capabilities_info_t __read_mostly cached_cap; +static unsigned int __read_mostly cached_cap_len; +static bool_t cached; + +if (unlikely (!cached) ) + { +arch_get_xen_caps (&cached_cap); + cached_cap_len =strlen (cached_cap) +1 ; + cached =1 ; + }
Quoted 8 lines
I'm sorry for noticing this only now, but without any locking this is
unsafe: x86'sarch_get_xen_caps()usingsafe_strcat()to fill the buffer, simultaneous invocations would possibly produce garbled output to all (i.e. also subsequently started) guests. Either use a real lock here, or make the guard a tristate one, which gets transitioned e.g. from 0 to -1 by the first one coming here (doing the initialization), with everyone else waiting for it to become +1 (to which the initializing party sets it once it is done).
That would indeed be bad.
What if an _init_ code called this to 'pre-cache' it?
Quoted 45 lines
Quoted 45 lines
xen/common/kernel.c +44
-0+DO (version_op)(unsigned int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg, +unsigned int len) +{ +union { +xen_version_op_val_t val; +xen_feature_info_t fi; + } u = {}; +unsigned int sz =0 ; +const void *ptr =NULL ; +int rc =xsm_version_op (XSM_OTHER , cmd); + +/* We can safely return -EPERM! */ +if ( rc ) +return rc; + +/* +* The HYPERVISOR_xen_version differs in that some return the value, +* and some copy it on back on argument. We follow the same rule for all +* sub-ops: return 0 on success, positive value of bytes returned, and +* always copy the result in arg. Yeey sanity! +*/ +switch ( cmd ) + { +case XEN_VERSION_version: + sz =sizeof (xen_version_op_val_t); + u.val = (xen_major_version () <<16 ) |xen_minor_version (); +break ; + +case XEN_VERSION_extraversion: + sz =strlen (xen_extra_version ()) +1 ; + ptr =xen_extra_version (); +break ; + +case XEN_VERSION_capabilities: + ptr =capabilities_info (&sz); +break ; + +case XEN_VERSION_changeset: + sz =strlen (xen_changeset ()) +1 ; + ptr =xen_changeset (); +break ; + +case XEN_VERSION_platform_parameters: + sz =sizeof (xen_version_op_val_t);
Quoted 8 lines
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 461
Quoted 5 lines
xen/common/kernel.c +5
-0+ u.val =HYPERVISOR_VIRT_START ; +break ; + +case XEN_VERSION_get_features: +if (copy_from_guest (&u.fi, arg,1 ) )Afaict this is incompatible with the null handle check further down (i.e. you also need to check for a null handle here).
Oh my. Indeed.
Quoted 50 lines
xen/include/public/arch-arm.h line 135
Quoted 12 lines
xen/include/public/arch-arm.h +3
-0@@ -128,6 +128,9 @@* * VCPUOP_register_vcpu_info * * VCPUOP_register_runstate_memory_area * +* HYPERVISOR_version_op +* All generic sub-operations +* * * Other notes on the ARM ABI: I don't think the extra almost blank line is warranted here.
Quoted 8 lines
xen/include/public/version.h +1
-1@@ -30,7 +30,15 @@#include "xen.h" -/* NB. All ops return zero on success, except XENVER_{version,pagesize} */ +/* xen/include/public/version.h line 43
Quoted 10 lines
xen/include/public/version.h +8
-0+* There are two hypercalls mentioned in here. The XENVER_ are for +* HYPERCALL_xen_version (17), while VERSION_ are for the +* HYPERCALL_version_op (41). +* +* The subops are very similar except that the later hypercall has a +* sane interface. +*/ +/* arg == NULL; returns major:minor (16:16). */ Nor is the extra blank one here.
xen/include/public/version.h typedef struct xen_feature_info xen_feature_info_t; · line 101
Quoted 8 lines
xen/include/public/version.h +4
-0@@ -87,6 +95,66 @@ typedef struct xen_feature_info xen_feature_info_t;#define XENVER_commandline 9typedef char xen_commandline_t [1024 ]; + + +/* +* The HYPERCALL_version_op has a set of sub-ops which mirror the And three consecutive blank lines are too much in any event. (If for no other reason that because that provides extremely bad patch context if a later change happened right next to these three lines.)
Quoted 11 lines
xen/include/public/version.h typedef struct xen_feature_info xen_feature_info_t; · line 153
Quoted 7 lines
xen/include/public/version.h +7
-0+/* +* arg == char. +* +* The toolstack fills it out for guest consumption. It is intended to hold +* the UUID of the guest. +*/ +#define XEN_VERSION_guest_handle 8So this is the place where I agree with Andrew char is not an appropriate type. A void or uint8 handle seems like what you want here.
/me nods.
Quoted 29 lines
Quoted 14 lines
xen/include/xsm/dummy.h +7
-0@@ -751,3 +751,22 @@ static XSM_INLINE int xsm_xen_version (XSM_DEFAULT_ARG uint32_t op)return xsm_default_action (XSM_PRIV , current->domain,NULL ); } } + +static XSM_INLINE int xsm_version_op (XSM_DEFAULT_ARG uint32_t op) +{ +XSM_ASSERT_ACTION (XSM_OTHER ); +switch ( op ) + { +case XEN_VERSION_version:xen/include/xsm/dummy.h static XSM_INLINE int xsm_xen_version (XSM_DEFAULT_ARG uint32_t op) · line 770
Quoted 10 lines
xen/include/xsm/dummy.h +10
-0+case XEN_VERSION_extraversion: +case XEN_VERSION_capabilities: +case XEN_VERSION_platform_parameters: +case XEN_VERSION_get_features: +case XEN_VERSION_pagesize: +case XEN_VERSION_guest_handle: +/* These MUST always be accessible to any guest by default. */ +return xsm_default_action (XSM_HOOK , current->domain,NULL ); +default : +return xsm_default_action (XSM_PRIV , current->domain,NULL );Considering that we seem to have settled on some exceptions here for the change adding XSM check to the legacy version op, do you really think going with no exception at all here is the right approach?
Quoted 4 lines
Because if we do, that'll prevent guests getting fully converted over to the new interface. Of course, we could also make this conversion specifically a non-goal, and omit e.g.
XEN_VERSION_VERSIONfrom this new interface.
No no. I think convesion is the right long-term goal.
However the nice thing about this hypercall is that it can return -EPERM.
Making it always return an value for XEN_VERSION_version, XEN_VERSION_platform_parameters, XEN_VERSION_get_features means that there are some exceptions to this "can return -EPERM" as they will be guaranteed an postive return value. They can ignore the -EPERM case.
And means that guest can still take shortcuts.
I agree with you that guests need these hypercalls but at the same time I am not sure what can be done so they don't fall flat on their faces if they are presented with -EPERM. The Linux xenbus_init can be modified to deal with this returning -EPERM where it makes some assumptions.
But in a likelyhood it is the bad assumption!
Andrew, what do you think?
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 04/34] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.
Quoted 29 lines
Quoted 1 line
Quoted 1 line · On 22.03.16 at 16:52, <[email protected]> wrote:
Quoted 18 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 18.03.16 at 20:22, <[email protected]> wrote:
xen/common/kernel.c +2
-0@@ -380,6 +388,133 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)return -ENOSYS ; } +static const char *capabilities_info (unsigned int *len) +{xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 402
Quoted 10 lines
xen/common/kernel.c +10
-0+static xen_capabilities_info_t __read_mostly cached_cap; +static unsigned int __read_mostly cached_cap_len; +static bool_t cached; + +if (unlikely (!cached) ) + { +arch_get_xen_caps (&cached_cap); + cached_cap_len =strlen (cached_cap) +1 ; + cached =1 ; + }Quoted 8 lines
I'm sorry for noticing this only now, but without any locking this is
unsafe: x86'sarch_get_xen_caps()usingsafe_strcat()to fill the buffer, simultaneous invocations would possibly produce garbled output to all (i.e. also subsequently started) guests. Either use a real lock here, or make the guard a tristate one, which gets transitioned e.g. from 0 to -1 by the first one coming here (doing the initialization), with everyone else waiting for it to become +1 (to which the initializing party sets it once it is done).
Quoted 3 lines
That would indeed be bad.
What if an _init_ code called this to 'pre-cache' it?
That's one of the options you have.
Quoted 43 lines
Quoted 28 lines
Quoted 13 lines
xen/include/xsm/dummy.h +7
-0@@ -751,3 +751,22 @@ static XSM_INLINE int xsm_xen_version (XSM_DEFAULT_ARG uint32_t op)return xsm_default_action (XSM_PRIV , current->domain,NULL ); } } + +static XSM_INLINE int xsm_version_op (XSM_DEFAULT_ARG uint32_t op) +{ +XSM_ASSERT_ACTION (XSM_OTHER ); +switch ( op ) + { +case XEN_VERSION_version:xen/include/xsm/dummy.h static XSM_INLINE int xsm_xen_version (XSM_DEFAULT_ARG uint32_t op) · line 770
Quoted 10 lines
xen/include/xsm/dummy.h +10
-0+case XEN_VERSION_extraversion: +case XEN_VERSION_capabilities: +case XEN_VERSION_platform_parameters: +case XEN_VERSION_get_features: +case XEN_VERSION_pagesize: +case XEN_VERSION_guest_handle: +/* These MUST always be accessible to any guest by default. */ +return xsm_default_action (XSM_HOOK , current->domain,NULL ); +default : +return xsm_default_action (XSM_PRIV , current->domain,NULL );Considering that we seem to have settled on some exceptions here for the change adding XSM check to the legacy version op, do you really think going with no exception at all here is the right approach?
Quoted 4 lines
Because if we do, that'll prevent guests getting fully converted over to the new interface. Of course, we could also make this conversion specifically a non-goal, and omit e.g.
XEN_VERSION_VERSIONfrom this new interface.No no. I think convesion is the right long-term goal.
However the nice thing about this hypercall is that it can return
-EPERM.Making it always return an value for
XEN_VERSION_version,XEN_VERSION_platform_parameters,XEN_VERSION_get_featuresmeans that there are some exceptions to this "can return-EPERM" as they will be guaranteed an postive return value. They can ignore the-EPERMcase.
Quoted 8 lines
And means that guest can still take shortcuts.
I agree with you that guests need these hypercalls but at the same time I am not sure what can be done so they don't fall flat on their faces if they are presented with
-EPERM. The Linuxxenbus_initcan be modified to deal with this returning-EPERMwhere it makes some assumptions.But in a likelyhood it is the bad assumption!
I'm afraid I can't conclude what you mean to say with all of the above.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 04/34] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.
Quoted 50 lines
Quoted 50 lines
Quoted 28 lines
Quoted 13 lines
xen/include/xsm/dummy.h +7
-0@@ -751,3 +751,22 @@ static XSM_INLINE int xsm_xen_version (XSM_DEFAULT_ARG uint32_t op)return xsm_default_action (XSM_PRIV , current->domain,NULL ); } } + +static XSM_INLINE int xsm_version_op (XSM_DEFAULT_ARG uint32_t op) +{ +XSM_ASSERT_ACTION (XSM_OTHER ); +switch ( op ) + { +case XEN_VERSION_version:xen/include/xsm/dummy.h static XSM_INLINE int xsm_xen_version (XSM_DEFAULT_ARG uint32_t op) · line 770
Quoted 10 lines
xen/include/xsm/dummy.h +10
-0+case XEN_VERSION_extraversion: +case XEN_VERSION_capabilities: +case XEN_VERSION_platform_parameters: +case XEN_VERSION_get_features: +case XEN_VERSION_pagesize: +case XEN_VERSION_guest_handle: +/* These MUST always be accessible to any guest by default. */ +return xsm_default_action (XSM_HOOK , current->domain,NULL ); +default : +return xsm_default_action (XSM_PRIV , current->domain,NULL );Considering that we seem to have settled on some exceptions here for the change adding XSM check to the legacy version op, do you really think going with no exception at all here is the right approach?
Quoted 4 lines
Because if we do, that'll prevent guests getting fully converted over to the new interface. Of course, we could also make this conversion specifically a non-goal, and omit e.g.
XEN_VERSION_VERSIONfrom this new interface.No no. I think convesion is the right long-term goal.
However the nice thing about this hypercall is that it can return
-EPERM.Making it always return an value for
XEN_VERSION_version,XEN_VERSION_platform_parameters,XEN_VERSION_get_featuresmeans that there are some exceptions to this "can return-EPERM" as they will be guaranteed an postive return value. They can ignore the-EPERMcase.And means that guest can still take shortcuts.
I agree with you that guests need these hypercalls but at the same time I am not sure what can be done so they don't fall flat on their faces if they are presented with
-EPERM. The Linuxxenbus_initcan be modified to deal with this returning-EPERMwhere it makes some assumptions.
Quoted 4 lines
Quoted 1 line
But in a likelyhood it is the bad assumption!
I'm afraid I can't conclude what you mean to say with all of the above.
That I am waffling.
Andrew, what is your opinion?
Quoted 3 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 04/34] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.
Quoted 47 lines · Konrad Rzeszutek Wilk
Quoted 47 lines
Quoted 47 lines
Quoted 22 lines
Quoted 22 lines
xen/include/xsm/dummy.h +16
-0@@ -751,3 +751,22 @@ static XSM_INLINE int xsm_xen_version (XSM_DEFAULT_ARG uint32_t op)return xsm_default_action (XSM_PRIV , current->domain,NULL ); } } + +static XSM_INLINE int xsm_version_op (XSM_DEFAULT_ARG uint32_t op) +{ +XSM_ASSERT_ACTION (XSM_OTHER ); +switch ( op ) + { +case XEN_VERSION_version: +case XEN_VERSION_extraversion: +case XEN_VERSION_capabilities: +case XEN_VERSION_platform_parameters: +case XEN_VERSION_get_features: +case XEN_VERSION_pagesize: +case XEN_VERSION_guest_handle: +/* These MUST always be accessible to any guest by default. */ +return xsm_default_action (XSM_HOOK , current->domain,NULL ); +default :Quoted 8 lines
xen/include/xsm/dummy.h static XSM_INLINE int xsm_xen_version (XSM_DEFAULT_ARG uint32_t op) · line 770
Quoted 1 line
xen/include/xsm/dummy.h +1
-0+return xsm_default_action (XSM_PRIV , current->domain,NULL );Considering that we seem to have settled on some exceptions here for the change adding XSM check to the legacy version op, do you really think going with no exception at all here is the right approach? Because if we do, that'll prevent guests getting fully converted over to the new interface. Of course, we could also make this conversion specifically a non-goal, and omit e.g.
XEN_VERSION_VERSIONfrom this new interface.No no. I think convesion is the right long-term goal.
However the nice thing about this hypercall is that it can return
-EPERM.Making it always return an value for
XEN_VERSION_version,XEN_VERSION_platform_parameters,XEN_VERSION_get_featuresmeans that there are some exceptions to this "can return-EPERM" as they will be guaranteed an postive return value. They can ignore the-EPERMcase.And means that guest can still take shortcuts.
I agree with you that guests need these hypercalls but at the same time I am not sure what can be done so they don't fall flat on their faces if they are presented with
-EPERM. The Linuxxenbus_initcan be modified to deal with this returning-EPERMwhere it makes some assumptions.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
But in a likelyhood it is the bad assumption!
I'm afraid I can't conclude what you mean to say with all of the above.
That I am waffling.
Andrew, what is your opinion?
Nothing good can come from failing a XEN_VERSION_version hypercall. There are a number easy ways for a guest to infer such information.
XEN_VERSION_platform_parameters is only useful for 32bit PV guests, and the toolstack. Given that it is returning a fixed number in the ABI, nothing good can come of failing this either.
get_features can effectively be failed for permission reasons by returning 0. As such, explicitly failing with -EPERM is similarly pointless.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Konrad Rzeszutek Wilk
Acked-by Daniel De GraafRe: [PATCH v4 04/34] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.
Quoted 58 lines · Andrew Cooper
Quoted 47 lines · Konrad Rzeszutek Wilk
Quoted 47 lines
Quoted 47 lines
Quoted 22 lines
Quoted 22 lines
xen/include/xsm/dummy.h +16
-0@@ -751,3 +751,22 @@ static XSM_INLINE int xsm_xen_version (XSM_DEFAULT_ARG uint32_t op)return xsm_default_action (XSM_PRIV , current->domain,NULL ); } } + +static XSM_INLINE int xsm_version_op (XSM_DEFAULT_ARG uint32_t op) +{ +XSM_ASSERT_ACTION (XSM_OTHER ); +switch ( op ) + { +case XEN_VERSION_version: +case XEN_VERSION_extraversion: +case XEN_VERSION_capabilities: +case XEN_VERSION_platform_parameters: +case XEN_VERSION_get_features: +case XEN_VERSION_pagesize: +case XEN_VERSION_guest_handle: +/* These MUST always be accessible to any guest by default. */ +return xsm_default_action (XSM_HOOK , current->domain,NULL ); +default :Quoted 8 lines
xen/include/xsm/dummy.h static XSM_INLINE int xsm_xen_version (XSM_DEFAULT_ARG uint32_t op) · line 770
Quoted 1 line
xen/include/xsm/dummy.h +1
-0+return xsm_default_action (XSM_PRIV , current->domain,NULL );Considering that we seem to have settled on some exceptions here for the change adding XSM check to the legacy version op, do you really think going with no exception at all here is the right approach? Because if we do, that'll prevent guests getting fully converted over to the new interface. Of course, we could also make this conversion specifically a non-goal, and omit e.g.
XEN_VERSION_VERSIONfrom this new interface.No no. I think convesion is the right long-term goal.
However the nice thing about this hypercall is that it can return
-EPERM.Making it always return an value for
XEN_VERSION_version,XEN_VERSION_platform_parameters,XEN_VERSION_get_featuresmeans that there are some exceptions to this "can return-EPERM" as they will be guaranteed an postive return value. They can ignore the-EPERMcase.And means that guest can still take shortcuts.
I agree with you that guests need these hypercalls but at the same time I am not sure what can be done so they don't fall flat on their faces if they are presented with
-EPERM. The Linuxxenbus_initcan be modified to deal with this returning-EPERMwhere it makes some assumptions.Quoted 6 lines
Quoted 3 lines
Quoted 1 line
But in a likelyhood it is the bad assumption!
I'm afraid I can't conclude what you mean to say with all of the above.
That I am waffling.
Andrew, what is your opinion?
Nothing good can come from failing a
XEN_VERSION_versionhypercall. There are a number easy ways for a guest to infer such information.
Quoted 7 lines
XEN_VERSION_platform_parametersis only useful for 32bit PV guests, and the toolstack. Given that it is returning a fixed number in the ABI, nothing good can come of failing this either.
get_featurescan effectively be failed for permission reasons by returning 0. As such, explicitly failing with-EPERMis similarly pointless.
Allright. So here it is:
From 0f82c5f4cd1537ab8555f2b94bb3fe738df69733 Mon Sep 17 00:00:00 2001
From: Konrad Rzeszutek Wilk <[email protected]>
Date: Tue, 22 Mar 2016 12:03:21 -0400
Subject: [PATCH] HYPERCALL_version_op. New hypercall mirroring XENVER_ but
sane.
This hypercall mirrors the XENVER_ in that it has similar functionality. However it is designed differently:
- No compat layer. The data structures are the same size on 32 as on 64-bit.
- The hypercall accepts three arguments - the command, pointer to an buffer, and the length of the buffer.
- Each sub-ops can be "probed" for size by returning the size of buffer that will be needed - if the buffer is NULL.
- Subops can complete even if the buffer is too small - truncated data will be filled and hypercall will return -ENOBUFS.
- VERSION_commandline, VERSION_changeset are privileged.
- There is no XENVER_compile_info equivalent.
- The hypercall can return -EPERM and toolstack/OSes are expected to deal with. However there are three subops: XEN_VERSION_version, XEN_VERSION_platform_parameters and XEN_VERSION_get_features that will always return an value as guests cannot survive without them.
While we combine some of the common code between XENVER_ and VERSION_ take the liberty of moving pae_extended_cr3 in x86 area.
---
Cc: Daniel De Graaf <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
v1-v3: Was not part of the series.
v4: New posting.
v5: Remove memset and use {}. Tweak copy_to_guest and capabilities_info,
add ASSERT(sz) per Andrew's review. Add cached=1 back in. Per Jan, s/VERSION_OP/VERSION/, squash size check with do_version_op, update the comments. Dropped Andrew's Review-by. Ate newlines. Added initcall to guard against garbage being set in cached data.
---
--- tools/flask/policy/policy/modules/xen/xen.te | 7 +- xen/arch/arm/traps.c | 1 + xen/arch/x86/hvm/hvm.c | 1 + xen/arch/x86/x86_64/compat/entry.S | 2 + xen/arch/x86/x86_64/entry.S | 2 + xen/common/compat/kernel.c | 2 + xen/common/kernel.c | 228 ++++++++++++++++++++++----- xen/include/public/arch-arm.h | 2 + xen/include/public/version.h | 70 +++++++- xen/include/public/xen.h | 1 + xen/include/xen/hypercall.h | 4 + xen/include/xsm/dummy.h | 21 +++ xen/include/xsm/xsm.h | 6 + xen/xsm/dummy.c | 1 + xen/xsm/flask/hooks.c | 35 ++++ xen/xsm/flask/policy/access_vectors | 21 ++- 16 files changed, 361 insertions(+), 43 deletions(-)
tools/flask/policy/policy/modules/xen/xen.te +5 -2
@@ -74,11 +74,12 @@ allow dom0_t xen_t:xen2 { get_symbol }; -# Allow dom0 to use all XENVER_ subops that have checks. +# Allow dom0 to use all XENVER_ subops and VERSION subops that have checks. # Note that dom0 is part of domain_type so this has duplicates. allow dom0_t xen_t:version { xen_extraversion xen_compile_info xen_capabilities xen_changeset xen_pagesize xen_guest_handle xen_commandline + extraversion capabilities changeset pagesize guest_handle commandline }; allow dom0_t xen_t:mmu memorymap;
@@ -145,10 +146,12 @@ if (guest_writeconsole) { # pmu_ctrl is for) allow domain_type xen_t:xen2 pmu_use; -# For normal guests all possible except XENVER_commandline. +# For normal guests all possible except XENVER_commandline, VERSION_changeset, +# and VERSION_commandline allow domain_type xen_t:version { xen_extraversion xen_compile_info xen_capabilities xen_changeset xen_pagesize xen_guest_handle + extraversion capabilities pagesize guest_handle }; ###############################################################################
xen/arch/arm/traps.c +1 -0
@@ -1235,6 +1235,7 @@ static arm_hypercall_t arm_hypercall_table[] = {HYPERCALL (multicall,2 ),HYPERCALL (platform_op,1 ),HYPERCALL_ARM (vcpu_op,3 ), + HYPERCALL(version_op, 3), };#ifndef NDEBUG
xen/arch/x86/hvm/hvm.c +1 -0
@@ -5322,6 +5322,7 @@ static const struct {COMPAT_CALL (platform_op),COMPAT_CALL (mmuext_op),HYPERCALL (xenpmu_op), +HYPERCALL (version_op), HYPERCALL(arch_1) };
xen/arch/x86/x86_64/compat/entry.S +2 -0
@@ -394,6 +394,7 @@ ENTRY(compat_hypercall_table) .quad do_tmem_op .quad do_ni_hypercall /* reserved for XenClient */ .quad do_xenpmu_op /* 40 */ + .quad do_version_op .rept __HYPERVISOR_arch_0-((.-compat_hypercall_table)/8) .quad compat_ni_hypercall .endr
@@ -445,6 +446,7 @@ ENTRY(compat_hypercall_args_table) .byte 1 /* do_tmem_op */ .byte 0 /* reserved for XenClient */ .byte 2 /* do_xenpmu_op */ /* 40 */ + .byte 3 /* do_version_op */ .rept __HYPERVISOR_arch_0-(.-compat_hypercall_args_table) .byte 0 /* compat_ni_hypercall */ .endr
xen/arch/x86/x86_64/entry.S +2 -0
@@ -730,6 +730,7 @@ ENTRY(hypercall_table) .quad do_tmem_op .quad do_ni_hypercall /* reserved for XenClient */ .quad do_xenpmu_op /* 40 */ + .quad do_version_op .rept __HYPERVISOR_arch_0-((.-hypercall_table)/8) .quad do_ni_hypercall .endr
@@ -781,6 +782,7 @@ ENTRY(hypercall_args_table) .byte 1 /* do_tmem_op */ .byte 0 /* reserved for XenClient */ .byte 2 /* do_xenpmu_op */ /* 40 */ + .byte 3 /* do_version_op */ .rept __HYPERVISOR_arch_0-(.-hypercall_args_table) .byte 0 /* do_ni_hypercall */ .endr
xen/common/compat/kernel.c +2 -0
@@ -39,6 +39,8 @@ CHECK_TYPE(capabilities_info);CHECK_TYPE (domain_handle); +CHECK_TYPE (version_op_val); +#define xennmi_callback compat_nmi_callback#define xennmi_callback_t compat_nmi_callback_t
xen/common/kernel.c +191 -37
256 lines not on this page · raw message
xen/include/public/arch-arm.h +2 -0
@@ -128,6 +128,8 @@* * VCPUOP_register_vcpu_info * * VCPUOP_register_runstate_memory_area * +* HYPERVISOR_version_op +* All generic sub-operations * * Other notes on the ARM ABI: *
xen/include/public/version.h +69 -1
82 lines not on this page · raw message
xen/include/public/xen.h +1 -0
@@ -115,6 +115,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_ulong_t);#define __HYPERVISOR_tmem_op 38#define __HYPERVISOR_xc_reserved_op 39/* reserved for XenClient */ #define __HYPERVISOR_xenpmu_op 40 +#define __HYPERVISOR_version_op 41/* supersedes xen_version (17) */ /* Architecture-specific hypercall definitions. */ #define __HYPERVISOR_arch_0 48
xen/include/xen/hypercall.h +4 -0
@@ -147,6 +147,10 @@ do_xenoprof_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg);extern long do_xenpmu_op (unsigned int op,XEN_GUEST_HANDLE_PARAM (xen_pmu_params_t) arg); +extern long +do_version_op (unsigned int cmd, +XEN_GUEST_HANDLE_PARAM (void ) arg,unsigned int len); +#ifdef CONFIG_COMPAT extern int
xen/include/xsm/dummy.h +21 -0
@@ -751,3 +751,24 @@ static XSM_INLINE int xsm_xen_version (XSM_DEFAULT_ARG uint32_t op)return xsm_default_action (XSM_PRIV , current->domain,NULL ); } } + +static XSM_INLINE int xsm_version_op (XSM_DEFAULT_ARG uint32_t op) +{ +XSM_ASSERT_ACTION (XSM_OTHER ); +switch ( op ) + { +case XEN_VERSION_version: +case XEN_VERSION_platform_parameters: +case XEN_VERSION_get_features: +/* These MUST always be accessible to any guest by default. */ +return 0 ; +case XEN_VERSION_extraversion: +case XEN_VERSION_capabilities: +case XEN_VERSION_pagesize: +case XEN_VERSION_guest_handle: +/* These can be accessible to a guest. */ +return xsm_default_action (XSM_HOOK , current->domain,NULL ); +default : +return xsm_default_action (XSM_PRIV , current->domain,NULL ); + } +}
xen/include/xsm/xsm.h +6 -0
@@ -194,6 +194,7 @@ struct xsm_operations {int (*pmu_op) (struct domain *d,unsigned int op);#endif int (*xen_version) (uint32_t cmd); +int (*version_op) (uint32_t cmd); };#ifdef CONFIG_XSM
@@ -737,6 +738,11 @@ static inline int xsm_xen_version (xsm_default_t def, uint32_t op) return xsm_ops->xen_version(op); } +static inline int xsm_version_op (xsm_default_t def,uint32_t op) +{ +return xsm_ops->version_op (op); +} +#endif /* XSM_NO_WRAPPERS */ #ifdef CONFIG_MULTIBOOT
xen/xsm/dummy.c +1 -0
@@ -163,4 +163,5 @@ void xsm_fixup_ops (struct xsm_operations *ops)set_to_dummy_if_null (ops, pmu_op);#endif set_to_dummy_if_null (ops, xen_version); +set_to_dummy_if_null (ops, version_op); }
xen/xsm/flask/hooks.c +35 -0
@@ -1658,6 +1658,40 @@ static int flask_xen_version (uint32_t op) } } +static int flask_version_op (uint32_t op) +{ +u32 dsid =domain_sid (current->domain); + +switch ( op ) + { +case XEN_VERSION_version: +case XEN_VERSION_platform_parameters: +case XEN_VERSION_get_features: +/* These MUST always be accessible to any guest by default. */ +return 0 ; +case XEN_VERSION_extraversion: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__EXTRAVERSION ,NULL ); +case XEN_VERSION_capabilities: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__CAPABILITIES ,NULL ); +case XEN_VERSION_changeset: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__CHANGESET ,NULL ); +case XEN_VERSION_pagesize: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__PAGESIZE ,NULL ); +case XEN_VERSION_guest_handle: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__GUEST_HANDLE ,NULL ); +case XEN_VERSION_commandline: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__COMMANDLINE ,NULL ); +default : +return -EPERM ; + } +} +long do_flask_op (XEN_GUEST_HANDLE_PARAM (xsm_op_t) u_flask_op);int compat_flask_op (XEN_GUEST_HANDLE_PARAM (xsm_op_t) u_flask_op);
@@ -1797,6 +1831,7 @@ static struct xsm_operations flask_ops = { .pmu_op = flask_pmu_op, #endif .xen_version = flask_xen_version, + .version_op = flask_version_op, };static __init void flask_init (void )
xen/xsm/flask/policy/access_vectors +18 -3
@@ -496,12 +496,14 @@ class security del_ocontext } -# Class version is used to describe the XENVER_ hypercall. +# Class version is used to describe the XENVER_ and VERSION hypercall. # Almost all sub-ops are described here - in the default case all of them should -# be allowed except the XENVER_commandline. +# be allowed except the XENVER_commandline, VERSION_commandline, and +# VERSION_changeset. # # The ones that are omitted are XENVER_version, XENVER_platform_parameters, -# and XENVER_get_features - as they MUST always be returned to a guest. +# XENVER_get_features, XEN_VERSION_version, XEN_VERSION_platform_parameters, +# and XEN_VERSION_get_features - as they MUST always be returned to a guest. # class version {
@@ -519,4 +521,17 @@ class version xen_guest_handle # Xen command line. xen_commandline +# --- VERSION hypercall --- +# Extra informations (-unstable). + extraversion +# Such as "xen-3.0-x86_64 xen-3.0-x86_32p hvm-3.0-x86_32 hvm-3.0-x86_32p hvm-3.0-x86_64". + capabilities +# Source code changeset. + changeset +# Page size the hypervisor uses. + pagesize +# An value that the control stack can choose. + guest_handle +# Xen command line. + commandline }
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v4 04/34] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 22.03.16 at 21:39, <[email protected]> wrote:
xen/common/kernel.c +6
-0@@ -381,6 +389,137 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)return -ENOSYS ; } +static const char *capabilities_info (unsigned int *len) +{ +static xen_capabilities_info_t __read_mostly cached_cap; +static unsigned int __read_mostly cached_cap_len; +static bool_t cached; +
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 407
Quoted 10 lines
xen/common/kernel.c +10
-0+if (unlikely (!cached) ) + { +arch_get_xen_caps (&cached_cap); + cached_cap_len =strlen (cached_cap) +1 ; + cached =1 ; + } + + *len = cached_cap_len; +return cached_cap; +}
With the init time call to prefill the cache being quite far away, I think you need a comment here. Even better, though, would be if you ditched the function altogether and did the prefilling right in that __init function below, while the consumers of the data would access the static variables directly. In the end that might even allow arch_get_xen_caps() to become __init.
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 515
Quoted 10 lines
xen/common/kernel.c +10
-0+if ( !rc ) + { +unsigned int bytes =min (sz, len); + +if (copy_to_guest (arg, ptr ? : &u, bytes) ) + rc = -EFAULT ; + +/* +* We return len (truncate) worth of data even if we fail. +*/
Single line comment.
Quoted 4 lines
xen/common/kernel.c +0
-0@@ -418,6 +557,21 @@ DO(ni_hypercall)(void)return -ENOSYS ; }
xen/common/kernel.c DO(ni_hypercall)(void) · line 569
Quoted 10 lines
xen/common/kernel.c +10
-0+static int __init kernel_cache_init (void ) +{ +unsigned int len; + +/* +* Pre-allocate the cache so we do not have to worry about +* simultaneous invocations on safe_strcat by guests and the cache +* data becoming garbage. +*/ + (void )capabilities_info (&len);
No need for the cast, afaics.
xen/include/public/version.h typedef struct xen_feature_info xen_feature_info_t; · line 126
Quoted 7 lines
xen/include/public/version.h +7
-0+/* +* arg == xen_version_op_val_t. Encoded as major:minor (31..16:15..0), while +* 63..32 are zero. +*/ +#define XEN_VERSION_version 0 + +/* arg == char. Contains NUL terminated utf-8 string. */
I should have noticed this before: "char" isn't really what you mean here and below. Perhaps better "char[]"?
Quoted 7 lines
xen/xsm/flask/hooks.c +1
-0@@ -1658,6 +1658,40 @@ static int flask_xen_version (uint32_t op) } } +static int flask_version_op (uint32_t op)
xen/xsm/flask/hooks.c static int flask_xen_version (uint32_t op) · line 1671
Quoted 10 lines
xen/xsm/flask/hooks.c +10
-0+{ +u32 dsid =domain_sid (current->domain); + +switch ( op ) + { +case XEN_VERSION_version: +case XEN_VERSION_platform_parameters: +case XEN_VERSION_get_features: +/* These MUST always be accessible to any guest by default. */ +return 0 ;
Perhaps these would better be taken care of in xsm_version_op()? (That consideration then also applies to the other patch of course.)
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Konrad Rzeszutek Wilk
Acked-by Daniel De GraafRe: [PATCH v4 04/34] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.
. fixed all of those ..
Quoted 6 lines
Quoted 6 lines
xen/xsm/flask/hooks.c +0
-0@@ -1658,6 +1658,40 @@ static int flask_xen_version (uint32_t op) } }
Quoted 13 lines
xen/xsm/flask/hooks.c static int flask_xen_version (uint32_t op) · line 1671
Quoted 11 lines
xen/xsm/flask/hooks.c +11
-0+static int flask_version_op (uint32_t op) +{ +u32 dsid =domain_sid (current->domain); + +switch ( op ) + { +case XEN_VERSION_version: +case XEN_VERSION_platform_parameters: +case XEN_VERSION_get_features: +/* These MUST always be accessible to any guest by default. */ +return 0 ;Perhaps these would better be taken care of in
xsm_version_op()?
It would be the oddball one.
All of the xsm_**() in the header file (include/xsm/xsm.h) call the function pointers.
Quoted 1 line
(That consideration then also applies to the other patch of course.)
Here is the updated patch:
From 10ecad7469a5ba12895418aa2d035def852654e7 Mon Sep 17 00:00:00 2001
From: Konrad Rzeszutek Wilk <[email protected]>
Date: Tue, 22 Mar 2016 16:53:19 -0400
Subject: [PATCH] HYPERCALL_version_op. New hypercall mirroring XENVER_ but
sane.
This hypercall mirrors the XENVER_ in that it has similar functionality. However it is designed differently:
- No compat layer. The data structures are the same size on 32 as on 64-bit.
- The hypercall accepts three arguments - the command, pointer to an buffer, and the length of the buffer.
- Each sub-ops can be "probed" for size by returning the size of buffer that will be needed - if the buffer is NULL.
- Subops can complete even if the buffer is too small - truncated data will be filled and hypercall will return -ENOBUFS.
- VERSION_commandline, VERSION_changeset are privileged.
- There is no XENVER_compile_info equivalent.
- The hypercall can return -EPERM and toolstack/OSes are expected to deal with. However there are three subops: XEN_VERSION_version, XEN_VERSION_platform_parameters and XEN_VERSION_get_features that will always return an value as guests cannot survive without them.
While we combine some of the common code between XENVER_ and VERSION_ take the liberty of moving pae_extended_cr3 in x86 area.
---
Cc: Daniel De Graaf <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
v1-v3: Was not part of the series.
v4: New posting.
v5: Remove memset and use {}. Tweak copy_to_guest and capabilities_info,
add ASSERT(sz) per Andrew's review. Add cached=1 back in. Per Jan, s/VERSION_OP/VERSION/, squash size check with do_version_op, update the comments. Dropped Andrew's Review-by. Ate newlines. Added initcall to guard against garbage being set in cached data. Folded code populating cache in __init. s/char/char[]/ in public.h
---
--- tools/flask/policy/policy/modules/xen/xen.te | 7 +- xen/arch/arm/traps.c | 1 + xen/arch/x86/hvm/hvm.c | 1 + xen/arch/x86/x86_64/compat/entry.S | 2 + xen/arch/x86/x86_64/entry.S | 2 + xen/common/compat/kernel.c | 2 + xen/common/kernel.c | 213 ++++++++++++++++++++++----- xen/include/public/arch-arm.h | 2 + xen/include/public/version.h | 70 ++++++++- xen/include/public/xen.h | 1 + xen/include/xen/hypercall.h | 4 + xen/include/xsm/dummy.h | 21 +++ xen/include/xsm/xsm.h | 6 + xen/xsm/dummy.c | 1 + xen/xsm/flask/hooks.c | 35 +++++ xen/xsm/flask/policy/access_vectors | 21 ++- 16 files changed, 346 insertions(+), 43 deletions(-)
tools/flask/policy/policy/modules/xen/xen.te +5 -2
@@ -74,11 +74,12 @@ allow dom0_t xen_t:xen2 { get_symbol }; -# Allow dom0 to use all XENVER_ subops that have checks. +# Allow dom0 to use all XENVER_ subops and VERSION subops that have checks. # Note that dom0 is part of domain_type so this has duplicates. allow dom0_t xen_t:version { xen_extraversion xen_compile_info xen_capabilities xen_changeset xen_pagesize xen_guest_handle xen_commandline + extraversion capabilities changeset pagesize guest_handle commandline }; allow dom0_t xen_t:mmu memorymap;
@@ -145,10 +146,12 @@ if (guest_writeconsole) { # pmu_ctrl is for) allow domain_type xen_t:xen2 pmu_use; -# For normal guests all possible except XENVER_commandline. +# For normal guests all possible except XENVER_commandline, VERSION_changeset, +# and VERSION_commandline allow domain_type xen_t:version { xen_extraversion xen_compile_info xen_capabilities xen_changeset xen_pagesize xen_guest_handle + extraversion capabilities pagesize guest_handle }; ###############################################################################
xen/arch/arm/traps.c +1 -0
@@ -1235,6 +1235,7 @@ static arm_hypercall_t arm_hypercall_table[] = {HYPERCALL (multicall,2 ),HYPERCALL (platform_op,1 ),HYPERCALL_ARM (vcpu_op,3 ), + HYPERCALL(version_op, 3), };#ifndef NDEBUG
xen/arch/x86/hvm/hvm.c +1 -0
@@ -5322,6 +5322,7 @@ static const struct {COMPAT_CALL (platform_op),COMPAT_CALL (mmuext_op),HYPERCALL (xenpmu_op), +HYPERCALL (version_op), HYPERCALL(arch_1) };
xen/arch/x86/x86_64/compat/entry.S +2 -0
@@ -394,6 +394,7 @@ ENTRY(compat_hypercall_table) .quad do_tmem_op .quad do_ni_hypercall /* reserved for XenClient */ .quad do_xenpmu_op /* 40 */ + .quad do_version_op .rept __HYPERVISOR_arch_0-((.-compat_hypercall_table)/8) .quad compat_ni_hypercall .endr
@@ -445,6 +446,7 @@ ENTRY(compat_hypercall_args_table) .byte 1 /* do_tmem_op */ .byte 0 /* reserved for XenClient */ .byte 2 /* do_xenpmu_op */ /* 40 */ + .byte 3 /* do_version_op */ .rept __HYPERVISOR_arch_0-(.-compat_hypercall_args_table) .byte 0 /* compat_ni_hypercall */ .endr
xen/arch/x86/x86_64/entry.S +2 -0
@@ -730,6 +730,7 @@ ENTRY(hypercall_table) .quad do_tmem_op .quad do_ni_hypercall /* reserved for XenClient */ .quad do_xenpmu_op /* 40 */ + .quad do_version_op .rept __HYPERVISOR_arch_0-((.-hypercall_table)/8) .quad do_ni_hypercall .endr
@@ -781,6 +782,7 @@ ENTRY(hypercall_args_table) .byte 1 /* do_tmem_op */ .byte 0 /* reserved for XenClient */ .byte 2 /* do_xenpmu_op */ /* 40 */ + .byte 3 /* do_version_op */ .rept __HYPERVISOR_arch_0-(.-hypercall_args_table) .byte 0 /* do_ni_hypercall */ .endr
xen/common/compat/kernel.c +2 -0
@@ -39,6 +39,8 @@ CHECK_TYPE(capabilities_info);CHECK_TYPE (domain_handle); +CHECK_TYPE (version_op_val); +#define xennmi_callback compat_nmi_callback#define xennmi_callback_t compat_nmi_callback_t
xen/common/kernel.c +176 -37
241 lines not on this page · raw message
xen/include/public/arch-arm.h +2 -0
@@ -128,6 +128,8 @@* * VCPUOP_register_vcpu_info * * VCPUOP_register_runstate_memory_area * +* HYPERVISOR_version_op +* All generic sub-operations * * Other notes on the ARM ABI: *
xen/include/public/version.h +69 -1
82 lines not on this page · raw message
xen/include/public/xen.h +1 -0
@@ -115,6 +115,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_ulong_t);#define __HYPERVISOR_tmem_op 38#define __HYPERVISOR_xc_reserved_op 39/* reserved for XenClient */ #define __HYPERVISOR_xenpmu_op 40 +#define __HYPERVISOR_version_op 41/* supersedes xen_version (17) */ /* Architecture-specific hypercall definitions. */ #define __HYPERVISOR_arch_0 48
xen/include/xen/hypercall.h +4 -0
@@ -147,6 +147,10 @@ do_xenoprof_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg);extern long do_xenpmu_op (unsigned int op,XEN_GUEST_HANDLE_PARAM (xen_pmu_params_t) arg); +extern long +do_version_op (unsigned int cmd, +XEN_GUEST_HANDLE_PARAM (void ) arg,unsigned int len); +#ifdef CONFIG_COMPAT extern int
xen/include/xsm/dummy.h +21 -0
@@ -751,3 +751,24 @@ static XSM_INLINE int xsm_xen_version (XSM_DEFAULT_ARG uint32_t op)return xsm_default_action (XSM_PRIV , current->domain,NULL ); } } + +static XSM_INLINE int xsm_version_op (XSM_DEFAULT_ARG uint32_t op) +{ +XSM_ASSERT_ACTION (XSM_OTHER ); +switch ( op ) + { +case XEN_VERSION_version: +case XEN_VERSION_platform_parameters: +case XEN_VERSION_get_features: +/* These MUST always be accessible to any guest by default. */ +return 0 ; +case XEN_VERSION_extraversion: +case XEN_VERSION_capabilities: +case XEN_VERSION_pagesize: +case XEN_VERSION_guest_handle: +/* These can be accessible to a guest. */ +return xsm_default_action (XSM_HOOK , current->domain,NULL ); +default : +return xsm_default_action (XSM_PRIV , current->domain,NULL ); + } +}
xen/include/xsm/xsm.h +6 -0
@@ -194,6 +194,7 @@ struct xsm_operations {int (*pmu_op) (struct domain *d,unsigned int op);#endif int (*xen_version) (uint32_t cmd); +int (*version_op) (uint32_t cmd); };#ifdef CONFIG_XSM
@@ -737,6 +738,11 @@ static inline int xsm_xen_version (xsm_default_t def, uint32_t op) return xsm_ops->xen_version(op); } +static inline int xsm_version_op (xsm_default_t def,uint32_t op) +{ +return xsm_ops->version_op (op); +} +#endif /* XSM_NO_WRAPPERS */ #ifdef CONFIG_MULTIBOOT
xen/xsm/dummy.c +1 -0
@@ -163,4 +163,5 @@ void xsm_fixup_ops (struct xsm_operations *ops)set_to_dummy_if_null (ops, pmu_op);#endif set_to_dummy_if_null (ops, xen_version); +set_to_dummy_if_null (ops, version_op); }
xen/xsm/flask/hooks.c +35 -0
@@ -1658,6 +1658,40 @@ static int flask_xen_version (uint32_t op) } } +static int flask_version_op (uint32_t op) +{ +u32 dsid =domain_sid (current->domain); + +switch ( op ) + { +case XEN_VERSION_version: +case XEN_VERSION_platform_parameters: +case XEN_VERSION_get_features: +/* These MUST always be accessible to any guest by default. */ +return 0 ; +case XEN_VERSION_extraversion: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__EXTRAVERSION ,NULL ); +case XEN_VERSION_capabilities: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__CAPABILITIES ,NULL ); +case XEN_VERSION_changeset: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__CHANGESET ,NULL ); +case XEN_VERSION_pagesize: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__PAGESIZE ,NULL ); +case XEN_VERSION_guest_handle: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__GUEST_HANDLE ,NULL ); +case XEN_VERSION_commandline: +return avc_has_perm (dsid,SECINITSID_XEN ,SECCLASS_VERSION , +VERSION__COMMANDLINE ,NULL ); +default : +return -EPERM ; + } +} +long do_flask_op (XEN_GUEST_HANDLE_PARAM (xsm_op_t) u_flask_op);int compat_flask_op (XEN_GUEST_HANDLE_PARAM (xsm_op_t) u_flask_op);
@@ -1797,6 +1831,7 @@ static struct xsm_operations flask_ops = { .pmu_op = flask_pmu_op, #endif .xen_version = flask_xen_version, + .version_op = flask_version_op, };static __init void flask_init (void )
xen/xsm/flask/policy/access_vectors +18 -3
@@ -496,12 +496,14 @@ class security del_ocontext } -# Class version is used to describe the XENVER_ hypercall. +# Class version is used to describe the XENVER_ and VERSION hypercall. # Almost all sub-ops are described here - in the default case all of them should -# be allowed except the XENVER_commandline. +# be allowed except the XENVER_commandline, VERSION_commandline, and +# VERSION_changeset. # # The ones that are omitted are XENVER_version, XENVER_platform_parameters, -# and XENVER_get_features - as they MUST always be returned to a guest. +# XENVER_get_features, XEN_VERSION_version, XEN_VERSION_platform_parameters, +# and XEN_VERSION_get_features - as they MUST always be returned to a guest. # class version {
@@ -519,4 +521,17 @@ class version xen_guest_handle # Xen command line. xen_commandline +# --- VERSION hypercall --- +# Extra informations (-unstable). + extraversion +# Such as "xen-3.0-x86_64 xen-3.0-x86_32p hvm-3.0-x86_32 hvm-3.0-x86_32p hvm-3.0-x86_64". + capabilities +# Source code changeset. + changeset +# Page size the hypervisor uses. + pagesize +# An value that the control stack can choose. + guest_handle +# Xen command line. + commandline }
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v4 04/34] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.
Quoted 21 lines
Quoted 7 lines
Quoted 7 lines · On 24.03.16 at 03:37, <[email protected]> wrote:
xen/xsm/flask/hooks.c +0
-0@@ -1658,6 +1658,40 @@ static int flask_xen_version (uint32_t op) } }Quoted 13 lines
xen/xsm/flask/hooks.c static int flask_xen_version (uint32_t op) · line 1671
Quoted 11 lines
xen/xsm/flask/hooks.c +11
-0+static int flask_version_op (uint32_t op) +{ +u32 dsid =domain_sid (current->domain); + +switch ( op ) + { +case XEN_VERSION_version: +case XEN_VERSION_platform_parameters: +case XEN_VERSION_get_features: +/* These MUST always be accessible to any guest by default. */ +return 0 ;Perhaps these would better be taken care of in
xsm_version_op()?
Quoted 3 lines
It would be the oddball one.
All of the xsm_**() in the header file (include/xsm/xsm.h) call the function pointers.
True, but if there appeared any second implementation besides FLASK, it would need to repeat code to meet this backend independent policy. Anyway - I'll leave it to Daniel to judge.
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 392
Quoted 5 lines
xen/common/kernel.c +1
-0@@ -381,6 +389,123 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)return -ENOSYS ; } +/* Computed be kernel_cache_init. */
... by ...
And I also think kernel_cache_init is a bad name - you initialize the capabilities cache, not some kernel cache.
Quoted 6 lines
xen/common/kernel.c +2
-0@@ -418,6 +543,20 @@ DO(ni_hypercall)(void)return -ENOSYS ; } +static int __init kernel_cache_init (void ) +{
xen/common/kernel.c DO(ni_hypercall)(void) · line 557
Quoted 10 lines
xen/common/kernel.c +10
-0+/* +* Pre-allocate the cache so we do not have to worry about +* simultaneous invocations on safe_strcat by guests and the cache +* data becoming garbage. +*/ +arch_get_xen_caps (&cached_cap); + cached_cap_len =strlen (cached_cap) +1 ; + +return 0 ; +}
With this I'm now missing the conversion of arch_get_xen_caps() to __init. Or was this meant to become a follow-up patch (since it might get a little larger if at once also taking care of moving the string literals into .init.*)?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 04/34] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.
Quoted 21 lines · Jan Beulich
Quoted 21 lines
Quoted 20 lines
Quoted 8 lines · On 24.03.16 at 03:37, <[email protected]> wrote:
xen/xsm/flask/hooks.c +1
-0@@ -1658,6 +1658,40 @@ static int flask_xen_version (uint32_t op) } } +static int flask_version_op (uint32_t op)xen/xsm/flask/hooks.c static int flask_xen_version (uint32_t op) · line 1671
Quoted 10 lines
xen/xsm/flask/hooks.c +10
-0+{ +u32 dsid =domain_sid (current->domain); + +switch ( op ) + { +case XEN_VERSION_version: +case XEN_VERSION_platform_parameters: +case XEN_VERSION_get_features: +/* These MUST always be accessible to any guest by default. */ +return 0 ;Perhaps these would better be taken care of in
xsm_version_op()?
Quoted 7 lines
Quoted 3 lines
It would be the oddball one.
All of the xsm_**() in the header file (include/xsm/xsm.h) call the function pointers.True, but if there appeared any second implementation besides FLASK, it would need to repeat code to meet this backend independent policy. Anyway - I'll leave it to Daniel to judge.
/me nods.
Quoted 11 lines
xen/common/kernel.c DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 392
Quoted 6 lines
xen/common/kernel.c +1
-0@@ -381,6 +389,123 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)return -ENOSYS ; } +/* Computed be kernel_cache_init. */ ... by ...
And I also think
kernel_cache_initis a bad name - you initialize the capabilities cache, not some kernel cache.
/me nods.
Quoted 14 lines
Quoted 14 lines
xen/common/kernel.c +9
-0@@ -418,6 +543,20 @@ DO(ni_hypercall)(void)return -ENOSYS ; } +static int __init kernel_cache_init (void ) +{ +/* +* Pre-allocate the cache so we do not have to worry about +* simultaneous invocations on safe_strcat by guests and the cache +* data becoming garbage. +*/ +arch_get_xen_caps (&cached_cap); + cached_cap_len =strlen (cached_cap) +1 ;
Quoted 8 lines
xen/common/kernel.c DO(ni_hypercall)(void) · line 557
Quoted 3 lines
xen/common/kernel.c +3
-0+ +return 0 ; +}With this I'm now missing the conversion of
arch_get_xen_caps()to__init. Or was this meant to become a follow-up patch (since it might get a little larger if at once also taking care of moving the string literals into .init.*)?
A follow up.
Quoted 3 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 04/34] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane.
In reply to Konrad Rzeszutek WilkQuoted 15 lines · Konrad Rzeszutek Wilk
This hypercall mirrors the
XENVER_in that it has similar functionality. However it is designed differently:
- No compat layer. The data structures are the same size on 32as on 64-bit.- The hypercall accepts three arguments - the command, pointer to an buffer, and the length of the buffer.
- Each sub-ops can be "probed" for size by returning the size of buffer that will be needed - if the buffer is NULL.
- Subops can complete even if the buffer is too slow - truncated data will be filled and hypercall will return-ENOBUFS.
-VERSION_OP_commandline,VERSION_OP_changesetare privileged.
- There are noXENVER_compile_infoequivalent.
- The hypercall can return-EPERMand toolstack/OSes are expected to deal with it.
Quoted 2 lines
Suggested-by Andrew Cooper <[email protected]>Signed-off-by Konrad Rzeszutek Wilk <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v4 5/34 libxc/libxl/python/xenstat: Use new XEN_VERSION_OP hypercall
In reply to Konrad Rzeszutek WilkWe change the xen_version libxc code to use the new hypercall. Which of course means every user in the code base has to be changed over.
It is important to note that the xc_version_op has a different return semantic than the previous one. It returns negative values on error (like the old one), but it also returns an positive value on success (unlike the old one). The positive value is the number of bytes copied in.
---
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: David Scott <[email protected]>
Cc: George Dunlap <[email protected]>
v2: Use xc_version_op_val_t instead of uint32 or such
v3: Make sure to check ret < 0 instead of ret (as it returns the size) -
in Ocaml code. Found by Andrew.
v4: Update comment for xc_version to mention the return the size
--- tools/libxc/include/xenctrl.h | 24 ++++++++++- tools/libxc/xc_core.c | 35 +++++++-------- tools/libxc/xc_dom_boot.c | 12 +++++- tools/libxc/xc_domain.c | 3 +- tools/libxc/xc_private.c | 53 ++++------------------- tools/libxc/xc_private.h | 7 +-- tools/libxc/xc_resume.c | 3 +- tools/libxc/xc_sr_save.c | 9 ++-- tools/libxc/xg_save_restore.h | 6 ++- tools/libxl/libxl.c | 79 ++++++++++++++++++++++------------ tools/ocaml/libs/xc/xenctrl_stubs.c | 39 +++++++---------- tools/python/xen/lowlevel/xc/xc.c | 30 +++++++------ tools/xenstat/libxenstat/src/xenstat.c | 12 +++--- tools/xentrace/xenctx.c | 3 +- 14 files changed, 169 insertions(+), 146 deletions(-)
tools/libxc/include/xenctrl.h +23 -1
@@ -1477,7 +1477,29 @@ int xc_tbuf_set_evt_mask(xc_interface *xch, uint32_t mask);int xc_domctl (xc_interface *xch,struct xen_domctl *domctl);int xc_sysctl (xc_interface *xch,struct xen_sysctl *sysctl); -int xc_version (xc_interface *xch,int cmd,void *arg); +/** +* This function returns the size of buffer to be allocated for +* the cmd. The cmd are XEN_VERSION_OP_*. +*/ +int xc_version_len (xc_interface *xch,unsigned int cmd); +/** +* This function retrieves the information from the version_op hypercall. +* The len is the size of the arg buffer. If arg is NULL, will not +* perform hypercall - instead will just return the size of arg +* buffer that is needed. +* +* Note that prior to Xen 4.7 this would return 0 for success and +* negative value (-1) for error (with the error in errno). In Xen 4.7 +* and later for success it will return an positive value which is the +* number of bytes copied in arg. +* +* It can also return -1 with various errno values: +* - EPERM - not permitted. +* - ENOBUFS - the len was to short, output in arg truncated. +* - ENOSYS - not implemented. +* +*/ +int xc_version (xc_interface *xch,unsigned int cmd,void *arg,ssize_t len);int xc_flask_op (xc_interface *xch,xen_flask_op_t *op);
tools/libxc/xc_core.c +18 -17
@@ -270,42 +270,43 @@ elfnote_fill_xen_version(xc_interface *xch, *xen_version) {int rc; +xen_version_op_val_t val =0 ;memset (xen_version,0 ,sizeof (*xen_version)); - rc =xc_version (xch, XENVER_version,NULL ); + rc =xc_version (xch, XEN_VERSION_OP_version, &val,sizeof (val));if ( rc <0 )return rc; - xen_version->major_version = rc >>16 ; - xen_version->minor_version = rc & ((1 <<16 ) -1 ); + xen_version->major_version = val >>16 ; + xen_version->minor_version = val & ((1 <<16 ) -1 ); - rc =xc_version (xch, XENVER_extraversion, - &xen_version->extra_version); + rc =xc_version (xch, XEN_VERSION_OP_extraversion, + xen_version->extra_version, +sizeof (xen_version->extra_version));if ( rc <0 )return rc; - rc =xc_version (xch, XENVER_compile_info, - &xen_version->compile_info); + rc =xc_version (xch, XEN_VERSION_OP_capabilities, + xen_version->capabilities, +sizeof (xen_version->capabilities));if ( rc <0 )return rc; - rc =xc_version (xch, - XENVER_capabilities, &xen_version->capabilities); + rc =xc_version (xch, XEN_VERSION_OP_changeset, xen_version->changeset, +sizeof (xen_version->changeset));if ( rc <0 )return rc; - rc =xc_version (xch, XENVER_changeset, &xen_version->changeset); + rc =xc_version (xch, XEN_VERSION_OP_platform_parameters, + &xen_version->platform_parameters, +sizeof (xen_version->platform_parameters));if ( rc <0 )return rc; - rc =xc_version (xch, XENVER_platform_parameters, - &xen_version->platform_parameters); + val =0 ; + rc =xc_version (xch, XEN_VERSION_OP_pagesize, &val,sizeof (val));if ( rc <0 )return rc; - - rc =xc_version (xch, XENVER_pagesize,NULL ); -if ( rc <0 ) -return rc; - xen_version->pagesize = rc; + xen_version->pagesize = val;return 0 ; }
tools/libxc/xc_dom_boot.c +10 -2
@@ -112,11 +112,19 @@ int xc_dom_compat_check(struct xc_dom_image *dom)int xc_dom_boot_xen_init (struct xc_dom_image *dom,xc_interface *xch,domid_t domid) { +xen_version_op_val_t val =0 ; + +if (xc_version (xch, XEN_VERSION_OP_version, &val,sizeof (val)) <0 ) + { +xc_dom_panic (xch,XC_INTERNAL_ERROR ,"can't get Xen version!" ); +return -1 ; + } + dom->xen_version = val; dom->xch = xch; dom->guest_domid = domid; - dom->xen_version =xc_version (xch, XENVER_version,NULL ); -if (xc_version (xch, XENVER_capabilities, &dom->xen_caps) <0 ) +if (xc_version (xch, XEN_VERSION_OP_capabilities, dom->xen_caps, +sizeof (dom->xen_caps)) <0 ) {xc_dom_panic (xch,XC_INTERNAL_ERROR ,"can't get xen capabilities" );return -1 ;
tools/libxc/xc_domain.c +2 -1
@@ -2084,7 +2084,8 @@ int xc_map_domain_meminfo(xc_interface *xch, int domid, _di.guest_width = minfo->guest_width;/* Get page table levels (see get_platform_info() in xg_save_restore.h */ -if (xc_version (xch, XENVER_capabilities, &xen_caps) ) +if (xc_version (xch, XEN_VERSION_OP_capabilities, xen_caps, +sizeof (xen_caps)) <0 ) {PERROR ("Could not get Xen capabilities (for page table levels)" );return -1 ;
tools/libxc/xc_private.c +9 -44
67 lines not on this page · raw message
tools/libxc/xc_private.h +4 -3
@@ -214,11 +214,12 @@ void xc__hypercall_buffer_cache_release(xc_interface *xch);* Hypercall interfaces. */ -static inline int do_xen_version (xc_interface *xch,int cmd,xc_hypercall_buffer_t *dest) +static inline long do_version_op (xc_interface *xch,int cmd, +xc_hypercall_buffer_t *dest,ssize_t len) {DECLARE_HYPERCALL_BUFFER_ARGUMENT (dest); -return xencall2 (xch->xcall, __HYPERVISOR_xen_version, - cmd,HYPERCALL_BUFFER_AS_ARG (dest)); +return xencall3 (xch->xcall, __HYPERVISOR_version_op, + cmd,HYPERCALL_BUFFER_AS_ARG (dest), len); }static inline int do_physdev_op (xc_interface *xch,int cmd,void *op,size_t len)
tools/libxc/xc_resume.c +2 -1
@@ -56,7 +56,8 @@ static int modify_returncode(xc_interface *xch, uint32_t domid)return 0 ;/* HVM guests have host address width. */ -if (xc_version (xch, XENVER_capabilities, &caps) !=0 ) +if (xc_version (xch, XEN_VERSION_OP_capabilities, caps, +sizeof (caps)) <0 ) {PERROR ("Could not get Xen capabilities" );return -1 ;
tools/libxc/xc_sr_save.c +5 -4
@@ -9,7 +9,7 @@static int write_headers (struct xc_sr_context *ctx,uint16_t guest_type) {xc_interface *xch = ctx->xch; -int32_t xen_version =xc_version (xch, XENVER_version,NULL ); +xen_version_op_val_t xen_version;struct xc_sr_ihdr ihdr = { .marker =IHDR_MARKER ,
@@ -21,15 +21,16 @@ static int write_headers(struct xc_sr_context *ctx, uint16_t guest_type) { .type = guest_type, .page_shift = XC_PAGE_SHIFT, - .xen_major = (xen_version >> 16) & 0xffff, - .xen_minor = (xen_version) & 0xffff, }; -if ( xen_version <0 ) +if (xc_version (xch, XEN_VERSION_OP_version, &xen_version, +sizeof (xen_version)) <0 ) {PERROR ("Unable to obtain Xen Version" );return -1 ; } + dhdr.xen_major = (xen_version >>16 ) &0xffff ; + dhdr.xen_minor = (xen_version) &0xffff ;if (write_exact (ctx->fd, &ihdr,sizeof (ihdr)) ) {
tools/libxc/xg_save_restore.h +4 -2
@@ -57,10 +57,12 @@ static inline int get_platform_info(xc_interface *xch, uint32_t dom,xen_capabilities_info_t xen_caps ="" ;xen_platform_parameters_t xen_params; -if (xc_version (xch, XENVER_platform_parameters, &xen_params) !=0 ) +if (xc_version (xch, XEN_VERSION_OP_platform_parameters, &xen_params, +sizeof (xen_params)) <0 )return 0 ; -if (xc_version (xch, XENVER_capabilities, &xen_caps) !=0 ) +if (xc_version (xch, XEN_VERSION_OP_capabilities, xen_caps, +sizeof (xen_caps)) <0 )return 0 ;if (xc_maximum_ram_page (xch, max_mfn))
tools/libxl/libxl.c +51 -28
101 lines not on this page · raw message
tools/ocaml/libs/xc/xenctrl_stubs.c +16 -23
@@ -853,21 +853,21 @@ CAMLprim value stub_xc_version_version(value xch)CAMLparam1 (xch);CAMLlocal1 (result);xen_extraversion_t extra; -long packed; +xen_version_op_val_t packed;int retval;caml_enter_blocking_section (); - packed =xc_version (_H (xch), XENVER_version,NULL ); + retval =xc_version (_H (xch), XEN_VERSION_OP_version, &packed,sizeof (packed));caml_leave_blocking_section (); -if (packed <0 ) +if (retval <0 )failwith_xc (_H (xch));caml_enter_blocking_section (); - retval =xc_version (_H (xch), XENVER_extraversion, &extra); + retval =xc_version (_H (xch), XEN_VERSION_OP_extraversion, &extra,sizeof (extra));caml_leave_blocking_section (); -if (retval) +if (retval <0 )failwith_xc (_H (xch)); result =caml_alloc_tuple (3 );
@@ -884,37 +884,28 @@ CAMLprim value stub_xc_version_compile_info(value xch) {CAMLparam1 (xch);CAMLlocal1 (result); -xen_compile_info_t ci; -int retval; - -caml_enter_blocking_section (); - retval =xc_version (_H (xch), XENVER_compile_info, &ci); -caml_leave_blocking_section (); - -if (retval) -failwith_xc (_H (xch)); result =caml_alloc_tuple (4 ); -Store_field (result,0 ,caml_copy_string (ci.compiler)); -Store_field (result,1 ,caml_copy_string (ci.compile_by)); -Store_field (result,2 ,caml_copy_string (ci.compile_domain)); -Store_field (result,3 ,caml_copy_string (ci.compile_date)); +Store_field (result,0 ,caml_copy_string ("" )); +Store_field (result,1 ,caml_copy_string ("" )); +Store_field (result,2 ,caml_copy_string ("" )); +Store_field (result,3 ,caml_copy_string ("" ));CAMLreturn (result); } -static value xc_version_single_string (value xch,int code,void *info) +static value xc_version_single_string (value xch,int code,void *info,ssize_t len) {CAMLparam1 (xch);int retval;caml_enter_blocking_section (); - retval =xc_version (_H (xch), code, info); + retval =xc_version (_H (xch), code, info, len);caml_leave_blocking_section (); -if (retval) +if (retval <0 )failwith_xc (_H (xch));CAMLreturn (caml_copy_string ((char *)info));
@@ -925,7 +916,8 @@ CAMLprim value stub_xc_version_changeset(value xch) {xen_changeset_info_t ci; -return xc_version_single_string (xch, XENVER_changeset, &ci); +return xc_version_single_string (xch, XEN_VERSION_OP_changeset, + &ci,sizeof (ci)); }
@@ -933,7 +925,8 @@ CAMLprim value stub_xc_version_capabilities(value xch) {xen_capabilities_info_t ci; -return xc_version_single_string (xch, XENVER_capabilities, &ci); +return xc_version_single_string (xch, XEN_VERSION_OP_capabilities, + &ci,sizeof (ci)); }
tools/python/xen/lowlevel/xc/xc.c +18 -12
@@ -1204,34 +1204,40 @@ static PyObject *pyxc_xeninfo(XcObject *self)xen_capabilities_info_t xen_caps;xen_platform_parameters_t p_parms;xen_commandline_t xen_commandline; -long xen_version; -long xen_pagesize; +xen_version_op_val_t xen_version; +xen_version_op_val_t xen_pagesize;char str[128 ]; - xen_version =xc_version (self->xc_handle, XENVER_version,NULL ); - -if (xc_version (self->xc_handle, XENVER_extraversion, &xen_extra) !=0 ) +if (xc_version (self->xc_handle, XEN_VERSION_OP_version, &xen_version, +sizeof (xen_version)) <0 )return pyxc_error_to_exception (self->xc_handle); -if (xc_version (self->xc_handle, XENVER_compile_info, &xen_cc) !=0 ) +if (xc_version (self->xc_handle, XEN_VERSION_OP_extraversion, &xen_extra, +sizeof (xen_extra)) <0 )return pyxc_error_to_exception (self->xc_handle); -if (xc_version (self->xc_handle, XENVER_changeset, &xen_chgset) !=0 ) +memset (&xen_cc,0 ,sizeof (xen_cc)); + +if (xc_version (self->xc_handle, XEN_VERSION_OP_changeset, &xen_chgset, +sizeof (xen_chgset)) <0 )return pyxc_error_to_exception (self->xc_handle); -if (xc_version (self->xc_handle, XENVER_capabilities, &xen_caps) !=0 ) +if (xc_version (self->xc_handle, XEN_VERSION_OP_capabilities, &xen_caps, +sizeof (xen_caps)) <0 )return pyxc_error_to_exception (self->xc_handle); -if (xc_version (self->xc_handle, XENVER_platform_parameters, &p_parms) !=0 ) +if (xc_version (self->xc_handle, XEN_VERSION_OP_platform_parameters, + &p_parms,sizeof (p_parms)) <0 )return pyxc_error_to_exception (self->xc_handle); -if (xc_version (self->xc_handle, XENVER_commandline, &xen_commandline) !=0 ) +if (xc_version (self->xc_handle, XEN_VERSION_OP_commandline, + &xen_commandline,sizeof (xen_commandline)) <0 )return pyxc_error_to_exception (self->xc_handle);snprintf (str,sizeof (str),"virt_start=0x%" PRI_xen_ulong, p_parms.virt_start); - xen_pagesize =xc_version (self->xc_handle, XENVER_pagesize,NULL ); -if (xen_pagesize <0 ) +if (xc_version (self->xc_handle, XEN_VERSION_OP_pagesize, &xen_pagesize, +sizeof (xen_pagesize)) <0 )return pyxc_error_to_exception (self->xc_handle); return Py_BuildValue("{s:i,s:i,s:s,s:s,s:i,s:s,s:s,s:s,s:s,s:s,s:s,s:s}",
tools/xenstat/libxenstat/src/xenstat.c +5 -7
@@ -621,20 +621,18 @@ unsigned long long xenstat_network_tdrop(xenstat_network * network)/* Collect Xen version information */ static int xenstat_collect_xen_version (xenstat_node * node) { -long vnum =0 ; +xen_version_op_val_t vnum =0 ;xen_extraversion_t version;/* Collect Xen version information if not already collected */ if (node->handle->xen_version[0 ] =='\0' ) {/* Get the Xen version number and extraversion string */ - vnum =xc_version (node->handle->xc_handle, - XENVER_version,NULL ); - -if (vnum <0 ) +if (xc_version (node->handle->xc_handle, + XEN_VERSION_OP_version, &vnum,sizeof (vnum)) <0 )return 0 ; -if (xc_version (node->handle->xc_handle, XENVER_extraversion, - &version) <0 ) +if (xc_version (node->handle->xc_handle, XEN_VERSION_OP_extraversion, + &version,sizeof (version)) <0 )return 0 ;/* Format the version information as a string and store it */ snprintf(node->handle->xen_version, VERSION_SIZE, "%ld.%ld%s",
tools/xentrace/xenctx.c +2 -1
@@ -1000,7 +1000,8 @@ static void dump_ctx(int vcpu) guest_word_size = (cpuctx.msr_efer &0x400 ) ?8 : guest_protected_mode ?4 :2 ;/* HVM guest context records are always host-sized */ -if (xc_version (xenctx.xc_handle, XENVER_capabilities, &xen_caps) !=0 ) { +if (xc_version (xenctx.xc_handle, XEN_VERSION_OP_capabilities, + &xen_caps,sizeof (xen_caps)) <0 ) {perror ("xc_version" );return ; }
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v4 05/34] libxc/libxl/python/xenstat: Use new XEN_VERSION_OP hypercall
Quoted 45 lines · Konrad Rzeszutek Wilk
We change the
xen_versionlibxc code to use the new hypercall. Which of course means every user in the code base has to be changed over.It is important to note that the
xc_version_ophas a different return semantic than the previous one. It returns negative values on error (like the old one), but it also returns an positive value on success (unlike the old one). The positive value is the number of bytes copied in.Signed-off-by Konrad Rzeszutek Wilk <[email protected]>---
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: David Scott <[email protected]>
Cc: George Dunlap <[email protected]>v2: Use
xc_version_op_val_tinstead of uint32 or such
v3: Make sure to check ret < 0 instead of ret (as it returns the size) -
in Ocaml code. Found by Andrew.
v4: Update comment forxc_versionto mention the return the size--- tools/libxc/include/xenctrl.h | 24 ++++++++++- tools/libxc/xc_core.c | 35 +++++++-------- tools/libxc/xc_dom_boot.c | 12 +++++- tools/libxc/xc_domain.c | 3 +- tools/libxc/xc_private.c | 53 ++++------------------- tools/libxc/xc_private.h | 7 +-- tools/libxc/xc_resume.c | 3 +- tools/libxc/xc_sr_save.c | 9 ++-- tools/libxc/xg_save_restore.h | 6 ++- tools/libxl/libxl.c | 79 ++++++++++++++++++++++------------ tools/ocaml/libs/xc/xenctrl_stubs.c | 39 +++++++---------- tools/python/xen/lowlevel/xc/xc.c | 30 +++++++------ tools/xenstat/libxenstat/src/xenstat.c | 12 +++--- tools/xentrace/xenctx.c | 3 +- 14 files changed, 169 insertions(+), 146 deletions(-)tools/libxc/include/xenctrl.h +0
-0
tools/libxc/include/xenctrl.h int xc_tbuf_set_evt_mask(xc_interface *xch, uint32_t mask); · line 1483
Quoted 8 lines
tools/libxc/include/xenctrl.h +4
-1@@ -1477,7 +1477,29 @@ int xc_tbuf_set_evt_mask(xc_interface *xch, uint32_t mask);int xc_domctl (xc_interface *xch,struct xen_domctl *domctl);int xc_sysctl (xc_interface *xch,struct xen_sysctl *sysctl); -int xc_version (xc_interface *xch,int cmd,void *arg); +/** +* This function returns the size of buffer to be allocated for +* the cmd. The cmd are XEN_VERSION_OP_*. +*/
This should return ssize_t as it could also plausibly return -1 and set errno.
Quoted 9 lines
tools/libxc/include/xenctrl.h +9
-0+int xc_version_len (xc_interface *xch,unsigned int cmd); +/** +* This function retrieves the information from the version_op hypercall. +* The len is the size of the arg buffer. If arg is NULL, will not +* perform hypercall - instead will just return the size of arg +* buffer that is needed. +* +* Note that prior to Xen 4.7 this would return 0 for success and +* negative value (-1) for error (with the error in errno). In Xen 4.7
tools/libxc/include/xenctrl.h int xc_tbuf_set_evt_mask(xc_interface *xch, uint32_t mask); · line 1502
Quoted 10 lines
tools/libxc/include/xenctrl.h +10
-0+* and later for success it will return an positive value which is the +* number of bytes copied in arg. +* +* It can also return -1 with various errno values: +* - EPERM - not permitted. +* - ENOBUFS - the len was to short, output in arg truncated. +* - ENOSYS - not implemented. +* +*/ +int xc_version (xc_interface *xch,unsigned int cmd,void *arg,ssize_t len);
This can get away with taking a size_t len. I am not sure how much we care about people trying to claim negative length for *arg.
Quoted 9 lines
tools/python/xen/lowlevel/xc/xc.c +0
-1@@ -1204,34 +1204,40 @@ static PyObject *pyxc_xeninfo(XcObject *self)xen_capabilities_info_t xen_caps;xen_platform_parameters_t p_parms;xen_commandline_t xen_commandline; -long xen_version;
tools/python/xen/lowlevel/xc/xc.c static PyObject *pyxc_xeninfo(XcObject *self) · line 1212
Quoted 10 lines
tools/python/xen/lowlevel/xc/xc.c +4
-4-long xen_pagesize; +xen_version_op_val_t xen_version; +xen_version_op_val_t xen_pagesize;char str[128 ]; - xen_version =xc_version (self->xc_handle, XENVER_version,NULL ); - -if (xc_version (self->xc_handle, XENVER_extraversion, &xen_extra) !=0 ) +if (xc_version (self->xc_handle, XEN_VERSION_OP_version, &xen_version, +sizeof (xen_version)) <0 )
Xen Style.
Quoted 10 lines
tools/xenstat/libxenstat/src/xenstat.c +1
-1@@ -621,20 +621,18 @@ unsigned long long xenstat_network_tdrop(xenstat_network * network)/* Collect Xen version information */ static int xenstat_collect_xen_version (xenstat_node * node) { -long vnum =0 ; +xen_version_op_val_t vnum =0 ;xen_extraversion_t version;
tools/xenstat/libxenstat/src/xenstat.c unsigned long long xenstat_network_tdrop(xenstat_network * network) · line 632
Quoted 10 lines
tools/xenstat/libxenstat/src/xenstat.c +2
-4/* Collect Xen version information if not already collected */ if (node->handle->xen_version[0 ] =='\0' ) {/* Get the Xen version number and extraversion string */ - vnum =xc_version (node->handle->xc_handle, - XENVER_version,NULL ); - -if (vnum <0 ) +if (xc_version (node->handle->xc_handle, + XEN_VERSION_OP_version, &vnum,sizeof (vnum)) <0 )return 0 ;
Curiously, the opposite style bug here.
With these trivial bits fixed, Reviewed-by: Andrew Cooper <[email protected]>, and a Tested-by: for the Ocaml stubs (eventually).
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 05/34] libxc/libxl/python/xenstat: Use new XEN_VERSION_OP hypercall
In reply to Konrad Rzeszutek WilkQuoted 10 lines · Konrad Rzeszutek Wilk
We change the
xen_versionlibxc code to use the new hypercall. Which of course means every user in the code base has to be changed over.It is important to note that the
xc_version_ophas a different return semantic than the previous one. It returns negative values on error (like the old one), but it also returns an positive value on success (unlike the old one). The positive value is the number of bytes copied in.
Quoted 8 lines
Signed-off-by Konrad Rzeszutek Wilk <[email protected]>---
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: David Scott <[email protected]>
Cc: George Dunlap <[email protected]>
xenctx bit:
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 05/34] libxc/libxl/python/xenstat: Use new XEN_VERSION_OP hypercall
In reply to Konrad Rzeszutek WilkOn Tue, Mar 15, 2016 at 01:56:27PM -0400, Konrad Rzeszutek Wilk wrote:
[...]
Quoted 24 lines
tools/libxc/xg_save_restore.h +4
-2@@ -57,10 +57,12 @@ static inline int get_platform_info(xc_interface *xch, uint32_t dom,xen_capabilities_info_t xen_caps ="" ;xen_platform_parameters_t xen_params; -if (xc_version (xch, XENVER_platform_parameters, &xen_params) !=0 ) +if (xc_version (xch, XEN_VERSION_OP_platform_parameters, &xen_params, +sizeof (xen_params)) <0 )return 0 ; -if (xc_version (xch, XENVER_capabilities, &xen_caps) !=0 ) +if (xc_version (xch, XEN_VERSION_OP_capabilities, xen_caps, +sizeof (xen_caps)) <0 )return 0 ;if (xc_maximum_ram_page (xch, max_mfn))tools/libxl/libxl.c +0
-0
tools/libxl/libxl.c libxl_numainfo *libxl_get_numainfo(libxl_ctx *ctx, int *nr) · line 5196
Quoted 6 lines
tools/libxl/libxl.c +3
-0@@ -5191,50 +5191,73 @@ libxl_numainfo *libxl_get_numainfo(libxl_ctx *ctx, int *nr)return ret; } + +static int xc_version_wrapper (libxl_ctx *ctx,unsigned int cmd,char *buf,ssize_t len,char **dst) +{
This function should accept libxl__gc *gc instead of libxl_ctx.
Preferably is should be renamed to
libxl__xc_version_wrapper
tools/libxl/libxl.c libxl_numainfo *libxl_get_numainfo(libxl_ctx *ctx, int *nr) · line 5200
Quoted 4 lines
tools/libxl/libxl.c +4
-0+GC_INIT (ctx); +int r; + + r =xc_version (ctx->xch, cmd, buf, len);
Then here CTX->xch
tools/libxl/libxl.c libxl_numainfo *libxl_get_numainfo(libxl_ctx *ctx, int *nr) · line 5209
Quoted 9 lines
tools/libxl/libxl.c +9
-0+if ( r == -EPERM ) + buf[0 ] ='\0' ; +else if ( r <0 ) + { +GC_FREE ; +return r; + } + *dst =libxl__strdup (NOGC , buf); +GC_FREE ;
Then get rid of all GC_* macros.
Quoted 4 lines
tools/libxl/libxl.c +3
-0+return 0 ; +} +const libxl_version_info *libxl_get_version_info (libxl_ctx *ctx)
[...]
Quoted 26 lines
tools/python/xen/lowlevel/xc/xc.c +6
-6@@ -1204,34 +1204,40 @@ static PyObject *pyxc_xeninfo(XcObject *self)xen_capabilities_info_t xen_caps;xen_platform_parameters_t p_parms;xen_commandline_t xen_commandline; -long xen_version; -long xen_pagesize; +xen_version_op_val_t xen_version; +xen_version_op_val_t xen_pagesize;char str[128 ]; - xen_version =xc_version (self->xc_handle, XENVER_version,NULL ); - -if (xc_version (self->xc_handle, XENVER_extraversion, &xen_extra) !=0 ) +if (xc_version (self->xc_handle, XEN_VERSION_OP_version, &xen_version, +sizeof (xen_version)) <0 )return pyxc_error_to_exception (self->xc_handle); -if (xc_version (self->xc_handle, XENVER_compile_info, &xen_cc) !=0 ) +if (xc_version (self->xc_handle, XEN_VERSION_OP_extraversion, &xen_extra, +sizeof (xen_extra)) <0 )return pyxc_error_to_exception (self->xc_handle);
tools/python/xen/lowlevel/xc/xc.c static PyObject *pyxc_xeninfo(XcObject *self) · line 1226
Quoted 10 lines
tools/python/xen/lowlevel/xc/xc.c +6
-2-if (xc_version (self->xc_handle, XENVER_changeset, &xen_chgset) !=0 ) +memset (&xen_cc,0 ,sizeof (xen_cc)); + +if (xc_version (self->xc_handle, XEN_VERSION_OP_changeset, &xen_chgset, +sizeof (xen_chgset)) <0 )return pyxc_error_to_exception (self->xc_handle); -if (xc_version (self->xc_handle, XENVER_capabilities, &xen_caps) !=0 ) +if (xc_version (self->xc_handle, XEN_VERSION_OP_capabilities, &xen_caps, +sizeof (xen_caps)) <0 )
Indentation.
Quoted 32 lines
tools/python/xen/lowlevel/xc/xc.c +6
-4return pyxc_error_to_exception (self->xc_handle); -if (xc_version (self->xc_handle, XENVER_platform_parameters, &p_parms) !=0 ) +if (xc_version (self->xc_handle, XEN_VERSION_OP_platform_parameters, + &p_parms,sizeof (p_parms)) <0 )return pyxc_error_to_exception (self->xc_handle); -if (xc_version (self->xc_handle, XENVER_commandline, &xen_commandline) !=0 ) +if (xc_version (self->xc_handle, XEN_VERSION_OP_commandline, + &xen_commandline,sizeof (xen_commandline)) <0 )return pyxc_error_to_exception (self->xc_handle);snprintf (str,sizeof (str),"virt_start=0x%" PRI_xen_ulong, p_parms.virt_start); - xen_pagesize =xc_version (self->xc_handle, XENVER_pagesize,NULL ); -if (xen_pagesize <0 ) +if (xc_version (self->xc_handle, XEN_VERSION_OP_pagesize, &xen_pagesize, +sizeof (xen_pagesize)) <0 )return pyxc_error_to_exception (self->xc_handle); return Py_BuildValue("{s:i,s:i,s:s,s:s,s:i,s:s,s:s,s:s,s:s,s:s,s:s,s:s}",tools/xenstat/libxenstat/src/xenstat.c +1
-1@@ -621,20 +621,18 @@ unsigned long long xenstat_network_tdrop(xenstat_network * network)/* Collect Xen version information */ static int xenstat_collect_xen_version (xenstat_node * node) { -long vnum =0 ; +xen_version_op_val_t vnum =0 ;xen_extraversion_t version;
tools/xenstat/libxenstat/src/xenstat.c unsigned long long xenstat_network_tdrop(xenstat_network * network) · line 631
Quoted 10 lines
tools/xenstat/libxenstat/src/xenstat.c +2
-4/* Collect Xen version information if not already collected */ if (node->handle->xen_version[0 ] =='\0' ) {/* Get the Xen version number and extraversion string */ - vnum =xc_version (node->handle->xc_handle, - XENVER_version,NULL ); - -if (vnum <0 ) +if (xc_version (node->handle->xc_handle, + XEN_VERSION_OP_version, &vnum,sizeof (vnum)) <0 )
Indentation.
tools/xenstat/libxenstat/src/xenstat.c unsigned long long xenstat_network_tdrop(xenstat_network * network) · line 635
Quoted 6 lines
tools/xenstat/libxenstat/src/xenstat.c +2
-2return 0 ; -if (xc_version (node->handle->xc_handle, XENVER_extraversion, - &version) <0 ) +if (xc_version (node->handle->xc_handle, XEN_VERSION_OP_extraversion, + &version,sizeof (version)) <0 )
Indentation.
Wei.
Quoted 20 lines
tools/xenstat/libxenstat/src/xenstat.c +0
-0return 0 ;/* Format the version information as a string and store it */ snprintf(node->handle->xen_version, VERSION_SIZE, "%ld.%ld%s",tools/xentrace/xenctx.c +2
-1@@ -1000,7 +1000,8 @@ static void dump_ctx(int vcpu) guest_word_size = (cpuctx.msr_efer &0x400 ) ?8 : guest_protected_mode ?4 :2 ;/* HVM guest context records are always host-sized */ -if (xc_version (xenctx.xc_handle, XENVER_capabilities, &xen_caps) !=0 ) { +if (xc_version (xenctx.xc_handle, XEN_VERSION_OP_capabilities, + &xen_caps,sizeof (xen_caps)) <0 ) {perror ("xc_version" );return ; }Signature · 1 line
2.5.0
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 05/34] libxc/libxl/python/xenstat: Use new XEN_VERSION_OP hypercall
Quoted 56 lines · Wei Liu
On Tue, Mar 15, 2016 at 01:56:27PM -0400, Konrad Rzeszutek Wilk wrote:
[...]Quoted 24 lines
tools/libxc/xg_save_restore.h +4
-2@@ -57,10 +57,12 @@ static inline int get_platform_info(xc_interface *xch, uint32_t dom,xen_capabilities_info_t xen_caps ="" ;xen_platform_parameters_t xen_params; -if (xc_version (xch, XENVER_platform_parameters, &xen_params) !=0 ) +if (xc_version (xch, XEN_VERSION_OP_platform_parameters, &xen_params, +sizeof (xen_params)) <0 )return 0 ; -if (xc_version (xch, XENVER_capabilities, &xen_caps) !=0 ) +if (xc_version (xch, XEN_VERSION_OP_capabilities, xen_caps, +sizeof (xen_caps)) <0 )return 0 ;if (xc_maximum_ram_page (xch, max_mfn))tools/libxl/libxl.c +0
-0tools/libxl/libxl.c libxl_numainfo *libxl_get_numainfo(libxl_ctx *ctx, int *nr) · line 5196
Quoted 6 lines
tools/libxl/libxl.c +3
-0@@ -5191,50 +5191,73 @@ libxl_numainfo *libxl_get_numainfo(libxl_ctx *ctx, int *nr)return ret; } + +static int xc_version_wrapper (libxl_ctx *ctx,unsigned int cmd,char *buf,ssize_t len,char **dst) +{This function should accept
libxl__gc*gc instead oflibxl_ctx.Preferably is should be renamed to
libxl__xc_version_wrappertools/libxl/libxl.c libxl_numainfo *libxl_get_numainfo(libxl_ctx *ctx, int *nr) · line 5200
Quoted 4 lines
tools/libxl/libxl.c +4
-0+GC_INIT (ctx); +int r; + + r =xc_version (ctx->xch, cmd, buf, len);Then here
CTX->xchtools/libxl/libxl.c libxl_numainfo *libxl_get_numainfo(libxl_ctx *ctx, int *nr) · line 5209
Quoted 9 lines
tools/libxl/libxl.c +9
-0+if ( r == -EPERM ) + buf[0 ] ='\0' ; +else if ( r <0 ) + { +GC_FREE ; +return r; + } + *dst =libxl__strdup (NOGC , buf); +GC_FREE ;
Quoted 7 lines
Then get rid of all GC_* macros.
Quoted 4 lines
tools/libxl/libxl.c +3
-0+return 0 ; +} +const libxl_version_info *libxl_get_version_info (libxl_ctx *ctx)[...]
Would this be to your liking?
Note that the Ocaml and xenstat are using real tabs instead of four spaces so they look odd.
From 36f39388c262123a0bdcddffdf565a032d7ca2cb Mon Sep 17 00:00:00 2001
From: Konrad Rzeszutek Wilk <[email protected]>
Date: Thu, 10 Mar 2016 16:11:59 -0500
Subject: [PATCH v4 06/35] libxc/libxl/python/xenstat/ocaml: Use new
XEN_VERSION_OP hypercall
We change the xen_version libxc code to use the new hypercall. Which of course means every user in the code base has to be changed over.
It is important to note that the xc_version_op has a different return semantic than the previous one. It returns negative values on error (like the old one), but it also returns an positive value on success (unlike the old one). The positive value is the number of bytes copied in.
Note that both Ocaml and xenstat use tabs instead of four spaces so they look quite odd.
---
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: David Scott <[email protected]>
Cc: George Dunlap <[email protected]>
v2: Use xc_version_op_val_t instead of uint32 or such
v3: Make sure to check ret < 0 instead of ret (as it returns the size) -
in Ocaml code. Found by Andrew.
v4: Update comment for xc_version to mention the return the size
v5: Wei's review
--- tools/libxc/include/xenctrl.h | 32 +++++++++++++- tools/libxc/xc_core.c | 35 +++++++-------- tools/libxc/xc_dom_boot.c | 12 +++++- tools/libxc/xc_domain.c | 3 +- tools/libxc/xc_private.c | 53 ++++------------------- tools/libxc/xc_private.h | 7 +-- tools/libxc/xc_resume.c | 3 +- tools/libxc/xc_sr_save.c | 9 ++-- tools/libxc/xg_save_restore.h | 6 ++- tools/libxl/libxl.c | 79 ++++++++++++++++++++++------------ tools/ocaml/libs/xc/xenctrl_stubs.c | 39 +++++++---------- tools/python/xen/lowlevel/xc/xc.c | 30 +++++++------ tools/xenstat/libxenstat/src/xenstat.c | 12 +++--- tools/xentrace/xenctx.c | 3 +- 14 files changed, 177 insertions(+), 146 deletions(-)
tools/libxc/include/xenctrl.h +31 -1
@@ -1477,7 +1477,37 @@ int xc_tbuf_set_evt_mask(xc_interface *xch, uint32_t mask);int xc_domctl (xc_interface *xch,struct xen_domctl *domctl);int xc_sysctl (xc_interface *xch,struct xen_sysctl *sysctl); -int xc_version (xc_interface *xch,int cmd,void *arg); +/** +* This function returns the size of buffer to be allocated for +* the cmd. The cmd are XEN_VERSION_OP_*. +*/ +ssize_t xc_version_len (xc_interface *xch,unsigned int cmd); + +/** +* This function retrieves the information from the version_op hypercall. +* The len is the size of the arg buffer. If arg is NULL, will not +* perform hypercall - instead will just return the size of arg +* buffer that is needed. +* +* Note that prior to Xen 4.7 this would return 0 for success and +* negative value (-1) for error (with the error in errno). In Xen 4.7 +* and later for success it will return an positive value which is the +* number of bytes copied in arg. +* +* It can also return -1 with various errno values: +* - EPERM - not permitted. +* - ENOBUFS - the len was to short, output in arg truncated. +* - ENOSYS - not implemented. +* +* @parm xch a handle to an open hypervisor interface +* @parm cmd XEN_VERSION_OP_* value +* @param arg Pointer to xen_version_op_buf_t or xen_version_op_val_t +* @param len Size of arg +* @return size of bytes copied in arg on success, -1 on failure (and +* errno will contain the error) +* +*/ +int xc_version (xc_interface *xch,unsigned int cmd,void *arg,size_t len);int xc_flask_op (xc_interface *xch,xen_flask_op_t *op);
tools/libxc/xc_core.c +18 -17
@@ -270,42 +270,43 @@ elfnote_fill_xen_version(xc_interface *xch, *xen_version) {int rc; +xen_version_op_val_t val =0 ;memset (xen_version,0 ,sizeof (*xen_version)); - rc =xc_version (xch, XENVER_version,NULL ); + rc =xc_version (xch, XEN_VERSION_OP_version, &val,sizeof (val));if ( rc <0 )return rc; - xen_version->major_version = rc >>16 ; - xen_version->minor_version = rc & ((1 <<16 ) -1 ); + xen_version->major_version = val >>16 ; + xen_version->minor_version = val & ((1 <<16 ) -1 ); - rc =xc_version (xch, XENVER_extraversion, - &xen_version->extra_version); + rc =xc_version (xch, XEN_VERSION_OP_extraversion, + xen_version->extra_version, +sizeof (xen_version->extra_version));if ( rc <0 )return rc; - rc =xc_version (xch, XENVER_compile_info, - &xen_version->compile_info); + rc =xc_version (xch, XEN_VERSION_OP_capabilities, + xen_version->capabilities, +sizeof (xen_version->capabilities));if ( rc <0 )return rc; - rc =xc_version (xch, - XENVER_capabilities, &xen_version->capabilities); + rc =xc_version (xch, XEN_VERSION_OP_changeset, xen_version->changeset, +sizeof (xen_version->changeset));if ( rc <0 )return rc; - rc =xc_version (xch, XENVER_changeset, &xen_version->changeset); + rc =xc_version (xch, XEN_VERSION_OP_platform_parameters, + &xen_version->platform_parameters, +sizeof (xen_version->platform_parameters));if ( rc <0 )return rc; - rc =xc_version (xch, XENVER_platform_parameters, - &xen_version->platform_parameters); + val =0 ; + rc =xc_version (xch, XEN_VERSION_OP_pagesize, &val,sizeof (val));if ( rc <0 )return rc; - - rc =xc_version (xch, XENVER_pagesize,NULL ); -if ( rc <0 ) -return rc; - xen_version->pagesize = rc; + xen_version->pagesize = val;return 0 ; }
tools/libxc/xc_dom_boot.c +10 -2
@@ -112,11 +112,19 @@ int xc_dom_compat_check(struct xc_dom_image *dom)int xc_dom_boot_xen_init (struct xc_dom_image *dom,xc_interface *xch,domid_t domid) { +xen_version_op_val_t val =0 ; + +if (xc_version (xch, XEN_VERSION_OP_version, &val,sizeof (val)) <0 ) + { +xc_dom_panic (xch,XC_INTERNAL_ERROR ,"can't get Xen version!" ); +return -1 ; + } + dom->xen_version = val; dom->xch = xch; dom->guest_domid = domid; - dom->xen_version =xc_version (xch, XENVER_version,NULL ); -if (xc_version (xch, XENVER_capabilities, &dom->xen_caps) <0 ) +if (xc_version (xch, XEN_VERSION_OP_capabilities, dom->xen_caps, +sizeof (dom->xen_caps)) <0 ) {xc_dom_panic (xch,XC_INTERNAL_ERROR ,"can't get xen capabilities" );return -1 ;
tools/libxc/xc_domain.c +2 -1
@@ -2084,7 +2084,8 @@ int xc_map_domain_meminfo(xc_interface *xch, int domid, _di.guest_width = minfo->guest_width;/* Get page table levels (see get_platform_info() in xg_save_restore.h */ -if (xc_version (xch, XENVER_capabilities, &xen_caps) ) +if (xc_version (xch, XEN_VERSION_OP_capabilities, xen_caps, +sizeof (xen_caps)) <0 ) {PERROR ("Could not get Xen capabilities (for page table levels)" );return -1 ;
tools/libxc/xc_private.c +9 -44
67 lines not on this page · raw message
tools/libxc/xc_private.h +4 -3
@@ -214,11 +214,12 @@ void xc__hypercall_buffer_cache_release(xc_interface *xch);* Hypercall interfaces. */ -static inline int do_xen_version (xc_interface *xch,int cmd,xc_hypercall_buffer_t *dest) +static inline long do_version_op (xc_interface *xch,int cmd, +xc_hypercall_buffer_t *dest,ssize_t len) {DECLARE_HYPERCALL_BUFFER_ARGUMENT (dest); -return xencall2 (xch->xcall, __HYPERVISOR_xen_version, - cmd,HYPERCALL_BUFFER_AS_ARG (dest)); +return xencall3 (xch->xcall, __HYPERVISOR_version_op, + cmd,HYPERCALL_BUFFER_AS_ARG (dest), len); }static inline int do_physdev_op (xc_interface *xch,int cmd,void *op,size_t len)
tools/libxc/xc_resume.c +2 -1
@@ -56,7 +56,8 @@ static int modify_returncode(xc_interface *xch, uint32_t domid)return 0 ;/* HVM guests have host address width. */ -if (xc_version (xch, XENVER_capabilities, &caps) !=0 ) +if (xc_version (xch, XEN_VERSION_OP_capabilities, caps, +sizeof (caps)) <0 ) {PERROR ("Could not get Xen capabilities" );return -1 ;
tools/libxc/xc_sr_save.c +5 -4
@@ -9,7 +9,7 @@static int write_headers (struct xc_sr_context *ctx,uint16_t guest_type) {xc_interface *xch = ctx->xch; -int32_t xen_version =xc_version (xch, XENVER_version,NULL ); +xen_version_op_val_t xen_version;struct xc_sr_ihdr ihdr = { .marker =IHDR_MARKER ,
@@ -21,15 +21,16 @@ static int write_headers(struct xc_sr_context *ctx, uint16_t guest_type) { .type = guest_type, .page_shift = XC_PAGE_SHIFT, - .xen_major = (xen_version >> 16) & 0xffff, - .xen_minor = (xen_version) & 0xffff, }; -if ( xen_version <0 ) +if (xc_version (xch, XEN_VERSION_OP_version, &xen_version, +sizeof (xen_version)) <0 ) {PERROR ("Unable to obtain Xen Version" );return -1 ; } + dhdr.xen_major = (xen_version >>16 ) &0xffff ; + dhdr.xen_minor = (xen_version) &0xffff ;if (write_exact (ctx->fd, &ihdr,sizeof (ihdr)) ) {
tools/libxc/xg_save_restore.h +4 -2
@@ -57,10 +57,12 @@ static inline int get_platform_info(xc_interface *xch, uint32_t dom,xen_capabilities_info_t xen_caps ="" ;xen_platform_parameters_t xen_params; -if (xc_version (xch, XENVER_platform_parameters, &xen_params) !=0 ) +if (xc_version (xch, XEN_VERSION_OP_platform_parameters, &xen_params, +sizeof (xen_params)) <0 )return 0 ; -if (xc_version (xch, XENVER_capabilities, &xen_caps) !=0 ) +if (xc_version (xch, XEN_VERSION_OP_capabilities, xen_caps, +sizeof (xen_caps)) <0 )return 0 ;if (xc_maximum_ram_page (xch, max_mfn))
tools/libxl/libxl.c +51 -28
101 lines not on this page · raw message
tools/ocaml/libs/xc/xenctrl_stubs.c +16 -23
@@ -853,21 +853,21 @@ CAMLprim value stub_xc_version_version(value xch)CAMLparam1 (xch);CAMLlocal1 (result);xen_extraversion_t extra; -long packed; +xen_version_op_val_t packed;int retval;caml_enter_blocking_section (); - packed =xc_version (_H (xch), XENVER_version,NULL ); + retval =xc_version (_H (xch), XEN_VERSION_OP_version, &packed,sizeof (packed));caml_leave_blocking_section (); -if (packed <0 ) +if (retval <0 )failwith_xc (_H (xch));caml_enter_blocking_section (); - retval =xc_version (_H (xch), XENVER_extraversion, &extra); + retval =xc_version (_H (xch), XEN_VERSION_OP_extraversion, &extra,sizeof (extra));caml_leave_blocking_section (); -if (retval) +if (retval <0 )failwith_xc (_H (xch)); result =caml_alloc_tuple (3 );
@@ -884,37 +884,28 @@ CAMLprim value stub_xc_version_compile_info(value xch) {CAMLparam1 (xch);CAMLlocal1 (result); -xen_compile_info_t ci; -int retval; - -caml_enter_blocking_section (); - retval =xc_version (_H (xch), XENVER_compile_info, &ci); -caml_leave_blocking_section (); - -if (retval) -failwith_xc (_H (xch)); result =caml_alloc_tuple (4 ); -Store_field (result,0 ,caml_copy_string (ci.compiler)); -Store_field (result,1 ,caml_copy_string (ci.compile_by)); -Store_field (result,2 ,caml_copy_string (ci.compile_domain)); -Store_field (result,3 ,caml_copy_string (ci.compile_date)); +Store_field (result,0 ,caml_copy_string ("" )); +Store_field (result,1 ,caml_copy_string ("" )); +Store_field (result,2 ,caml_copy_string ("" )); +Store_field (result,3 ,caml_copy_string ("" ));CAMLreturn (result); } -static value xc_version_single_string (value xch,int code,void *info) +static value xc_version_single_string (value xch,int code,void *info,ssize_t len) {CAMLparam1 (xch);int retval;caml_enter_blocking_section (); - retval =xc_version (_H (xch), code, info); + retval =xc_version (_H (xch), code, info, len);caml_leave_blocking_section (); -if (retval) +if (retval <0 )failwith_xc (_H (xch));CAMLreturn (caml_copy_string ((char *)info));
@@ -925,7 +916,8 @@ CAMLprim value stub_xc_version_changeset(value xch) {xen_changeset_info_t ci; -return xc_version_single_string (xch, XENVER_changeset, &ci); +return xc_version_single_string (xch, XEN_VERSION_OP_changeset, + &ci,sizeof (ci)); }
@@ -933,7 +925,8 @@ CAMLprim value stub_xc_version_capabilities(value xch) {xen_capabilities_info_t ci; -return xc_version_single_string (xch, XENVER_capabilities, &ci); +return xc_version_single_string (xch, XEN_VERSION_OP_capabilities, + &ci,sizeof (ci)); }
tools/python/xen/lowlevel/xc/xc.c +18 -12
@@ -1204,34 +1204,40 @@ static PyObject *pyxc_xeninfo(XcObject *self)xen_capabilities_info_t xen_caps;xen_platform_parameters_t p_parms;xen_commandline_t xen_commandline; -long xen_version; -long xen_pagesize; +xen_version_op_val_t xen_version; +xen_version_op_val_t xen_pagesize;char str[128 ]; - xen_version =xc_version (self->xc_handle, XENVER_version,NULL ); - -if (xc_version (self->xc_handle, XENVER_extraversion, &xen_extra) !=0 ) +if (xc_version (self->xc_handle, XEN_VERSION_OP_version, &xen_version, +sizeof (xen_version)) <0 )return pyxc_error_to_exception (self->xc_handle); -if (xc_version (self->xc_handle, XENVER_compile_info, &xen_cc) !=0 ) +if (xc_version (self->xc_handle, XEN_VERSION_OP_extraversion, &xen_extra, +sizeof (xen_extra)) <0 )return pyxc_error_to_exception (self->xc_handle); -if (xc_version (self->xc_handle, XENVER_changeset, &xen_chgset) !=0 ) +memset (&xen_cc,0 ,sizeof (xen_cc)); + +if (xc_version (self->xc_handle, XEN_VERSION_OP_changeset, &xen_chgset, +sizeof (xen_chgset)) <0 )return pyxc_error_to_exception (self->xc_handle); -if (xc_version (self->xc_handle, XENVER_capabilities, &xen_caps) !=0 ) +if (xc_version (self->xc_handle, XEN_VERSION_OP_capabilities, &xen_caps, +sizeof (xen_caps)) <0 )return pyxc_error_to_exception (self->xc_handle); -if (xc_version (self->xc_handle, XENVER_platform_parameters, &p_parms) !=0 ) +if (xc_version (self->xc_handle, XEN_VERSION_OP_platform_parameters, + &p_parms,sizeof (p_parms)) <0 )return pyxc_error_to_exception (self->xc_handle); -if (xc_version (self->xc_handle, XENVER_commandline, &xen_commandline) !=0 ) +if (xc_version (self->xc_handle, XEN_VERSION_OP_commandline, + &xen_commandline,sizeof (xen_commandline)) <0 )return pyxc_error_to_exception (self->xc_handle);snprintf (str,sizeof (str),"virt_start=0x%" PRI_xen_ulong, p_parms.virt_start); - xen_pagesize =xc_version (self->xc_handle, XENVER_pagesize,NULL ); -if (xen_pagesize <0 ) +if (xc_version (self->xc_handle, XEN_VERSION_OP_pagesize, &xen_pagesize, +sizeof (xen_pagesize)) <0 )return pyxc_error_to_exception (self->xc_handle); return Py_BuildValue("{s:i,s:i,s:s,s:s,s:i,s:s,s:s,s:s,s:s,s:s,s:s,s:s}",
tools/xenstat/libxenstat/src/xenstat.c +5 -7
@@ -621,20 +621,18 @@ unsigned long long xenstat_network_tdrop(xenstat_network * network)/* Collect Xen version information */ static int xenstat_collect_xen_version (xenstat_node * node) { -long vnum =0 ; +xen_version_op_val_t vnum =0 ;xen_extraversion_t version;/* Collect Xen version information if not already collected */ if (node->handle->xen_version[0 ] =='\0' ) {/* Get the Xen version number and extraversion string */ - vnum =xc_version (node->handle->xc_handle, - XENVER_version,NULL ); - -if (vnum <0 ) +if (xc_version (node->handle->xc_handle, + XEN_VERSION_OP_version, &vnum,sizeof (vnum)) <0 )return 0 ; -if (xc_version (node->handle->xc_handle, XENVER_extraversion, - &version) <0 ) +if (xc_version (node->handle->xc_handle, XEN_VERSION_OP_extraversion, + &version,sizeof (version)) <0 )return 0 ;/* Format the version information as a string and store it */ snprintf(node->handle->xen_version, VERSION_SIZE, "%ld.%ld%s",
tools/xentrace/xenctx.c +2 -1
@@ -1000,7 +1000,8 @@ static void dump_ctx(int vcpu) guest_word_size = (cpuctx.msr_efer &0x400 ) ?8 : guest_protected_mode ?4 :2 ;/* HVM guest context records are always host-sized */ -if (xc_version (xenctx.xc_handle, XENVER_capabilities, &xen_caps) !=0 ) { +if (xc_version (xenctx.xc_handle, XEN_VERSION_OP_capabilities, + &xen_caps,sizeof (xen_caps)) <0 ) {perror ("xc_version" );return ; }
Signature · 8 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH v4 6/34 x86/arm: Add BUGFRAME_NR define and BUILD checks.
In reply to Konrad Rzeszutek WilkSo that we have a nice mechansim to figure out the upper bounds of bug.frames and also catch compiler errors in case one tries to use a higher frame number.
---
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/include/asm-arm/bug.h | 2 ++ xen/include/asm-x86/bug.h | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-)
xen/include/asm-arm/bug.h +2 -0
@@ -31,6 +31,7 @@ struct bug_frame {#define BUGFRAME_warn 0#define BUGFRAME_bug 1#define BUGFRAME_assert 2 +#define BUGFRAME_NR 3/* Many versions of GCC doesn't support the asm %c parameter which would * be preferable to this unpleasantness. We use mergeable string
@@ -39,6 +40,7 @@ struct bug_frame {*/ #define BUG_FRAME (type, line, file, has_msg, msg) do { \ BUILD_BUG_ON((line) >> 16); \ + BUILD_BUG_ON(type >= BUGFRAME_NR); \ asm ("1:"BUG_INSTR"\n" \ ".pushsection .rodata.str, \"aMS\", %progbits, 1\n" \ "2:\t.asciz " __stringify(file) "\n" \
xen/include/asm-x86/bug.h +2 -1
@@ -9,7 +9,7 @@#define BUGFRAME_warn 1#define BUGFRAME_bug 2#define BUGFRAME_assert 3 - +#define BUGFRAME_NR 4#ifndef __ASSEMBLY__ struct bug_frame {
@@ -51,6 +51,7 @@ struct bug_frame {#define BUG_FRAME (type, line, ptr, second_frame, msg) do { \ BUILD_BUG_ON((line) >> (BUG_LINE_LO_WIDTH + BUG_LINE_HI_WIDTH)); \ + BUILD_BUG_ON((type) >= (BUGFRAME_NR)); \ asm volatile ( _ASM_BUGFRAME_TEXT(second_frame) \ :: _ASM_BUGFRAME_INFO(type, line, ptr, msg) ); \ } while (0)
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v4 06/34] x86/arm: Add BUGFRAME_NR define and BUILD checks.
Quoted 52 lines · Konrad Rzeszutek Wilk
So that we have a nice mechansim to figure out the upper bounds of bug.frames and also catch compiler errors in case one tries to use a higher frame number.
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/include/asm-arm/bug.h | 2 ++ xen/include/asm-x86/bug.h | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-)xen/include/asm-arm/bug.h +2
-0@@ -31,6 +31,7 @@ struct bug_frame {#define BUGFRAME_warn 0#define BUGFRAME_bug 1#define BUGFRAME_assert 2 +#define BUGFRAME_NR 3/* Many versions of GCC doesn't support the asm %c parameter which would * be preferable to this unpleasantness. We use mergeable string @@ -39,6 +40,7 @@ struct bug_frame {*/ #define BUG_FRAME (type, line, file, has_msg, msg) do { \ BUILD_BUG_ON((line) >> 16); \ + BUILD_BUG_ON(type >= BUGFRAME_NR); \ asm ("1:"BUG_INSTR"\n" \ ".pushsection .rodata.str, \"aMS\", %progbits, 1\n" \ "2:\t.asciz " __stringify(file) "\n" \xen/include/asm-x86/bug.h +1
-1@@ -9,7 +9,7 @@#define BUGFRAME_warn 1#define BUGFRAME_bug 2#define BUGFRAME_assert 3 - +#define BUGFRAME_NR 4#ifndef __ASSEMBLY__ struct bug_frame {
xen/include/asm-x86/bug.h struct bug_frame { · line 57
Quoted 7 lines
xen/include/asm-x86/bug.h +1
-0@@ -51,6 +51,7 @@ struct bug_frame {#define BUG_FRAME (type, line, ptr, second_frame, msg) do { \ BUILD_BUG_ON((line) >> (BUG_LINE_LO_WIDTH + BUG_LINE_HI_WIDTH)); \ + BUILD_BUG_ON((type) >= (BUGFRAME_NR)); \ asm volatile ( _ASM_BUGFRAME_TEXT(second_frame) \ :: _ASM_BUGFRAME_INFO(type, line, ptr, msg) ); \ } while (0)
Please fold this hunk in as well,
xen/include/asm-x86/bug.h +5 -0
@@ -83,6 +83,11 @@ extern const struct bug_frame __start_bug_frames[],* in .rodata */ .macro BUG_FRAME type, line, file_str, second_frame, msg + + .if \type >= BUGFRAME_NR + .error "Invalid BUGFRAME index" + .endif + .L\@ud: ud2a .pushsection .rodata.str1, "aMS", @progbits, 1
Which is an equivalent check for ASM bugframes.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 06/34] x86/arm: Add BUGFRAME_NR define and BUILD checks.
In reply to Konrad Rzeszutek WilkHi Konrad,
Quoted 5 lines · Konrad Rzeszutek Wilk
So that we have a nice mechansim to figure out the upper bounds of bug.frames and also catch compiler errors in case one tries to use a higher frame number.
Signed-off-by Konrad Rzeszutek Wilk <[email protected]>
For the ARM part:
Regards,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v4 06/34] x86/arm: Add BUGFRAME_NR define and BUILD checks.
In reply to Konrad Rzeszutek WilkQuoted 12 lines
Quoted 1 line
Quoted 1 line · On 15.03.16 at 18:56, <[email protected]> wrote:
xen/include/asm-arm/bug.h +1
-0@@ -31,6 +31,7 @@ struct bug_frame {#define BUGFRAME_warn 0#define BUGFRAME_bug 1#define BUGFRAME_assert 2 +#define BUGFRAME_NR 3/* Many versions of GCC doesn't support the asm %c parameter which would * be preferable to this unpleasantness. We use mergeable string
xen/include/asm-arm/bug.h struct bug_frame { · line 43
Quoted 4 lines
xen/include/asm-arm/bug.h +1
-0@@ -39,6 +40,7 @@ struct bug_frame {*/ #define BUG_FRAME (type, line, file, has_msg, msg) do { \ BUILD_BUG_ON((line) >> 16); \ + BUILD_BUG_ON(type >= BUGFRAME_NR); \
The x86 variant has type properly parenthesized - why not here?
xen/include/asm-x86/bug.h line 13
Quoted 9 lines
xen/include/asm-x86/bug.h +1
-1@@ -9,7 +9,7 @@#define BUGFRAME_warn 1#define BUGFRAME_bug 2#define BUGFRAME_assert 3 - +#define BUGFRAME_NR 4#ifndef __ASSEMBLY__
Please retain the blank line.
xen/include/asm-x86/bug.h struct bug_frame { · line 54
Quoted 5 lines
xen/include/asm-x86/bug.h +1
-0@@ -51,6 +51,7 @@ struct bug_frame {#define BUG_FRAME (type, line, ptr, second_frame, msg) do { \ BUILD_BUG_ON((line) >> (BUG_LINE_LO_WIDTH + BUG_LINE_HI_WIDTH)); \ + BUILD_BUG_ON((type) >= (BUGFRAME_NR)); \
The ARM variant has BUGFRAME_NR properly un-parenthesized - why here?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 06/34] x86/arm: Add BUGFRAME_NR define and BUILD checks.
Quoted 31 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 15.03.16 at 18:56, <[email protected]> wrote:
xen/include/asm-arm/bug.h +1
-0@@ -31,6 +31,7 @@ struct bug_frame {#define BUGFRAME_warn 0#define BUGFRAME_bug 1#define BUGFRAME_assert 2 +#define BUGFRAME_NR 3/* Many versions of GCC doesn't support the asm %c parameter which would * be preferable to this unpleasantness. We use mergeable string xen/include/asm-arm/bug.h struct bug_frame { · line 43
Quoted 4 lines
xen/include/asm-arm/bug.h +1
-0@@ -39,6 +40,7 @@ struct bug_frame {*/ #define BUG_FRAME (type, line, file, has_msg, msg) do { \ BUILD_BUG_ON((line) >> 16); \ + BUILD_BUG_ON(type >= BUGFRAME_NR); \The x86 variant has type properly parenthesized - why not here?
xen/include/asm-x86/bug.h line 13
Quoted 9 lines
xen/include/asm-x86/bug.h +1
-1@@ -9,7 +9,7 @@#define BUGFRAME_warn 1#define BUGFRAME_bug 2#define BUGFRAME_assert 3 - +#define BUGFRAME_NR 4#ifndef __ASSEMBLY__Please retain the blank line.
Quoted 8 lines
xen/include/asm-x86/bug.h struct bug_frame { · line 54
Quoted 5 lines
xen/include/asm-x86/bug.h +1
-0@@ -51,6 +51,7 @@ struct bug_frame {#define BUG_FRAME (type, line, ptr, second_frame, msg) do { \ BUILD_BUG_ON((line) >> (BUG_LINE_LO_WIDTH + BUG_LINE_HI_WIDTH)); \ + BUILD_BUG_ON((type) >= (BUGFRAME_NR)); \The ARM variant has
BUGFRAME_NRproperly un-parenthesized - why here?
I know I copied and pasted it and I must have done something uncanny.
Anyhow this is what the change looks like now (I've retained the Reviewed and Ack as I think this change is mostly cosmetical in nature?)
From 123ad665b283f8c59688bd86be0bbe79ce5723bb Mon Sep 17 00:00:00 2001
From: Konrad Rzeszutek Wilk <[email protected]>
Date: Thu, 10 Mar 2016 16:45:31 -0500
Subject: [PATCH] x86/arm: Add BUGFRAME_NR define and BUILD checks.
So that we have a nice mechansim to figure out the upper bounds of bug.frames and also catch compiler errors in case one tries to use a higher frame number.
---
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]>
v3: First time included.
v4: Add BUG_FRAME check also in the assembler version of the macro.
v5: Add Acks, make BUILD_BUG_ON checks look correct. Position the
BUGFRAME_NR properly.
---
--- xen/include/asm-arm/bug.h | 3 +++ xen/include/asm-x86/bug.h | 7 +++++++ 2 files changed, 10 insertions(+)
xen/include/asm-arm/bug.h +3 -0
@@ -32,6 +32,8 @@ struct bug_frame {#define BUGFRAME_bug 1#define BUGFRAME_assert 2 +#define BUGFRAME_NR 3 +/* Many versions of GCC doesn't support the asm %c parameter which would * be preferable to this unpleasantness. We use mergeable string * sections to avoid multiple copies of the string appearing in the
@@ -39,6 +41,7 @@ struct bug_frame {*/ #define BUG_FRAME (type, line, file, has_msg, msg) do { \ BUILD_BUG_ON((line) >> 16); \ + BUILD_BUG_ON((type) >= BUGFRAME_NR); \ asm ("1:"BUG_INSTR"\n" \ ".pushsection .rodata.str, \"aMS\", %progbits, 1\n" \ "2:\t.asciz " __stringify(file) "\n" \
xen/include/asm-x86/bug.h +7 -0
@@ -10,6 +10,7 @@#define BUGFRAME_bug 2#define BUGFRAME_assert 3 +#define BUGFRAME_NR 4#ifndef __ASSEMBLY__ struct bug_frame {
@@ -51,6 +52,7 @@ struct bug_frame {#define BUG_FRAME (type, line, ptr, second_frame, msg) do { \ BUILD_BUG_ON((line) >> (BUG_LINE_LO_WIDTH + BUG_LINE_HI_WIDTH)); \ + BUILD_BUG_ON((type) >= BUGFRAME_NR); \ asm volatile ( _ASM_BUGFRAME_TEXT(second_frame) \ :: _ASM_BUGFRAME_INFO(type, line, ptr, msg) ); \ } while (0)
@@ -83,6 +85,11 @@ extern const struct bug_frame __start_bug_frames[],* in .rodata */ .macro BUG_FRAME type, line, file_str, second_frame, msg + + .if \type >= BUGFRAME_NR + .error "Invalid BUGFRAME index" + .endif + .L\@ud: ud2a .pushsection .rodata.str1, "aMS", @progbits, 1
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v4 06/34] x86/arm: Add BUGFRAME_NR define and BUILD checks.
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 18.03.16 at 20:59, <[email protected]> wrote:
I know I copied and pasted it and I must have done something uncanny.
Anyhow this is what the change looks like now (I've retained the Reviewed and Ack as I think this change is mostly cosmetical in nature?)
I think that's okay.
Quoted 2 lines
v5: Add Acks, make
BUILD_BUG_ONchecks look correct. Position the
BUGFRAME_NRproperly.
Almost, that is.
xen/include/asm-x86/bug.h line 14
Quoted 8 lines
xen/include/asm-x86/bug.h +1
-0@@ -10,6 +10,7 @@#define BUGFRAME_bug 2#define BUGFRAME_assert 3 +#define BUGFRAME_NR 4#ifndef __ASSEMBLY__
The insertion wants to go _before_ the blank line. (And in the ARM case you then may consider removing the preceding blank line too; in any event the ARM and x86 ones should look similar in the end.)
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 06/34] x86/arm: Add BUGFRAME_NR define and BUILD checks.
Quoted 19 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 18.03.16 at 20:59, <[email protected]> wrote:
I know I copied and pasted it and I must have done something uncanny.
Anyhow this is what the change looks like now (I've retained the Reviewed and Ack as I think this change is mostly cosmetical in nature?)
I think that's okay.
Quoted 2 lines
v5: Add Acks, make
BUILD_BUG_ONchecks look correct. Position the
BUGFRAME_NRproperly.Almost, that is.
Quoted 6 lines
xen/include/asm-x86/bug.h +0
-0@@ -10,6 +10,7 @@#define BUGFRAME_bug 2#define BUGFRAME_assert 3
Quoted 8 lines
xen/include/asm-x86/bug.h line 14
Quoted 2 lines
xen/include/asm-x86/bug.h +1
-0+#define BUGFRAME_NR 4#ifndef __ASSEMBLY__The insertion wants to go _before_ the blank line. (And in the ARM case you then may consider removing the preceding blank line too; in any event the ARM and x86 ones should look similar in the end.)
Here it is. Last call :-)
From f97548200461b9eb4d8187eb9e1f021c74160759 Mon Sep 17 00:00:00 2001
From: Konrad Rzeszutek Wilk <[email protected]>
Date: Thu, 10 Mar 2016 16:45:31 -0500
Subject: [PATCH] x86/arm: Add BUGFRAME_NR define and BUILD checks.
So that we have a nice mechansim to figure out the upper bounds of bug.frames and also catch compiler errors in case one tries to use a higher frame number.
---
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]>
v3: First time included.
v4: Add BUG_FRAME check also in the assembler version of the macro.
v5: Add Acks, make BUILD_BUG_ON checks look correct. Position the
BUGFRAME_NR properly. Reposition the BUGFRAME_NR again.
---
--- xen/include/asm-arm/bug.h | 3 +++ xen/include/asm-x86/bug.h | 8 ++++++++ 2 files changed, 11 insertions(+)
xen/include/asm-arm/bug.h +3 -0
@@ -32,6 +32,8 @@ struct bug_frame {#define BUGFRAME_bug 1#define BUGFRAME_assert 2 +#define BUGFRAME_NR 3 +/* Many versions of GCC doesn't support the asm %c parameter which would * be preferable to this unpleasantness. We use mergeable string * sections to avoid multiple copies of the string appearing in the
@@ -39,6 +41,7 @@ struct bug_frame {*/ #define BUG_FRAME (type, line, file, has_msg, msg) do { \ BUILD_BUG_ON((line) >> 16); \ + BUILD_BUG_ON((type) >= BUGFRAME_NR); \ asm ("1:"BUG_INSTR"\n" \ ".pushsection .rodata.str, \"aMS\", %progbits, 1\n" \ "2:\t.asciz " __stringify(file) "\n" \
xen/include/asm-x86/bug.h +8 -0
@@ -10,6 +10,8 @@#define BUGFRAME_bug 2#define BUGFRAME_assert 3 +#define BUGFRAME_NR 4 +#ifndef __ASSEMBLY__ struct bug_frame {
@@ -51,6 +53,7 @@ struct bug_frame {#define BUG_FRAME (type, line, ptr, second_frame, msg) do { \ BUILD_BUG_ON((line) >> (BUG_LINE_LO_WIDTH + BUG_LINE_HI_WIDTH)); \ + BUILD_BUG_ON((type) >= BUGFRAME_NR); \ asm volatile ( _ASM_BUGFRAME_TEXT(second_frame) \ :: _ASM_BUGFRAME_INFO(type, line, ptr, msg) ); \ } while (0)
@@ -83,6 +86,11 @@ extern const struct bug_frame __start_bug_frames[],* in .rodata */ .macro BUG_FRAME type, line, file_str, second_frame, msg + + .if \type >= BUGFRAME_NR + .error "Invalid BUGFRAME index" + .endif + .L\@ud: ud2a .pushsection .rodata.str1, "aMS", @progbits, 1
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v4 06/34] x86/arm: Add BUGFRAME_NR define and BUILD checks.
Quoted 30 lines
Quoted 1 line
Quoted 1 line · On 22.03.16 at 16:39, <[email protected]> wrote:
Quoted 19 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 18.03.16 at 20:59, <[email protected]> wrote:
I know I copied and pasted it and I must have done something uncanny.
Anyhow this is what the change looks like now (I've retained the Reviewed and Ack as I think this change is mostly cosmetical in nature?)
I think that's okay.
Quoted 2 lines
v5: Add Acks, make
BUILD_BUG_ONchecks look correct. Position the
BUGFRAME_NRproperly.Almost, that is.
Quoted 6 lines
xen/include/asm-x86/bug.h +0
-0@@ -10,6 +10,7 @@#define BUGFRAME_bug 2#define BUGFRAME_assert 3Quoted 8 lines
xen/include/asm-x86/bug.h line 15
Quoted 2 lines
xen/include/asm-x86/bug.h +1
-0+#define BUGFRAME_NR 4#ifndef __ASSEMBLY__The insertion wants to go _before_ the blank line. (And in the ARM case you then may consider removing the preceding blank line too; in any event the ARM and x86 ones should look similar in the end.)
Quoted 1 line
Here it is. Last call :-)
Thanks, looks fine now.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v4 7/34 arm/x86: Use struct virtual_region to do bug, symbol, and (x86) exception tables
In reply to Konrad Rzeszutek Wilklookup.
During execution of the hypervisor we have two regions of executable code - stext -> _etext, and _sinittext -> _einitext.
The later is not needed after bootup.
We also have various built-in macros and functions to search in between those two swaths depending on the state of the system.
That is either for bug_frames, exceptions (x86) or symbol names for the instruction.
With xSplice in the picture - we need a mechansim for new payloads to searched as well for all of this.
Originally we had extra 'if (xsplice)...' but that gets a bit tiring and does not hook up nicely.
This 'struct virtual_region' and virtual_region_list provide a mechanism to search for the bug_frames,exception table, and symbol names entries without having various calls in other sub-components in the system.
Code which wishes to participate in bug_frames and exception table entries search has to only use two public APIs:
- register_virtual_region
- unregister_virtual_region
to let the core code know. Furthermore there are also overrides via the .skip function. There are three possible flags that can be passed in - depending on what kind of search is being done. A return of 1 means skip this region. If the .skip is NULL the region will be considered.
The ->lookup_symbol will only be used if ->skip returns 1 for CHECKING_SYMBOLS (and of course if it points to a function). Otherwise 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]>
---
--- xen/arch/arm/traps.c | 45 ++++++++++----- xen/arch/x86/extable.c | 16 +++++- xen/arch/x86/setup.c | 3 +- xen/arch/x86/traps.c | 46 +++++++++------ xen/common/Makefile | 1 + xen/common/bug_ex_symbols.c | 119 +++++++++++++++++++++++++++++++++++++++ xen/common/symbols.c | 29 +++++++++- xen/include/xen/bug_ex_symbols.h | 74 ++++++++++++++++++++++++ xen/include/xen/kernel.h | 2 + xen/include/xen/symbols.h | 9 +++ 10 files changed, 307 insertions(+), 37 deletions(-) create mode 100644 xen/common/bug_ex_symbols.c create mode 100644 xen/include/xen/bug_ex_symbols.h
xen/arch/arm/traps.c +30 -15
@@ -16,6 +16,7 @@* GNU General Public License for more details. */ +#include <xen/bug_ex_symbols.h> #include <xen/config.h> #include <xen/stdbool.h> #include <xen/init.h>
@@ -101,6 +102,8 @@ integer_param("debug_stack_lines", debug_stack_lines);void init_traps (void ) { +setup_virtual_regions (); +/* Setup Hyp vector base */ WRITE_SYSREG ((vaddr_t )hyp_traps_vector,VBAR_EL2 );
@@ -1077,27 +1080,39 @@ void do_unexpected_trap(const char *msg, struct cpu_user_regs *regs)int do_bug_frame (struct cpu_user_regs *regs,vaddr_t pc) { -const struct bug_frame *bug; +const struct bug_frame *bug =NULL ;const char *prefix ="" , *filename, *predicate;unsigned long fixup; -int id, lineno; -static const struct bug_frame *const stop_frames[] = { - __stop_bug_frames_0, - __stop_bug_frames_1, - __stop_bug_frames_2, -NULL - }; +int id =-1 , lineno; +struct virtual_region *region; -for ( bug = __start_bug_frames, id =0 ; stop_frames[id]; ++bug ) +list_for_each_entry ( region, &virtual_region_list, list ) { -while (unlikely (bug == stop_frames[id]) ) - ++id; +unsigned int i; -if ( ((vaddr_t )bug_loc (bug)) == pc ) -break ; - } +if ( region->skip && region->skip (CHECKING_BUG_FRAME , region->priv) ) +continue ; + +if ( pc < region->start || pc > region->end ) +continue ; -if ( !stop_frames[id] ) +for ( id =0 ; id <BUGFRAME_NR ; id++ ) + { +const struct bug_frame *b =NULL ; + +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; + } + } + } + } + found: +if ( !bug )return -ENOENT ;/* WARN, BUG or ASSERT: decode the filename pointer and line number. */
xen/arch/x86/extable.c +14 -2
@@ -1,6 +1,8 @@ +#include <xen/bug_ex_symbols.h> #include <xen/config.h> #include <xen/init.h> +#include <xen/list.h> #include <xen/perfc.h> #include <xen/sort.h> #include <xen/spinlock.h>
@@ -80,8 +82,18 @@ search_one_table(const struct exception_table_entry *first,unsigned long search_exception_table (unsigned long addr) { -return search_one_table ( - __start___ex_table, __stop___ex_table-1 , addr); +struct virtual_region *region; + +list_for_each_entry ( region, &virtual_region_list, list ) + { +if ( region->skip && region->skip (CHECKING_EXCEPTION , region->priv) ) +continue ; + +if ( (addr >= region->start) && (addr < region->end) ) +return search_one_table (region->ex, region->ex_end-1 , addr); + } + +return 0 ; }unsigned long
xen/arch/x86/setup.c +2 -1
@@ -1,3 +1,4 @@ +#include <xen/bug_ex_symbols.h> #include <xen/config.h> #include <xen/init.h> #include <xen/lib.h>
@@ -614,8 +615,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)load_system_tables ();smp_prepare_boot_cpu (); -sort_exception_tables (); +setup_virtual_regions ();/* Full exception support from here on in. */ loader = (mbi->flags &MBI_LOADERNAME )
xen/arch/x86/traps.c +30 -16
70 lines not on this page · raw message
xen/common/Makefile +1 -0
@@ -1,4 +1,5 @@ obj-y += bitmap.o +obj-y += bug_ex_symbols.o obj-$(CONFIG_CORE_PARKING) += core_parking.o obj-y += cpu.o obj-y += cpupool.o
xen/common/bug_ex_symbols.c new file +119 -0
119 lines not on this page · raw message
xen/common/symbols.c +26 -3
@@ -10,6 +10,7 @@* compression (see tools/symbols.c for a more complete description) */ +#include <xen/bug_ex_symbols.h> #include <xen/config.h> #include <xen/symbols.h> #include <xen/kernel.h>
@@ -95,10 +96,28 @@ static unsigned int get_symbol_offset(unsigned long pos)return name - symbols_names; } +bool_t __is_active_kernel_text (unsigned long addr,symbols_lookup_t *cb) +{ +struct virtual_region *region; + +list_for_each_entry ( region, &virtual_region_list, list ) + { +if ( region->skip && region->skip (CHECKING_SYMBOL , region->priv) ) +continue ; + +if ( addr >= region->start && addr < region->end ) + { +if ( cb && region->symbols_lookup ) + *cb = region->symbols_lookup; +return 1 ; + } + } +return 0 ; +} +bool_t is_active_kernel_text (unsigned long addr) { -return (is_kernel_text (addr) || - (system_state < SYS_STATE_active &&is_kernel_inittext (addr))); +return __is_active_kernel_text (addr,NULL ); } const char *symbols_lookup(unsigned long addr,
@@ -108,13 +127,17 @@ const char *symbols_lookup(unsigned long addr, {unsigned long i, low, high, mid;unsigned long symbol_end =0 ; +symbols_lookup_t symbol_lookup =NULL ; namebuf[KSYM_NAME_LEN ] =0 ; namebuf[0 ] =0 ; -if (!is_active_kernel_text (addr)) +if (!__is_active_kernel_text (addr, &symbol_lookup))return NULL ; +if (symbol_lookup) +return (symbol_lookup)(addr, symbolsize, offset, namebuf); +/* do a binary search on the sorted symbols_addresses array */ low =0 ; high = symbols_num_syms;
xen/include/xen/bug_ex_symbols.h new file +74 -0
74 lines not on this page · raw message
xen/include/xen/kernel.h +2 -0
@@ -65,12 +65,14 @@1 ; \ }) +extern char _start[], _end[], start[];#define is_kernel (p) ({ \ char *__p = (char *)(unsigned long)(p); \ (__p >= _start) && (__p < _end); \ }) +/* For symbols_lookup usage. */ extern char _stext[], _etext[];#define is_kernel_text (p) ({ \ char *__p = (char *)(unsigned long)(p); \
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,
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v4 07/34] arm/x86: Use struct virtual_region to do bug, symbol, and (x86) exception tables
xen/arch/arm/traps.c line 19
Quoted 9 lines · Konrad Rzeszutek Wilk
xen/arch/arm/traps.c +1
-0@@ -16,6 +16,7 @@* GNU General Public License for more details. */ +#include <xen/bug_ex_symbols.h>
how about just <xen/virtual_region.h> ? It contains more than just bugframes.
Quoted 8 lines
xen/common/bug_ex_symbols.c new file +2
-0@@ -0,0 +1,119 @@ +/* +* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
xen/common/bug_ex_symbols.c line 12
Quoted 10 lines
xen/common/bug_ex_symbols.c new file +10
-0+* +*/ + +#include <xen/bug_ex_symbols.h> +#include <xen/config.h> +#include <xen/kernel.h> +#include <xen/init.h> +#include <xen/spinlock.h> + +extern char __stext[];
There is no such symbol. _stext comes in via kernel.h
xen/common/bug_ex_symbols.c line 14
Quoted 2 lines
xen/common/bug_ex_symbols.c new file +2
-0+ +struct virtual_region kernel_text = {
How about just "compiled" ? This is more than just .text.
Quoted 22 lines
xen/common/bug_ex_symbols.c new file +22
-0+ .list = LIST_HEAD_INIT(kernel_text.list), + .start = (unsigned long)_stext, + .end = (unsigned long )_etext, +#ifdef CONFIG_X86 + .ex = (struct exception_table_entry *)__start___ex_table, + .ex_end = (struct exception_table_entry *)__stop___ex_table, +#endif +}; + +/* +* The kernel_inittext should only be used when system_state +* is booting. Otherwise all accesses should be ignored. +*/ +static bool_t ignore_if_active (unsigned int flag,unsigned long priv) +{ +return (system_state >= SYS_STATE_active); +} + +/* +* Becomes irrelevant when __init sections are cleared. +*/ +struct virtual_region kernel_inittext = {
xen/common/bug_ex_symbols.c line 46
Quoted 10 lines
xen/common/bug_ex_symbols.c new file +10
-0+ .list = LIST_HEAD_INIT(kernel_inittext.list), + .skip = ignore_if_active, + .start = (unsigned long)_sinittext, + .end = (unsigned long )_einittext, +#ifdef CONFIG_X86 +/* Even if they are __init their exception entry still gets stuck here. */ + .ex = (struct exception_table_entry *)__start___ex_table, + .ex_end = (struct exception_table_entry *)__stop___ex_table, +#endif +};
This can live in .init.data and be taken off the linked list in init_done(), which performs other bits of cleanup relating to .init
xen/common/bug_ex_symbols.c line 53
Quoted 7 lines
xen/common/bug_ex_symbols.c new file +7
-0+ +/* +* No locking. Additions are done either at startup (when there is only +* one CPU) or when all CPUs are running without IRQs. +* +* Deletions are big tricky. We MUST make sure all but one CPU +* are running cpu_relax().
It should still be possible to lock this properly. We expect no contention, at which point acquiring and releasing the locks will always hit fastpaths, but it will avoid accidental corruption if something goes wrong.
In each of register or deregister, take the lock, then confirm whether the current region is in a list or not, by looking at r->list. With the single virtual_region_lock held, that can safely avoid repeatedly adding the region to the region list.
Quoted 27 lines
xen/common/bug_ex_symbols.c new file +27
-0+* +*/ +LIST_HEAD (virtual_region_list); + +int register_virtual_region (struct virtual_region *r) +{ +ASSERT (!local_irq_is_enabled ()); + +list_add_tail (&r->list, &virtual_region_list); +return 0 ; +} + +void unregister_virtual_region (struct virtual_region *r) +{ +ASSERT (!local_irq_is_enabled ()); + +list_del_init (&r->list); +} + +void __init setup_virtual_regions (void ) +{ +ssize_t sz; +unsigned int i, idx; +static const struct bug_frame *const stop_frames[] = { + __start_bug_frames, + __stop_bug_frames_0, + __stop_bug_frames_1,
xen/common/bug_ex_symbols.c line 90
Quoted 10 lines
xen/common/bug_ex_symbols.c new file +10
-0+ __stop_bug_frames_2, +#ifdef CONFIG_X86 + __stop_bug_frames_3, +#endif +NULL + }; + +#ifdef CONFIG_X86 +sort_exception_tables (); +#endif
Any reason why this needs moving out of setup.c ?
Quoted 27 lines
xen/include/xen/bug_ex_symbols.h new file +21
-0@@ -0,0 +1,74 @@ +/* +* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. +* +*/ + +#ifndef __BUG_EX_SYMBOL_LIST__ +#define __BUG_EX_SYMBOL_LIST__ + +#include <xen/config.h> +#include <xen/list.h> +#include <xen/symbols.h> + +#ifdef CONFIG_X86 +#include <asm/uaccess.h> +#endif +#include <asm/bug.h> + +struct virtual_region +{ + struct list_head list; +
xen/include/xen/bug_ex_symbols.h line 31
Quoted 10 lines
xen/include/xen/bug_ex_symbols.h new file +10
-0+#define CHECKING_SYMBOL (1<<1) +#define CHECKING_BUG_FRAME (1<<2) +#define CHECKING_EXCEPTION (1<<3) +/* +* Whether to skip this region for particular searches. The flag +* can be CHECKING_[SYMBOL|BUG_FRAMES|EXCEPTION]. +* +* If the function returns 1 this region will be skipped. +*/ +bool_t (*skip)(unsigned int flag,unsigned long priv);
Why do we need infrastructure like this? A virtual region is either active and in use (in which case it should be on the list and fully complete), or not in use and never available to query.
If it was only to deal with .init, I would recommend dropping it all.
Quoted 48 lines
xen/include/xen/bug_ex_symbols.h new file +43
-0+ +unsigned long start;/* Virtual address start. */ +unsigned long end;/* Virtual address start. */ + +/* +* If ->skip returns false for CHECKING_SYMBOL we will use +* 'symbols_lookup' callback to retrieve the name of the +* addr between start and end. If this is NULL the +* default lookup mechanism is used (the skip value is +* ignored). +*/ +symbols_lookup_t symbols_lookup; + +struct { +struct bug_frame *bugs;/* The pointer to array of bug frames. */ +ssize_t n_bugs;/* The number of them. */ + } frame[BUGFRAME_NR ]; + +#ifdef CONFIG_X86 +struct exception_table_entry *ex; +struct exception_table_entry *ex_end; +#endif + + unsigned long priv; /* To be used by above funcionts if need to. */ +}; + +extern struct list_head virtual_region_list; + +extern void setup_virtual_regions (void ); +extern int register_virtual_region (struct virtual_region *r); +extern void unregister_virtual_region (struct virtual_region *r); + +#endif /* __BUG_EX_SYMBOL_LIST__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/ xen/include/xen/kernel.h +0
-0
xen/include/xen/kernel.h line 68
Quoted 4 lines
xen/include/xen/kernel.h +1
-0@@ -65,12 +65,14 @@1 ; \ }) +
Spurious change.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 07/34] arm/x86: Use struct virtual_region to do bug, symbol, and (x86) exception tables
Quoted 9 lines · Andrew Cooper
Quoted 8 lines · Konrad Rzeszutek Wilk
xen/arch/arm/traps.c +0
-0@@ -16,6 +16,7 @@* GNU General Public License for more details. */
Quoted 4 lines
xen/arch/arm/traps.c line 19
Quoted 1 line
xen/arch/arm/traps.c +1
-0+#include <xen/bug_ex_symbols.h> how about just <
xen/virtual_region.h> ? It contains more than just bugframes.
/me nods.
Quoted 13 lines
Quoted 13 lines
xen/common/bug_ex_symbols.c new file +6
-0@@ -0,0 +1,119 @@ +/* +* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. +* +*/ + +#include <xen/bug_ex_symbols.h>
Quoted 8 lines
xen/common/bug_ex_symbols.c line 12
Quoted 6 lines
xen/common/bug_ex_symbols.c new file +6
-0+#include <xen/config.h> +#include <xen/kernel.h> +#include <xen/init.h> +#include <xen/spinlock.h> + +extern char __stext[];There is no such symbol.
_stextcomes in viakernel.h
Argh.
Quoted 33 lines
xen/common/bug_ex_symbols.c line 14
Quoted 3 lines
xen/common/bug_ex_symbols.c new file +2
-0+ +struct virtual_region kernel_text = {How about just "compiled" ? This is more than just .text.
Quoted 27 lines
xen/common/bug_ex_symbols.c new file +27
-0+ .list = LIST_HEAD_INIT(kernel_text.list), + .start = (unsigned long)_stext, + .end = (unsigned long )_etext, +#ifdef CONFIG_X86 + .ex = (struct exception_table_entry *)__start___ex_table, + .ex_end = (struct exception_table_entry *)__stop___ex_table, +#endif +}; + +/* +* The kernel_inittext should only be used when system_state +* is booting. Otherwise all accesses should be ignored. +*/ +static bool_t ignore_if_active (unsigned int flag,unsigned long priv) +{ +return (system_state >= SYS_STATE_active); +} + +/* +* Becomes irrelevant when __init sections are cleared. +*/ +struct virtual_region kernel_inittext = { + .list =LIST_HEAD_INIT (kernel_inittext.list), + .skip = ignore_if_active, + .start = (unsigned long )_sinittext, + .end = (unsigned long )_einittext, +#ifdef CONFIG_X86
Quoted 8 lines
xen/common/bug_ex_symbols.c line 46
Quoted 5 lines
xen/common/bug_ex_symbols.c new file +5
-0+/* Even if they are __init their exception entry still gets stuck here. */ + .ex = (struct exception_table_entry *)__start___ex_table, + .ex_end = (struct exception_table_entry *)__stop___ex_table, +#endif +};This can live in .init.data and be taken off the linked list in
init_done(), which performs other bits of cleanup relating to .init
Unfortunatly at that point of time it is SMP - so if we clean it up we need to use a spin_lock.
Quoted 14 lines
xen/common/bug_ex_symbols.c line 53
Quoted 8 lines
xen/common/bug_ex_symbols.c new file +7
-0+ +/* +* No locking. Additions are done either at startup (when there is only +* one CPU) or when all CPUs are running without IRQs. +* +* Deletions are big tricky. We MUST make sure all but one CPU +* are running cpu_relax(). It should still be possible to lock this properly. We expect no contention, at which point acquiring and releasing the locks will always hit fastpaths, but it will avoid accidental corruption if something goes wrong.
Quoted 4 lines
In each of register or deregister, take the lock, then confirm whether the current region is in a list or not, by looking at
r->list. With the singlevirtual_region_lockheld, that can safely avoid repeatedly adding the region to the region list.
Yeah. I don't know why I was thinking we can't. Ah, I was thinking about traversing the list - and we don't want the spin_lock as this is in the do_traps or other code that really really should not take any spinlocks.
But if the adding/removing is done under a spinlock then that is OK.
Let me do that.
Quoted 32 lines
Quoted 32 lines
xen/common/bug_ex_symbols.c new file +31
-0+* +*/ +LIST_HEAD (virtual_region_list); + +int register_virtual_region (struct virtual_region *r) +{ +ASSERT (!local_irq_is_enabled ()); + +list_add_tail (&r->list, &virtual_region_list); +return 0 ; +} + +void unregister_virtual_region (struct virtual_region *r) +{ +ASSERT (!local_irq_is_enabled ()); + +list_del_init (&r->list); +} + +void __init setup_virtual_regions (void ) +{ +ssize_t sz; +unsigned int i, idx; +static const struct bug_frame *const stop_frames[] = { + __start_bug_frames, + __stop_bug_frames_0, + __stop_bug_frames_1, + __stop_bug_frames_2, +#ifdef CONFIG_X86 + __stop_bug_frames_3, +#endif
Quoted 8 lines
xen/common/bug_ex_symbols.c line 90
Quoted 6 lines
xen/common/bug_ex_symbols.c new file +6
-0+ NULL + }; + +#ifdef CONFIG_X86 +sort_exception_tables (); +#endif Any reason why this needs moving out of
setup.c?
None at all.
Quoted 44 lines
Quoted 28 lines
xen/include/xen/bug_ex_symbols.h new file +21
-0@@ -0,0 +1,74 @@ +/* +* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. +* +*/ + +#ifndef __BUG_EX_SYMBOL_LIST__ +#define __BUG_EX_SYMBOL_LIST__ + +#include <xen/config.h> +#include <xen/list.h> +#include <xen/symbols.h> + +#ifdef CONFIG_X86 +#include <asm/uaccess.h> +#endif +#include <asm/bug.h> + +struct virtual_region +{ + struct list_head list; +xen/include/xen/bug_ex_symbols.h line 31
Quoted 10 lines
xen/include/xen/bug_ex_symbols.h new file +10
-0+#define CHECKING_SYMBOL (1<<1) +#define CHECKING_BUG_FRAME (1<<2) +#define CHECKING_EXCEPTION (1<<3) +/* +* Whether to skip this region for particular searches. The flag +* can be CHECKING_[SYMBOL|BUG_FRAMES|EXCEPTION]. +* +* If the function returns 1 this region will be skipped. +*/ +bool_t (*skip)(unsigned int flag,unsigned long priv);Why do we need infrastructure like this? A virtual region is either active and in use (in which case it should be on the list and fully complete), or not in use and never available to query.
Quoted 1 line
If it was only to deal with .init, I would recommend dropping it all.
That was the reason.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 07/34] arm/x86: Use struct virtual_region to do bug, symbol, and (x86) exception tables
Quoted 92 lines · Konrad Rzeszutek Wilk
Quoted 9 lines · Andrew Cooper
Quoted 8 lines · Konrad Rzeszutek Wilk
xen/arch/arm/traps.c +0
-0@@ -16,6 +16,7 @@* GNU General Public License for more details. */ Quoted 3 lines
xen/arch/arm/traps.c line 19
Quoted 1 line
xen/arch/arm/traps.c +1
-0+#include <xen/bug_ex_symbols.h> how about just <
xen/virtual_region.h> ? It contains more than just bugframes./me nods.
Quoted 11 lines
Quoted 11 lines
xen/common/bug_ex_symbols.c new file +5
-0@@ -0,0 +1,119 @@ +/* +* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. +* +*/ +Quoted 8 lines
xen/common/bug_ex_symbols.c line 12
Quoted 7 lines
xen/common/bug_ex_symbols.c new file +7
-0+#include <xen/bug_ex_symbols.h> +#include <xen/config.h> +#include <xen/kernel.h> +#include <xen/init.h> +#include <xen/spinlock.h> + +extern char __stext[];There is no such symbol.
_stextcomes in viakernel.hArgh.
Quoted 30 lines
xen/common/bug_ex_symbols.c line 14
Quoted 2 lines
xen/common/bug_ex_symbols.c new file +2
-0+ +struct virtual_region kernel_text = {How about just "compiled" ? This is more than just .text.
Quoted 26 lines
xen/common/bug_ex_symbols.c new file +26
-0+ .list = LIST_HEAD_INIT(kernel_text.list), + .start = (unsigned long)_stext, + .end = (unsigned long )_etext, +#ifdef CONFIG_X86 + .ex = (struct exception_table_entry *)__start___ex_table, + .ex_end = (struct exception_table_entry *)__stop___ex_table, +#endif +}; + +/* +* The kernel_inittext should only be used when system_state +* is booting. Otherwise all accesses should be ignored. +*/ +static bool_t ignore_if_active (unsigned int flag,unsigned long priv) +{ +return (system_state >= SYS_STATE_active); +} + +/* +* Becomes irrelevant when __init sections are cleared. +*/ +struct virtual_region kernel_inittext = { + .list =LIST_HEAD_INIT (kernel_inittext.list), + .skip = ignore_if_active, + .start = (unsigned long )_sinittext, + .end = (unsigned long)_einittext,Quoted 8 lines
xen/common/bug_ex_symbols.c line 46
Quoted 6 lines
xen/common/bug_ex_symbols.c new file +6
-0+#ifdef CONFIG_X86 +/* Even if they are __init their exception entry still gets stuck here. */ + .ex = (struct exception_table_entry *)__start___ex_table, + .ex_end = (struct exception_table_entry *)__stop___ex_table, +#endif +};This can live in .init.data and be taken off the linked list in
init_done(), which performs other bits of cleanup relating to .initUnfortunatly at that point of time it is SMP - so if we clean it up we need to use a
spin_lock.Quoted 12 lines
xen/common/bug_ex_symbols.c line 53
Quoted 7 lines
xen/common/bug_ex_symbols.c new file +7
-0+ +/* +* No locking. Additions are done either at startup (when there is only +* one CPU) or when all CPUs are running without IRQs. +* +* Deletions are big tricky. We MUST make sure all but one CPU +* are running cpu_relax(). It should still be possible to lock this properly. We expect no contention, at which point acquiring and releasing the locks will always hit fastpaths, but it will avoid accidental corruption if something goes wrong.
Quoted 4 lines
In each of register or deregister, take the lock, then confirm whether the current region is in a list or not, by looking at
r->list. With the singlevirtual_region_lockheld, that can safely avoid repeatedly adding the region to the region list.
Quoted 7 lines
Yeah. I don't know why I was thinking we can't. Ah, I was thinking about traversing the list - and we don't want the
spin_lockas this is in thedo_trapsor other code that really really should not take any spinlocks.But if the adding/removing is done under a spinlock then that is OK.
Let me do that.
Actually, that isn't sufficient. Sorry for misleaing you.
You have to exclude modifications to the list against other cpus waking it in an exception handler, which might include NMI and MCE context.
Now I think about it, going lockless here is probably a bonus, as we don't want to be messing around with locks in fatal contexts. In which case, it would be better to use a single linked list and cmpxchg to insert/remove elements. It generally wants to be walked forwards, and will only have a handful of elements, so searching forwards to delete will be ok.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 07/34] arm/x86: Use struct virtual_region to do bug, symbol, and (x86) exception tables
Quoted 105 lines · Andrew Cooper
Quoted 92 lines · Konrad Rzeszutek Wilk
Quoted 9 lines · Andrew Cooper
Quoted 8 lines · Konrad Rzeszutek Wilk
xen/arch/arm/traps.c +0
-0@@ -16,6 +16,7 @@* GNU General Public License for more details. */ Quoted 3 lines
xen/arch/arm/traps.c line 19
Quoted 1 line
xen/arch/arm/traps.c +1
-0+#include <xen/bug_ex_symbols.h> how about just <
xen/virtual_region.h> ? It contains more than just bugframes./me nods.
Quoted 11 lines
Quoted 11 lines
xen/common/bug_ex_symbols.c new file +5
-0@@ -0,0 +1,119 @@ +/* +* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. +* +*/ +Quoted 8 lines
xen/common/bug_ex_symbols.c line 12
Quoted 7 lines
xen/common/bug_ex_symbols.c new file +7
-0+#include <xen/bug_ex_symbols.h> +#include <xen/config.h> +#include <xen/kernel.h> +#include <xen/init.h> +#include <xen/spinlock.h> + +extern char __stext[];There is no such symbol.
_stextcomes in viakernel.hArgh.
Quoted 30 lines
xen/common/bug_ex_symbols.c line 14
Quoted 2 lines
xen/common/bug_ex_symbols.c new file +2
-0+ +struct virtual_region kernel_text = {How about just "compiled" ? This is more than just .text.
Quoted 26 lines
xen/common/bug_ex_symbols.c new file +26
-0+ .list = LIST_HEAD_INIT(kernel_text.list), + .start = (unsigned long)_stext, + .end = (unsigned long )_etext, +#ifdef CONFIG_X86 + .ex = (struct exception_table_entry *)__start___ex_table, + .ex_end = (struct exception_table_entry *)__stop___ex_table, +#endif +}; + +/* +* The kernel_inittext should only be used when system_state +* is booting. Otherwise all accesses should be ignored. +*/ +static bool_t ignore_if_active (unsigned int flag,unsigned long priv) +{ +return (system_state >= SYS_STATE_active); +} + +/* +* Becomes irrelevant when __init sections are cleared. +*/ +struct virtual_region kernel_inittext = { + .list =LIST_HEAD_INIT (kernel_inittext.list), + .skip = ignore_if_active, + .start = (unsigned long )_sinittext, + .end = (unsigned long)_einittext,Quoted 8 lines
xen/common/bug_ex_symbols.c line 46
Quoted 6 lines
xen/common/bug_ex_symbols.c new file +6
-0+#ifdef CONFIG_X86 +/* Even if they are __init their exception entry still gets stuck here. */ + .ex = (struct exception_table_entry *)__start___ex_table, + .ex_end = (struct exception_table_entry *)__stop___ex_table, +#endif +};This can live in .init.data and be taken off the linked list in
init_done(), which performs other bits of cleanup relating to .initUnfortunatly at that point of time it is SMP - so if we clean it up we need to use a
spin_lock.Quoted 12 lines
xen/common/bug_ex_symbols.c line 53
Quoted 7 lines
xen/common/bug_ex_symbols.c new file +7
-0+ +/* +* No locking. Additions are done either at startup (when there is only +* one CPU) or when all CPUs are running without IRQs. +* +* Deletions are big tricky. We MUST make sure all but one CPU +* are running cpu_relax(). It should still be possible to lock this properly. We expect no contention, at which point acquiring and releasing the locks will always hit fastpaths, but it will avoid accidental corruption if something goes wrong.
Quoted 4 lines
In each of register or deregister, take the lock, then confirm whether the current region is in a list or not, by looking at
r->list. With the singlevirtual_region_lockheld, that can safely avoid repeatedly adding the region to the region list.Quoted 7 lines
Yeah. I don't know why I was thinking we can't. Ah, I was thinking about traversing the list - and we don't want the
spin_lockas this is in thedo_trapsor other code that really really should not take any spinlocks.But if the adding/removing is done under a spinlock then that is OK.
Let me do that.
Actually, that isn't sufficient. Sorry for misleaing you.
You have to exclude modifications to the list against other cpus waking it in an exception handler, which might include NMI and MCE context.
Quoted 6 lines
Now I think about it, going lockless here is probably a bonus, as we don't want to be messing around with locks in fatal contexts. In which case, it would be better to use a single linked list and cmpxchg to insert/remove elements. It generally wants to be walked forwards, and will only have a handful of elements, so searching forwards to delete will be ok.
Actually, knowing that the list is only ever walked forwards by the exception handlers, and with some regular spinlocks around mutation, dudicious use of list_add_tail_rcu() and list_del_rcu() should suffice (I think), and will definitely be better than handrolling a single linked list.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 07/34] arm/x86: Use struct virtual_region to do bug, symbol, and (x86) exception tables
Quoted 115 lines
Quoted 1 line
Quoted 1 line · On 15.03.16 at 21:02, <[email protected]> wrote:
Quoted 60 lines · Andrew Cooper
Quoted 59 lines · Konrad Rzeszutek Wilk
Quoted 9 lines · Andrew Cooper
Quoted 8 lines · Konrad Rzeszutek Wilk
xen/arch/arm/traps.c +0
-0@@ -16,6 +16,7 @@* GNU General Public License for more details. */ Quoted 3 lines
xen/arch/arm/traps.c line 19
Quoted 1 line
xen/arch/arm/traps.c +1
-0+#include <xen/bug_ex_symbols.h> how about just <
xen/virtual_region.h> ? It contains more than just bugframes./me nods.
Quoted 11 lines
Quoted 11 lines
xen/common/bug_ex_symbols.c new file +5
-0@@ -0,0 +1,119 @@ +/* +* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. +* +*/ +Quoted 8 lines
xen/common/bug_ex_symbols.c line 12
Quoted 7 lines
xen/common/bug_ex_symbols.c new file +7
-0+#include <xen/bug_ex_symbols.h> +#include <xen/config.h> +#include <xen/kernel.h> +#include <xen/init.h> +#include <xen/spinlock.h> + +extern char __stext[];There is no such symbol.
_stextcomes in viakernel.hArgh.
Quoted 24 lines
xen/common/bug_ex_symbols.c line 14
Quoted 2 lines
xen/common/bug_ex_symbols.c new file +2
-0+ +struct virtual_region kernel_text = {How about just "compiled" ? This is more than just .text.
Quoted 20 lines
xen/common/bug_ex_symbols.c new file +20
-0+ .list = LIST_HEAD_INIT(kernel_text.list), + .start = (unsigned long)_stext, + .end = (unsigned long )_etext, +#ifdef CONFIG_X86 + .ex = (struct exception_table_entry *)__start___ex_table, + .ex_end = (struct exception_table_entry *)__stop___ex_table, +#endif +}; + +/* +* The kernel_inittext should only be used when system_state +* is booting. Otherwise all accesses should be ignored. +*/ +static bool_t ignore_if_active (unsigned int flag,unsigned long priv) +{ +return (system_state >= SYS_STATE_active); +} + +/* +* Becomes irrelevant when __init sections are cleared. Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
xen/common/bug_ex_symbols.c
Quoted 8 lines
xen/common/bug_ex_symbols.c new file +8
-0+*/ +struct virtual_region kernel_inittext = { + .list =LIST_HEAD_INIT (kernel_inittext.list), + .skip = ignore_if_active, + .start = (unsigned long )_sinittext, + .end = (unsigned long )_einittext, +#ifdef CONFIG_X86 +/* Even if they are __init their exception entry still gets stuck here. */
Quoted 37 lines
Quoted 25 lines
Quoted 6 lines
xen/common/bug_ex_symbols.c line 22
Quoted 4 lines
xen/common/bug_ex_symbols.c new file +4
-0+ .ex = (struct exception_table_entry *)__start___ex_table, + .ex_end = (struct exception_table_entry *)__stop___ex_table, +#endif +};This can live in .init.data and be taken off the linked list in
init_done(), which performs other bits of cleanup relating to .initUnfortunatly at that point of time it is SMP - so if we clean it up we need to use a
spin_lock.Quoted 12 lines
xen/common/bug_ex_symbols.c line 53
Quoted 7 lines
xen/common/bug_ex_symbols.c new file +7
-0+ +/* +* No locking. Additions are done either at startup (when there is only +* one CPU) or when all CPUs are running without IRQs. +* +* Deletions are big tricky. We MUST make sure all but one CPU +* are running cpu_relax(). It should still be possible to lock this properly. We expect no contention, at which point acquiring and releasing the locks will always hit fastpaths, but it will avoid accidental corruption if something goes wrong.
Quoted 4 lines
In each of register or deregister, take the lock, then confirm whether the current region is in a list or not, by looking at
r->list. With the singlevirtual_region_lockheld, that can safely avoid repeatedly adding the region to the region list.Quoted 7 lines
Yeah. I don't know why I was thinking we can't. Ah, I was thinking about traversing the list - and we don't want the
spin_lockas this is in thedo_trapsor other code that really really should not take any spinlocks.But if the adding/removing is done under a spinlock then that is OK.
Let me do that.
Actually, that isn't sufficient. Sorry for misleaing you.
You have to exclude modifications to the list against other cpus waking it in an exception handler, which might include NMI and MCE context.
Quoted 6 lines
Now I think about it, going lockless here is probably a bonus, as we don't want to be messing around with locks in fatal contexts. In which case, it would be better to use a single linked list and cmpxchg to insert/remove elements. It generally wants to be walked forwards, and will only have a handful of elements, so searching forwards to delete will be ok.
Quoted 5 lines
Actually, knowing that the list is only ever walked forwards by the exception handlers, and with some regular spinlocks around mutation, dudicious use of
list_add_tail_rcu()andlist_del_rcu()should suffice (I think), and will definitely be better than handrolling a single linked list.
Good that I went to the end of this sub-thread, before replying to suggest just this.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 07/34] arm/x86: Use struct virtual_region to do bug, symbol, and (x86) exception tables
In reply to Konrad Rzeszutek WilkQuoted 2 lines
Quoted 1 line
Quoted 1 line · On 15.03.16 at 18:56, <[email protected]> wrote:
lookup.
Was this meant to be part of $subject?
Quoted 29 lines
xen/arch/arm/traps.c +5
-14@@ -1077,27 +1080,39 @@ void do_unexpected_trap(const char *msg, struct cpu_user_regs *regs)int do_bug_frame (struct cpu_user_regs *regs,vaddr_t pc) { -const struct bug_frame *bug; +const struct bug_frame *bug =NULL ;const char *prefix ="" , *filename, *predicate;unsigned long fixup; -int id, lineno; -static const struct bug_frame *const stop_frames[] = { - __stop_bug_frames_0, - __stop_bug_frames_1, - __stop_bug_frames_2, -NULL - }; +int id =-1 , lineno; +struct virtual_region *region; -for ( bug = __start_bug_frames, id =0 ; stop_frames[id]; ++bug ) +list_for_each_entry ( region, &virtual_region_list, list ) { -while (unlikely (bug == stop_frames[id]) ) - ++id; +unsigned int i; -if ( ((vaddr_t )bug_loc (bug)) == pc ) -break ; - }
xen/arch/arm/traps.c void do_unexpected_trap(const char *msg, struct · line 1102
Quoted 10 lines
xen/arch/arm/traps.c +8
-1+if ( region->skip && region->skip (CHECKING_BUG_FRAME , region->priv) ) +continue ; + +if ( pc < region->start || pc > region->end ) +continue ; -if ( !stop_frames[id] ) +for ( id =0 ; id <BUGFRAME_NR ; id++ ) + { +const struct bug_frame *b =NULL ;
Pointless initializer.
xen/arch/x86/extable.c line 3
Quoted 6 lines
xen/arch/x86/extable.c +1
-0@@ -1,6 +1,8 @@ +#include <xen/bug_ex_symbols.h> #include <xen/config.h>
In cases like this please take the opportunity to get rid of the explicit inclusion of xen/config.h.
Quoted 7 lines
xen/common/bug_ex_symbols.c new file +4
-0@@ -0,0 +1,119 @@ +/* +* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. +* +*/
xen/common/bug_ex_symbols.c line 14
Quoted 10 lines
xen/common/bug_ex_symbols.c new file +10
-0+ +#include <xen/bug_ex_symbols.h> +#include <xen/config.h> +#include <xen/kernel.h> +#include <xen/init.h> +#include <xen/spinlock.h> + +extern char __stext[]; + +struct virtual_region kernel_text = {
static
xen/common/bug_ex_symbols.c line 21
Quoted 7 lines
xen/common/bug_ex_symbols.c new file +7
-0+ .list = LIST_HEAD_INIT(kernel_text.list), + .start = (unsigned long)_stext, + .end = (unsigned long )_etext, +#ifdef CONFIG_X86 + .ex = (struct exception_table_entry *)__start___ex_table, + .ex_end = (struct exception_table_entry *)__stop___ex_table, +#endif
Is this together with ...
xen/common/bug_ex_symbols.c line 45
Quoted 13 lines
xen/common/bug_ex_symbols.c new file +13
-0+/* +* Becomes irrelevant when __init sections are cleared. +*/ +struct virtual_region kernel_inittext = { + .list =LIST_HEAD_INIT (kernel_inittext.list), + .skip = ignore_if_active, + .start = (unsigned long )_sinittext, + .end = (unsigned long )_einittext, +#ifdef CONFIG_X86 +/* Even if they are __init their exception entry still gets stuck here. */ + .ex = (struct exception_table_entry *)__start___ex_table, + .ex_end = (struct exception_table_entry *)__stop___ex_table, +#endif
... this really a good idea? I.e. are there not going to be any odd side effects because of that redundancy?
Also note that the comment preceding this object is a single line one.
xen/common/bug_ex_symbols.c line 56
Quoted 9 lines
xen/common/bug_ex_symbols.c new file +9
-0+/* +* No locking. Additions are done either at startup (when there is only +* one CPU) or when all CPUs are running without IRQs. +* +* Deletions are big tricky. We MUST make sure all but one CPU +* are running cpu_relax(). +* +*/ +LIST_HEAD (virtual_region_list);
I wonder whether this wouldn't better be static, with the iterator that the various parties need getting put here as an out-of-line function (instead of getting open coded in a couple of places).
Quoted 11 lines
xen/common/bug_ex_symbols.c new file +11
-0+void __init setup_virtual_regions (void ) +{ +ssize_t sz; +unsigned int i, idx; +static const struct bug_frame *const stop_frames[] = { + __start_bug_frames, + __stop_bug_frames_0, + __stop_bug_frames_1, + __stop_bug_frames_2, +#ifdef CONFIG_X86 + __stop_bug_frames_3,
xen/common/bug_ex_symbols.c line 93
Quoted 10 lines
xen/common/bug_ex_symbols.c new file +10
-0+#endif + NULL + }; + +#ifdef CONFIG_X86 +sort_exception_tables (); +#endif + +/* N.B. idx != i */ +for ( idx =0 , i =1 ; stop_frames[i]; i++, idx++ )
Irrespective of the comment - why two loop variables when they get incremented in lockstep.
xen/common/bug_ex_symbols.c line 97
Quoted 4 lines
xen/common/bug_ex_symbols.c new file +4
-0+ { +struct bug_frame *s; + + s = (struct bug_frame *)stop_frames[i-1 ];
Bogus cast, the more that it discards constness.
xen/common/bug_ex_symbols.c static unsigned int get_symbol_offset(unsigned long pos) · line 99
Quoted 5 lines
xen/common/bug_ex_symbols.c new file +1
-0@@ -95,10 +96,28 @@ static unsigned int get_symbol_offset(unsigned long pos)return name - symbols_names; } +bool_t __is_active_kernel_text (unsigned long addr,symbols_lookup_t *cb)
No new (and even more so global) symbols with double underscores at their beginning please.
xen/common/bug_ex_symbols.c const char *symbols_lookup(unsigned long addr, · line 130
Quoted 5 lines
xen/common/bug_ex_symbols.c new file +1
-0@@ -108,13 +127,17 @@ const char *symbols_lookup(unsigned long addr, {unsigned long i, low, high, mid;unsigned long symbol_end =0 ; +symbols_lookup_t symbol_lookup =NULL ;
Pointless initializer.
xen/common/bug_ex_symbols.c const char *symbols_lookup(unsigned long addr, · line 138
Quoted 9 lines
xen/common/bug_ex_symbols.c new file +3
-1namebuf[KSYM_NAME_LEN ] =0 ; namebuf[0 ] =0 ; -if (!is_active_kernel_text (addr)) +if (!__is_active_kernel_text (addr, &symbol_lookup))return NULL ; +if (symbol_lookup) +return (symbol_lookup)(addr, symbolsize, offset, namebuf);
Note that there are few coding style issues here (missing blanks, superfluous parentheses).
Quoted 8 lines
xen/include/xen/bug_ex_symbols.h new file +5
-0@@ -0,0 +1,74 @@ +/* +* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. +* +*/ +
xen/include/xen/bug_ex_symbols.h line 15
Quoted 10 lines
xen/include/xen/bug_ex_symbols.h new file +10
-0+#ifndef __BUG_EX_SYMBOL_LIST__ +#define __BUG_EX_SYMBOL_LIST__ + +#include <xen/config.h> +#include <xen/list.h> +#include <xen/symbols.h> + +#ifdef CONFIG_X86 +#include <asm/uaccess.h> +#endif
Why?
Quoted 28 lines
xen/include/xen/bug_ex_symbols.h new file +28
-0+#include <asm/bug.h> + +struct virtual_region +{ +struct list_head list; + +#define CHECKING_SYMBOL (1<<1) +#define CHECKING_BUG_FRAME (1<<2) +#define CHECKING_EXCEPTION (1<<3) +/* +* Whether to skip this region for particular searches. The flag +* can be CHECKING_[SYMBOL|BUG_FRAMES|EXCEPTION]. +* +* If the function returns 1 this region will be skipped. +*/ +bool_t (*skip)(unsigned int flag,unsigned long priv); + +unsigned long start;/* Virtual address start. */ +unsigned long end;/* Virtual address start. */ + +/* +* If ->skip returns false for CHECKING_SYMBOL we will use +* 'symbols_lookup' callback to retrieve the name of the +* addr between start and end. If this is NULL the +* default lookup mechanism is used (the skip value is +* ignored). +*/ +symbols_lookup_t symbols_lookup;
xen/include/xen/bug_ex_symbols.h line 53
Quoted 10 lines
xen/include/xen/bug_ex_symbols.h new file +10
-0+ +struct { +struct bug_frame *bugs;/* The pointer to array of bug frames. */ +ssize_t n_bugs;/* The number of them. */ + } frame[BUGFRAME_NR ]; + +#ifdef CONFIG_X86 +struct exception_table_entry *ex; +struct exception_table_entry *ex_end; +#endif
The bug frame and exception related data are kind of odd to be placed in a structure with this name. Would that not better be accessed through ...
xen/include/xen/bug_ex_symbols.h line 55
Quoted 1 line
xen/include/xen/bug_ex_symbols.h new file +1
-0+unsigned long priv;/* To be used by above funcionts if need to. */
... this by the interested parties?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 07/34] arm/x86: Use struct virtual_region to do bug, symbol, and (x86) exception tables
. snip..
Quoted 14 lines
Quoted 1 line
+struct
virtual_regionkernel_text= {static
Review
Quoted 7 lines
(quoted diff) +7
-0+ .list = LIST_HEAD_INIT(kernel_text.list), + .start = (unsigned long)_stext, + .end = (unsigned long)_etext, +#ifdef CONFIG_X86 + .ex = (struct exception_table_entry *)__start___ex_table, + .ex_end = (struct exception_table_entry *)__stop___ex_table, +#endifIs this together with ...
Quoted 16 lines
Review
Quoted 13 lines
(quoted diff) +13
-0+/* + * Becomes irrelevant when __init sections are cleared. + */ +struct virtual_region kernel_inittext = { + .list = LIST_HEAD_INIT(kernel_inittext.list), + .skip = ignore_if_active, + .start = (unsigned long)_sinittext, + .end = (unsigned long)_einittext, +#ifdef CONFIG_X86 + /* Even if they are __init their exception entry still gets stuck here. */ + .ex = (struct exception_table_entry *)__start___ex_table, + .ex_end = (struct exception_table_entry *)__stop___ex_table, +#endif... this really a good idea? I.e. are there not going to be any odd side effects because of that redundancy?
None. If the EIP falls within _stext and _etext then its 'ex' table will be scanned. If _inittext and _einittext then this one. Both of them end up scanning the same exact exception table (which is kind silly) - but there are no side-effect.
It would be good to only have __init related exceptions on the __inittext (and also ditch the __init exception tables once the boot is completed) but I am not exactly sure how to automatically make the macros resolve what sections it should go in. That is a further TODO though.
Quoted 16 lines
Also note that the comment preceding this object is a single line one.
Review
Quoted 9 lines
(quoted diff) +9
-0+/* + * No locking. Additions are done either at startup (when there is only + * one CPU) or when all CPUs are running without IRQs. + * + * Deletions are big tricky. We MUST make sure all but one CPU + * are running cpu_relax(). + * + */ +LIST_HEAD(virtual_region_list);I wonder whether this wouldn't better be static, with the iterator that the various parties need getting put here as an out-of-line function (instead of getting open coded in a couple of places).
There are three users of this list:
* search_exception_table - which ends up calling search_one_table
if within start->end and if region->ex is defined.
* do_invalid_trap (x86 and ARM) - where both scan start->end.
* symbols_lookup - where we scan start->end.
The last two could be unified in a:
struct virtual_region search_virtual_region(unsigned long addr);
And the first one can use this and then check if region->ex is set as well.
[trying it out]
.. snip..
Quoted 7 lines
Review const char *symbols_lookup(unsigned long addr, · line 130
Quoted 5 lines
(quoted diff) +1
-0@@ -108,13 +127,17 @@ const char *symbols_lookup(unsigned long addr, { unsigned long i, low, high, mid; unsigned long symbol_end = 0; + symbols_lookup_t symbol_lookup = NULL;Pointless initializer.
I believe we need it. That is the contents on the stack can be garbage and the __is_active_kernel_text won't update symbol_lookup unless it finds a match. Ah, and also the compiler is unhappy:
symbols.c: In function ‘symbols_lookup’:
symbols.c:136:8: error: ‘symbol_lookup’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
if (symbol_lookup)
^cc1: all warnings being treated as errors
Quoted 8 lines
Quoted 8 lines
(quoted diff) +1
-1namebuf[KSYM_NAME_LEN] = 0; namebuf[0] = 0; - if (!is_active_kernel_text(addr)) + if (!__is_active_kernel_text(addr, &symbol_lookup)) return NULL;
Quoted 5 lines
Review const char *symbols_lookup(unsigned long addr, · line 138
Quoted 2 lines
(quoted diff) +2
-0+ if (symbol_lookup) + return (symbol_lookup)(addr, symbolsize, offset, namebuf);Note that there are few coding style issues here (missing blanks, superfluous parentheses).
That file uses a different StyleGuide. The Linux one. Which reminds me that __is_active_kernel_text needs to adhere to different StyleGuide.
Quoted 13 lines
Quoted 13 lines
xen/include/xen/bug_ex_symbols.h new file +9
-0@@ -0,0 +1,74 @@ +/* +* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. +* +*/ + +#ifndef __BUG_EX_SYMBOL_LIST__ +#define __BUG_EX_SYMBOL_LIST__ + +#include <xen/config.h>
Quoted 8 lines
xen/include/xen/bug_ex_symbols.h line 15
Quoted 6 lines
xen/include/xen/bug_ex_symbols.h new file +6
-0+#include <xen/list.h> +#include <xen/symbols.h> + +#ifdef CONFIG_X86 +#include <asm/uaccess.h> +#endif Why?
Otherwise the compilation will fail on ARM as they do not have exceptions (and no asm/uaccess.h file)
Quoted 44 lines
Quoted 29 lines
xen/include/xen/bug_ex_symbols.h new file +28
-0+#include <asm/bug.h> + +struct virtual_region +{ +struct list_head list; + +#define CHECKING_SYMBOL (1<<1) +#define CHECKING_BUG_FRAME (1<<2) +#define CHECKING_EXCEPTION (1<<3) +/* +* Whether to skip this region for particular searches. The flag +* can be CHECKING_[SYMBOL|BUG_FRAMES|EXCEPTION]. +* +* If the function returns 1 this region will be skipped. +*/ +bool_t (*skip)(unsigned int flag,unsigned long priv); + +unsigned long start;/* Virtual address start. */ +unsigned long end;/* Virtual address start. */ + +/* +* If ->skip returns false for CHECKING_SYMBOL we will use +* 'symbols_lookup' callback to retrieve the name of the +* addr between start and end. If this is NULL the +* default lookup mechanism is used (the skip value is +* ignored). +*/ +symbols_lookup_t symbols_lookup;xen/include/xen/bug_ex_symbols.h line 53
Quoted 10 lines
xen/include/xen/bug_ex_symbols.h new file +10
-0+ +struct { +struct bug_frame *bugs;/* The pointer to array of bug frames. */ +ssize_t n_bugs;/* The number of them. */ + } frame[BUGFRAME_NR ]; + +#ifdef CONFIG_X86 +struct exception_table_entry *ex; +struct exception_table_entry *ex_end; +#endif The bug frame and exception related data are kind of odd to be placed in a structure with this name. Would that not better be accessed through ...
Quoted 3 lines
xen/include/xen/bug_ex_symbols.h line 54
Quoted 1 line
xen/include/xen/bug_ex_symbols.h new file +1
-0+unsigned long priv;/* To be used by above funcionts if need to. */ ... this by the interested parties?
This had been re-worked with Andrew's suggestions and yours. Pls see:
From d542ae2b6de421c5402888519d4d11a09abe8d46 Mon Sep 17 00:00:00 2001
From: Konrad Rzeszutek Wilk <[email protected]>
Date: Thu, 10 Mar 2016 16:35:50 -0500
Subject: [PATCH] arm/x86: Use struct virtual_region to do bug, symbol, and
(x86) exception tables lookup.
During execution of the hypervisor we have two regions of executable code - stext -> _etext, and _sinittext -> _einitext.
The later is not needed after bootup.
We also have various built-in macros and functions to search in between those two swaths depending on the state of the system.
That is either for bug_frames, exceptions (x86) or symbol names for the instruction.
With xSplice in the picture - we need a mechansim for new payloads to searched as well for all of this.
Originally we had extra 'if (xsplice)...' but that gets a bit tiring and does not hook up nicely.
This 'struct virtual_region' and virtual_region_list provide a mechanism to search for the bug_frames, exception table, and symbol names entries without having various calls in other sub-components in the system.
Code which wishes to participate in bug_frames and exception table entries search has to only use two public APIs:
- register_virtual_region
- unregister_virtual_region
to let the core code know.
If the ->lookup_symbol is not then the default internal symbol lookup mechanism is used.
---
Cc: Stefano Stabellini <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
v4: New patch.
v5:
- Rename to virtual_region.
- Ditch the 'skip' function.
- Remove the _stext.
- Use RCU lists.
- Add a search function.
---
--- 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 | 151 +++++++++++++++++++++++++++++++++++++++ xen/include/xen/symbols.h | 9 +++ xen/include/xen/virtual_region.h | 56 +++++++++++++++ 10 files changed, 292 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 (); +/* Setup Hyp vector base */ WRITE_SYSREG ((vaddr_t )hyp_traps_vector,VBAR_EL2 );
@@ -1077,27 +1080,33 @@ void do_unexpected_trap(const char *msg, struct cpu_user_regs *regs)int do_bug_frame (struct cpu_user_regs *regs,vaddr_t pc) { -const struct bug_frame *bug; +const struct bug_frame *bug =NULL ;const char *prefix ="" , *filename, *predicate;unsigned long fixup; -int id, lineno; -static const struct bug_frame *const stop_frames[] = { - __stop_bug_frames_0, - __stop_bug_frames_1, - __stop_bug_frames_2, -NULL - }; +int id =-1 , lineno; +struct virtual_region *region; -for ( bug = __start_bug_frames, id =0 ; stop_frames[id]; ++bug ) + region =search_virtual_regions (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); +struct virtual_region *region =search_virtual_regions (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 (); +/* 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; +struct virtual_region *region;DEBUGGER_trap_entry (TRAP_invalid_op, regs);
@@ -1160,16 +1155,29 @@ void do_invalid_op(struct cpu_user_regs *regs) memcmp(bug_insn, "\xf\xb", sizeof(bug_insn)) ) goto die; -for ( bug = __start_bug_frames, id =0 ; stop_frames[id]; ++bug ) + region =search_virtual_regions (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 !!search_virtual_regions (addr); } const char *symbols_lookup(unsigned long addr,
@@ -108,13 +108,18 @@ const char *symbols_lookup(unsigned long addr, {unsigned long i, low, high, mid;unsigned long symbol_end =0 ; +struct virtual_region *region; namebuf[KSYM_NAME_LEN ] =0 ; namebuf[0 ] =0 ; -if (!is_active_kernel_text (addr)) + region =search_virtual_regions (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 +151 -0
151 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 +56 -0
56 lines not on this page · raw message
Signature · 8 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v4 07/34] arm/x86: Use struct virtual_region to do bug, symbol, and (x86) exception tables
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 22.03.16 at 21:18, <[email protected]> wrote:
It would be good to only have
__initrelated exceptions on the__inittext(and also ditch the__initexception tables once the boot is completed) but I am not exactly sure how to automatically make the macros resolve what sections it should go in. That is a further TODO though.
I'm pretty confident that this can't be reasonably addressed without the compiler's help, by extending the section attribute to also allow for templates rather than only fixed names.
Quoted 12 lines
Quoted 7 lines
xen/common/symbols.c const char *symbols_lookup(unsigned long addr, · line 130
Quoted 5 lines
xen/common/symbols.c +1
-0@@ -108,13 +127,17 @@ const char *symbols_lookup(unsigned long addr, {unsigned long i, low, high, mid;unsigned long symbol_end =0 ; +symbols_lookup_t symbol_lookup =NULL ;Pointless initializer.
I believe we need it. That is the contents on the stack can be garbage and the
__is_active_kernel_textwon't updatesymbol_lookupunless it finds a match. Ah, and also the compiler is unhappy:
Quoted 6 lines
symbols.c: In function ‘symbols_lookup’:
symbols.c:136:8: error: ‘symbol_lookup’ may be used uninitialized in this function [-Werror=maybe-uninitialized]if (symbol_lookup) ^cc1: all warnings being treated as errors
That's unfortunate, since ...
Quoted 6 lines
Quoted 6 lines
xen/common/symbols.c const char *symbols_lookup(unsigned long addr, · line 118
Quoted 6 lines
xen/common/symbols.c +1
-1namebuf[KSYM_NAME_LEN ] =0 ; namebuf[0 ] =0 ; -if (!is_active_kernel_text (addr)) +if (!__is_active_kernel_text (addr, &symbol_lookup))return NULL ;
... this return ensures that ...
Quoted 2 lines
Quoted 2 lines
Review const char *symbols_lookup(unsigned long addr, · line 137
Quoted 2 lines
(quoted diff) +2
-0+ if (symbol_lookup) + return (symbol_lookup)(addr, symbolsize, offset, namebuf);
... this won't be reached with symbol_lookup uninitialized.
Quoted 5 lines
Quoted 2 lines
Note that there are few coding style issues here (missing blanks, superfluous parentheses).
That file uses a different StyleGuide. The Linux one. Which reminds me that
__is_active_kernel_textneeds to adhere to different StyleGuide.
Linux style would not be using spaces for indentation. The file is really a bad mixture of styles, but yes, you're right that you don't violate that pre-existing mixture.
Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
xen/include/xen/bug_ex_symbols.h new file +9
-0@@ -0,0 +1,74 @@ +/* +* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. +* +*/ + +#ifndef __BUG_EX_SYMBOL_LIST__ +#define __BUG_EX_SYMBOL_LIST__ + +#include <xen/config.h> Quoted 8 lines
xen/include/xen/bug_ex_symbols.h line 15
Quoted 6 lines
xen/include/xen/bug_ex_symbols.h new file +6
-0+#include <xen/list.h> +#include <xen/symbols.h> + +#ifdef CONFIG_X86 +#include <asm/uaccess.h> +#endif Why?
Quoted 2 lines
Otherwise the compilation will fail on ARM as they do not have exceptions (and no
asm/uaccess.hfile)
Well, the question was for the #include, not the #ifdef.
Quoted 11 lines
xen/common/symbols.c +1
-0@@ -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>
xen/common/symbols.c static unsigned int get_symbol_offset(unsigned long pos) · line 101
Quoted 6 lines
xen/common/symbols.c +1
-2@@ -97,8 +98,7 @@ static unsigned int get_symbol_offset(unsigned long pos)bool_t is_active_kernel_text (unsigned long addr) { -return (is_kernel_text (addr) || - (system_state < SYS_STATE_active &&is_kernel_inittext (addr))); +return !!search_virtual_regions (addr);
search_virtual_regions() doesn't sound like it would be looking for text addresses only.
xen/common/virtual_region.c line 6
Quoted 9 lines
xen/common/virtual_region.c new file +6
-0@@ -0,0 +1,151 @@ +/* +* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. +* +*/ + +#include <xen/config.h>
No new explicit inclusion of xen/config.h please. We're actually in the process of getting rid of such elsewhere.
xen/common/virtual_region.c line 13
Quoted 7 lines
xen/common/virtual_region.c new file +7
-0+#include <xen/init.h> +#include <xen/kernel.h> +#include <xen/rcupdate.h> +#include <xen/spinlock.h> +#include <xen/virtual_region.h> + +static struct virtual_region compiled = {
I think "compiled" is a bad name, as patch modules are equally compiled - "core" or "builtin" perhaps?
xen/common/virtual_region.c line 51
Quoted 1 line
xen/common/virtual_region.c new file +1
-0+struct virtual_region *search_virtual_regions (unsigned long addr)
Misplaced *. And probably should return a pointer to const.
xen/common/virtual_region.c line 55
Quoted 4 lines
xen/common/virtual_region.c new file +4
-0+{ +struct virtual_region *region; + +list_for_each_entry_rcu ( region, &virtual_region_list, list )
Where's the rcu_read_lock() use of which the comment preceding the #define of this mandates?
xen/common/virtual_region.c line 73
Quoted 1 line
xen/common/virtual_region.c new file +1
-0+static void __unregister_virtual_region (struct virtual_region *r)
As I think I have said before - no double underscore prefixes on new identifiers please.
xen/common/virtual_region.c line 86
Quoted 13 lines
xen/common/virtual_region.c new file +13
-0+{ +unsigned long flags; + +spin_lock_irqsave (&virtual_region_lock, flags); +list_del_rcu (&r->list); +spin_unlock_irqrestore (&virtual_region_lock, flags); +/* +* We do not need to invoke call_rcu. +* +* This is due to the fact that on the deletion we have made sure +* to use spinlocks (to guard against somebody else calling +* unregister_virtual_region) and list_deletion spiced with an memory +* barrier - which will flush out the cache lines in other CPUs.
I don't think barriers do any kind of cache flushing on remote CPUs (not even on the local one).
xen/common/virtual_region.c line 113
Quoted 5 lines
xen/common/virtual_region.c new file +5
-0+void __init setup_virtual_regions (void ) +{ +ssize_t sz; +unsigned int i; +static const struct bug_frame *const stop_frames[] = {
This (now sitting in an __init function) should then become __initconstrel.
xen/common/virtual_region.c line 114
Quoted 1 line
xen/common/virtual_region.c new file +1
-0+ __start_bug_frames,
This element makes the array name bogus.
xen/common/virtual_region.c line 124
Quoted 10 lines
xen/common/virtual_region.c new file +10
-0+ __stop_bug_frames_0, + __stop_bug_frames_1, + __stop_bug_frames_2, +#ifdef CONFIG_X86 + __stop_bug_frames_3, +#endif + NULL + }; + +/* N.B. idx != i */
Stale comment?
xen/common/virtual_region.c line 137
Quoted 13 lines
xen/common/virtual_region.c new file +13
-0+for ( i =1 ; stop_frames[i]; i++ ) + { +const struct bug_frame *s; + + s = stop_frames[i-1 ]; + sz = stop_frames[i] - s; + + compiled.frame[i-1 ].n_bugs = sz; + compiled.frame[i-1 ].bugs = s; + + compiled_init.frame[i-1 ].n_bugs = sz; + compiled_init.frame[i-1 ].bugs = s; + }
Many times "[i - 1]" please.
xen/common/virtual_region.c line 140
Quoted 2 lines
xen/common/virtual_region.c new file +2
-0+register_virtual_region (&compiled_init); +register_virtual_region (&compiled);
Is there a particular reason not to do the main region first? Probably it's benign, but if there is a reason, I think a comment would be warranted.
xen/include/xen/symbols.h line 12
Quoted 11 lines
xen/include/xen/symbols.h +5
-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,
Stray parentheses.
xen/include/xen/virtual_region.h line 7
Quoted 10 lines
xen/include/xen/virtual_region.h new file +7
-0@@ -0,0 +1,56 @@ +/* +* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. +* +*/ + +#ifndef __BUG_EX_SYMBOL_LIST__ +#define __BUG_EX_SYMBOL_LIST__
No longer in line with the header name, and missing a XEN_ portion.
xen/include/xen/virtual_region.h line 26
Quoted 9 lines
xen/include/xen/virtual_region.h new file +9
-0+struct virtual_region +{ +struct list_head list; +unsigned long start;/* Virtual address start. */ +unsigned long end;/* Virtual address start. */ + +/* +* If this is NULL the default lookup mechanism is used. +*/
Here or elsewhere I'm sure I've made the comment before: This is a single line comment.
xen/include/xen/virtual_region.h line 37
Quoted 12 lines
xen/include/xen/virtual_region.h new file +4
-0+symbols_lookup_t *symbols_lookup; + +struct { +const struct bug_frame *bugs;/* The pointer to array of bug frames. */
xen/include/xen/virtual_region.h new file +7
-0+ssize_t n_bugs;/* The number of them. */ + } frame[BUGFRAME_NR ]; + +#ifdef CONFIG_X86 +struct exception_table_entry *ex; +struct exception_table_entry *ex_end; +#endif
Would there be any harm omitting the #ifdef and leaving the pointers be NULL on ARM?
xen/include/xen/virtual_region.h line 44
Quoted 5 lines
xen/include/xen/virtual_region.h new file +5
-0+extern struct virtual_region *search_virtual_regions (unsigned long addr); +extern void setup_virtual_regions (void ); +extern void unregister_init_virtual_region (void ); +extern int register_virtual_region (struct virtual_region *r); +extern void unregister_virtual_region (struct virtual_region *r);
While a matter of taste, I personally would prefer if "extern" was omitted on function declarations.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 07/34] arm/x86: Use struct virtual_region to do bug, symbol, and (x86) exception tables
Hi Jan,
Quoted 16 lines · Jan Beulich
xen/include/xen/virtual_region.h line 37
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 22.03.16 at 21:18, <[email protected]> wrote:
xen/include/xen/virtual_region.h new file +4
-0+symbols_lookup_t *symbols_lookup; + +struct { +const struct bug_frame *bugs;/* The pointer to array of bug frames. */
xen/include/xen/virtual_region.h new file +7
-0+ssize_t n_bugs;/* The number of them. */ + } frame[BUGFRAME_NR ]; + +#ifdef CONFIG_X86 +struct exception_table_entry *ex; +struct exception_table_entry *ex_end; +#endif Would there be any harm omitting the #ifdef and leaving the pointers be NULL on ARM?
The structure exception_table_entry is only defined for x86 (asm-x86/uaccess.h).
Regards,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v4 07/34] arm/x86: Use struct virtual_region to do bug, symbol, and (x86) exception tables
Quoted 21 lines
Quoted 1 line
Quoted 1 line · On 23.03.16 at 12:17, <[email protected]> wrote:
Hi Jan,
Quoted 16 lines · Jan Beulich
xen/include/xen/virtual_region.h line 37
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 22.03.16 at 21:18, <[email protected]> wrote:
xen/include/xen/virtual_region.h new file +4
-0+symbols_lookup_t *symbols_lookup; + +struct { +const struct bug_frame *bugs;/* The pointer to array of bug frames. */
xen/include/xen/virtual_region.h new file +7
-0+ssize_t n_bugs;/* The number of them. */ + } frame[BUGFRAME_NR ]; + +#ifdef CONFIG_X86 +struct exception_table_entry *ex; +struct exception_table_entry *ex_end; +#endif Would there be any harm omitting the #ifdef and leaving the pointers be NULL on ARM?
Quoted 2 lines
The structure
exception_table_entryis only defined for x86 (asm-x86/uaccess.h).
But the uses above are fine without the structure ever getting defined.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 07/34] arm/x86: Use struct virtual_region to do bug, symbol, and (x86) exception tables
In reply to Jan BeulichQuoted 10 lines
Quoted 8 lines
Quoted 5 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+#ifdef CONFIG_X86 +#include <asm/uaccess.h> +#endifWhy?
Otherwise the compilation will fail on ARM as they do not have exceptions (and no
asm/uaccess.hfile)Well, the question was for the #include, not the #ifdef.
Ah, yes. And with the 'ex' being pointers it matters no.
Quoted 13 lines
Quoted 13 lines
xen/common/symbols.c +1
-0@@ -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)
Quoted 8 lines
xen/common/symbols.c static unsigned int get_symbol_offset(unsigned long pos) · line 101
Quoted 5 lines
xen/common/symbols.c +1
-2bool_t is_active_kernel_text (unsigned long addr) { -return (is_kernel_text (addr) || - (system_state < SYS_STATE_active &&is_kernel_inittext (addr))); +return !!search_virtual_regions (addr);
search_virtual_regions()doesn't sound like it would be looking for text addresses only.
I am not sure what would be a better name - as it (search_virtual_regions) is used by three other callers?
search_for_addr?
.. snip..
Quoted 18 lines
Quoted 5 lines
xen/common/symbols.c +4
-0+static void __unregister_virtual_region (struct virtual_region *r) +{ +unsigned long flags; +xen/common/symbols.c static unsigned int get_symbol_offset(unsigned long pos)
Quoted 10 lines
xen/common/symbols.c +10
-0+spin_lock_irqsave (&virtual_region_lock, flags); +list_del_rcu (&r->list); +spin_unlock_irqrestore (&virtual_region_lock, flags); +/* +* We do not need to invoke call_rcu. +* +* This is due to the fact that on the deletion we have made sure +* to use spinlocks (to guard against somebody else calling +* unregister_virtual_region) and list_deletion spiced with an memory +* barrier - which will flush out the cache lines in other CPUs. I don't think barriers do any kind of cache flushing on remote CPUs (not even on the local one).
I am not sure what I had been thinking. The only thing it does is a memory barrier.
.. snip..
I believe I've addressed the review comments you had:
From 4a2690ba815db7edd5fe075c8d7e9e2ac62a0020 Mon Sep 17 00:00:00 2001
From: Konrad Rzeszutek Wilk <[email protected]>
Date: Thu, 10 Mar 2016 16:35:50 -0500
Subject: [PATCH] arm/x86: Use struct virtual_region to do bug, symbol, and
(x86) exception tables lookup.
During execution of the hypervisor we have two regions of executable code - stext -> _etext, and _sinittext -> _einitext.
The later is not needed after bootup.
We also have various built-in macros and functions to search in between those two swaths depending on the state of the system.
That is either for bug_frames, exceptions (x86) or symbol names for the instruction.
With xSplice in the picture - we need a mechansim for new payloads to searched as well for all of this.
Originally we had extra 'if (xsplice)...' but that gets a bit tiring and does not hook up nicely.
This 'struct virtual_region' and virtual_region_list provide a mechanism to search for the bug_frames, exception table, and symbol names entries without having various calls in other sub-components in the system.
Code which wishes to participate in bug_frames and exception table entries search has to only use two public APIs:
- register_virtual_region
- unregister_virtual_region
to let the core code know.
If the ->lookup_symbol is not then the default internal symbol lookup mechanism is used.
---
Cc: Stefano Stabellini <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
v4: New patch.
v5:
- Rename to virtual_region.
- Ditch the 'skip' function.
- Remove the _stext.
- Use RCU lists.
- Add a search function.
- Remove extern, add rcu_read_lock. remove __ from name.
---
--- xen/arch/arm/setup.c | 4 + xen/arch/arm/traps.c | 39 ++++++---- xen/arch/x86/extable.c | 12 ++- xen/arch/x86/setup.c | 6 ++ xen/arch/x86/traps.c | 40 ++++++---- xen/common/Makefile | 1 + xen/common/symbols.c | 11 ++- xen/common/virtual_region.c | 160 +++++++++++++++++++++++++++++++++++++++ xen/include/xen/symbols.h | 9 +++ xen/include/xen/virtual_region.h | 48 ++++++++++++ 10 files changed, 293 insertions(+), 37 deletions(-) create mode 100644 xen/common/virtual_region.c create mode 100644 xen/include/xen/virtual_region.h
xen/arch/arm/setup.c +4 -0
@@ -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 (); +/* Setup Hyp vector base */ WRITE_SYSREG ((vaddr_t )hyp_traps_vector,VBAR_EL2 );
@@ -1077,27 +1080,33 @@ void do_unexpected_trap(const char *msg, struct cpu_user_regs *regs)int do_bug_frame (struct cpu_user_regs *regs,vaddr_t pc) { -const struct bug_frame *bug; +const struct bug_frame *bug =NULL ;const char *prefix ="" , *filename, *predicate;unsigned long fixup; -int id, lineno; -static const struct bug_frame *const stop_frames[] = { - __stop_bug_frames_0, - __stop_bug_frames_1, - __stop_bug_frames_2, -NULL - }; +int id =-1 , lineno; +struct virtual_region *region; -for ( bug = __start_bug_frames, id =0 ; stop_frames[id]; ++bug ) + region =search_for_addr (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); +struct virtual_region *region =search_for_addr (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 (); +/* 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; +struct virtual_region *region;DEBUGGER_trap_entry (TRAP_invalid_op, regs);
@@ -1160,16 +1155,29 @@ void do_invalid_op(struct cpu_user_regs *regs) memcmp(bug_insn, "\xf\xb", sizeof(bug_insn)) ) goto die; -for ( bug = __start_bug_frames, id =0 ; stop_frames[id]; ++bug ) + region =search_for_addr (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 !!search_for_addr (addr); } const char *symbols_lookup(unsigned long addr,
@@ -108,13 +108,18 @@ const char *symbols_lookup(unsigned long addr, {unsigned long i, low, high, mid;unsigned long symbol_end =0 ; +struct virtual_region *region; namebuf[KSYM_NAME_LEN ] =0 ; namebuf[0 ] =0 ; -if (!is_active_kernel_text (addr)) + region =search_for_addr (addr); +if (!region)return NULL ; +if (region->symbols_lookup) +return region->symbols_lookup (addr, symbolsize, offset, namebuf); +/* do a binary search on the sorted symbols_addresses array */ low =0 ; high = symbols_num_syms;
xen/common/virtual_region.c new file +160 -0
160 lines not on this page · raw message
xen/include/xen/symbols.h +9 -0
@@ -5,6 +5,15 @@#define KSYM_NAME_LEN 127 +/* +* Typedef for the callback functions that symbols_lookup +* can call if virtual_region_list has an callback for it. +*/ +typedef const char *symbols_lookup_t (unsigned long addr, +unsigned long *symbolsize, +unsigned long *offset, +char *namebuf); +/* Lookup an address. */ const char *symbols_lookup(unsigned long addr, unsigned long *symbolsize,
xen/include/xen/virtual_region.h new file +48 -0
48 lines not on this page · raw message
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v4 07/34] arm/x86: Use struct virtual_region to do bug, symbol, and (x86) exception tables
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines · On 24.03.16 at 03:49, <[email protected]> wrote:
xen/common/symbols.c +1
-0@@ -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)Quoted 8 lines
xen/common/symbols.c static unsigned int get_symbol_offset(unsigned long pos)
Quoted 5 lines
xen/common/symbols.c +1
-2bool_t is_active_kernel_text (unsigned long addr) { -return (is_kernel_text (addr) || - (system_state < SYS_STATE_active &&is_kernel_inittext (addr))); +return !!search_virtual_regions (addr);
search_virtual_regions()doesn't sound like it would be looking for text addresses only.
Quoted 4 lines
I am not sure what would be a better name - as it (
search_virtual_regions) is used by three other callers?
search_for_addr?
How would that make clear that you're after .text addresses only? Part of the problem of course is that only .text regions get registered, yet the function names all don't reflect this. Perhaps generally s/virtual/text/ ?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v4 8/34 vmap: Make the while loop less fishy.
In reply to Konrad Rzeszutek WilkIt looks like it could underflow at first glance. That is if i is zero and you get in the while loop with the i--. However the postfix expression is evaluated after the conditional so the loop is fine and won't execute (with i==0).
However in spirit of defense programming lets clarify the loop conditional.
---
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Tim Deegan <[email protected]>
---
--- xen/common/vmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
xen/common/vmap.c +2 -2
@@ -246,8 +246,8 @@ void *vmalloc(size_t size)return va; error: -while ( i-- ) -free_domheap_page (mfn_to_page (mfn_x (mfn[i]))); +while ( i ) +free_domheap_page (mfn_to_page (mfn_x (mfn[--i])));xfree (mfn);return NULL ; }
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v4 08/34] vmap: Make the while loop less fishy.
Quoted 9 lines · Konrad Rzeszutek Wilk
It looks like it could underflow at first glance. That is if i is zero and you get in the while loop with the i--. However the postfix expression is evaluated after the conditional so the loop is fine and won't execute (with i==0).
However in spirit of defense programming lets clarify the loop conditional.
Signed-off-by Konrad Rzeszutek Wilk <[email protected]>
This looks as if it will quieten Coverity, even though it is no functional change.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 08/34] vmap: Make the while loop less fishy.
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 15.03.16 at 20:33, <[email protected]> wrote:
Quoted 8 lines · Konrad Rzeszutek Wilk
It looks like it could underflow at first glance. That is if i is zero and you get in the while loop with the i--. However the postfix expression is evaluated after the conditional so the loop is fine and won't execute (with i==0).
However in spirit of defense programming lets clarify the loop conditional.
Quoted 6 lines
Quoted 1 line
Signed-off-by Konrad Rzeszutek Wilk <[email protected]>Reviewed-by Andrew Cooper <[email protected]>This looks as if it will quieten Coverity, even though it is no functional change.
Quieten Coverity? In what way? And why would it complain in the first place? As just in reply to Konrad, this is well defined behavior.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 08/34] vmap: Make the while loop less fishy.
Quoted 10 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 15.03.16 at 20:33, <[email protected]> wrote:
Quoted 8 lines · Konrad Rzeszutek Wilk
It looks like it could underflow at first glance. That is if i is zero and you get in the while loop with the i--. However the postfix expression is evaluated after the conditional so the loop is fine and won't execute (with i==0).
However in spirit of defense programming lets clarify the loop conditional.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Konrad Rzeszutek Wilk <[email protected]>Reviewed-by Andrew Cooper <[email protected]>This looks as if it will quieten Coverity, even though it is no functional change.
Quieten Coverity? In what way? And why would it complain in the first place? As just in reply to Konrad, this is well defined behavior.
213 error:
CID 63648: Overflowed constant (INTEGER_OVERFLOW)
7. overflow_const: Decrement (--) operation overflows on operand
i, whose value is an unsigned constant, 0.
214 while ( i-- )
215 free_domheap_page(mfn_to_page(mfn_x(mfn[i])));
216 xfree(mfn);
217 return NULL;
By flipping the location of the postfix decrement, the problematic case of getting to error: with i as 0 will not enter the loop, and won't decrement i to UINT32_MAX.
It is arguable as to whether this is a Coverity bug or not. Unsigned integer overflow is defined under the C spec. On the other hand, I really don't blame Coverity for raising an issue here saying "did you really mean for this underflow to happen".
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 08/34] vmap: Make the while loop less fishy.
Quoted 30 lines
Quoted 1 line
Quoted 1 line · On 17.03.16 at 15:37, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 15.03.16 at 20:33, <[email protected]> wrote:
Quoted 8 lines · Konrad Rzeszutek Wilk
It looks like it could underflow at first glance. That is if i is zero and you get in the while loop with the i--. However the postfix expression is evaluated after the conditional so the loop is fine and won't execute (with i==0).
However in spirit of defense programming lets clarify the loop conditional.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Konrad Rzeszutek Wilk <[email protected]>Reviewed-by Andrew Cooper <[email protected]>This looks as if it will quieten Coverity, even though it is no functional change.
Quieten Coverity? In what way? And why would it complain in the first place? As just in reply to Konrad, this is well defined behavior.
213 error:
CID 63648: Overflowed constant (INTEGER_OVERFLOW)
7.overflow_const: Decrement (--) operation overflows on operand
i, whose value is an unsigned constant, 0.
214 while ( i-- )
215 free_domheap_page(mfn_to_page(mfn_x(mfn[i])));
216 xfree(mfn);
217 return NULL;
Quoted 3 lines
By flipping the location of the postfix decrement, the problematic case of getting to error: with i as 0 will not enter the loop, and won't decrement i to
UINT32_MAX.
But (as alluded to before) this is a pretty common cleanup pattern, and I really don't see us (a) fix all instances just because Coverity complains and (b) avoid introducing any new instances.
Quoted 4 lines
It is arguable as to whether this is a Coverity bug or not. Unsigned integer overflow is defined under the C spec. On the other hand, I really don't blame Coverity for raising an issue here saying "did you really mean for this underflow to happen".
Since this is defined behavior, I personally view it as a Coverity issue. Which is not to say that such a warning may not help some people in certain cases.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 08/34] vmap: Make the while loop less fishy.
Jan Beulich writes ("Re: [Xen-devel] [PATCH v4 08/34] vmap: Make the while loop less fishy."):
Quoted 10 lines · On 17.03.16 at 15:37, <[email protected]> wrote:
Quoted 9 lines
213 error:
CID 63648: Overflowed constant (INTEGER_OVERFLOW)
7.overflow_const: Decrement (--) operation overflows on operand
i, whose value is an unsigned constant, 0.
214 while ( i-- )
215 free_domheap_page(mfn_to_page(mfn_x(mfn[i])));
216 xfree(mfn);
217 return NULL;
Quoted 7 lines
Quoted 3 lines
By flipping the location of the postfix decrement, the problematic case of getting to error: with i as 0 will not enter the loop, and won't decrement i to
UINT32_MAX.But (as alluded to before) this is a pretty common cleanup pattern, and I really don't see us (a) fix all instances just because Coverity complains and (b) avoid introducing any new instances.
I'm inclined to agree.
Quoted 8 lines
Quoted 4 lines
It is arguable as to whether this is a Coverity bug or not. Unsigned integer overflow is defined under the C spec. On the other hand, I really don't blame Coverity for raising an issue here saying "did you really mean for this underflow to happen".
Since this is defined behavior, I personally view it as a Coverity issue. Which is not to say that such a warning may not help some people in certain cases.
I think this should be marked as a false positive in Coverity.
Coverity ought to be re-educated so that it can see that:
* The decrement result is defined as ~(unsigned)0
* So there is no UB at this stage
* ~0 will be written to i, which is potentially hazardous
* But this is a dead store so in fact it is harmless
The problem is that Coverity is failing to distinguish this from cases where an unsigned value is decreased and wraps, and then _the resulting value with huge magnitude is used_.
These latter situations are often serious security bugs. But if the huge value is never used there is clearly no bug.
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 08/34] vmap: Make the while loop less fishy.
In reply to Konrad Rzeszutek WilkQuoted 5 lines
Quoted 1 line
Quoted 1 line · On 15.03.16 at 18:56, <[email protected]> wrote:
It looks like it could underflow at first glance. That is if i is zero and you get in the while loop with the i--. However the postfix expression is evaluated after the conditional so the loop is fine and won't execute (with i==0).
I don't think this is the only place we do such, and with this being well defined behavior I also don't see why we need to change any of such uses.
(And btw., what does this have to do with the already large xSplice series?)
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 08/34] vmap: Make the while loop less fishy.
In reply to Konrad Rzeszutek WilkKonrad Rzeszutek Wilk writes ("[PATCH v4 08/34] vmap: Make the while loop less fishy."):
xen/common/vmap.c void *vmalloc(size_t size) · line 250
Quoted 5 lines
error:
xen/common/vmap.c +2
-2-while ( i-- ) -free_domheap_page (mfn_to_page (mfn_x (mfn[i]))); +while ( i ) +free_domheap_page (mfn_to_page (mfn_x (mfn[--i])));
I quite strongly dislike this. It is good practice to keep the loop control code together where this is reasonably convenient.
I wouldn't quibble on such a stylistic matter (particularly outside my bailiwick) but (a) I would like to reinforce Jan's position and
(b) it seems worth writing an email as there will be many occurrences.
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 08/34] vmap: Make the while loop less fishy.
Quoted 7 lines · Ian Jackson
Konrad Rzeszutek Wilk writes ("[PATCH v4 08/34] vmap: Make the while loop less fishy."):
xen/common/vmap.c void *vmalloc(size_t size) · line 250
Quoted 5 lines
error:
xen/common/vmap.c +2
-2-while ( i-- ) -free_domheap_page (mfn_to_page (mfn_x (mfn[i]))); +while ( i ) +free_domheap_page (mfn_to_page (mfn_x (mfn[--i])));
Quoted 6 lines
I quite strongly dislike this. It is good practice to keep the loop control code together where this is reasonably convenient.
I wouldn't quibble on such a stylistic matter (particularly outside my bailiwick) but (a) I would like to reinforce Jan's position and
(b) it seems worth writing an email as there will be many occurrences.
Since we're taking about general principle (and I've been referred to here from a similar discussion elsewhere [1]), let me weigh in as well.
I can see the point of not wanting the decrement to be in the middle of the expression here. But I also entirely agree with Konrad's assessment that this code is likely to be confusing; and the fact that a computer program following a list of rules *developed by professional bug-finders* is confused by this kind of semantics I think supports this assessment. At very least it has the potential to waste a lot of mental energy figuring out why code that looks wrong isn't wrong; and at worst there's a risk that at some point someone will "fix" it incorrectly.
The fact that there are already many instances of this pattern in the source tree would be relevant if we expect nobody but people currently familiar with the code to every try to read or modify it. But since on the contrary we hope that others will contribute to the codebase, and even that they may eventually become maintainers, I think there is sense in addressing them, at least as they come up.
In my case I've suggested adding a comment to clue people into the fact that the postfix semantics are in operation; I think that balances "reducing cognitive load" with "avoids unnecessarily verbose code".
Other options would be things like this:
do {
i--;
[cleanup]
} while ( i > 0 );
or
while ( i > 0 ) {
i--;
[cleanup]
}
The first one I think is the clearest, but neither one are very concise.
-George
[1] marc.info/?i=<[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 08/34] vmap: Make the while loop less fishy.
Quoted 30 lines
Quoted 1 line
Quoted 1 line · On 21.03.16 at 13:04, <[email protected]> wrote:
Quoted 7 lines · Ian Jackson
Konrad Rzeszutek Wilk writes ("[PATCH v4 08/34] vmap: Make the while loop less fishy."):
xen/common/vmap.c void *vmalloc(size_t size) · line 250
Quoted 5 lines
error:
xen/common/vmap.c +2
-2-while ( i-- ) -free_domheap_page (mfn_to_page (mfn_x (mfn[i]))); +while ( i ) +free_domheap_page (mfn_to_page (mfn_x (mfn[--i])));Quoted 6 lines
I quite strongly dislike this. It is good practice to keep the loop control code together where this is reasonably convenient.
I wouldn't quibble on such a stylistic matter (particularly outside my bailiwick) but (a) I would like to reinforce Jan's position and
(b) it seems worth writing an email as there will be many occurrences.Since we're taking about general principle (and I've been referred to here from a similar discussion elsewhere [1]), let me weigh in as well.
I can see the point of not wanting the decrement to be in the middle of the expression here. But I also entirely agree with Konrad's assessment that this code is likely to be confusing; and the fact that a computer program following a list of rules *developed by professional bug-finders* is confused by this kind of semantics I think supports this assessment. At very least it has the potential to waste a lot of mental energy figuring out why code that looks wrong isn't wrong; and at worst there's a risk that at some point someone will "fix" it incorrectly.
Quoted 6 lines
The fact that there are already many instances of this pattern in the source tree would be relevant if we expect nobody but people currently familiar with the code to every try to read or modify it. But since on the contrary we hope that others will contribute to the codebase, and even that they may eventually become maintainers, I think there is sense in addressing them, at least as they come up.
Well, if talk was about something really complex here, I might agree. But unary prefix and postfix operators are an integral part of the C language, and while code reading indeed shouldn't require overly much mental energy, I think we should be permitted to make full knowledge of the base programming language a prereq to reading our code. Otherwise - where do you want to draw the boundary of what is permitted and what is not? (Yes, I know I'm guilty in occasionally writing rather complex expressions, with at times not immediately obvious side effects, and I'm trying to do better irrespective of all such also falling in the above "basic language" features category. That's because I can see doing so being past the boundary of reasonably understandable code.)
Quoted 12 lines
In my case I've suggested adding a comment to clue people into the fact that the postfix semantics are in operation; I think that balances "reducing cognitive load" with "avoids unnecessarily verbose code".
Other options would be things like this:
do {
i--;
[cleanup]
} while ( i > 0 );
Quoted 8 lines
or
while ( i > 0 ) {
i--;
[cleanup]
}The first one I think is the clearest, but neither one are very concise.
But you realize that the first (but not the second) one is wrong for the i == 0 case?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 08/34] vmap: Make the while loop less fishy.
Quoted 37 lines · Jan Beulich
Quoted 30 lines
Quoted 1 line
Quoted 1 line · On 21.03.16 at 13:04, <[email protected]> wrote:
Quoted 7 lines · Ian Jackson
Konrad Rzeszutek Wilk writes ("[PATCH v4 08/34] vmap: Make the while loop less fishy."):
xen/common/vmap.c void *vmalloc(size_t size) · line 250
Quoted 5 lines
error:
xen/common/vmap.c +2
-2-while ( i-- ) -free_domheap_page (mfn_to_page (mfn_x (mfn[i]))); +while ( i ) +free_domheap_page (mfn_to_page (mfn_x (mfn[--i])));Quoted 6 lines
I quite strongly dislike this. It is good practice to keep the loop control code together where this is reasonably convenient.
I wouldn't quibble on such a stylistic matter (particularly outside my bailiwick) but (a) I would like to reinforce Jan's position and
(b) it seems worth writing an email as there will be many occurrences.Since we're taking about general principle (and I've been referred to here from a similar discussion elsewhere [1]), let me weigh in as well.
I can see the point of not wanting the decrement to be in the middle of the expression here. But I also entirely agree with Konrad's assessment that this code is likely to be confusing; and the fact that a computer program following a list of rules *developed by professional bug-finders* is confused by this kind of semantics I think supports this assessment. At very least it has the potential to waste a lot of mental energy figuring out why code that looks wrong isn't wrong; and at worst there's a risk that at some point someone will "fix" it incorrectly.
Quoted 6 lines
The fact that there are already many instances of this pattern in the source tree would be relevant if we expect nobody but people currently familiar with the code to every try to read or modify it. But since on the contrary we hope that others will contribute to the codebase, and even that they may eventually become maintainers, I think there is sense in addressing them, at least as they come up.
Quoted 13 lines
Well, if talk was about something really complex here, I might agree. But unary prefix and postfix operators are an integral part of the C language, and while code reading indeed shouldn't require overly much mental energy, I think we should be permitted to make full knowledge of the base programming language a prereq to reading our code. Otherwise - where do you want to draw the boundary of what is permitted and what is not? (Yes, I know I'm guilty in occasionally writing rather complex expressions, with at times not immediately obvious side effects, and I'm trying to do better irrespective of all such also falling in the above "basic language" features category. That's because I can see doing so being past the boundary of reasonably understandable code.)
And I'm not saying that we can't take advantage of postfix operators in this case; I'm just saying that if we are going to, it would be better to point it out in a comment.
There are lots of "features" of C that standard practice still demands that we add a comment for; the default fall-through for switch statements comes to mind. Of course programmers should be required to know that switch statements default to fallthrough in C; but it's still a common mistake to forget that, and so we point them in the right direction by adding comments.
Similarly, of course programmers should know the difference between prefix and postfix operators. But this is a case where there's a risk of tripping over something, so it makes sense to point them in the right direction by adding comments.
Or to take a different tack: I understand that you don't think there's no particular benefit to adding a comment in cases like this; could you explain to me why you think it would have a significant cost?
Quoted 8 lines
Quoted 5 lines
do {
i--;
[cleanup]
} while ( i > 0 );But you realize that the first (but not the second) one is wrong for the i == 0 case?
So it is. I think I was thinking of a case where it was known that at least one iteration had succeeded; but obviously the second is more safe in general.
-George
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 08/34] vmap: Make the while loop less fishy.
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 21.03.16 at 15:22, <[email protected]> wrote:
Or to take a different tack: I understand that you don't think there's no particular benefit to adding a comment in cases like this; could you explain to me why you think it would have a significant cost?
There's no significant cost here. Yet I do think that commenting the obvious is not really helpful (or else we end up with more comments than there is actual code; some may consider this a good thing, but I'm of the opinion that this would only serve obfuscating the code). Plus - as said in various other contexts - I'm in favor of consistency, i.e. I would think that if these constructs warrant a comment, all of them should get one. The fall through example you gave for switch statements is actually a good one: There the comments silence Coverity. If comments here had the same effect, I think I'd have no reservations against adding such, yet I don't think they do.
In the end it boils down to: I'm not going to ack any such change myself, but I'm also not going to stand in the way of other maintainers ack-ing such comments getting added. What I would object to though is calling such constructs "fishy" in commit titles, commit messages, or the comments being added.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v4 9/34 vmap: ASSERT on NULL.
In reply to Konrad Rzeszutek WilkThe vmap_to_page macro (three levels deep!) can come up with a NULL pointer. Lets add the proper ASSERT to catch this errant behavior.
---
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Tim Deegan <[email protected]>
---
--- xen/common/vmap.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
xen/common/vmap.c +5 -1
@@ -279,8 +279,12 @@ void vfree(void *va)ASSERT (pages);for ( i =0 ; i < pages; i++ ) -page_list_add (vmap_to_page (va + i *PAGE_SIZE ), &pg_list); + { +struct page_info *page =vmap_to_page (va + i *PAGE_SIZE ); +ASSERT (page); +page_list_add (page, &pg_list); + }vunmap (va);while ( (pg =page_list_remove_head (&pg_list)) !=NULL )
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH v4 10/34 vmap: Add vmalloc_cb and vfree_cb
In reply to Konrad Rzeszutek WilkFor those users who want to supply their own vmap callback. To be called _after_ the pages have been allocated and the vmap API is ready to hand out virtual addresses.
Instead of using the vmap ones it can call the callback which will be responsible for generating the virtual address.
This allows users (such as xSplice) to provide their own mechanism to set the page flags.
The users (such as patch titled "xsplice: Implement payload loading") can wrap the calls to __vmap to accomplish this.
We also provide a mechanism for the calleer to squirrel the MFN array in case they want to modify the virtual addresses easily.
We also provide the free-ing code path - to use the vunmap_cb to take care of tearing down the virtual addresses.
---
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Keir Fraser <[email protected]>
Cc: Tim Deegan <[email protected]>
---
--- xen/common/vmap.c | 35 ++++++++++++++++++++++++++++------- xen/include/xen/vmap.h | 14 ++++++++++++++ 2 files changed, 42 insertions(+), 7 deletions(-)
xen/common/vmap.c +28 -7
@@ -216,7 +216,7 @@ void vunmap(const void *va)vm_free (va); } -void *vmalloc (size_t size) +void *vmalloc_cb (size_t size,vmap_cb_t vmap_cb,mfn_t **mfn_array) {mfn_t *mfn;size_t pages, i;
@@ -238,11 +238,15 @@ void *vmalloc(size_t size) mfn[i] =_mfn (page_to_mfn (pg)); } - va =vmap (mfn, pages); + va = vmap_cb ? (vmap_cb)(mfn, pages) :vmap (mfn, pages);if ( va ==NULL ) goto error; -xfree (mfn); +if ( mfn_array ) + *mfn_array = mfn; +else +xfree (mfn); +return va; error:
@@ -252,6 +256,11 @@ void *vmalloc(size_t size)return NULL ; } +void *vmalloc (size_t size) +{ +return vmalloc_cb (size,NULL ,NULL ); +} +void *vzalloc (size_t size) {void *p =vmalloc (size);
@@ -266,7 +275,7 @@ void *vzalloc(size_t size)return p; } -void vfree (void *va) +void vfree_cb (void *va,unsigned int nr_pages,vfree_cb_t vfree_cb_fnc) {unsigned int i, pages;struct page_info *pg;
@@ -275,8 +284,12 @@ void vfree(void *va)if ( !va )return ; - pages =vm_size (va); -ASSERT (pages); +if ( !vfree_cb_fnc ) + { + pages =vm_size (va); +ASSERT (pages); + }else + pages = nr_pages;for ( i =0 ; i < pages; i++ ) {
@@ -285,9 +298,17 @@ void vfree(void *va)ASSERT (page); page_list_add(page, &pg_list); } -vunmap (va); +if ( !vfree_cb_fnc ) +vunmap (va); +else +vfree_cb_fnc (va, nr_pages);while ( (pg =page_list_remove_head (&pg_list)) !=NULL )free_domheap_page (pg); } + +void vfree (void *va) +{ +vfree_cb (va,0 ,NULL ); +}#endif
xen/include/xen/vmap.h +14 -0
@@ -12,9 +12,23 @@ void *__vmap(const mfn_t *mfn, unsigned int granularity,void *vmap (const mfn_t *mfn,unsigned int nr);void vunmap (const void *);void *vmalloc (size_t size); + +/* +* Callback for vmalloc_cb to use when vmap-ing. +*/ +typedef void *(*vmap_cb_t )(const mfn_t *mfn,unsigned int pages); +void *vmalloc_cb (size_t size,vmap_cb_t vmap_cb,mfn_t **); +void *vzalloc (size_t size);void vfree (void *va); +/* +* Callback for vfree to use an equivalent of vmap_cb_t +* when tearing down. +*/ +typedef void (*vfree_cb_t )(void *va,unsigned int pages); +void vfree_cb (void *va,unsigned int pages,vfree_cb_t vfree_cb_fnc); +void __iomem *ioremap (paddr_t ,size_t );static inline void iounmap (void __iomem *va)
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v4 10/34] vmap: Add vmalloc_cb and vfree_cb
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 15.03.16 at 18:56, <[email protected]> wrote:
For those users who want to supply their own vmap callback. To be called _after_ the pages have been allocated and the vmap API is ready to hand out virtual addresses.
Instead of using the vmap ones it can call the callback which will be responsible for generating the virtual address.
This allows users (such as xSplice) to provide their own mechanism to set the page flags.
The users (such as patch titled "xsplice: Implement payload loading") can wrap the calls to__vmapto accomplish this.
Quoted 8 lines
We also provide a mechanism for the calleer to squirrel the MFN array in case they want to modify the virtual addresses easily.
We also provide the free-ing code path - to use the
vunmap_cbto take care of tearing down the virtual addresses.Signed-off-by Konrad Rzeszutek Wilk <[email protected]>
To be honest, looking at this alone I'm not convinced. But I'll make my final opinion dependent on seeing the actual use. Nevertheless a few comments right away.
xen/common/vmap.c void *vmalloc(size_t size) · line 241
Quoted 6 lines
xen/common/vmap.c +1
-1@@ -238,11 +238,15 @@ void *vmalloc(size_t size) mfn[i] =_mfn (page_to_mfn (pg)); } - va =vmap (mfn, pages); + va = vmap_cb ? (vmap_cb)(mfn, pages) :vmap (mfn, pages);
Stray parentheses.
Quoted 10 lines
xen/common/vmap.c +1
-1@@ -266,7 +275,7 @@ void *vzalloc(size_t size)return p; } -void vfree (void *va) +void vfree_cb (void *va,unsigned int nr_pages,vfree_cb_t vfree_cb_fnc) {unsigned int i, pages;struct page_info *pg;
xen/common/vmap.c void vfree(void *va) · line 291
Quoted 10 lines
xen/common/vmap.c +5
-2@@ -275,8 +284,12 @@ void vfree(void *va)if ( !va )return ; - pages =vm_size (va); -ASSERT (pages); +if ( !vfree_cb_fnc ) + { + pages =vm_size (va); +ASSERT (pages); + }else
Coding style.
xen/common/vmap.c void vfree(void *va) · line 292
Quoted 1 line
xen/common/vmap.c +1
-0+ pages = nr_pages;
So this "caller provides size" worries me in particular, the more that this doesn't mirror anything the allocation side does. And if this indeed is needed for usablity - why two variables with the same purpose but different names (nr_pages and pages)?
xen/include/xen/vmap.h void *__vmap(const mfn_t *mfn, unsigned int granularity, · line 20
Quoted 12 lines
xen/include/xen/vmap.h +6
-0@@ -12,9 +12,23 @@ void *__vmap(const mfn_t *mfn, unsigned int granularity,void *vmap (const mfn_t *mfn,unsigned int nr);void vunmap (const void *);void *vmalloc (size_t size); + +/* +* Callback for vmalloc_cb to use when vmap-ing. +*/ +typedef void *(*vmap_cb_t )(const mfn_t *mfn,unsigned int pages); +void *vmalloc_cb (size_t size,vmap_cb_t vmap_cb,mfn_t **);
I think it is generally better to typedef such to be functions, not pointers to functions, as that allows function declarations to be made using the typedef (which in turn avoids having to touch those declarations when the typedef changes).
xen/include/xen/vmap.h void *__vmap(const mfn_t *mfn, unsigned int granularity, · line 20
Quoted 1 line
xen/include/xen/vmap.h +1
-0+void *vmalloc_cb (size_t size,vmap_cb_t vmap_cb,mfn_t **);
Doing so then also makes more obvious in such declarations that the respective parameter is a pointer.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v4 11/34 xsplice: Design document
In reply to Konrad Rzeszutek WilkA 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.
v4: Add const on some structures. Truncate size to uint16_t where it makes sense.
v5: Convert 'id' to 'name', Add Ross's comments about what is implemented.
v6: Wei's and Ross's reviews.
v7: Jan's review comments.
v8: 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.
v9: Drop the LOADED->CHECKED state and go directly to CHECKED state. Drop
LOADED.
--- docs/misc/xsplice.markdown | 1027 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1027 insertions(+) create mode 100644 docs/misc/xsplice.markdown
docs/misc/xsplice.markdown new file +1027 -0
@@ -0,0 +1,1027 @@ +# 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; + Elf64_Xword new_addr; + Elf64_Xword old_addr; + Elf64_Word new_size; + Elf64_Word old_size; + uint8_t pad[32]; +}; +</pre> + +The size of the structure is 64 bytes. + +* `name` is the symbol name of the old function. Only used if `old_addr` is + zero, otherwise will be used during dynamic linking (when hypervisor loads + the payload). + +* `old_addr` is the address of the function to be patched and is filled in at + payload generation time if hypervisor function address is known. If unknown, + the value *MUST* be zero and the hypervisor will attempt to resolve the address. + +* `new_addr` is the address of the function that is replacing the old + function. The address is filled in during relocation. The value **MUST** be + the address of the new function in the file. + +* `old_size` and `new_size` contain the sizes of the respective functions in bytes. + The value of `old_size` **MUST** not be zero. + +* `pad` **MUST** be zero. + +The size of the `xsplice_patch_func` array is determined from the ELF section +size. + +When applying the patch the hypervisor iterates over each `xsplice_patch_func` +structure and the core code inserts a trampoline at `old_addr` to `new_addr`. + +When reverting a patch, the hypervisor iterates over each `xsplice_patch_func` +and the core code copies the data from the undo buffer (private internal copy) +to `old_addr`. + +## Hypercalls + +We will employ the sub operations of the system management hypercall (sysctl). +There are to be four sub-operations: + + * upload the payloads. + * listing of payloads summary uploaded and their state. + * getting an particular payload summary and its state. + * command to apply, delete, or revert the payload. + +Most of the actions are asynchronous therefore the caller is responsible +to verify that it has been applied properly by retrieving the summary of it +and verifying that there are no error codes associated with the payload. + +We **MUST** make some of them asynchronous due to the nature of patching +it requires every physical CPU to be lock-step with each other. +The patching mechanism while an implementation detail, is not an short +operation and as such the design **MUST** assume it will be an long-running +operation. + +The sub-operations will spell out how preemption is to be handled (if at all). + +Furthermore it is possible to have multiple different payloads for the same +function. As such an unique name per payload has to be visible to allow proper manipulation. + +The hypercall is part of the `xen_sysctl`. The top level structure contains +one uint32_t to determine the sub-operations and one padding field which +*MUST* always be zero. + +<pre> +struct xen_sysctl_xsplice_op { + uint32_t cmd; /* IN: XEN_SYSCTL_XSPLICE_*. */ + uint32_t pad; /* IN: Always zero. */ + union { + ... see below ... + } u; +}; + +</pre> +while the rest of hypercall specific structures are part of the this structure. + +### Basic type: struct xen_xsplice_name + +Most of the hypercalls employ an shared structure called `struct xen_xsplice_name` +which contains: + + * `name` - pointer where the string for the name is located. + * `size` - the size of the string + * `pad` - padding - to be zero. + +The structure is as follow: + +<pre> +#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`. Initially (on first hypercall) *MUST* be zero. + * `idx` index iterator. On first call *MUST* be zero, subsequent calls varies. + * `nr` the max number of entries to populate. + * `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. + * `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; /* IN/OUT: Initially *MUST* be zero. + On subsequent calls reuse value. + If varies between calls, we are + * getting stale data. */ + uint32_t idx; /* IN/OUT: Index into array. */ + uint32_t nr; /* IN: How many status, names, and len + should fill out. + OUT: How many payloads left. */ + uint32_t pad; /* IN: Must be zero. */ + XEN_GUEST_HANDLE_64(xen_xsplice_status_t) status; /* OUT. Must have enough + space allocate for nr of them. */ + XEN_GUEST_HANDLE_64(char) id; /* OUT: Array of names. Each member + MUST XEN_XSPLICE_NAME_SIZE in size. + Must have nr of them. */ + XEN_GUEST_HANDLE_64(uint32) len; /* OUT: Array of lengths of name's. + Must have nr of them. */ +}; +</pre> + +### XEN_SYSCTL_XSPLICE_ACTION (3) + +Perform an operation on the payload structure referenced by the `name` field. +The operation request is asynchronous and the status should be retrieved +by using either **XEN_SYSCTL_XSPLICE_GET** or **XEN_SYSCTL_XSPLICE_LIST** hypercall. + +The caller provides: + + * A 'struct xen_xsplice_name` `name` containing the unique name. + * `cmd` the command requested: + * *XSPLICE_ACTION_CHECK* (1) check that the payload will apply properly. + This also verfies the payload - which may require SecureBoot firmware + calls. This is the initial state an payload is in. + * *XSPLICE_ACTION_UNLOAD* (2) unload the payload. + Any further hypercalls against the `name` will result in failure unless + **XEN_SYSCTL_XSPLICE_UPLOAD** hypercall is perfomed with same `name`. + * *XSPLICE_ACTION_REVERT* (3) revert the payload. If the operation takes + more time than the upper bound of time the `rc` in `xen_xsplice_status' + retrieved via **XEN_SYSCTL_XSPLICE_GET** will be -XEN_EBUSY. + * *XSPLICE_ACTION_APPLY* (4) apply the payload. If the operation takes + more time than the upper bound of time the `rc` in `xen_xsplice_status' + retrieved via **XEN_SYSCTL_XSPLICE_GET** will be -XEN_EBUSY. + * *XSPLICE_ACTION_REPLACE* (5) revert all applied payloads and apply this + payload. If the operation takes more time than the upper bound of time + the `rc` in `xen_xsplice_status' retrieved via **XEN_SYSCTL_XSPLICE_GET** + will be -XEN_EBUSY. + * `time` the upper bound of time (ms) the cmd should take. Zero means infinite. + If within the time the operation does not succeed the operation would go in + error state. + * `pad` - *MUST* be zero. + +The return value will be zero unless the provided fields are incorrect. + +The structure is as follow: + +<pre> +#define XSPLICE_ACTION_CHECK 1 +#define XSPLICE_ACTION_UNLOAD 2 +#define XSPLICE_ACTION_REVERT 3 +#define XSPLICE_ACTION_APPLY 4 +#define XSPLICE_ACTION_REPLACE 5 +struct xen_sysctl_xsplice_action { + xen_xsplice_name_t name; /* IN, name of the patch. */ + uint32_t cmd; /* IN: XSPLICE_ACTION_* */ + uint32_t time; /* IN: Zero if no timeout. */ + /* Or upper bound of time (ms) */ + /* for operation to take. */ +}; + +</pre> + +## State diagrams of XSPLICE_ACTION commands. + +There is a strict ordering state of what the commands can be. +The XSPLICE_ACTION prefix has been dropped to easy reading and +does not include the XSPLICE_STATES: + +<pre> + /->\ + \ / + UNLOAD <--- CHECK ---> REPLACE|APPLY --> REVERT --\ + \ | + \-------------------<-------------/ + +</pre> +## State transition table of XSPLICE_ACTION commands and XSPLICE_STATUS. + +Note that: + + - The CHECKED state is the starting one achieved with *XEN_SYSCTL_XSPLICE_UPLOAD* hypercall. + - The REVERT operation on success will automatically move to the CHECKED state. + - There are two STATES: CHECKED and APPLIED. + - There are five actions (aka commands): CHECK, APPLY, REPLACE, REVERT, and UNLOAD. + +The state transition table of valid states and action states: + +<pre> + ++---------+---------+--------------------------------+-------+--------+ +| ACTION | Current | Result | Next STATE: | +| ACTION | STATE | |CHECKED|APPLIED | ++---------+----------+-------------------------------+-------+--------+ +| CHECK | CHECKED | Check payload (once more, no) | x | | +| | | errors) | | | ++---------+---------+--------------------------------+-------+--------+ +| CHECK | CHECKED | Check payload (once more, with | | | +| | | errors) | | | ++---------+---------+--------------------------------+-------+--------+ +| UNLOAD | CHECKED | Unload payload. Always works. | | | +| | | No next states. | | | ++---------+---------+--------------------------------+-------+--------+ +| APPLY | CHECKED | Apply payload (success). | | x | ++---------+---------+--------------------------------+-------+--------+ +| APPLY | CHECKED | Apply payload (error|timeout) | x | | ++---------+---------+--------------------------------+-------+--------+ +| REPLACE | CHECKED | Revert payloads and apply new | | x | +| | | payload with success. | | | ++---------+---------+--------------------------------+-------+--------+ +| REPLACE | CHECKED | Revert payloads and apply new | x | | +| | | payload with error. | | | ++---------+---------+--------------------------------+-------+--------+ +| REVERT | APPLIED | Revert payload (success). | x | | ++---------+---------+--------------------------------+-------+--------+ +| REVERT | APPLIED | Revert payload (error|timeout) | | x | ++---------+---------+--------------------------------+-------+--------+ +</pre> + +All the other state transitions are invalid. + +## Sequence of events. + +The normal sequence of events is to: + + 1. *XEN_SYSCTL_XSPLICE_UPLOAD* to upload the payload. If there are errors *STOP* here. + 2. *XEN_SYSCTL_XSPLICE_GET* to check the `->rc`. If *-XEN_EAGAIN* spin. If zero go to next step. + 3. *XEN_SYSCTL_XSPLICE_ACTION* with *XSPLICE_ACTION_APPLY* to apply the patch. + 4. *XEN_SYSCTL_XSPLICE_GET* to check the `->rc`. If in *-XEN_EAGAIN* spin. If zero exit with success. + + +## Addendum + +Implementation quirks should not be discussed in a design document. + +However these observations can provide aid when developing against this +document. + + +### Alternative assembler + +Alternative assembler is a mechanism to use different instructions depending +on what the CPU supports. This is done by providing multiple streams of code +that can be patched in - or if the CPU does not support it - padded with +`nop` operations. The alternative assembler macros cause the compiler to +expand the code to place a most generic code in place - emit a special +ELF .section header to tag this location. During run-time the hypervisor +can leave the areas alone or patch them with an better suited opcodes. + +Note that patching functions that copy to or from guest memory requires +to support alternative support. For example this can be due to SMAP +(specifically *stac* and *clac* operations) which is enabled on Broadwell +and later architectures. It may be related to other alternative instructions. + +### When to patch + +During the discussion on the design two candidates bubbled where +the call stack for each CPU would be deterministic. This would +minimize the chance of the patch not being applied due to safety +checks failing. Safety checks such as not patching code which +is on the stack - which can lead to corruption. + +#### Rendezvous code instead of stop_machine for patching + +The hypervisor's time rendezvous code runs synchronously across all CPUs +every second. Using the stop_machine to patch can stall the time rendezvous +code and result in NMI. As such having the patching be done at the tail +of rendezvous code should avoid this problem. + +However the entrance point for that code is +do_softirq->timer_softirq_action->time_calibration +which ends up calling on_selected_cpus on remote CPUs. + +The remote CPUs receive CALL_FUNCTION_VECTOR IPI and execute the +desired function. + +#### Before entering the guest code. + +Before we call VMXResume we check whether any soft IRQs need to be executed. +This is a good spot because all Xen stacks are effectively empty at +that point. + +To randezvous all the CPUs an barrier with an maximum timeout (which +could be adjusted), combined with forcing all other CPUs through the +hypervisor with IPIs, can be utilized to execute lockstep instructions +on all CPUs. + +The approach is similar in concept to stop_machine and the time rendezvous +but is time-bound. However the local CPU stack is much shorter and +a lot more deterministic. + +This is implemented in the Xen Project hypervisor. + +### Compiling the hypervisor code + +Hotpatch generation often requires support for compiling the target +with -ffunction-sections / -fdata-sections. Changes would have to +be done to the linker scripts to support this. + +### Generation of xSplice ELF payloads + +The design of that is not discussed in this design. + +This is implemented in a seperate tool which lives in a seperate +GIT repo. + +Currently it resides at https://github.com/rosslagerwall/xsplice-build + +### Exception tables and symbol tables growth + +We may need support for adapting or augmenting exception tables if +patching such code. Hotpatches may need to bring their own small +exception tables (similar to how Linux modules support this). + +If supporting hotpatches that introduce additional exception-locations +is not important, one could also change the exception table in-place +and reorder it afterwards. + +As found almost every patch (XSA) to a non-trivial function requires +additional entries in the exception table and/or the bug frames. + +This is implemented in the Xen Project hypervisor. + +### .rodata sections + +The patching might require strings to be updated as well. As such we must be +also able to patch the strings as needed. This sounds simple - but the compiler +has a habit of coalescing strings that are the same - which means if we in-place +alter the strings - other users will be inadvertently affected as well. + +This is also where pointers to functions live - and we may need to patch this +as well. And switch-style jump tables. + +To guard against that we must be prepared to do patching similar to +trampoline patching or in-line depending on the flavour. If we can +do in-line patching we would need to: + + * alter `.rodata` to be writeable. + * inline patch. + * alter `.rodata` to be read-only. + +If are doing trampoline patching we would need to: + + * allocate a new memory location for the string. + * all locations which use this string will have to be updated to use the + offset to the string. + * mark the region RO when we are done. + +The trampoline patching is implemented in the Xen Project hypervisor. + +### .bss and .data sections. + +In place patching writable data is not suitable as it is unclear what should be done +depending on the current state of data. As such it should not be attempted. + +However, functions which are being patched can bring in changes to strings +(.data or .rodata section changes), or even to .bss sections. + +As such the ELF payload can introduce new .rodata, .bss, and .data sections. +Patching in the new function will end up also patching in the new .rodata +section and the new function will reference the new string in the new +.rodata section. + +This is implemented in the Xen Project hypervisor. + +### Security + +Only the privileged domain should be allowed to do this operation. + + +# Not Yet Done + +This is for further development of xSplice. + +## Goals + +The implementation must also have a mechanism for: + + * An dependency mechanism for the payloads. To use that information to load: + - The appropiate payload. To verify that payload is built against the + hypervisor. This can be done via the `build-id` + or via providing an copy of the old code - so that the hypervisor can + verify it against the code in memory. + - To construct an appropiate order of payloads to load in case they + depend on each other. + * Be able to lookup in the Xen hypervisor the symbol names of functions from the ELF payload. + * Be able to patch .rodata, .bss, and .data sections. + * Further safety checks (blacklist of which functions cannot be patched, check + the stack, make sure the payload is built with same compiler as hypervisor). + * NOP out the code sequence if `new_size` is zero. + * Deal with other relocation types: R_X86_64_[8,16,32,32S], R_X86_64_PC[8,16,64] in payload file. + +### xSplice interdependencies + +xSplice patches interdependencies are tricky. + +There are the ways this can be addressed: + * A single large patch that subsumes and replaces all previous ones. + Over the life-time of patching the hypervisor this large patch + grows to accumulate all the code changes. + * Hotpatch stack - where an mechanism exists that loads the hotpatches + in the same order they were built in. We would need an build-id + of the hypevisor to make sure the hot-patches are build against the + correct build. + * Payload containing the old code to check against that. That allows + the hotpatches to be loaded indepedently (if they don't overlap) - or + if the old code also containst previously patched code - even if they + overlap. + +The disadvantage of the first large patch is that it can grow over +time and not provide an bisection mechanism to identify faulty patches. + +The hot-patch stack puts stricts requirements on the order of the patches +being loaded and requires an hypervisor build-id to match against. + +The old code allows much more flexibility and an additional guard, +but is more complex to implement. + +### Handle inlined __LINE__ + +This problem is related to hotpatch construction +and potentially has influence on the design of the hotpatching +infrastructure in Xen. + +For example: + +We have file1.c with functions f1 and f2 (in that order). f2 contains a +BUG() (or WARN()) macro and at that point embeds the source line number +into the generated code for f2. + +Now we want to hotpatch f1 and the hotpatch source-code patch adds 2 +lines to f1 and as a consequence shifts out f2 by two lines. The newly +constructed file1.o will now contain differences in both binary +functions f1 (because we actually changed it with the applied patch) and +f2 (because the contained BUG macro embeds the new line number). + +Without additional information, an algorithm comparing file1.o before +and after hotpatch application will determine both functions to be +changed and will have to include both into the binary hotpatch. + +Options: + +1. Transform source code patches for hotpatches to be line-neutral for + each chunk. This can be done in almost all cases with either + reformatting of the source code or by introducing artificial + preprocessor "#line n" directives to adjust for the introduced + differences. + + This approach is low-tech and simple. Potentially generated + backtraces and existing debug information refers to the original + build and does not reflect hotpatching state except for actually + hotpatched functions but should be mostly correct. + +2. Ignoring the problem and living with artificially large hotpatches + that unnecessarily patch many functions. + + This approach might lead to some very large hotpatches depending on + content of specific source file. It may also trigger pulling in + functions into the hotpatch that cannot reasonable be hotpatched due + to limitations of a hotpatching framework (init-sections, parts of + the hotpatching framework itself, ...) and may thereby prevent us + from patching a specific problem. + + The decision between 1. and 2. can be made on a patch--by-patch + basis. + +3. Introducing an indirection table for storing line numbers and + treating that specially for binary diffing. Linux may follow + this approach. + + We might either use this indirection table for runtime use and patch + that with each hotpatch (similarly to exception tables) or we might + purely use it when building hotpatches to ignore functions that only + differ at exactly the location where a line-number is embedded. + +For BUG(), WARN(), etc., the line number is embedded into the bug frame, not +the function itself. + +Similar considerations are true to a lesser extent for __FILE__, but it +could be argued that file renaming should be done outside of hotpatches. + +## Signature checking requirements. + +The signature checking requires that the layout of the data in memory +**MUST** be same for signature to be verified. This means that the payload +data layout in ELF format **MUST** match what the hypervisor would be +expecting such that it can properly do signature verification. + +The signature is based on the all of the payloads continuously laid out +in memory. The signature is to be appended at the end of the ELF payload +prefixed with the string '~Module signature appended~\n', followed by +an signature header then followed by the signature, key identifier, and signers +name. + +Specifically the signature header would be: + +<pre> +#define PKEY_ALGO_DSA 0 +#define PKEY_ALGO_RSA 1 + +#define PKEY_ID_PGP 0 /* OpenPGP generated key ID */ +#define PKEY_ID_X509 1 /* X.509 arbitrary subjectKeyIdentifier */ + +#define HASH_ALGO_MD4 0 +#define HASH_ALGO_MD5 1 +#define HASH_ALGO_SHA1 2 +#define HASH_ALGO_RIPE_MD_160 3 +#define HASH_ALGO_SHA256 4 +#define HASH_ALGO_SHA384 5 +#define HASH_ALGO_SHA512 6 +#define HASH_ALGO_SHA224 7 +#define HASH_ALGO_RIPE_MD_128 8 +#define HASH_ALGO_RIPE_MD_256 9 +#define HASH_ALGO_RIPE_MD_320 10 +#define HASH_ALGO_WP_256 11 +#define HASH_ALGO_WP_384 12 +#define HASH_ALGO_WP_512 13 +#define HASH_ALGO_TGR_128 14 +#define HASH_ALGO_TGR_160 15 +#define HASH_ALGO_TGR_192 16 + + +struct elf_payload_signature { + u8 algo; /* Public-key crypto algorithm PKEY_ALGO_*. */ + u8 hash; /* Digest algorithm: HASH_ALGO_*. */ + u8 id_type; /* Key identifier type PKEY_ID*. */ + u8 signer_len; /* Length of signer's name */ + u8 key_id_len; /* Length of key identifier */ + u8 __pad[3]; + __be32 sig_len; /* Length of signature data */ +}; + +</pre> +(Note that this has been borrowed from Linux module signature code.). + + +### .bss and .data sections. + +In place patching writable data is not suitable as it is unclear what should be done +depending on the current state of data. As such it should not be attempted. + +That said we should provide hook functions so that the existing data +can be changed during payload application. + + +### Inline patching + +The hypervisor should verify that the in-place patching would fit within +the code or data. + +### Trampoline (e9 opcode) + +The e9 opcode used for jmpq uses a 32-bit signed displacement. That means +we are limited to up to 2GB of virtual address to place the new code +from the old code. That should not be a problem since Xen hypervisor has +a very small footprint. + +However if we need - we can always add two trampolines. One at the 2GB +limit that calls the next trampoline. + +Please note there is a small limitation for trampolines in +function entries: The target function (+ trailing padding) must be able +to accomodate the trampoline. On x86 with +-2 GB relative jumps, +this means 5 bytes are required. + +Depending on compiler settings, there are several functions in Xen that +are smaller (without inter-function padding). + +<pre> +readelf -sW xen-syms | grep " FUNC " | \ + awk '{ if ($3 < 5) print $3, $4, $5, $8 }' + +... +3 FUNC LOCAL wbinvd_ipi +3 FUNC LOCAL shadow_l1_index +... +</pre> +A compile-time check for, e.g., a minimum alignment of functions or a +runtime check that verifies symbol size (+ padding to next symbols) for +that in the hypervisor is advised. + +The tool for generating payloads currently does perform a compile-time +check to ensure that the function to be replaced is large enough. +
Signature · 7 lines
2.5.0 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v4 11/34] xsplice: Design document
Quoted 55 lines
Quoted 1 line
Quoted 1 line · On 15.03.16 at 18:56, <[email protected]> wrote:
docs/misc/xsplice.markdown new file +3
-0+### XEN_SYSCTL_XSPLICE_LIST (2) + +Retrieve an array of abbreviated status and names of payloads that areloaded in the
docs/misc/xsplice.markdown new file +50
-0+hypervisor. + +The caller provides: + + * `version`. Initially (on first hypercall) *MUST* be zero. + * `idx` index iterator. On first call *MUST* be zero, subsequent calls varies. + * `nr` the max number of entries to populate. + * `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. + * `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: +
docs/misc/xsplice.markdown line 544
Quoted 10 lines
docs/misc/xsplice.markdown new file +10
-0+<pre> +struct xen_sysctl_xsplice_list { + uint32_t version; /* IN/OUT: Initially *MUST* be zero. + On subsequent calls reuse value. + If varies between calls, we are + * getting stale data. */ + uint32_t idx; /* IN/OUT: Index into array. */ + uint32_t nr; /* IN: How many status, names, and len + should fill out. + OUT: How many payloads left. */
I think there's an ambiguity left in both the description above and the comments here: With idx required to be zero upon first invocation (which I'm not clear why that is), which parts of the three arrays get filled when idx is non-zero: [0, idx) or [nr, nr + idx)?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 11/34] xsplice: Design document
Quoted 61 lines · Jan Beulich
Quoted 61 lines
Quoted 1 line
Quoted 1 line · On 15.03.16 at 18:56, <[email protected]> wrote:
(quoted diff) +3
-0+### XEN_SYSCTL_XSPLICE_LIST (2) + +Retrieve an array of abbreviated status and names of payloads that areloaded in the
(quoted diff) +56
-0+hypervisor. + +The caller provides: + + * `version`. Initially (on first hypercall) *MUST* be zero. + * `idx` index iterator. On first call *MUST* be zero, subsequent calls varies. + * `nr` the max number of entries to populate. + * `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. + * `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; /* IN/OUT: Initially *MUST* be zero. + On subsequent calls reuse value. + If varies between calls, we are + * getting stale data. */
Quoted 8 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ uint32_t idx; /* IN/OUT: Index into array. */ + uint32_t nr; /* IN: How many status, names, and len + should fill out. + OUT: How many payloads left. */I think there's an ambiguity left in both the description above and the comments here: With idx required to be zero upon first invocation (which I'm not clear why that is), which parts of the
That is actually a stale design choice. Initially the "How many payloads left" was going to be stamped in 'idx'. But it is now in 'nr'.
The value can be arbitrary, albeit on first invocation it should be 0 otherwise you won't get 'nr' telling you how many payloads there left. Unless your 'idx' falls below the amount of payloads.
As in, say we have 20 payloads.
If the first hypercall for 'idx' has 30, then the hypercall will return -EINVAL. If the first hypercall 'idx' has 19, then the hypercall will populate ->name,->len,->status, ->version and write ->nr with 1.
Quoted 1 line
three arrays get filled when idx is non-zero: [0, idx) or [nr, nr + idx)?
I am going to assume the you are filling the two /*IN*/ entries, so ->idx and ->nr.
[0, idx]:
If there is data and the amount of payloads is greater than idx (0), and there are no hypercall preemptions, then:
->nr = remaining amount
->version = version value
->name[0..idx]
->len[0..idx]
->status[0..idx]
[nr, nr + idx]:
If there is data and the amount of payloads is less than nr, then -EINVAL is returned.
If there is data and the amount of payloads is greater than 'nr', and there are no hypercall preemptions, then:
->nr = remaining amount
->version = version value
->name[nr..nr + idx]
->len[nr..nr+idx]
->status[nr..nr+idx]
Let me update the design doc to remove the /*IN*/ part about the 'idx'.
docs/misc/xsplice.markdown +5 -3
@@ -487,7 +487,9 @@ hypervisor. The caller provides: * `version`. Initially (on first hypercall) *MUST* be zero. - * `idx` index iterator. On first call *MUST* be zero, subsequent calls varies. + * `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. * `nr` the max number of entries to populate. * `pad` - *MUST* be zero. * `status` virtual address of where to write `struct xen_xsplice_status`
@@ -538,9 +540,9 @@ struct xen_sysctl_xsplice_list { On subsequent calls reuse value. If varies between calls, we are * getting stale data. */ - uint32_t idx; /* IN/OUT: Index into array. */ + uint32_t idx; /* IN: Index into array. */ uint32_t nr; /* IN: How many status, names, and len - should fill out. + should be filled out. 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
Quoted 3 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v4 11/34] xsplice: Design document
Quoted 28 lines
docs/misc/xsplice.markdown +5
-3@@ -487,7 +487,9 @@ hypervisor. The caller provides: * `version`. Initially (on first hypercall) *MUST* be zero. - * `idx` index iterator. On first call *MUST* be zero, subsequent calls varies. + * `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. * `nr` the max number of entries to populate. * `pad` - *MUST* be zero. * `status` virtual address of where to write `struct xen_xsplice_status`@@ -538,9 +540,9 @@ struct xen_sysctl_xsplice_list { On subsequent calls reuse value. If varies between calls, we are * getting stale data. */ - uint32_t idx; /* IN/OUT: Index into array. */ + uint32_t idx; /* IN: Index into array. */ uint32_t nr; /* IN: How many status, names, and len - should fill out. + should be filled out. OUT: How many payloads left. */ uint32_t pad; /* IN: Must be zero. */ XEN_GUEST_HANDLE_64(xen_xsplice_status_t) status; /* OUT. Must have enoughQuoted 1 line
Quoted 2 lines
Quoted 2 lines
Jan
And it occurred to me that we can do a probe call similar to XEN_VERSION.
That is fill 'nr' with zero and ->names, ->status, ->list, etc can be NULL. Then 'nr' will be filled back with the number of payloads.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel