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 36EBDC30653 for ; Wed, 3 Jul 2024 15:02:39 +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:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=rBIPBJJ723/xzA36sG+8U0IhzwlEnprfiz5kFUgY8L8=; b=M/D5H9bDPOl8hGHQMT2mii9j4S JvBIfXaBQ7qWClQpCI91yRsvVqJi302GiobmR6Sqnj69NOu3zDuUilbxxFhC7SHyYvZv0Uojerq+R LJ2BnP+vh9DFrfN3dGjRkIlwpRV9FgmmzSJfvVRbzgkGe/dWm2P3VXAPDI9M37fSuZcw01rqG80yp GrKUfUFuXsu2kHxVJVDlBU+5mW7W7kHXrNY3l5UjoSI1Y4kMNuziCGm+RJftgF2SGDZoIiqOA9Zg0 Jithdk6kLGg8q/gS8mmI4p6e01h0Lw0EKJMvLQsop5tl+L+/vHEYh+tXljeTtT9PAv8jUqmKwFEQc BYs+6o7A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sP1V4-0000000AbES-0qhz; Wed, 03 Jul 2024 15:02:26 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sP1Uq-0000000Ab8U-2IOR for linux-arm-kernel@lists.infradead.org; Wed, 03 Jul 2024 15:02:14 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 8822662326; Wed, 3 Jul 2024 15:02:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E74F2C2BD10; Wed, 3 Jul 2024 15:02:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720018931; bh=inCHldH9Dlwyh/zOAE2VhEgtnXtFJn3LffZ8Wuw5rfE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=QXirydPx98ylk807Kr0IvThvOzX0uaRdHHI6xbrttp3bygpYOPwXc1hZU6ia+TEJJ KQuaKUUaxceVGHX8OfX76bd6iypQ1XY0evyThCu0zX17+1fmHVCZlsJFsNjgOmh80/ MVbhdHGV4w4euNcb6ajsptpzqLtUInOOD9NzqCPmmlP5m+QIgdc4sS8Ro3flchxDYc gbgJXFRYXPOoLswr3CKFa587/dtgqf8/86GaWh4ucbd47R+sHfu5u7lqBBfc3JRM8Y bZgo+kiy+laS14WpS0F94WlX0uSeB0UzRFCRPOhc3TNI3zK4SY+q6p+fLDSFBV6qER SPdA9H0CHAdkg== Date: Wed, 3 Jul 2024 16:02:05 +0100 From: Will Deacon To: Rob Clark Cc: iommu@lists.linux.dev, linux-arm-msm@vger.kernel.org, Robin Murphy , Rob Clark , Joerg Roedel , Jason Gunthorpe , Steven Price , Boris Brezillon , Kevin Tian , Joao Martins , "moderated list:ARM SMMU DRIVERS" , open list Subject: Re: [PATCH v5 1/2] iommu/io-pgtable-arm: Add way to debug pgtable walk Message-ID: <20240703150205.GA6012@willie-the-truck> References: <20240626204033.255813-1-robdclark@gmail.com> <20240626204033.255813-2-robdclark@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240626204033.255813-2-robdclark@gmail.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240703_080212_852771_2EE28E02 X-CRM114-Status: GOOD ( 25.39 ) 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 Hi Rob, On Wed, Jun 26, 2024 at 01:40:26PM -0700, Rob Clark wrote: > 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 | 34 +++++++++++++++++++++++++--------- > include/linux/io-pgtable.h | 16 ++++++++++++++++ > 2 files changed, 41 insertions(+), 9 deletions(-) Non-technical question, but with patch 2/2 being drm-specific, how do you plan to get this merged this once it's finalised? I can take this part via the IOMMU tree? > +static phys_addr_t arm_lpae_iova_to_phys(struct io_pgtable_ops *ops, > + unsigned long iova) > +{ > + struct arm_lpae_io_pgtable *data = io_pgtable_ops_to_data(ops); > + struct io_pgtable_walk_data wd = {}; > + int ret, lvl; > + > + ret = arm_lpae_pgtable_walk(ops, iova, &wd); > + if (ret) > + return 0; > + > + lvl = wd.level + data->start_level; nit, but the level is architectural so I think we should initialise wd.level to data->start_level instead. > > -found_translation: > iova &= (ARM_LPAE_BLOCK_SIZE(lvl, data) - 1); > - return iopte_to_paddr(pte, data) | iova; > + return iopte_to_paddr(wd.ptes[wd.level - 1], data) | iova; > } > > static void arm_lpae_restrict_pgsizes(struct io_pgtable_cfg *cfg) > @@ -804,6 +819,7 @@ arm_lpae_alloc_pgtable(struct io_pgtable_cfg *cfg) > .map_pages = arm_lpae_map_pages, > .unmap_pages = arm_lpae_unmap_pages, > .iova_to_phys = arm_lpae_iova_to_phys, > + .pgtable_walk = arm_lpae_pgtable_walk, > }; > > return data; > diff --git a/include/linux/io-pgtable.h b/include/linux/io-pgtable.h > index 86cf1f7ae389..4d696724c7da 100644 > --- a/include/linux/io-pgtable.h > +++ b/include/linux/io-pgtable.h > @@ -171,12 +171,26 @@ struct io_pgtable_cfg { > }; > }; > > +/** > + * struct 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 io_pgtable_walk_data { > + u64 ptes[4]; > + int level; > +}; I wonder if we can do better than hardcoding the '4' here? I wouldn't be surprised if this doesn't work, but could we do something along the lines of: struct io_pgtable_walk_data { int level; int num_levels; u64 ptes[] __counted_by(num_levels); }; and then have the Arm (LPAE)-specific code wrap that in a private structure: struct arm_lpae_io_pgtable_walk_data { struct io_pgtable_walk_data data; u64 ptes[ARM_LPAE_MAX_LEVELS]; }; which is used by the walker? Will