Move internal definitions out of kernel-wide include
cover Move internal definitions out of kernel-wide include
Hi,
Here's a set of changes for a few things, inspried by recent discussions with Guilherme, Ard, and Paramjit.
Thanks!
-Kees
Kees Cook (5):
pstore/ram: Consolidate kfree() paths
pstore/ram: Move pmsg init earlier
pstore/ram: Move internal definitions out of kernel-wide include pstore/ram: Set freed addresses to NULL
MAINTAINERS: Update pstore maintainers
MAINTAINERS | 8 +-- fs/pstore/ram.c | 42 ++++++++-------- fs/pstore/ram_core.c | 14 ++++-- fs/pstore/ram_internal.h | 98 +++++++++++++++++++++++++++++++++++++ include/linux/pstore_ram.h | 99 -------------------------------------- 5 files changed, 136 insertions(+), 125 deletions(-) create mode 100644 fs/pstore/ram_internal.h
Signature · 1 line
2.34.1
PATCH 1/5 pstore/ram: Consolidate kfree() paths
There's no reason to keep separate kfree() paths: either all allocations succeeded, or not. Everything is torn down in the case of failure, so adjust the callers to reflect this.
--- fs/pstore/ram.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
fs/pstore/ram.c +11 -11
@@ -451,6 +451,12 @@ static void ramoops_free_przs(struct ramoops_context *cxt) {int i; +/* Free pmsg PRZ */ +persistent_ram_free (cxt->mprz); + +/* Free console PRZ */ +persistent_ram_free (cxt->cprz); +/* Free dump PRZs */ if (cxt->dprzs) {for (i =0 ; i < cxt->max_dump_cnt; i++)
@@ -772,12 +778,12 @@ static int ramoops_probe(struct platform_device *pdev) dump_mem_sz, cxt->record_size, &cxt->max_dump_cnt, 0, 0);if (err) - goto fail_out; + goto fail_init; err =ramoops_init_prz ("console" , dev, cxt, &cxt->cprz, &paddr, cxt->console_size,0 );if (err) - goto fail_init_cprz; + goto fail_init; cxt->max_ftrace_cnt = (cxt->flags &RAMOOPS_FLAG_FTRACE_PER_CPU ) ? nr_cpu_ids
@@ -788,12 +794,12 @@ static int ramoops_probe(struct platform_device *pdev) (cxt->flags &RAMOOPS_FLAG_FTRACE_PER_CPU ) ? PRZ_FLAG_NO_LOCK : 0);if (err) - goto fail_init_fprz; + goto fail_init; err =ramoops_init_prz ("pmsg" , dev, cxt, &cxt->mprz, &paddr, cxt->pmsg_size,0 );if (err) - goto fail_init_mprz; + goto fail_init; cxt->pstore.data = cxt;/*
@@ -857,11 +863,7 @@ static int ramoops_probe(struct platform_device *pdev)kfree (cxt->pstore.buf); fail_clear: cxt->pstore.bufsize =0 ; -persistent_ram_free (cxt->mprz); -fail_init_mprz: -fail_init_fprz: -persistent_ram_free (cxt->cprz); -fail_init_cprz: +fail_init:ramoops_free_przs (cxt); fail_out:return err;
@@ -876,8 +878,6 @@ static int ramoops_remove(struct platform_device *pdev)kfree (cxt->pstore.buf); cxt->pstore.bufsize =0 ; -persistent_ram_free (cxt->mprz); -persistent_ram_free (cxt->cprz);ramoops_free_przs (cxt);return 0 ;
Signature · 1 line
2.34.1
Guilherme G. Piccoli
reviewerRe: [PATCH 1/5] pstore/ram: Consolidate kfree() paths
Quoted 4 lines · Kees Cook
There's no reason to keep separate
kfree()paths: either all allocations succeeded, or not. Everything is torn down in the case of failure, so adjust the callers to reflect this.
Quoted 8 lines
Cc Anton Vorontsov <[email protected]>Cc Colin Cross <[email protected]>Cc Tony Luck <[email protected]>Signed-off-by Kees Cook <[email protected]>--- fs/pstore/ram.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
Tested by building / booting and triggering crashes with efi and ramoops backends.
Cheers,
Guilherme
PATCH 2/5 pstore/ram: Move pmsg init earlier
In reply to Kees CookSince the ftrace area can vary in size based on CPU count, move pmsg initialization earlier so it will have a stable location.
--- fs/pstore/ram.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
fs/pstore/ram.c +5 -5
@@ -785,6 +785,11 @@ static int ramoops_probe(struct platform_device *pdev)if (err) goto fail_init; + err =ramoops_init_prz ("pmsg" , dev, cxt, &cxt->mprz, &paddr, + cxt->pmsg_size,0 ); +if (err) + goto fail_init; + cxt->max_ftrace_cnt = (cxt->flags &RAMOOPS_FLAG_FTRACE_PER_CPU ) ? nr_cpu_ids :1 ;
@@ -796,11 +801,6 @@ static int ramoops_probe(struct platform_device *pdev)if (err) goto fail_init; - err =ramoops_init_prz ("pmsg" , dev, cxt, &cxt->mprz, &paddr, - cxt->pmsg_size,0 ); -if (err) - goto fail_init; - cxt->pstore.data = cxt;/* * Prepare frontend flags based on which areas are initialized.
Signature · 1 line
2.34.1
Guilherme G. Piccoli
reviewerRe: [PATCH 2/5] pstore/ram: Move pmsg init earlier
Quoted 9 lines · Kees Cook
Since the ftrace area can vary in size based on CPU count, move pmsg initialization earlier so it will have a stable location.
Suggested-by Paramjit Oberoi <[email protected]>Cc Anton Vorontsov <[email protected]>Cc Colin Cross <[email protected]>Cc Tony Luck <[email protected]>Signed-off-by Kees Cook <[email protected]>---
Reviewed: Guilherme G. Piccoli <[email protected]>
Since I'm not using pmsg my tests are of limited scope here, so better to consider I just reviewed the patch heh
Cheers,
Guilherme
PATCH 3/5 pstore/ram: Move internal definitions out of kernel-wide include
In reply to Kees CookMost of the details of the ram backend are entirely internal to the backend itself. Leave only what is needed to instantiate a ram backend in the kernel-wide header.
--- fs/pstore/ram.c | 3 +- fs/pstore/ram_core.c | 3 +- fs/pstore/ram_internal.h | 98 +++++++++++++++++++++++++++++++++++++ include/linux/pstore_ram.h | 99 -------------------------------------- 4 files changed, 102 insertions(+), 101 deletions(-) create mode 100644 fs/pstore/ram_internal.h
fs/pstore/ram.c +2 -1
@@ -18,10 +18,11 @@#include <linux/platform_device.h> #include <linux/slab.h> #include <linux/compiler.h> -#include <linux/pstore_ram.h> #include <linux/of.h> #include <linux/of_address.h> +#include "internal.h" +#include "ram_internal.h" #define RAMOOPS_KERNMSG_HDR "===="#define MIN_MEM_SIZE 4096UL
fs/pstore/ram_core.c +2 -1
@@ -13,13 +13,14 @@#include <linux/kernel.h> #include <linux/list.h> #include <linux/memblock.h> -#include <linux/pstore_ram.h> #include <linux/rslib.h> #include <linux/slab.h> #include <linux/uaccess.h> #include <linux/vmalloc.h> #include <asm/page.h> +#include "ram_internal.h" +/** * struct persistent_ram_buffer - persistent circular RAM buffer *
fs/pstore/ram_internal.h new file +98 -0
98 lines not on this page · raw message
include/linux/pstore_ram.h +0 -99
112 lines not on this page · raw message
Signature · 1 line
2.34.1
Guilherme G. Piccoli
reviewerRe: [PATCH 3/5] pstore/ram: Move internal definitions out of kernel-wide include
Quoted 9 lines · Kees Cook
Most of the details of the ram backend are entirely internal to the backend itself. Leave only what is needed to instantiate a ram backend in the kernel-wide header.
Cc Anton Vorontsov <[email protected]>Cc Colin Cross <[email protected]>Cc Tony Luck <[email protected]>Signed-off-by Kees Cook <[email protected]>---
Tested by building and booting the kernel - since it's just header file rework, guess this is enough right?
BTW, let me know if you prefer me to respond on the series once or per patch Kees (as I'm doing here).
Cheers,
Guilherme
Re: [PATCH 3/5] pstore/ram: Move internal definitions out of kernel-wide include
Quoted 11 lines · Guilherme G. Piccoli
Quoted 9 lines · Kees Cook
Most of the details of the ram backend are entirely internal to the backend itself. Leave only what is needed to instantiate a ram backend in the kernel-wide header.
Cc Anton Vorontsov <[email protected]>Cc Colin Cross <[email protected]>Cc Tony Luck <[email protected]>Signed-off-by Kees Cook <[email protected]>---
Quoted 7 lines
Reviewed-and-tested-by Guilherme G. Piccoli <[email protected]>Tested by building and booting the kernel - since it's just header file rework, guess this is enough right?
BTW, let me know if you prefer me to respond on the series once or per patch Kees (as I'm doing here).
Thanks! Yeah, per-patch is good. :)
Signature · 1 line
Kees Cook
PATCH 4/5 pstore/ram: Set freed addresses to NULL
In reply to Kees CookFor good measure, set all the freed addresses to NULL when managing przs.
--- fs/pstore/ram.c | 13 ++++++++----- fs/pstore/ram_core.c | 11 +++++++++-- fs/pstore/ram_internal.h | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-)
fs/pstore/ram.c +8 -5
@@ -453,25 +453,27 @@ static void ramoops_free_przs(struct ramoops_context *cxt)int i;/* Free pmsg PRZ */ -persistent_ram_free (cxt->mprz); +persistent_ram_free (&cxt->mprz);/* Free console PRZ */ -persistent_ram_free (cxt->cprz); +persistent_ram_free (&cxt->cprz);/* Free dump PRZs */ if (cxt->dprzs) {for (i =0 ; i < cxt->max_dump_cnt; i++) -persistent_ram_free (cxt->dprzs[i]); +persistent_ram_free (&cxt->dprzs[i]);kfree (cxt->dprzs); + cxt->fprzs =NULL ; cxt->max_dump_cnt =0 ; }/* Free ftrace PRZs */ if (cxt->fprzs) {for (i =0 ; i < cxt->max_ftrace_cnt; i++) -persistent_ram_free (cxt->fprzs[i]); +persistent_ram_free (&cxt->fprzs[i]);kfree (cxt->fprzs); + cxt->fprzs =NULL ; cxt->max_ftrace_cnt =0 ; } }
@@ -555,9 +557,10 @@ static int ramoops_init_przs(const char *name,while (i >0 ) { i--; -persistent_ram_free (prz_ar[i]); +persistent_ram_free (&prz_ar[i]); }kfree (prz_ar); + prz_ar =NULL ; goto fail; } *paddr += zone_sz;
fs/pstore/ram_core.c +9 -2
@@ -544,8 +544,14 @@ static int persistent_ram_post_init(struct persistent_ram_zone *prz, u32 sig,return 0 ; } -void persistent_ram_free (struct persistent_ram_zone *prz) +void persistent_ram_free (struct persistent_ram_zone **_prz) { +struct persistent_ram_zone *prz; + +if (!_prz) +return ; + + prz = *_prz;if (!prz)return ;
@@ -569,6 +575,7 @@ void persistent_ram_free(struct persistent_ram_zone *prz)persistent_ram_free_old (prz);kfree (prz->label);kfree (prz); + *_prz =NULL ; } struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size,
@@ -605,6 +612,6 @@ struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size,return prz; err: -persistent_ram_free (prz); +persistent_ram_free (&prz);return ERR_PTR (ret); }
fs/pstore/ram_internal.h +1 -1
@@ -82,7 +82,7 @@ struct persistent_ram_zone {struct persistent_ram_zone *persistent_ram_new (phys_addr_t start,size_t size,u32 sig,struct persistent_ram_ecc_info *ecc_info,unsigned int memtype,u32 flags,char *label); -void persistent_ram_free (struct persistent_ram_zone *prz); +void persistent_ram_free (struct persistent_ram_zone **_prz);void persistent_ram_zap (struct persistent_ram_zone *prz); int persistent_ram_write(struct persistent_ram_zone *prz, const void *s,
Signature · 1 line
2.34.1
Guilherme G. Piccoli
reviewerRe: [PATCH 4/5] pstore/ram: Set freed addresses to NULL
Quoted 8 lines · Kees Cook
For good measure, set all the freed addresses to NULL when managing przs.
Cc Anton Vorontsov <[email protected]>Cc Colin Cross <[email protected]>Cc Tony Luck <[email protected]>Signed-off-by Kees Cook <[email protected]>---
Tested by building / booting and triggering crashes with efi and ramoops backends.
Cheers,
Guilherme
PATCH 5/5 MAINTAINERS: Update pstore maintainers
In reply to Kees CookUpdate pstore to better reflect reality of active contributors:
- Remove Anton and Colin (thank you for your help through the years!)
- Move Tony to Reviewer
- Add Guilherme as Reviewer
- Add mailing list
- Upgrade to Supported
--- MAINTAINERS | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
MAINTAINERS +4 -4
@@ -16458,10 +16458,10 @@ F: net/psample PSTORE FILESYSTEM M: Kees Cook <[email protected]> -M: Anton Vorontsov <[email protected]> -M: Colin Cross <[email protected]> -M: Tony Luck <[email protected]> -S: Maintained +R: Tony Luck <[email protected]> +R: Guilherme G. Piccoli <[email protected]> +L: [email protected] +S: Supported T: git git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/pstore F: Documentation/admin-guide/ramoops.rst F: Documentation/admin-guide/pstore-blk.rst
Signature · 1 line
2.34.1
Re: [PATCH 5/5] MAINTAINERS: Update pstore maintainers
Quoted 34 lines · Kees Cook
Update pstore to better reflect reality of active contributors:
- Remove Anton and Colin (thank you for your help through the years!)
- Move Tony to Reviewer
- Add Guilherme as Reviewer
- Add mailing list
- Upgrade to SupportedSigned-off-by Kees Cook <[email protected]>--- MAINTAINERS | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)MAINTAINERS +4
-5@@ -16458,10 +16458,10 @@ F: net/psample PSTORE FILESYSTEM M: Kees Cook <[email protected]> -M: Anton Vorontsov <[email protected]> -M: Colin Cross <[email protected]> -M: Tony Luck <[email protected]> -S: Maintained +R: Tony Luck <[email protected]> +R: Guilherme G. Piccoli <[email protected]> +L: [email protected] +S: Supported T: git git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/pstore F: Documentation/admin-guide/ramoops.rst F: Documentation/admin-guide/pstore-blk.rst --
Quoted 2 lines
2.34.1
Re: [PATCH 5/5] MAINTAINERS: Update pstore maintainers
In reply to Kees CookQuoted 22 lines · Kees Cook
Update pstore to better reflect reality of active contributors:
- Remove Anton and Colin (thank you for your help through the years!)
- Move Tony to Reviewer
- Add Guilherme as Reviewer
- Add mailing list
- Upgrade to SupportedSigned-off-by Kees Cook <[email protected]>--- MAINTAINERS | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)MAINTAINERS +0
-1@@ -16458,10 +16458,10 @@ F: net/psample PSTORE FILESYSTEM M: Kees Cook <[email protected]> -M: Anton Vorontsov <[email protected]>
MAINTAINERS F: net/psample · line 16467
Quoted 10 lines
MAINTAINERS +4
-3-M: Colin Cross <[email protected]> -M: Tony Luck <[email protected]> -S: Maintained +R: Tony Luck <[email protected]> +R: Guilherme G. Piccoli <[email protected]> +L: [email protected] +S: Supported T: git git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/pstore F: Documentation/admin-guide/ramoops.rst F: Documentation/admin-guide/pstore-blk.rst
Thanks Kees!
Just curious, why linux-hardening was the picked list? Cheers,
Guilherme
Re: [PATCH 5/5] MAINTAINERS: Update pstore maintainers
Quoted 4 lines · Guilherme G. Piccoli
Quoted 1 line · Kees Cook
Just curious, why linux-hardening was the picked list?
It's where the bulk of other things I work on end up living, and there's an active patchwork instance, so it'll do patch lifetime tracking for us:
https://patchwork.kernel.org/project/linux-hardening/list/
Signature · 1 line
Kees Cook
Guilherme G. Piccoli
reviewerRe: [PATCH 5/5] MAINTAINERS: Update pstore maintainers
Quoted 11 lines · Kees Cook
Quoted 4 lines · Guilherme G. Piccoli
Quoted 1 line · Kees Cook
Just curious, why linux-hardening was the picked list?
It's where the bulk of other things I work on end up living, and there's an active patchwork instance, so it'll do patch lifetime tracking for us:
https://patchwork.kernel.org/project/linux-hardening/list/
Makes sense, and very nice that it has the patchwork set! Thanks,
Guilherme
Guilherme G. Piccoli
reviewerRe: [PATCH 5/5] MAINTAINERS: Update pstore maintainers
In reply to Kees CookQuoted 8 lines · Kees Cook
Update pstore to better reflect reality of active contributors:
- Remove Anton and Colin (thank you for your help through the years!)
- Move Tony to Reviewer
- Add Guilherme as Reviewer
- Add mailing list
- Upgrade to Supported
Quoted 4 lines
Signed-off-by Kees Cook <[email protected]>--- MAINTAINERS | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Hi Kees, sorry to revamp this thread for a "tangential" topic, but it feels a "kinda" proper thread.
Since I was added as a reviewer on pstore (in linux-next so far), I started to receive a bunch of emails from ARM device-tree folks; they're adding ramoops entries to their DTs and looping pstore folks.
Examples:
https://lore.kernel.org/linux-hardening/[email protected]/
https://lore.kernel.org/linux-hardening/[email protected]/
Personally, I have no knowledge of these HW to evaluate if the ramoops setting is appropriate, so they're nop from my side, I just delete them. But that raises the question - are you/Tony reviewing this kind of change? It's not related to pstore/ramoops code, it's just users setting ramoops in their DTs, so seems to me a bit far from the purpose of the pstore entry.
What do you/Tony think about that? Likely the DT folks are following this entry in the MAINTAINERS to send these emails:
PSTORE FILESYSTEM
M: Kees Cook <[email protected]>
[...]
F: include/linux/pstore* K: \b(pstore|ramoops) <------
Should this be kept? Maybe only the ramoops entry could be removed?
Again, totally fine be me to keep'em, it's just that I'm receiving and ignoring the emails, so if everybody else is doing the same, better to just remove this entry from MAINTAINERS.
Thanks,
Guilherme
Re: [PATCH 5/5] MAINTAINERS: Update pstore maintainers
Quoted 28 lines · Guilherme G. Piccoli
Quoted 8 lines · Kees Cook
Update pstore to better reflect reality of active contributors:
- Remove Anton and Colin (thank you for your help through the years!)
- Move Tony to Reviewer
- Add Guilherme as Reviewer
- Add mailing list
- Upgrade to SupportedQuoted 4 lines
Signed-off-by Kees Cook <[email protected]>--- MAINTAINERS | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)Hi Kees, sorry to revamp this thread for a "tangential" topic, but it feels a "kinda" proper thread.
Since I was added as a reviewer on pstore (in linux-next so far), I started to receive a bunch of emails from ARM device-tree folks; they're adding ramoops entries to their DTs and looping pstore folks.
Examples:
Quoted 6 lines
Personally, I have no knowledge of these HW to evaluate if the ramoops setting is appropriate, so they're nop from my side, I just delete them. But that raises the question - are you/Tony reviewing this kind of change? It's not related to pstore/ramoops code, it's just users setting ramoops in their DTs, so seems to me a bit far from the purpose of the pstore entry.
I usually look at it very quickly, but I can't meaningfully positively review it because I don't know the hardware, etc.
Quoted 10 lines
What do you/Tony think about that? Likely the DT folks are following this entry in the
MAINTAINERSto send these emails:PSTORE FILESYSTEM
M: Kees Cook <[email protected]>
[...]F: include/linux/pstore* K: \b(pstore|ramoops) <------Should this be kept? Maybe only the ramoops entry could be removed?
I would like to keep it -- if something mentions pstore and ramoops, I'd like to see it. I can't review all of it, but I'd like it to at least show up in my inbox. :)
Signature · 1 line
Kees Cook
Guilherme G. Piccoli
reviewerRe: [PATCH 5/5] MAINTAINERS: Update pstore maintainers
Quoted 7 lines · Kees Cook
[...]
Quoted 6 lines
PSTORE FILESYSTEM
M: Kees Cook <[email protected]>
[...]F: include/linux/pstore* K: \b(pstore|ramoops) <------
Quoted 6 lines
Quoted 1 line
Should this be kept? Maybe only the ramoops entry could be removed?
I would like to keep it -- if something mentions pstore and ramoops, I'd like to see it. I can't review all of it, but I'd like it to at least show up in my inbox. :)
Totally fine by me, was curious and now I understand this is not legacy, but something of your interest indeed.
Thanks for the prompt response!
Cheers,
Guilherme