From patchwork Thu Jan 19 06:01:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9525211 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 D72BC60437 for ; Thu, 19 Jan 2017 06:05:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C43C52860C for ; Thu, 19 Jan 2017 06:05:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B8EEF2863A; Thu, 19 Jan 2017 06:05:22 +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 60A0C2860C for ; Thu, 19 Jan 2017 06:05:22 +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 1cU5oj-0007CF-I1; Thu, 19 Jan 2017 06:03:25 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cU5oi-0007AT-7g for xen-devel@lists.xenproject.org; Thu, 19 Jan 2017 06:03:24 +0000 Received: from [85.158.137.68] by server-4.bemta-3.messagelabs.com id 95/2B-01392-BA650885; Thu, 19 Jan 2017 06:03:23 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrHLMWRWlGSWpSXmKPExsVywNykWHdVWEO Ewfo5Vhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8bHjqlMBUflK7ZMfMTYwHhPvIuRi0NIYDqj xIU9d1i6GDk5JAR4JY4sm8HaxcgBZPtLLLxfBVHTwCixoOM3M0gNm4C6xOOvPUwgtoiAksS9V ZOZQIqYBbqZJFY+3MoC0iwsECHxr0sdpIZFQFWi/chUsF5eAQ+JfZP2skHskpM4eWwyK4jNCR S/Mv8CO4gtJOAusWXFJaYJjLwLGBlWMWoUpxaVpRbpGhvoJRVlpmeU5CZm5ugaGhjr5aYWFye mp+YkJhXrJefnbmIEhkM9AwPjDsbOE36HGCU5mJREee0tGyKE+JLyUyozEosz4otKc1KLDzHK cHAoSfDOCQXKCRalpqdWpGXmAAMTJi3BwaMkwlsFkuYtLkjMLc5Mh0idYlSUEueNAkkIgCQyS vPg2mDRcIlRVkqYl5GBgUGIpyC1KDezBFX+FaM4B6OSMO93kCk8mXklcNNfAS1mAlpspVwPsr gkESEl1cDYlxa6f8df49qAy65zdL9leFsGbT0/OXnmGcUS9tQpHHUHKny2up4x+/6i7cZby96 tJ/dyr90atOWfA8takSN50/RvPZ8gkpVqJp/BoP+jrOHOiV2KWzTLji80nrmZQc/dKNuTY868 kw/Cr/2VZJfW49vyeJn16Q+XjW+dnvh83uGPXkv3pMztUGIpzkg01GIuKk4EAAyZluqBAgAA X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-13.tower-31.messagelabs.com!1484805800!80652688!1 X-Originating-IP: [192.55.52.115] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 3396 invoked from network); 19 Jan 2017 06:03:22 -0000 Received: from mga14.intel.com (HELO mga14.intel.com) (192.55.52.115) by server-13.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 19 Jan 2017 06:03:22 -0000 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Jan 2017 22:03:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,252,1477983600"; d="scan'208";a="215119527" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.63]) by fmsmga004.fm.intel.com with ESMTP; 18 Jan 2017 22:03:07 -0800 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Thu, 19 Jan 2017 14:01:14 +0800 Message-Id: <1484805686-7249-13-git-send-email-yi.y.sun@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1484805686-7249-1-git-send-email-yi.y.sun@linux.intel.com> References: <1484805686-7249-1-git-send-email-yi.y.sun@linux.intel.com> Cc: wei.liu2@citrix.com, konrad.wilk@oracle.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 RESEND v5 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 --- v5: - modify commit message to provide exact patch name to continue from. - modify return value of callback functions because we do not need them to return number of entries the feature uses. In caller, we call 'get_cos_num' to get the number of entries the feature uses. - move type check out from callback functions to caller. - modify variables names to make them better, e.g. 'feat_tmp' to 'feat'. --- xen/arch/x86/psr.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c index c3e25bf..b8d3c82 100644 --- a/xen/arch/x86/psr.c +++ b/xen/arch/x86/psr.c @@ -165,6 +165,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. */ + int (*write_msr)(unsigned int cos, const uint64_t val[], + struct feat_node *feat); }; /* @@ -418,6 +421,21 @@ static bool l3_cat_fits_cos_max(const uint64_t val[], return true; } +static int 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 -EINVAL; + + 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 0; +} + static const struct feat_ops l3_cat_ops = { .get_cos_max = l3_cat_get_cos_max, .get_feat_info = l3_cat_get_feat_info, @@ -427,6 +445,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, @@ -909,10 +928,67 @@ 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; + int ret; + + if ( !feat_list ) + return; + + /* We need set all features values into MSRs. */ + list_for_each_entry(feat, feat_list, list) + { + ret = feat->ops.write_msr(cos, val, feat); + if ( ret < 0 ) + return; + + 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,