linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kieran Bingham <kieran.bingham@ideasonboard.com>
To: David Laight <David.Laight@ACULAB.COM>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	"linux-renesas-soc@vger.kernel.org"
	<linux-renesas-soc@vger.kernel.org>,
	"linux-media@vger.kernel.org" <linux-media@vger.kernel.org>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
	open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 02/11] media: vsp1: use kernel __packed for structures
Date: Tue, 13 Mar 2018 15:03:47 +0100	[thread overview]
Message-ID: <8ecfb374-e979-a54d-74d9-d65dfbb5c3ef@ideasonboard.com> (raw)
In-Reply-To: <554b73e9ee2d43b19ac42ee380b7d160@AcuMS.aculab.com>

Hi David,

On 13/03/18 13:38, David Laight wrote:
> From: Kieran Bingham [mailto:kieran.bingham+renesas@ideasonboard.com]
>> On 13/03/18 11:20, David Laight wrote:
>>> From: Kieran Bingham
>>>> Sent: 09 March 2018 22:04
>>>> The kernel provides a __packed definition to abstract away from the
>>>> compiler specific attributes tag.
>>>>
>>>> Convert all packed structures in VSP1 to use it.
>>>>
>>>> Signed-off-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
>>>> ---
>>>>  drivers/media/platform/vsp1/vsp1_dl.c | 6 +++---
>>>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>>>
>>>> diff --git a/drivers/media/platform/vsp1/vsp1_dl.c b/drivers/media/platform/vsp1/vsp1_dl.c
>>>> index 37e2c984fbf3..382e45c2054e 100644
>>>> --- a/drivers/media/platform/vsp1/vsp1_dl.c
>>>> +++ b/drivers/media/platform/vsp1/vsp1_dl.c
>>>> @@ -29,19 +29,19 @@
>>>>  struct vsp1_dl_header_list {
>>>>  	u32 num_bytes;
>>>>  	u32 addr;
>>>> -} __attribute__((__packed__));
>>>> +} __packed;
>>>>
>>>>  struct vsp1_dl_header {
>>>>  	u32 num_lists;
>>>>  	struct vsp1_dl_header_list lists[8];
>>>>  	u32 next_header;
>>>>  	u32 flags;
>>>> -} __attribute__((__packed__));
>>>> +} __packed;
>>>>
>>>>  struct vsp1_dl_entry {
>>>>  	u32 addr;
>>>>  	u32 data;
>>>> -} __attribute__((__packed__));
>>>> +} __packed;
>>>
>>> Do these structures ever actually appear in misaligned memory?
>>> If they don't then they shouldn't be marked 'packed'.
>>
>> I believe the declaration is to ensure that the struct definition is not altered
>> by the compiler as these structures specifically define the layout of how the
>> memory is read by the VSP1 hardware.
> 
> The C language and ABI define structure layouts.
> 
>> Certainly 2 u32's sequentially stored in a struct are unlikely to be moved or
>> rearranged by the compiler (though I believe it would be free to do so if it
>> chose without this attribute), but I think the declaration shows the intent of
>> the memory structure.
> 
> The language requires the fields be in order and the ABI stops the compiler
> adding 'random' padding.
> 
>> Isn't this a common approach throughout the kernel when dealing with hardware
>> defined memory structures ?
> 
> Absolutely not.
> __packed tells the compiler that the structure might be on any address boundary.
> On many architectures this means the compiler must use byte accesses with shifts
> and ors for every access.
> The most a hardware defined structure will have is a compile-time assert
> that it is the correct size (to avoid silly errors from changes).



Ok - interesting, I see what you're saying - and certainly don't want the
compiler to be performing byte accesses on the structures unnecessarily.

I'm trying to distinguish the difference here. Is the single point that
 __packed

causes byte-access, where as

__attribute__((__packed__));

does not?

Looking at the GCC docs [0]: I see that  __attribute__((__packed__)) tells the
compiler that the "structure or union is placed to minimize the memory required".

However, the keil compiler docs[1] do certainly declare that __packed causes
byte alignment.

I was confused/thrown off here by the Kernel defining __packed as
__attribute__((packed)) at [2].

Do __attribute__((packed)) and __attribute__((__packed__)) differ ?

In which case, from what I've read so far I wish "__packed" was "__unaligned"...


[0]
https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-packed-type-attribute

[1] http://www.keil.com/support/man/docs/armcc/armcc_chr1359124230195.htm

[2]
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/compiler-gcc.h?h=v4.16-rc5#n92


Regards

Kieran


> 	David
> 

  reply	other threads:[~2018-03-13 14:03 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.50cd35ac550b4477f13fb4f3fbd3ffb6bcccfc8a.1520632434.git-series.kieran.bingham+renesas@ideasonboard.com>
2018-03-09 22:03 ` [PATCH 01/11] media: vsp1: drm: Fix minor grammar error Kieran Bingham
2018-03-09 22:04 ` [PATCH 02/11] media: vsp1: use kernel __packed for structures Kieran Bingham
2018-03-13 11:20   ` David Laight
2018-03-13 11:47     ` Kieran Bingham
2018-03-13 12:38       ` David Laight
2018-03-13 14:03         ` Kieran Bingham [this message]
2018-03-13 22:34           ` Kieran Bingham
2018-03-09 22:04 ` [PATCH 03/11] media: vsp1: Rename dl_child to dl_next Kieran Bingham
2018-03-09 22:04 ` [PATCH 04/11] media: vsp1: Remove unused display list structure field Kieran Bingham
2018-03-09 22:04 ` [PATCH 05/11] media: vsp1: Clean up DLM objects on error Kieran Bingham
2018-03-09 22:04 ` [PATCH 06/11] media: vsp1: Provide VSP1 feature helper macro Kieran Bingham
2018-03-09 22:04 ` [PATCH 07/11] media: vsp1: Use header display lists for all WPF outputs linked to the DU Kieran Bingham
2018-03-09 22:04 ` [PATCH 08/11] media: vsp1: Add support for extended display list headers Kieran Bingham
2018-03-09 22:04 ` [PATCH 09/11] media: vsp1: Provide support for extended command pools Kieran Bingham
2018-03-10 11:26   ` Kieran Bingham
2018-03-12 16:30   ` jacopo mondi
2018-03-13 10:27     ` Kieran Bingham
2018-03-09 22:04 ` [PATCH 10/11] media: vsp1: Support Interlaced display pipelines Kieran Bingham
2018-03-09 22:04 ` [PATCH 11/11] drm: rcar-du: Support interlaced video output through vsp1 Kieran Bingham

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=8ecfb374-e979-a54d-74d9-d65dfbb5c3ef@ideasonboard.com \
    --to=kieran.bingham@ideasonboard.com \
    --cc=David.Laight@ACULAB.COM \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --subject='Re: [PATCH 02/11] media: vsp1: use kernel __packed for structures' \
    /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

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).