From patchwork Wed Oct 11 07:20:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9998875 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 0335560230 for ; Wed, 11 Oct 2017 07:43:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E95A4205FB for ; Wed, 11 Oct 2017 07:43:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DE1F028901; Wed, 11 Oct 2017 07:43: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 4CF60205FB for ; Wed, 11 Oct 2017 07:43: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 1e2Bdj-0007gx-7e; Wed, 11 Oct 2017 07:41:15 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e2Bdi-0007gr-0r for xen-devel@lists.xenproject.org; Wed, 11 Oct 2017 07:41:14 +0000 Received: from [193.109.254.147] by server-11.bemta-6.messagelabs.com id D8/BD-20813-91BCDD95; Wed, 11 Oct 2017 07:41:13 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrAIsWRWlGSWpSXmKPExsXS1tYhoSt++m6 kwYYDShbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8biA92MBe3qFRenf2BtYOyT6WLk4hASmMYo sf1GA2sXIyeHhACvxJFlM4BsDiDbX2Ltcj2ImgZGiYM9k1lAatgE1CUef+1hArFFBJQk7q2az ARSxCzwnVHi0oObYIOEBdwlZqw+wg5iswioSsycPIkRxOYV8JB4dP4ZE8QyOYmTxyaD1XMCxS fNmA5WIwTUO/XDTRaIekGJkzOfsIAcxAy0eP08IZAws4C8RPPW2cwTGAVmIamahVA1C0nVAkb mVYzqxalFZalFuqZ6SUWZ6RkluYmZObqGBmZ6uanFxYnpqTmJScV6yfm5mxiBockABDsYp1/2 P8QoycGkJMqrMOdupBBfUn5KZUZicUZ8UWlOavEhRhkODiUJXrtTQDnBotT01Iq0zBxglMCkJ Th4lER4I08CpXmLCxJzizPTIVKnGHU5Om7e/cMkxJKXn5cqJc77GaRIAKQoozQPbgQsYi8xyk oJ8zICHSXEU5BalJtZgir/ilGcg1FJmFcO5BKezLwSuE2vgI5gAjpCNO0OyBEliQgpqQZGkbM afaePa8u4Si8SuTi5q+/M7YKNH2dk7q+1/PFzf+FffgPFviq9zuLtP9U9Q//7WJ8sWVR/7gzz oYWNwovD1lwKE9eYcubcD+9Md1u395Zb18+VC2IU27f68JNQlw6vwrOamyNPqL7RvcVx53S0e Zna4+R1J2MfnLvKyRCfsdGJf2dr9l1XJZbijERDLeai4kQAKZAauNMCAAA= X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-10.tower-27.messagelabs.com!1507707669!87902641!1 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.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 27147 invoked from network); 11 Oct 2017 07:41:11 -0000 Received: from mga09.intel.com (HELO mga09.intel.com) (134.134.136.24) by server-10.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 11 Oct 2017 07:41:11 -0000 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Oct 2017 00:41:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,360,1503385200"; d="scan'208";a="159208673" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.75]) by orsmga005.jf.intel.com with ESMTP; 11 Oct 2017 00:41:06 -0700 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Wed, 11 Oct 2017 15:20:38 +0800 Message-Id: <1507706438-24486-1-git-send-email-yi.y.sun@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1507281180-5101-1-git-send-email-yi.y.sun@linux.intel.com> References: <1507281180-5101-1-git-send-email-yi.y.sun@linux.intel.com> MIME-Version: 1.0 Cc: Yi Sun , Andrew Cooper , Julien Grall , Jan Beulich , Wei Liu , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [Xen-devel] [PATCH v5] x86: psr: support co-exist features' values setting 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: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP The whole value array is transferred into 'do_write_psr_msrs'. Then, we can write all features values on the cos id into MSRs. Because multiple features may co-exist, we need handle all features to write values of them into a COS register with new COS ID. E.g: 1. L3 CAT and L2 CAT co-exist. 2. Dom1 and Dom2 share the same COS ID (2). The L3 CAT CBM of Dom1 is 0x1ff, the L2 CAT CBM of Dom1 is 0x1f. 3. User wants to change L2 CBM of Dom1 to be 0xf. Because COS ID 2 is used by Dom2 too, we have to pick a new COS ID 3. The values of Dom1 on COS ID 3 are all default values as below: --------- | COS 3 | --------- L3 CAT | 0x7ff | --------- L2 CAT | 0xff | --------- 4. After setting, the L3 CAT CBM value of Dom1 should be kept and the new L2 CAT CBM is set. So, the values on COS ID 3 should be below. --------- | COS 3 | --------- L3 CAT | 0x1ff | --------- L2 CAT | 0xf | --------- Signed-off-by: Yi Sun --- CC: Jan Beulich CC: Andrew Cooper CC: Wei Liu CC: Roger Pau Monné CC: Julien Grall v5: - remove 'result' and use an ASSERT to handle error case. (suggested by Chao Peng) v4: - remove init of 'result'. (suggested by Roger Pau Monné) - remove 'features' in 'cos_write_info' and get socket info in 'do_write_psr_msrs' to get features array. (suggested by Jan Beulich) - fix a typo in commit message. (suggested by Kent R. Spillner) v3: - add 'result' in 'cos_write_info' to return error code. (suggested by Roger Pau Monné) v2: - fix issues in commit message. (suggested by Roger Pau Monné) - remove unnecessary local variable 'val_array'. (suggested by Roger Pau Monné) --- xen/arch/x86/psr.c | 55 +++++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c index daa2aeb..8936cf7 100644 --- a/xen/arch/x86/psr.c +++ b/xen/arch/x86/psr.c @@ -1111,25 +1111,43 @@ static unsigned int get_socket_cpu(unsigned int socket) struct cos_write_info { unsigned int cos; - struct feat_node *feature; const uint32_t *val; - const struct feat_props *props; + unsigned int array_len; }; static void do_write_psr_msrs(void *data) { - const struct cos_write_info *info = data; - struct feat_node *feat = info->feature; - const struct feat_props *props = info->props; - unsigned int i, cos = info->cos, cos_num = props->cos_num; + struct cos_write_info *info = data; + unsigned int i, index = 0, cos = info->cos; + struct psr_socket_info *socket_info = + get_socket_info(cpu_to_socket(smp_processor_id())); - for ( i = 0; i < cos_num; i++ ) + /* + * Iterate all featuers to write different value (not same as MSR) for + * each feature. + */ + for ( i = 0; i < ARRAY_SIZE(feat_props); i++ ) { - if ( feat->cos_reg_val[cos * cos_num + i] != info->val[i] ) + struct feat_node *feat = socket_info->features[i]; + const struct feat_props *props = feat_props[i]; + unsigned int cos_num, j; + + if ( !feat || !props ) + continue; + + cos_num = props->cos_num; + ASSERT(info->array_len >= index + cos_num); + + for ( j = 0; j < cos_num; j++ ) { - feat->cos_reg_val[cos * cos_num + i] = info->val[i]; - props->write_msr(cos, info->val[i], props->type[i]); + if ( feat->cos_reg_val[cos * cos_num + j] != info->val[index + j] ) + { + feat->cos_reg_val[cos * cos_num + j] = info->val[index + j]; + props->write_msr(cos, info->val[index + j], props->type[j]); + } } + + index += cos_num; } } @@ -1137,30 +1155,17 @@ static int write_psr_msrs(unsigned int socket, unsigned int cos, const uint32_t val[], unsigned int array_len, enum psr_feat_type feat_type) { - int ret; struct psr_socket_info *info = get_socket_info(socket); struct cos_write_info data = { .cos = cos, - .feature = info->features[feat_type], - .props = feat_props[feat_type], + .val = val, + .array_len = array_len, }; if ( cos > info->features[feat_type]->cos_max ) return -EINVAL; - /* Skip to the feature's value head. */ - ret = skip_prior_features(&array_len, feat_type); - if ( ret < 0 ) - return ret; - - val += ret; - - if ( array_len < feat_props[feat_type]->cos_num ) - return -ENOSPC; - - data.val = val; - if ( socket == cpu_to_socket(smp_processor_id()) ) do_write_psr_msrs(&data); else