From: NeilBrown <neilb@suse.com>
To: James Clarke <jrtc27@jrtc27.com>
Cc: linux-raid@vger.kernel.org,
debian-sparc <debian-sparc@lists.debian.org>,
Jes Sorensen <Jes.Sorensen@redhat.com>
Subject: Re: [PATCH] Fix bus error when accessing MBR partition records
Date: Wed, 05 Oct 2016 13:21:08 +1100 [thread overview]
Message-ID: <871szv5yej.fsf@notabene.neil.brown.name> (raw)
In-Reply-To: <CB9B156B-28E1-4EDE-9738-9B03ECC60291@jrtc27.com>
[-- Attachment #1: Type: text/plain, Size: 2349 bytes --]
On Mon, Oct 03 2016, James Clarke wrote:
> Hi Neil,
>
>> On 2 Oct 2016, at 23:32, NeilBrown <neilb@suse.com> wrote:
>>
>>> On Thu, Sep 29 2016, James Clarke wrote:
>>>
>>> Since the MBR layout only has partition records as 2-byte aligned, the 32-bit
>>> fields in them are not aligned. Thus, they cannot be accessed on some
>>> architectures (such as SPARC) by using a "struct MBR_part_record *" pointer,
>>> as the compiler can assume that the pointer is properly aligned. Instead, the
>>> records must be accessed by going through the MBR struct itself every time.
>>
>> Weird....
>>
>> Can you see if adding "__attribute__((packed))" to struct
>> MBR_part_record also fixes the problem?
>
> That also works. When I wrote the patch initially, I wasn’t sure if it was a
> "correct" fix, but having looked into it more I *believe* it is conformant. The
> alignment of a packed struct is 1-byte, so, while the compiler may know that the
> 32-bit fields are 8-byte aligned within the struct, the pointer to the struct
> need not be aligned, and so the correct conservative code is generated.
>
>> It seems strange that the compiler lets you take a pointer, but then
>> doesn't use it correctly. Maybe it is an inconsistency in the types.
>
> Yes, the type doesn’t include the provenance of the pointer, so in general the
> compiler can’t know it came from a packed struct (although in this case not much
> static analysis would be needed). See [1] and [2].
>
>> I don't necessarily disagree with your fix, but I'd like to understand
>> why the current code is wrong.
>
> Hopefully the links make it clearer.
>
> Regards,
> James
>
> [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51628
> [2] https://llvm.org/bugs/show_bug.cgi?id=22821
Thanks.
It looks as though the type change I suggested would work, but probably isn't
the best solution.
Your patch is probably safest, though adding the __attribute__((packed))
as well wouldn't hurt.
I'll leave it for Jes to decide what exactly to apply, but I can offer
a
Reviewed-by: NeilBrown <neilb@suse.com>
for you patch.
BTW I tried compiling mdadm with clang to see if my clang was new enough
to give a warning (it isn't) but it found a few other things to give
errors about ... I should post patches.
Thanks,
NeilBrown
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 800 bytes --]
next prev parent reply other threads:[~2016-10-05 2:21 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-29 12:28 [PATCH] Fix bus error when accessing MBR partition records James Clarke
2016-10-02 22:32 ` NeilBrown
2016-10-02 23:00 ` James Clarke
2016-10-05 2:21 ` NeilBrown [this message]
2016-10-07 15:14 ` Jes Sorensen
2016-10-17 20:16 ` [PATCH v2] " James Clarke
2016-10-19 16:33 ` Jes Sorensen
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=871szv5yej.fsf@notabene.neil.brown.name \
--to=neilb@suse.com \
--cc=Jes.Sorensen@redhat.com \
--cc=debian-sparc@lists.debian.org \
--cc=jrtc27@jrtc27.com \
--cc=linux-raid@vger.kernel.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).