public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* jffs2 and unaligned access
@ 2008-05-07 10:27 Sascha Hauer
  2008-05-07 10:53 ` David Woodhouse
  0 siblings, 1 reply; 6+ messages in thread
From: Sascha Hauer @ 2008-05-07 10:27 UTC (permalink / raw)
  To: linux-mtd; +Cc: David Woodhouse, Jon Smirl

Hi,

memcpy_from/to_io() use word aligned accesses on the io side of memory.
The MPC5200 local plus bus where our flashes are connected does not
allow unaligned accesses, so we have to use the io versions of memcpy.

I have the suspicion that this is not the correct fix to our problem,
but maybe someone can have a look at it and point me in the right
direction.

Thanks,
  Sascha

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

---
 fs/jffs2/scan.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Index: linux-2.6/fs/jffs2/scan.c
===================================================================
--- linux-2.6.orig/fs/jffs2/scan.c
+++ linux-2.6/fs/jffs2/scan.c
@@ -16,6 +16,7 @@
 #include <linux/pagemap.h>
 #include <linux/crc32.h>
 #include <linux/compiler.h>
+#include <linux/io.h>
 #include "nodelist.h"
 #include "summary.h"
 #include "debug.h"
@@ -506,7 +507,7 @@ static int jffs2_scan_eraseblock (struct
 					sumptr = kmalloc(sumlen, GFP_KERNEL);
 					if (!sumptr)
 						return -ENOMEM;
-					memcpy(sumptr + sumlen - buf_len, buf + buf_size - buf_len, buf_len);
+					memcpy_fromio(sumptr + sumlen - buf_len, buf + buf_size - buf_len, buf_len);
 				}
 				if (buf_len < sumlen) {
 					/* Need to read more so that the entire summary node is present */
@@ -1036,7 +1037,7 @@ static int jffs2_scan_dirent_node(struct
 	if (!fd) {
 		return -ENOMEM;
 	}
-	memcpy(&fd->name, rd->name, checkedlen);
+	memcpy_fromio(&fd->name, rd->name, checkedlen);
 	fd->name[checkedlen] = 0;
 
 	crc = crc32(0, fd->name, rd->nsize);
-- 
Pengutronix e.K. - Linux Solutions for Science and Industry
-----------------------------------------------------------
Kontakt-Informationen finden Sie im Header dieser Mail oder
auf der Webseite -> http://www.pengutronix.de/impressum/ <-

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: jffs2 and unaligned access
  2008-05-07 10:27 jffs2 and unaligned access Sascha Hauer
@ 2008-05-07 10:53 ` David Woodhouse
  2008-05-07 13:25   ` Sascha Hauer
  2008-05-07 20:42   ` Segher Boessenkool
  0 siblings, 2 replies; 6+ messages in thread
From: David Woodhouse @ 2008-05-07 10:53 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: linuxppc-dev, linux-mtd, Jon Smirl

On Wed, 2008-05-07 at 12:27 +0200, Sascha Hauer wrote:
> memcpy_from/to_io() use word aligned accesses on the io side of memory.
> The MPC5200 local plus bus where our flashes are connected does not
> allow unaligned accesses, so we have to use the io versions of memcpy.

But this region of flash is marked as suitable for execute-in-place,
otherwise the point() function wouldn't be working to give a direct
pointer to it. It sounds like we shouldn't be allowing that.

Which in turn means that perhaps we should have a property in the
corresponding node in the device-tree which indicates that it's not
suitable for direct access?

-- 
dwmw2

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: jffs2 and unaligned access
  2008-05-07 10:53 ` David Woodhouse
@ 2008-05-07 13:25   ` Sascha Hauer
  2008-06-05 21:38     ` Jon Smirl
  2008-05-07 20:42   ` Segher Boessenkool
  1 sibling, 1 reply; 6+ messages in thread
From: Sascha Hauer @ 2008-05-07 13:25 UTC (permalink / raw)
  To: David Woodhouse; +Cc: linuxppc-dev, linux-mtd, Jon Smirl

On Wed, May 07, 2008 at 11:53:49AM +0100, David Woodhouse wrote:
> On Wed, 2008-05-07 at 12:27 +0200, Sascha Hauer wrote:
> > memcpy_from/to_io() use word aligned accesses on the io side of memory.
> > The MPC5200 local plus bus where our flashes are connected does not
> > allow unaligned accesses, so we have to use the io versions of memcpy.
> 
> But this region of flash is marked as suitable for execute-in-place,
> otherwise the point() function wouldn't be working to give a direct
> pointer to it. It sounds like we shouldn't be allowing that.

It actually is suitable for execute-in-place. It's the flash U-Boot
starts from. The compiler will generate a proper alignment for you.

> 
> Which in turn means that perhaps we should have a property in the
> corresponding node in the device-tree which indicates that it's not
> suitable for direct access?

So far we did not work with the device-tree flash binding but with the
physmap-flash driver, but ok, this is subject to change anyway.

I gave it a quick try to disable direct accesses. It works, but has a
1:10 performance impact on mounting a jffs2. At least it's a clean
solution.

Sascha


