From patchwork Wed Sep 27 15:15:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liu, Jingqi" X-Patchwork-Id: 14610 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp2869492vqu; Wed, 27 Sep 2023 13:01:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHL0ZiK5RoADz28ULb46F4zc55SsePJ31+VpFr1gMQ+mmMqTtG49eP0k4Gekf3to1TmX9b7 X-Received: by 2002:a9d:7dd1:0:b0:6b9:a192:aaf3 with SMTP id k17-20020a9d7dd1000000b006b9a192aaf3mr3337545otn.17.1695844871671; Wed, 27 Sep 2023 13:01:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695844871; cv=none; d=google.com; s=arc-20160816; b=fXDkXOxnmlkhgGmb3hr5k5ahpS83c5WOC0N7IevY3UV4v44d2k46E93lstup4yct+F ATbFVomWpmm0GvRnPPkWKQqdc7eGAQBrv9h0KLU0bTTB4gS24X2vfxl+jPrKKAKqB2oY nDTsG4d9/wjqrjG/xJBnSzuqvFbE9a2/1JsE6FbO7UEfJt94wJrVsXx3n0JUE7rEFKFo UmK8/HnOp1jvVGNUWUmi/7QUUMtNpT1vOXLwoHn77f2paub34ImULQpOCLIth1DTnifz NveU9mX1FR5JHQHnOfv5/teTM/o9JP7EVgGMVjSfx9/fvVGgl4PDG/9W08kiHSUIh2q3 fNUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=MhsrBKoh0T0907NMaDxMZbZHPn2zj+zBm4/Oy5qccrE=; fh=XFDRxS7z/mPiLWcvDFNXxtez86tw5VSUEAZ1VPulNcQ=; b=LNZJFTDtNN0ifIYD5JbQSQPS2oZKK51hBX3t5FuUrF5iv2+4jHtGrjlwV4MtpVWLPA K8+yPlQ+s9PQqqY5oLXkPjyQCpXx8XVZEnBHrgWuS4mb+nkHxfXeg5DVQxkQrR8Sm16g wT1VMFzkjJYELrMuebN0IoQsQ9JgdNmuHzL1JIWHbK0pqRbK7G8Kq1n8T+xhVSaF0YMe BiJAY42aVlFKckMxzhNcxQlAw0/VI1BZurxDRYefUnWX9EYFWeiRBtB3O6KwreCmPMNy CTLBdzcxt1jyrHGcal80liLn/8x8x0kWBtGYxkRxE2rJCmpFUBP5gKyjoXsTDgB2kio6 +v1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hSOSzZST; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id n3-20020a6546c3000000b00578ca217736si16524374pgr.719.2023.09.27.13.01.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 13:01:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hSOSzZST; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id E68CB80A1A5D; Wed, 27 Sep 2023 08:19:22 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232398AbjI0PTS (ORCPT + 19 others); Wed, 27 Sep 2023 11:19:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232366AbjI0PTN (ORCPT ); Wed, 27 Sep 2023 11:19:13 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B74913A for ; Wed, 27 Sep 2023 08:19:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695827951; x=1727363951; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=FBQTjIZQirFkI7kJ7l4LKRUe9HyPMIJruBmDzzFQW5w=; b=hSOSzZSTXP+S/tSUyPDxbc0ViIqOansUyb1pONYXFSHCrrjEkwj6M7/L xwaU8fmxqdxvix5a8p/RNWS0aecpirMrtORXyaa6dby2gQuiNR9osHJCq J5U2hSDesmSg3yu+aclbZCvtURHj4DqiO3WIc5yhgaa5HWOQljhIVKtKK M6Gm/GJaoXuumNU6HCE9tj3IWViBzJ46rNadzLQLx/g9yt436ypmNmzV1 HeZMAP2lCS9oxWWdb4PF7PJkCwt/PPloGHtfh6LaEymX7/5XnL9LvxWzW aGwRr3htk2505P6axSM+1uHP+oikB97t8UsbDZYb3ore9/HjAocs7Hk/7 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10846"; a="362098897" X-IronPort-AV: E=Sophos;i="6.03,181,1694761200"; d="scan'208";a="362098897" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Sep 2023 08:19:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10846"; a="819461109" X-IronPort-AV: E=Sophos;i="6.03,181,1694761200"; d="scan'208";a="819461109" Received: from cascade.sh.intel.com ([10.239.48.35]) by fmsmga004.fm.intel.com with ESMTP; 27 Sep 2023 08:19:08 -0700 From: Jingqi Liu To: iommu@lists.linux.dev, Lu Baolu , Tian Kevin , Joerg Roedel , Will Deacon , Robin Murphy Cc: linux-kernel@vger.kernel.org, Jingqi Liu Subject: [PATH v3 0/3] iommu/vt-d: debugfs: Enhancements to IOMMU debugfs Date: Wed, 27 Sep 2023 23:15:33 +0800 Message-Id: <20230927151536.67319-1-Jingqi.liu@intel.com> X-Mailer: git-send-email 2.21.3 MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 27 Sep 2023 08:19:23 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778222232108594225 X-GMAIL-MSGID: 1778222232108594225 The original debugfs only dumps all IOMMU page tables without pasid supported. It traverses all devices on the pci bus, then dumps all page tables based on device domains. This traversal is from software perspective. This series dumps page tables whose mappings are created and destroyed by the iommu_map/unmap() interfaces, by traversing root tables, context tables, pasid directories and pasid tables from hardware perspective. It supports dumping a specified page table in legacy mode or scalable mode with or without a specified pasid. It adds a debugfs directory per pair of {device, pasid} when attaching device with or without pasid, i.e. /sys/kernel/debug/iommu/intel//. And create a debugfs file in the directory for users to dump the page table corresponding to {device, pasid}. e.g. /sys/kernel/debug/iommu/intel/0000:00:02.0/0/domain_translation_struct. Each device has a PASID#0, i.e. RID_PASID. Remove the corresponding debugfs directory and file when detaching or releasing a device. For legacy mode, according to bus number and DEVFN, traverse the root table and context table to get the pointer of page table in the context table entry, then dump the specified page table. For scalable mode, according to bus number, DEVFN and pasid, traverse the root table, context table, pasid directory and pasid table to get the pointer of page table in the pasid table entry, then dump the specified page table. Examples are as follows: 1) Dump the page table of device "0000:00:01.0" that only supports legacy mode. $ sudo cat /sys/kernel/debug/iommu/intel/0000:00:01.0/0/domain_translation_struct 2) Dump the page table of device "0000:00:02.0" with PASID "1" that supports scalable mode. $ sudo cat /sys/kernel/debug/iommu/intel/0000:00:0a.0/1/domain_translation_struct Change log: v3: - Add domain as a parameter for creating debugfs pasid directory per Baolu's review. - dput() the dentry after debugfs_lookup() per Baolu's review. - debugfs device and pasid directory are managed separately per Baolu's review. v2: https://lore.kernel.org/linux-iommu/20230922151636.77139-1-Jingqi.liu@intel.com - Add a debugfs directory per {dev, pasid} as suggested by Kevin. - Create the debugfs directory when attaching device as suggested by Baolu. - Only dump the page tables whose mappings are created and destroyed by the iommu_map/unmap() interfaces per Baolu's review. - Rename the helpers for creating/removing debugfs directory/file and merge patch 2,3,4,5 to one patch per Baolu's review. v1: https://lore.kernel.org/linux-iommu/20230625150442.42197-1-Jingqi.liu@intel.com Jingqi Liu (3): iommu/vt-d: debugfs: Dump entry pointing to huge page iommu/vt-d: debugfs: Create/remove debugfs file per {device, pasid} iommu/vt-d: debugfs: Support dumping a specified page table drivers/iommu/intel/debugfs.c | 307 ++++++++++++++++++++++++++++------ drivers/iommu/intel/iommu.c | 29 ++++ drivers/iommu/intel/iommu.h | 12 ++ 3 files changed, 298 insertions(+), 50 deletions(-)