Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp13336104ybl; Sun, 29 Dec 2019 09:34:04 -0800 (PST) X-Google-Smtp-Source: APXvYqx+AhG47jN1rHIlJ+W+iACODN7BXCjU6uYspzk1QhgMJaOZ5hy0GKC6RLVQbe96OUpSoTSh X-Received: by 2002:a9d:6d81:: with SMTP id x1mr72953036otp.9.1577640843850; Sun, 29 Dec 2019 09:34:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577640843; cv=none; d=google.com; s=arc-20160816; b=LFkp14R3PEtV9DaxUcgBhcmXi6Z9fmnTNjbk0jVcVfN+Somz2Yl0rtFvZEYlpVeaKd EByTiN00hRtJGNuCDf04QL+2MTCxSNhcCVACtAh2DpFuC0bXovkQXu61ll6zYUTKYh25 6hXlxho4S9yAxZtz/FVW+pD1DREst6hAmUbd4oDeaKser3cFykGFW5sgsD4rHiyddhQW tWCTQDXt8pLoiAMIhsZ1+VoubZa/g/Z7MkeflNc/GHtSjQRe6y8UwZLl5cIWV16MeknU p6q9IgUoZbaE6wPa7EhSejl80Rrixxfl8t1iBMa8Vz4nQVxKPpOEpRSL+6pkYHNpdT6N hshQ== 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=6bQgmhgngWmTllNK8p7od1PbXWa8N7cezNrDx1N1A5E=; b=nq0sxFWjJ3AJOFEHA3w1PXmO9J9Gv6pab0BkAI7LX7BE+NfObpa8H7TfTrYCM7/DRU bHiJ952tmUvVOSpUXLK33P0O2T/XUbPh2zsd69HfAejz0J5M3M3FjKsshzr3sPqSlHzk rZr3QX53pVSojpXfNh4dLk7ppW/yg26JCdxqGeVffGuIj6o02nbTwx5D4FNdXLzIsKTT sh2QpaPXYTPaw8c/F/uWIixz1m3//pVtakbAS/QNVddz/ZSDU/OakFZ6+cl7HM/VMe8O c3I2uX5xm86H2aPE8rEDb6o8yEQ0S9SF+hBDF/ZVuz8mhu5XCEEDPlerJINe9d2HEMWb jq3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=n4RzOkEC; 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 v4si14451402oth.306.2019.12.29.09.33.53; Sun, 29 Dec 2019 09:34:03 -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=n4RzOkEC; 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 S1729353AbfL2Rcp (ORCPT + 99 others); Sun, 29 Dec 2019 12:32:45 -0500 Received: from mail.kernel.org ([198.145.29.99]:33342 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729342AbfL2Rck (ORCPT ); Sun, 29 Dec 2019 12:32:40 -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 A7A51208E4; Sun, 29 Dec 2019 17:32:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577640760; bh=+Kf9WqdIqt2OINxaomJUPTrMY0shwAmeuuV8RdUx/7Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n4RzOkECTfYuK2ft21KL6Wsr7mlbSffYal/MJm5yyIPgt8P8G9vAFfoLRW+mbQadk 9Nrs2NPr04WIppI+oTZG/YuE86W8y1na96UwL9pChShmkgIsFsNaX3xpl3CyohMzmC 2S/Inl5LjQgZegbt/aVxc8XEVfnnZ5gXDAS4xV2Y= 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.19 090/219] x86/ioapic: Prevent inconsistent state when moving an interrupt Date: Sun, 29 Dec 2019 18:18:12 +0100 Message-Id: <20191229162520.902452219@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191229162508.458551679@linuxfoundation.org> References: <20191229162508.458551679@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 ab22eded61d2..fa3b85b222e3 100644 --- a/arch/x86/kernel/apic/io_apic.c +++ b/arch/x86/kernel/apic/io_apic.c @@ -1724,9 +1724,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; @@ -1763,7 +1764,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