Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp212476ybk; Thu, 14 May 2020 21:38:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwPv0gCAXKi7OTohNffZOmXuSF0T0W39///fDpa5z1dATUp6Af5xdaWdjgaxVpRB50XGix X-Received: by 2002:aa7:db4a:: with SMTP id n10mr1162733edt.11.1589517496500; Thu, 14 May 2020 21:38:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589517496; cv=none; d=google.com; s=arc-20160816; b=001lXipHnG3yFAcK6DT2m7PjTVUytXC6rzKHeddHF8zzQZ4Pbfs7bl+85YE+iPNqj5 Sb390hNaFcko7MtadW4+oZucgX9KCbA4bEPGWLd3FmjIncFAlqwu80lPk0lHn7WzPNc3 PoOVJPKkeoz3LUD1ybes8ePsGok888LfiDE2hZta/ydiE9r2jEHKhCjshIvtyNSPPrKM L7LGTGiVpjlNLtcFW+RvDHqUGPvTQq3O0z/+ZfxFXxQbDorF1AImlu0bGRbk/m8SJHX9 4J0a6BZpZEcbYRb1Z9RPAtlnMZH0//QW183gqrUCP2CHkaTHAUOMXDEtiWCahhisIV/7 SiTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=Q0Xsq8GMnu68/qw68eevoB1EZp/9x/o4TfesIJn9ezY=; b=ZJDj75LdJK2q1HCPMc+oWbgkWdrc89od62Bndzjx593iF8Y9temHuGfHp5DiXaq6fv Nkj42MaUt8+Sxu2qAKh5Q6YlaA5t70pV72cBcm1QWSmnsvK+vNWDNTlF8MgJAu+sWfYl NBh7hep+PAJa1vCwHfseT4IA3lkktaMZXGW6gAI9s9+sVgp6l04CWLRzoxtnIqwRkioa P5jHaxOZ408Gaa/8CEzhE57Fxrkfjs2sMy0dMU2gQyVj9p10+rWJ0/vh2AIGVNdZU8oG mG3fLXcJcPWcSkHcPG/vp7aI57/P0FVS16tbK1bhTs+bMTYxvm3nldwj1GpTSTrORH4c K6HA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c2si500285edm.499.2020.05.14.21.37.51; Thu, 14 May 2020 21:38:16 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726604AbgEOEeJ (ORCPT + 99 others); Fri, 15 May 2020 00:34:09 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:46328 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726243AbgEOEeI (ORCPT ); Fri, 15 May 2020 00:34:08 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 2B276EA82EB723149A80; Fri, 15 May 2020 12:33:58 +0800 (CST) Received: from use12-sp2.huawei.com (10.67.189.174) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.487.0; Fri, 15 May 2020 12:33:48 +0800 From: Xiaoming Ni To: , , , , , , , , , , , , , , , , , CC: , , , Subject: [PATCH 3/4] watchdog: move watchdog sysctl to watchdog.c Date: Fri, 15 May 2020 12:33:43 +0800 Message-ID: <1589517224-123928-4-git-send-email-nixiaoming@huawei.com> X-Mailer: git-send-email 1.8.5.6 In-Reply-To: <1589517224-123928-1-git-send-email-nixiaoming@huawei.com> References: <1589517224-123928-1-git-send-email-nixiaoming@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.189.174] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Move watchdog sysctl interface to watchdog.c. Use register_sysctl() to register the sysctl interface to avoid merge conflicts when different features modify sysctl.c at the same time. Signed-off-by: Xiaoming Ni --- kernel/sysctl.c | 96 -------------------------------------------- kernel/watchdog.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 96 deletions(-) diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 01fc559..e394990 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -97,9 +97,6 @@ #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE #include #endif -#ifdef CONFIG_LOCKUP_DETECTOR -#include -#endif #if defined(CONFIG_SYSCTL) @@ -120,9 +117,6 @@ #endif /* Constants used for minimum and maximum */ -#ifdef CONFIG_LOCKUP_DETECTOR -static int sixty = 60; -#endif static int __maybe_unused two = 2; static int __maybe_unused four = 4; @@ -887,96 +881,6 @@ static int sysrq_sysctl_handler(struct ctl_table *table, int write, .mode = 0444, .proc_handler = proc_dointvec, }, -#if defined(CONFIG_LOCKUP_DETECTOR) - { - .procname = "watchdog", - .data = &watchdog_user_enabled, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = proc_watchdog, - .extra1 = SYSCTL_ZERO, - .extra2 = SYSCTL_ONE, - }, - { - .procname = "watchdog_thresh", - .data = &watchdog_thresh, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = proc_watchdog_thresh, - .extra1 = SYSCTL_ZERO, - .extra2 = &sixty, - }, - { - .procname = "nmi_watchdog", - .data = &nmi_watchdog_user_enabled, - .maxlen = sizeof(int), - .mode = NMI_WATCHDOG_SYSCTL_PERM, - .proc_handler = proc_nmi_watchdog, - .extra1 = SYSCTL_ZERO, - .extra2 = SYSCTL_ONE, - }, - { - .procname = "watchdog_cpumask", - .data = &watchdog_cpumask_bits, - .maxlen = NR_CPUS, - .mode = 0644, - .proc_handler = proc_watchdog_cpumask, - }, -#ifdef CONFIG_SOFTLOCKUP_DETECTOR - { - .procname = "soft_watchdog", - .data = &soft_watchdog_user_enabled, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = proc_soft_watchdog, - .extra1 = SYSCTL_ZERO, - .extra2 = SYSCTL_ONE, - }, - { - .procname = "softlockup_panic", - .data = &softlockup_panic, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = proc_dointvec_minmax, - .extra1 = SYSCTL_ZERO, - .extra2 = SYSCTL_ONE, - }, -#ifdef CONFIG_SMP - { - .procname = "softlockup_all_cpu_backtrace", - .data = &sysctl_softlockup_all_cpu_backtrace, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = proc_dointvec_minmax, - .extra1 = SYSCTL_ZERO, - .extra2 = SYSCTL_ONE, - }, -#endif /* CONFIG_SMP */ -#endif -#ifdef CONFIG_HARDLOCKUP_DETECTOR - { - .procname = "hardlockup_panic", - .data = &hardlockup_panic, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = proc_dointvec_minmax, - .extra1 = SYSCTL_ZERO, - .extra2 = SYSCTL_ONE, - }, -#ifdef CONFIG_SMP - { - .procname = "hardlockup_all_cpu_backtrace", - .data = &sysctl_hardlockup_all_cpu_backtrace, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = proc_dointvec_minmax, - .extra1 = SYSCTL_ZERO, - .extra2 = SYSCTL_ONE, - }, -#endif /* CONFIG_SMP */ -#endif -#endif - #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) { .procname = "unknown_nmi_panic", diff --git a/kernel/watchdog.c b/kernel/watchdog.c index b6b1f54..05e1d58 100644 --- a/kernel/watchdog.c +++ b/kernel/watchdog.c @@ -23,6 +23,9 @@ #include #include #include +#ifdef CONFIG_SYSCTL +#include +#endif #include #include @@ -756,10 +759,124 @@ int proc_watchdog_cpumask(struct ctl_table *table, int write, mutex_unlock(&watchdog_mutex); return err; } + +static int sixty = 60; + +static struct ctl_table watchdog_sysctls[] = { + { + .procname = "watchdog", + .data = &watchdog_user_enabled, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_watchdog, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE, + }, + { + .procname = "watchdog_thresh", + .data = &watchdog_thresh, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_watchdog_thresh, + .extra1 = SYSCTL_ZERO, + .extra2 = &sixty, + }, + { + .procname = "nmi_watchdog", + .data = &nmi_watchdog_user_enabled, + .maxlen = sizeof(int), + .mode = NMI_WATCHDOG_SYSCTL_PERM, + .proc_handler = proc_nmi_watchdog, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE, + }, + { + .procname = "watchdog_cpumask", + .data = &watchdog_cpumask_bits, + .maxlen = NR_CPUS, + .mode = 0644, + .proc_handler = proc_watchdog_cpumask, + }, +#ifdef CONFIG_SOFTLOCKUP_DETECTOR + { + .procname = "soft_watchdog", + .data = &soft_watchdog_user_enabled, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_soft_watchdog, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE, + }, + { + .procname = "softlockup_panic", + .data = &softlockup_panic, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE, + }, +#ifdef CONFIG_SMP + { + .procname = "softlockup_all_cpu_backtrace", + .data = &sysctl_softlockup_all_cpu_backtrace, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE, + }, +#endif /* CONFIG_SMP */ +#endif +#ifdef CONFIG_HARDLOCKUP_DETECTOR + { + .procname = "hardlockup_panic", + .data = &hardlockup_panic, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE, + }, +#ifdef CONFIG_SMP + { + .procname = "hardlockup_all_cpu_backtrace", + .data = &sysctl_hardlockup_all_cpu_backtrace, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE, + }, +#endif /* CONFIG_SMP */ +#endif + {} +}; + +/* + * The watchdog sysctl has a default value. + * Even if register_sysctl() fails, it does not affect the main function of + * the watchdog. At the same time, during the system initialization phase, + * malloc small memory will almost never fail. + * So the return value is ignored here + */ +static void __init watchdog_sysctl_init(void) +{ + struct ctl_table_header *p = register_sysctl("kernel", watchdog_sysctls); + + if (unlikely(!p)) { + pr_err("%s fail\n", __func__); + return; + } + kmemleak_not_leak(p); +} +#else +#define watchdog_sysctl_init() do { } while (0) #endif /* CONFIG_SYSCTL */ void __init lockup_detector_init(void) { + watchdog_sysctl_init(); if (tick_nohz_full_enabled()) pr_info("Disabling watchdog on nohz_full cores by default\n"); -- 1.8.5.6