diff mbox

pci: fix requester id with PCI bridges

Message ID 20160511065318.GA13293@pxdev.xzpeter.org (mailing list archive)
State New, archived
Headers show

Commit Message

Peter Xu May 11, 2016, 6:53 a.m. UTC
On Wed, May 11, 2016 at 02:40:30PM +0800, Peter Xu wrote:
> Recently I encountered issue when debugging Intel IOMMU IR codes,
> that interrupts are not working correctly with PCI bridges (reported
> by Radim). This patch fixes the problem. I assume requester ID
> should be the devfn on root PCI bus (that's how I understand it
> before, and also in guest kernel, IRTE entry SID is filled in that
> way), however I failed to find any good document to confirm
> this. Please let me know if this is correct (or I made any
> mistake).

One thing to mention is that, this patch does *not* fix the problem
if directly applied, because IR patchset introduced another patch
that also need a similar fix. In case if there is someone (Radim?)
who would like to try this patch, we need to apply this patch as
well:

---8<---


--->8---

This should be able to be applied directly onto IR v6 patchset as
well.

Thanks,

-- peterx

Comments

Michael S. Tsirkin May 12, 2016, 7:11 a.m. UTC | #1
On Wed, May 11, 2016 at 02:53:18PM +0800, Peter Xu wrote:
> On Wed, May 11, 2016 at 02:40:30PM +0800, Peter Xu wrote:
> > Recently I encountered issue when debugging Intel IOMMU IR codes,
> > that interrupts are not working correctly with PCI bridges (reported
> > by Radim). This patch fixes the problem. I assume requester ID
> > should be the devfn on root PCI bus (that's how I understand it
> > before, and also in guest kernel, IRTE entry SID is filled in that
> > way), however I failed to find any good document to confirm
> > this. Please let me know if this is correct (or I made any
> > mistake).
> 
> One thing to mention is that, this patch does *not* fix the problem
> if directly applied, because IR patchset introduced another patch
> that also need a similar fix. In case if there is someone (Radim?)
> who would like to try this patch, we need to apply this patch as
> well:
> 
> ---8<---
> 
> diff --git a/target-i386/kvm.c b/target-i386/kvm.c
> index 80b3251..0876a1c 100644
> --- a/target-i386/kvm.c
> +++ b/target-i386/kvm.c
> @@ -3342,7 +3342,8 @@ int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route,
>          src.data = route->u.msi.data;
> 
>          ret = class->int_remap(iommu, &src, &dst, dev ? \
> -                               pci_requester_id(dev) : X86_IOMMU_SID_INVALID);
> +                               pci_requester_id_recursive(dev) : \
> +                               X86_IOMMU_SID_INVALID);
>          if (ret) {
>              trace_kvm_x86_fixup_msi_error(route->gsi);
>              return 1;
> 
> --->8---
> 
> This should be able to be applied directly onto IR v6 patchset as
> well.
> 
> Thanks,
> 
> -- peterx

I really dislike the name pci_requester_id_recursive.
Are there cases where we need the original requester id value?
I am guessing not, and if I'm right we should just change the implementation
of pci_requester_id to DTRT.
Peter Xu May 12, 2016, 7:32 a.m. UTC | #2
On Thu, May 12, 2016 at 10:11:31AM +0300, Michael S. Tsirkin wrote:
> On Wed, May 11, 2016 at 02:53:18PM +0800, Peter Xu wrote:
> > On Wed, May 11, 2016 at 02:40:30PM +0800, Peter Xu wrote:
> > > Recently I encountered issue when debugging Intel IOMMU IR codes,
> > > that interrupts are not working correctly with PCI bridges (reported
> > > by Radim). This patch fixes the problem. I assume requester ID
> > > should be the devfn on root PCI bus (that's how I understand it
> > > before, and also in guest kernel, IRTE entry SID is filled in that
> > > way), however I failed to find any good document to confirm
> > > this. Please let me know if this is correct (or I made any
> > > mistake).
> > 
> > One thing to mention is that, this patch does *not* fix the problem
> > if directly applied, because IR patchset introduced another patch
> > that also need a similar fix. In case if there is someone (Radim?)
> > who would like to try this patch, we need to apply this patch as
> > well:
> > 
> > ---8<---
> > 
> > diff --git a/target-i386/kvm.c b/target-i386/kvm.c
> > index 80b3251..0876a1c 100644
> > --- a/target-i386/kvm.c
> > +++ b/target-i386/kvm.c
> > @@ -3342,7 +3342,8 @@ int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route,
> >          src.data = route->u.msi.data;
> > 
> >          ret = class->int_remap(iommu, &src, &dst, dev ? \
> > -                               pci_requester_id(dev) : X86_IOMMU_SID_INVALID);
> > +                               pci_requester_id_recursive(dev) : \
> > +                               X86_IOMMU_SID_INVALID);
> >          if (ret) {
> >              trace_kvm_x86_fixup_msi_error(route->gsi);
> >              return 1;
> > 
> > --->8---
> > 
> > This should be able to be applied directly onto IR v6 patchset as
> > well.
> > 
> > Thanks,
> > 
> > -- peterx
> 
> I really dislike the name pci_requester_id_recursive.

Do you have better suggestion on this? :)

