Skip to contentSkip to conversation

pstore: resend three patches

PATCH In review Geliang Tang 4 participants 12 messages Nov 7, 2015 – Jun 2, 2016

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

v2 cover pstore: resend three patches

I sent these patches a few weeks ago. Due to the recent changes in pstore, these patched might not apply anymore. So I refresh and resend them.

---
Changes in v2:
- refresh the patches.
---

Geliang Tang (3):
pstore: check PSTORE_FLAGS_FRAGILE in pstore_unregister
efi-pstore: implement efivars_pstore_exit()
pstore: drop file opened reference count

 drivers/firmware/efi/efi-pstore.c | 7 +++++++
 fs/pstore/inode.c                 | 1 -
 fs/pstore/platform.c              | 9 ++++++---
 3 files changed, 13 insertions(+), 4 deletions(-)
Signature · 1 line
2.5.0
#1 lore raw

PATCH v2 1/3 pstore: check PSTORE_FLAGS_FRAGILE in pstore_unregister

When PSTORE_FLAGS_FRAGILE flag is set, only kmsg is registered in pstore_register. So, under these circumstances, only kmsg needs to be unregistered in pstore_unregister.

---
 fs/pstore/platform.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
fs/pstore/platform.c +6 -3
index 588461b..5b8f1eb 100644
@@ -497,9 +497,12 @@ EXPORT_SYMBOL_GPL(pstore_register);
 
 void pstore_unregister(struct pstore_info *psi)
 {
-	pstore_unregister_pmsg();
-	pstore_unregister_ftrace();
-	pstore_unregister_console();
+	if ((psi->flags & PSTORE_FLAGS_FRAGILE) == 0) {
+		pstore_unregister_pmsg();
+		pstore_unregister_ftrace();
+		pstore_unregister_console();
+	}
+
 	pstore_unregister_kmsg();
 
 	free_buf_for_compression();
Signature · 1 line
2.5.0
#2 lore raw

Re: [PATCH v2 1/3] pstore: check PSTORE_FLAGS_FRAGILE in pstore_unregister

Quoted 5 lines · Geliang Tang

When PSTORE_FLAGS_FRAGILE flag is set, only kmsg is registered in pstore_register. So, under these circumstances, only kmsg needs to be unregistered in pstore_unregister.

I actually did the exact same thing recently, sorry to missing this earlier version.

-Kees

Quoted 28 lines
---
 fs/pstore/platform.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
fs/pstore/platform.c +6 -4
index 588461b..5b8f1eb 100644
@@ -497,9 +497,12 @@ EXPORT_SYMBOL_GPL(pstore_register);
 
 void pstore_unregister(struct pstore_info *psi)
 {
-       pstore_unregister_pmsg();
-       pstore_unregister_ftrace();
-       pstore_unregister_console();
+       if ((psi->flags & PSTORE_FLAGS_FRAGILE) == 0) {
+               pstore_unregister_pmsg();
+               pstore_unregister_ftrace();
+               pstore_unregister_console();
+       }
+
        pstore_unregister_kmsg();
 
        free_buf_for_compression();
--

2.5.0

Signature · 2 lines
Kees Cook
Chrome OS & Brillo Security
#3 lore raw

PATCH v2 2/3 efi-pstore: implement efivars_pstore_exit()

In reply to Geliang Tang

The original efivars_pstore_exit() is empty. I
1) add a bufsize check statement.
2) call pstore_unregister as it is defined now.
3) free the memory and set bufsize to 0.

---
 drivers/firmware/efi/efi-pstore.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/firmware/efi/efi-pstore.c +7 -0
index eac76a7..62d57d8 100644
@@ -393,6 +393,13 @@ static __init int efivars_pstore_init(void)
 
 static __exit void efivars_pstore_exit(void)
 {
+	if (!efi_pstore_info.bufsize)
+		return;
+
+	pstore_unregister(&efi_pstore_info);
+	kfree(efi_pstore_info.buf);
+	efi_pstore_info.buf = NULL;
+	efi_pstore_info.bufsize = 0;
 }
 
 module_init(efivars_pstore_init);
Signature · 1 line
2.5.0
#4 lore raw

Re: [PATCH v2 2/3] efi-pstore: implement efivars_pstore_exit()

Quoted 18 lines · Geliang Tang

The original efivars_pstore_exit() is empty. I
1) add a bufsize check statement.
2) call pstore_unregister as it is defined now.
3) free the memory and set bufsize to 0.

---
 drivers/firmware/efi/efi-pstore.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/firmware/efi/efi-pstore.c +0 -0
index eac76a7..62d57d8 100644
@@ -393,6 +393,13 @@ static __init int efivars_pstore_init(void)
 
 static __exit void efivars_pstore_exit(void)
 {

drivers/firmware/efi/efi-pstore.c static __init int efivars_pstore_init(void) · line 405

Quoted 10 lines
drivers/firmware/efi/efi-pstore.c +7 -0
+	if (!efi_pstore_info.bufsize)
+		return;
+
+	pstore_unregister(&efi_pstore_info);
+	kfree(efi_pstore_info.buf);
+	efi_pstore_info.buf = NULL;
+	efi_pstore_info.bufsize = 0;
 }
 
 module_init(efivars_pstore_init);

Looks OK to me. Kees, are you picking this up?

#5 lore raw

Re: [PATCH v2 2/3] efi-pstore: implement efivars_pstore_exit()

Quoted 28 lines · Matt Fleming
Quoted 27 lines · Geliang Tang

The original efivars_pstore_exit() is empty. I
1) add a bufsize check statement.
2) call pstore_unregister as it is defined now.
3) free the memory and set bufsize to 0.

---
 drivers/firmware/efi/efi-pstore.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/firmware/efi/efi-pstore.c +7 -0
index eac76a7..62d57d8 100644
@@ -393,6 +393,13 @@ static __init int efivars_pstore_init(void)
 
 static __exit void efivars_pstore_exit(void)
 {
+     if (!efi_pstore_info.bufsize)
+             return;
+
+     pstore_unregister(&efi_pstore_info);
+     kfree(efi_pstore_info.buf);
+     efi_pstore_info.buf = NULL;
+     efi_pstore_info.bufsize = 0;
 }
 
Quoted 3 lines

drivers/firmware/efi/efi-pstore.c static __init int efivars_pstore_init(void) · line 405

Quoted 1 line
drivers/firmware/efi/efi-pstore.c +0 -0
 module_init(efivars_pstore_init);

Looks OK to me. Kees, are you picking this up?

I can, though usually it goes through Tony.

-Kees

Signature · 2 lines
Kees Cook
Chrome OS Security
reviewer
#6 lore raw

RE: [PATCH v2 2/3] efi-pstore: implement efivars_pstore_exit()

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

module_init(efivars_pstore_init);

Looks OK to me. Kees, are you picking this up?

I can, though usually it goes through Tony.

Can I count that as "Acked-by" from both of you?

-Tony

Acked-by
#7 lore raw

Re: [PATCH v2 2/3] efi-pstore: implement efivars_pstore_exit()

Quoted 7 lines · Tony
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

module_init(efivars_pstore_init);

Looks OK to me. Kees, are you picking this up?

I can, though usually it goes through Tony.

Can I count that as "Acked-by" from both of you?

Yup, sorry. I thought I'd acked them already. :) My bad!

-Kees

Signature · 2 lines
Kees Cook
Chrome OS Security
#8 lore raw

Re: [PATCH v2 2/3] efi-pstore: implement efivars_pstore_exit()

Quoted 5 lines · Kees Cook
Quoted 4 lines · Tony
Quoted 4 lines
Quoted 3 lines
Quoted 1 line

module_init(efivars_pstore_init);

Looks OK to me. Kees, are you picking this up?

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

I can, though usually it goes through Tony.

Can I count that as "Acked-by" from both of you?

Yup, sorry. I thought I'd acked them already. :) My bad!

Hi Kees,

Could you please apply these three pending patches for me? I think they are still valid. Thank you very much.

-Geliang

Quoted 5 lines

-Kees

Signature · 2 lines
Kees Cook
Chrome OS Security
#9 lore raw

Re: [PATCH v2 2/3] efi-pstore: implement efivars_pstore_exit()

Quoted 12 lines · Geliang Tang
Quoted 11 lines · Kees Cook
Quoted 7 lines · Tony
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

