* [PATCH] mm: detect numbers of vmstat keys/values mismatch
@ 2018-10-15 18:38 Yu Zhao
2018-10-15 18:41 ` Jann Horn
0 siblings, 1 reply; 3+ messages in thread
From: Yu Zhao @ 2018-10-15 18:38 UTC (permalink / raw)
To: Andrew Morton, Michal Hocko
Cc: Jan Kara, David Rientjes, Kemi Wang, Greg Kroah-Hartman,
Steven Rostedt, Roman Gushchin, Kees Cook, Jann Horn,
Andrey Ryabinin, Sebastian Andrzej Siewior, linux-kernel,
linux-mm, Yu Zhao
There were mismatches between number of vmstat keys and number of
vmstat values. They were fixed recently by:
commit 58bc4c34d249 ("mm/vmstat.c: skip NR_TLB_REMOTE_FLUSH* properly")
commit 28e2c4bb99aa ("mm/vmstat.c: fix outdated vmstat_text")
Add a BUILD_BUG_ON to detect such mismatch and hopefully prevent
it from happening again.
Signed-off-by: Yu Zhao <yuzhao@google.com>
---
include/linux/vmstat.h | 4 ++++
mm/vmstat.c | 18 ++++++++----------
2 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
index f25cef84b41d..33fdd37124cb 100644
--- a/include/linux/vmstat.h
+++ b/include/linux/vmstat.h
@@ -78,6 +78,10 @@ extern void vm_events_fold_cpu(int cpu);
#else
+struct vm_event_state {
+ unsigned long event[0];
+};
+
/* Disable counters */
static inline void count_vm_event(enum vm_event_item item)
{
diff --git a/mm/vmstat.c b/mm/vmstat.c
index 7878da76abf2..7ebf871b4cc9 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -1647,23 +1647,21 @@ enum writeback_stat_item {
NR_VM_WRITEBACK_STAT_ITEMS,
};
+#define NR_VM_STAT_ITEMS (NR_VM_ZONE_STAT_ITEMS + NR_VM_NUMA_STAT_ITEMS + \
+ NR_VM_NODE_STAT_ITEMS + NR_VM_WRITEBACK_STAT_ITEMS + \
+ ARRAY_SIZE(((struct vm_event_state *)0)->event))
+
static void *vmstat_start(struct seq_file *m, loff_t *pos)
{
+ int i;
unsigned long *v;
- int i, stat_items_size;
+
+ BUILD_BUG_ON(ARRAY_SIZE(vmstat_text) != NR_VM_STAT_ITEMS);
if (*pos >= ARRAY_SIZE(vmstat_text))
return NULL;
- stat_items_size = NR_VM_ZONE_STAT_ITEMS * sizeof(unsigned long) +
- NR_VM_NUMA_STAT_ITEMS * sizeof(unsigned long) +
- NR_VM_NODE_STAT_ITEMS * sizeof(unsigned long) +
- NR_VM_WRITEBACK_STAT_ITEMS * sizeof(unsigned long);
-
-#ifdef CONFIG_VM_EVENT_COUNTERS
- stat_items_size += sizeof(struct vm_event_state);
-#endif
- v = kmalloc(stat_items_size, GFP_KERNEL);
+ v = kmalloc_array(NR_VM_STAT_ITEMS, sizeof(unsigned long), GFP_KERNEL);
m->private = v;
if (!v)
return ERR_PTR(-ENOMEM);
--
2.19.1.331.ge82ca0e54c-goog
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mm: detect numbers of vmstat keys/values mismatch
2018-10-15 18:38 [PATCH] mm: detect numbers of vmstat keys/values mismatch Yu Zhao
@ 2018-10-15 18:41 ` Jann Horn
2018-10-15 18:44 ` Yu Zhao
0 siblings, 1 reply; 3+ messages in thread
From: Jann Horn @ 2018-10-15 18:41 UTC (permalink / raw)
To: yuzhao
Cc: Andrew Morton, Michal Hocko, jack, David Rientjes, kemi.wang,
Greg Kroah-Hartman, Steven Rostedt, guro, Kees Cook,
Andrey Ryabinin, bigeasy, kernel list, Linux-MM
On Mon, Oct 15, 2018 at 8:38 PM Yu Zhao <yuzhao@google.com> wrote:
> There were mismatches between number of vmstat keys and number of
> vmstat values. They were fixed recently by:
> commit 58bc4c34d249 ("mm/vmstat.c: skip NR_TLB_REMOTE_FLUSH* properly")
> commit 28e2c4bb99aa ("mm/vmstat.c: fix outdated vmstat_text")
>
> Add a BUILD_BUG_ON to detect such mismatch and hopefully prevent
> it from happening again.
A BUILD_BUG_ON() like this is already in the mm tree:
https://ozlabs.org/~akpm/mmotm/broken-out/mm-vmstat-assert-that-vmstat_text-is-in-sync-with-stat_items_size.patch
> Signed-off-by: Yu Zhao <yuzhao@google.com>
> ---
> include/linux/vmstat.h | 4 ++++
> mm/vmstat.c | 18 ++++++++----------
> 2 files changed, 12 insertions(+), 10 deletions(-)
>
> diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
> index f25cef84b41d..33fdd37124cb 100644
> --- a/include/linux/vmstat.h
> +++ b/include/linux/vmstat.h
> @@ -78,6 +78,10 @@ extern void vm_events_fold_cpu(int cpu);
>
> #else
>
> +struct vm_event_state {
> + unsigned long event[0];
> +};
> +
> /* Disable counters */
> static inline void count_vm_event(enum vm_event_item item)
> {
> diff --git a/mm/vmstat.c b/mm/vmstat.c
> index 7878da76abf2..7ebf871b4cc9 100644
> --- a/mm/vmstat.c
> +++ b/mm/vmstat.c
> @@ -1647,23 +1647,21 @@ enum writeback_stat_item {
> NR_VM_WRITEBACK_STAT_ITEMS,
> };
>
> +#define NR_VM_STAT_ITEMS (NR_VM_ZONE_STAT_ITEMS + NR_VM_NUMA_STAT_ITEMS + \
> + NR_VM_NODE_STAT_ITEMS + NR_VM_WRITEBACK_STAT_ITEMS + \
> + ARRAY_SIZE(((struct vm_event_state *)0)->event))
> +
> static void *vmstat_start(struct seq_file *m, loff_t *pos)
> {
> + int i;
> unsigned long *v;
> - int i, stat_items_size;
> +
> + BUILD_BUG_ON(ARRAY_SIZE(vmstat_text) != NR_VM_STAT_ITEMS);
>
> if (*pos >= ARRAY_SIZE(vmstat_text))
> return NULL;
> - stat_items_size = NR_VM_ZONE_STAT_ITEMS * sizeof(unsigned long) +
> - NR_VM_NUMA_STAT_ITEMS * sizeof(unsigned long) +
> - NR_VM_NODE_STAT_ITEMS * sizeof(unsigned long) +
> - NR_VM_WRITEBACK_STAT_ITEMS * sizeof(unsigned long);
> -
> -#ifdef CONFIG_VM_EVENT_COUNTERS
> - stat_items_size += sizeof(struct vm_event_state);
> -#endif
>
> - v = kmalloc(stat_items_size, GFP_KERNEL);
> + v = kmalloc_array(NR_VM_STAT_ITEMS, sizeof(unsigned long), GFP_KERNEL);
> m->private = v;
> if (!v)
> return ERR_PTR(-ENOMEM);
> --
> 2.19.1.331.ge82ca0e54c-goog
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mm: detect numbers of vmstat keys/values mismatch
2018-10-15 18:41 ` Jann Horn
@ 2018-10-15 18:44 ` Yu Zhao
0 siblings, 0 replies; 3+ messages in thread
From: Yu Zhao @ 2018-10-15 18:44 UTC (permalink / raw)
To: Jann Horn
Cc: Andrew Morton, Michal Hocko, jack, David Rientjes, kemi.wang,
Greg Kroah-Hartman, Steven Rostedt, guro, Kees Cook,
Andrey Ryabinin, bigeasy, kernel list, Linux-MM
On Mon, Oct 15, 2018 at 08:41:52PM +0200, Jann Horn wrote:
> On Mon, Oct 15, 2018 at 8:38 PM Yu Zhao <yuzhao@google.com> wrote:
> > There were mismatches between number of vmstat keys and number of
> > vmstat values. They were fixed recently by:
> > commit 58bc4c34d249 ("mm/vmstat.c: skip NR_TLB_REMOTE_FLUSH* properly")
> > commit 28e2c4bb99aa ("mm/vmstat.c: fix outdated vmstat_text")
> >
> > Add a BUILD_BUG_ON to detect such mismatch and hopefully prevent
> > it from happening again.
>
> A BUILD_BUG_ON() like this is already in the mm tree:
> https://ozlabs.org/~akpm/mmotm/broken-out/mm-vmstat-assert-that-vmstat_text-is-in-sync-with-stat_items_size.patch
My bad! Didn't notice this. Please disregard this patch.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-10-15 18:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-15 18:38 [PATCH] mm: detect numbers of vmstat keys/values mismatch Yu Zhao
2018-10-15 18:41 ` Jann Horn
2018-10-15 18:44 ` Yu Zhao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox