Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp946333pxa; Wed, 5 Aug 2020 17:15:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1HvmosCiPoYJsWotpsjSyy8C3SHpQjmztYdKh1MWyFouuRq8BZO37Y6hlW0BQUCZMpaFX X-Received: by 2002:a17:906:a055:: with SMTP id bg21mr1790845ejb.516.1596672937209; Wed, 05 Aug 2020 17:15:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596672937; cv=none; d=google.com; s=arc-20160816; b=S6mkVJTLAPJ5BSyhz5wLR+diED4KD07lrIhZMA8/e5y4QrjezbR4hylguqzGogT2Dr yFf6HNhU/C1+oYVEa8xLb+HUVIRo5uZoix4R9tpwoh1IcOCw1Vz2ZaQEUaPfjauLQHr+ 7wQkQQJSsADA/CA0SatlfuxZZ0xTaYBWglWBuL/va9YAf12c2j5uy8oUz6w0sK5lM0ea gUu8O/Zjv6oit/xl3xHnyWi3qJ0C5NjZptLPNLtTNPeSSvaf46eF2uUMZZqvKLE2dC1K Gy1/wdOndUcoZBFVfgoX69fz2UA2zwk53HAIQwMcE5y+EwhaBce1BkznYxcPSEDMvaUC K97Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=Xwhl6oTAS7prpbXCRZdZshg5xz57JrEbZ056Cu9NiLQ=; b=cIY76qYRv7pzNaUKdkJdVOacollrhH7ARHmE8lwc5wUN9QAcN+gYk4UB93oXtDtJPi /yb5NaNeaaTQGX+QaNEo4dC3/5LNg1ZJVFLzQIs4hbcll1XVdKzrp008ENHZnFBBlm01 I1gYUxEZxm9YWkPxrkj17adFx0fzpfDkOkBTEjzcgzlPDPxuJZaQoxVmpmLOW4qISyO6 ElbAMT/Iwn8ipsrUyFovGb2kz8iEARH/6qbbVCtW3i/kosc0NrzBY1WyKFROWPeswVrC qdv9COMRcOL91FyW7I0XCGIkO3WN/VKI3PJ7UUXlgh/Gb41tUHfWH7YJL5L7KoQQ1WB6 4Jaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=VKxFANE2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o18si2221224ejg.391.2020.08.05.17.15.14; Wed, 05 Aug 2020 17:15:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=VKxFANE2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726799AbgHFAO7 (ORCPT + 99 others); Wed, 5 Aug 2020 20:14:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726605AbgHFAOp (ORCPT ); Wed, 5 Aug 2020 20:14:45 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 808B2C061757 for ; Wed, 5 Aug 2020 17:14:44 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id l67so21056880ybb.7 for ; Wed, 05 Aug 2020 17:14:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Xwhl6oTAS7prpbXCRZdZshg5xz57JrEbZ056Cu9NiLQ=; b=VKxFANE2z8MkZfjpbuaXTo5P0s50q7AGLs5Y57qk8+qSFN45yWmnON2wvsbgP2aWqe EBFsVb1emqXoo16aaqh2e223MPRKIRHggIQI3gjhx3BjgZXiqMIozVHGxjmXQNLXgqoo L/BEsleyNk+bsbmRzMwQFTYc64tVPcEWQ9Jcgx+IytqxeluWoQU7xOd12x+RomIJyoib TeKOijeKxj1NcXOxiPSMQxBecKm+jMeR5jnHGv3MV4k7dAat60xTlWY/rLDArWBXZtqY KXAFOX83AU/ixka8rnhi3PcwcrJ1odMJHVhJCXpVf2GfwNqYwvHVeuI4eE8brjJKtC/R 3kaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Xwhl6oTAS7prpbXCRZdZshg5xz57JrEbZ056Cu9NiLQ=; b=cj9yo3/nxpg1bpNYC46Re9+gvKa2viWmbb5nTTUoZjqgle/CpAYN9I3owhO2tBCuFf 5t80/LpkHxnDm4E7O3RfOlhzB8pt+IRXDREjOYwVoYxDbaW0S6+dBpQI/KhTOHFYk5jt nDo0zjumBLHpA94bAQjVjVbo1Q5/Fbnr7McvX0SgOOU77+MO3pSsFl32MdnPNldFx1ar sehTF2+N6Q0t4c5I3rjC0g27PfCukL3dwsh7OXRDiedbZxKhU/8DD2R36whUSoiuPYZ6 W1FiK61cVR9hmUqLLV4V6QT39Z6x85Be3x9AAiAa+tf1/DnGVRPVSUi/UmkZuvgLPxaY KGMA== X-Gm-Message-State: AOAM533U5Pyd/u7edH9MGVwpCwXQuD6w+IOu9eco+i+pggLF4F2fel3o APV+5/Qv5/JxY9uBXZATFm/9Fee2TyuMNlDGvPf9np8oAoqWhM3BSenT/DT7hpf9N4HokTbBuZP 4jJ82ApZIRQ75xteo7cR6c0cpLIhgxYoV8jk+VzwSaGb+U18Xv+D7TYHkqfP5m918LYocXZQ= X-Received: by 2002:a25:b41:: with SMTP id 62mr9521967ybl.8.1596672883707; Wed, 05 Aug 2020 17:14:43 -0700 (PDT) Date: Wed, 5 Aug 2020 17:14:27 -0700 In-Reply-To: <20200806001431.2072150-1-jwadams@google.com> Message-Id: <20200806001431.2072150-4-jwadams@google.com> Mime-Version: 1.0 References: <20200806001431.2072150-1-jwadams@google.com> X-Mailer: git-send-email 2.28.0.236.gb10cc79966-goog Subject: [RFC PATCH 3/7] core/metricfs: metric for kernel warnings From: Jonathan Adams To: linux-kernel@vger.kernel.org Cc: kvm@vger.kernel.org, Paolo Bonzini , Jim Mattson , David Rientjes , Jonathan Adams Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Count kernel warnings by function name of the caller. Each time WARN() is called, which includes WARN_ON(), increment a counter in a 256-entry hash table. The table key is the entry point of the calling function, which is found using kallsyms. We store the name of the function in the table (because it may be a module address); reporting the metric just walks the table and prints the values. The "warnings" metric is cumulative. Signed-off-by: Jonathan Adams --- jwadams@google.com: rebased to 5.8-rc6, removed google-isms, added lockdep_assert_held(), NMI handling, ..._unknown*_counts and locking in warn_tbl_fn(); renamed warn_metric... to warn_tbl... The original work was done in 2012 by an engineer no longer at Google. --- kernel/panic.c | 131 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) diff --git a/kernel/panic.c b/kernel/panic.c index e2157ca387c8..c019b41ab387 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -31,6 +31,9 @@ #include #include #include +#include +#include +#include #include #define PANIC_TIMER_STEP 100 @@ -568,6 +571,133 @@ void oops_exit(void) kmsg_dump(KMSG_DUMP_OOPS); } +#ifdef CONFIG_METRICFS + +/* + * Hash table from function address to count of WARNs called within that + * function. + * So far this is an add-only hash table (ie, entries never removed), so some + * simplifying assumptions are made. + */ +#define WARN_TBL_BITS (8) +#define WARN_TBL_SIZE (1<= 0) + warn_tbl[entry].count++; + else + warn_tbl_unknown_count++; + + spin_unlock_irqrestore(&warn_tbl_lock, flags); +} + +/* + * Export the hash table to metricfs. + */ +static void warn_tbl_fn(struct metric_emitter *e) +{ + int i; + unsigned long flags; + int unknown_count = READ_ONCE(warn_tbl_unknown_count) + + atomic_read(&warn_tbl_unknown_nmi_count) + + atomic_read(&warn_tbl_unknown_lookup_count); + + if (unknown_count != 0) + METRIC_EMIT_INT(e, unknown_count, "(unknown)", NULL); + + spin_lock_irqsave(&warn_tbl_lock, flags); + for (i = 0; i < WARN_TBL_SIZE; i++) { + unsigned long fn = (unsigned long)warn_tbl[i].function; + const char *function_name = warn_tbl[i].function_name; + int count = warn_tbl[i].count; + + if (!fn) + continue; + + // function_name[] is constant once function is non-NULL + spin_unlock_irqrestore(&warn_tbl_lock, flags); + METRIC_EMIT_INT(e, count, function_name, NULL); + spin_lock_irqsave(&warn_tbl_lock, flags); + } + spin_unlock_irqrestore(&warn_tbl_lock, flags); +} +METRIC_EXPORT_COUNTER(warnings, "Count of calls to WARN().", + "function", NULL, warn_tbl_fn); + +static int __init metricfs_panic_init(void) +{ + metric_init_warnings(NULL); + return 0; +} +late_initcall(metricfs_panic_init); + +#else /* CONFIG_METRICFS */ +inline void tbl_increment(void *caller) {} +#endif + struct warn_args { const char *fmt; va_list args; @@ -576,6 +706,7 @@ struct warn_args { void __warn(const char *file, int line, void *caller, unsigned taint, struct pt_regs *regs, struct warn_args *args) { + tbl_increment(caller); disable_trace_on_warning(); if (file) -- 2.28.0.236.gb10cc79966-goog