mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-26 06:33:19 -04:00
Linux 4.18
-----BEGIN PGP SIGNATURE-----
iQFSBAABCAA8FiEEq68RxlopcLEwq+PEeb4+QwBBGIYFAltwm2geHHRvcnZhbGRz
QGxpbnV4LWZvdW5kYXRpb24ub3JnAAoJEHm+PkMAQRiGITkH/iSzkVhT2OxHoir0
mLVzTi7/Z17L0e/ELl7TvAC0iLFlWZKdlGR0g3b4/QpXLPmNK4HxiDRTQuWn8ke0
qDZyDq89HqLt+mpeFZ43PCd9oqV8CH2xxK3iCWReqv6bNnowGnRpSStlks4rDqWn
zURC/5sUh7TzEG4s997RrrpnyPeQWUlf/Mhtzg2/WvK2btoLWgu5qzjX1uFh3s7u
vaF2NXVJ3X03gPktyxZzwtO1SwLFS1jhwUXWBZ5AnoJ99ywkghQnkqS/2YpekNTm
wFk80/78sU+d91aAqO8kkhHj8VRrd+9SGnZ4mB2aZHwjZjGcics4RRtxukSfOQ+6
L47IdXo=
=sJkt
-----END PGP SIGNATURE-----
Merge tag 'v4.18' into rdma.git for-next
Resolve merge conflicts from the -rc cycle against the rdma.git tree:
Conflicts:
drivers/infiniband/core/uverbs_cmd.c
- New ifs added to ib_uverbs_ex_create_flow in -rc and for-next
- Merge removal of file->ucontext in for-next with new code in -rc
drivers/infiniband/core/uverbs_main.c
- for-next removed code from ib_uverbs_write() that was modified
in for-rc
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
This commit is contained in:
commit
89982f7cce
1684 changed files with 18047 additions and 9534 deletions
47
lib/Kconfig
47
lib/Kconfig
|
|
@ -420,60 +420,15 @@ config HAS_IOPORT_MAP
|
|||
depends on HAS_IOMEM && !NO_IOPORT_MAP
|
||||
default y
|
||||
|
||||
config HAS_DMA
|
||||
bool
|
||||
depends on !NO_DMA
|
||||
default y
|
||||
source "kernel/dma/Kconfig"
|
||||
|
||||
config SGL_ALLOC
|
||||
bool
|
||||
default n
|
||||
|
||||
config NEED_SG_DMA_LENGTH
|
||||
bool
|
||||
|
||||
config NEED_DMA_MAP_STATE
|
||||
bool
|
||||
|
||||
config ARCH_DMA_ADDR_T_64BIT
|
||||
def_bool 64BIT || PHYS_ADDR_T_64BIT
|
||||
|
||||
config IOMMU_HELPER
|
||||
bool
|
||||
|
||||
config ARCH_HAS_SYNC_DMA_FOR_DEVICE
|
||||
bool
|
||||
|
||||
config ARCH_HAS_SYNC_DMA_FOR_CPU
|
||||
bool
|
||||
select NEED_DMA_MAP_STATE
|
||||
|
||||
config DMA_DIRECT_OPS
|
||||
bool
|
||||
depends on HAS_DMA
|
||||
|
||||
config DMA_NONCOHERENT_OPS
|
||||
bool
|
||||
depends on HAS_DMA
|
||||
select DMA_DIRECT_OPS
|
||||
|
||||
config DMA_NONCOHERENT_MMAP
|
||||
bool
|
||||
depends on DMA_NONCOHERENT_OPS
|
||||
|
||||
config DMA_NONCOHERENT_CACHE_SYNC
|
||||
bool
|
||||
depends on DMA_NONCOHERENT_OPS
|
||||
|
||||
config DMA_VIRT_OPS
|
||||
bool
|
||||
depends on HAS_DMA
|
||||
|
||||
config SWIOTLB
|
||||
bool
|
||||
select DMA_DIRECT_OPS
|
||||
select NEED_DMA_MAP_STATE
|
||||
|
||||
config CHECK_SIGNATURE
|
||||
bool
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@ if HAVE_ARCH_KASAN
|
|||
|
||||
config KASAN
|
||||
bool "KASan: runtime memory debugger"
|
||||
depends on SLUB || (SLAB && !DEBUG_SLAB)
|
||||
depends on (SLUB && SYSFS) || (SLAB && !DEBUG_SLAB)
|
||||
select SLUB_DEBUG if SLUB
|
||||
select CONSTRUCTORS
|
||||
select STACKDEPOT
|
||||
help
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
config ARCH_HAS_UBSAN_SANITIZE_ALL
|
||||
bool
|
||||
|
||||
config ARCH_WANTS_UBSAN_NO_NULL
|
||||
def_bool n
|
||||
|
||||
config UBSAN
|
||||
bool "Undefined behaviour sanity checker"
|
||||
help
|
||||
|
|
@ -39,14 +36,6 @@ config UBSAN_ALIGNMENT
|
|||
Enabling this option on architectures that support unaligned
|
||||
accesses may produce a lot of false positives.
|
||||
|
||||
config UBSAN_NULL
|
||||
bool "Enable checking of null pointers"
|
||||
depends on UBSAN
|
||||
default y if !ARCH_WANTS_UBSAN_NO_NULL
|
||||
help
|
||||
This option enables detection of memory accesses via a
|
||||
null pointer.
|
||||
|
||||
config TEST_UBSAN
|
||||
tristate "Module for testing for undefined behavior detection"
|
||||
depends on m && UBSAN
|
||||
|
|
|
|||
12
lib/Makefile
12
lib/Makefile
|
|
@ -23,15 +23,12 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \
|
|||
sha1.o chacha20.o irq_regs.o argv_split.o \
|
||||
flex_proportions.o ratelimit.o show_mem.o \
|
||||
is_single_threaded.o plist.o decompress.o kobject_uevent.o \
|
||||
earlycpio.o seq_buf.o siphash.o \
|
||||
earlycpio.o seq_buf.o siphash.o dec_and_lock.o \
|
||||
nmi_backtrace.o nodemask.o win_minmax.o
|
||||
|
||||
lib-$(CONFIG_PRINTK) += dump_stack.o
|
||||
lib-$(CONFIG_MMU) += ioremap.o
|
||||
lib-$(CONFIG_SMP) += cpumask.o
|
||||
lib-$(CONFIG_DMA_DIRECT_OPS) += dma-direct.o
|
||||
lib-$(CONFIG_DMA_NONCOHERENT_OPS) += dma-noncoherent.o
|
||||
lib-$(CONFIG_DMA_VIRT_OPS) += dma-virt.o
|
||||
|
||||
lib-y += kobject.o klist.o
|
||||
obj-y += lockref.o
|
||||
|
|
@ -98,10 +95,6 @@ obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
|
|||
obj-$(CONFIG_DEBUG_LIST) += list_debug.o
|
||||
obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
|
||||
|
||||
ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
|
||||
lib-y += dec_and_lock.o
|
||||
endif
|
||||
|
||||
obj-$(CONFIG_BITREVERSE) += bitrev.o
|
||||
obj-$(CONFIG_RATIONAL) += rational.o
|
||||
obj-$(CONFIG_CRC_CCITT) += crc-ccitt.o
|
||||
|
|
@ -148,7 +141,6 @@ obj-$(CONFIG_SMP) += percpu_counter.o
|
|||
obj-$(CONFIG_AUDIT_GENERIC) += audit.o
|
||||
obj-$(CONFIG_AUDIT_COMPAT_GENERIC) += compat_audit.o
|
||||
|
||||
obj-$(CONFIG_SWIOTLB) += swiotlb.o
|
||||
obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.o
|
||||
obj-$(CONFIG_FAULT_INJECTION) += fault-inject.o
|
||||
obj-$(CONFIG_NOTIFIER_ERROR_INJECTION) += notifier-error-inject.o
|
||||
|
|
@ -169,8 +161,6 @@ obj-$(CONFIG_NLATTR) += nlattr.o
|
|||
|
||||
obj-$(CONFIG_LRU_CACHE) += lru_cache.o
|
||||
|
||||
obj-$(CONFIG_DMA_API_DEBUG) += dma-debug.o
|
||||
|
||||
obj-$(CONFIG_GENERIC_CSUM) += checksum.o
|
||||
|
||||
obj-$(CONFIG_GENERIC_ATOMIC64) += atomic64.o
|
||||
|
|
|
|||
|
|
@ -33,3 +33,19 @@ int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock)
|
|||
}
|
||||
|
||||
EXPORT_SYMBOL(_atomic_dec_and_lock);
|
||||
|
||||
int _atomic_dec_and_lock_irqsave(atomic_t *atomic, spinlock_t *lock,
|
||||
unsigned long *flags)
|
||||
{
|
||||
/* Subtract 1 from counter unless that drops it to 0 (ie. it was 1) */
|
||||
if (atomic_add_unless(atomic, -1, 1))
|
||||
return 0;
|
||||
|
||||
/* Otherwise do it the slow way */
|
||||
spin_lock_irqsave(lock, *flags);
|
||||
if (atomic_dec_and_test(atomic))
|
||||
return 1;
|
||||
spin_unlock_irqrestore(lock, *flags);
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(_atomic_dec_and_lock_irqsave);
|
||||
|
|
|
|||
1773
lib/dma-debug.c
1773
lib/dma-debug.c
File diff suppressed because it is too large
Load diff
204
lib/dma-direct.c
204
lib/dma-direct.c
|
|
@ -1,204 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* DMA operations that map physical memory directly without using an IOMMU or
|
||||
* flushing caches.
|
||||
*/
|
||||
#include <linux/export.h>
|
||||
#include <linux/mm.h>
|
||||
#include <linux/dma-direct.h>
|
||||
#include <linux/scatterlist.h>
|
||||
#include <linux/dma-contiguous.h>
|
||||
#include <linux/pfn.h>
|
||||
#include <linux/set_memory.h>
|
||||
|
||||
#define DIRECT_MAPPING_ERROR 0
|
||||
|
||||
/*
|
||||
* Most architectures use ZONE_DMA for the first 16 Megabytes, but
|
||||
* some use it for entirely different regions:
|
||||
*/
|
||||
#ifndef ARCH_ZONE_DMA_BITS
|
||||
#define ARCH_ZONE_DMA_BITS 24
|
||||
#endif
|
||||
|
||||
/*
|
||||
* For AMD SEV all DMA must be to unencrypted addresses.
|
||||
*/
|
||||
static inline bool force_dma_unencrypted(void)
|
||||
{
|
||||
return sev_active();
|
||||
}
|
||||
|
||||
static bool
|
||||
check_addr(struct device *dev, dma_addr_t dma_addr, size_t size,
|
||||
const char *caller)
|
||||
{
|
||||
if (unlikely(dev && !dma_capable(dev, dma_addr, size))) {
|
||||
if (!dev->dma_mask) {
|
||||
dev_err(dev,
|
||||
"%s: call on device without dma_mask\n",
|
||||
caller);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (*dev->dma_mask >= DMA_BIT_MASK(32)) {
|
||||
dev_err(dev,
|
||||
"%s: overflow %pad+%zu of device mask %llx\n",
|
||||
caller, &dma_addr, size, *dev->dma_mask);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool dma_coherent_ok(struct device *dev, phys_addr_t phys, size_t size)
|
||||
{
|
||||
dma_addr_t addr = force_dma_unencrypted() ?
|
||||
__phys_to_dma(dev, phys) : phys_to_dma(dev, phys);
|
||||
return addr + size - 1 <= dev->coherent_dma_mask;
|
||||
}
|
||||
|
||||
void *dma_direct_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
|
||||
gfp_t gfp, unsigned long attrs)
|
||||
{
|
||||
unsigned int count = PAGE_ALIGN(size) >> PAGE_SHIFT;
|
||||
int page_order = get_order(size);
|
||||
struct page *page = NULL;
|
||||
void *ret;
|
||||
|
||||
/* we always manually zero the memory once we are done: */
|
||||
gfp &= ~__GFP_ZERO;
|
||||
|
||||
/* GFP_DMA32 and GFP_DMA are no ops without the corresponding zones: */
|
||||
if (dev->coherent_dma_mask <= DMA_BIT_MASK(ARCH_ZONE_DMA_BITS))
|
||||
gfp |= GFP_DMA;
|
||||
if (dev->coherent_dma_mask <= DMA_BIT_MASK(32) && !(gfp & GFP_DMA))
|
||||
gfp |= GFP_DMA32;
|
||||
|
||||
again:
|
||||
/* CMA can be used only in the context which permits sleeping */
|
||||
if (gfpflags_allow_blocking(gfp)) {
|
||||
page = dma_alloc_from_contiguous(dev, count, page_order, gfp);
|
||||
if (page && !dma_coherent_ok(dev, page_to_phys(page), size)) {
|
||||
dma_release_from_contiguous(dev, page, count);
|
||||
page = NULL;
|
||||
}
|
||||
}
|
||||
if (!page)
|
||||
page = alloc_pages_node(dev_to_node(dev), gfp, page_order);
|
||||
|
||||
if (page && !dma_coherent_ok(dev, page_to_phys(page), size)) {
|
||||
__free_pages(page, page_order);
|
||||
page = NULL;
|
||||
|
||||
if (IS_ENABLED(CONFIG_ZONE_DMA32) &&
|
||||
dev->coherent_dma_mask < DMA_BIT_MASK(64) &&
|
||||
!(gfp & (GFP_DMA32 | GFP_DMA))) {
|
||||
gfp |= GFP_DMA32;
|
||||
goto again;
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_ZONE_DMA) &&
|
||||
dev->coherent_dma_mask < DMA_BIT_MASK(32) &&
|
||||
!(gfp & GFP_DMA)) {
|
||||
gfp = (gfp & ~GFP_DMA32) | GFP_DMA;
|
||||
goto again;
|
||||
}
|
||||
}
|
||||
|
||||
if (!page)
|
||||
return NULL;
|
||||
ret = page_address(page);
|
||||
if (force_dma_unencrypted()) {
|
||||
set_memory_decrypted((unsigned long)ret, 1 << page_order);
|
||||
*dma_handle = __phys_to_dma(dev, page_to_phys(page));
|
||||
} else {
|
||||
*dma_handle = phys_to_dma(dev, page_to_phys(page));
|
||||
}
|
||||
memset(ret, 0, size);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* NOTE: this function must never look at the dma_addr argument, because we want
|
||||
* to be able to use it as a helper for iommu implementations as well.
|
||||
*/
|
||||
void dma_direct_free(struct device *dev, size_t size, void *cpu_addr,
|
||||
dma_addr_t dma_addr, unsigned long attrs)
|
||||
{
|
||||
unsigned int count = PAGE_ALIGN(size) >> PAGE_SHIFT;
|
||||
unsigned int page_order = get_order(size);
|
||||
|
||||
if (force_dma_unencrypted())
|
||||
set_memory_encrypted((unsigned long)cpu_addr, 1 << page_order);
|
||||
if (!dma_release_from_contiguous(dev, virt_to_page(cpu_addr), count))
|
||||
free_pages((unsigned long)cpu_addr, page_order);
|
||||
}
|
||||
|
||||
dma_addr_t dma_direct_map_page(struct device *dev, struct page *page,
|
||||
unsigned long offset, size_t size, enum dma_data_direction dir,
|
||||
unsigned long attrs)
|
||||
{
|
||||
dma_addr_t dma_addr = phys_to_dma(dev, page_to_phys(page)) + offset;
|
||||
|
||||
if (!check_addr(dev, dma_addr, size, __func__))
|
||||
return DIRECT_MAPPING_ERROR;
|
||||
return dma_addr;
|
||||
}
|
||||
|
||||
int dma_direct_map_sg(struct device *dev, struct scatterlist *sgl, int nents,
|
||||
enum dma_data_direction dir, unsigned long attrs)
|
||||
{
|
||||
int i;
|
||||
struct scatterlist *sg;
|
||||
|
||||
for_each_sg(sgl, sg, nents, i) {
|
||||
BUG_ON(!sg_page(sg));
|
||||
|
||||
sg_dma_address(sg) = phys_to_dma(dev, sg_phys(sg));
|
||||
if (!check_addr(dev, sg_dma_address(sg), sg->length, __func__))
|
||||
return 0;
|
||||
sg_dma_len(sg) = sg->length;
|
||||
}
|
||||
|
||||
return nents;
|
||||
}
|
||||
|
||||
int dma_direct_supported(struct device *dev, u64 mask)
|
||||
{
|
||||
#ifdef CONFIG_ZONE_DMA
|
||||
if (mask < DMA_BIT_MASK(ARCH_ZONE_DMA_BITS))
|
||||
return 0;
|
||||
#else
|
||||
/*
|
||||
* Because 32-bit DMA masks are so common we expect every architecture
|
||||
* to be able to satisfy them - either by not supporting more physical
|
||||
* memory, or by providing a ZONE_DMA32. If neither is the case, the
|
||||
* architecture needs to use an IOMMU instead of the direct mapping.
|
||||
*/
|
||||
if (mask < DMA_BIT_MASK(32))
|
||||
return 0;
|
||||
#endif
|
||||
/*
|
||||
* Various PCI/PCIe bridges have broken support for > 32bit DMA even
|
||||
* if the device itself might support it.
|
||||
*/
|
||||
if (dev->dma_32bit_limit && mask > DMA_BIT_MASK(32))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int dma_direct_mapping_error(struct device *dev, dma_addr_t dma_addr)
|
||||
{
|
||||
return dma_addr == DIRECT_MAPPING_ERROR;
|
||||
}
|
||||
|
||||
const struct dma_map_ops dma_direct_ops = {
|
||||
.alloc = dma_direct_alloc,
|
||||
.free = dma_direct_free,
|
||||
.map_page = dma_direct_map_page,
|
||||
.map_sg = dma_direct_map_sg,
|
||||
.dma_supported = dma_direct_supported,
|
||||
.mapping_error = dma_direct_mapping_error,
|
||||
};
|
||||
EXPORT_SYMBOL(dma_direct_ops);
|
||||
|
|
@ -1,102 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* Copyright (C) 2018 Christoph Hellwig.
|
||||
*
|
||||
* DMA operations that map physical memory directly without providing cache
|
||||
* coherence.
|
||||
*/
|
||||
#include <linux/export.h>
|
||||
#include <linux/mm.h>
|
||||
#include <linux/dma-direct.h>
|
||||
#include <linux/dma-noncoherent.h>
|
||||
#include <linux/scatterlist.h>
|
||||
|
||||
static void dma_noncoherent_sync_single_for_device(struct device *dev,
|
||||
dma_addr_t addr, size_t size, enum dma_data_direction dir)
|
||||
{
|
||||
arch_sync_dma_for_device(dev, dma_to_phys(dev, addr), size, dir);
|
||||
}
|
||||
|
||||
static void dma_noncoherent_sync_sg_for_device(struct device *dev,
|
||||
struct scatterlist *sgl, int nents, enum dma_data_direction dir)
|
||||
{
|
||||
struct scatterlist *sg;
|
||||
int i;
|
||||
|
||||
for_each_sg(sgl, sg, nents, i)
|
||||
arch_sync_dma_for_device(dev, sg_phys(sg), sg->length, dir);
|
||||
}
|
||||
|
||||
static dma_addr_t dma_noncoherent_map_page(struct device *dev, struct page *page,
|
||||
unsigned long offset, size_t size, enum dma_data_direction dir,
|
||||
unsigned long attrs)
|
||||
{
|
||||
dma_addr_t addr;
|
||||
|
||||
addr = dma_direct_map_page(dev, page, offset, size, dir, attrs);
|
||||
if (!dma_mapping_error(dev, addr) && !(attrs & DMA_ATTR_SKIP_CPU_SYNC))
|
||||
arch_sync_dma_for_device(dev, page_to_phys(page) + offset,
|
||||
size, dir);
|
||||
return addr;
|
||||
}
|
||||
|
||||
static int dma_noncoherent_map_sg(struct device *dev, struct scatterlist *sgl,
|
||||
int nents, enum dma_data_direction dir, unsigned long attrs)
|
||||
{
|
||||
nents = dma_direct_map_sg(dev, sgl, nents, dir, attrs);
|
||||
if (nents > 0 && !(attrs & DMA_ATTR_SKIP_CPU_SYNC))
|
||||
dma_noncoherent_sync_sg_for_device(dev, sgl, nents, dir);
|
||||
return nents;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU
|
||||
static void dma_noncoherent_sync_single_for_cpu(struct device *dev,
|
||||
dma_addr_t addr, size_t size, enum dma_data_direction dir)
|
||||
{
|
||||
arch_sync_dma_for_cpu(dev, dma_to_phys(dev, addr), size, dir);
|
||||
}
|
||||
|
||||
static void dma_noncoherent_sync_sg_for_cpu(struct device *dev,
|
||||
struct scatterlist *sgl, int nents, enum dma_data_direction dir)
|
||||
{
|
||||
struct scatterlist *sg;
|
||||
int i;
|
||||
|
||||
for_each_sg(sgl, sg, nents, i)
|
||||
arch_sync_dma_for_cpu(dev, sg_phys(sg), sg->length, dir);
|
||||
}
|
||||
|
||||
static void dma_noncoherent_unmap_page(struct device *dev, dma_addr_t addr,
|
||||
size_t size, enum dma_data_direction dir, unsigned long attrs)
|
||||
{
|
||||
if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC))
|
||||
dma_noncoherent_sync_single_for_cpu(dev, addr, size, dir);
|
||||
}
|
||||
|
||||
static void dma_noncoherent_unmap_sg(struct device *dev, struct scatterlist *sgl,
|
||||
int nents, enum dma_data_direction dir, unsigned long attrs)
|
||||
{
|
||||
if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC))
|
||||
dma_noncoherent_sync_sg_for_cpu(dev, sgl, nents, dir);
|
||||
}
|
||||
#endif
|
||||
|
||||
const struct dma_map_ops dma_noncoherent_ops = {
|
||||
.alloc = arch_dma_alloc,
|
||||
.free = arch_dma_free,
|
||||
.mmap = arch_dma_mmap,
|
||||
.sync_single_for_device = dma_noncoherent_sync_single_for_device,
|
||||
.sync_sg_for_device = dma_noncoherent_sync_sg_for_device,
|
||||
.map_page = dma_noncoherent_map_page,
|
||||
.map_sg = dma_noncoherent_map_sg,
|
||||
#ifdef CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU
|
||||
.sync_single_for_cpu = dma_noncoherent_sync_single_for_cpu,
|
||||
.sync_sg_for_cpu = dma_noncoherent_sync_sg_for_cpu,
|
||||
.unmap_page = dma_noncoherent_unmap_page,
|
||||
.unmap_sg = dma_noncoherent_unmap_sg,
|
||||
#endif
|
||||
.dma_supported = dma_direct_supported,
|
||||
.mapping_error = dma_direct_mapping_error,
|
||||
.cache_sync = arch_dma_cache_sync,
|
||||
};
|
||||
EXPORT_SYMBOL(dma_noncoherent_ops);
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* lib/dma-virt.c
|
||||
*
|
||||
* DMA operations that map to virtual addresses without flushing memory.
|
||||
*/
|
||||
#include <linux/export.h>
|
||||
#include <linux/mm.h>
|
||||
#include <linux/dma-mapping.h>
|
||||
#include <linux/scatterlist.h>
|
||||
|
||||
static void *dma_virt_alloc(struct device *dev, size_t size,
|
||||
dma_addr_t *dma_handle, gfp_t gfp,
|
||||
unsigned long attrs)
|
||||
{
|
||||
void *ret;
|
||||
|
||||
ret = (void *)__get_free_pages(gfp, get_order(size));
|
||||
if (ret)
|
||||
*dma_handle = (uintptr_t)ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void dma_virt_free(struct device *dev, size_t size,
|
||||
void *cpu_addr, dma_addr_t dma_addr,
|
||||
unsigned long attrs)
|
||||
{
|
||||
free_pages((unsigned long)cpu_addr, get_order(size));
|
||||
}
|
||||
|
||||
static dma_addr_t dma_virt_map_page(struct device *dev, struct page *page,
|
||||
unsigned long offset, size_t size,
|
||||
enum dma_data_direction dir,
|
||||
unsigned long attrs)
|
||||
{
|
||||
return (uintptr_t)(page_address(page) + offset);
|
||||
}
|
||||
|
||||
static int dma_virt_map_sg(struct device *dev, struct scatterlist *sgl,
|
||||
int nents, enum dma_data_direction dir,
|
||||
unsigned long attrs)
|
||||
{
|
||||
int i;
|
||||
struct scatterlist *sg;
|
||||
|
||||
for_each_sg(sgl, sg, nents, i) {
|
||||
BUG_ON(!sg_page(sg));
|
||||
sg_dma_address(sg) = (uintptr_t)sg_virt(sg);
|
||||
sg_dma_len(sg) = sg->length;
|
||||
}
|
||||
|
||||
return nents;
|
||||
}
|
||||
|
||||
const struct dma_map_ops dma_virt_ops = {
|
||||
.alloc = dma_virt_alloc,
|
||||
.free = dma_virt_free,
|
||||
.map_page = dma_virt_map_page,
|
||||
.map_sg = dma_virt_map_sg,
|
||||
};
|
||||
EXPORT_SYMBOL(dma_virt_ops);
|
||||
|
|
@ -596,15 +596,70 @@ static unsigned long memcpy_mcsafe_to_page(struct page *page, size_t offset,
|
|||
return ret;
|
||||
}
|
||||
|
||||
static size_t copy_pipe_to_iter_mcsafe(const void *addr, size_t bytes,
|
||||
struct iov_iter *i)
|
||||
{
|
||||
struct pipe_inode_info *pipe = i->pipe;
|
||||
size_t n, off, xfer = 0;
|
||||
int idx;
|
||||
|
||||
if (!sanity(i))
|
||||
return 0;
|
||||
|
||||
bytes = n = push_pipe(i, bytes, &idx, &off);
|
||||
if (unlikely(!n))
|
||||
return 0;
|
||||
for ( ; n; idx = next_idx(idx, pipe), off = 0) {
|
||||
size_t chunk = min_t(size_t, n, PAGE_SIZE - off);
|
||||
unsigned long rem;
|
||||
|
||||
rem = memcpy_mcsafe_to_page(pipe->bufs[idx].page, off, addr,
|
||||
chunk);
|
||||
i->idx = idx;
|
||||
i->iov_offset = off + chunk - rem;
|
||||
xfer += chunk - rem;
|
||||
if (rem)
|
||||
break;
|
||||
n -= chunk;
|
||||
addr += chunk;
|
||||
}
|
||||
i->count -= xfer;
|
||||
return xfer;
|
||||
}
|
||||
|
||||
/**
|
||||
* _copy_to_iter_mcsafe - copy to user with source-read error exception handling
|
||||
* @addr: source kernel address
|
||||
* @bytes: total transfer length
|
||||
* @iter: destination iterator
|
||||
*
|
||||
* The pmem driver arranges for filesystem-dax to use this facility via
|
||||
* dax_copy_to_iter() for protecting read/write to persistent memory.
|
||||
* Unless / until an architecture can guarantee identical performance
|
||||
* between _copy_to_iter_mcsafe() and _copy_to_iter() it would be a
|
||||
* performance regression to switch more users to the mcsafe version.
|
||||
*
|
||||
* Otherwise, the main differences between this and typical _copy_to_iter().
|
||||
*
|
||||
* * Typical tail/residue handling after a fault retries the copy
|
||||
* byte-by-byte until the fault happens again. Re-triggering machine
|
||||
* checks is potentially fatal so the implementation uses source
|
||||
* alignment and poison alignment assumptions to avoid re-triggering
|
||||
* hardware exceptions.
|
||||
*
|
||||
* * ITER_KVEC, ITER_PIPE, and ITER_BVEC can return short copies.
|
||||
* Compare to copy_to_iter() where only ITER_IOVEC attempts might return
|
||||
* a short copy.
|
||||
*
|
||||
* See MCSAFE_TEST for self-test.
|
||||
*/
|
||||
size_t _copy_to_iter_mcsafe(const void *addr, size_t bytes, struct iov_iter *i)
|
||||
{
|
||||
const char *from = addr;
|
||||
unsigned long rem, curr_addr, s_addr = (unsigned long) addr;
|
||||
|
||||
if (unlikely(i->type & ITER_PIPE)) {
|
||||
WARN_ON(1);
|
||||
return 0;
|
||||
}
|
||||
if (unlikely(i->type & ITER_PIPE))
|
||||
return copy_pipe_to_iter_mcsafe(addr, bytes, i);
|
||||
if (iter_is_iovec(i))
|
||||
might_fault();
|
||||
iterate_and_advance(i, bytes, v,
|
||||
|
|
@ -701,6 +756,20 @@ size_t _copy_from_iter_nocache(void *addr, size_t bytes, struct iov_iter *i)
|
|||
EXPORT_SYMBOL(_copy_from_iter_nocache);
|
||||
|
||||
#ifdef CONFIG_ARCH_HAS_UACCESS_FLUSHCACHE
|
||||
/**
|
||||
* _copy_from_iter_flushcache - write destination through cpu cache
|
||||
* @addr: destination kernel address
|
||||
* @bytes: total transfer length
|
||||
* @iter: source iterator
|
||||
*
|
||||
* The pmem driver arranges for filesystem-dax to use this facility via
|
||||
* dax_copy_from_iter() for ensuring that writes to persistent memory
|
||||
* are flushed through the CPU cache. It is differentiated from
|
||||
* _copy_from_iter_nocache() in that guarantees all data is flushed for
|
||||
* all iterator types. The _copy_from_iter_nocache() only attempts to
|
||||
* bypass the cache for the ITER_IOVEC case, and on some archs may use
|
||||
* instructions that strand dirty-data in the cache.
|
||||
*/
|
||||
size_t _copy_from_iter_flushcache(void *addr, size_t bytes, struct iov_iter *i)
|
||||
{
|
||||
char *to = addr;
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ int percpu_ida_alloc(struct percpu_ida *pool, int state)
|
|||
spin_lock_irqsave(&tags->lock, flags);
|
||||
|
||||
/* Fastpath */
|
||||
if (likely(tags->nr_free >= 0)) {
|
||||
if (likely(tags->nr_free)) {
|
||||
tag = tags->freelist[--tags->nr_free];
|
||||
spin_unlock_irqrestore(&tags->lock, flags);
|
||||
return tag;
|
||||
|
|
|
|||
|
|
@ -350,3 +350,31 @@ bool refcount_dec_and_lock(refcount_t *r, spinlock_t *lock)
|
|||
}
|
||||
EXPORT_SYMBOL(refcount_dec_and_lock);
|
||||
|
||||
/**
|
||||
* refcount_dec_and_lock_irqsave - return holding spinlock with disabled
|
||||
* interrupts if able to decrement refcount to 0
|
||||
* @r: the refcount
|
||||
* @lock: the spinlock to be locked
|
||||
* @flags: saved IRQ-flags if the is acquired
|
||||
*
|
||||
* Same as refcount_dec_and_lock() above except that the spinlock is acquired
|
||||
* with disabled interupts.
|
||||
*
|
||||
* Return: true and hold spinlock if able to decrement refcount to 0, false
|
||||
* otherwise
|
||||
*/
|
||||
bool refcount_dec_and_lock_irqsave(refcount_t *r, spinlock_t *lock,
|
||||
unsigned long *flags)
|
||||
{
|
||||
if (refcount_dec_not_one(r))
|
||||
return false;
|
||||
|
||||
spin_lock_irqsave(lock, *flags);
|
||||
if (!refcount_dec_and_test(r)) {
|
||||
spin_unlock_irqrestore(lock, *flags);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
EXPORT_SYMBOL(refcount_dec_and_lock_irqsave);
|
||||
|
|
|
|||
|
|
@ -774,7 +774,7 @@ int rhashtable_walk_start_check(struct rhashtable_iter *iter)
|
|||
skip++;
|
||||
if (list == iter->list) {
|
||||
iter->p = p;
|
||||
skip = skip;
|
||||
iter->skip = skip;
|
||||
goto found;
|
||||
}
|
||||
}
|
||||
|
|
@ -964,8 +964,16 @@ EXPORT_SYMBOL_GPL(rhashtable_walk_stop);
|
|||
|
||||
static size_t rounded_hashtable_size(const struct rhashtable_params *params)
|
||||
{
|
||||
return max(roundup_pow_of_two(params->nelem_hint * 4 / 3),
|
||||
(unsigned long)params->min_size);
|
||||
size_t retsize;
|
||||
|
||||
if (params->nelem_hint)
|
||||
retsize = max(roundup_pow_of_two(params->nelem_hint * 4 / 3),
|
||||
(unsigned long)params->min_size);
|
||||
else
|
||||
retsize = max(HASH_DEFAULT_SIZE,
|
||||
(unsigned long)params->min_size);
|
||||
|
||||
return retsize;
|
||||
}
|
||||
|
||||
static u32 rhashtable_jhash2(const void *key, u32 length, u32 seed)
|
||||
|
|
@ -1022,8 +1030,6 @@ int rhashtable_init(struct rhashtable *ht,
|
|||
struct bucket_table *tbl;
|
||||
size_t size;
|
||||
|
||||
size = HASH_DEFAULT_SIZE;
|
||||
|
||||
if ((!params->key_len && !params->obj_hashfn) ||
|
||||
(params->obj_hashfn && !params->obj_cmpfn))
|
||||
return -EINVAL;
|
||||
|
|
@ -1050,8 +1056,7 @@ int rhashtable_init(struct rhashtable *ht,
|
|||
|
||||
ht->p.min_size = max_t(u16, ht->p.min_size, HASH_MIN_SIZE);
|
||||
|
||||
if (params->nelem_hint)
|
||||
size = rounded_hashtable_size(&ht->p);
|
||||
size = rounded_hashtable_size(&ht->p);
|
||||
|
||||
if (params->locks_mul)
|
||||
ht->p.locks_mul = roundup_pow_of_two(params->locks_mul);
|
||||
|
|
@ -1143,13 +1148,14 @@ void rhashtable_free_and_destroy(struct rhashtable *ht,
|
|||
void (*free_fn)(void *ptr, void *arg),
|
||||
void *arg)
|
||||
{
|
||||
struct bucket_table *tbl;
|
||||
struct bucket_table *tbl, *next_tbl;
|
||||
unsigned int i;
|
||||
|
||||
cancel_work_sync(&ht->run_work);
|
||||
|
||||
mutex_lock(&ht->mutex);
|
||||
tbl = rht_dereference(ht->tbl, ht);
|
||||
restart:
|
||||
if (free_fn) {
|
||||
for (i = 0; i < tbl->size; i++) {
|
||||
struct rhash_head *pos, *next;
|
||||
|
|
@ -1166,7 +1172,12 @@ void rhashtable_free_and_destroy(struct rhashtable *ht,
|
|||
}
|
||||
}
|
||||
|
||||
next_tbl = rht_dereference(tbl->future_tbl, ht);
|
||||
bucket_table_free(tbl);
|
||||
if (next_tbl) {
|
||||
tbl = next_tbl;
|
||||
goto restart;
|
||||
}
|
||||
mutex_unlock(&ht->mutex);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(rhashtable_free_and_destroy);
|
||||
|
|
|
|||
|
|
@ -24,9 +24,6 @@
|
|||
**/
|
||||
struct scatterlist *sg_next(struct scatterlist *sg)
|
||||
{
|
||||
#ifdef CONFIG_DEBUG_SG
|
||||
BUG_ON(sg->sg_magic != SG_MAGIC);
|
||||
#endif
|
||||
if (sg_is_last(sg))
|
||||
return NULL;
|
||||
|
||||
|
|
@ -111,10 +108,7 @@ struct scatterlist *sg_last(struct scatterlist *sgl, unsigned int nents)
|
|||
for_each_sg(sgl, sg, nents, i)
|
||||
ret = sg;
|
||||
|
||||
#ifdef CONFIG_DEBUG_SG
|
||||
BUG_ON(sgl[0].sg_magic != SG_MAGIC);
|
||||
BUG_ON(!sg_is_last(ret));
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(sg_last);
|
||||
|
|
|
|||
1087
lib/swiotlb.c
1087
lib/swiotlb.c
File diff suppressed because it is too large
Load diff
|
|
@ -5282,21 +5282,31 @@ static struct bpf_test tests[] = {
|
|||
{ /* Mainly checking JIT here. */
|
||||
"BPF_MAXINSNS: Ctx heavy transformations",
|
||||
{ },
|
||||
#if defined(CONFIG_BPF_JIT_ALWAYS_ON) && defined(CONFIG_S390)
|
||||
CLASSIC | FLAG_EXPECTED_FAIL,
|
||||
#else
|
||||
CLASSIC,
|
||||
#endif
|
||||
{ },
|
||||
{
|
||||
{ 1, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) },
|
||||
{ 10, !!(SKB_VLAN_TCI & VLAN_TAG_PRESENT) }
|
||||
},
|
||||
.fill_helper = bpf_fill_maxinsns6,
|
||||
.expected_errcode = -ENOTSUPP,
|
||||
},
|
||||
{ /* Mainly checking JIT here. */
|
||||
"BPF_MAXINSNS: Call heavy transformations",
|
||||
{ },
|
||||
#if defined(CONFIG_BPF_JIT_ALWAYS_ON) && defined(CONFIG_S390)
|
||||
CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
|
||||
#else
|
||||
CLASSIC | FLAG_NO_DATA,
|
||||
#endif
|
||||
{ },
|
||||
{ { 1, 0 }, { 10, 0 } },
|
||||
.fill_helper = bpf_fill_maxinsns7,
|
||||
.expected_errcode = -ENOTSUPP,
|
||||
},
|
||||
{ /* Mainly checking JIT here. */
|
||||
"BPF_MAXINSNS: Jump heavy test",
|
||||
|
|
@ -5347,18 +5357,28 @@ static struct bpf_test tests[] = {
|
|||
{
|
||||
"BPF_MAXINSNS: exec all MSH",
|
||||
{ },
|
||||
#if defined(CONFIG_BPF_JIT_ALWAYS_ON) && defined(CONFIG_S390)
|
||||
CLASSIC | FLAG_EXPECTED_FAIL,
|
||||
#else
|
||||
CLASSIC,
|
||||
#endif
|
||||
{ 0xfa, 0xfb, 0xfc, 0xfd, },
|
||||
{ { 4, 0xababab83 } },
|
||||
.fill_helper = bpf_fill_maxinsns13,
|
||||
.expected_errcode = -ENOTSUPP,
|
||||
},
|
||||
{
|
||||
"BPF_MAXINSNS: ld_abs+get_processor_id",
|
||||
{ },
|
||||
#if defined(CONFIG_BPF_JIT_ALWAYS_ON) && defined(CONFIG_S390)
|
||||
CLASSIC | FLAG_EXPECTED_FAIL,
|
||||
#else
|
||||
CLASSIC,
|
||||
#endif
|
||||
{ },
|
||||
{ { 1, 0xbee } },
|
||||
.fill_helper = bpf_fill_ld_abs_get_processor_id,
|
||||
.expected_errcode = -ENOTSUPP,
|
||||
},
|
||||
/*
|
||||
* LD_IND / LD_ABS on fragmented SKBs
|
||||
|
|
|
|||
|
|
@ -260,13 +260,6 @@ plain(void)
|
|||
{
|
||||
int err;
|
||||
|
||||
/*
|
||||
* Make sure crng is ready. Otherwise we get "(ptrval)" instead
|
||||
* of a hashed address when printing '%p' in plain_hash() and
|
||||
* plain_format().
|
||||
*/
|
||||
wait_for_random_bytes();
|
||||
|
||||
err = plain_hash();
|
||||
if (err) {
|
||||
pr_warn("plain 'p' does not appear to be hashed\n");
|
||||
|
|
|
|||
Loading…
Reference in a new issue