From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 50A48105F797 for ; Fri, 13 Mar 2026 10:44:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=lcZZrXAdqn94ZnDjs/X+KlRU4FcdDdVAYMMtG10Pb8c=; b=uc0cDf764+uG15fcCars1uuOGe XwHTTp8Rwpfm6LzO4fXisP9Fv2HJ8oIytU0U2NfKmB1HfCI9podv5o0Hr6QMD7oZVSaw6orIUWAFS 3ThsKB8OoC0RZXFrwQEiHFFNHpAOlwv/A4QpSqUSgR+l/T2Is7eQXzeUoW7yLEDC6eyavoTXoyVbs 2eG0qCC5e+trDT147UxyyChYNhw9UpGswJz0/i7OcbQRI1/PX1qHgkDsw9n/QDJ7zWOLHC71hnnGk 3773VZQfubl+hTFKThiAZSxzG8RXouSz3TweQ++BeqqTLfXhwoQMKKGeg42xxghLcsSUw40xlSc0T 9ZcLeVYA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1w1005-0000000HX3x-2piV; Fri, 13 Mar 2026 10:44:13 +0000 Received: from canpmsgout06.his.huawei.com ([113.46.200.221]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1w0zzz-0000000HWxv-3LKG for linux-arm-kernel@lists.infradead.org; Fri, 13 Mar 2026 10:44:09 +0000 dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=lcZZrXAdqn94ZnDjs/X+KlRU4FcdDdVAYMMtG10Pb8c=; b=qqLGyyQjUhrMc2GS64tIsSIUdZ2Qru97dJaSrN8+490ySt/R6QLsaAp07/9t9Nb/odHAQPdYI xG7nFFqBXWAp4NAttE+Wcl5cBjndGC25Av//Iy4V08b5omxSvc9TZDZguGJtmdANupeCoZBizsA ejcTysM3ZQbAEuKNIlly8Is= Received: from mail.maildlp.com (unknown [172.19.162.223]) by canpmsgout06.his.huawei.com (SkyGuard) with ESMTPS id 4fXLZK1JwXzRhQR; Fri, 13 Mar 2026 18:39:05 +0800 (CST) Received: from kwepemj200003.china.huawei.com (unknown [7.202.194.15]) by mail.maildlp.com (Postfix) with ESMTPS id F00C840569; Fri, 13 Mar 2026 18:44:00 +0800 (CST) Received: from localhost.huawei.com (10.90.31.46) by kwepemj200003.china.huawei.com (7.202.194.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 13 Mar 2026 18:44:00 +0800 From: Qinxin Xia To: , , CC: , , , , , , , Subject: [RFC PATCH 5/5] iommu/arm-smmu-v3: Add Context Descriptor display to debugfs Date: Fri, 13 Mar 2026 18:43:51 +0800 Message-ID: <20260313104351.3502293-6-xiaqinxin@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20260313104351.3502293-1-xiaqinxin@huawei.com> References: <20260313104351.3502293-1-xiaqinxin@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="y" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.90.31.46] X-ClientProxiedBy: kwepems100001.china.huawei.com (7.221.188.238) To kwepemj200003.china.huawei.com (7.202.194.15) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260313_034408_168655_677149B8 X-CRM114-Status: GOOD ( 15.43 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add Context Descriptor (CD) display functionality to debugfs. This allow inspecting CD contents for all Substream IDs including: - CD validity and translation parameters - TTBR0 and TCR configurations - Raw CD data /sys/kernel/debug/iommu/arm_smmu_v3/smmu0/stream_table/ └── 0000:01:00.0:0/ ├── ste └── context_descriptors/ └── all Signed-off-by: Qinxin Xia --- .../arm/arm-smmu-v3/arm-smmu-v3-debugfs.c | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-debugfs.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-debugfs.c index f62df02847ac..66ae1228c6ad 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-debugfs.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-debugfs.c @@ -27,6 +27,13 @@ * - Context Pointers: Stage 1 and Stage 2 translation context addresses * - Raw Data: Complete 64-bit STE words in hexadecimal * + * CD Information Displayed: + * - Validity: Active state of the context descriptor + * - T0SZ: Input address space size configuration + * - EPD0/EPD1: Stage 1 translation enable flags + * - TTBR0: Stage 1 translation table base address + * - Raw Data: Complete CD structure in hexadecimal format + * * Directory Structure: * /sys/kernel/debug/iommu/arm_smmu_v3/ * └── smmu0/ @@ -35,6 +42,8 @@ * └── stream_table * └── 0000:01:00.0:0/ # PCI device with Stream ID 0 * ├── ste # Stream Table Entry + * └── context_descriptors/ + * └── all # All Context Descriptors * * The capabilities file provides detailed information about: * - Architecture version and translation stage support (Stage1/Stage2) @@ -59,6 +68,8 @@ static struct dentry *smmuv3_root_dir; static DEFINE_MUTEX(arm_smmu_debugfs_lock); +#define MAX_SSIDS 32 /* Reasonable limit for SSID enumeration */ + /** * smmu_debugfs_capabilities_show() - Display SMMU capabilities * @seq: seq_file to write to @@ -329,6 +340,90 @@ static int smmu_debugfs_ste_show(struct seq_file *seq, void *v) } DEFINE_SHOW_ATTRIBUTE(smmu_debugfs_ste); +/** + * smmu_debug_dump_cd() - Dump Context Descriptor details to seq_file + * @seq: seq_file to write to + * @dev: device associated with the CD + * @ssid: Substream ID + */ +static void smmu_debug_dump_cd(struct seq_file *seq, struct device *dev, u32 ssid) +{ + struct arm_smmu_master *master = dev_iommu_priv_get(dev); + struct arm_smmu_cd *cd; + u64 data; + int i; + + if (!master) { + seq_puts(seq, "No master data\n"); + return; + } + + cd = arm_smmu_get_cd_ptr(master, ssid); + if (!cd) { + seq_printf(seq, "CD not available for SSID %u\n", ssid); + return; + } + + seq_printf(seq, "CD for Substream ID %u:\n", ssid); + + /* CD 0 */ + data = le64_to_cpu(cd->data[0]); + seq_printf(seq, " Valid: %s\n", data & CTXDESC_CD_0_V ? "Yes" : "No"); + seq_printf(seq, " T0SZ: 0x%llx\n", data & CTXDESC_CD_0_TCR_T0SZ); + seq_printf(seq, " EPD0: %s\n", data & CTXDESC_CD_0_TCR_EPD0 ? "Yes" : "No"); + seq_printf(seq, " EPD1: %s\n", data & CTXDESC_CD_0_TCR_EPD1 ? "Yes" : "No"); + + /* CD 1 */ + data = le64_to_cpu(cd->data[1]); + seq_printf(seq, " TTBR0: 0x%016llx\n", data & CTXDESC_CD_1_TTB0_MASK); + + /* Display raw CD data */ + seq_puts(seq, " Raw Data:\n"); + for (i = 0; i < CTXDESC_CD_DWORDS; i++) + seq_printf(seq, " CD[%d]: 0x%016llx\n", i, + le64_to_cpu(cd->data[i])); +} + +/** + * smmu_debug_dump_all_cds() - Dump all valid Context Descriptors for a device + * @seq: seq_file to write to + * @dev: target device + */ +static void smmu_debug_dump_all_cds(struct seq_file *seq, struct device *dev) +{ + struct arm_smmu_master *master = dev_iommu_priv_get(dev); + u32 max_ssids, ssid; + + if (!master) { + seq_puts(seq, "No master data\n"); + return; + } + + max_ssids = min_t(u32, 1 << master->ssid_bits, MAX_SSIDS); + + seq_printf(seq, "Context Descriptors for device (max SSIDs: %u):\n", + max_ssids); + + for (ssid = 0; ssid < max_ssids; ssid++) { + struct arm_smmu_cd *cd = arm_smmu_get_cd_ptr(master, ssid); + + if (cd && (le64_to_cpu(cd->data[0]) & CTXDESC_CD_0_V)) { + seq_printf(seq, "\n--- SSID %u ---\n", ssid); + smmu_debug_dump_cd(seq, dev, ssid); + } + } +} + +/* All CDs debugfs file operations */ +static int smmu_debugfs_all_cds_show(struct seq_file *seq, void *v) +{ + struct device *dev = seq->private; + + smmu_debug_dump_all_cds(seq, dev); + return 0; +} +DEFINE_SHOW_ATTRIBUTE(smmu_debugfs_all_cds); + /** * smmu_debugfs_create_stream_table() - Create debugfs entries for stream table * @dev: device to create entries for @@ -388,9 +483,26 @@ int smmu_debugfs_create_stream_table(struct device *dev, goto cleanup_dev; } + /* Create CD directory */ + cd_dir = debugfs_create_dir("context_descriptors", dev_dir); + if (!cd_dir) { + ret = -ENOMEM; + goto cleanup_dev; + } + + /* Create "all" file to show all valid CDs */ + all_cds_file = debugfs_create_file("all", 0444, cd_dir, dev, + &smmu_debugfs_all_cds_fops); + if (!all_cds_file) { + ret = -ENOMEM; + goto cleanup_cd; + } + /* Success for this stream ID, continue to next */ continue; +cleanup_cd: + debugfs_remove(cd_dir); cleanup_dev: debugfs_remove_recursive(dev_dir); cleanup: -- 2.33.0