Skip to contentSkip to conversation

efi: register efivars with efi or gsmi from module_init

PATCH In review Tom Gundersen 2 participants 5 messages Feb 18, 2013 – Feb 25, 2013 3 messages not in the archive EFI

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 efi: register efivars with efi or gsmi from module_init

The generic efi code or the gsmi code used to request efivars to register itself with them. That would only work if efivars was compiled into the kernel, and not when built as a module.

I.e., CONFIG_EFI_VARS_GENERIC_OPS=y and CONFIG_EFI_VARS_SYSFS=m gives:

drivers/built-in.o: In function `generic_register':
drivers/firmware/efi/generic-ops.c:41: undefined reference to `efivars_sysfs_init'.

This patch reverses the logic and does the registration from efivars_sysfs_init().

---

Hi Matt,

This and the following patch applies on top of the chainsaw branch. Feel free to squash them into your other patches, or to consider them as glorified bug-reporst if you prefer to solve the problems differently.

Cheers,

Tom

drivers/firmware/efi/generic-ops.c | 6 ------

 drivers/firmware/efi/sysfs.c       | 14 ++++++++++----
 drivers/firmware/google/gsmi.c     | 11 +++--------
 include/linux/efi.h                |  6 +++++-
 4 files changed, 18 insertions(+), 19 deletions(-)
drivers/firmware/efi/generic-ops.c +0 -6
index b474800..df1251e 100644
@@ -17,9 +17,6 @@
  */
 
 #include <linux/efi.h>
-#include <linux/kconfig.h>
-
-extern struct kobject *efi_kobj;
 
 static struct efivars generic_efivars;
 static struct efivar_operations generic_ops;
@@ -37,9 +34,6 @@ int generic_register(void)
 	if (error)
 		return error;
 
-#if defined(CONFIG_EFI_VARS_SYSFS) || defined(CONFIG_EFI_VARS_SYSFS_MODULE)
-	efivars_sysfs_init(efi_kobj);
-#endif
 	return 0;
 }
 
drivers/firmware/efi/sysfs.c +10 -4
index d066eb5..d61ab95 100644
@@ -76,6 +76,7 @@ MODULE_DESCRIPTION("sysfs interface to EFI Variables");
 MODULE_LICENSE("GPL");
 MODULE_VERSION(EFIVARS_VERSION);
 
+
 static struct kset *efivars_kset;
 
 static struct bin_attribute *efivars_new_var;
@@ -525,16 +526,20 @@ void efivars_sysfs_exit(void)
 	kset_unregister(efivars_kset);
 }
 
-int efivars_sysfs_init(struct kobject *parent_kobj)
+int efivars_sysfs_init(void)
 {
 	int error = 0;
 
 	printk(KERN_INFO "EFI Variables Facility v%s %s\n", EFIVARS_VERSION,
 	       EFIVARS_DATE);
 
-	efivars_kset = kset_create_and_add("vars", NULL, parent_kobj);
+#if defined(CONFIG_EFI_VARS_GENERIC_OPS)
+	efivars_kset = kset_create_and_add("vars", NULL, efi_kobj);
+#elif defined(CONFIG_GOOGLE_SMI) || defined(CONFIG_GOOGLE_SMI_MODULE)
+	efivars_kset = kset_create_and_add("vars", NULL, gsmi_kobj);
+#endif
 	if (!efivars_kset) {
-		printk(KERN_ERR "efivars: Subsystem registration failed.\n");
+		pr_err("efivars: Subsystem registration failed.\n");
 		return -ENOMEM;
 	}
 
@@ -546,4 +551,5 @@ int efivars_sysfs_init(struct kobject *parent_kobj)
 
 	return error;
 }
-EXPORT_SYMBOL_GPL(efivars_sysfs_init);
+
+module_init(efivars_sysfs_init);
drivers/firmware/google/gsmi.c +3 -8
index e902f21..e084486 100644
@@ -760,7 +760,9 @@ static __init int gsmi_system_valid(void)
 	return 0;
 }
 
-static struct kobject *gsmi_kobj;
+struct kobject *gsmi_kobj;
+EXPORT_SYMBOL_GPL(gsmi_kobj);
+
 static struct efivars efivars;
 
 static __init int gsmi_init(void)
@@ -888,13 +890,6 @@ static __init int gsmi_init(void)
 		goto out_remove_sysfs_files;
 	}
 
-	ret = efivars_sysfs_init(gsmi_kobj);
-	if (ret) {
-		printk(KERN_INFO "gsmi: Failed to create efivars files\n");
-		efivars_unregister(&efivars);
-		goto out_remove_sysfs_files;
-	}
-
 	register_reboot_notifier(&gsmi_reboot_notifier);
 	register_die_notifier(&gsmi_die_notifier);
 	atomic_notifier_chain_register(&panic_notifier_list,
include/linux/efi.h +5 -1
index 58b3cae..008d345 100644
@@ -744,6 +744,11 @@ utf16_strlen(efi_char16_t *s)
 
 extern struct kobject *efi_kobj;
 
+#ifdef CONFIG_GOOGLE_SMI
+extern struct kobject *gsmi_kobj;
+#endif /* CONFIG_EFI_VARS */
+
+
 #ifdef CONFIG_EFI_VARS
 /*
  * Return the number of bytes is the length of this string
@@ -863,7 +868,6 @@ int efivar_query_info(u32 attributes, u64 *storage_size,
 		      u64 *remaining_size, u64 *max_size);
 
 #if defined(CONFIG_EFI_VARS_SYSFS) || defined(CONFIG_EFI_VARS_SYSFS_MODULE)
-int efivars_sysfs_init(struct kobject *parent);
 int efivar_create_sysfs_entry(struct efivar_entry *new_var);
 #endif
 
Signature · 1 line
1.8.1.3

A message that is not in the archive (sent off-list or not yet received): 1361149277-1026-1-git-send-email-teg-B22kvLQNl6c@public.gmane.org

#2 lore raw

PATCH 2/2 efi: rename the efivars module

As part of the splitting up of efivars this got renamed to 'sysfs', rename it back to 'efivars' for backwards compatibility.

---
 drivers/firmware/efi/Kconfig   |   2 +
 drivers/firmware/efi/Makefile  |   2 +-
 drivers/firmware/efi/efivars.c | 555 +++++++++++++++++++++++++++++++++++++++++
 drivers/firmware/efi/sysfs.c   | 555 -----------------------------------------
 4 files changed, 558 insertions(+), 556 deletions(-)
 create mode 100644 drivers/firmware/efi/efivars.c
 delete mode 100644 drivers/firmware/efi/sysfs.c
drivers/firmware/efi/Kconfig +2 -0
index e83ef8f..8ca7476 100644
@@ -41,6 +41,8 @@ config EFI_VARS_SYSFS
 	  Subsequent efibootmgr releases may be found at:
 	  <http://linux.dell.com/efibootmgr>
 
+	  If built as a module it will be called efivars.
+
 config EFI_VARS_PSTORE
 	tristate "EFI Variable Persistent Storage"
 	depends on PSTORE
drivers/firmware/efi/Makefile +1 -1
index 9660b3d..705b63e 100644
@@ -3,6 +3,6 @@
 #
 obj-$(CONFIG_EFI)			+= efi.o
 obj-$(CONFIG_EFI_VARS)			+= vars.o
-obj-$(CONFIG_EFI_VARS_SYSFS)		+= sysfs.o
+obj-$(CONFIG_EFI_VARS_SYSFS)		+= efivars.o
 obj-$(CONFIG_EFI_VARS_PSTORE)		+= pstore.o
 obj-$(CONFIG_EFI_VARS_GENERIC_OPS)	+= generic-ops.o
drivers/firmware/efi/efivars.c new file +555 -0

555 lines not on this page · raw message

drivers/firmware/efi/sysfs.c deleted +0 -555

555 lines not on this page · raw message

Signature · 1 line
1.8.1.3

A message that is not in the archive (sent off-list or not yet received): 1361149277-1026-2-git-send-email-teg-B22kvLQNl6c@public.gmane.org

#4 lore raw

Re: [PATCH 2/2] efi: rename the efivars module

Quoted 5 lines · Tom Gundersen

As part of the splitting up of efivars this got renamed to 'sysfs', rename it back to 'efivars' for backwards compatibility.

Quoted 8 lines
---
 drivers/firmware/efi/Kconfig   |   2 +
 drivers/firmware/efi/Makefile  |   2 +-
 drivers/firmware/efi/efivars.c | 555 +++++++++++++++++++++++++++++++++++++++++
 drivers/firmware/efi/sysfs.c   | 555 -----------------------------------------
 4 files changed, 558 insertions(+), 556 deletions(-)
 create mode 100644 drivers/firmware/efi/efivars.c
 delete mode 100644 drivers/firmware/efi/sysfs.c

Good point!

In order to avoid introducing a bisection problem we're probably going to have to do the sysfs and efivars split together, so that we don't end up with two files called efivars.c.

I'll rejiggle the patches to avoid this problem, thanks.

#5 lore raw
In reply to a message not in the archive
Quoted 10 lines · Tom Gundersen

The generic efi code or the gsmi code used to request efivars to register itself with them. That would only work if efivars was compiled into the kernel, and not when built as a module.

I.e., CONFIG_EFI_VARS_GENERIC_OPS=y and CONFIG_EFI_VARS_SYSFS=m gives:

drivers/built-in.o: In function `generic_register':
drivers/firmware/efi/generic-ops.c:41: undefined reference to `efivars_sysfs_init'.

Quoted 6 lines

This patch reverses the logic and does the registration from efivars_sysfs_init().

---

Guh, yes. The way I implemented this is rather silly. Thanks for the report! I was trying to avoid having a struct kobject * in struct efivars, because that inherently ties the efivar_entry API to the sysfs code, and the whole point of this series is that you can have EFI variable support without the sysfs stuff.

Instead of doing the #ifdef-ery how does this look? It keeps everything contained within struct efivars just like the old code. Unfortunately it's applied against some changes I've got locally, so the context might look a bit weird, but you can still get the idea.

---

drivers/firmware/efi/generic-ops.c +1 -10
index 7f51ebd..1a0fc96 100644
@@ -26,8 +26,6 @@ static struct efivar_operations generic_ops;
 
 int generic_register(void)
 {
-	int error;
-
 	if (!efi_enabled(EFI_RUNTIME_SERVICES))
 		return 0;
 
@@ -36,14 +34,7 @@ int generic_register(void)
 	generic_ops.get_next_variable = efi.get_next_variable;
 	generic_ops.query_variable_info = efi.query_variable_info;
 
-	error = efivars_register(&generic_efivars, &generic_ops);
-	if (error)
-		return error;
-
-#if defined(CONFIG_EFI_VARS_SYSFS) || defined(CONFIG_EFI_VARS_SYSFS_MODULE)
-	efivars_sysfs_init(efi_kobj);
-#endif
-	return 0;
+	return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
 }
 
 void generic_unregister(void)
drivers/firmware/efi/sysfs.c +8 -1
index 797e451..8a42d08 100644
@@ -525,8 +525,9 @@ void efivars_sysfs_exit(void)
 	kset_unregister(efivars_kset);
 }
 
-int efivars_sysfs_init(struct kobject *parent_kobj)
+int efivars_sysfs_init(void)
 {
+	struct kobject *parent_kobj;
 	int error = 0;
 
 	printk(KERN_INFO "EFI Variables Facility v%s %s\n", EFIVARS_VERSION,
@@ -535,6 +536,12 @@ int efivars_sysfs_init(struct kobject *parent_kobj)
 	if (!efi_enabled(EFI_RUNTIME_SERVICES))
 		return 0;
 
+	parent_kobj = efivars_kobject();
+	if (!parent_kobj) {
+		printk(KERN_ERR "efivars: No kobject registered.\n");
+		return -EINVAL;
+	}
+
 	efivars_kset = kset_create_and_add("vars", NULL, parent_kobj);
 	if (!efivars_kset) {
 		printk(KERN_ERR "efivars: Subsystem registration failed.\n");
drivers/firmware/efivars.c +17 -5
index ef216b4..81f70db 100644
@@ -855,17 +855,28 @@ int efivar_entry_iter(int (*func)(struct efivar_entry *, void *), void *data)
 }
 EXPORT_SYMBOL_GPL(efivar_entry_iter);
 
+/**
+ * efivars_kobject - get the kobject for the registered efivars
+ */
+struct kobject *efivars_kobject(void)
+{
+	return __efivars->kobject;
+}
+EXPORT_SYMBOL_GPL(efivars_kobject);
+
 static DEFINE_MUTEX(efivars_mutex);
 
 /**
  * efivars_register - register an efivars
  * @efivars: efivars to register
  * @ops: efivars operations
+ * @kobject: @efivars-specific kobject
  *
  * Only a single efivars can be registered at any time.
  */
 int efivars_register(struct efivars *efivars,
-		     const struct efivar_operations *ops)
+		     const struct efivar_operations *ops,
+		     struct kobject *kobject)
 {
 	int rv;
 
@@ -877,6 +888,7 @@ int efivars_register(struct efivars *efivars,
 
 	spin_lock_init(&efivars->lock);
 	INIT_LIST_HEAD(&efivars->list);
+	efivars->kobject = kobject;
 	efivars->ops = ops;
 
 	__efivars = efivars;
@@ -926,7 +938,7 @@ out:
 }
 EXPORT_SYMBOL_GPL(efivars_unregister);
 
-static struct kobject *efivars_kobject;
+static struct kobject *efivars_kobj;
 
 static int __init
 efivars_init(void)
@@ -943,8 +955,8 @@ efivars_init(void)
 		return -ENOMEM;
 	}
 
