<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/kernel/irq/manage.c, branch linux-4.13.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-4.13.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-4.13.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2017-10-18T07:38:31Z</updated>
<entry>
<title>genirq/cpuhotplug: Enforce affinity setting on startup of managed irqs</title>
<updated>2017-10-18T07:38:31Z</updated>
<author>
<name>Thomas Gleixner</name>
</author>
<published>2017-10-04T19:07:38Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=c2e2b0db395b7ea655213495240a366c7dbe04f6'/>
<id>urn:sha1:c2e2b0db395b7ea655213495240a366c7dbe04f6</id>
<content type='text'>
commit e43b3b58548051f8809391eb7bec7a27ed3003ea upstream.

Managed interrupts can end up in a stale state on CPU hotplug. If the
interrupt is not targeting a single CPU, i.e. the affinity mask spawns
multiple CPUs then the following can happen:

After boot:

dstate:   0x01601200
            IRQD_ACTIVATED
            IRQD_IRQ_STARTED
            IRQD_SINGLE_TARGET
            IRQD_AFFINITY_SET
            IRQD_AFFINITY_MANAGED
node:     0
affinity: 24-31
effectiv: 24
pending:  0

After offlining CPU 31 - 24

dstate:   0x01a31000
            IRQD_IRQ_DISABLED
            IRQD_IRQ_MASKED
            IRQD_SINGLE_TARGET
            IRQD_AFFINITY_SET
            IRQD_AFFINITY_MANAGED
            IRQD_MANAGED_SHUTDOWN
node:     0
affinity: 24-31
effectiv: 24
pending:  0

Now CPU 25 gets onlined again, so it should get the effective interrupt
affinity for this interruopt, but due to the x86 interrupt affinity setter
restrictions this ends up after restarting the interrupt with:

dstate:   0x01601300
            IRQD_ACTIVATED
            IRQD_IRQ_STARTED
            IRQD_SINGLE_TARGET
            IRQD_AFFINITY_SET
            IRQD_SETAFFINITY_PENDING
            IRQD_AFFINITY_MANAGED
node:     0
affinity: 24-31
effectiv: 24
pending:  24-31

So the interrupt is still affine to CPU 24, which was the last CPU to go
offline of that affinity set and the move to an online CPU within 24-31,
in this case 25, is pending. This mechanism is x86/ia64 specific as those
architectures cannot move interrupts from thread context and do this when
an interrupt is actually handled. So the move is set to pending.

Whats worse is that offlining CPU 25 again results in:

dstate:   0x01601300
            IRQD_ACTIVATED
            IRQD_IRQ_STARTED
            IRQD_SINGLE_TARGET
            IRQD_AFFINITY_SET
            IRQD_SETAFFINITY_PENDING
            IRQD_AFFINITY_MANAGED
node:     0
affinity: 24-31
effectiv: 24
pending:  24-31

This means the interrupt has not been shut down, because the outgoing CPU
is not in the effective affinity mask, but of course nothing notices that
the effective affinity mask is pointing at an offline CPU.

In the case of restarting a managed interrupt the move restriction does not
apply, so the affinity setting can be made unconditional. This needs to be
done _before_ the interrupt is started up as otherwise the condition for
moving it from thread context would not longer be fulfilled.

With that change applied onlining CPU 25 after offlining 31-24 results in:

dstate:   0x01600200
            IRQD_ACTIVATED
            IRQD_IRQ_STARTED
            IRQD_SINGLE_TARGET
            IRQD_AFFINITY_MANAGED
node:     0
affinity: 24-31
effectiv: 25
pending:

And after offlining CPU 25:

dstate:   0x01a30000
            IRQD_IRQ_DISABLED
            IRQD_IRQ_MASKED
            IRQD_SINGLE_TARGET
            IRQD_AFFINITY_MANAGED
            IRQD_MANAGED_SHUTDOWN
node:     0
affinity: 24-31
effectiv: 25
pending:

which is the correct and expected result.

