Commit 005a79e5 authored by Gerald Schaefer's avatar Gerald Schaefer Committed by Linus Torvalds

mm/slub: fix endianness bug for alloc/free_traces attributes

On big-endian s390, the alloc/free_traces attributes produce endless
output, because of always 0 idx in slab_debugfs_show().

idx is de-referenced from *v, which points to a loff_t value, with

    unsigned int idx = *(unsigned int *)v;

This will only give the upper 32 bits on big-endian, which remain 0.

Instead of only fixing this de-reference, during discussion it seemed
more appropriate to change the seq_ops so that they use an explicit
iterator in private loc_track struct.

This patch adds idx to loc_track, which will also fix the endianness
bug.

Link: https://lore.kernel.org/r/20211117193932.4049412-1-gerald.schaefer@linux.ibm.com
Link: https://lkml.kernel.org/r/20211126171848.17534-1-gerald.schaefer@linux.ibm.com
Fixes: 64dd6849 ("mm: slub: move sysfs slab alloc/free interfaces to debugfs")
Signed-off-by: default avatarGerald Schaefer <gerald.schaefer@linux.ibm.com>
Reported-by: default avatarSteffen Maier <maier@linux.ibm.com>
Acked-by: default avatarVlastimil Babka <vbabka@suse.cz>
Cc: Faiyaz Mohammed <faiyazm@codeaurora.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Christoph Lameter <cl@linux.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 9ab3b0c8
...@@ -5081,6 +5081,7 @@ struct loc_track { ...@@ -5081,6 +5081,7 @@ struct loc_track {
unsigned long max; unsigned long max;
unsigned long count; unsigned long count;
struct location *loc; struct location *loc;
loff_t idx;
}; };
static struct dentry *slab_debugfs_root; static struct dentry *slab_debugfs_root;
...@@ -6052,11 +6053,11 @@ __initcall(slab_sysfs_init); ...@@ -6052,11 +6053,11 @@ __initcall(slab_sysfs_init);
#if defined(CONFIG_SLUB_DEBUG) && defined(CONFIG_DEBUG_FS) #if defined(CONFIG_SLUB_DEBUG) && defined(CONFIG_DEBUG_FS)
static int slab_debugfs_show(struct seq_file *seq, void *v) static int slab_debugfs_show(struct seq_file *seq, void *v)
{ {
struct location *l;
unsigned int idx = *(unsigned int *)v;
struct loc_track *t = seq->private; struct loc_track *t = seq->private;
struct location *l;
unsigned long idx;
idx = (unsigned long) t->idx;
if (idx < t->count) { if (idx < t->count) {
l = &t->loc[idx]; l = &t->loc[idx];
...@@ -6105,16 +6106,18 @@ static void *slab_debugfs_next(struct seq_file *seq, void *v, loff_t *ppos) ...@@ -6105,16 +6106,18 @@ static void *slab_debugfs_next(struct seq_file *seq, void *v, loff_t *ppos)
{ {
struct loc_track *t = seq->private; struct loc_track *t = seq->private;
v = ppos; t->idx = ++(*ppos);
++*ppos;
if (*ppos <= t->count) if (*ppos <= t->count)
return v; return ppos;
return NULL; return NULL;
} }
static void *slab_debugfs_start(struct seq_file *seq, loff_t *ppos) static void *slab_debugfs_start(struct seq_file *seq, loff_t *ppos)
{ {
struct loc_track *t = seq->private;
t->idx = *ppos;
return ppos; return ppos;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment