Skip to contentSkip to conversation

efi: add efivars kobject to efi sysfs folder

PATCH In review Lee, Chun-Yi 5 participants 5 messages Oct 4, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 efi: add efivars kobject to efi sysfs folder

UEFI variable filesystem need a new mount point, so this patch add efivars kobject to efi_kobj for create a /sys/firmware/efi/efivars folder.

Cc Matt Fleming <[email protected]>
Cc Jeremy Kerr <[email protected]>
Cc Matthew Garrett <[email protected]>
Cc H. Peter Anvin <[email protected]>
---
 drivers/firmware/efivars.c |   11 +++++++++++
 include/linux/efi.h        |    1 +
 2 files changed, 12 insertions(+), 0 deletions(-)
drivers/firmware/efivars.c +11 -0
index 1e1aad0..7c1234e 100644
@@ -1487,6 +1487,7 @@ void unregister_efivars(struct efivars *efivars)
 		sysfs_remove_bin_file(&efivars->kset->kobj, efivars->del_var);
 	kfree(efivars->new_var);
 	kfree(efivars->del_var);
+	kobject_put(efivars->kobject);
 	kset_unregister(efivars->kset);
 }
 EXPORT_SYMBOL_GPL(unregister_efivars);
@@ -1518,6 +1519,13 @@ int register_efivars(struct efivars *efivars,
 		goto out;
 	}
 
