From patchwork Wed Feb 15 08:49:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9573587 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 3738060493 for ; Wed, 15 Feb 2017 08:55:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 296E028448 for ; Wed, 15 Feb 2017 08:55:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E1E52844C; Wed, 15 Feb 2017 08:55:38 +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 BDCF72844A for ; Wed, 15 Feb 2017 08:55:37 +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 1cdvL5-0007Wq-8i; Wed, 15 Feb 2017 08:53:27 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cdvL4-0007Vy-Ls for xen-devel@lists.xenproject.org; Wed, 15 Feb 2017 08:53:26 +0000 Received: from [193.109.254.147] by server-6.bemta-6.messagelabs.com id 20/38-15112-60714A85; Wed, 15 Feb 2017 08:53:26 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrLLMWRWlGSWpSXmKPExsXS1tYhocsqviT C4P9qVYvvWyYzOTB6HP5whSWAMYo1My8pvyKBNWNn3w2WgteyFZ8XtDE2MB4Q62Lk5BASmMYo MftGDogtIcArcWTZDNYuRg4gO0Di30LBLkYuoJIGRomDKx6zg9SwCahLPP7awwRiiwgoSdxbN ZkJpIhZYBGTxIpJ39lAEsICgRILbu4GK2IRUJU4Mm0VC4jNK+Ah0ft0NhvEMjmJk8cms4LYnE DxYxfmsEIc5C5xtGca0wRG3gWMDKsY1YtTi8pSi3TN9JKKMtMzSnITM3N0DQ3M9HJTi4sT01N zEpOK9ZLzczcxAoOBAQh2MM474X+IUZKDSUmUl+3Y4gghvqT8lMqMxOKM+KLSnNTiQ4wyHBxK ErxMYksihASLUtNTK9Iyc4BhCZOW4OBREuH9KQqU5i0uSMwtzkyHSJ1iVJQS5/0IkhAASWSU5 sG1wWLhEqOslDAvI9AhQjwFqUW5mSWo8q8YxTkYlYR5/4NM4cnMK4Gb/gpoMRPQYta4hSCLSx IRUlINjPk1crcvJU2fsDGJ647L5+rFVQuXNaXunnmlcgWH42rFd9FHjrc0ndlS17Xb30t70y6 hKim26OT6NQKnDvBItk/hFV34p64+T69kdhNfJSOr1Y+KcG9G151X9jN+93ZfFrgvy4lNIOvj xtWPY+8+PnxHRMlaJf27t0D26iXiVSxvnb5U2u0rV2Ipzkg01GIuKk4EAJMp99CAAgAA X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-8.tower-27.messagelabs.com!1487148772!76852937!13 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.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 27814 invoked from network); 15 Feb 2017 08:53:25 -0000 Received: from mga09.intel.com (HELO mga09.intel.com) (134.134.136.24) by server-8.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 15 Feb 2017 08:53:25 -0000 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Feb 2017 00:53:24 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.35,165,1484035200"; d="scan'208"; a="1094969740" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.63]) by orsmga001.jf.intel.com with ESMTP; 15 Feb 2017 00:53:22 -0800 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Wed, 15 Feb 2017 16:49:27 +0800 Message-Id: <1487148579-7243-13-git-send-email-yi.y.sun@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1487148579-7243-1-git-send-email-yi.y.sun@linux.intel.com> References: <1487148579-7243-1-git-send-email-yi.y.sun@linux.intel.com> Cc: kevin.tian@intel.com, 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 v8 12/24] x86: refactor psr: set value: implement write msr 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 Continue with previous patch: 'x86: refactor psr: set value: implement cos id picking flow.' We have got all features values and COS ID to set. Then, we write MSRs of all features except the setting value is same as original value. Till now, set value process is completed. Signed-off-by: Yi Sun --- v8: - modify 'write_msr' callback function to 'void' because we have to set all features' cbm. When input cos exceeds some features' cos_max, just skip them but not break the iteration. --- xen/arch/x86/psr.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c index 5de53ac..82bb8fe 100644 --- a/xen/arch/x86/psr.c +++ b/xen/arch/x86/psr.c @@ -169,6 +169,9 @@ struct feat_ops { bool (*fits_cos_max)(const uint64_t val[], const struct feat_node *feat, unsigned int cos); + /* write_msr is used to write out feature MSR register. */ + void (*write_msr)(unsigned int cos, const uint64_t val[], + struct feat_node *feat); }; /* @@ -427,6 +430,21 @@ static bool l3_cat_fits_cos_max(const uint64_t val[], return true; } +static void l3_cat_write_msr(unsigned int cos, const uint64_t val[], + struct feat_node *feat) +{ + if ( cos > feat->info.l3_cat_info.cos_max ) + return; + + if ( feat->cos_reg_val[cos] != val[0] ) + { + feat->cos_reg_val[cos] = val[0]; + wrmsrl(MSR_IA32_PSR_L3_MASK(cos), val[0]); + } + + return; +} + static const struct feat_ops l3_cat_ops = { .get_cos_max = l3_cat_get_cos_max, .get_feat_info = l3_cat_get_feat_info, @@ -436,6 +454,7 @@ static const struct feat_ops l3_cat_ops = { .set_new_val = l3_cat_set_new_val, .compare_val = l3_cat_compare_val, .fits_cos_max = l3_cat_fits_cos_max, + .write_msr = l3_cat_write_msr, }; static void __init parse_psr_bool(char *s, char *value, char *feature, @@ -918,10 +937,66 @@ static int pick_avail_cos(const struct psr_socket_info *info, return -ENOENT; } +static unsigned int get_socket_cpu(unsigned int socket) +{ + if ( likely(socket < nr_sockets) ) + return cpumask_any(socket_cpumask[socket]); + + return nr_cpu_ids; +} + +struct cos_write_info +{ + unsigned int cos; + struct list_head *feat_list; + const uint64_t *val; +}; + +static void do_write_psr_msr(void *data) +{ + struct cos_write_info *info = (struct cos_write_info *)data; + unsigned int cos = info->cos; + struct list_head *feat_list= info->feat_list; + const uint64_t *val = info->val; + struct feat_node *feat; + + if ( !feat_list ) + return; + + /* + * We need set all features values into MSRs. Even the cos exceeds some + * features' cos_max, just skip them. + */ + list_for_each_entry(feat, feat_list, list) + { + feat->ops.write_msr(cos, val, feat); + val += feat->ops.get_cos_num(feat); + } +} + static int write_psr_msr(unsigned int socket, unsigned int cos, const uint64_t *val) { - return -ENOENT; + struct psr_socket_info *info = get_socket_info(socket); + struct cos_write_info data = + { + .cos = cos, + .feat_list = &info->feat_list, + .val = val, + }; + + if ( socket == cpu_to_socket(smp_processor_id()) ) + do_write_psr_msr(&data); + else + { + unsigned int cpu = get_socket_cpu(socket); + + if ( cpu >= nr_cpu_ids ) + return -ENOTSOCK; + on_selected_cpus(cpumask_of(cpu), do_write_psr_msr, &data, 1); + } + + return 0; } int psr_set_val(struct domain *d, unsigned int socket,