Received: by 10.223.176.46 with SMTP id f43csp1303716wra; Fri, 26 Jan 2018 15:53:14 -0800 (PST) X-Google-Smtp-Source: AH8x225jiv/1E564XbS+sGV4Kk+LlwTtV9vkJ7yjeSlUPzSc7yxamjskXsx50Myxk3zUAZglTAI2 X-Received: by 2002:a17:902:9a04:: with SMTP id v4-v6mr15222422plp.252.1517010793995; Fri, 26 Jan 2018 15:53:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517010793; cv=none; d=google.com; s=arc-20160816; b=wYUSPqPzbk1uuX17lH1OmgzWo63mGUIPPRaV70lHjjbQAq/YBpRf9RigxOqfp354t4 vE4EnPkf0VQDIefXjGrN0kbNcNp8Z8MdGXJGJBfHJ8ZT44nPCVci/7FSw9kEjEgi0PS0 IanYqag6SGrK5+SYpXaqe4MyX5lSmHN8b51LWc/mnjlIcgOeWKNd8F2M3DPyjFK9VU90 8prI8BQgBN5jxCuWs5zWMFxHMljamaO3ZORp06Koelu7QNqovcZuKuGiI9OBN0zAbBgg J22NiXksbwTUJUN/5K5kkUwiSIwGeqY/HPgGfpESTlavflXc/qpNhh7+iP3QOgqcdWdT gXHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:dkim-signature:arc-authentication-results; bh=p5/m904XTT6P45DAsjuypx+AmuBVYgtqPlVs+g+aX9o=; b=HgwYjE7Pq+DeDZR7aDh3RsLPDLbO4SieWOSbkH5/BwTD5s1bNOHlSdt5mxJeG8XYXB o2NNGeTxTknay/6ktyBhaksUPjkmSi/Ms515T3F8SoTsJKh5PIyhY72+idPDmHrQ1dv5 +5Elsgk3WcBcgNWSo/9BTmIyJCEfkpYnnttYg4YeEzN0RE4RoaSO37W9diKu/q+VXdKC H3rMcqFyBzC51C32+RBhilxj3rPt8dkbiwC9i+tSqv80Yb1BRFvQcBrVrZSAmH6xHg0p 5mzdjK+ZvH8EYVM20dmDZ+1QhQmUuo10YsPICgn4Bh/8C7I68eObCpRZZdHm3HJ7aFyO zqRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector1-amd-com header.b=BFiHGZE3; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bb5-v6si1794075plb.93.2018.01.26.15.52.59; Fri, 26 Jan 2018 15:53:13 -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; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector1-amd-com header.b=BFiHGZE3; 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 S1752503AbeAZXw0 (ORCPT + 99 others); Fri, 26 Jan 2018 18:52:26 -0500 Received: from mail-dm3nam03on0042.outbound.protection.outlook.com ([104.47.41.42]:40576 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752391AbeAZXwX (ORCPT ); Fri, 26 Jan 2018 18:52:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=p5/m904XTT6P45DAsjuypx+AmuBVYgtqPlVs+g+aX9o=; b=BFiHGZE31Lo1vmxOeT4yp6JBfS/P+p4AYllvWXK/h9ZEOyaOEAzsCSTwNgOkxw9c0GZOpr6zxTupIpb0xrF8m+TL2kHEKQ2ncSQ5BB3M0a394RHbFzMRYJcNJ9HdHo1WAWWzEKrU2AErc32saYdKpkAznvXvAI3DlKeWwQivnC4= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Gary.Hook@amd.com; Received: from [127.0.1.1] (165.204.78.1) by CY4PR12MB1207.namprd12.prod.outlook.com (10.168.166.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.444.14; Fri, 26 Jan 2018 23:52:20 +0000 Subject: [PATCH 1/5] iommu/amd - Add debugfs support From: Gary R Hook To: iommu@lists.linux-foundation.org Cc: joro@8bytes.org, linux-kernel@vger.kernel.org Date: Fri, 26 Jan 2018 17:52:15 -0600 Message-ID: <151701073560.16448.7715293076458740364.stgit@taos> In-Reply-To: <151701071164.16448.3611271062222336838.stgit@taos> References: <151701071164.16448.3611271062222336838.stgit@taos> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: BL0PR1501CA0025.namprd15.prod.outlook.com (52.132.16.38) To CY4PR12MB1207.namprd12.prod.outlook.com (10.168.166.22) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 619adebb-8352-4aae-ff56-08d56517d6e4 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(5600026)(4604075)(2017052603307)(7153060)(7193020);SRVR:CY4PR12MB1207; X-Microsoft-Exchange-Diagnostics: 1;CY4PR12MB1207;3:x4KrkgBq8+Ow1Y8mwey0QccaIXC6ZH7OI2iTCF1C0Eo0bTRVANLnt4Ysjp5odoXLpc3ebKTuGevUbia/NxXvHrGsFXWXjPQbU1yhsIr66uhb3yTKN/F7AF9A+PORXpWv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zimA/bgvYT2IUQLeXX0V/FuMYgFo3vDzaVC4eo99poKSU/5ANHya71NmUWixIrxBrxYRHxt86UiteBQjDuOPm/jz9K3mBUN3iVS7gvwhWinKphL6qI20IVf34lOu+/4Nl2PWBJZqoem+o0xkUmZe2m9RCEzjXsm0w14E925nMEMicGIYaVbdRPnx1mr0eLJ12E26hAO3QZFqfl0Y/R+BPWPkc;4:T7w6rIXFUecWMPM4M9+vNvdm3PX1SAH2YqUy8rgOUnWBNmG/9lanHMQe5fBtYKDz7syABfs7xg6IeI2HMlFw8e2v4zyj9/rpqoiGMv8Rsa6V0uQ/vp7fgORyxiLDOqYHtub2yriq47xfTNoxdkiCJBLSYw6pJKyFqQSZK5k0o9x+TkPK9yGUQqpof0XbhrDSWJIhqNyf39La3YPLWdwlnTCX2b3Va2yt3VQcmJa2hLjfBwTuhbmhuxLEwEAbDFiNG8e0GMkCH+Mcqiei3XkHMq5bVoqgtEtMqZrGe0wns8M5JJxfCOGWUJFlewuG2Q2X X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040501)(2401047)(5005006)(8121501046)(3231078)(2400081)(944501161)(3002001)(10201501046)(93006095)(93001095)(6055026)(6041288)(20161123560045)(20161123564045)(20161123562045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:CY4PR12MB1207;BCL:0;PCL:0;RULEID:;SRVR:CY4PR12MB1207; X-Forefront-PRVS: 05641FD966 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6049001)(7916004)(396003)(39380400002)(376002)(39860400002)(366004)(346002)(189003)(199004)(6666003)(2950100002)(5660300001)(7736002)(103116003)(186003)(6916009)(52116002)(2486003)(8676002)(33896004)(77096007)(23676004)(83506002)(386003)(33716001)(16526019)(59450400001)(76176011)(58126008)(6486002)(9686003)(81156014)(90366009)(81166006)(230700001)(8936002)(53936002)(16576012)(25786009)(316002)(478600001)(68736007)(575784001)(66066001)(86362001)(50466002)(97736004)(4326008)(305945005)(3846002)(6116002)(106356001)(72206003)(26005)(2906002)(2361001)(47776003)(105586002)(2351001);DIR:OUT;SFP:1101;SCL:1;SRVR:CY4PR12MB1207;H:[127.0.1.1];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: =?utf-8?B?MTtDWTRQUjEyTUIxMjA3OzIzOnhyenJMTDh1WWJWOFNtREl6ZnowZWxDUWp6?= =?utf-8?B?WFo4VER5MWowRy8zSVR1a0QwVkdRb3JsNGlVZVg5OElyM1JkaFJHTEFtNzg0?= =?utf-8?B?YUpUdjRic242RTZjSk1qNDQyRTlkS2tuQUpkeGVPcmpWWm5EbUQ5NmFsYlZH?= =?utf-8?B?dko3NnpPK0ZSQTZUTGp5OVBld1E4QUxkN2hpTTFpMEFCUTBHcVQzSW9NOFhk?= =?utf-8?B?KzVRZjlrSWxuckpaLzJibXhFWWtnNmwrZ2JNZE0weTJlb1RYdlV0Z2Y1Y3d3?= =?utf-8?B?aE94RGNtN2cvSHRUV0RjeEtSaXpSY3k5RFkwZUNDbm5VMElib1Z1VFNqZFh6?= =?utf-8?B?bnZhWnhlVmhpWGMvcUdJVUdDNWN5Ykl4a2JlblRTMlRkV0RYLzZwRDhIVEIy?= =?utf-8?B?WUQ4d3liYzFuZ1grNUtEVDR0aUJzMzExS3NWbjROcmszWS9ZWTl1TVptczIv?= =?utf-8?B?WVQ0Yy9QQ0xlYzlNQjArR20yemFXeUo1R0N4b1FGR2QrU1BEM0NXVzB0TytB?= =?utf-8?B?RUVZaGxMS1N4MW9qVStiOERwZUNrTER6WVRRb0I0V0RKcnZlUlBmMDVIbmFW?= =?utf-8?B?RFBmWVc0MlVpRG42MC8xT2F5WGM2T1IwL1lvMFNIQTRkdUJXdmk3T2dwK3Fn?= =?ut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fliHuwAxM9PllzmdlQa7FhqpKJF7pQjTEvSeHkfr2Cm7TXzY5Kc+y6EtFNIOBva1O/vqAl6TOz3KG1GVufiMq9f1aEjJfAD8yIUC9KL5m+BDMgR3g3mo1HyMIQ8RGnMjrf+yPO+B2dn1EXIh+myPP4AO09oE2H3Lze/LxaspWQjIUR43tJZdRqa6LSn+g6FKMvdgV+6wcY+SZz2fV35ci6M5OpDN709+2zp0vkr2B22Z SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;CY4PR12MB1207;20:XGwPczfJwH67EwkvWIL/4uH1nFw/FYVJYOWFZ/Rm3ulnqZgiM8sqytldznv21naw8gR9cWO2CsU29oa+Q9DdG+Wt1kgxQ+ZkHBOptYnz9TGE4qrwz2NBPDxqJuMPs77dfltZLblKwsw4pOS3bnkdGsiVI6Gnr/CDh6h/d8oG2W2S/V5qZhSXOU/guwlZxPUL70blhmArn7ThINo3QJ2n8ORt5rYSIylSEx5enbFxln/lxZP88uJLK6h87Osgtxx9 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2018 23:52:20.0059 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 619adebb-8352-4aae-ff56-08d56517d6e4 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1207 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Create the basic debugfs functions. Expose a count of IOMMU device table entries that appear to be in use. Signed-off-by: Gary R Hook --- drivers/iommu/Kconfig | 9 +++ drivers/iommu/Makefile | 2 - drivers/iommu/amd_iommu_debugfs.c | 112 +++++++++++++++++++++++++++++++++++++ drivers/iommu/amd_iommu_init.c | 7 ++ drivers/iommu/amd_iommu_proto.h | 6 ++ drivers/iommu/amd_iommu_types.h | 3 + 6 files changed, 136 insertions(+), 3 deletions(-) create mode 100644 drivers/iommu/amd_iommu_debugfs.c diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig index f3a21343e636..7753989b6be7 100644 --- a/drivers/iommu/Kconfig +++ b/drivers/iommu/Kconfig @@ -135,6 +135,15 @@ config AMD_IOMMU_V2 hardware. Select this option if you want to use devices that support the PCI PRI and PASID interface. +config AMD_IOMMU_DEBUG + bool "Expose AMD IOMMU internals in DebugFS" + depends on AMD_IOMMU && DEBUG_FS + default n + help + With this option you can enable access to AMD IOMMU registers and + data structures through debugfs. Select this to see information + about the internal state of the device. + # Intel IOMMU support config DMAR_TABLE bool diff --git a/drivers/iommu/Makefile b/drivers/iommu/Makefile index 1fb695854809..d9e9ed5f6cfc 100644 --- a/drivers/iommu/Makefile +++ b/drivers/iommu/Makefile @@ -9,7 +9,7 @@ obj-$(CONFIG_IOMMU_IO_PGTABLE_LPAE) += io-pgtable-arm.o obj-$(CONFIG_IOMMU_IOVA) += iova.o obj-$(CONFIG_OF_IOMMU) += of_iommu.o obj-$(CONFIG_MSM_IOMMU) += msm_iommu.o -obj-$(CONFIG_AMD_IOMMU) += amd_iommu.o amd_iommu_init.o +obj-$(CONFIG_AMD_IOMMU) += amd_iommu.o amd_iommu_init.o amd_iommu_debugfs.o obj-$(CONFIG_AMD_IOMMU_V2) += amd_iommu_v2.o obj-$(CONFIG_ARM_SMMU) += arm-smmu.o obj-$(CONFIG_ARM_SMMU_V3) += arm-smmu-v3.o diff --git a/drivers/iommu/amd_iommu_debugfs.c b/drivers/iommu/amd_iommu_debugfs.c new file mode 100644 index 000000000000..18f70934961d --- /dev/null +++ b/drivers/iommu/amd_iommu_debugfs.c @@ -0,0 +1,112 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * AMD IOMMU driver + * + * Copyright (C) 2018 Advanced Micro Devices, Inc. + * + * Author: Gary R Hook + */ + +#ifdef CONFIG_DEBUG_FS + +#include +#include +#include +#include "amd_iommu_proto.h" +#include "amd_iommu_types.h" + +/* DebugFS helpers */ +#define OBUFP (obuf + oboff) +#define OBUFLEN obuflen +#define OBUFSPC (OBUFLEN - oboff) +#define OSCNPRINTF(fmt, ...) \ + scnprintf(OBUFP, OBUFSPC, fmt, ## __VA_ARGS__) + +static struct dentry *iommu_debugfs_dir; +static DEFINE_RWLOCK(iommu_debugfs_lock); + +#define MAX_NAME_LEN 20 + +static unsigned int amd_iommu_count_valid_dtes(int start, int end) +{ + unsigned int n = 0; + int i; + + /* Scan the DTE table from entry 'start' through entry 'end' for + * active entries + */ + for (i = start ; i <= end ; i++) + if ((amd_iommu_dev_table[i].data[0] ^ 0x3) + || amd_iommu_dev_table[i].data[1]) + n++; + return n; +} + +static ssize_t amd_iommu_debugfs_dtecount_read(struct file *filp, + char __user *ubuf, + size_t count, loff_t *offp) +{ + struct amd_iommu *iommu = filp->private_data; + unsigned int obuflen = 512; + unsigned int oboff = 0; + unsigned int n; + ssize_t ret; + char *obuf; + + if (!iommu) + return 0; + + obuf = kmalloc(OBUFLEN, GFP_KERNEL); + if (!obuf) + return -ENOMEM; + + n = amd_iommu_count_valid_dtes(0, 0xFFFF); + oboff += OSCNPRINTF("%d\n", n); + + ret = simple_read_from_buffer(ubuf, count, offp, obuf, oboff); + kfree(obuf); + + return ret; +} + +static const struct file_operations amd_iommu_debugfs_dtecount_ops = { + .owner = THIS_MODULE, + .open = simple_open, + .read = amd_iommu_debugfs_dtecount_read, + .write = NULL, +}; + +void amd_iommu_debugfs_setup(struct amd_iommu *iommu) +{ + char name[MAX_NAME_LEN + 1]; + struct dentry *d_dte; + unsigned long flags; + + if (!debugfs_initialized()) + return; + + write_lock_irqsave(&iommu_debugfs_lock, flags); + if (!iommu_debugfs_dir) + iommu_debugfs_dir = debugfs_create_dir("amd-iommu", NULL); + write_unlock_irqrestore(&iommu_debugfs_lock, flags); + if (!iommu_debugfs_dir) + goto err; + + snprintf(name, MAX_NAME_LEN, "iommu%02d", iommu->index); + iommu->debugfs_instance = debugfs_create_dir(name, iommu_debugfs_dir); + if (!iommu->debugfs_instance) + goto err; + + d_dte = debugfs_create_file("count", 0400, + iommu->debugfs_instance, iommu, + &amd_iommu_debugfs_dtecount_ops); + if (!d_dte) + goto err; + + return; + +err: + debugfs_remove_recursive(iommu->debugfs_instance); +} + +#endif diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c index 6fe2d0346073..43856c7f4ea1 100644 --- a/drivers/iommu/amd_iommu_init.c +++ b/drivers/iommu/amd_iommu_init.c @@ -89,6 +89,7 @@ #define ACPI_DEVFLAG_ATSDIS 0x10000000 #define LOOP_TIMEOUT 100000 + /* * ACPI table definitions * @@ -2720,6 +2721,7 @@ int __init amd_iommu_enable_faulting(void) */ static int __init amd_iommu_init(void) { + struct amd_iommu *iommu; int ret; ret = iommu_go_to_state(IOMMU_INITIALIZED); @@ -2729,14 +2731,15 @@ static int __init amd_iommu_init(void) disable_iommus(); free_iommu_resources(); } else { - struct amd_iommu *iommu; - uninit_device_table_dma(); for_each_iommu(iommu) iommu_flush_all_caches(iommu); } } + for_each_iommu(iommu) + amd_iommu_debugfs_setup(iommu); + return ret; } diff --git a/drivers/iommu/amd_iommu_proto.h b/drivers/iommu/amd_iommu_proto.h index 640c286a0ab9..f2a978dbcff7 100644 --- a/drivers/iommu/amd_iommu_proto.h +++ b/drivers/iommu/amd_iommu_proto.h @@ -33,6 +33,12 @@ extern void amd_iommu_uninit_devices(void); extern void amd_iommu_init_notifier(void); extern int amd_iommu_init_api(void); +#ifdef CONFIG_DEBUG_FS +extern void amd_iommu_debugfs_setup(struct amd_iommu *iommu); +#else +static inline void amd_iommu_debugfs_setup(struct amd_iommu *iommu) {} +#endif + /* Needed for interrupt remapping */ extern int amd_iommu_prepare(void); extern int amd_iommu_enable(void); diff --git a/drivers/iommu/amd_iommu_types.h b/drivers/iommu/amd_iommu_types.h index 6a877ebd058b..43c008dc7ade 100644 --- a/drivers/iommu/amd_iommu_types.h +++ b/drivers/iommu/amd_iommu_types.h @@ -593,6 +593,9 @@ struct amd_iommu { u32 flags; volatile u64 __aligned(8) cmd_sem; + + /* DebugFS Info */ + struct dentry *debugfs_instance; }; static inline struct amd_iommu *dev_to_amd_iommu(struct device *dev)