From patchwork Mon Sep 11 04:38:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9946625 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4AEA56035D for ; Mon, 11 Sep 2017 04:42:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 40CF627D0C for ; Mon, 11 Sep 2017 04:42:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 35A0528429; Mon, 11 Sep 2017 04:42:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 60D3F27D0C for ; Mon, 11 Sep 2017 04:42:16 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drGVh-0002QD-5r; Mon, 11 Sep 2017 04:39:49 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drGVg-0002Mv-2w for xen-devel@lists.xen.org; Mon, 11 Sep 2017 04:39:48 +0000 Received: from [193.109.254.147] by server-5.bemta-6.messagelabs.com id E2/AB-03454-39316B95; Mon, 11 Sep 2017 04:39:47 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupjkeJIrShJLcpLzFFi42Jpa+sQ0Z0kvC3 SYOE6Y4slHxezODB6HN39mymAMYo1My8pvyKBNWPLhR/MBV3eFWdXfGNqYNxv3cXIxSEkMJ1R 4tLl2SxdjJwcEgK8EkeWzWCFsAMkjl16zAxR1MsosWbtMWaQBJuAvsSKxwfBikQEpCWufb7MC FLELPCFSWLr5Ttgk4QFfCX61h5hArFZBFQl3u+cww5i8wrYSew7eRBqm7zErraLYIM4geIHX7 4DWyAkYCux4PQC1gmMvAsYGVYxahSnFpWlFukameslFWWmZ5TkJmbm6BoamOnlphYXJ6an5iQ mFesl5+duYgSGBAMQ7GBcvDbwEKMkB5OSKO+741sihfiS8lMqMxKLM+KLSnNSiw8xynBwKEnw qghtixQSLEpNT61Iy8wBBidMWoKDR0mENwokzVtckJhbnJkOkTrFaM9xbNPlP0wcHTfvAslNY HLD9wd/mIRY8vLzUqXEeeVA2gRA2jJK8+CGwqLpEqOslDAvI9CZQjwFqUW5mSWo8q8YxTkYlY R5I0Cm8GTmlcDtfgV0FhPQWTyXtoCcVZKIkJJqYPSY88jJfKbKiZZVB7a/eNdyvaTM0P/Ut/X yvjvErMxeMAiwSzk5382++nG53vaOhbKO8ewlyzUu7Wh6yPTLbH4bX/h2lWiLUM/kjjue7zjn BX+M27Xo2btv/sZ+f1ZwqqwWSVntNS2zd9XJE555fL13rk418lQqOJj+hvPnzMjkXQp73v+tO qfEUpyRaKjFXFScCACt+DQhoQIAAA== X-Env-Sender: haozhong.zhang@intel.com X-Msg-Ref: server-2.tower-27.messagelabs.com!1505104735!56506342!23 X-Originating-IP: [134.134.136.20] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTM0LjEzNC4xMzYuMjAgPT4gMzU1MzU4\n X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 50655 invoked from network); 11 Sep 2017 04:39:46 -0000 Received: from mga02.intel.com (HELO mga02.intel.com) (134.134.136.20) by server-2.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 11 Sep 2017 04:39:46 -0000 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Sep 2017 21:39:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.42,376,1500966000"; d="scan'208"; a="1217078541" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.142]) by fmsmga002.fm.intel.com with ESMTP; 10 Sep 2017 21:39:43 -0700 From: Haozhong Zhang To: xen-devel@lists.xen.org Date: Mon, 11 Sep 2017 12:38:09 +0800 Message-Id: <20170911043820.14617-29-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170911043820.14617-1-haozhong.zhang@intel.com> References: <20170911043820.14617-1-haozhong.zhang@intel.com> Cc: Haozhong Zhang , Wei Liu , Andrew Cooper , Ian Jackson , Jan Beulich , Chao Peng , Dan Williams , Daniel De Graaf Subject: [Xen-devel] [RFC XEN PATCH v3 28/39] xen: add hypercall XENMEM_populate_pmem_map X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP This hypercall will be used by device models to map host PMEM pages to guest. Signed-off-by: Haozhong Zhang --- Cc: Daniel De Graaf Cc: Ian Jackson Cc: Wei Liu Cc: Andrew Cooper CC: Jan Beulich --- tools/flask/policy/modules/xen.if | 2 +- tools/libxc/include/xenctrl.h | 17 ++++++++++++++ tools/libxc/xc_domain.c | 15 +++++++++++++ xen/common/compat/memory.c | 1 + xen/common/memory.c | 44 +++++++++++++++++++++++++++++++++++++ xen/include/public/memory.h | 14 +++++++++++- xen/include/xsm/dummy.h | 11 ++++++++++ xen/include/xsm/xsm.h | 12 ++++++++++ xen/xsm/dummy.c | 4 ++++ xen/xsm/flask/hooks.c | 13 +++++++++++ xen/xsm/flask/policy/access_vectors | 2 ++ 11 files changed, 133 insertions(+), 2 deletions(-) diff --git a/tools/flask/policy/modules/xen.if b/tools/flask/policy/modules/xen.if index 912640002e..9634dee25f 100644 --- a/tools/flask/policy/modules/xen.if +++ b/tools/flask/policy/modules/xen.if @@ -55,7 +55,7 @@ define(`create_domain_common', ` psr_cmt_op psr_cat_op soft_reset }; 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 }; + allow $1 $2:mmu { map_read map_write adjust memorymap physmap pinpage mmuext_op updatemp populate_pmem_map }; allow $1 $2:grant setup; allow $1 $2:hvm { cacheattr getparam hvmctl sethvmc setparam nested altp2mhvm altp2mhvm_op dm }; diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index 41e5e3408c..a81dcdbe58 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -2643,6 +2643,23 @@ int xc_nvdimm_pmem_setup_data(xc_interface *xch, unsigned long smfn, unsigned long emfn, unsigned long mgmt_smfn, unsigned long mgmt_emfn); +/* + * Map specified host PMEM pages to the specified guest address. + * + * Parameters: + * xch: xc interface handle + * domid: the target domain id + * mfn: the start MFN of the PMEM pages + * gfn: the start GFN of the target guest physical pages + * nr_mfns: the number of PMEM pages to be mapped + * + * Return: + * On success, return 0. Otherwise, return a non-zero error code. + */ +int xc_domain_populate_pmem_map(xc_interface *xch, uint32_t domid, + unsigned long mfn, unsigned long gfn, + unsigned long nr_mfns); + /* Compat shims */ #include "xenctrl_compat.h" diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c index 3bab4e8bab..b548da750a 100644 --- a/tools/libxc/xc_domain.c +++ b/tools/libxc/xc_domain.c @@ -2397,6 +2397,21 @@ int xc_domain_soft_reset(xc_interface *xch, domctl.domain = (domid_t)domid; return do_domctl(xch, &domctl); } + +int xc_domain_populate_pmem_map(xc_interface *xch, uint32_t domid, + unsigned long mfn, unsigned long gfn, + unsigned long nr_mfns) +{ + struct xen_pmem_map args = { + .domid = domid, + .mfn = mfn, + .gfn = gfn, + .nr_mfns = nr_mfns, + }; + + return do_memory_op(xch, XENMEM_populate_pmem_map, &args, sizeof(args)); +} + /* * Local variables: * mode: C diff --git a/xen/common/compat/memory.c b/xen/common/compat/memory.c index 35bb259808..51bec835b9 100644 --- a/xen/common/compat/memory.c +++ b/xen/common/compat/memory.c @@ -525,6 +525,7 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE_PARAM(void) compat) case XENMEM_add_to_physmap: case XENMEM_remove_from_physmap: case XENMEM_access_op: + case XENMEM_populate_pmem_map: break; case XENMEM_get_vnumainfo: diff --git a/xen/common/memory.c b/xen/common/memory.c index 26da6050f6..31ef480562 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -1379,6 +1380,49 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) } #endif +#ifdef CONFIG_NVDIMM_PMEM + case XENMEM_populate_pmem_map: + { + struct xen_pmem_map map; + struct xen_pmem_map_args args; + + if ( copy_from_guest(&map, arg, 1) ) + return -EFAULT; + + if ( map.domid == DOMID_SELF ) + return -EINVAL; + + d = rcu_lock_domain_by_any_id(map.domid); + if ( !d ) + return -EINVAL; + + rc = xsm_populate_pmem_map(XSM_TARGET, curr_d, d); + if ( rc ) + { + rcu_unlock_domain(d); + return rc; + } + + args.domain = d; + args.mfn = map.mfn; + args.gfn = map.gfn; + args.nr_mfns = map.nr_mfns; + args.nr_done = start_extent; + args.preempted = 0; + + rc = pmem_populate(&args); + + rcu_unlock_domain(d); + + if ( rc == -ERESTART && args.preempted ) + return hypercall_create_continuation( + __HYPERVISOR_memory_op, "lh", + op | (args.nr_done << MEMOP_EXTENT_SHIFT), arg); + + break; + } +#endif /* CONFIG_NVDIMM_PMEM */ + default: rc = arch_memory_op(cmd, arg); break; diff --git a/xen/include/public/memory.h b/xen/include/public/memory.h index 29386df98b..d74436e4b0 100644 --- a/xen/include/public/memory.h +++ b/xen/include/public/memory.h @@ -650,7 +650,19 @@ struct xen_vnuma_topology_info { typedef struct xen_vnuma_topology_info xen_vnuma_topology_info_t; DEFINE_XEN_GUEST_HANDLE(xen_vnuma_topology_info_t); -/* Next available subop number is 28 */ +#define XENMEM_populate_pmem_map 28 + +struct xen_pmem_map { + /* IN */ + domid_t domid; + unsigned long mfn; + unsigned long gfn; + unsigned int nr_mfns; +}; +typedef struct xen_pmem_map xen_pmem_map_t; +DEFINE_XEN_GUEST_HANDLE(xen_pmem_map_t); + +/* Next available subop number is 29 */ #endif /* __XEN_PUBLIC_MEMORY_H__ */ diff --git a/xen/include/xsm/dummy.h b/xen/include/xsm/dummy.h index ba89ea4bc1..6107da308c 100644 --- a/xen/include/xsm/dummy.h +++ b/xen/include/xsm/dummy.h @@ -724,3 +724,14 @@ static XSM_INLINE int xsm_xen_version (XSM_DEFAULT_ARG uint32_t op) return xsm_default_action(XSM_PRIV, current->domain, NULL); } } + +#ifdef CONFIG_NVDIMM_PMEM + +static XSM_INLINE int xsm_populate_pmem_map(XSM_DEFAULT_ARG + struct domain *d1, struct domain *d2) +{ + XSM_ASSERT_ACTION(XSM_TARGET); + return xsm_default_action(action, d1, d2); +} + +#endif /* CONFIG_NVDIMM_PMEM */ diff --git a/xen/include/xsm/xsm.h b/xen/include/xsm/xsm.h index 7f7feffc68..e43e79f719 100644 --- a/xen/include/xsm/xsm.h +++ b/xen/include/xsm/xsm.h @@ -180,6 +180,10 @@ struct xsm_operations { int (*dm_op) (struct domain *d); #endif int (*xen_version) (uint32_t cmd); + +#ifdef CONFIG_NVDIMM_PMEM + int (*populate_pmem_map) (struct domain *d1, struct domain *d2); +#endif }; #ifdef CONFIG_XSM @@ -692,6 +696,14 @@ static inline int xsm_xen_version (xsm_default_t def, uint32_t op) return xsm_ops->xen_version(op); } +#ifdef CONFIG_NVDIMM_PMEM +static inline int xsm_populate_pmem_map(xsm_default_t def, + struct domain *d1, struct domain *d2) +{ + return xsm_ops->populate_pmem_map(d1, d2); +} +#endif /* CONFIG_NVDIMM_PMEM */ + #endif /* XSM_NO_WRAPPERS */ #ifdef CONFIG_MULTIBOOT diff --git a/xen/xsm/dummy.c b/xen/xsm/dummy.c index 479b103614..4d65eaca61 100644 --- a/xen/xsm/dummy.c +++ b/xen/xsm/dummy.c @@ -157,4 +157,8 @@ void __init xsm_fixup_ops (struct xsm_operations *ops) set_to_dummy_if_null(ops, dm_op); #endif set_to_dummy_if_null(ops, xen_version); + +#ifdef CONFIG_NVDIMM_PMEM + set_to_dummy_if_null(ops, populate_pmem_map); +#endif } diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c index edfe529495..d91f246b47 100644 --- a/xen/xsm/flask/hooks.c +++ b/xen/xsm/flask/hooks.c @@ -1719,6 +1719,15 @@ static int flask_xen_version (uint32_t op) } } +#ifdef CONFIG_NVDIMM_PMEM + +static int flask_populate_pmem_map(struct domain *d1, struct domain *d2) +{ + return domain_has_perm(d1, d2, SECCLASS_MMU, MMU__POPULATE_PMEM_MAP); +} + +#endif /* CONFIG_NVDIMM_PMEM */ + long do_flask_op(XEN_GUEST_HANDLE_PARAM(xsm_op_t) u_flask_op); int compat_flask_op(XEN_GUEST_HANDLE_PARAM(xsm_op_t) u_flask_op); @@ -1852,6 +1861,10 @@ static struct xsm_operations flask_ops = { .dm_op = flask_dm_op, #endif .xen_version = flask_xen_version, + +#ifdef CONFIG_NVDIMM_PMEM + .populate_pmem_map = flask_populate_pmem_map, +#endif }; void __init flask_init(const void *policy_buffer, size_t policy_size) diff --git a/xen/xsm/flask/policy/access_vectors b/xen/xsm/flask/policy/access_vectors index af05826064..fe32fd93c8 100644 --- a/xen/xsm/flask/policy/access_vectors +++ b/xen/xsm/flask/policy/access_vectors @@ -387,6 +387,8 @@ 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 +# XENMEM_populate_pmem_map + populate_pmem_map } # control of the paging_domctl split by subop