Skip to content

x86: Rework the vector management

Thomas Gleixner linux-iommu lkml stable 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest52 patches 3 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/52genirq: Fix cpumask check in __irq_startup_managed()kernel/irq/chip.c+1 -10 replies
2/52genirq/debugfs: Show debug information for all irq descriptorskernel/irq/irqdesc.c kernel/irq/manage.c+1 -10 replies
3/52genirq/msi: Capture device name for debugfsinclude/linux/irqdesc.h kernel/irq/debugfs.c kernel/irq/internals.h +1 more+21 -10 replies
4/52irqdomain/debugfs: Provide domain specific debug callbackinclude/linux/irqdomain.h kernel/irq/debugfs.c kernel/irq/irqdomain.c+9 -10 replies
5/52genirq: Make state consistent for !IRQ_DOMAIN_HIERARCHYinclude/linux/irqdomain.h kernel/irq/internals.h+11 -40 replies
6/52genirq: Set managed shut down flag at initkernel/irq/irqdesc.c+1 -10 replies
7/52genirq: Separate activation and startupkernel/irq/autoprobe.c kernel/irq/chip.c kernel/irq/internals.h +1 more+43 -80 replies
8/52genirq/irqdomain: Update irq_domain_ops.activate() signaturearch/x86/include/asm/irqdomain.h arch/x86/kernel/apic/htirq.c arch/x86/kernel/apic/io_apic.c +9 more+36 -250 replies
9/52genirq/irqdomain: Allow irq_domain_activate_irq() to failinclude/linux/irqdomain.h kernel/irq/chip.c kernel/irq/internals.h +2 more+52 -210 replies
10/52genirq/irqdomain: Propagate early activationarch/x86/kernel/apic/io_apic.c include/linux/irqdomain.h kernel/irq/chip.c +3 more+13 -120 replies
11/52genirq/irqdomain: Add force reactivation flag to irq domainsinclude/linux/msi.h kernel/irq/msi.c+7 -00 replies
12/52genirq: Implement bitmap matrix allocatorinclude/linux/irq.h kernel/irq/Kconfig kernel/irq/Makefile +1 more+454 -00 replies
13/52genirq/matrix: Add tracepointsinclude/trace/events/irq_matrix.h kernel/irq/matrix.c+216 -00 replies
14/52x86/apic: Deinline x2apic functionsarch/x86/include/asm/x2apic.h arch/x86/kernel/apic/x2apic.h arch/x86/kernel/apic/x2apic_cluster.c +1 more+49 -510 replies
15/52x86/apic: Sanitize return value of apic.set_apic_id()arch/x86/include/asm/apic.h arch/x86/kernel/apic/apic_flat_64.c arch/x86/kernel/apic/apic_numachip.c +4 more+8 -80 replies
16/52x86/apic: Sanitize return value of check_apicid_used()arch/x86/include/asm/apic.h arch/x86/kernel/apic/bigsmp_32.c+4 -40 replies
17/52x86/apic: Move probe32 specific APIC functionsarch/x86/include/asm/apic.h arch/x86/kernel/apic/apic.c arch/x86/kernel/apic/probe_32.c+25 -310 replies
18/52x86/apic: Move APIC noop specific functionsarch/x86/include/asm/apic.h arch/x86/kernel/apic/apic_noop.c+7 -70 replies
19/52x86/apic: Sanitize 32/64bit APIC callbacksarch/x86/include/asm/apic.h arch/x86/include/asm/kvm_host.h arch/x86/kernel/apic/Makefile +2 more+22 -440 replies
20/52x86/apic: Move common APIC callbacksarch/x86/include/asm/apic.h arch/x86/kernel/apic/apic.c arch/x86/kernel/apic/apic_common.c+90 -890 replies
21/52x86/apic: Reorganize struct apicarch/x86/include/asm/apic.h+52 -610 replies
22/52x86/apic/x2apic: Simplify cluster managementarch/x86/kernel/apic/x2apic_cluster.c+76 -780 replies
23/52x86/apic: Get rid of apic->target_cpusarch/x86/include/asm/apic.h arch/x86/kernel/apic/apic_common.c arch/x86/kernel/apic/apic_flat_64.c +10 more+5 -450 replies
24/52x86/vector: Rename used_vectors to system_vectorsarch/x86/include/asm/desc.h arch/x86/kernel/apic/vector.c arch/x86/kernel/idt.c +2 more+11 -110 replies
25/52x86/apic: Get rid of multi CPU affinityarch/x86/kernel/apic/vector.c+3 -100 replies
26/52x86/ioapic: Remove obsolete post hotplug updatearch/x86/include/asm/io_apic.h arch/x86/kernel/apic/io_apic.c arch/x86/kernel/smpboot.c+0 -450 replies
27/52x86/vector: Simplify the CPU hotplug vector updatearch/x86/kernel/apic/vector.c+36 -300 replies
28/52x86/vector: Cleanup variable namesarch/x86/kernel/apic/vector.c+114 -1140 replies
29/52x86/vector: Store the single CPU targets in apic dataarch/x86/kernel/apic/vector.c+5 -00 replies
30/52x86/vector: Simplify vector move cleanuparch/x86/kernel/apic/vector.c+77 -1440 replies
31/52x86/ioapic: Mark legacy vectors at reallocation timearch/x86/include/asm/irqdomain.h arch/x86/kernel/apic/io_apic.c+2 -00 replies
32/52x86/apic: Get rid of the legacy irq data storagearch/x86/kernel/apic/vector.c+13 -390 replies
33/52x86/vector: Remove pointless pointer checksarch/x86/kernel/apic/vector.c+1 -10 replies
34/52x86/vector: Move helper functions aroundarch/x86/kernel/apic/vector.c+15 -150 replies
35/52x86/apic: Add replacement for cpu_mask_to_apicid()arch/x86/include/asm/apic.h arch/x86/kernel/apic/apic_common.c arch/x86/kernel/apic/apic_flat_64.c +8 more+36 -00 replies
36/52x86/irq/vector: Initialize matrix allocatorarch/x86/Kconfig arch/x86/include/asm/apic.h arch/x86/include/asm/hw_irq.h +4 more+65 -60 replies
37/52x86/vector: Add vector domain debugfs supportarch/x86/kernel/apic/vector.c+48 -20 replies
38/52x86/smpboot: Set online before setting up vectorsarch/x86/kernel/smpboot.c+5 -50 replies
39/52x86/vector: Add tracepoints for vector managementarch/x86/include/asm/trace/irq_vectors.h arch/x86/kernel/apic/vector.c+246 -00 replies
40/52x86/vector: Use matrix allocator for vector assignmentarch/x86/kernel/apic/vector.c+117 -1730 replies
41/52x86/apic: Remove unused callbacksarch/x86/kernel/apic/apic_common.c arch/x86/kernel/apic/apic_flat_64.c arch/x86/kernel/apic/apic_noop.c +8 more+0 -1550 replies
42/52x86/vector: Compile SMP only code conditionallyarch/x86/kernel/apic/vector.c+20 -150 replies
43/52x86/vector: Untangle internal state from irq_cfgarch/x86/include/asm/hw_irq.h arch/x86/kernel/apic/vector.c+49 -420 replies
44/52x86/apic/msi: Force reactivation of interrupts at startup timearch/x86/kernel/apic/msi.c+3 -20 replies
45/52iommu/vt-d: Reevaluate vector configuration on activate()drivers/iommu/intel_irq_remapping.c+21 -170 replies
46/52iommu/amd: Reevaluate vector configuration on activate()drivers/iommu/amd_iommu.c+29 -100 replies
47/52x86/io_apic: Reevaluate vector configuration on activate()arch/x86/kernel/apic/io_apic.c+22 -150 replies
48/52x86/vector: Handle managed interrupts properarch/x86/include/asm/irq_vectors.h arch/x86/kernel/apic/vector.c+174 -240 replies
49/52x86/vector/msi: Switch to global reservation modearch/x86/kernel/apic/vector.c+63 -340 replies
50/52x86/vector: Switch IOAPIC to global reservation modearch/x86/kernel/apic/vector.c+33 -230 replies
51/52x86/irq: Simplify hotplug vector accountingarch/x86/include/asm/apic.h arch/x86/include/asm/irq.h arch/x86/kernel/apic/vector.c +2 more+33 -1050 replies
52/52x86/vector: Respect affinity mask in irq descriptorarch/x86/kernel/apic/vector.c+17 -40 replies

Reviews trailers per patch

None of the 52 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchJuergen Gross
SeriesT-b A-b
1/52
2/52
3/52
4/52
5/52
6/52
7/52
8/52
9/52
10/52
11/52
12/52
13/52
14/52
15/52
16/52
17/52
18/52
19/52
20/52
21/52
22/52
23/52
24/52
25/52
26/52
27/52
28/52
29/52
30/52
31/52
32/52
33/52
34/52
35/52
36/52
37/52
38/52
39/52
40/52
41/52
42/52
43/52
44/52
45/52
46/52
47/52
48/52
49/52
50/52
51/52
52/52

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [patch 00/52] x86: Rework the vector management

Sorry for the large CC list, but this is a major surgery.

The vector management in x86 including the surrounding code is a conglomorate of ancient bits and pieces which have been subject to 'modernization' and featuritis over the years. The most obscure parts are the vector allocation mechanics, the cleanup vector handling and the cpu hotplug machinery. Replacing these pieces of art was on my todo list for a long time.

Recent attempts to 'solve' CPU offline / hibernation issues which are partially caused by the current vector management implementation made me look for real. Further information in this thread:

    http://lkml.kernel.org/r/[email protected]

Aside of drivers allocating gazillion of interrupts, there are quite some things which can be addressed in the x86 vector management and in the core code.

- Multi CPU affinities:

A dubious property which is not available on all machines and causes major complexity both in the allocator and the cleanup/hotplug management. See:

http://lkml.kernel.org/r/alpine.DEB.2.20.1709071045440.1827@nanos

- Priority level spreading:

An obscure and undocumented property which I think is sufficiently argued to be not required in:

http://lkml.kernel.org/r/alpine.DEB.2.20.1709071045440.1827@nanos

- Allocation of vectors when interrupt descriptors are allocated.

This is a historical implementation detail, which is not really required when the vector allocation is delayed up to the point when request_irq() is invoked. This might make request_irq() fail, when the vector space is exhausted, but drivers should handle request_irq() fails anyway.

The upside of changing this is that the active vector space becomes smaller especially on hibernation/cpu offline when drivers shut down queue interrupts of outgoing CPUs.

Some of this is already addressed with the managed interrupt facility, but that was bolted on top of the existing vector management because proper integration was not possible at that point. I take the blame for this, but the tradeoff of not doing it would have been more broken driver boiler plate code all over the place. So I went for the lesser of two evils.

- Allocation of vectors on the wrong place

Even for managed interrupts the vector allocation at descriptor allocation happens on the wrong place and gets fixed after the fact with a call to set_affinity(). In case of not remapped interrupts this results in at least one interrupt on the wrong CPU before it is migrated to the desired target.

- Lack of instrumentation

All of this is a black box which allows no insight into the actual vector usage.

The series addresses these points and converts the x86 vector management to a bitmap based allocator which provides proper reservation management for 'managed interrupts' and best effort reservation for regular interrupts. The latter allows overcommitment, which 'fixes' some of hotplug/hibernation problems in a clean way. It can't fix all of them depending on the driver involved.

This rework is no excuse for driver writers to do exhaustive vector allocations instead of utilizing the managed interrupt infrastructure, but it addresses long standing issues in this code with the side effect of mitigating some of the driver oddities. The proper solution for multi queue management are 'managed interrupts' which has been proven in the block-mq work as they solve issues which are worked around in other drivers in creative ways with lots of copied code and often enough broken attempts to handle interrupt affinity and CPU hotplug problems.

The new bitmap allocator and the x86 vector management code are instrumented with tracepoints and the irq domain debugfs files allow deep insight into the vector allocation and reservations.

The patches work on machines with and without interrupt remapping and inside of KVM guests of various flavours, though I have no idea what I broke on the way with other hypervisors, posted interrupts etc. So I kindly ask for your support in testing and review.

The series applies on top of Linus tree and is available as git branch:

