Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1501396
| From | Mike Galbraith <umgwanakikbuti@gmail.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [patch ]mm/zs_malloc: Fix bit spinlock replacement |
| Date | 2016-10-16 05:20 +0200 |
| Message-ID | <ssK9r-62-3@gated-at.bofh.it> (permalink) |
| References | <spcH2-6dt-141@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
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
Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread
[patch ]mm/zs_malloc: Fix bit spinlock replacement Mike Galbraith <umgwanakikbuti@gmail.com> - 2016-10-16 05:20 +0200
Re: [patch ]mm/zs_malloc: Fix bit spinlock replacement Sebastian Andrzej Siewior <bigeasy@linutronix.de> - 2016-10-17 17:20 +0200
Re: [patch ]mm/zs_malloc: Fix bit spinlock replacement Mike Galbraith <umgwanakikbuti@gmail.com> - 2016-10-17 18:20 +0200
[patch v2 ] mm/zs_malloc: Fix bit spinlock replacement Mike Galbraith <umgwanakikbuti@gmail.com> - 2016-10-19 18:00 +0200
Re: [patch v2 ] mm/zs_malloc: Fix bit spinlock replacement Sebastian Andrzej Siewior <bigeasy@linutronix.de> - 2016-10-20 13:00 +0200
csiph-web