Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp333275pxb; Mon, 16 Aug 2021 06:32:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygMWp9EnMQEVECDfsevkjhNNx7HF+VymOfstTB/Pq2Gb0zD0uiLb5O7aBQQYLXV2WsTbDp X-Received: by 2002:a05:6e02:5aa:: with SMTP id k10mr11964002ils.301.1629120731641; Mon, 16 Aug 2021 06:32:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629120731; cv=none; d=google.com; s=arc-20160816; b=PasjPwaGeX6igIpMv8IvNv2JSjz6q0137gXvjVYtWodJJuCfk5ULQAlChUyvbHrgtZ CqFoG5XxnQThjT9WhfGSQ1Tj7T+lbQoI2wO6dRPDgCisqx7kFswYCHg+i/x9hChk41BV 7wXsW89tkl4Y2WONdcyknEGn9pZN2LiudbwK+fKGZd1brP/SQtZKSxwbw0F7wMpnzwAa Jg8TbgrpKJrQh6BVpW6tXaSr2ZH3P4t+/FQc75b+7ygNZ8BsK81ZuAZSOlCNNRayBxll /a2M8mQhxi317UwTGM+ZHi3lAzviSDqjs4ZLNYbbDaJBuxHtG69xojsLhpB6UAOb9FWK fdfQ== 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=lKcUGB7fPCGRsaUOtbSp3Vxzosd67arZYSevKZzrLGk=; b=q17syoNo1bTeSO0wBPbSu8/xZ2N90wb172hqeRGin3KG2x754RRB/Ladecz5by3z2Y 6kUtnCW8oE7ALzU+ObtOp5R0n5TxT4xIcnthNb3pxYXrKirIaiaF2k5OX5GqksmfTBho hrQiJ82Ak7xCEYWEQd+Sp2MZlBbS5RINqs9lunZoDZ9xSiWJqFPkUOW3Ci+WCCtLYmnN b1M0XjI2IHBoT0pgbn0qeAvVpZjjUwM9HHlBP/92W3mGEBV/FH/KqrSc6yX6UIVfysGs mclU0cetbwZl59sFW1BKRhMxp6z/Q7lJ6DsFnv3VAPuozWfrfaeA+1iB++5hzwm05U9i ymXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=B8LKccqA; 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 l13si3107322jaq.11.2021.08.16.06.31.58; Mon, 16 Aug 2021 06:32:11 -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=B8LKccqA; 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 S241435AbhHPN3h (ORCPT + 99 others); Mon, 16 Aug 2021 09:29:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:44416 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240547AbhHPNTx (ORCPT ); Mon, 16 Aug 2021 09:19:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 21208632A7; Mon, 16 Aug 2021 13:14:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1629119685; bh=uGLOyo7wHkxz6pejIDwgVgpBw/s0jqcR2PLVWvLYvRg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B8LKccqAB66qV9icz3WBOhWhS4xdP0wEqspJ5Sj6s7dvrNn+jOHPiTzmEXKBNyJRe mr9nQCaMkRmbHXXrPR3az4F08CZwtrOGHuSB2/wvrpZX3j+mtfmCd6p0JyFZiK+9ew 6cx4Vx+Cr1q/X5XcRI6T8efyYGjKKviv/4WNVSr8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Gleixner , Marc Zyngier Subject: [PATCH 5.13 122/151] x86/msi: Force affinity setup before startup Date: Mon, 16 Aug 2021 15:02:32 +0200 Message-Id: <20210816125448.084932001@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210816125444.082226187@linuxfoundation.org> References: <20210816125444.082226187@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 ff363f480e5997051dd1de949121ffda3b753741 upstream. The X86 MSI mechanism cannot handle interrupt affinity changes safely after startup other than from an interrupt handler, unless interrupt remapping is enabled. The startup sequence in the generic interrupt code violates that assumption. Mark the irq chips with the new IRQCHIP_AFFINITY_PRE_STARTUP flag so that the default interrupt setting happens before the interrupt is started up for the first time. While the interrupt remapping MSI chip does not require this, there is no point in treating it differently as this might spare an interrupt to a CPU which is not in the default affinity mask. For the non-remapping case go to the direct write path when the interrupt is not yet started similar to the not yet activated case. Fixes: 18404756765c ("genirq: Expose default irq affinity mask (take 3)") Signed-off-by: Thomas Gleixner Tested-by: Marc Zyngier Reviewed-by: Marc Zyngier Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20210729222542.886722080@linutronix.de Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/apic/msi.c | 11 ++++++++--- arch/x86/kernel/hpet.c | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) --- a/arch/x86/kernel/apic/msi.c +++ b/arch/x86/kernel/apic/msi.c @@ -58,11 +58,13 @@ msi_set_affinity(struct irq_data *irqd, * The quirk bit is not set in this case. * - The new vector is the same as the old vector * - The old vector is MANAGED_IRQ_SHUTDOWN_VECTOR (interrupt starts up) + * - The interrupt is not yet started up * - The new destination CPU is the same as the old destination CPU */ if (!irqd_msi_nomask_quirk(irqd) || cfg->vector == old_cfg.vector || old_cfg.vector == MANAGED_IRQ_SHUTDOWN_VECTOR || + !irqd_is_started(irqd) || cfg->dest_apicid == old_cfg.dest_apicid) { irq_msi_update_msg(irqd, cfg); return ret; @@ -150,7 +152,8 @@ static struct irq_chip pci_msi_controlle .irq_ack = irq_chip_ack_parent, .irq_retrigger = irq_chip_retrigger_hierarchy, .irq_set_affinity = msi_set_affinity, - .flags = IRQCHIP_SKIP_SET_WAKE, + .flags = IRQCHIP_SKIP_SET_WAKE | + IRQCHIP_AFFINITY_PRE_STARTUP, }; int pci_msi_prepare(struct irq_domain *domain, struct device *dev, int nvec, @@ -219,7 +222,8 @@ static struct irq_chip pci_msi_ir_contro .irq_mask = pci_msi_mask_irq, .irq_ack = irq_chip_ack_parent, .irq_retrigger = irq_chip_retrigger_hierarchy, - .flags = IRQCHIP_SKIP_SET_WAKE, + .flags = IRQCHIP_SKIP_SET_WAKE | + IRQCHIP_AFFINITY_PRE_STARTUP, }; static struct msi_domain_info pci_msi_ir_domain_info = { @@ -273,7 +277,8 @@ static struct irq_chip dmar_msi_controll .irq_retrigger = irq_chip_retrigger_hierarchy, .irq_compose_msi_msg = dmar_msi_compose_msg, .irq_write_msi_msg = dmar_msi_write_msg, - .flags = IRQCHIP_SKIP_SET_WAKE, + .flags = IRQCHIP_SKIP_SET_WAKE | + IRQCHIP_AFFINITY_PRE_STARTUP, }; static int dmar_msi_init(struct irq_domain *domain, --- a/arch/x86/kernel/hpet.c +++ b/arch/x86/kernel/hpet.c @@ -508,7 +508,7 @@ static struct irq_chip hpet_msi_controll .irq_set_affinity = msi_domain_set_affinity, .irq_retrigger = irq_chip_retrigger_hierarchy, .irq_write_msi_msg = hpet_msi_write_msg, - .flags = IRQCHIP_SKIP_SET_WAKE, + .flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_AFFINITY_PRE_STARTUP, }; static int hpet_msi_init(struct irq_domain *domain,