-	efivars_kobject = kobject_create_and_add("efivars", efi_kobj);
-	if (!efivars_kobject) {
+	efivars_kobj = kobject_create_and_add("efivars", efi_kobj);
+	if (!efivars_kobj) {
 		pr_err("efivars: Subsystem registration failed.\n");
 		kobject_put(efi_kobj);
 		return -ENOMEM;
@@ -965,7 +977,7 @@ static void __exit
 efivars_exit(void)
 {
 	if (efi_enabled(EFI_RUNTIME_SERVICES)) {
-		kobject_put(efivars_kobject);
+		kobject_put(efivars_kobj);
 		kobject_put(efi_kobj);
 	}
 }
drivers/firmware/google/gsmi.c +1 -1
index e902f21..d5ac00c 100644
@@ -882,7 +882,7 @@ static __init int gsmi_init(void)
 		goto out_remove_bin_file;
 	}
 
-	ret = efivars_register(&efivars, &efivar_ops);
+	ret = efivars_register(&efivars, &efivar_ops, gsmi_kobj);
 	if (ret) {
 		printk(KERN_INFO "gsmi: Failed to register efivars\n");
 		goto out_remove_sysfs_files;
include/linux/efi.h +4 -2
index b81928b..ab3934d 100644
@@ -825,8 +825,10 @@ struct efivar_entry {
 };
 
 int efivars_register(struct efivars *efivars,
-		     const struct efivar_operations *ops);
+		     const struct efivar_operations *ops,
+		     struct kobject *kobject);
 int efivars_unregister(struct efivars *efivars);
+struct kobject *efivars_kobject(void);
 
 int efivar_init(int (*func)(struct efivar_entry *, void *), void *data);
 
@@ -861,7 +863,7 @@ int efivar_query_info(u32 attributes, u64 *storage_size,
 		      u64 *remaining_size, u64 *max_size);
 
 #if defined(CONFIG_EFI_VARS_SYSFS) || defined(CONFIG_EFI_VARS_SYSFS_MODULE)
-int efivars_sysfs_init(struct kobject *parent);
+int efivars_sysfs_init(void);
 int efivar_create_sysfs_entry(struct efivar_entry *new_var);
 #endif
 

A message that is not in the archive (sent off-list or not yet received): 1361455094.2842.15.camel-ZqTwcBeJ+wsBof6jY8KHXm7IUlhRatedral2JQCrhuEAvxtiuMwx3w@public.gmane.org

#7 lore raw
Quoted 10 lines · Matt Fleming

Guh, yes. The way I implemented this is rather silly. Thanks for the report! I was trying to avoid having a struct kobject * in struct efivars, because that inherently ties the efivar_entry API to the sysfs code, and the whole point of this series is that you can have EFI variable support without the sysfs stuff.

Instead of doing the #ifdef-ery how does this look? It keeps everything contained within struct efivars just like the old code. Unfortunately it's applied against some changes I've got locally, so the context might look a bit weird, but you can still get the idea.

Not tested, but as far as I can tell this looks great. Thanks!

Cheers,

Tom