* pci_get_dev_by_id() from interrupt handlers @ 2010-04-20 16:04 Joerg Roedel 2010-04-20 16:32 ` Greg KH 0 siblings, 1 reply; 9+ messages in thread From: Joerg Roedel @ 2010-04-20 16:04 UTC (permalink / raw) To: Jesse Barnes; +Cc: linux-pci, linux-kernel 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 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: pci_get_dev_by_id() from interrupt handlers 2010-04-20 16:04 pci_get_dev_by_id() from interrupt handlers Joerg Roedel @ 2010-04-20 16:32 ` Greg KH 2010-04-20 17:35 ` Joerg Roedel 0 siblings, 1 reply; 9+ messages in thread From: Greg KH @ 2010-04-20 16:32 UTC (permalink / raw) To: Joerg Roedel; +Cc: Jesse Barnes, linux-pci, linux-kernel On Tue, Apr 20, 2010 at 06:04:24PM +0200, Joerg Roedel wrote: > 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? > 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. > 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 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: pci_get_dev_by_id() from interrupt handlers 2010-04-20 16:32 ` Greg KH @ 2010-04-20 17:35 ` Joerg Roedel 2010-04-20 17:52 ` Greg KH 0 siblings, 1 reply; 9+ messages in thread From: Joerg Roedel @ 2010-04-20 17:35 UTC (permalink / raw) To: Greg KH; +Cc: Joerg Roedel, Jesse Barnes, linux-pci, linux-kernel On Tue, Apr 20, 2010 at 09:32:15AM -0700, Greg KH wrote: > On Tue, Apr 20, 2010 at 06:04:24PM +0200, Joerg Roedel wrote: > > 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 ;-) > > 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 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: pci_get_dev_by_id() from interrupt handlers 2010-04-20 17:35 ` Joerg Roedel @ 2010-04-20 17:52 ` Greg KH 2010-04-21 10:05 ` Joerg Roedel 0 siblings, 1 reply; 9+ messages in thread From: Greg KH @ 2010-04-20 17:52 UTC (permalink / raw) To: Joerg Roedel; +Cc: Joerg Roedel, Jesse Barnes, linux-pci, linux-kernel On Tue, Apr 20, 2010 at 07:35:59PM +0200, Joerg Roedel wrote: > On Tue, Apr 20, 2010 at 09:32:15AM -0700, Greg KH wrote: > > On Tue, Apr 20, 2010 at 06:04:24PM +0200, Joerg Roedel wrote: > > > 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. That's not good. > 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. > 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 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: pci_get_dev_by_id() from interrupt handlers 2010-04-20 17:52 ` Greg KH @ 2010-04-21 10:05 ` Joerg Roedel 2010-04-21 10:21 ` Peter Zijlstra 0 siblings, 1 reply; 9+ messages in thread From: Joerg Roedel @ 2010-04-21 10:05 UTC (permalink / raw) To: Greg KH; +Cc: Joerg Roedel, Jesse Barnes, linux-pci, linux-kernel On Tue, Apr 20, 2010 at 10:52:02AM -0700, Greg KH wrote: > 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. > 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 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: pci_get_dev_by_id() from interrupt handlers 2010-04-21 10:05 ` Joerg Roedel @ 2010-04-21 10:21 ` Peter Zijlstra 2010-04-21 10:41 ` Joerg Roedel 0 siblings, 1 reply; 9+ messages in thread From: Peter Zijlstra @ 2010-04-21 10:21 UTC (permalink / raw) To: Joerg Roedel; +Cc: Greg KH, Joerg Roedel, Jesse Barnes, linux-pci, linux-kernel On Wed, 2010-04-21 at 12:05 +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. > 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. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: pci_get_dev_by_id() from interrupt handlers 2010-04-21 10:21 ` Peter Zijlstra @ 2010-04-21 10:41 ` Joerg Roedel 2010-04-21 10:46 ` Peter Zijlstra 0 siblings, 1 reply; 9+ messages in thread From: Joerg Roedel @ 2010-04-21 10:41 UTC (permalink / raw) To: Peter Zijlstra Cc: Greg KH, Joerg Roedel, Jesse Barnes, linux-pci, linux-kernel On Wed, Apr 21, 2010 at 12:21:11PM +0200, Peter Zijlstra wrote: > On Wed, 2010-04-21 at 12:05 +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. > > > 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 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: pci_get_dev_by_id() from interrupt handlers 2010-04-21 10:41 ` Joerg Roedel @ 2010-04-21 10:46 ` Peter Zijlstra 2010-04-21 10:55 ` Joerg Roedel 0 siblings, 1 reply; 9+ messages in thread From: Peter Zijlstra @ 2010-04-21 10:46 UTC (permalink / raw) To: Joerg Roedel; +Cc: Greg KH, Joerg Roedel, Jesse Barnes, linux-pci, linux-kernel On Wed, 2010-04-21 at 12:41 +0200, Joerg Roedel wrote: > On Wed, Apr 21, 2010 at 12:21:11PM +0200, Peter Zijlstra wrote: > > On Wed, 2010-04-21 at 12:05 +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. > > > > > 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. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: pci_get_dev_by_id() from interrupt handlers 2010-04-21 10:46 ` Peter Zijlstra @ 2010-04-21 10:55 ` Joerg Roedel 0 siblings, 0 replies; 9+ messages in thread From: Joerg Roedel @ 2010-04-21 10:55 UTC (permalink / raw) To: Peter Zijlstra Cc: Greg KH, Joerg Roedel, Jesse Barnes, linux-pci, linux-kernel On Wed, Apr 21, 2010 at 12:46:56PM +0200, Peter Zijlstra wrote: > On Wed, 2010-04-21 at 12:41 +0200, Joerg Roedel wrote: > > On Wed, Apr 21, 2010 at 12:21:11PM +0200, Peter Zijlstra wrote: > > > On Wed, 2010-04-21 at 12:05 +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. > > > > > > > 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. Ok, thanks. I am going to use this interface instead. Joerg ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2010-04-21 10:55 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2010-04-20 16:04 pci_get_dev_by_id() from interrupt handlers Joerg Roedel 2010-04-20 16:32 ` Greg KH 2010-04-20 17:35 ` Joerg Roedel 2010-04-20 17:52 ` Greg KH 2010-04-21 10:05 ` Joerg Roedel 2010-04-21 10:21 ` Peter Zijlstra 2010-04-21 10:41 ` Joerg Roedel 2010-04-21 10:46 ` Peter Zijlstra 2010-04-21 10:55 ` Joerg Roedel
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox