From patchwork Mon Sep 11 04:37:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9946597 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 441E26035D for ; Mon, 11 Sep 2017 04:42:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 39F61289DE for ; Mon, 11 Sep 2017 04:42:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2EC4228AD8; Mon, 11 Sep 2017 04:42:00 +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 A28FA289DE for ; Mon, 11 Sep 2017 04:41:59 +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 1drGV4-0001Lr-1O; Mon, 11 Sep 2017 04:39:10 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drGV1-0001Jz-WE for xen-devel@lists.xen.org; Mon, 11 Sep 2017 04:39:08 +0000 Received: from [193.109.254.147] by server-8.bemta-6.messagelabs.com id 72/A6-17770-B6316B95; Mon, 11 Sep 2017 04:39:07 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrFLMWRWlGSWpSXmKPExsXS1tYhopspvC3 S4MF6G4slHxezODB6HN39mymAMYo1My8pvyKBNeP7pR3MBfvVKlZsPcHWwDhNvouRi0NIYDqj xMm+t+xdjJwcEgK8EkeWzWDtYuQAsgMkztwNBgkLCfQySjw8KgRiswnoS6x4fJAVxBYRkJa49 vkyI8gcZoFTTBIdcw8wgySEBUIkVuxsYgGxWQRUJY4tf88GYvMK2Ekc71vIArFLXmJX20WwQZ xA8YMv3zFDLLOVWHB6AesERt4FjAyrGDWKU4vKUot0jcz1kooy0zNKchMzc3QNDcz0clOLixP TU3MSk4r1kvNzNzECw4EBCHYwLl4beIhRkoNJSZT33fEtkUJ8SfkplRmJxRnxRaU5qcWHGGU4 OJQkeM8IbosUEixKTU+tSMvMAQYmTFqCg0dJhHcRSJq3uCAxtzgzHSJ1ilGXo+Pm3T9MQix5+ XmpUuK8m0GKBECKMkrz4EbAouQSo6yUMC8j0FFCPAWpRbmZJajyrxjFORiVhHllhICm8GTmlc BtegV0BBPQETyXtoAcUZKIkJJqYBS+MT9CQ8xm4vUt5u0GP07wWd0W9i4tir3bGFhleF1FQHT Nq6iQytKPJ/Wi+uftmHzE7pb7Iam+189UPuicFGBq2Oqu/LaPk4k1ptM2eck3MelznTl7X8RJ V5kcn1QW/ffVonTfiNzvvjpsEk+83rH5uMV8EVhxewXjDZGlja/1vRvlczdKKbEUZyQaajEXF ScCAGiQ0OKNAgAA X-Env-Sender: haozhong.zhang@intel.com X-Msg-Ref: server-2.tower-27.messagelabs.com!1505104735!56506342!5 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 47817 invoked from network); 11 Sep 2017 04:39:05 -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:05 -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:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.42,376,1500966000"; d="scan'208"; a="1217078361" 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:02 -0700 From: Haozhong Zhang To: xen-devel@lists.xen.org Date: Mon, 11 Sep 2017 12:37:51 +0800 Message-Id: <20170911043820.14617-11-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 10/39] xen/pmem: add XEN_SYSCTL_nvdimm_pmem_get_rgions_nr 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 XEN_SYSCTL_nvdimm_pmem_get_rgions_nr, which is a command of hypercall XEN_SYSCTL_nvdimm_op, is to get the number of PMEM regions of the specified type (see PMEM_REGION_TYPE_*). Signed-off-by: Haozhong Zhang --- Cc: Ian Jackson Cc: Wei Liu Cc: Andrew Cooper Cc: Jan Beulich --- tools/libxc/include/xenctrl.h | 15 +++++++++++++++ tools/libxc/xc_misc.c | 24 ++++++++++++++++++++++++ xen/common/pmem.c | 29 ++++++++++++++++++++++++++++- xen/include/public/sysctl.h | 16 ++++++++++++++-- 4 files changed, 81 insertions(+), 3 deletions(-) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index 43151cb415..e4d26967ba 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -2572,6 +2572,21 @@ int xc_livepatch_replace(xc_interface *xch, char *name, uint32_t timeout); int xc_domain_cacheflush(xc_interface *xch, uint32_t domid, xen_pfn_t start_pfn, xen_pfn_t nr_pfns); +/* + * Get the number of PMEM regions of the specified type. + * + * Parameters: + * xch: xc interface handle + * type: the type of PMEM regions, must be one of PMEM_REGION_TYPE_* + * nr: the number of PMEM regions is returned via this parameter + * + * Return: + * On success, return 0 and the number of PMEM regions is returned via @nr. + * Otherwise, return a non-zero error code. + */ +int xc_nvdimm_pmem_get_regions_nr(xc_interface *xch, + uint8_t type, uint32_t *nr); + /* Compat shims */ #include "xenctrl_compat.h" diff --git a/tools/libxc/xc_misc.c b/tools/libxc/xc_misc.c index 7e15e904e3..fa66410869 100644 --- a/tools/libxc/xc_misc.c +++ b/tools/libxc/xc_misc.c @@ -888,6 +888,30 @@ int xc_livepatch_replace(xc_interface *xch, char *name, uint32_t timeout) return _xc_livepatch_action(xch, name, LIVEPATCH_ACTION_REPLACE, timeout); } +int xc_nvdimm_pmem_get_regions_nr(xc_interface *xch, uint8_t type, uint32_t *nr) +{ + DECLARE_SYSCTL; + xen_sysctl_nvdimm_op_t *nvdimm = &sysctl.u.nvdimm; + int rc; + + if ( !nr || type != PMEM_REGION_TYPE_RAW ) + return -EINVAL; + + sysctl.cmd = XEN_SYSCTL_nvdimm_op; + nvdimm->cmd = XEN_SYSCTL_nvdimm_pmem_get_regions_nr; + nvdimm->pad = 0; + nvdimm->u.pmem_regions_nr.type = type; + nvdimm->err = 0; + + rc = do_sysctl(xch, &sysctl); + if ( !rc ) + *nr = nvdimm->u.pmem_regions_nr.num_regions; + else if ( nvdimm->err ) + rc = nvdimm->err; + + return rc; +} + /* * Local variables: * mode: C diff --git a/xen/common/pmem.c b/xen/common/pmem.c index d67f237cd5..995dfcb867 100644 --- a/xen/common/pmem.c +++ b/xen/common/pmem.c @@ -105,6 +105,23 @@ static int pmem_list_add(struct list_head *list, return rc; } +static int pmem_get_regions_nr(xen_sysctl_nvdimm_pmem_regions_nr_t *regions_nr) +{ + int rc = 0; + + switch ( regions_nr->type ) + { + case PMEM_REGION_TYPE_RAW: + regions_nr->num_regions = nr_raw_regions; + break; + + default: + rc = -EINVAL; + } + + return rc; +} + /** * Register a pmem region to Xen. * @@ -142,7 +159,17 @@ int pmem_register(unsigned long smfn, unsigned long emfn, unsigned int pxm) */ int pmem_do_sysctl(struct xen_sysctl_nvdimm_op *nvdimm) { - int rc = -ENOSYS; + int rc; + + switch ( nvdimm->cmd ) + { + case XEN_SYSCTL_nvdimm_pmem_get_regions_nr: + rc = pmem_get_regions_nr(&nvdimm->u.pmem_regions_nr); + break; + + default: + rc = -ENOSYS; + } nvdimm->err = -rc; diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index e8272ae968..cf308bbc45 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -1118,11 +1118,23 @@ DEFINE_XEN_GUEST_HANDLE(xen_sysctl_set_parameter_t); * Interface for NVDIMM management. */ +/* Types of PMEM regions */ +#define PMEM_REGION_TYPE_RAW 0 /* PMEM regions detected by Xen */ + +/* XEN_SYSCTL_nvdimm_pmem_get_regions_nr */ +struct xen_sysctl_nvdimm_pmem_regions_nr { + uint8_t type; /* IN: one of PMEM_REGION_TYPE_* */ + uint32_t num_regions; /* OUT: the number of PMEM regions of type @type */ +}; +typedef struct xen_sysctl_nvdimm_pmem_regions_nr xen_sysctl_nvdimm_pmem_regions_nr_t; +DEFINE_XEN_GUEST_HANDLE(xen_sysctl_nvdimm_pmem_regions_nr_t); + struct xen_sysctl_nvdimm_op { - uint32_t cmd; /* IN: XEN_SYSCTL_nvdimm_*; none is implemented yet. */ + uint32_t cmd; /* IN: XEN_SYSCTL_nvdimm_*. */ +#define XEN_SYSCTL_nvdimm_pmem_get_regions_nr 0 uint32_t pad; /* IN: Always zero. */ union { - /* Parameters of XEN_SYSCTL_nvdimm_* will be added here. */ + xen_sysctl_nvdimm_pmem_regions_nr_t pmem_regions_nr; } u; uint32_t err; /* OUT: error code */ };