Allow setting up shared memory areas between VMs from xl config files
v2 cover Allow setting up shared memory areas between VMs from xl config files
This series implements the new xl config entry proposed in [1]. Users can use the new config entry to statically setup shared memory areas among VMs that don't have grant table support so that they could communicate with each other through the static shared memory areas.
[1] Proposla to allow setting up shared memory areas between VMs from xl config file:
https://lists.xen.org/archives/html/xen-devel/2017-08/msg03242.html
v2:
* fixed several code style issues.
* introduce MMU__SHARE_MEM in flask av permissions, and add a check to this. permission in the flask hook for xsm_map_gmfn_foreign.
* support rolling back during creation on partial failure.
* refcounting the sshm path instead of using "alive" and "zombie" to label the master and counting the slaves.
Cheers,
Zhongze Liu (6):
libxc: add xc_domain_remove_from_physmap to wrap
XENMEM_remove_from_physmap
libxl: introduce a new structure to represent static shared memory
regions
libxl:xl: add parsing code to parse "libxl_static_sshm" from xl config
files
xsm: flask: change the dummy xsm policy and flask hook for
map_gmfn_foregin
libxl: support mapping static shared memory areas during domain
creation
libxl: support unmapping static shared memory areas during domain
destruction
tools/flask/policy/modules/xen.if | 2 + tools/libxc/include/xenctrl.h | 4 + tools/libxc/xc_domain.c | 11 + tools/libxl/Makefile | 4 +- tools/libxl/libxl.h | 4 + tools/libxl/libxl_arch.h | 6 + tools/libxl/libxl_arm.c | 15 ++ tools/libxl/libxl_create.c | 27 ++ tools/libxl/libxl_domain.c | 5 + tools/libxl/libxl_internal.h | 15 ++ tools/libxl/libxl_sshm.c | 480 ++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_types.idl | 34 ++- tools/libxl/libxl_x86.c | 18 ++ tools/libxl/libxlu_sshm.c | 210 ++++++++++++++++ tools/libxl/libxlutil.h | 6 + tools/xl/xl_parse.c | 24 +- xen/arch/arm/mm.c | 2 +- xen/arch/x86/mm/p2m.c | 2 +- xen/include/xsm/dummy.h | 8 +- xen/include/xsm/xsm.h | 7 +- xen/xsm/flask/hooks.c | 10 +- xen/xsm/flask/policy/access_vectors | 4 + 22 files changed, 883 insertions(+), 15 deletions(-) create mode 100644 tools/libxl/libxl_sshm.c create mode 100644 tools/libxl/libxlu_sshm.c
Signature · 7 lines
2.14.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v2 1/6 libxc: add xc_domain_remove_from_physmap to wrap XENMEM_remove_from_physmap
This is for the proposal "Allow setting up shared memory areas between VMs from xl config file". See:
https://lists.xen.org/archives/html/xen-devel/2017-08/msg03242.html
Then plan is to use XENMEM_add_to_physmap_batch to map the shared pages from one domU to another and use XENMEM_remove_from_physmap to cancel the sharing. A wrapper to XENMEM_add_to_physmap_batch was added in the following commit:
commit 20e725e9364cff4a29945f66986ecd88cca8743d
Now add the wrapper to XENMEM_remove_from_physmap.
--- tools/libxc/include/xenctrl.h | 4 ++++ tools/libxc/xc_domain.c | 11 +++++++++++ 2 files changed, 15 insertions(+)
tools/libxc/include/xenctrl.h +4 -0
@@ -1381,6 +1381,10 @@ int xc_domain_add_to_physmap_batch(xc_interface *xch, xen_pfn_t *gfpns, int *errs); +int xc_domain_remove_from_physmap (xc_interface *xch, +domid_t domid, +xen_pfn_t gpfn); + int xc_domain_populate_physmap(xc_interface *xch, uint32_t domid, unsigned long nr_extents,
tools/libxc/xc_domain.c +11 -0
@@ -1077,6 +1077,17 @@ out:return rc; } +int xc_domain_remove_from_physmap (xc_interface *xch, +domid_t domid, +xen_pfn_t gpfn) +{ +struct xen_remove_from_physmap xrfp = { + .domid = domid, + .gpfn = gpfn, + }; +return do_memory_op (xch, XENMEM_remove_from_physmap, &xrfp,sizeof (xrfp)); +} +int xc_domain_claim_pages (xc_interface *xch,uint32_t domid,unsigned long nr_pages)
Signature · 7 lines
2.14.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v2 2/6 libxl: introduce a new structure to represent static shared memory regions
In reply to Zhongze LiuAdd a new structure to the IDL familiy to represent static shared memory regions as proposed in the proposal "Allow setting up shared memory areas between VMs from xl config file" (see [1]).
Also fix some code style issues (indentation, trailling whitespaces).
[1] https://lists.xen.org/archives/html/xen-devel/2017-08/msg03242.html
---
v2: mention in the commit msg that several style corrections have been done
--- tools/libxl/libxl.h | 4 ++++ tools/libxl/libxl_types.idl | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-)
tools/libxl/libxl.h +4 -0
@@ -2237,6 +2237,10 @@ int libxl_fd_set_nonblock(libxl_ctx *ctx, int fd, int nonblock);int libxl_qemu_monitor_command (libxl_ctx *ctx,uint32_t domid,const char *command_line,char **output); +/* Constants for libxl_static_shm */ +#define LIBXL_SSHM_RANGE_UNKNOWN UINT64_MAX +#define LIBXL_SSHM_ID_MAXLEN 128 +#include <libxl_event.h> #endif /* LIBXL_H */
tools/libxl/libxl_types.idl +31 -3
@@ -472,7 +472,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("blkdev_start", string), ("vnuma_nodes", Array(libxl_vnode_info, "num_vnuma_nodes")), - + ("device_model_version", libxl_device_model_version), ("device_model_stubdomain", libxl_defbool), # if you set device_model you must set device_model_version too
@@ -543,10 +543,10 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("keymap", string), ("sdl", libxl_sdl_info), ("spice", libxl_spice_info), - + ("gfx_passthru", libxl_defbool), ("gfx_passthru_kind", libxl_gfx_passthru_kind), - + ("serial", string), ("boot", string), ("usb", libxl_defbool),
@@ -779,6 +779,33 @@ libxl_device_channel = Struct("device_channel", [ ])), ]) +libxl_sshm_cachepolicy = Enumeration("sshm_cachepolicy", [ + (-1, "UNKNOWN"), + (0, "ARM_NORMAL"), # ARM policies should be < 32 + (32, "X86_NORMAL"), # X86 policies should be >= 32 + ], init_val = "LIBXL_SSHM_CHCHE_POLICY_UNKNOWN") + +libxl_sshm_prot = Enumeration("sshm_prot", [ + (-1, "UNKNOWN"), + (3, "RW"), + ], init_val = "LIBXL_SSHM_PROT_UNKNOWN") + +libxl_sshm_role = Enumeration("sshm_role", [ + (-1, "UNKNOWN"), + (0, "MASTER"), + (1, "SLAVE"), + ], init_val = "LIBXL_SSHM_ROLE_UNKNOWN") + +libxl_static_shm = Struct("static_shm", [ + ("id", string), + ("offset", uint64, {'init_val': 'LIBXL_SSHM_RANGE_UNKNOWN'}), + ("begin", uint64, {'init_val': 'LIBXL_SSHM_RANGE_UNKNOWN'}), + ("end", uint64, {'init_val': 'LIBXL_SSHM_RANGE_UNKNOWN'}), + ("prot", libxl_sshm_prot, {'init_val': 'LIBXL_SSHM_PROT_UNKNOWN'}), + ("cache_policy", libxl_sshm_cachepolicy, {'init_val': 'LIBXL_SSHM_CACHEPOLICY_UNKNOWN'}), + ("role", libxl_sshm_role, {'init_val': 'LIBXL_SSHM_ROLE_UNKNOWN'}), +]) + libxl_domain_config = Struct("domain_config", [ ("c_info", libxl_domain_create_info), ("b_info", libxl_domain_build_info),
@@ -797,6 +824,7 @@ libxl_domain_config = Struct("domain_config", [ ("channels", Array(libxl_device_channel, "num_channels")), ("usbctrls", Array(libxl_device_usbctrl, "num_usbctrls")), ("usbdevs", Array(libxl_device_usbdev, "num_usbdevs")), + ("sshms", Array(libxl_static_shm, "num_sshms")), ("on_poweroff", libxl_action_on_shutdown), ("on_reboot", libxl_action_on_shutdown),
Signature · 7 lines
2.14.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v2 3/6 libxl:xl: add parsing code to parse "libxl_static_sshm" from xl config files
In reply to Zhongze LiuAdd the parsing utils for the newly introduced libxl_static_sshm struct to the libxl/libxlu_* family. And add realated parsing code in xl to parse the struct from xl config files. This is for the proposal "Allow setting up shared memory areas between VMs from xl config file" (see [1]).
[1] https://lists.xen.org/archives/html/xen-devel/2017-08/msg03242.html
---
v2:
* fix all the 'Yoda conditions'
* use the predefined XC_PAGE_MASK instead of defining a new one
--- tools/libxl/Makefile | 2 +- tools/libxl/libxlu_sshm.c | 210 ++++++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxlutil.h | 6 ++ tools/xl/xl_parse.c | 24 +++++- 4 files changed, 240 insertions(+), 2 deletions(-) create mode 100644 tools/libxl/libxlu_sshm.c
tools/libxl/Makefile +1 -1
@@ -175,7 +175,7 @@ AUTOINCS= libxlu_cfg_y.h libxlu_cfg_l.h _libxl_list.h _paths.h \ AUTOSRCS= libxlu_cfg_y.c libxlu_cfg_l.c AUTOSRCS += _libxl_save_msgs_callout.c _libxl_save_msgs_helper.c LIBXLU_OBJS = libxlu_cfg_y.o libxlu_cfg_l.o libxlu_cfg.o \ - libxlu_disk_l.o libxlu_disk.o libxlu_vif.o libxlu_pci.o + libxlu_disk_l.o libxlu_disk.o libxlu_vif.o libxlu_pci.o libxlu_sshm.o $(LIBXLU_OBJS): CFLAGS += $(CFLAGS_libxenctrl) # For xentoollog.h $(TEST_PROG_OBJS) _libxl.api-for-check: CFLAGS += $(CFLAGS_libxentoollog)
tools/libxl/libxlu_sshm.c new file +210 -0
210 lines not on this page · raw message
tools/libxl/libxlutil.h +6 -0
@@ -118,6 +118,12 @@ int xlu_rdm_parse(XLU_Config *cfg, libxl_rdm_reserve *rdm, const char *str);int xlu_vif_parse_rate (XLU_Config *cfg,const char *rate,libxl_device_nic *nic); +/* +* static shared memory specification parsing +*/ +int xlu_sshm_parse (XLU_Config *cfg,const char *spec, +libxl_static_shm *sshm); +#endif /* LIBXLUTIL_H */ /*
tools/xl/xl_parse.c +23 -1
@@ -813,7 +813,7 @@ void parse_config_data(const char *config_source,long l, vcpus =0 ;XLU_Config *config;XLU_ConfigList *cpus, *vbds, *nics, *pcis, *cvfbs, *cpuids, *vtpms, - *usbctrls, *usbdevs, *p9devs; + *usbctrls, *usbdevs, *p9devs, *sshms;XLU_ConfigList *channels, *ioports, *irqs, *iomem, *viridian, *dtdevs, *mca_caps;int num_ioports, num_irqs, num_iomem, num_cpus, num_viridian, num_mca_caps;
@@ -1392,6 +1392,28 @@ void parse_config_data(const char *config_source, } } +if (!xlu_cfg_get_list (config,"static_shm" , &sshms,0 ,0 )) { + d_config->num_sshms =0 ; + d_config->sshms =NULL ; +while ((buf =xlu_cfg_get_listitem (sshms, d_config->num_sshms)) !=NULL ) { +libxl_static_shm *sshm; +char *buf2 =strdup (buf); +int ret; + + sshm =ARRAY_EXTEND_INIT_NODEVID (d_config->sshms, + d_config->num_sshms, + libxl_static_shm_init); + ret =xlu_sshm_parse (config, buf2, sshm); +if (ret) { +fprintf (stderr, +"xl: Invalid argument for static_shm: %s" , buf2); +exit (EXIT_FAILURE ); + } + +free (buf2); + } + } +if (!xlu_cfg_get_list (config,"p9" , &p9devs,0 ,0 )) {libxl_device_p9 *p9;char *security_model =NULL ;
Signature · 7 lines
2.14.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v2 3/6] libxl:xl: add parsing code to parse "libxl_static_sshm" from xl config files
Quoted 8 lines · Zhongze Liu
Add the parsing utils for the newly introduced
libxl_static_sshmstruct to the libxl/libxlu_* family. And add realated parsing code in xl to parse the struct from xl config files. This is for the proposal "Allow setting up shared memory areas between VMs from xl config file" (see [1]).[1] https://lists.xen.org/archives/html/xen-devel/2017-08/msg03242.html
Signed-off-by Zhongze Liu <[email protected]>
I am wondering if there is a chance to extract the key=value parsing into standalone function and use it everywhere though.
Quoted 11 lines
Cc Andrew Cooper <[email protected]>Cc George Dunlap <[email protected]>Cc Ian Jackson <[email protected]>Cc Jan Beulich <[email protected]>Cc Konrad Rzeszutek Wilk <[email protected]>Cc Stefano Stabellini <[email protected]>Cc Tim Deegan <[email protected]>Cc Wei Liu <[email protected]>Cc Julien Grall <[email protected]>
Correctly trim your CC list next time please. A lot of hypervisor people don't need to get CCed on this patch.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v2 3/6] libxl:xl: add parsing code to parse "libxl_static_sshm" from xl config files
2017-09-02 0:03 GMT+08:00 Wei Liu <[email protected]>:
Quoted 6 lines · Zhongze Liu
Quoted 5 lines
Add the parsing utils for the newly introduced
libxl_static_sshmstruct to the libxl/libxlu_* family. And add realated parsing code in xl to parse the struct from xl config files. This is for the proposal "Allow setting up shared memory areas between VMs from xl config file" (see [1]).
Quoted 8 lines
Quoted 3 lines
[1] https://lists.xen.org/archives/html/xen-devel/2017-08/msg03242.html
Signed-off-by Zhongze Liu <[email protected]>Acked-by Wei Liu <[email protected]>I am wondering if there is a chance to extract the key=value parsing into standalone function and use it everywhere though.
I think this is a good idea.
Quoted 13 lines
Quoted 12 lines
Cc Andrew Cooper <[email protected]>Cc George Dunlap <[email protected]>Cc Ian Jackson <[email protected]>Cc Jan Beulich <[email protected]>Cc Konrad Rzeszutek Wilk <[email protected]>Cc Stefano Stabellini <[email protected]>Cc Tim Deegan <[email protected]>Cc Wei Liu <[email protected]>Cc Julien Grall <[email protected]>
Quoted 2 lines
Correctly trim your CC list next time please. A lot of hypervisor people don't need to get CCed on this patch.
Actually, this list is generated by get_maintainer.pl. Maybe next time I should go carefully through the list and remove some of the names manually.
Cheers,
Zhongze Liu
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v2 3/6] libxl:xl: add parsing code to parse "libxl_static_sshm" from xl config files
Quoted 9 lines · Zhongze Liu
2017-09-02 0:03 GMT+08:00 Wei Liu <[email protected]>:
Quoted 8 lines · Zhongze Liu
Quoted 7 lines
Add the parsing utils for the newly introduced
libxl_static_sshmstruct to the libxl/libxlu_* family. And add realated parsing code in xl to parse the struct from xl config files. This is for the proposal "Allow setting up shared memory areas between VMs from xl config file" (see [1]).[1] https://lists.xen.org/archives/html/xen-devel/2017-08/msg03242.html
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Signed-off-by Zhongze Liu <[email protected]>Acked-by Wei Liu <[email protected]>I am wondering if there is a chance to extract the key=value parsing into standalone function and use it everywhere though.
I think this is a good idea.
To be clear, I'm not saying that's a prerequisite for this series.
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Cc Andrew Cooper <[email protected]>Cc George Dunlap <[email protected]>Cc Ian Jackson <[email protected]>Cc Jan Beulich <[email protected]>Cc Konrad Rzeszutek Wilk <[email protected]>Cc Stefano Stabellini <[email protected]>Cc Tim Deegan <[email protected]>Cc Wei Liu <[email protected]>Cc Julien Grall <[email protected]>
Quoted 6 lines
Quoted 2 lines
Correctly trim your CC list next time please. A lot of hypervisor people don't need to get CCed on this patch.
Actually, this list is generated by get_maintainer.pl. Maybe next time I should go carefully through the list and remove some of the names manually.
You could have used it the wrong way.
Either
$ ./scripts/get_maintainers.pl -f FILE # not patch
or
$ ./scripts/get_maintainers.pl PATCH # not file
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v2 3/6] libxl:xl: add parsing code to parse "libxl_static_sshm" from xl config files
In reply to Zhongze LiuQuoted 9 lines · Zhongze Liu
Add the parsing utils for the newly introduced
libxl_static_sshmstruct to the libxl/libxlu_* family. And add realated parsing code in xl to parse the struct from xl config files. This is for the proposal "Allow setting up shared memory areas between VMs from xl config file" (see [1]).[1] https://lists.xen.org/archives/html/xen-devel/2017-08/msg03242.html
Signed-off-by Zhongze Liu <[email protected]>
BTW when you resend this patch should go last because it depends on others.
And you didn't patch documents (manpage, xenstore path doc).
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 4/6 xsm: flask: change the dummy xsm policy and flask hook for map_gmfn_foregin
In reply to Zhongze LiuThe original dummy xsm_map_gmfn_foregin checks if source domain has the proper privileges over the target domain. Under this policy, it's not allowed if a Dom0 wants to map pages from one DomU to another, which restricts some useful yet not dangerous use cases of the API, such as sharing pages among DomU's by calling XENMEM_add_to_physmap from Dom0.
For the dummy xsm_map_gmfn_foregin, change to policy to: IFF the current domain has the proper privileges on (d) and (t), grant the access.
For the flask side: 1) Introduce a new av permission MMU__SHARE_MEM to denote if two domains can share memory through map_gmfn_foregin. 2) Change to hook to grant the access IFF the current domain has proper MMU privileges on (d) and (t), and MMU__SHARE_MEM is allowed between (d) and (t). 3) Modify the default xen.te to allow MMU__SHARE_MEM for normal domains that allow grant mapping/event channels.
References to the xsm check have also been updated to pass the current domain as a new parameter.
This is for the proposal "Allow setting up shared memory areas between VMs from xl config file" (see [1]).
[1] https://lists.xen.org/archives/html/xen-devel/2017-08/msg03242.html
---
v2:
* Preserve the error code in both the dummy xsm callback and the flask hook.
* Also check if (d) and (t) can share memory in the flask hook.
--- tools/flask/policy/modules/xen.if | 2 ++ xen/arch/arm/mm.c | 2 +- xen/arch/x86/mm/p2m.c | 2 +- xen/include/xsm/dummy.h | 8 ++++++-- xen/include/xsm/xsm.h | 7 ++++--- xen/xsm/flask/hooks.c | 10 ++++++++-- xen/xsm/flask/policy/access_vectors | 4 ++++ 7 files changed, 26 insertions(+), 9 deletions(-)
tools/flask/policy/modules/xen.if +2 -0
@@ -127,6 +127,8 @@ define(`domain_comms', ` domain_event_comms($1, $2) allow $1 $2:grant { map_read map_write copy unmap }; allow $2 $1:grant { map_read map_write copy unmap }; + allow $1 $2:mmu share_mem; + allow $2 $1:mmu share_mem; ') # domain_self_comms(domain)
xen/arch/arm/mm.c +1 -1
@@ -1284,7 +1284,7 @@ int xenmem_add_to_physmap_one(return -EINVAL ; } - rc =xsm_map_gmfn_foreign (XSM_TARGET , d, od); + rc =xsm_map_gmfn_foreign (XSM_TARGET , current->domain, d, od);if ( rc ) {rcu_unlock_domain (od);
xen/arch/x86/mm/p2m.c +1 -1
@@ -2545,7 +2545,7 @@ int p2m_add_foreign(struct domain *tdom, unsigned long fgfn,if ( tdom == fdom ) goto out; - rc =xsm_map_gmfn_foreign (XSM_TARGET , tdom, fdom); + rc =xsm_map_gmfn_foreign (XSM_TARGET , current->domain, tdom, fdom);if ( rc ) goto out;
xen/include/xsm/dummy.h +6 -2
@@ -525,10 +525,14 @@ static XSM_INLINE int xsm_remove_from_physmap(XSM_DEFAULT_ARG struct domain *d1,return xsm_default_action (action, d1, d2); } -static XSM_INLINE int xsm_map_gmfn_foreign(XSM_DEFAULT_ARG struct domain *d, struct domain *t) +static XSM_INLINE int xsm_map_gmfn_foreign(XSM_DEFAULT_ARG struct domain *cd, +struct domain *d,struct domain *t) { +int rc;XSM_ASSERT_ACTION (XSM_TARGET ); -return xsm_default_action (action, d, t); + rc =xsm_default_action (action, cd, d); +if (rc)return rc; +return xsm_default_action (action, cd, t); } static XSM_INLINE int xsm_hvm_param(XSM_DEFAULT_ARG struct domain *d, unsigned long op)
xen/include/xsm/xsm.h +4 -3
@@ -85,7 +85,7 @@ struct xsm_operations {int (*memory_pin_page) (struct domain *d1,struct domain *d2,struct page_info *page);int (*add_to_physmap) (struct domain *d1,struct domain *d2);int (*remove_from_physmap) (struct domain *d1,struct domain *d2); -int (*map_gmfn_foreign) (struct domain *d,struct domain *t); +int (*map_gmfn_foreign) (struct domain *cd,struct domain *d,struct domain *t);int (*claim_pages) (struct domain *d);int (*console_io) (struct domain *d,int cmd);
@@ -372,9 +372,10 @@ static inline int xsm_remove_from_physmap(xsm_default_t def, struct domain *d1,return xsm_ops->remove_from_physmap (d1, d2); } -static inline int xsm_map_gmfn_foreign (xsm_default_t def,struct domain *d,struct domain *t) +static inline int xsm_map_gmfn_foreign (xsm_default_t def,struct domain *cd, +struct domain *d,struct domain *t) { -return xsm_ops->map_gmfn_foreign (d, t); +return xsm_ops->map_gmfn_foreign (cd, d, t); }static inline int xsm_claim_pages (xsm_default_t def,struct domain *d)
xen/xsm/flask/hooks.c +8 -2
@@ -1165,9 +1165,15 @@ static int flask_remove_from_physmap(struct domain *d1, struct domain *d2)return domain_has_perm (d1, d2,SECCLASS_MMU ,MMU__PHYSMAP ); } -static int flask_map_gmfn_foreign (struct domain *d,struct domain *t) +static int flask_map_gmfn_foreign (struct domain *cd, +struct domain *d,struct domain *t) { -return domain_has_perm (d, t,SECCLASS_MMU ,MMU__MAP_READ |MMU__MAP_WRITE ); +int rc; + rc =domain_has_perm (cd, d,SECCLASS_MMU ,MMU__MAP_READ |MMU__MAP_WRITE ); +if (rc)return rc; + rc =domain_has_perm (cd, t,SECCLASS_MMU ,MMU__MAP_READ |MMU__MAP_WRITE ); +if (rc)return rc; +return domain_has_perm (d, t,SECCLASS_MMU ,MMU__SHARE_MEM ); }static int flask_hvm_param (struct domain *d,unsigned long op)
xen/xsm/flask/policy/access_vectors +4 -0
@@ -383,6 +383,10 @@ class mmu # Allow a privileged domain to install a map of a page it does not own. Used # for stub domain device models with the PV framebuffer. target_hack +# Checked when using map_gmfn_foreign to share memory: +# source = domain whose memory is being shared +# target = client domain + share_mem } # control of the paging_domctl split by subop
Signature · 7 lines
2.14.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v2 4/6] xsm: flask: change the dummy xsm policy and flask hook for map_gmfn_foregin
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 27.08.17 at 10:36, <[email protected]> wrote:
xen/arch/arm/mm.c +1
-1@@ -1284,7 +1284,7 @@ int xenmem_add_to_physmap_one(return -EINVAL ; } - rc =xsm_map_gmfn_foreign (XSM_TARGET , d, od); + rc =xsm_map_gmfn_foreign (XSM_TARGET , current->domain, d, od);if ( rc ) {rcu_unlock_domain (od);
xen/arch/x86/mm/p2m.c int p2m_add_foreign(struct domain *tdom, unsigned long fgfn, · line 2548
Quoted 5 lines
xen/arch/x86/mm/p2m.c +1
-1@@ -2545,7 +2545,7 @@ int p2m_add_foreign(struct domain *tdom, unsigned long fgfn,if ( tdom == fdom ) goto out; - rc =xsm_map_gmfn_foreign (XSM_TARGET , tdom, fdom); + rc =xsm_map_gmfn_foreign (XSM_TARGET , current->domain, tdom, fdom);
I continue to dislike the added arguments here, as being pointless to pass. I'm not the maintainer of either of the modified files, so I won't (and can't) veto the change though.
xen/include/xsm/dummy.h static XSM_INLINE int xsm_remove_from_physmap(XSM_DEFAULT_ARG struct domain *d1, · line 532
Quoted 12 lines
xen/include/xsm/dummy.h +3
-1@@ -525,10 +525,14 @@ static XSM_INLINE int xsm_remove_from_physmap(XSM_DEFAULT_ARG struct domain *d1,return xsm_default_action (action, d1, d2); } -static XSM_INLINE int xsm_map_gmfn_foreign(XSM_DEFAULT_ARG struct domain *d, struct domain *t) +static XSM_INLINE int xsm_map_gmfn_foreign(XSM_DEFAULT_ARG struct domain *cd, +struct domain *d,struct domain *t) { +int rc;XSM_ASSERT_ACTION (XSM_TARGET );
Missing blank line between declaration and statements.
xen/include/xsm/dummy.h static XSM_INLINE int xsm_remove_from_physmap(XSM_DEFAULT_ARG struct domain *d1, · line 534
Quoted 3 lines
xen/include/xsm/dummy.h +2
-1-return xsm_default_action (action, d, t); + rc =xsm_default_action (action, cd, d); +if (rc)return rc;
Coding style. In any event, as suggested before the whole thing is easier to write as
xen/include/xsm/dummy.h static XSM_INLINE int xsm_remove_from_physmap(XSM_DEFAULT_ARG struct domain *d1, · line 535
Quoted 1 line
xen/include/xsm/dummy.h +1
-0+return xsm_default_action (action, cd, t);
return xsm_default_action(action, cd, d) ?: xsm_default_action(action, cd, t);
anyway imo (suitably split across lines if needed, of course).
Quoted 8 lines
xen/xsm/flask/hooks.c +1
-1@@ -1165,9 +1165,15 @@ static int flask_remove_from_physmap(struct domain *d1, struct domain *d2)return domain_has_perm (d1, d2,SECCLASS_MMU ,MMU__PHYSMAP ); } -static int flask_map_gmfn_foreign (struct domain *d,struct domain *t) +static int flask_map_gmfn_foreign(struct domain *cd,
xen/xsm/flask/hooks.c static int flask_remove_from_physmap(struct domain *d1, struct domain *d2) · line 1177
Quoted 10 lines
xen/xsm/flask/hooks.c +7
-1+ struct domain *d, struct domain *t) { -return domain_has_perm (d, t,SECCLASS_MMU ,MMU__MAP_READ |MMU__MAP_WRITE ); + int rc; + rc =domain_has_perm (cd, d,SECCLASS_MMU ,MMU__MAP_READ |MMU__MAP_WRITE ); +if (rc)return rc; + rc =domain_has_perm (cd, t,SECCLASS_MMU ,MMU__MAP_READ |MMU__MAP_WRITE ); +if (rc)return rc; +return domain_has_perm (d, t,SECCLASS_MMU ,MMU__SHARE_MEM ); }
At least the style problems mentioned above apply here too.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v2 4/6] xsm: flask: change the dummy xsm policy and flask hook for map_gmfn_foregin
Hi Jan,
Thanks for having a look at the patch.
2017-08-28 16:29 GMT+08:00 Jan Beulich <[email protected]>:
Quoted 31 lines
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 27.08.17 at 10:36, <[email protected]> wrote:
xen/arch/arm/mm.c +1
-1@@ -1284,7 +1284,7 @@ int xenmem_add_to_physmap_one(return -EINVAL ; } - rc =xsm_map_gmfn_foreign (XSM_TARGET , d, od); + rc =xsm_map_gmfn_foreign (XSM_TARGET , current->domain, d, od);if ( rc ) {rcu_unlock_domain (od);xen/arch/x86/mm/p2m.c int p2m_add_foreign(struct domain *tdom, unsigned long fgfn, · line 2548
Quoted 5 lines
xen/arch/x86/mm/p2m.c +1
-1@@ -2545,7 +2545,7 @@ int p2m_add_foreign(struct domain *tdom, unsigned long fgfn,if ( tdom == fdom ) goto out; - rc =xsm_map_gmfn_foreign (XSM_TARGET , tdom, fdom); + rc =xsm_map_gmfn_foreign (XSM_TARGET , current->domain, tdom, fdom);I continue to dislike the added arguments here, as being pointless to pass. I'm not the maintainer of either of the modified files, so I won't (and can't) veto the change though.
Quoted 6 lines
xen/include/xsm/dummy.h +0
-0@@ -525,10 +525,14 @@ static XSM_INLINE int xsm_remove_from_physmap(XSM_DEFAULT_ARG struct domain *d1,return xsm_default_action (action, d1, d2); }
Quoted 8 lines
xen/include/xsm/dummy.h static XSM_INLINE int xsm_remove_from_physmap(XSM_DEFAULT_ARG struct domain *d1, · line 532
Quoted 6 lines
xen/include/xsm/dummy.h +3
-1-static XSM_INLINE int xsm_map_gmfn_foreign(XSM_DEFAULT_ARG struct domain *d, struct domain *t) +static XSM_INLINE int xsm_map_gmfn_foreign(XSM_DEFAULT_ARG struct domain *cd, +struct domain *d,struct domain *t) { +int rc;XSM_ASSERT_ACTION (XSM_TARGET );Missing blank line between declaration and statements.
Sorry. Will fix this.
Quoted 11 lines
xen/include/xsm/dummy.h static XSM_INLINE int xsm_remove_from_physmap(XSM_DEFAULT_ARG struct domain *d1, · line 534
Quoted 4 lines
xen/include/xsm/dummy.h +2
-1-return xsm_default_action (action, d, t); + rc =xsm_default_action (action, cd, d); +if (rc)return rc;Coding style. In any event, as suggested before the whole thing is easier to write as
xen/include/xsm/dummy.h static XSM_INLINE int xsm_remove_from_physmap(XSM_DEFAULT_ARG struct domain *d1, · line 535
Quoted 1 line
xen/include/xsm/dummy.h +1
-0+return xsm_default_action (action, cd, t);return xsm_default_action(action, cd, d) ?: xsm_default_action(action, cd, t);
But aren't we going to preserve the error code here?
Cheers,
Zhongze Liu
Quoted 24 lines
anyway imo (suitably split across lines if needed, of course).
Quoted 8 lines
xen/xsm/flask/hooks.c +1
-1@@ -1165,9 +1165,15 @@ static int flask_remove_from_physmap(struct domain *d1, struct domain *d2)return domain_has_perm (d1, d2,SECCLASS_MMU ,MMU__PHYSMAP ); } -static int flask_map_gmfn_foreign (struct domain *d,struct domain *t) +static int flask_map_gmfn_foreign(struct domain *cd,xen/xsm/flask/hooks.c static int flask_remove_from_physmap(struct domain *d1, struct domain *d2) · line 1177
Quoted 10 lines
xen/xsm/flask/hooks.c +7
-1+ struct domain *d, struct domain *t) { -return domain_has_perm (d, t,SECCLASS_MMU ,MMU__MAP_READ |MMU__MAP_WRITE ); + int rc; + rc =domain_has_perm (cd, d,SECCLASS_MMU ,MMU__MAP_READ |MMU__MAP_WRITE ); +if (rc)return rc; + rc =domain_has_perm (cd, t,SECCLASS_MMU ,MMU__MAP_READ |MMU__MAP_WRITE ); +if (rc)return rc; +return domain_has_perm (d, t,SECCLASS_MMU ,MMU__SHARE_MEM ); }At least the style problems mentioned above apply here too.
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v2 4/6] xsm: flask: change the dummy xsm policy and flask hook for map_gmfn_foregin
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 28.08.17 at 13:01, <[email protected]> wrote:
2017-08-28 16:29 GMT+08:00 Jan Beulich <[email protected]>:
Quoted 9 lines
xen/include/xsm/dummy.h static XSM_INLINE int xsm_remove_from_physmap(XSM_DEFAULT_ARG struct domain *d1, · line 532
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 27.08.17 at 10:36, <[email protected]> wrote:
xen/include/xsm/dummy.h +3
-1-static XSM_INLINE int xsm_map_gmfn_foreign(XSM_DEFAULT_ARG struct domain *d, struct domain *t) +static XSM_INLINE int xsm_map_gmfn_foreign(XSM_DEFAULT_ARG struct domain *cd, +struct domain *d,struct domain *t) { +int rc;XSM_ASSERT_ACTION (XSM_TARGET );Missing blank line between declaration and statements.
Sorry. Will fix this.
Quoted 5 lines
Quoted 4 lines
xen/include/xsm/dummy.h +2
-1-return xsm_default_action (action, d, t); + rc =xsm_default_action (action, cd, d); +if (rc)return rc;
Quoted 8 lines
Quoted 6 lines
Coding style. In any event, as suggested before the whole thing is easier to write as
Quoted 1 line
+ return
xsm_default_action(action, cd, t);return xsm_default_action(action, cd, d) ?: xsm_default_action(action, cd, t);But aren't we going to preserve the error code here?
I don't understand the question - if the first function invocation returns an error, that is what the function here will return. Else it returns what the second xsm_default_action() invocation hands back.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v2 4/6] xsm: flask: change the dummy xsm policy and flask hook for map_gmfn_foregin
In reply to Jan BeulichQuoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 27.08.17 at 10:36, <[email protected]> wrote:
xen/arch/arm/mm.c +1
-1@@ -1284,7 +1284,7 @@ int xenmem_add_to_physmap_one(return -EINVAL ; } - rc =xsm_map_gmfn_foreign (XSM_TARGET , d, od); + rc =xsm_map_gmfn_foreign (XSM_TARGET , current->domain, d, od);if ( rc ) {rcu_unlock_domain (od);xen/arch/x86/mm/p2m.c +0
-0@@ -2545,7 +2545,7 @@ int p2m_add_foreign(struct domain *tdom, unsigned long fgfn,if ( tdom == fdom ) goto out;
Quoted 6 lines
xen/arch/x86/mm/p2m.c int p2m_add_foreign(struct domain *tdom, unsigned long fgfn, · line 2548
Quoted 2 lines
xen/arch/x86/mm/p2m.c +1
-1- rc =xsm_map_gmfn_foreign (XSM_TARGET , tdom, fdom); + rc =xsm_map_gmfn_foreign (XSM_TARGET , current->domain, tdom, fdom);I continue to dislike the added arguments here, as being pointless to pass. I'm not the maintainer of either of the modified files, so I won't (and can't) veto the change though.
You mean, you think xsm_map_gmfn_foreign() can look up 'current' itself?
If not can you be more explicit what you'd prefer?
-George
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v2 4/6] xsm: flask: change the dummy xsm policy and flask hook for map_gmfn_foregin
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 28.08.17 at 16:24, <[email protected]> wrote:
Quoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 27.08.17 at 10:36, <[email protected]> wrote:
xen/arch/arm/mm.c +1
-1@@ -1284,7 +1284,7 @@ int xenmem_add_to_physmap_one(return -EINVAL ; } - rc =xsm_map_gmfn_foreign (XSM_TARGET , d, od); + rc =xsm_map_gmfn_foreign (XSM_TARGET , current->domain, d, od);if ( rc ) {rcu_unlock_domain (od);xen/arch/x86/mm/p2m.c +0
-0@@ -2545,7 +2545,7 @@ int p2m_add_foreign(struct domain *tdom, unsigned long fgfn,if ( tdom == fdom ) goto out;
Quoted 8 lines
Quoted 6 lines
xen/arch/x86/mm/p2m.c int p2m_add_foreign(struct domain *tdom, unsigned long fgfn, · line 2548
Quoted 2 lines
xen/arch/x86/mm/p2m.c +1
-1- rc =xsm_map_gmfn_foreign (XSM_TARGET , tdom, fdom); + rc =xsm_map_gmfn_foreign (XSM_TARGET , current->domain, tdom, fdom);I continue to dislike the added arguments here, as being pointless to pass. I'm not the maintainer of either of the modified files, so I won't (and can't) veto the change though.
You mean, you think
xsm_map_gmfn_foreign()can look up 'current' itself?
Yes, that's what I had suggested before (in more detail than I have given here); I also don't think it would be xsm_map_gmfn_foreign(), but rather whatever functions back it.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 5/6 libxl: support mapping static shared memory areas during domain creation
In reply to Zhongze LiuAdd libxl__sshm_add to map shared pages from one DomU to another, The mapping process involves the follwing steps:
* Set defaults and check for further errors in the static_shm configs:
overlapping areas, invalid ranges, duplicated master domain, no master domain etc.
* Write infomation of static shared memory areas into the appropriate xenstore paths.
* Use xc_domain_add_to_physmap_batch to do the page sharing.
* Set the refcount of the shared region accordingly
Temporarily mark this as unsupported on x86 because calling p2m_add_foregin on two domU's is currently not allowd on x86 (see the comments in x86/mm/p2m.c:p2m_add_foregin for more details).
This is for the proposal "Allow setting up shared memory areas between VMs from xl config file" (see [1]).
[1] https://lists.xen.org/archives/html/xen-devel/2017-08/msg03242.html
---
v2:
* coding style corrections
* replace libxl__xs_get_sshmpath() with a macro
* use the predefined XC_PAGE_SIZE instead of hardcoding 12
* avoid calling xc_domain_add_to_physmap many time during xs retry
* unmapping mapped pages on partial failure
* refcounting the node
--- tools/libxl/Makefile | 2 +- tools/libxl/libxl_arch.h | 6 + tools/libxl/libxl_arm.c | 15 ++ tools/libxl/libxl_create.c | 27 ++++ tools/libxl/libxl_internal.h | 13 ++ tools/libxl/libxl_sshm.c | 375 +++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_x86.c | 18 +++ 7 files changed, 455 insertions(+), 1 deletion(-) create mode 100644 tools/libxl/libxl_sshm.c
tools/libxl/Makefile +1 -1
@@ -138,7 +138,7 @@ LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \ libxl_dom_suspend.o libxl_dom_save.o libxl_usb.o \ libxl_vtpm.o libxl_nic.o libxl_disk.o libxl_console.o \ libxl_cpupool.o libxl_mem.o libxl_sched.o libxl_tmem.o \ - libxl_9pfs.o libxl_domain.o \ + libxl_9pfs.o libxl_domain.o libxl_sshm.o \ $(LIBXL_OBJS-y) LIBXL_OBJS += libxl_genid.o LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o
tools/libxl/libxl_arch.h +6 -0
@@ -71,6 +71,12 @@ int libxl__arch_extra_memory(libxl__gc *gc,const libxl_domain_build_info *info, uint64_t *out); +_hidden +bool libxl__arch_domain_support_sshm(const libxl_domain_build_info *b_info); + +_hidden +int libxl__arch_domain_sshm_cachepolicy_setdefault(libxl_static_shm *sshm); +#if defined(__i386__) || defined(__x86_64__)#define LAPIC_BASE_ADDRESS 0xfee00000
tools/libxl/libxl_arm.c +15 -0
@@ -1065,6 +1065,21 @@ void libxl__arch_domain_build_info_acpi_setdefault(libxl_defbool_setdefault (&b_info->acpi, false); } +bool libxl__arch_domain_support_sshm (const libxl_domain_build_info *b_info) +{ +return true; +} + +int libxl__arch_domain_sshm_cachepolicy_setdefault (libxl_static_shm *sshm) +{ +if (sshm->cache_policy ==LIBXL_SSHM_CACHEPOLICY_UNKNOWN ) + sshm->cache_policy =LIBXL_SSHM_CACHEPOLICY_ARM_NORMAL ; +if (sshm->cache_policy >=LIBXL_SSHM_CACHEPOLICY_X86_NORMAL ) +return ERROR_INVAL ; + +return 0 ; +} +/* * Local variables: * mode: C
tools/libxl/libxl_create.c +27 -0
@@ -501,6 +501,14 @@ int libxl__domain_build(libxl__gc *gc, ret =ERROR_INVAL ; goto out; } + +/* the p2m has been setup, we could map the static shared memory now. */ + ret =libxl__sshm_add (gc, domid, d_config->sshms, d_config->num_sshms); +if (ret !=0 ) { +LOG (ERROR ,"failed to map static shared memory" ); + goto out; + } + ret =libxl__build_post (gc, domid, info, state, vments, localents); out:return ret;
@@ -918,6 +926,25 @@ static void initiate_domain_create(libxl__egc *egc, goto error_out; } +if (d_config->num_sshms !=0 && + !libxl__arch_domain_support_sshm (&d_config->b_info)) { +LOGD (ERROR , domid,"static_shm is not supported by this domain type." ); + ret =ERROR_INVAL ; + goto error_out; + } + +for (i =0 ; i < d_config->num_sshms; ++i) { + ret =libxl__sshm_setdefault (gc, domid, &d_config->sshms[i]); +if (ret) { +LOGD (ERROR , domid,"Unable to set defaults for static sshm" ); + goto error_out; + } + } + + ret =libxl__sshm_check_overlap (gc, domid, + d_config->sshms, d_config->num_sshms); +if (ret) goto error_out; + ret =libxl__domain_make (gc, d_config, &domid, &state->config);if (ret) {LOGD (ERROR , domid,"cannot make domain: %d" , ret);
tools/libxl/libxl_internal.h +13 -0
@@ -4352,6 +4352,19 @@ static inline bool libxl__acpi_defbool_val(const libxl_domain_build_info *b_info }#endif +/* +* Set up static shared ram pages for HVM domains to communicate +* +* This function should only be called after the memory map is constructed +* and before any further memory access. */ +_hidden int libxl__sshm_add(libxl__gc *gc, uint32_t domid, +libxl_static_shm *sshm,int len); + +_hidden int libxl__sshm_check_overlap(libxl__gc *gc, uint32_t domid, +libxl_static_shm *sshms,int len); +_hidden int libxl__sshm_setdefault(libxl__gc *gc, uint32_t domid, +libxl_static_shm *sshm); +/* * Local variables: * mode: C
tools/libxl/libxl_sshm.c new file +375 -0
375 lines not on this page · raw message
tools/libxl/libxl_x86.c +18 -0
@@ -587,6 +587,24 @@ void libxl__arch_domain_build_info_acpi_setdefault(libxl_defbool_setdefault (&b_info->acpi, true); } +bool libxl__arch_domain_support_sshm (const libxl_domain_build_info *b_info) +{ +/* FIXME: Mark this as unsupported for calling p2m_add_foreign on two +* DomU's is currently not allowd on x86, see the comments in +* x86/mm/p2m.c: p2m_add_foreign */ +return false; +} + +int libxl__arch_domain_sshm_cachepolicy_setdefault (libxl_static_shm *sshm) +{ +if (sshm->cache_policy ==LIBXL_SSHM_CACHEPOLICY_UNKNOWN ) + sshm->cache_policy =LIBXL_SSHM_CACHEPOLICY_X86_NORMAL ; +if (sshm->cache_policy <LIBXL_SSHM_CACHEPOLICY_X86_NORMAL ) +return ERROR_INVAL ; + +return 0 ; +} +/* * Local variables: * mode: C
Signature · 7 lines
2.14.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v2 5/6] libxl: support mapping static shared memory areas during domain creation
Quoted 21 lines · Zhongze Liu
Add
libxl__sshm_addto map shared pages from one DomU to another, The mapping process involves the follwing steps:* Set defaults and check for further errors in the
static_shmconfigs:
overlapping areas, invalid ranges, duplicated master domain, no master domain etc.
* Write infomation of static shared memory areas into the appropriate xenstore paths.
* Usexc_domain_add_to_physmap_batchto do the page sharing.
* Set the refcount of the shared region accordinglyTemporarily mark this as unsupported on x86 because calling
p2m_add_foreginon two domU's is currently not allowd on x86 (see the comments in x86/mm/p2m.c:p2m_add_foregin for more details).This is for the proposal "Allow setting up shared memory areas between VMs from xl config file" (see [1]).
[1] https://lists.xen.org/archives/html/xen-devel/2017-08/msg03242.html
Signed-off-by Zhongze Liu <[email protected]>
[...]
Quoted 12 lines
tools/libxl/libxl_sshm.c new file +12
-0+ + rc =libxl__xs_read_checked (gc, xt, +GCSPRINTF ("%s/master" , sshm_path), + &xs_value); +if (rc) goto out; + master_domid =strtoull (xs_value,NULL ,16 ); + +if (sshm->prot ==LIBXL_SSHM_PROT_UNKNOWN ) { + sshm->prot = master_sshm.prot; + } +/* check if the slave is asking too much permission */ +if (master_sshm.prot < sshm->prot) {
tools/libxl/libxl_sshm.c line 260
Quoted 10 lines
tools/libxl/libxl_sshm.c new file +10
-0+SSHM_ERROR (domid, sshm->id,"slave is asking too much permission." ); + rc =ERROR_INVAL ; + goto out; + } + +/* all checks passed, do the job */ +if (!isretry) { + rc =libxl__sshm_do_map (gc, master_domid, domid, sshm, + master_sshm.begin, master_sshm.end); +if (rc) goto out;
You probably need to roll back the mapping should the transaction gets aborted in this loop.
Quoted 16 lines
tools/libxl/libxl_sshm.c new file +16
-0+ } + +/* write the result to xenstore and commit */ + rc =libxl__xs_write_checked (gc, xt, dom_role_path,"slave" ); +if (rc) goto out; + rc =libxl__xs_writev (gc, xt, slave_path, ents); +if (rc) goto out; + rc =libxl__sshm_incref (gc, xt, sshm_path); +if (rc) goto out; + + rc =libxl__xs_transaction_commit (gc, &xt); +if (!rc)break ; +if (rc <0 ) goto out; + isretry = true; + } +
tools/libxl/libxl_sshm.c line 291
Quoted 10 lines
tools/libxl/libxl_sshm.c new file +10
-0+ rc =0 ; +out: +libxl__xs_transaction_abort (gc, &xt); +return rc; +} + +static int libxl__sshm_add_master (libxl__gc *gc,uint32_t domid, +libxl_static_shm *sshm) +{ +
No refcount increment here?
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v2 5/6] libxl: support mapping static shared memory areas during domain creation
Hi Wei,
Thanks for reviewing.
2017-09-02 0:23 GMT+08:00 Wei Liu <[email protected]>:
Quoted 40 lines · Zhongze Liu
Quoted 21 lines
Add
libxl__sshm_addto map shared pages from one DomU to another, The mapping process involves the follwing steps:* Set defaults and check for further errors in the
static_shmconfigs:
overlapping areas, invalid ranges, duplicated master domain, no master domain etc.
* Write infomation of static shared memory areas into the appropriate xenstore paths.
* Usexc_domain_add_to_physmap_batchto do the page sharing.
* Set the refcount of the shared region accordinglyTemporarily mark this as unsupported on x86 because calling
p2m_add_foreginon two domU's is currently not allowd on x86 (see the comments in x86/mm/p2m.c:p2m_add_foregin for more details).This is for the proposal "Allow setting up shared memory areas between VMs from xl config file" (see [1]).
[1] https://lists.xen.org/archives/html/xen-devel/2017-08/msg03242.html
Signed-off-by Zhongze Liu <[email protected]>[...]
Quoted 17 lines
tools/libxl/libxl_sshm.c new file +17
-0+ + rc =libxl__xs_read_checked (gc, xt, +GCSPRINTF ("%s/master" , sshm_path), + &xs_value); +if (rc) goto out; + master_domid =strtoull (xs_value,NULL ,16 ); + +if (sshm->prot ==LIBXL_SSHM_PROT_UNKNOWN ) { + sshm->prot = master_sshm.prot; + } +/* check if the slave is asking too much permission */ +if (master_sshm.prot < sshm->prot) { +SSHM_ERROR (domid, sshm->id,"slave is asking too much permission." ); + rc =ERROR_INVAL ; + goto out; + } +
Quoted 8 lines
tools/libxl/libxl_sshm.c line 260
Quoted 5 lines
tools/libxl/libxl_sshm.c new file +5
-0+/* all checks passed, do the job */ +if (!isretry) { + rc =libxl__sshm_do_map (gc, master_domid, domid, sshm, + master_sshm.begin, master_sshm.end); +if (rc) goto out;You probably need to roll back the mapping should the transaction gets aborted in this loop.
OK. I'll move the rollback code to the abort path.
Quoted 21 lines
Quoted 21 lines
tools/libxl/libxl_sshm.c new file +20
-0+ } + +/* write the result to xenstore and commit */ + rc =libxl__xs_write_checked (gc, xt, dom_role_path,"slave" ); +if (rc) goto out; + rc =libxl__xs_writev (gc, xt, slave_path, ents); +if (rc) goto out; + rc =libxl__sshm_incref (gc, xt, sshm_path); +if (rc) goto out; + + rc =libxl__xs_transaction_commit (gc, &xt); +if (!rc)break ; +if (rc <0 ) goto out; + isretry = true; + } + + rc =0 ; +out: +libxl__xs_transaction_abort (gc, &xt); +return rc;
Quoted 8 lines
tools/libxl/libxl_sshm.c line 291
Quoted 6 lines
tools/libxl/libxl_sshm.c new file +6
-0+} + +static int libxl__sshm_add_master (libxl__gc *gc,uint32_t domid, +libxl_static_shm *sshm) +{ +No refcount increment here?
For every sshm ID, this will be called only once. And in the xenstore ents array, I've already
set "users = 1", so there's no need to call libxl__sshm_incref().
Cheers,
Zhongze Liu
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 6/6 libxl: support unmapping static shared memory areas during domain destruction
In reply to Zhongze LiuAdd libxl__sshm_del to unmap static shared memory areas mapped by libxl__sshm_add during domain creation. The unmapping process is:
* For a master: decrease the refcount of the sshm region, if the refcount reaches 0, cleanup the whole sshm path.
* For a slave: unmap the shared pages, and cleanup related xs entries. decrease the refcount of the sshm region, if the refcount reaches 0, cleanup the whole sshm path.
This is for the proposal "Allow setting up shared memory areas between VMs from xl config file" (see [1]).
[1] https://lists.xen.org/archives/html/xen-devel/2017-08/msg03242.html
---
v2:
* use the predefined XC_PAGE_SIZE instead of hardcoding 12
* refcounting the node
--- tools/libxl/libxl_domain.c | 5 +++ tools/libxl/libxl_internal.h | 2 + tools/libxl/libxl_sshm.c | 105 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 112 insertions(+)
tools/libxl/libxl_domain.c +5 -0
@@ -1028,6 +1028,11 @@ void libxl__destroy_domid(libxl__egc *egc, libxl__destroy_domid_state *dis) goto out; } + rc =libxl__sshm_del (gc, domid); +if (rc) { +LOGD (ERROR , domid,"Deleting static shm failed." ); + } +if (libxl__device_pci_destroy_all (gc, domid) <0 )LOGD (ERROR , domid,"Pci shutdown failed" ); rc =xc_domain_pause (ctx->xch, domid);
tools/libxl/libxl_internal.h +2 -0
@@ -4360,6 +4360,8 @@ static inline bool libxl__acpi_defbool_val(const libxl_domain_build_info *b_info _hidden int libxl__sshm_add(libxl__gc *gc, uint32_t domid,libxl_static_shm *sshm,int len); +_hidden int libxl__sshm_del(libxl__gc *gc, uint32_t domid); + _hidden int libxl__sshm_check_overlap(libxl__gc *gc, uint32_t domid,libxl_static_shm *sshms,int len); _hidden int libxl__sshm_setdefault(libxl__gc *gc, uint32_t domid,
tools/libxl/libxl_sshm.c +105 -0
111 lines not on this page · raw message
Signature · 7 lines
2.14.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 8 lines · Zhongze Liu
This series implements the new xl config entry proposed in [1]. Users can use the new config entry to statically setup shared memory areas among VMs that don't have grant table support so that they could communicate with each other through the static shared memory areas.
[1] Proposla to allow setting up shared memory areas between VMs from xl config file:
https://lists.xen.org/archives/html/xen-devel/2017-08/msg03242.html
Quoted 7 lines
v2:
* fixed several code style issues.
* introduceMMU__SHARE_MEMin flask av permissions, and add a check to this. permission in the flask hook forxsm_map_gmfn_foreign.
* support rolling back during creation on partial failure.
* refcounting the sshm path instead of using "alive" and "zombie" to label the master and counting the slaves.
Hey Zhongze,
any plans on sending an update of this series?
Quoted 33 lines
Cheers,
Zhongze Liu (6):
libxc: addxc_domain_remove_from_physmapto wrap
XENMEM_remove_from_physmap
libxl: introduce a new structure to represent static shared memory
regions
libxl:xl: add parsing code to parse "libxl_static_sshm" from xl config
files
xsm: flask: change the dummy xsm policy and flask hook for
map_gmfn_foregin
libxl: support mapping static shared memory areas during domain
creation
libxl: support unmapping static shared memory areas during domain
destructiontools/flask/policy/modules/xen.if | 2 + tools/libxc/include/xenctrl.h | 4 + tools/libxc/xc_domain.c | 11 + tools/libxl/Makefile | 4 +- tools/libxl/libxl.h | 4 + tools/libxl/libxl_arch.h | 6 + tools/libxl/libxl_arm.c | 15 ++ tools/libxl/libxl_create.c | 27 ++ tools/libxl/libxl_domain.c | 5 + tools/libxl/libxl_internal.h | 15 ++ tools/libxl/libxl_sshm.c | 480 ++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_types.idl | 34 ++- tools/libxl/libxl_x86.c | 18 ++ tools/libxl/libxlu_sshm.c | 210 ++++++++++++++++ tools/libxl/libxlutil.h | 6 + tools/xl/xl_parse.c | 24 +- xen/arch/arm/mm.c | 2 +-
Quoted 12 lines
xen/arch/x86/mm/p2m.c | 2 +- xen/include/xsm/dummy.h | 8 +- xen/include/xsm/xsm.h | 7 +- xen/xsm/flask/hooks.c | 10 +- xen/xsm/flask/policy/access_vectors | 4 + 22 files changed, 883 insertions(+), 15 deletions(-) create mode 100644 tools/libxl/libxl_sshm.c create mode 100644 tools/libxl/libxlu_sshm.cSignature · 1 line
2.14.0
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Hi Stefano,
Sorry for the long delay. I've been busy with other school stuff recently so I can only use my spare time on this. The current situation is: the code has already been completed, but I'm still drafting the man pages and there are approximately 20% left. I'll try my best to update it within the following one week or so.
Sorry again for failing to schedule my time effectively.
Cheers,
Zhongze Liu.
2017-10-11 7:55 GMT+08:00 Stefano Stabellini <[email protected]>:
Quoted 17 lines · Zhongze Liu
Quoted 8 lines
This series implements the new xl config entry proposed in [1]. Users can use the new config entry to statically setup shared memory areas among VMs that don't have grant table support so that they could communicate with each other through the static shared memory areas.
[1] Proposla to allow setting up shared memory areas between VMs from xl config file:
https://lists.xen.org/archives/html/xen-devel/2017-08/msg03242.htmlQuoted 7 lines
v2:
* fixed several code style issues.
* introduceMMU__SHARE_MEMin flask av permissions, and add a check to this. permission in the flask hook forxsm_map_gmfn_foreign.
* support rolling back during creation on partial failure.
* refcounting the sshm path instead of using "alive" and "zombie" to label the master and counting the slaves.
Quoted 50 lines
Hey Zhongze,
any plans on sending an update of this series?
Quoted 45 lines
Cheers,
Zhongze Liu (6):
libxc: addxc_domain_remove_from_physmapto wrap
XENMEM_remove_from_physmap
libxl: introduce a new structure to represent static shared memory
regions
libxl:xl: add parsing code to parse "libxl_static_sshm" from xl config
files
xsm: flask: change the dummy xsm policy and flask hook for
map_gmfn_foregin
libxl: support mapping static shared memory areas during domain
creation
libxl: support unmapping static shared memory areas during domain
destructiontools/flask/policy/modules/xen.if | 2 + tools/libxc/include/xenctrl.h | 4 + tools/libxc/xc_domain.c | 11 + tools/libxl/Makefile | 4 +- tools/libxl/libxl.h | 4 + tools/libxl/libxl_arch.h | 6 + tools/libxl/libxl_arm.c | 15 ++ tools/libxl/libxl_create.c | 27 ++ tools/libxl/libxl_domain.c | 5 + tools/libxl/libxl_internal.h | 15 ++ tools/libxl/libxl_sshm.c | 480 ++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_types.idl | 34 ++- tools/libxl/libxl_x86.c | 18 ++ tools/libxl/libxlu_sshm.c | 210 ++++++++++++++++ tools/libxl/libxlutil.h | 6 + tools/xl/xl_parse.c | 24 +- xen/arch/arm/mm.c | 2 +- xen/arch/x86/mm/p2m.c | 2 +- xen/include/xsm/dummy.h | 8 +- xen/include/xsm/xsm.h | 7 +- xen/xsm/flask/hooks.c | 10 +- xen/xsm/flask/policy/access_vectors | 4 + 22 files changed, 883 insertions(+), 15 deletions(-) create mode 100644 tools/libxl/libxl_sshm.c create mode 100644 tools/libxl/libxlu_sshm.c--
2.14.0
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel