[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 4/6] x86/MSI: use standard C types in structures/unions


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Thu, 16 Feb 2023 19:16:02 +0000
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=wcuN25BzXiIPNxzbrQUOhWcdNGeIF9a4jM1EDS0Yz2M=; b=KnJNyWcpJCwaWwzgX3FVi81Becd2UUMx29giXGS2/A27C3RcSQ+ZYMEMNOaKfFFZDQ4nLyJcDPh8yL99GAj19XjY2sN5Qwmmwm189eN87vnzVe1IiMjZuszQRZYXCzywuzxkU72QwExr+JL3cqqP7JIGBVSHvNMD7uFGKliP3nRYM/oGk/yVe2b/uw8v7b+74v2qCmS9ykKz7EdjWzGiZdbNk8ef2Nz830cFOzIWcxkF6atwT/QKndQpvD9dDVOqFmWavuc8cm+t89s5wwC4ZkZkmhq1AW65qGuUVDuTXu5ARUbF6be3qJZ5eB4OjQfozMQEGd5ya7/HEYJkdc2iWQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=X/NXhttVcoskLkIFbVIQA5disUpr8YHp6IfOHjO95W1aOoLgj16JDtKowCfZAiU+Mr18/5igDZobIOES9ilF3xAQkHDsbbnzafD0kDqGVjFFkyyYqjIoCSVBGsMEfYSUVrKJoefbtyNFq4XgM9+tQ89EsY79UiaFeXJoFpgUF17HN+SfI+EM7CJ/yhXVembj1z+8hzntYSmSv6P3YK0YoPnQzB3xRfadFXv6yOi/VfUT4yfytcs+v2bEYRwUdlDRvl79ySmb5GMSFIAwjl53Q+RFeiZEHZuxYUBrRxdwm2rPx14Vth11PeKztxFX8muWDAJ4ZxvOzaSIlf5fIof+Fg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: George Dunlap <george.dunlap@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Thu, 16 Feb 2023 19:17:26 +0000
  • Ironport-data: A9a23:uZYs9aku6GU7OscOqlGvdWXo5gysJ0RdPkR7XQ2eYbSJt1+Wr1Gzt xIWC2+Gbv7cNmb3e413PYngoR8HvJ7Rm9IyT1RqqX09QiMWpZLJC+rCIxarNUt+DCFhoGFPt JxCN4aafKjYaleG+39B55C49SEUOZmgH+a6U6icfHgqH2eIcQ954Tp7gek1n4V0ttawBgKJq LvartbWfVSowFaYCEpNg064gE4p7auaVA8w5ARkPqgR5QGGzRH5MbpETU2PByqgKmVrNrbSq 9brlNmR4m7f9hExPdKp+p6TnpoiG+O60aCm0xK6aoD66vRwjnVaPpUTbZLwXXx/mTSR9+2d/ f0W3XCGpaXFCYWX8AgVe0Ew/yiTpsSq8pefSZS0mZT7I0Er7xIAahihZa07FdRwxwp5PY1B3 axBLyJXRyDavMaZ3ryVc7Ez35s9Bsa+aevzulk4pd3YJdAPZMmaBo/stZpf1jp2gd1SF/HDY cZfcSBocBnLfxxIPBEQFY46m+CrwHL4dlW0qnrM/fZxvzeVkVw3iea9WDbWUoXiqcF9t0CUv G/ZuU/+BQkXLoe3wjuZ6HO8wOTImEsXXapDS+fnpqA72TV/wEQXKwMkCEOWg8CHl0/9Uv8GI VAayxQH+P1aGEuDC4OVsweDiHyOswMYWtFQO/Yn8wzLwa3Riy6GAkAUQzgHb8Yp3OcmSDpv2 lKXktfBAT10rKbTWX+b7q2Trz65JW4SN2BqWMMfZQ4M4t2mqodjiBvKF49nCPTs0I2zHizsy TeXqiR4n68UkcMAy6S8+xbAni6ooZ/KCAUy4207Q16Y0++wX6b9D6TA1LQRxa0eRGpFZjFtZ EQ5pvU=
  • Ironport-hdrordr: A9a23:QRUCnqsoSCU8WWPnYxgLPKYU7skCa4Aji2hC6mlwRA09TyXGra 2TdaUgvyMc1gx7ZJhBo7+90We7MArhHO1OkO4s1NCZLXTbUQqTXftfBO7ZrwEIdBeOldK1uZ 0QFpSWTeeAdmSS7vyKnjVQcexB/DDvysnB64bjJjVWPHlXgslbnnhE422gYylLrWd9dPwE/d anl6h6T23KQwVqUi33PAhMYwCFzOe75q7OUFojPVoK+QOOhTSn5PrTFAWZ5A4XV3di0Kov6m /Mli3+/+GGv+ugwhHR+mfP59AO8eGRhudrNYipsIw4Oz/sggGnaMBIXKCDhik8pKWC+Usni9 7FpjYnJoBW52nKdm+4jBPx003L0Soo6VXl1ViE6EGT7PDRdXYfMY5slIhZehzW5w4Ju8x96r tC2ya8u4BMBR3NsSzh75yQPisa3HackD4Hq6o+nnZfWYwRZPt4qpEexlpcFNMlEDjh4I4qPe FyBIX35epQc3mdc3fF11Mfi+CEbzAWJFOrU0ICssua33x/m2149VIRwIglknIJ5PsGOu55zt WBFp4tuKBFT8cQY644LvwGW9GLBmvERg+JGH6OIHz8fZt3e07lmtrS2vEY9euqcJsHwN8Zg5 LaSm5VsmY0ZgbHFdCO5ptW6RrAKV/NHAgF8vsupaSRh4eMAYYCaUa4ORQTeoqb0rsi6/TgKr WO0Mk8OY6lEYPscbw5qzEWFaMib0X2a/dlyerTa2j+0/4jFbeaxtAzUMyjUoYFQgxUE1/XMz 8kYAXZAvlmwwSCZkLY6SKhLk8FPHaPsq5NLA==
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 16/02/2023 2:16 pm, Jan Beulich wrote:
> On 16.02.2023 11:55, Andrew Cooper wrote:
>> On 09/02/2023 10:39 am, Jan Beulich wrote:
>>> Consolidate this to use exclusively standard types, and change
>>> indentation style to Xen's there at the same time (the file already had
>>> a mix of styles).
>>>
>>> No functional change intended.
>>>
>>> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
>> So I suppose Acked-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> because
>> this is an improvement on the status quo, but I have quite a few requests.
> Thanks. I'll be happy to carry out some of them (but the sheer amount makes
> it so I'd rather not apply the A-b to the result). It's always difficult to
> judge how much "while doing this" is going to be acceptable ...

