From patchwork Mon Sep 11 04:37:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9946603 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 B2F626035D for ; Mon, 11 Sep 2017 04:42:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FFFC21C9A for ; Mon, 11 Sep 2017 04:42:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 936C127D0C; Mon, 11 Sep 2017 04:42:04 +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 E852F289DE for ; Mon, 11 Sep 2017 04:42:03 +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 1drGV5-0001Nt-Co; Mon, 11 Sep 2017 04:39:11 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drGV4-0001Li-1N for xen-devel@lists.xen.org; Mon, 11 Sep 2017 04:39:10 +0000 Received: from [193.109.254.147] by server-5.bemta-6.messagelabs.com id F5/2B-03454-D6316B95; Mon, 11 Sep 2017 04:39:09 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuplkeJIrShJLcpLzFFi42Jpa+sQ0c0R3hZ psOibtsWSj4tZHBg9ju7+zRTAGMWamZeUX5HAmnH61FmmgvX2FUt/b2ZrYPxi0MXIxSEkMJ1R 4lXHOvYuRk4OCQFeiSPLZrBC2AESXZ0TmEBsIYFeRolHBzJBbDYBfYkVjw+C1YgISEtc+3yZE WQQs8ApJomOuQeYQRLCAkESEzuusYDYLAKqEpderwUbxCtgJ3GxfzojxAJ5iV1tF8EGcQLFD7 58xwyxzFZiwekFrBMYeRcwMqxi1ChOLSpLLdI1MtdLKspMzyjJTczM0TU0MNPLTS0uTkxPzUl MKtZLzs/dxAgMCAYg2MG4eG3gIUZJDiYlUd53x7dECvEl5adUZiQWZ8QXleakFh9ilOHgUJLg PSO4LVJIsCg1PbUiLTMHGJowaQkOHiUR3kUgad7igsTc4sx0iNQpRnuOY5su/2Hi6Lh5F0huA pMbvj/4wyTEkpeflyolzrsZpE0ApC2jNA9uKCyWLjHKSgnzMgKdKcRTkFqUm1mCKv+KUZyDUU mYV0YIaApPZl4J3O5XQGcxAZ3Fc2kLyFkliQgpqQbGJRG/g//sXSnoPmcb50udlHJB/fj8Zb8 W/+K+1SHMPLUqwfD33pNm5aXf2DVvby+eXy7w+G40wwKuWU68BVaiUbMVn5h9zFjfubrQPeRK wN4j21RVvATF+3lKk57+iJ/EcjmA3zpiYl7ZY3093qT2dw7Mr+r9Zefpv++QX9ixVMW17uGfh e5KLMUZiYZazEXFiQBVcvRLoAIAAA== X-Env-Sender: haozhong.zhang@intel.com X-Msg-Ref: server-2.tower-27.messagelabs.com!1505104735!56506342!6 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 47850 invoked from network); 11 Sep 2017 04:39:08 -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:08 -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:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.42,376,1500966000"; d="scan'208"; a="1217078374" 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:05 -0700 From: Haozhong Zhang To: xen-devel@lists.xen.org Date: Mon, 11 Sep 2017 12:37:52 +0800 Message-Id: <20170911043820.14617-12-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 11/39] xen/pmem: add 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 XEN_SYSCTL_nvdimm_pmem_get_regions, which is a command of hypercall XEN_SYSCTL_nvdimm_op, is to get a list of PMEM regions of 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 | 18 ++++++++++++ tools/libxc/xc_misc.c | 63 ++++++++++++++++++++++++++++++++++++++++ xen/common/pmem.c | 67 +++++++++++++++++++++++++++++++++++++++++++ xen/include/public/sysctl.h | 27 +++++++++++++++++ 4 files changed, 175 insertions(+) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index e4d26967ba..d750e67460 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -2587,6 +2587,24 @@ int xc_domain_cacheflush(xc_interface *xch, uint32_t domid, int xc_nvdimm_pmem_get_regions_nr(xc_interface *xch, uint8_t type, uint32_t *nr); +/* + * Get an array of information 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_* + * buffer: the buffer where the information of PMEM regions is returned, + * the caller should allocate enough memory for it. + * nr : IN: the maximum number of PMEM regions that can be returned + * in @buffer + * OUT: the actual number of returned PMEM regions in @buffer + * + * Return: + * On success, return 0. Otherwise, return a non-zero error code. + */ +int xc_nvdimm_pmem_get_regions(xc_interface *xch, uint8_t type, + void *buffer, uint32_t *nr); + /* Compat shims */ #include "xenctrl_compat.h" diff --git a/tools/libxc/xc_misc.c b/tools/libxc/xc_misc.c index fa66410869..f9ce802eda 100644 --- a/tools/libxc/xc_misc.c +++ b/tools/libxc/xc_misc.c @@ -912,6 +912,69 @@ int xc_nvdimm_pmem_get_regions_nr(xc_interface *xch, uint8_t type, uint32_t *nr) return rc; } +int xc_nvdimm_pmem_get_regions(xc_interface *xch, uint8_t type, + void *buffer, uint32_t *nr) +{ + DECLARE_SYSCTL; + DECLARE_HYPERCALL_BOUNCE(buffer, 0, XC_HYPERCALL_BUFFER_BOUNCE_OUT); + + xen_sysctl_nvdimm_op_t *nvdimm = &sysctl.u.nvdimm; + xen_sysctl_nvdimm_pmem_regions_t *regions = &nvdimm->u.pmem_regions; + unsigned int max; + unsigned long size; + int rc; + + if ( !buffer || !nr ) + return -EINVAL; + + max = *nr; + if ( !max ) + return 0; + + switch ( type ) + { + case PMEM_REGION_TYPE_RAW: + size = sizeof(xen_sysctl_nvdimm_pmem_raw_region_t) * max; + break; + + default: + return -EINVAL; + } + + HYPERCALL_BOUNCE_SET_SIZE(buffer, size); + if ( xc_hypercall_bounce_pre(xch, buffer) ) + return -EFAULT; + + sysctl.cmd = XEN_SYSCTL_nvdimm_op; + nvdimm->cmd = XEN_SYSCTL_nvdimm_pmem_get_regions; + nvdimm->pad = 0; + nvdimm->err = 0; + regions->type = type; + regions->num_regions = max; + + switch ( type ) + { + case PMEM_REGION_TYPE_RAW: + set_xen_guest_handle(regions->u_buffer.raw_regions, buffer); + break; + + default: + rc = -EINVAL; + goto out; + } + + rc = do_sysctl(xch, &sysctl); + if ( !rc ) + *nr = regions->num_regions; + else if ( nvdimm->err ) + rc = -nvdimm->err; + +out: + xc_hypercall_bounce_post(xch, buffer); + + return rc; +} + /* * Local variables: * mode: C diff --git a/xen/common/pmem.c b/xen/common/pmem.c index 995dfcb867..a737e7dc71 100644 --- a/xen/common/pmem.c +++ b/xen/common/pmem.c @@ -22,6 +22,8 @@ #include #include +#include + /* * All PMEM regions presenting in NFIT SPA range structures are linked * in this list. @@ -122,6 +124,67 @@ static int pmem_get_regions_nr(xen_sysctl_nvdimm_pmem_regions_nr_t *regions_nr) return rc; } +static int pmem_get_raw_regions( + XEN_GUEST_HANDLE_64(xen_sysctl_nvdimm_pmem_raw_region_t) regions, + unsigned int *num_regions) +{ + struct list_head *cur; + unsigned int nr = 0, max = *num_regions; + xen_sysctl_nvdimm_pmem_raw_region_t region; + int rc = 0; + + if ( !guest_handle_okay(regions, max * sizeof(region)) ) + return -EINVAL; + + list_for_each(cur, &pmem_raw_regions) + { + struct pmem *pmem = list_entry(cur, struct pmem, link); + + if ( nr >= max ) + break; + + region.smfn = pmem->smfn; + region.emfn = pmem->emfn; + region.pxm = pmem->u.raw.pxm; + + if ( copy_to_guest_offset(regions, nr, ®ion, 1) ) + { + rc = -EFAULT; + break; + } + + nr++; + } + + *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; + int rc = 0; + + if ( !max ) + return 0; + + switch ( type ) + { + case PMEM_REGION_TYPE_RAW: + rc = pmem_get_raw_regions(regions->u_buffer.raw_regions, &max); + break; + + default: + rc = -EINVAL; + } + + if ( !rc ) + regions->num_regions = max; + + return rc; +} + /** * Register a pmem region to Xen. * @@ -167,6 +230,10 @@ int pmem_do_sysctl(struct xen_sysctl_nvdimm_op *nvdimm) rc = pmem_get_regions_nr(&nvdimm->u.pmem_regions_nr); break; + case XEN_SYSCTL_nvdimm_pmem_get_regions: + rc = pmem_get_regions(&nvdimm->u.pmem_regions); + break; + default: rc = -ENOSYS; } diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index cf308bbc45..2635b1c911 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -1121,6 +1121,15 @@ DEFINE_XEN_GUEST_HANDLE(xen_sysctl_set_parameter_t); /* Types of PMEM regions */ #define PMEM_REGION_TYPE_RAW 0 /* PMEM regions detected by Xen */ +/* PMEM_REGION_TYPE_RAW */ +struct xen_sysctl_nvdimm_pmem_raw_region { + uint64_t smfn; + uint64_t emfn; + uint32_t pxm; +}; +typedef struct xen_sysctl_nvdimm_pmem_raw_region xen_sysctl_nvdimm_pmem_raw_region_t; +DEFINE_XEN_GUEST_HANDLE(xen_sysctl_nvdimm_pmem_raw_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_* */ @@ -1129,12 +1138,30 @@ struct xen_sysctl_nvdimm_pmem_regions_nr { 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); +/* XEN_SYSCTL_nvdimm_pmem_get_regions */ +struct xen_sysctl_nvdimm_pmem_regions { + uint8_t type; /* IN: one of PMEM_REGION_TYPE_* */ + uint32_t num_regions; /* IN: the maximum number of entries that can be + returned via the guest handler in @u_buffer + OUT: the actual number of entries returned via + the guest handler in @u_buffer */ + union { + /* if type == PMEM_REGION_TYPE_RAW */ + XEN_GUEST_HANDLE_64(xen_sysctl_nvdimm_pmem_raw_region_t) raw_regions; + } u_buffer; /* IN: the guest handler where the entries of PMEM + regions of the type @type are returned */ +}; +typedef struct xen_sysctl_nvdimm_pmem_regions xen_sysctl_nvdimm_pmem_regions_t; +DEFINE_XEN_GUEST_HANDLE(xen_sysctl_nvdimm_pmem_regions_t); + struct xen_sysctl_nvdimm_op { uint32_t cmd; /* IN: XEN_SYSCTL_nvdimm_*. */ #define XEN_SYSCTL_nvdimm_pmem_get_regions_nr 0 +#define XEN_SYSCTL_nvdimm_pmem_get_regions 1 uint32_t pad; /* IN: Always zero. */ union { xen_sysctl_nvdimm_pmem_regions_nr_t pmem_regions_nr; + xen_sysctl_nvdimm_pmem_regions_t pmem_regions; } u; uint32_t err; /* OUT: error code */ };