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

Re: [PATCH v3 3/4] xen/vpci: header: filter PCI capabilities


  • To: Stewart Hildebrand <stewart.hildebrand@xxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 22 Aug 2023 15:40:18 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.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=eSZoM99ookfYqK8mLVpIPqwIoQbLgyvrXM2nSJsj/xs=; b=VOYBCcyEDH0eHPE7I7vQL81o1RuhosfpmW/ra/0nt4dLLJJGXmo4Qdxne7pd1z5IaJnvpama4xvH+Wx7iQ9sWDaum+CYoHYs+qK7KEOhAV+wCkveR7JkWTxWgAQe+T0InLJETEBxySI7M5p28ZaTEsQPO5YVkGWs1GWDdl2fLCPBqSU9UeUmZiE/LfGorCo6Yarjb7x2A9KoVBGXmtLZV4NgML5weW+To39eV4w5n3dAnL39Gw3v/5x/2nvR6AdA+3f9V93iJsjJeusaYY0ztGtAF6X0V+j6xoI7HYV8uuJgWqOnnBllX8myGh2p5nFWUZTpibtBq5o+xxYGfTE+Xw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eYb3JDOkrnynJKZW3hf/98l68r5XKWDLp94liixhy7FwFZuVfDTSMEZGN/ov7OlRQ8pPaZoQpXFkVJzMxJ4cMk+BTKYqTupw4iq76uBeu7gTJmOtEeFhiEGedAXe6G6i3GK2RHKjCMdKBp5EmTqNBAAR0nkaxejo6Etq7FOiIXI4fBbuXQ3v29E6MNLHeUxzWmqn9ZwfoAtWek4wqZZCuXcVy9ySrSSa0Nraq93/DD2W2GLXU6sEWV56PDzDB8n2978k3d+kI/zNrTllMXukENwDJ57V/q4f+D9SESGkdR5P4JS6BooFb18+/E0tclyXCFUA4Mt2NoCkUiglXgC7rw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Tue, 22 Aug 2023 13:40:36 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 22.08.2023 03:29, Stewart Hildebrand wrote:
> Currently, Xen vPCI only supports virtualizing the MSI and MSI-X capabilities.
> Hide all other PCI capabilities (including extended capabilities) from domUs 
> for
> now, even though there may be certain devices/drivers that depend on being 
> able
> to discover certain capabilities.
> 
> We parse the physical PCI capabilities linked list and add vPCI register
> handlers for the next elements, inserting our own next value, thus presenting 
> a
> modified linked list to the domU.
> 
> Introduce helper functions vpci_hw_read8 and vpci_read_val. The vpci_read_val
> helper function returns a fixed value, which may be used for RAZ registers, or
> registers whose value doesn't change.
> 
> Introduce pci_find_next_cap_ttl() helper while adapting the logic from
> pci_find_next_cap() to suit our needs, and implement the existing
> pci_find_next_cap() in terms of the new helper.
> 
> Signed-off-by: Stewart Hildebrand <stewart.hildebrand@xxxxxxx>
> ---
> v2->v3:
> * get rid of > 0 in loop condition
> * implement pci_find_next_cap in terms of new pci_find_next_cap_ttl function 
> so
>   that hypothetical future callers wouldn't be required to pass &ttl.
> * change NULL to (void *)0 for RAZ value passed to vpci_read_val
> * change type of ttl to unsigned int
> * remember to mask off the low 2 bits of next in the initial loop iteration
> * change return type of pci_find_next_cap and pci_find_next_cap_ttl
> * avoid wrapping the PCI_STATUS_CAP_LIST condition by using ! instead of == 0

Looks mostly okay to me now, just two things (pointed out before):

> --- a/xen/drivers/pci/pci.c
> +++ b/xen/drivers/pci/pci.c
> @@ -39,30 +39,38 @@ int pci_find_cap_offset(pci_sbdf_t sbdf, u8 cap)
>      return 0;
>  }
>  
> -int pci_find_next_cap(pci_sbdf_t sbdf, u8 pos, int cap)
> +uint8_t pci_find_next_cap_ttl(pci_sbdf_t sbdf, uint8_t pos,
> +                              bool (*is_match)(uint8_t), unsigned int *ttl)
>  {
> -    u8 id;
> -    int ttl = 48;
> +    uint8_t id;
>  
> -    while ( ttl-- )
> +    while ( (*ttl)-- )
>      {
>          pos = pci_conf_read8(sbdf, pos);
>          if ( pos < 0x40 )
>              break;
>  
> -        pos &= ~3;
> -        id = pci_conf_read8(sbdf, pos + PCI_CAP_LIST_ID);
> +        id = pci_conf_read8(sbdf, (pos & ~3) + PCI_CAP_LIST_ID);
>  
>          if ( id == 0xff )
>              break;
> -        if ( id == cap )
> +        if ( is_match(id) )
>              return pos;
>  
> -        pos += PCI_CAP_LIST_NEXT;
> +        pos = (pos & ~3) + PCI_CAP_LIST_NEXT;
>      }
> +
>      return 0;
>  }
>  
> +uint8_t pci_find_next_cap(pci_sbdf_t sbdf, uint8_t pos,
> +                          bool (*is_match)(uint8_t))
> +{
> +    unsigned int ttl = 48;
> +
> +    return pci_find_next_cap_ttl(sbdf, pos, is_match, &ttl) & ~3;
> +}

You still change the original function's signature. In this patch, the
prototype for it should not need touching at all.

The other is the imo excessive use of fixed width types. "pos" has no
business being uint8_t (but that'll be taken care of in the earlier
patch for the case here), and similarly e.g. id doesn't need to be (in
the earlier function). But I can see that at least some of the cases
here are on the edge ...

Jan



 


Rackspace

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