From patchwork Mon Oct 16 03:28:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 153160 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3215111vqb; Sun, 15 Oct 2023 20:32:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEYd215ctAuXxIJ6x6m3qXk3lTW+go3nd1HKnZGOjZsM0kRj6LMwbE1k0U/cobdSXWt8X5p X-Received: by 2002:a05:6a00:3916:b0:68e:2fd4:288a with SMTP id fh22-20020a056a00391600b0068e2fd4288amr37353682pfb.3.1697427150004; Sun, 15 Oct 2023 20:32:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697427149; cv=none; d=google.com; s=arc-20160816; b=LmcjVRYOw6lgIjqqAJPqaMkaAE5X47PeIE8CFIiBkjDq3QMpT3jbd5wMUxfowljMVg 91D8IwBcfxnTq2PXR29l8RsrEhWKN+RbX9DxJf4calWVvEHu/td8AUbQ9z3Tjhc80kIv 7uFGW5Wr9C4/7i04XHoB3J+N9I5qdJDq2Ho8IuD30ykp9w/t5KMkZvj2wkztyW+SZi56 Ek7P7L42dYmcD4Pms1ouh3vK/4hXEXq7eaiMcxiZ5lnwRwdhqVuyWY8X9TFowFjhE+Z5 +lO8qx+m+acRc7Rq/nezAYI8i2HjQUf9xdkx36crCliSl6X9xIoZlLFc0HCc39NseWO1 NQTA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=KlOYdQwHTvqLSJaiLlmIFSOCxEnkby7KYc2G/VycQ0M=; fh=+U1mz0Qo6S03r4tUB6unzur/vi2NL5Ihgqvce3o6AxQ=; b=nIRvPwuCkh57B/W/pGYGf18XHZUsxtxqx4aiIWuom/F7/SWbnbWFg517POqW++vw95 snjL5+27jz4hzwOZ1hpl4pHHQw3I7Thn5OXeiOAYLcBw7AKX8MEuRFwe7dDr7pAaQeU7 WjdrfPlu4rJ7ahDVPvWVKGF2o5M4uDsb77Th24CIq3RuFvysRB38+g8GEsHFRt4INYe/ NQPkflWulIFMk+/DFDxWxBrQpd/Us9E6QUUkgRz7mYZP1dH7eUXChi8FlmuqnqXC9Dfr o4vPe8xCY+UN5QW5WbvrS++m5P7JD3YTJIvPvabxK4qDSxDKUaQyInpMVi31xOQfkmLa stkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=JhawLF0S; 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 g4-20020a056a001a0400b006be03d801basi2051876pfv.331.2023.10.15.20.32.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 20:32:29 -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=JhawLF0S; 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 31401804C565; Sun, 15 Oct 2023 20:32:28 -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 S230478AbjJPDcT (ORCPT + 18 others); Sun, 15 Oct 2023 23:32:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231501AbjJPDcM (ORCPT ); Sun, 15 Oct 2023 23:32:12 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71CECD9 for ; Sun, 15 Oct 2023 20:32: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=1697427131; x=1728963131; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7iMKDRCvqp9vX9k3vsWvlopQYAJfIXTN0uAtyli9Xik=; b=JhawLF0SP9+PKOKUSLP3xoFATIesC9VDB7eqYc6GqKsJVrYROPLIz7BE 5Wredt/EtmZcWkkjvN4y+BoGOed9iFxKNfCCA+MW+36XQ22a+lqWK2NUp rxK6/2DMLm7RImYgVicaHQ/OD74+CupbW6kkQczgNhHtlSVTsZ6UmGsrE Fga+jSBwaNEsvrDuyJrwGbo/KLi1BCEhSX84gNj12F7UVoF0cVpl8ooBC OzJDIrMGSkuGvSMOPxMT+3A0GMLoWPdYrhJg/p003iYshgDj6O1ZdkyAo rid02wj9xeLFVcIJYszViB94EDbeu9qQz7/ewjAjid3Rf5nGM227f39Lp w==; X-IronPort-AV: E=McAfee;i="6600,9927,10863"; a="365701124" X-IronPort-AV: E=Sophos;i="6.03,228,1694761200"; d="scan'208";a="365701124" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Oct 2023 20:32:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10863"; a="705444251" X-IronPort-AV: E=Sophos;i="6.03,228,1694761200"; d="scan'208";a="705444251" Received: from allen-box.sh.intel.com ([10.239.159.127]) by orsmga003.jf.intel.com with ESMTP; 15 Oct 2023 20:32:09 -0700 From: Lu Baolu To: Joerg Roedel Cc: Jingqi Liu , Jiapeng Chong , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] iommu/vt-d: Remove unused function Date: Mon, 16 Oct 2023 11:28:27 +0800 Message-Id: <20231016032830.101321-2-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231016032830.101321-1-baolu.lu@linux.intel.com> References: <20231016032830.101321-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, 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 (snail.vger.email [0.0.0.0]); Sun, 15 Oct 2023 20:32:29 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779881371546377497 X-GMAIL-MSGID: 1779881371546377497 From: Jiapeng Chong The function are defined in the pasid.c file, but not called elsewhere, so delete the unused function. drivers/iommu/intel/pasid.c:342:20: warning: unused function 'pasid_set_wpe'. Reported-by: Abaci Robot Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=6185 Signed-off-by: Jiapeng Chong Link: https://lore.kernel.org/r/20230818091603.64800-1-jiapeng.chong@linux.alibaba.com Signed-off-by: Lu Baolu --- drivers/iommu/intel/pasid.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c index 8f92b92f3d2a..06ddb3c927f5 100644 --- a/drivers/iommu/intel/pasid.c +++ b/drivers/iommu/intel/pasid.c @@ -335,15 +335,6 @@ static inline void pasid_set_fault_enable(struct pasid_entry *pe) pasid_set_bits(&pe->val[0], 1 << 1, 0); } -/* - * Setup the WPE(Write Protect Enable) field (Bit 132) of a - * scalable mode PASID entry. - */ -static inline void pasid_set_wpe(struct pasid_entry *pe) -{ - pasid_set_bits(&pe->val[2], 1 << 4, 1 << 4); -} - /* * Setup the P(Present) field (Bit 0) of a scalable mode PASID * entry. From patchwork Mon Oct 16 03:28:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 153161 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3215157vqb; Sun, 15 Oct 2023 20:32:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEgwtuuMvpqF2pghdGPMhCcfRV2ZQvNUfokiNcEKQJEWDZhD/8QbJcy4yYF2pBYGG5k79+9 X-Received: by 2002:a05:6a20:c901:b0:163:ab09:193e with SMTP id gx1-20020a056a20c90100b00163ab09193emr1836626pzb.1.1697427156480; Sun, 15 Oct 2023 20:32:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697427156; cv=none; d=google.com; s=arc-20160816; b=dYR7a0bDXWPg/qNPSjLtLKnoLs9oD4fnjpCKwyOAxbUQJKd7g0BNTHdIU6p4Mkt7qd YiKodC5mVAaXybn3xGHvHiTSzUq3A+g7LJadzPSlw9wpwJyDvo9QCf6idJeRe7ddgTxY b3uG4Fa1zoFouHrtvecLb4QW/MCNPvZvT/m+NedDqTdMFHGFe2r9iVCw3xA/TrobBTXF aaR/+3aQ2q3n5cEAY4ex44WAtqjdgMDrRFP0tC57OEHNUaS45no9knwgMXqkSG22lBNq o7hhtyqgENHV2wXO0ZTtaJtQ3g4TuPyfKObhv41WrvdP0PJulU7YsCcydVTFCPOFMILF SiwA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=zlqa33me375OhdeoQVltgfwAOxPFY7T0X5tm9uj2YKY=; fh=+U1mz0Qo6S03r4tUB6unzur/vi2NL5Ihgqvce3o6AxQ=; b=CGjfrBmhufdVqabmlW5IsuhppaZJ/RgcjbDOHKZfNhWGpp4hZbzQYwWl5vB0wGf26C Q5IqBYJwEhyV9fAYITR5pvLSMPMkRiJl4wozmNp3H2KMuxGq0F/80VHyI4AEvi1XxpW2 JpKHzrO9zf3PDkkGhYgCavQjbbkjV9jKWx6AwoH6B3dTn68ExTRHZoRJRXhz5iOFgqWC dZIfq6/A4Pm7atY8CS6BLgo2BlfeSrI+5fr3Z+ZCAxWHNkfJC+g312xooQ2A1RHPD+EX wz2oAXP7l9KHnaMLtmr+T01YEbvOqmtXlowlnAhakJ1lFHB6UKW64asK6DqoRkbVue0O u3Tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=F8bZRogz; 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 bo13-20020a17090b090d00b0026c198d8182si5416620pjb.105.2023.10.15.20.32.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 20:32:36 -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=F8bZRogz; 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 08620804C214; Sun, 15 Oct 2023 20:32:35 -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 S231551AbjJPDcY (ORCPT + 18 others); Sun, 15 Oct 2023 23:32:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231511AbjJPDcO (ORCPT ); Sun, 15 Oct 2023 23:32:14 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27E55DE for ; Sun, 15 Oct 2023 20:32:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697427133; x=1728963133; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zgBbDJXbHtsNwJit7h5lRyc7ItRonwTU9Y4WoJHuj+4=; b=F8bZRogzJd1FRa+ajf3Hj7Z/44gP3oisErtGLVNIPb4KouWLQ3evvB4t YQCYxQPBidaAMLHNTidSCywIUNtL++uhU3qmzRWJTsl0U9oVGYPGoI/dB mLNRKK7CDXLiwUwKHLlTdRa8Vht9wd0HBBQMrjd6I2nXm/dqh1BPAehDX mcyMlrHA0RE4XrdvyMmTleQZj2Mg7dW2GgxJBbidOdCGHfhMUPOpqaFKm /q8th6alwOoIWjrdDcy6TaO4eLD62OWibP7wJdJtAmRcJxrFX8/Q+8/MV EBpSQXRmLYsoMdu1IkiX5Ay4T9GCK3MRPwn4ctuyRPjPTxVKOzDjZPgET w==; X-IronPort-AV: E=McAfee;i="6600,9927,10863"; a="365701129" X-IronPort-AV: E=Sophos;i="6.03,228,1694761200"; d="scan'208";a="365701129" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Oct 2023 20:32:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10863"; a="705444256" X-IronPort-AV: E=Sophos;i="6.03,228,1694761200"; d="scan'208";a="705444256" Received: from allen-box.sh.intel.com ([10.239.159.127]) by orsmga003.jf.intel.com with ESMTP; 15 Oct 2023 20:32:11 -0700 From: Lu Baolu To: Joerg Roedel Cc: Jingqi Liu , Jiapeng Chong , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] iommu/vt-d: debugfs: Dump entry pointing to huge page Date: Mon, 16 Oct 2023 11:28:28 +0800 Message-Id: <20231016032830.101321-3-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231016032830.101321-1-baolu.lu@linux.intel.com> References: <20231016032830.101321-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, 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 (snail.vger.email [0.0.0.0]); Sun, 15 Oct 2023 20:32:35 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779881378010086034 X-GMAIL-MSGID: 1779881378010086034 From: Jingqi Liu For the page table entry pointing to a huge page, the data below the level of the huge page is meaningless and does not need to be dumped. Signed-off-by: Jingqi Liu Link: https://lore.kernel.org/r/20231013135811.73953-2-Jingqi.liu@intel.com Signed-off-by: Lu Baolu --- drivers/iommu/intel/debugfs.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/intel/debugfs.c b/drivers/iommu/intel/debugfs.c index 1f925285104e..497c1561d3d2 100644 --- a/drivers/iommu/intel/debugfs.c +++ b/drivers/iommu/intel/debugfs.c @@ -311,9 +311,14 @@ static inline unsigned long level_to_directory_size(int level) static inline void dump_page_info(struct seq_file *m, unsigned long iova, u64 *path) { - seq_printf(m, "0x%013lx |\t0x%016llx\t0x%016llx\t0x%016llx\t0x%016llx\t0x%016llx\n", - iova >> VTD_PAGE_SHIFT, path[5], path[4], - path[3], path[2], path[1]); + seq_printf(m, "0x%013lx |\t0x%016llx\t0x%016llx\t0x%016llx", + iova >> VTD_PAGE_SHIFT, path[5], path[4], path[3]); + if (path[2]) { + seq_printf(m, "\t0x%016llx", path[2]); + if (path[1]) + seq_printf(m, "\t0x%016llx", path[1]); + } + seq_putc(m, '\n'); } static void pgtable_walk_level(struct seq_file *m, struct dma_pte *pde, From patchwork Mon Oct 16 03:28:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 153162 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3215173vqb; Sun, 15 Oct 2023 20:32:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG++vOAnSXOK/nVBhD4sljCApGQ1lxX+/HLuoJU42cT233Pn009iOKkXRlx7BQVpoammIRe X-Received: by 2002:a05:6a00:3985:b0:68f:c8b3:3077 with SMTP id fi5-20020a056a00398500b0068fc8b33077mr35556242pfb.1.1697427159600; Sun, 15 Oct 2023 20:32:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697427159; cv=none; d=google.com; s=arc-20160816; b=gnvKTW4lZR7oXN34jkK+GmCR0zA9wAznHksitWahjcAcL5p8msOkV+ciFiV1kYIAZz 9NgKVmOITvxrCAVEENacPjbGAfPHOkvtQhTZdhJELEcvBGGiWfC1+XV3NGvnb8ySXyGd 8Pkgqj78W95UkxEXQJrgJRQoRZ4qL7PhS99NFUFY+Ex71u+AJrqWgcMBqHwTRuJdd7xp tlf8FxZCWh8fqQznchmF+Cu5ctrNpQdwToSkQHzMH1uRuiuzcEaZJmGJmuPhWlwE84WB dROkE/VQEbknP+jy+vaY9N+FWS5+DGzrC4WtQHXdxyYLN0LPQcOO8AyxQYVxjl5ZofK2 HgAw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Q4QL9D1Xp+E2wYIakbhQ9hOU5KihfJdUBQ6C1h8ufEQ=; fh=+U1mz0Qo6S03r4tUB6unzur/vi2NL5Ihgqvce3o6AxQ=; b=iDKTdOC1tYC6hVHcB1zYlaZs9IMDBs8GQpWwJ+YKEl5JxwmFB7SJRH0Fi/iqJaRnEd bqfgP2W7x1Jrgr1jGGHQsqzUA30mNQvyTjvOmdWr94bRVEcZ60QUhi8/hnyq9K9DpAc4 0FmNbQQ943H6S4EdlUdFgGbnLI5nltkqzNitb9mn467O2ufBBfv8n398c7s5x+62WpfG GNwxxKVPbpKKC/VaUJdmwpUylSFO6OHYhI4iuMra4CkwHL85nj3CYSm9sWKGek3F1DQP RYEQ8aQyg86uA+dP/n9wQg4wzv/ctWSTc7FOWFaMpnWPDwmSaG+HZ/SoLZuE9br0QWje P8jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nYZz+8s1; 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 p15-20020aa7860f000000b00690f191430csi6877558pfn.56.2023.10.15.20.32.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 20:32:39 -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=nYZz+8s1; 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 4B2CC80ACB75; Sun, 15 Oct 2023 20:32:38 -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 S231646AbjJPDca (ORCPT + 18 others); Sun, 15 Oct 2023 23:32:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231555AbjJPDcS (ORCPT ); Sun, 15 Oct 2023 23:32:18 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFDCBE3 for ; Sun, 15 Oct 2023 20:32:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697427134; x=1728963134; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gcS2gVf871BMvktYqKffgfurRtP/g/aQmfhIpspVA+k=; b=nYZz+8s1JikdFzxWQxgLnU/Ag0VvFo0WTPT+SqU2sKoFoEwuVfQWeh7b YgsqaWO182mvp6QVPjNm5RK8yDty9Dz+xDD5NGEaSh8c8j/Cs4thPgZws 6xoFA7fotMIQ+6o4I4EZLC/0IMPky9Zi/ASmLla5mlR2d3/uHoqjnz8jp Of92nqUileIswnyHRDaCGjTwjjB8HFED2cH88sRt7IKOmsXcYYpwQ8Cjv vIHmI+knag/tzZqZUTkzuzGdoN6HQgWO5bDgo70f44RUFqk34GA3rbQUX rA/9YmG5ZHAtmWKoqvLYFdiC0V/9AXpkSvORnNrOdAGei09cVc50Xn+1K g==; X-IronPort-AV: E=McAfee;i="6600,9927,10863"; a="365701133" X-IronPort-AV: E=Sophos;i="6.03,228,1694761200"; d="scan'208";a="365701133" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Oct 2023 20:32:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10863"; a="705444260" X-IronPort-AV: E=Sophos;i="6.03,228,1694761200"; d="scan'208";a="705444260" Received: from allen-box.sh.intel.com ([10.239.159.127]) by orsmga003.jf.intel.com with ESMTP; 15 Oct 2023 20:32:12 -0700 From: Lu Baolu To: Joerg Roedel Cc: Jingqi Liu , Jiapeng Chong , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] iommu/vt-d: debugfs: Create/remove debugfs file per {device, pasid} Date: Mon, 16 Oct 2023 11:28:29 +0800 Message-Id: <20231016032830.101321-4-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231016032830.101321-1-baolu.lu@linux.intel.com> References: <20231016032830.101321-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, 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 (snail.vger.email [0.0.0.0]); Sun, 15 Oct 2023 20:32:38 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779881381362088265 X-GMAIL-MSGID: 1779881381362088265 From: Jingqi Liu Add a debugfs directory per pair of {device, pasid} if the mappings of its page table are created and destroyed by the iommu_map/unmap() interfaces. i.e. /sys/kernel/debug/iommu/intel//. 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. When setting a domain to a PASID of device, create a debugfs file in the pasid debugfs directory for users to dump the page table of the specified pasid. Remove the debugfs device directory of the device when releasing a device. e.g. /sys/kernel/debug/iommu/intel/0000:00:01.0 Signed-off-by: Jingqi Liu Link: https://lore.kernel.org/r/20231013135811.73953-3-Jingqi.liu@intel.com Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.h | 14 +++++++++ drivers/iommu/intel/debugfs.c | 53 +++++++++++++++++++++++++++++++---- drivers/iommu/intel/iommu.c | 7 +++++ 3 files changed, 69 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index 7dac94f62b4e..f9c1dd1ccff8 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -716,12 +716,18 @@ struct device_domain_info { struct intel_iommu *iommu; /* IOMMU used by this device */ struct dmar_domain *domain; /* pointer to domain */ struct pasid_table *pasid_table; /* pasid table */ +#ifdef CONFIG_INTEL_IOMMU_DEBUGFS + struct dentry *debugfs_dentry; /* pointer to device directory dentry */ +#endif }; struct dev_pasid_info { struct list_head link_domain; /* link to domain siblings */ struct device *dev; ioasid_t pasid; +#ifdef CONFIG_INTEL_IOMMU_DEBUGFS + struct dentry *debugfs_dentry; /* pointer to pasid directory dentry */ +#endif }; static inline void __iommu_flush_cache( @@ -883,8 +889,16 @@ static inline void intel_svm_remove_dev_pasid(struct device *dev, ioasid_t pasid #ifdef CONFIG_INTEL_IOMMU_DEBUGFS void intel_iommu_debugfs_init(void); +void intel_iommu_debugfs_create_dev(struct device_domain_info *info); +void intel_iommu_debugfs_remove_dev(struct device_domain_info *info); +void intel_iommu_debugfs_create_dev_pasid(struct dev_pasid_info *dev_pasid); +void intel_iommu_debugfs_remove_dev_pasid(struct dev_pasid_info *dev_pasid); #else static inline void intel_iommu_debugfs_init(void) {} +static inline void intel_iommu_debugfs_create_dev(struct device_domain_info *info) {} +static inline void intel_iommu_debugfs_remove_dev(struct device_domain_info *info) {} +static inline void intel_iommu_debugfs_create_dev_pasid(struct dev_pasid_info *dev_pasid) {} +static inline void intel_iommu_debugfs_remove_dev_pasid(struct dev_pasid_info *dev_pasid) {} #endif /* CONFIG_INTEL_IOMMU_DEBUGFS */ extern const struct attribute_group *intel_iommu_groups[]; diff --git a/drivers/iommu/intel/debugfs.c b/drivers/iommu/intel/debugfs.c index 497c1561d3d2..8a18a7be5215 100644 --- a/drivers/iommu/intel/debugfs.c +++ b/drivers/iommu/intel/debugfs.c @@ -111,6 +111,8 @@ static const struct iommu_regset iommu_regs_64[] = { IOMMU_REGSET_ENTRY(VCRSP), }; +static struct dentry *intel_iommu_debug; + static int iommu_regset_show(struct seq_file *m, void *unused) { struct dmar_drhd_unit *drhd; @@ -671,16 +673,12 @@ static const struct file_operations dmar_perf_latency_fops = { void __init intel_iommu_debugfs_init(void) { - struct dentry *intel_iommu_debug = debugfs_create_dir("intel", - iommu_debugfs_dir); + intel_iommu_debug = debugfs_create_dir("intel", iommu_debugfs_dir); debugfs_create_file("iommu_regset", 0444, intel_iommu_debug, NULL, &iommu_regset_fops); debugfs_create_file("dmar_translation_struct", 0444, intel_iommu_debug, NULL, &dmar_translation_struct_fops); - debugfs_create_file("domain_translation_struct", 0444, - intel_iommu_debug, NULL, - &domain_translation_struct_fops); debugfs_create_file("invalidation_queue", 0444, intel_iommu_debug, NULL, &invalidation_queue_fops); #ifdef CONFIG_IRQ_REMAP @@ -690,3 +688,48 @@ void __init intel_iommu_debugfs_init(void) debugfs_create_file("dmar_perf_latency", 0644, intel_iommu_debug, NULL, &dmar_perf_latency_fops); } + +/* + * Create a debugfs directory for each device, and then create a + * debugfs file in this directory for users to dump the page table + * of the default domain. e.g. + * /sys/kernel/debug/iommu/intel/0000:00:01.0/domain_translation_struct + */ +void intel_iommu_debugfs_create_dev(struct device_domain_info *info) +{ + info->debugfs_dentry = debugfs_create_dir(dev_name(info->dev), intel_iommu_debug); + + debugfs_create_file("domain_translation_struct", 0444, info->debugfs_dentry, + NULL, &domain_translation_struct_fops); +} + +/* Remove the device debugfs directory. */ +void intel_iommu_debugfs_remove_dev(struct device_domain_info *info) +{ + debugfs_remove_recursive(info->debugfs_dentry); +} + +/* + * Create a debugfs directory per pair of {device, pasid}, then create the + * corresponding debugfs file in this directory for users to dump its page + * table. e.g. + * /sys/kernel/debug/iommu/intel/0000:00:01.0/1/domain_translation_struct + * + * The debugfs only dumps the page tables whose mappings are created and + * destroyed by the iommu_map/unmap() interfaces. Check the mapping type + * of the domain before creating debugfs directory. + */ +void intel_iommu_debugfs_create_dev_pasid(struct dev_pasid_info *dev_pasid) +{ + struct device_domain_info *info = dev_iommu_priv_get(dev_pasid->dev); + char dir_name[10]; + + sprintf(dir_name, "%x", dev_pasid->pasid); + dev_pasid->debugfs_dentry = debugfs_create_dir(dir_name, info->debugfs_dentry); +} + +/* Remove the device pasid debugfs directory. */ +void intel_iommu_debugfs_remove_dev_pasid(struct dev_pasid_info *dev_pasid) +{ + debugfs_remove_recursive(dev_pasid->debugfs_dentry); +} diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 3685ba90ec88..d77d60bc418f 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4409,6 +4409,8 @@ static struct iommu_device *intel_iommu_probe_device(struct device *dev) } } + intel_iommu_debugfs_create_dev(info); + return &iommu->iommu; } @@ -4418,6 +4420,7 @@ static void intel_iommu_release_device(struct device *dev) dmar_remove_one_dev_info(dev); intel_pasid_free_table(dev); + intel_iommu_debugfs_remove_dev(info); dev_iommu_priv_set(dev, NULL); kfree(info); set_dma_ops(dev, NULL); @@ -4710,6 +4713,7 @@ static void intel_iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid) spin_unlock_irqrestore(&dmar_domain->lock, flags); domain_detach_iommu(dmar_domain, iommu); + intel_iommu_debugfs_remove_dev_pasid(dev_pasid); kfree(dev_pasid); out_tear_down: intel_pasid_tear_down_entry(iommu, dev, pasid, false); @@ -4762,6 +4766,9 @@ static int intel_iommu_set_dev_pasid(struct iommu_domain *domain, list_add(&dev_pasid->link_domain, &dmar_domain->dev_pasids); spin_unlock_irqrestore(&dmar_domain->lock, flags); + if (domain->type & __IOMMU_DOMAIN_PAGING) + intel_iommu_debugfs_create_dev_pasid(dev_pasid); + return 0; out_detach_iommu: domain_detach_iommu(dmar_domain, iommu); From patchwork Mon Oct 16 03:28:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 153163 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3215201vqb; Sun, 15 Oct 2023 20:32:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE3kDOk+K0eYsU4aAg8N62RdnegTDBHTlc0KXi7KkejpYWMy94g+SqvmeBD+wY3egsgrfEj X-Received: by 2002:a17:90b:1e50:b0:27d:32d8:5f23 with SMTP id pi16-20020a17090b1e5000b0027d32d85f23mr8232699pjb.2.1697427165696; Sun, 15 Oct 2023 20:32:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697427165; cv=none; d=google.com; s=arc-20160816; b=UKamSpd5q8J3+rDWxC7xPMIW71ExkUzryYCXiGhu6fqo4yYv20n4kXdXRPmSGJ1kmg H/vccvNAhVauyo+aE2T6i7vGeXVinmmI8CnCNmsMr0SuCu1y7zyjeOxfruY0RWkH2jwi GQzoq87KNbATG7guKneuJUas6TUW9KzADQIwfw8Rt+MfP5Mpbejlq7AyRlbWwoweZfjX 4szx6nZLK+q74rwpxtoz8DvbUmjvd1Anl/zdWbcX+X+MWP2Uhrbcw55NAiNFxZYUnrGe wE+qJ2EK+eSjki+Wx8sUHIVb7EEgXVjYpHYOP7pUbRltfsD+asTcM8cAtaNu4RKBi8Iw NEdQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jcDGF55Z0mDCNe7sM1+g+l1uWXtAWfbmqPRiWgE5HWQ=; fh=+U1mz0Qo6S03r4tUB6unzur/vi2NL5Ihgqvce3o6AxQ=; b=PW7GIczs+2bP+jvDxNSNsMuqfzWI+a4r5w/9N2X2z73Tyawryo4YUDY3ldzTQ3ZoCt oMQdMCz8hQ3XJS4q+iFAqnk6XnDiIv9y1KVKzwJV1f3tB0fxmtp5EUTae3rSBe+nT8Kt DEkQD7thnVo9fhsNwoxLHgbYobYWLM5NSleiInYqtHQEBfRN4gW9nOUVXzRvRjnSxNHx mjaI1PYJGOHMSe8o4s0TaWmPMI/yUXmCdPhPZWs9wB6SClFXzFqNypZbvUZ2XZcBr8UM XSzt9kDGoupfoMc3N9AwrqddAcKUaZfExgtgQffhxwQMlOrcegdNas0vnOMhafvF5hZT nY/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=B8NaAgOz; 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 a24-20020a17090a8c1800b0027763f3e3c8si4971690pjo.186.2023.10.15.20.32.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 20:32:45 -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=B8NaAgOz; 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 7E5BC804C494; Sun, 15 Oct 2023 20:32:44 -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 S231490AbjJPDcg (ORCPT + 18 others); Sun, 15 Oct 2023 23:32:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231604AbjJPDcV (ORCPT ); Sun, 15 Oct 2023 23:32:21 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D161BE9 for ; Sun, 15 Oct 2023 20:32:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697427136; x=1728963136; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cLIuhJ4fUheXhS2lbr+n6fx+II71lQXYR6PDa5cejgc=; b=B8NaAgOzMVwEH5EC8gkBKbKqCdABHBZG5cGx7asucHpIArIZW5L2Rcqn 38MHJBFVhmQ2/c7/7UMjmf3VCoQ8dnTlCdCBuEFyKeDGu9T6zhY6niIVK r1ZKHLamle13/zzHnwYEE5akNC8lZ90p1kLoSqzFf5n1oRKdFfPN6H7Dn h9LjBrSJHnAhQ+p7M0yeOwu3UrbcMxs1vKY2ywi4BYFfIQgpAL8UG+HDY L/ApvHeyOVtTvkY3IoWUF4ItQlLn7S0DYnTiesuuROvWp2mBdfsQF+Gjd hteGwsztidAjH1Qu+F3uPkVUJdiklzb01xVkAUWugztujg3GTnPNEuR03 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10863"; a="365701137" X-IronPort-AV: E=Sophos;i="6.03,228,1694761200"; d="scan'208";a="365701137" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Oct 2023 20:32:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10863"; a="705444264" X-IronPort-AV: E=Sophos;i="6.03,228,1694761200"; d="scan'208";a="705444264" Received: from allen-box.sh.intel.com ([10.239.159.127]) by orsmga003.jf.intel.com with ESMTP; 15 Oct 2023 20:32:14 -0700 From: Lu Baolu To: Joerg Roedel Cc: Jingqi Liu , Jiapeng Chong , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] iommu/vt-d: debugfs: Support dumping a specified page table Date: Mon, 16 Oct 2023 11:28:30 +0800 Message-Id: <20231016032830.101321-5-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231016032830.101321-1-baolu.lu@linux.intel.com> References: <20231016032830.101321-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, 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 (snail.vger.email [0.0.0.0]); Sun, 15 Oct 2023 20:32:44 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779881387528685206 X-GMAIL-MSGID: 1779881387528685206 From: Jingqi Liu The original debugfs only dumps all page tables without pasid. With pasid supported, the page table with pasid also needs to be dumped. This patch supports dumping a specified page table in legacy mode or scalable mode with or without a specified pasid. 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:1f.0" that only supports legacy mode. $ sudo cat /sys/kernel/debug/iommu/intel/0000:00:1f.0/domain_translation_struct 2) Dump the page table of device "0000:00:0a.0" with PASID "1" that supports scalable mode. $ sudo cat /sys/kernel/debug/iommu/intel/0000:00:0a.0/1/domain_translation_struct Suggested-by: Kevin Tian Signed-off-by: Jingqi Liu Link: https://lore.kernel.org/r/20231013135811.73953-4-Jingqi.liu@intel.com Signed-off-by: Lu Baolu --- drivers/iommu/intel/debugfs.c | 153 ++++++++++++++++++++++++++-------- 1 file changed, 119 insertions(+), 34 deletions(-) diff --git a/drivers/iommu/intel/debugfs.c b/drivers/iommu/intel/debugfs.c index 8a18a7be5215..dee61e513be6 100644 --- a/drivers/iommu/intel/debugfs.c +++ b/drivers/iommu/intel/debugfs.c @@ -347,58 +347,140 @@ static void pgtable_walk_level(struct seq_file *m, struct dma_pte *pde, } } -static int __show_device_domain_translation(struct device *dev, void *data) +static int domain_translation_struct_show(struct seq_file *m, + struct device_domain_info *info, + ioasid_t pasid) { - struct dmar_domain *domain; - struct seq_file *m = data; - u64 path[6] = { 0 }; + bool scalable, found = false; + struct dmar_drhd_unit *drhd; + struct intel_iommu *iommu; + u16 devfn, bus, seg; - domain = to_dmar_domain(iommu_get_domain_for_dev(dev)); - if (!domain) - return 0; + bus = info->bus; + devfn = info->devfn; + seg = info->segment; - seq_printf(m, "Device %s @0x%llx\n", dev_name(dev), - (u64)virt_to_phys(domain->pgd)); - seq_puts(m, "IOVA_PFN\t\tPML5E\t\t\tPML4E\t\t\tPDPE\t\t\tPDE\t\t\tPTE\n"); + rcu_read_lock(); + for_each_active_iommu(iommu, drhd) { + struct context_entry *context; + u64 pgd, path[6] = { 0 }; + u32 sts, agaw; - pgtable_walk_level(m, domain->pgd, domain->agaw + 2, 0, path); - seq_putc(m, '\n'); + if (seg != iommu->segment) + continue; - /* Don't iterate */ - return 1; -} + sts = dmar_readl(iommu->reg + DMAR_GSTS_REG); + if (!(sts & DMA_GSTS_TES)) { + seq_printf(m, "DMA Remapping is not enabled on %s\n", + iommu->name); + continue; + } + if (dmar_readq(iommu->reg + DMAR_RTADDR_REG) & DMA_RTADDR_SMT) + scalable = true; + else + scalable = false; -static int show_device_domain_translation(struct device *dev, void *data) -{ - struct iommu_group *group; - - group = iommu_group_get(dev); - if (group) { /* - * The group->mutex is held across the callback, which will - * block calls to iommu_attach/detach_group/device. Hence, + * The iommu->lock is held across the callback, which will + * block calls to domain_attach/domain_detach. Hence, * the domain of the device will not change during traversal. * - * All devices in an iommu group share a single domain, hence - * we only dump the domain of the first device. Even though, - * this code still possibly races with the iommu_unmap() + * Traversing page table possibly races with the iommu_unmap() * interface. This could be solved by RCU-freeing the page * table pages in the iommu_unmap() path. */ - iommu_group_for_each_dev(group, data, - __show_device_domain_translation); - iommu_group_put(group); + spin_lock(&iommu->lock); + + context = iommu_context_addr(iommu, bus, devfn, 0); + if (!context || !context_present(context)) + goto iommu_unlock; + + if (scalable) { /* scalable mode */ + struct pasid_entry *pasid_tbl, *pasid_tbl_entry; + struct pasid_dir_entry *dir_tbl, *dir_entry; + u16 dir_idx, tbl_idx, pgtt; + u64 pasid_dir_ptr; + + pasid_dir_ptr = context->lo & VTD_PAGE_MASK; + + /* Dump specified device domain mappings with PASID. */ + dir_idx = pasid >> PASID_PDE_SHIFT; + tbl_idx = pasid & PASID_PTE_MASK; + + dir_tbl = phys_to_virt(pasid_dir_ptr); + dir_entry = &dir_tbl[dir_idx]; + + pasid_tbl = get_pasid_table_from_pde(dir_entry); + if (!pasid_tbl) + goto iommu_unlock; + + pasid_tbl_entry = &pasid_tbl[tbl_idx]; + if (!pasid_pte_is_present(pasid_tbl_entry)) + goto iommu_unlock; + + /* + * According to PASID Granular Translation Type(PGTT), + * get the page table pointer. + */ + pgtt = (u16)(pasid_tbl_entry->val[0] & GENMASK_ULL(8, 6)) >> 6; + agaw = (u8)(pasid_tbl_entry->val[0] & GENMASK_ULL(4, 2)) >> 2; + + switch (pgtt) { + case PASID_ENTRY_PGTT_FL_ONLY: + pgd = pasid_tbl_entry->val[2]; + break; + case PASID_ENTRY_PGTT_SL_ONLY: + case PASID_ENTRY_PGTT_NESTED: + pgd = pasid_tbl_entry->val[0]; + break; + default: + goto iommu_unlock; + } + pgd &= VTD_PAGE_MASK; + } else { /* legacy mode */ + pgd = context->lo & VTD_PAGE_MASK; + agaw = context->hi & 7; + } + + seq_printf(m, "Device %04x:%02x:%02x.%x ", + iommu->segment, bus, PCI_SLOT(devfn), PCI_FUNC(devfn)); + + if (scalable) + seq_printf(m, "with pasid %x @0x%llx\n", pasid, pgd); + else + seq_printf(m, "@0x%llx\n", pgd); + + seq_printf(m, "%-17s\t%-18s\t%-18s\t%-18s\t%-18s\t%-s\n", + "IOVA_PFN", "PML5E", "PML4E", "PDPE", "PDE", "PTE"); + pgtable_walk_level(m, phys_to_virt(pgd), agaw + 2, 0, path); + + found = true; +iommu_unlock: + spin_unlock(&iommu->lock); + if (found) + break; } + rcu_read_unlock(); return 0; } -static int domain_translation_struct_show(struct seq_file *m, void *unused) +static int dev_domain_translation_struct_show(struct seq_file *m, void *unused) { - return bus_for_each_dev(&pci_bus_type, NULL, m, - show_device_domain_translation); + struct device_domain_info *info = (struct device_domain_info *)m->private; + + return domain_translation_struct_show(m, info, IOMMU_NO_PASID); } -DEFINE_SHOW_ATTRIBUTE(domain_translation_struct); +DEFINE_SHOW_ATTRIBUTE(dev_domain_translation_struct); + +static int pasid_domain_translation_struct_show(struct seq_file *m, void *unused) +{ + struct dev_pasid_info *dev_pasid = (struct dev_pasid_info *)m->private; + struct device_domain_info *info = dev_iommu_priv_get(dev_pasid->dev); + + return domain_translation_struct_show(m, info, dev_pasid->pasid); +} +DEFINE_SHOW_ATTRIBUTE(pasid_domain_translation_struct); static void invalidation_queue_entry_show(struct seq_file *m, struct intel_iommu *iommu) @@ -700,7 +782,7 @@ void intel_iommu_debugfs_create_dev(struct device_domain_info *info) info->debugfs_dentry = debugfs_create_dir(dev_name(info->dev), intel_iommu_debug); debugfs_create_file("domain_translation_struct", 0444, info->debugfs_dentry, - NULL, &domain_translation_struct_fops); + info, &dev_domain_translation_struct_fops); } /* Remove the device debugfs directory. */ @@ -726,6 +808,9 @@ void intel_iommu_debugfs_create_dev_pasid(struct dev_pasid_info *dev_pasid) sprintf(dir_name, "%x", dev_pasid->pasid); dev_pasid->debugfs_dentry = debugfs_create_dir(dir_name, info->debugfs_dentry); + + debugfs_create_file("domain_translation_struct", 0444, dev_pasid->debugfs_dentry, + dev_pasid, &pasid_domain_translation_struct_fops); } /* Remove the device pasid debugfs directory. */