qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Zhao Liu <zhao1.liu@intel.com>, Peter Maydell <peter.maydell@linaro.org>
Cc: "Richard Henderson" <richard.henderson@linaro.org>,
	"Philippe Mathieu-DaudÃ" <philmd@linaro.org>,
	qemu-devel@nongnu.org
Subject: Re: [PATCH 1/2] memattrs: Get rid of bit fields
Date: Mon, 20 Jan 2025 18:41:00 +0100	[thread overview]
Message-ID: <33692b30-464d-4f7c-b66c-86fcd9b4e55f@redhat.com> (raw)
In-Reply-To: <Z458D/RuBQ8Kq0al@intel.com>

On 1/20/25 17:38, Zhao Liu wrote:
> 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.

Right, this would allow for a 16-bit PASID, 19 free bits and no QEMU_PACKED:

typedef struct MemTxAttrs {
     bool unspecified;
     uint8_t int secure:1;
     uint8_t int space:2;
     uint8_t int user:1;
     uint8_t memory:1;
     uint16_t requester_id;
     uint16_t pid;
     uint16_t _reserved;
} MemTxAttrs;
QEMU_BUILD_BUG_ON(sizeof(MemTxAttrs) > 8);

Together with const_zero!() that would be fine for both C and Rust, and 
a bit more efficient too.

Paolo



      parent reply	other threads:[~2025-01-20 17:41 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     ` [PATCH 1/2] memattrs: Get rid of bit fields Zhao Liu
2025-01-20 16:53       ` CLEMENT MATHIEU--DRIF
2025-01-21 12:15         ` Zhao Liu
2025-01-20 17:41       ` 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=33692b30-464d-4f7c-b66c-86fcd9b4e55f@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=zhao1.liu@intel.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).