> Are there cases where we need the original requester id value?
> I am guessing not, and if I'm right we should just change the implementation
> of pci_requester_id to DTRT.

There are two other callers for it (besides the MSI one):

- assigned_device_pci_cap_init()
- do_pcie_aer_inject_error()

For both the cases, I am not sure whether we can do the replacement.

-- peterx
Michael S. Tsirkin May 12, 2016, 7:51 a.m. UTC | #3
On Thu, May 12, 2016 at 03:32:03PM +0800, Peter Xu wrote:
> On Thu, May 12, 2016 at 10:11:31AM +0300, Michael S. Tsirkin wrote:
> > On Wed, May 11, 2016 at 02:53:18PM +0800, Peter Xu wrote:
> > > On Wed, May 11, 2016 at 02:40:30PM +0800, Peter Xu wrote:
> > > > Recently I encountered issue when debugging Intel IOMMU IR codes,
> > > > that interrupts are not working correctly with PCI bridges (reported
> > > > by Radim). This patch fixes the problem. I assume requester ID
> > > > should be the devfn on root PCI bus (that's how I understand it
> > > > before, and also in guest kernel, IRTE entry SID is filled in that
> > > > way), however I failed to find any good document to confirm
> > > > this. Please let me know if this is correct (or I made any
> > > > mistake).
> > > 
> > > One thing to mention is that, this patch does *not* fix the problem
> > > if directly applied, because IR patchset introduced another patch
> > > that also need a similar fix. In case if there is someone (Radim?)
> > > who would like to try this patch, we need to apply this patch as
> > > well:
> > > 
> > > ---8<---
> > > 
> > > diff --git a/target-i386/kvm.c b/target-i386/kvm.c
> > > index 80b3251..0876a1c 100644
> > > --- a/target-i386/kvm.c
> > > +++ b/target-i386/kvm.c
> > > @@ -3342,7 +3342,8 @@ int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route,
> > >          src.data = route->u.msi.data;
> > > 
> > >          ret = class->int_remap(iommu, &src, &dst, dev ? \
> > > -                               pci_requester_id(dev) : X86_IOMMU_SID_INVALID);
> > > +                               pci_requester_id_recursive(dev) : \
> > > +                               X86_IOMMU_SID_INVALID);
> > >          if (ret) {
> > >              trace_kvm_x86_fixup_msi_error(route->gsi);
> > >              return 1;
> > > 
> > > --->8---
> > > 
> > > This should be able to be applied directly onto IR v6 patchset as
> > > well.
> > > 
> > > Thanks,
> > > 
> > > -- peterx
> > 
> > I really dislike the name pci_requester_id_recursive.
> 
> Do you have better suggestion on this? :)
> 
> > Are there cases where we need the original requester id value?
> > I am guessing not, and if I'm right we should just change the implementation
> > of pci_requester_id to DTRT.
> 
> There are two other callers for it (besides the MSI one):
> 
> - assigned_device_pci_cap_init()
> - do_pcie_aer_inject_error()
> 
> For both the cases, I am not sure whether we can do the replacement.
> 
> -- peterx

Read the specs please. We can't just pile on APIs.
Peter Xu May 16, 2016, 7:23 a.m. UTC | #4
On Thu, May 12, 2016 at 10:51:43AM +0300, Michael S. Tsirkin wrote:
> On Thu, May 12, 2016 at 03:32:03PM +0800, Peter Xu wrote:
[...]
> > > Are there cases where we need the original requester id value?
> > > I am guessing not, and if I'm right we should just change the implementation
> > > of pci_requester_id to DTRT.
> > 
> > There are two other callers for it (besides the MSI one):
> > 
> > - assigned_device_pci_cap_init()

This should use the new interface.

> > - do_pcie_aer_inject_error()

This should use the old one, which is to get BDF only.

> > 
> > For both the cases, I am not sure whether we can do the replacement.
> > 
> > -- peterx
> 
> Read the specs please. We can't just pile on APIs.

IIUC, we may still need to add a new API here, because not all of
them are looking for requester IDs. I just posted v2 for this patch.
Instead of renaming the new function, I renamed the old one to
pci_get_bdf(). Hope that works.

Thanks,

-- peterx
diff mbox

Patch

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 80b3251..0876a1c 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -3342,7 +3342,8 @@  int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route,
         src.data = route->u.msi.data;

         ret = class->int_remap(iommu, &src, &dst, dev ? \
-                               pci_requester_id(dev) : X86_IOMMU_SID_INVALID);
+                               pci_requester_id_recursive(dev) : \
+                               X86_IOMMU_SID_INVALID);
         if (ret) {
             trace_kvm_x86_fixup_msi_error(route->gsi);
             return 1;