* [PATCH 4.2] zram: fix pool names truncation
@ 2015-08-11 13:33 Sergey Senozhatsky
2015-08-11 13:33 ` [PATCH] zram: fix max pool limitation Sergey Senozhatsky
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Sergey Senozhatsky @ 2015-08-11 13:33 UTC (permalink / raw)
To: Andrew Morton, Minchan Kim
Cc: linux-kernel, Sergey Senozhatsky, Sergey Senozhatsky
Hello,
found this reading the code just now. I do believe we need this
patch in 4.2 (before 4.3), because the bug breaks new devices
creation under some specific conditions -- new pool names are
getting truncated to only 3 digits and, thus,
debugfs_create_dir() fails.
The commit message contains more details.
Andrew, can you please pick up this patch?
Sergey Senozhatsky (1):
zram: fix max pool limitation
drivers/block/zram/zram_drv.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--
2.5.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] zram: fix max pool limitation
2015-08-11 13:33 [PATCH 4.2] zram: fix pool names truncation Sergey Senozhatsky
@ 2015-08-11 13:33 ` Sergey Senozhatsky
2015-08-11 14:38 ` Sergey Senozhatsky
2015-08-11 15:43 ` [PATCH v2] zram: fix pool name truncation Sergey Senozhatsky
` (2 subsequent siblings)
3 siblings, 1 reply; 6+ messages in thread
From: Sergey Senozhatsky @ 2015-08-11 13:33 UTC (permalink / raw)
To: Andrew Morton, Minchan Kim
Cc: linux-kernel, Sergey Senozhatsky, Sergey Senozhatsky
zram_meta_alloc() constructs a pool name for zs_create_pool() call
as
snprintf(pool_name, sizeof(pool_name), "zram%d", device_id);
However, it defines pool name buffer to be only 8 chars long
(minus trailing zero), which means that we can have only 1000
pool names: zram0 -- zram999.
With CONFIG_ZSMALLOC_STAT enabled an attempt to create a device
zram1000 can fail if device zram100 already exists, because
snprintf() will truncate new pool name to zram100 and pass it
to debugfs_create_dir(), causing:
debugfs dir <zram100> creation failed
zram: Error creating memory pool
... and so on (zram101 - zram1010, etc).
Fix it by increasing pool_name buffer size to 11:
-- zram prefix (length 4)
-- int device_id can use up to 10 chars
-- terminating zero byte
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
---
drivers/block/zram/zram_drv.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index b088ca9..1dec01d 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -502,7 +502,7 @@ static void zram_meta_free(struct zram_meta *meta, u64 disksize)
static struct zram_meta *zram_meta_alloc(int device_id, u64 disksize)
{
size_t num_pages;
- char pool_name[8];
+ char pool_name[15];
struct zram_meta *meta = kmalloc(sizeof(*meta), GFP_KERNEL);
if (!meta)
--
2.5.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] zram: fix max pool limitation
2015-08-11 13:33 ` [PATCH] zram: fix max pool limitation Sergey Senozhatsky
@ 2015-08-11 14:38 ` Sergey Senozhatsky
0 siblings, 0 replies; 6+ messages in thread
From: Sergey Senozhatsky @ 2015-08-11 14:38 UTC (permalink / raw)
To: Sergey Senozhatsky
Cc: Andrew Morton, Minchan Kim, linux-kernel, Sergey Senozhatsky
On (08/11/15 22:33), Sergey Senozhatsky wrote:
> zram_meta_alloc() constructs a pool name for zs_create_pool() call
> as
> snprintf(pool_name, sizeof(pool_name), "zram%d", device_id);
>
> However, it defines pool name buffer to be only 8 chars long
> (minus trailing zero), which means that we can have only 1000
> pool names: zram0 -- zram999.
>
> With CONFIG_ZSMALLOC_STAT enabled an attempt to create a device
> zram1000 can fail if device zram100 already exists, because
> snprintf() will truncate new pool name to zram100 and pass it
> to debugfs_create_dir(), causing:
>
> debugfs dir <zram100> creation failed
> zram: Error creating memory pool
>
> ... and so on (zram101 - zram1010, etc).
>
> Fix it by increasing pool_name buffer size to 11:
oh... don't know how this happened. to 15.
-ss
> -- zram prefix (length 4)
> -- int device_id can use up to 10 chars
> -- terminating zero byte
>
> Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
> ---
> drivers/block/zram/zram_drv.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> index b088ca9..1dec01d 100644
> --- a/drivers/block/zram/zram_drv.c
> +++ b/drivers/block/zram/zram_drv.c
> @@ -502,7 +502,7 @@ static void zram_meta_free(struct zram_meta *meta, u64 disksize)
> static struct zram_meta *zram_meta_alloc(int device_id, u64 disksize)
> {
> size_t num_pages;
> - char pool_name[8];
> + char pool_name[15];
> struct zram_meta *meta = kmalloc(sizeof(*meta), GFP_KERNEL);
>
> if (!meta)
> --
> 2.5.0
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2] zram: fix pool name truncation
2015-08-11 13:33 [PATCH 4.2] zram: fix pool names truncation Sergey Senozhatsky
2015-08-11 13:33 ` [PATCH] zram: fix max pool limitation Sergey Senozhatsky
@ 2015-08-11 15:43 ` Sergey Senozhatsky
2015-08-12 13:30 ` [PATCH 4.2] zram: fix pool names truncation Sergey Senozhatsky
2015-08-12 13:32 ` [PATCH v3] zram: fix pool name truncation Sergey Senozhatsky
3 siblings, 0 replies; 6+ messages in thread
From: Sergey Senozhatsky @ 2015-08-11 15:43 UTC (permalink / raw)
To: Andrew Morton, Minchan Kim
Cc: linux-kernel, Sergey Senozhatsky, Sergey Senozhatsky
zram_meta_alloc() constructs a pool name for zs_create_pool() call
as
snprintf(pool_name, sizeof(pool_name), "zram%d", device_id);
However, it defines pool name buffer to be only 8 chars long
(minus trailing zero), which means that we can have only 1000
pool names: zram0 -- zram999.
With CONFIG_ZSMALLOC_STAT enabled an attempt to create a device
zram1000 can fail if device zram100 already exists, because
snprintf() will truncate new pool name to zram100 and pass it
to debugfs_create_dir(), causing:
debugfs dir <zram100> creation failed
zram: Error creating memory pool
... and so on (zram101 - zram1010, etc).
Fix it by increasing pool_name buffer size to 15:
-- zram prefix (length 4)
-- int device_id can use up to 10 chars
-- terminating zero byte
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
---
drivers/block/zram/zram_drv.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index b088ca9..1dec01d 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -502,7 +502,7 @@ static void zram_meta_free(struct zram_meta *meta, u64 disksize)
static struct zram_meta *zram_meta_alloc(int device_id, u64 disksize)
{
size_t num_pages;
- char pool_name[8];
+ char pool_name[15];
struct zram_meta *meta = kmalloc(sizeof(*meta), GFP_KERNEL);
if (!meta)
--
2.5.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 4.2] zram: fix pool names truncation
2015-08-11 13:33 [PATCH 4.2] zram: fix pool names truncation Sergey Senozhatsky
2015-08-11 13:33 ` [PATCH] zram: fix max pool limitation Sergey Senozhatsky
2015-08-11 15:43 ` [PATCH v2] zram: fix pool name truncation Sergey Senozhatsky
@ 2015-08-12 13:30 ` Sergey Senozhatsky
2015-08-12 13:32 ` [PATCH v3] zram: fix pool name truncation Sergey Senozhatsky
3 siblings, 0 replies; 6+ messages in thread
From: Sergey Senozhatsky @ 2015-08-12 13:30 UTC (permalink / raw)
To: Andrew Morton
Cc: Minchan Kim, linux-kernel, Sergey Senozhatsky, Sergey Senozhatsky
On (08/11/15 22:33), Sergey Senozhatsky wrote:
> found this reading the code just now. I do believe we need this
> patch in 4.2 (before 4.3), because the bug breaks new devices
> creation under some specific conditions -- new pool names are
> getting truncated to only 3 digits and, thus,
> debugfs_create_dir() fails.
>
> The commit message contains more details.
>
Hello,
I have an alternative fix; a somewhat better one. We actually
don't have to snprintf() there anything. We already have
zram->disk->disk_name constructed exactly same way, so we can
pass it to zram_meta_alloc() instead of device_id.
I'll send out a patch shortly.
-ss
>
> Andrew, can you please pick up this patch?
>
>
> Sergey Senozhatsky (1):
> zram: fix max pool limitation
>
> drivers/block/zram/zram_drv.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> --
> 2.5.0
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v3] zram: fix pool name truncation
2015-08-11 13:33 [PATCH 4.2] zram: fix pool names truncation Sergey Senozhatsky
` (2 preceding siblings ...)
2015-08-12 13:30 ` [PATCH 4.2] zram: fix pool names truncation Sergey Senozhatsky
@ 2015-08-12 13:32 ` Sergey Senozhatsky
3 siblings, 0 replies; 6+ messages in thread
From: Sergey Senozhatsky @ 2015-08-12 13:32 UTC (permalink / raw)
To: Andrew Morton, Minchan Kim
Cc: linux-kernel, Sergey Senozhatsky, Sergey Senozhatsky
zram_meta_alloc() constructs a pool name for zs_create_pool() call
as
snprintf(pool_name, sizeof(pool_name), "zram%d", device_id);
However, it defines pool name buffer to be only 8 bytes long
(minus trailing zero), which means that we can have only 1000
pool names: zram0 -- zram999.
With CONFIG_ZSMALLOC_STAT enabled an attempt to create a device
zram1000 can fail if device zram100 already exists, because
snprintf() will truncate new pool name to zram100 and pass it
debugfs_create_dir(), causing:
debugfs dir <zram100> creation failed
zram: Error creating memory pool
... and so on.
Fix it by passing zram->disk->disk_name to zram_meta_alloc()
instead of divice_id. We construct zram%d name earlier and
keep it as a ->disk_name, no need to snprintf() it again.
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
---
drivers/block/zram/zram_drv.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index b088ca9..c87d2f6 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -499,10 +499,9 @@ static void zram_meta_free(struct zram_meta *meta, u64 disksize)
kfree(meta);
}
-static struct zram_meta *zram_meta_alloc(int device_id, u64 disksize)
+static struct zram_meta *zram_meta_alloc(char *pool_name, u64 disksize)
{
size_t num_pages;
- char pool_name[8];
struct zram_meta *meta = kmalloc(sizeof(*meta), GFP_KERNEL);
if (!meta)
@@ -515,7 +514,6 @@ static struct zram_meta *zram_meta_alloc(int device_id, u64 disksize)
goto out_error;
}
- snprintf(pool_name, sizeof(pool_name), "zram%d", device_id);
meta->mem_pool = zs_create_pool(pool_name, GFP_NOIO | __GFP_HIGHMEM);
if (!meta->mem_pool) {
pr_err("Error creating memory pool\n");
@@ -1033,7 +1031,7 @@ static ssize_t disksize_store(struct device *dev,
return -EINVAL;
disksize = PAGE_ALIGN(disksize);
- meta = zram_meta_alloc(zram->disk->first_minor, disksize);
+ meta = zram_meta_alloc(zram->disk->disk_name, disksize);
if (!meta)
return -ENOMEM;
--
2.5.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-08-12 13:33 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-11 13:33 [PATCH 4.2] zram: fix pool names truncation Sergey Senozhatsky
2015-08-11 13:33 ` [PATCH] zram: fix max pool limitation Sergey Senozhatsky
2015-08-11 14:38 ` Sergey Senozhatsky
2015-08-11 15:43 ` [PATCH v2] zram: fix pool name truncation Sergey Senozhatsky
2015-08-12 13:30 ` [PATCH 4.2] zram: fix pool names truncation Sergey Senozhatsky
2015-08-12 13:32 ` [PATCH v3] zram: fix pool name truncation Sergey Senozhatsky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox