Skip to content

Commit 19f545b

Browse files
umgwanakikbutiIngo Molnar
authored andcommitted
zram: Use local lock to protect per-CPU data
The zcomp driver uses per-CPU compression. The per-CPU data pointer is acquired with get_cpu_ptr() which implicitly disables preemption. It allocates memory inside the preempt disabled region which conflicts with the PREEMPT_RT semantics. Replace the implicit preemption control with an explicit local lock. This allows RT kernels to substitute it with a real per CPU lock, which serializes the access but keeps the code section preemptible. On non RT kernels this maps to preempt_disable() as before, i.e. no functional change. [bigeasy: Use local_lock(), description, drop reordering] Signed-off-by: Mike Galbraith <[email protected]> Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Acked-by: Peter Zijlstra <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent ed19f19 commit 19f545b

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

drivers/block/zram/zcomp.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,13 @@ ssize_t zcomp_available_show(const char *comp, char *buf)
110110

111111
struct zcomp_strm *zcomp_stream_get(struct zcomp *comp)
112112
{
113-
return get_cpu_ptr(comp->stream);
113+
local_lock(&comp->stream->lock);
114+
return this_cpu_ptr(comp->stream);
114115
}
115116

116117
void zcomp_stream_put(struct zcomp *comp)
117118
{
118-
put_cpu_ptr(comp->stream);
119+
local_unlock(&comp->stream->lock);
119120
}
120121

121122
int zcomp_compress(struct zcomp_strm *zstrm,
@@ -159,6 +160,8 @@ int zcomp_cpu_up_prepare(unsigned int cpu, struct hlist_node *node)
159160
int ret;
160161

161162
zstrm = per_cpu_ptr(comp->stream, cpu);
163+
local_lock_init(&zstrm->lock);
164+
162165
ret = zcomp_strm_init(zstrm, comp);
163166
if (ret)
164167
pr_err("Can't allocate a compression stream\n");

drivers/block/zram/zcomp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55

66
#ifndef _ZCOMP_H_
77
#define _ZCOMP_H_
8+
#include <linux/local_lock.h>
89

910
struct zcomp_strm {
11+
/* The members ->buffer and ->tfm are protected by ->lock. */
12+
local_lock_t lock;
1013
/* compression/decompression buffer */
1114
void *buffer;
1215
struct crypto_comp *tfm;

0 commit comments

Comments
 (0)