MTD/NAND user-space ABI: interesting observation

Brian Norris computersforpeace at gmail.com
Fri Feb 14 21:05:52 EST 2014


Hi all,

Perhaps it's a non-issue, but I was realizing during some testing today
that there is no sound way to determine (in user-space) if a particular
raw read (i.e., from a /dev/mtdX) resulted in either a correctable bit
error or an uncorrectable ECC error. The current method used by
mtd-utils' nanddump is more or less a sequence of:

  ioctl(fd, ECCGETSTATS, &stat1);
  read(fd, buf, len);
  ioctl(fd, ECCGETSTATS, &stat2);
  if (stat2.corrected > stat1.corrected)
  	correctable bitflip;
  if (stat2.failed > stat1.failed)
  	uncorrectable error;

This is completely unsound if you are performing concurrent reads on the
same MTD device node (e.g., running two concurrent 'nanddump'
processes). The issue is pretty obvious once you study it, but I was
left scratching my head this afternoon when I had two separate nanddump
processes reporting bitflips at exactly the same times, at different
addresses!

I think this issue is probably not that important, since user-space raw
MTD accesses are really only good for testing/debugging, and any sane
solution would utilize a translation layer or special-purpose filesystem
(UBI, UBIFS, JFFS2, etc.) to handle -EUCLEAN and -EBADMSG (which is
presented properly in the MTD in-kernel API).

Just food for thought. Have a nice weekend!

Brian



More information about the linux-mtd mailing list