From patchwork Tue Oct 10 09:19:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9995511 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 822E860230 for ; Tue, 10 Oct 2017 09:43:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 67CB92841D for ; Tue, 10 Oct 2017 09:43:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5C74928455; Tue, 10 Oct 2017 09:43:12 +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 F333C28426 for ; Tue, 10 Oct 2017 09:43:10 +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 1e1r1M-0004S8-VZ; Tue, 10 Oct 2017 09:40:16 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e1r1M-0004S2-8I for xen-devel@lists.xenproject.org; Tue, 10 Oct 2017 09:40:16 +0000 Received: from [193.109.254.147] by server-3.bemta-6.messagelabs.com id 03/27-14867-F759CD95; Tue, 10 Oct 2017 09:40:15 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrAIsWRWlGSWpSXmKPExsXS1tYhols09U6 kwaSr+hbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8bFTXdYCn6pVSxqMW9g/CHdxcjFISQwjVHi e3MTYxcjJ4eEAK/EkWUzWCFsf4n7v16xQhQ1MEr8+XYfLMEmoC7x+GsPE4gtIqAkcW/VZCaQI maB74wSlx7cBCsSFnCX2HXsIzOIzSKgKnGx8zp7FyMHBy9Q/MM3O4gFchInj00GK+cU8JCYNG M62BFCQCVTP9xkAbF5BQQlTs58wgLSygy0d/08IZAws4C8RPPW2cwTGAVmIamahVA1C0nVAkb mVYwaxalFZalFusaGeklFmekZJbmJmTm6hgZmermpxcWJ6ak5iUnFesn5uZsYgaHJAAQ7GJsW BR5ilORgUhLl/dp/J1KILyk/pTIjsTgjvqg0J7X4EKMMB4eSBK/NFKCcYFFqempFWmYOMEpg0 hIcPEoivF8nA6V5iwsSc4sz0yFSpxh1OTpu3v3DJMSSl5+XKiXOOx1khgBIUUZpHtwIWMReYp SVEuZlBDpKiKcgtSg3swRV/hWjOAejkjBvG8gUnsy8ErhNr4COYAI6QjQN7IiSRISUVANj+7T r38xb+yY0J69aXju7NmJv0fzpfzgbfgf/2GfR5HiM897dZEdl05l3OrLf1CjaNvwUYvw0/XaY Ulaj3vOrEqs+6sh+SfKvcJMzdeToXJF3q3DFCWW7NwVyrU+P/F6yIvwPm9r9l76TIvnnSitP2 5nKPP1n1AfhDbGVScv8vPLDreVfT9NXYinOSDTUYi4qTgQAsHk4KNMCAAA= X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-12.tower-27.messagelabs.com!1507628400!109473608!1 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.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 35046 invoked from network); 10 Oct 2017 09:40:02 -0000 Received: from mga02.intel.com (HELO mga02.intel.com) (134.134.136.20) by server-12.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 10 Oct 2017 09:40:02 -0000 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Oct 2017 02:39:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,504,1500966000"; d="scan'208";a="158793090" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.75]) by orsmga005.jf.intel.com with ESMTP; 10 Oct 2017 02:39:35 -0700 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Tue, 10 Oct 2017 17:19:10 +0800 Message-Id: <1507627150-4278-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 v3] 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 It changes the memebers in 'cos_write_info' to transfer the feature array, feature properties array and value array. 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 Reviewed-by: Roger Pau Monné --- CC: Jan Beulich CC: Andrew Cooper CC: Wei Liu CC: Roger Pau Monné CC: Julien Grall v2: - add 'result' in 'cos_write_info' to return error code. (suggested by Roger Pau Monné) v1: - 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 | 63 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c index daa2aeb..4f47a0b 100644 --- a/xen/arch/x86/psr.c +++ b/xen/arch/x86/psr.c @@ -1111,25 +1111,47 @@ static unsigned int get_socket_cpu(unsigned int socket) struct cos_write_info { unsigned int cos; - struct feat_node *feature; + struct feat_node **features; const uint32_t *val; - const struct feat_props *props; + unsigned int array_len; + int result; }; 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; - 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 = 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; + if ( info->array_len < index + cos_num ) + { + info->result = -ENOSPC; + return; + } + + 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 +1159,19 @@ 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], + .features = info->features, + .val = val, + .array_len = array_len, + .result = 0, }; 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 @@ -1172,7 +1183,7 @@ static int write_psr_msrs(unsigned int socket, unsigned int cos, on_selected_cpus(cpumask_of(cpu), do_write_psr_msrs, &data, 1); } - return 0; + return data.result; } int psr_set_val(struct domain *d, unsigned int socket,