From: David Sterba <dsterba@suse.cz>
To: Dimitri John Ledkov <xnox@debian.org>
Cc: linux-btrfs@vger.kernel.org, Shawn Landen <shawnlandden@gmail.com>
Subject: Re: [PATCH 3/4] Fixing unaligned memory accesses.
Date: Mon, 22 Sep 2014 15:03:35 +0200 [thread overview]
Message-ID: <20140922130334.GM9715@twin.jikos.cz> (raw)
In-Reply-To: <1411261282-26831-3-git-send-email-xnox@debian.org>
On Sun, Sep 21, 2014 at 02:01:21AM +0100, Dimitri John Ledkov wrote:
> From: Shawn Landen <shawnlandden@gmail.com>
>
> Bug-Debian: http://bugs.debian.org/656955
The bug seems old (2012) and agains 0.19. We've fixed a few unaligned
access bugs in the meantime. Can you please retest with 3.16?
> --- a/ctree.h
> +++ b/ctree.h
> @@ -19,6 +19,8 @@
> #ifndef __BTRFS__
> #define __BTRFS__
>
> +#include <stdint.h>
> +
> #if BTRFS_FLAT_INCLUDES
> #include "list.h"
> #include "kerncompat.h"
> @@ -1191,13 +1193,17 @@ struct btrfs_root {
> static inline u##bits btrfs_##name(const struct extent_buffer *eb) \
> { \
> const struct btrfs_header *h = (struct btrfs_header *)eb->data; \
> - return le##bits##_to_cpu(h->member); \
> + uint##bits##_t t; \
> + memcpy(&t, &h->member, sizeof(h->member)); \
> + return le##bits##_to_cpu(t); \
The change to memcpy is safe, the compiler is smart enough to not emit
any memcpy call for x86_64 and there's no change to the leXX_to_cpu
macros.
However, I'd like to check first if this is really necessary due to the
old version in the bugreport. I'd prefer using the u8/.../u64 types
instead of the stdint.h ones, for sake of consistency with the rest of
the codebase.
> --- a/volumes.c
> +++ b/volumes.c
> @@ -472,10 +472,11 @@ static int find_next_chunk(struct btrfs_root *root, u64 objectid, u64 *offset)
> if (found_key.objectid != objectid)
> *offset = 0;
> else {
> + u64 t;
> chunk = btrfs_item_ptr(path->nodes[0], path->slots[0],
> struct btrfs_chunk);
> - *offset = found_key.offset +
> - btrfs_chunk_length(path->nodes[0], chunk);
> + t = found_key.offset + btrfs_chunk_length(path->nodes[0], chunk);
> + memcpy(offset, &t, sizeof(found_key.offset));
That's not enough, there are more direct assignments to *offset in that
function. The preferred way is to add 'put_unaligned' helper into
kerncompat.h and use it.
next prev parent reply other threads:[~2014-09-22 13:03 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-21 1:01 [PATCH 1/4] Properly cast to avoid compiler warnings, fixes FTBFS on alpha and ia64 Dimitri John Ledkov
2014-09-21 1:01 ` [PATCH 2/4] Fixes FTBFS with --no-add-needed Dimitri John Ledkov
2014-09-22 12:23 ` David Sterba
2014-09-21 1:01 ` [PATCH 3/4] Fixing unaligned memory accesses Dimitri John Ledkov
2014-09-22 13:03 ` David Sterba [this message]
2014-09-21 1:01 ` [PATCH 4/4] Default to acting like fsck Dimitri John Ledkov
2014-09-21 12:59 ` Tobias Geerinckx-Rice
2014-09-22 8:58 ` Dimitri John Ledkov
2014-09-22 13:13 ` David Sterba
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=20140922130334.GM9715@twin.jikos.cz \
--to=dsterba@suse.cz \
--cc=linux-btrfs@vger.kernel.org \
--cc=shawnlandden@gmail.com \
--cc=xnox@debian.org \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).