Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4141538ybv; Mon, 10 Feb 2020 13:12:31 -0800 (PST) X-Google-Smtp-Source: APXvYqylWIr/CzASw90Bjczx+22pVhRqmTOBUYnxyliDZzmNqIl465s+j9G3rkzyELD5QOL1Z0S1 X-Received: by 2002:a05:6830:2110:: with SMTP id i16mr2492561otc.337.1581369151091; Mon, 10 Feb 2020 13:12:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581369151; cv=none; d=google.com; s=arc-20160816; b=sOl0gkXC6d/tLXvLXmf+cYKaksgC7rRXcoMwtg9ttPqhidBfZ2hqiDJlqmyZN9x6mf AML+QYAg42S32EGODVHfIbS8ptctB7+pr4zfK+tWz4N7Rqdj8qs1fmheJG+4sLrXQGua pccmitNKCYiF/zNkSjaSUPKo5tVzGlAaVeK3dag42pU6Qm9ii5/rBxSuyafx82HOXINd yk9vB6VKaJki61U66P4xaCBX/PZEoNYOCBT+pp6qhXv0KSvjkwro5GW+xWKWqfc9O85V frHCFjqpai9CDp+nl16rzoZlR5MPqtpJyI7i5rPHyG7fuZ4WzRA6YvSz6yNceoFhNcvc 3InA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=2aBdkIehXvvjGEIFItUGB/IdE8tYLQKmWBuVnPFCoY8=; b=A+UK2SAftym+eaHsjvxY+b2agrUxkiuofwFaxO7Jpgr9RvYLYNzb9+g5AGfJxRn2+d G70bGum3FzxkPqP+IgYLHrXjM/Sc5LETvKCKqKFXK8/Ghp/EMKT0BwDzjlUMhZsOPUIY 12U8nk6EjxiFkovO2Qm9LQJ+pZJoP97GMk0AFog3dfNTSVGS+BGJNpVH45nZqFvTk0w2 cYFen1Im0Xsbh1hv3mqzdro2NQE+JKWHSweAwTy9OpFYCEcraot4sk/MS66boALmziwo GRHzvcooKgj9l4iR5e8IbooLEPOYMAczBgWCCBfmfu/Jgckq3EAFLcEU4SpzxYgTWsC0 UMGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cDb7rkvn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z2si653792oix.100.2020.02.10.13.12.18; Mon, 10 Feb 2020 13:12:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cDb7rkvn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727447AbgBJVLq (ORCPT + 99 others); Mon, 10 Feb 2020 16:11:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:57372 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727056AbgBJVLp (ORCPT ); Mon, 10 Feb 2020 16:11:45 -0500 Received: from localhost (unknown [104.132.1.111]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 688F42070A; Mon, 10 Feb 2020 21:11:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581369103; bh=wt38Mhym5ZWnCPH9lj6WqRDHQEUu2aeLLF6wfdyZzD0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=cDb7rkvniOHn1WQlq1D5LQQmx3ut1Mnxdws+AjakBYeO1vQ/kfSeE04pxrgmEJAKh TE1G4itYT8Kw3gUsLdOCPMpzvCEWBhXFESNRn5W3+yp1ommfJqMJ1Shez4VWRk14pB krBNauxdipP/iPJool2axmooTCsdLxQUW6Wx1HFw= Date: Mon, 10 Feb 2020 13:11:42 -0800 From: Greg Kroah-Hartman To: "Theodore Y. Ts'o" , Jonathan Corbet , Saravana Kannan , Jason Baron , Will Deacon Cc: linux-kernel@vger.kernel.org, kernel-team@android.com, Randy Dunlap Subject: Re: [PATCH v6] dynamic_debug: allow to work if debugfs is disabled Message-ID: <20200210211142.GB1373304@kroah.com> References: <20200123093628.GA18991@willie-the-truck> <20200123085015.GA436361@kroah.com> <20200125101130.449a8e4d@lwn.net> <20200125014231.GI147870@mit.edu> <20200123155340.GD147870@mit.edu> <20200209110549.GA1621867@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200209110549.GA1621867@kroah.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With the realization that having debugfs enabled on "production" systems is generally not a good idea, debugfs is being disabled from more and more platforms over time. However, the functionality of dynamic debugging still is needed at times, and since it relies on debugfs for its user api, having debugfs disabled also forces dynamic debug to be disabled. To get around this, also create the "control" file for dynamic_debug in procfs. This allows people turn on debugging as needed at runtime for individual driverfs and subsystems. Reported-by: many different companies Cc: Jason Baron Signed-off-by: Greg Kroah-Hartman --- v6: fix up Kconfig help, it was a bit incorrect,thanks to Saravana for the review. v5: as many people asked for it, now enable the control file in both debugfs and procfs at the same time. v4: tweaks to the .rst text thanks to Randy's review v3: rename init function as it is now no longer just for debugfs, thanks to Jason for the review. Fix build warning for debugfs_initialized call. v2: Fix up octal permissions and add procfs reference to the Kconfig entry, thanks to Will for the review. .../admin-guide/dynamic-debug-howto.rst | 3 +++ lib/Kconfig.debug | 7 ++++--- lib/dynamic_debug.c | 20 ++++++++++++++----- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/Documentation/admin-guide/dynamic-debug-howto.rst b/Documentation/admin-guide/dynamic-debug-howto.rst index 252e5ef324e5..585451d12608 100644 --- a/Documentation/admin-guide/dynamic-debug-howto.rst +++ b/Documentation/admin-guide/dynamic-debug-howto.rst @@ -54,6 +54,9 @@ If you make a mistake with the syntax, the write will fail thus:: /dynamic_debug/control -bash: echo: write error: Invalid argument +Note, for systems without 'debugfs' enabled, the control file can also +be found in ``/proc/dynamic_debug/control``. + Viewing Dynamic Debug Behaviour =============================== diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 69def4a9df00..7f4992fd8a2e 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -98,7 +98,7 @@ config DYNAMIC_DEBUG bool "Enable dynamic printk() support" default n depends on PRINTK - depends on DEBUG_FS + depends on (DEBUG_FS || PROC_FS) help Compiles debug level messages into the kernel, which would not @@ -116,8 +116,9 @@ config DYNAMIC_DEBUG Usage: Dynamic debugging is controlled via the 'dynamic_debug/control' file, - which is contained in the 'debugfs' filesystem. Thus, the debugfs - filesystem must first be mounted before making use of this feature. + which is contained in the 'debugfs' filesystem or procfs. + Thus, the debugfs or procfs filesystem must first be mounted before + making use of this feature. We refer the control file as: /dynamic_debug/control. This file contains a list of the debug statements that can be enabled. The format for each line of the file is: diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index c60409138e13..c220c1891729 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -991,15 +991,25 @@ static void ddebug_remove_all_tables(void) static __initdata int ddebug_init_success; -static int __init dynamic_debug_init_debugfs(void) +static int __init dynamic_debug_init_control(void) { - struct dentry *dir; + struct proc_dir_entry *procfs_dir; + struct dentry *debugfs_dir; if (!ddebug_init_success) return -ENODEV; - dir = debugfs_create_dir("dynamic_debug", NULL); - debugfs_create_file("control", 0644, dir, NULL, &ddebug_proc_fops); + /* Create the control file in debugfs if it is enabled */ + if (debugfs_initialized()) { + debugfs_dir = debugfs_create_dir("dynamic_debug", NULL); + debugfs_create_file("control", 0644, debugfs_dir, NULL, + &ddebug_proc_fops); + } + + /* Also create the control file in procfs */ + procfs_dir = proc_mkdir("dynamic_debug", NULL); + if (procfs_dir) + proc_create("control", 0644, procfs_dir, &ddebug_proc_fops); return 0; } @@ -1077,4 +1087,4 @@ static int __init dynamic_debug_init(void) early_initcall(dynamic_debug_init); /* Debugfs setup must be done later */ -fs_initcall(dynamic_debug_init_debugfs); +fs_initcall(dynamic_debug_init_control); base-commit: bb6d3fb354c5ee8d6bde2d576eb7220ea09862b9 -- 2.25.0