From patchwork Fri Jan 1 18:13:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Suthikulpanit, Suravee" X-Patchwork-Id: 59102 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp4081608lbb; Fri, 1 Jan 2016 10:26:17 -0800 (PST) X-Received: by 10.98.44.209 with SMTP id s200mr101481858pfs.2.1451672777735; Fri, 01 Jan 2016 10:26:17 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 192si18221440pfa.49.2016.01.01.10.26.17; Fri, 01 Jan 2016 10:26:17 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752577AbcAAS0P (ORCPT + 29 others); Fri, 1 Jan 2016 13:26:15 -0500 Received: from mail-by2on0075.outbound.protection.outlook.com ([207.46.100.75]:54991 "EHLO na01-by2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752256AbcAASYd (ORCPT ); Fri, 1 Jan 2016 13:24:33 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Suravee.Suthikulpanit@amd.com; Received: from ssuthiku-cz-dev.amd.com (165.204.77.1) by SN1PR12MB0446.namprd12.prod.outlook.com (10.162.105.14) with Microsoft SMTP Server (TLS) id 15.1.361.13; Fri, 1 Jan 2016 18:24:30 +0000 From: Suravee Suthikulpanit To: , , , , CC: , , Suravee Suthikulpanit Subject: [PATCH v2 2/6] perf/amd/iommu: Modify functions to query max banks and counters Date: Fri, 1 Jan 2016 12:13:36 -0600 Message-ID: <1451672020-2150-3-git-send-email-Suravee.Suthikulpanit@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1451672020-2150-1-git-send-email-Suravee.Suthikulpanit@amd.com> References: <1451672020-2150-1-git-send-email-Suravee.Suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BLUPR01CA041.prod.exchangelabs.com (25.160.23.31) To SN1PR12MB0446.namprd12.prod.outlook.com (25.162.105.14) X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0446; 2:UtKYNxhP4JUdDQ6vv4TyhRMWETe+TaV44ilhyyWyThqmNQRw3BL0F4BDwdoSOVdf2hAA9PpNT4jDfa7OOV128PSjzKOx2hBvOXTtY3D3LYJb9zpzT2x7HdR7HH6xFobUJ4JrbtjnSBC3SwH+b0owsA==; 3:Inx4viQtjRjCndUYZWju8CfpMRO5mQvxOh2enQt3W0It8c0gxwRPXEkvZPLNXEPl9MOVaWQx5I7mcGT/GL/ifnoKKplMYsKa2y/aBbrP5pA3I/lbuykFAnSwjgzp9wxW; 25:mzqHByAsuADXq5j6rwkjg9ElhEaDou/edQWAv3jSugqn+zkYc7JaisuXyHf7Ib0CtmNvvkr6iEHJqFRz2n6uJB86FZwTlpie8bQB0oO3zCdxlSxJnukfWdS6A11XDO+dXG8XEGd5tq4cInHlUr0NiljaZmRFpTiVvcsGTL8h/zwj+Ka1UDSld7IzuKJMewQzuqZObPb4CLK1zVDBCorrh8k6mH/a7LBidPWUScESo1pJYdFJQvbQyYyLQ/VQuags1yufTHcuaYMzw9eKEH9wcw== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SN1PR12MB0446; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0446; 20:ZmdI8J6vLeEX+uty1PPBTqVdRfDTSC/xpnYsBV0DGyIgib0URpa7emySVaa79WUJOtUOyBBaTqPo/6x9oZZmK0jTOD6qKhdjc4foKiztiWxRXRPSRoel+//BTgXYh/DIGuity8pExrXnLAVO1Cm6C5XVn/qCXgWHtk9n04EPYHt29QBfT6Eu+eZ3ssgi5OEn1KDVxxax9g/Az2Y1kpECnSZ0CHk7vXbNXVJcs0N8PlP6G7nhbGnJTplCQPE0XUrNfGnfPDerobvQ3y4/GlR86l9cNOLYFtug2Vzvf7E1oD0xSxwbcaYQZVFhjwektXeGTeqKu9G3FmC+Qc2ntJ+yolvd+UF409vFc04+VjRz1p1Jg+rmEhumEW3WOOU53dgYuQZh0x7uJlaOB4h2W/+qgQlMX406rhdo7z2cz7rVrSNUjjeU8pzYG3FzGbMYkWkAIc9t8mOfOsYxnzLAq3sqknlFE0kcuwl3Kuito3jiYrezvfit871WTi2KaqaVbudK; 4:mtP348P80QjohqBGj/Anyn54136w1eT0HU9HfX2Xcxrd334V74CRyIWuV2SuLmG3bO66kIU0KgzqCvNjcncwRxYQQOZWVtxA9ii3ISw7VNDv/5yspMEr6NOCrlXsHum9FGtuHHBsoUXBkp7o7Ox0BQRZKGU7hO/elseT2tRBfo4BuEIxWPIyC0tgNClfwyfzcPfYedtxA4/SgRzzLX5diCstBALhdd6YEnXttHyMNqvrNE35EthUdsdj/vNL6k0IVq6FZSmySPkDOC5GGdLB2z+oze1iWQiFUFQErN2kJE7AI9XmQl6GEHofRk9Cy/RsQ8qE4NuHd8Adl1YZ+1yUT0w9ZVCBHkeJtZBKGEgBI9iGufhwGEAjsdjb+T2EGBwoQBwccTUYaLk1p1x0Wk69SNNRCSIs14Rvj/vZ0v2jY2E= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(520078)(5005006)(3002001)(10201501046); SRVR:SN1PR12MB0446; BCL:0; PCL:0; RULEID:; SRVR:SN1PR12MB0446; X-Forefront-PRVS: 0808323E97 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(189002)(199003)(5008740100001)(19580405001)(97736004)(36756003)(66066001)(50986999)(3846002)(50466002)(586003)(6116002)(40100003)(19580395003)(229853001)(1096002)(122386002)(189998001)(47776003)(2201001)(77096005)(2950100001)(50226001)(76176999)(92566002)(86362001)(5001770100001)(42186005)(48376002)(53416004)(106356001)(575784001)(101416001)(4326007)(105586002)(5003940100001)(87976001)(5004730100002); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0446; H:ssuthiku-cz-dev.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN1PR12MB0446; 23:AxC+zBWw9BvSzCeo1esBYaXa/tYzgV5mnCUtLJ3t8?= =?us-ascii?Q?bYtKgZxNiFw7jSNewt3OVEruf1n6CAzJ5aR0IxV+bUjWfYjjx/Um7HYc6AWJ?= =?us-ascii?Q?tVMdWJeYpsXJfhuhB4KcnxFriU/CP7OUt4CizcC2k6qGPbGjc4PxIE8m3jGP?= =?us-ascii?Q?EhMHsU5UIN6IrvL9sOCH0qNBSI774PYgymc/SvIZ7TL9YUK7c/4QkcoFx57f?= =?us-ascii?Q?4prGiGNozH+a2fxta3qBnkx5eDwb880fJO9bMcSgNDS3YT2qB6fhwjA5BHDV?= =?us-ascii?Q?sF8gEKDPPWu5Wu/Vk4XAQjraS5nJUeXd6TiJeIam72xeitSeotcXzLXotw+S?= =?us-ascii?Q?jFWwEQ3h/3AWkT2165AIFYTpSRe+3K1oHyPTqPQY4srpkMd6tHVzlRtNznDd?= =?us-ascii?Q?bEHSKOpNIr5M/NvlyBl0Nj4vPUxyGFMBzLQL+lXPiIlamYbA81zFhXsiYASo?= =?us-ascii?Q?Zy2otoS9Aig965x2dRC+bjWwSc2SnuizdHz+mdMd4oG0J4CBJj/A5/cf+Y/q?= =?us-ascii?Q?HUD9NX+jXb/pipRjqYGiNQY+lkNt8gch6IXeNCETa2NnqQNVV4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elWoPTXPTo/OOULY8rff1iOZDg95V0HLoksRteG8O7Hi8xCEcRBT04wzTjTMA/7PiCcV1Q X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jan 2016 18:24:30.0181 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0446 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, amd_iommu_pc_get_max_[banks|counters]() require devid, which should not be the case. Also, these don't properly support multi-IOMMU system. Current and future AMD systems with IOMMU that support perf counter would likely contain homogeneous IOMMUs where multiple IOMMUs are availalbe. So, this patch modifies these function to iterate all IOMMU to check the max banks and counters reported by the hardware. Signed-off-by: Suravee Suthikulpanit --- arch/x86/kernel/cpu/perf_event_amd_iommu.c | 17 +++++++---------- drivers/iommu/amd_iommu_init.c | 20 ++++++++++++-------- include/linux/perf/perf_event_amd_iommu.h | 7 ++----- 3 files changed, 21 insertions(+), 23 deletions(-) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c index 1192f1d..e6d2485 100644 --- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c +++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c @@ -237,14 +237,6 @@ static int perf_iommu_event_init(struct perf_event *event) return -EINVAL; } - /* integrate with iommu base devid (0000), assume one iommu */ - perf_iommu->max_banks = - amd_iommu_pc_get_max_banks(IOMMU_BASE_DEVID); - perf_iommu->max_counters = - amd_iommu_pc_get_max_counters(IOMMU_BASE_DEVID); - if ((perf_iommu->max_banks == 0) || (perf_iommu->max_counters == 0)) - return -EINVAL; - /* update the hw_perf_event struct with the iommu config data */ hwc->config = config; hwc->extra_reg.config = config1; @@ -455,6 +447,11 @@ static __init int _init_perf_amd_iommu( if (_init_events_attrs(perf_iommu) != 0) pr_err("perf: amd_iommu: Only support raw events.\n"); + perf_iommu->max_banks = amd_iommu_pc_get_max_banks(); + perf_iommu->max_counters = amd_iommu_pc_get_max_counters(); + if ((perf_iommu->max_banks == 0) || (perf_iommu->max_counters == 0)) + return -EINVAL; + /* Init null attributes */ perf_iommu->null_group = NULL; perf_iommu->pmu.attr_groups = perf_iommu->attr_groups; @@ -465,8 +462,8 @@ static __init int _init_perf_amd_iommu( amd_iommu_pc_exit(); } else { pr_info("perf: amd_iommu: Detected. (%d banks, %d counters/bank)\n", - amd_iommu_pc_get_max_banks(IOMMU_BASE_DEVID), - amd_iommu_pc_get_max_counters(IOMMU_BASE_DEVID)); + amd_iommu_pc_get_max_banks(), + amd_iommu_pc_get_max_counters()); } return ret; diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c index b6d684c..275c0f5 100644 --- a/drivers/iommu/amd_iommu_init.c +++ b/drivers/iommu/amd_iommu_init.c @@ -2251,15 +2251,17 @@ EXPORT_SYMBOL(amd_iommu_v2_supported); * ****************************************************************************/ -u8 amd_iommu_pc_get_max_banks(u16 devid) +u8 amd_iommu_pc_get_max_banks(void) { struct amd_iommu *iommu; u8 ret = 0; - /* locate the iommu governing the devid */ - iommu = amd_iommu_rlookup_table[devid]; - if (iommu) + for_each_iommu(iommu) { + if (!iommu->max_banks || + (ret && (iommu->max_banks != ret))) + return 0; ret = iommu->max_banks; + } return ret; } @@ -2271,15 +2273,17 @@ bool amd_iommu_pc_supported(void) } EXPORT_SYMBOL(amd_iommu_pc_supported); -u8 amd_iommu_pc_get_max_counters(u16 devid) +u8 amd_iommu_pc_get_max_counters(void) { struct amd_iommu *iommu; u8 ret = 0; - /* locate the iommu governing the devid */ - iommu = amd_iommu_rlookup_table[devid]; - if (iommu) + for_each_iommu(iommu) { + if (!iommu->max_counters || + (ret && (iommu->max_counters != ret))) + return 0; ret = iommu->max_counters; + } return ret; } diff --git a/include/linux/perf/perf_event_amd_iommu.h b/include/linux/perf/perf_event_amd_iommu.h index 845d173..815eabb 100644 --- a/include/linux/perf/perf_event_amd_iommu.h +++ b/include/linux/perf/perf_event_amd_iommu.h @@ -24,15 +24,12 @@ #define PC_MAX_SPEC_BNKS 64 #define PC_MAX_SPEC_CNTRS 16 -/* iommu pc reg masks*/ -#define IOMMU_BASE_DEVID 0x0000 - /* amd_iommu_init.c external support functions */ extern bool amd_iommu_pc_supported(void); -extern u8 amd_iommu_pc_get_max_banks(u16 devid); +extern u8 amd_iommu_pc_get_max_banks(void); -extern u8 amd_iommu_pc_get_max_counters(u16 devid); +extern u8 amd_iommu_pc_get_max_counters(void); extern int amd_iommu_pc_get_set_reg_val(u16 devid, u8 bank, u8 cntr, u8 fxn, u64 *value, bool is_write);