Skip to contentSkip to conversation

mtd: nand: Disable subpage writes for drivers without ecc->hwctl

PATCH In review Helmut Schaa 5 participants 23 messages Apr 9, 2014 – Dec 19, 2015

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

PATCH 1/1 mtd: nand: Disable subpage writes for drivers without ecc->hwctl

nand_write_subpage_hwecc causes a crash if the driver did not register ecc->hwctl or ecc->calculate. Fix this by disabling subpage writes if ecc->hwctl or ecc->calculate is not provided by the driver.

This behavior was introduced in commit 837a6ba4f3b6d23026674e6af6b6849a4634fff9 "mtd: nand: subpage write support for hardware based ECC schemes".

This fixes a crash with fsl_elbc_nand and maybe others:

Unable to handle kernel paging request for instruction fetch
Faulting instruction address: 0x00000000
Oops: Kernel access of bad area, sig: 11 [#1]
SMP NR_CPUS=2 P1020 RDB
Modules linked in: ath9k ath9k_common pppoe ppp_async option iptable_nat ath9k_hw ath usb_wwan pppox ppp_generic nf_nat_ipv4 nf_conntrack_ipv4 mac80211 ipt_MASQUERADE cfg80211 xt_time xt_tcpudp xt_state xt_quota xt_policy xt_pkttype xt_owner xt_nat xt_multiport xt_mh
CPU: 1 PID: 2161 Comm: ubiformat Not tainted 3.10.26 #6
task: efbc2700 ti: c7950000 task.ti: c7950000
NIP: 00000000 LR: c01a495c CTR: 00000000
REGS: c7951cb0 TRAP: 0400   Not tainted  (3.10.26)
MSR: 00029000 <CE,EE,ME>  CR: 24002028  XER: 00000000

GPR00: c01a4b6c c7951d60 efbc2700 ef84b000 00000001 00000000 000001ff c7800500
GPR08: 00000000 00000000 efae5e40 c01a4ae4 24002022 10023418 c7951e5c c7800500
GPR16: c017b6a8 00000000 0000003f c053404c 00000000 00000004 00000000 00000003
GPR24: 00000010 00000200 ef84b000 c7800d00 c7800000 c7800500 ef84b1c8 00000000
NIP [00000000] (null)
LR [c01a495c] nand_write_subpage_hwecc+0x74/0x174

Call Trace:

[c7951d60] [c7951d64] 0xc7951d64 (unreliable) [c7951da0] [c01a4b6c] nand_write_page+0x88/0x198 [c7951dd0] [c01a5f7c] nand_do_write_ops+0x2f4/0x39c [c7951e40] [c01a61e0] nand_write+0x58/0x84 [c7951e80] [c019e29c] mtdchar_write+0x1dc/0x28c [c7951ef0] [c00aba84] vfs_write+0xcc/0x1ac [c7951f10] [c00ac04c] SyS_write+0x4c/0x90 [c7951f40] [c000cd84] ret_from_syscall+0x0/0x3c
--- Exception: c01 at 0x48050ed8

     LR = 0x100071b8
 Instruction dump:
 XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
 XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
 ---[ end trace 161d3c65a2a15cb8 ]---

Kernel panic - not syncing: Fatal exception
Cc Gupta, Pekon <[email protected]>
Cc Artem Bityutskiy <[email protected]>
Cc David Woodhouse <[email protected]>

---
I noticed this bug on openwrt with kernel 3.10 but it looks as if this can still happen in more recent kernels.

 drivers/mtd/nand/nand_base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/nand_base.c +1 -1
index 9715a7b..2298289 100644
@@ -3768,7 +3768,7 @@ int nand_scan_tail(struct mtd_info *mtd)
 			ecc->write_oob = nand_write_oob_std;
 		if (!ecc->read_subpage)
 			ecc->read_subpage = nand_read_subpage;
-		if (!ecc->write_subpage)
+		if (!ecc->write_subpage && ecc->hwctl && ecc->calculate)
 			ecc->write_subpage = nand_write_subpage_hwecc;
 
 	case NAND_ECC_HW_SYNDROME:
Signature · 1 line
1.8.4.5
#1 lore raw
Quoted 64 lines

From: Helmut Schaa [mailto:[email protected]]

nand_write_subpage_hwecc causes a crash if the driver did not register ecc->hwctl or ecc->calculate. Fix this by disabling subpage writes if ecc->hwctl or ecc->calculate is not provided by the driver.

This behavior was introduced in commit 837a6ba4f3b6d23026674e6af6b6849a4634fff9 "mtd: nand: subpage write support for hardware based ECC schemes".

This fixes a crash with fsl_elbc_nand and maybe others:

Unable to handle kernel paging request for instruction fetch
Faulting instruction address: 0x00000000
Oops: Kernel access of bad area, sig: 11 [#1]
SMP NR_CPUS=2 P1020 RDB
Modules linked in: ath9k ath9k_common pppoe ppp_async option iptable_nat ath9k_hw ath usb_wwan pppox ppp_generic
nf_nat_ipv4 nf_conntrack_ipv4 mac80211 ipt_MASQUERADE cfg80211 xt_time xt_tcpudp xt_state xt_quota xt_policy xt_pkttype
xt_owner xt_nat xt_multiport xt_mh
CPU: 1 PID: 2161 Comm: ubiformat Not tainted 3.10.26 #6
task: efbc2700 ti: c7950000 task.ti: c7950000
NIP: 00000000 LR: c01a495c CTR: 00000000
REGS: c7951cb0 TRAP: 0400   Not tainted  (3.10.26)
MSR: 00029000 <CE,EE,ME>  CR: 24002028  XER: 00000000

GPR00: c01a4b6c c7951d60 efbc2700 ef84b000 00000001 00000000 000001ff c7800500
GPR08: 00000000 00000000 efae5e40 c01a4ae4 24002022 10023418 c7951e5c c7800500
GPR16: c017b6a8 00000000 0000003f c053404c 00000000 00000004 00000000 00000003
GPR24: 00000010 00000200 ef84b000 c7800d00 c7800000 c7800500 ef84b1c8 00000000
NIP [00000000] (null)
LR [c01a495c] nand_write_subpage_hwecc+0x74/0x174

Call Trace:

[c7951d60] [c7951d64] 0xc7951d64 (unreliable) [c7951da0] [c01a4b6c] nand_write_page+0x88/0x198 [c7951dd0] [c01a5f7c] nand_do_write_ops+0x2f4/0x39c [c7951e40] [c01a61e0] nand_write+0x58/0x84 [c7951e80] [c019e29c] mtdchar_write+0x1dc/0x28c [c7951ef0] [c00aba84] vfs_write+0xcc/0x1ac [c7951f10] [c00ac04c] SyS_write+0x4c/0x90 [c7951f40] [c000cd84] ret_from_syscall+0x0/0x3c --- Exception: c01 at 0x48050ed8

    LR = 0x100071b8
Instruction dump:
XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
---[ end trace 161d3c65a2a15cb8 ]---

Kernel panic - not syncing: Fatal exception
Cc Gupta, Pekon <[email protected]>
Cc Artem Bityutskiy <[email protected]>
Cc David Woodhouse <[email protected]>

---
I noticed this bug on openwrt with kernel 3.10 but it looks as if this can still happen in more recent kernels.

drivers/mtd/nand/nand_base.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/nand_base.c +0 -0
index 9715a7b..2298289 100644

drivers/mtd/nand/nand_base.c int nand_scan_tail(struct mtd_info *mtd) · line 3771

Quoted 5 lines
drivers/mtd/nand/nand_base.c +1 -1
@@ -3768,7 +3768,7 @@ int nand_scan_tail(struct mtd_info *mtd)
 			ecc->write_oob = nand_write_oob_std;
 		if (!ecc->read_subpage)
 			ecc->read_subpage = nand_read_subpage;
-		if (!ecc->write_subpage)
+		if (!ecc->write_subpage && ecc->hwctl && ecc->calculate)

I don't think this is correct because nand_write_subpage_hwecc() is a replaceable function (default generic implementation). So

(1) if chip->ecc.hwctl() and chip->ecc.calculate are not implemented but you still want to use subpage write feature, then you need to provide custom implementation for chip->ecc.write_subpage().
that's same for other interfaces of nand_chip like chip->ecc.write_page().

(2) If you don't want to use subpage write feature then just disable it using

	chip->options |= NAND_NO_SUBPAGE_WRITE;

Can you please tell which NAND controller driver is causing this ? We need to fix that..

with regards, pekon

#2 lore raw
Quoted 14 lines · Pekon

drivers/mtd/nand/nand_base.c int nand_scan_tail(struct mtd_info *mtd) · line 3771

Quoted 10 lines
drivers/mtd/nand/nand_base.c +1 -1
index 9715a7b..2298289 100644
@@ -3768,7 +3768,7 @@ int nand_scan_tail(struct mtd_info *mtd)
                      ecc->write_oob = nand_write_oob_std;
              if (!ecc->read_subpage)
                      ecc->read_subpage = nand_read_subpage;
-              if (!ecc->write_subpage)
+              if (!ecc->write_subpage && ecc->hwctl && ecc->calculate)

I don't think this is correct because nand_write_subpage_hwecc() is a replaceable function (default generic implementation). So

Quoted 4 lines

(1) if chip->ecc.hwctl() and chip->ecc.calculate are not implemented but you still want to use subpage write feature, then you need to provide custom implementation for chip->ecc.write_subpage().
that's same for other interfaces of nand_chip like chip->ecc.write_page().

But these don't cause panics :)

Quoted 5 lines

(2) If you don't want to use subpage write feature then just disable it using

        chip->options |= NAND_NO_SUBPAGE_WRITE;

Can you please tell which NAND controller driver is causing this ? We need to fix that..

This happens with fsl_elbc_nand (while trying to run ubiformat on a mtd dev) but the
crash was caused by the introduction of nand_write_subpage_hwecc. So, in this case I think instead of trying to fix every possible driver we should let the nand core
code handle this issue gracefully. Maybe we could add a WARN_ON_ONCE to notice which drivers require adjustments.

Regards,
Helmut

#3 lore raw
Quoted 2 lines

From: Helmut Schaa [mailto:[email protected]]

Quoted 1 line · Pekon

[...]

Quoted 8 lines
Quoted 5 lines

(1) if chip->ecc.hwctl() and chip->ecc.calculate are not implemented but you still want to use subpage write feature, then you need to provide custom implementation for chip->ecc.write_subpage().
that's same for other interfaces of nand_chip like chip->ecc.write_page().

But these don't cause panics :)

because fsl_elbc_nand.c uses custom implementations of chip->ecc.write_page()

	@@ fsl_elbc_chip_init(...)
		chip->ecc.write_page = fsl_elbc_write_page;

Same needs to be done if subpage write is needed. However, as this is a regression so please check if following patch solves your problem.[1]

Quoted 6 lines
Quoted 5 lines

(2) If you don't want to use subpage write feature then just disable it using

        chip->options |= NAND_NO_SUBPAGE_WRITE;

Can you please tell which NAND controller driver is causing this ? We need to fix that..

Quoted 8 lines

This happens with fsl_elbc_nand (while trying to run ubiformat on a mtd dev) but the
crash was caused by the introduction of nand_write_subpage_hwecc. So, in this case I think instead of trying to fix every possible driver we should let the nand core
code handle this issue gracefully. Maybe we could add a WARN_ON_ONCE to notice which drivers require adjustments.

Yes agree. May be good to keep subpage write disabled by default, as only handful drivers possibly use that.

[1] ## <not compile tested>
------------

Quoted 1 line

From bfd39102ed6aa99b7ac2b8394a2d12b879fbb4b7 Mon Sep 17 00:00:00 2001

From: Pekon Gupta <[email protected]>
Date: Wed, 9 Apr 2014 15:51:25 +0530
Subject: [PATCH] mtd: eLBC NAND: disable subpage write support

As fsl_elbc_nand do not implement NAND ECC interfaces (like chip->ecc.hwctl(), chip->ecc.calculate, and chip->ecc.correct) So it cannot use default implementation of nand_write_subpage_hwecc() as in nand_base.c. Hence disabling subpage write support till a custom implementation for chip->ecc_write_subpage is added.

---
 drivers/mtd/nand/fsl_elbc_nand.c | 1 +
 1 file changed, 1 insertion(+)
drivers/mtd/nand/fsl_elbc_nand.c +1 -0
index ec549cd..a21252c 100644
@@ -755,6 +755,7 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv)
 
        /* set up nand options */
        chip->bbt_options = NAND_BBT_USE_FLASH;
+       chip->options |= NAND_NO_SUBPAGE_WRITE;
 
        chip->controller = &elbc_fcm_ctrl->controller;
        chip->priv = priv;

--
1.8.5.1.163.gd7aced9

----------------
(looping possible maintainers of this driver Huang Shijie and Scott Wood)

with regards, pekon

#4 lore raw
Quoted 9 lines · Pekon
Quoted 2 lines

From: Helmut Schaa [mailto:[email protected]]

Quoted 1 line · Pekon

[...]

Quoted 6 lines
Quoted 5 lines

(1) if chip->ecc.hwctl() and chip->ecc.calculate are not implemented but you still want to use subpage write feature, then you need to provide custom implementation for chip->ecc.write_subpage().
that's same for other interfaces of nand_chip like chip->ecc.write_page().

Quoted 8 lines
Quoted 2 lines

But these don't cause panics :)

because fsl_elbc_nand.c uses custom implementations of chip->ecc.write_page()

        @@ fsl_elbc_chip_init(...)
                chip->ecc.write_page = fsl_elbc_write_page;

Same needs to be done if subpage write is needed. However, as this is a regression so please check if following patch solves your problem.[1]

That was my first approach too, seems to work ok for fsl_elbc_nand but some other drivers might still experience crashes. A quick grep shows that sh_flctl might
be affected as well.

So, I'd still argue that it would make more sense to keep the driver interface behavior sane either by setting NAND_NO_SUBPAGE_WRITE as default or by using some checks as proposed initially.

Thanks,
Helmut

#5 lore raw
In reply to Gupta, Pekon
Quoted 61 lines · Pekon
Quoted 2 lines

From: Helmut Schaa [mailto:[email protected]]

Quoted 1 line · Pekon

[...]

Quoted 8 lines
Quoted 5 lines

(1) if chip->ecc.hwctl() and chip->ecc.calculate are not implemented but you still want to use subpage write feature, then you need to provide custom implementation for chip->ecc.write_subpage().
that's same for other interfaces of nand_chip like chip->ecc.write_page().

But these don't cause panics :)

because fsl_elbc_nand.c uses custom implementations of chip->ecc.write_page()

	@@ fsl_elbc_chip_init(...)
		chip->ecc.write_page = fsl_elbc_write_page;

Same needs to be done if subpage write is needed. However, as this is a regression so please check if following patch solves your problem.[1]

Quoted 6 lines
Quoted 5 lines

(2) If you don't want to use subpage write feature then just disable it using

        chip->options |= NAND_NO_SUBPAGE_WRITE;

Can you please tell which NAND controller driver is causing this ? We need to fix that..

Quoted 8 lines

This happens with fsl_elbc_nand (while trying to run ubiformat on a mtd dev) but the
crash was caused by the introduction of nand_write_subpage_hwecc. So, in this case I think instead of trying to fix every possible driver we should let the nand core
code handle this issue gracefully. Maybe we could add a WARN_ON_ONCE to notice which drivers require adjustments.

Yes agree. May be good to keep subpage write disabled by default, as only handful drivers possibly use that.

[1] ## <not compile tested>
------------
From bfd39102ed6aa99b7ac2b8394a2d12b879fbb4b7 Mon Sep 17 00:00:00 2001
From: Pekon Gupta <[email protected]>
Date: Wed, 9 Apr 2014 15:51:25 +0530
Subject: [PATCH] mtd: eLBC NAND: disable subpage write support

As fsl_elbc_nand do not implement NAND ECC interfaces (like chip->ecc.hwctl(), chip->ecc.calculate, and chip->ecc.correct) So it cannot use default implementation of nand_write_subpage_hwecc() as in nand_base.c. Hence disabling subpage write support till a custom implementation for chip->ecc_write_subpage is added.

---
 drivers/mtd/nand/fsl_elbc_nand.c | 1 +
 1 file changed, 1 insertion(+)
drivers/mtd/nand/fsl_elbc_nand.c +0 -0
index ec549cd..a21252c 100644

drivers/mtd/nand/fsl_elbc_nand.c static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv) · line 758

Quoted 4 lines
drivers/mtd/nand/fsl_elbc_nand.c +1 -0
@@ -755,6 +755,7 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv)
 
        /* set up nand options */
        chip->bbt_options = NAND_BBT_USE_FLASH;
+       chip->options |= NAND_NO_SUBPAGE_WRITE;

Won't this break compatibility with existing UBI volumes? That's why I didn't set this flag on eLBC when I set it on IFC (on the latter UBI is simply broken without that flag, but eLBC gets away with it because of the ECC algorithm used).

-Scott

#6 lore raw
Quoted 64 lines

From: Scott Wood [mailto:[email protected]]

Quoted 63 lines · Pekon
Quoted 2 lines

From: Helmut Schaa [mailto:[email protected]]

Quoted 1 line · Pekon

[...]

Quoted 8 lines
Quoted 5 lines

(1) if chip->ecc.hwctl() and chip->ecc.calculate are not implemented but you still want to use subpage write feature, then you need to provide custom implementation for chip->ecc.write_subpage().
that's same for other interfaces of nand_chip like chip->ecc.write_page().

But these don't cause panics :)

because fsl_elbc_nand.c uses custom implementations of chip->ecc.write_page()

	@@ fsl_elbc_chip_init(...)
		chip->ecc.write_page = fsl_elbc_write_page;

