From patchwork Wed Oct 11 08:39:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liu, Jingqi" X-Patchwork-Id: 15205 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp388924vqb; Wed, 11 Oct 2023 01:45:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGrweXhGRNr96ThUZxhMWZl+1d5wivb8r5NRCDUIltQINE1CUlhPHO+4McSdYlKtud0cG/R X-Received: by 2002:a05:6808:6408:b0:3af:6453:2d83 with SMTP id fg8-20020a056808640800b003af64532d83mr19181809oib.2.1697013906099; Wed, 11 Oct 2023 01:45:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697013906; cv=none; d=google.com; s=arc-20160816; b=KDdMEZTzitbc7NUGKY8HZfs3DKAhhtouPwXcOdJYllD+Pwy+WHRQyL8YzQM7AnCEKz ClWq79swnkNZrrkIKUcyrGnOxyhuSrNr6KDOQp5eV/9GwPkd7Ml2Pmg6kaDKgQE8woHi EJ7N0mIxdcm8Qm7UPkvhCoxK3jI+jSg9x/uCGXSf/RrF1Yo6l1JH7VbDb+nBY4gL32j9 3SeIOru8gWRUJ+iQXn7wN/z/sWh1R3txOmORfvZzVtcHIvk6nbsiDfF+nDKOpoijpYKP BFr1nUdvqSCp1wa5P/4GnsyhrfdE01WR2mSlVW6yvpWx7jDS5Le9NtV3eyrlS0pxf5u6 +SUw== 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=Qd3wk0+/Sh9Kv6fqFgqxbWX8igPVkmWOjlYEVF3rZYI=; fh=ph/zG4YMOu55Ql52XuNa0mX2god/6U9yAdLjMXHBlck=; b=xk3uIhArQvKuffdSoVQM5hiQrhzxaUkAWuISSgBL1Bx3Str8wE2DgwDwQN68cccIu3 ITciBBXrQVrHkqQZd9xJH8iD9dQB/BD0cbVqRhqVY5HJewaAu6tHkUC+qUJenrPNCscj hBVeXRm5el49yC6zc2HbhkRsaBXqbIKqSGnzUCwef2Tj9qPg8rv/SZXKr1pUGNXQONTi CN2xVGiL1eFxiOLYCuw0ao/XebdkbrAt4/K0W/ABCgeIXogagz+HO6fd14hvlM16J9vo LNEn5A8nZp2uus9BQpM0dNUMv6e7wd61qjMb1rcUG3uP/G6xqKqMVpdsfXllgBGLMnkl 4XYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cCupjOCJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id o3-20020a655bc3000000b00584d3c4a775si14100041pgr.626.2023.10.11.01.45.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 01:45:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cCupjOCJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id D601381B6AA8; Wed, 11 Oct 2023 01:45:04 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345542AbjJKIov (ORCPT + 19 others); Wed, 11 Oct 2023 04:44:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345349AbjJKIot (ORCPT ); Wed, 11 Oct 2023 04:44:49 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49F4098 for ; Wed, 11 Oct 2023 01:44:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697013885; x=1728549885; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=FA+jyWK+BSN42cAZ+8JuVtQ0iB2leEc/ZRDAIJ0Y5OU=; b=cCupjOCJ/uIeMtSMNAwnSqBLmy3s00aSI+NPtF1Srks5QxjS7it5iHrr YRfKynLhK3tJx7UPoKOOE2yOa/BUzWQL3NzNZljAb5/NuoEU+nptHznpw ntN8h+eqTIpmhE9hZZpDT9T8dDq45ZxXAMNs5eYk1sJBqngI9X4QjI3G6 skVKOXw+qHwXtFCSfgMc0VBeQIh+wKLdzXIvY0OaupID4NpyPANuw6Khx hz2F24FOi98ft95dTz7nwgz7G0IomoOH5lSnSe11rUuVjQboechHOgDvJ XwpWmnWDQpOihY2BzR0g8er/k24ZeYDiG30pTy3XJ5WwvhmiYy59BQ7/Z w==; X-IronPort-AV: E=McAfee;i="6600,9927,10859"; a="383474559" X-IronPort-AV: E=Sophos;i="6.03,214,1694761200"; d="scan'208";a="383474559" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 01:44:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10859"; a="877587364" X-IronPort-AV: E=Sophos;i="6.03,214,1694761200"; d="scan'208";a="877587364" Received: from cascade.sh.intel.com ([10.239.48.35]) by orsmga004.jf.intel.com with ESMTP; 11 Oct 2023 01:44:42 -0700 From: Jingqi Liu To: iommu@lists.linux.dev, Lu Baolu , Tian Kevin , David Woodhouse , Joerg Roedel , Will Deacon , Robin Murphy Cc: linux-kernel@vger.kernel.org, Jingqi Liu Subject: [PATH v4 0/3] iommu/vt-d: debugfs: Enhancements to IOMMU debugfs Date: Wed, 11 Oct 2023 16:39:12 +0800 Message-Id: <20231011083915.36706-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,URIBL_BLOCKED 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 (snail.vger.email [0.0.0.0]); Wed, 11 Oct 2023 01:45:04 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779448053595316109 X-GMAIL-MSGID: 1779448053595316109 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 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/1/domain_translation_struct. For the default domain without pasid, it creates a debugfs file in the debugfs device directory for users to dump its page table. e.g. /sys/kernel/debug/iommu/intel/0000:00:02.0/domain_translation_struct. 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/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: v4: - Save the debugfs dentry in 'device_domain_info' and 'dev_pasid_info' structures to simplify debugfs operations per Baolu's review. - Use 'dev_pasid_info' to get the infomation of {device, pasid} pair when dumping the page table per Baolu's review. v3: https://lore.kernel.org/linux-iommu/20230927151536.67319-1-Jingqi.liu@intel.com - 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 | 300 ++++++++++++++++++++++++++++------ drivers/iommu/intel/iommu.c | 11 ++ drivers/iommu/intel/iommu.h | 18 ++ 3 files changed, 283 insertions(+), 46 deletions(-)