All of lore.kernel.org
 help / color / mirror / Atom feed
* Kernel unaligned access at ... btrfs_real_readdir+0x51c/0x718 [btrfs]
@ 2018-04-16 14:52 René Rebe
  2018-04-16 16:48 ` David Sterba
  0 siblings, 1 reply; 6+ messages in thread
From: René Rebe @ 2018-04-16 14:52 UTC (permalink / raw)
  To: linux-btrfs

Hi,

I just installed the latest #t2sde test build on a sparc64 system with btrfs rootfs - you know, just for the fun of testing, and in contrast to my x86 and ppc systems I get tons of unaligned access warnings, in the form of:

[    0.000000] Btrfs loaded, crc32c=crc32c-generic
[    0.000000] BTRFS: device fsid c84acf49-452a-4ed3-ae86-576975967db5 devid 1 transid 42 /dev/sda3
[    0.000000] BTRFS info (device sda3): disk space caching is enabled
[    0.000000] BTRFS info (device sda3): has skinny extents
[    0.000000] Kernel unaligned access at TPC[102f3080] btrfs_real_readdir+0x51c/0x718 [btrfs]
[    0.000000] Kernel unaligned access at TPC[102f30dc] btrfs_real_readdir+0x578/0x718 [btrfs]
[    0.000000] Kernel unaligned access at TPC[102f313c] btrfs_real_readdir+0x5d8/0x718 [btrfs]
[    0.000000] Kernel unaligned access at TPC[102f31a0] btrfs_real_readdir+0x63c/0x718 [btrfs]
[    0.000000] Kernel unaligned access at TPC[102f3080] btrfs_real_readdir+0x51c/0x718 [btrfs]
[    0.000000] log_unaligned: 38289 callbacks suppressed
[    0.000000] Kernel unaligned access at TPC[102f3080] btrfs_real_readdir+0x51c/0x718 [btrfs]
[    0.000000] Kernel unaligned access at TPC[102f30dc] btrfs_real_readdir+0x578/0x718 [btrfs]
[    0.000000] Kernel unaligned access at TPC[102f313c] btrfs_real_readdir+0x5d8/0x718 [btrfs]
[    0.000000] Kernel unaligned access at TPC[102f31a0] btrfs_real_readdir+0x63c/0x718 [btrfs]
[    0.000000] Kernel unaligned access at TPC[102f3080] btrfs_real_readdir+0x51c/0x718 [btrfs]
[    0.000000] log_unaligned: 112774 callbacks suppressed

in case some someone likes to address those, or has a quick patch to test, … just let me know ;-)

Greetings,
	René Rebe

-- 
 ExactCODE GmbH, Lietzenburger Str. 42, DE-10789 Berlin
 http://exactcode.com | http://exactscan.com | http://ocrkit.com | http://t2-project.org | http://rene.rebe.de

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

* Re: Kernel unaligned access at ... btrfs_real_readdir+0x51c/0x718 [btrfs]
  2018-04-16 14:52 Kernel unaligned access at ... btrfs_real_readdir+0x51c/0x718 [btrfs] René Rebe
@ 2018-04-16 16:48 ` David Sterba
  2018-04-16 19:55   ` René Rebe
  0 siblings, 1 reply; 6+ messages in thread
From: David Sterba @ 2018-04-16 16:48 UTC (permalink / raw)
  To: René Rebe; +Cc: linux-btrfs

On Mon, Apr 16, 2018 at 04:52:16PM +0200, René Rebe wrote:
> I just installed the latest #t2sde test build on a sparc64 system with
> btrfs rootfs - you know, just for the fun of testing, and in contrast
> to my x86 and ppc systems I get tons of unaligned access warnings, in
> the form of:
> 
> [    0.000000] Btrfs loaded, crc32c=crc32c-generic
> [    0.000000] BTRFS: device fsid c84acf49-452a-4ed3-ae86-576975967db5 devid 1 transid 42 /dev/sda3
> [    0.000000] BTRFS info (device sda3): disk space caching is enabled
> [    0.000000] BTRFS info (device sda3): has skinny extents
> [    0.000000] Kernel unaligned access at TPC[102f3080] btrfs_real_readdir+0x51c/0x718 [btrfs]
> [    0.000000] Kernel unaligned access at TPC[102f30dc] btrfs_real_readdir+0x578/0x718 [btrfs]
> [    0.000000] Kernel unaligned access at TPC[102f313c] btrfs_real_readdir+0x5d8/0x718 [btrfs]
> [    0.000000] Kernel unaligned access at TPC[102f31a0] btrfs_real_readdir+0x63c/0x718 [btrfs]
> [    0.000000] Kernel unaligned access at TPC[102f3080] btrfs_real_readdir+0x51c/0x718 [btrfs]
> [    0.000000] log_unaligned: 38289 callbacks suppressed
> [    0.000000] Kernel unaligned access at TPC[102f3080] btrfs_real_readdir+0x51c/0x718 [btrfs]
> [    0.000000] Kernel unaligned access at TPC[102f30dc] btrfs_real_readdir+0x578/0x718 [btrfs]
> [    0.000000] Kernel unaligned access at TPC[102f313c] btrfs_real_readdir+0x5d8/0x718 [btrfs]
> [    0.000000] Kernel unaligned access at TPC[102f31a0] btrfs_real_readdir+0x63c/0x718 [btrfs]
> [    0.000000] Kernel unaligned access at TPC[102f3080] btrfs_real_readdir+0x51c/0x718 [btrfs]
> [    0.000000] log_unaligned: 112774 callbacks suppressed
> 
> in case some someone likes to address those, or has a quick patch to
> test, … just let me know ;-)

The warnings are valid, there's unaligned access introduced by patch

23b5ec74943f44378b68c0edd8e210a86318ea5e
btrfs: fix readdir deadlock with pagefault

The directory entries (struct dir_entry) are copied to a temporary
buffer as they fit, ie. no alignment, and the members accessed in
several places.

The following patch adds the proper unaligned access, only compile-tested.
Please test and let me know, thanks!

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index e064c49c9a9a..f958eb686462 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -31,6 +31,7 @@
 #include <linux/uio.h>
 #include <linux/magic.h>
 #include <linux/iversion.h>
+#include <asm/unaligned.h>
 #include "ctree.h"
 #include "disk-io.h"
 #include "transaction.h"
@@ -5905,11 +5906,13 @@ static int btrfs_filldir(void *addr, int entries, struct dir_context *ctx)
                struct dir_entry *entry = addr;
                char *name = (char *)(entry + 1);
 
-               ctx->pos = entry->offset;
-               if (!dir_emit(ctx, name, entry->name_len, entry->ino,
-                             entry->type))
+               ctx->pos = get_unaligned(&entry->offset);
+               if (!dir_emit(ctx, name, get_unaligned(&entry->name_len),
+                                       get_unaligned(&entry->ino),
+                                       get_unaligned(&entry->type)))
                        return 1;
-               addr += sizeof(struct dir_entry) + entry->name_len;
+               addr += sizeof(struct dir_entry) +
+                       get_unaligned(&entry->name_len);
                ctx->pos++;
        }
        return 0;
@@ -5999,14 +6002,15 @@ static int btrfs_real_readdir(struct file *file, struct dir_context *ctx)
                }
 
                entry = addr;
-               entry->name_len = name_len;
+               put_unaligned(name_len, &entry->name_len);
                name_ptr = (char *)(entry + 1);
                read_extent_buffer(leaf, name_ptr, (unsigned long)(di + 1),
                                   name_len);
-               entry->type = btrfs_filetype_table[btrfs_dir_type(leaf, di)];
+               put_unaligned(btrfs_filetype_table[btrfs_dir_type(leaf, di)],
+                               &entry->type);
                btrfs_dir_item_key_to_cpu(leaf, di, &location);
-               entry->ino = location.objectid;
-               entry->offset = found_key.offset;
+               put_unaligned(location.objectid, &entry->ino);
+               put_unaligned(found_key.offset, &entry->offset);
                entries++;
                addr += sizeof(struct dir_entry) + name_len;
                total_len += sizeof(struct dir_entry) + name_len;
---

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

* Re: Kernel unaligned access at ... btrfs_real_readdir+0x51c/0x718 [btrfs]
  2018-04-16 19:55   ` René Rebe
