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

Re: [QEMU PATCH v9] xen/passthrough: use gsi to map pirq when dom0 is PVH


  • To: "Hildebrand, Stewart" <Stewart.Hildebrand@xxxxxxx>
  • From: "Chen, Jiqian" <Jiqian.Chen@xxxxxxx>
  • Date: Mon, 4 Nov 2024 06:03:55 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=y2Hr+8gyUpiKqgP5pTX0yvlWPuKT4QFcdrQGcMEPrOo=; b=e7bJr4836dGkudu2Qf0KopnTgaTgLqsyzluW5avQdQzSAXjSkT82PUrV0RlvEjwDypckSocifVk3N3xgutPVh+UXyBQsJ/rSc6xpEaMNMz8W0P48UVD+q7zB2T2aZEzAG7ydPmvcUp5VGZJEbDOcZo9HMe9oAE3TlpFPLeUpp482+SidBW3aqKYnL0nyqDC9s7/rKIVgKOUG3k99CD+H1hE5M9jcSvo9Qm+nGIHhtG7QhwvoSummZShvgvjoaP9CBngYi7120cu+vuaWXjP2i0gUW5IkFEzyHT50plRxUwJG2EGB9Xde2uX5q6LJ1jlGbAw0W0vmzY76gMvWpXnzDA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=mXCMJ05lu39Rxwk824QJxBqfmPDToJkPeoO0UMeN+UK51MvHr0Vg5j3h8qcrLgFDmQcL++okjlUf0/zFm1cIonQt7DSmeMI6qXCN022EHshm7B6Q6qSdDdfjlHCvuBScIXexVxhrTqAjCmrzGrSSct6aVLdegCQwUPPfdGtvsptNnXa4hR5LBWjwjSeRR1EBppnT4wdFRioNwElCQAjF0nps4QCdFcJCyOLrkJy8JvvFni2ziCoRKpbbuRqQj6zjcPu76XDE/d03iLfhja0dNGq/4Et6iwRf6xTtgcTdK2F6TqBriiLCXCBwNPTRKTGoCGQX3OWAVwDJ5OY5jpi2VQ==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com;
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Anthony PERARD <anthony@xxxxxxxxxxxxxx>, Paul Durrant <paul@xxxxxxx>, "Edgar E . Iglesias" <edgar.iglesias@xxxxxxxxx>, "Michael S . Tsirkin" <mst@xxxxxxxxxx>, Marcel Apfelbaum <marcel.apfelbaum@xxxxxxxxx>, "qemu-devel@xxxxxxxxxx" <qemu-devel@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, "Huang, Ray" <Ray.Huang@xxxxxxx>, "Chen, Jiqian" <Jiqian.Chen@xxxxxxx>
  • Delivery-date: Mon, 04 Nov 2024 06:04:26 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHbJfQPdMv3M7YW802ZtCXuQqWNubKicokAgATEWwA=
  • Thread-topic: [QEMU PATCH v9] xen/passthrough: use gsi to map pirq when dom0 is PVH

On 2024/11/1 21:09, Stewart Hildebrand wrote:
> On 10/24/24 05:06, Jiqian Chen wrote:
>> diff --git a/hw/xen/xen_pt.c b/hw/xen/xen_pt.c
>> index 3635d1b39f79..5b10d501d566 100644
>> --- a/hw/xen/xen_pt.c
>> +++ b/hw/xen/xen_pt.c
>> @@ -766,6 +766,50 @@ static void xen_pt_destroy(PCIDevice *d) {
>>  }
>>  /* init */
>>  
>> +#if CONFIG_XEN_CTRL_INTERFACE_VERSION >= 42000
>> +static bool xen_pt_need_gsi(void)
>> +{
>> +    FILE *fp;
>> +    int len;
>> +    char type[10];
> 
> A brief in-code comment to explain how you arrived at 10 would be
> appreciated.
The max number of characters in the description of the "guest_type" is 4 ("PVH" 
plus line break).
I set it to 10 to prevent longer description types in the future.
Do you have another suggest number?

> 
>> +    const char *guest_type = "/sys/hypervisor/guest_type";
>> +
>> +    fp = fopen(guest_type, "r");
>> +    if (fp == NULL) {
>> +        error_report("Cannot open %s: %s", guest_type, strerror(errno));
>> +        return false;
>> +    }
>> +    fgets(type, sizeof(type), fp);
> 
> Please check the return value of fgets.
Will change in next version.

> 
>> +    fclose(fp);
>> +
>> +    len = strlen(type);
> 
> Before passing to strlen, is "type" always guaranteed to have a
> terminating '\0' character?
Yes, "fgets" will guarantee that, and I will add check for "fgets" when it 
returns NULL in next version.

> 
>> +    if (len) {
>> +        type[len - 1] = '\0';
>> +        if (!strcmp(type, "PVH")) {
>> +            return true;
>> +        }
>> +    }
>> +    return false;
>> +}
>> +
>> +static int xen_pt_map_pirq_for_gsi(PCIDevice *d, int *pirq)
>> +{
>> +    int gsi;
>> +    XenPCIPassthroughState *s = XEN_PT_DEVICE(d);
>> +
>> +    gsi = xc_pcidev_get_gsi(xen_xc,
>> +                            PCI_SBDF(s->real_device.domain,
>> +                                     s->real_device.bus,
>> +                                     s->real_device.dev,
>> +                                     s->real_device.func));
>> +    if (gsi >= 0) {
>> +        return xc_physdev_map_pirq_gsi(xen_xc, xen_domid, gsi, pirq);
>> +    }
>> +
>> +    return gsi;
>> +}
>> +#endif
>> +
>>  static void xen_pt_realize(PCIDevice *d, Error **errp)
>>  {
>>      ERRP_GUARD();
>> @@ -847,7 +891,16 @@ static void xen_pt_realize(PCIDevice *d, Error **errp)
>>          goto out;
>>      }
>>  
>> +#if CONFIG_XEN_CTRL_INTERFACE_VERSION >= 42000
>> +    if (xen_pt_need_gsi()) {
>> +        rc = xen_pt_map_pirq_for_gsi(d, &pirq);
>> +    } else {
>> +        rc = xc_physdev_map_pirq(xen_xc, xen_domid, machine_irq, &pirq);
>> +    }
>> +#else
>>      rc = xc_physdev_map_pirq(xen_xc, xen_domid, machine_irq, &pirq);
>> +#endif
>> +
>>      if (rc < 0) {
>>          XEN_PT_ERR(d, "Mapping machine irq %u to pirq %i failed, (err: 
>> %d)\n",
>>                     machine_irq, pirq, errno);
>> diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
>> index eb26cac81098..07805aa8a5f3 100644
>> --- a/include/hw/pci/pci.h
>> +++ b/include/hw/pci/pci.h
>> @@ -23,6 +23,10 @@ extern bool pci_available;
>>  #define PCI_SLOT_MAX            32
>>  #define PCI_FUNC_MAX            8
>>  
>> +#define PCI_SBDF(seg, bus, dev, func) \
>> +            ((((uint32_t)(seg)) << 16) | \
>> +            (PCI_BUILD_BDF(bus, PCI_DEVFN(dev, func))))
>> +
>>  /* Class, Vendor and Device IDs from Linux's pci_ids.h */
>>  #include "hw/pci/pci_ids.h"
>>  
> 

-- 
Best regards,
Jiqian Chen.

 


Rackspace

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