Skip to content

Commit e84cf6a

Browse files
KAGA-KOKOIngo Molnar
authored andcommitted
x86/apic/vector: Handle vector release on CPU unplug correctly
When a irq vector is replaced, then the previous vector is normally released when the first interrupt happens on the new vector. If the target CPU of the previous vector is already offline when the new vector is installed, then the previous vector is silently discarded, which leads to accounting issues causing suspend failures and other problems. Adjust the logic so that the previous vector is freed in the underlying matrix allocator to ensure that the accounting stays correct. Fixes: 69cde00 ("x86/vector: Use matrix allocator for vector assignment") Reported-by: Yuriy Vostrikov <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Tested-by: Yuriy Vostrikov <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Randy Dunlap <[email protected]> Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 651ca2c commit e84cf6a

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

arch/x86/kernel/apic/vector.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,21 +134,40 @@ static void apic_update_vector(struct irq_data *irqd, unsigned int newvec,
134134
{
135135
struct apic_chip_data *apicd = apic_chip_data(irqd);
136136
struct irq_desc *desc = irq_data_to_desc(irqd);
137+
bool managed = irqd_affinity_is_managed(irqd);
137138

138139
lockdep_assert_held(&vector_lock);
139140

140141
trace_vector_update(irqd->irq, newvec, newcpu, apicd->vector,
141142
apicd->cpu);
142143

143-
/* Setup the vector move, if required */
144-
if (apicd->vector && cpu_online(apicd->cpu)) {
144+
/*
145+
* If there is no vector associated or if the associated vector is
146+
* the shutdown vector, which is associated to make PCI/MSI
147+
* shutdown mode work, then there is nothing to release. Clear out
148+
* prev_vector for this and the offlined target case.
149+
*/
150+
apicd->prev_vector = 0;
151+
if (!apicd->vector || apicd->vector == MANAGED_IRQ_SHUTDOWN_VECTOR)
152+
goto setnew;
153+
/*
154+
* If the target CPU of the previous vector is online, then mark
155+
* the vector as move in progress and store it for cleanup when the
156+
* first interrupt on the new vector arrives. If the target CPU is
157+
* offline then the regular release mechanism via the cleanup
158+
* vector is not possible and the vector can be immediately freed
159+
* in the underlying matrix allocator.
160+
*/
161+
if (cpu_online(apicd->cpu)) {
145162
apicd->move_in_progress = true;
146163
apicd->prev_vector = apicd->vector;
147164
apicd->prev_cpu = apicd->cpu;
148165
} else {
149-
apicd->prev_vector = 0;
166+
irq_matrix_free(vector_matrix, apicd->cpu, apicd->vector,
167+
managed);
150168
}
151169

170+
setnew:
152171
apicd->vector = newvec;
153172
apicd->cpu = newcpu;
154173
BUG_ON(!IS_ERR_OR_NULL(per_cpu(vector_irq, newcpu)[newvec]));

0 commit comments

Comments
 (0)