LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: David Miller <davem@davemloft.net>
To: chris.mason@oracle.com
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	btrfs-devel@oss.oracle.com
Subject: Re: [ANNOUNCE] Btrfs v0.12 released
Date: Sun, 10 Feb 2008 17:12:57 -0800 (PST)	[thread overview]
Message-ID: <20080210.171257.233096646.davem@davemloft.net> (raw)
In-Reply-To: <200802061200.14690.chris.mason@oracle.com>

From: Chris Mason <chris.mason@oracle.com>
Date: Wed, 6 Feb 2008 12:00:13 -0500

> So, here's v0.12.

I couldn't even make a filesystem on sparc64 without the following
patch.

The first problem is that these SETGET macros lose typing information,
and therefore can't see the 'packed' attribute and therefore take
unaligned access SIGBUS signals on sparc64 when trying to derefernce
the member.

The next problem is a similar issue in btrfs_name_hash().  This gets
passed things like &key.offset which is a member of a packed
structure, losing this packed'ness information btrfs_name_hash()
performs a potentially unaligned memory access, again resulting in a
SIGBUS.

This function never returns an error, so the simplest fix was to
return the hash value which avoids all of the issues.  In attempting
other schemes to fix this, I found it very difficult to give gcc
a packed attribute for that "u64 *" argument other than to create
some new pseudo structure which would have been ugly.

Similar code lives in the btrfs kernel code too, I'll try to get a
partition at least mounted and working minimally and if successful
I'll send you patches for that too.

diff -up --recursive --new-file vanilla/btrfs-progs-0.12/ctree.h btrfs-progs-0.12/ctree.h
--- vanilla/btrfs-progs-0.12/ctree.h	2008-02-06 08:37:45.000000000 -0800
+++ btrfs-progs-0.12/ctree.h	2008-02-10 16:53:24.000000000 -0800
@@ -451,18 +451,16 @@ static inline void btrfs_set_##name(stru
 static inline u##bits btrfs_##name(struct extent_buffer *eb,		\
 				   type *s)				\
 {									\
-	unsigned long offset = (unsigned long)s +			\
-				offsetof(type, member);			\
-	__le##bits *tmp = (__le##bits *)(eb->data + offset);		\
-	return le##bits##_to_cpu(*tmp);					\
+	unsigned long offset = (unsigned long)s;			\
+	type *p = (type *) (eb->data + offset);				\
+	return le##bits##_to_cpu(p->member);				\
 }									\
 static inline void btrfs_set_##name(struct extent_buffer *eb,		\
 				    type *s, u##bits val)		\
 {									\
-	unsigned long offset = (unsigned long)s +			\
-				offsetof(type, member);			\
-	__le##bits *tmp = (__le##bits *)(eb->data + offset);		\
-	*tmp = cpu_to_le##bits(val);					\
+	unsigned long offset = (unsigned long)s;			\
+	type *p = (type *) (eb->data + offset);				\
+	p->member = cpu_to_le##bits(val);				\
 }
 
 #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits)		\
