qemu-trivial.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Thomas Huth <thuth@redhat.com>, Michael Tokarev <mjt@tls.msk.ru>,
	Roque Arcudia Hernandez <roqueh@google.com>,
	richard.henderson@linaro.org, jansene@google.com
Cc: qemu-devel@nongnu.org, Gerd Hoffmann <kraxel@redhat.com>,
	QEMU Trivial <qemu-trivial@nongnu.org>
Subject: Re: [PATCH] hw/usb: Use __attribute__((packed)) vs __packed
Date: Thu, 21 Nov 2024 12:23:34 +0100	[thread overview]
Message-ID: <4549dfdb-f0b3-4a97-a8cf-3501a6051771@redhat.com> (raw)
In-Reply-To: <68860810-cb4e-44c6-9466-a117bd4fcd49@redhat.com>

On 11/21/24 11:24, Thomas Huth wrote:
> On 21/11/2024 11.01, Michael Tokarev wrote:
>> 04.11.2024 10:37, Thomas Huth wrote:
>>> On 01/11/2024 22.17, Roque Arcudia Hernandez wrote:
>>>> __packed is non standard and is not present in clang-cl.
>>>> __attribute__((packed)) has the same semantics.
>>>>
>>>> Signed-off-by: Erwin Jansen <jansene@google.com>
>>>> Signed-off-by: Roque Arcudia Hernandez <roqueh@google.com>
>>>> ---
>>>>   include/hw/usb/dwc2-regs.h | 2 +-
>>>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>>>
>>>> diff --git a/include/hw/usb/dwc2-regs.h b/include/hw/usb/dwc2-regs.h
>>>> index 523b112c5e..b8b4266543 100644
>>>> --- a/include/hw/usb/dwc2-regs.h
>>>> +++ b/include/hw/usb/dwc2-regs.h
>>>> @@ -838,7 +838,7 @@
>>>>   struct dwc2_dma_desc {
>>>>           uint32_t status;
>>>>           uint32_t buf;
>>>> -} __packed;
>>>> +} QEMU_PACKED;
>>>
>>> Reviewed-by: Thomas Huth <thuth@redhat.com>
>>>
>>> Actually, the struct only consists of two 32-bit values, so I doubt 
>>> that the "packed" is needed here at all. Maybe we could even simply 
>>> remove it?
>> To me it is important to mark structures as packed if it is
>> important for them to have strict layout like in this case,
>> even if de-facto it does not change the actual layout.  It's
>> just like an annotation saying this structure can be used
>> on wire or somesuch.
> 
> Well, it can have an impact on your binary, too. On architectures that 
> don't support unaligned memory accesses, the compiler has to generate 
> code that reads the values of packed structures in a more cumbersome 
> way. So if you used "packed" though it's not really necessary (i.e. 
> everything is naturally aligned, and you can be sure that the starting 
> address is also properly aligned), the compiler generates worse code 
> than necessary in that case.
Well, in this case the struct is downright unused. :)  But we can't know 
if it is naturally aligned or not in guest memory, so it is advisable to 
keep the QEMU_PACKED.

Paolo



      reply	other threads:[~2024-11-21 11:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20241101211720.3354111-1-roqueh@google.com>
2024-11-04  7:37 ` [PATCH] hw/usb: Use __attribute__((packed)) vs __packed Thomas Huth
2024-11-21 10:01   ` Michael Tokarev
2024-11-21 10:24     ` Thomas Huth
2024-11-21 11:23       ` Paolo Bonzini [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=4549dfdb-f0b3-4a97-a8cf-3501a6051771@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=jansene@google.com \
    --cc=kraxel@redhat.com \
    --cc=mjt@tls.msk.ru \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=roqueh@google.com \
    --cc=thuth@redhat.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 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).