[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>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Thu, 16 Feb 2023 10:55:11 +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=s4nfn4Vekhn3GCdG0vdvtts/f3miz2wH6PD7FEmBKK8=; b=B2FT5RETGbwXGfnA1V3oVN+Pv28uWnfHPUyAeHwy8t9R5xE0lXBAINjyPESNKTiwccT2wXUC2poqKWJ7OZYjbVsFzR6OHJJmxM/cQzXWSvyt7CiBuIf3xvf6ProeBWaSOp+adZLMcH1o1C5q/KltfJgTzbueMZkwiuiBPk3ahIK8nSFUJGYrQwhosqbP17/Hf295RCMl7dBO+7+ttIfbMLQ4Z7Hgl/l/D2YzJf/cgDKmN/p9ubyX4qSQOdXz0VyBpE4a/wSwr62z3FSoitmK28G7ngpTfLUas1nascsLDvPQx5meUVCGNfDiMnjOOcDw53OUxqv0BqxyYR6wHZqpLw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Kmdvx09Z+EJ1w9Nhgm4t5/cLAJk4dhugBCYzzF+UnvxsTn50rEkdnGb3QfANpnRlHCZhdlhoXs55Rf3TLDNMKtjE76QEdtbE4xerYVuRJsWe6SBNEuA9bTpFm3cT5dAsRdoADawLm+pUj1M8E0YuPuFxt9YtC4MWHpDRovitOIt8LUw1qlMfalga1v9RjLvbjuQfxc4beoDNlpJJ0c8aQQRGSB9TJFIyPB45t1aqNw89v0eajvDKFEDAX7lJjnVuHvDcUisiGlLdwdPBln1bKo/6gj4pzzMfTMHJiKvu2jKE7zi7HUI+zfZIeHBfqYqWH8/t21DtImCDqViDGaPsyg==
  • 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>
  • Delivery-date: Thu, 16 Feb 2023 10:55:40 +0000
  • Ironport-data: A9a23:UFdd4KnCE1Z7VQshbxWgo7no5gyiJ0RdPkR7XQ2eYbSJt1+Wr1Gzt xIZDGHUM6uCN2r0e9t0O4S/9kwC78CAx9BrGgY4+Cg3HiMWpZLJC+rCIxarNUt+DCFhoGFPt JxCN4aafKjYaleG+39B55C49SEUOZmgH+a6U6icfHgqH2eIcQ954Tp7gek1n4V0ttawBgKJq LvartbWfVSowFaYCEpNg064gE4p7auaVA8w5ARkPqgR5QGGzhH5MbpETU2PByqgKmVrNrbSq 9brlNmR4m7f9hExPdKp+p6TnpoiG+O60aCm0xK6aoD66vRwjnVaPpUTbZLwXXx/mTSR9+2d/ f0W3XCGpaXFCYWX8AgVe0Ew/yiTpsSq8pefSZS0mZT7I0Er7xIAahihZa07FdRwxwp5PY1B3 fUgERASdSDYvumRh4mSTeVNjNY+Msa+aevzulk4pd3YJdAPZMiZBo/svJpf1jp2gd1SF/HDY cZfcSBocBnLfxxIPBEQFY46m+CrwHL4dlW0qnrM/fZxvzeVkVU3jOaF3Nn9I7RmQe18mEqCq 32A1GP+GhwAb/SUyCaf82LqjejK9c/+cNNMTefnqaEy6LGV7nACDzhJRWC2ndSksleFdfMEN FA0+TV7+MDe82TuFLERRSaQonSJoxodUNp4CPAh5UeGza+8yxaUAC0IQyBMbPQitdQqXno62 1mRhdTrCDdz9rqPRhq16bO8vT60fy8PIgc/iTQsSAIE55zpptg1hxeXFNJ7Svbp0JvyBC36x C2MoG4mnbIPgMUX1qK9u1fanzaroZuPRQkwjunKYl+YAspCTNbNT+SVBZLzt56s8K7xooG9g UU5
  • Ironport-hdrordr: A9a23:v3Us+a3cvDFzfutnJK0JIQqjBLwkLtp133Aq2lEZdPU1SKClfq WV98jzuiWatN98Yh8dcLK7WJVoMEm8yXcd2+B4V9qftWLdyQiVxe9ZnO7f6gylNyri9vNMkY dMGpIObOEY1GIK7/rH3A==
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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.

> ---
> For most (all?) of the single bit I was on the edge of switching them to
> bool - thoughts?

Yes.

>
> --- 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, 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.

>  };
>  
>  struct irq_desc;
> @@ -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).

