From patchwork Tue Jan 10 07:42:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9506639 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 33F25606E1 for ; Tue, 10 Jan 2017 07:45:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2468028485 for ; Tue, 10 Jan 2017 07:45:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1298A284B0; Tue, 10 Jan 2017 07:45:49 +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 7E3C628485 for ; Tue, 10 Jan 2017 07:45:48 +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 1cQr5y-000458-6g; Tue, 10 Jan 2017 07:43:50 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cQr5w-00042u-Ma for xen-devel@lists.xenproject.org; Tue, 10 Jan 2017 07:43:48 +0000 Received: from [85.158.143.35] by server-9.bemta-6.messagelabs.com id 83/C4-27165-4B094785; Tue, 10 Jan 2017 07:43:48 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrPLMWRWlGSWpSXmKPExsVywNykWHfzhJI Ig4e7pC2+b5nM5MDocfjDFZYAxijWzLyk/IoE1oy2C18YC2ZaVWzYt4y1gfGTZhcjJ4eQQKXE 8a9rmUBsCQFeiSPLZrBC2P4SC1resXQxcgHVNDBKPLn/G6yITUBd4vHXHjBbREBJ4t6qyUwgR cwC+xkl5h8/zgySEBawlnj68zcjiM0ioCoxb8keFhCbV8BD4svKnYwQG+QkTh6bDLaNEyjecn UdI8RF7hLNb+8zTmDkXcDIsIpRozi1qCy1SNfYWC+pKDM9oyQ3MTNH19DATC83tbg4MT01JzG pWC85P3cTIzAgGIBgB+PO9YGHGCU5mJREeVN0SyKE+JLyUyozEosz4otKc1KLDzHKcHAoSfB+ 7QfKCRalpqdWpGXmAEMTJi3BwaMkwssCkuYtLkjMLc5Mh0idYlSUEufdC5IQAElklObBtcHi4 RKjrJQwLyPQIUI8BalFuZklqPKvGMU5GJWEedlBpvBk5pXATX8FtJgJaHGkXTHI4pJEhJRUA6 OxGXvorvCDazyb8jaHmZiWi2lflIq7cOZpe16s7IcenvvCXlPnWDZMeW8YO28Wq8xRmzv8sc9 OyrhzpC/ZmVt3v2ChrfLxdZct1t9TKk4Xy/euWn5zw7H8DzYxM+Yc15jUKOUrzrf27cY2a+nm q6539Swt7sd+sfD/sH3FHt45M+1NzRM1/iqxFGckGmoxFxUnAgBFj8idggIAAA== X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-11.tower-21.messagelabs.com!1484034222!51795053!3 X-Originating-IP: [192.55.52.115] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 15361 invoked from network); 10 Jan 2017 07:43:47 -0000 Received: from mga14.intel.com (HELO mga14.intel.com) (192.55.52.115) by server-11.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 10 Jan 2017 07:43:47 -0000 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP; 09 Jan 2017 23:43:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,343,1477983600"; d="scan'208";a="211583137" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.63]) by fmsmga004.fm.intel.com with ESMTP; 09 Jan 2017 23:43:37 -0800 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Tue, 10 Jan 2017 15:42:28 +0800 Message-Id: <1484034155-4521-10-git-send-email-yi.y.sun@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1484034155-4521-1-git-send-email-yi.y.sun@linux.intel.com> References: <1484034155-4521-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] [RFC 09/16] x86: implement set value flow for MBA. 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 set value flow for MBA including its callback function and domctl interface. Signed-off-by: Yi Sun --- xen/arch/x86/domctl.c | 6 ++ xen/arch/x86/psr.c | 152 +++++++++++++++++++++++++++++++++++++--- xen/include/asm-x86/msr-index.h | 1 + xen/include/public/domctl.h | 1 + 4 files changed, 149 insertions(+), 11 deletions(-) diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c index 6145cf4..a7cf690 100644 --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -1393,6 +1393,12 @@ long arch_do_domctl( PSR_VAL_TYPE_L2); break; + case XEN_DOMCTL_PSR_MBA_OP_SET_THRTL: + ret = psr_set_val(d, domctl->u.psr_alloc_op.target, + domctl->u.psr_alloc_op.data, + PSR_VAL_TYPE_MBA); + break; + case XEN_DOMCTL_PSR_CAT_OP_GET_L3_CBM: ret = psr_get_val(d, domctl->u.psr_alloc_op.target, &domctl->u.psr_alloc_op.data, diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c index fd95a6d..965ed17 100644 --- a/xen/arch/x86/psr.c +++ b/xen/arch/x86/psr.c @@ -332,6 +332,14 @@ static bool_t psr_check_cbm(unsigned int cbm_len, uint64_t cbm) return 1; } +static bool_t psr_check_thrtl(unsigned int thrtl_max, uint64_t thrtl) +{ + if ( thrtl > thrtl_max ) + return 0; + + return 1; +} + /* L3 CAT callback functions implementation. */ static void l3_cat_init_feature(unsigned int eax, unsigned int ebx, unsigned int ecx, unsigned int edx, @@ -1012,11 +1020,121 @@ static bool mba_get_val(const struct feat_node *feat, unsigned int cos, return true; } +static unsigned int mba_get_cos_num(const struct feat_node *feat) +{ + /* MBA uses one COS. */ + return 1; +} + +static int mba_get_old_val(uint64_t val[], + const struct feat_node *feat, + unsigned int old_cos) +{ + if ( old_cos > feat->info.mba_info.cos_max ) + /* Use default value. */ + old_cos = 0; + + val[0] = feat->cos_reg_val[old_cos]; + + /* MBA uses one COS. */ + return 1; +} + +static int mba_set_new_val(uint64_t val[], + const struct feat_node *feat, + unsigned int old_cos, + enum psr_val_type type, + uint64_t m) +{ + if ( type != PSR_VAL_TYPE_MBA ) + return 1; + + if ( !psr_check_thrtl(feat->info.mba_info.thrtl_max, m) ) + return -EINVAL; + + val[0] = m; + + /* MBA uses one COS. */ + return 1; +} + +static unsigned int mba_get_cos_max_from_type(const struct feat_node *feat, + enum psr_val_type type) +{ + if ( type != PSR_VAL_TYPE_MBA ) + return 0; + + return feat->info.mba_info.cos_max; +} + +static int mba_compare_val(const uint64_t val[], + const struct feat_node *feat, + unsigned int cos, bool *found) +{ + uint64_t mba_def = 0; + + if ( cos > feat->info.mba_info.cos_max ) + { + if ( val[0] != mba_def ) + { + *found = false; + return -ENOENT; + } + *found = true; + } + else + *found = (val[0] == feat->cos_reg_val[cos]); + + /* MBA uses one COS. */ + return 1; +} + +static unsigned int mba_exceeds_cos_max(const uint64_t val[], + const struct feat_node *feat, + unsigned int cos) +{ + uint64_t mba_def = 0; + + if ( cos > feat->info.mba_info.cos_max && + val[0] != mba_def ) + /* + * Exceed cos_max and value to set is not default, + * return error. + */ + return 0; + + /* MBA uses one COS. */ + return 1; +} + +static int mba_write_msr(unsigned int cos, const uint64_t val[], + struct feat_node *feat) +{ + if ( cos > feat->info.mba_info.cos_max ) + return 1; + + if ( feat->cos_reg_val[cos] != val[0] ) + { + wrmsrl(MSR_IA32_PSR_MBA_MASK(cos), val[0]); + feat->cos_reg_val[cos] = val[0]; + } + + /* MBA uses one COS. */ + return 1; +} + struct feat_ops mba_ops = { .init_feature = mba_init_feature, .get_max_cos_max = mba_get_max_cos_max, .get_feat_info = mba_get_feat_info, .get_val = mba_get_val, + .get_cos_num = mba_get_cos_num, + .get_old_val = mba_get_old_val, + .set_new_val = mba_set_new_val, + .get_cos_max_from_type = mba_get_cos_max_from_type, + .compare_val = mba_compare_val, + .exceeds_cos_max = mba_exceeds_cos_max, + .write_msr = mba_write_msr, }; static void __init parse_psr_bool(char *s, char *value, char *feature, @@ -1519,20 +1637,10 @@ static int write_psr_msr(unsigned int socket, unsigned int cos, return 0; } -int psr_set_val(struct domain *d, unsigned int socket, - uint64_t val, enum psr_val_type type) +static uint32_t psr_val_type_to_feat_flag(enum psr_val_type type) { - unsigned int old_cos; - int cos, ret; - unsigned int *ref; - 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_VAL_TYPE_L3: @@ -1545,10 +1653,32 @@ int psr_set_val(struct domain *d, unsigned int socket, case PSR_VAL_TYPE_L2: flag = PSR_SOCKET_L2_CAT; break; + case PSR_VAL_TYPE_MBA: + flag = PSR_SOCKET_MBA; + break; default: flag = 0xFFFF; break; } + + return flag; +} + +int psr_set_val(struct domain *d, unsigned int socket, + uint64_t val, enum psr_val_type type) +{ + unsigned int old_cos; + int cos, ret; + unsigned int *ref; + 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); + + flag = psr_val_type_to_feat_flag(type); if ( !test_bit(flag, &info->feat_mask) ) return -ENODEV; diff --git a/xen/include/asm-x86/msr-index.h b/xen/include/asm-x86/msr-index.h index a41e63a..2e97c6c 100644 --- a/xen/include/asm-x86/msr-index.h +++ b/xen/include/asm-x86/msr-index.h @@ -344,6 +344,7 @@ #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)) +#define MSR_IA32_PSR_MBA_MASK(n) (0x00000d50 + (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 2de7214..11609bc 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -1140,6 +1140,7 @@ struct xen_domctl_psr_alloc_op { #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 +#define XEN_DOMCTL_PSR_MBA_OP_SET_THRTL 8 #define XEN_DOMCTL_PSR_MBA_OP_GET_THRTL 9 uint32_t cmd; /* IN: XEN_DOMCTL_PSR_*_OP_* */ uint32_t target; /* IN */