Skip to contentSkip to conversation

pci_get_dev_by_id() from interrupt handlers

DISCUSSION Joerg Roedel 4 participants 9 messages Apr 20, 2010 – Apr 21, 2010

lore
Share & tools
lore
#0 lore raw

Hi Jesse,

I have a question regarding the warning in the pci_get_dev_by_id() [search.c] function which triggers when called from interrupt context. As far as I have seen this function should be save to be called in atomic mode. Is there any other reason it should not be called in interrupt handlers? I need to (indirectly) call this function for my IOMMU driver to handle events from the IOMMU.

Thanks,
Joerg

#1 lore raw
Quoted 6 lines · Joerg Roedel

Hi Jesse,

I have a question regarding the warning in the pci_get_dev_by_id() [search.c] function which triggers when called from interrupt context. As far as I have seen this function should be save to be called in atomic mode.

Are you sure?

Quoted 2 lines

Is there any other reason it should not be called in interrupt handlers?

klist traversal is not safe to be done in interrupt context as the spinlock is not told to be interrupt safe. Now you could go and change the klist core to be interrupt safe, but you should probably rethink your need here first.

Quoted 4 lines

I need to (indirectly) call this function for my IOMMU driver to handle events from the IOMMU.

From interrupt? Why not use an interrupt thread instead if you really

need to do this.

Actually, what are you trying to accomplish here?

thanks,

greg k-h

#2 lore raw
Quoted 9 lines · Greg KH
Quoted 6 lines · Joerg Roedel

Hi Jesse,

I have a question regarding the warning in the pci_get_dev_by_id() [search.c] function which triggers when called from interrupt context. As far as I have seen this function should be save to be called in atomic mode.

Are you sure?

Not anymore. You proved me wrong ;-)

Quoted 7 lines
Quoted 2 lines

Is there any other reason it should not be called in interrupt handlers?

klist traversal is not safe to be done in interrupt context as the spinlock is not told to be interrupt safe. Now you could go and change the klist core to be interrupt safe, but you should probably rethink your need here first.

The idea was to capture IO page faults in the IOMMU and propagate them to KVM instead of just printk into dmesg. KVM could do something better then like killing the guest. Currently a malicious guest could flood host dmesg by causing IO page faults.
For the AMD IOMMU the page faults are reported in an event log and the cpu is informed by an interrupt about it. The event log entry contains the bus/dev/function of the device. To get the necessary information to propagate this to KVM I need to get the 'struct device' for it. I could certainly do this in a tasklet instead but doing that only for the task of converting bus/device/function into 'struct device' sounds a bit complicated to me.

Regards,

Joerg

#3 lore raw
Quoted 10 lines · Joerg Roedel
Quoted 8 lines · Greg KH
Quoted 2 lines · Joerg Roedel

Is there any other reason it should not be called in interrupt handlers?

klist traversal is not safe to be done in interrupt context as the spinlock is not told to be interrupt safe. Now you could go and change the klist core to be interrupt safe, but you should probably rethink your need here first.

Quoted 4 lines

The idea was to capture IO page faults in the IOMMU and propagate them to KVM instead of just printk into dmesg. KVM could do something better then like killing the guest. Currently a malicious guest could flood host dmesg by causing IO page faults.

That's not good.

Quoted 4 lines

For the AMD IOMMU the page faults are reported in an event log and the cpu is informed by an interrupt about it. The event log entry contains the bus/dev/function of the device. To get the necessary information to propagate this to KVM I need to get the 'struct device' for it.

Ok, that's reasonable.

Quoted 3 lines

I could certainly do this in a tasklet instead but doing that only for the task of converting bus/device/function into 'struct device' sounds a bit complicated to me.

Why not do the whole thing in an interrupt task as the whole thing sounds like something that shouldn't be done in interrupt context, right? Now that we have this type of functionality, we should take advantage of it :)

Eventually, notifying KVM isn't something that you want to do from interrupt context anyway, right?

thanks,

greg k-h

#4 lore raw
Quoted 6 lines · Greg KH

On Tue, Apr 20, 2010 at 07:35:59PM +0200, Joerg Roedel wrote:

Why not do the whole thing in an interrupt task as the whole thing sounds like something that shouldn't be done in interrupt context, right? Now that we have this type of functionality, we should take advantage of it :)

Ok, I think I move the IOMMU interrupt handling to a tasklet.

Quoted 2 lines

Eventually, notifying KVM isn't something that you want to do from interrupt context anyway, right?

On the KVM side it is probably nothing more than setting a request bit. But lets see how this could be done :-)

Thanks,

Joerg

#5 lore raw
Quoted 8 lines · Joerg Roedel
Quoted 5 lines

Why not do the whole thing in an interrupt task as the whole thing sounds like something that shouldn't be done in interrupt context, right? Now that we have this type of functionality, we should take advantage of it :)

Ok, I think I move the IOMMU interrupt handling to a tasklet.

tasklet is softirq context, and is not what gregkh was talking about.

You'd still need to change the klist spinlock to be softirq-safe.

#6 lore raw
Quoted 7 lines · Peter Zijlstra
Quoted 6 lines · Joerg Roedel
Quoted 5 lines

Why not do the whole thing in an interrupt task as the whole thing sounds like something that shouldn't be done in interrupt context, right? Now that we have this type of functionality, we should take advantage of it :)

Quoted 5 lines
Quoted 2 lines

Ok, I think I move the IOMMU interrupt handling to a tasklet.

tasklet is softirq context, and is not what gregkh was talking about.

You'd still need to change the klist spinlock to be softirq-safe.

Ah right. Thanks for pointing this out. I couldn't find much about the interrupt tasks. Is it about the request_threaded_irq interface? And this would be run in the context of a kernel thread, right?

Joerg

#7 lore raw
Quoted 10 lines · Joerg Roedel
Quoted 9 lines · Peter Zijlstra
Quoted 8 lines · Joerg Roedel
Quoted 5 lines

Why not do the whole thing in an interrupt task as the whole thing sounds like something that shouldn't be done in interrupt context, right? Now that we have this type of functionality, we should take advantage of it :)

Ok, I think I move the IOMMU interrupt handling to a tasklet.

Quoted 7 lines
Quoted 3 lines

tasklet is softirq context, and is not what gregkh was talking about.

You'd still need to change the klist spinlock to be softirq-safe.

Ah right. Thanks for pointing this out. I couldn't find much about the interrupt tasks. Is it about the request_threaded_irq interface? And this would be run in the context of a kernel thread, right?

Right, request_threaded_irq() is what was meant, the comment there does a good job of describing how to use it.

#8 lore raw
Quoted 13 lines · Peter Zijlstra
Quoted 12 lines · Joerg Roedel
Quoted 11 lines · Peter Zijlstra
Quoted 8 lines · Joerg Roedel
Quoted 5 lines

Why not do the whole thing in an interrupt task as the whole thing sounds like something that shouldn't be done in interrupt context, right? Now that we have this type of functionality, we should take advantage of it :)

Ok, I think I move the IOMMU interrupt handling to a tasklet.

tasklet is softirq context, and is not what gregkh was talking about.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

You'd still need to change the klist spinlock to be softirq-safe.

Ah right. Thanks for pointing this out. I couldn't find much about the interrupt tasks. Is it about the request_threaded_irq interface? And this would be run in the context of a kernel thread, right?

Right, request_threaded_irq() is what was meant, the comment there does a good job of describing how to use it.

Ok, thanks. I am going to use this interface instead.

Joerg