Re: [PATCH 7/8] zram: Use local lock to protect per-CPU data

2020-05-20 Thread Peter Zijlstra
On Tue, May 19, 2020 at 10:19:11PM +0200, Sebastian Andrzej Siewior wrote:
> +static DEFINE_LOCAL_LOCK(zcomp_lock);
> +
>  struct zcomp_strm *zcomp_stream_get(struct zcomp *comp)
>  {
> - return *get_cpu_ptr(comp->stream);
> + local_lock(zcomp_lock);
> + return *this_cpu_ptr(comp->stream);
>  }

put it in struct czomp_strm ?


[PATCH 7/8] zram: Use local lock to protect per-CPU data

2020-05-19 Thread Sebastian Andrzej Siewior
From: Mike Galbraith 

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]

Cc: Minchan Kim 
Cc: Nitin Gupta 
Cc: Sergey Senozhatsky 
Signed-off-by: Mike Galbraith 
Signed-off-by: Sebastian Andrzej Siewior 
---
 drivers/block/zram/zcomp.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c
index 1a8564a79d8dc..32854d460b299 100644
--- a/drivers/block/zram/zcomp.c
+++ b/drivers/block/zram/zcomp.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "zcomp.h"
 
@@ -111,14 +112,17 @@ ssize_t zcomp_available_show(const char *comp, char *buf)
return sz;
 }
 
+static DEFINE_LOCAL_LOCK(zcomp_lock);
+
 struct zcomp_strm *zcomp_stream_get(struct zcomp *comp)
 {
-   return *get_cpu_ptr(comp->stream);
+   local_lock(zcomp_lock);
+   return *this_cpu_ptr(comp->stream);
 }
 
 void zcomp_stream_put(struct zcomp *comp)
 {
-   put_cpu_ptr(comp->stream);
+   local_unlock(zcomp_lock);
 }
 
 int zcomp_compress(struct zcomp_strm *zstrm,
-- 
2.26.2