From patchwork Tue Aug 20 17:16:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 13770511 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 04710C3DA4A for ; Tue, 20 Aug 2024 17:20:04 +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: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=4fyhtVpDgygfT5fUkGsgqPbatgiu5TzPiPLAt109+iE=; b=MHyDqqAf3ErnzXBmfKu7sS2e80 xDb0DBDDkTTHYIWIlAG/ezLhjuDkPjX4jqPZ0U7vq4njZf0t9+Y65mptddyxki1DAR1ngFF24DapR cID4P+cvxDXSR3JcBR587bJbVE4lGBHhQS5R2hIa9wSscB4O914Q4EDmopnPdv7mMqW+QeHy362ne OorRQl/gykkISNtwr7C8sunGK7PcQmVmVvflE9tj8B/fynvMYMKqlWMFTF8d/ERfQDByW7WBvV8zC 7eO0bJ0XzI1pVbODLjbjv8PH7KGQ9dEXUyIAy4wO++b8Vr9IGslNj2sfb2VJcxtcnw8ZM01WkGeEy cz6b2rTQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgSWR-000000069Lj-2gho; Tue, 20 Aug 2024 17:19:55 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgSTt-000000068a6-0UMC for linux-arm-kernel@lists.infradead.org; Tue, 20 Aug 2024 17:17:18 +0000 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-201cd78c6a3so44394895ad.1 for ; Tue, 20 Aug 2024 10:17:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724174236; x=1724779036; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4fyhtVpDgygfT5fUkGsgqPbatgiu5TzPiPLAt109+iE=; b=mnZxBA1oT9ADQToS8puitk670NdyIFYoVQkLeelx/b05EQ2Le77LGYDq69NdhSNovP Pt3VyOYpO2cT+5Iz5iaOPT6u20gbLNmP13lKxU/zvhjw76BaQzKMN3fO/nmCWdsQRuFZ VK9M2ndW1A8ytU2gPx6sEmhJeVNwTs2HOdnm5Rpblaw6BMnWWiDxCV3zXYqgUG09Rwb/ CNTRRtpSzyeBOw0DFvEBFA96913WgT3e/sGz2KCoW4cV/Ax40Vi8p0yL/w15ve0szT0U doKKMBKDTqXlozQziruTktG9vSrFzBvmQbH05t76g7RU5pk8GmIygc8eZ0TFtFS/TeB0 Cplg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724174236; x=1724779036; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4fyhtVpDgygfT5fUkGsgqPbatgiu5TzPiPLAt109+iE=; b=V+58/UHzjaHjQYZcXNIQl2qZCuunid4lqroPQ7Z/hgS+4TC1i/Qb81mBW9qHs808fR qshbhrwTn92y5LdCZWPALNmD0QI2GjgNQfUNPwscX8taKyUu4rHEbOfG+cyCp79yKtzK DXGBQdDVc9piP5XRQF4ul0FKTpS2BjdNHR4uXzsx7vEUCIG35LFhdSrnh6voe9cCtlbg GEqjgCogaDj04hgtFHCUIeGkOpB7ir+5yK+0cxU7dUpY1c3CZ8QqAgd7RojhPLvLVttN cdv9CZab1MOdp2hHoeXnoJ1wDOtge5bLT4tmvLvxPnQo1HLHPziPmU4GoTvs/nMVLm4G jT/Q== X-Forwarded-Encrypted: i=1; AJvYcCXbz8WsUwHBOLKJaJIiw+FbLoIyjLzgh/oEP0uo0a7NAJaBo7EhOdB5F/gJiHUG3afybhx0bgzkHwzg2THKs0HW@lists.infradead.org X-Gm-Message-State: AOJu0Yx+Vv45y/LtDjQA+foBS7d6ZVbr7uowy38jRphi1DcTpSkFTqXU khbTVei6w8H6nk3Qh/hIDO5k5bk9E+xpBni0MmI4EFdFtLA39sdU X-Google-Smtp-Source: AGHT+IG89nPNiTxJdoeWAd4I9+Nt1kCBeEpf+Ehrfj9fghEkvWbqdwi+s8kDEywa2ecTlYbOssqipA== X-Received: by 2002:a17:902:e549:b0:202:671:e5bd with SMTP id d9443c01a7336-2020671f9b0mr167387315ad.42.1724174235653; Tue, 20 Aug 2024 10:17:15 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:bd02:d0ce:e791:dc08:a375]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-201f038b303sm80401575ad.192.2024.08.20.10.17.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 10:17:15 -0700 (PDT) From: Rob Clark To: iommu@lists.linux.dev Cc: linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org, Mostafa Saleh , Will Deacon , Rob Clark , Robin Murphy , Joerg Roedel , Jason Gunthorpe , Kevin Tian , Joao Martins , Boris Brezillon , linux-arm-kernel@lists.infradead.org (moderated list:ARM SMMU DRIVERS), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v7 3/4] iommu/io-pgtable-arm: Add way to debug pgtable walk Date: Tue, 20 Aug 2024 10:16:46 -0700 Message-ID: <20240820171652.145673-4-robdclark@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240820171652.145673-1-robdclark@gmail.com> References: <20240820171652.145673-1-robdclark@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240820_101717_183180_63F6D5D2 X-CRM114-Status: GOOD ( 13.83 ) 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 From: Rob Clark Add an io-pgtable method to walk the pgtable returning the raw PTEs that would be traversed for a given iova access. Signed-off-by: Rob Clark --- drivers/iommu/io-pgtable-arm.c | 25 +++++++++++++++++++++++++ include/linux/io-pgtable.h | 15 +++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c index 5fa1274a665a..a666ee03de47 100644 --- a/drivers/iommu/io-pgtable-arm.c +++ b/drivers/iommu/io-pgtable-arm.c @@ -759,6 +759,30 @@ static phys_addr_t arm_lpae_iova_to_phys(struct io_pgtable_ops *ops, return iopte_to_paddr(d.pte, data) | iova; } +static int visit_pgtable_walk(struct io_pgtable_walk_data *walk_data, int lvl, + arm_lpae_iopte pte, size_t size) +{ + struct arm_lpae_io_pgtable_walk_data *data = walk_data->data; + data->ptes[data->level++] = pte; + return 0; +} + +static int arm_lpae_pgtable_walk(struct io_pgtable_ops *ops, unsigned long iova, + void *wd) +{ + struct arm_lpae_io_pgtable *data = io_pgtable_ops_to_data(ops); + struct io_pgtable_walk_data walk_data = { + .data = wd, + .visit = visit_pgtable_walk, + .addr = iova, + .end = iova + 1, + }; + + ((struct arm_lpae_io_pgtable_walk_data *)wd)->level = 0; + + return __arm_lpae_iopte_walk(data, &walk_data, data->pgd, data->start_level); +} + static int io_pgtable_visit(struct arm_lpae_io_pgtable *data, struct io_pgtable_walk_data *walk_data, arm_lpae_iopte *ptep, int lvl) @@ -928,6 +952,7 @@ arm_lpae_alloc_pgtable(struct io_pgtable_cfg *cfg) .unmap_pages = arm_lpae_unmap_pages, .iova_to_phys = arm_lpae_iova_to_phys, .read_and_clear_dirty = arm_lpae_read_and_clear_dirty, + .pgtable_walk = arm_lpae_pgtable_walk, }; return data; diff --git a/include/linux/io-pgtable.h b/include/linux/io-pgtable.h index f9a81761bfce..76eabd890e6a 100644 --- a/include/linux/io-pgtable.h +++ b/include/linux/io-pgtable.h @@ -174,12 +174,26 @@ struct io_pgtable_cfg { }; }; +/** + * struct arm_lpae_io_pgtable_walk_data - information from a pgtable walk + * + * @ptes: The recorded PTE values from the walk + * @level: The level of the last PTE + * + * @level also specifies the last valid index in @ptes + */ +struct arm_lpae_io_pgtable_walk_data { + u64 ptes[4]; + int level; +}; + /** * struct io_pgtable_ops - Page table manipulation API for IOMMU drivers. * * @map_pages: Map a physically contiguous range of pages of the same size. * @unmap_pages: Unmap a range of virtually contiguous pages of the same size. * @iova_to_phys: Translate iova to physical address. + * @pgtable_walk: (optional) Perform a page table walk for a given iova. * * These functions map directly onto the iommu_ops member functions with * the same names. @@ -193,6 +207,7 @@ struct io_pgtable_ops { struct iommu_iotlb_gather *gather); phys_addr_t (*iova_to_phys)(struct io_pgtable_ops *ops, unsigned long iova); + int (*pgtable_walk)(struct io_pgtable_ops *ops, unsigned long iova, void *wd); int (*read_and_clear_dirty)(struct io_pgtable_ops *ops, unsigned long iova, size_t size, unsigned long flags,