2018-01-31 01:11:08

by Gary R Hook

[permalink] [raw]
Subject: [PATCH] iommu/amd - Use dev_err to send events to the system log

Remove printk and use a more preferable error logging function.

Signed-off-by: Gary R Hook <[email protected]>
---
drivers/iommu/amd_iommu.c | 56 +++++++++++++++++++++++----------------------
1 file changed, 29 insertions(+), 27 deletions(-)

diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index b58e0a745b7f..90a61f546bac 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -546,6 +546,8 @@ static void amd_iommu_report_page_fault(u16 devid, u16 domain_id,

static void iommu_print_event(struct amd_iommu *iommu, void *__evt)
{
+ struct pci_dev *pdev = iommu->dev;
+ struct device *dev = &pdev->dev;
int type, devid, domid, flags;
volatile u32 *event = __evt;
int count = 0;
@@ -572,53 +574,53 @@ static void iommu_print_event(struct amd_iommu *iommu, void *__evt)
amd_iommu_report_page_fault(devid, domid, address, flags);
return;
} else {
- printk(KERN_ERR "AMD-Vi: Event logged [");
+ dev_err(dev, "AMD-Vi: Event logged [");
}

switch (type) {
case EVENT_TYPE_ILL_DEV:
- printk("ILLEGAL_DEV_TABLE_ENTRY device=%02x:%02x.%x "
- "address=0x%016llx flags=0x%04x]\n",
- PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid),
- address, flags);
+ dev_err(dev, "ILLEGAL_DEV_TABLE_ENTRY device=%02x:%02x.%x "
+ "address=0x%016llx flags=0x%04x]\n",
+ PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid),
+ address, flags);
dump_dte_entry(devid);
break;
case EVENT_TYPE_DEV_TAB_ERR:
- printk("DEV_TAB_HARDWARE_ERROR device=%02x:%02x.%x "
- "address=0x%016llx flags=0x%04x]\n",
- PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid),
- address, flags);
+ dev_err(dev, "DEV_TAB_HARDWARE_ERROR device=%02x:%02x.%x "
+ "address=0x%016llx flags=0x%04x]\n",
+ PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid),
+ address, flags);
break;
case EVENT_TYPE_PAGE_TAB_ERR:
- printk("PAGE_TAB_HARDWARE_ERROR device=%02x:%02x.%x "
- "domain=0x%04x address=0x%016llx flags=0x%04x]\n",
- PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid),
- domid, address, flags);
+ dev_err(dev, "PAGE_TAB_HARDWARE_ERROR device=%02x:%02x.%x "
+ "domain=0x%04x address=0x%016llx flags=0x%04x]\n",
+ PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid),
+ domid, address, flags);
break;
case EVENT_TYPE_ILL_CMD:
- printk("ILLEGAL_COMMAND_ERROR address=0x%016llx]\n", address);
+ dev_err(dev, "ILLEGAL_COMMAND_ERROR address=0x%016llx]\n", address);
dump_command(address);
break;
case EVENT_TYPE_CMD_HARD_ERR:
- printk("COMMAND_HARDWARE_ERROR address=0x%016llx "
- "flags=0x%04x]\n", address, flags);
+ dev_err(dev, "COMMAND_HARDWARE_ERROR address=0x%016llx "
+ "flags=0x%04x]\n", address, flags);
break;
case EVENT_TYPE_IOTLB_INV_TO:
- printk("IOTLB_INV_TIMEOUT device=%02x:%02x.%x "
- "address=0x%016llx]\n",
- PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid),
- address);
+ dev_err(dev, "IOTLB_INV_TIMEOUT device=%02x:%02x.%x "
+ "address=0x%016llx]\n",
+ PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid),
+ address);
break;
case EVENT_TYPE_INV_DEV_REQ:
- printk("INVALID_DEVICE_REQUEST device=%02x:%02x.%x "
- "address=0x%016llx flags=0x%04x]\n",
- PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid),
- address, flags);
+ dev_err(dev, "INVALID_DEVICE_REQUEST device=%02x:%02x.%x "
+ "address=0x%016llx flags=0x%04x]\n",
+ PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid),
+ address, flags);
break;
default:
- printk(KERN_ERR "UNKNOWN type=0x%02x event[0]=0x%08x "
- "event[1]=0x%08x event[2]=0x%08x event[3]=0x%08x\n",
- type, event[0], event[1], event[2], event[3]);
+ dev_err(dev, KERN_ERR "UNKNOWN event[0]=0x%08x event[1]=0x%08x "
+ "event[2]=0x%08x event[3]=0x%08x\n",
+ event[0], event[1], event[2], event[3]);
}

memset(__evt, 0, 4 * sizeof(u32));



2018-02-13 13:24:28

by Joerg Roedel

[permalink] [raw]
Subject: Re: [PATCH] iommu/amd - Use dev_err to send events to the system log