+	efivars->kobject = kobject_create_and_add("efivars", parent_kobj);
+	if (!efivars->kobject) {
+		pr_err("efivars: Subsystem registration failed.\n");
+		error = -ENOMEM;
+		goto err_unreg_vars;
+	}
+
 	/*
 	 * Per EFI spec, the maximum storage allocated for both
 	 * the variable name and variable data is 1024 bytes.
@@ -1562,6 +1570,9 @@ int register_efivars(struct efivars *efivars,
 
 	register_filesystem(&efivars_fs_type);
 
+err_unreg_vars:
+	kset_unregister(efivars->kset);
+
 out:
 	kfree(variable_name);
 
include/linux/efi.h +1 -0
index 1829a97..c993f54 100644
@@ -654,6 +654,7 @@ struct efivars {
 	spinlock_t lock;
 	struct list_head list;
 	struct kset *kset;
+	struct kobject *kobject;
 	struct bin_attribute *new_var, *del_var;
 	const struct efivar_operations *ops;
 	struct efivar_entry *walk_entry;
Signature · 1 line
1.7.7
#1 lore raw
Quoted 9 lines · Chun-Yi

UEFI variable filesystem need a new mount point, so this patch add efivars kobject to efi_kobj for create a /sys/firmware/efi/efivars folder.

Cc Matt Fleming <[email protected]>
Cc Jeremy Kerr <[email protected]>
Cc Matthew Garrett <[email protected]>
Cc H. Peter Anvin <[email protected]>
Quoted 4 lines
---
 drivers/firmware/efivars.c |   11 +++++++++++
 include/linux/efi.h        |    1 +
 2 files changed, 12 insertions(+), 0 deletions(-)

Jeremy, did you want to pick this up as part of your series?

Actually, shouldn't the new filesystem be called "efivarfs", or "efifs" to make it more explicit that it is a filesystem?

We also need something in Documentation/filesystems/ describing the old EFI variable method, why it's no longer any good, and why the new filesystem is favoured. Does anybody have anything to add to the following?

Documentation/filesystems/00-INDEX +2 -0
index 8c624a1..ddf5a83 100644
@@ -38,6 +38,8 @@ dnotify_test.c
 	- example program for dnotify
 ecryptfs.txt
 	- docs on eCryptfs: stacked cryptographic filesystem for Linux.
+efivars.txt
+	- info for the efivars filesystem.
 exofs.txt
 	- info, usage, mount options, design about EXOFS.
 ext2.txt
Documentation/filesystems/efivars.txt new file +16 -0
new file mode 100644
index 0000000..4350c1a
@@ -0,0 +1,16 @@
+
+efivars - a (U)EFI variable filesystem
+
+The efivars filesystem was created to address the shortcomings of
+using entries in sysfs to maintain EFI variables. The old sysfs EFI
+variables code only supported variables of up to 1024 bytes. This
+limitation existed in version 0.99 of the EFI specification, but was
+removed before any full releases. Since variables can now be larger
+than a single page, sysfs isn't the best interface for this.
+
+Variables can be created, deleted and modified with the efivars
+filesystem.
+
+The efivars filesystem is typically mounted like this,
+
+	mount -t efivars none /sys/firmware/efi/efivars
#2 lore raw

Hi Matt,

Quoted 1 line

Jeremy, did you want to pick this up as part of your series?

I have this in my series, yes. I'm just working on the authenticated delete code, then will send out the next revision.

Speaking of which - Peter: I've realised that doing a GetVariable() after the SetVariable is a much cleaner way of checking whether we need to drop the inode after an authenticated delete.

Because the inode's size may not be simply updated by the write(), we should probably be doing a GetVariable() after an APPEND_WRITE, to read the new size. Rather than having a separate (and quite complex) code path to check for the delete case, we may as well use the same logic to determine if the variable has been deleted.

Quoted 2 lines

Actually, shouldn't the new filesystem be called "efivarfs", or "efifs" to make it more explicit that it is a filesystem?

I'm not too fussed about the name, but +1 for efivarfs.

Quoted 4 lines

We also need something in Documentation/filesystems/ describing the old EFI variable method, why it's no longer any good, and why the new filesystem is favoured. Does anybody have anything to add to the following?

Looks good to me. We can always elaborate later, if necessary.

Cheers,

Jeremy

#3 lore raw
Quoted 11 lines · Jeremy Kerr

Hi Matt,

Quoted 1 line

Jeremy, did you want to pick this up as part of your series?

I have this in my series, yes. I'm just working on the authenticated delete code, then will send out the next revision.

Speaking of which - Peter: I've realised that doing a GetVariable() after the SetVariable is a much cleaner way of checking whether we need to drop the inode after an authenticated delete.

Quoted 5 lines

Because the inode's size may not be simply updated by the write(), we should probably be doing a GetVariable() after an APPEND_WRITE, to read the new size. Rather than having a separate (and quite complex) code path to check for the delete case, we may as well use the same logic to determine if the variable has been deleted.

Yeah, this is fine.

Quoted 4 lines
Quoted 2 lines

Actually, shouldn't the new filesystem be called "efivarfs", or "efifs" to make it more explicit that it is a filesystem?

I'm not too fussed about the name, but +1 for efivarfs.

I like efivarfs for the name, as well.

Quoted 6 lines
Quoted 4 lines

We also need something in Documentation/filesystems/ describing the old EFI variable method, why it's no longer any good, and why the new filesystem is favoured. Does anybody have anything to add to the following?

Looks good to me. We can always elaborate later, if necessary.

Yep.

Signature · 1 line
        Peter
#4 lore raw
In reply to Matt Fleming

於 四,2012-10-04 於 09:54 +0100,Matt Fleming 提到:

Quoted 15 lines · Chun-Yi
Quoted 9 lines

UEFI variable filesystem need a new mount point, so this patch add efivars kobject to efi_kobj for create a /sys/firmware/efi/efivars folder.

Cc Matt Fleming <[email protected]>
Cc Jeremy Kerr <[email protected]>
Cc Matthew Garrett <[email protected]>
Cc H. Peter Anvin <[email protected]>
Quoted 4 lines
---
 drivers/firmware/efivars.c |   11 +++++++++++
 include/linux/efi.h        |    1 +
 2 files changed, 12 insertions(+), 0 deletions(-)
Quoted 2 lines

Actually, shouldn't the new filesystem be called "efivarfs", or "efifs" to make it more explicit that it is a filesystem?

I used "efivars" because this folder generated by efivars. But, I like your suggestion for use "efivarfs", it's better then "efivars".

Quoted 32 lines

We also need something in Documentation/filesystems/ describing the old EFI variable method, why it's no longer any good, and why the new filesystem is favoured. Does anybody have anything to add to the following?

Documentation/filesystems/00-INDEX +2 -0
index 8c624a1..ddf5a83 100644
@@ -38,6 +38,8 @@ dnotify_test.c
 	- example program for dnotify
 ecryptfs.txt
 	- docs on eCryptfs: stacked cryptographic filesystem for Linux.
+efivars.txt
+	- info for the efivars filesystem.
 exofs.txt
 	- info, usage, mount options, design about EXOFS.
 ext2.txt
Documentation/filesystems/efivars.txt new file +6 -0
new file mode 100644
index 0000000..4350c1a
@@ -0,0 +1,16 @@
+
+efivars - a (U)EFI variable filesystem
+
+The efivars filesystem was created to address the shortcomings of
+using entries in sysfs to maintain EFI variables. The old sysfs EFI
+variables code only supported variables of up to 1024 bytes. This

Documentation/filesystems/efivars.txt line 16

Quoted 10 lines
Documentation/filesystems/efivars.txt new file +10 -0
+limitation existed in version 0.99 of the EFI specification, but was
+removed before any full releases. Since variables can now be larger
+than a single page, sysfs isn't the best interface for this.
+
+Variables can be created, deleted and modified with the efivars
+filesystem.
+
+The efivars filesystem is typically mounted like this,
+
+	mount -t efivars none /sys/firmware/efi/efivars

The above documentation is really good!

Thanks a lot!
Joey Lee