Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp13386136ybl; Sun, 29 Dec 2019 10:37:57 -0800 (PST) X-Google-Smtp-Source: APXvYqzAC3WuHIgOPUcv/TXZ6rCQg3DC45M72vTBniXIpZobhKwHvB/YyJVdtFRSp2ZJKdlp2Nf3 X-Received: by 2002:a05:6830:1112:: with SMTP id w18mr63963197otq.356.1577644677728; Sun, 29 Dec 2019 10:37:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577644677; cv=none; d=google.com; s=arc-20160816; b=A7Lh05ShoIr7TbbTPLswoxna7LxOMlehS+YLksDOg2hgzTM8UHKE/QEpfJJtZAmBM0 u+8iKi0GVH0DG8IpZRqD4doVf5iwdwClKabVmLfJesF24Umh0F+glkofX+8vUmXTZ5Bl WtYZCVtDic/D3sJXdcv8dIw17WtkCVDlxJ310gHusc+BjpbgwLtJt7S3aJBmwoy2jgB9 uqmY9S5axDO9xBaISHUVrOBEdzE7XtPMqdV8m214i3kO5nuJoqPYXKN/rODowuYU3hNg +r9LUM41AJ47ZSOHwtqEkQ5qXHB32/u3xJJa7rRJqhna0KzKAx49+LShfguLicZMZo+I kjTg== 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=6Lxiw6iTQUL1iK0KX0SoQrrKdd79o6BKG396Qa6Ig5w=; b=ml0w2QzkrjHql8qPGPeh1VhHPyIXYmLveA2AHMjdMhPYtcyo0DomRA0SzQmQb743CX tb86gwI0NHhcu5yGfX+hQIoKR5hTDvc3wtRl8bs76jzt79Rk/5Qe3k2WfXThLyqZ46Kc jRdMfCjlc0EVa1bKKLmNUGCeXBsA8u+vL9Uk/z0cs4C28tBfF01NuO6u04k2GufsKWUS pmImafTXNDAgtkWJldzFM+OtspRxzjqVr2C/IV2w95W3s5gKqDPmX3a1cwC1t7ZMdDNG JSWhKfEAEyuk4CXnty8bI9q5SmDheHySAHzHhxNmTesSR1CZTc227uMhxqiS98ZNCxTa 2FFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wNy8uPdz; 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 k19si21628934otr.52.2019.12.29.10.37.45; Sun, 29 Dec 2019 10:37:57 -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=wNy8uPdz; 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 S1727621AbfL2RXy (ORCPT + 99 others); Sun, 29 Dec 2019 12:23:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:41786 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727595AbfL2RXr (ORCPT ); Sun, 29 Dec 2019 12:23:47 -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 E9E3121D7E; Sun, 29 Dec 2019 17:23:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577640226; bh=UcLj21KbTmfij9dhrxgXikQYoPDlI2o6g70sRvaZz3o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wNy8uPdzscwOWWUBaHrzwCUEX/91sQIsVFa3tz1getVgiSJQBKlAdBtjf51CgQ2Mn ZlL0qPPAVAZMjxomR5qsnTXhYpVppW0G0R9WBhboWcPYhcUfQKDYchy1TyOc6L6MR9 KxGMJCCuK1rNf+wEqd4QfWwnXjX2XJco8MxrHz3c= 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.14 069/161] x86/ioapic: Prevent inconsistent state when moving an interrupt Date: Sun, 29 Dec 2019 18:18:37 +0100 Message-Id: <20191229162421.186747087@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191229162355.500086350@linuxfoundation.org> References: <20191229162355.500086350@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 566b7bc5deaa..2271adbc3c42 100644 --- a/arch/x86/kernel/apic/io_apic.c +++ b/arch/x86/kernel/apic/io_apic.c @@ -1690,9 +1690,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; @@ -1729,7 +1730,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