Skip to contentSkip to conversation

mtd: phram improvements

PATCH Applied Vincent Whitchurch 4 participants 16 messages Apr 12, 2022 – May 10, 2022

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

v3 cover mtd: phram improvements

v3:
- Fix build error on some configs.
- Reword binding.
- Added note about alternatives in cover letter (see below)

v2:
- Add note on what "phram" means in binding.
- Use /schemas/mtd/mtd.yaml instead of relative pathUse /schemas/mtd/mtd.yaml instead of relative path in binding.

The phram driver in the MTD subsystem can be used to allow the kernel to use an MTD or (via mtdblock) a block device in RAM (with the contents loaded by a bootloader for example). This series has some improvements to make it more usable by adding device tree support and to significantly improve its performance by using cached mappings when possible.

I use this feature to pass the squashfs rootfs to the kernel when booting from RAM. The boot is much faster and requires less memory than initrd (which is on top of that being deprecated), and it allows the same disk images to be used when booting from RAM, unlike initramfs.

If there is no interest in extending the phram driver to support this, an option is to use a new custom block driver. I have patches for that too. That will not support MTDs of course, but it works for block devices and it is faster and smaller than mtdblock + MTD + phram.

Vincent Whitchurch (4):
mtd: core: Check devicetree alias for index
dt-bindings: reserved-memory: Support MTD/block device
mtd: phram: Allow probing via reserved-memory
mtd: phram: Allow cached mappings

 .../bindings/reserved-memory/phram.yaml       | 47 +++++++++++
 drivers/mtd/devices/phram.c                   | 78 +++++++++++++++++--
 drivers/mtd/mtdcore.c                         | 11 ++-
 drivers/of/platform.c                         |  1 +
 4 files changed, 129 insertions(+), 8 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/reserved-memory/phram.yaml
Signature · 1 line
2.34.1
#1 lore raw

PATCH v3 1/4 mtd: core: Check devicetree alias for index

Allow the MTD index to be specified via a devicetree alias, so that the number does not just depend on probe order. This is useful to allow pseudo-devices like phram to be optionally used on systems, without having this affect the numbering of the real hardware MTD devices.

---
 drivers/mtd/mtdcore.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/mtd/mtdcore.c +9 -2
