From patchwork Tue Oct 25 03:40:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9393893 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 8F2BD60762 for ; Tue, 25 Oct 2016 02:36:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 824A528B39 for ; Tue, 25 Oct 2016 02:36:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 761E82927D; Tue, 25 Oct 2016 02:36:15 +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 079D428B39 for ; Tue, 25 Oct 2016 02:36:15 +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 1byrYy-0004S5-EC; Tue, 25 Oct 2016 02:34:04 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1byrYx-0004Qx-4w for xen-devel@lists.xenproject.org; Tue, 25 Oct 2016 02:34:03 +0000 Received: from [193.109.254.147] by server-1.bemta-6.messagelabs.com id 9F/FF-01767-A94CE085; Tue, 25 Oct 2016 02:34:02 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrPLMWRWlGSWpSXmKPExsVywNykWHfmEb4 Ig5m3LCy+b5nM5MDocfjDFZYAxijWzLyk/IoE1oxdP3YwFTzSrVjes52xgbFNqYuRk0NIoELi ++u5rCC2hACvxJFlM6DsAIkr32YzdzFyAdU0MEpcPLGEESTBJqAu8fhrDxOILSKgJHFv1WQmk CJmgf2MEr9ePmYBSQgLhEhcebEezGYRUJU48GcyWDOvgLvEj29vGSE2yEmcPDYZbBungIfEnb 3H2SEucpfoa2hinMDIu4CRYRWjRnFqUVlqka6huV5SUWZ6RkluYmaOrqGBmV5uanFxYnpqTmJ SsV5yfu4mRmBAMADBDsbbGwMOMUpyMCmJ8s7cxBchxJeUn1KZkVicEV9UmpNafIhRhoNDSYJ3 /WGgnGBRanpqRVpmDjA0YdISHDxKIrxPQNK8xQWJucWZ6RCpU4yKUuK8i0ASAiCJjNI8uDZYP FxilJUS5mUEOkSIpyC1KDezBFX+FaM4B6OSMO8LkCk8mXklcNNfAS1mAlosGM8DsrgkESEl1c Co8azqd4jCCRMW3yq+zTnNi9pZ+A5smdKfvHb1ydnTm36s6OgvnRrHHttqWB708uxOlopo2/O R0TOmyaYnpoWu5fc81hj/WN6xceO+pL5pwrypXe4NshqF9Qv6fhdVimwyLawMZimyfspyZJ7o Seu4v0I63bcVz5+bocV1gWm7BNvVzeF30pRYijMSDbWYi4oTAU+6YwGCAgAA X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-14.tower-27.messagelabs.com!1477362814!54875270!9 X-Originating-IP: [192.55.52.115] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.0.13; banners=-,-,- X-VirusChecked: Checked Received: (qmail 50357 invoked from network); 25 Oct 2016 02:34:01 -0000 Received: from mga14.intel.com (HELO mga14.intel.com) (192.55.52.115) by server-14.tower-27.messagelabs.com with DHE-RSA-CAMELLIA256-SHA encrypted SMTP; 25 Oct 2016 02:34:01 -0000 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP; 24 Oct 2016 19:34:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.31,544,1473145200"; d="scan'208"; a="1049570185" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.60]) by orsmga001.jf.intel.com with ESMTP; 24 Oct 2016 19:33:59 -0700 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Tue, 25 Oct 2016 11:40:56 +0800 Message-Id: <1477366863-5246-9-git-send-email-yi.y.sun@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1477366863-5246-1-git-send-email-yi.y.sun@linux.intel.com> References: <1477366863-5246-1-git-send-email-yi.y.sun@linux.intel.com> Cc: wei.liu2@citrix.com, he.chen@linux.intel.com, andrew.cooper3@citrix.com, ian.jackson@eu.citrix.com, Yi Sun , jbeulich@suse.com, chao.p.peng@linux.intel.com Subject: [Xen-devel] [PATCH v3 08/15] x86: refactor psr: Implement get hw info callback function 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 Get feature HW info is an interface provided by psr.c. This can be abstracted as an operation. This patch defines 'get_feat_info' callback function to get the feature HW info and implement the callback function for L3 CAT/CDP. It also modifies the sysctl interface to make it general. Signed-off-by: Yi Sun --- xen/arch/x86/psr.c | 55 ++++++++++++++++++++++++++++++++++++----------- xen/arch/x86/sysctl.c | 17 ++++++++++----- xen/include/asm-x86/psr.h | 4 ++-- 3 files changed, 56 insertions(+), 20 deletions(-) diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c index 750278c..acd180c 100644 --- a/xen/arch/x86/psr.c +++ b/xen/arch/x86/psr.c @@ -27,6 +27,10 @@ /* Per spec, the maximum COS register number is 128. */ #define MAX_COS_REG_NUM 128 +#define CBM_LEN 0 +#define COS_MAX 1 +#define CDP_FLAG 2 + enum psr_feat_type { PSR_SOCKET_L3_CAT = 0, PSR_SOCKET_L3_CDP, @@ -45,6 +49,9 @@ struct feat_ops { unsigned int ecx, unsigned int edx, struct feat_node *feat, struct psr_cat_socket_info *info); + /* get_feat_info is used to get feature HW info. */ + bool (*get_feat_info)(const struct feat_node *feat, enum cbm_type type, + uint32_t dat[], uint32_t array_len); }; /* CAT/CDP HW info data structure. */ @@ -209,8 +216,37 @@ static void l3_cat_init_feature(unsigned int eax, unsigned int ebx, test_bit(PSR_SOCKET_L3_CDP, &info->feat_mask) ? "on" : "off"); } +static bool l3_cat_get_feat_info(const struct feat_node *feat, + enum cbm_type type, + uint32_t dat[], uint32_t array_len) +{ + if ( !dat || 3 > array_len ) + return false; + + switch ( type ) { + case PSR_CBM_TYPE_L3: + case PSR_CBM_TYPE_L3_DATA: + case PSR_CBM_TYPE_L3_CODE: + if ( feat->feature == PSR_SOCKET_L3_CDP ) + dat[CDP_FLAG] |= XEN_SYSCTL_PSR_CAT_L3_CDP; + else + dat[CDP_FLAG] = 0; + break; + + default: + /* This feature is not requested feature. */ + return false; + } + + dat[CBM_LEN] = feat->info.cbm_len; + dat[COS_MAX] = feat->info.cos_max; + + return true; +} + struct feat_ops l3_cat_ops = { .init_feature = l3_cat_init_feature, + .get_feat_info = l3_cat_get_feat_info, }; static unsigned int get_socket_cpu(unsigned int socket) @@ -434,8 +470,8 @@ static inline bool_t cdp_is_enabled(unsigned int socket) return test_bit(PSR_SOCKET_L3_CDP, &cat_socket_info[socket].feat_mask); } -int psr_get_cat_l3_info(unsigned int socket, uint32_t *cbm_len, - uint32_t *cos_max, uint32_t *flags) +int psr_get_info(unsigned int socket, enum cbm_type type, + uint32_t dat[], uint32_t array_len) { struct psr_cat_socket_info *info = get_cat_socket_info(socket); struct feat_node *feat_tmp; @@ -443,18 +479,11 @@ int psr_get_cat_l3_info(unsigned int socket, uint32_t *cbm_len, if ( IS_ERR(info) ) return PTR_ERR(info); - feat_tmp = get_feat_l3(info); - if ( !feat_tmp ) - return -ENOENT; - - *cbm_len = feat_tmp->info.cbm_len; - *cos_max = feat_tmp->info.cos_max; - - *flags = 0; - if ( cdp_is_enabled(socket) ) - *flags |= XEN_SYSCTL_PSR_CAT_L3_CDP; + list_for_each_entry(feat_tmp, &info->feat_list, list) + if ( feat_tmp->ops.get_feat_info(feat_tmp, type, dat, array_len) ) + return 0; - return 0; + return -ENOENT; } int psr_get_l3_cbm(struct domain *d, unsigned int socket, diff --git a/xen/arch/x86/sysctl.c b/xen/arch/x86/sysctl.c index 14e7dc7..e82adec 100644 --- a/xen/arch/x86/sysctl.c +++ b/xen/arch/x86/sysctl.c @@ -83,6 +83,9 @@ void arch_do_physinfo(xen_sysctl_physinfo_t *pi) pi->capabilities |= XEN_SYSCTL_PHYSCAP_hvm_directio; } +#define CBM_LEN 0 +#define COS_MAX 1 +#define CDP_FLAG 2 long arch_do_sysctl( struct xen_sysctl *sysctl, XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) { @@ -176,15 +179,19 @@ long arch_do_sysctl( switch ( sysctl->u.psr_cat_op.cmd ) { case XEN_SYSCTL_PSR_CAT_get_l3_info: - ret = psr_get_cat_l3_info(sysctl->u.psr_cat_op.target, - &sysctl->u.psr_cat_op.u.l3_info.cbm_len, - &sysctl->u.psr_cat_op.u.l3_info.cos_max, - &sysctl->u.psr_cat_op.u.l3_info.flags); + { + uint32_t dat[3]; + ret = psr_get_info(sysctl->u.psr_cat_op.target, + PSR_CBM_TYPE_L3, dat, 3); + + sysctl->u.psr_cat_op.u.l3_info.cbm_len = dat[CBM_LEN]; + sysctl->u.psr_cat_op.u.l3_info.cos_max = dat[COS_MAX]; + sysctl->u.psr_cat_op.u.l3_info.flags = dat[CDP_FLAG]; if ( !ret && __copy_field_to_guest(u_sysctl, sysctl, u.psr_cat_op) ) ret = -EFAULT; break; - + } default: ret = -EOPNOTSUPP; break; diff --git a/xen/include/asm-x86/psr.h b/xen/include/asm-x86/psr.h index 57f47e9..eccfa75 100644 --- a/xen/include/asm-x86/psr.h +++ b/xen/include/asm-x86/psr.h @@ -63,8 +63,8 @@ int psr_alloc_rmid(struct domain *d); void psr_free_rmid(struct domain *d); void psr_ctxt_switch_to(struct domain *d); -int psr_get_cat_l3_info(unsigned int socket, uint32_t *cbm_len, - uint32_t *cos_max, uint32_t *flags); +int psr_get_info(unsigned int socket, enum cbm_type type, + uint32_t dat[], uint32_t array_len); int psr_get_l3_cbm(struct domain *d, unsigned int socket, uint64_t *cbm, enum cbm_type type); int psr_set_l3_cbm(struct domain *d, unsigned int socket,