@ 2018-04-16 19:15     ` David Sterba
  2018-04-17 10:18       ` René Rebe
  0 siblings, 1 reply; 6+ messages in thread
From: David Sterba @ 2018-04-16 19:15 UTC (permalink / raw)
  To: René Rebe; +Cc: dsterba, linux-btrfs

[-- Attachment #1: Type: text/plain, Size: 978 bytes --]

On Mon, Apr 16, 2018 at 09:55:45PM +0200, René Rebe wrote:
> Hi,
> 
> On 04/16/2018 06:48 PM, David Sterba wrote:
> > The warnings are valid, there's unaligned access introduced by patch
> > 
> > 23b5ec74943f44378b68c0edd8e210a86318ea5e
> > btrfs: fix readdir deadlock with pagefault
> > 
> > The directory entries (struct dir_entry) are copied to a temporary
> > buffer as they fit, ie. no alignment, and the members accessed in
> > several places.
> > 
> > The following patch adds the proper unaligned access, only compile-tested.
> > Please test and let me know, thanks!
> Would have loved to immediately give it a try, however, sorry,
> I forgot to mention I'm on the latest stable release -4.16.2-
> on a first glance this does not look like it does just apply.
> 
> I would re-base myself if I would not also have a glibc initialization 
> bug to hunt and debug, too :-/
> 
> If you happen to also rebase it for current -stable, ... ;-)