index 7731796024e0..9eb0680db312 100644
@@ -557,9 +557,10 @@ static int mtd_nvmem_add(struct mtd_info *mtd)
 
 int add_mtd_device(struct mtd_info *mtd)
 {
+	struct device_node *np = mtd_get_of_node(mtd);
 	struct mtd_info *master = mtd_get_master(mtd);
 	struct mtd_notifier *not;
-	int i, error;
+	int i, error, ofidx;
 
 	/*
 	 * May occur, for instance, on buggy drivers which call
@@ -598,7 +599,13 @@ int add_mtd_device(struct mtd_info *mtd)
 
 	mutex_lock(&mtd_table_mutex);
 
-	i = idr_alloc(&mtd_idr, mtd, 0, 0, GFP_KERNEL);
+	ofidx = -1;
+	if (np)
+		ofidx = of_alias_get_id(np, "mtd");
+	if (ofidx >= 0)
+		i = idr_alloc(&mtd_idr, mtd, ofidx, ofidx + 1, GFP_KERNEL);
+	else
+		i = idr_alloc(&mtd_idr, mtd, 0, 0, GFP_KERNEL);
 	if (i < 0) {
 		error = i;
 		goto fail_locked;
Signature · 1 line
2.34.1
maintainer Applied
#2 lore raw

Re: [PATCH v3 1/4] mtd: core: Check devicetree alias for index

Quoted 6 lines · Vincent Whitchurch

Allow the MTD index to be specified via a devicetree alias, so that the number does not just depend on probe order. This is useful to allow pseudo-devices like phram to be optionally used on systems, without having this affect the numbering of the real hardware MTD devices.

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next, thanks.

Miquel

#3 lore raw

PATCH v3 2/4 dt-bindings: reserved-memory: Support MTD/block device

In reply to Vincent Whitchurch

Add bindings to allow MTD/block devices to be used in reserved-memory regions using the "phram" (MTD in PHysical RAM) driver.

This allows things like partitioning to be specified via the existing devicetree bindings.

---

Notes:
v3:
- Reword description.

v2:
- Add note on what "phram" means.
- Use /schemas/mtd/mtd.yaml instead of relative pathUse /schemas/mtd/mtd.yaml instead of relative path.

 .../bindings/reserved-memory/phram.yaml       | 47 +++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/reserved-memory/phram.yaml
Documentation/devicetree/bindings/reserved-memory/phram.yaml new file +47 -0
new file mode 100644
index 000000000000..6c4db28015f1
@@ -0,0 +1,47 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/reserved-memory/phram.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: MTD/block device in RAM
+
+description: |
+  Specifies that the reserved memory region can be used as an MTD or block
+  device.
+
+  The "phram" node is named after the "MTD in PHysical RAM" driver which
+  provides an implementation of this functionality in Linux.
+
+maintainers:
+  - Vincent Whitchurch <[email protected]>
+
+allOf:
+  - $ref: "reserved-memory.yaml"
+  - $ref: "/schemas/mtd/mtd.yaml"
+
+properties:
+  compatible:
+    const: phram
+
+  reg:
+    description: region of memory that can be used as an MTD/block device
+
+required:
+  - compatible
+  - reg
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    reserved-memory {
+        #address-cells = <1>;
+        #size-cells = <1>;
+
+        phram: flash@12340000 {
+            compatible = "phram";
+            label = "rootfs";
+            reg = <0x12340000 0x00800000>;
+        };
+    };
Signature · 1 line
2.34.1
maintainer Reviewed-by on v3 2/4
#4 lore raw

Re: [PATCH v3 2/4] dt-bindings: reserved-memory: Support MTD/block device

Quoted 13 lines · Vincent Whitchurch

Add bindings to allow MTD/block devices to be used in reserved-memory regions using the "phram" (MTD in PHysical RAM) driver.

This allows things like partitioning to be specified via the existing devicetree bindings.

---

Notes:
v3:
- Reword description.

Quoted 8 lines

v2:
- Add note on what "phram" means.
- Use /schemas/mtd/mtd.yaml instead of relative pathUse /schemas/mtd/mtd.yaml instead of relative path.

 .../bindings/reserved-memory/phram.yaml       | 47 +++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/reserved-memory/phram.yaml

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

maintainer Applied
#5 lore raw

Re: [PATCH v3 2/4] dt-bindings: reserved-memory: Support MTD/block device

In reply to Vincent Whitchurch
Quoted 8 lines · Vincent Whitchurch

Add bindings to allow MTD/block devices to be used in reserved-memory regions using the "phram" (MTD in PHysical RAM) driver.

This allows things like partitioning to be specified via the existing devicetree bindings.

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next, thanks.

Miquel

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#6 lore raw

PATCH v3 3/4 mtd: phram: Allow probing via reserved-memory

In reply to Vincent Whitchurch

Allow phram to be probed from the devicetree. It expects to be in a reserved-memory node as documented by the bindings. This allows things like partitioning to be specified via the devicetree.

---

Notes:
v3:
- Add missing semicolon after MODULE_DEVICE_TABLE causing build errors on some configs.

 drivers/mtd/devices/phram.c | 67 ++++++++++++++++++++++++++++++++++---
 drivers/of/platform.c       |  1 +
 2 files changed, 64 insertions(+), 4 deletions(-)
drivers/mtd/devices/phram.c +63 -4
index d503821a3e60..506e9edf5c85 100644
@@ -27,6 +27,9 @@
 #include <linux/slab.h>
 #include <linux/mtd/mtd.h>
 #include <asm/div64.h>
+#include <linux/platform_device.h>
+#include <linux/of_address.h>
+#include <linux/of.h>
 
 struct phram_mtd_list {
 	struct mtd_info mtd;
@@ -89,8 +92,10 @@ static void unregister_devices(void)
 	}
 }
 
-static int register_device(char *name, phys_addr_t start, size_t len, uint32_t erasesize)
+static int register_device(struct platform_device *pdev, const char *name,
+			   phys_addr_t start, size_t len, uint32_t erasesize)
 {
+	struct device_node *np = pdev ? pdev->dev.of_node : NULL;
 	struct phram_mtd_list *new;
 	int ret = -ENOMEM;
 
@@ -119,13 +124,19 @@ static int register_device(char *name, phys_addr_t start, size_t len, uint32_t e
 	new->mtd.erasesize = erasesize;
 	new->mtd.writesize = 1;
 
+	mtd_set_of_node(&new->mtd, np);
+
 	ret = -EAGAIN;
 	if (mtd_device_register(&new->mtd, NULL, 0)) {
 		pr_err("Failed to register new device\n");
 		goto out2;
 	}
 
-	list_add_tail(&new->list, &phram_list);
+	if (pdev)
+		platform_set_drvdata(pdev, new);
+	else
+		list_add_tail(&new->list, &phram_list);
+
 	return 0;
 
 out2:
@@ -278,7 +289,7 @@ static int phram_setup(const char *val)
 		goto error;
 	}
 
-	ret = register_device(name, start, len, (uint32_t)erasesize);
+	ret = register_device(NULL, name, start, len, (uint32_t)erasesize);
 	if (ret)
 		goto error;
 
@@ -325,10 +336,54 @@ static int phram_param_call(const char *val, const struct kernel_param *kp)
 module_param_call(phram, phram_param_call, NULL, NULL, 0200);
 MODULE_PARM_DESC(phram, "Memory region to map. \"phram=<name>,<start>,<length>[,<erasesize>]\"");
 
+#ifdef CONFIG_OF
+static const struct of_device_id phram_of_match[] = {
+	{ .compatible = "phram" },
+	{}
+};
+MODULE_DEVICE_TABLE(of, phram_of_match);
+#endif
+
+static int phram_probe(struct platform_device *pdev)
+{
+	struct resource *res;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		return -ENOMEM;
+
+	/* mtd_set_of_node() reads name from "label" */
+	return register_device(pdev, NULL, res->start, resource_size(res),
+			       PAGE_SIZE);
+}
+
+static int phram_remove(struct platform_device *pdev)
+{
+	struct phram_mtd_list *phram = platform_get_drvdata(pdev);
+
+	mtd_device_unregister(&phram->mtd);
+	iounmap(phram->mtd.priv);
+	kfree(phram);
+
+	return 0;
+}
+
+static struct platform_driver phram_driver = {
+	.probe		= phram_probe,
+	.remove		= phram_remove,
+	.driver		= {
+		.name		= "phram",
+		.of_match_table	= of_match_ptr(phram_of_match),
+	},
+};
 
 static int __init init_phram(void)
 {
-	int ret = 0;
+	int ret;
+
+	ret = platform_driver_register(&phram_driver);
+	if (ret)
+		return ret;
 
 #ifndef MODULE
 	if (phram_paramline[0])
@@ -336,12 +391,16 @@ static int __init init_phram(void)
 	phram_init_called = 1;
 #endif
 
+	if (ret)
+		platform_driver_unregister(&phram_driver);
+
 	return ret;
 }
 
 static void __exit cleanup_phram(void)
 {
 	unregister_devices();
+	platform_driver_unregister(&phram_driver);
 }
 
 module_init(init_phram);