On Tue, Jan 30, 2018 at 07:04:27PM -0600, Gary R Hook wrote:
> + dev_err(dev, "ILLEGAL_DEV_TABLE_ENTRY device=%02x:%02x.%x "
> + "address=0x%016llx flags=0x%04x]\n",
> + PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid),
> + address, flags);

That prints the PCI device-name of the IOMMU in front of the message. Is
that actually helpful?

If at all, we should print the name of the iommu-device in front of the
message, not the PCI device that hosts the IOMMU.


Thanks,

Joerg


2018-02-13 15:49:21

by Gary R Hook

[permalink] [raw]
Subject: Re: [PATCH] iommu/amd - Use dev_err to send events to the system log

On 2/13/2018 8:22 AM, Joerg Roedel wrote:
> On Tue, Jan 30, 2018 at 07:04:27PM -0600, Gary R Hook wrote:
>> + dev_err(dev, "ILLEGAL_DEV_TABLE_ENTRY device=%02x:%02x.%x "
>> + "address=0x%016llx flags=0x%04x]\n",
>> + PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid),
>> + address, flags);
>
> That prints the PCI device-name of the IOMMU in front of the message. Is
> that actually helpful?
>
> If at all, we should print the name of the iommu-device in front of the
> message, not the PCI device that hosts the IOMMU.

so (e.g.):

dev_err(&iommu->dev->dev, "ILLEGAL...

?

I'm okay with that. It does make more sense.

Gary

2018-02-13 16:03:40

by Joerg Roedel

[permalink] [raw]
Subject: Re: [PATCH] iommu/amd - Use dev_err to send events to the system log

On Tue, Feb 13, 2018 at 10:47:55AM -0500, Hook, Gary wrote:
>
> dev_err(&iommu->dev->dev, "ILLEGAL...

I think its more something like iommu->iommu->dev.


Joerg

2018-02-13 19:25:59

by Gary R Hook

[permalink] [raw]
Subject: Re: [PATCH] iommu/amd - Use dev_err to send events to the system log

On 2/13/2018 11:00 AM, Joerg Roedel wrote:
> On Tue, Feb 13, 2018 at 10:47:55AM -0500, Hook, Gary wrote:
>>
>> dev_err(&iommu->dev->dev, "ILLEGAL...
>
> I think its more something like iommu->iommu->dev.
>
>


Without actually running a driver and getting some debug info, I'll just
say that my example compiled, the amd_iommu structure points to a
pci_dev which contains a device, and the two possibilities are likely
equivalent.

I'll vet that, of course, but working under the assumption that they are
equivalent, the question becomes, do you have a preference?

Thanks,
Gary

2018-02-14 11:50:53

by Joerg Roedel

[permalink] [raw]
Subject: Re: [PATCH] iommu/amd - Use dev_err to send events to the system log

On Tue, Feb 13, 2018 at 02:24:56PM -0500, Hook, Gary wrote:
> Without actually running a driver and getting some debug info, I'll just
> say that my example compiled, the amd_iommu structure points to a pci_dev
> which contains a device, and the two possibilities are likely equivalent.
>
> I'll vet that, of course, but working under the assumption that they are
> equivalent, the question becomes, do you have a preference?

They are not equivalent, your version points to the pci_dev containing
the IOMMU, my version points to the (virtual) iommu-device for that
particular iommu in the kernel.

So the difference in the prefix is:

your version: '0000:00:00.2:'

vs. my version: 'ivhd0:'

The latter is the better prefix, because it points to the iommu. A
pci_dev can contain more than one iommu, so that prefix is not specific
enough. I know that there is currently no hardware implementing multiple
iommus on one pci_dev, but it is allowed according to the spec.


Regards,

Joerg

2018-02-14 19:56:44

by Gary R Hook

[permalink] [raw]
Subject: Re: [PATCH] iommu/amd - Use dev_err to send events to the system log

On 2/14/2018 6:49 AM, Joerg Roedel wrote:
> On Tue, Feb 13, 2018 at 02:24:56PM -0500, Hook, Gary wrote:
>> Without actually running a driver and getting some debug info, I'll just
>> say that my example compiled, the amd_iommu structure points to a pci_dev
>> which contains a device, and the two possibilities are likely equivalent.
>>
>> I'll vet that, of course, but working under the assumption that they are
>> equivalent, the question becomes, do you have a preference?
>
> They are not equivalent, your version points to the pci_dev containing
> the IOMMU, my version points to the (virtual) iommu-device for that
> particular iommu in the kernel.
>
> So the difference in the prefix is:
>
> your version: '0000:00:00.2:'
>
> vs. my version: 'ivhd0:'
>
> The latter is the better prefix, because it points to the iommu. A
> pci_dev can contain more than one iommu, so that prefix is not specific
> enough. I know that there is currently no hardware implementing multiple
> iommus on one pci_dev, but it is allowed according to the spec.

Excellent; specificity is good. I'll crank a new version using that
device.

Thank you!