Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934389AbeAJRCT (ORCPT + 1 other); Wed, 10 Jan 2018 12:02:19 -0500 Received: from mail-by2nam01on0059.outbound.protection.outlook.com ([104.47.34.59]:35872 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933668AbeAJRCQ (ORCPT ); Wed, 10 Jan 2018 12:02:16 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Gary.Hook@amd.com; Subject: Re: [PATCH v6 2/5] iommu/vt-d: Add debugfs support to show context internals To: Sohil Mehta , Joerg Roedel , Alex Williamson Cc: Ravi V Shankar , Fenghua Yu , linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, Andy Shevchenko , David Woodhouse , Gayatri Kammela References: <1515556102-34150-1-git-send-email-sohil.mehta@intel.com> <1515556102-34150-3-git-send-email-sohil.mehta@intel.com> From: Gary R Hook Message-ID: <042eb604-9ff6-1e50-2027-801cf8e59a33@amd.com> Date: Wed, 10 Jan 2018 11:02:08 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <1515556102-34150-3-git-send-email-sohil.mehta@intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: MWHPR10CA0051.namprd10.prod.outlook.com (10.169.238.13) To DM5PR12MB1210.namprd12.prod.outlook.com (10.168.237.13) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 2734f85c-febb-4065-bb9e-08d5584be5a2 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(48565401081)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060)(7193020);SRVR:DM5PR12MB1210; X-Microsoft-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YvfVEAee1IQarTc47sSuWoV3/GJrCCFkSMh/PLGx0pK63y6bEjc96N0Roc45g2MOPDwBppK2seOgFHGHX3S3zwIVylwfUeZtCYTXm6swEFoUBLZEFEwMIg6dGBKsqRzyhBhWv4jVzL340gJ1x65aB+4iL51hY2CekEC/R07pMerY0x9htA0XthxNsPSlSZVDG5eMxa1cVW5uK95FHNmHjS1eSmTfA8nT4+UvnJ7kxg5VqtXQz6Nh3GyZiVQhiryNwV+rht3exc4sDV50+xydstYeSCArwvoEdWBs11KNos+I+8OwR6eNt4I1KViZ3pjfJHdCdlSZAMVdsNxelZy6P1hunE6UsXYVdz4/y1ZINQSWzwvwSiCDLHl6F;4:zbZ0gCcIvJ7ToAVuZi3/q9ce6IOP+79gOoRffMq/gJnyI76koK639ldKLx/1WD2bdh3prLhQfC/bOmIm/feTeODgkHgy+A8kT6NNdiSPrfdm1hMXQr59hxbd7GjXjEYCDF0pJSNlDH35zRfH4CkFntqn9U41f6pgEH1bc2V0+e6cGvsr0EZv8nMwL9A9jv8j45rypgpwXR9UPXuzl8/1bLpCfV96EuI7kWO+HlcYWQG3PbLkS+f2sGUnTxKzpLUr1LvKstXvA7yzd0GKjNbkHgZE9cNxFa9nAPzFoB0SJdjTUzyPX6mcy7BO/bCGwX/O23F+swzyGkHSimnrwr72mw== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(211171220733660)(228905959029699); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040470)(2401047)(5005006)(8121501046)(10201501046)(3231023)(944501075)(93006095)(93001095)(3002001)(6055026)(6041268)(20161123562045)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(6072148)(201708071742011);SRVR:DM5PR12MB1210;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:DM5PR12MB1210; X-Forefront-PRVS: 0548586081 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6049001)(366004)(39380400002)(39860400002)(346002)(396003)(376002)(24454002)(189003)(199004)(4326008)(6246003)(97736004)(8936002)(5660300001)(2950100002)(81166006)(305945005)(53936002)(65826007)(7416002)(7736002)(6666003)(81156014)(6116002)(3846002)(68736007)(105586002)(64126003)(8676002)(106356001)(50466002)(25786009)(2906002)(110136005)(31686004)(53546011)(59450400001)(478600001)(72206003)(386003)(575784001)(31696002)(16576012)(316002)(58126008)(52116002)(2486003)(52146003)(76176011)(36756003)(23676004)(65956001)(86362001)(2870700001)(90366009)(47776003)(229853002)(66066001)(16526018)(6486002)(77096006)(67846002)(83506002)(54906003)(65806001);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR12MB1210;H:[10.236.109.62];FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtETTVQUjEyTUIxMjEwOzIzOmdvbFVrNzRsNnlZNnhBa0IzRnp0YUpYcTZG?= =?utf-8?B?S2F4UlYyNzZYV2dCQmJLWk4wOGtGNWFPQ0xOK3M4M0h4Q2dPdFdlMFoxUVUv?= =?utf-8?B?TWNJNWFIQ3Ixd0hCeFNKMjBZVGlVTjFjTWNkWVpBYys5dlJkSkFTWXZPbjZk?= =?utf-8?B?ZGdKZFFOODNKN00xeUdKTHhLVUZxMW9vQm0wUTBHR1p0Nkt5QnJkR2ZGK2NU?= =?utf-8?B?TVpGanZ0NDFNc0ZGQlM5TzhnK3JEdGVFS1dmV2RkZlFtQzRsSEQzMEJRTGsr?= =?utf-8?B?NmpkODlaM3E5eUtWVmhWeEZuNkEzenVHMlhhcEZBSmlVTjRIYkdRaEVWSkV0?= =?utf-8?B?eXk2bEdvSVVaOGk4UnJmbFY5alo3SDRLYStyYnlDS296OVZhaVd0cnFRS1Ni?= =?utf-8?B?NGRuNXhyQm1DRTZtSGQwQ0xhOXZOUTZhb3ZOWlVsOWpQRllrUGxad2lLeHpL?= =?utf-8?B?bm5ObXhodnpPUzlTUjF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/sUfugVoo9qzd0/Ro6DQ/aGWVZ2nGNdqw354LfbBzhyTxkELMiGYkgnctp9n4mr2u1mj+RdmmW8qHVviRTIwpodVeIMmqrFdt+cgl+15Vdpd26XmezkM5xG2/2kQwOcZRLErb+X9N8=;5:4SYHNOI9AlmwDTFZ3JPJqbN86edLmaUHwzERvZaqTeHXp9TwF1lyW3zzs88yGn3MyfzlcaPveQf/UlEgZcvJGJ6YYu6obqLzDd3/NrbDrC/URPisDx3VsKJDKuxzudKD5awmJn0uuQ+qY69OKUNDvneydL25RdTqlk/3w46KirU=;24:dnNBsN0wER7AMqVXwS0F3EJt4BWiNq0MIKRMFghkpuI4OjGfMX2lJwTgsD3SznepFZGs98bQ/uW9Y6hecjlqWaJxRaVFKkMYCwKwnEUVf1s=;7:yMWBXydexoxmg4OBxTXz6/mZMS8nGLXFrtRWcNnaiS72kHh/xonogN8sw2wQuxbNP0bxfuoe+xpe+xLMmysdCXucecnTxfTXCT1Xswsfx3UerS+eTxfrvxnBLut+bKmSnp6gFhtXvdplWaVMR6x9ovAxqJbz4Mfw0aEv1Ixzjb3Gcn+XVlj86GNGbE3u9h2+qjuIahpuJ/OpS8+Srgc1YzZ3qyvasgde5Tu64di1AjZYuFawCK7gFTvwb4TCkBce SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DM5PR12MB1210;20:h+ZmGc3RG13of4UPLC8O3me2SEGWyXS6W5OjvEynUYEAadV7qJEBtHBa+wjpHVSuxc4hy79LEVycthSClEP0oLYHsPhVa6CAcwJ6VKMm6Us7aBzeSBGBuZnaZza2DXbjC6eWCx+xGJ2pGMbilbQbuTFiBDxhSmk+4BpetoV+4pLwKkPgJimtjqMgiiyWee12I54ZAntu4ViypU+UQvlCe7VWWP82uoR+g1aqPGHhCqC7x2nI7lNJ4JdQNT4Tn7SH X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jan 2018 17:02:12.5606 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2734f85c-febb-4065-bb9e-08d5584be5a2 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1210 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: On 01/09/2018 09:48 PM, Sohil Mehta wrote: > From: Gayatri Kammela > > IOMMU internals states such as root and context can be exported to the > userspace. > > Example of such dump in Kabylake: > > root@OTC-KBLH-01:~# cat > /sys/kernel/debug/intel_iommu/dmar_translation_struct > > IOMMU dmar0: Extended Root Table Addr:402b9e800 > Extended Root table entries: > Bus 0 L: 402150001 H: 0 > Lower Context table entries for Bus: 0 > [entry] DID :B :D .F Low High > [80] 0000:00:0a.00 40214fa05 102 > Higher Context table entries for Bus: 0 > [80] 0000:00:0a.00 40260000c 0 > > IOMMU dmar1: Root Table Addr:4558a3000 > Root tbl entries: > Bus 0 L: 4558aa001 H: 0 > Context table entries for Bus: 0 > [entry] DID :B :D .F Low High > [160] 0000:00:14.00 4558a9001 102 > [184] 0000:00:17.00 400eac001 302 > [248] 0000:00:1f.00 4558af001 202 > [251] 0000:00:1f.03 40070e001 502 > [254] 0000:00:1f.06 4467c9001 602 > Root tbl entries: > Bus 1 L: 3fc8c2001 H: 0 > Context table entries for Bus: 1 > [entry] DID :B :D .F Low High > [0] 0000:01:00.00 3fc8c3001 402 > > Cc: Sohil Mehta > Cc: Fenghua Yu > Cc: Ashok Raj > Signed-off-by: Jacob Pan > Signed-off-by: Gayatri Kammela > --- > > v6: Change the order of includes to an alphabetical order > Change seq_printf formatting > > v5: Change to a SPDX license tag > Fix seq_printf formatting > > v4: Remove the unused function parameter > Fix checkpatch.pl warnings > Remove error reporting for debugfs_create_file function > Fix unnecessary reprogramming of the context entries > Simplify and merge the show context and extended context patch into one > Remove redundant IOMMU null check under for_each_active_iommu > > v3: Add a macro for seq file operations > Change the intel_iommu_ctx file name to dmar_translation_struct > > v2: No change > > drivers/iommu/Makefile | 1 + > drivers/iommu/intel-iommu-debug.c | 139 ++++++++++++++++++++++++++++++++++++++ > drivers/iommu/intel-iommu.c | 4 ++ > 3 files changed, 144 insertions(+) > create mode 100644 drivers/iommu/intel-iommu-debug.c > > diff --git a/drivers/iommu/Makefile b/drivers/iommu/Makefile > index 1fb6958..fdbaf46 100644 > --- a/drivers/iommu/Makefile > +++ b/drivers/iommu/Makefile > @@ -15,6 +15,7 @@ obj-$(CONFIG_ARM_SMMU) += arm-smmu.o > obj-$(CONFIG_ARM_SMMU_V3) += arm-smmu-v3.o > obj-$(CONFIG_DMAR_TABLE) += dmar.o > obj-$(CONFIG_INTEL_IOMMU) += intel-iommu.o > +obj-$(CONFIG_INTEL_IOMMU_DEBUG) += intel-iommu-debug.o > obj-$(CONFIG_INTEL_IOMMU_SVM) += intel-svm.o > obj-$(CONFIG_IPMMU_VMSA) += ipmmu-vmsa.o > obj-$(CONFIG_IRQ_REMAP) += intel_irq_remapping.o irq_remapping.o > diff --git a/drivers/iommu/intel-iommu-debug.c b/drivers/iommu/intel-iommu-debug.c > new file mode 100644 > index 0000000..d5b0eea > --- /dev/null > +++ b/drivers/iommu/intel-iommu-debug.c > @@ -0,0 +1,139 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Copyright © 2017 Intel Corporation. > + * > + * Authors: Gayatri Kammela > + * Jacob Pan > + * > + */ > + > +#define pr_fmt(fmt) "INTEL_IOMMU: " fmt > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include "irq_remapping.h" > + > +#define TOTAL_BUS_NR (256) /* full bus range 256 */ > +#define DEFINE_SHOW_ATTRIBUTE(__name) \ > +static int __name ## _open(struct inode *inode, struct file *file) \ > +{ \ > + return single_open(file, __name ## _show, inode->i_private); \ > +} \ > +static const struct file_operations __name ## _fops = \ > +{ \ > + .open = __name ## _open, \ > + .read = seq_read, \ > + .llseek = seq_lseek, \ > + .release = single_release, \ > + .owner = THIS_MODULE, \ > +} > + > +static void ctx_tbl_entry_show(struct seq_file *m, struct intel_iommu *iommu, > + int bus, bool ext, bool new_ext) > +{ > + struct context_entry *context; > + int ctx; > + unsigned long flags; > + > + seq_printf(m, "%s Context table entries for Bus: %d\n", > + ext ? "Lower" : "", bus); > + seq_puts(m, "[entry]\tDID :B :D .F\tLow\t\tHigh\n"); > + > + spin_lock_irqsave(&iommu->lock, flags); > + > + /* Publish either context entries or extended contenxt entries */ ^^^^^^^^ typo