From patchwork Thu Mar 16 11:08:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9627867 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 6CF0B6048C for ; Thu, 16 Mar 2017 11:16:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 64C702857D for ; Thu, 16 Mar 2017 11:16:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 58FFD285B8; Thu, 16 Mar 2017 11:16:05 +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.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID 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 D216F2857D for ; Thu, 16 Mar 2017 11:16:04 +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 1coTMR-0004le-3P; Thu, 16 Mar 2017 11:14:27 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1coTMQ-0004kF-58 for xen-devel@lists.xenproject.org; Thu, 16 Mar 2017 11:14:26 +0000 Received: from [85.158.137.68] by server-11.bemta-3.messagelabs.com id CE/47-23940-1937AC85; Thu, 16 Mar 2017 11:14:25 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrDLMWRWlGSWpSXmKPExsVywNwkVndC8ak Ig5efzCy+b5nM5MDocfjDFZYAxijWzLyk/IoE1oyuY0eZCx6rVcyY28nSwHhXuouRi4NF4BaT xNlVH9lBHCGBaYwSLe3P2LoYOTkkBHgljiybwdrFyAFk+0s8+ygHUdPAKPF46z92kBo2AXWJx 197mEBsEQEliXurJjOBFDEL7GSSWHf6OzNIQlggUuLT1KmsIDaLgKrEhddPwGxeAQ+Jl/+2sk Msk5M4eWwyWJwTKP6xvR3MFhJwl3i34S/7BEa+BYwMqxg1ilOLylKLdA1N9JKKMtMzSnITM3N 0DQ2M9XJTi4sT01NzEpOK9ZLzczcxAkOFAQh2MK7Y7nmIUZKDSUmUt/zHiQghvqT8lMqMxOKM +KLSnNTiQ4wyHBxKErxHlE5GCAkWpaanVqRl5gCDFiYtwcGjJMKbC5LmLS5IzC3OTIdInWJUl BLnvQCSEABJZJTmwbXBIuUSo6yUMC8j0CFCPAWpRbmZJajyrxjFORiVhHk3g0zhycwrgZv+Cm gxE9Ditx9OgCwuSURISTUwps3Zlic2fQPHlN3zF0rxrWMzf7w349Gf96xWSl0p55SPXmp+f1t 22wpVw08eBQWJvhPLdvX8CsxU93vKIXZI/vUOrZMxLf+FMpxLF6lvdTyTJrq8z2Vb8h6HOmYD yebv93+u9zfXreBVSLzRZRG1a2b6rk+eJ6uVObN+KPP63dX1jvzUEbVSiaU4I9FQi7moOBEAi VTtOY8CAAA= X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-2.tower-31.messagelabs.com!1489662818!78881615!16 X-Originating-IP: [192.55.52.93] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTkyLjU1LjUyLjkzID0+IDMyNDY2NQ==\n X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 11887 invoked from network); 16 Mar 2017 11:14:24 -0000 Received: from mga11.intel.com (HELO mga11.intel.com) (192.55.52.93) by server-2.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 16 Mar 2017 11:14:24 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1489662864; x=1521198864; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=EnNSqsIhOTbRseYBCHnuXbymYXSe/QfR2zmjr1l+U+g=; b=Gfmj2qSfvz/tnjG5h5WM+Ur/z/gZYve4O0ciGWQyp/UTZD1IcDvxUA+C pV0KHDm/qJJYzEme6pI++UD/Yg8SHg==; Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Mar 2017 04:14:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,172,1486454400"; d="scan'208";a="944976672" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.63]) by orsmga003.jf.intel.com with ESMTP; 16 Mar 2017 04:14:21 -0700 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Thu, 16 Mar 2017 19:08:07 +0800 Message-Id: <1489662495-5375-18-git-send-email-yi.y.sun@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1489662495-5375-1-git-send-email-yi.y.sun@linux.intel.com> References: <1489662495-5375-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, roger.pau@citrix.com Subject: [Xen-devel] [PATCH v9 17/25] x86: refactor psr: CDP: implement set value callback functions. 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 This patch implements L3 CDP set value related callback functions. With this patch, 'psr-cat-cbm-set' command can work for L3 CDP. Signed-off-by: Yi Sun --- v9: - add comment to explain why CDP uses 2 COSs. (suggested by Wei Liu) - use 'cat_default_val'. (suggested by Wei Liu) - remove 'l3_cdp_get_cos_num' because we can directly get cos_num from feat_node now. (suggested by Jan Beulich) - remove cos checking because it has been moved to common function. (suggested by Jan Beulich) - l3_cdp_set_new_val parameter 'm' is changed to 'new_val'. (suggested by Jan Beulich) - directly use get_cdp_data(feat, 0) and get_cdp_code(feat, 0) to get default value. (suggested by Jan Beulich) - modify 'l3_cdp_write_msr' flow to write value into register according to input type. - changes about 'uint64_t' to 'uint32_t'. (suggested by Jan Beulich) v8: - modify 'l3_cdp_write_msr' type to 'void'. v5: - remove type check in callback function. (suggested by Jan Beulich) - 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. (suggested by Jan Beulich) - remove 'l3_cdp_get_cos_max_from_type'. - rename 'l3_cdp_exceeds_cos_max' to 'l3_cdp_fits_cos_max'. (suggested by Jan Beulich) v4: - create this patch to make codes easier to understand. (suggested by Jan Beulich) --- xen/arch/x86/psr.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c index 0ce8a6b..7ede8a1 100644 --- a/xen/arch/x86/psr.c +++ b/xen/arch/x86/psr.c @@ -530,10 +530,101 @@ static void l3_cdp_get_val(const struct feat_node *feat, unsigned int cos, *val = get_cdp_code(feat, cos); } +static void l3_cdp_get_old_val(uint32_t val[], + const struct feat_node *feat, + unsigned int old_cos) +{ + /* Data */ + val[0] = get_cdp_data(feat, old_cos); + /* Code */ + val[1] = get_cdp_code(feat, old_cos); +} + +static int l3_cdp_set_new_val(uint32_t val[], + const struct feat_node *feat, + enum cbm_type type, + uint32_t new_val) +{ + if ( !psr_check_cbm(feat->info.cat_info.cbm_len, new_val) ) + return -EINVAL; + + if ( type == PSR_CBM_TYPE_L3_DATA ) + val[0] = new_val; + else + val[1] = new_val; + + return 0; +} + +static int l3_cdp_compare_val(const uint32_t val[], + const struct feat_node *feat, + unsigned int cos) +{ + /* + * Different features' cos_max are different. If cos id of the feature + * being set exceeds other feature's cos_max, the val of other feature + * must be default value. HW supports such case. + */ + if ( cos > feat->info.cat_info.cos_max ) + { + if ( val[0] != get_cdp_data(feat, 0) || + val[1] != get_cdp_code(feat, 0) ) + return -EINVAL; + + /* Find */ + return 1; + } + + if ( val[0] == get_cdp_data(feat, cos) && + val[1] == get_cdp_code(feat, cos) ) + /* Find */ + return 1; + + /* Not find */ + return 0; +} + +static bool l3_cdp_fits_cos_max(const uint32_t val[], + const struct feat_node *feat, + unsigned int cos) +{ + if ( cos > feat->info.cat_info.cos_max && + (val[0] != get_cdp_data(feat, 0) || val[1] != get_cdp_code(feat, 0)) ) + /* + * Exceed cos_max and value to set is not default, + * return error. + */ + return false; + + return true; +} + +static void l3_cdp_write_msr(unsigned int cos, uint32_t val, + enum cbm_type type, struct feat_node *feat) +{ + /* Data */ + if ( type == PSR_CBM_TYPE_L3_DATA && get_cdp_data(feat, cos) != val ) + { + get_cdp_data(feat, cos) = val; + wrmsrl(MSR_IA32_PSR_L3_MASK_DATA(cos), (uint64_t)val); + } + /* Code */ + if ( type == PSR_CBM_TYPE_L3_CODE && get_cdp_code(feat, cos) != val ) + { + get_cdp_code(feat, cos) = val; + wrmsrl(MSR_IA32_PSR_L3_MASK_CODE(cos), (uint64_t)val); + } +} + struct feat_ops l3_cdp_ops = { .get_cos_max = cat_get_cos_max, .get_feat_info = l3_cdp_get_feat_info, .get_val = l3_cdp_get_val, + .get_old_val = l3_cdp_get_old_val, + .set_new_val = l3_cdp_set_new_val, + .compare_val = l3_cdp_compare_val, + .fits_cos_max = l3_cdp_fits_cos_max, + .write_msr = l3_cdp_write_msr, }; static void __init parse_psr_bool(char *s, char *value, char *feature,