Same needs to be done if subpage write is needed. However, as this is a regression so please check if following patch solves your problem.[1]

Quoted 6 lines
Quoted 5 lines

(2) If you don't want to use subpage write feature then just disable it using

        chip->options |= NAND_NO_SUBPAGE_WRITE;

Can you please tell which NAND controller driver is causing this ? We need to fix that..

Quoted 8 lines

This happens with fsl_elbc_nand (while trying to run ubiformat on a mtd dev) but the
crash was caused by the introduction of nand_write_subpage_hwecc. So, in this case I think instead of trying to fix every possible driver we should let the nand core
code handle this issue gracefully. Maybe we could add a WARN_ON_ONCE to notice which drivers require adjustments.

Yes agree. May be good to keep subpage write disabled by default, as only handful drivers possibly use that.

[1] ## <not compile tested>
------------
From bfd39102ed6aa99b7ac2b8394a2d12b879fbb4b7 Mon Sep 17 00:00:00 2001
From: Pekon Gupta <[email protected]>
Date: Wed, 9 Apr 2014 15:51:25 +0530
Subject: [PATCH] mtd: eLBC NAND: disable subpage write support

As fsl_elbc_nand do not implement NAND ECC interfaces (like chip->ecc.hwctl(), chip->ecc.calculate, and chip->ecc.correct) So it cannot use default implementation of nand_write_subpage_hwecc() as in nand_base.c. Hence disabling subpage write support till a custom implementation for chip->ecc_write_subpage is added.

---
 drivers/mtd/nand/fsl_elbc_nand.c | 1 +
 1 file changed, 1 insertion(+)
drivers/mtd/nand/fsl_elbc_nand.c +0 -0
index ec549cd..a21252c 100644
@@ -755,6 +755,7 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv)
 
Quoted 8 lines

drivers/mtd/nand/fsl_elbc_nand.c static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv) · line 758

Quoted 3 lines
drivers/mtd/nand/fsl_elbc_nand.c +1 -0
        /* set up nand options */
        chip->bbt_options = NAND_BBT_USE_FLASH;
+       chip->options |= NAND_NO_SUBPAGE_WRITE;

Won't this break compatibility with existing UBI volumes?
That's why I didn't set this flag on eLBC when I set it on IFC (on the latter UBI is simply broken without that flag, but eLBC gets away with it because of the ECC algorithm used).

Are you sure subpage write is supported on this driver ? I couldn't find any custom implementation for chip->ecc.write_subpage() in fsl_elbc_nand.c.

And when fsl_elbc_nand.c uses default implementation of chip->ecc.write_subpage() = nand_write_subpage_hwecc then it crashes because it does not implement chip->ecc.hwctl(). (refer [1])

However above is just a fix for this regression, as it needs to be back ported till kernel 3.10.x+. I'll send another patch to 'disable' subpage write support by default for drivers, and only the ones which need it should explicitly enable it.

[1] http://lists.infradead.org/pipermail/linux-mtd/2014-April/053182.html

with regards, pekon

#8 lore raw
In reply to Scott Wood
Quoted 77 lines · Scott Wood
Quoted 5 lines · Pekon
Quoted 2 lines

From: Helmut Schaa [mailto:[email protected]]

Quoted 1 line · Pekon

[...]

Quoted 2 lines
Quoted 2 lines

(1) if chip->ecc.hwctl() and chip->ecc.calculate are not

implemented but you

Quoted 1 line
Quoted 1 line
Quoted 1 line

still want to use subpage write feature, then you need to provide

custom

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

implementation for chip->ecc.write_subpage(). that's same for other interfaces of nand_chip like

chip->ecc.write_page().

Quoted 4 lines
Quoted 3 lines

But these don't cause panics :)

because fsl_elbc_nand.c uses custom implementations of

chip->ecc.write_page()

Quoted 5 lines
	@@ fsl_elbc_chip_init(...)
		chip->ecc.write_page = fsl_elbc_write_page;

Same needs to be done if subpage write is needed. However, as this is a regression so please check if following patch solves your

problem.[1]

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

(2) If you don't want to use subpage write feature then just

disable it using

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
        chip->options |= NAND_NO_SUBPAGE_WRITE;

Can you please tell which NAND controller driver is causing this ? We need to fix that..

This happens with fsl_elbc_nand (while trying to run ubiformat on a mtd dev) but the
crash was caused by the introduction of nand_write_subpage_hwecc.

So, in this

Quoted 1 line
Quoted 1 line

case I think instead of trying to fix every possible driver we

should

Quoted 2 lines
Quoted 2 lines

let the nand core
code handle this issue gracefully. Maybe we could add a WARN_ON_ONCE

to

Quoted 9 lines
Quoted 2 lines

notice which drivers require adjustments.

Yes agree. May be good to keep subpage write disabled by default, as only handful drivers possibly use that.

[1] ## <not compile tested>
------------
From bfd39102ed6aa99b7ac2b8394a2d12b879fbb4b7 Mon Sep 17 00:00:00

2001

Quoted 5 lines

From: Pekon Gupta <[email protected]>
Date: Wed, 9 Apr 2014 15:51:25 +0530
Subject: [PATCH] mtd: eLBC NAND: disable subpage write support

As fsl_elbc_nand do not implement NAND ECC interfaces (like

chip->ecc.hwctl(),

Quoted 3 lines

chip->ecc.calculate, and chip->ecc.correct) So it cannot use default implementation of nand_write_subpage_hwecc() as in nand_base.c. Hence disabling subpage write support till a custom implementation

for

Review

Quoted 9 lines

chip->ecc_write_subpage is added.

---
 drivers/mtd/nand/fsl_elbc_nand.c | 1 +
 1 file changed, 1 insertion(+)
(quoted diff) +0 -0

b/drivers/mtd/nand/fsl_elbc_nand.c

drivers/mtd/nand/fsl_elbc_nand.c static int fsl_elbc_chip_init(struct fsl_elbc_mtd

Quoted 4 lines

index ec549cd..a21252c 100644

drivers/mtd/nand/fsl_elbc_nand.c +0 -0
@@ -755,6 +755,7 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd

*priv)

Quoted 1 line
Quoted 8 lines
Quoted 3 lines
        /* set up nand options */
        chip->bbt_options = NAND_BBT_USE_FLASH;

+ chip->options |= NAND_NO_SUBPAGE_WRITE;

Won't this break compatibility with existing UBI volumes? That's why I didn't set this flag on eLBC when I set it on IFC (on the latter UBI is simply broken without that flag, but eLBC gets away with it because of the ECC algorithm used).

Could be. I had to override the VID header offset accordingly to be able to attach to the ubi volume after applying this patch ...

Helmut

#9 lore raw

Hi Helmut Schaa,

Quoted 2 lines

From: Helmut Schaa [mailto:[email protected]]

Quoted 1 line

