Skip to content

Commit 08ffb58

Browse files
committed
Merge tag 'pstore-v4.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
Pull pstore updates from Kees Cook: "pstore improvements: - refactor init to happen as early as possible again (Joel Fernandes) - improve resource reservation names" * tag 'pstore-v4.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: pstore/ram: Clarify resource reservation labels pstore: Refactor compression initialization pstore: Allocate compression during late_initcall() pstore: Centralize init/exit routines
2 parents 638820d + 1227daa commit 08ffb58

File tree

6 files changed

+90
-33
lines changed

6 files changed

+90
-33
lines changed

fs/pstore/inode.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -482,12 +482,10 @@ static struct file_system_type pstore_fs_type = {
482482
.kill_sb = pstore_kill_sb,
483483
};
484484

485-
static int __init init_pstore_fs(void)
485+
int __init pstore_init_fs(void)
486486
{
487487
int err;
488488

489-
pstore_choose_compression();
490-
491489
/* Create a convenient mount point for people to access pstore */
492490
err = sysfs_create_mount_point(fs_kobj, "pstore");
493491
if (err)
@@ -500,14 +498,9 @@ static int __init init_pstore_fs(void)
500498
out:
501499
return err;
502500
}
503-
module_init(init_pstore_fs)
504501

505-
static void __exit exit_pstore_fs(void)
502+
void __exit pstore_exit_fs(void)
506503
{
507504
unregister_filesystem(&pstore_fs_type);
508505
sysfs_remove_mount_point(fs_kobj, "pstore");
509506
}
510-
module_exit(exit_pstore_fs)
511-
512-
MODULE_AUTHOR("Tony Luck <tony.luck@intel.com>");
513-
MODULE_LICENSE("GPL");

fs/pstore/internal.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ extern bool pstore_is_mounted(void);
3737
extern void pstore_record_init(struct pstore_record *record,
3838
struct pstore_info *psi);
3939

40-
/* Called during module_init() */
41-
extern void __init pstore_choose_compression(void);
40+
/* Called during pstore init/exit. */
41+
int __init pstore_init_fs(void);
42+
void __exit pstore_exit_fs(void);
4243

4344
#endif

fs/pstore/platform.c

