Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp13477672ybl; Sun, 29 Dec 2019 12:51:44 -0800 (PST) X-Google-Smtp-Source: APXvYqzbJ91LKj51G1DfcbO6s49LQj3KZt+eH6R4U2yjaoebwGW0l4xEyRvL4e3A8GO3F/hTYK4b X-Received: by 2002:a05:6830:20cf:: with SMTP id z15mr70550623otq.277.1577652704148; Sun, 29 Dec 2019 12:51:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577652704; cv=none; d=google.com; s=arc-20160816; b=pPiVbJFdcPxFW0o7cl+V3ab0bSgg4lFml9fbcP9hLryVZkGdjQ4tvldTK7g04CFKOB O8ZWuX6BoiQLES35qvuhA0Y+mQWljMDuTE/nGDebK2JLETpCH/3oxhws1JbCrD9YmQ8B Z4/Lix88B0YEOHd4tZ5yI1oDCzbVmv3H/Sg/PKJA2eDPizmz5ol5qUfnXtz184tiKCDn hllKIdhGNkCcoqx3RTf/yQiO9YdlLXa89M8S/e33KOcFD1eLEulpotd2nPh3E6Km6Znw JeHcaiMwxQQQAgopxpWE1ihY4SAIc3fnCv/Pif9p0MChXhw3+tfpyPleCCPXVdvT9ou9 OSoA== 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=bXci5Lkf4cONEKgJNlobRsaHWrKbLxR42Oqu9D00UME=; b=vpov+exQNA101wH7BvP7Mhoex2NYbpfYZzaRtTEZIPOkCRXDtor0PDVo2MZbKetReR jnFr5V5YzZtd5DFgdVD2Vqp0Ti4jWpthHLZwKuyMOvXl5BM3OjeqxD3GaqE6Ehinqxs9 b76ru5iUbRbvuTIJTRo9w/XAvc/AEsFF6qZjsxTBu9tAHUwx6wM5v5bNGMo3af4rB024 5Ih5ef6y7fGGtapJtSpRB/JWrQX6m5fS7AlOt0vY+GyiivQPmxPddj6ItpAYUaKaIR5Q ePUvUEw0g4Q7tMRHkDfSZ0WW+fGkijmC8jSK+dOLS2BH7xablM2RtwyV6ChIApBrYQS2 FF6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=K3cG8Tze; 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 r10si22375842otn.241.2019.12.29.12.51.32; Sun, 29 Dec 2019 12:51:44 -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=K3cG8Tze; 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 S1731806AbfL2SHd (ORCPT + 99 others); Sun, 29 Dec 2019 13:07:33 -0500 Received: from mail.kernel.org ([198.145.29.99]:59372 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731414AbfL2RsP (ORCPT ); Sun, 29 Dec 2019 12:48:15 -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 E39C620718; Sun, 29 Dec 2019 17:48:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577641694; bh=Y4m/RwN2ranY735rniath50UVtHZnmae7VpkTlARzpY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K3cG8TzeJYAQ45IvkPBxARPuSKuBzwbhOeNp2BmvwNEyiLY8W0YSqSdKR1Eg+wdmh 8KF12OdOv4Tw7+LGdEFcaG60gDzJ6Iov+6fXBLkujZpn0lHQ+8uqgFJDrGm6wsbQbP tUgpggCcjh61n66XNWM+Dv6H0i7a4L5CpkXDGsdU= 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 5.4 172/434] x86/ioapic: Prevent inconsistent state when moving an interrupt Date: Sun, 29 Dec 2019 18:23:45 +0100 Message-Id: <20191229172713.231931259@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191229172702.393141737@linuxfoundation.org> References: <20191229172702.393141737@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 d6af97fd170a..f0262cb5657a 100644 --- a/arch/x86/kernel/apic/io_apic.c +++ b/arch/x86/kernel/apic/io_apic.c @@ -1727,9 +1727,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; @@ -1766,7 +1767,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