Skip to contentSkip to conversation

pstore/ram : Add support for cached pages

PATCH In review Mukesh Ojha 3 participants 5 messages Feb 10, 2021 – Feb 11, 2021

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

PATCH 1/1 pstore/ram : Add support for cached pages

There could be a sceanario 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.

---
 Documentation/admin-guide/ramoops.rst |  4 +++-
 fs/pstore/ram.c                       |  1 +
 fs/pstore/ram_core.c                  | 10 ++++++++--
 3 files changed, 12 insertions(+), 3 deletions(-)
Documentation/admin-guide/ramoops.rst +3 -1
index b0a1ae7..8f107d8 100644
@@ -3,7 +3,7 @@ Ramoops oops/panic logger
 
 Sergiu Iordache <[email protected]>
 
-Updated: 17 November 2011
+Updated: 10 Feb 2021
 
 Introduction
 ------------
@@ -30,6 +30,8 @@ mapping to pgprot_writecombine. Setting ``mem_type=1`` attempts to use
 depends on atomic operations. At least on ARM, pgprot_noncached causes the
 memory to be mapped strongly ordered, and atomic operations on strongly ordered
 memory are implementation defined, and won't work on many ARMs such as omaps.
+Setting ``mem_type=2`` attempts to treat the memory region as normal memory,
+which enables full cache on it. This can improve the performance.
 
 The memory area is divided into ``record_size`` chunks (also rounded down to
 power of two) and each kmesg dump writes a ``record_size`` chunk of
fs/pstore/ram.c +1 -0
index ca6d8a8..b262c57 100644
@@ -666,6 +666,7 @@ static int ramoops_parse_dt(struct platform_device *pdev,
 		field = value;						\
 	}
 
+	parse_u32("mem-type", pdata->record_size, pdata->mem_type);
 	parse_u32("record-size", pdata->record_size, 0);
 	parse_u32("console-size", pdata->console_size, 0);
 	parse_u32("ftrace-size", pdata->ftrace_size, 0);
fs/pstore/ram_core.c +8 -2
index aa8e0b6..83cd612 100644
@@ -396,6 +396,10 @@ void persistent_ram_zap(struct persistent_ram_zone *prz)
 	persistent_ram_update_header_ecc(prz);
 }
 
