Skip to content

Commit

Permalink
print: introduce a format specifier for pci_sbdf_t
Browse files Browse the repository at this point in the history
The new format specifier is '%pp', and prints a pci_sbdf_t using the
seg:bus:dev.func format. Replace all SBDFs printed using
'%04x:%02x:%02x.%u' to use the new format specifier.

No functional change intended.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Acked-by: Julien Grall <julien.grall@arm.com>
For just the pieces where Jan is the only maintainer:
Acked-by: Jan Beulich <jbeulich@suse.com>
  • Loading branch information
royger authored and andyhhp committed Jul 28, 2020
1 parent 8899a28 commit 1ee1441
Show file tree
Hide file tree
Showing 20 changed files with 189 additions and 254 deletions.
5 changes: 5 additions & 0 deletions docs/misc/printk-formats.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,8 @@ Domain and vCPU information:
The domain part as above, with the vcpu_id printed in decimal.
e.g. d0v1
d[IDLE]v0

PCI:

%pp PCI device address in S:B:D.F format from a pci_sbdf_t.
e.g. 0004:02:00.0
10 changes: 3 additions & 7 deletions xen/arch/x86/hvm/vmsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -697,10 +697,8 @@ static int vpci_msi_update(const struct pci_dev *pdev, uint32_t data,

if ( rc )
{
gdprintk(XENLOG_ERR,
"%04x:%02x:%02x.%u: failed to bind PIRQ %u: %d\n",
pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn),
PCI_FUNC(pdev->devfn), pirq + i, rc);
gdprintk(XENLOG_ERR, "%pp: failed to bind PIRQ %u: %d\n",
&pdev->sbdf, pirq + i, rc);
while ( bind.machine_irq-- > pirq )
pt_irq_destroy_bind(pdev->domain, &bind);
return rc;
Expand Down Expand Up @@ -754,9 +752,7 @@ static int vpci_msi_enable(const struct pci_dev *pdev, uint32_t data,
&msi_info);
if ( rc )
{
gdprintk(XENLOG_ERR, "%04x:%02x:%02x.%u: failed to map PIRQ: %d\n",
pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn),
PCI_FUNC(pdev->devfn), rc);
gdprintk(XENLOG_ERR, "%pp: failed to map PIRQ: %d\n", &pdev->sbdf, rc);
return rc;
}

