Skip to content

Commit 9d843e8

Browse files
Mukesh Ojhakees
authored andcommitted
pstore: Add mem_type property DT parsing support
There could be a scenario where we define some region in normal memory and use them store to logs which is later retrieved by bootloader during warm reset. In this scenario, we wanted to treat this memory as normal cacheable memory instead of default behaviour which is an overhead. Making it cacheable could improve performance. This commit gives control to change mem_type from Device tree, and also documents the value for normal memory. Signed-off-by: Mukesh Ojha <[email protected]> Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent a38fd87 commit 9d843e8

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

Documentation/admin-guide/ramoops.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Ramoops oops/panic logger
33

44
Sergiu Iordache <[email protected]>
55

6-
Updated: 17 November 2011
6+
Updated: 10 Feb 2021
77

88
Introduction
99
------------
@@ -30,6 +30,8 @@ mapping to pgprot_writecombine. Setting ``mem_type=1`` attempts to use
3030
depends on atomic operations. At least on ARM, pgprot_noncached causes the
3131
memory to be mapped strongly ordered, and atomic operations on strongly ordered
3232
memory are implementation defined, and won't work on many ARMs such as omaps.
33+
Setting ``mem_type=2`` attempts to treat the memory region as normal memory,
34+
which enables full cache on it. This can improve the performance.
3335

3436
The memory area is divided into ``record_size`` chunks (also rounded down to
3537
power of two) and each kmesg dump writes a ``record_size`` chunk of

Documentation/devicetree/bindings/reserved-memory/ramoops.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,14 @@ Optional properties:
4242
- pmsg-size: size in bytes of log buffer reserved for userspace messages
4343
(defaults to 0: disabled)
4444

45-
- unbuffered: if present, use unbuffered mappings to map the reserved region
46-
(defaults to buffered mappings)
45+
- mem-type: if present, sets the type of mapping is to be used to map the
46+
reserved region. mem-type: 0 = write-combined (default), 1 = unbuffered,
47+
2 = cached.
48+
49+
- unbuffered: deprecated, use mem_type instead. If present, and mem_type is
50+
not specified, it is equivalent to mem_type = 1 and uses unbuffered mappings
51+
to map the reserved region (defaults to buffered mappings mem_type = 0). If
52+
both are specified -- "mem_type" overrides "unbuffered".
4753

4854
- max-reason: if present, sets maximum type of kmsg dump reasons to store
4955
(defaults to 2: log Oopses and Panics). This can be set to INT_MAX to

fs/pstore/ram.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ MODULE_PARM_DESC(mem_size,
5656
static unsigned int mem_type;
5757
module_param(mem_type, uint, 0400);
5858
MODULE_PARM_DESC(mem_type,
59-
"set to 1 to try to use unbuffered memory (default 0)");
59+
"memory type: 0=write-combined (default), 1=unbuffered, 2=cached");
6060

6161
static int ramoops_max_reason = -1;
6262
module_param_named(max_reason, ramoops_max_reason, int, 0400);
@@ -648,6 +648,10 @@ static int ramoops_parse_dt(struct platform_device *pdev,
648648

649649
pdata->mem_size = resource_size(res);
650650
pdata->mem_address = res->start;
651+
/*
652+
* Setting "unbuffered" is deprecated and will be ignored if
653+
* "mem_type" is also specified.
654+
*/
651655
pdata->mem_type = of_property_read_bool(of_node, "unbuffered");
652656
/*
653657
* Setting "no-dump-oops" is deprecated and will be ignored if
@@ -666,6 +670,7 @@ static int ramoops_parse_dt(struct platform_device *pdev,
666670
field = value; \
667671
}
668672

673+
parse_u32("mem-type", pdata->record_size, pdata->mem_type);
669674
parse_u32("record-size", pdata->record_size, 0);
670675
parse_u32("console-size", pdata->console_size, 0);
671676
parse_u32("ftrace-size", pdata->ftrace_size, 0);

fs/pstore/ram_core.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,10 @@ void persistent_ram_zap(struct persistent_ram_zone *prz)
396396
persistent_ram_update_header_ecc(prz);
397397
}
398398

399+
#define MEM_TYPE_WCOMBINE 0
400+
#define MEM_TYPE_NONCACHED 1
401+
#define MEM_TYPE_NORMAL 2
402+
399403
static void *persistent_ram_vmap(phys_addr_t start, size_t size,
400404
unsigned int memtype)
401405
{
@@ -409,10 +413,20 @@ static void *persistent_ram_vmap(phys_addr_t start, size_t size,
409413
page_start = start - offset_in_page(start);
410414
page_count = DIV_ROUND_UP(size + offset_in_page(start), PAGE_SIZE);
411415

412-
if (memtype)
416+
switch (memtype) {
417+
case MEM_TYPE_NORMAL:
418+
prot = PAGE_KERNEL;
419+
break;
420+
case MEM_TYPE_NONCACHED:
413421
prot = pgprot_noncached(PAGE_KERNEL);
414-
else
422+
break;
423+
case MEM_TYPE_WCOMBINE:
415424
prot = pgprot_writecombine(PAGE_KERNEL);
425+
break;
426+
default:
427+
pr_err("invalid mem_type=%d\n", memtype);
428+
return NULL;
429+
}
416430

417431
pages = kmalloc_array(page_count, sizeof(struct page *), GFP_KERNEL);
418432
if (!pages) {

0 commit comments

Comments
 (0)