Lines changed: 62 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -274,36 +274,56 @@ static int pstore_decompress(void *in, void *out,
274274

275275
static void allocate_buf_for_compression(void)
276276
{
277+
struct crypto_comp *ctx;
278+
int size;
279+
char *buf;
280+
281+
/* Skip if not built-in or compression backend not selected yet. */
277282
if (!IS_ENABLED(CONFIG_PSTORE_COMPRESS) || !zbackend)
278283
return;
279284

285+
/* Skip if no pstore backend yet or compression init already done. */
286+
if (!psinfo || tfm)
287+
return;
288+
280289
if (!crypto_has_comp(zbackend->name, 0, 0)) {
281-
pr_err("No %s compression\n", zbackend->name);
290+
pr_err("Unknown compression: %s\n", zbackend->name);
282291
return;
283292
}
284293

285-
big_oops_buf_sz = zbackend->zbufsize(psinfo->bufsize);
286-
if (big_oops_buf_sz <= 0)
294+
size = zbackend->zbufsize(psinfo->bufsize);
295+
if (size <= 0) {
296+
pr_err("Invalid compression size for %s: %d\n",
297+
zbackend->name, size);
287298
return;
299+
}
288300

289-
big_oops_buf = kmalloc(big_oops_buf_sz, GFP_KERNEL);
290-
if (!big_oops_buf) {
291-
pr_err("allocate compression buffer error!\n");
301+
buf = kmalloc(size, GFP_KERNEL);
302+
if (!buf) {
303+
pr_err("Failed %d byte compression buffer allocation for: %s\n",
304+
size, zbackend->name);
292305
return;
293306
}
294307

295-
tfm = crypto_alloc_comp(zbackend->name, 0, 0);
296-
if (IS_ERR_OR_NULL(tfm)) {
297-
kfree(big_oops_buf);
298-
big_oops_buf = NULL;
299-
pr_err("crypto_alloc_comp() failed!\n");
308+
ctx = crypto_alloc_comp(zbackend->name, 0, 0);
309+
if (IS_ERR_OR_NULL(ctx)) {
310+
kfree(buf);
311+
pr_err("crypto_alloc_comp('%s') failed: %ld\n", zbackend->name,
312+
PTR_ERR(ctx));
300313
return;
301314
}
315+
316+
/* A non-NULL big_oops_buf indicates compression is available. */
317+
tfm = ctx;
318+
big_oops_buf_sz = size;
319+
big_oops_buf = buf;
320+
321+
pr_info("Using compression: %s\n", zbackend->name);
302322
}
303323

304324
static void free_buf_for_compression(void)
305325
{
306-
if (IS_ENABLED(CONFIG_PSTORE_COMPRESS) && !IS_ERR_OR_NULL(tfm))
326+
if (IS_ENABLED(CONFIG_PSTORE_COMPRESS) && tfm)
307327
crypto_free_comp(tfm);
308328
kfree(big_oops_buf);
309329
big_oops_buf = NULL;
@@ -774,14 +794,43 @@ void __init pstore_choose_compression(void)
774794
for (step = zbackends; step->name; step++) {
775795
if (!strcmp(compress, step->name)) {
776796
zbackend = step;
777-
pr_info("using %s compression\n", zbackend->name);
778797
return;
779798
}
780799
}
781800
}
782801

802+
static int __init pstore_init(void)
803+
{
804+
int ret;
805+
806+
pstore_choose_compression();
807+
808+
/*
809+
* Check if any pstore backends registered earlier but did not
810+
* initialize compression because crypto was not ready. If so,
811+
* initialize compression now.
812+
*/
813+
allocate_buf_for_compression();
814+
815+
ret = pstore_init_fs();
816+
if (ret)
817+
return ret;
818+
819+
return 0;
820+
}
821+
late_initcall(pstore_init);
822+
823+
static void __exit pstore_exit(void)
824+
{
825+
pstore_exit_fs();
826+
}
827+
module_exit(pstore_exit)
828+
783829
module_param(compress, charp, 0444);
784830
MODULE_PARM_DESC(compress, "Pstore compression to use");
785831

786832
module_param(backend, charp, 0444);
787833
MODULE_PARM_DESC(backend, "Pstore backend to use");
834+
835+
MODULE_AUTHOR("Tony Luck <tony.luck@intel.com>");
836+
MODULE_LICENSE("GPL");

fs/pstore/ram.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -587,9 +587,16 @@ static int ramoops_init_przs(const char *name,
587587
goto fail;
588588

589589
for (i = 0; i < *cnt; i++) {
590+
char *label;
591+
592+
if (*cnt == 1)
593+
label = kasprintf(GFP_KERNEL, "ramoops:%s", name);
594+
else
595+
label = kasprintf(GFP_KERNEL, "ramoops:%s(%d/%d)",
596+
name, i, *cnt - 1);
590597
prz_ar[i] = persistent_ram_new(*paddr, zone_sz, sig,
591-
&cxt->ecc_info,
592-
cxt->memtype, flags);
598+
&cxt->ecc_info,
599+
cxt->memtype, flags, label);
593600
if (IS_ERR(prz_ar[i])) {
594601
err = PTR_ERR(prz_ar[i]);
595602
dev_err(dev, "failed to request %s mem region (0x%zx@0x%llx): %d\n",
@@ -619,6 +626,8 @@ static int ramoops_init_prz(const char *name,
619626
struct persistent_ram_zone **prz,
620627
phys_addr_t *paddr, size_t sz, u32 sig)
621628
{
629+
char *label;
630+
622631
if (!sz)
623632
return 0;
624633

@@ -629,8 +638,9 @@ static int ramoops_init_prz(const char *name,
629638
return -ENOMEM;
630639
}
631640

641+
label = kasprintf(GFP_KERNEL, "ramoops:%s", name);
632642
*prz = persistent_ram_new(*paddr, sz, sig, &cxt->ecc_info,
633-
cxt->memtype, 0);
643+
cxt->memtype, 0, label);
634644
if (IS_ERR(*prz)) {
635645
int err = PTR_ERR(*prz);
636646

@@ -962,7 +972,7 @@ static int __init ramoops_init(void)
962972

963973
return ret;
964974
}
965-
late_initcall(ramoops_init);
975+
postcore_initcall(ramoops_init);
966976

967977
static void __exit ramoops_exit(void)
968978
{

fs/pstore/ram_core.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -438,11 +438,11 @@ static void *persistent_ram_vmap(phys_addr_t start, size_t size,
438438
}
439439

440440
static void *persistent_ram_iomap(phys_addr_t start, size_t size,
441-
unsigned int memtype)
441+
unsigned int memtype, char *label)
442442
{
443443
void *va;
444444

445-
if (!request_mem_region(start, size, "persistent_ram")) {
445+
if (!request_mem_region(start, size, label ?: "ramoops")) {
446446
pr_err("request mem region (0x%llx@0x%llx) failed\n",
447447
(unsigned long long)size, (unsigned long long)start);
448448
return NULL;
@@ -470,7 +470,8 @@ static int persistent_ram_buffer_map(phys_addr_t start, phys_addr_t size,
470470
if (pfn_valid(start >> PAGE_SHIFT))
471471
prz->vaddr = persistent_ram_vmap(start, size, memtype);
472472
else
473-
prz->vaddr = persistent_ram_iomap(start, size, memtype);
473+
prz->vaddr = persistent_ram_iomap(start, size, memtype,
474+
prz->label);
474475

475476
if (!prz->vaddr) {
476477
pr_err("%s: Failed to map 0x%llx pages at 0x%llx\n", __func__,
@@ -541,12 +542,13 @@ void persistent_ram_free(struct persistent_ram_zone *prz)
541542
prz->ecc_info.par = NULL;
542543

543544
persistent_ram_free_old(prz);
545+
kfree(prz->label);
544546
kfree(prz);
545547
}
546548

547549
struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size,
548550
u32 sig, struct persistent_ram_ecc_info *ecc_info,
549-
unsigned int memtype, u32 flags)
551+
unsigned int memtype, u32 flags, char *label)
550552
{
551553
struct persistent_ram_zone *prz;
552554
int ret = -ENOMEM;
@@ -560,6 +562,7 @@ struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size,
560562
/* Initialize general buffer state. */
561563
raw_spin_lock_init(&prz->buffer_lock);
562564
prz->flags = flags;
565+
prz->label = label;
563566

564567
ret = persistent_ram_buffer_map(start, size, prz, memtype);
565568
if (ret)

include/linux/pstore_ram.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ struct persistent_ram_zone {
4646
phys_addr_t paddr;
4747
size_t size;
4848
void *vaddr;
49+
char *label;
4950
struct persistent_ram_buffer *buffer;
5051
size_t buffer_size;
5152
u32 flags;
@@ -65,7 +66,7 @@ struct persistent_ram_zone {
6566

6667
struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size,
6768
u32 sig, struct persistent_ram_ecc_info *ecc_info,
68-
unsigned int memtype, u32 flags);
69+
unsigned int memtype, u32 flags, char *label);
6970
void persistent_ram_free(struct persistent_ram_zone *prz);
7071
void persistent_ram_zap(struct persistent_ram_zone *prz);
7172

0 commit comments

Comments
 (0)