Fixes: 761ea388e8c4 ("genirq: Handle managed irqs gracefully in irq_startup()")
Reported-by: YASUAKI ISHIMATSU &lt;yasu.isimatu@gmail.com&gt;
Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Cc: axboe@kernel.dk
Cc: linux-scsi@vger.kernel.org
Cc: Sumit Saxena &lt;sumit.saxena@broadcom.com&gt;
Cc: Marc Zyngier &lt;marc.zyngier@arm.com&gt;
Cc: mpe@ellerman.id.au
Cc: Shivasharan Srikanteshwara &lt;shivasharan.srikanteshwara@broadcom.com&gt;
Cc: Kashyap Desai &lt;kashyap.desai@broadcom.com&gt;
Cc: keith.busch@intel.com
Cc: peterz@infradead.org
Cc: Hannes Reinecke &lt;hare@suse.de&gt;
Cc: Christoph Hellwig &lt;hch@lst.de&gt;
Link: https://lkml.kernel.org/r/alpine.DEB.2.20.1710042208400.2406@nanos
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
</entry>
<entry>
<title>genirq: Keep chip buslock across irq_request/release_resources()</title>
<updated>2017-07-12T08:14:42Z</updated>
<author>
<name>Thomas Gleixner</name>
</author>
<published>2017-07-11T21:41:52Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=19d39a3810e7032f311ef83effdac40339b9d022'/>
<id>urn:sha1:19d39a3810e7032f311ef83effdac40339b9d022</id>
<content type='text'>
Moving the irq_request/release_resources() callbacks out of the spinlocked,
irq disabled and bus locked region, unearthed an interesting abuse of the
irq_bus_lock/irq_bus_sync_unlock() callbacks.

The OMAP GPIO driver does merily power management inside of them. The
irq_request_resources() callback of this GPIO irqchip calls a function
which reads a GPIO register. That read aborts now because the clock of the
GPIO block is not magically enabled via the irq_bus_lock() callback.

Move the callbacks under the bus lock again to prevent this. In the
free_irq() path this requires to drop the bus_lock before calling
synchronize_irq() and reaquiring it before calling the
irq_release_resources() callback.

The bus lock can't be held because:

   1) The data which has been changed between bus_lock/un_lock is cached in
      the irq chip driver private data and needs to go out to the irq chip
      via the slow bus (usually SPI or I2C) before calling
      synchronize_irq().

      That's the reason why this bus_lock/unlock magic exists in the first
      place, as you cannot do SPI/I2C transactions while holding desc-&gt;lock
      with interrupts disabled.

   2) synchronize_irq() will actually deadlock, if there is a handler on
      flight. These chips use threaded handlers for obvious reasons, as
      they allow to do SPI/I2C communication. When the threaded handler
      returns then bus_lock needs to be taken in irq_finalize_oneshot() as
      we need to talk to the actual irq chip once more. After that the
      threaded handler is marked done, which makes synchronize_irq() return.

      So if we hold bus_lock accross the synchronize_irq() call, the
      handler cannot mark itself done because it blocks on the bus
      lock. That in turn makes synchronize_irq() wait forever on the
      threaded handler to complete....

Add the missing unlock of desc-&gt;request_mutex in the error path of
__free_irq() and add a bunch of comments to explain the locking and
protection rules.

Fixes: 46e48e257360 ("genirq: Move irq resource handling out of spinlocked region")
Reported-and-tested-by: Sebastian Reichel &lt;sebastian.reichel@collabora.co.uk&gt;
Reported-and-tested-by: Tony Lindgren &lt;tony@atomide.com&gt;
Reported-by: Pavel Machek &lt;pavel@ucw.cz&gt;
Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Not-longer-ranted-at-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
Cc: Linus Walleij &lt;linus.walleij@linaro.org&gt;
Cc: Grygorii Strashko &lt;grygorii.strashko@ti.com&gt;
Cc: Marc Zyngier &lt;marc.zyngier@arm.com&gt;
</content>
</entry>
<entry>
<title>genirq: Allow to pass the IRQF_TIMER flag with percpu irq request</title>
<updated>2017-07-06T21:16:22Z</updated>
<author>
<name>Daniel Lezcano</name>
</author>
<published>2017-07-06T12:29:04Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=c80081b9209713e0fe86d3def395a9fc66503c58'/>
<id>urn:sha1:c80081b9209713e0fe86d3def395a9fc66503c58</id>
<content type='text'>
The irq timings infrastructure tracks when interrupts occur in order to
statistically predict te next interrupt event.

There is no point to track timer interrupts and try to predict them because
the next expiration time is already known. This can be avoided via the
IRQF_TIMER flag which is passed by timer drivers in request_irq(). It marks
the interrupt as timer based which alloes to ignore these interrupts in the
timings code.

Per CPU interrupts which are requested via request_percpu_+irq() have no
flag argument, so marking per cpu timer interrupts is not possible and they
get tracked pointlessly.

Add __request_percpu_irq() as a variant of request_percpu_irq() with a
flags argument and make request_percpu_irq() an inline wrapper passing
flags = 0.

The flag parameter is restricted to IRQF_TIMER as all other IRQF_ flags
make no sense for per cpu interrupts.

The next step is to convert all existing users of request_percpu_irq() and
then remove the wrapper and the underscores.

[ tglx: Massaged changelog ]

Signed-off-by: Daniel Lezcano &lt;daniel.lezcano@linaro.org&gt;
Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Cc: peterz@infradead.org
Cc: nicolas.pitre@linaro.org
Cc: vincent.guittot@linaro.org
Cc: rafael@kernel.org
Link: http://lkml.kernel.org/r/1499344144-3964-1-git-send-email-daniel.lezcano@linaro.org
</content>
</entry>
<entry>
<title>genirq/timings: Move free timings out of spinlocked region</title>
<updated>2017-07-04T10:46:16Z</updated>
<author>
<name>Thomas Gleixner</name>
</author>
<published>2017-06-29T21:33:39Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=2343877fbda701599653e63f8dcc318aa1bf15ee'/>
<id>urn:sha1:2343877fbda701599653e63f8dcc318aa1bf15ee</id>
<content type='text'>
No point to do memory management from a interrupt disabled spin locked
region.

Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Reviewed-by: Marc Zyngier &lt;marc.zyngier@arm.com&gt;
Cc: Daniel Lezcano &lt;daniel.lezcano@linaro.org&gt;
Cc: Heiko Stuebner &lt;heiko@sntech.de&gt;
Cc: Julia Cartwright &lt;julia@ni.com&gt;
Cc: Linus Walleij &lt;linus.walleij@linaro.org&gt;
Cc: Brian Norris &lt;briannorris@chromium.org&gt;
Cc: Doug Anderson &lt;dianders@chromium.org&gt;
Cc: linux-rockchip@lists.infradead.org
Cc: John Keeping &lt;john@metanate.com&gt;
Cc: linux-gpio@vger.kernel.org
Link: http://lkml.kernel.org/r/20170629214344.196130646@linutronix.de

</content>
</entry>
<entry>
<title>genirq: Move irq resource handling out of spinlocked region</title>
<updated>2017-07-04T10:46:16Z</updated>
<author>
<name>Thomas Gleixner</name>
</author>
<published>2017-06-29T21:33:38Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=46e48e257360f0845fe17089713cbad4db611e70'/>
<id>urn:sha1:46e48e257360f0845fe17089713cbad4db611e70</id>
<content type='text'>
Aside of being conceptually wrong, there is also an actual (hard to
trigger and mostly theoretical) problem.

CPU0				CPU1
free_irq(X)			interrupt X
				spin_lock(desc-&gt;lock)
				wake irq thread()
				spin_unlock(desc-&gt;lock)
spin_lock(desc-&gt;lock)
remove action()
shutdown_irq()			
release_resources()		thread_handler()
spin_unlock(desc-&gt;lock)		  access released resources.

synchronize_irq()

Move the release resources invocation after synchronize_irq() so it's
guaranteed that the threaded handler has finished.

Move the resource request call out of the desc-&gt;lock held region as well,
so the invocation context is the same for both request and release.

This solves the problems with those functions on RT as well.
 
Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Reviewed-by: Marc Zyngier &lt;marc.zyngier@arm.com&gt;
Cc: Heiko Stuebner &lt;heiko@sntech.de&gt;
Cc: Julia Cartwright &lt;julia@ni.com&gt;
Cc: Linus Walleij &lt;linus.walleij@linaro.org&gt;
Cc: Brian Norris &lt;briannorris@chromium.org&gt;
Cc: Doug Anderson &lt;dianders@chromium.org&gt;
Cc: linux-rockchip@lists.infradead.org
Cc: John Keeping &lt;john@metanate.com&gt;
Cc: linux-gpio@vger.kernel.org
Link: http://lkml.kernel.org/r/20170629214344.117028181@linutronix.de

</content>
</entry>
<entry>
<title>genirq: Add mutex to irq desc to serialize request/free_irq()</title>
<updated>2017-07-04T10:46:16Z</updated>
<author>
<name>Thomas Gleixner</name>
</author>
<published>2017-06-29T21:33:37Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=9114014cf4e6df0b22d764380ae1fc54f1a7a8b2'/>
<id>urn:sha1:9114014cf4e6df0b22d764380ae1fc54f1a7a8b2</id>
<content type='text'>
The irq_request/release_resources() callbacks ar currently invoked under
desc-&gt;lock with interrupts disabled. This is a source of problems on RT and
conceptually not required.

Add a seperate mutex to struct irq_desc which allows to serialize
request/free_irq(), which can be used to move the resource functions out of
the desc-&gt;lock held region.

Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Reviewed-by: Marc Zyngier &lt;marc.zyngier@arm.com&gt;
Cc: Heiko Stuebner &lt;heiko@sntech.de&gt;
Cc: Julia Cartwright &lt;julia@ni.com&gt;
Cc: Linus Walleij &lt;linus.walleij@linaro.org&gt;
Cc: Brian Norris &lt;briannorris@chromium.org&gt;
Cc: Doug Anderson &lt;dianders@chromium.org&gt;
Cc: linux-rockchip@lists.infradead.org
Cc: John Keeping &lt;john@metanate.com&gt;
Cc: linux-gpio@vger.kernel.org
Link: http://lkml.kernel.org/r/20170629214344.039220922@linutronix.de

</content>
</entry>
<entry>
<title>genirq: Move bus locking into __setup_irq()</title>
<updated>2017-07-04T10:46:15Z</updated>
<author>
<name>Thomas Gleixner</name>
</author>
<published>2017-06-29T21:33:36Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=3a90795e1e885167209056a1a90be965add30e25'/>
<id>urn:sha1:3a90795e1e885167209056a1a90be965add30e25</id>
<content type='text'>
There is no point in having the irq_bus_lock() protection around all
callers to __setup_irq().

Move it into __setup_irq(). This is also a preparatory patch for addressing
the issues with the irq resource callbacks.

Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Reviewed-by: Marc Zyngier &lt;marc.zyngier@arm.com&gt;
Cc: Heiko Stuebner &lt;heiko@sntech.de&gt;
Cc: Julia Cartwright &lt;julia@ni.com&gt;
Cc: Linus Walleij &lt;linus.walleij@linaro.org&gt;
Cc: Brian Norris &lt;briannorris@chromium.org&gt;
Cc: Doug Anderson &lt;dianders@chromium.org&gt;
Cc: linux-rockchip@lists.infradead.org
Cc: John Keeping &lt;john@metanate.com&gt;
Cc: linux-gpio@vger.kernel.org
Link: http://lkml.kernel.org/r/20170629214343.960949031@linutronix.de

</content>
</entry>
<entry>
<title>genirq/timings: Add infrastructure to track the interrupt timings</title>
<updated>2017-06-24T09:44:11Z</updated>
<author>
<name>Daniel Lezcano</name>
</author>
<published>2017-06-23T14:11:07Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=b2d3d61adb7b73cfe5f82404f7a130a76fc64232'/>
<id>urn:sha1:b2d3d61adb7b73cfe5f82404f7a130a76fc64232</id>
<content type='text'>
The interrupt framework gives a lot of information about each interrupt. It
does not keep track of when those interrupts occur though, which is a
prerequisite for estimating the next interrupt arrival for power management
purposes.

Add a mechanism to record the timestamp for each interrupt occurrences in a
per-CPU circular buffer to help with the prediction of the next occurrence
using a statistical model.