Scott Wood <[email protected]> schrieb:

[...]

Quoted 30 lines
Quoted 30 lines
Quoted 5 lines

From: Pekon Gupta <[email protected]>
Date: Wed, 9 Apr 2014 15:51:25 +0530
Subject: [PATCH] mtd: eLBC NAND: disable subpage write support

As fsl_elbc_nand do not implement NAND ECC interfaces (like

chip->ecc.hwctl(),

Quoted 3 lines

chip->ecc.calculate, and chip->ecc.correct) So it cannot use default implementation of nand_write_subpage_hwecc() as in nand_base.c. Hence disabling subpage write support till a custom implementation

for

Review

Quoted 9 lines

chip->ecc_write_subpage is added.

---
 drivers/mtd/nand/fsl_elbc_nand.c | 1 +
 1 file changed, 1 insertion(+)
(quoted diff) +0 -0

b/drivers/mtd/nand/fsl_elbc_nand.c

drivers/mtd/nand/fsl_elbc_nand.c static int fsl_elbc_chip_init(struct fsl_elbc_mtd

Quoted 4 lines

index ec549cd..a21252c 100644

drivers/mtd/nand/fsl_elbc_nand.c +0 -0
@@ -755,6 +755,7 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd

*priv)

Quoted 4 lines
drivers/mtd/nand/fsl_elbc_nand.c +1 -0
        /* set up nand options */
        chip->bbt_options = NAND_BBT_USE_FLASH;
+       chip->options |= NAND_NO_SUBPAGE_WRITE;
Quoted 7 lines
Quoted 4 lines

Won't this break compatibility with existing UBI volumes? That's why I didn't set this flag on eLBC when I set it on IFC (on the latter UBI is simply broken without that flag, but eLBC gets away with it because of the ECC algorithm used).

Could be. I had to override the VID header offset accordingly to be able to attach to the ubi volume after applying this patch ...

There could be some misconfiguration in the way you generate your UBIFS image. Just check following:
(1) min-io-size (-m) passed to mkfs.ubifs and ubinize commands?
(2) vid-hdr-offset (-O) passed to ubinize and ubiattach commands?
(3) subpage-size (-s) passed to ubinize commands? [optional] All of the above should be set to $PAGE_SIZE of your NAND device.

Because if your image itself was generated such a way that vid-hdr was offset at page-boundaries then you shouldn't have needed this change.
---------------------------
nand_base.c @@ nand_write_page(..)

	if (!(chip->options & NAND_NO_SUBPAGE_WRITE) &&
		chip->ecc.write_subpage)
		subpage = offset || (data_len < mtd->writesize);   <<-----
	else
		subpage = 0;
	[...]
	else if (subpage)  <<--------
		status = chip->ecc.write_subpage(mtd, chip, offset, data_len,
							 buf, oob_required);

---------------------------
So, even if the subpage-write is enabled, but all the write accesses are page-aligned, (that is offset==0 && data_len % mtd->writesize ==0) then also chip->ecc.write_subpage() does _not_ come in path.

with regards, pekon

#10 lore raw
Quoted 62 lines · Pekon

Hi Helmut Schaa,

Quoted 2 lines

From: Helmut Schaa [mailto:[email protected]]

Quoted 1 line

Scott Wood <[email protected]> schrieb:

[...]

Quoted 30 lines
Quoted 30 lines
Quoted 5 lines

From: Pekon Gupta <[email protected]>
Date: Wed, 9 Apr 2014 15:51:25 +0530
Subject: [PATCH] mtd: eLBC NAND: disable subpage write support

As fsl_elbc_nand do not implement NAND ECC interfaces (like

chip->ecc.hwctl(),

Quoted 3 lines

chip->ecc.calculate, and chip->ecc.correct) So it cannot use default implementation of nand_write_subpage_hwecc() as in nand_base.c. Hence disabling subpage write support till a custom implementation

for

Review

Quoted 9 lines

chip->ecc_write_subpage is added.

---
 drivers/mtd/nand/fsl_elbc_nand.c | 1 +
 1 file changed, 1 insertion(+)
(quoted diff) +0 -0

b/drivers/mtd/nand/fsl_elbc_nand.c

drivers/mtd/nand/fsl_elbc_nand.c static int fsl_elbc_chip_init(struct fsl_elbc_mtd

Quoted 4 lines

index ec549cd..a21252c 100644

drivers/mtd/nand/fsl_elbc_nand.c +0 -0
@@ -755,6 +755,7 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd

*priv)

Quoted 4 lines
drivers/mtd/nand/fsl_elbc_nand.c +1 -0
        /* set up nand options */
        chip->bbt_options = NAND_BBT_USE_FLASH;
+       chip->options |= NAND_NO_SUBPAGE_WRITE;
Quoted 7 lines
Quoted 4 lines

Won't this break compatibility with existing UBI volumes? That's why I didn't set this flag on eLBC when I set it on IFC (on the latter UBI is simply broken without that flag, but eLBC gets away with it because of the ECC algorithm used).

Could be. I had to override the VID header offset accordingly to be able to attach to the ubi volume after applying this patch ...

There could be some misconfiguration in the way you generate your UBIFS image. Just check following:
(1) min-io-size (-m) passed to mkfs.ubifs and ubinize commands?
(2) vid-hdr-offset (-O) passed to ubinize and ubiattach commands?
(3) subpage-size (-s) passed to ubinize commands? [optional] All of the above should be set to $PAGE_SIZE of your NAND device.

Because if your image itself was generated such a way that vid-hdr was offset at page-boundaries then you shouldn't have needed this change.
---------------------------
nand_base.c @@ nand_write_page(..)

        if (!(chip->options & NAND_NO_SUBPAGE_WRITE) &&
                chip->ecc.write_subpage)
                subpage = offset || (data_len < mtd->writesize);   <<-----
        else
                subpage = 0;
        [...]
        else if (subpage)  <<--------
                status = chip->ecc.write_subpage(mtd, chip, offset, data_len,
                                                         buf, oob_required);
Quoted 4 lines

---------------------------
So, even if the subpage-write is enabled, but all the write accesses are page-aligned, (that is offset==0 && data_len % mtd->writesize ==0) then also chip->ecc.write_subpage() does _not_ come in path.

Reverting "mtd: nand: subpage write support for hardware based ECC schemes" and then
using ubiformat (without additional options) to create a volume results in a VID header offset
of 512. And it was possible to attach to this volume successfully. Setting NAND_NO_SUBPAGE_WRITE prevents this ubi volume to be attached without explicitly
setting the VID header offset. This indicates that with this patch some setups might break.

I don't necessarily want to get my patch in but IMO this is not a regression in fsl_elbc_nand but in nand_base (also possibly affecting other drivers).

Helmut

#7 lore raw
In reply to Gupta, Pekon
Quoted 73 lines · Pekon
Quoted 64 lines

From: Scott Wood [mailto:[email protected]]

Quoted 63 lines · Pekon
Quoted 2 lines

From: Helmut Schaa [mailto:[email protected]]

Quoted 1 line · Pekon

[...]

Quoted 8 lines
Quoted 5 lines

(1) if chip->ecc.hwctl() and chip->ecc.calculate are not implemented but you still want to use subpage write feature, then you need to provide custom implementation for chip->ecc.write_subpage().
that's same for other interfaces of nand_chip like chip->ecc.write_page().

But these don't cause panics :)

because fsl_elbc_nand.c uses custom implementations of chip->ecc.write_page()

	@@ fsl_elbc_chip_init(...)
		chip->ecc.write_page = fsl_elbc_write_page;

Same needs to be done if subpage write is needed. However, as this is a regression so please check if following patch solves your problem.[1]

Quoted 6 lines
Quoted 5 lines

(2) If you don't want to use subpage write feature then just disable it using

        chip->options |= NAND_NO_SUBPAGE_WRITE;

Can you please tell which NAND controller driver is causing this ? We need to fix that..

Quoted 8 lines

This happens with fsl_elbc_nand (while trying to run ubiformat on a mtd dev) but the
crash was caused by the introduction of nand_write_subpage_hwecc. So, in this case I think instead of trying to fix every possible driver we should let the nand core
code handle this issue gracefully. Maybe we could add a WARN_ON_ONCE to notice which drivers require adjustments.