Expand Down
37 changes: 14 additions & 23 deletions xen/arch/x86/msi.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ static bool msi_set_mask_bit(struct irq_desc *desc, bool host, bool guest)
{
pdev->msix->warned = domid;
printk(XENLOG_G_WARNING
"cannot mask IRQ %d: masking MSI-X on Dom%d's %04x:%02x:%02x.%u\n",
desc->irq, domid, seg, bus, slot, func);
"cannot mask IRQ %d: masking MSI-X on Dom%d's %pp\n",
desc->irq, domid, &pdev->sbdf);
}
}
pdev->msix->host_maskall = maskall;
Expand Down Expand Up @@ -985,11 +985,11 @@ static int msix_capability_init(struct pci_dev *dev,
struct domain *d = dev->domain ?: currd;

if ( !is_hardware_domain(currd) || d != currd )
printk("%s use of MSI-X on %04x:%02x:%02x.%u by Dom%d\n",
printk("%s use of MSI-X on %pp by %pd\n",
is_hardware_domain(currd)
? XENLOG_WARNING "Potentially insecure"
: XENLOG_ERR "Insecure",
seg, bus, slot, func, d->domain_id);
&dev->sbdf, d);
if ( !is_hardware_domain(d) &&
/* Assume a domain without memory has no mappings yet. */
(!is_hardware_domain(currd) || domain_tot_pages(d)) )
Expand Down Expand Up @@ -1043,18 +1043,15 @@ static int __pci_enable_msi(struct msi_info *msi, struct msi_desc **desc)
old_desc = find_msi_entry(pdev, msi->irq, PCI_CAP_ID_MSI);
if ( old_desc )
{
printk(XENLOG_ERR "irq %d already mapped to MSI on %04x:%02x:%02x.%u\n",
msi->irq, msi->seg, msi->bus,
PCI_SLOT(msi->devfn), PCI_FUNC(msi->devfn));
printk(XENLOG_ERR "irq %d already mapped to MSI on %pp\n",
msi->irq, &pdev->sbdf);
return -EEXIST;
}

old_desc = find_msi_entry(pdev, -1, PCI_CAP_ID_MSIX);
if ( old_desc )
{
printk(XENLOG_WARNING "MSI-X already in use on %04x:%02x:%02x.%u\n",
msi->seg, msi->bus,
PCI_SLOT(msi->devfn), PCI_FUNC(msi->devfn));
printk(XENLOG_WARNING "MSI-X already in use on %pp\n", &pdev->sbdf);
__pci_disable_msix(old_desc);
}

Expand Down Expand Up @@ -1091,8 +1088,6 @@ static void __pci_disable_msi(struct msi_desc *entry)
static int __pci_enable_msix(struct msi_info *msi, struct msi_desc **desc)
{
struct pci_dev *pdev;
u8 slot = PCI_SLOT(msi->devfn);
u8 func = PCI_FUNC(msi->devfn);
struct msi_desc *old_desc;

ASSERT(pcidevs_locked());
Expand All @@ -1106,16 +1101,15 @@ static int __pci_enable_msix(struct msi_info *msi, struct msi_desc **desc)
old_desc = find_msi_entry(pdev, msi->irq, PCI_CAP_ID_MSIX);
if ( old_desc )
{
printk(XENLOG_ERR "irq %d already mapped to MSI-X on %04x:%02x:%02x.%u\n",
msi->irq, msi->seg, msi->bus, slot, func);
printk(XENLOG_ERR "irq %d already mapped to MSI-X on %pp\n",
msi->irq, &pdev->sbdf);
return -EEXIST;
}

old_desc = find_msi_entry(pdev, -1, PCI_CAP_ID_MSI);
if ( old_desc )
{
printk(XENLOG_WARNING "MSI already in use on %04x:%02x:%02x.%u\n",
msi->seg, msi->bus, slot, func);
printk(XENLOG_WARNING "MSI already in use on %pp\n", &pdev->sbdf);
__pci_disable_msi(old_desc);
}

Expand Down Expand Up @@ -1162,9 +1156,8 @@ static void __pci_disable_msix(struct msi_desc *entry)
writel(1, entry->mask_base + PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET);
else if ( !(control & PCI_MSIX_FLAGS_MASKALL) )
{
printk(XENLOG_WARNING
"cannot disable IRQ %d: masking MSI-X on %04x:%02x:%02x.%u\n",
entry->irq, seg, bus, slot, func);
printk(XENLOG_WARNING "cannot disable IRQ %d: masking MSI-X on %pp\n",
entry->irq, &dev->sbdf);
maskall = true;
}
dev->msix->host_maskall = maskall;
Expand Down Expand Up @@ -1340,7 +1333,6 @@ int pci_restore_msi_state(struct pci_dev *pdev)
struct msi_desc *entry, *tmp;
struct irq_desc *desc;
struct msi_msg msg;
u8 slot = PCI_SLOT(pdev->devfn), func = PCI_FUNC(pdev->devfn);
unsigned int type = 0, pos = 0;
u16 control = 0;

Expand Down Expand Up @@ -1369,9 +1361,8 @@ int pci_restore_msi_state(struct pci_dev *pdev)
if (desc->msi_desc != entry)
{
bogus:
dprintk(XENLOG_ERR,
"Restore MSI for %04x:%02x:%02x:%u entry %u not set?\n",
pdev->seg, pdev->bus, slot, func, i);
dprintk(XENLOG_ERR, "Restore MSI for %pp entry %u not set?\n",
&pdev->sbdf, i);
spin_unlock_irqrestore(&desc->lock, flags);
if ( type == PCI_CAP_ID_MSIX )
pci_conf_write16(pdev->sbdf, msix_control_reg(pos),
Expand Down
18 changes: 18 additions & 0 deletions xen/common/vsprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,20 @@ static char *print_vcpu(char *str, const char *end, const struct vcpu *v)
return number(str + 1, end, v->vcpu_id, 10, -1, -1, 0);
}

static char *print_pci_addr(char *str, const char *end, const pci_sbdf_t *sbdf)
{
str = number(str, end, sbdf->seg, 16, 4, -1, ZEROPAD);
if ( str < end )
*str = ':';
str = number(str + 1, end, sbdf->bus, 16, 2, -1, ZEROPAD);
if ( str < end )
*str = ':';
str = number(str + 1, end, sbdf->dev, 16, 2, -1, ZEROPAD);
if ( str < end )
*str = '.';
return number(str + 1, end, sbdf->fn, 8, -1, -1, 0);
}

static char *pointer(char *str, const char *end, const char **fmt_ptr,
const void *arg, int field_width, int precision,
int flags)
Expand Down Expand Up @@ -476,6 +490,10 @@ static char *pointer(char *str, const char *end, const char **fmt_ptr,
}
}

case 'p': /* PCI SBDF. */
++*fmt_ptr;
return print_pci_addr(str, end, arg);

case 's': /* Symbol name with offset and size (iff offset != 0) */
case 'S': /* Symbol name unconditionally with offset and size */
{
Expand Down
22 changes: 10 additions & 12 deletions xen/drivers/passthrough/amd/iommu_acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ static void __init add_ivrs_mapping_entry(
iommu, &ivrs_mappings[alias_id].intremap_inuse, 0);

if ( !ivrs_mappings[alias_id].intremap_table )
panic("No memory for %04x:%02x:%02x.%u's IRT\n",
iommu->seg, PCI_BUS(alias_id), PCI_SLOT(alias_id),
PCI_FUNC(alias_id));
panic("No memory for %pp's IRT\n",
&PCI_SBDF2(iommu->seg, alias_id));
}
}

Expand Down Expand Up @@ -738,9 +737,8 @@ static u16 __init parse_ivhd_device_special(
return 0;
}

AMD_IOMMU_DEBUG("IVHD Special: %04x:%02x:%02x.%u variety %#x handle %#x\n",
seg, PCI_BUS(bdf), PCI_SLOT(bdf), PCI_FUNC(bdf),
special->variety, special->handle);
AMD_IOMMU_DEBUG("IVHD Special: %pp variety %#x handle %#x\n",
&PCI_SBDF2(seg, bdf), special->variety, special->handle);
add_ivrs_mapping_entry(bdf, bdf, special->header.data_setting, true,
iommu);

Expand All @@ -764,9 +762,9 @@ static u16 __init parse_ivhd_device_special(
if ( idx < nr_ioapic_sbdf )
{
AMD_IOMMU_DEBUG("IVHD: Command line override present for IO-APIC %#x"
"(IVRS: %#x devID %04x:%02x:%02x.%u)\n",
ioapic_sbdf[idx].id, special->handle, seg,
PCI_BUS(bdf), PCI_SLOT(bdf), PCI_FUNC(bdf));
"(IVRS: %#x devID %pp)\n",
ioapic_sbdf[idx].id, special->handle,
&PCI_SBDF2(seg, bdf));
break;
}

Expand Down Expand Up @@ -836,9 +834,9 @@ static u16 __init parse_ivhd_device_special(
break;
case HPET_CMDL:
AMD_IOMMU_DEBUG("IVHD: Command line override present for HPET %#x "
"(IVRS: %#x devID %04x:%02x:%02x.%u)\n",
hpet_sbdf.id, special->handle, seg, PCI_BUS(bdf),
PCI_SLOT(bdf), PCI_FUNC(bdf));
"(IVRS: %#x devID %pp)\n",
hpet_sbdf.id, special->handle,
&PCI_SBDF2(seg, bdf));
break;
case HPET_NONE:
/* set device id of hpet */
Expand Down
5 changes: 2 additions & 3 deletions xen/drivers/passthrough/amd/iommu_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,8 @@ void amd_iommu_flush_iotlb(u8 devfn, const struct pci_dev *pdev,

if ( !iommu )
{
AMD_IOMMU_DEBUG("%s: Can't find iommu for %04x:%02x:%02x.%u\n",
__func__, pdev->seg, pdev->bus,
PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
AMD_IOMMU_DEBUG("%s: Can't find iommu for %pp\n",
__func__, &pdev->sbdf);
return;
}

Expand Down
5 changes: 2 additions & 3 deletions xen/drivers/passthrough/amd/iommu_detect.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,8 @@ int __init amd_iommu_detect_one_acpi(

rt = pci_ro_device(iommu->seg, bus, PCI_DEVFN(dev, func));
if ( rt )
printk(XENLOG_ERR
"Could not mark config space of %04x:%02x:%02x.%u read-only (%d)\n",
iommu->seg, bus, dev, func, rt);
printk(XENLOG_ERR "Could not mark config space of %pp read-only (%d)\n",
&PCI_SBDF2(iommu->seg, iommu->bdf), rt);

list_add_tail(&iommu->list, &amd_iommu_head);
rt = 0;
Expand Down
18 changes: 7 additions & 11 deletions xen/drivers/passthrough/amd/iommu_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -558,10 +558,10 @@ static void parse_event_log_entry(struct amd_iommu *iommu, u32 entry[])
unsigned int flags = MASK_EXTR(entry[1], IOMMU_EVENT_FLAGS_MASK);
uint64_t addr = *(uint64_t *)(entry + 2);

printk(XENLOG_ERR "AMD-Vi: %s: %04x:%02x:%02x.%u d%d addr %016"PRIx64
printk(XENLOG_ERR "AMD-Vi: %s: %pp d%u addr %016"PRIx64
" flags %#x%s%s%s%s%s%s%s%s%s%s\n",
code_str, iommu->seg, PCI_BUS(device_id), PCI_SLOT(device_id),
PCI_FUNC(device_id), domain_id, addr, flags,
code_str, &PCI_SBDF2(iommu->seg, device_id),
domain_id, addr, flags,
(flags & 0xe00) ? " ??" : "",
(flags & 0x100) ? " TR" : "",
(flags & 0x080) ? " RZ" : "",
Expand Down Expand Up @@ -753,9 +753,8 @@ static bool_t __init set_iommu_interrupt_handler(struct amd_iommu *iommu)
pcidevs_unlock();
if ( !iommu->msi.dev )
{
AMD_IOMMU_DEBUG("IOMMU: no pdev for %04x:%02x:%02x.%u\n",
iommu->seg, PCI_BUS(iommu->bdf),
PCI_SLOT(iommu->bdf), PCI_FUNC(iommu->bdf));
AMD_IOMMU_DEBUG("IOMMU: no pdev for %pp\n",
&PCI_SBDF2(iommu->seg, iommu->bdf));
return 0;
}

Expand Down Expand Up @@ -841,9 +840,6 @@ __initcall(iov_adjust_irq_affinities);
static void amd_iommu_erratum_746_workaround(struct amd_iommu *iommu)
{
u32 value;
u8 bus = PCI_BUS(iommu->bdf);
u8 dev = PCI_SLOT(iommu->bdf);
u8 func = PCI_FUNC(iommu->bdf);

if ( (boot_cpu_data.x86 != 0x15) ||
(boot_cpu_data.x86_model < 0x10) ||
Expand All @@ -861,8 +857,8 @@ static void amd_iommu_erratum_746_workaround(struct amd_iommu *iommu)

pci_conf_write32(PCI_SBDF2(iommu->seg, iommu->bdf), 0xf4, value | (1 << 2));
printk(XENLOG_INFO
"AMD-Vi: Applying erratum 746 workaround for IOMMU at %04x:%02x:%02x.%u\n",
iommu->seg, bus, dev, func);
"AMD-Vi: Applying erratum 746 workaround for IOMMU at %pp\n",
&PCI_SBDF2(iommu->seg, iommu->bdf));

/* Clear the enable writing bit */
pci_conf_write32(PCI_SBDF2(iommu->seg, iommu->bdf), 0xf0, 0x90);
Expand Down
9 changes: 3 additions & 6 deletions xen/drivers/passthrough/amd/iommu_intr.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,7 @@ static struct amd_iommu *_find_iommu_for_device(int seg, int bdf)
if ( iommu )
return iommu;

AMD_IOMMU_DEBUG("No IOMMU for MSI dev = %04x:%02x:%02x.%u\n",
seg, PCI_BUS(bdf), PCI_SLOT(bdf), PCI_FUNC(bdf));
AMD_IOMMU_DEBUG("No IOMMU for MSI dev = %pp\n", &PCI_SBDF2(seg, bdf));
return ERR_PTR(-EINVAL);
}

Expand Down Expand Up @@ -863,10 +862,8 @@ static void dump_intremap_table(const struct amd_iommu *iommu,

if ( ivrs_mapping )
{
printk(" %04x:%02x:%02x:%u:\n", iommu->seg,
PCI_BUS(ivrs_mapping->dte_requestor_id),
PCI_SLOT(ivrs_mapping->dte_requestor_id),
PCI_FUNC(ivrs_mapping->dte_requestor_id));
printk(" %pp:\n",
&PCI_SBDF2(iommu->seg, ivrs_mapping->dte_requestor_id));
ivrs_mapping = NULL;
}

Expand Down
25 changes: 9 additions & 16 deletions xen/drivers/passthrough/amd/pci_amd_iommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ struct amd_iommu *find_iommu_for_device(int seg, int bdf)
tmp.dte_requestor_id = bdf;
ivrs_mappings[bdf] = tmp;

printk(XENLOG_WARNING "%04x:%02x:%02x.%u not found in ACPI tables;"
" using same IOMMU as function 0\n",
seg, PCI_BUS(bdf), PCI_SLOT(bdf), PCI_FUNC(bdf));
printk(XENLOG_WARNING "%pp not found in ACPI tables;"
" using same IOMMU as function 0\n", &PCI_SBDF2(seg, bdf));

/* write iommu field last */
ivrs_mappings[bdf].iommu = ivrs_mappings[bd0].iommu;
Expand Down Expand Up @@ -349,9 +348,8 @@ static int reassign_device(struct domain *source, struct domain *target,
return rc;

amd_iommu_setup_domain_device(target, iommu, devfn, pdev);
AMD_IOMMU_DEBUG("Re-assign %04x:%02x:%02x.%u from dom%d to dom%d\n",
pdev->seg, pdev->bus, PCI_SLOT(devfn), PCI_FUNC(devfn),
source->domain_id, target->domain_id);
AMD_IOMMU_DEBUG("Re-assign %pp from dom%d to dom%d\n",
&pdev->sbdf, source->domain_id, target->domain_id);

return 0;
}
Expand Down Expand Up @@ -459,15 +457,12 @@ static int amd_iommu_add_device(u8 devfn, struct pci_dev *pdev)
if ( pdev->type == DEV_TYPE_PCI_HOST_BRIDGE &&
is_hardware_domain(pdev->domain) )
{
AMD_IOMMU_DEBUG("Skipping host bridge %04x:%02x:%02x.%u\n",
pdev->seg, pdev->bus, PCI_SLOT(devfn),
PCI_FUNC(devfn));
AMD_IOMMU_DEBUG("Skipping host bridge %pp\n", &pdev->sbdf);
return 0;
}

AMD_IOMMU_DEBUG("No iommu for %04x:%02x:%02x.%u; cannot be handed to d%d\n",
pdev->seg, pdev->bus, PCI_SLOT(devfn), PCI_FUNC(devfn),
pdev->domain->domain_id);
AMD_IOMMU_DEBUG("No iommu for %pp; cannot be handed to d%d\n",
&pdev->sbdf, pdev->domain->domain_id);
return -ENODEV;
}

Expand Down Expand Up @@ -522,10 +517,8 @@ static int amd_iommu_remove_device(u8 devfn, struct pci_dev *pdev)
iommu = find_iommu_for_device(pdev->seg, bdf);
if ( !iommu )
{
AMD_IOMMU_DEBUG("Fail to find iommu."
" %04x:%02x:%02x.%u cannot be removed from dom%d\n",
pdev->seg, pdev->bus, PCI_SLOT(devfn), PCI_FUNC(devfn),
pdev->domain->domain_id);
AMD_IOMMU_DEBUG("Fail to find iommu. %pp cannot be removed from %pd\n",
&pdev->sbdf, pdev->domain);
return -ENODEV;
}

Expand Down

0 comments on commit 1ee1441

Please sign in to comment.