Sure, attached a 4.16.2 version.

[-- Attachment #2: 0001-test-readdir-unaligned-access.patch --]
[-- Type: text/plain, Size: 2074 bytes --]

>From 4df58593a5a42c632f1c18ced3d6fae2196e29a9 Mon Sep 17 00:00:00 2001
From: David Sterba <dsterba@suse.com>
Date: Mon, 16 Apr 2018 21:10:14 +0200
Subject: [PATCH] test readdir unaligned access

---
 fs/btrfs/inode.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index c7b75dd58fad..c2df7b158820 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -44,6 +44,7 @@
 #include <linux/uio.h>
 #include <linux/magic.h>
 #include <linux/iversion.h>
+#include <asm/unaligned.h>
 #include "ctree.h"
 #include "disk-io.h"
 #include "transaction.h"
@@ -5951,11 +5952,13 @@ static int btrfs_filldir(void *addr, int entries, struct dir_context *ctx)
 		struct dir_entry *entry = addr;
 		char *name = (char *)(entry + 1);
 
-		ctx->pos = entry->offset;
-		if (!dir_emit(ctx, name, entry->name_len, entry->ino,
-			      entry->type))
+		ctx->pos = get_unaligned(&entry->offset);
+		if (!dir_emit(ctx, name, get_unaligned(&entry->name_len),
+					get_unaligned(&entry->ino),
+					get_unaligned(&entry->type)))
 			return 1;
-		addr += sizeof(struct dir_entry) + entry->name_len;
+		addr += sizeof(struct dir_entry) +
+			get_unaligned(&entry->name_len);
 		ctx->pos++;
 	}
 	return 0;
@@ -6045,14 +6048,15 @@ static int btrfs_real_readdir(struct file *file, struct dir_context *ctx)
 		}
 
 		entry = addr;
-		entry->name_len = name_len;
+		put_unaligned(name_len, &entry->name_len);
 		name_ptr = (char *)(entry + 1);
 		read_extent_buffer(leaf, name_ptr, (unsigned long)(di + 1),
 				   name_len);
-		entry->type = btrfs_filetype_table[btrfs_dir_type(leaf, di)];
+		put_unaligned(btrfs_filetype_table[btrfs_dir_type(leaf, di)],
+				&entry->type);
 		btrfs_dir_item_key_to_cpu(leaf, di, &location);
-		entry->ino = location.objectid;
-		entry->offset = found_key.offset;
+		put_unaligned(location.objectid, &entry->ino);
+		put_unaligned(found_key.offset,&entry->offset);
 		entries++;
 		addr += sizeof(struct dir_entry) + name_len;
 		total_len += sizeof(struct dir_entry) + name_len;
-- 
2.16.2


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

* Re: Kernel unaligned access at ... btrfs_real_readdir+0x51c/0x718 [btrfs]
  2018-04-16 16:48 ` David Sterba
@ 2018-04-16 19:55   ` René Rebe
  2018-04-16 19:15     ` David Sterba
  0 siblings, 1 reply; 6+ messages in thread
From: René Rebe @ 2018-04-16 19:55 UTC (permalink / raw)
  To: dsterba, linux-btrfs

Hi,

On 04/16/2018 06:48 PM, David Sterba wrote:
> The warnings are valid, there's unaligned access introduced by patch
> 
> 23b5ec74943f44378b68c0edd8e210a86318ea5e
> btrfs: fix readdir deadlock with pagefault
> 
> The directory entries (struct dir_entry) are copied to a temporary
> buffer as they fit, ie. no alignment, and the members accessed in
> several places.
> 
> The following patch adds the proper unaligned access, only compile-tested.
> Please test and let me know, thanks!
Would have loved to immediately give it a try, however, sorry,
I forgot to mention I'm on the latest stable release -4.16.2-
on a first glance this does not look like it does just apply.

I would re-base myself if I would not also have a glibc initialization 
bug to hunt and debug, too :-/

If you happen to also rebase it for current -stable, ... ;-)

-- 
   René Rebe, ExactCODE GmbH, Lietzenburger Str. 42, DE-10789 Berlin
   https://exactcode.com | https://t2sde.org | https://rene.rebe.de

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

* Re: Kernel unaligned access at ... btrfs_real_readdir+0x51c/0x718 [btrfs]
  2018-04-16 19:15     ` David Sterba
