Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3421759pxf; Mon, 22 Mar 2021 06:11:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxD83DgPbXspk+dB7smq1mM1UdvnmkcFEtHOS5avLgzer0HqMVmYtFOFa9Nsa8EHAa47hh/ X-Received: by 2002:adf:e7cf:: with SMTP id e15mr18336372wrn.346.1616418706942; Mon, 22 Mar 2021 06:11:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616418706; cv=none; d=google.com; s=arc-20160816; b=Q8l+Vhv6cBWFSIpQe0XRiXteSTZ4HzjP/VjA2FDPtNEsV8xJG/28Fl8twyDJzsftou XmB3cyAh7XLyan5HC8Mw9iRCuLjbZj/Ow6i1+NmJ4BD7AB01rQtFxlIytah7poPf5s+E KMrRw3ylN06pd0dSLiLI0grTa8RojODnDDqXrFaQOq2ql3IGnhmv55qgkxQxdDOloqXx 1EKrK3nVUnGCo7b6sv8sE8GNygOVAEy2/S9YnNJOCWJT0FmuMeZHLll1dxDR2njlP9p6 FVBnTCxr+jMjCvcoLWRPuKG/DF/b/eiS3RaNxsd/1A5ZkcLHP3FAapFDfYThdv+hIHuB eecA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/H+TcZOX6l/k9BK2EogB3Sd1Y3vRLklVxfidmdUUhi0=; b=nTzqSDQZbm4D8HulHDdBjzU1f6JWVISMzxJsSrHVdR/Uk8fosAgP+vDND171l3JFJi rhDbtG6Ufn/WWzLmfUZAkrVKvUHUwSziZqQxkssfOVVXdh7Bo13cxOym0uMrSM2I8Gpo k8oCTDT7T+wkC8eDERdN6FPDi2JPCL3mNuXjhTOPuO+Wmn+1Fvlyo+CLSvi0T5//vXSM P7ddzzAvoI20R1e2zhP6PeKWu1+2Mgmmgfeub8F8wn8gcRENkKT2JYrjJBRA2Uyp7egV 3tkIooy9U5fxicATmZ5hHyxmivH+P5PtCmeMyBkpXfRlK1sGxWUgIAu+ddC9TD/wa5Aw 83hQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mb4ufhWK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n3si11530715edo.368.2021.03.22.06.11.24; Mon, 22 Mar 2021 06:11:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mb4ufhWK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233702AbhCVNIo (ORCPT + 99 others); Mon, 22 Mar 2021 09:08:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:47546 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232209AbhCVMy1 (ORCPT ); Mon, 22 Mar 2021 08:54:27 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0007360238; Mon, 22 Mar 2021 12:47:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1616417266; bh=uNNTSGPSxTzpQ8kXMfjQqx2Cg0+Zzvn4moUfv5kkXBM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mb4ufhWK3kqejov7dkPAXnwcsQHUlYI1B1p4f7TgUr56EADjT1Fy/OJvuBeO69I39 2sz+iDnO8MHdqUKEmE9QMH8l3uooBKicfbA/sconsTDnNHtDqIBBcYZ7sGO6Ngds0B oOlbHzu52CdZ7a6IY3L7WPl0At41hDTvLHJiCfPQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vitaly Kuznetsov , Thomas Gleixner Subject: [PATCH 4.9 19/25] x86/ioapic: Ignore IRQ2 again Date: Mon, 22 Mar 2021 13:29:09 +0100 Message-Id: <20210322121921.003950608@linuxfoundation.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210322121920.399826335@linuxfoundation.org> References: <20210322121920.399826335@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Gleixner commit a501b048a95b79e1e34f03cac3c87ff1e9f229ad upstream. Vitaly ran into an issue with hotplugging CPU0 on an Amazon instance where the matrix allocator claimed to be out of vectors. He analyzed it down to the point that IRQ2, the PIC cascade interrupt, which is supposed to be not ever routed to the IO/APIC ended up having an interrupt vector assigned which got moved during unplug of CPU0. The underlying issue is that IRQ2 for various reasons (see commit af174783b925 ("x86: I/O APIC: Never configure IRQ2" for details) is treated as a reserved system vector by the vector core code and is not accounted as a regular vector. The Amazon BIOS has an routing entry of pin2 to IRQ2 which causes the IO/APIC setup to claim that interrupt which is granted by the vector domain because there is no sanity check. As a consequence the allocation counter of CPU0 underflows which causes a subsequent unplug to fail with: [ ... ] CPU 0 has 4294967295 vectors, 589 available. Cannot disable CPU There is another sanity check missing in the matrix allocator, but the underlying root cause is that the IO/APIC code lost the IRQ2 ignore logic during the conversion to irqdomains. For almost 6 years nobody complained about this wreckage, which might indicate that this requirement could be lifted, but for any system which actually has a PIC IRQ2 is unusable by design so any routing entry has no effect and the interrupt cannot be connected to a device anyway. Due to that and due to history biased paranoia reasons restore the IRQ2 ignore logic and treat it as non existent despite a routing entry claiming otherwise. Fixes: d32932d02e18 ("x86/irq: Convert IOAPIC to use hierarchical irqdomain interfaces") Reported-by: Vitaly Kuznetsov Signed-off-by: Thomas Gleixner Tested-by: Vitaly Kuznetsov Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20210318192819.636943062@linutronix.de Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/apic/io_apic.c | 10 ++++++++++ 1 file changed, 10 insertions(+) --- a/arch/x86/kernel/apic/io_apic.c +++ b/arch/x86/kernel/apic/io_apic.c @@ -1042,6 +1042,16 @@ static int mp_map_pin_to_irq(u32 gsi, in if (idx >= 0 && test_bit(mp_irqs[idx].srcbus, mp_bus_not_pci)) { irq = mp_irqs[idx].srcbusirq; legacy = mp_is_legacy_irq(irq); + /* + * IRQ2 is unusable for historical reasons on systems which + * have a legacy PIC. See the comment vs. IRQ2 further down. + * + * If this gets removed at some point then the related code + * in lapic_assign_system_vectors() needs to be adjusted as + * well. + */ + if (legacy && irq == PIC_CASCADE_IR) + return -EINVAL; } mutex_lock(&ioapic_mutex);