From patchwork Thu Oct 6 07:48:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13000025 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 6C7B3C433FE for ; Thu, 6 Oct 2022 07:49:33 +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: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=fEa4i6i7EGs57Ef7aA3RNpRUI2XwluCWkbe5ZyyU2sA=; b=LIwq1ph75qoE6D 9nWOh6l6x3mTfSn00MudkIP4AmD1iTYCj9KheYXZs05N3VfJm14BPSXkooSlaeJ6Cqy0SQhk3yCER 5aux4pN8rITwHeZ1vvC2Fq1GOGGaFU/Dom2JYmNnM0YDmslN0uNEY60OTzHmncRci7VYDiIYF5VUW xhbnTiJWTypw6RB/PvsyWnX5t4gfAGoeBjEUIcplUJ0hLP9uKpf3m88xLIIuKtX/ibDvUQiQBSnap GxD+wzb3E08kw0gfmqP9iQjFHF/akEoJbPldswyiSZMN2zhQ74z3/XjsRHZYud4QNAqroehNS+8+E qCO2gJCRUPwn8mbonHCA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ogLcT-000UUw-2y; Thu, 06 Oct 2022 07:48:37 +0000 Received: from [2001:4bb8:180:b914:9f51:af7e:d950:bc8d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1ogLcL-000URq-T2; Thu, 06 Oct 2022 07:48:30 +0000 From: Christoph Hellwig To: Russell King Cc: Robin Murphy , linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev, =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 1/2] =?utf-8?q?ARM/dma-mapp=D1=96ng=3A_don=27t_override_-=3E?= =?utf-8?q?dma=5Fcoherent_when_set_from_a_bus_notifier?= Date: Thu, 6 Oct 2022 09:48:23 +0200 Message-Id: <20221006074824.521457-2-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221006074824.521457-1-hch@lst.de> References: <20221006074824.521457-1-hch@lst.de> MIME-Version: 1.0 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 Commit ae626eb97376 ("ARM/dma-mapping: use dma-direct unconditionally") caused a regression on the mvebu platform, wherein devices that are dma-coherent are marked as dma-noncoherent, because although mvebu_hwcc_notifier() after that commit still marks then as coherent, the arm_coherent_dma_ops() function, which is called later, overwrites this setting, since it is being called from drivers/of/device.c with coherency parameter determined by of_dma_is_coherent(), and the device-trees do not declare the 'dma-coherent' property. Fix this by defaulting never clearing the dma_coherent flag in arm_coherent_dma_ops(). Fixes: ae626eb97376 ("ARM/dma-mapping: use dma-direct unconditionally") Reported-by: Marek BehĂșn Tested-by: Marek BehĂșn --- arch/arm/mm/dma-mapping.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index 089c9c644cce2..bfc7476f14114 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -1769,8 +1769,16 @@ static void arm_teardown_iommu_dma_ops(struct device *dev) { } void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, const struct iommu_ops *iommu, bool coherent) { - dev->archdata.dma_coherent = coherent; - dev->dma_coherent = coherent; + /* + * Due to legacy code that sets the ->dma_coherent flag from a bus + * notifier we can't just assign coherent to the ->dma_coherent flag + * here, but instead have to make sure we only set but never clear it + * for now. + */ + if (coherent) { + dev->archdata.dma_coherent = true; + dev->dma_coherent = true; + } /* * Don't override the dma_ops if they have already been set. Ideally From patchwork Thu Oct 6 07:48:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13000026 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 AD5AFC4332F for ; Thu, 6 Oct 2022 07:49:34 +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: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=KpBVk4Y0nRf/kxl2CQ4LUwCd4OUtZdEhg6EHHJ3+QvA=; b=vpgw5rLExaspCs qqP4JUzI4shpfACAfrQwn3Dao70cYn1RO0vX95rZz6/NeDJHaSfus4tknCQK3Ukn0VNSEynyGT5OS pBGmMR+2w0nH5IALF9LM92CzCVetbriSoxZ+JdnIWNstZ17DnQ7WzbJpmgtooRk2jalql50mA80Tq 1VVbB8MvHhjNNEAx5JNlYSD682LZs6l5zFqAz0JT2L6lNrmQJNMMGP++u7a2VQbGpRLIVQh8SIyQS FgExi6PWviU7NrcWTNP4hVzqilGygNc1JjaFrUTsOnXd3bmY+6plFjW/xO98nb0jcIvJx4Lan3kQ1 pb53jEBm4aD/hkdishWw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ogLca-000UYh-Ty; Thu, 06 Oct 2022 07:48:45 +0000 Received: from [2001:4bb8:180:b914:9f51:af7e:d950:bc8d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1ogLcO-000USl-Ou; Thu, 06 Oct 2022 07:48:33 +0000 From: Christoph Hellwig To: Russell King Cc: Robin Murphy , linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev, =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 2/2] ARM/dma-mapping: remove the dma_coherent member of struct dev_archdata Date: Thu, 6 Oct 2022 09:48:24 +0200 Message-Id: <20221006074824.521457-3-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221006074824.521457-1-hch@lst.de> References: <20221006074824.521457-1-hch@lst.de> MIME-Version: 1.0 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 Since commit ae626eb97376 ("ARM/dma-mapping: use dma-direct unconditionally") only the dma_coherent flag in struct device is used, so remove the now write only flag in struct dev_archdata. Signed-off-by: Christoph Hellwig --- arch/arm/include/asm/device.h | 1 - arch/arm/mm/dma-mapping.c | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/arch/arm/include/asm/device.h b/arch/arm/include/asm/device.h index 8754c0f5fc904..c6beb1708c64b 100644 --- a/arch/arm/include/asm/device.h +++ b/arch/arm/include/asm/device.h @@ -9,7 +9,6 @@ struct dev_archdata { #ifdef CONFIG_ARM_DMA_USE_IOMMU struct dma_iommu_mapping *mapping; #endif - unsigned int dma_coherent:1; unsigned int dma_ops_setup:1; }; diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index bfc7476f14114..f60d6b4afe5df 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -1775,10 +1775,8 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, * here, but instead have to make sure we only set but never clear it * for now. */ - if (coherent) { - dev->archdata.dma_coherent = true; + if (coherent) dev->dma_coherent = true; - } /* * Don't override the dma_ops if they have already been set. Ideally