domain context infrastructure
v3 cover domain context infrastructure
From: Paul Durrant <[email protected]>
Paul Durrant (5):
xen/common: introduce a new framework for save/restore of 'domain'
context
xen/common/domctl: introduce XEN_DOMCTL_get/setdomaincontext tools/misc: add xen-domctx to present domain context common/domain: add a domain context record for shared_info... tools/libxc: make use of domain context SHARED_INFO record...
.gitignore | 1 + tools/flask/policy/modules/xen.if | 4 +- tools/libxc/include/xenctrl.h | 5 + tools/libxc/xc_domain.c | 54 +++++ tools/libxc/xc_sr_common.c | 58 +++++ tools/libxc/xc_sr_common.h | 11 +- tools/libxc/xc_sr_common_x86_pv.c | 47 ++++ tools/libxc/xc_sr_common_x86_pv.h | 3 + tools/libxc/xc_sr_restore_x86_pv.c | 40 ++-- tools/libxc/xc_sr_save_x86_pv.c | 26 +- tools/libxc/xg_save_restore.h | 1 + tools/misc/Makefile | 4 + tools/misc/xen-domctx.c | 273 +++++++++++++++++++++ xen/common/Makefile | 1 + xen/common/domain.c | 60 +++++ xen/common/domctl.c | 167 +++++++++++++ xen/common/save.c | 313 +++++++++++++++++++++++++ xen/include/public/arch-arm/hvm/save.h | 5 + xen/include/public/arch-x86/hvm/save.h | 5 + xen/include/public/domctl.h | 41 ++++ xen/include/public/save.h | 89 +++++++ xen/include/xen/save.h | 165 +++++++++++++ xen/xsm/flask/hooks.c | 6 + xen/xsm/flask/policy/access_vectors | 4 + 24 files changed, 1332 insertions(+), 51 deletions(-) create mode 100644 tools/misc/xen-domctx.c create mode 100644 xen/common/save.c create mode 100644 xen/include/public/save.h create mode 100644 xen/include/xen/save.h
Signature · 1 line
2.20.1
PATCH v3 1/5 xen/common: introduce a new framework for save/restore of 'domain' context
To allow enlightened HVM guests (i.e. those that have PV drivers) to be migrated without their co-operation it will be necessary to transfer 'PV' state such as event channel state, grant entry state, etc.
Currently there is a framework (entered via the hvm_save/load() functions) that allows a domain's 'HVM' (architectural) state to be transferred but 'PV' state is also common with pure PV guests and so this framework is not really suitable.
This patch adds the new public header and low level implementation of a new common framework, entered via the domain_save/load() functions. Subsequent patches will introduce other parts of the framework, and code that will make use of it within the current version of the libxc migration stream.
This patch also marks the HVM-only framework as deprecated in favour of the new framework.
---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Volodymyr Babchuk <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>
v3:
- Addressed comments from Julien and Jan
- Save handlers no longer need to state entry length up-front
- Save handlers expected to deal with multiple instances internally
- Entries are now auto-padded to 8 byte boundary
v2:
- Allow multi-stage save/load to avoid the need to double-buffer
- Get rid of the masks and add an 'ignore' flag instead
- Create copy function union to preserve const save buffer
- Deprecate HVM-only framework
--- xen/common/Makefile | 1 + xen/common/save.c | 313 +++++++++++++++++++++++++ xen/include/public/arch-arm/hvm/save.h | 5 + xen/include/public/arch-x86/hvm/save.h | 5 + xen/include/public/save.h | 80 +++++++ xen/include/xen/save.h | 165 +++++++++++++ 6 files changed, 569 insertions(+) create mode 100644 xen/common/save.c create mode 100644 xen/include/public/save.h create mode 100644 xen/include/xen/save.h
xen/common/Makefile +1 -0
@@ -37,6 +37,7 @@ obj-y += radix-tree.o obj-y += rbtree.o obj-y += rcupdate.o obj-y += rwlock.o +obj-y += save.o obj-y += shutdown.o obj-y += softirq.o obj-y += sort.o
xen/common/save.c new file +313 -0
313 lines not on this page · raw message
xen/include/public/arch-arm/hvm/save.h +5 -0
@@ -26,6 +26,11 @@#ifndef __XEN_PUBLIC_HVM_SAVE_ARM_H__#define __XEN_PUBLIC_HVM_SAVE_ARM_H__ +/* +* Further use of HVM state is deprecated. New state records should only +* be added to the domain state header: public/save.h +*/ +#endif /*
xen/include/public/arch-x86/hvm/save.h +5 -0
@@ -648,6 +648,11 @@ struct hvm_msr {*/ #define HVM_SAVE_CODE_MAX 20 +/* +* Further use of HVM state is deprecated. New state records should only +* be added to the domain state header: public/save.h +*/ +#endif /* __XEN_PUBLIC_HVM_SAVE_X86_H__ */ /*
xen/include/public/save.h new file +80 -0
80 lines not on this page · raw message
xen/include/xen/save.h new file +165 -0
165 lines not on this page · raw message
Signature · 1 line
2.20.1
Re: [PATCH v3 1/5] xen/common: introduce a new framework for save/restore of 'domain' context
Quoted 17 lines · Paul Durrant
xen/common/save.c new file +14
-0@@ -0,0 +1,313 @@ +/* +* save.c: Save and restore PV guest state common to all domain types. +* +* Copyright Amazon.com Inc. or its affiliates. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +*
xen/common/save.c line 24
Quoted 10 lines
xen/common/save.c new file +10
-0+* You should have received a copy of the GNU General Public License along with +* this program; If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <xen/compile.h> +#include <xen/save.h> + +struct domain_context { +struct domain *domain; +const char *name;/* for logging purposes */
With this comment, why ...
xen/common/save.c line 32
Quoted 8 lines
xen/common/save.c new file +8
-0+struct domain_save_descriptor desc; +size_t len;/* for internal accounting */ +union { +struct domain_save_ops *save; +struct domain_load_ops *load; + } ops; +void *priv; +bool log;
... this separate field? Couldn't "no logging" simply be expressed by name being NULL?
xen/common/save.c line 95
Quoted 4 lines
xen/common/save.c new file +4
-0+int domain_save_end (struct domain_context *c) +{ +struct domain *d = c->domain; +uint8_t pad[DOMAIN_SAVE_ALIGN ] = {};
Preferably moved into the more narrow scope, and probably wants making "static const".
xen/common/save.c line 106
Quoted 11 lines
xen/common/save.c new file +11
-0+size_t len =ROUNDUP (c->len,DOMAIN_SAVE_ALIGN ) - c->len;/* padding */ +int rc; + +if ( len ) + { + rc =domain_save_data (c, pad, len); + +if ( rc ) +return rc; + } +ASSERT (IS_ALIGNED (c->len,DOMAIN_SAVE_ALIGN ));
While you mention the auto-padding as a change in v3, it's not really clear to me why it was introduced. Could you add half a sentence to the description clarifying the motivation?
xen/common/save.c line 127
Quoted 10 lines
xen/common/save.c new file +10
-0+int domain_save (struct domain *d,struct domain_save_ops *ops,void *priv, +bool dry_run) +{ +struct domain_context c = { + .domain = d, + .ops.save = ops, + .priv = priv, + .log = !dry_run, + }; +static struct domain_save_header h = {
const?
xen/common/save.c line 133
Quoted 6 lines
xen/common/save.c new file +6
-0+ .magic = DOMAIN_SAVE_MAGIC, + .xen_major = XEN_VERSION, + .xen_minor = XEN_SUBVERSION, + .version = DOMAIN_SAVE_VERSION, + }; +struct domain_save_end e = {};
const? (static would likely be quite pointless here)
Quoted 34 lines
xen/common/save.c new file +34
-0+int domain_load (struct domain *d,struct domain_load_ops *ops,void *priv) +{ +struct domain_context c = { + .domain = d, + .ops.load = ops, + .priv = priv, + .log = true, + }; +unsigned int instance; +struct domain_save_header h; +int rc; + +ASSERT (d != current->domain); + + rc = c.ops.load->read (c.priv, &c.desc,sizeof (c.desc)); +if ( rc ) +return rc; + + rc =DOMAIN_LOAD_ENTRY (HEADER , &c, &instance, &h,sizeof (h)); +if ( rc ) +return rc; + +if ( instance || h.magic !=DOMAIN_SAVE_MAGIC || + h.version !=DOMAIN_SAVE_VERSION ) +return -EINVAL ; + +domain_pause (d); + +for (;;) + { +unsigned int i; +domain_load_handler load; + + rc = c.ops.load->read (c.priv, &c.desc,sizeof (c.desc));
xen/common/save.c line 281
Quoted 10 lines
xen/common/save.c new file +10
-0+if ( rc ) +return rc; + + rc = -EINVAL ; + +if ( c.desc.typecode ==DOMAIN_SAVE_CODE (END ) ) + { +struct domain_save_end e; + + rc =DOMAIN_LOAD_ENTRY (END , &c, &instance,NULL ,sizeof (e));
Without using &e here I don't see how you can get away without an "unused variable" warning.
Quoted 26 lines
xen/include/public/save.h new file +23
-0@@ -0,0 +1,80 @@ +/* +* save.h +* +* Structure definitions for common PV/HVM domain state that is held by +* Xen and must be saved along with the domain's memory. +* +* Copyright Amazon.com Inc. or its affiliates. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to +* deal in the Software without restriction, including without limitation the +* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +* sell copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
xen/include/public/save.h line 33
Quoted 10 lines
xen/include/public/save.h new file +10
-0+* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +* DEALINGS IN THE SOFTWARE. +*/ + +#ifndef XEN_PUBLIC_SAVE_H +#define XEN_PUBLIC_SAVE_H + +#include "xen.h" + +#if defined(__XEN__) || defined(__XEN_TOOLS__)
Move #include down below here?
xen/include/public/save.h line 41
Quoted 7 lines
xen/include/public/save.h new file +7
-0+/* Entry data is preceded by a descriptor */ +struct domain_save_descriptor { +uint16_t typecode; + +/* +* Instance number of the entry (since there may by multiple of some +* types of entry).
With a German bias I'm inclined to ask: "entries"?
xen/include/public/save.h line 54
Quoted 13 lines
xen/include/public/save.h new file +13
-0+*/ +uint16_t instance; + +/* Entry length not including this descriptor */ +uint32_t length; +}; + +/* +* Each entry has a type associated with it. DECLARE_DOMAIN_SAVE_TYPE +* binds these things together. +*/ +#define DECLARE_DOMAIN_SAVE_TYPE (_x, _code, _type) \ + struct DOMAIN_SAVE_TYPE_##_x { char c[_code]; _type t; };
Perhaps point out in the comment that this type is not meant to have instantiations?
xen/include/public/save.h line 59
Quoted 4 lines
xen/include/public/save.h new file +4
-0+#define DOMAIN_SAVE_CODE (_x) \ + (sizeof(((struct DOMAIN_SAVE_TYPE_##_x *)(0))->c)) +#define DOMAIN_SAVE_TYPE (_x) \ + typeof(((struct DOMAIN_SAVE_TYPE_##_x *)(0))->t)
Feels like I already mentioned the oddity of having parentheses around a single token that's not a macro parameter name.
Quoted 27 lines
xen/include/xen/save.h new file +24
-0@@ -0,0 +1,165 @@ +/* +* save.h: support routines for save/restore +* +* Copyright Amazon.com Inc. or its affiliates. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along with +* this program; If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef XEN_SAVE_H +#define XEN_SAVE_H + +#include <xen/init.h> +#include <xen/sched.h> +#include <xen/types.h>
xen/include/xen/save.h line 34
Quoted 10 lines
xen/include/xen/save.h new file +10
-0+ +#include <public/save.h> + +struct domain_context ; + +int domain_save_begin (struct domain_context *c,unsigned int typecode, +const char *name,unsigned int instance); + +#define DOMAIN_SAVE_BEGIN (_x, _c, _instance) \ + domain_save_begin((_c), DOMAIN_SAVE_CODE(_x), #_x, (_instance))
As per prior conversation I would have expected no leading underscores here anymore, and no parenthesization of what is still _c. More of these further down.
xen/include/xen/save.h line 77
Quoted 8 lines
xen/include/xen/save.h new file +8
-0+static inline int domain_load_entry (struct domain_context *c, +unsigned int typecode,const char *name, +unsigned int *instance,void *dst, +size_t len) +{ +int rc; + + rc =domain_load_begin (c, typecode, name, instance);
For some reason I've spotted this only here: Why is instance a pointer parameter of the function, when typecode is a value? Both live next to one another in struct domain_save_descriptor, and hence instance could be retrieved at the same time as typecode.
Quoted 6 lines
xen/include/xen/save.h new file +6
-0+/* +* Register save and restore handlers. Save handlers will be invoked +* in order of DOMAIN_SAVE_CODE(). +*/ +#define DOMAIN_REGISTER_SAVE_RESTORE (_x, _save, _load) \ + static int __init __domain_register_##_x##_save_restore(void) \
xen/include/xen/save.h line 124
Quoted 10 lines
xen/include/xen/save.h new file +10
-0+ { \ +domain_register_save_type ( \ +DOMAIN_SAVE_CODE (_x), \ + #_x, \ + &(_save), \ + &(_load)); \ + \ +return 0 ; \ + } \ + __initcall(__domain_register_##_x##_save_restore);
I'm puzzled by part of the comment: Invoking by save code looks reasonable for the saving side (albeit END doesn't match this rule afaics), but is this going to be good enough for the consuming side? There may be dependencies between types, and with fixed ordering there may be no way to insert a depended upon type ahead of an already defined one (at least as long as the codes are meant to be stable).
Quoted 7 lines
xen/include/xen/save.h new file +7
-0+/* +* Entry points: +* +* ops: These are callback functions provided by the caller that will +* be used to write to (in the save case) or read from (in the +* load case) the context buffer. See above for more detail. +* priv: This is a pointer that will be passed to the copy function to
xen/include/xen/save.h line 163
Quoted 10 lines
xen/include/xen/save.h new file +10
-0+* allow it to identify the context buffer and the current state +* of the save or load operation. +* dry_run: If this is set then the caller of domain_save() is only trying +* to acquire the total size of the data, not the data itself. +* In this case the caller may supply different ops to avoid doing +* unnecessary work. +*/ +int domain_save (struct domain *d,struct domain_save_ops *ops,void *priv, +bool dry_run); +int domain_load (struct domain *d,struct domain_load_ops *ops,void *priv);
I guess ops want to be pointer to const in both cases?
Jan
RE: [PATCH v3 1/5] xen/common: introduce a new framework for save/restore of 'domain' context
Quoted 51 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 19 May 2020 14:04
To: Paul Durrant <[email protected]>
Cc: [email protected]; Paul Durrant <[email protected]>; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>; Volodymyr Babchuk <[email protected]>; Roger Pau Monné <[email protected]>
Subject: Re: [PATCH v3 1/5] xen/common: introduce a new framework for save/restore of 'domain' contextQuoted 17 lines · Paul Durrant
xen/common/save.c new file +14
-0@@ -0,0 +1,313 @@ +/* +* save.c: Save and restore PV guest state common to all domain types. +* +* Copyright Amazon.com Inc. or its affiliates. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* xen/common/save.c line 24
Quoted 10 lines
xen/common/save.c new file +10
-0+* You should have received a copy of the GNU General Public License along with +* this program; If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <xen/compile.h> +#include <xen/save.h> + +struct domain_context { +struct domain *domain; +const char *name;/* for logging purposes */ With this comment, why ...
xen/common/save.c line 32
Quoted 8 lines
xen/common/save.c new file +8
-0+struct domain_save_descriptor desc; +size_t len;/* for internal accounting */ +union { +struct domain_save_ops *save; +struct domain_load_ops *load; + } ops; +void *priv; +bool log;
Quoted 3 lines
... this separate field? Couldn't "no logging" simply be expressed by name being NULL?
Ok. The log bool predated the name pointer so, yes these could be combined.
Quoted 8 lines
xen/common/save.c line 95
Quoted 4 lines
xen/common/save.c new file +4
-0+int domain_save_end (struct domain_context *c) +{ +struct domain *d = c->domain; +uint8_t pad[DOMAIN_SAVE_ALIGN ] = {};Preferably moved into the more narrow scope, and probably wants making "static const".
Ok.
Quoted 7 lines
Quoted 7 lines
xen/common/save.c new file +7
-0+size_t len =ROUNDUP (c->len,DOMAIN_SAVE_ALIGN ) - c->len;/* padding */ +int rc; + +if ( len ) + { + rc =domain_save_data (c, pad, len); +
Quoted 9 lines
xen/common/save.c line 106
Quoted 4 lines
xen/common/save.c new file +4
-0+if ( rc ) +return rc; + } +ASSERT (IS_ALIGNED (c->len,DOMAIN_SAVE_ALIGN ));While you mention the auto-padding as a change in v3, it's not really clear to me why it was introduced. Could you add half a sentence to the description clarifying the motivation?
Julien favoured it and it does seem like a good idea as it avoids the need to put explicit trailing 'pad' fields in entries. I'll add to the commit comment to explain.
Quoted 4 lines
Quoted 4 lines
xen/common/save.c new file +4
-0+int domain_save (struct domain *d,struct domain_save_ops *ops,void *priv, +bool dry_run) +{ +struct domain_context c = {
Quoted 9 lines
xen/common/save.c line 127
Quoted 6 lines
xen/common/save.c new file +6
-0+ .domain = d, + .ops.save = ops, + .priv = priv, + .log = !dry_run, + }; +static struct domain_save_header h = {const?
Yes, it can be.
Quoted 9 lines
xen/common/save.c line 133
Quoted 6 lines
xen/common/save.c new file +6
-0+ .magic = DOMAIN_SAVE_MAGIC, + .xen_major = XEN_VERSION, + .xen_minor = XEN_SUBVERSION, + .version = DOMAIN_SAVE_VERSION, + }; +struct domain_save_end e = {};const? (static would likely be quite pointless here)
Ok.
Quoted 39 lines
Quoted 39 lines
xen/common/save.c new file +39
-0+int domain_load (struct domain *d,struct domain_load_ops *ops,void *priv) +{ +struct domain_context c = { + .domain = d, + .ops.load = ops, + .priv = priv, + .log = true, + }; +unsigned int instance; +struct domain_save_header h; +int rc; + +ASSERT (d != current->domain); + + rc = c.ops.load->read (c.priv, &c.desc,sizeof (c.desc)); +if ( rc ) +return rc; + + rc =DOMAIN_LOAD_ENTRY (HEADER , &c, &instance, &h,sizeof (h)); +if ( rc ) +return rc; + +if ( instance || h.magic !=DOMAIN_SAVE_MAGIC || + h.version !=DOMAIN_SAVE_VERSION ) +return -EINVAL ; + +domain_pause (d); + +for (;;) + { +unsigned int i; +domain_load_handler load; + + rc = c.ops.load->read (c.priv, &c.desc,sizeof (c.desc)); +if ( rc ) +return rc; + + rc = -EINVAL ; +
Quoted 8 lines
xen/common/save.c line 281
Quoted 5 lines
xen/common/save.c new file +5
-0+if ( c.desc.typecode ==DOMAIN_SAVE_CODE (END ) ) + { +struct domain_save_end e; + + rc =DOMAIN_LOAD_ENTRY (END , &c, &instance,NULL ,sizeof (e));Without using &e here I don't see how you can get away without an "unused variable" warning.
Hmm. I definitely don't get a warning, but yes this ought to be changed.
Quoted 31 lines
Quoted 31 lines
xen/include/public/save.h new file +27
-0@@ -0,0 +1,80 @@ +/* +* save.h +* +* Structure definitions for common PV/HVM domain state that is held by +* Xen and must be saved along with the domain's memory. +* +* Copyright Amazon.com Inc. or its affiliates. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to +* deal in the Software without restriction, including without limitation the +* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +* sell copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +* DEALINGS IN THE SOFTWARE. +*/ +
Quoted 9 lines
xen/include/public/save.h line 33
Quoted 6 lines
xen/include/public/save.h new file +6
-0+#ifndef XEN_PUBLIC_SAVE_H +#define XEN_PUBLIC_SAVE_H + +#include "xen.h" + +#if defined(__XEN__) || defined(__XEN_TOOLS__)Move #include down below here?
Sure.
Quoted 10 lines
xen/include/public/save.h line 41
Quoted 7 lines
xen/include/public/save.h new file +7
-0+/* Entry data is preceded by a descriptor */ +struct domain_save_descriptor { +uint16_t typecode; + +/* +* Instance number of the entry (since there may by multiple of some +* types of entry). With a German bias I'm inclined to ask: "entries"?
Not sure. Still understandable so I'm happy to change. Also s/by/be.
Quoted 8 lines
Quoted 8 lines
xen/include/public/save.h new file +8
-0+*/ +uint16_t instance; + +/* Entry length not including this descriptor */ +uint32_t length; +}; + +/*
Quoted 8 lines
xen/include/public/save.h line 54
Quoted 5 lines
xen/include/public/save.h new file +5
-0+* Each entry has a type associated with it. DECLARE_DOMAIN_SAVE_TYPE +* binds these things together. +*/ +#define DECLARE_DOMAIN_SAVE_TYPE (_x, _code, _type) \ + struct DOMAIN_SAVE_TYPE_##_x { char c[_code]; _type t; };Perhaps point out in the comment that this type is not meant to have instantiations?
Ok.
Quoted 9 lines
xen/include/public/save.h line 59
Quoted 5 lines
xen/include/public/save.h new file +4
-0+#define DOMAIN_SAVE_CODE (_x) \ + (sizeof(((struct DOMAIN_SAVE_TYPE_##_x *)(0))->c)) +#define DOMAIN_SAVE_TYPE (_x) \ + typeof(((struct DOMAIN_SAVE_TYPE_##_x *)(0))->t)Feels like I already mentioned the oddity of having parentheses around a single token that's not a macro parameter name.
Ok. Missed that.
Quoted 33 lines
Quoted 33 lines
xen/include/xen/save.h new file +30
-0@@ -0,0 +1,165 @@ +/* +* save.h: support routines for save/restore +* +* Copyright Amazon.com Inc. or its affiliates. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along with +* this program; If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef XEN_SAVE_H +#define XEN_SAVE_H + +#include <xen/init.h> +#include <xen/sched.h> +#include <xen/types.h> + +#include <public/save.h> + +struct domain_context ; + +int domain_save_begin(struct domain_context *c, unsigned int typecode,
Quoted 8 lines
xen/include/xen/save.h line 34
Quoted 4 lines
xen/include/xen/save.h new file +4
-0+ const char *name, unsigned int instance); + +#define DOMAIN_SAVE_BEGIN (_x, _c, _instance) \ + domain_save_begin((_c), DOMAIN_SAVE_CODE(_x), #_x, (_instance))As per prior conversation I would have expected no leading underscores here anymore, and no parenthesization of what is still _c. More of these further down.
What's wrong with leading underscores in macro arguments? They can't pollute any namespace. Also, I prefer to keep the parentheses for arguments.
Quoted 15 lines
xen/include/xen/save.h line 77
Quoted 9 lines
xen/include/xen/save.h new file +8
-0+static inline int domain_load_entry (struct domain_context *c, +unsigned int typecode,const char *name, +unsigned int *instance,void *dst, +size_t len) +{ +int rc; + + rc =domain_load_begin (c, typecode, name, instance);For some reason I've spotted this only here: Why is instance a pointer parameter of the function, when typecode is a value? Both live next to one another in struct
domain_save_descriptor, and hence instance could be retrieved at the same time as typecode.
Because the typecode is known a priori. It has to be known for the correct handler to be invoked. It is only provided here for verification purposes. I could have provided the instance as an argument to the load handler but I prefer making the interactions for save and load more symmetric.
Quoted 12 lines
Quoted 12 lines
xen/include/xen/save.h new file +12
-0+/* +* Register save and restore handlers. Save handlers will be invoked +* in order of DOMAIN_SAVE_CODE(). +*/ +#define DOMAIN_REGISTER_SAVE_RESTORE (_x, _save, _load) \ + static int __init __domain_register_##_x##_save_restore(void) \ + { \ + domain_register_save_type( \ + DOMAIN_SAVE_CODE(_x), \ + #_x, \ + &(_save), \ + &(_load)); \
Quoted 8 lines
xen/include/xen/save.h line 124
Quoted 4 lines
xen/include/xen/save.h new file +4
-0+ \ +return 0 ; \ + } \ + __initcall(__domain_register_##_x##_save_restore);I'm puzzled by part of the comment: Invoking by save code looks reasonable for the saving side (albeit END doesn't match this rule afaics), but is this going to be good enough for the consuming side?
No, this only relates to the save side which is why the comment says 'Save handlers'. I do note that it would be more consistent to use 'load' rather than 'restore' here though.
Quoted 5 lines
There may be dependencies between types, and with fixed ordering there may be no way to insert a depended upon type ahead of an already defined one (at least as long as the codes are meant to be stable).
The ordering of load handlers is determined by the stream. I'll add a sentence saying that.
Quoted 11 lines
Quoted 11 lines
xen/include/xen/save.h new file +11
-0+/* +* Entry points: +* +* ops: These are callback functions provided by the caller that will +* be used to write to (in the save case) or read from (in the +* load case) the context buffer. See above for more detail. +* priv: This is a pointer that will be passed to the copy function to +* allow it to identify the context buffer and the current state +* of the save or load operation. +* dry_run: If this is set then the caller of domain_save() is only trying +* to acquire the total size of the data, not the data itself.
Quoted 9 lines
xen/include/xen/save.h line 163
Quoted 6 lines
xen/include/xen/save.h new file +6
-0+* In this case the caller may supply different ops to avoid doing +* unnecessary work. +*/ +int domain_save (struct domain *d,struct domain_save_ops *ops,void *priv, +bool dry_run); +int domain_load (struct domain *d,struct domain_load_ops *ops,void *priv);I guess ops want to be pointer to const in both cases?
Yes, it can be.
Paul
Quoted 1 line
Jan
Re: [PATCH v3 1/5] xen/common: introduce a new framework for save/restore of 'domain' context
Quoted 46 lines · Paul Durrant
Quoted 37 lines
From: Jan Beulich <[email protected]>
Sent: 19 May 2020 14:04Quoted 33 lines · Paul Durrant
xen/include/xen/save.h new file +30
-0@@ -0,0 +1,165 @@ +/* +* save.h: support routines for save/restore +* +* Copyright Amazon.com Inc. or its affiliates. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along with +* this program; If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef XEN_SAVE_H +#define XEN_SAVE_H + +#include <xen/init.h> +#include <xen/sched.h> +#include <xen/types.h> + +#include <public/save.h> + +struct domain_context ; + +int domain_save_begin(struct domain_context *c, unsigned int typecode,Quoted 8 lines
xen/include/xen/save.h line 34
Quoted 4 lines
xen/include/xen/save.h new file +4
-0+ const char *name, unsigned int instance); + +#define DOMAIN_SAVE_BEGIN (_x, _c, _instance) \ + domain_save_begin((_c), DOMAIN_SAVE_CODE(_x), #_x, (_instance))As per prior conversation I would have expected no leading underscores here anymore, and no parenthesization of what is still _c. More of these further down.
Quoted 2 lines
What's wrong with leading underscores in macro arguments? They can't pollute any namespace.
They can still hide file scope variables legitimately named this way (which may get accessed by a macro without being a macro argument). The wording of the standard is quite clear:
"All identifiers that begin with an underscore are always reserved for use as identifiers with file scope in both the ordinary and tag name spaces."
Quoted 1 line
Also, I prefer to keep the parentheses for arguments.
More code churn then once we hopefully standardize of the less obfuscating variant without.
Quoted 15 lines
Quoted 5 lines
Quoted 5 lines
xen/include/xen/save.h new file +5
-0+static inline int domain_load_entry (struct domain_context *c, +unsigned int typecode,const char *name, +unsigned int *instance,void *dst, +size_t len) +{Quoted 9 lines
xen/include/xen/save.h line 77
Quoted 3 lines
xen/include/xen/save.h new file +3
-0+int rc; + + rc =domain_load_begin (c, typecode, name, instance);For some reason I've spotted this only here: Why is instance a pointer parameter of the function, when typecode is a value? Both live next to one another in struct
domain_save_descriptor, and hence instance could be retrieved at the same time as typecode.
Quoted 5 lines
Because the typecode is known a priori. It has to be known for the correct handler to be invoked. It is only provided here for verification purposes. I could have provided the instance as an argument to the load handler but I prefer making the interactions for save and load more symmetric.
Hmm, I don't see any symmetry violation in the alternative model, but anyway.
Quoted 25 lines
Quoted 12 lines
Quoted 12 lines
xen/include/xen/save.h new file +12
-0+/* +* Register save and restore handlers. Save handlers will be invoked +* in order of DOMAIN_SAVE_CODE(). +*/ +#define DOMAIN_REGISTER_SAVE_RESTORE (_x, _save, _load) \ + static int __init __domain_register_##_x##_save_restore(void) \ + { \ + domain_register_save_type( \ + DOMAIN_SAVE_CODE(_x), \ + #_x, \ + &(_save), \ + &(_load)); \Quoted 8 lines
xen/include/xen/save.h line 124
Quoted 4 lines
xen/include/xen/save.h new file +4
-0+ \ +return 0 ; \ + } \ + __initcall(__domain_register_##_x##_save_restore);I'm puzzled by part of the comment: Invoking by save code looks reasonable for the saving side (albeit END doesn't match this rule afaics), but is this going to be good enough for the consuming side?
No, this only relates to the save side which is why the comment says 'Save handlers'. I do note that it would be more consistent to use 'load' rather than 'restore' here though.
Quoted 8 lines
Quoted 5 lines
There may be dependencies between types, and with fixed ordering there may be no way to insert a depended upon type ahead of an already defined one (at least as long as the codes are meant to be stable).
The ordering of load handlers is determined by the stream. I'll add a sentence saying that.
I.e. the consumer of the "get" interface (and producer of the stream) is supposed to take apart the output it gets, bring records into suitable order (which implies it knows of all the records, and which hence means this code may need updating in cases where I'd expect only the hypervisor needs), and only then issue to the stream?
Jan
RE: [PATCH v3 1/5] xen/common: introduce a new framework for save/restore of 'domain' context
Quoted 61 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 19 May 2020 15:24
To: [email protected]
Cc: [email protected]; 'Paul Durrant' <[email protected]>; 'Andrew Cooper' <[email protected]>; 'George Dunlap' <[email protected]>; 'Ian Jackson' <[email protected]>; 'Julien Grall' <[email protected]>; 'Stefano Stabellini' <[email protected]>; 'Wei Liu' <[email protected]>; 'Volodymyr Babchuk' <[email protected]>; 'Roger Pau Monné' <[email protected]>
Subject: Re: [PATCH v3 1/5] xen/common: introduce a new framework for save/restore of 'domain' contextQuoted 46 lines · Paul Durrant
Quoted 37 lines
From: Jan Beulich <[email protected]>
Sent: 19 May 2020 14:04Quoted 33 lines · Paul Durrant
xen/include/xen/save.h new file +30
-0@@ -0,0 +1,165 @@ +/* +* save.h: support routines for save/restore +* +* Copyright Amazon.com Inc. or its affiliates. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along with +* this program; If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef XEN_SAVE_H +#define XEN_SAVE_H + +#include <xen/init.h> +#include <xen/sched.h> +#include <xen/types.h> + +#include <public/save.h> + +struct domain_context ; + +int domain_save_begin(struct domain_context *c, unsigned int typecode,Quoted 8 lines
xen/include/xen/save.h line 34
Quoted 4 lines
xen/include/xen/save.h new file +4
-0+ const char *name, unsigned int instance); + +#define DOMAIN_SAVE_BEGIN (_x, _c, _instance) \ + domain_save_begin((_c), DOMAIN_SAVE_CODE(_x), #_x, (_instance))As per prior conversation I would have expected no leading underscores here anymore, and no parenthesization of what is still _c. More of these further down.
Quoted 2 lines
What's wrong with leading underscores in macro arguments? They can't pollute any namespace.
Quoted 7 lines
They can still hide file scope variables legitimately named this way (which may get accessed by a macro without being a macro argument). The wording of the standard is quite clear:
"All identifiers that begin with an underscore are always reserved for use as identifiers with file scope in both the ordinary and tag name spaces."
Ok.
Quoted 5 lines
Quoted 1 line
Also, I prefer to keep the parentheses for arguments.
More code churn then once we hopefully standardize of the less obfuscating variant without.
If we standardize that way, so be it.
Quoted 55 lines
Quoted 15 lines
Quoted 5 lines
Quoted 5 lines
xen/include/xen/save.h new file +5
-0+static inline int domain_load_entry (struct domain_context *c, +unsigned int typecode,const char *name, +unsigned int *instance,void *dst, +size_t len) +{Quoted 9 lines
xen/include/xen/save.h line 77
Quoted 3 lines
xen/include/xen/save.h new file +3
-0+int rc; + + rc =domain_load_begin (c, typecode, name, instance);For some reason I've spotted this only here: Why is instance a pointer parameter of the function, when typecode is a value? Both live next to one another in struct
domain_save_descriptor, and hence instance could be retrieved at the same time as typecode.Quoted 5 lines
Because the typecode is known a priori. It has to be known for the correct handler to be invoked. It is only provided here for verification purposes. I could have provided the instance as an argument to the load handler but I prefer making the interactions for save and load more symmetric.
Hmm, I don't see any symmetry violation in the alternative model, but anyway.
Quoted 31 lines
Quoted 12 lines
Quoted 12 lines
xen/include/xen/save.h new file +12
-0+/* +* Register save and restore handlers. Save handlers will be invoked +* in order of DOMAIN_SAVE_CODE(). +*/ +#define DOMAIN_REGISTER_SAVE_RESTORE (_x, _save, _load) \ + static int __init __domain_register_##_x##_save_restore(void) \ + { \ + domain_register_save_type( \ + DOMAIN_SAVE_CODE(_x), \ + #_x, \ + &(_save), \ + &(_load)); \Quoted 8 lines
xen/include/xen/save.h line 124
Quoted 4 lines
xen/include/xen/save.h new file +4
-0+ \ +return 0 ; \ + } \ + __initcall(__domain_register_##_x##_save_restore);I'm puzzled by part of the comment: Invoking by save code looks reasonable for the saving side (albeit END doesn't match this rule afaics), but is this going to be good enough for the consuming side?
No, this only relates to the save side which is why the comment says 'Save handlers'. I do note that it would be more consistent to use 'load' rather than 'restore' here though.
Quoted 5 lines
There may be dependencies between types, and with fixed ordering there may be no way to insert a depended upon type ahead of an already defined one (at least as long as the codes are meant to be stable).
Quoted 8 lines
Quoted 2 lines
The ordering of load handlers is determined by the stream. I'll add a sentence saying that.
I.e. the consumer of the "get" interface (and producer of the stream) is supposed to take apart the output it gets, bring records into suitable order (which implies it knows of all the records, and which hence means this code may need updating in cases where I'd expect only the hypervisor needs), and only then issue to the stream?
The intention is that the stream is always in a suitable order so the load side does not have to do any re-ordering.
Paul
Re: [PATCH v3 1/5] xen/common: introduce a new framework for save/restore of 'domain' context
Quoted 42 lines · Paul Durrant
Quoted 42 lines
From: Jan Beulich <[email protected]>
Sent: 19 May 2020 15:24Quoted 37 lines · Paul Durrant
Quoted 16 lines
From: Jan Beulich <[email protected]>
Sent: 19 May 2020 14:04Quoted 12 lines · Paul Durrant
xen/include/xen/save.h new file +12
-0+/* +* Register save and restore handlers. Save handlers will be invoked +* in order of DOMAIN_SAVE_CODE(). +*/ +#define DOMAIN_REGISTER_SAVE_RESTORE (_x, _save, _load) \ + static int __init __domain_register_##_x##_save_restore(void) \ + { \ + domain_register_save_type( \ + DOMAIN_SAVE_CODE(_x), \ + #_x, \ + &(_save), \ + &(_load)); \Quoted 8 lines
xen/include/xen/save.h line 124
Quoted 4 lines
xen/include/xen/save.h new file +4
-0+ \ +return 0 ; \ + } \ + __initcall(__domain_register_##_x##_save_restore);I'm puzzled by part of the comment: Invoking by save code looks reasonable for the saving side (albeit END doesn't match this rule afaics), but is this going to be good enough for the consuming side?
No, this only relates to the save side which is why the comment says 'Save handlers'. I do note that it would be more consistent to use 'load' rather than 'restore' here though.
Quoted 5 lines
There may be dependencies between types, and with fixed ordering there may be no way to insert a depended upon type ahead of an already defined one (at least as long as the codes are meant to be stable).
The ordering of load handlers is determined by the stream. I'll add a sentence saying that.
Quoted 8 lines
Quoted 5 lines
I.e. the consumer of the "get" interface (and producer of the stream) is supposed to take apart the output it gets, bring records into suitable order (which implies it knows of all the records, and which hence means this code may need updating in cases where I'd expect only the hypervisor needs), and only then issue to the stream?
The intention is that the stream is always in a suitable order so the load side does not have to do any re-ordering.
I understood this to be the intention, but what I continue to not understand is where / how the save side orders it suitably. "Save handlers will be invoked in order of DOMAIN_SAVE_CODE()" does not allow for any ordering, unless at the time of the introduction of a particular code you already know what others it may depend on in the future, reserving appropriate codes.
And as said - END also doesn't look to fit this comment.
Jan
RE: [PATCH v3 1/5] xen/common: introduce a new framework for save/restore of 'domain' context
Quoted 63 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 19 May 2020 16:18
To: [email protected]
Cc: [email protected]; 'Paul Durrant' <[email protected]>; 'Andrew Cooper' <[email protected]>; 'George Dunlap' <[email protected]>; 'Ian Jackson' <[email protected]>; 'Julien Grall' <[email protected]>; 'Stefano Stabellini' <[email protected]>; 'Wei Liu' <[email protected]>; 'Volodymyr Babchuk' <[email protected]>; 'Roger Pau Monné' <[email protected]>
Subject: Re: [PATCH v3 1/5] xen/common: introduce a new framework for save/restore of 'domain' contextQuoted 42 lines · Paul Durrant
Quoted 42 lines
From: Jan Beulich <[email protected]>
Sent: 19 May 2020 15:24Quoted 37 lines · Paul Durrant
Quoted 16 lines
From: Jan Beulich <[email protected]>
Sent: 19 May 2020 14:04Quoted 12 lines · Paul Durrant
xen/include/xen/save.h new file +12
-0+/* +* Register save and restore handlers. Save handlers will be invoked +* in order of DOMAIN_SAVE_CODE(). +*/ +#define DOMAIN_REGISTER_SAVE_RESTORE (_x, _save, _load) \ + static int __init __domain_register_##_x##_save_restore(void) \ + { \ + domain_register_save_type( \ + DOMAIN_SAVE_CODE(_x), \ + #_x, \ + &(_save), \ + &(_load)); \Quoted 8 lines
xen/include/xen/save.h line 124
Quoted 4 lines
xen/include/xen/save.h new file +4
-0+ \ +return 0 ; \ + } \ + __initcall(__domain_register_##_x##_save_restore);I'm puzzled by part of the comment: Invoking by save code looks reasonable for the saving side (albeit END doesn't match this rule afaics), but is this going to be good enough for the consuming side?
No, this only relates to the save side which is why the comment says 'Save handlers'. I do note that it would be more consistent to use 'load' rather than 'restore' here though.
Quoted 5 lines
There may be dependencies between types, and with fixed ordering there may be no way to insert a depended upon type ahead of an already defined one (at least as long as the codes are meant to be stable).
The ordering of load handlers is determined by the stream. I'll add a sentence saying that.
Quoted 8 lines
Quoted 5 lines
I.e. the consumer of the "get" interface (and producer of the stream) is supposed to take apart the output it gets, bring records into suitable order (which implies it knows of all the records, and which hence means this code may need updating in cases where I'd expect only the hypervisor needs), and only then issue to the stream?
The intention is that the stream is always in a suitable order so the load side does not have to do any re-ordering.
Quoted 7 lines
I understood this to be the intention, but what I continue to not understand is where / how the save side orders it suitably. "Save handlers will be invoked in order of
DOMAIN_SAVE_CODE()" does not allow for any ordering, unless at the time of the introduction of a particular code you already know what others it may depend on in the future, reserving appropriate codes.
That's just how it is *now*. If a new code is defined that needs to be in the stream before one of the existing ones then we'll have to introduce a more elaborate scheme to deal with that at the time. Using the save code as the array index and iterating in that order is purely a convenience, and the load side does not depend on entries being in save code order.
Quoted 2 lines
And as said - END also doesn't look to fit this comment.
Ok, I can add a comment stating that exception.
Paul
Quoted 1 line
Jan
Re: [PATCH v3 1/5] xen/common: introduce a new framework for save/restore of 'domain' context
Quoted 71 lines · Paul Durrant
Quoted 63 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 19 May 2020 16:18
To: [email protected]
Cc: [email protected]; 'Paul Durrant' <[email protected]>; 'Andrew Cooper' <[email protected]>; 'George Dunlap' <[email protected]>; 'Ian Jackson' <[email protected]>; 'Julien Grall' <[email protected]>; 'Stefano Stabellini' <[email protected]>; 'Wei Liu' <[email protected]>; 'Volodymyr Babchuk' <[email protected]>; 'Roger Pau Monné' <[email protected]>
Subject: Re: [PATCH v3 1/5] xen/common: introduce a new framework for save/restore of 'domain' contextQuoted 42 lines · Paul Durrant
Quoted 42 lines
From: Jan Beulich <[email protected]>
Sent: 19 May 2020 15:24Quoted 37 lines · Paul Durrant
Quoted 16 lines
From: Jan Beulich <[email protected]>
Sent: 19 May 2020 14:04Quoted 12 lines · Paul Durrant
(quoted diff) +12
-0+/* + * Register save and restore handlers. Save handlers will be invoked + * in order of DOMAIN_SAVE_CODE(). + */ +#define DOMAIN_REGISTER_SAVE_RESTORE(_x, _save, _load) \ + static int __init __domain_register_##_x##_save_restore(void) \ + { \ + domain_register_save_type( \ + DOMAIN_SAVE_CODE(_x), \ + #_x, \ + &(_save), \ + &(_load)); \Quoted 8 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ \ + return 0; \ + } \ + __initcall(__domain_register_##_x##_save_restore);I'm puzzled by part of the comment: Invoking by save code looks reasonable for the saving side (albeit END doesn't match this rule afaics), but is this going to be good enough for the consuming side?
No, this only relates to the save side which is why the comment says 'Save handlers'. I do note that it would be more consistent to use 'load' rather than 'restore' here though.
Quoted 5 lines
There may be dependencies between types, and with fixed ordering there may be no way to insert a depended upon type ahead of an already defined one (at least as long as the codes are meant to be stable).
The ordering of load handlers is determined by the stream. I'll add a sentence saying that.
Quoted 8 lines
Quoted 5 lines
I.e. the consumer of the "get" interface (and producer of the stream) is supposed to take apart the output it gets, bring records into suitable order (which implies it knows of all the records, and which hence means this code may need updating in cases where I'd expect only the hypervisor needs), and only then issue to the stream?
The intention is that the stream is always in a suitable order so the load side does not have to do any re-ordering.
Quoted 7 lines
I understood this to be the intention, but what I continue to not understand is where / how the save side orders it suitably. "Save handlers will be invoked in order of
DOMAIN_SAVE_CODE()" does not allow for any ordering, unless at the time of the introduction of a particular code you already know what others it may depend on in the future, reserving appropriate codes.
Quoted 6 lines
That's just how it is *now*. If a new code is defined that needs to be in the stream before one of the existing ones then we'll have to introduce a more elaborate scheme to deal with that at the time. Using the save code as the array index and iterating in that order is purely a convenience, and the load side does not depend on entries being in save code order.
Could then you make the comment indicate so? This will allow people wanting to modify this do so more easily, without much digging in code or mail history.
Jan
RE: [PATCH v3 1/5] xen/common: introduce a new framework for save/restore of 'domain' context
Quoted 91 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 19 May 2020 16:37
To: [email protected]
Cc: [email protected]; 'Paul Durrant' <[email protected]>; 'Andrew Cooper' <[email protected]>; 'George Dunlap' <[email protected]>; 'Ian Jackson' <[email protected]>; 'Julien Grall' <[email protected]>; 'Stefano Stabellini' <[email protected]>; 'Wei Liu' <[email protected]>; 'Volodymyr Babchuk' <[email protected]>; 'Roger Pau Monné' <[email protected]>
Subject: Re: [PATCH v3 1/5] xen/common: introduce a new framework for save/restore of 'domain' contextQuoted 10 lines · Paul Durrant
Quoted 10 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 19 May 2020 16:18
To: [email protected]
Cc: [email protected]; 'Paul Durrant' <[email protected]>; 'Andrew Cooper' <[email protected]>; 'George Dunlap' <[email protected]>; 'Ian Jackson' <[email protected]>; 'Julien Grall' <[email protected]>; 'Stefano Stabellini' <[email protected]>; 'Wei Liu' <[email protected]>; 'Volodymyr Babchuk' <[email protected]>; 'Roger Pau Monné' <[email protected]>
Subject: Re: [PATCH v3 1/5] xen/common: introduce a new framework for save/restore of 'domain'context
Quoted 61 lines
Quoted 53 lines · Paul Durrant
Quoted 42 lines
Quoted 42 lines
From: Jan Beulich <[email protected]>
Sent: 19 May 2020 15:24Quoted 37 lines · Paul Durrant
Quoted 16 lines
From: Jan Beulich <[email protected]>
Sent: 19 May 2020 14:04Quoted 12 lines · Paul Durrant
(quoted diff) +12
-0+/* + * Register save and restore handlers. Save handlers will be invoked + * in order of DOMAIN_SAVE_CODE(). + */ +#define DOMAIN_REGISTER_SAVE_RESTORE(_x, _save, _load) \ + static int __init __domain_register_##_x##_save_restore(void) \ + { \ + domain_register_save_type( \ + DOMAIN_SAVE_CODE(_x), \ + #_x, \ + &(_save), \ + &(_load)); \Quoted 8 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ \ + return 0; \ + } \ + __initcall(__domain_register_##_x##_save_restore);I'm puzzled by part of the comment: Invoking by save code looks reasonable for the saving side (albeit END doesn't match this rule afaics), but is this going to be good enough for the consuming side?
No, this only relates to the save side which is why the comment says 'Save handlers'. I do note that it would be more consistent to use 'load' rather than 'restore' here though.
Quoted 5 lines
There may be dependencies between types, and with fixed ordering there may be no way to insert a depended upon type ahead of an already defined one (at least as long as the codes are meant to be stable).
The ordering of load handlers is determined by the stream. I'll add a sentence saying that.
Quoted 8 lines
Quoted 5 lines
I.e. the consumer of the "get" interface (and producer of the stream) is supposed to take apart the output it gets, bring records into suitable order (which implies it knows of all the records, and which hence means this code may need updating in cases where I'd expect only the hypervisor needs), and only then issue to the stream?
The intention is that the stream is always in a suitable order so the load side does not have to do any re-ordering.
Quoted 7 lines
I understood this to be the intention, but what I continue to not understand is where / how the save side orders it suitably. "Save handlers will be invoked in order of
DOMAIN_SAVE_CODE()" does not allow for any ordering, unless at the time of the introduction of a particular code you already know what others it may depend on in the future, reserving appropriate codes.Quoted 6 lines
That's just how it is *now*. If a new code is defined that needs to be in the stream before one of the existing ones then we'll have to introduce a more elaborate scheme to deal with that at the time. Using the save code as the array index and iterating in that order is purely a convenience, and the load side does not depend on entries being in save code order.
Quoted 3 lines
Could then you make the comment indicate so? This will allow people wanting to modify this do so more easily, without much digging in code or mail history.
Ok, I'll add some words to that effect.
Paul
Quoted 2 lines
Jan
PATCH v3 2/5 xen/common/domctl: introduce XEN_DOMCTL_get/setdomaincontext
In reply to Paul DurrantThese domctls provide a mechanism to get and set domain context from the toolstack.
---
Cc: Daniel De Graaf <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Stefano Stabellini <[email protected]>
v3:
- Addressed comments from Julien and Jan
- Use vmalloc() rather than xmalloc_bytes()
v2:
- drop mask parameter
- const-ify some more buffers
--- tools/flask/policy/modules/xen.if | 4 +- tools/libxc/include/xenctrl.h | 5 + tools/libxc/xc_domain.c | 54 +++++++++ xen/common/domctl.c | 167 ++++++++++++++++++++++++++++ xen/include/public/domctl.h | 41 +++++++ xen/xsm/flask/hooks.c | 6 + xen/xsm/flask/policy/access_vectors | 4 + 7 files changed, 279 insertions(+), 2 deletions(-)
tools/flask/policy/modules/xen.if +2 -2
@@ -53,7 +53,7 @@ define(`create_domain_common', ` allow $1 $2:domain2 { set_cpu_policy settsc setscheduler setclaim set_vnumainfo get_vnumainfo cacheflush psr_cmt_op psr_alloc soft_reset - resource_map get_cpu_policy }; + resource_map get_cpu_policy setcontext }; allow $1 $2:security check_context; allow $1 $2:shadow enable; allow $1 $2:mmu { map_read map_write adjust memorymap physmap pinpage mmuext_op updatemp };
@@ -97,7 +97,7 @@ define(`migrate_domain_out', ` allow $1 $2:hvm { gethvmc getparam }; allow $1 $2:mmu { stat pageinfo map_read }; allow $1 $2:domain { getaddrsize getvcpucontext pause destroy }; - allow $1 $2:domain2 gettsc; + allow $1 $2:domain2 { gettsc getcontext }; allow $1 $2:shadow { enable disable logdirty }; ')
tools/libxc/include/xenctrl.h +5 -0
@@ -867,6 +867,11 @@ int xc_domain_hvm_setcontext(xc_interface *xch,uint8_t *hvm_ctxt, uint32_t size); +int xc_domain_getcontext (xc_interface *xch,uint32_t domid, +void *ctxt_buf,size_t *size); +int xc_domain_setcontext (xc_interface *xch,uint32_t domid, +const void *ctxt_buf,size_t size); +/** * This function will return guest IO ABI protocol *
tools/libxc/xc_domain.c +54 -0
60 lines not on this page · raw message
xen/common/domctl.c +167 -0
185 lines not on this page · raw message
xen/include/public/domctl.h +41 -0
59 lines not on this page · raw message
xen/xsm/flask/hooks.c +6 -0
@@ -745,6 +745,12 @@ static int flask_domctl(struct domain *d, int cmd)case XEN_DOMCTL_get_cpu_policy:return current_has_perm (d,SECCLASS_DOMAIN2 ,DOMAIN2__GET_CPU_POLICY ); +case XEN_DOMCTL_setdomaincontext: +return current_has_perm (d,SECCLASS_DOMAIN2 ,DOMAIN2__SETCONTEXT ); + +case XEN_DOMCTL_getdomaincontext: +return current_has_perm (d,SECCLASS_DOMAIN2 ,DOMAIN2__GETCONTEXT ); +default :return avc_unknown_permission ("domctl" , cmd); }
xen/xsm/flask/policy/access_vectors +4 -0
@@ -245,6 +245,10 @@ class domain2 resource_map # XEN_DOMCTL_get_cpu_policy get_cpu_policy +# XEN_DOMCTL_setdomaincontext + setcontext +# XEN_DOMCTL_getdomaincontext + getcontext } # Similar to class domain, but primarily contains domctls related to HVM domains
Signature · 1 line
2.20.1
Re: [PATCH v3 2/5] xen/common/domctl: introduce XEN_DOMCTL_get/setdomaincontext
Quoted 13 lines · Paul Durrant
xen/include/public/domctl.h +7
-0@@ -1129,6 +1129,43 @@ struct xen_domctl_vuart_op {*/ }; +/* +* XEN_DOMCTL_getdomaincontext +* --------------------------- +* +* buffer (IN): The buffer into which the context data should be +* copied, or NULL to query the buffer size that should +* be allocated.
xen/include/public/domctl.h struct xen_domctl_vuart_op { · line 1148
Quoted 10 lines
xen/include/public/domctl.h +10
-0+* size (IN/OUT): If 'buffer' is NULL then the value passed in must be +* zero, and the value passed out will be the size of the +* buffer to allocate. +* If 'buffer' is non-NULL then the value passed in must +* be the size of the buffer into which data may be copied. +* The value passed out will be the size of data written. +*/ +struct xen_domctl_getdomaincontext { +uint32_t size; +uint32_t pad;
This and its counterpart don't seem to get checked to be zero. While an option for a domctl, any desire to use the field in the future would then require an interface version bump.
Jan
RE: [PATCH v3 2/5] xen/common/domctl: introduce XEN_DOMCTL_get/setdomaincontext
Quoted 30 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 19 May 2020 14:49
To: Paul Durrant <[email protected]>
Cc: [email protected]; Paul Durrant <[email protected]>; Daniel De Graaf <[email protected]>; Ian Jackson <[email protected]>; Wei Liu <[email protected]>; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>
Subject: Re: [PATCH v3 2/5] xen/common/domctl: introduce XEN_DOMCTL_get/setdomaincontextQuoted 19 lines · Paul Durrant
xen/include/public/domctl.h +13
-0@@ -1129,6 +1129,43 @@ struct xen_domctl_vuart_op {*/ }; +/* +* XEN_DOMCTL_getdomaincontext +* --------------------------- +* +* buffer (IN): The buffer into which the context data should be +* copied, or NULL to query the buffer size that should +* be allocated. +* size (IN/OUT): If 'buffer' is NULL then the value passed in must be +* zero, and the value passed out will be the size of the +* buffer to allocate. +* If 'buffer' is non-NULL then the value passed in must +* be the size of the buffer into which data may be copied. +* The value passed out will be the size of data written.
Quoted 9 lines
xen/include/public/domctl.h struct xen_domctl_vuart_op { · line 1148
Quoted 4 lines
xen/include/public/domctl.h +4
-0+*/ +struct xen_domctl_getdomaincontext { +uint32_t size; +uint32_t pad;This and its counterpart don't seem to get checked to be zero. While an option for a domctl, any desire to use the field in the future would then require an interface version bump.
Indeed. It does need to be zero checked.
Paul
Quoted 1 line
Jan
PATCH v3 3/5 tools/misc: add xen-domctx to present domain context
In reply to Paul DurrantThis tool is analogous to 'xen-hvmctx' which presents HVM context. Subsequent patches will add 'dump' functions when new records are introduced.
---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
v3:
- Re-worked to avoid copying onto stack
- Added optional typecode and instance arguments
v2:
- Change name from 'xen-ctx' to 'xen-domctx'
--- .gitignore | 1 + tools/misc/Makefile | 4 + tools/misc/xen-domctx.c | 200 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 205 insertions(+) create mode 100644 tools/misc/xen-domctx.c
.gitignore +1 -0
@@ -209,6 +209,7 @@ tools/misc/xen_cpuperf tools/misc/xen-cpuid tools/misc/xen-detect tools/misc/xen-diag +tools/misc/xen-domctx tools/misc/xen-tmem-list-parse tools/misc/xen-livepatch tools/misc/xenperf
tools/misc/Makefile +4 -0
@@ -30,6 +30,7 @@ INSTALL_SBIN += xenpm INSTALL_SBIN += xenwatchdogd INSTALL_SBIN += xen-livepatch INSTALL_SBIN += xen-diag +INSTALL_SBIN += xen-domctx INSTALL_SBIN += $(INSTALL_SBIN-y) # Everything to be installed in a private bin/
@@ -108,6 +109,9 @@ xen-livepatch: xen-livepatch.o xen-diag: xen-diag.o $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) +xen-domctx: xen-domctx.o + $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) + xen-lowmemd: xen-lowmemd.o $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(LDLIBS_libxenstore) $(APPEND_LDFLAGS)
tools/misc/xen-domctx.c new file +200 -0
200 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v3 4/5 common/domain: add a domain context record for shared_info...
In reply to Paul DurrantFrom: Paul Durrant <[email protected]>
... and update xen-domctx to dump some information describing the record.
NOTE: The domain may or may not be using the embedded vcpu_info array so
ultimately separate context records will be added for vcpu_info when this becomes necessary.
---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Stefano Stabellini <[email protected]>
v3:
- Actually dump some of the content of shared_info
v2:
- Drop the header change to define a 'Xen' page size and instead use a variable length struct now that the framework makes this is feasible
- Guard use of 'has_32bit_shinfo' in common code with CONFIG_COMPAT
--- tools/misc/xen-domctx.c | 73 +++++++++++++++++++++++++++++++++++++++ xen/common/domain.c | 60 ++++++++++++++++++++++++++++++++ xen/include/public/save.h | 11 +++++- 3 files changed, 143 insertions(+), 1 deletion(-)
tools/misc/xen-domctx.c +73 -0
@@ -31,6 +31,7 @@#include <errno.h> #include <xenctrl.h> +#include <xen-tools/libs.h> #include <xen/xen.h> #include <xen/domctl.h> #include <xen/save.h>
@@ -61,6 +62,76 @@ static void dump_header(void) } +static void print_binary (const char *prefix,void *val,size_t size, +const char *suffix) +{ +printf ("%s" , prefix); + +while (size--) + { +uint8_t octet = *(uint8_t *)val++; +unsigned int i; + +for ( i =0 ; i <8 ; i++ ) + { +printf ("%u" , octet &1 ); + octet >>=1 ; + } + } + +printf ("%s" , suffix); +} + +static void dump_shared_info (void ) +{ +DOMAIN_SAVE_TYPE (SHARED_INFO) *s; +shared_info_any_t *info; +unsigned int i; + +GET_PTR (s); + +printf (" SHARED_INFO: has_32bit_shinfo: %s buffer_size: %u\n" , + s->has_32bit_shinfo ?"true" :"false" , s->buffer_size); + + info = (shared_info_any_t *)s->buffer; + +#define GET_FIELD_PTR (_f) \ + (s->has_32bit_shinfo ? (void *)&(info->x32._f) : (void *)&(info->x64._f)) +#define GET_FIELD_SIZE (_f) \ + (s->has_32bit_shinfo ? sizeof(info->x32._f) : sizeof(info->x64._f)) +#define GET_FIELD (_f) \ + (s->has_32bit_shinfo ? info->x32._f : info->x64._f) + +/* Array lengths are the same for 32-bit and 64-bit shared info */ + +for ( i =0 ; i <ARRAY_SIZE (info->x64.evtchn_pending); i++ ) + { +const char *prefix = !i ? +" evtchn_pending: " : +" " ; + +print_binary (prefix,GET_FIELD_PTR (evtchn_pending[0 ]), +GET_FIELD_SIZE (evtchn_pending[0 ]),"\n" ); + } + +for ( i =0 ; i <ARRAY_SIZE (info->x64.evtchn_mask); i++ ) + { +const char *prefix = !i ? +" evtchn_mask: " : +" " ; + +print_binary (prefix,GET_FIELD_PTR (evtchn_mask[0 ]), +GET_FIELD_SIZE (evtchn_mask[0 ]),"\n" ); + } + +printf (" wc: version: %u sec: %u nsec: %u\n" , +GET_FIELD (wc_version),GET_FIELD (wc_sec),GET_FIELD (wc_nsec)); + +#undef GET_FIELD +#undef GET_FIELD_SIZE +#undef GET_FIELD_PTR +} +static void dump_end (void ) {DOMAIN_SAVE_TYPE (END) *e;
@@ -167,12 +238,14 @@ int main(int argc, char **argv)if ( (typecode <0 || typecode == desc->typecode) && (instance <0 || instance == desc->instance) ) { +printf ("[%u] type: %u instance: %u length: %u\n" , entry++, desc->typecode, desc->instance, desc->length);switch (desc->typecode) {case DOMAIN_SAVE_CODE (HEADER ):dump_header ();break ; +case DOMAIN_SAVE_CODE (SHARED_INFO ):dump_shared_info ();break ;case DOMAIN_SAVE_CODE (END ):dump_end ();break ;default :printf ("Unknown type %u: skipping\n" , desc->typecode);
xen/common/domain.c +60 -0
72 lines not on this page · raw message
xen/include/public/save.h +10 -1
@@ -73,7 +73,16 @@ struct domain_save_header { }; DECLARE_DOMAIN_SAVE_TYPE(HEADER, 1, struct domain_save_header); -#define DOMAIN_SAVE_CODE_MAX 1 +struct domain_shared_info_context { +uint8_t has_32bit_shinfo; +uint8_t pad[3 ]; +uint32_t buffer_size; +uint8_t buffer[XEN_FLEX_ARRAY_DIM ];/* Implementation specific size */ +}; + +DECLARE_DOMAIN_SAVE_TYPE(SHARED_INFO, 2, struct domain_shared_info_context); + +#define DOMAIN_SAVE_CODE_MAX 2#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */
Signature · 1 line
2.20.1
Re: [PATCH v3 4/5] common/domain: add a domain context record for shared_info...
tools/misc/xen-domctx.c static void dump_header(void) · line 65
Quoted 5 lines · Paul Durrant
tools/misc/xen-domctx.c +1
-0@@ -61,6 +62,76 @@ static void dump_header(void) } +static void print_binary(const char *prefix, void *val, size_t size,
const also for val?
tools/misc/xen-domctx.c static void dump_header(void) · line 70
Quoted 5 lines
tools/misc/xen-domctx.c +5
-0+ const char *suffix) +{ +printf ("%s" , prefix); + +while (size--)
Judging from style elsewhere you look to be missing two blanks here.
Review static void dump_header(void) · line 72
Quoted 2 lines
(quoted diff) +2
-0+ { + uint8_t octet = *(uint8_t *)val++;
Following the above then also better don't cast const away here.
Quoted 17 lines
tools/misc/xen-domctx.c +17
-0+unsigned int i; + +for ( i =0 ; i <8 ; i++ ) + { +printf ("%u" , octet &1 ); + octet >>=1 ; + } + } + +printf ("%s" , suffix); +} + +static void dump_shared_info (void ) +{ +DOMAIN_SAVE_TYPE (SHARED_INFO) *s; +shared_info_any_t *info; +unsigned int i;
tools/misc/xen-domctx.c static void dump_header(void) · line 99
Quoted 10 lines
tools/misc/xen-domctx.c +10
-0+ +GET_PTR (s); + +printf (" SHARED_INFO: has_32bit_shinfo: %s buffer_size: %u\n" , + s->has_32bit_shinfo ?"true" :"false" , s->buffer_size); + + info = (shared_info_any_t *)s->buffer; + +#define GET_FIELD_PTR (_f) \ + (s->has_32bit_shinfo ? (void *)&(info->x32._f) : (void *)&(info->x64._f))
Better cast to const void * ?
tools/misc/xen-domctx.c static void dump_header(void) · line 105
Quoted 6 lines
tools/misc/xen-domctx.c +6
-0+#define GET_FIELD_SIZE (_f) \ + (s->has_32bit_shinfo ? sizeof(info->x32._f) : sizeof(info->x64._f)) +#define GET_FIELD (_f) \ + (s->has_32bit_shinfo ? info->x32._f : info->x64._f) + +/* Array lengths are the same for 32-bit and 64-bit shared info */
Not really, no:
xen_ulong_t evtchn_pending[sizeof(xen_ulong_t) * 8];
xen_ulong_t evtchn_mask[sizeof(xen_ulong_t) * 8];tools/misc/xen-domctx.c int main(int argc, char **argv) · line 243
Quoted 7 lines
tools/misc/xen-domctx.c +1
-0@@ -167,12 +238,14 @@ int main(int argc, char **argv)if ( (typecode <0 || typecode == desc->typecode) && (instance <0 || instance == desc->instance) ) { +printf ("[%u] type: %u instance: %u length: %u\n" , entry++, desc->typecode, desc->instance, desc->length);
Stray insertion of a blank line?
xen/common/domain.c int continue_hypercall_on_cpu( · line 1656
Quoted 8 lines
xen/common/domain.c +4
-0@@ -1649,6 +1650,65 @@ int continue_hypercall_on_cpu(return 0 ; } +static int save_shared_info (const struct domain *d,struct domain_context *c, +bool dry_run) +{ +struct domain_shared_info_context ctxt = { .buffer_size =PAGE_SIZE };
Why not sizeof(shared_info), utilizing the zero padding on the receiving side?
xen/common/domain.c int continue_hypercall_on_cpu( · line 1667
Quoted 11 lines
xen/common/domain.c +11
-0+size_t hdr_size = offsetof(typeof (ctxt ), buffer); +int rc; + + rc =DOMAIN_SAVE_BEGIN (SHARED_INFO , c,0 ); +if ( rc ) +return rc; + +#ifdef CONFIG_COMPAT +if ( !dry_run ) + ctxt.has_32bit_shinfo =has_32bit_shinfo (d); +#endif
Nothing will go wrong without the if(), I suppose? Better drop it then? It could then also easily be part of the initializer of ctxt.
Quoted 23 lines
xen/common/domain.c +23
-0+ rc =domain_save_data (c, &ctxt, hdr_size); +if ( rc ) +return rc; + + rc =domain_save_data (c, d->shared_info, ctxt.buffer_size); +if ( rc ) +return rc; + +return domain_save_end (c); +} + +static int load_shared_info (struct domain *d,struct domain_context *c) +{ +struct domain_shared_info_context ctxt; +size_t hdr_size = offsetof(typeof (ctxt ), buffer); +unsigned int i; +int rc; + + rc =DOMAIN_LOAD_BEGIN (SHARED_INFO , c, &i); +if ( rc || i )/* expect only a single instance */ +return rc; + + rc =domain_load_data (c, &ctxt, hdr_size);
xen/common/domain.c int continue_hypercall_on_cpu( · line 1701
Quoted 10 lines
xen/common/domain.c +10
-0+if ( rc ) +return rc; + +if ( ctxt.pad[0 ] || ctxt.pad[1 ] || ctxt.pad[2 ] || + ctxt.buffer_size !=PAGE_SIZE ) +return -EINVAL ; + +#ifdef CONFIG_COMPAT + d->arch.has_32bit_shinfo = ctxt.has_32bit_shinfo; +#endif
There's nothing wrong with using has_32bit_shinfo(d) here as well.
xen/include/public/save.h struct domain_save_header { · line 78
Quoted 10 lines
xen/include/public/save.h +3
-1@@ -73,7 +73,16 @@ struct domain_save_header { }; DECLARE_DOMAIN_SAVE_TYPE(HEADER, 1, struct domain_save_header); -#define DOMAIN_SAVE_CODE_MAX 1 +struct domain_shared_info_context { +uint8_t has_32bit_shinfo; +uint8_t pad[3 ];
32-(or 16-)bit flags, with just a single bit used for the purpose?
Jan
RE: [PATCH v3 4/5] common/domain: add a domain context record for shared_info...
Quoted 10 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 19 May 2020 15:08
To: Paul Durrant <[email protected]>
Cc: [email protected]; Paul Durrant <[email protected]>; Ian Jackson <[email protected]>; Wei Liu <[email protected]>; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>
Subject: Re: [PATCH v3 4/5] common/domain: add a domain context record forshared_info...
Quoted 8 lines
tools/misc/xen-domctx.c static void dump_header(void) · line 65
Quoted 5 lines · Paul Durrant
tools/misc/xen-domctx.c +1
-0@@ -61,6 +62,76 @@ static void dump_header(void) } +static void print_binary(const char *prefix, void *val, size_t size,const also for val?
Yes, it can be.
Quoted 10 lines
tools/misc/xen-domctx.c static void dump_header(void) · line 70
Quoted 6 lines
tools/misc/xen-domctx.c +5
-0+ const char *suffix) +{ +printf ("%s" , prefix); + +while (size--)Judging from style elsewhere you look to be missing two blanks here.
Yes.
Quoted 26 lines
Review static void dump_header(void) · line 72
Quoted 2 lines
(quoted diff) +2
-0+ { + uint8_t octet = *(uint8_t *)val++;Following the above then also better don't cast const away here.
Quoted 21 lines
tools/misc/xen-domctx.c +21
-0+unsigned int i; + +for ( i =0 ; i <8 ; i++ ) + { +printf ("%u" , octet &1 ); + octet >>=1 ; + } + } + +printf ("%s" , suffix); +} + +static void dump_shared_info (void ) +{ +DOMAIN_SAVE_TYPE (SHARED_INFO) *s; +shared_info_any_t *info; +unsigned int i; + +GET_PTR (s); + + printf(" SHARED_INFO: has_32bit_shinfo: %s buffer_size: %u\n",
Quoted 9 lines
tools/misc/xen-domctx.c static void dump_header(void) · line 99
Quoted 6 lines
tools/misc/xen-domctx.c +6
-0+ s->has_32bit_shinfo ? "true" : "false", s->buffer_size); + + info = (shared_info_any_t *)s->buffer; + +#define GET_FIELD_PTR (_f) \ + (s->has_32bit_shinfo ? (void *)&(info->x32._f) : (void *)&(info->x64._f))Better cast to const void * ?
Ok.
Quoted 9 lines
tools/misc/xen-domctx.c static void dump_header(void) · line 105
Quoted 6 lines
tools/misc/xen-domctx.c +6
-0+#define GET_FIELD_SIZE (_f) \ + (s->has_32bit_shinfo ? sizeof(info->x32._f) : sizeof(info->x64._f)) +#define GET_FIELD (_f) \ + (s->has_32bit_shinfo ? info->x32._f : info->x64._f) + +/* Array lengths are the same for 32-bit and 64-bit shared info */ Not really, no:
Quoted 3 lines
xen_ulong_t evtchn_pending[sizeof(xen_ulong_t) * 8];
xen_ulong_t evtchn_mask[sizeof(xen_ulong_t) * 8];Oh, I must have misread.
Quoted 10 lines
tools/misc/xen-domctx.c int main(int argc, char **argv) · line 243
Quoted 7 lines
tools/misc/xen-domctx.c +1
-0@@ -167,12 +238,14 @@ int main(int argc, char **argv)if ( (typecode <0 || typecode == desc->typecode) && (instance <0 || instance == desc->instance) ) { +printf ("[%u] type: %u instance: %u length: %u\n" , entry++, desc->typecode, desc->instance, desc->length);Stray insertion of a blank line?
Yes.
Quoted 4 lines
Quoted 4 lines
xen/common/domain.c +0
-0@@ -1649,6 +1650,65 @@ int continue_hypercall_on_cpu(return 0 ; }
Quoted 8 lines
xen/common/domain.c int continue_hypercall_on_cpu( · line 1656
Quoted 4 lines
xen/common/domain.c +4
-0+static int save_shared_info (const struct domain *d,struct domain_context *c, +bool dry_run) +{ +struct domain_shared_info_context ctxt = { .buffer_size =PAGE_SIZE };Why not
sizeof(shared_info), utilizing the zero padding on the receiving side?
Ok, yes, I guess that would work.
Quoted 6 lines
Quoted 6 lines
xen/common/domain.c +6
-0+size_t hdr_size = offsetof(typeof (ctxt ), buffer); +int rc; + + rc =DOMAIN_SAVE_BEGIN (SHARED_INFO , c,0 ); +if ( rc ) +return rc;
Quoted 9 lines
xen/common/domain.c int continue_hypercall_on_cpu( · line 1667
Quoted 5 lines
xen/common/domain.c +5
-0+ +#ifdef CONFIG_COMPAT +if ( !dry_run ) + ctxt.has_32bit_shinfo =has_32bit_shinfo (d); +#endif Nothing will go wrong without the
if(), I suppose? Better drop it then? It could then also easily be part of the initializer of ctxt.
Ok. I said last time I wanted to keep it as it was illustrative but I'll drop it since it has now come up twice.
Quoted 27 lines
Quoted 27 lines
xen/common/domain.c +27
-0+ rc =domain_save_data (c, &ctxt, hdr_size); +if ( rc ) +return rc; + + rc =domain_save_data (c, d->shared_info, ctxt.buffer_size); +if ( rc ) +return rc; + +return domain_save_end (c); +} + +static int load_shared_info (struct domain *d,struct domain_context *c) +{ +struct domain_shared_info_context ctxt; +size_t hdr_size = offsetof(typeof (ctxt ), buffer); +unsigned int i; +int rc; + + rc =DOMAIN_LOAD_BEGIN (SHARED_INFO , c, &i); +if ( rc || i )/* expect only a single instance */ +return rc; + + rc =domain_load_data (c, &ctxt, hdr_size); +if ( rc ) +return rc; + + if ( ctxt.pad[0] || ctxt.pad[1] || ctxt.pad[2] ||
Quoted 9 lines
xen/common/domain.c int continue_hypercall_on_cpu( · line 1701
Quoted 6 lines
xen/common/domain.c +6
-0+ ctxt.buffer_size != PAGE_SIZE ) +return -EINVAL ; + +#ifdef CONFIG_COMPAT + d->arch.has_32bit_shinfo = ctxt.has_32bit_shinfo; +#endif There's nothing wrong with using
has_32bit_shinfo(d)here as well.
I just thought it looked odd.
Quoted 6 lines
Quoted 6 lines
xen/include/public/save.h +0
-0@@ -73,7 +73,16 @@ struct domain_save_header { }; DECLARE_DOMAIN_SAVE_TYPE(HEADER, 1, struct domain_save_header);
Quoted 7 lines
xen/include/public/save.h struct domain_save_header { · line 78
Quoted 4 lines
xen/include/public/save.h +3
-1-#define DOMAIN_SAVE_CODE_MAX 1 +struct domain_shared_info_context { +uint8_t has_32bit_shinfo; +uint8_t pad[3 ];32-(or 16-)bit flags, with just a single bit used for the purpose?
I debated that. Given this is xen/tools-only would a bit-field be acceptable?
Paul
Quoted 1 line
Jan
Re: [PATCH v3 4/5] common/domain: add a domain context record for shared_info...
Quoted 18 lines · Paul Durrant
Quoted 10 lines
From: Jan Beulich <[email protected]>
Sent: 19 May 2020 15:08Quoted 6 lines · Paul Durrant
xen/include/public/save.h +0
-0@@ -73,7 +73,16 @@ struct domain_save_header { }; DECLARE_DOMAIN_SAVE_TYPE(HEADER, 1, struct domain_save_header);Quoted 7 lines
xen/include/public/save.h struct domain_save_header { · line 78
Quoted 4 lines
xen/include/public/save.h +3
-1-#define DOMAIN_SAVE_CODE_MAX 1 +struct domain_shared_info_context { +uint8_t has_32bit_shinfo; +uint8_t pad[3 ];32-(or 16-)bit flags, with just a single bit used for the purpose?
Quoted 1 line
I debated that. Given this is xen/tools-only would a bit-field be acceptable?
Looking at domctl.h and sysctl.h, the only instance I can find is a live-patching struct, and I'd suppose the addition of bitfields there was missed in the hasty review back then. While it might be acceptable, I'd recommend against it. It'll bite us the latest with a port to an arch where endianness is not fixed, and hence may vary between hypercall caller and callee. The standard way of using #define-s looks more future proof.
Jan
RE: [PATCH v3 4/5] common/domain: add a domain context record for shared_info...
Quoted 31 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 19 May 2020 16:34
To: [email protected]
Cc: [email protected]; 'Paul Durrant' <[email protected]>; 'Ian Jackson' <[email protected]>; 'Wei Liu' <[email protected]>; 'Andrew Cooper' <[email protected]>; 'George Dunlap' <[email protected]>; 'Julien Grall' <[email protected]>; 'Stefano Stabellini' <[email protected]>
Subject: Re: [PATCH v3 4/5] common/domain: add a domain context record forshared_info...Quoted 18 lines · Paul Durrant
Quoted 10 lines
From: Jan Beulich <[email protected]>
Sent: 19 May 2020 15:08Quoted 6 lines · Paul Durrant
xen/include/public/save.h +0
-0@@ -73,7 +73,16 @@ struct domain_save_header { }; DECLARE_DOMAIN_SAVE_TYPE(HEADER, 1, struct domain_save_header);Quoted 7 lines
xen/include/public/save.h struct domain_save_header { · line 78
Quoted 4 lines
xen/include/public/save.h +3
-1-#define DOMAIN_SAVE_CODE_MAX 1 +struct domain_shared_info_context { +uint8_t has_32bit_shinfo; +uint8_t pad[3 ];32-(or 16-)bit flags, with just a single bit used for the purpose?
Quoted 1 line
I debated that. Given this is xen/tools-only would a bit-field be acceptable?
Quoted 8 lines
Looking at
domctl.handsysctl.h, the only instance I can find is a live-patching struct, and I'd suppose the addition of bitfields there was missed in the hasty review back then. While it might be acceptable, I'd recommend against it. It'll bite us the latest with a port to an arch where endianness is not fixed, and hence may vary between hypercall caller and callee. The standard way of using #define-s looks more future proof.
Ok, I'll go with a flag. Probably is better in the long run.
Paul
Quoted 1 line
Jan
PATCH v3 5/5 tools/libxc: make use of domain context SHARED_INFO record...
In reply to Paul Durrant... in the save/restore code.
This patch replaces direct mapping of the shared_info_frame (retrieved using XEN_DOMCTL_getdomaininfo) with save/load of the domain context SHARED_INFO record.
No modifications are made to the definition of the migration stream at this point. Subsequent patches will define a record in the libxc domain image format for passing domain context and convert the save/restore code to use that.
---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
v3:
- Moved basic get/set domain context functions to common code
v2:
- Re-based (now making use of DOMAIN_SAVE_FLAG_IGNORE)
--- tools/libxc/xc_sr_common.c | 58 ++++++++++++++++++++++++++++++ tools/libxc/xc_sr_common.h | 11 +++++- tools/libxc/xc_sr_common_x86_pv.c | 47 ++++++++++++++++++++++++ tools/libxc/xc_sr_common_x86_pv.h | 3 ++ tools/libxc/xc_sr_restore_x86_pv.c | 40 ++++++++------------- tools/libxc/xc_sr_save_x86_pv.c | 26 ++------------ tools/libxc/xg_save_restore.h | 1 + 7 files changed, 137 insertions(+), 49 deletions(-)
tools/libxc/xc_sr_common.c +58 -0
@@ -138,6 +138,64 @@ int read_record(struct xc_sr_context *ctx, int fd, struct xc_sr_record *rec)return 0 ; }; +int get_domain_context (struct xc_sr_context *ctx) +{ +xc_interface *xch = ctx->xch; +size_t len =0 ; +int rc; + +if ( ctx->domain_context.buffer ) + { +ERROR ("Domain context already present" ); +return -1 ; + } + + rc =xc_domain_getcontext (xch, ctx->domid,NULL , &len); +if ( rc <0 ) + { +PERROR ("Unable to get size of domain context" ); +return -1 ; + } + + ctx->domain_context.buffer =malloc (len); +if ( !ctx->domain_context.buffer ) + { +PERROR ("Unable to allocate memory for domain context" ); +return -1 ; + } + + rc =xc_domain_getcontext (xch, ctx->domid, ctx->domain_context.buffer, + &len); +if ( rc <0 ) + { +PERROR ("Unable to get domain context" ); +return -1 ; + } + + ctx->domain_context.len = len; + +return 0 ; +} + +int set_domain_context (struct xc_sr_context *ctx) +{ +xc_interface *xch = ctx->xch; + +if ( !ctx->domain_context.buffer ) + { +ERROR ("Domain context not present" ); +return -1 ; + } + +return xc_domain_setcontext (xch, ctx->domid, ctx->domain_context.buffer, + ctx->domain_context.len); +} + +void common_cleanup (struct xc_sr_context *ctx) +{ +free (ctx->domain_context.buffer); +} +static void __attribute__((unused))build_assertions (void ) {BUILD_BUG_ON (sizeof (struct xc_sr_ihdr ) !=24 );
tools/libxc/xc_sr_common.h +10 -1
@@ -208,6 +208,11 @@ struct xc_sr_contextxc_dominfo_t dominfo; +struct { +void *buffer; +unsigned int len; + } domain_context; +union /* Common save or restore data. */ { struct /* Save data. */
@@ -314,7 +319,7 @@ struct xc_sr_context/* The guest pfns containing the p2m leaves */ xen_pfn_t *p2m_pfns; -/* Read-only mapping of guests shared info page */ +/* Pointer to shared_info (located in context buffer) */ shared_info_any_t *shinfo;/* p2m generation count for verifying validity of local p2m. */
@@ -425,6 +430,10 @@ int read_record(struct xc_sr_context *ctx, int fd, struct xc_sr_record *rec);int populate_pfns (struct xc_sr_context *ctx,unsigned int count,const xen_pfn_t *original_pfns,const uint32_t *types); +int get_domain_context (struct xc_sr_context *ctx); +int set_domain_context (struct xc_sr_context *ctx); +void common_cleanup (struct xc_sr_context *ctx); +#endif /* * Local variables:
tools/libxc/xc_sr_common_x86_pv.c +47 -0
53 lines not on this page · raw message
tools/libxc/xc_sr_common_x86_pv.h +3 -0
@@ -97,6 +97,9 @@ int x86_pv_domain_info(struct xc_sr_context *ctx);*/ int x86_pv_map_m2p (struct xc_sr_context *ctx); +int x86_pv_get_shinfo (struct xc_sr_context *ctx); +int x86_pv_set_shinfo (struct xc_sr_context *ctx); +#endif /* * Local variables:
tools/libxc/xc_sr_restore_x86_pv.c +15 -25
@@ -864,8 +864,7 @@ static int handle_shared_info(struct xc_sr_context *ctx, {xc_interface *xch = ctx->xch;unsigned int i; -int rc =-1 ; -shared_info_any_t *guest_shinfo =NULL ; +int rc;const shared_info_any_t *old_shinfo = rec->data;if ( !ctx->x86.pv.restore.seen_pv_info )
@@ -878,39 +877,30 @@ static int handle_shared_info(struct xc_sr_context *ctx, {ERROR ("X86_PV_SHARED_INFO record wrong size: length %u" ", expected 4096" , rec->length); - goto err; +return -1 ; } - guest_shinfo =xc_map_foreign_range ( - xch, ctx->domid,PAGE_SIZE ,PROT_READ |PROT_WRITE , - ctx->dominfo.shared_info_frame); -if ( !guest_shinfo ) - { -PERROR ("Failed to map Shared Info at mfn %#lx" , - ctx->dominfo.shared_info_frame); - goto err; - } + rc =x86_pv_get_shinfo (ctx); +if ( rc ) +return rc; -MEMCPY_FIELD (guest_shinfo, old_shinfo, vcpu_info, ctx->x86.pv.width); -MEMCPY_FIELD (guest_shinfo, old_shinfo, arch, ctx->x86.pv.width); +MEMCPY_FIELD (ctx->x86.pv.shinfo, old_shinfo, vcpu_info, + ctx->x86.pv.width); +MEMCPY_FIELD (ctx->x86.pv.shinfo, old_shinfo, arch, ctx->x86.pv.width); -SET_FIELD (guest_shinfo, arch.pfn_to_mfn_frame_list_list, +SET_FIELD (ctx->x86.pv.shinfo, arch.pfn_to_mfn_frame_list_list,0 , ctx->x86.pv.width); -MEMSET_ARRAY_FIELD (guest_shinfo, evtchn_pending,0 , ctx->x86.pv.width); +MEMSET_ARRAY_FIELD (ctx->x86.pv.shinfo, evtchn_pending,0 , + ctx->x86.pv.width);for ( i =0 ; i <XEN_LEGACY_MAX_VCPUS ; i++ ) -SET_FIELD (guest_shinfo, vcpu_info[i].evtchn_pending_sel, +SET_FIELD (ctx->x86.pv.shinfo, vcpu_info[i].evtchn_pending_sel,0 , ctx->x86.pv.width); -MEMSET_ARRAY_FIELD (guest_shinfo, evtchn_mask,0xff , ctx->x86.pv.width); - - rc =0 ; +MEMSET_ARRAY_FIELD (ctx->x86.pv.shinfo, evtchn_mask,0xff , + ctx->x86.pv.width); - err: -if ( guest_shinfo ) -munmap (guest_shinfo,PAGE_SIZE ); - -return rc; +return x86_pv_set_shinfo (ctx); }/* restore_ops function. */
tools/libxc/xc_sr_save_x86_pv.c +3 -23
@@ -9,25 +9,6 @@ static inline bool is_canonical_address(xen_vaddr_t vaddr)return ((int64_t )vaddr >>47 ) == ((int64_t )vaddr >>63 ); } -/* -* Maps the guests shared info page. -*/ -static int map_shinfo (struct xc_sr_context *ctx) -{ -xc_interface *xch = ctx->xch; - - ctx->x86.pv.shinfo =xc_map_foreign_range ( - xch, ctx->domid,PAGE_SIZE ,PROT_READ , ctx->dominfo.shared_info_frame); -if ( !ctx->x86.pv.shinfo ) - { -PERROR ("Failed to map shared info frame at mfn %#lx" , - ctx->dominfo.shared_info_frame); -return -1 ; - } - -return 0 ; -} -/* * Copy a list of mfns from a guest, accounting for differences between guest * and toolstack width. Can fail if truncation would occur.
@@ -1041,7 +1022,7 @@ static int x86_pv_setup(struct xc_sr_context *ctx)if ( rc )return rc; - rc =map_shinfo (ctx); + rc =x86_pv_get_shinfo (ctx);if ( rc )return rc;
@@ -1112,12 +1093,11 @@ static int x86_pv_cleanup(struct xc_sr_context *ctx)if ( ctx->x86.pv.p2m )munmap (ctx->x86.pv.p2m, ctx->x86.pv.p2m_frames *PAGE_SIZE ); -if ( ctx->x86.pv.shinfo ) -munmap (ctx->x86.pv.shinfo,PAGE_SIZE ); -if ( ctx->x86.pv.m2p )munmap (ctx->x86.pv.m2p, ctx->x86.pv.nr_m2p_frames *PAGE_SIZE ); +common_cleanup (ctx); +return 0 ; }
tools/libxc/xg_save_restore.h +1 -0
@@ -19,6 +19,7 @@#include <xen/foreign/x86_32.h> #include <xen/foreign/x86_64.h> +#include <xen/save.h> /* ** We process save/restore/migrate in batches of pages; the below
Signature · 1 line
2.20.1