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

Re: [PATCH 2/5] vtd: Use pci_sbdf_t in acpi_parse_dev_scope()


  • To: Teddy Astie <teddy.astie@xxxxxxxxxx>
  • From: dmukhin@xxxxxxxx
  • Date: Tue, 19 May 2026 20:00:07 -0700
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 205.220.161.53) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=ford.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=ford.com; dkim=pass (signature was verified) header.d=saarlouis.ford.com; dkim=pass (signature was verified) header.d=ford.com; arc=none (0)
  • 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=fRi9H6nH899Pi7a2qa3EUyS/cVHiPDhQqk/JIJtR7lI=; b=eihzzELllLZvc5mWf24pFv9YWYEFviVWlvPo+UZVpQF6MSqul0Le6x8hZ/f2WJbQ4fkg1VYtbyMMMJB9QnY1DLJU0sOJHWPSjt3W2Il2gJvSXp4lGU220TGiLNzQWXO7FDUnlTp5SbvdGif/bWphwJDJEzQo2MH7kHCXusaBYvxKc/w0iP/YbILLq7ruTARBDXwlGq1NlsUVtVr9Eo+bF8ZjtJ3/wmrDMhwx07JGBCj72dahWM/fVlnqsATo7pws5dDs74yFFGRgbdo86rP9O/OZGC+MWCRFli/z2FUH7Rp/VrIXh7l2pjNccIcEKP5NxmXZgXzYTu/39Tg+7LQFsw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=NOgUCwBUoNdMR8xwd9ugyBYuvIfnRbT+6u+JNdt3Up9TyYwtRD3jxQdYDB9pNVYwG4jmpHY4u2HB8u1gUEk7LkSxe+iM8w3pru7SOn77jdPeh0EGc0HArtcSImr31KXwz78tDSPwCNePZg9cfW87v8yN+EZpcfLv+yCB7wOAb2/WW8wrk26FQqm5XGmzhPZCwEnKL42jyTn7pGd3ClfVwqmiFxsu46wiT4T9d6J/Crl7T5e33LN+rsZZTw2XWofdAPX7oQfRfrZx3UkTnHEbalfua7Lz6P+BnA+nwA2Sj+tRQEBqGr1B1JVMFfJ0Y2JuL1cKz/WVhH7jtK5mYwk+aw==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=ppford header.d=ford.com header.i="@ford.com" header.h="Cc:Content-Type:Date:From:In-Reply-To:Message-ID:MIME-Version:References:Subject:To"; dkim=pass header.s=selector2-azureford-onmicrosoft-com header.d=azureford.onmicrosoft.com header.i="@azureford.onmicrosoft.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"; dkim=pass header.s=ppserprodsaar header.d=saarlouis.ford.com header.i="@saarlouis.ford.com" header.h="Cc:Content-Type:Date:From:In-Reply-To:Message-ID:MIME-Version:References:Subject:To"; dkim=pass header.s=ppfserpocford header.d=ford.com header.i="@ford.com" header.h="Cc:Content-Type:Date:From:In-Reply-To:Message-ID:MIME-Version:References:Subject:To"
  • Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Wed, 20 May 2026 03:00:39 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Pser-m365-app: SER-APP