drivers/of/platform.c +1 -0
index a16b74f32aa9..55d62b82c650 100644
@@ -509,6 +509,7 @@ EXPORT_SYMBOL_GPL(of_platform_default_populate);
 
 #ifndef CONFIG_PPC
 static const struct of_device_id reserved_mem_matches[] = {
+	{ .compatible = "phram" },
 	{ .compatible = "qcom,rmtfs-mem" },
 	{ .compatible = "qcom,cmd-db" },
 	{ .compatible = "qcom,smem" },
Signature · 1 line
2.34.1
maintainer Acked-by on v3 3/4
#7 lore raw

Re: [PATCH v3 3/4] mtd: phram: Allow probing via reserved-memory

Quoted 7 lines · Vincent Whitchurch

Allow phram to be probed from the devicetree. It expects to be in a reserved-memory node as documented by the bindings. This allows things like partitioning to be specified via the devicetree.

---

Quoted 7 lines

Notes:
v3:
- Add missing semicolon after MODULE_DEVICE_TABLE causing build errors on some configs.

 drivers/mtd/devices/phram.c | 67 ++++++++++++++++++++++++++++++++++---
 drivers/of/platform.c       |  1 +

For DT,

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

maintainer Applied
#8 lore raw

Re: [PATCH v3 3/4] mtd: phram: Allow probing via reserved-memory

In reply to Vincent Whitchurch
Quoted 6 lines · Vincent Whitchurch

Allow phram to be probed from the devicetree. It expects to be in a reserved-memory node as documented by the bindings. This allows things like partitioning to be specified via the devicetree.

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next, thanks.

Miquel

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#9 lore raw

PATCH v3 4/4 mtd: phram: Allow cached mappings

In reply to Vincent Whitchurch

Currently phram always uses ioremap(), but this is unnecessary when normal memory is used. If the reserved-memory node does not specify the no-map property, indicating it should be mapped as system RAM and ioremap() cannot be used on it, use a cached mapping using memremap(MEMREMAP_WB) instead.

On one of my systems this improves read performance by ~70%.

---
 drivers/mtd/devices/phram.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/mtd/devices/phram.c +10 -3
index 506e9edf5c85..89d74a1eff4f 100644
@@ -34,6 +34,7 @@
 struct phram_mtd_list {
 	struct mtd_info mtd;
 	struct list_head list;
+	bool cached;
 };
 
 static LIST_HEAD(phram_list);
@@ -96,6 +97,7 @@ static int register_device(struct platform_device *pdev, const char *name,
 			   phys_addr_t start, size_t len, uint32_t erasesize)
 {
 	struct device_node *np = pdev ? pdev->dev.of_node : NULL;
+	bool cached = np ? !of_property_read_bool(np, "no-map") : false;
 	struct phram_mtd_list *new;
 	int ret = -ENOMEM;
 
@@ -103,8 +105,13 @@ static int register_device(struct platform_device *pdev, const char *name,
 	if (!new)
 		goto out0;
 
+	new->cached = cached;
+
 	ret = -EIO;
-	new->mtd.priv = ioremap(start, len);
+	if (cached)
+		new->mtd.priv = memremap(start, len, MEMREMAP_WB);
+	else
+		new->mtd.priv = ioremap(start, len);
 	if (!new->mtd.priv) {
 		pr_err("ioremap failed\n");
 		goto out1;
@@ -140,7 +147,7 @@ static int register_device(struct platform_device *pdev, const char *name,
 	return 0;
 
 out2:
-	iounmap(new->mtd.priv);
+	cached ? memunmap(new->mtd.priv) : iounmap(new->mtd.priv);
 out1:
 	kfree(new);
 out0:
@@ -362,7 +369,7 @@ static int phram_remove(struct platform_device *pdev)
 	struct phram_mtd_list *phram = platform_get_drvdata(pdev);
 
 	mtd_device_unregister(&phram->mtd);
-	iounmap(phram->mtd.priv);
+	phram->cached ? memunmap(phram->mtd.priv) : iounmap(phram->mtd.priv);
 	kfree(phram);
 
 	return 0;
Signature · 1 line
2.34.1
#10 lore raw

Re: [PATCH v3 4/4] mtd: phram: Allow cached mappings

Thank you for the patch! Yet something to improve:

Hi Vincent,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on mtd/mtd/next]
[also build test ERROR on mtd/mtd/fixes robh/for-next v5.18-rc2 next-20220412] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Vincent-Whitchurch/mtd-phram-improvements/20220412-215547
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next
config: sh-allmodconfig (https://download.01.org/0day-ci/archive/20220413/[email protected]/config)
compiler: sh4-linux-gcc (GCC) 11.2.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/188069fe016214c257926df29c84b97859850720
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Vincent-Whitchurch/mtd-phram-improvements/20220412-215547
git checkout 188069fe016214c257926df29c84b97859850720
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=sh SHELL=/bin/bash drivers/mtd/devices/

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

In file included from include/linux/io.h:13,
from drivers/mtd/devices/phram.c:21:
drivers/mtd/devices/phram.c: In function 'register_device':

>> arch/sh/include/asm/io.h:274:33: error: expected expression before 'do'
     274 | #define iounmap(addr)           do { } while (0)
         |                                 ^~
   drivers/mtd/devices/phram.c:150:44: note: in expansion of macro 'iounmap'
     150 |         cached ? memunmap(new->mtd.priv) : iounmap(new->mtd.priv);
         |                                            ^~~~~~~
   drivers/mtd/devices/phram.c: In function 'phram_remove':
>> arch/sh/include/asm/io.h:274:33: error: expected expression before 'do'
     274 | #define iounmap(addr)           do { } while (0)
         |                                 ^~
   drivers/mtd/devices/phram.c:372:53: note: in expansion of macro 'iounmap'
     372 |         phram->cached ? memunmap(phram->mtd.priv) : iounmap(phram->mtd.priv);
         |                                                     ^~~~~~~

vim +/do +274 arch/sh/include/asm/io.h

d57d64080ddc0f Paul Mundt 2010-01-19 272

13f1fc870dd747 Christoph Hellwig 2020-07-14  273  #else /* CONFIG_MMU */
13f1fc870dd747 Christoph Hellwig 2020-07-14 @274  #define iounmap(addr)		do { } while (0)
13f1fc870dd747 Christoph Hellwig 2020-07-14  275  #define ioremap(offset, size)	((void __iomem *)(unsigned long)(offset))
13f1fc870dd747 Christoph Hellwig 2020-07-14  276  #endif /* CONFIG_MMU */

d627a2ebd1a303 Paul Mundt 2010-01-28 277

Signature · 2 lines
0-DAY CI Kernel Test Service
https://01.org/lkp
#11 lore raw

Re: [PATCH v3 4/4] mtd: phram: Allow cached mappings

Quoted 20 lines · kernel test robot

All errors (new ones prefixed by >>):

In file included from include/linux/io.h:13,
from drivers/mtd/devices/phram.c:21:
drivers/mtd/devices/phram.c: In function 'register_device':

Quoted 1 line
Quoted 1 line

arch/sh/include/asm/io.h:274:33: error: expected expression before 'do'

     274 | #define iounmap(addr)           do { } while (0)
         |                                 ^~
   drivers/mtd/devices/phram.c:150:44: note: in expansion of macro 'iounmap'
     150 |         cached ? memunmap(new->mtd.priv) : iounmap(new->mtd.priv);
         |                                            ^~~~~~~

drivers/mtd/devices/phram.c: In function 'phram_remove':

Quoted 1 line
Quoted 1 line

arch/sh/include/asm/io.h:274:33: error: expected expression before 'do'

     274 | #define iounmap(addr)           do { } while (0)
         |                                 ^~
   drivers/mtd/devices/phram.c:372:53: note: in expansion of macro 'iounmap'
     372 |         phram->cached ? memunmap(phram->mtd.priv) : iounmap(phram->mtd.priv);
         |                                                     ^~~~~~~
Quoted 8 lines

vim +/do +274 arch/sh/include/asm/io.h

d57d64080ddc0f Paul Mundt 2010-01-19 272

13f1fc870dd747 Christoph Hellwig 2020-07-14  273  #else /* CONFIG_MMU */
13f1fc870dd747 Christoph Hellwig 2020-07-14 @274  #define iounmap(addr)		do { } while (0)
13f1fc870dd747 Christoph Hellwig 2020-07-14  275  #define ioremap(offset, size)	((void __iomem *)(unsigned long)(offset))
13f1fc870dd747 Christoph Hellwig 2020-07-14  276  #endif /* CONFIG_MMU */

d627a2ebd1a303 Paul Mundt 2010-01-28 277

Thank you for the report. This patch could certainly be changed to work around this, but ISTM that the right fix is in the SH header file, since the problem could hit in other cases too. I've posted a fix here now:

https://lore.kernel.org/lkml/20220414081257.1487499-1-vincent.whitchurch(a)axis.com/

maintainer
#12 lore raw

Re: [PATCH v3 4/4] mtd: phram: Allow cached mappings

Hi Vincent,

vincent.whitchurch(a)axis.com wrote on Thu, 14 Apr 2022 11:04:02 +0200:

Quoted 30 lines · kernel test robot
Quoted 20 lines

All errors (new ones prefixed by >>):

In file included from include/linux/io.h:13,
from drivers/mtd/devices/phram.c:21:
drivers/mtd/devices/phram.c: In function 'register_device':

Quoted 1 line
Quoted 1 line

arch/sh/include/asm/io.h:274:33: error: expected expression before 'do'

     274 | #define iounmap(addr)           do { } while (0)
         |                                 ^~
   drivers/mtd/devices/phram.c:150:44: note: in expansion of macro 'iounmap'
     150 |         cached ? memunmap(new->mtd.priv) : iounmap(new->mtd.priv);
         |                                            ^~~~~~~

drivers/mtd/devices/phram.c: In function 'phram_remove':

Quoted 1 line
Quoted 1 line

arch/sh/include/asm/io.h:274:33: error: expected expression before 'do'

     274 | #define iounmap(addr)           do { } while (0)
         |                                 ^~
   drivers/mtd/devices/phram.c:372:53: note: in expansion of macro 'iounmap'
     372 |         phram->cached ? memunmap(phram->mtd.priv) : iounmap(phram->mtd.priv);
         |                                                     ^~~~~~~
Quoted 8 lines

vim +/do +274 arch/sh/include/asm/io.h

d57d64080ddc0f Paul Mundt 2010-01-19 272

13f1fc870dd747 Christoph Hellwig 2020-07-14  273  #else /* CONFIG_MMU */
13f1fc870dd747 Christoph Hellwig 2020-07-14 @274  #define iounmap(addr)		do { } while (0)
13f1fc870dd747 Christoph Hellwig 2020-07-14  275  #define ioremap(offset, size)	((void __iomem *)(unsigned long)(offset))
13f1fc870dd747 Christoph Hellwig 2020-07-14  276  #endif /* CONFIG_MMU */

d627a2ebd1a303 Paul Mundt 2010-01-28 277

Quoted 5 lines

Thank you for the report. This patch could certainly be changed to work around this, but ISTM that the right fix is in the SH header file, since the problem could hit in other cases too. I've posted a fix here now:

https://lore.kernel.org/lkml/20220414081257.1487499-1-vincent.whitchurch(a)axis.com/

Looks good to me but I don't want to be the one "carrying" new compile errors so I'll drop the series for now, until you get this patch applied. Please then just resend the series with this thread mentioned and I'll take it back.

Thanks,
Miquèl

maintainer
#13 lore raw

Re: [PATCH v3 4/4] mtd: phram: Allow cached mappings

miquel.raynal(a)bootlin.com wrote on Mon, 25 Apr 2022 10:28:16 +0200:

Quoted 38 lines

Hi Vincent,

vincent.whitchurch(a)axis.com wrote on Thu, 14 Apr 2022 11:04:02 +0200:

Quoted 34 lines · kernel test robot
Quoted 20 lines

All errors (new ones prefixed by >>):

In file included from include/linux/io.h:13,
from drivers/mtd/devices/phram.c:21:
drivers/mtd/devices/phram.c: In function 'register_device':

Quoted 1 line
Quoted 1 line

arch/sh/include/asm/io.h:274:33: error: expected expression before 'do'

     274 | #define iounmap(addr)           do { } while (0)
         |                                 ^~
   drivers/mtd/devices/phram.c:150:44: note: in expansion of macro 'iounmap'
     150 |         cached ? memunmap(new->mtd.priv) : iounmap(new->mtd.priv);
         |                                            ^~~~~~~

drivers/mtd/devices/phram.c: In function 'phram_remove':

Quoted 1 line
Quoted 1 line

arch/sh/include/asm/io.h:274:33: error: expected expression before 'do'

     274 | #define iounmap(addr)           do { } while (0)
         |                                 ^~
   drivers/mtd/devices/phram.c:372:53: note: in expansion of macro 'iounmap'
     372 |         phram->cached ? memunmap(phram->mtd.priv) : iounmap(phram->mtd.priv);
         |                                                     ^~~~~~~
Quoted 8 lines

vim +/do +274 arch/sh/include/asm/io.h

d57d64080ddc0f Paul Mundt 2010-01-19 272

13f1fc870dd747 Christoph Hellwig 2020-07-14  273  #else /* CONFIG_MMU */
13f1fc870dd747 Christoph Hellwig 2020-07-14 @274  #define iounmap(addr)		do { } while (0)
13f1fc870dd747 Christoph Hellwig 2020-07-14  275  #define ioremap(offset, size)	((void __iomem *)(unsigned long)(offset))
13f1fc870dd747 Christoph Hellwig 2020-07-14  276  #endif /* CONFIG_MMU */

d627a2ebd1a303 Paul Mundt 2010-01-28 277

Thank you for the report. This patch could certainly be changed to work around this, but ISTM that the right fix is in the SH header file, since the problem could hit in other cases too. I've posted a fix here now:

Quoted 6 lines
Quoted 1 line

https://lore.kernel.org/lkml/20220414081257.1487499-1-vincent.whitchurch(a)axis.com/

Looks good to me but I don't want to be the one "carrying" new compile errors so I'll drop the series for now, until you get this patch applied. Please then just resend the series with this thread mentioned and I'll take it back.

BTW, I'm only talking about this improvement, patches 1-3 will remain.

#14 lore raw

Re: [PATCH v3 4/4] mtd: phram: Allow cached mappings

Quoted 7 lines · Miquel Raynal

miquel.raynal(a)bootlin.com wrote on Mon, 25 Apr 2022 10:28:16 +0200:

Quoted 4 lines

Looks good to me but I don't want to be the one "carrying" new compile errors so I'll drop the series for now, until you get this patch applied. Please then just resend the series with this thread mentioned and I'll take it back.

BTW, I'm only talking about this improvement, patches 1-3 will remain.

Thank you. I've now refactored this patch and send it out separately as a v4, primarily to avoid the SH build problems (which look like they're going to take a while[0] to get fixed) but also to remove some code duplication.

[0] https://lore.kernel.org/lkml/CAMuHMdW-8HaQip+DT5W2Owq8M8kbYwHsf8_Zd-5rRfSjSjK0=g(a)mail.gmail.com/

maintainer Applied
#15 lore raw

Re: [PATCH v3 4/4] mtd: phram: Allow cached mappings

In reply to Vincent Whitchurch
Quoted 10 lines · Vincent Whitchurch

Currently phram always uses ioremap(), but this is unnecessary when normal memory is used. If the reserved-memory node does not specify the no-map property, indicating it should be mapped as system RAM and ioremap() cannot be used on it, use a cached mapping using memremap(MEMREMAP_WB) instead.

On one of my systems this improves read performance by ~70%.

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next, thanks.

Miquel

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/