From: Zhao Liu <zhao1.liu@intel.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Philippe Mathieu-DaudÃ" <philmd@linaro.org>,
qemu-devel@nongnu.org, "Zhao Liu" <zhao1.liu@intel.com>
Subject: Re: [PATCH 1/2] memattrs: Get rid of bit fields
Date: Tue, 21 Jan 2025 00:38:39 +0800 [thread overview]
Message-ID: <Z458D/RuBQ8Kq0al@intel.com> (raw)
In-Reply-To: <CAFEAcA_VAOU+p_BC5bpnk2GKa5piywjf+yhFTh=-3O7TGut+uA@mail.gmail.com>
Hi Peter,
> > /*
> > * PID (PCI PASID) support: Limited to 8 bits process identifier.
> > */
> > - unsigned int pid:8;
> > -} MemTxAttrs;
> > + uint8_t pid;
> > +
> > + /* Requester ID (for MSI for example) */
> > + uint16_t requester_id;
> > +} QEMU_PACKED MemTxAttrs;
>
> If we pull the requester_id up to the top of the struct
> we don't need the QEMU_PACKED, I think? (You get worse codegen
> on some platforms if you use 'packed' when you don't need to.)
Yes! I agree.
> It would be good to note in the commit message:
> (1) that this doesn't change the size of MemTxAttrs,
> which is important because we pass it around directly,
> not via a pointer (or does it raise it from 4 to 8 bytes?)
MemTxAttrs is raised to 8 bytes (yes, I should mention this).
> (2) that it does mean we have no spare space in the
> struct for new fields without moving beyond 8 bytes.
Thanks for the reminder, yes it is currently full. I found I missed
a commnet from Paolo [*], that he suggested only convert `unspecified`
to a bool. My bad :-(
It still raises the size to 8 bytes but saves spare space, like:
typedef struct MemTxAttrs {
unsigned int secure:1;
unsigned int space:2;
unsigned int user:1;
unsigned int memory:1;
unsigned int requester_id:16;
unsigned int pid:8;
bool unspecified;
uint8_t _reserved1;
uint16_t _reserved2;
} MemTxAttrs;
Similar to your comment above, to get pakced structure, I think I need
push `unspecified` field down to other bit fields.
The rust side would require extra work to ZERO the other bit fields
though. I'll go back to that mail thread and discuss the details again.
[*]: https://lore.kernel.org/qemu-devel/20241205060714.256270-1-zhao1.liu@intel.com/T/#m8b05874d630e3ec8834617babb97b32ec3b39fce
> In particular we're talking about maybe adding a
> "debug" attribute; so this is an unfortunate refactoring
> from that point of view.
Thank you for your comment. In v2, I will try converting only
`unspecified` to a bool. Will that meet your expectations?
Regards,
Zhao
next parent reply other threads:[~2025-01-20 16:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20250120074258.2204342-1-zhao1.liu@intel.com>
[not found] ` <20250120074258.2204342-2-zhao1.liu@intel.com>
[not found] ` <CAFEAcA_VAOU+p_BC5bpnk2GKa5piywjf+yhFTh=-3O7TGut+uA@mail.gmail.com>
2025-01-20 16:38 ` Zhao Liu [this message]
2025-01-20 16:53 ` [PATCH 1/2] memattrs: Get rid of bit fields CLEMENT MATHIEU--DRIF
2025-01-21 12:15 ` Zhao Liu
2025-01-20 17:41 ` Paolo Bonzini
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=Z458D/RuBQ8Kq0al@intel.com \
--to=zhao1.liu@intel.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.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;
as well as URLs for NNTP newsgroup(s).