Everything I've suggested is minimal enough IMO.

>
>>> --- a/xen/arch/x86/include/asm/msi.h
>>> +++ b/xen/arch/x86/include/asm/msi.h
>>> @@ -66,15 +66,15 @@ struct msi_info {
>>>  };
>>>  
>>>  struct msi_msg {
>>> -   union {
>>> -           u64     address; /* message address */
>>> -           struct {
>>> -                   u32     address_lo; /* message address low 32 bits */
>>> -                   u32     address_hi; /* message address high 32 bits */
>>> -           };
>>> -   };
>>> -   u32     data;           /* 16 bits of msi message data */
>>> -   u32     dest32;         /* used when Interrupt Remapping with EIM is 
>>> enabled */
>>> +    union {
>>> +        uint64_t address; /* message address */
>>> +        struct {
>>> +            uint32_t address_lo; /* message address low 32 bits */
>>> +            uint32_t address_hi; /* message address high 32 bits */
>>> +        };
>>> +    };
>>> +    uint32_t data;        /* 16 bits of msi message data */
>>> +    uint32_t dest32;      /* used when Interrupt Remapping with EIM is 
>>> enabled */
>> The 16 is actively wrong for data,
> It it? The upper 16 bits aren't used, are they?

Well... I've just found that my local PCI reference doesn't actually
match the spec when it comes to stating the width of the message field. 
Guess I need to stop using this reference.

But the rules given would require this to turn into uint16_t as that's
the specified size of the register...  But that will probably require a
separate patch.

>
>> but honestly it's only this dest32
>> comment which has any value whatsoever (when it has been de-Intel'd).
>>
>> I'd correct dest32 to reference the AMD too, and delete the rest.
> I guess I'll simply drop "with EIM".

Yeah, probably the easiest adjustment.  AMD is more complicated anyway IIRC.

>>> @@ -94,35 +94,35 @@ extern int pci_restore_msi_state(struct
>>>  extern int pci_reset_msix_state(struct pci_dev *pdev);
>>>  
>>>  struct msi_desc {
>>> -   struct msi_attrib {
>>> -           __u8    type;           /* {0: unused, 5h:MSI, 11h:MSI-X} */
>>> -           __u8    pos;            /* Location of the MSI capability */
>>> -           __u8    maskbit : 1;    /* mask/pending bit supported ?   */
>>> -           __u8    is_64   : 1;    /* Address size: 0=32bit 1=64bit  */
>>> -           __u8    host_masked : 1;
>>> -           __u8    guest_masked : 1;
>>> -           __u16   entry_nr;       /* specific enabled entry         */
>>> -   } msi_attrib;
>>> -
>>> -   bool irte_initialized;
>>> -   uint8_t gvec;                   /* guest vector. valid when pi_desc 
>>> isn't NULL */
>>> -   const struct pi_desc *pi_desc;  /* pointer to posted descriptor */
>>> -
>>> -   struct list_head list;
>>> -
>>> -   union {
>>> -           void __iomem *mask_base;/* va for the entry in mask table */
>>> -           struct {
>>> -                   unsigned int nvec;/* number of vectors            */
>>> -                   unsigned int mpos;/* location of mask register    */
>>> -           } msi;
>>> -           unsigned int hpet_id;   /* HPET (dev is NULL)             */
>>> -   };
>>> -   struct pci_dev *dev;
>>> -   int irq;
>>> -   int remap_index;                /* index in interrupt remapping table */
>>> +    struct msi_attrib {
>>> +        uint8_t type;        /* {0: unused, 5h:MSI, 11h:MSI-X} */
>>> +        uint8_t pos;         /* Location of the MSI capability */
>>> +        uint8_t maskbit      : 1; /* mask/pending bit supported ?   */
>>> +        uint8_t is_64        : 1; /* Address size: 0=32bit 1=64bit  */
>>> +        uint8_t host_masked  : 1;
>>> +        uint8_t guest_masked : 1;
>>> +        uint16_t entry_nr;   /* specific enabled entry */
>> entry_nr wants to move up to between pos and maskbit, and then we shrink
>> the total structure by 8 bytes (I think).
> The struct is 6 bytes now and will be 6 bytes with the adjustment you
> suggest. Plus I'd prefer to not do any re-ordering in this patch.

Ah, so I see what went wrong.  Right now, we've got:

8b type
8b pos
4b the bitfields
12b padding
16b entry_nr

and rearranging it moves the padding to the end but doesn't drop it,
because overall the structure has 16b alignment because of the uint16_t

If it were packed, then the following byte fields would shuffle up into
the padding, and there would ba knockon effect.

But don't worry seeing as it doesn't make a difference.

>
>> Additionally, the structure doesn't need to be packed - its a single
>> uint32_t's worth of bitfield.
> Like with re-ordering I would prefer to not touch entirely unrelated
> aspects. I'll see if I can motivate myself to make a separate follow-on
> change.

Personally I'd consider dropping some __packed as sufficiently relevant
to this change to be included, but fine.

>
>> Finally, can we drop the reserved fields and leave them as anonymous
>> bitfields?
> Perhaps - I can give that a try, hoping that we don't access them
> anywhere by their name (even if just to e.g. zero them).

Well, its easy to try right now.  And if not, then it needs a different
patch anyway.

~Andrew



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.