linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs: properly access unaligned checksum buffer
@ 2011-03-18 15:28 David Sterba
  2011-03-18 15:56 ` Chris Mason
  0 siblings, 1 reply; 3+ messages in thread
From: David Sterba @ 2011-03-18 15:28 UTC (permalink / raw)
  To: chris.mason; +Cc: linux-btrfs, adrien.dessemond, David Sterba

fixes https://bugzilla.kernel.org/show_bug.cgi?id=29142
reported on SPARC64, warnings like:

[ 1523.941667] Kernel unaligned access at TPC[100e4034]
btrfs_csum_final+0x38/0x3c [btrfs]

Reported-by: Adrien Dessemond <adrien.dessemond@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Tested-by: Adrien Dessemond <adrien.dessemond@gmail.com>
---
 fs/btrfs/disk-io.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index e1aa8d6..8065863 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -198,7 +198,11 @@ u32 btrfs_csum_data(struct btrfs_root *root, char *data, u32 seed, size_t len)
 
 void btrfs_csum_final(u32 crc, char *result)
 {
+#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
 	*(__le32 *)result = ~cpu_to_le32(crc);
+#else
+	put_unaligned_le32(~crc, result);
+#endif
 }
 
 /*
-- 
1.7.4.1.176.g501cc


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

* Re: [PATCH] btrfs: properly access unaligned checksum buffer
  2011-03-18 15:28 [PATCH] btrfs: properly access unaligned checksum buffer David Sterba
@ 2011-03-18 15:56 ` Chris Mason
  2011-03-18 22:56   ` David Sterba
  0 siblings, 1 reply; 3+ messages in thread
From: Chris Mason @ 2011-03-18 15:56 UTC (permalink / raw)
  To: David Sterba; +Cc: linux-btrfs, adrien.dessemond

Excerpts from David Sterba's message of 2011-03-18 11:28:25 -0400:
> fixes https://bugzilla.kernel.org/show_bug.cgi?id=29142
> reported on SPARC64, warnings like:
> 
> [ 1523.941667] Kernel unaligned access at TPC[100e4034]
> btrfs_csum_final+0x38/0x3c [btrfs]
> 
> Reported-by: Adrien Dessemond <adrien.dessemond@gmail.com>
> Signed-off-by: David Sterba <dsterba@suse.cz>
> Tested-by: Adrien Dessemond <adrien.dessemond@gmail.com>
> ---
>  fs/btrfs/disk-io.c |    4 ++++
>  1 files changed, 4 insertions(+), 0 deletions(-)
> 
> diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
> index e1aa8d6..8065863 100644
> --- a/fs/btrfs/disk-io.c
> +++ b/fs/btrfs/disk-io.c
> @@ -198,7 +198,11 @@ u32 btrfs_csum_data(struct btrfs_root *root, char *data, u32 seed, size_t len)
>  
>  void btrfs_csum_final(u32 crc, char *result)
>  {
> +#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
>      *(__le32 *)result = ~cpu_to_le32(crc);
> +#else
> +    put_unaligned_le32(~crc, result);
> +#endif
>  }

Thanks for fielding this one.  Does put_unaligned_le32 optimize away on
platforms with efficient access?  It would be great if we didn't need
the #ifdef.

-chris



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

* Re: [PATCH] btrfs: properly access unaligned checksum buffer
  2011-03-18 15:56 ` Chris Mason
@ 2011-03-18 22:56   ` David Sterba
  0 siblings, 0 replies; 3+ messages in thread
From: David Sterba @ 2011-03-18 22:56 UTC (permalink / raw)
  To: Chris Mason; +Cc: David Sterba, linux-btrfs, adrien.dessemond

On Fri, Mar 18, 2011 at 11:56:53AM -0400, Chris Mason wrote:
> Thanks for fielding this one.  Does put_unaligned_le32 optimize away on
> platforms with efficient access?  It would be great if we didn't need
> the #ifdef.

(quicktest: assembly output is same for put_unaligned_le32 and direct
assignment on my x86_64)
I was originally following examples in
Documentation/unaligned-memory-access.txt. From other code it seems to me that
the define CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS is intended for larger
portions of code. Macros/wrappers for {put,get}_unaligned* are chosen via
arch/<arch>/include/asm/unaligned.h accordingly, therefore it's safe to use
put_unaligned_le32 without the ifdef.

dave
--

From: David Sterba <dsterba@suse.cz>

fixes https://bugzilla.kernel.org/show_bug.cgi?id=29142
reported on SPARC64, warnings like:

[ 1523.941667] Kernel unaligned access at TPC[100e4034]
btrfs_csum_final+0x38/0x3c [btrfs]

Reported-by: Adrien Dessemond <adrien.dessemond@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Tested-by: Adrien Dessemond <adrien.dessemond@gmail.com>
---
 fs/btrfs/disk-io.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index e1aa8d6..80a6830 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -29,6 +29,7 @@
 #include <linux/crc32c.h>
 #include <linux/slab.h>
 #include <linux/migrate.h>
+#include <asm/unaligned.h>
 #include "compat.h"
 #include "ctree.h"
 #include "disk-io.h"
@@ -198,7 +199,7 @@ u32 btrfs_csum_data(struct btrfs_root *root, char *data, u32 seed, size_t len)

 void btrfs_csum_final(u32 crc, char *result)
 {
-       *(__le32 *)result = ~cpu_to_le32(crc);
+       put_unaligned_le32(~crc, result);
 }

 /*
--
1.7.4.1.176.g501cc

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

end of thread, other threads:[~2011-03-18 22:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-18 15:28 [PATCH] btrfs: properly access unaligned checksum buffer David Sterba
2011-03-18 15:56 ` Chris Mason
2011-03-18 22:56   ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).