From patchwork Mon Sep 11 04:38:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9946587 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 6A5246035D for ; Mon, 11 Sep 2017 04:41:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 60C61289DE for ; Mon, 11 Sep 2017 04:41:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 559D028AD8; Mon, 11 Sep 2017 04:41:47 +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 DFEE9289DE for ; Mon, 11 Sep 2017 04:41:46 +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 1drGVa-0002C3-7K; Mon, 11 Sep 2017 04:39:42 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drGVZ-00029W-1x for xen-devel@lists.xen.org; Mon, 11 Sep 2017 04:39:41 +0000 Received: from [193.109.254.147] by server-1.bemta-6.messagelabs.com id 87/38-03414-C8316B95; Mon, 11 Sep 2017 04:39:40 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpkkeJIrShJLcpLzFFi42Jpa+sQ0e0U3hZ pMOe8mcWSj4tZHBg9ju7+zRTAGMWamZeUX5HAmjH9xF7Ggl7lijMvMxoYm2W6GLk4hASmM0q8 6H3P2sXIySEhwCtxZNkMKDtA4uzL0+wQRb2MEr2TdjKCJNgE9CVWPD4IViQiIC1x7fNlRpAiZ oFTTBIdcw8wgySEBQokdjZuZQexWQRUJe6cfw3WwCtgJ/F62Us2iA3yErvaLoLFOYHiB1++A+ sVErCVWHB6AesERt4FjAyrGDWKU4vKUot0jcz1kooy0zNKchMzc3QNDcz0clOLixPTU3MSk4r 1kvNzNzECA4IBCHYwLl4beIhRkoNJSZT33fEtkUJ8SfkplRmJxRnxRaU5qcWHGGU4OJQkeFWE tkUKCRalpqdWpGXmAEMTJi3BwaMkwhsFkuYtLkjMLc5Mh0idYjTmOLbp8h8mjo6bd/8wCbHk5 eelSonzyoGUCoCUZpTmwQ2CxcwlRlkpYV5GoNOEeApSi3IzS1DlXzGKczAqCfNGgEzhycwrgd v3CugUJqBTeC5tATmlJBEhJdXAmD7bO3zlu46V8jfLv27MfXCBee3JaTe2zTl7K/6U3oUFfBl eJ10/XVnC9qqbm9G2gfvWAq9Xt5r4p4puVvPSj7/Vybvrv9Cq+69Yuj7P+eXBFalh2hzjoWZ4 9sn27q5llwPFzkbIrZ79Xp8nP2MSs+mRQx9zrp6d1x5pHvYpvb/1VdlBpzmXPyuxFGckGmoxF xUnAgBEH/kXlAIAAA== X-Env-Sender: haozhong.zhang@intel.com X-Msg-Ref: server-2.tower-27.messagelabs.com!1505104735!56506342!19 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 49991 invoked from network); 11 Sep 2017 04:39:37 -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:37 -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:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.42,376,1500966000"; d="scan'208"; a="1217078500" 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:34 -0700 From: Haozhong Zhang To: xen-devel@lists.xen.org Date: Mon, 11 Sep 2017 12:38:05 +0800 Message-Id: <20170911043820.14617-25-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 Subject: [Xen-devel] [RFC XEN PATCH v3 24/39] xen/pmem: support PMEM_REGION_TYPE_DATA for XEN_SYSCTL_nvdimm_pmem_get_regions 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 Allow XEN_SYSCTL_nvdimm_pmem_get_regions to return a list of data PMEM regions. Signed-off-by: Haozhong Zhang --- Cc: Ian Jackson Cc: Wei Liu Cc: Andrew Cooper Cc: Jan Beulich --- tools/libxc/xc_misc.c | 8 ++++++++ xen/common/pmem.c | 46 +++++++++++++++++++++++++++++++++++++++++++++ xen/include/public/sysctl.h | 12 ++++++++++++ 3 files changed, 66 insertions(+) diff --git a/tools/libxc/xc_misc.c b/tools/libxc/xc_misc.c index db74df853a..93a1f8fdc5 100644 --- a/tools/libxc/xc_misc.c +++ b/tools/libxc/xc_misc.c @@ -944,6 +944,10 @@ int xc_nvdimm_pmem_get_regions(xc_interface *xch, uint8_t type, size = sizeof(xen_sysctl_nvdimm_pmem_mgmt_region_t) * max; break; + case PMEM_REGION_TYPE_DATA: + size = sizeof(xen_sysctl_nvdimm_pmem_data_region_t) * max; + break; + default: return -EINVAL; } @@ -969,6 +973,10 @@ int xc_nvdimm_pmem_get_regions(xc_interface *xch, uint8_t type, set_xen_guest_handle(regions->u_buffer.mgmt_regions, buffer); break; + case PMEM_REGION_TYPE_DATA: + set_xen_guest_handle(regions->u_buffer.data_regions, buffer); + break; + default: rc = -EINVAL; goto out; diff --git a/xen/common/pmem.c b/xen/common/pmem.c index cbe557c220..ed4a014c30 100644 --- a/xen/common/pmem.c +++ b/xen/common/pmem.c @@ -251,6 +251,48 @@ static int pmem_get_mgmt_regions( return rc; } +static int pmem_get_data_regions( + XEN_GUEST_HANDLE_64(xen_sysctl_nvdimm_pmem_data_region_t) regions, + unsigned int *num_regions) +{ + struct list_head *cur; + unsigned int nr = 0, max = *num_regions; + xen_sysctl_nvdimm_pmem_data_region_t region; + int rc = 0; + + if ( !guest_handle_okay(regions, max * sizeof(region)) ) + return -EINVAL; + + spin_lock(&pmem_data_lock); + + list_for_each(cur, &pmem_data_regions) + { + struct pmem *pmem = list_entry(cur, struct pmem, link); + + if ( nr >= max ) + break; + + region.smfn = pmem->smfn; + region.emfn = pmem->emfn; + region.mgmt_smfn = pmem->u.data.mgmt_smfn; + region.mgmt_emfn = pmem->u.data.mgmt_emfn; + + if ( copy_to_guest_offset(regions, nr, ®ion, 1) ) + { + rc = -EFAULT; + break; + } + + nr++; + } + + spin_unlock(&pmem_data_lock); + + *num_regions = nr; + + return rc; +} + static int pmem_get_regions(xen_sysctl_nvdimm_pmem_regions_t *regions) { unsigned int type = regions->type, max = regions->num_regions; @@ -269,6 +311,10 @@ static int pmem_get_regions(xen_sysctl_nvdimm_pmem_regions_t *regions) rc = pmem_get_mgmt_regions(regions->u_buffer.mgmt_regions, &max); break; + case PMEM_REGION_TYPE_DATA: + rc = pmem_get_data_regions(regions->u_buffer.data_regions, &max); + break; + default: rc = -EINVAL; } diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index d7c12f23fb..8595ea438a 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -1141,6 +1141,16 @@ struct xen_sysctl_nvdimm_pmem_mgmt_region { typedef struct xen_sysctl_nvdimm_pmem_mgmt_region xen_sysctl_nvdimm_pmem_mgmt_region_t; DEFINE_XEN_GUEST_HANDLE(xen_sysctl_nvdimm_pmem_mgmt_region_t); +/* PMEM_REGION_TYPE_DATA */ +struct xen_sysctl_nvdimm_pmem_data_region { + uint64_t smfn; + uint64_t emfn; + uint64_t mgmt_smfn; + uint64_t mgmt_emfn; +}; +typedef struct xen_sysctl_nvdimm_pmem_data_region xen_sysctl_nvdimm_pmem_data_region_t; +DEFINE_XEN_GUEST_HANDLE(xen_sysctl_nvdimm_pmem_data_region_t); + /* XEN_SYSCTL_nvdimm_pmem_get_regions_nr */ struct xen_sysctl_nvdimm_pmem_regions_nr { uint8_t type; /* IN: one of PMEM_REGION_TYPE_* */ @@ -1161,6 +1171,8 @@ struct xen_sysctl_nvdimm_pmem_regions { XEN_GUEST_HANDLE_64(xen_sysctl_nvdimm_pmem_raw_region_t) raw_regions; /* if type == PMEM_REGION_TYPE_MGMT */ XEN_GUEST_HANDLE_64(xen_sysctl_nvdimm_pmem_mgmt_region_t) mgmt_regions; + /* if type == PMEM_REGION_TYPE_DATA */ + XEN_GUEST_HANDLE_64(xen_sysctl_nvdimm_pmem_data_region_t) data_regions; } u_buffer; /* IN: the guest handler where the entries of PMEM regions of the type @type are returned */ };