From patchwork Wed Oct 11 01:55:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9998457 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 D03C860230 for ; Wed, 11 Oct 2017 02:18:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BCC2A288B0 for ; Wed, 11 Oct 2017 02:18:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B1787288BB; Wed, 11 Oct 2017 02:18:35 +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 EAD86288B0 for ; Wed, 11 Oct 2017 02:18:34 +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 1e26Ym-0007he-6w; Wed, 11 Oct 2017 02:15:48 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e26Yl-0007hY-9f for xen-devel@lists.xenproject.org; Wed, 11 Oct 2017 02:15:47 +0000 Received: from [193.109.254.147] by server-1.bemta-6.messagelabs.com id 42/D9-31121-2DE7DD95; Wed, 11 Oct 2017 02:15:46 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrPIsWRWlGSWpSXmKPExsVywNxEW/di3d1 Ig447+hbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8alB9dZCyZpVty4v461gfGwbBcjB4eQQKXE ogN2XYycHBICvBJHls1gBQlLCARIvPpp1sXIBVTRwCgxc9MaJpAaNgF1icdfe8BsEQEliXurJ jOBFDELfGeUuPTgJitIQljAXWLa/SMsIDaLgKrE7dOtYA28QPHdr7qYIZbJSZw8NhmsnlPAQ2 LSjOmMILYQUM3UDzdZIOoFJU7OfMICchAz0OL184RAwswC8hLNW2czT2AUmIWkahZC1SwkVQs YmVcxahSnFpWlFukaGeglFWWmZ5TkJmbm6BoamOnlphYXJ6an5iQmFesl5+duYgQGJgMQ7GD8 tSzgEKMkB5OSKO9r9buRQnxJ+SmVGYnFGfFFpTmpxYcYZTg4lCR4U2uBcoJFqempFWmZOcAYg UlLcPAoifDeqQZK8xYXJOYWZ6ZDpE4x6nJ03Lz7h0mIJS8/L1VKnDcLZIYASFFGaR7cCFi8Xm KUlRLmZQQ6SoinILUoN7MEVf4VozgHo5Iw7ymQKTyZeSVwm14BHcEEdIRo2h2QI0oSEVJSDYx s+Uun+9rLOS/bKnX4+0PhStOAyAOKm9d+zA73qFPvZbh2L37eV4W/BzXLfvwral9wvzv38nGv Y+eZH005wBPPMjNzfbdWYbZD5wSP1WwHxLYt/pZ1P+nSr4Uh8U8+rmCx2yA9V+3rjqeGmRMST W5VbV/Y9arBbG73vLYoW4ENmRd2pW30Tt+mxFKckWioxVxUnAgATDcg2tICAAA= X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-16.tower-27.messagelabs.com!1507688143!110743547!1 X-Originating-IP: [192.55.52.43] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 9115 invoked from network); 11 Oct 2017 02:15:45 -0000 Received: from mga05.intel.com (HELO mga05.intel.com) (192.55.52.43) by server-16.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 11 Oct 2017 02:15:45 -0000 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga105.fm.intel.com with ESMTP; 10 Oct 2017 19:15:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.43,359,1503385200"; d="scan'208"; a="1204485618" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.75]) by fmsmga001.fm.intel.com with ESMTP; 10 Oct 2017 19:15:40 -0700 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Wed, 11 Oct 2017 09:55:13 +0800 Message-Id: <1507686913-5106-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 v4] 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 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 | 62 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c index daa2aeb..a812124 100644 --- a/xen/arch/x86/psr.c +++ b/xen/arch/x86/psr.c @@ -1111,25 +1111,48 @@ 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; + 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; + 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; + 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 +1160,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 @@ -1172,7 +1182,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,