All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Luis R. Rodriguez" <mcgrof@kernel.org>
To: "Luis R. Rodriguez" <mcgrof@kernel.org>
Cc: Greg KH <gregkh@linuxfoundation.org>,
	akpm@linux-foundation.org, keescook@chromium.org,
	mfuzzey@parkeon.com, zohar@linux.vnet.ibm.com,
	dhowells@redhat.com, pali.rohar@gmail.com, tiwai@suse.de,
	arend.vanspriel@broadcom.com, zajec5@gmail.com, nbroeking@me.com,
	markivx@codeaurora.org, stephen.boyd@linaro.org,
	broonie@kernel.org, dmitry.torokhov@gmail.com,
	dwmw2@infradead.org, torvalds@linux-foundation.org,
	Abhay_Salunke@dell.com, bjorn.andersson@linaro.org,
	jewalt@lgsinnovations.com, linux-kernel@vger.kernel.org,
	linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH v2 19/23] firmware: add debug facility to emulate forcing sysfs fallback
Date: Fri, 1 Dec 2017 00:54:25 +0100	[thread overview]
Message-ID: <20171130235425.GO729@wotan.suse.de> (raw)
In-Reply-To: <20171130203516.GN729@wotan.suse.de>

On Thu, Nov 30, 2017 at 09:35:16PM +0100, Luis R. Rodriguez wrote:
> On Wed, Nov 29, 2017 at 11:28:04AM +0100, Greg KH wrote:
> > On Mon, Nov 20, 2017 at 10:24:05AM -0800, Luis R. Rodriguez wrote:
> > > diff --git a/drivers/base/firmware_debug.c b/drivers/base/firmware_debug.c
> > > new file mode 100644
> > > index 000000000000..f2817eb6f480
> > > --- /dev/null
> > > +++ b/drivers/base/firmware_debug.c
> > > @@ -0,0 +1,34 @@
> > > +// SPDX-License-Identifier: GPL-2.0
> > > +/* Firmware dubugging interface */
> > > +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
> > > +
> > > +#include <linux/debugfs.h>
> > > +#include "firmware_debug.h"
> > > +
> > > +struct firmware_debug fw_debug;
> > > +
> > > +static struct dentry *debugfs_firmware;
> > > +
> > > +int __init register_fw_debugfs(void)
> > > +{
> > > +	debugfs_firmware = debugfs_create_dir("firmware", NULL);
> > > +	if (!debugfs_firmware)
> > > +		return -ENOMEM;
> > 
> > You never need to check the return value of a debugfs call, you should
> > not care about it, nor do anything different in your code.  The value
> > returned can always be passed back into any other debugfs call when
> > needed.
> 
> Neat, so all uses as in the above are wrong eh?

You know, I'm wondering if it just makes sense to go straight into making
CONFIG_FW_LOADER_USER_HELPER_FALLBACK nothing but a setting a bool on a
config to true.

diff --git a/drivers/base/firmware_loader.c b/drivers/base/firmware_loader.c
index 43b97a8137f7..d3f2aabfc41d 100644
--- a/drivers/base/firmware_loader.c
+++ b/drivers/base/firmware_loader.c
@@ -117,6 +117,12 @@ struct fw_name_devm {
 	const char *name;
 };
 
+struct firmware_config {
+	bool force_sysfs_fallback;
+};
+
+static struct firmware_config fw_config;
+
 static inline struct fw_priv *to_fw_priv(struct kref *ref)
 {
 	return container_of(ref, struct fw_priv, ref);
@@ -1151,18 +1157,25 @@ static int fw_load_from_user_helper(struct firmware *firmware,
 }
 
 #ifdef CONFIG_FW_LOADER_USER_HELPER_FALLBACK
-static bool fw_force_sysfs_fallback(unsigned int opt_flags)
+static void __init fw_config_init(void)
 {
-	return true;
+	fw_config.force_sysfs_fallback = true;
 }
+
 #else
+static void __init fw_config_init(void)
+{
+}
+#endif
+
 static bool fw_force_sysfs_fallback(unsigned int opt_flags)
 {
+	if (fw_config.force_sysfs_fallback)
+		return true;
 	if (!(opt_flags & FW_OPT_USERHELPER))
 		return false;
 	return true;
 }
-#endif
 
 static bool fw_run_sysfs_fallback(unsigned int opt_flags)
 {
@@ -1911,6 +1924,7 @@ static int __init firmware_class_init(void)
 	int ret;
 
 	/* No need to unfold these on exit */
+	fw_config_init();
 	fw_cache_init();
 
 	ret = register_fw_pm_ops();

After which we can add two generic syfs firmware knobs to help do the same as I did
for debugfs, only we actually support it as proper API. Thoughts?

For instance for changing to force the usermode helper:

diff --git a/drivers/base/firmware_loader.c b/drivers/base/firmware_loader.c
index d3f2aabfc41d..659db28f5c02 100644
--- a/drivers/base/firmware_loader.c
+++ b/drivers/base/firmware_loader.c
@@ -41,6 +41,9 @@ MODULE_AUTHOR("Manuel Estrada Sainz");
 MODULE_DESCRIPTION("Multi purpose firmware loading support");
 MODULE_LICENSE("GPL");
 
+static unsigned int zero;
+static unsigned int one = 1;
+
 enum fw_status {
 	FW_STATUS_UNKNOWN,
 	FW_STATUS_LOADING,
@@ -1919,6 +1922,19 @@ static struct notifier_block fw_shutdown_nb = {
 	.notifier_call = fw_shutdown_notify,
 };
 
+struct ctl_table firmware_config_table[] = {
+	{
+		.procname	= "force_sysfs_fallback",
+		.data		= &fw_config.force_sysfs_fallback,
+		.maxlen         = sizeof(unsigned int),
+		.mode           = 0644,
+		.proc_handler   = proc_douintvec_minmax,
+		.extra1		= &zero,
+		.extra2		= &one,
+	},
+	{ }
+};
+
 static int __init firmware_class_init(void)
 {
 	int ret;
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 557d46728577..202442f3c58c 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -251,6 +251,10 @@ extern struct ctl_table random_table[];
 extern struct ctl_table epoll_table[];
 #endif
 
+#ifdef CONFIG_FW_LOADER
+extern struct ctl_table firmware_config_table[];
+#endif
+
 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
 int sysctl_legacy_va_layout;
 #endif
@@ -746,6 +750,13 @@ static struct ctl_table kern_table[] = {
 		.mode		= 0555,
 		.child		= usermodehelper_table,
 	},
+#ifdef CONFIG_FW_LOADER
+	{
+		.procname	= "firmware_config",
+		.mode		= 0555,
+		.child		= firmware_config_table,
+	},
+#endif
 	{
 		.procname	= "overflowuid",
 		.data		= &overflowuid,

Thoughts, preferences?

  Luis

  reply	other threads:[~2017-11-30 23:54 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-20 18:23 [PATCH v2 00/23] firmware: cleanup for v4.16 Luis R. Rodriguez
2017-11-20 18:23 ` [PATCH v2 01/23] firmware: rename struct firmware_priv to struct fw_sysfs Luis R. Rodriguez
2017-11-20 18:23 ` [PATCH v2 02/23] firmware: rename struct firmware_buf to struct fw_priv Luis R. Rodriguez
2017-11-20 18:23 ` [PATCH v2 03/23] firmware: rename struct fw_priv->fw_id to fw_name Luis R. Rodriguez
2017-11-20 18:23 ` [PATCH v2 04/23] firmware: move core data structures to the top of file Luis R. Rodriguez
2017-11-20 18:23 ` [PATCH v2 05/23] firmware: remove duplicate fw_state_aborted() Luis R. Rodriguez
2017-11-20 18:23 ` [PATCH v2 06/23] firmware: remove unused __fw_state_is_done() Luis R. Rodriguez
2017-11-20 18:23 ` [PATCH v2 07/23] firmware: use static inlines for state machine checking Luis R. Rodriguez
2017-11-20 18:23 ` [PATCH v2 08/23] firmware: rename sysfs state checks with sysfs prefix Luis R. Rodriguez
2017-11-20 18:23 ` [PATCH v2 09/23] firmware: use static inline for to_fw_priv() Luis R. Rodriguez
2017-11-29 10:14   ` Greg KH
2017-11-20 18:23 ` [PATCH v2 10/23] firmware: add helper to copy built-in data to pre-alloc buffer Luis R. Rodriguez
2017-11-29 10:17   ` Greg KH
2017-11-30 20:18     ` Luis R. Rodriguez
2017-11-20 18:23 ` [PATCH v2 11/23] firmware: provide helper for FW_OPT_USERHELPER Luis R. Rodriguez
2017-11-20 18:23 ` [PATCH v2 12/23] firmware: replace #ifdef over FW_OPT_FALLBACK with function checks Luis R. Rodriguez
2017-11-20 18:23 ` [PATCH v2 13/23] test_firmware: wrap sysfs timeout test into helper Luis R. Rodriguez
2017-11-20 18:24 ` [PATCH v2 14/23] test_firmware: wrap basic sysfs fallback tests " Luis R. Rodriguez
2017-11-20 18:24 ` [PATCH v2 15/23] test_firmware: wrap custom sysfs load " Luis R. Rodriguez
2017-11-20 18:24 ` [PATCH v2 16/23] test_firmware: enable custom fallback testing on limited kernel configs Luis R. Rodriguez
2017-11-29 10:20   ` Greg KH
2017-11-29 10:22   ` Greg KH
2017-11-30 20:31     ` Luis R. Rodriguez
2017-11-30 21:40       ` Shuah Khan
2017-11-29 10:28   ` Greg KH
2017-11-20 18:24 ` [PATCH v2 17/23] test_firmware: replace syfs fallback check with kconfig_has helper Luis R. Rodriguez
2017-11-20 18:24 ` [PATCH v2 18/23] firmware: enable to split firmware_class into separate target files Luis R. Rodriguez
2017-11-20 18:24 ` [PATCH v2 19/23] firmware: add debug facility to emulate forcing sysfs fallback Luis R. Rodriguez
2017-11-29 10:28   ` Greg KH
2017-11-30 20:35     ` Luis R. Rodriguez
2017-11-30 23:54       ` Luis R. Rodriguez [this message]
2017-11-20 18:24 ` [PATCH v2 20/23] firmware: add debug facility to emulate disabling " Luis R. Rodriguez
2017-11-20 18:24 ` [PATCH v2 21/23] test_firmware: add a library for shared helpers Luis R. Rodriguez
2017-11-20 18:24 ` [PATCH v2 22/23] test_firmware: test the 3 firmware kernel configs using debugfs Luis R. Rodriguez
2017-11-20 18:24 ` [PATCH v2 23/23] firmware: cleanup - group and document up private firmware parameters Luis R. Rodriguez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171130235425.GO729@wotan.suse.de \
    --to=mcgrof@kernel.org \
    --cc=Abhay_Salunke@dell.com \
    --cc=akpm@linux-foundation.org \
    --cc=arend.vanspriel@broadcom.com \
    --cc=bjorn.andersson@linaro.org \
    --cc=broonie@kernel.org \
    --cc=dhowells@redhat.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jewalt@lgsinnovations.com \
    --cc=keescook@chromium.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=markivx@codeaurora.org \
    --cc=mfuzzey@parkeon.com \
    --cc=nbroeking@me.com \
    --cc=pali.rohar@gmail.com \
    --cc=stephen.boyd@linaro.org \
    --cc=tiwai@suse.de \
    --cc=torvalds@linux-foundation.org \
    --cc=zajec5@gmail.com \
    --cc=zohar@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.