Skip to content

Commit a372659

Browse files
umgwanakikbutitorvalds
authored andcommitted
zsmalloc: replace get_cpu_var with local_lock
The usage of get_cpu_var() in zs_map_object() is problematic because it disables preemption and makes it impossible to acquire any sleeping lock on PREEMPT_RT such as a spinlock_t. Replace the get_cpu_var() usage with a local_lock_t which is embedded struct mapping_area. It ensures that the access the struct is synchronized against all users on the same CPU. [minchan: remove the bit_spin_lock part and change the title] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Mike Galbraith <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Minchan Kim <[email protected]> Tested-by: Sebastian Andrzej Siewior <[email protected]> Cc: Peter Zijlstra (Intel) <[email protected]> Cc: Sergey Senozhatsky <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent b475d42 commit a372659

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

mm/zsmalloc.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#include <linux/wait.h>
6666
#include <linux/pagemap.h>
6767
#include <linux/fs.h>
68+
#include <linux/local_lock.h>
6869

6970
#define ZSPAGE_MAGIC 0x58
7071

@@ -276,6 +277,7 @@ struct zspage {
276277
};
277278

278279
struct mapping_area {
280+
local_lock_t lock;
279281
char *vm_buf; /* copy buffer for objects that span pages */
280282
char *vm_addr; /* address of kmap_atomic()'ed pages */
281283
enum zs_mapmode vm_mm; /* mapping mode */
@@ -451,7 +453,9 @@ MODULE_ALIAS("zpool-zsmalloc");
451453
#endif /* CONFIG_ZPOOL */
452454

453455
/* per-cpu VM mapping areas for zspage accesses that cross page boundaries */
454-
static DEFINE_PER_CPU(struct mapping_area, zs_map_area);
456+
static DEFINE_PER_CPU(struct mapping_area, zs_map_area) = {
457+
.lock = INIT_LOCAL_LOCK(lock),
458+
};
455459

456460
static __maybe_unused int is_first_page(struct page *page)
457461
{
@@ -1269,7 +1273,8 @@ void *zs_map_object(struct zs_pool *pool, unsigned long handle,
12691273
class = zspage_class(pool, zspage);
12701274
off = (class->size * obj_idx) & ~PAGE_MASK;
12711275

1272-
area = &get_cpu_var(zs_map_area);
1276+
local_lock(&zs_map_area.lock);
1277+
area = this_cpu_ptr(&zs_map_area);
12731278
area->vm_mm = mm;
12741279
if (off + class->size <= PAGE_SIZE) {
12751280
/* this object is contained entirely within a page */
@@ -1320,7 +1325,7 @@ void zs_unmap_object(struct zs_pool *pool, unsigned long handle)
13201325

13211326
__zs_unmap_object(area, pages, off, class->size);
13221327
}
1323-
put_cpu_var(zs_map_area);
1328+
local_unlock(&zs_map_area.lock);
13241329

13251330
migrate_read_unlock(zspage);
13261331
}

0 commit comments

Comments
 (0)