-- 
Pengutronix e.K. - Linux Solutions for Science and Industry
-----------------------------------------------------------
Kontakt-Informationen finden Sie im Header dieser Mail oder
auf der Webseite -> http://www.pengutronix.de/impressum/ <-

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: jffs2 and unaligned access
  2008-05-07 10:53 ` David Woodhouse
  2008-05-07 13:25   ` Sascha Hauer
@ 2008-05-07 20:42   ` Segher Boessenkool
  2008-05-08 13:19     ` Detlev Zundel
  1 sibling, 1 reply; 6+ messages in thread
From: Segher Boessenkool @ 2008-05-07 20:42 UTC (permalink / raw)
  To: David Woodhouse; +Cc: linuxppc-dev, Sascha Hauer, linux-mtd

>> memcpy_from/to_io() use word aligned accesses on the io side of 
>> memory.
>> The MPC5200 local plus bus where our flashes are connected does not
>> allow unaligned accesses, so we have to use the io versions of memcpy.
>
> But this region of flash is marked as suitable for execute-in-place,
> otherwise the point() function wouldn't be working to give a direct
> pointer to it. It sounds like we shouldn't be allowing that.
>
> Which in turn means that perhaps we should have a property in the
> corresponding node in the device-tree which indicates that it's not
> suitable for direct access?

This isn't usually a property of the flash device, but of the various
buses/controllers above the flash device.  The device tree should mimic
reality (and it does, it just seems the kernel doesn't use this 
information
yet?)


Segher

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: jffs2 and unaligned access
  2008-05-07 20:42   ` Segher Boessenkool
@ 2008-05-08 13:19     ` Detlev Zundel
  0 siblings, 0 replies; 6+ messages in thread
From: Detlev Zundel @ 2008-05-08 13:19 UTC (permalink / raw)
  To: linux-mtd; +Cc: linuxppc-dev

Hi,

>>> memcpy_from/to_io() use word aligned accesses on the io side of
>>> memory.
>>> The MPC5200 local plus bus where our flashes are connected does not
>>> allow unaligned accesses, so we have to use the io versions of memcpy.
>>
>> But this region of flash is marked as suitable for execute-in-place,
>> otherwise the point() function wouldn't be working to give a direct
>> pointer to it. It sounds like we shouldn't be allowing that.
>>
>> Which in turn means that perhaps we should have a property in the
>> corresponding node in the device-tree which indicates that it's not
>> suitable for direct access?
>
> This isn't usually a property of the flash device, but of the various
> buses/controllers above the flash device.  

I wholeheartedly agree.  After all, its the Local+ bus playing games
here.  And fixing that for JFFS2 only ignores that other devices can
*and will* be connected on this bus.  Unaligned accesses to such devices
will also fail (likely from mtd unrelated code) - and fail silently,
taking quite a while to figure out what is going wrong where.

> The device tree should mimic reality (and it does, it just seems the
> kernel doesn't use this information yet?)

How is this exactly supposed to work?

Cheers
  Detlev

-- 
In the topologic hell the beer is packed in Klein's bottles.
--
DENX Software Engineering GmbH,      MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich,  Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu@denx.de

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: jffs2 and unaligned access
  2008-05-07 13:25   ` Sascha Hauer
@ 2008-06-05 21:38     ` Jon Smirl
  0 siblings, 0 replies; 6+ messages in thread
From: Jon Smirl @ 2008-06-05 21:38 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: linux-mtd, David Woodhouse, linuxppc-dev

On 5/7/08, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> On Wed, May 07, 2008 at 11:53:49AM +0100, David Woodhouse wrote:
>  > On Wed, 2008-05-07 at 12:27 +0200, Sascha Hauer wrote:
>  > > memcpy_from/to_io() use word aligned accesses on the io side of memory.
>  > > The MPC5200 local plus bus where our flashes are connected does not
>  > > allow unaligned accesses, so we have to use the io versions of memcpy.
>  >
>  > But this region of flash is marked as suitable for execute-in-place,
>  > otherwise the point() function wouldn't be working to give a direct
>  > pointer to it. It sounds like we shouldn't be allowing that.
>
>
> It actually is suitable for execute-in-place. It's the flash U-Boot
>  starts from. The compiler will generate a proper alignment for you.
>
>
>  >
>  > Which in turn means that perhaps we should have a property in the
>  > corresponding node in the device-tree which indicates that it's not
>  > suitable for direct access?
>
>
> So far we did not work with the device-tree flash binding but with the
>  physmap-flash driver, but ok, this is subject to change anyway.
>
>  I gave it a quick try to disable direct accesses. It works, but has a
>  1:10 performance impact on mounting a jffs2. At least it's a clean
>  solution.

How did this get resolved? The thread died without any final solution
being proposed.


>
>
>  Sascha
>
>
>
>  --
>  Pengutronix e.K. - Linux Solutions for Science and Industry
>  -----------------------------------------------------------
>  Kontakt-Informationen finden Sie im Header dieser Mail oder
>  auf der Webseite -> http://www.pengutronix.de/impressum/ <-
>


-- 
Jon Smirl
jonsmirl@gmail.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-06-05 21:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-07 10:27 jffs2 and unaligned access Sascha Hauer
2008-05-07 10:53 ` David Woodhouse
2008-05-07 13:25   ` Sascha Hauer
2008-06-05 21:38     ` Jon Smirl
2008-05-07 20:42   ` Segher Boessenkool
2008-05-08 13:19     ` Detlev Zundel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox