From patchwork Sun Mar 5 08:54:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 64280 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1291353wrd; Sun, 5 Mar 2023 01:02:40 -0800 (PST) X-Google-Smtp-Source: AK7set8f7MJCVTwE/mn2v+Q2il1MwI13B0h+UDZitez9k2xMS7c9RZX8u+X4XaP7TwaB4C2vTtpA X-Received: by 2002:a17:90b:4c10:b0:229:2427:532f with SMTP id na16-20020a17090b4c1000b002292427532fmr7272587pjb.40.1678006960030; Sun, 05 Mar 2023 01:02:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678006960; cv=none; d=google.com; s=arc-20160816; b=ZMrr5abQDEsvU1+3nFQiz1nmjJRzN62uj7UwVJiK0HS9pr9qY2AbPLob6FFrkwFF3u kvHFoY3f1/B+NVkWcX+YRZ26H8DdkE+aDMidGRclIL/qmrjI1DfQsMDRy5TqdjNdk56u qsg8LeTfhdEBRPpGiqAadrsTO6oIjiQWOcnvZVfjaYd2MGKchTJj98kmq6rXbdJoqOcG 40J49eAVCXcaQYtt2W6btI+DDLQLB4Ez9XwOHobX5007EA1qKou1re/avHPvE2iiUley ME3YARh1FwO6B99g0FweeocQTih2tJPovz8hQFmC+8eDm8i/LKfI0UBJwqjXXLsJ7rlK eW+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:content-transfer-encoding :message-id:subject:cc:to:dkim-signature:dkim-signature:from; bh=G5qK0cf96IOotNupUsQvBaE4OYdkjC+Vg5n4Iv6niHg=; b=Blq3czsWkuZwLKSxQZmpRg9IqaNLkogZDAGrdzWKkyXWiyiDzDpSi6B/OjHuPO62z0 H14mTT39cafbY0ZX6QtYkptdQ0mOUzO9OWp/7Rh+cnqyIsyPZukFuuL9TQLyZ2sU77D/ a9Bb6NXu8ShRf+Z1WQau368XEiWsc2U/S02C1++rkxXWA6fOFEkxKW9riJoY9O7gODJX VyDwmu4hriAuYGK3hcNRZIm4Zo+706Ucv4uBJ1I5VES6VsON3mVv2f5B/ehUf0od4Rua scgEFP4z2fh8tT7IPvanE8BQJ42RPljijNh6so1NOINgr4QdXO7hGvpZdPa+zhEqZQWq Ao0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=I8VpbrhA; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=3cb4O1U2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d2-20020a630e02000000b0050304fd5863si6798022pgl.257.2023.03.05.01.02.26; Sun, 05 Mar 2023 01:02:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=I8VpbrhA; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=3cb4O1U2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229681AbjCEIzF (ORCPT + 99 others); Sun, 5 Mar 2023 03:55:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229379AbjCEIzD (ORCPT ); Sun, 5 Mar 2023 03:55:03 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B34E3BBB1 for ; Sun, 5 Mar 2023 00:55:00 -0800 (PST) From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1678006497; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=G5qK0cf96IOotNupUsQvBaE4OYdkjC+Vg5n4Iv6niHg=; b=I8VpbrhAS1DupUj7g0z21VhlQU/avesiXSxcO4ylP6fed/iGxhso8j7joczA2h0XW3A3si KATyN3zmC9xLkv87qXv1w5GR5tZkg1FjjzVmCaZVFskAtqjJicJ3fVRmjmJRB1KYFZXnN4 /MA92lUhFYBdb0elP1McGmctjLJMLl7ianQdMbqr8eHiQuIwxcf1alg7qgQ65i29FUbCu7 u5mjutyCDsQoI62BV6C3ew083lN/to6NmAahi4EUkmLtCdaZJcjokLEHqi0qFTd51R1wMG h8AdtvLSDkEqQGxa48FvO0XX4M2tbDVhpdXl/DU5utFlgSqpVnUZC9iVaLbL1Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1678006497; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=G5qK0cf96IOotNupUsQvBaE4OYdkjC+Vg5n4Iv6niHg=; b=3cb4O1U24M7od50mfx9ciDOm13bkNOP7H4sVAjkpDuOgOzm75nXtBsGkhQ+VcuBnMgC060 sxWIw3sRpo5QSKCQ== To: Linus Torvalds Cc: linux-kernel@vger.kernel.org, x86@kernel.org Subject: [GIT pull] irq/urgent for v6.3-rc1 Message-ID: <167800644191.309766.5757985605946414576.tglx@xen13> MIME-Version: 1.0 Date: Sun, 5 Mar 2023 09:54:57 +0100 (CET) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759517825750339331?= X-GMAIL-MSGID: =?utf-8?q?1759517825750339331?= Linus, please pull the latest irq/urgent branch from: git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git irq-urgent-2023-03-05 up to: 0fb7fb713461: genirq/msi, platform-msi: Ensure that MSI descriptors are unreferenced A set of updates for the interrupt susbsystem: - Prevent possible NULL pointer derefences in irq_data_get_affinity_mask() and irq_domain_create_hierarchy(). - Take the per device MSI lock before invoking code which relies on it being hold. - Make sure that MSI descriptors are unreferenced before freeing them. This was overlooked when the platform MSI code was converted to use core infrastructure and results in a fals positive warning. - Remove dead code in the MSI subsystem. - Clarify the documentation for pci_msix_free_irq(). - More kobj_type constification. Thanks, tglx ------------------> Johan Hovold (21): genirq/msi: Drop dead domain name assignment Juergen Gross (1): irqdomain: Add missing NULL pointer check in irq_domain_create_hierarchy() Marc Zyngier (4): genirq/msi: Take the per-device MSI lock before validating the control structure Reinette Chatre (1): PCI/MSI: Clarify usage of pci_msix_free_irq() Sergey Shtylyov (1): genirq/ipi: Fix NULL pointer deref in irq_data_get_affinity_mask() Thomas Gleixner (1): genirq/msi, platform-msi: Ensure that MSI descriptors are unreferenced Thomas Weißschuh (1): genirq/irqdesc: Make kobj_type structures constant drivers/base/platform-msi.c | 1 + drivers/pci/msi/api.c | 4 ++-- include/linux/msi.h | 2 ++ kernel/irq/ipi.c | 8 ++++++-- kernel/irq/irqdesc.c | 4 ++-- kernel/irq/irqdomain.c | 3 ++- kernel/irq/msi.c | 28 +++++++++++++++++++++++----- kernel/irq/msi.c | 9 ++++++--- 8 files changed, 44 insertions(+), 15 deletions(-) diff --git a/drivers/base/platform-msi.c b/drivers/base/platform-msi.c index 5883e7634a2b..f37ad34c80ec 100644 --- a/drivers/base/platform-msi.c +++ b/drivers/base/platform-msi.c @@ -324,6 +324,7 @@ void platform_msi_device_domain_free(struct irq_domain *domain, unsigned int vir struct platform_msi_priv_data *data = domain->host_data; msi_lock_descs(data->dev); + msi_domain_depopulate_descs(data->dev, virq, nr_irqs); irq_domain_free_irqs_common(domain, virq, nr_irqs); msi_free_msi_descs_range(data->dev, virq, virq + nr_irqs - 1); msi_unlock_descs(data->dev); diff --git a/include/linux/msi.h b/include/linux/msi.h index a112b913fff9..15dd71817996 100644 --- a/include/linux/msi.h +++ b/include/linux/msi.h @@ -631,6 +631,8 @@ int msi_domain_prepare_irqs(struct irq_domain *domain, struct device *dev, int nvec, msi_alloc_info_t *args); int msi_domain_populate_irqs(struct irq_domain *domain, struct device *dev, int virq, int nvec, msi_alloc_info_t *args); +void msi_domain_depopulate_descs(struct device *dev, int virq, int nvec); + struct irq_domain * __platform_msi_create_device_domain(struct device *dev, unsigned int nvec, diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c index aa5b7eeeceb8..6522dfb2e49c 100644 --- a/kernel/irq/irqdomain.c +++ b/kernel/irq/irqdomain.c @@ -1172,7 +1172,8 @@ struct irq_domain *irq_domain_create_hierarchy(struct irq_domain *parent, domain = __irq_domain_create(fwnode, 0, ~0, 0, ops, host_data); if (domain) { - domain->root = parent->root; + if (parent) + domain->root = parent->root; domain->parent = parent; domain->flags |= flags; diff --git a/kernel/irq/msi.c b/kernel/irq/msi.c index 13d96495e6d0..d169ee0c1799 100644 --- a/kernel/irq/msi.c +++ b/kernel/irq/msi.c @@ -830,11 +830,8 @@ static struct irq_domain *__msi_create_irq_domain(struct fwnode_handle *fwnode, domain = irq_domain_create_hierarchy(parent, flags | IRQ_DOMAIN_FLAG_MSI, 0, fwnode, &msi_domain_ops, info); - if (domain) { - if (!domain->name && info->chip) - domain->name = info->chip->name; + if (domain) irq_domain_update_bus_token(domain, info->bus_token); - } return domain; } @@ -1112,14 +1109,35 @@ int msi_domain_populate_irqs(struct irq_domain *domain, struct device *dev, return 0; fail: - for (--virq; virq >= virq_base; virq--) + for (--virq; virq >= virq_base; virq--) { + msi_domain_depopulate_descs(dev, virq, 1); irq_domain_free_irqs_common(domain, virq, 1); + } msi_domain_free_descs(dev, &ctrl); unlock: msi_unlock_descs(dev); return ret; } +void msi_domain_depopulate_descs(struct device *dev, int virq_base, int nvec) +{ + struct msi_ctrl ctrl = { + .domid = MSI_DEFAULT_DOMAIN, + .first = virq_base, + .last = virq_base + nvec - 1, + }; + struct msi_desc *desc; + struct xarray *xa; + unsigned long idx; + + if (!msi_ctrl_valid(dev, &ctrl)) + return; + + xa = &dev->msi.data->__domains[ctrl.domid].store; + xa_for_each_range(xa, idx, desc, ctrl.first, ctrl.last) + desc->irq = 0; +} + /* * Carefully check whether the device can use reservation mode. If * reservation mode is enabled then the early activation will assign a diff --git a/drivers/pci/msi/api.c b/drivers/pci/msi/api.c index b8009aa11f3c..be679aa5db64 100644 --- a/drivers/pci/msi/api.c +++ b/drivers/pci/msi/api.c @@ -163,11 +163,11 @@ EXPORT_SYMBOL_GPL(pci_msix_alloc_irq_at); /** * pci_msix_free_irq - Free an interrupt on a PCI/MSIX interrupt domain - * which was allocated via pci_msix_alloc_irq_at() * * @dev: The PCI device to operate on * @map: A struct msi_map describing the interrupt to free - * as returned from the allocation function. + * + * Undo an interrupt vector allocation. Does not disable MSI-X. */ void pci_msix_free_irq(struct pci_dev *dev, struct msi_map map) { diff --git a/kernel/irq/ipi.c b/kernel/irq/ipi.c index bbd945bacef0..961d4af76af3 100644 --- a/kernel/irq/ipi.c +++ b/kernel/irq/ipi.c @@ -188,9 +188,9 @@ EXPORT_SYMBOL_GPL(ipi_get_hwirq); static int ipi_send_verify(struct irq_chip *chip, struct irq_data *data, const struct cpumask *dest, unsigned int cpu) { - const struct cpumask *ipimask = irq_data_get_affinity_mask(data); + const struct cpumask *ipimask; - if (!chip || !ipimask) + if (!chip || !data) return -EINVAL; if (!chip->ipi_send_single && !chip->ipi_send_mask) @@ -199,6 +199,10 @@ static int ipi_send_verify(struct irq_chip *chip, struct irq_data *data, if (cpu >= nr_cpu_ids) return -EINVAL; + ipimask = irq_data_get_affinity_mask(data); + if (!ipimask) + return -EINVAL; + if (dest) { if (!cpumask_subset(dest, ipimask)) return -EINVAL; diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c index fd0996274401..240e145e969f 100644 --- a/kernel/irq/irqdesc.c +++ b/kernel/irq/irqdesc.c @@ -277,7 +277,7 @@ static struct attribute *irq_attrs[] = { }; ATTRIBUTE_GROUPS(irq); -static struct kobj_type irq_kobj_type = { +static const struct kobj_type irq_kobj_type = { .release = irq_kobj_release, .sysfs_ops = &kobj_sysfs_ops, .default_groups = irq_groups, @@ -335,7 +335,7 @@ postcore_initcall(irq_sysfs_init); #else /* !CONFIG_SYSFS */ -static struct kobj_type irq_kobj_type = { +static const struct kobj_type irq_kobj_type = { .release = irq_kobj_release, }; diff --git a/kernel/irq/msi.c b/kernel/irq/msi.c index 783a3e6a0b10..13d96495e6d0 100644 --- a/kernel/irq/msi.c +++ b/kernel/irq/msi.c @@ -1084,10 +1084,13 @@ int msi_domain_populate_irqs(struct irq_domain *domain, struct device *dev, struct xarray *xa; int ret, virq; - if (!msi_ctrl_valid(dev, &ctrl)) - return -EINVAL; - msi_lock_descs(dev); + + if (!msi_ctrl_valid(dev, &ctrl)) { + ret = -EINVAL; + goto unlock; + } + ret = msi_domain_add_simple_msi_descs(dev, &ctrl); if (ret) goto unlock;