diff -up --recursive --new-file vanilla/btrfs-progs-0.12/dir-item.c btrfs-progs-0.12/dir-item.c
--- vanilla/btrfs-progs-0.12/dir-item.c	2008-02-06 08:37:45.000000000 -0800
+++ btrfs-progs-0.12/dir-item.c	2008-02-10 17:03:34.000000000 -0800
@@ -71,8 +71,7 @@ int btrfs_insert_xattr_item(struct btrfs
 
 	key.objectid = dir;
 	btrfs_set_key_type(&key, BTRFS_XATTR_ITEM_KEY);
-	ret = btrfs_name_hash(name, name_len, &key.offset);
-	BUG_ON(ret);
+	key.offset = btrfs_name_hash(name, name_len);
 	path = btrfs_alloc_path();
 	if (!path)
 		return -ENOMEM;
@@ -122,8 +121,7 @@ int btrfs_insert_dir_item(struct btrfs_t
 
 	key.objectid = dir;
 	btrfs_set_key_type(&key, BTRFS_DIR_ITEM_KEY);
-	ret = btrfs_name_hash(name, name_len, &key.offset);
-	BUG_ON(ret);
+	key.offset = btrfs_name_hash(name, name_len);
 	path = btrfs_alloc_path();
 	data_size = sizeof(*dir_item) + name_len;
 	dir_item = insert_with_overflow(trans, root, path, &key, data_size,
@@ -196,8 +194,7 @@ struct btrfs_dir_item *btrfs_lookup_dir_
 	key.objectid = dir;
 	btrfs_set_key_type(&key, BTRFS_DIR_ITEM_KEY);
 
-	ret = btrfs_name_hash(name, name_len, &key.offset);
-	BUG_ON(ret);
+	key.offset = btrfs_name_hash(name, name_len);
 
 	ret = btrfs_search_slot(trans, root, &key, path, ins_len, cow);
 	if (ret < 0)
@@ -258,8 +255,7 @@ struct btrfs_dir_item *btrfs_lookup_xatt
 
 	key.objectid = dir;
 	btrfs_set_key_type(&key, BTRFS_XATTR_ITEM_KEY);
-	ret = btrfs_name_hash(name, name_len, &key.offset);
-	BUG_ON(ret);
+	key.offset = btrfs_name_hash(name, name_len);
 	ret = btrfs_search_slot(trans, root, &key, path, ins_len, cow);
 	if (ret < 0)
 		return ERR_PTR(ret);
diff -up --recursive --new-file vanilla/btrfs-progs-0.12/dir-test.c btrfs-progs-0.12/dir-test.c
--- vanilla/btrfs-progs-0.12/dir-test.c	2008-02-06 08:37:45.000000000 -0800
+++ btrfs-progs-0.12/dir-test.c	2008-02-10 17:03:49.000000000 -0800
@@ -129,8 +129,8 @@ error:
 				    struct btrfs_dir_item);
 		found = (char *)(di + 1);
 		found_len = btrfs_dir_name_len(di);
-		btrfs_name_hash(buf, strlen(buf), &myhash);
-		btrfs_name_hash(found, found_len, &foundhash);
+		myhash = btrfs_name_hash(buf, strlen(buf));
+		foundhash = btrfs_name_hash(found, found_len);
 		if (myhash != foundhash)
 			goto fatal_release;
 		btrfs_release_path(root, &path);
diff -up --recursive --new-file vanilla/btrfs-progs-0.12/hash.c btrfs-progs-0.12/hash.c
--- vanilla/btrfs-progs-0.12/hash.c	2008-02-06 08:37:45.000000000 -0800
+++ btrfs-progs-0.12/hash.c	2008-02-10 17:02:36.000000000 -0800
@@ -75,12 +75,13 @@ static void str2hashbuf(const char *msg,
 		*buf++ = pad;
 }
 
-int btrfs_name_hash(const char *name, int len, u64 *hash_result)
+u64 btrfs_name_hash(const char *name, int len)
 {
 	__u32	hash;
 	__u32	minor_hash = 0;
 	const char	*p;
 	__u32		in[8], buf[2];
+	u64		hash_result;
 
 	/* Initialize the default seed for the hash checksum functions */
 	buf[0] = 0x67452301;
@@ -97,8 +98,8 @@ int btrfs_name_hash(const char *name, in
 	}
 	hash = buf[0];
 	minor_hash = buf[1];
-	*hash_result = buf[0];
-	*hash_result <<= 32;
-	*hash_result |= buf[1];
-	return 0;
+	hash_result = buf[0];
+	hash_result <<= 32;
+	hash_result |= buf[1];
+	return hash_result;
 }
diff -up --recursive --new-file vanilla/btrfs-progs-0.12/hash.h btrfs-progs-0.12/hash.h
--- vanilla/btrfs-progs-0.12/hash.h	2008-02-06 08:37:45.000000000 -0800
+++ btrfs-progs-0.12/hash.h	2008-02-10 17:02:21.000000000 -0800
@@ -18,5 +18,5 @@
 
 #ifndef __HASH__
 #define __HASH__
-int btrfs_name_hash(const char *name, int len, u64 *hash_result);
+u64 btrfs_name_hash(const char *name, int len);
 #endif
diff -up --recursive --new-file vanilla/btrfs-progs-0.12/hasher.c btrfs-progs-0.12/hasher.c
--- vanilla/btrfs-progs-0.12/hasher.c	2008-02-06 08:37:45.000000000 -0800
+++ btrfs-progs-0.12/hasher.c	2008-02-10 17:04:04.000000000 -0800
@@ -35,8 +35,7 @@ int main() {
 			continue;
 		if (line[strlen(line)-1] == '\n')
 			line[strlen(line)-1] = '\0';
-		ret = btrfs_name_hash(line, strlen(line), &result);
-		BUG_ON(ret);
+		result = btrfs_name_hash(line, strlen(line));
 		printf("hash returns %llu\n", (unsigned long long)result);
 	}
 	return 0;

  reply	other threads:[~2008-02-11  1:12 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-06 17:00 Chris Mason
2008-02-11  1:12 ` David Miller [this message]
2008-02-11 13:42   ` Chris Mason
2008-02-12  6:43     ` David Miller
2008-02-12 13:43       ` Chris Mason
2008-02-12  7:21 ` BTRFS partition usage David Miller
2008-02-12  8:11   ` David Miller
2008-02-12 13:49     ` Chris Mason
2008-02-12 14:00       ` Jan Engelhardt
2008-02-12 14:08         ` Chris Mason
2008-02-12 14:21           ` Jan Engelhardt
2008-02-12 14:35             ` Chris Mason
2008-02-12 15:04               ` Jan Engelhardt
2008-02-12 16:17                 ` Chris Mason
2008-02-12 23:38                 ` David Miller
2008-02-12 23:42                   ` Jan Engelhardt
2008-02-13  1:09                     ` David Miller
2008-02-13  1:22                     ` Rene Herman
2008-02-12 23:35               ` David Miller
2008-02-13  7:02                 ` Christoph Hellwig
2008-02-12 23:34             ` David Miller
2008-02-12 23:33           ` David Miller
2008-02-13  2:10             ` Jeff Garzik
2008-02-14  0:51               ` Szabolcs Szakacsits
2008-02-12 23:26         ` David Miller
2008-02-12 23:39           ` Jan Engelhardt
2008-02-13  1:08             ` David Miller
2008-02-13  1:25           ` Bryan Henderson
2008-02-12 23:28         ` David Miller
2008-02-13  0:45           ` Theodore Tso
2008-02-12 20:50       ` David Miller
2008-02-12  9:23 ` CRC32C big endian bugs David Miller
2008-02-12 21:55 ` BTRFS only works with PAGE_SIZE <= 4K David Miller
2008-02-12 22:03   ` Chris Mason

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080210.171257.233096646.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=btrfs-devel@oss.oracle.com \
    --cc=chris.mason@oracle.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --subject='Re: [ANNOUNCE] Btrfs v0.12 released' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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).