From patchwork Mon Oct 15 18:38:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Zhao X-Patchwork-Id: 10642411 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0395E112B for ; Mon, 15 Oct 2018 18:38:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E8E9B29A35 for ; Mon, 15 Oct 2018 18:38:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DBE1A29ADB; Mon, 15 Oct 2018 18:38:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7368629A35 for ; Mon, 15 Oct 2018 18:38:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 46B136B0266; Mon, 15 Oct 2018 14:38:48 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3F0606B026A; Mon, 15 Oct 2018 14:38:48 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 294016B026B; Mon, 15 Oct 2018 14:38:48 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-it1-f200.google.com (mail-it1-f200.google.com [209.85.166.200]) by kanga.kvack.org (Postfix) with ESMTP id 003F16B0266 for ; Mon, 15 Oct 2018 14:38:47 -0400 (EDT) Received: by mail-it1-f200.google.com with SMTP id m67-v6so18173926ita.8 for ; Mon, 15 Oct 2018 11:38:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:mime-version:content-transfer-encoding; bh=FB27Bd0ZCxbVI2xpfmkuDM1L376zbfAO2vlWDhwgClM=; b=mn5qpPRckOzAc/wi5Lyi0nY21rLiN8NqZk0LaO/pLfAQUGZbXUjR7LzMOybR7hiHdd nMNm3xjktbf3t3wLPKt4nvT4X5a+bixUDCdSFeZG7B3J3mqg43vdEG9z/qIDKCRoxmxL qDkngod2TDn/l7xNK7jD6D5LjJ0tCue58xHzVnpW8vuCmjX0FX2EN/Ne+5YrJyFV2HcR qmREBFNcBZCqZcepsN4MySxEGv8okOWb50xfYz8PeyEXDbl1mfYsp4wAFqgEYAPNqwpf dYhqS7QRxigZM1VLIVi4QfyY1L1dM/al/LTHy9ieMd1L1GQwWrm8jhWMuQQlT9bGGawS 2nLg== X-Gm-Message-State: ABuFfoj9PKcfyX6q4XeMYgePiWE7BMprP7HwwmQ6SHy1ng3AS4A7ove3 4MlL0H521s499hM9ur0DVdXcZHWRDVrj/9ya2oeeKxnE1rGvrr7gG9gPliJZex0atowFGcDrOG+ rAsElg4WIKhtNCt8EPmzN1356B4dx9kWlBQUwdRQn+u3VrQHz3BnPoHV8dyaHC6MT/0d0v3/hNQ GJKgbDUvnxBkOgu0uKNng6xHlI5VUS1PG3kM4yh7Ar4Cs2rsZuB0grfQlH4x3eKKZldCuE2onC2 WLdbPlSR6Mp2ZFa53+QG/5SEy9QKL7OjxQm2ukuUSKYC79Awupi1pLptJPXxEyoYPV0n59JNQ8O vEvNMi4KzkWWat0BPV6BJnA7En8MKRn0nN//yN3JX9p2JF7J1WmZ7bV3ydqDbcsM/QOvKeNzYCO y X-Received: by 2002:a24:6841:: with SMTP id v62-v6mr13002055itb.8.1539628727741; Mon, 15 Oct 2018 11:38:47 -0700 (PDT) X-Received: by 2002:a24:6841:: with SMTP id v62-v6mr13002021itb.8.1539628727116; Mon, 15 Oct 2018 11:38:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539628727; cv=none; d=google.com; s=arc-20160816; b=o8dGV4lGw+hPifal0773LN8eGarhB+wY7BB0yxLWOBZtBh6ZuxnOP2Mb9cdanef/6S yYbq5vlauhI30mWltAaNvpy5Iiax1DHNIK5Xit9H7DSxYhqrobHygixxtRBon4VU6Y/1 yyYEgDq0ENVizTFWPiquUMp4UPBE8vJOLYNYj7d6xHQOlqyKrLZf1ycBnyWKTruO8zky +jf4bbewr6NIhCjtmdhyCA8t+rq+3IDxTeBePDtTbWWc+Ejb5ypY9VY65DX+ZCTldh7Y QGTxqN16u2Sij3NcqTCb1Kliq5m7aIaWwjqnCoNIg8C/IWixjdQqyRZluPT1BYpH0FX1 vOxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=FB27Bd0ZCxbVI2xpfmkuDM1L376zbfAO2vlWDhwgClM=; b=ddo6L4h/CmZw+lsjDFVU3d0IElqRJV4AIUUbgO4ubXUOj1Ke2G9Sw5jn1oY9iHNJMR v8TfVknHdb7SgbbTw9crzZqyRoAUh8B83BMmQ1ofBoSkybZGPu2sDhhLHiHpwwZMLMNn qnn/Z/oBgffS25fNTrG7CMwdccTJRrlGXTDi06vIrF0uiMcgaanp2WeuoozERRbZUCb+ B9t/hNty/NW7lC5zXyK2t07qvNBLB4OsheKzG7A6N64OGsi9ztm6jvQy21X6Zv+vqd+n aL3c+EsMSbwZwWWzMidF7SNBMwLawyqQcegx5+Bq2vdg42m3YlCQEeJL5b65ucr9j1l3 mCgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=eqQOtV1w; spf=pass (google.com: domain of yuzhao@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=yuzhao@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id k14-v6sor5177950iog.54.2018.10.15.11.38.47 for (Google Transport Security); Mon, 15 Oct 2018 11:38:47 -0700 (PDT) Received-SPF: pass (google.com: domain of yuzhao@google.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=eqQOtV1w; spf=pass (google.com: domain of yuzhao@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=yuzhao@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=FB27Bd0ZCxbVI2xpfmkuDM1L376zbfAO2vlWDhwgClM=; b=eqQOtV1w+ZQOgh4MkPoaMGVdeg1qMF2xxJp+KZztdyjuGO5jESuQQXJEuH996LMttB HUs9XsC2VyomHR8kx3HWdLPFn9D8yh89ty+M9Sqb1whj+Y3M+yDB/0vd9H8MWSBwwVjg XVM/A/D9MxK2aoP0Qo/91+lgPl2jTI9nGDsXODVK7mS3EO29S7WPpiGcie15DPD2Vwvr cjC6oexlB0SfCOQ2RQ4Dopr7x/PLsEfpwusK15DVzYKclmsDMbUTxdwAoWPuwSDbzO8G xQvIvNZPFSxbVqr7YeArYPW1OKqHzo/WKuNEn3wOVfYrXel0SxQTe0y6OG3MmApKCFtf O+gg== X-Google-Smtp-Source: ACcGV6220peb/QNpOZnl4+HyjvTT/7c2GjbvtM8l/0gTyCAed+n4hIjaSyWnmXOgAFhPit03KoxDJg== X-Received: by 2002:a6b:108:: with SMTP id 8-v6mr11794134iob.274.1539628726584; Mon, 15 Oct 2018 11:38:46 -0700 (PDT) Received: from yuzhao.bld.corp.google.com ([2620:15c:183:0:a0c3:519e:9276:fc96]) by smtp.gmail.com with ESMTPSA id z11-v6sm5883974itz.26.2018.10.15.11.38.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 11:38:45 -0700 (PDT) From: Yu Zhao 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@vger.kernel.org, linux-mm@kvack.org, Yu Zhao Subject: [PATCH] mm: detect numbers of vmstat keys/values mismatch Date: Mon, 15 Oct 2018 12:38:41 -0600 Message-Id: <20181015183841.114341-1-yuzhao@google.com> X-Mailer: git-send-email 2.19.1.331.ge82ca0e54c-goog MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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);