On Mon, May 18, 2026 at 05:21:26PM +0200, Teddy Astie wrote:
> Use a dedicated pci_sbdf_t struct that we update instead of recreating
> one each time we need it.
> 
> Signed-off-by: Teddy Astie <teddy.astie@xxxxxxxxxx>
> ---
>  xen/drivers/passthrough/vtd/dmar.c | 42 ++++++++++++------------------
>  1 file changed, 16 insertions(+), 26 deletions(-)
> 
> diff --git a/xen/drivers/passthrough/vtd/dmar.c 
> b/xen/drivers/passthrough/vtd/dmar.c
> index 2a756831a6..c36f4bbd7b 100644
> --- a/xen/drivers/passthrough/vtd/dmar.c
> +++ b/xen/drivers/passthrough/vtd/dmar.c
> @@ -310,7 +310,7 @@ static int __init acpi_parse_dev_scope(
>  {
>      struct acpi_ioapic_unit *acpi_ioapic_unit;
>      const struct acpi_dmar_device_scope *acpi_scope;
> -    u16 bus, sub_bus, sec_bus;
> +    u16 sub_bus, sec_bus;
>      const struct acpi_dmar_pci_path *path;
>      struct acpi_drhd_unit *drhd = type == DMAR_TYPE ?
>          container_of(scope, struct acpi_drhd_unit, scope) : NULL;
> @@ -332,29 +332,26 @@ static int __init acpi_parse_dev_scope(
>  
>      while ( start < end )
>      {
> +        pci_sbdf_t dev_sbdf;
>          acpi_scope = start;
>          path = (const void *)(acpi_scope + 1);
>          depth = (acpi_scope->length - sizeof(*acpi_scope)) / sizeof(*path);
> -        bus = acpi_scope->bus;
> +        dev_sbdf = PCI_SBDF(seg, acpi_scope->bus, path->dev, path->fn);

`dev_sbdf` calculation depends on `path` which is updated in `while()` loop
below.

>  
>          while ( --depth > 0 )
>          {
> -            bus = pci_conf_read8(PCI_SBDF(seg, bus, path->dev, path->fn),
> -                                 PCI_SECONDARY_BUS);
> +            dev_sbdf.bus = pci_conf_read8(dev_sbdf, PCI_SECONDARY_BUS);
>              path++;
>          }
>  
>          switch ( acpi_scope->entry_type )
>          {
>          case ACPI_DMAR_SCOPE_TYPE_BRIDGE:
> -            sec_bus = pci_conf_read8(PCI_SBDF(seg, bus, path->dev, path->fn),
> -                                     PCI_SECONDARY_BUS);
> -            sub_bus = pci_conf_read8(PCI_SBDF(seg, bus, path->dev, path->fn),
> -                                     PCI_SUBORDINATE_BUS);
> +            sec_bus = pci_conf_read8(dev_sbdf, PCI_SECONDARY_BUS);
> +            sub_bus = pci_conf_read8(dev_sbdf, PCI_SUBORDINATE_BUS);
>              if ( iommu_verbose )
>                  printk(VTDPREFIX " bridge: %pp start=%x sec=%x sub=%x\n",
> -                       &PCI_SBDF(seg, bus, path->dev, path->fn),
> -                       acpi_scope->bus, sec_bus, sub_bus);
> +                       &dev_sbdf, acpi_scope->bus, sec_bus, sub_bus);
>  
>              dmar_scope_add_buses(scope, sec_bus, sub_bus);
>              gfx_only = false;
> @@ -362,8 +359,7 @@ static int __init acpi_parse_dev_scope(
>  
>          case ACPI_DMAR_SCOPE_TYPE_HPET:
>              if ( iommu_verbose )
> -                printk(VTDPREFIX " MSI HPET: %pp\n",
> -                       &PCI_SBDF(seg, bus, path->dev, path->fn));
> +                printk(VTDPREFIX " MSI HPET: %pp\n", &dev_sbdf);
>  
>              if ( drhd )
>              {
> @@ -374,9 +370,7 @@ static int __init acpi_parse_dev_scope(
>                  if ( !acpi_hpet_unit )
>                      goto out;
>                  acpi_hpet_unit->id = acpi_scope->enumeration_id;
> -                acpi_hpet_unit->bus = bus;
> -                acpi_hpet_unit->dev = path->dev;
> -                acpi_hpet_unit->func = path->fn;
> +                acpi_hpet_unit->bdf = dev_sbdf.bdf;
>                  list_add(&acpi_hpet_unit->list, &drhd->hpet_list);
>  
>                  gfx_only = false;
> @@ -386,16 +380,15 @@ static int __init acpi_parse_dev_scope(
>  
>          case ACPI_DMAR_SCOPE_TYPE_ENDPOINT:
>              if ( iommu_verbose )
> -                printk(VTDPREFIX " endpoint: %pp\n",
> -                       &PCI_SBDF(seg, bus, path->dev, path->fn));
> +                printk(VTDPREFIX " endpoint: %pp\n", &dev_sbdf);
>  
> -            if ( drhd && pci_device_detect(seg, bus, path->dev, path->fn) )
> +            if ( drhd && pci_device_detect(seg, dev_sbdf.bus, dev_sbdf.dev, 
> dev_sbdf.fn) )

Looks like `pci_device_detect()` also needs some refactoring...
(Probably out of scope for this series, though)

>              {
> -                if ( pci_conf_read8(PCI_SBDF(seg, bus, path->dev, path->fn),
> +                if ( pci_conf_read8(dev_sbdf,
>                                      PCI_CLASS_DEVICE + 1) != 0x03
>                                      /* PCI_BASE_CLASS_DISPLAY */ )
>                      gfx_only = false;
> -                else if ( !seg && !bus && path->dev == 2 && !path->fn )
> +                else if ( !seg && !dev_sbdf.bus && path->dev == 2 && 
> !path->fn )
>                      igd_drhd_address = drhd->address;
>              }
>  
> @@ -403,8 +396,7 @@ static int __init acpi_parse_dev_scope(
>  
>          case ACPI_DMAR_SCOPE_TYPE_IOAPIC:
>              if ( iommu_verbose )
> -                printk(VTDPREFIX " IOAPIC: %pp\n",
> -                       &PCI_SBDF(seg, bus, path->dev, path->fn));
> +                printk(VTDPREFIX " IOAPIC: %pp\n", &dev_sbdf);
>  
>              if ( drhd )
>              {
> @@ -413,9 +405,7 @@ static int __init acpi_parse_dev_scope(
>                  if ( !acpi_ioapic_unit )
>                      goto out;
>                  acpi_ioapic_unit->apic_id = acpi_scope->enumeration_id;
> -                acpi_ioapic_unit->ioapic.bdf.bus = bus;
> -                acpi_ioapic_unit->ioapic.bdf.dev = path->dev;
> -                acpi_ioapic_unit->ioapic.bdf.func = path->fn;
> +                acpi_ioapic_unit->ioapic.info = dev_sbdf.bdf;
>                  list_add(&acpi_ioapic_unit->list, &drhd->ioapic_list);
>  
>                  gfx_only = false;
> @@ -431,7 +421,7 @@ static int __init acpi_parse_dev_scope(
>              gfx_only = false;
>              continue;
>          }
> -        scope->devices[didx++] = PCI_BDF(bus, path->dev, path->fn);
> +        scope->devices[didx++] = dev_sbdf.bdf;
>          start += acpi_scope->length;
>      }
>  
> -- 
> 2.52.0
> 
> 
> 
> --
> Teddy Astie | Vates XCP-ng Developer
> 
> XCP-ng & Xen Orchestra - Vates solutions
> 
> web: https://vates.tech



 


Rackspace

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