From patchwork Tue Aug 1 08:48:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9873899 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 BC68E60365 for ; Tue, 1 Aug 2017 09:07:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C3E8E28670 for ; Tue, 1 Aug 2017 09:07:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B4EAE2582C; Tue, 1 Aug 2017 09:07:13 +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 E3C692582C for ; Tue, 1 Aug 2017 09:07:12 +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 1dcT6N-00052g-8y; Tue, 01 Aug 2017 09:04:31 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dcT6L-00051W-VJ for xen-devel@lists.xenproject.org; Tue, 01 Aug 2017 09:04:30 +0000 Received: from [85.158.139.211] by server-5.bemta-5.messagelabs.com id 2E/B2-02177-D1440895; Tue, 01 Aug 2017 09:04:29 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrBLMWRWlGSWpSXmKPExsXS1tYhoivj0hB p8Gq7nMX3LZOZHBg9Dn+4whLAGMWamZeUX5HAmjHzVE7BIoeKs1POszYwPtbrYuTiEBKYxijR faiNqYuRk0NCgFfiyLIZrBC2v8S5pT2MEEUNjBJ3pj9hBkmwCahLPP7aA9YgIqAkcW/VZCaQI maB+UwSr88/ACri4BAG6t64UBukhkVAVaLjz2t2EJtXwF1i9u9XLBAL5CROHpsMtoxTwENix8 0bYK1CQDU7ZyZOYORdwMiwilG9OLWoLLVI11QvqSgzPaMkNzEzR9fQwFQvN7W4ODE9NScxqVg vOT93EyMwFBiAYAfjl37nQ4ySHExKoryKPfWRQnxJ+SmVGYnFGfFFpTmpxYcYZTg4lCR4JZwb IoUEi1LTUyvSMnOAQQmTluDgURLhveAElOYtLkjMLc5Mh0idYtTleDXh/zcmIZa8/LxUKXHei yBFAiBFGaV5cCNgEXKJUVZKmJcR6CghnoLUotzMElT5V4ziHIxKwrz3QabwZOaVwG16BXQEE9 ARkqW1IEeUJCKkpBoYZ9xwvHN09bvZLF4RvdZsuTZTMg7Zzps4xb7KrfjY0tB2hns8EzrTZiR M7Yq4IRrBJ9h+Q+t3lMvKY4JcdRm303rTfzXk8ZYYWD+Z7KI0/93LyD9q0WX+VSqrTkvOM37N 8Pzydbdgs4+73rp8mBGYUq/GG1+3gOvcwyXxc4LDGY+UaExIzpRQYinOSDTUYi4qTgQAnUyVx 4sCAAA= X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-16.tower-206.messagelabs.com!1501578248!89431283!8 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.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 48781 invoked from network); 1 Aug 2017 09:04:28 -0000 Received: from mga02.intel.com (HELO mga02.intel.com) (134.134.136.20) by server-16.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 1 Aug 2017 09:04:28 -0000 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Aug 2017 02:04:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,305,1498546800"; d="scan'208";a="118061565" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.80]) by orsmga002.jf.intel.com with ESMTP; 01 Aug 2017 02:04:25 -0700 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Tue, 1 Aug 2017 16:48:38 +0800 Message-Id: <1501577334-7431-8-git-send-email-yi.y.sun@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1501577334-7431-1-git-send-email-yi.y.sun@linux.intel.com> References: <1501577334-7431-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, 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 v15 07/23] 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. 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 CDP related patches. Signed-off-by: Yi Sun Reviewed-by: Jan Beulich --- v14: - rebase domctl.c on latest code: bool_t is replaced by bool. v12: - remove 'psr_get_feat_and_type' and implement its functionality in 'psr_get_val'. - use 'ASSERT_UNREACHABLE' to record error. (suggested by Jan Beulich) - return success only if the 'val' is set in 'psr_get_val'. (suggested by Jan Beulich) v11: - declare a 'switch()' wide variable 'val32' in domctl. (suggested by Jan Beulich) - remove 'get_val' callback function which is replaced by generic codes. (suggested by Jan Beulich) - fix coding style issue. (suggested by Jan Beulich) - do not 'ASSERT' domain pointer. (suggested by Jan Beulich) - modify commit message. v10: - use an intermediate variable to get value and avoid cast in domctl. (suggested by Jan Beulich) - remove 'type' in 'get_val' parameters and will add it back when implementing CDP. (suggested by Jan Beulich) - remove unnecessary variable and return error about 'info' in 'psr_get_feat'. (suggested by Jan Beulich) - use 'ASSERT' to check input parameter in 'psr_get_val'. (suggested by Jan Beulich) - changes about 'feat_props'. (suggested by Jan Beulich) 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 | 20 ++++++++++--------- xen/arch/x86/psr.c | 51 ++++++++++++++++++++++++++++++++++++++++++++--- xen/include/asm-x86/psr.h | 4 ++-- 3 files changed, 61 insertions(+), 14 deletions(-) diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c index c1d016b..e9a72c8 100644 --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -1442,6 +1442,8 @@ long arch_do_domctl( case XEN_DOMCTL_psr_cat_op: switch ( domctl->u.psr_cat_op.cmd ) { + uint32_t val32; + case XEN_DOMCTL_PSR_CAT_OP_SET_L3_CBM: ret = psr_set_l3_cbm(d, domctl->u.psr_cat_op.target, domctl->u.psr_cat_op.data, @@ -1461,23 +1463,23 @@ 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); + ret = psr_get_val(d, domctl->u.psr_cat_op.target, + &val32, PSR_CBM_TYPE_L3); + domctl->u.psr_cat_op.data = val32; copyback = true; 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); + ret = psr_get_val(d, domctl->u.psr_cat_op.target, + &val32, PSR_CBM_TYPE_L3_CODE); + domctl->u.psr_cat_op.data = val32; copyback = true; 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); + ret = psr_get_val(d, domctl->u.psr_cat_op.target, + &val32, PSR_CBM_TYPE_L3_DATA); + domctl->u.psr_cat_op.data = val32; copyback = true; break; diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c index 20d083e..0fe63dd 100644 --- a/xen/arch/x86/psr.c +++ b/xen/arch/x86/psr.c @@ -524,10 +524,55 @@ 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) { - return 0; + const struct psr_socket_info *info = get_socket_info(socket); + const struct feat_node *feat; + enum psr_feat_type feat_type; + unsigned int cos, i; + + ASSERT(val); + + if ( IS_ERR(info) ) + return PTR_ERR(info); + + feat_type = psr_cbm_type_to_feat_type(type); + if ( feat_type >= ARRAY_SIZE(info->features) ) + return -ENOENT; + + feat = info->features[feat_type]; + if ( !feat ) + return -ENOENT; + + if ( !feat_props[feat_type] ) + { + ASSERT_UNREACHABLE(); + 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->cos_max ) + cos = 0; + + for ( i = 0; i < feat_props[feat_type]->cos_num; i++ ) + { + if ( type == feat_props[feat_type]->type[i] ) + { + *val = feat->cos_reg_val[cos * feat_props[feat_type]->cos_num + i]; + return 0; + } + } + + return -EINVAL; } int psr_set_l3_cbm(struct domain *d, unsigned int socket, diff --git a/xen/include/asm-x86/psr.h b/xen/include/asm-x86/psr.h index 8d15328..0e960bf 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);