All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] fs: btrfs: Fix unaligned memory accesses
@ 2018-01-20  7:17 Alberto Sánchez Molero
  2018-01-22 16:27 ` Robert Nelson
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Alberto Sánchez Molero @ 2018-01-20  7:17 UTC (permalink / raw)
  To: u-boot

Loading files stored with lzo compression from a btrfs filesystem was
producing unaligned memory accesses, which were causing a data abort
and a reset on an Orange Pi Zero.

The change in hash.c is not triggered by any error but follows the
same pattern. Please confirm.

Fixed according to doc/README.unaligned-memory-access.txt



Signed-off by: Alberto Sánchez Molero <alsamolero@gmail.com>
---
 fs/btrfs/compression.c | 5 +++--
 fs/btrfs/hash.c        | 3 ++-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index a59ff5a..4e685a0 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -9,6 +9,7 @@
 #include "btrfs.h"
 #include <linux/lzo.h>
 #include <u-boot/zlib.h>
+#include <asm/unaligned.h>

 static u32 decompress_lzo(const u8 *cbuf, u32 clen, u8 *dbuf, u32 dlen)
 {
@@ -19,7 +20,7 @@ static u32 decompress_lzo(const u8 *cbuf, u32 clen,
u8 *dbuf, u32 dlen)
     if (clen < 4)
         return -1;

-    tot_len = le32_to_cpu(*(u32 *) cbuf);
+    tot_len = le32_to_cpu(get_unaligned((u32 *) cbuf));
     cbuf += 4;
     clen -= 4;
     tot_len -= 4;
@@ -32,7 +33,7 @@ static u32 decompress_lzo(const u8 *cbuf, u32 clen,
u8 *dbuf, u32 dlen)
     res = 0;

     while (tot_len > 4) {
-        in_len = le32_to_cpu(*(u32 *) cbuf);
+        in_len = le32_to_cpu(get_unaligned((u32 *) cbuf));
         cbuf += 4;
         clen -= 4;

diff --git a/fs/btrfs/hash.c b/fs/btrfs/hash.c
index f8a50e5..1c75ea8 100644
--- a/fs/btrfs/hash.c
+++ b/fs/btrfs/hash.c
@@ -8,6 +8,7 @@

 #include "btrfs.h"
 #include <u-boot/crc.h>
+#include <asm/unaligned.h>

 static u32 btrfs_crc32c_table[256];

@@ -34,5 +35,5 @@ u32 btrfs_csum_data(char *data, u32 seed, size_t len)

 void btrfs_csum_final(u32 crc, void *result)
 {
-    *((u32 *) result) = cpu_to_le32(~crc);
+    put_unaligned(cpu_to_le32(~crc), (u32 *) result);
 }
-- 
2.16.0

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

* [U-Boot] [PATCH] fs: btrfs: Fix unaligned memory accesses
  2018-01-20  7:17 [U-Boot] [PATCH] fs: btrfs: Fix unaligned memory accesses Alberto Sánchez Molero
@ 2018-01-22 16:27 ` Robert Nelson
  2018-01-25 13:48 ` Marek Behún
  2018-01-28 18:53 ` [U-Boot] " Tom Rini
  2 siblings, 0 replies; 5+ messages in thread
From: Robert Nelson @ 2018-01-22 16:27 UTC (permalink / raw)
  To: u-boot

On Sat, Jan 20, 2018 at 1:17 AM, Alberto Sánchez Molero
<alsamolero@gmail.com> wrote:
> Loading files stored with lzo compression from a btrfs filesystem was
> producing unaligned memory accesses, which were causing a data abort
> and a reset on an Orange Pi Zero.
>
> The change in hash.c is not triggered by any error but follows the
> same pattern. Please confirm.
>
> Fixed according to doc/README.unaligned-memory-access.txt

Awesome!

Marek, this fixes the issue i was also seeing on the Beagle's with lzo
compression.

Tested-by: Robert Nelson <robertcnelson@gmail.com>