Each CPU can store up to IRQ_TIMINGS_SIZE events &lt;irq, timestamp&gt;, the
current value of IRQ_TIMINGS_SIZE is 32.

Each event is encoded into a single u64, where the high 48 bits are used
for the timestamp and the low 16 bits are for the irq number.

A static key is introduced so when the irq prediction is switched off at
runtime, the overhead is near to zero.

It results in most of the code in internals.h for inline reasons and a very
few in the new file timings.c. The latter will contain more in the next patch
which will provide the statistical model for the next event prediction.

Signed-off-by: Daniel Lezcano &lt;daniel.lezcano@linaro.org&gt;
Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Acked-by: Nicolas Pitre &lt;nicolas.pitre@linaro.org&gt;
Cc: Jens Axboe &lt;axboe@kernel.dk&gt;
Cc: Hannes Reinecke &lt;hare@suse.com&gt;
Cc: Vincent Guittot &lt;vincent.guittot@linaro.org&gt;
Cc: "Rafael J . Wysocki" &lt;rafael@kernel.org&gt;
Cc: Peter Zijlstra &lt;peterz@infradead.org&gt;
Cc: Bjorn Helgaas &lt;bhelgaas@google.com&gt;
Link: http://lkml.kernel.org/r/1498227072-5980-1-git-send-email-daniel.lezcano@linaro.org
</content>
</entry>
<entry>
<title>genirq: Add force argument to irq_startup()</title>
<updated>2017-06-22T16:21:24Z</updated>
<author>
<name>Thomas Gleixner</name>
</author>
<published>2017-06-19T23:37:49Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=4cde9c6b826834b861a2b58653ab33150f562064'/>
<id>urn:sha1:4cde9c6b826834b861a2b58653ab33150f562064</id>
<content type='text'>
In order to handle managed interrupts gracefully on irq_startup() so they
won't lose their assigned affinity, it's necessary to allow startups which
keep the interrupts in managed shutdown state, if none of the assigend CPUs
is online. This allows drivers to request interrupts w/o the CPUs being
online, which avoid online/offline churn in drivers.

Add a force argument which can override that decision and let only
request_irq() and enable_irq() allow the managed shutdown
handling. enable_irq() is required, because the interrupt might be
requested with IRQF_NOAUTOEN and enable_irq() invokes irq_startup() which
would then wreckage the assignment again. All other callers force startup
and potentially break the assigned affinity.

No functional change as this only adds the function argument.

Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Cc: Jens Axboe &lt;axboe@kernel.dk&gt;
Cc: Marc Zyngier &lt;marc.zyngier@arm.com&gt;
Cc: Michael Ellerman &lt;mpe@ellerman.id.au&gt;
Cc: Keith Busch &lt;keith.busch@intel.com&gt;
Cc: Peter Zijlstra &lt;peterz@infradead.org&gt;
Cc: Christoph Hellwig &lt;hch@lst.de&gt;
Link: http://lkml.kernel.org/r/20170619235447.112094565@linutronix.de

</content>
</entry>
<entry>
<title>genirq: Move pending helpers to internal.h</title>
<updated>2017-06-22T16:21:15Z</updated>
<author>
<name>Christoph Hellwig</name>
</author>
<published>2017-06-19T23:37:24Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=137221df69c6f8a7002f82dc3d95052d34f5667e'/>
<id>urn:sha1:137221df69c6f8a7002f82dc3d95052d34f5667e</id>
<content type='text'>
So that the affinity code can reuse them.


Signed-off-by: Christoph Hellwig &lt;hch@lst.de&gt;
Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Cc: Jens Axboe &lt;axboe@kernel.dk&gt;
Cc: Marc Zyngier &lt;marc.zyngier@arm.com&gt;
Cc: Michael Ellerman &lt;mpe@ellerman.id.au&gt;
Cc: Keith Busch &lt;keith.busch@intel.com&gt;
Cc: Peter Zijlstra &lt;peterz@infradead.org&gt;
Link: http://lkml.kernel.org/r/20170619235445.109426284@linutronix.de

</content>
</entry>
</feed>
