* [Cluster-devel] [PATCH] gfs2: Avoid alignment hole in struct lm_lockname
@ 2017-03-06 14:33 Andreas Gruenbacher
2017-03-06 15:10 ` Bob Peterson
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Andreas Gruenbacher @ 2017-03-06 14:33 UTC (permalink / raw)
To: cluster-devel.redhat.com
Commit 88ffbf3e03 switches to using rhashtables for glocks, hashing over
the entire struct lm_lockname instead of its individual fields. On some
architectures, struct lm_lockname contains a hole of uninitialized
memory due to alignment rules, which now leads to incorrect hash values.
Get rid of that hole.
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
CC: <stable@vger.kernel.org> #v4.3+
---
fs/gfs2/incore.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h
index c45084a..511e1ed 100644
--- a/fs/gfs2/incore.h
+++ b/fs/gfs2/incore.h
@@ -207,7 +207,7 @@ struct lm_lockname {
struct gfs2_sbd *ln_sbd;
u64 ln_number;
unsigned int ln_type;
-};
+} __packed __aligned(sizeof(int));
#define lm_name_equal(name1, name2) \
(((name1)->ln_number == (name2)->ln_number) && \
--
2.7.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [Cluster-devel] [PATCH] gfs2: Avoid alignment hole in struct lm_lockname
2017-03-06 14:33 [Cluster-devel] [PATCH] gfs2: Avoid alignment hole in struct lm_lockname Andreas Gruenbacher
@ 2017-03-06 15:10 ` Bob Peterson
2017-03-06 15:15 ` Steven Whitehouse
2017-03-06 18:27 ` Bob Peterson
2 siblings, 0 replies; 9+ messages in thread
From: Bob Peterson @ 2017-03-06 15:10 UTC (permalink / raw)
To: cluster-devel.redhat.com
----- Original Message -----
| Commit 88ffbf3e03 switches to using rhashtables for glocks, hashing over
| the entire struct lm_lockname instead of its individual fields. On some
| architectures, struct lm_lockname contains a hole of uninitialized
| memory due to alignment rules, which now leads to incorrect hash values.
| Get rid of that hole.
|
| Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
| CC: <stable@vger.kernel.org> #v4.3+
| ---
| fs/gfs2/incore.h | 2 +-
| 1 file changed, 1 insertion(+), 1 deletion(-)
|
| diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h
| index c45084a..511e1ed 100644
| --- a/fs/gfs2/incore.h
| +++ b/fs/gfs2/incore.h
| @@ -207,7 +207,7 @@ struct lm_lockname {
| struct gfs2_sbd *ln_sbd;
| u64 ln_number;
| unsigned int ln_type;
| -};
| +} __packed __aligned(sizeof(int));
|
| #define lm_name_equal(name1, name2) \
| (((name1)->ln_number == (name2)->ln_number) && \
| --
| 2.7.4
|
|
Hi,
Looks good. I've tested it as well.
Signed-off-by: Bob Peterson <rpeterso@redhat.com>
Regards,
Bob Peterson
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Cluster-devel] [PATCH] gfs2: Avoid alignment hole in struct lm_lockname
2017-03-06 14:33 [Cluster-devel] [PATCH] gfs2: Avoid alignment hole in struct lm_lockname Andreas Gruenbacher
2017-03-06 15:10 ` Bob Peterson
@ 2017-03-06 15:15 ` Steven Whitehouse
2017-03-06 16:55 ` Andreas Gruenbacher
2017-03-06 18:27 ` Bob Peterson
2 siblings, 1 reply; 9+ messages in thread
From: Steven Whitehouse @ 2017-03-06 15:15 UTC (permalink / raw)
To: cluster-devel.redhat.com
Hi,
On 06/03/17 14:33, Andreas Gruenbacher wrote:
> Commit 88ffbf3e03 switches to using rhashtables for glocks, hashing over
> the entire struct lm_lockname instead of its individual fields. On some
> architectures, struct lm_lockname contains a hole of uninitialized
> memory due to alignment rules, which now leads to incorrect hash values.
> Get rid of that hole.
>
> Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
> CC: <stable@vger.kernel.org> #v4.3+
> ---
> fs/gfs2/incore.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h
> index c45084a..511e1ed 100644
> --- a/fs/gfs2/incore.h
> +++ b/fs/gfs2/incore.h
> @@ -207,7 +207,7 @@ struct lm_lockname {
> struct gfs2_sbd *ln_sbd;
> u64 ln_number;
> unsigned int ln_type;
> -};
> +} __packed __aligned(sizeof(int));
>
> #define lm_name_equal(name1, name2) \
> (((name1)->ln_number == (name2)->ln_number) && \
I'm still not sure that this is the best solution. Also, either it
should be packed or aligned to a certain size, I'm not sure how it can
be both? Changing the alignment may cause access issues on some arches.
I think it would be better just to initialize the structure to zero when
we allocate a new glock, that will ensure that the padding is always
zeroed, without changing the alignment,
Steve.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Cluster-devel] [PATCH] gfs2: Avoid alignment hole in struct lm_lockname
2017-03-06 15:15 ` Steven Whitehouse
@ 2017-03-06 16:55 ` Andreas Gruenbacher
2017-03-06 17:43 ` Steven Whitehouse
0 siblings, 1 reply; 9+ messages in thread
From: Andreas Gruenbacher @ 2017-03-06 16:55 UTC (permalink / raw)
To: cluster-devel.redhat.com
On Mon, Mar 6, 2017 at 4:15 PM, Steven Whitehouse <swhiteho@redhat.com> wrote:
> On 06/03/17 14:33, Andreas Gruenbacher wrote:
>>
>> Commit 88ffbf3e03 switches to using rhashtables for glocks, hashing over
>> the entire struct lm_lockname instead of its individual fields. On some
>> architectures, struct lm_lockname contains a hole of uninitialized
>> memory due to alignment rules, which now leads to incorrect hash values.
>> Get rid of that hole.
>>
>> Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
>> CC: <stable@vger.kernel.org> #v4.3+
>> ---
>> fs/gfs2/incore.h | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h
>> index c45084a..511e1ed 100644
>> --- a/fs/gfs2/incore.h
>> +++ b/fs/gfs2/incore.h
>> @@ -207,7 +207,7 @@ struct lm_lockname {
>> struct gfs2_sbd *ln_sbd;
>> u64 ln_number;
>> unsigned int ln_type;
>> -};
>> +} __packed __aligned(sizeof(int));
>> #define lm_name_equal(name1, name2) \
>> (((name1)->ln_number == (name2)->ln_number) && \
>
> I'm still not sure that this is the best solution. Also, either it should be
> packed or aligned to a certain size, I'm not sure how it can be both?
Well, the size of struct lm_lockname is 20 in either case. With a
__packed struct lm_lockname *p, gcc will generate code that assumes no
alignment for p->ln_number and p->ln_type accesses. With a __packed,
__aligned(sizeof(int)) struct lm_lockname *p, gcc will generate code
that assumes int alignment. That's probably irrelevant on all
architectures except SPARC, but it doesn't hurt.
> Changing the alignment may cause access issues on some arches.
It could when working with pointers to elements of struct lm_lockname
without being careful. That's not happening, and it's unlikely to
happen in the future, though.
> I think it
> would be better just to initialize the structure to zero when we allocate a
> new glock, that will ensure that the padding is always zeroed, without
> changing the alignment,
That's a possibility. We'd always needlessly hash four bytes of zeroes, though.
Thanks,
Andreas
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Cluster-devel] [PATCH] gfs2: Avoid alignment hole in struct lm_lockname
2017-03-06 16:55 ` Andreas Gruenbacher
@ 2017-03-06 17:43 ` Steven Whitehouse
0 siblings, 0 replies; 9+ messages in thread
From: Steven Whitehouse @ 2017-03-06 17:43 UTC (permalink / raw)
To: cluster-devel.redhat.com
Hi,
On 06/03/17 16:55, Andreas Gruenbacher wrote:
> On Mon, Mar 6, 2017 at 4:15 PM, Steven Whitehouse <swhiteho@redhat.com> wrote:
>> On 06/03/17 14:33, Andreas Gruenbacher wrote:
>>> Commit 88ffbf3e03 switches to using rhashtables for glocks, hashing over
>>> the entire struct lm_lockname instead of its individual fields. On some
>>> architectures, struct lm_lockname contains a hole of uninitialized
>>> memory due to alignment rules, which now leads to incorrect hash values.
>>> Get rid of that hole.
>>>
>>> Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
>>> CC: <stable@vger.kernel.org> #v4.3+
>>> ---
>>> fs/gfs2/incore.h | 2 +-
>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h
>>> index c45084a..511e1ed 100644
>>> --- a/fs/gfs2/incore.h
>>> +++ b/fs/gfs2/incore.h
>>> @@ -207,7 +207,7 @@ struct lm_lockname {
>>> struct gfs2_sbd *ln_sbd;
>>> u64 ln_number;
>>> unsigned int ln_type;
>>> -};
>>> +} __packed __aligned(sizeof(int));
>>> #define lm_name_equal(name1, name2) \
>>> (((name1)->ln_number == (name2)->ln_number) && \
>> I'm still not sure that this is the best solution. Also, either it should be
>> packed or aligned to a certain size, I'm not sure how it can be both?
> Well, the size of struct lm_lockname is 20 in either case. With a
> __packed struct lm_lockname *p, gcc will generate code that assumes no
> alignment for p->ln_number and p->ln_type accesses. With a __packed,
> __aligned(sizeof(int)) struct lm_lockname *p, gcc will generate code
> that assumes int alignment. That's probably irrelevant on all
> architectures except SPARC, but it doesn't hurt.
>
>> Changing the alignment may cause access issues on some arches.
> It could when working with pointers to elements of struct lm_lockname
> without being careful. That's not happening, and it's unlikely to
> happen in the future, though.
Yes, we should not need pointers to ln_type, since it would be at least
as large as the info itself, so it would be a bit strange, I agree. It
does look at bit odd like that though.
>> I think it
>> would be better just to initialize the structure to zero when we allocate a
>> new glock, that will ensure that the padding is always zeroed, without
>> changing the alignment,
> That's a possibility. We'd always needlessly hash four bytes of zeroes, though.
>
> Thanks,
> Andreas
Yes, we don't really want to take that hit either.... perhaps we'll have
to live with the alignment thing...
Steve.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Cluster-devel] [PATCH] gfs2: Avoid alignment hole in struct lm_lockname
2017-03-06 14:33 [Cluster-devel] [PATCH] gfs2: Avoid alignment hole in struct lm_lockname Andreas Gruenbacher
2017-03-06 15:10 ` Bob Peterson
2017-03-06 15:15 ` Steven Whitehouse
@ 2017-03-06 18:27 ` Bob Peterson
2017-03-15 11:24 ` Andrew Price
2 siblings, 1 reply; 9+ messages in thread
From: Bob Peterson @ 2017-03-06 18:27 UTC (permalink / raw)
To: cluster-devel.redhat.com
----- Original Message -----
| Commit 88ffbf3e03 switches to using rhashtables for glocks, hashing over
| the entire struct lm_lockname instead of its individual fields. On some
| architectures, struct lm_lockname contains a hole of uninitialized
| memory due to alignment rules, which now leads to incorrect hash values.
| Get rid of that hole.
|
| Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
| CC: <stable@vger.kernel.org> #v4.3+
| ---
Hi,
Thanks. This is now applied to the for-next branch of the linux-gfs2 tree:
https://git.kernel.org/cgit/linux/kernel/git/gfs2/linux-gfs2.git/commit/?h=for-next&id=415730e5de2361518a2d884c0f64de37c5bfefeb
Regards,
Bob Peterson
Red Hat File Systems
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Cluster-devel] [PATCH] gfs2: Avoid alignment hole in struct lm_lockname
2017-03-06 18:27 ` Bob Peterson
@ 2017-03-15 11:24 ` Andrew Price
2017-03-15 11:41 ` Andreas Gruenbacher
0 siblings, 1 reply; 9+ messages in thread
From: Andrew Price @ 2017-03-15 11:24 UTC (permalink / raw)
To: cluster-devel.redhat.com
On 06/03/17 18:27, Bob Peterson wrote:
> ----- Original Message -----
> | Commit 88ffbf3e03 switches to using rhashtables for glocks, hashing over
> | the entire struct lm_lockname instead of its individual fields. On some
> | architectures, struct lm_lockname contains a hole of uninitialized
> | memory due to alignment rules, which now leads to incorrect hash values.
> | Get rid of that hole.
> |
> | Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
> | CC: <stable@vger.kernel.org> #v4.3+
> | ---
> Hi,
>
> Thanks. This is now applied to the for-next branch of the linux-gfs2 tree:
> https://git.kernel.org/cgit/linux/kernel/git/gfs2/linux-gfs2.git/commit/?h=for-next&id=415730e5de2361518a2d884c0f64de37c5bfefeb
Will this get sent to Linus in the 4.11 cycle or is it being held for
the 4.12 merge window?
Andy
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Cluster-devel] [PATCH] gfs2: Avoid alignment hole in struct lm_lockname
2017-03-15 11:24 ` Andrew Price
@ 2017-03-15 11:41 ` Andreas Gruenbacher
2017-03-15 14:34 ` Bob Peterson
0 siblings, 1 reply; 9+ messages in thread
From: Andreas Gruenbacher @ 2017-03-15 11:41 UTC (permalink / raw)
To: cluster-devel.redhat.com
On Wed, Mar 15, 2017 at 12:24 PM, Andrew Price <anprice@redhat.com> wrote:
> Will this get sent to Linus in the 4.11 cycle or is it being held for the
> 4.12 merge window?
This causes potential filesystem corruption, so it should go into
4.11. Bob has put it in for-next to give it some exposure but I don't
think he's sent Linus a pull request, yet.
Andreas
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Cluster-devel] [PATCH] gfs2: Avoid alignment hole in struct lm_lockname
2017-03-15 11:41 ` Andreas Gruenbacher
@ 2017-03-15 14:34 ` Bob Peterson
0 siblings, 0 replies; 9+ messages in thread
From: Bob Peterson @ 2017-03-15 14:34 UTC (permalink / raw)
To: cluster-devel.redhat.com
----- Original Message -----
| On Wed, Mar 15, 2017 at 12:24 PM, Andrew Price <anprice@redhat.com> wrote:
| > Will this get sent to Linus in the 4.11 cycle or is it being held for the
| > 4.12 merge window?
|
| This causes potential filesystem corruption, so it should go into
| 4.11. Bob has put it in for-next to give it some exposure but I don't
| think he's sent Linus a pull request, yet.
|
| Andreas
|
Hi Guys,
I just sent Linus a pull request for this. Sorry it took so long.
Bob
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2017-03-15 14:34 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-06 14:33 [Cluster-devel] [PATCH] gfs2: Avoid alignment hole in struct lm_lockname Andreas Gruenbacher
2017-03-06 15:10 ` Bob Peterson
2017-03-06 15:15 ` Steven Whitehouse
2017-03-06 16:55 ` Andreas Gruenbacher
2017-03-06 17:43 ` Steven Whitehouse
2017-03-06 18:27 ` Bob Peterson
2017-03-15 11:24 ` Andrew Price
2017-03-15 11:41 ` Andreas Gruenbacher
2017-03-15 14:34 ` Bob Peterson
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).