From patchwork Fri Oct 13 08:40:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 10003805 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 ADB5B60216 for ; Fri, 13 Oct 2017 09:04:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A2ACE29009 for ; Fri, 13 Oct 2017 09:04:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 973332900B; Fri, 13 Oct 2017 09:04:14 +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 3E4D62900A for ; Fri, 13 Oct 2017 09:04:13 +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 1e2vrC-0001vi-Py; Fri, 13 Oct 2017 09:02:14 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e2vrC-0001ua-5W for xen-devel@lists.xenproject.org; Fri, 13 Oct 2017 09:02:14 +0000 Received: from [193.109.254.147] by server-7.bemta-6.messagelabs.com id A9/13-25852-51180E95; Fri, 13 Oct 2017 09:02:13 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrEIsWRWlGSWpSXmKPExsVywNwkVpev8UG kQd8TM4vvWyYzOTB6HP5whSWAMYo1My8pvyKBNWPFnrlsBRO1Kmauf8HSwLhQvouRi0NIYBqj xKW7P1m7GDk5JAR4JY4smwFlB0jc3HeBDaKogVFi0ZylLCAJNgF1icdfe5hAbBEBJYl7qyYzg RQxC/xmlDi15RBYQljAUeL1l61gk1gEVCUeL//ODmLzCnhIHFv4nB1ig5zEyWOTwWo4BTwlup o2MoPYQkA1m79MZoOoF5Q4OfMJ0GIOoAXqEuvnCYGEmQXkJZq3zmaewCgwC0nVLISqWUiqFjA yr2LUKE4tKkst0jU21ksqykzPKMlNzMzRNTQw08tNLS5OTE/NSUwq1kvOz93ECAxPBiDYwbhz feAhRkkOJiVRXrXIB5FCfEn5KZUZicUZ8UWlOanFhxhlODiUJHh9GoBygkWp6akVaZk5wEiBS Utw8CiJ8GqCpHmLCxJzizPTIVKnGHU5Om7e/cMkxJKXn5cqJc5rAVIkAFKUUZoHNwIWtZcYZa WEeRmBjhLiKUgtys0sQZV/xSjOwagkzPunHmgKT2ZeCdymV0BHMAEd8S4C7IiSRISUVAOjwhn J0FWyEdzHMp9Pny4pH/RB7cLHWoVPB3ufdkkZJ6/8YLkzo/uH28XfuSc+/BayDW3OCDz3fgsb b+r5b6tN2Nuf3048XRXR8Pi1wUKL6VGhae+mbC25cNKDp/F8p7Sgz2Lj9uB1045VfWNcOY39n Msu1Yl59cJfdjZ4Tnh/5FDnZQY71pKbSizFGYmGWsxFxYkAe3NC2NUCAAA= X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-6.tower-27.messagelabs.com!1507885322!111673941!3 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.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 9320 invoked from network); 13 Oct 2017 09:02:06 -0000 Received: from mga11.intel.com (HELO mga11.intel.com) (192.55.52.93) by server-6.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 13 Oct 2017 09:02:06 -0000 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Oct 2017 02:02:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.43,370,1503385200"; d="scan'208"; a="1024784878" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.75]) by orsmga003.jf.intel.com with ESMTP; 13 Oct 2017 02:02:03 -0700 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Fri, 13 Oct 2017 16:40:58 +0800 Message-Id: <1507884068-18757-7-git-send-email-yi.y.sun@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1507884068-18757-1-git-send-email-yi.y.sun@linux.intel.com> References: <1507884068-18757-1-git-send-email-yi.y.sun@linux.intel.com> MIME-Version: 1.0 Cc: Wei Liu , Yi Sun , Andrew Cooper , Jan Beulich , Chao Peng , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [Xen-devel] [PATCH v7 06/16] x86: implement get hw info flow for MBA 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 This patch implements get HW info flow for MBA including its callback function and sysctl interface. Signed-off-by: Yi Sun Reviewed-by: Roger Pau Monné Acked-by: Jan Beulich --- CC: Jan Beulich CC: Andrew Cooper CC: Wei Liu CC: Roger Pau Monné CC: Chao Peng v7: - change 'PSR_INFO_IDX_MBA_FLAG' to 'PSR_INFO_IDX_MBA_FLAGS'. (suggested by Jan Beulich) v5: - use ASSERT in 'mba_get_feat_info'. (suggested by Roger Pau Monné) - correct initialization format of 'data[PSR_INFO_ARRAY_SIZE]'. (suggested by Roger Pau Monné and Jan Beulich) v4: - remove 'ALLOC_' from macro names. (suggested by Roger Pau Monné) - initialize 'data[PSR_INFO_ARRAY_SIZE]' to 0 to prevent to leak stack data. (suggested by Roger Pau Monné) v3: - replace 'PSR_VAL_TYPE_MBA' to 'PSR_TYPE_MBA_THRTL'. (suggested by Roger Pau Monné) v2: - use 'XEN_SYSCTL_PSR_MBA_LINEAR' to set MBA feature HW info. (suggested by Chao Peng) v1: - sort 'PSR_INFO_IDX_' macros as feature. (suggested by Chao Peng) - rename 'PSR_INFO_IDX_MBA_LINEAR' to 'PSR_INFO_IDX_MBA_FLAG'. - rename 'linear' in 'struct mba_info' to 'flags' for future extension. (suggested by Chao Peng) --- xen/arch/x86/psr.c | 14 +++++++++++++- xen/arch/x86/sysctl.c | 21 ++++++++++++++++++++- xen/include/asm-x86/psr.h | 2 ++ xen/include/public/sysctl.h | 8 ++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c index 64d30b9..f5b395b 100644 --- a/xen/arch/x86/psr.c +++ b/xen/arch/x86/psr.c @@ -263,6 +263,10 @@ static enum psr_feat_type psr_type_to_feat_type(enum psr_type type) feat_type = FEAT_TYPE_L2_CAT; break; + case PSR_TYPE_MBA_THRTL: + feat_type = FEAT_TYPE_MBA; + break; + default: ASSERT_UNREACHABLE(); } @@ -483,7 +487,15 @@ static const struct feat_props l2_cat_props = { static bool mba_get_feat_info(const struct feat_node *feat, uint32_t data[], unsigned int array_len) { - return false; + ASSERT(array_len == PSR_INFO_ARRAY_SIZE); + + data[PSR_INFO_IDX_COS_MAX] = feat->cos_max; + data[PSR_INFO_IDX_MBA_THRTL_MAX] = feat->mba.thrtl_max; + + if ( feat->mba.linear ) + data[PSR_INFO_IDX_MBA_FLAGS] |= XEN_SYSCTL_PSR_MBA_LINEAR; + + return true; } static void mba_write_msr(unsigned int cos, uint32_t val, diff --git a/xen/arch/x86/sysctl.c b/xen/arch/x86/sysctl.c index 6d48cac..ffad585 100644 --- a/xen/arch/x86/sysctl.c +++ b/xen/arch/x86/sysctl.c @@ -174,7 +174,7 @@ long arch_do_sysctl( case XEN_SYSCTL_psr_alloc: switch ( sysctl->u.psr_alloc.cmd ) { - uint32_t data[PSR_INFO_ARRAY_SIZE]; + uint32_t data[PSR_INFO_ARRAY_SIZE] = { }; case XEN_SYSCTL_PSR_get_l3_info: { @@ -214,6 +214,25 @@ long arch_do_sysctl( break; } + case XEN_SYSCTL_PSR_get_mba_info: + { + ret = psr_get_info(sysctl->u.psr_alloc.target, + PSR_TYPE_MBA_THRTL, data, ARRAY_SIZE(data)); + if ( ret ) + break; + + sysctl->u.psr_alloc.u.mba_info.cos_max = + data[PSR_INFO_IDX_COS_MAX]; + sysctl->u.psr_alloc.u.mba_info.thrtl_max = + data[PSR_INFO_IDX_MBA_THRTL_MAX]; + sysctl->u.psr_alloc.u.mba_info.flags = + data[PSR_INFO_IDX_MBA_FLAGS]; + + if ( __copy_field_to_guest(u_sysctl, sysctl, u.psr_alloc) ) + ret = -EFAULT; + break; + } + default: ret = -EOPNOTSUPP; break; diff --git a/xen/include/asm-x86/psr.h b/xen/include/asm-x86/psr.h index 3cf544a..c2257da 100644 --- a/xen/include/asm-x86/psr.h +++ b/xen/include/asm-x86/psr.h @@ -39,6 +39,8 @@ #define PSR_INFO_IDX_COS_MAX 0 #define PSR_INFO_IDX_CAT_CBM_LEN 1 #define PSR_INFO_IDX_CAT_FLAGS 2 +#define PSR_INFO_IDX_MBA_THRTL_MAX 1 +#define PSR_INFO_IDX_MBA_FLAGS 2 #define PSR_INFO_ARRAY_SIZE 3 struct psr_cmt_l3 { diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index a50e345..f7f26c3 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -698,6 +698,7 @@ struct xen_sysctl_pcitopoinfo { #define XEN_SYSCTL_PSR_get_l3_info 0 #define XEN_SYSCTL_PSR_get_l2_info 1 +#define XEN_SYSCTL_PSR_get_mba_info 2 struct xen_sysctl_psr_alloc { uint32_t cmd; /* IN: XEN_SYSCTL_PSR_* */ uint32_t target; /* IN */ @@ -708,6 +709,13 @@ struct xen_sysctl_psr_alloc { #define XEN_SYSCTL_PSR_CAT_L3_CDP (1u << 0) uint32_t flags; /* OUT: CAT flags */ } cat_info; + + struct { + uint32_t thrtl_max; /* OUT: Maximum throttle */ + uint32_t cos_max; /* OUT: Maximum COS */ +#define XEN_SYSCTL_PSR_MBA_LINEAR (1u << 0) + uint32_t flags; /* OUT: MBA flags */ + } mba_info; } u; };