From patchwork Sat Jun 17 18:25:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Karlman X-Patchwork-Id: 13283697 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 D0353EB64D9 for ; Sat, 17 Jun 2023 18:26:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:MIME-Version:Message-Id:Date: Subject:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=63+oLNcUONwaI4UZfldV1TcLSxNKWQdMeKIMZN7nSyo=; b=y6qlWPPAfvmpjd EEDuZafI7RCxx5dFY5uQ1l9Fg7b1gFU8f1Uarv+Ly6hb5M9FJ8lqKfAY0asCasBnnc3kUpcNaeZcq 9G392KFiPwOfcBpydNGQbr431sHrdD2cinIlNTS+V8HSDt0wjSJ4wrDbOr27HKtmHIC2ifU5jiNRE aHC2fkOhA6Ldge+XUUn11jy7OzxwqP2eDdCwqTuJzO5OqsjjodmEp1Kd9bF1UnDuLq7bMqi6JbBwK hdRV1aulvUasE3rip4g8mndxg3rPB5Y6Eq4iyFz+CrJa9DnvMVYmO3cMtWHpniGqbn0ZpRE7K3VZt 7D7BOgtcKYHg6cxKmkvA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qAacR-00461a-1p; Sat, 17 Jun 2023 18:25:51 +0000 Received: from s.wrqvwxzv.outbound-mail.sendgrid.net ([149.72.154.232]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qAacO-0045zo-1F for linux-arm-kernel@lists.infradead.org; Sat, 17 Jun 2023 18:25:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kwiboo.se; h=from:subject:mime-version:to:cc:content-transfer-encoding: content-type:cc:content-type:from:subject:to; s=s1; bh=EZjVZREN01PWnkecDc4m5lCo/JtuKVVXTJsEdeEOdg8=; b=hQDnLUHbQZH9KfpZwBRovWXzOu/XVbbjTrf3x1f6Dy5nxloVFie4p2zywi6melbP46GZ /fa3V+mdDUVCSeSkF9Fn4PWKGzoonbL/iBsAf0lHvKzJWxGOJbS5LTEn/lya3lNIIhKG38 KuabaFAJ1KJVyJ9SisKR0BltkU8mpg6G+KGEHEQywZ17ywqFERJPnXQF3Qy3Ja1KmQUpDF HGZ/Vq1vJlGASgSp1ASaXO5ILstboC1IyDMnW4GJvA1aFun+8RpL+b5tKdLXFfVRMvxD91 wbcKS/bYbacqyP/YTrnachADeSsbRQ3P/DP+B6MJup0mmcO+BnJ6FmR4zeilxJqw== Received: by filterdrecv-d7bbbc8bf-zf9x9 with SMTP id filterdrecv-d7bbbc8bf-zf9x9-1-648DFAA7-10 2023-06-17 18:25:43.829440288 +0000 UTC m=+3264351.627270026 Received: from bionic.localdomain (unknown) by geopod-ismtpd-9 (SG) with ESMTP id Nw1GHX5WQdWvCqSwbmqvyw Sat, 17 Jun 2023 18:25:43.459 +0000 (UTC) From: Jonas Karlman Subject: [PATCH v3 0/2] iommu: rockchip: Fix directory table address encoding Date: Sat, 17 Jun 2023 18:25:44 +0000 (UTC) Message-Id: <20230617182540.3091374-1-jonas@kwiboo.se> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-SG-EID: TdbjyGynYnRZWhH+7lKUQJL+ZxmxpowvO2O9SQF5CwCVrYgcwUXgU5DKUU3QxAfZekEeQsTe+RrMu3cja6a0h4BqyTv2htkF2lNGw0iSDwD2SgTmfxp5qa7u3fdNgmCQtZ+zr8KKPzgjbaUueHLCyyWpIyByEJgWIV0EZo4DoeET8F7X8RhR4Bi6K924YkR0wwJ4VnjEaFuhexwAENEcIJahJ0N5HIJwKF/lJrhGaR1m2z3/XLr3t6rvSNqmxxw9JOIrKZK0/fAb079SSGRKAA== To: Joerg Roedel , Will Deacon , Robin Murphy , Heiko Stuebner Cc: Benjamin Gaignard , iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, Jonas Karlman X-Entity-ID: P7KYpSJvGCELWjBME/J5tg== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230617_112549_096938_7C9D52DF X-CRM114-Status: GOOD ( 12.41 ) 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 The address to the directory table is currently encoded using an incorrect bit layout when configured into the DTE_ADDR reg on IOMMU v2. This currently do not cause any issue because the directory and page tables is allocated in memory below 4GB thanks to the use of the GFP_DMA32 flag. Testing has shown that the directory table address should be encoded using the same bit layout as the page table and memory page addresses. Only removing the GFP_DMA32 on a RK3568 device with 8GB of memory will result in a page fault similar to: [ 0.907236] rk_iommu fe043e00.iommu: Page fault at 0x00000000ff801000 of type read [ 0.907264] rk_iommu fe043e00.iommu: iova = 0x00000000ff801000: dte_index: 0x3fe pte_index: 0x1 page_offset: 0x0 [ 0.907281] rk_iommu fe043e00.iommu: mmu_dte_addr: 0x000000010189a000 dte@0x000000010189aff8: 0x1722101 valid: 1 pte@0x0000000101722004: 0x2c01107 valid: 1 page@0x0000000102c01000 flags: 0x106 This series fixes this by using the existing mk_dtentries instead of the dma_addr_dte ops to encode the directory table address, removes unused ops and finally removes the GFP_DMA32 flag to allow for directory and page tables to be allocated in memory above 4GB on IOMMU v2. Changes in v3: - merge patch 1 and 2 - only remove GFP_DMA32 flag for IOMMU v2 Changes in v2: - no changes, rebased on next-20230615 This series can also be found at [1]. [1] https://github.com/Kwiboo/linux-rockchip/commits/next-20230616-iommu Jonas Karlman (2): iommu: rockchip: Fix directory table address encoding iommu: rockchip: Allocate tables from all available memory for IOMMU v2 drivers/iommu/rockchip-iommu.c | 50 +++++++--------------------------- 1 file changed, 10 insertions(+), 40 deletions(-)