+#define MEM_TYPE_WCOMBINE	0
+#define MEM_TYPE_NONCACHED	1
+#define MEM_TYPE_NORMAL		2
+
 static void *persistent_ram_vmap(phys_addr_t start, size_t size,
 		unsigned int memtype)
 {
@@ -409,9 +413,11 @@ static void *persistent_ram_vmap(phys_addr_t start, size_t size,
 	page_start = start - offset_in_page(start);
 	page_count = DIV_ROUND_UP(size + offset_in_page(start), PAGE_SIZE);
 
-	if (memtype)
+	if (memtype == MEM_TYPE_NORMAL)
+		prot = PAGE_KERNEL;
+	else if (memtype == MEM_TYPE_NONCACHED)
 		prot = pgprot_noncached(PAGE_KERNEL);
-	else
+	else if (memtype == MEM_TYPE_WCOMBINE)
 		prot = pgprot_writecombine(PAGE_KERNEL);
 
 	pages = kmalloc_array(page_count, sizeof(struct page *), GFP_KERNEL);
Signature · 2 lines
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center,
Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
reviewer
#1 lore raw

Hi--

Quoted 1 line · Mukesh Ojha

There could be a sceanario where we define some region

scenario

Quoted 33 lines

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.

---
 Documentation/admin-guide/ramoops.rst |  4 +++-
 fs/pstore/ram.c                       |  1 +
 fs/pstore/ram_core.c                  | 10 ++++++++--
 3 files changed, 12 insertions(+), 3 deletions(-)
Documentation/admin-guide/ramoops.rst +1 -1
index b0a1ae7..8f107d8 100644
@@ -3,7 +3,7 @@ Ramoops oops/panic logger
 
 Sergiu Iordache <[email protected]>
 
-Updated: 17 November 2011
+Updated: 10 Feb 2021
 
 Introduction
 ------------

Documentation/admin-guide/ramoops.rst mapping to pgprot_writecombine. Setting ``mem_type=1`` attempts to use · line 33

Quoted 4 lines
Documentation/admin-guide/ramoops.rst +1 -0
@@ -30,6 +30,8 @@ mapping to pgprot_writecombine. Setting ``mem_type=1`` attempts to use
 depends on atomic operations. At least on ARM, pgprot_noncached causes the
 memory to be mapped strongly ordered, and atomic operations on strongly ordered
 memory are implementation defined, and won't work on many ARMs such as omaps.
+Setting ``mem_type=2`` attempts to treat the memory region as normal memory,

Does "mem_type=" work? or does it need to be "mem-type=", as below? I.e., do both of them work?

fs/pstore/ram.c static int ramoops_parse_dt(struct platform_device *pdev, · line 669

Quoted 13 lines
Documentation/admin-guide/ramoops.rst +1 -0
+which enables full cache on it. This can improve the performance.
 
 The memory area is divided into ``record_size`` chunks (also rounded down to
 power of two) and each kmesg dump writes a ``record_size`` chunk of
fs/pstore/ram.c +1 -0
index ca6d8a8..b262c57 100644
@@ -666,6 +666,7 @@ static int ramoops_parse_dt(struct platform_device *pdev,
 		field = value;						\
 	}
 
+	parse_u32("mem-type", pdata->record_size, pdata->mem_type);
              here^^^^^^^^^^

thanks.

Signature · 1 line
~Randy
reviewer
#2 lore raw
Quoted 37 lines · Randy Dunlap

Hi--

Quoted 1 line · Mukesh Ojha

There could be a sceanario where we define some region

scenario

Quoted 30 lines

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.

---
 Documentation/admin-guide/ramoops.rst |  4 +++-
 fs/pstore/ram.c                       |  1 +
 fs/pstore/ram_core.c                  | 10 ++++++++--
 3 files changed, 12 insertions(+), 3 deletions(-)
Documentation/admin-guide/ramoops.rst +1 -1
index b0a1ae7..8f107d8 100644
@@ -3,7 +3,7 @@ Ramoops oops/panic logger
 
 Sergiu Iordache <[email protected]>
 
-Updated: 17 November 2011
+Updated: 10 Feb 2021
 
Quoted 11 lines

Documentation/admin-guide/ramoops.rst mapping to pgprot_writecombine. Setting ``mem_type=1`` attempts to use · line 33

Quoted 7 lines
Documentation/admin-guide/ramoops.rst +1 -0
 Introduction
 ------------
@@ -30,6 +30,8 @@ mapping to pgprot_writecombine. Setting ``mem_type=1`` attempts to use
 depends on atomic operations. At least on ARM, pgprot_noncached causes the
 memory to be mapped strongly ordered, and atomic operations on strongly ordered
 memory are implementation defined, and won't work on many ARMs such as omaps.
+Setting ``mem_type=2`` attempts to treat the memory region as normal memory,

Does "mem_type=" work? or does it need to be "mem-type=", as below? I.e., do both of them work?

Ah yes, as documented:

"Hyphens (dashes) and underscores are equivalent in parameter names,"

thanks.

Quoted 15 lines

fs/pstore/ram.c static int ramoops_parse_dt(struct platform_device *pdev, · line 669

Quoted 13 lines
Documentation/admin-guide/ramoops.rst +1 -0
+which enables full cache on it. This can improve the performance.
 
 The memory area is divided into ``record_size`` chunks (also rounded down to
 power of two) and each kmesg dump writes a ``record_size`` chunk of
fs/pstore/ram.c +1 -0
index ca6d8a8..b262c57 100644
@@ -666,6 +666,7 @@ static int ramoops_parse_dt(struct platform_device *pdev,
 		field = value;						\
 	}
 
+	parse_u32("mem-type", pdata->record_size, pdata->mem_type);
              here^^^^^^^^^^
Signature · 1 line
~Randy
#3 lore raw
In reply to Mukesh Ojha
Quoted 8 lines · Mukesh Ojha

There could be a sceanario 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.

Cool; yeah. I like this idea.

Quoted 3 lines

This commit gives control to change mem_type from Device tree, and also documents the value for normal memory.

What's the safest default setting?

Quoted 36 lines
---
 Documentation/admin-guide/ramoops.rst |  4 +++-
 fs/pstore/ram.c                       |  1 +
 fs/pstore/ram_core.c                  | 10 ++++++++--
 3 files changed, 12 insertions(+), 3 deletions(-)
Documentation/admin-guide/ramoops.rst +3 -1
index b0a1ae7..8f107d8 100644
@@ -3,7 +3,7 @@ Ramoops oops/panic logger
 
 Sergiu Iordache <[email protected]>
 
-Updated: 17 November 2011
+Updated: 10 Feb 2021
 
 Introduction
 ------------
@@ -30,6 +30,8 @@ mapping to pgprot_writecombine. Setting ``mem_type=1`` attempts to use
 depends on atomic operations. At least on ARM, pgprot_noncached causes the
 memory to be mapped strongly ordered, and atomic operations on strongly ordered
 memory are implementation defined, and won't work on many ARMs such as omaps.
+Setting ``mem_type=2`` attempts to treat the memory region as normal memory,
+which enables full cache on it. This can improve the performance.
 
 The memory area is divided into ``record_size`` chunks (also rounded down to
 power of two) and each kmesg dump writes a ``record_size`` chunk of
fs/pstore/ram.c +0 -0
index ca6d8a8..b262c57 100644

fs/pstore/ram.c static int ramoops_parse_dt(struct platform_device *pdev, · line 669

Quoted 4 lines
fs/pstore/ram.c +1 -0
@@ -666,6 +666,7 @@ static int ramoops_parse_dt(struct platform_device *pdev,
 		field = value;						\
 	}
 
+	parse_u32("mem-type", pdata->record_size, pdata->mem_type);

This was handled by "unbuffered" above. Can you find a way to resolve potential conflicts between these?

Quoted 8 lines
fs/pstore/ram.c +0 -0
 	parse_u32("record-size", pdata->record_size, 0);
 	parse_u32("console-size", pdata->console_size, 0);
 	parse_u32("ftrace-size", pdata->ftrace_size, 0);
fs/pstore/ram_core.c +0 -0
index aa8e0b6..83cd612 100644

fs/pstore/ram_core.c void persistent_ram_zap(struct persistent_ram_zone *prz) · line 401

Quoted 6 lines
fs/pstore/ram_core.c +3 -0
@@ -396,6 +396,10 @@ void persistent_ram_zap(struct persistent_ram_zone *prz)
 	persistent_ram_update_header_ecc(prz);
 }
 
+#define MEM_TYPE_WCOMBINE	0
+#define MEM_TYPE_NONCACHED	1
+#define MEM_TYPE_NORMAL		2

It might be nice for this to have a human-readable name too, but let's start with numeric. :)

Please update the mem_type MODULE_PARM_DESC to detail the new values too.

Quoted 6 lines
fs/pstore/ram_core.c +1 -0
+
 static void *persistent_ram_vmap(phys_addr_t start, size_t size,
 		unsigned int memtype)
 {
@@ -409,9 +413,11 @@ static void *persistent_ram_vmap(phys_addr_t start, size_t size,
 	page_start = start - offset_in_page(start);

fs/pstore/ram_core.c static void *persistent_ram_vmap(phys_addr_t start, size_t size, · line 421

Quoted 10 lines
fs/pstore/ram_core.c +4 -2
 	page_count = DIV_ROUND_UP(size + offset_in_page(start), PAGE_SIZE);
 
-	if (memtype)
+	if (memtype == MEM_TYPE_NORMAL)
+		prot = PAGE_KERNEL;
+	else if (memtype == MEM_TYPE_NONCACHED)
 		prot = pgprot_noncached(PAGE_KERNEL);
-	else
+	else if (memtype == MEM_TYPE_WCOMBINE)
 		prot = pgprot_writecombine(PAGE_KERNEL);

Let's make this a switch statement.

Quoted 6 lines
fs/pstore/ram_core.c +0 -1
 	pages = kmalloc_array(page_count, sizeof(struct page *), GFP_KERNEL);
-- 

Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project

Signature · 1 line
Kees Cook
#4 lore raw
Quoted 10 lines · Kees Cook
Quoted 8 lines · Mukesh Ojha

There could be a sceanario 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.

Cool; yeah. I like this idea.

Thanks.

Quoted 4 lines
Quoted 3 lines

This commit gives control to change mem_type from Device tree, and also documents the value for normal memory.

What's the safest default setting?

We could keep it default, like it already exist to have unbuffered or not to have it in Device tree.

and could  use mem-type to cover normal memory(DDR)  as cached one and it will also cover buffered and unbufferd mapping

by mentioning it in device tree as numeric value.

Quoted 39 lines
Quoted 39 lines
---
  Documentation/admin-guide/ramoops.rst |  4 +++-
  fs/pstore/ram.c                       |  1 +
  fs/pstore/ram_core.c                  | 10 ++++++++--
  3 files changed, 12 insertions(+), 3 deletions(-)
Documentation/admin-guide/ramoops.rst +3 -1
index b0a1ae7..8f107d8 100644
@@ -3,7 +3,7 @@ Ramoops oops/panic logger
 
  Sergiu Iordache <[email protected]>
 
-Updated: 17 November 2011
+Updated: 10 Feb 2021
 
  Introduction
  ------------
@@ -30,6 +30,8 @@ mapping to pgprot_writecombine. Setting ``mem_type=1`` attempts to use
  depends on atomic operations. At least on ARM, pgprot_noncached causes the
  memory to be mapped strongly ordered, and atomic operations on strongly ordered
  memory are implementation defined, and won't work on many ARMs such as omaps.
+Setting ``mem_type=2`` attempts to treat the memory region as normal memory,
+which enables full cache on it. This can improve the performance.
 
  The memory area is divided into ``record_size`` chunks (also rounded down to
  power of two) and each kmesg dump writes a ``record_size`` chunk of
fs/pstore/ram.c +0 -0
index ca6d8a8..b262c57 100644
@@ -666,6 +666,7 @@ static int ramoops_parse_dt(struct platform_device *pdev,
  		field = value;						\
  	}
 
Quoted 3 lines

fs/pstore/ram.c static int ramoops_parse_dt(struct platform_device *pdev, · line 669

Quoted 1 line
fs/pstore/ram.c +1 -0
+	parse_u32("mem-type", pdata->record_size, pdata->mem_type);

This was handled by "unbuffered" above. Can you find a way to resolve potential conflicts between these?

Currently there is no conflict code-wise, even after this change, as it overrides if mem-type is there

otherwise everything is intact.

However, if we want to use only  mem-type property then i can remove unbuffered property.

not having unbuffered property i.e default=> mem-type = 0 having unbuffered property => mem-type = 1 mem-type = 2 for cached normal memory

Quoted 12 lines
Quoted 12 lines
fs/pstore/ram.c +0 -0
  	parse_u32("record-size", pdata->record_size, 0);
  	parse_u32("console-size", pdata->console_size, 0);
  	parse_u32("ftrace-size", pdata->ftrace_size, 0);
fs/pstore/ram_core.c +0 -0
index aa8e0b6..83cd612 100644
@@ -396,6 +396,10 @@ void persistent_ram_zap(struct persistent_ram_zone *prz)
  	persistent_ram_update_header_ecc(prz);
  }
 
Quoted 7 lines

fs/pstore/ram_core.c void persistent_ram_zap(struct persistent_ram_zone *prz) · line 401

Quoted 3 lines
fs/pstore/ram_core.c +3 -0
+#define MEM_TYPE_WCOMBINE	0
+#define MEM_TYPE_NONCACHED	1
+#define MEM_TYPE_NORMAL		2

It might be nice for this to have a human-readable name too, but let's start with numeric. :)

Please update the mem_type MODULE_PARM_DESC to detail the new values too.

Ok, will do in next patch.

Quoted 9 lines
Quoted 9 lines
fs/pstore/ram_core.c +1 -0
+
  static void *persistent_ram_vmap(phys_addr_t start, size_t size,
  		unsigned int memtype)
  {
@@ -409,9 +413,11 @@ static void *persistent_ram_vmap(phys_addr_t start, size_t size,
  	page_start = start - offset_in_page(start);
  	page_count = DIV_ROUND_UP(size + offset_in_page(start), PAGE_SIZE);
 
Quoted 9 lines

fs/pstore/ram_core.c static void *persistent_ram_vmap(phys_addr_t start, size_t size, · line 421

Quoted 8 lines
fs/pstore/ram_core.c +4 -2
-	if (memtype)
+	if (memtype == MEM_TYPE_NORMAL)
+		prot = PAGE_KERNEL;
+	else if (memtype == MEM_TYPE_NONCACHED)
  		prot = pgprot_noncached(PAGE_KERNEL);
-	else
+	else if (memtype == MEM_TYPE_WCOMBINE)
  		prot = pgprot_writecombine(PAGE_KERNEL);

Let's make this a switch statement.

Ok, will do in next patch.

Thanks

Mukesh

Quoted 7 lines
Quoted 7 lines
fs/pstore/ram_core.c +0 -1
  	pages = kmalloc_array(page_count, sizeof(struct page *), GFP_KERNEL);
-- 

Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project