Received: by 2002:a17:90a:9103:0:0:0:0 with SMTP id k3csp11800945pjo; Thu, 2 Jan 2020 14:30:51 -0800 (PST) X-Google-Smtp-Source: APXvYqyRufcObalgKLpA9DUVy4hXeUm8O3LHb5KO4DKHU5WH2P5w++pxnJFG3gZVkE6PTmIOwJhs X-Received: by 2002:a9d:70cb:: with SMTP id w11mr78432335otj.230.1578004251370; Thu, 02 Jan 2020 14:30:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578004251; cv=none; d=google.com; s=arc-20160816; b=Ym6Sv/K7H3naYhTk4vjKz/22SEqSeGrVFISUVDoBcWYyNWKR4s/f772wA/AlB0Vmvy iXxudqcvQQS1smMFgpmX5CvTeYLW84bIDxMzxaSyChLO0l26yDqIzZMxsYVbYdt+qHD1 sjxbg7m0OPm+D9Eq0YxPmxTGvdHiNMJzCCoNId9CvE/Gmcb1B7k5gEXi5uyEG1y2MkMm wqxESZ4kc2hBNUcXrpTRZ53Ipa5cdGlHL2orn2r8jywsu3eAqx3XhfqnXGot8vzhoiOX jSurZP72Tjx8sY23TfwPs3lY4lM3xwavsmM8wL/iC3PaWFpyc3dB8jA4js5EXoJzH5vE dLpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PWjH2jJSokx4BNn3vRrgyJFBKzSA0gzBgbf318WIzw8=; b=DDYSxtk3FI8C/0hO9kTe+eEb6nfFSWI9ZP3kglMp5hSxBe8yTP2do4DxdZd+HFlHab RGTXDLa23zLsli6QkoZpI3vqkwXiaOwFAWCRitJbFxWnzli9Itv1ZgEqFlXlRmBOnEb9 4PAyq8W+I7BNvnDzfk7hDRXPPGAYxGv7+mHjskLs+KePQmQGmpQ3MDeD8xs+PcOJ8uaX IR61oYvQmk1QS6b3nCHOLEWXm889E+9wQ+h1D6Jvf8LSSTJTYLKwmb3pqIT0yp84cgKs LySxQ0NFea44WRo3knKCqT0sUcoOCWgSMPxjlvlZuMxxk15JeYOtMy4eOLB3dFC3Fmfi TuTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OZtYQPKl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w202si18936723oiw.194.2020.01.02.14.30.39; Thu, 02 Jan 2020 14:30:51 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OZtYQPKl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729815AbgABW35 (ORCPT + 99 others); Thu, 2 Jan 2020 17:29:57 -0500 Received: from mail.kernel.org ([198.145.29.99]:32896 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730094AbgABW3v (ORCPT ); Thu, 2 Jan 2020 17:29:51 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 960AB20863; Thu, 2 Jan 2020 22:29:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578004191; bh=gFmiTIFanl6uDAvj8mEMHH0JSvxZewluyRxF6kMjtPI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OZtYQPKl7iABZgkwVSmz/rhokJVmcRzdKvflbN1cf6/ryclnBxRzFZVZhSAsWCWJ1 7/pfBCXfhTCC6ORBTsZrz5/8k+6Zz9bZHREFUIREZD0gXDFgqQvCRY59ayC8CnaGaL tz0q5E7njmHkRwZ8GBxGlZHEqLI7jbcXu6AdndHU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Gleixner , Andy Shevchenko , Linus Torvalds , Peter Zijlstra , Sebastian Siewior , Ingo Molnar , Sasha Levin Subject: [PATCH 4.9 041/171] x86/ioapic: Prevent inconsistent state when moving an interrupt Date: Thu, 2 Jan 2020 23:06:12 +0100 Message-Id: <20200102220552.675021311@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102220546.960200039@linuxfoundation.org> References: <20200102220546.960200039@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Gleixner [ Upstream commit df4393424af3fbdcd5c404077176082a8ce459c4 ] There is an issue with threaded interrupts which are marked ONESHOT and using the fasteoi handler: if (IS_ONESHOT()) mask_irq(); .... cond_unmask_eoi_irq() chip->irq_eoi(); if (setaffinity_pending) { mask_ioapic(); ... move_affinity(); unmask_ioapic(); } So if setaffinity is pending the interrupt will be moved and then unconditionally unmasked at the ioapic level, which is wrong in two aspects: 1) It should be kept masked up to the point where the threaded handler finished. 2) The physical chip state and the software masked state are inconsistent Guard both the mask and the unmask with a check for the software masked state. If the line is marked masked then the ioapic line is also masked, so both mask_ioapic() and unmask_ioapic() can be skipped safely. Signed-off-by: Thomas Gleixner Cc: Andy Shevchenko Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Sebastian Siewior Fixes: 3aa551c9b4c4 ("genirq: add threaded interrupt handler support") Link: https://lkml.kernel.org/r/20191017101938.321393687@linutronix.de Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin --- arch/x86/kernel/apic/io_apic.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c index 09dd95cabfc2..3401b28f1312 100644 --- a/arch/x86/kernel/apic/io_apic.c +++ b/arch/x86/kernel/apic/io_apic.c @@ -1712,9 +1712,10 @@ static bool io_apic_level_ack_pending(struct mp_chip_data *data) static inline bool ioapic_irqd_mask(struct irq_data *data) { - /* If we are moving the irq we need to mask it */ + /* If we are moving the IRQ we need to mask it */ if (unlikely(irqd_is_setaffinity_pending(data))) { - mask_ioapic_irq(data); + if (!irqd_irq_masked(data)) + mask_ioapic_irq(data); return true; } return false; @@ -1751,7 +1752,9 @@ static inline void ioapic_irqd_unmask(struct irq_data *data, bool masked) */ if (!io_apic_level_ack_pending(data->chip_data)) irq_move_masked_irq(data); - unmask_ioapic_irq(data); + /* If the IRQ is masked in the core, leave it: */ + if (!irqd_irq_masked(data)) + unmask_ioapic_irq(data); } } #else -- 2.20.1