Yes agree. May be good to keep subpage write disabled by default, as only handful drivers possibly use that.

[1] ## <not compile tested>
------------
From bfd39102ed6aa99b7ac2b8394a2d12b879fbb4b7 Mon Sep 17 00:00:00 2001
From: Pekon Gupta <[email protected]>
Date: Wed, 9 Apr 2014 15:51:25 +0530
Subject: [PATCH] mtd: eLBC NAND: disable subpage write support

As fsl_elbc_nand do not implement NAND ECC interfaces (like chip->ecc.hwctl(), chip->ecc.calculate, and chip->ecc.correct) So it cannot use default implementation of nand_write_subpage_hwecc() as in nand_base.c. Hence disabling subpage write support till a custom implementation for chip->ecc_write_subpage is added.

---
 drivers/mtd/nand/fsl_elbc_nand.c | 1 +
 1 file changed, 1 insertion(+)
drivers/mtd/nand/fsl_elbc_nand.c +0 -0
index ec549cd..a21252c 100644
@@ -755,6 +755,7 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv)
 
Quoted 8 lines

drivers/mtd/nand/fsl_elbc_nand.c static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv) · line 758

Quoted 3 lines
drivers/mtd/nand/fsl_elbc_nand.c +1 -0
        /* set up nand options */
        chip->bbt_options = NAND_BBT_USE_FLASH;
+       chip->options |= NAND_NO_SUBPAGE_WRITE;

Won't this break compatibility with existing UBI volumes?
That's why I didn't set this flag on eLBC when I set it on IFC (on the latter UBI is simply broken without that flag, but eLBC gets away with it because of the ECC algorithm used).

Quoted 2 lines

Are you sure subpage write is supported on this driver ? I couldn't find any custom implementation for chip->ecc.write_subpage() in fsl_elbc_nand.c.

I'm referring to UBI volumes created before chip->ecc.write_subpage() existed.

-Scott

#11 lore raw
In reply to Helmut Schaa

Hi Schaa, Scott,

Quoted 67 lines

From: Helmut Schaa [mailto:[email protected]]

Quoted 61 lines · Pekon
Quoted 2 lines

From: Helmut Schaa [mailto:[email protected]]

Quoted 1 line

Scott Wood <[email protected]> schrieb:

[...]

Quoted 30 lines
Quoted 30 lines
Quoted 5 lines

From: Pekon Gupta <[email protected]>
Date: Wed, 9 Apr 2014 15:51:25 +0530
Subject: [PATCH] mtd: eLBC NAND: disable subpage write support

As fsl_elbc_nand do not implement NAND ECC interfaces (like

chip->ecc.hwctl(),

Quoted 3 lines

chip->ecc.calculate, and chip->ecc.correct) So it cannot use default implementation of nand_write_subpage_hwecc() as in nand_base.c. Hence disabling subpage write support till a custom implementation

for

Review

Quoted 9 lines

chip->ecc_write_subpage is added.

---
 drivers/mtd/nand/fsl_elbc_nand.c | 1 +
 1 file changed, 1 insertion(+)
(quoted diff) +0 -0

b/drivers/mtd/nand/fsl_elbc_nand.c

drivers/mtd/nand/fsl_elbc_nand.c static int fsl_elbc_chip_init(struct fsl_elbc_mtd

Quoted 4 lines

index ec549cd..a21252c 100644

drivers/mtd/nand/fsl_elbc_nand.c +0 -0
@@ -755,6 +755,7 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd

*priv)

Quoted 4 lines
drivers/mtd/nand/fsl_elbc_nand.c +1 -0
        /* set up nand options */
        chip->bbt_options = NAND_BBT_USE_FLASH;
+       chip->options |= NAND_NO_SUBPAGE_WRITE;
Quoted 7 lines
Quoted 4 lines

Won't this break compatibility with existing UBI volumes? That's why I didn't set this flag on eLBC when I set it on IFC (on the latter UBI is simply broken without that flag, but eLBC gets away with it because of the ECC algorithm used).

Could be. I had to override the VID header offset accordingly to be able to attach to the ubi volume after applying this patch ...

There could be some misconfiguration in the way you generate your UBIFS image. Just check following:
(1) min-io-size (-m) passed to mkfs.ubifs and ubinize commands?
(2) vid-hdr-offset (-O) passed to ubinize and ubiattach commands?
(3) subpage-size (-s) passed to ubinize commands? [optional] All of the above should be set to $PAGE_SIZE of your NAND device.

Because if your image itself was generated such a way that vid-hdr was offset at page-boundaries then you shouldn't have needed this change.
---------------------------
nand_base.c @@ nand_write_page(..)

        if (!(chip->options & NAND_NO_SUBPAGE_WRITE) &&
                chip->ecc.write_subpage)
                subpage = offset || (data_len < mtd->writesize);   <<-----
        else
                subpage = 0;
        [...]
        else if (subpage)  <<--------
                status = chip->ecc.write_subpage(mtd, chip, offset, data_len,
                                                         buf, oob_required);
Quoted 4 lines

---------------------------
So, even if the subpage-write is enabled, but all the write accesses are page-aligned, (that is offset==0 && data_len % mtd->writesize ==0) then also chip->ecc.write_subpage() does _not_ come in path.

Quoted 10 lines

Reverting "mtd: nand: subpage write support for hardware based ECC schemes" and then
using ubiformat (without additional options) to create a volume results in a VID header offset
of 512. And it was possible to attach to this volume successfully. Setting NAND_NO_SUBPAGE_WRITE prevents this ubi volume to be attached without explicitly
setting the VID header offset. This indicates that with this patch some setups might break.

As per [1] and [2], If the subpage is _not_ supported then VID-header offset should be aligned to PAGE_SIZE boundary. And it has implications on LEB size calculation too. I don't know how it was working earlier but if the earlier UBI images were using 512 as VID Header offset even without subpage Support then it's incorrect configuration.
Now whether we still want backward compatibility for something which was incorrect, is something I leave it for Maintainers {Artem, Brian} to decide.

Quoted 4 lines

I don't necessarily want to get my patch in but IMO this is not a regression in fsl_elbc_nand but in nand_base (also possibly affecting other drivers).

Helmut

Yes, it's not about the patch, but to fix the root issue for all the drivers. Hopefully you are observations are on latest mtd-utils, as older versions of the tool might have some bug-fixes.

[1] http://www.linux-mtd.infradead.org/doc/ubi.html#L_min_io_unit
[2] http://www.linux-mtd.infradead.org/doc/ubi.html#L_subpage

with regards, pekon

#12 lore raw
Quoted 5 lines · Pekon

As per [1] and [2], If the subpage is _not_ supported then VID-header offset should be aligned to PAGE_SIZE boundary. And it has implications on LEB size calculation too. I don't know how it was working earlier but if the earlier UBI images were using 512 as VID Header offset even without subpage Support then it's incorrect configuration.

I believe what was happening before was full page writes with only subpage content (the rest left at 0xff).

Quoted 2 lines

Now whether we still want backward compatibility for something which was incorrect, is something I leave it for Maintainers {Artem, Brian} to decide.

Why is it incorrect? Subpage writes were happening -- if they weren't, then we wouldn't have seen problems on IFC without that flag.

-Scott

#13 lore raw
Quoted 11 lines

From: Scott Wood [mailto:[email protected]]

Quoted 6 lines · Pekon

As per [1] and [2], If the subpage is _not_ supported then VID-header offset should be aligned to PAGE_SIZE boundary. And it has implications on LEB size calculation too. I don't know how it was working earlier but if the earlier UBI images were using 512 as VID Header offset even without subpage Support then it's incorrect configuration.

I believe what was happening before was full page writes with only subpage content (the rest left at 0xff).

Yes, that is possible, sorry I missed that nand_do_write_ops() does 0xff padding for non-page aligned writes. In that case replicating fsl_elbc_write_page() for chip->ecc.write_subpage should also work and maintain backward compatibility.

(not compile tested)
------------------------------------

drivers/mtd/nand/fsl_elbc_nand.c +14 -0
index a21252c..cc79ce4 100644
@@ -723,6 +723,19 @@ static int fsl_elbc_write_page(struct mtd_info *mtd, struct nand_chip *chip,
        return 0;
 }
 
