mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hans Verkuil <hverkuil-cisco@xs4all.nl>
To: Ricardo Ribalda <ribalda@chromium.org>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3] media: dvb: Fix dtvs_stats packing.
Date: Mon, 15 Apr 2024 11:51:30 +0200	[thread overview]
Message-ID: <3f8660b0-e29c-47e2-b877-10da058388f9@xs4all.nl> (raw)
In-Reply-To: <CANiDSCvkRWZXuG7dfw0WXvgT+LHQqG3fx9F1M2P0_9dkB9VOKA@mail.gmail.com>

Hi Ricardo,

On 12/04/2024 17:00, Ricardo Ribalda wrote:
> Hi Hans
> 
> On Fri, 12 Apr 2024 at 16:21, Hans Verkuil <hverkuil-cisco@xs4all.nl> wrote:
>>
>> On 10/04/2024 14:24, Ricardo Ribalda wrote:
>>> The structure is packed, which requires that all its fields need to be
>>> also packed.
>>>
>>> ./include/uapi/linux/dvb/frontend.h:854:2: warning: field  within 'struct dtv_stats' is less aligned than 'union dtv_stats::(anonymous at ./include/uapi/linux/dvb/frontend.h:854:2)' and is usually due to 'struct dtv_stats' being packed, which can lead to unaligned accesses [-Wunaligned-access]
>>>
>>> Explicitly set the inner union as packed.
>>>
>>> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
>>> ---
>>>  include/uapi/linux/dvb/frontend.h | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/include/uapi/linux/dvb/frontend.h b/include/uapi/linux/dvb/frontend.h
>>> index 7e0983b987c2d..8d38c6befda8d 100644
>>> --- a/include/uapi/linux/dvb/frontend.h
>>> +++ b/include/uapi/linux/dvb/frontend.h
>>> @@ -854,7 +854,7 @@ struct dtv_stats {
>>>       union {
>>>               __u64 uvalue;   /* for counters and relative scales */
>>>               __s64 svalue;   /* for 0.001 dB measures */
>>> -     };
>>> +     }  __attribute__ ((packed));
>>>  } __attribute__ ((packed));
>>
>> This is used in the public API, and I think this change can cause ABI changes.
>>
>> Can you compare the layouts? Also between gcc and llvm since gcc never warned
>> about this.
> 
> The pahole output looks the same in both cases:
> 
> https://godbolt.org/z/oK4desv7Y
> vs
> https://godbolt.org/z/E36MjPr7v
> 
> And it is also the same for all the compiler versions that I tried.
> 
> 
> struct dtv_stats {
> uint8_t                    scale;                /*     0     1 */
> union {
> uint64_t           uvalue;               /*     1     8 */
> int64_t            svalue;               /*     1     8 */
> };                                               /*     1     8 */
> 
> /* size: 9, cachelines: 1, members: 2 */
> /* last cacheline: 9 bytes */
> } __attribute__((__packed__));
> 
> 
> 
> struct dtv_stats {
> uint8_t scale; /* 0 1 */
> union {
> uint64_t uvalue; /* 1 8 */
> int64_t svalue; /* 1 8 */
> }; /* 1 8 */
> 
> /* size: 9, cachelines: 1, members: 2 */
> /* last cacheline: 9 bytes */
> } __attribute__((__packed__));
> 
> 
>>
>> I'm not going to accept this unless it is clear that there are no ABI changes.
> 
> Is there something else that I can try?

No, that's what I needed. I also found some clang discussions here:

https://github.com/llvm/llvm-project/issues/55520

I propose that I add the following sentence to these three packing patches:

"Marking the inner union as 'packed' does not change the layout, since the
whole struct is already packed, it just silences the clang warning. See
also this llvm discussion: https://github.com/llvm/llvm-project/issues/55520"

If you are OK with that, then I can add that to your patches.

Related to this: I added CEC and DVB support to the ABI checks in the build
scripts. And fixed a bunch of mistakes there (e.g. 'false=true' where I meant
to write 'fail=true'!) that made the ABI checks useless.

I updated the abi/* files accordingly as well.

Regards,

	Hans

> 
> Regards!
> 
>>
>> Note that the ABI test in the build scripts only tests V4L2 at the moment,
>> not the DVB API.
>>
>> Regards,
>>
>>         Hans
>>
> 
> 


  reply	other threads:[~2024-04-15  9:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-10 12:24 [PATCH 0/3] media: Fix missing warnings for llvm am32 Ricardo Ribalda
2024-04-10 12:24 ` [PATCH 1/3] media: dvb: as102-fe: Fix as10x_register_addr packing Ricardo Ribalda
2024-04-12 14:19   ` Hans Verkuil
2024-04-10 12:24 ` [PATCH 2/3] media: dvb: Fix dtvs_stats packing Ricardo Ribalda
2024-04-12 14:21   ` Hans Verkuil
2024-04-12 15:00     ` Ricardo Ribalda
2024-04-15  9:51       ` Hans Verkuil [this message]
2024-04-15 10:29         ` Ricardo Ribalda
2024-04-10 12:24 ` [PATCH 3/3] media: videodev2: Fix v4l2_ext-control packing Ricardo Ribalda

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=3f8660b0-e29c-47e2-b877-10da058388f9@xs4all.nl \
    --to=hverkuil-cisco@xs4all.nl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=ribalda@chromium.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

all inboxes | Powered by JetHome®