>
> Signed-off by: Alberto Sánchez Molero <alsamolero@gmail.com>
> ---
>  fs/btrfs/compression.c | 5 +++--
>  fs/btrfs/hash.c        | 3 ++-
>  2 files changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
> index a59ff5a..4e685a0 100644
> --- a/fs/btrfs/compression.c
> +++ b/fs/btrfs/compression.c
> @@ -9,6 +9,7 @@
>  #include "btrfs.h"
>  #include <linux/lzo.h>
>  #include <u-boot/zlib.h>
> +#include <asm/unaligned.h>
>
>  static u32 decompress_lzo(const u8 *cbuf, u32 clen, u8 *dbuf, u32 dlen)
>  {
> @@ -19,7 +20,7 @@ static u32 decompress_lzo(const u8 *cbuf, u32 clen,
> u8 *dbuf, u32 dlen)
>      if (clen < 4)
>          return -1;
>
> -    tot_len = le32_to_cpu(*(u32 *) cbuf);
> +    tot_len = le32_to_cpu(get_unaligned((u32 *) cbuf));
>      cbuf += 4;
>      clen -= 4;
>      tot_len -= 4;
> @@ -32,7 +33,7 @@ static u32 decompress_lzo(const u8 *cbuf, u32 clen,
> u8 *dbuf, u32 dlen)
>      res = 0;
>
>      while (tot_len > 4) {
> -        in_len = le32_to_cpu(*(u32 *) cbuf);
> +        in_len = le32_to_cpu(get_unaligned((u32 *) cbuf));
>          cbuf += 4;
>          clen -= 4;
>
> diff --git a/fs/btrfs/hash.c b/fs/btrfs/hash.c
> index f8a50e5..1c75ea8 100644
> --- a/fs/btrfs/hash.c
> +++ b/fs/btrfs/hash.c
> @@ -8,6 +8,7 @@
>
>  #include "btrfs.h"
>  #include <u-boot/crc.h>
> +#include <asm/unaligned.h>
>
>  static u32 btrfs_crc32c_table[256];
>
> @@ -34,5 +35,5 @@ u32 btrfs_csum_data(char *data, u32 seed, size_t len)
>
>  void btrfs_csum_final(u32 crc, void *result)
>  {
> -    *((u32 *) result) = cpu_to_le32(~crc);
> +    put_unaligned(cpu_to_le32(~crc), (u32 *) result);
>  }
> --
> 2.16.0
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> https://lists.denx.de/listinfo/u-boot



-- 
Robert Nelson
https://rcn-ee.com/

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

* [U-Boot] [PATCH] fs: btrfs: Fix unaligned memory accesses
  2018-01-20  7:17 [U-Boot] [PATCH] fs: btrfs: Fix unaligned memory accesses Alberto Sánchez Molero
  2018-01-22 16:27 ` Robert Nelson
@ 2018-01-25 13:48 ` Marek Behún
  2018-01-25 14:51   ` Robert Nelson
  2018-01-28 18:53 ` [U-Boot] " Tom Rini
  2 siblings, 1 reply; 5+ messages in thread
From: Marek Behún @ 2018-01-25 13:48 UTC (permalink / raw)
  To: u-boot

Hi Alberto,
Thanks. I just forwarded this to Robert Nelson who encountered this
issue.
You can add Reviewed-by: Marek Behun <marek.behun@nic.cz>

Marek

On Sat, 20 Jan 2018 09:17:57 +0200
Alberto Sánchez Molero <alsamolero@gmail.com> wrote:

> Loading files stored with lzo compression from a btrfs filesystem was
> producing unaligned memory accesses, which were causing a data abort
> and a reset on an Orange Pi Zero.
> 
> The change in hash.c is not triggered by any error but follows the
> same pattern. Please confirm.
> 
> Fixed according to doc/README.unaligned-memory-access.txt

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

* [U-Boot] [PATCH] fs: btrfs: Fix unaligned memory accesses
  2018-01-25 13:48 ` Marek Behún
@ 2018-01-25 14:51   ` Robert Nelson
  0 siblings, 0 replies; 5+ messages in thread
From: Robert Nelson @ 2018-01-25 14:51 UTC (permalink / raw)
  To: u-boot

On Thu, Jan 25, 2018 at 7:48 AM, Marek Behún <marek.behun@nic.cz> wrote:
> Hi Alberto,
> Thanks. I just forwarded this to Robert Nelson who encountered this
> issue.
> You can add Reviewed-by: Marek Behun <marek.behun@nic.cz>

Weird, wonder how my email failed to go thru.

Tested-by: Robert Nelson <robertcnelson@gmail.com>

I've been running a few boards with btrfs/lzo enable this week, with
this patch on top of v2018.01 and everythink looks great!

Regards,

-- 
Robert Nelson
https://rcn-ee.com/

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

* [U-Boot] fs: btrfs: Fix unaligned memory accesses
  2018-01-20  7:17 [U-Boot] [PATCH] fs: btrfs: Fix unaligned memory accesses Alberto Sánchez Molero
  2018-01-22 16:27 ` Robert Nelson
  2018-01-25 13:48 ` Marek Behún
@ 2018-01-28 18:53 ` Tom Rini
  2 siblings, 0 replies; 5+ messages in thread
From: Tom Rini @ 2018-01-28 18:53 UTC (permalink / raw)
  To: u-boot

On Sat, Jan 20, 2018 at 09:17:57AM +0200, Alberto Sánchez Molero wrote:

> Loading files stored with lzo compression from a btrfs filesystem was
> producing unaligned memory accesses, which were causing a data abort
> and a reset on an Orange Pi Zero.
> 
> The change in hash.c is not triggered by any error but follows the
> same pattern. Please confirm.
> 
> Fixed according to doc/README.unaligned-memory-access.txt
> 
> 
> 
> Signed-off-by: Alberto Sánchez Molero <alsamolero@gmail.com>
> Tested-by: Robert Nelson <robertcnelson@gmail.com>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180128/054f4989/attachment.sig>

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

end of thread, other threads:[~2018-01-28 18:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-20  7:17 [U-Boot] [PATCH] fs: btrfs: Fix unaligned memory accesses Alberto Sánchez Molero
2018-01-22 16:27 ` Robert Nelson
2018-01-25 13:48 ` Marek Behún
2018-01-25 14:51   ` Robert Nelson
2018-01-28 18:53 ` [U-Boot] " Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.