+/* ECC will be calculated automatically, and errors will be detected in
+ * waitfunc.
+ */
+static int fsl_elbc_write_subpage(struct mtd_info *mtd, struct nand_chip *chip,
+                               uint32_t offset, uint32_t data_len,
+                               const uint8_t *buf, int oob_required)
+{
+       fsl_elbc_write_buf(mtd, buf, mtd->writesize);
+       fsl_elbc_write_buf(mtd, chip->oob_poi, mtd->oobsize);
+
+       return 0;
+}
+
 static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv)
 {
        struct fsl_lbc_ctrl *ctrl = priv->ctrl;
@@ -762,6 +775,7 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv)
 
        chip->ecc.read_page = fsl_elbc_read_page;
        chip->ecc.write_page = fsl_elbc_write_page;
+       chip->ecc.write_subpage = fsl_elbc_write_subpage;
 
        /* If CS Base Register selects full hardware ECC then use it */
        if ((in_be32(&lbc->bank[priv->bank].br) & BR_DECC) ==

------------------------------------

with regards, pekon

#14 lore raw
Quoted 14 lines · Pekon
Quoted 3 lines

From: Scott Wood [mailto:[email protected]]

Quoted 2 lines · Pekon

As per [1] and [2], If the subpage is _not_ supported then

VID-header offset

Quoted 1 line
Quoted 1 line

should be aligned to PAGE_SIZE boundary. And it has implications on

LEB size

Quoted 1 line
Quoted 1 line

calculation too. I don't know how it was working earlier but if the

earlier

Quoted 6 lines
Quoted 2 lines

UBI images were using 512 as VID Header offset even without subpage Support then it's incorrect configuration.

I believe what was happening before was full page writes with only subpage content (the rest left at 0xff).

Quoted 8 lines

Yes, that is possible, sorry I missed that nand_do_write_ops() does 0xff padding
for non-page aligned writes. In that case replicating fsl_elbc_write_page() for
chip->ecc.write_subpage should also work and maintain backward compatibility.

(not compile tested)

JFI, I'm in vacation till next week and don't have access to the affected system. Will do a test once I'm back. Helmut

Quoted 42 lines

------------------------------------

drivers/mtd/nand/fsl_elbc_nand.c +1 -0
index a21252c..cc79ce4 100644
@@ -723,6 +723,19 @@ static int fsl_elbc_write_page(struct mtd_info
 *mtd, struct nand_chip *chip,
       return 0;
 }
 
+/* ECC will be calculated automatically, and errors will be detected

in
+ * waitfunc.
+ */
+static int fsl_elbc_write_subpage(struct mtd_info *mtd, struct nand_chip *chip,

drivers/mtd/nand/fsl_elbc_nand.c +9 -0
+                               uint32_t offset, uint32_t data_len,
+                               const uint8_t *buf, int oob_required)
+{
+       fsl_elbc_write_buf(mtd, buf, mtd->writesize);
+       fsl_elbc_write_buf(mtd, chip->oob_poi, mtd->oobsize);
+
+       return 0;
+}
+

static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv)

{
       struct fsl_lbc_ctrl *ctrl = priv->ctrl;
drivers/mtd/nand/fsl_elbc_nand.c +1 -0
@@ -762,6 +775,7 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd
 *priv)
 
       chip->ecc.read_page = fsl_elbc_read_page;
       chip->ecc.write_page = fsl_elbc_write_page;
