aboutsummaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/base/Kconfig7
-rw-r--r--drivers/base/Makefile1
-rw-r--r--drivers/base/arch_numa.c371
-rw-r--r--drivers/block/zram/backend_842.c10
-rw-r--r--drivers/block/zram/backend_deflate.c25
-rw-r--r--drivers/block/zram/backend_lz4.c10
-rw-r--r--drivers/block/zram/backend_lz4hc.c16
-rw-r--r--drivers/block/zram/backend_lzo.c10
-rw-r--r--drivers/block/zram/backend_lzorle.c10
-rw-r--r--drivers/block/zram/backend_zstd.c11
-rw-r--r--drivers/block/zram/zram_drv.c188
-rw-r--r--drivers/block/zram/zram_drv.h14
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c4
-rw-r--r--drivers/gpu/drm/drm_gem_shmem_helper.c2
-rw-r--r--drivers/gpu/drm/i915/gem/i915_gem_shmem.c2
-rw-r--r--drivers/gpu/drm/panthor/panthor_gem.c2
-rw-r--r--drivers/gpu/drm/ttm/ttm_backup.c2
-rw-r--r--drivers/gpu/drm/ttm/ttm_bo_vm.c2
-rw-r--r--drivers/gpu/drm/xe/xe_device.c2
19 files changed, 216 insertions, 473 deletions
diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig
index 43f20ca95a2a..a9acf4575f4f 100644
--- a/drivers/base/Kconfig
+++ b/drivers/base/Kconfig
@@ -230,13 +230,6 @@ config GENERIC_ARCH_TOPOLOGY
appropriate scaling, sysfs interface for reading capacity values at
runtime.
-config GENERIC_ARCH_NUMA
- bool
- select NUMA_MEMBLKS
- help
- Enable support for generic NUMA implementation. Currently, RISC-V
- and ARM64 use it.
-
config FW_DEVLINK_SYNC_STATE_TIMEOUT
bool "sync_state() behavior defaults to timeout instead of strict"
help
diff --git a/drivers/base/Makefile b/drivers/base/Makefile
index 8074a10183dc..435710f643a5 100644
--- a/drivers/base/Makefile
+++ b/drivers/base/Makefile
@@ -25,7 +25,6 @@ obj-$(CONFIG_PINCTRL) += pinctrl.o
obj-$(CONFIG_DEV_COREDUMP) += devcoredump.o
obj-$(CONFIG_GENERIC_MSI_IRQ) += platform-msi.o
obj-$(CONFIG_GENERIC_ARCH_TOPOLOGY) += arch_topology.o
-obj-$(CONFIG_GENERIC_ARCH_NUMA) += arch_numa.o
obj-$(CONFIG_ACPI) += physical_location.o
obj-y += test/
diff --git a/drivers/base/arch_numa.c b/drivers/base/arch_numa.c
deleted file mode 100644
index 6476227b772c..000000000000
--- a/drivers/base/arch_numa.c
+++ /dev/null
@@ -1,371 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-/*
- * NUMA support, based on the x86 implementation.
- *
- * Copyright (C) 2015 Cavium Inc.
- * Author: Ganapatrao Kulkarni <gkulkarni@cavium.com>
- */
-
-#define pr_fmt(fmt) "NUMA: " fmt
-
-#include <linux/acpi.h>
-#include <linux/memblock.h>
-#include <linux/module.h>
-#include <linux/of.h>
-#include <linux/numa_memblks.h>
-
-#include <asm/sections.h>
-
-static int cpu_to_node_map[NR_CPUS] = { [0 ... NR_CPUS-1] = NUMA_NO_NODE };
-
-bool numa_off;
-
-static __init int numa_parse_early_param(char *opt)
-{
- if (!opt)
- return -EINVAL;
- if (str_has_prefix(opt, "off"))
- numa_off = true;
- if (!strncmp(opt, "fake=", 5))
- return numa_emu_cmdline(opt + 5);
-
- return 0;
-}
-early_param("numa", numa_parse_early_param);
-
-cpumask_var_t node_to_cpumask_map[MAX_NUMNODES];
-EXPORT_SYMBOL(node_to_cpumask_map);
-
-#ifdef CONFIG_DEBUG_PER_CPU_MAPS
-
-/*
- * Returns a pointer to the bitmask of CPUs on Node 'node'.
- */
-const struct cpumask *cpumask_of_node(int node)
-{
-
- if (node == NUMA_NO_NODE)
- return cpu_all_mask;
-
- if (WARN_ON(node < 0 || node >= nr_node_ids))
- return cpu_none_mask;
-
- if (WARN_ON(node_to_cpumask_map[node] == NULL))
- return cpu_online_mask;
-
- return node_to_cpumask_map[node];
-}
-EXPORT_SYMBOL(cpumask_of_node);
-
-#endif
-
-#ifndef CONFIG_NUMA_EMU
-static void numa_update_cpu(unsigned int cpu, bool remove)
-{
- int nid = cpu_to_node(cpu);
-
- if (nid == NUMA_NO_NODE)
- return;
-
- if (remove)
- cpumask_clear_cpu(cpu, node_to_cpumask_map[nid]);
- else
- cpumask_set_cpu(cpu, node_to_cpumask_map[nid]);
-}
-
-void numa_add_cpu(unsigned int cpu)
-{
- numa_update_cpu(cpu, false);
-}
-
-void numa_remove_cpu(unsigned int cpu)
-{
- numa_update_cpu(cpu, true);
-}
-#endif
-
-void numa_clear_node(unsigned int cpu)
-{
- numa_remove_cpu(cpu);
- set_cpu_numa_node(cpu, NUMA_NO_NODE);
-}
-
-/*
- * Allocate node_to_cpumask_map based on number of available nodes
- * Requires node_possible_map to be valid.
- *
- * Note: cpumask_of_node() is not valid until after this is done.
- * (Use CONFIG_DEBUG_PER_CPU_MAPS to check this.)
- */
-static void __init setup_node_to_cpumask_map(void)
-{
- int node;
-
- /* setup nr_node_ids if not done yet */
- if (nr_node_ids == MAX_NUMNODES)
- setup_nr_node_ids();
-
- /* allocate and clear the mapping */
- for (node = 0; node < nr_node_ids; node++) {
- alloc_bootmem_cpumask_var(&node_to_cpumask_map[node]);
- cpumask_clear(node_to_cpumask_map[node]);
- }
-
- /* cpumask_of_node() will now work */
- pr_debug("Node to cpumask map for %u nodes\n", nr_node_ids);
-}
-
-/*
- * Set the cpu to node and mem mapping
- */
-void numa_store_cpu_info(unsigned int cpu)
-{
- set_cpu_numa_node(cpu, cpu_to_node_map[cpu]);
-}
-
-void __init early_map_cpu_to_node(unsigned int cpu, int nid)
-{
- /* fallback to node 0 */
- if (nid < 0 || nid >= MAX_NUMNODES || numa_off)
- nid = 0;
-
- cpu_to_node_map[cpu] = nid;
-
- /*
- * We should set the numa node of cpu0 as soon as possible, because it
- * has already been set up online before. cpu_to_node(0) will soon be
- * called.
- */
- if (!cpu)
- set_cpu_numa_node(cpu, nid);
-}
-
-#ifdef CONFIG_HAVE_SETUP_PER_CPU_AREA
-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
-EXPORT_SYMBOL(__per_cpu_offset);
-
-int early_cpu_to_node(int cpu)
-{
- return cpu_to_node_map[cpu];
-}
-
-static int __init pcpu_cpu_distance(unsigned int from, unsigned int to)
-{
- return node_distance(early_cpu_to_node(from), early_cpu_to_node(to));
-}
-
-void __init setup_per_cpu_areas(void)
-{
- unsigned long delta;
- unsigned int cpu;
- int rc = -EINVAL;
-
- if (pcpu_chosen_fc != PCPU_FC_PAGE) {
- /*
- * Always reserve area for module percpu variables. That's
- * what the legacy allocator did.
- */
- rc = pcpu_embed_first_chunk(PERCPU_MODULE_RESERVE,
- PERCPU_DYNAMIC_RESERVE, PAGE_SIZE,
- pcpu_cpu_distance,
- early_cpu_to_node);
-#ifdef CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK
- if (rc < 0)
- pr_warn("PERCPU: %s allocator failed (%d), falling back to page size\n",
- pcpu_fc_names[pcpu_chosen_fc], rc);
-#endif
- }
-
-#ifdef CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK
- if (rc < 0)
- rc = pcpu_page_first_chunk(PERCPU_MODULE_RESERVE, early_cpu_to_node);
-#endif
- if (rc < 0)
- panic("Failed to initialize percpu areas (err=%d).", rc);
-
- delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
- for_each_possible_cpu(cpu)
- __per_cpu_offset[cpu] = delta + pcpu_unit_offsets[cpu];
-}
-#endif
-
-/*
- * Initialize NODE_DATA for a node on the local memory
- */
-static void __init setup_node_data(int nid, u64 start_pfn, u64 end_pfn)
-{
- if (start_pfn >= end_pfn)
- pr_info("Initmem setup node %d [<memory-less node>]\n", nid);
-
- alloc_node_data(nid);
-
- NODE_DATA(nid)->node_id = nid;
- NODE_DATA(nid)->node_start_pfn = start_pfn;
- NODE_DATA(nid)->node_spanned_pages = end_pfn - start_pfn;
-}
-
-static int __init numa_register_nodes(void)
-{
- int nid;
-
- /* Check the validity of the memblock/node mapping */
- if (!memblock_validate_numa_coverage(0))
- return -EINVAL;
-
- /* Finally register nodes. */
- for_each_node_mask(nid, numa_nodes_parsed) {
- unsigned long start_pfn, end_pfn;
-
- get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
- setup_node_data(nid, start_pfn, end_pfn);
- node_set_online(nid);
- }
-
- return 0;
-}
-
-static int __init numa_init(int (*init_func)(void))
-{
- int ret;
-
- ret = numa_memblks_init(init_func, /* memblock_force_top_down */ false);
- if (ret < 0)
- goto out_free_distance;
-
- if (nodes_empty(numa_nodes_parsed)) {
- pr_info("No NUMA configuration found\n");
- ret = -EINVAL;
- goto out_free_distance;
- }
-
- ret = numa_register_nodes();
- if (ret < 0)
- goto out_free_distance;
-
- setup_node_to_cpumask_map();
-
- return 0;
-out_free_distance:
- numa_reset_distance();
- return ret;
-}
-
-/**
- * dummy_numa_init() - Fallback dummy NUMA init
- *
- * Used if there's no underlying NUMA architecture, NUMA initialization
- * fails, or NUMA is disabled on the command line.
- *
- * Must online at least one node (node 0) and add memory blocks that cover all
- * allowed memory. It is unlikely that this function fails.
- *
- * Return: 0 on success, -errno on failure.
- */
-static int __init dummy_numa_init(void)
-{
- phys_addr_t start = memblock_start_of_DRAM();
- phys_addr_t end = memblock_end_of_DRAM() - 1;
- int ret;
-
- if (numa_off)
- pr_info("NUMA disabled\n"); /* Forced off on command line. */
- pr_info("Faking a node at [mem %pap-%pap]\n", &start, &end);
-
- ret = numa_add_memblk(0, start, end + 1);
- if (ret) {
- pr_err("NUMA init failed\n");
- return ret;
- }
-
- numa_off = true;
- return 0;
-}
-
-#ifdef CONFIG_ACPI_NUMA
-static int __init arch_acpi_numa_init(void)
-{
- int ret;
-
- ret = acpi_numa_init();
- if (ret) {
- pr_debug("Failed to initialise from firmware\n");
- return ret;
- }
-
- return srat_disabled() ? -EINVAL : 0;
-}
-#else
-static int __init arch_acpi_numa_init(void)
-{
- return -EOPNOTSUPP;
-}
-#endif
-
-/**
- * arch_numa_init() - Initialize NUMA
- *
- * Try each configured NUMA initialization method until one succeeds. The
- * last fallback is dummy single node config encompassing whole memory.
- */
-void __init arch_numa_init(void)
-{
- if (!numa_off) {
- if (!acpi_disabled && !numa_init(arch_acpi_numa_init))
- return;
- if (acpi_disabled && !numa_init(of_numa_init))
- return;
- }
-
- numa_init(dummy_numa_init);
-}
-
-#ifdef CONFIG_NUMA_EMU
-void __init numa_emu_update_cpu_to_node(int *emu_nid_to_phys,
- unsigned int nr_emu_nids)
-{
- int i, j;
-
- /*
- * Transform cpu_to_node_map table to use emulated nids by
- * reverse-mapping phys_nid. The maps should always exist but fall
- * back to zero just in case.
- */
- for (i = 0; i < ARRAY_SIZE(cpu_to_node_map); i++) {
- if (cpu_to_node_map[i] == NUMA_NO_NODE)
- continue;
- for (j = 0; j < nr_emu_nids; j++)
- if (cpu_to_node_map[i] == emu_nid_to_phys[j])
- break;
- cpu_to_node_map[i] = j < nr_emu_nids ? j : 0;
- }
-}
-
-u64 __init numa_emu_dma_end(void)
-{
- return memblock_start_of_DRAM() + SZ_4G;
-}
-
-void debug_cpumask_set_cpu(unsigned int cpu, int node, bool enable)
-{
- struct cpumask *mask;
-
- if (node == NUMA_NO_NODE)
- return;
-
- mask = node_to_cpumask_map[node];
- if (!cpumask_available(mask)) {
- pr_err("node_to_cpumask_map[%i] NULL\n", node);
- dump_stack();
- return;
- }
-
- if (enable)
- cpumask_set_cpu(cpu, mask);
- else
- cpumask_clear_cpu(cpu, mask);
-
- pr_debug("%s cpu %d node %d: mask now %*pbl\n",
- enable ? "numa_add_cpu" : "numa_remove_cpu",
- cpu, node, cpumask_pr_args(mask));
-}
-#endif /* CONFIG_NUMA_EMU */
diff --git a/drivers/block/zram/backend_842.c b/drivers/block/zram/backend_842.c
index 10d9d5c60f53..3846a04c69d7 100644
--- a/drivers/block/zram/backend_842.c
+++ b/drivers/block/zram/backend_842.c
@@ -1,5 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
+#define pr_fmt(fmt) "842: " fmt
+
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/sw842.h>
@@ -13,6 +15,14 @@ static void release_params_842(struct zcomp_params *params)
static int setup_params_842(struct zcomp_params *params)
{
+ if (params->dict_sz) {
+ pr_err("dictionary is not supported\n");
+ return -EOPNOTSUPP;
+ }
+ if (params->level != ZCOMP_PARAM_NOT_SET) {
+ pr_err("compression level is not supported\n");
+ return -EOPNOTSUPP;
+ }
return 0;
}
diff --git a/drivers/block/zram/backend_deflate.c b/drivers/block/zram/backend_deflate.c
index f92a52a720d1..f71b11bcac78 100644
--- a/drivers/block/zram/backend_deflate.c
+++ b/drivers/block/zram/backend_deflate.c
@@ -1,5 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
+#define pr_fmt(fmt) "deflate: " fmt
+
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
@@ -22,10 +24,29 @@ static void deflate_release_params(struct zcomp_params *params)
static int deflate_setup_params(struct zcomp_params *params)
{
- if (params->level == ZCOMP_PARAM_NOT_SET)
+ if (params->dict_sz) {
+ pr_err("dictionary is not supported\n");
+ return -EOPNOTSUPP;
+ }
+
+ if (params->level == ZCOMP_PARAM_NOT_SET) {
params->level = Z_DEFAULT_COMPRESSION;
- if (params->deflate.winbits == ZCOMP_PARAM_NOT_SET)
+ } else if (params->level < Z_DEFAULT_COMPRESSION ||
+ params->level > Z_BEST_COMPRESSION) {
+ pr_err("invalid compression level %d\n", params->level);
+ return -EINVAL;
+ }
+
+ if (params->deflate.winbits == ZCOMP_PARAM_NOT_SET) {
params->deflate.winbits = DEFLATE_DEF_WINBITS;
+ } else {
+ s32 wb = params->deflate.winbits;
+
+ if ((wb < -15 || wb > -9) && (wb < 9 || wb > 15)) {
+ pr_err("invalid winbits %d\n", wb);
+ return -EINVAL;
+ }
+ }
return 0;
}
diff --git a/drivers/block/zram/backend_lz4.c b/drivers/block/zram/backend_lz4.c
index c449d511ba86..1e28104ad964 100644
--- a/drivers/block/zram/backend_lz4.c
+++ b/drivers/block/zram/backend_lz4.c
@@ -1,3 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#define pr_fmt(fmt) "lz4: " fmt
+
#include <linux/kernel.h>
#include <linux/lz4.h>
#include <linux/slab.h>
@@ -28,8 +32,12 @@ static int lz4_setup_params(struct zcomp_params *params)
LZ4_stream_t *dict_stream;
int ret;
- if (params->level == ZCOMP_PARAM_NOT_SET)
+ if (params->level == ZCOMP_PARAM_NOT_SET) {
params->level = LZ4_ACCELERATION_DEFAULT;
+ } else if (params->level < LZ4_ACCELERATION_DEFAULT) {
+ pr_err("invalid compression level %d\n", params->level);
+ return -EINVAL;
+ }
if (!params->dict || !params->dict_sz)
return 0;
diff --git a/drivers/block/zram/backend_lz4hc.c b/drivers/block/zram/backend_lz4hc.c
index f6a336acfe20..d8aa01bb258f 100644
--- a/drivers/block/zram/backend_lz4hc.c
+++ b/drivers/block/zram/backend_lz4hc.c
@@ -1,3 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#define pr_fmt(fmt) "lz4hc: " fmt
+
#include <linux/kernel.h>
#include <linux/lz4.h>
#include <linux/slab.h>
@@ -18,8 +22,18 @@ static void lz4hc_release_params(struct zcomp_params *params)
static int lz4hc_setup_params(struct zcomp_params *params)
{
- if (params->level == ZCOMP_PARAM_NOT_SET)
+ if (params->level == ZCOMP_PARAM_NOT_SET) {
params->level = LZ4HC_DEFAULT_CLEVEL;
+ } else if (params->level < 1 || params->level > LZ4HC_MAX_CLEVEL) {
+ /*
+ * Use < 1 rather than < LZ4HC_MIN_CLEVEL here because
+ * LZ4HC_compress_generic() only clamps levels below 1
+ * (levels 1 and 2 are valid). LZ4HC_MIN_CLEVEL (3) is
+ * advisory and not enforced by the library.
+ */
+ pr_err("invalid compression level %d\n", params->level);
+ return -EINVAL;
+ }
return 0;
}
diff --git a/drivers/block/zram/backend_lzo.c b/drivers/block/zram/backend_lzo.c
index 4c906beaae6b..d83f92cf757c 100644
--- a/drivers/block/zram/backend_lzo.c
+++ b/drivers/block/zram/backend_lzo.c
@@ -1,5 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
+#define pr_fmt(fmt) "lzo: " fmt
+
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/lzo.h>
@@ -12,6 +14,14 @@ static void lzo_release_params(struct zcomp_params *params)
static int lzo_setup_params(struct zcomp_params *params)
{
+ if (params->dict_sz) {
+ pr_err("dictionary is not supported\n");
+ return -EOPNOTSUPP;
+ }
+ if (params->level != ZCOMP_PARAM_NOT_SET) {
+ pr_err("compression level is not supported\n");
+ return -EOPNOTSUPP;
+ }
return 0;
}
diff --git a/drivers/block/zram/backend_lzorle.c b/drivers/block/zram/backend_lzorle.c
index 10640c96cbfc..1b120d062c92 100644
--- a/drivers/block/zram/backend_lzorle.c
+++ b/drivers/block/zram/backend_lzorle.c
@@ -1,5 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
+#define pr_fmt(fmt) "lzo-rle: " fmt
+
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/lzo.h>
@@ -12,6 +14,14 @@ static void lzorle_release_params(struct zcomp_params *params)
static int lzorle_setup_params(struct zcomp_params *params)
{
+ if (params->dict_sz) {
+ pr_err("dictionary is not supported\n");
+ return -EOPNOTSUPP;
+ }
+ if (params->level != ZCOMP_PARAM_NOT_SET) {
+ pr_err("compression level is not supported\n");
+ return -EOPNOTSUPP;
+ }
return 0;
}
diff --git a/drivers/block/zram/backend_zstd.c b/drivers/block/zram/backend_zstd.c
index d00b548056dc..08da3810cffd 100644
--- a/drivers/block/zram/backend_zstd.c
+++ b/drivers/block/zram/backend_zstd.c
@@ -1,5 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
+#define pr_fmt(fmt) "zstd: " fmt
+
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
@@ -58,8 +60,13 @@ static int zstd_setup_params(struct zcomp_params *params)
return -ENOMEM;
params->drv_data = zp;
- if (params->level == ZCOMP_PARAM_NOT_SET)
+ if (params->level == ZCOMP_PARAM_NOT_SET) {
params->level = zstd_default_clevel();
+ } else if (params->level < zstd_min_clevel() ||
+ params->level > zstd_max_clevel()) {
+ pr_err("invalid compression level %d\n", params->level);
+ goto error;
+ }
zp->cprm = zstd_get_params(params->level, PAGE_SIZE);
@@ -85,7 +92,6 @@ static int zstd_setup_params(struct zcomp_params *params)
return 0;
error:
- zstd_release_params(params);
return -EINVAL;
}
@@ -161,7 +167,6 @@ static int zstd_create(struct zcomp_params *params, struct zcomp_ctx *ctx)
return 0;
error:
- zstd_release_params(params);
zstd_destroy(ctx);
return -EINVAL;
}
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 4bfe63a5225d..a9b3bb1d3bef 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -56,7 +56,7 @@ static size_t huge_class_size;
static const struct block_device_operations zram_devops;
-static void slot_free(struct zram *zram, u32 index);
+static void slot_free(struct zram *zram, unsigned long index);
/*
* entry locking rules:
@@ -70,11 +70,11 @@ static void slot_free(struct zram *zram, u32 index);
* 4) Use TRY lock variant when in atomic context
* - must check return value and handle locking failers
*/
-static __must_check bool slot_trylock(struct zram *zram, u32 index)
+static __must_check bool slot_trylock(struct zram *zram, unsigned long index)
{
unsigned long *lock = &zram->table[index].__lock;
- if (!test_and_set_bit_lock(ZRAM_ENTRY_LOCK, lock)) {
+ if (!test_and_set_bit_lock(ZRAM_ENTRY_LOCK_BIT, lock)) {
mutex_acquire(&zram->table_lock_map, 0, 1, _RET_IP_);
lock_acquired(&zram->table_lock_map, _RET_IP_);
return true;
@@ -83,21 +83,21 @@ static __must_check bool slot_trylock(struct zram *zram, u32 index)
return false;
}
-static void slot_lock(struct zram *zram, u32 index)
+static void slot_lock(struct zram *zram, unsigned long index)
{
unsigned long *lock = &zram->table[index].__lock;
mutex_acquire(&zram->table_lock_map, 0, 0, _RET_IP_);
- wait_on_bit_lock(lock, ZRAM_ENTRY_LOCK, TASK_UNINTERRUPTIBLE);
+ wait_on_bit_lock(lock, ZRAM_ENTRY_LOCK_BIT, TASK_UNINTERRUPTIBLE);
lock_acquired(&zram->table_lock_map, _RET_IP_);
}
-static void slot_unlock(struct zram *zram, u32 index)
+static void slot_unlock(struct zram *zram, unsigned long index)
{
unsigned long *lock = &zram->table[index].__lock;
mutex_release(&zram->table_lock_map, _RET_IP_);
- clear_and_wake_up_bit(ZRAM_ENTRY_LOCK, lock);
+ clear_and_wake_up_bit(ZRAM_ENTRY_LOCK_BIT, lock);
}
static inline bool init_done(struct zram *zram)
@@ -110,55 +110,56 @@ static inline struct zram *dev_to_zram(struct device *dev)
return (struct zram *)dev_to_disk(dev)->private_data;
}
-static unsigned long get_slot_handle(struct zram *zram, u32 index)
+static unsigned long get_slot_handle(struct zram *zram, unsigned long index)
{
return zram->table[index].handle;
}
-static void set_slot_handle(struct zram *zram, u32 index, unsigned long handle)
+static void set_slot_handle(struct zram *zram, unsigned long index,
+ unsigned long handle)
{
zram->table[index].handle = handle;
}
-static bool test_slot_flag(struct zram *zram, u32 index,
+static bool test_slot_flag(struct zram *zram, unsigned long index,
enum zram_pageflags flag)
{
return zram->table[index].attr.flags & BIT(flag);
}
-static void set_slot_flag(struct zram *zram, u32 index,
+static void set_slot_flag(struct zram *zram, unsigned long index,
enum zram_pageflags flag)
{
zram->table[index].attr.flags |= BIT(flag);
}
-static void clear_slot_flag(struct zram *zram, u32 index,
+static void clear_slot_flag(struct zram *zram, unsigned long index,
enum zram_pageflags flag)
{
zram->table[index].attr.flags &= ~BIT(flag);
}
-static size_t get_slot_size(struct zram *zram, u32 index)
+static size_t get_slot_size(struct zram *zram, unsigned long index)
{
return zram->table[index].attr.flags & (BIT(ZRAM_FLAG_SHIFT) - 1);
}
-static void set_slot_size(struct zram *zram, u32 index, size_t size)
+static void set_slot_size(struct zram *zram, unsigned long index, size_t size)
{
unsigned long flags = zram->table[index].attr.flags >> ZRAM_FLAG_SHIFT;
zram->table[index].attr.flags = (flags << ZRAM_FLAG_SHIFT) | size;
}
-static inline bool slot_allocated(struct zram *zram, u32 index)
+static inline bool slot_allocated(struct zram *zram, unsigned long index)
{
return get_slot_size(zram, index) ||
test_slot_flag(zram, index, ZRAM_SAME) ||
test_slot_flag(zram, index, ZRAM_WB);
}
-static inline void set_slot_comp_priority(struct zram *zram, u32 index,
- u32 prio)
+static inline void set_slot_comp_priority(struct zram *zram,
+ unsigned long index, u32 prio)
{
prio &= ZRAM_COMP_PRIORITY_MASK;
/*
@@ -170,14 +171,14 @@ static inline void set_slot_comp_priority(struct zram *zram, u32 index,
zram->table[index].attr.flags |= (prio << ZRAM_COMP_PRIORITY_BIT1);
}
-static inline u32 get_slot_comp_priority(struct zram *zram, u32 index)
+static inline u32 get_slot_comp_priority(struct zram *zram, unsigned long index)
{
u32 prio = zram->table[index].attr.flags >> ZRAM_COMP_PRIORITY_BIT1;
return prio & ZRAM_COMP_PRIORITY_MASK;
}
-static void mark_slot_accessed(struct zram *zram, u32 index)
+static void mark_slot_accessed(struct zram *zram, unsigned long index)
{
clear_slot_flag(zram, index, ZRAM_IDLE);
clear_slot_flag(zram, index, ZRAM_PP_SLOT);
@@ -284,7 +285,7 @@ static void release_pp_ctl(struct zram *zram, struct zram_pp_ctl *ctl)
}
static bool place_pp_slot(struct zram *zram, struct zram_pp_ctl *ctl,
- u32 index)
+ unsigned long index)
{
struct zram_pp_slot *pps;
u32 bid;
@@ -418,7 +419,7 @@ static void mark_idle(struct zram *zram, ktime_t cutoff)
{
int is_idle = 1;
unsigned long nr_pages = zram->disksize >> PAGE_SHIFT;
- int index;
+ unsigned long index;
for (index = 0; index < nr_pages; index++) {
/*
@@ -485,8 +486,9 @@ static ssize_t idle_store(struct device *dev, struct device_attribute *attr,
#define INVALID_BDEV_BLOCK (~0UL)
static int read_from_zspool_raw(struct zram *zram, struct page *page,
- u32 index);
-static int read_from_zspool(struct zram *zram, struct page *page, u32 index);
+ unsigned long index);
+static int read_from_zspool(struct zram *zram, struct page *page,
+ unsigned long index);
struct zram_wb_ctl {
/* idle list is accessed only by the writeback task, no concurency */
@@ -522,7 +524,7 @@ struct zram_rb_req {
/* error status (sync read) */
int error;
};
- u32 index;
+ unsigned long index;
};
#define FOUR_K(x) ((x) * (1 << (PAGE_SHIFT - 12)))
@@ -910,7 +912,7 @@ static void zram_account_writeback_submit(struct zram *zram)
static int zram_writeback_complete(struct zram *zram, struct zram_wb_req *req)
{
- u32 index = req->pps->index;
+ unsigned long index = req->pps->index;
int err;
err = blk_status_to_errno(req->bio.bi_status);
@@ -1032,7 +1034,7 @@ static int zram_writeback_slots(struct zram *zram,
struct zram_wb_req *req = NULL;
struct zram_pp_slot *pps;
int ret = 0, err = 0;
- u32 index = 0;
+ unsigned long index = 0;
while ((pps = select_pp_slot(ctl))) {
if (zram->wb_limit_enable && !zram->bd_wb_limit) {
@@ -1198,7 +1200,7 @@ static void scan_slots_for_writeback(struct zram *zram, u32 mode,
unsigned long lo, unsigned long hi,
struct zram_pp_ctl *ctl)
{
- u32 index = lo;
+ unsigned long index = lo;
while (index < hi) {
bool ok = true;
@@ -1235,8 +1237,8 @@ static ssize_t writeback_store(struct device *dev,
const char *buf, size_t len)
{
struct zram *zram = dev_to_zram(dev);
- u64 nr_pages = zram->disksize >> PAGE_SHIFT;
- unsigned long lo = 0, hi = nr_pages;
+ unsigned long nr_pages;
+ unsigned long lo = 0, hi;
struct zram_pp_ctl *pp_ctl = NULL;
struct zram_wb_ctl *wb_ctl = NULL;
char *args, *param, *val;
@@ -1250,6 +1252,9 @@ static ssize_t writeback_store(struct device *dev,
if (!zram->backing_dev)
return -ENODEV;
+ nr_pages = zram->disksize >> PAGE_SHIFT;
+ hi = nr_pages;
+
pp_ctl = init_pp_ctl();
if (!pp_ctl)
return -ENOMEM;
@@ -1333,7 +1338,8 @@ out:
return ret;
}
-static int decompress_bdev_page(struct zram *zram, struct page *page, u32 index)
+static int decompress_bdev_page(struct zram *zram, struct page *page,
+ unsigned long index)
{
struct zcomp_strm *zstrm;
unsigned int size;
@@ -1375,7 +1381,7 @@ static void zram_deferred_decompress(struct work_struct *w)
struct zram_rb_req *req = container_of(w, struct zram_rb_req, work);
struct page *page = bio_first_page_all(req->bio);
struct zram *zram = req->zram;
- u32 index = req->index;
+ unsigned long index = req->index;
int ret;
ret = decompress_bdev_page(zram, page, index);
@@ -1426,7 +1432,7 @@ static void zram_async_read_endio(struct bio *bio)
}
static int read_from_bdev_async(struct zram *zram, struct page *page,
- u32 index, unsigned long blk_idx,
+ unsigned long index, unsigned long blk_idx,
struct bio *parent)
{
struct zram_rb_req *req;
@@ -1476,8 +1482,8 @@ static void zram_sync_read(struct work_struct *w)
* chained IO with parent IO in same context, it's a deadlock. To avoid that,
* use a worker thread context.
*/
-static int read_from_bdev_sync(struct zram *zram, struct page *page, u32 index,
- unsigned long blk_idx)
+static int read_from_bdev_sync(struct zram *zram, struct page *page,
+ unsigned long index, unsigned long blk_idx)
{
struct zram_rb_req req;
@@ -1496,8 +1502,9 @@ static int read_from_bdev_sync(struct zram *zram, struct page *page, u32 index,
return decompress_bdev_page(zram, page, index);
}
-static int read_from_bdev(struct zram *zram, struct page *page, u32 index,
- unsigned long blk_idx, struct bio *parent)
+static int read_from_bdev(struct zram *zram, struct page *page,
+ unsigned long index, unsigned long blk_idx,
+ struct bio *parent)
{
atomic64_inc(&zram->stats.bd_reads);
if (!parent) {
@@ -1509,8 +1516,9 @@ static int read_from_bdev(struct zram *zram, struct page *page, u32 index,
}
#else
static inline void reset_bdev(struct zram *zram) {};
-static int read_from_bdev(struct zram *zram, struct page *page, u32 index,
- unsigned long blk_idx, struct bio *parent)
+static int read_from_bdev(struct zram *zram, struct page *page,
+ unsigned long index, unsigned long blk_idx,
+ struct bio *parent)
{
return -EIO;
}
@@ -1538,9 +1546,10 @@ static ssize_t read_block_state(struct file *file, char __user *buf,
size_t count, loff_t *ppos)
{
char *kbuf;
- ssize_t index, written = 0;
+ unsigned long index;
+ ssize_t written = 0;
struct zram *zram = file->private_data;
- unsigned long nr_pages = zram->disksize >> PAGE_SHIFT;
+ unsigned long nr_pages;
kbuf = kvmalloc(count, GFP_KERNEL);
if (!kbuf)
@@ -1552,6 +1561,8 @@ static ssize_t read_block_state(struct file *file, char __user *buf,
return -EINVAL;
}
+ nr_pages = zram->disksize >> PAGE_SHIFT;
+
for (index = *ppos; index < nr_pages; index++) {
int copied;
@@ -1560,7 +1571,7 @@ static ssize_t read_block_state(struct file *file, char __user *buf,
goto next;
copied = snprintf(kbuf + written, count,
- "%12zd %12u.%06d %c%c%c%c%c%c\n",
+ "%12lu %12u.%06d %c%c%c%c%c%c\n",
index, zram->table[index].attr.ac_time, 0,
test_slot_flag(zram, index, ZRAM_SAME) ? 's' : '.',
test_slot_flag(zram, index, ZRAM_WB) ? 'w' : '.',
@@ -1652,6 +1663,17 @@ static void comp_algorithm_set(struct zram *zram, u32 prio, const char *alg)
zram->comp_algs[prio] = alg;
}
+static void comp_params_reset(struct zram *zram, u32 prio)
+{
+ struct zcomp_params *params = &zram->params[prio];
+
+ vfree(params->dict);
+ params->level = ZCOMP_PARAM_NOT_SET;
+ params->deflate.winbits = ZCOMP_PARAM_NOT_SET;
+ params->dict_sz = 0;
+ params->dict = NULL;
+}
+
static int __comp_algorithm_store(struct zram *zram, u32 prio, const char *buf)
{
const char