From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752377AbbHBUip (ORCPT ); Sun, 2 Aug 2015 16:38:45 -0400 Received: from www.linutronix.de ([62.245.132.108]:58486 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751638AbbHBUil (ORCPT ); Sun, 2 Aug 2015 16:38:41 -0400 Message-Id: <20150802203609.222975294@linutronix.de> User-Agent: quilt/0.63-1 Date: Sun, 02 Aug 2015 20:38:23 -0000 From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Jiang Liu , Peter Zijlstra , Rusty Russell , Bjorn Helgaas Subject: [patch 1/7] x86/irq: Protect smp_cleanup_move References: <20150802203427.110728870@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Disposition: inline; filename=x86-irq--Protect-smp_cleanup_move X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org smp_cleanup_move fiddles without protection in the interrupt descriptors and the vector array. A concurrent irq setup/teardown or affinity setting can pull the rug under that operation. Add proper locking. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/apic/vector.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) Index: tip/arch/x86/kernel/apic/vector.c =================================================================== --- tip.orig/arch/x86/kernel/apic/vector.c +++ tip/arch/x86/kernel/apic/vector.c @@ -539,6 +539,9 @@ asmlinkage __visible void smp_irq_move_c entering_ack_irq(); + /* Prevent vectors vanishing under us */ + raw_spin_lock(&vector_lock); + me = smp_processor_id(); for (vector = FIRST_EXTERNAL_VECTOR; vector < NR_VECTORS; vector++) { int irq; @@ -546,6 +549,7 @@ asmlinkage __visible void smp_irq_move_c struct irq_desc *desc; struct apic_chip_data *data; + retry: irq = __this_cpu_read(vector_irq[vector]); if (irq <= VECTOR_UNDEFINED) @@ -555,12 +559,16 @@ asmlinkage __visible void smp_irq_move_c if (!desc) continue; + if (!raw_spin_trylock(&desc->lock)) { + raw_spin_unlock(&vector_lock); + cpu_relax(); + raw_spin_lock(&vector_lock); + goto retry; + } + data = apic_chip_data(&desc->irq_data); if (!data) - continue; - - raw_spin_lock(&desc->lock); - + goto unlock; /* * Check if the irq migration is in progress. If so, we * haven't received the cleanup request yet for this irq. @@ -589,6 +597,8 @@ unlock: raw_spin_unlock(&desc->lock); } + raw_spin_unlock(&vector_lock); + exiting_irq(); }