module_init(efivars_pstore_init);

Looks OK to me. Kees, are you picking this up?

I can, though usually it goes through Tony.

Can I count that as "Acked-by" from both of you?

Yup, sorry. I thought I'd acked them already. :) My bad!

Quoted 7 lines
Quoted 2 lines

Hi Kees,

Could you please apply these three pending patches for me? I think they are still valid. Thank you very much.

Yes, added to my for-next tree now. Thanks!

-Kees

Signature · 2 lines
Kees Cook
Chrome OS & Brillo Security
#10 lore raw

Re: [PATCH v2 2/3] efi-pstore: implement efivars_pstore_exit()

In reply to Luck, Tony
Quoted 7 lines · Tony
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

module_init(efivars_pstore_init);

Looks OK to me. Kees, are you picking this up?

I can, though usually it goes through Tony.

Can I count that as "Acked-by" from both of you?

Yep, Acked-by: Matt Fleming <[email protected]>

#11 lore raw

PATCH v2 3/3 pstore: drop file opened reference count

In reply to Geliang Tang

In my recent commit, I added '.owner = THIS_MODULE' in both pstore_fs_type and pstore_file_operations to increase a reference count when pstore filesystem is mounted and pstore file is opened.[1]

But, it's repetitive. There is no need to increase the opened reference count. We only need to increase the mounted reference count. When a file is opened, the filesystem can't be unmounted. Hence the pstore module can't be unloaded either.

So I drop the opened reference count in this patch.

[1] https://lkml.org/lkml/2015/10/20/84

---
Here is the reference count test:

$ sudo /sbin/insmod lib/zlib_deflate/zlib_deflate.ko
$ sudo /sbin/insmod fs/pstore/pstore.ko
$ lsmod
Module                  Size  Used by
pstore                 13301  0
zlib_deflate           20156  1 pstore
$ sudo mount -t pstore pstore /sys/fs/pstore
$ lsmod
Module                  Size  Used by
pstore                 13301  1
zlib_deflate           20156  1 pstore
$ sudo /sbin/insmod lib/reed_solomon/reed_solomon.ko
$ sudo /sbin/insmod fs/pstore/ramoops.ko mem_address=0x80000000 mem_size=0x40000 ecc=1
$ lsmod
Module                  Size  Used by
ramoops                11156  0
reed_solomon            5878  1 ramoops
pstore                 13301  2 ramoops
zlib_deflate           20156  1 pstore
$ sudo rmmod ramoops
$ lsmod
Module                  Size  Used by
reed_solomon            5878  0
pstore                 13301  1
zlib_deflate           20156  1 pstore
$ tail -f /sys/fs/pstore/console-ramoops-0 &
[1] 4479
$ lsmod
Module                  Size  Used by
reed_solomon            5878  0
pstore                 13301  1
zlib_deflate           20156  1 pstore
$ sudo umount /sys/fs/pstore
umount: /sys/fs/pstore: target is busy
        (In some cases useful info about processes that
         use the device is found by lsof(8) or fuser(1).)
$ kill -9 4479
[1]+  Killed                  tail -f /sys/fs/pstore/console-ramoops-0
$ lsmod
Module                  Size  Used by
reed_solomon            5878  0
pstore                 13301  1
zlib_deflate           20156  1 pstore
$ sudo umount /sys/fs/pstore
$ lsmod
Module                  Size  Used by
reed_solomon            5878  0
pstore                 13301  0
zlib_deflate           20156  1 pstore
$ sudo rmmod pstore
$ lsmod
Module                  Size  Used by
reed_solomon            5878  0
zlib_deflate           20156  0
---
 fs/pstore/inode.c | 1 -
 1 file changed, 1 deletion(-)
fs/pstore/inode.c +0 -1
index d8c439d..ac6c78fe 100644
@@ -178,7 +178,6 @@ static loff_t pstore_file_llseek(struct file *file, loff_t off, int whence)
 }
 
 static const struct file_operations pstore_file_operations = {
-	.owner		= THIS_MODULE,
 	.open		= pstore_file_open,
 	.read		= pstore_file_read,
 	.llseek		= pstore_file_llseek,
Signature · 1 line
2.5.0