From patchwork Wed Dec 14 04:08:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9474037 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 78ACA60823 for ; Wed, 14 Dec 2016 11:12:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6FDAF2871B for ; Wed, 14 Dec 2016 11:12:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 633F72871F; Wed, 14 Dec 2016 11:12:30 +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=-2.7 required=2.0 tests=BAYES_00, DATE_IN_PAST_06_12, 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 D6C0A2871B for ; Wed, 14 Dec 2016 11:12:29 +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 1cH7SI-00069l-EC; Wed, 14 Dec 2016 11:10:38 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cH7SH-00068t-PO for xen-devel@lists.xenproject.org; Wed, 14 Dec 2016 11:10:37 +0000 Received: from [85.158.143.35] by server-6.bemta-6.messagelabs.com id 80/AE-15112-DA821585; Wed, 14 Dec 2016 11:10:37 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrDLMWRWlGSWpSXmKPExsXS1tYhobtGIzD CYNp9WYvvWyYzOTB6HP5whSWAMYo1My8pvyKBNWP6/VPsBUtMKqYdWsrewLhZtYuRk0NIoELi 9vGtzCC2hACvxJFlM1ghbD+J9wv/sEHUNDBK7NuUAmKzCahLPP7awwRiiwgoSdxbNRnI5uJgF uhmklj5cCsLSEJYwEHi6/1DQAkODhYBVYmHO7lAwrwCHhLf989lgpgvJ3Hy2GRWkBJOoPi/LY kQq9wlLva+Y5/AyLuAkWEVo0ZxalFZapGukbFeUlFmekZJbmJmjq6hgZlebmpxcWJ6ak5iUrF ecn7uJkZgKDAAwQ7GP/MDDzFKcjApifJyXQ2IEOJLyk+pzEgszogvKs1JLT7EKMPBoSTBO0s9 MEJIsCg1PbUiLTMHGJQwaQkOHiUR3iAVoDRvcUFibnFmOkTqFKOilDjvSpA+AZBERmkeXBssE i4xykoJ8zICHSLEU5BalJtZgir/ilGcg1FJmHcDyBSezLwSuOmvgBYzAS0WXeIPsrgkESEl1c DIayVasf+63wXLBb+vBRk8NHqieuSwRE/W1pYnuat7fv4uWRe/ZG/ZOnWuKk73k0VSu7T1L5f wdjLPKr/+j2NWh8ivfel1jb0bCg/yLvY3rOAqmWf47AnHTBU7G2OV7LLjfbdcX3CVns32ck8s Ca6OWqyzwVozPSfw7i7ejXs6jJoaJ4XVeSqxFGckGmoxFxUnAgAX2La3fwIAAA== X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-12.tower-21.messagelabs.com!1481713769!48240089!21 X-Originating-IP: [134.134.136.24] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTM0LjEzNC4xMzYuMjQgPT4gMzkwOTcx\n X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 26624 invoked from network); 14 Dec 2016 11:10:36 -0000 Received: from mga09.intel.com (HELO mga09.intel.com) (134.134.136.24) by server-12.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 14 Dec 2016 11:10:36 -0000 Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga102.jf.intel.com with ESMTP; 14 Dec 2016 03:10:35 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,346,1477983600"; d="scan'208";a="39863403" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.63]) by orsmga004.jf.intel.com with ESMTP; 14 Dec 2016 03:10:33 -0800 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Wed, 14 Dec 2016 12:08:00 +0800 Message-Id: <1481688484-5093-21-git-send-email-yi.y.sun@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1481688484-5093-1-git-send-email-yi.y.sun@linux.intel.com> References: <1481688484-5093-1-git-send-email-yi.y.sun@linux.intel.com> Cc: 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 Subject: [Xen-devel] [PATCH v4 20/24] x86: L2 CAT: implement set 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 This patch implements L2 CAT set value related callback functions and domctl interface. Signed-off-by: Yi Sun --- xen/arch/x86/domctl.c | 6 ++ xen/arch/x86/psr.c | 132 +++++++++++++++++++++++++++++++++++++++- xen/include/asm-x86/msr-index.h | 1 + xen/include/public/domctl.h | 1 + 4 files changed, 139 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c index e5aa932..69aa4d3 100644 --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -1403,6 +1403,12 @@ long arch_do_domctl( PSR_CBM_TYPE_L3_DATA); break; + case XEN_DOMCTL_PSR_CAT_OP_SET_L2_CBM: + ret = psr_set_val(d, domctl->u.psr_cat_op.target, + domctl->u.psr_cat_op.data, + PSR_CBM_TYPE_L2); + break; + case XEN_DOMCTL_PSR_CAT_OP_GET_L3_CBM: ret = psr_get_val(d, domctl->u.psr_cat_op.target, &domctl->u.psr_cat_op.data, diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c index 0886a01..ed1ec2f 100644 --- a/xen/arch/x86/psr.c +++ b/xen/arch/x86/psr.c @@ -796,17 +796,127 @@ static bool l2_cat_get_val(const struct feat_node *feat, unsigned int cos, if ( cos > feat->info.l2_cat_info.cos_max ) cos = 0; - /* L2 CAT */ *val = feat->cos_reg_val[cos]; return true; } +static unsigned int l2_cat_get_cos_num(const struct feat_node *feat) +{ + /* L2 CAT uses one COS. */ + return 1; +} + +static int l2_cat_get_old_val(uint64_t val[], + const struct feat_node *feat, + unsigned int old_cos) +{ + if ( old_cos > feat->info.l2_cat_info.cos_max ) + /* Use default value. */ + old_cos = 0; + + val[0] = feat->cos_reg_val[old_cos]; + + /* L2 CAT uses one COS. */ + return 1; +} + +static int l2_cat_set_new_val(uint64_t val[], + const struct feat_node *feat, + unsigned int old_cos, + enum cbm_type type, + uint64_t m) +{ + if ( type != PSR_CBM_TYPE_L2 ) + return 1; + + if ( !psr_check_cbm(feat->info.l2_cat_info.cbm_len, m) ) + return -EINVAL; + + val[0] = m; + + /* L2 CAT uses one COS. */ + return 1; +} + +static unsigned int l2_cat_get_cos_max_from_type(const struct feat_node *feat, + enum cbm_type type) +{ + if ( type != PSR_CBM_TYPE_L2 ) + return 0; + + return feat->info.l2_cat_info.cos_max; +} + +static int l2_cat_compare_val(const uint64_t val[], + const struct feat_node *feat, + unsigned int cos, bool *found) +{ + uint64_t l2_def_cbm; + + l2_def_cbm = (1ull << feat->info.l2_cat_info.cbm_len) - 1; + + if ( cos > feat->info.l2_cat_info.cos_max ) + { + if ( val[0] != l2_def_cbm ) + { + *found = false; + return -ENOENT; + } + *found = true; + } + else + *found = (val[0] == feat->cos_reg_val[cos]); + + /* L2 CAT uses one COS. */ + return 1; +} + +static unsigned int l2_cat_exceeds_cos_max(const uint64_t val[], + const struct feat_node *feat, + unsigned int cos) +{ + uint64_t l2_def_cbm; + + l2_def_cbm = (1ull << feat->info.l2_cat_info.cbm_len) - 1; + + if ( cos > feat->info.l2_cat_info.cos_max && + val[0] != l2_def_cbm ) + /* + * Exceed cos_max and value to set is not default, + * return error. + */ + return 0; + + /* L2 CAT uses one COS. */ + return 1; +} + +static int l2_cat_write_msr(unsigned int cos, const uint64_t val[], + struct feat_node *feat) +{ + if ( cos > feat->info.l2_cat_info.cos_max ) + return 1; + + feat->cos_reg_val[cos] = val[0]; + wrmsrl(MSR_IA32_PSR_L2_MASK(cos), val[0]); + + /* L2 CAT uses one COS. */ + return 1; +} + struct feat_ops l2_cat_ops = { .init_feature = l2_cat_init_feature, .get_max_cos_max = l2_cat_get_max_cos_max, .get_feat_info = l2_cat_get_feat_info, .get_val = l2_cat_get_val, + .get_cos_num = l2_cat_get_cos_num, + .get_old_val = l2_cat_get_old_val, + .set_new_val = l2_cat_set_new_val, + .get_cos_max_from_type = l2_cat_get_cos_max_from_type, + .compare_val = l2_cat_compare_val, + .exceeds_cos_max = l2_cat_exceeds_cos_max, + .write_msr = l2_cat_write_msr, }; static void __init parse_psr_bool(char *s, char *value, char *feature, @@ -1317,10 +1427,30 @@ int psr_set_val(struct domain *d, unsigned int socket, uint64_t *val_array; struct psr_socket_info *info = get_socket_info(socket); uint32_t array_len; + uint32_t flag; if ( IS_ERR(info) ) return PTR_ERR(info); + /* Judge if feature is enabled. */ + switch ( type ) { + case PSR_CBM_TYPE_L3: + flag = PSR_SOCKET_L3_CAT; + break; + case PSR_CBM_TYPE_L3_DATA: + case PSR_CBM_TYPE_L3_CODE: + flag = PSR_SOCKET_L3_CDP; + break; + case PSR_CBM_TYPE_L2: + flag = PSR_SOCKET_L2_CAT; + break; + default: + flag = 0xFFFF; + break; + } + if ( !test_bit(flag, &info->feat_mask) ) + return -ENODEV; + /* * Step 0: * old_cos means the COS ID current domain is using. By default, it is 0. diff --git a/xen/include/asm-x86/msr-index.h b/xen/include/asm-x86/msr-index.h index 98dbff1..a41e63a 100644 --- a/xen/include/asm-x86/msr-index.h +++ b/xen/include/asm-x86/msr-index.h @@ -343,6 +343,7 @@ #define MSR_IA32_PSR_L3_MASK(n) (0x00000c90 + (n)) #define MSR_IA32_PSR_L3_MASK_CODE(n) (0x00000c90 + (n) * 2 + 1) #define MSR_IA32_PSR_L3_MASK_DATA(n) (0x00000c90 + (n) * 2) +#define MSR_IA32_PSR_L2_MASK(n) (0x00000d10 + (n)) /* Intel Model 6 */ #define MSR_P6_PERFCTR(n) (0x000000c1 + (n)) diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index d04e318..17c4ab4 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -1137,6 +1137,7 @@ struct xen_domctl_psr_cat_op { #define XEN_DOMCTL_PSR_CAT_OP_SET_L3_DATA 3 #define XEN_DOMCTL_PSR_CAT_OP_GET_L3_CODE 4 #define XEN_DOMCTL_PSR_CAT_OP_GET_L3_DATA 5 +#define XEN_DOMCTL_PSR_CAT_OP_SET_L2_CBM 6 #define XEN_DOMCTL_PSR_CAT_OP_GET_L2_CBM 7 uint32_t cmd; /* IN: XEN_DOMCTL_PSR_CAT_OP_* */ uint32_t target; /* IN */