Commit 33dcb37c authored by Christoph Hellwig's avatar Christoph Hellwig
Browse files

dma-mapping: fix page attributes for dma_mmap_*



All the way back to introducing dma_common_mmap we've defaulted to mark
the pages as uncached.  But this is wrong for DMA coherent devices.
Later on DMA_ATTR_WRITE_COMBINE also got incorrect treatment as that
flag is only treated special on the alloc side for non-coherent devices.

Introduce a new dma_pgprot helper that deals with the check for coherent
devices so that only the remapping cases ever reach arch_dma_mmap_pgprot
and we thus ensure no aliasing of page attributes happens, which makes
the powerpc version of arch_dma_mmap_pgprot obsolete and simplifies the
remaining ones.

Note that this means arch_dma_mmap_pgprot is a bit misnamed now, but
we'll phase it out soon.

Fixes: 64ccc9c0 ("common: dma-mapping: add support for generic dma_mmap_* calls")
Reported-by: default avatarShawn Anastasio <shawn@anastas.io>
Reported-by: default avatarGavin Li <git@thegavinli.com>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Acked-by: Catalin Marinas <catalin.marinas@arm.com> # arm64
parent d8ad5553
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -2405,9 +2405,7 @@ long arch_dma_coherent_to_pfn(struct device *dev, void *cpu_addr,
pgprot_t arch_dma_mmap_pgprot(struct device *dev, pgprot_t prot,
		unsigned long attrs)
{
	if (!dev_is_dma_coherent(dev))
	return __get_dma_pgprot(attrs, prot);
	return prot;
}

void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
+1 −3
Original line number Diff line number Diff line
@@ -14,9 +14,7 @@
pgprot_t arch_dma_mmap_pgprot(struct device *dev, pgprot_t prot,
		unsigned long attrs)
{
	if (!dev_is_dma_coherent(dev) || (attrs & DMA_ATTR_WRITE_COMBINE))
	return pgprot_writecombine(prot);
	return prot;
}

void arch_sync_dma_for_device(struct device *dev, phys_addr_t paddr,
+0 −1
Original line number Diff line number Diff line
@@ -121,7 +121,6 @@ config PPC
	select ARCH_32BIT_OFF_T if PPC32
	select ARCH_HAS_DEBUG_VIRTUAL
	select ARCH_HAS_DEVMEM_IS_ALLOWED
	select ARCH_HAS_DMA_MMAP_PGPROT
	select ARCH_HAS_ELF_RANDOMIZE
	select ARCH_HAS_FORTIFY_SOURCE
	select ARCH_HAS_GCOV_PROFILE_ALL
+1 −2
Original line number Diff line number Diff line
@@ -49,8 +49,7 @@ obj-y := cputable.o ptrace.o syscalls.o \
				   signal.o sysfs.o cacheinfo.o time.o \
				   prom.o traps.o setup-common.o \
				   udbg.o misc.o io.o misc_$(BITS).o \
				   of_platform.o prom_parse.o \
				   dma-common.o
				   of_platform.o prom_parse.o
obj-$(CONFIG_PPC64)		+= setup_64.o sys_ppc32.o \
				   signal_64.o ptrace32.o \
				   paca.o nvram_64.o firmware.o

arch/powerpc/kernel/dma-common.c

deleted100644 → 0
+0 −17
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Contains common dma routines for all powerpc platforms.
 *
 * Copyright (C) 2019 Shawn Anastasio.
 */

#include <linux/mm.h>
#include <linux/dma-noncoherent.h>

pgprot_t arch_dma_mmap_pgprot(struct device *dev, pgprot_t prot,
		unsigned long attrs)
{
	if (!dev_is_dma_coherent(dev))
		return pgprot_noncached(prot);
	return prot;
}
Loading