Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754733AbbENBtb (ORCPT ); Wed, 13 May 2015 21:49:31 -0400 Received: from mailapp01.imgtec.com ([195.59.15.196]:6804 "EHLO mailapp01.imgtec.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754275AbbENBt3 (ORCPT ); Wed, 13 May 2015 21:49:29 -0400 Subject: [PATCH] MIPS: Flush cache after DMA_FROM_DEVICE for agressively speculative CPUs From: Leonid Yegoshin To: , , , , Date: Wed, 13 May 2015 18:49:24 -0700 Message-ID: <20150514014924.36593.68642.stgit@ubuntu-yegoshin> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.20.3.79] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2617 Lines: 64 Some MIPS CPUs have an aggressive speculative load and may erroneuosly load some cache line in the middle of DMA transaction. CPU discards result but cache doesn't. If DMA happens from device then additional cache invalidation is needed on that CPU's after DMA. Found in test. Signed-off-by: Leonid Yegoshin --- arch/mips/mm/dma-default.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/arch/mips/mm/dma-default.c b/arch/mips/mm/dma-default.c index 609d1241b0c4..ccf49ecfbf8c 100644 --- a/arch/mips/mm/dma-default.c +++ b/arch/mips/mm/dma-default.c @@ -67,11 +67,13 @@ static inline struct page *dma_addr_to_page(struct device *dev, * systems and only the R10000 and R12000 are used in such systems, the * SGI IP28 Indigo² rsp. SGI IP32 aka O2. */ -static inline int cpu_needs_post_dma_flush(struct device *dev) +static inline int cpu_needs_post_dma_flush(struct device *dev, + enum dma_data_direction direction) { return !plat_device_is_coherent(dev) && (boot_cpu_type() == CPU_R10000 || boot_cpu_type() == CPU_R12000 || + (cpu_has_maar && (direction != DMA_TO_DEVICE)) || boot_cpu_type() == CPU_BMIPS5000); } @@ -255,7 +257,7 @@ static inline void __dma_sync(struct page *page, static void mips_dma_unmap_page(struct device *dev, dma_addr_t dma_addr, size_t size, enum dma_data_direction direction, struct dma_attrs *attrs) { - if (cpu_needs_post_dma_flush(dev)) + if (cpu_needs_post_dma_flush(dev, direction)) __dma_sync(dma_addr_to_page(dev, dma_addr), dma_addr & ~PAGE_MASK, size, direction); plat_post_dma_flush(dev); @@ -309,7 +311,7 @@ static void mips_dma_unmap_sg(struct device *dev, struct scatterlist *sg, static void mips_dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size, enum dma_data_direction direction) { - if (cpu_needs_post_dma_flush(dev)) + if (cpu_needs_post_dma_flush(dev, direction)) __dma_sync(dma_addr_to_page(dev, dma_handle), dma_handle & ~PAGE_MASK, size, direction); plat_post_dma_flush(dev); @@ -328,7 +330,7 @@ static void mips_dma_sync_sg_for_cpu(struct device *dev, { int i; - if (cpu_needs_post_dma_flush(dev)) + if (cpu_needs_post_dma_flush(dev, direction)) for (i = 0; i < nelems; i++, sg++) __dma_sync(sg_page(sg), sg->offset, sg->length, direction); -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/