+       chip->ecc.write_subpage = fsl_elbc_write_subpage;
 
       /* If CS Base Register selects full hardware ECC then use it */
       if ((in_be32(&lbc->bank[priv->bank].br) & BR_DECC) ==

------------------------------------

with regards, pekon

Signature · 1 line
Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.
#15 lore raw

Hi,

Quoted 26 lines

From: Helmut Schaa [mailto:[email protected]]

Quoted 7 lines

On 14. April 2014 07:55:30 MESZ, "Gupta, Pekon" <[email protected]>

Quoted 4 lines

From: Scott Wood [mailto:[email protected]]

Quoted 3 lines · Pekon

As per [1] and [2], If the subpage is _not_ supported then

VID-header offset

Quoted 1 line
Quoted 1 line

should be aligned to PAGE_SIZE boundary. And it has

implications on

Quoted 4 lines

LEB size

Quoted 1 line
Quoted 1 line

calculation too. I don't know how it was working earlier but if the

earlier

Quoted 1 line
Quoted 1 line

UBI images were using 512 as VID Header offset even without

subpage

Quoted 12 lines
Quoted 5 lines
Quoted 1 line

Support then it's incorrect configuration.

I believe what was happening before was full page writes with only subpage content (the rest left at 0xff).

Yes, that is possible, sorry I missed that nand_do_write_ops() does 0xff padding
for non-page aligned writes. In that case replicating fsl_elbc_write_page() for
chip->ecc.write_subpage should also work and maintain backward compatibility.

Quoted 6 lines
Quoted 1 line

(not compile tested)

JFI, I'm in vacation till next week and don't have access to the affected system. Will do a test once I'm back.
Helmut

Any update on below patch? Does this maintain compatibility to existing UBIFS images ?

with regards, Pekon

Quoted 42 lines

drivers/mtd/nand/fsl_elbc_nand.c static int fsl_elbc_write_page(struct

Quoted 7 lines

------------------------------------

drivers/mtd/nand/fsl_elbc_nand.c +0 -0
index a21252c..cc79ce4 100644
@@ -723,6 +723,19 @@ static int fsl_elbc_write_page(struct

mtd_info

drivers/mtd/nand/fsl_elbc_nand.c static int fsl_elbc_chip_init(struct

Quoted 23 lines
drivers/mtd/nand/fsl_elbc_nand.c +1 -0
 *mtd, struct nand_chip *chip,
       return 0;
 }
 
+/* ECC will be calculated automatically, and errors will be detected

in
+ * waitfunc.
+ */
+static int fsl_elbc_write_subpage(struct mtd_info *mtd, struct nand_chip *chip,

drivers/mtd/nand/fsl_elbc_nand.c +9 -0
+                               uint32_t offset, uint32_t data_len,
+                               const uint8_t *buf, int oob_required)
+{
+       fsl_elbc_write_buf(mtd, buf, mtd->writesize);
+       fsl_elbc_write_buf(mtd, chip->oob_poi, mtd->oobsize);
+
+       return 0;
+}
+

static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv)

{
       struct fsl_lbc_ctrl *ctrl = priv->ctrl;
drivers/mtd/nand/fsl_elbc_nand.c +0 -0
@@ -762,6 +775,7 @@ static int fsl_elbc_chip_init(struct

fsl_elbc_mtd

Quoted 10 lines
drivers/mtd/nand/fsl_elbc_nand.c +1 -0
 *priv)
 
       chip->ecc.read_page = fsl_elbc_read_page;
       chip->ecc.write_page = fsl_elbc_write_page;
+       chip->ecc.write_subpage = fsl_elbc_write_subpage;
 
       /* If CS Base Register selects full hardware ECC then use it */
       if ((in_be32(&lbc->bank[priv->bank].br) & BR_DECC) ==

------------------------------------

author Tested-by
#16 lore raw

Hi Pekon,

Quoted 2 lines · Pekon

Any update on below patch? Does this maintain compatibility to existing UBIFS images ?

Patch works fine with a VID header offset of 512 and without the crash :)

Feel free to add my

when sending the patch.

Thanks,
Helmut

Quoted 46 lines

with regards, Pekon

Quoted 42 lines

drivers/mtd/nand/fsl_elbc_nand.c static int fsl_elbc_write_page(struct

Quoted 7 lines

------------------------------------

drivers/mtd/nand/fsl_elbc_nand.c +0 -0
index a21252c..cc79ce4 100644
@@ -723,6 +723,19 @@ static int fsl_elbc_write_page(struct

mtd_info

drivers/mtd/nand/fsl_elbc_nand.c static int fsl_elbc_chip_init(struct

Quoted 23 lines
drivers/mtd/nand/fsl_elbc_nand.c +1 -0
 *mtd, struct nand_chip *chip,
       return 0;
 }
 
+/* ECC will be calculated automatically, and errors will be detected

in
+ * waitfunc.
+ */
+static int fsl_elbc_write_subpage(struct mtd_info *mtd, struct nand_chip *chip,

drivers/mtd/nand/fsl_elbc_nand.c +9 -0
+                               uint32_t offset, uint32_t data_len,
+                               const uint8_t *buf, int oob_required)
+{
+       fsl_elbc_write_buf(mtd, buf, mtd->writesize);
+       fsl_elbc_write_buf(mtd, chip->oob_poi, mtd->oobsize);
+
+       return 0;
+}
+

static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv)

{
       struct fsl_lbc_ctrl *ctrl = priv->ctrl;
drivers/mtd/nand/fsl_elbc_nand.c +0 -0
@@ -762,6 +775,7 @@ static int fsl_elbc_chip_init(struct

fsl_elbc_mtd

Quoted 10 lines
drivers/mtd/nand/fsl_elbc_nand.c +1 -0
 *priv)
 
       chip->ecc.read_page = fsl_elbc_read_page;
       chip->ecc.write_page = fsl_elbc_write_page;
+       chip->ecc.write_subpage = fsl_elbc_write_subpage;
 
       /* If CS Base Register selects full hardware ECC then use it */
       if ((in_be32(&lbc->bank[priv->bank].br) & BR_DECC) ==

------------------------------------

#17 lore raw
In reply to Helmut Schaa

Hi,

I have my archaeology hat on, in the deep corners of my mailbox...

Quoted 9 lines · Helmut Schaa

nand_write_subpage_hwecc causes a crash if the driver did not register ecc->hwctl or ecc->calculate. Fix this by disabling subpage writes if ecc->hwctl or ecc->calculate is not provided by the driver.

This behavior was introduced in commit 837a6ba4f3b6d23026674e6af6b6849a4634fff9 "mtd: nand: subpage write support for hardware based ECC schemes".

This fixes a crash with fsl_elbc_nand and maybe others:

[...]

Quoted 17 lines
Cc Gupta, Pekon <[email protected]>
Cc Artem Bityutskiy <[email protected]>
Cc David Woodhouse <[email protected]>

---
I noticed this bug on openwrt with kernel 3.10 but it looks as if this can still happen in more recent kernels.

 drivers/mtd/nand/nand_base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/nand_base.c +0 -0
index 9715a7b..2298289 100644

drivers/mtd/nand/nand_base.c int nand_scan_tail(struct mtd_info *mtd) · line 3774

Quoted 8 lines
drivers/mtd/nand/nand_base.c +1 -1
@@ -3768,7 +3768,7 @@ int nand_scan_tail(struct mtd_info *mtd)
 			ecc->write_oob = nand_write_oob_std;
 		if (!ecc->read_subpage)
 			ecc->read_subpage = nand_read_subpage;
-		if (!ecc->write_subpage)
+		if (!ecc->write_subpage && ecc->hwctl && ecc->calculate)
 			ecc->write_subpage = nand_write_subpage_hwecc;
 
 	case NAND_ECC_HW_SYNDROME:

I realize we've merged a fix for fsl_elbc_nand long ago (commit f034d87def51 "mtd: eLBC NAND: fix subpage write support"), but this change still looks sane, applies, and could possibly fix some other drivers that are lurking somewhere. Any reason I shouldn't apply it?

Regards,
Brian

#18 lore raw
Quoted 39 lines · Brian Norris

Hi,

I have my archaeology hat on, in the deep corners of my mailbox...

Quoted 9 lines · Helmut Schaa

nand_write_subpage_hwecc causes a crash if the driver did not register ecc->hwctl or ecc->calculate. Fix this by disabling subpage writes if ecc->hwctl or ecc->calculate is not provided by the driver.

This behavior was introduced in commit 837a6ba4f3b6d23026674e6af6b6849a4634fff9 "mtd: nand: subpage write support for hardware based ECC schemes".

This fixes a crash with fsl_elbc_nand and maybe others:

[...]

Quoted 24 lines
Cc Gupta, Pekon <[email protected]>
Cc Artem Bityutskiy <[email protected]>
Cc David Woodhouse <[email protected]>

---
I noticed this bug on openwrt with kernel 3.10 but it looks as if this can still happen in more recent kernels.

 drivers/mtd/nand/nand_base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/nand_base.c +1 -1
index 9715a7b..2298289 100644
@@ -3768,7 +3768,7 @@ int nand_scan_tail(struct mtd_info *mtd)
                      ecc->write_oob = nand_write_oob_std;
              if (!ecc->read_subpage)
                      ecc->read_subpage = nand_read_subpage;
-             if (!ecc->write_subpage)
+             if (!ecc->write_subpage && ecc->hwctl && ecc->calculate)
                      ecc->write_subpage = nand_write_subpage_hwecc;
 
Quoted 6 lines

drivers/mtd/nand/nand_base.c int nand_scan_tail(struct mtd_info *mtd) · line 3774

Quoted 1 line
drivers/mtd/nand/nand_base.c +0 -0
      case NAND_ECC_HW_SYNDROME:

I realize we've merged a fix for fsl_elbc_nand long ago (commit f034d87def51 "mtd: eLBC NAND: fix subpage write support"), but this change still looks sane, applies, and could possibly fix some other drivers that are lurking somewhere. Any reason I shouldn't apply it?

I'm not carrying this patch in my tree anymore and did not see any more crashes with the flash configuration I'm using. So, I think the original patch is kind of superfluous.

Regards,
Helmut

#19 lore raw
Quoted 31 lines · Helmut Schaa
Quoted 22 lines · Brian Norris
Quoted 9 lines · Helmut Schaa

nand_write_subpage_hwecc causes a crash if the driver did not register ecc->hwctl or ecc->calculate. Fix this by disabling subpage writes if ecc->hwctl or ecc->calculate is not provided by the driver.

This behavior was introduced in commit 837a6ba4f3b6d23026674e6af6b6849a4634fff9 "mtd: nand: subpage write support for hardware based ECC schemes".

This fixes a crash with fsl_elbc_nand and maybe others:

[...]

Quoted 11 lines
drivers/mtd/nand/nand_base.c +1 -1
@@ -3768,7 +3768,7 @@ int nand_scan_tail(struct mtd_info *mtd)
                      ecc->write_oob = nand_write_oob_std;
              if (!ecc->read_subpage)
                      ecc->read_subpage = nand_read_subpage;
-             if (!ecc->write_subpage)
+             if (!ecc->write_subpage && ecc->hwctl && ecc->calculate)
                      ecc->write_subpage = nand_write_subpage_hwecc;
 
Quoted 6 lines

drivers/mtd/nand/nand_base.c int nand_scan_tail(struct mtd_info *mtd) · line 3774

Quoted 1 line
drivers/mtd/nand/nand_base.c +0 -0
      case NAND_ECC_HW_SYNDROME:

I realize we've merged a fix for fsl_elbc_nand long ago (commit f034d87def51 "mtd: eLBC NAND: fix subpage write support"), but this change still looks sane, applies, and could possibly fix some other drivers that are lurking somewhere. Any reason I shouldn't apply it?

Quoted 3 lines

I'm not carrying this patch in my tree anymore and did not see any more crashes with the flash configuration I'm using. So, I think the original patch is kind of superfluous.

There could easily be other drivers that don't have hwctl() or calculate() callbacks yet use NAND_ECC_HW. By inspection, I see that maybe the new hisi504_nand.c is susceptible, as well as sh_flctl.c and maybe even sunxi_nand.c (?). Some of these might not be hit if they don't use NAND that support subpage writes.

Anyway, I think this patch is helpful, because it prevents drivers from having to fill in a 'subpage' write callback that looks just like their write_page() callback.

Brian

#20 lore raw

Hi Brian,

Quoted 13 lines · On Fri, 11 Dec 2015 16:40:25 -0800 Brian Norris <[email protected]>…
Quoted 12 lines · Helmut Schaa
Quoted 10 lines · Brian Norris
Quoted 9 lines · Helmut Schaa

nand_write_subpage_hwecc causes a crash if the driver did not register ecc->hwctl or ecc->calculate. Fix this by disabling subpage writes if ecc->hwctl or ecc->calculate is not provided by the driver.

This behavior was introduced in commit 837a6ba4f3b6d23026674e6af6b6849a4634fff9 "mtd: nand: subpage write support for hardware based ECC schemes".

This fixes a crash with fsl_elbc_nand and maybe others:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

[...]

drivers/mtd/nand/nand_base.c int nand_scan_tail(struct mtd_info *mtd) · line 3770

Quoted 7 lines
drivers/mtd/nand/nand_base.c +0 -0
@@ -3768,7 +3768,7 @@ int nand_scan_tail(struct mtd_info *mtd)
                      ecc->write_oob = nand_write_oob_std;
              if (!ecc->read_subpage)
                      ecc->read_subpage = nand_read_subpage;

Shouldn't we have the same kind of test for ->read_subpage.

		if (!ecc->read_subpage && ecc->correct &&
		    ecc->calculate)
			ecc->read_subpage = nand_read_subpage;
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
drivers/mtd/nand/nand_base.c +1 -1
-             if (!ecc->write_subpage)
+             if (!ecc->write_subpage && ecc->hwctl && ecc->calculate)
                      ecc->write_subpage = nand_write_subpage_hwecc;
 
      case NAND_ECC_HW_SYNDROME:
Quoted 8 lines
Quoted 4 lines

I realize we've merged a fix for fsl_elbc_nand long ago (commit f034d87def51 "mtd: eLBC NAND: fix subpage write support"), but this change still looks sane, applies, and could possibly fix some other drivers that are lurking somewhere. Any reason I shouldn't apply it?

I'm not carrying this patch in my tree anymore and did not see any more crashes with the flash configuration I'm using. So, I think the original patch is kind of superfluous.

Quoted 5 lines

There could easily be other drivers that don't have hwctl() or calculate() callbacks yet use NAND_ECC_HW. By inspection, I see that maybe the new hisi504_nand.c is susceptible, as well as sh_flctl.c and maybe even sunxi_nand.c (?). Some of these might not be hit if they don't use NAND that support subpage writes.

Yep, sunxi platforms could be hit by this bug, but it seems nobody decided to design a board with an SLC NAND (and MLCs are not supporting subpage writes).

Quoted 4 lines

Anyway, I think this patch is helpful, because it prevents drivers from having to fill in a 'subpage' write callback that looks just like their write_page() callback.

I agree.

Best Regards,

Boris

Signature · 3 lines
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
#21 lore raw
Quoted 60 lines · Boris Brezillon

Hi Brian,

Quoted 13 lines · On Fri, 11 Dec 2015 16:40:25 -0800 Brian Norris <[email protected]>…
Quoted 12 lines · Helmut Schaa
Quoted 10 lines · Brian Norris
Quoted 9 lines · Helmut Schaa

nand_write_subpage_hwecc causes a crash if the driver did not register ecc->hwctl or ecc->calculate. Fix this by disabling subpage writes if ecc->hwctl or ecc->calculate is not provided by the driver.

This behavior was introduced in commit 837a6ba4f3b6d23026674e6af6b6849a4634fff9 "mtd: nand: subpage write support for hardware based ECC schemes".

This fixes a crash with fsl_elbc_nand and maybe others:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

[...]

drivers/mtd/nand/nand_base.c int nand_scan_tail(struct mtd_info *mtd) · line 3770

Quoted 7 lines
drivers/mtd/nand/nand_base.c +0 -0
@@ -3768,7 +3768,7 @@ int nand_scan_tail(struct mtd_info *mtd)
                      ecc->write_oob = nand_write_oob_std;
              if (!ecc->read_subpage)
                      ecc->read_subpage = nand_read_subpage;

Shouldn't we have the same kind of test for ->read_subpage.

                if (!ecc->read_subpage && ecc->correct &&
                    ecc->calculate)
                        ecc->read_subpage = nand_read_subpage;
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
drivers/mtd/nand/nand_base.c +1 -1
-             if (!ecc->write_subpage)
+             if (!ecc->write_subpage && ecc->hwctl && ecc->calculate)
                      ecc->write_subpage = nand_write_subpage_hwecc;
 
      case NAND_ECC_HW_SYNDROME:
Quoted 8 lines
Quoted 4 lines

I realize we've merged a fix for fsl_elbc_nand long ago (commit f034d87def51 "mtd: eLBC NAND: fix subpage write support"), but this change still looks sane, applies, and could possibly fix some other drivers that are lurking somewhere. Any reason I shouldn't apply it?

I'm not carrying this patch in my tree anymore and did not see any more crashes with the flash configuration I'm using. So, I think the original patch is kind of superfluous.

Quoted 5 lines

There could easily be other drivers that don't have hwctl() or calculate() callbacks yet use NAND_ECC_HW. By inspection, I see that maybe the new hisi504_nand.c is susceptible, as well as sh_flctl.c and maybe even sunxi_nand.c (?). Some of these might not be hit if they don't use NAND that support subpage writes.

Yep, sunxi platforms could be hit by this bug, but it seems nobody decided to design a board with an SLC NAND (and MLCs are not supporting subpage writes).

Quoted 1 line
Quoted 5 lines
Quoted 3 lines

Anyway, I think this patch is helpful, because it prevents drivers from having to fill in a 'subpage' write callback that looks just like their write_page() callback.

I agree.

Fine with me then.
Helmut

#22 lore raw
In reply to Boris Brezillon
Quoted 27 lines · Boris Brezillon
Quoted 13 lines · On Fri, 11 Dec 2015 16:40:25 -0800 Brian Norris <[email protected]>…
Quoted 12 lines · Helmut Schaa
Quoted 10 lines · Brian Norris
Quoted 9 lines · Helmut Schaa

nand_write_subpage_hwecc causes a crash if the driver did not register ecc->hwctl or ecc->calculate. Fix this by disabling subpage writes if ecc->hwctl or ecc->calculate is not provided by the driver.

This behavior was introduced in commit 837a6ba4f3b6d23026674e6af6b6849a4634fff9 "mtd: nand: subpage write support for hardware based ECC schemes".

This fixes a crash with fsl_elbc_nand and maybe others:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

[...]

drivers/mtd/nand/nand_base.c int nand_scan_tail(struct mtd_info *mtd) · line 3770

Quoted 7 lines
drivers/mtd/nand/nand_base.c +0 -0
@@ -3768,7 +3768,7 @@ int nand_scan_tail(struct mtd_info *mtd)
                      ecc->write_oob = nand_write_oob_std;
              if (!ecc->read_subpage)
                      ecc->read_subpage = nand_read_subpage;

Shouldn't we have the same kind of test for ->read_subpage.

Quoted 3 lines
		if (!ecc->read_subpage && ecc->correct &&
		    ecc->calculate)
			ecc->read_subpage = nand_read_subpage;

We could do that, though right now we have a little less danger for read_subpage() than we do with write_subpage(), because drivers have to opt in with the NAND_SUBPAGE_READ flag before this function will actually be used. Feel free to send a patch if you'd like.

Quoted 26 lines
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
drivers/mtd/nand/nand_base.c +1 -1
-             if (!ecc->write_subpage)
+             if (!ecc->write_subpage && ecc->hwctl && ecc->calculate)
                      ecc->write_subpage = nand_write_subpage_hwecc;
 
      case NAND_ECC_HW_SYNDROME:
Quoted 8 lines
Quoted 4 lines

I realize we've merged a fix for fsl_elbc_nand long ago (commit f034d87def51 "mtd: eLBC NAND: fix subpage write support"), but this change still looks sane, applies, and could possibly fix some other drivers that are lurking somewhere. Any reason I shouldn't apply it?

I'm not carrying this patch in my tree anymore and did not see any more crashes with the flash configuration I'm using. So, I think the original patch is kind of superfluous.

Quoted 5 lines

There could easily be other drivers that don't have hwctl() or calculate() callbacks yet use NAND_ECC_HW. By inspection, I see that maybe the new hisi504_nand.c is susceptible, as well as sh_flctl.c and maybe even sunxi_nand.c (?). Some of these might not be hit if they don't use NAND that support subpage writes.

Yep, sunxi platforms could be hit by this bug, but it seems nobody decided to design a board with an SLC NAND (and MLCs are not supporting subpage writes).

Quoted 1 line
Quoted 5 lines
Quoted 3 lines

Anyway, I think this patch is helpful, because it prevents drivers from having to fill in a 'subpage' write callback that looks just like their write_page() callback.

I agree.

OK. Applied to l2-mtd.git, with additional commentary about how the reported issue is already fixed, but there could be other drivers who run across this problem.

Brian