Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Brian Starkey <brian.starkey@arm.com>
To: Daniel Stone <daniel@fooishbar.org>
Cc: Ben Widawsky <ben@bwidawsk.net>,
	"Kristian H . Kristensen" <hoegsberg@gmail.com>,
	Intel GFX <intel-gfx@lists.freedesktop.org>,
	DRI Development <dri-devel@lists.freedesktop.org>
Subject: Re: [PATCH 2/3] drm: Create a format/modifier blob
Date: Wed, 3 May 2017 15:03:22 +0100	[thread overview]
Message-ID: <20170503140322.GC20378@e106950-lin.cambridge.arm.com> (raw)
In-Reply-To: <CAPj87rPodbdWPL5vc7UsaLzufTuZL9XnMHEb_Aac5TMCC6qeYA@mail.gmail.com>

On Wed, May 03, 2017 at 02:51:18PM +0100, Daniel Stone wrote:
>Hi Brian,
>
>On 3 May 2017 at 13:51, Brian Starkey <brian.starkey@arm.com> wrote:
>> On Tue, May 02, 2017 at 10:14:27PM -0700, Ben Widawsky wrote:
>>> +       modifiers_size =
>>> +               sizeof(struct drm_format_modifier) *
>>> format_modifier_count;
>>> +
>>> +       blob_size = ALIGN(sizeof(struct drm_format_modifier_blob), 8);
>>> +       blob_size += ALIGN(formats_size, 8);
>>> +       blob_size += modifiers_size;
>>> +
>>> +       blob = drm_property_create_blob(dev, blob_size, NULL);
>>> +       if (IS_ERR(blob))
>>> +               return -1;
>>> +
>>> +       blob_data = (struct drm_format_modifier_blob *)blob->data;
>>> +       blob_data->version = FORMAT_BLOB_CURRENT;
>>> +       blob_data->count_formats = format_count;
>>> +       blob_data->formats_offset = sizeof(struct
>>> drm_format_modifier_blob);
>>
>> This looks to be missing some alignment.
>>
>> Definitely needs to be at least to 4 bytes, but given you aligned
>> it up to 8 for the initial "blob_size" I assume the intention was to
>> put the formats on the next 8-byte aligned address after the end of
>> the struct, e.g.:
>>
>>         blob_data->formats_offset = ALIGN(sizeof(struct
>> drm_format_modifier_blob), 8);
>
>It's fairly subtle, but I think it's correct.

It's the exact subtlety that I was concerned about.

>
>formats_offset is the end of the fixed-size element, which is
>currently aligned to 32 bytes, and practically speaking would always
>have to be anyway. As it is an array of uint32_t, this gives natural
>alignment.

Why must it always be? The __packed attribute means it'll have no
padding - so any u16 or u8 added to the end will break it - putting
the formats array on a non-aligned boundary.

If the assumption is that the struct will always be made of only
u32/u64 members (and the implementation will break otherwise) then
there had better be a really big comment saying so, and preferably a
compile-time assertion too.

I'm missing the reason for it being __packed in the first place -
perhaps that's just a left over and needs to be removed.

Either way, this line aligns to 8:

+       blob_size = ALIGN(sizeof(struct drm_format_modifier_blob), 8);

...and the rest of the blob_size calculation looks like it assumes the
formats array starts at that 8-byte boundary. So, for clarity and
consistency I reckon the blob_size code and the code that builds the
blob should do the same thing.

Cheers,
-Brian

>
>If we have an odd number of formats supported, the formats[] array
>will end on a 4-byte rather than 8-byte boundary, so the ALIGN() on
>formats_size guarantees that modifiers_offset will be aligned to an
>8-byte quantity, which is required as it has 64-bit elements.
>
>The size of a pointer is not relevant since we're not passing pointers
>across the kernel/userspace boundary, just offsets within a struct.
>The alignment of those offsets has to correspond to the types located
>at those offsets, i.e. 4 bytes for formats (guaranteed by fixed header
>layout), and 8 bytes for modifiers (guaranteed by explicit alignment).
>
>Cheers,
>Daniel
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2017-05-03 14:03 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-03  5:14 [PATCH 1/3] drm: Plumb modifiers through plane init Ben Widawsky
2017-05-03  5:14 ` [PATCH 2/3] drm: Create a format/modifier blob Ben Widawsky
2017-05-03 11:00   ` Brian Starkey
2017-05-03 11:47     ` Daniel Stone
2017-05-03 12:39       ` Brian Starkey
2017-05-03 12:51   ` Brian Starkey
2017-05-03 13:51     ` [Intel-gfx] " Daniel Stone
2017-05-03 14:03       ` Brian Starkey [this message]
2017-05-03 14:07         ` Daniel Stone
2017-05-03 14:17           ` Brian Starkey
2017-05-03 13:15   ` Liviu Dudau
2017-05-11 17:58     ` Ben Widawsky
2017-05-03 13:32   ` Emil Velikov
2017-05-03 15:08   ` Daniel Vetter
2017-05-16 21:19     ` [Intel-gfx] " Ben Widawsky
2017-05-17 11:31       ` Daniel Vetter
2017-05-17 15:12         ` Daniel Vetter
2017-05-18  0:00         ` Ben Widawsky
2017-05-18  0:38           ` Rob Clark
2017-05-18  0:42             ` [Intel-gfx] " Rob Clark
2017-05-04  9:28   ` Daniel Stone
2017-05-03  5:14 ` [PATCH 3/3] drm/i915: Add format modifiers for Intel Ben Widawsky
2017-05-03  5:30 ` ✓ Fi.CI.BAT: success for series starting with [1/3] drm: Plumb modifiers through plane init Patchwork
2017-05-03 10:34 ` [PATCH 1/3] " Liviu Dudau
2017-05-03 13:45   ` [Intel-gfx] " Daniel Stone
2017-05-03 14:07     ` Liviu Dudau
2017-05-03 14:14       ` Daniel Stone
2017-05-03 14:52         ` Liviu Dudau
2017-05-03 16:45           ` Daniel Vetter
2017-05-03 17:30             ` [Intel-gfx] " Liviu Dudau
2017-05-10 16:34               ` Ben Widawsky
2017-05-10 17:24                 ` Liviu Dudau
2017-05-10 19:33                   ` [Intel-gfx] " Ben Widawsky
2017-05-10 20:21                     ` Liviu Dudau
2017-05-10 16:33     ` Ben Widawsky
2017-05-03 18:28 ` kbuild test robot
2017-05-03 18:48 ` kbuild test robot

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=20170503140322.GC20378@e106950-lin.cambridge.arm.com \
    --to=brian.starkey@arm.com \
    --cc=ben@bwidawsk.net \
    --cc=daniel@fooishbar.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hoegsberg@gmail.com \
    --cc=intel-gfx@lists.freedesktop.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