@ 2018-04-17 10:18       ` René Rebe
  2018-04-18 13:03         ` David Sterba
  0 siblings, 1 reply; 6+ messages in thread
From: René Rebe @ 2018-04-17 10:18 UTC (permalink / raw)
  Cc: linux-btrfs

Hi,

On 16 Apr 2018, at 21:15, David Sterba <dsterba@suse.cz> wrote:

> On Mon, Apr 16, 2018 at 09:55:45PM +0200, René Rebe wrote:
>> Hi,
>> 
>> On 04/16/2018 06:48 PM, David Sterba wrote:
>>> The warnings are valid, there's unaligned access introduced by patch
>>> 
>>> 23b5ec74943f44378b68c0edd8e210a86318ea5e
>>> btrfs: fix readdir deadlock with pagefault
>>> 
>>> The directory entries (struct dir_entry) are copied to a temporary
>>> buffer as they fit, ie. no alignment, and the members accessed in
>>> several places.
>>> 
>>> The following patch adds the proper unaligned access, only compile-tested.
>>> Please test and let me know, thanks!
>> Would have loved to immediately give it a try, however, sorry,
>> I forgot to mention I'm on the latest stable release -4.16.2-
>> on a first glance this does not look like it does just apply.
>> 
>> I would re-base myself if I would not also have a glibc initialization 
>> bug to hunt and debug, too :-/
>> 
>> If you happen to also rebase it for current -stable, ... ;-)
> 
> Sure, attached a 4.16.2 version.
> <0001-test-readdir-unaligned-access.patch>

Cool, thanks, built and so far it works, the warnings are gone.

	https://www.youtube.com/watch?v=XYsKct4T2xk

Greetings form Berlin,
	René

-- 
 ExactCODE GmbH, Lietzenburger Str. 42, DE-10789 Berlin
 http://exactcode.com | http://exactscan.com | http://ocrkit.com | http://t2-project.org | http://rene.rebe.de


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

* Re: Kernel unaligned access at ... btrfs_real_readdir+0x51c/0x718 [btrfs]
  2018-04-17 10:18       ` René Rebe
@ 2018-04-18 13:03         ` David Sterba
  0 siblings, 0 replies; 6+ messages in thread
From: David Sterba @ 2018-04-18 13:03 UTC (permalink / raw)
  To: René Rebe; +Cc: linux-btrfs

On Tue, Apr 17, 2018 at 12:18:45PM +0200, René Rebe wrote:
> On 16 Apr 2018, at 21:15, David Sterba <dsterba@suse.cz> wrote:
> > On Mon, Apr 16, 2018 at 09:55:45PM +0200, René Rebe wrote:
> >> On 04/16/2018 06:48 PM, David Sterba wrote:
> >>> The warnings are valid, there's unaligned access introduced by patch
> >>> 
> >>> 23b5ec74943f44378b68c0edd8e210a86318ea5e
> >>> btrfs: fix readdir deadlock with pagefault
> >>> 
> >>> The directory entries (struct dir_entry) are copied to a temporary
> >>> buffer as they fit, ie. no alignment, and the members accessed in
> >>> several places.
> >>> 
> >>> The following patch adds the proper unaligned access, only compile-tested.
> >>> Please test and let me know, thanks!
> >> Would have loved to immediately give it a try, however, sorry,
> >> I forgot to mention I'm on the latest stable release -4.16.2-
> >> on a first glance this does not look like it does just apply.
> >> 
> >> I would re-base myself if I would not also have a glibc initialization 
> >> bug to hunt and debug, too :-/
> >> 
> >> If you happen to also rebase it for current -stable, ... ;-)
> > 
> > Sure, attached a 4.16.2 version.
> > <0001-test-readdir-unaligned-access.patch>
> 
> Cool, thanks, built and so far it works, the warnings are gone.
> 
> 	https://www.youtube.com/watch?v=XYsKct4T2xk

Thanks for testing on a real hardware! I'm not aware of regular runtime
testing on sparc, the other architectures with strict alignment
requirement have probably the emulation turned on by default so the
warnings do not appear. Or nobody bothers to report them though the
fixes are typically simple.

I like your vintage hw videos, keep going!

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

end of thread, other threads:[~2018-04-18 13:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-16 14:52 Kernel unaligned access at ... btrfs_real_readdir+0x51c/0x718 [btrfs] René Rebe
2018-04-16 16:48 ` David Sterba
2018-04-16 19:55   ` René Rebe
2018-04-16 19:15     ` David Sterba
2018-04-17 10:18       ` René Rebe
2018-04-18 13:03         ` David Sterba

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.