All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Galbraith <umgwanakikbuti@gmail.com>
To: Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Thomas Gleixner <tglx@linutronix.de>
Cc: LKML <linux-kernel@vger.kernel.org>,
	linux-rt-users <linux-rt-users@vger.kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>
Subject: [patch ]mm/zs_malloc: Fix bit spinlock replacement
Date: Sun, 16 Oct 2016 05:18:03 +0200	[thread overview]
Message-ID: <1476587883.1538.12.camel@gmail.com> (raw)
In-Reply-To: <20161006085228.jl6rpszdp5c2p2nr@linutronix.de>


Do not alter HANDLE_SIZE, memory corruption ensues.  The handle is
a pointer, allocate space for the struct it points to and align it
ZS_ALIGN.  Also, when accessing the struct, mask HANDLE_PIN_BIT.

Signed-off-by: Mike Galbraith <umgwanakikbuti@gmail.com>
---
 mm/zsmalloc.c |   13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -71,6 +71,8 @@
 #define ZS_MAX_ZSPAGE_ORDER 2
 #define ZS_MAX_PAGES_PER_ZSPAGE (_AC(1, UL) << ZS_MAX_ZSPAGE_ORDER)
 
+#define ZS_HANDLE_SIZE (sizeof(unsigned long))
+
 #ifdef CONFIG_PREEMPT_RT_BASE
 
 struct zsmalloc_handle {
@@ -78,11 +80,11 @@ struct zsmalloc_handle {
 	struct mutex lock;
 };
 
-#define ZS_HANDLE_SIZE (sizeof(struct zsmalloc_handle))
+#define ZS_HANDLE_ALLOC_SIZE (sizeof(struct zsmalloc_handle))
 
 #else
 
-#define ZS_HANDLE_SIZE (sizeof(unsigned long))
+#define ZS_HANDLE_ALLOC_SIZE ZS_HANDLE_SIZE
 #endif
 
 /*
@@ -339,8 +341,9 @@ static void SetZsPageMovable(struct zs_p
 
 static int create_cache(struct zs_pool *pool)
 {
-	pool->handle_cachep = kmem_cache_create("zs_handle", ZS_HANDLE_SIZE,
-					0, 0, NULL);
+	pool->handle_cachep = kmem_cache_create("zs_handle",
+						ZS_HANDLE_ALLOC_SIZE,
+						ZS_ALIGN, 0, NULL);
 	if (!pool->handle_cachep)
 		return 1;
 
@@ -380,7 +383,7 @@ static unsigned long cache_alloc_handle(
 #ifdef CONFIG_PREEMPT_RT_BASE
 static struct zsmalloc_handle *zs_get_pure_handle(unsigned long handle)
 {
-	return (void *)(handle &~((1 << OBJ_TAG_BITS) - 1));
+	return (void *)(handle & ~BIT(HANDLE_PIN_BIT));
 }
 #endif
 

  parent reply	other threads:[~2016-10-16  3:18 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-06  8:52 [ANNOUNCE] 4.8-rt1 Sebastian Andrzej Siewior
2016-10-16  3:08 ` [patch] ftrace: Fix latency trace header alignment Mike Galbraith
2016-10-17 13:23   ` Sebastian Andrzej Siewior
2016-10-16  3:11 ` [patch] drivers,connector: Protect send_msg() with a local lock for RT Mike Galbraith
2016-10-17 14:16   ` Sebastian Andrzej Siewior
2016-10-16  3:14 ` [patch] drivers/zram: Don't disable preemption in zcomp_stream_get/put() Mike Galbraith
2016-10-17 14:24   ` Sebastian Andrzej Siewior
2016-10-17 16:19     ` Mike Galbraith
2016-10-17 16:29       ` Sebastian Andrzej Siewior
2016-10-17 17:18         ` Mike Galbraith
2016-10-17 17:46           ` Mike Galbraith
2016-10-19 15:56     ` [patch v2] " Mike Galbraith
2016-10-19 16:54       ` Sebastian Andrzej Siewior
2016-10-20  2:59         ` Mike Galbraith
2016-10-20 11:02       ` Sebastian Andrzej Siewior
2016-10-16  3:18 ` Mike Galbraith [this message]
2016-10-17 15:15   ` [patch ]mm/zs_malloc: Fix bit spinlock replacement Sebastian Andrzej Siewior
2016-10-17 16:12     ` Mike Galbraith
2016-10-17 16:12       ` Mike Galbraith
2016-10-19 15:50   ` [patch v2 ] mm/zs_malloc: " Mike Galbraith
2016-10-20 10:59     ` Sebastian Andrzej Siewior
2016-10-20  9:34 ` [rfc patch] hotplug: Call mmdrop_delayed() in sched_cpu_dying() if PREEMPT_RT_FULL Mike Galbraith
2016-10-20 11:21   ` Sebastian Andrzej Siewior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1476587883.1538.12.camel@gmail.com \
    --to=umgwanakikbuti@gmail.com \
    --cc=bigeasy@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.