> +    } 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_msg msg;             /* Last set MSI message */
> +    struct msi_msg msg;      /* Last set MSI message */
>  };
>  
>  /*
> @@ -180,48 +180,48 @@ int msi_free_irq(struct msi_desc *entry)
>  
>  struct __packed msg_data {
>  #if defined(__LITTLE_ENDIAN_BITFIELD)

There's no such thing as a big endian x86 bitfield.  Just delete this
ifdefary to simplify the result.

Additionally, the structure doesn't need to be packed - its a single
uint32_t's worth of bitfield.

Finally, can we drop the reserved fields and leave them as anonymous
bitfields?

> -     __u32   vector          :  8;
> -     __u32   delivery_mode   :  3;   /* 000b: FIXED | 001b: lowest prior */
> -     __u32   reserved_1      :  3;
> -     __u32   level           :  1;   /* 0: deassert | 1: assert */
> -     __u32   trigger         :  1;   /* 0: edge | 1: level */
> -     __u32   reserved_2      : 16;
> +    uint32_t vector        :  8;
> +    uint32_t delivery_mode :  3;    /* 000b: FIXED | 001b: lowest prior */
> +    uint32_t reserved_1    :  3;
> +    uint32_t level         :  1;    /* 0: deassert | 1: assert */
> +    uint32_t trigger       :  1;    /* 0: edge | 1: level */
> +    uint32_t reserved_2    : 16;
>  #elif defined(__BIG_ENDIAN_BITFIELD)
> -     __u32   reserved_2      : 16;
> -     __u32   trigger         :  1;   /* 0: edge | 1: level */
> -     __u32   level           :  1;   /* 0: deassert | 1: assert */
> -     __u32   reserved_1      :  3;
> -     __u32   delivery_mode   :  3;   /* 000b: FIXED | 001b: lowest prior */
> -     __u32   vector          :  8;
> +    uint32_t reserved_2    : 16;
> +    uint32_t trigger       :  1;    /* 0: edge | 1: level */
> +    uint32_t level         :  1;    /* 0: deassert | 1: assert */
> +    uint32_t reserved_1    :  3;
> +    uint32_t delivery_mode :  3;    /* 000b: FIXED | 001b: lowest prior */
> +    uint32_t vector        :  8;
>  #else
>  #error "Bitfield endianness not defined! Check your byteorder.h"
>  #endif
>  };
>  
>  struct __packed msg_address {
> -     union {
> -             struct {
> +    union {
> +        struct {
>  #if defined(__LITTLE_ENDIAN_BITFIELD)

Same here for ifdefary and packed.

> -                     __u32   reserved_1      :  2;
> -                     __u32   dest_mode       :  1;   /*0:physic | 1:logic */
> -                     __u32   redirection_hint:  1;   /*0: dedicated CPU
> -                                                       1: lowest priority */
> -                     __u32   reserved_2      :  4;
> -                     __u32   dest_id         : 24;   /* Destination ID */
> +            uint32_t reserved_1       :  2;
> +            uint32_t dest_mode        :  1; /* 0:phys | 1:logic */
> +            uint32_t redirection_hint :  1; /* 0: dedicated CPU
> +                                               1: lowest priority */
> +            uint32_t reserved_2       :  4;
> +            uint32_t dest_id          : 24; /* Destination ID */

Considering that these fields are stale (its missing the remappable bit
for one), I do have to question if we actually use them correctly in code...

But that's not something for this patch.

~Andrew



 


Rackspace

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