From: Lars Ellenberg <lars.ellenberg@linbit.com>
To: drbd-dev@lists.linbit.com
Subject: Re: [Drbd-dev] history uuids misaligned within device_statistics
Date: Mon, 24 Jun 2019 17:35:42 +0200 [thread overview]
Message-ID: <20190624153542.GT30528@soda.linbit> (raw)
In-Reply-To: <2f0bb666-e3bf-1f38-025a-910b7a37ac1e@gmail.com>
On Tue, Jun 18, 2019 at 12:16:45AM -0600, David Butterfield wrote:
> I should clarify that I observed the history_uuids misalignment as a runtime error from libubsan:
>
> drbd_nl.c:5091:21: runtime error: store to misaligned address 0x7fc223ffd33c for type 'u64', which requires 8 byte alignment
> 0x7fc223ffd33c: note: pointer points here
> 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
> ^
>
> 5076 static void device_to_statistics(struct device_statistics *s,
> 5077 struct drbd_device *device)
> ...
> 5090 for (n = 0; n < ARRAY_SIZE(md->history_uuids); n++)
> 5091 history_uuids[n] = md->history_uuids[n];
>
> The history_uuids are declared with __bin_field() which does not appear to specify an alignment.
> It happens to follow a 32-bit field, so that's where it lands.
> >> 272 __bin_field(14, 0, history_uuids, HISTORY_UUIDS * sizeof(__u64))
Right, this comes out as a char[HISTORY_UUIDS * sizeof(__u64)],
and as such won't have an alignment... okay.
So maybe we should instead do memcpy?
diff --git a/drbd/drbd_nl.c b/drbd/drbd_nl.c
index adeb04e4..f77df9da 100644
--- a/drbd/drbd_nl.c
+++ b/drbd/drbd_nl.c
@@ -5074,15 +5074,13 @@ static void device_to_statistics(struct device_statistics *s,
s->dev_upper_blocked = !may_inc_ap_bio(device);
if (get_ldev(device)) {
struct drbd_md *md = &device->ldev->md;
- u64 *history_uuids = (u64 *)s->history_uuids;
struct request_queue *q;
int n;
spin_lock_irq(&md->uuid_lock);
s->dev_current_uuid = md->current_uuid;
BUILD_BUG_ON(sizeof(s->history_uuids) != sizeof(md->history_uuids));
- for (n = 0; n < ARRAY_SIZE(md->history_uuids); n++)
- history_uuids[n] = md->history_uuids[n];
+ memcpy(s->history_uuids, md->history_uuids, sizeof(s->history_uuids));
s->history_uuids_len = sizeof(s->history_uuids);
spin_unlock_irq(&md->uuid_lock);
Or come up with a "__u64_array()" field type,
that would add an __attribute__((aligned(8)))?
--
: Lars Ellenberg
: LINBIT | Keeping the Digital World Running
: DRBD -- Heartbeat -- Corosync -- Pacemaker
: R&D, Integration, Ops, Consulting, Support
DRBD® and LINBIT® are registered trademarks of LINBIT
prev parent reply other threads:[~2019-06-24 15:35 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-31 19:01 [Drbd-dev] drbd_nl.c:drbd_adm_prepare() indexes drbd_genl_ops[] by cmd number David Butterfield
2019-06-03 9:21 ` Lars Ellenberg
[not found] ` <cf05cd9c-687f-6264-0bc3-aefa90c91b3a@gmail.com>
[not found] ` <CANr6vz8kxacCYSb38G464Y2c1xw1ZqZAddN45LTwEcnE_Y2dsA@mail.gmail.com>
2019-06-04 8:18 ` David Butterfield
2019-06-04 9:41 ` Lars Ellenberg
2019-06-04 9:49 ` Lars Ellenberg
2019-06-05 15:57 ` [Drbd-dev] history uuids misaligned within device_statistics David Butterfield
2019-06-12 13:58 ` Lars Ellenberg
2019-06-18 6:16 ` David Butterfield
2019-06-24 15:35 ` Lars Ellenberg [this message]
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=20190624153542.GT30528@soda.linbit \
--to=lars.ellenberg@linbit.com \
--cc=drbd-dev@lists.linbit.com \
/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 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.