Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp6489079rwd; Mon, 19 Jun 2023 08:01:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ41eLRZtR27iHD+S77pxm7kATVthhmPIXTXqDfhsY2J7AcnZHqOCPalFwaOb4kfGxi+SCaa X-Received: by 2002:a17:902:d509:b0:1b3:d418:7599 with SMTP id b9-20020a170902d50900b001b3d4187599mr1183635plg.13.1687186898422; Mon, 19 Jun 2023 08:01:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687186898; cv=none; d=google.com; s=arc-20160816; b=ojop2uA0vtxTpeR6PbTA7MKLTKRk/iigIMPIVRy0stVJY1vxE9Ph8gaqqgoGDExddR b0qiF2WixHnUCQYcbRxeRCGV//mszdTopoVTwa2DXtFTdcu6nQrFvBzBrGnuXwe11BqB lWWZc/hOhrh8uW5OYZgmqcmgpN9bO/1ik7XCEa2cOCEsS6+gNb7F212TLKKYx1b6eK8a mn6DZljoFtCkECYjTKtOXsD5lKae5Bg738GXtWb6lFaU+kKp2kOWD4auwslFp0l2Z8AX ItXASuN+xEdI3UMo8wiGQ9QTc15hdb6LulhP3uWSATu/uaY91otHXo9fmNlL0mBQlFux L0Cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=RM2d725kxM4YfJKGZEHc2Fd/WQ2Xqhz1cqH9UM4aP+E=; b=jL5sLJV8gBKM6LU5WdkrPMJYbMnAJ7L/zYsWPIZfwCg+0NuEMIFaR0jS7tzYja/jTN Ka7CyRwWWrfOtqD4HDyoxPugphZeaadEuI613RRd/+0tSvUIsUGe56dMQ6G7MX29nLpP Xfp76/CMD/ovW6QePbje49UV+//lW15uywXmHnklnKNKCKpvWn19giqQG5zrcJGpUX0o CI9VjmW1WyJja/wATId+PYPDi7x1TfClgZmtCtFh+jdG7+q5zcS64zFAxk/c+JQRSto4 xePWP6v8r7A79fWeP5aCc52tf+VMu4rwhWCe6emaOMCvbQFiFxL/itnTzbJ6efHkUc3N 1V4A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x3-20020a1709028ec300b001a963979936si20219463plo.153.2023.06.19.08.01.14; Mon, 19 Jun 2023 08:01:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229894AbjFSOcw (ORCPT + 99 others); Mon, 19 Jun 2023 10:32:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229649AbjFSOcu (ORCPT ); Mon, 19 Jun 2023 10:32:50 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CBC81F1 for ; Mon, 19 Jun 2023 07:32:48 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 60E2912FC; Mon, 19 Jun 2023 07:33:32 -0700 (PDT) Received: from [10.1.196.40] (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 58EC53F59C; Mon, 19 Jun 2023 07:32:47 -0700 (PDT) Message-ID: Date: Mon, 19 Jun 2023 15:32:42 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH v3 1/2] iommu: rockchip: Fix directory table address encoding Content-Language: en-GB To: Jonas Karlman , Joerg Roedel , Will Deacon , Heiko Stuebner , Benjamin Gaignard Cc: iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, Joerg Roedel References: <20230617182540.3091374-1-jonas@kwiboo.se> <20230617182540.3091374-2-jonas@kwiboo.se> From: Robin Murphy In-Reply-To: <20230617182540.3091374-2-jonas@kwiboo.se> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 On 17/06/2023 7:25 pm, Jonas Karlman wrote: > The physical address to the directory table is currently encoded using > the following bit layout for IOMMU v2. > > 31:12 - Address bit 31:0 > 11: 4 - Address bit 39:32 > > This is also the bit layout used by the vendor kernel. > > However, testing has shown that addresses to the directory/page tables > and memory pages are all encoded using the same bit layout. > > IOMMU v1: > 31:12 - Address bit 31:0 > > IOMMU v2: > 31:12 - Address bit 31:0 > 11: 8 - Address bit 35:32 > 7: 4 - Address bit 39:36 > > Change to use the mk_dtentries ops to encode the directory table address > correctly. The value written to DTE_ADDR may include the valid bit set, > a bit that is ignored and DTE_ADDR reg read it back as 0. > > This also update the bit layout comment for the page address and the > number of nybbles that are read back for DTE_ADDR comment. > > These changes render the dte_addr_phys and dma_addr_dte ops unused and > is removed. Reviewed-by: Robin Murphy > Fixes: 227014b33f62 ("iommu: rockchip: Add internal ops to handle variants") > Fixes: c55356c534aa ("iommu: rockchip: Add support for iommu v2") > Fixes: c987b65a574f ("iommu/rockchip: Fix physical address decoding") > Signed-off-by: Jonas Karlman > --- > v3: > - squash removal of unused ops into this patch > - update commit message > > v2: > - replace currently with correctly in commit message > > drivers/iommu/rockchip-iommu.c | 43 ++++------------------------------ > 1 file changed, 5 insertions(+), 38 deletions(-) > > diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c > index 4054030c3237..ae42959bc490 100644 > --- a/drivers/iommu/rockchip-iommu.c > +++ b/drivers/iommu/rockchip-iommu.c > @@ -98,8 +98,6 @@ struct rk_iommu_ops { > phys_addr_t (*pt_address)(u32 dte); > u32 (*mk_dtentries)(dma_addr_t pt_dma); > u32 (*mk_ptentries)(phys_addr_t page, int prot); > - phys_addr_t (*dte_addr_phys)(u32 addr); > - u32 (*dma_addr_dte)(dma_addr_t dt_dma); > u64 dma_bit_mask; > }; > > @@ -278,8 +276,8 @@ static u32 rk_mk_pte(phys_addr_t page, int prot) > /* > * In v2: > * 31:12 - Page address bit 31:0 > - * 11:9 - Page address bit 34:32 > - * 8:4 - Page address bit 39:35 > + * 11: 8 - Page address bit 35:32 > + * 7: 4 - Page address bit 39:36 > * 3 - Security > * 2 - Writable > * 1 - Readable > @@ -506,7 +504,7 @@ static int rk_iommu_force_reset(struct rk_iommu *iommu) > > /* > * Check if register DTE_ADDR is working by writing DTE_ADDR_DUMMY > - * and verifying that upper 5 nybbles are read back. > + * and verifying that upper 5 (v1) or 7 (v2) nybbles are read back. > */ > for (i = 0; i < iommu->num_mmu; i++) { > dte_addr = rk_ops->pt_address(DTE_ADDR_DUMMY); > @@ -531,33 +529,6 @@ static int rk_iommu_force_reset(struct rk_iommu *iommu) > return 0; > } > > -static inline phys_addr_t rk_dte_addr_phys(u32 addr) > -{ > - return (phys_addr_t)addr; > -} > - > -static inline u32 rk_dma_addr_dte(dma_addr_t dt_dma) > -{ > - return dt_dma; > -} > - > -#define DT_HI_MASK GENMASK_ULL(39, 32) > -#define DTE_BASE_HI_MASK GENMASK(11, 4) > -#define DT_SHIFT 28 > - > -static inline phys_addr_t rk_dte_addr_phys_v2(u32 addr) > -{ > - u64 addr64 = addr; > - return (phys_addr_t)(addr64 & RK_DTE_PT_ADDRESS_MASK) | > - ((addr64 & DTE_BASE_HI_MASK) << DT_SHIFT); > -} > - > -static inline u32 rk_dma_addr_dte_v2(dma_addr_t dt_dma) > -{ > - return (dt_dma & RK_DTE_PT_ADDRESS_MASK) | > - ((dt_dma & DT_HI_MASK) >> DT_SHIFT); > -} > - > static void log_iova(struct rk_iommu *iommu, int index, dma_addr_t iova) > { > void __iomem *base = iommu->bases[index]; > @@ -577,7 +548,7 @@ static void log_iova(struct rk_iommu *iommu, int index, dma_addr_t iova) > page_offset = rk_iova_page_offset(iova); > > mmu_dte_addr = rk_iommu_read(base, RK_MMU_DTE_ADDR); > - mmu_dte_addr_phys = rk_ops->dte_addr_phys(mmu_dte_addr); > + mmu_dte_addr_phys = rk_ops->pt_address(mmu_dte_addr); > > dte_addr_phys = mmu_dte_addr_phys + (4 * dte_index); > dte_addr = phys_to_virt(dte_addr_phys); > @@ -967,7 +938,7 @@ static int rk_iommu_enable(struct rk_iommu *iommu) > > for (i = 0; i < iommu->num_mmu; i++) { > rk_iommu_write(iommu->bases[i], RK_MMU_DTE_ADDR, > - rk_ops->dma_addr_dte(rk_domain->dt_dma)); > + rk_ops->mk_dtentries(rk_domain->dt_dma)); > rk_iommu_base_command(iommu->bases[i], RK_MMU_CMD_ZAP_CACHE); > rk_iommu_write(iommu->bases[i], RK_MMU_INT_MASK, RK_MMU_IRQ_MASK); > } > @@ -1405,8 +1376,6 @@ static struct rk_iommu_ops iommu_data_ops_v1 = { > .pt_address = &rk_dte_pt_address, > .mk_dtentries = &rk_mk_dte, > .mk_ptentries = &rk_mk_pte, > - .dte_addr_phys = &rk_dte_addr_phys, > - .dma_addr_dte = &rk_dma_addr_dte, > .dma_bit_mask = DMA_BIT_MASK(32), > }; > > @@ -1414,8 +1383,6 @@ static struct rk_iommu_ops iommu_data_ops_v2 = { > .pt_address = &rk_dte_pt_address_v2, > .mk_dtentries = &rk_mk_dte_v2, > .mk_ptentries = &rk_mk_pte_v2, > - .dte_addr_phys = &rk_dte_addr_phys_v2, > - .dma_addr_dte = &rk_dma_addr_dte_v2, > .dma_bit_mask = DMA_BIT_MASK(40), > }; >