From patchwork Thu Mar 16 11:07:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9627889 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 C45D66048C for ; Thu, 16 Mar 2017 11:16:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC294285A1 for ; Thu, 16 Mar 2017 11:16:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B1075285B5; Thu, 16 Mar 2017 11:16:24 +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.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID 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 061752857D for ; Thu, 16 Mar 2017 11:16:24 +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 1coTLy-0004HJ-Fh; Thu, 16 Mar 2017 11:13:58 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1coTLx-0004G6-Ae for xen-devel@lists.xenproject.org; Thu, 16 Mar 2017 11:13:57 +0000 Received: from [85.158.137.68] by server-9.bemta-3.messagelabs.com id F1/4E-20914-4737AC85; Thu, 16 Mar 2017 11:13:56 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrNLMWRWlGSWpSXmKPExsVywNwkVrek+FS EQfNTZovvWyYzOTB6HP5whSWAMYo1My8pvyKBNaN/yhbmgoOOFTv/r2JrYNyo38XIycEicItJ 4voh+S5GLg4hgWmMEkdXzGMESUgI8EocWTaDFcL2l9g9ax4LRFEDo8SkjnXMIAk2AXWJx197m EBsEQEliXurJjOBFDEL7GSSWHf6O1iRsICfRO+B32xdjBxA61Ql1u8sAQnzCrhLHHh7hAligZ zEyWOTwZZxCnhIfGxvB7OFgGrebfjLPoGRbwEjwypGjeLUorLUIl1DE72kosz0jJLcxMwcXUM DY73c1OLixPTUnMSkYr3k/NxNjMBAYQCCHYwrtnseYpTkYFIS5S3/cSJCiC8pP6UyI7E4I76o NCe1+BCjDAeHkgTvEaWTEUKCRanpqRVpmTnAkIVJS3DwKInw5oKkeYsLEnOLM9MhUqcYFaXEe S+AJARAEhmleXBtsDi5xCgrJczLCHSIEE9BalFuZgmq/CtGcQ5GJWHezSBTeDLzSuCmvwJazA S0+O2HEyCLSxIRUlINjA7LwtZZlK/3dN+YE1rXy3f6iauga9WzT757mXb77zu9v/JaQs7eeYc O2kma5XxbfMfHzzeoTPbw7epbitMzHKZLuO29esNyvfSSIqnisz+mrdcKfydn1DFrCUfbi49X u+6HzTmWy/7aMyPF6tWJkH277zGI1Dz/872m1N8h7LOIl9vKgCNsjkosxRmJhlrMRcWJANuLK f+OAgAA X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-2.tower-31.messagelabs.com!1489662818!78881615!7 X-Originating-IP: [192.55.52.93] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTkyLjU1LjUyLjkzID0+IDMyNDY2NQ==\n X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 7654 invoked from network); 16 Mar 2017 11:13:55 -0000 Received: from mga11.intel.com (HELO mga11.intel.com) (192.55.52.93) by server-2.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 16 Mar 2017 11:13:55 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1489662835; x=1521198835; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=zUkezw7huLuYspPIsNTdSI/DzngyeCEhQfGFguhhUc8=; b=CnFb/R1t0p77gt/6N3dd4bNoOH03A+6yBCK7vVlZYqiPxDo/R9BVAy5G x83RejdOzkm0c6xiFo7v4Oub5Pu8ag==; Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Mar 2017 04:13:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,172,1486454400"; d="scan'208";a="944976443" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.63]) by orsmga003.jf.intel.com with ESMTP; 16 Mar 2017 04:13:52 -0700 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Thu, 16 Mar 2017 19:07:58 +0800 Message-Id: <1489662495-5375-9-git-send-email-yi.y.sun@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1489662495-5375-1-git-send-email-yi.y.sun@linux.intel.com> References: <1489662495-5375-1-git-send-email-yi.y.sun@linux.intel.com> Cc: kevin.tian@intel.com, wei.liu2@citrix.com, andrew.cooper3@citrix.com, dario.faggioli@citrix.com, he.chen@linux.intel.com, ian.jackson@eu.citrix.com, Yi Sun , mengxu@cis.upenn.edu, jbeulich@suse.com, chao.p.peng@linux.intel.com, roger.pau@citrix.com Subject: [Xen-devel] [PATCH v9 08/25] x86: refactor psr: L3 CAT: implement get value flow. 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 There is an interface in user space to show feature value of domains. This patch implements get value flow in hypervisor including L3 CAT callback function. It also changes domctl interface to make it more general. With this patch, 'psr-cat-show' can work for L3 CAT but not for L3 code/data which is implemented in patch "x86: refactor psr: implement get value flow for CDP.". Signed-off-by: Yi Sun Reviewed-by: Konrad Rzeszutek Wilk --- v9: - add commit message to explain there is an user space interface. - rename 'l3_cat_get_val' to 'cat_get_val' to cover all L3/L2 CAT features. (suggested by Roger Pau) - replace feature list handling to feature array handling. (suggested by Roger Pau) - change parameter of 'psr_get'. Use 'psr_cos_ids' directly to replace domain. Also declare it to 'const'. (suggested by Jan Beulich) - change code flow to remove 'psr_get' but add 'psr_get_feat' to make codes more reasonable. (suggested by Jan Beulich) - modify patch title to indicate 'L3 CAT'. (suggested by Jan Beulich) - move cos check into common function because this check is required by all features. (suggested by Jan Beulich) - fix coding style issue. (suggested by Jan Beulich) - changes about 'uint64_t' to 'uint32_t'.. (suggested by Jan Beulich) v7: - rename '__psr_get' to 'psr_get'. (suggested by Wei Liu) v6: - modify commit message to make it clearer. (suggested by Konrad Rzeszutek Wilk) - remove one extra space in code. (suggested by Konrad Rzeszutek Wilk) - remove unnecessary comment. (suggested by Konrad Rzeszutek Wilk) - write a helper function to move get info and get val functions into it. Because most codes of 'get_info' and 'get_val' are same. (suggested by Konrad Rzeszutek Wilk) v5: - rename 'dat[]' to 'data[]' (suggested by Jan Beulich) - modify variables names to make them better, e.g. 'feat_tmp' to 'feat'. (suggested by Jan Beulich) - check if feature type match in caller of feature callback function. (suggested by Jan Beulich) v4: - create this patch to make codes easier to understand. (suggested by Jan Beulich) --- xen/arch/x86/domctl.c | 21 +++++++++-------- xen/arch/x86/psr.c | 58 +++++++++++++++++++++++++++++++++++++++++------ xen/include/asm-x86/psr.h | 4 ++-- 3 files changed, 65 insertions(+), 18 deletions(-) diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c index 02b48e8..e714d1d 100644 --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -1455,23 +1455,26 @@ long arch_do_domctl( break; case XEN_DOMCTL_PSR_CAT_OP_GET_L3_CBM: - ret = psr_get_l3_cbm(d, domctl->u.psr_cat_op.target, - &domctl->u.psr_cat_op.data, - PSR_CBM_TYPE_L3); + domctl->u.psr_cat_op.data = 0; + ret = psr_get_val(d, domctl->u.psr_cat_op.target, + (uint32_t *)&domctl->u.psr_cat_op.data, + PSR_CBM_TYPE_L3); copyback = 1; break; case XEN_DOMCTL_PSR_CAT_OP_GET_L3_CODE: - ret = psr_get_l3_cbm(d, domctl->u.psr_cat_op.target, - &domctl->u.psr_cat_op.data, - PSR_CBM_TYPE_L3_CODE); + domctl->u.psr_cat_op.data = 0; + ret = psr_get_val(d, domctl->u.psr_cat_op.target, + (uint32_t *)&domctl->u.psr_cat_op.data, + PSR_CBM_TYPE_L3_CODE); copyback = 1; break; case XEN_DOMCTL_PSR_CAT_OP_GET_L3_DATA: - ret = psr_get_l3_cbm(d, domctl->u.psr_cat_op.target, - &domctl->u.psr_cat_op.data, - PSR_CBM_TYPE_L3_DATA); + domctl->u.psr_cat_op.data = 0; + ret = psr_get_val(d, domctl->u.psr_cat_op.target, + (uint32_t *)&domctl->u.psr_cat_op.data, + PSR_CBM_TYPE_L3_DATA); copyback = 1; break; diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c index 83358e3..53105f5 100644 --- a/xen/arch/x86/psr.c +++ b/xen/arch/x86/psr.c @@ -97,6 +97,10 @@ struct feat_node { /* get_feat_info is used to get feature HW info. */ bool (*get_feat_info)(const struct feat_node *feat, uint32_t data[], unsigned int array_len); + + /* get_val is used to get feature COS register value. */ + void (*get_val)(const struct feat_node *feat, unsigned int cos, + enum cbm_type type, uint32_t *val); } ops; /* Encapsulate feature specific HW info here. */ @@ -275,10 +279,17 @@ static bool cat_get_feat_info(const struct feat_node *feat, return true; } +static void cat_get_val(const struct feat_node *feat, unsigned int cos, + enum cbm_type type, uint32_t *val) +{ + *val = feat->cos_reg_val[cos]; +} + /* L3 CAT ops */ static const struct feat_ops l3_cat_ops = { .get_cos_max = cat_get_cos_max, .get_feat_info = cat_get_feat_info, + .get_val = cat_get_val, }; static void __init parse_psr_bool(char *s, char *value, char *feature, @@ -504,21 +515,30 @@ static struct psr_socket_info *get_socket_info(unsigned int socket) return socket_info + socket; } -int psr_get_info(unsigned int socket, enum cbm_type type, - uint32_t data[], unsigned int array_len) +static const struct feat_node * psr_get_feat(unsigned int socket, + enum cbm_type type) { const struct psr_socket_info *info = get_socket_info(socket); const struct feat_node *feat; enum psr_feat_type feat_type; if ( IS_ERR(info) ) - return PTR_ERR(info); + return NULL; + + feat_type = psr_cbm_type_to_feat_type(type); + feat = info->features[feat_type]; + return feat; +} + +int psr_get_info(unsigned int socket, enum cbm_type type, + uint32_t data[], unsigned int array_len) +{ + const struct feat_node *feat; if ( !data ) return -EINVAL; - feat_type = psr_cbm_type_to_feat_type(type); - feat = info->features[feat_type]; + feat = psr_get_feat(socket, type); if ( !feat ) return -ENOENT; @@ -528,9 +548,33 @@ int psr_get_info(unsigned int socket, enum cbm_type type, return -EINVAL; } -int psr_get_l3_cbm(struct domain *d, unsigned int socket, - uint64_t *cbm, enum cbm_type type) +int psr_get_val(struct domain *d, unsigned int socket, + uint32_t *val, enum cbm_type type) { + const struct feat_node *feat; + unsigned int cos; + + if ( !d || !val ) + return -EINVAL; + + feat = psr_get_feat(socket, type); + if ( !feat ) + return -ENOENT; + + cos = d->arch.psr_cos_ids[socket]; + /* + * If input cos exceeds current feature's cos_max, we should return its + * default value which is stored in cos 0. This case only happens + * when more than two features enabled concurrently and at least one + * features's cos_max is bigger than others. When a domain's working cos + * id is bigger than some features' cos_max, HW automatically works as + * default value for those features which cos_max is smaller. + */ + if ( cos > feat->ops.get_cos_max(feat) ) + cos = 0; + + feat->ops.get_val(feat, cos, type, val); + return 0; } diff --git a/xen/include/asm-x86/psr.h b/xen/include/asm-x86/psr.h index e27e685..cd00733 100644 --- a/xen/include/asm-x86/psr.h +++ b/xen/include/asm-x86/psr.h @@ -72,8 +72,8 @@ void psr_ctxt_switch_to(struct domain *d); int psr_get_info(unsigned int socket, enum cbm_type type, uint32_t data[], unsigned int array_len); -int psr_get_l3_cbm(struct domain *d, unsigned int socket, - uint64_t *cbm, enum cbm_type type); +int psr_get_val(struct domain *d, unsigned int socket, + uint32_t *val, enum cbm_type type); int psr_set_l3_cbm(struct domain *d, unsigned int socket, uint64_t cbm, enum cbm_type type);