git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git WIP.x86/apic

Note, that this branch is Linus tree plus scheduler and x86 fixes which I required to do proper testing. They have outstanding pull requests and might be merged already when you read this.

Thanks,

tglx

---
 arch/x86/include/asm/x2apic.h              |   49 -
 b/arch/x86/Kconfig                         |    1 
 b/arch/x86/include/asm/apic.h              |  255 +-----
 b/arch/x86/include/asm/desc.h              |    2 
 b/arch/x86/include/asm/hw_irq.h            |    6 
 b/arch/x86/include/asm/io_apic.h           |    2 
 b/arch/x86/include/asm/irq.h               |    4 
 b/arch/x86/include/asm/irq_vectors.h       |    8 
 b/arch/x86/include/asm/irqdomain.h         |    5 
 b/arch/x86/include/asm/kvm_host.h          |    2 
 b/arch/x86/include/asm/trace/irq_vectors.h |  244 ++++++
 b/arch/x86/kernel/apic/Makefile            |    2 
 b/arch/x86/kernel/apic/apic.c              |   38 -
 b/arch/x86/kernel/apic/apic_common.c       |   46 +
 b/arch/x86/kernel/apic/apic_flat_64.c      |   10 
 b/arch/x86/kernel/apic/apic_noop.c         |   25 
 b/arch/x86/kernel/apic/apic_numachip.c     |   12 
 b/arch/x86/kernel/apic/bigsmp_32.c         |    8 
 b/arch/x86/kernel/apic/htirq.c             |    5 
 b/arch/x86/kernel/apic/io_apic.c           |   94 --
 b/arch/x86/kernel/apic/msi.c               |    5 
 b/arch/x86/kernel/apic/probe_32.c          |   29 
 b/arch/x86/kernel/apic/vector.c            | 1090 +++++++++++++++++------------
 b/arch/x86/kernel/apic/x2apic.h            |    9 
 b/arch/x86/kernel/apic/x2apic_cluster.c    |  196 +----
 b/arch/x86/kernel/apic/x2apic_phys.c       |   44 +
 b/arch/x86/kernel/apic/x2apic_uv_x.c       |   17 
 b/arch/x86/kernel/i8259.c                  |    1 
 b/arch/x86/kernel/idt.c                    |   12 
 b/arch/x86/kernel/irq.c                    |  101 --
 b/arch/x86/kernel/irqinit.c                |    1 
 b/arch/x86/kernel/setup.c                  |   12 
 b/arch/x86/kernel/smpboot.c                |   14 
 b/arch/x86/kernel/traps.c                  |    2 
 b/arch/x86/kernel/vsmp_64.c                |   19 
 b/arch/x86/platform/uv/uv_irq.c            |    5 
 b/arch/x86/xen/apic.c                      |    6 
 b/drivers/gpio/gpio-xgene-sb.c             |    7 
 b/drivers/iommu/amd_iommu.c                |   44 -
 b/drivers/iommu/intel_irq_remapping.c      |   43 -
 b/drivers/irqchip/irq-gic-v3-its.c         |    5 
 b/drivers/pinctrl/stm32/pinctrl-stm32.c    |    5 
 b/include/linux/irq.h                      |   22 
 b/include/linux/irqdesc.h                  |    1 
 b/include/linux/irqdomain.h                |   14 
 b/include/linux/msi.h                      |    5 
 b/include/trace/events/irq_matrix.h        |  201 +++++
 b/kernel/irq/Kconfig                       |    3 
 b/kernel/irq/Makefile                      |    1 
 b/kernel/irq/autoprobe.c                   |    2 
 b/kernel/irq/chip.c                        |   37 
 b/kernel/irq/debugfs.c                     |   12 
 b/kernel/irq/internals.h                   |   19 
 b/kernel/irq/irqdesc.c                     |    3 
 b/kernel/irq/irqdomain.c                   |   43 -
 b/kernel/irq/manage.c                      |   18 
 b/kernel/irq/matrix.c                      |  443 +++++++++++
 b/kernel/irq/msi.c                         |   32 
 58 files changed, 2133 insertions(+), 1208 deletions(-)