From patchwork Tue Feb 9 22:53:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Suthikulpanit, Suravee" X-Patchwork-Id: 61599 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp2316769lbl; Tue, 9 Feb 2016 14:54:58 -0800 (PST) X-Received: by 10.98.67.92 with SMTP id q89mr11904296pfa.137.1455058488493; Tue, 09 Feb 2016 14:54:48 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id aj1si335308pad.244.2016.02.09.14.54.48; Tue, 09 Feb 2016 14:54:48 -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 S965022AbcBIWyj (ORCPT + 30 others); Tue, 9 Feb 2016 17:54:39 -0500 Received: from mail-bn1on0074.outbound.protection.outlook.com ([157.56.110.74]:24256 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S965002AbcBIWyd (ORCPT ); Tue, 9 Feb 2016 17:54:33 -0500 Authentication-Results: 8bytes.org; dkim=none (message not signed) header.d=none; 8bytes.org; dmarc=none action=none header.from=amd.com; Received: from localhost.localdomain (58.10.104.205) by BLUPR12MB0434.namprd12.prod.outlook.com (10.162.92.14) with Microsoft SMTP Server (TLS) id 15.1.403.16; Tue, 9 Feb 2016 22:54:26 +0000 From: Suravee Suthikulpanit To: , , , , CC: , , , Suravee Suthikulpanit Subject: [PATCH V3 2/5] perf/amd/iommu: Modify functions to query max banks and counters Date: Tue, 9 Feb 2016 16:53:52 -0600 Message-ID: <1455058435-8716-3-git-send-email-Suravee.Suthikulpanit@amd.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1455058435-8716-1-git-send-email-Suravee.Suthikulpanit@amd.com> References: <1455058435-8716-1-git-send-email-Suravee.Suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [58.10.104.205] X-ClientProxiedBy: SG2PR03CA0004.apcprd03.prod.outlook.com (25.160.233.14) To BLUPR12MB0434.namprd12.prod.outlook.com (25.162.92.14) X-MS-Office365-Filtering-Correlation-Id: f26f3c1b-c68f-44d4-1ecb-08d331a3f833 X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0434; 2:nO7x7V3h+reRySOVYlLJTujJv1YiYZy5MWlcupahAQuUoiOnDcCdga6HPeCD+IEGVesYoKGujJh2xbki1IYEtUajIamLGP2t1+KN7krIRbIcoy2pVQoQF72mE5Homef69HQJBQgssgpmeMdCVGRrkrp4T5hryc8SMJFS+2OS6iCWQLYoq5jjVR3gQcxh0O2P; 3:8D+JNwee1pJ6n2ZOnNnWt8rz37PlX24WEXrgnHByA1R2qL7E+VD7UVYsHiXJpR+oua4Yl6QHj0fAEFXo5wbJ15aipe5o3i9QAQYPamPU7zIhcLpUntG2UNpKnIlc+jqW; 25:TQbC/CWZr4dSkJPOjthF3DfX9xlxhVw1AkOHQxjYhAcIyAvMp8Trd/AP3OeRvGg4nvomsGUCCR7KR/uk8V67BGwApR7z6xjheYN2R00IAt4jNc2pQ+SJnIeBpxMmFBVb5oXsGVgLenSG/I+YfZYwrOCyQnvinE4SCoGa0Te9pWge1fBhQdxrl8SoCXOI+7OFIBBs1zy4nJSf9qxURgDP9xXlDW6LCeoY9/Jmqt824yRPcOrYKohh4KiHiWyOURsceAHTXS/+Jb7Lc+aRQ7LcxdWzkQ9iDl6fHMs4v54MU03hgLDVXA3WJXYCpKXxl6s3 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR12MB0434; X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0434; 20:JWrwDnAIafnGY0zIDYfV62Ex3ntvsXW7w6raKqnqA3QBITFRDjHOGxVY9GtMB+uTjkASpdQEpLTBivuDxSu2MBX3/ZADWzb7tZ51MDUF1lZL1PLJ3zUUssJ7dEVYEASYKTFmrg2/UOKHtYZQXfpA+2bd9YU5QOA+T75bBD6D8tEL2jZz5/CEbUTuKuloQ5GnU642gvKXTcD8XF1e3Uw8FgL7hEfZc6i8ISwzyKPRb975Oiria/P8+Jwk+IRt2bseO4EKfolJjlAQ5pkBzWzt5UKH6pCRmvh/4lWPvkneLyYhXDzrgi6GHOau+K4zC8q1zoWGYmvthlHCrMbR8M6I3dvF45RFsKfRGB/ZR9JBs/BjdqmoH8K9UsQOXRVAz9Znd+U31Ba+tw98DeU29I61RK0PKkey+nuACJYnU9IAOpKG43P7JShiFW/rqfxKYgGcOCN0LQnCZzrqiE5rI6djoQiqLRBbpkugC84m/Zzkgn2VWp+N7VkBvzek3MnxtZ7x; 4:ws/a16PhOeHrn2UJU4t/XvM5RtF77IBG+w5Rn/pOqIqHAxZGB4UwvS26wmZHgp/q8pKOCRyYiyu9aPQJHEUSFEUZOuxVtEqEil8OxVQi74VtM2n1SltmeSuhwhoccXjWUOD5eBPZiKiGz898Yda7KgXEVSLthjcfkGWOiT7u7RGOGACTcNGQN7Mgq9E8asSYAnRU2+tUZF6h0/egZnNcMAZsphdiE2c+nQcJ/31J1We+7fr60w9cCV5HO1xftPst6Qku0FMjfOxNX7zw4hFr347dCxLFpoY9doXRIbKqLgTJQj868NvXknZb7SmQ65d84XKG47a5s3ku8ATOcyfUBl0Jhvm35MhAFf+0jePT6G15isPlWh76OD+gjsjL0JvaysAV7VTuXraStupxIGiobrgoO/9Q5E+5bInkRGSNggI= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046); SRVR:BLUPR12MB0434; BCL:0; PCL:0; RULEID:; SRVR:BLUPR12MB0434; X-Forefront-PRVS: 08476BC6EF X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(6069001)(19580405001)(19580395003)(48376002)(122386002)(36756003)(77096005)(5001960100002)(5003940100001)(92566002)(86362001)(575784001)(50986999)(42186005)(76176999)(2906002)(87976001)(40100003)(5008740100001)(189998001)(4326007)(5004730100002)(50466002)(47776003)(66066001)(229853001)(50226001)(5001770100001)(3846002)(6116002)(1096002)(2950100001)(2201001)(586003); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR12MB0434; H:localhost.localdomain; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BLUPR12MB0434; 23:IyiVgP+pTeRQDFnxaBoCMhcRnlpYJIIgEBLIpNcvx?= =?us-ascii?Q?nE8sH/Ckj36mBQregKw1Xi6Gr3UIuVDtwZwOUUZpSnt9fDk0aAgUapyy0oNx?= =?us-ascii?Q?L683haj8zUD+EgUxs2sXYA7HVGRma2+Jmy5+XozOMBhE9YaicaptGy9w6w3O?= =?us-ascii?Q?9s4nilk5gACCQ+89/9iJ/DwAZB+MHU9QDVMj2R+h+yXobcMeNH47UwIWs6BL?= =?us-ascii?Q?8VdKiUPZca96uLtrpXwwDPRV5V8ya6IndfKvKhFnf0gvC51hzeflsOz5oty7?= =?us-ascii?Q?pXH4rXRI6Mri/Bh9egOiOCII+FmcYaEkFE3Do05QuM0FBtPx/6wwq60tSPxJ?= =?us-ascii?Q?e0qed4XIOJ9c6M6ByljblXXdn1ard+iLEWDOCJzixmKDLjUS5a/LxVUlaEu7?= =?us-ascii?Q?sqCkfbrJvAbI5z1arRPcHUCAhFVH9zjJ31YI4Adp1P9/Wlm6rOQOrrhgZbDs?= =?us-ascii?Q?hKPKdskpDFXdmlHLYkiPnx1PFC2GtukSVCVST7B8Kd1qq/Q4l/l7rsGmsm4F?= =?us-ascii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HOLjUaX45jhFyXwW5pODVj/9g9eefgPh/TR/THNoT5i0KJ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Feb 2016 22:54:26.7588 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR12MB0434 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. Reviewed-by: Joerg Roedel 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(-) -- 2.5.0 diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c index d44525e..2d59e20 100644 --- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c +++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c @@ -232,14 +232,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; @@ -450,6 +442,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; @@ -460,8 +457,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);