From patchwork Sun Mar 9 08:41:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 872781 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A23D31925BF; Sun, 9 Mar 2025 08:41:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741509706; cv=none; b=PBDTCUkI3veoHGJFObieoBh08WXf82lrMzSb34X2lou3QX7ywvRWeoolx0jVJzLft7pTNu3+4UbCTwmvkqAN+kzit8SzeKaPb0rpNKPfGTSv741AgjneeALbs5xFyIWzv5jAdWu3FWCdNyN/Y1XNm06li1RL++KOtRNbivz+7II= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741509706; c=relaxed/simple; bh=jGrSz3q2PeovBJ75uquLx2u7rWcyV5mNW9o+5ursyaY=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=EXFT2vWG6Vzw9BL1pWHz4Wds7NYBPa1Z2KjNH3O0ofRJ80xIVOhYww1kjOxfgFage+EXZ0sz6bfVFeCjtBYtdNX+zUxa4g+U7bMKC0M0FDr1fo1OaxX67FE1GNFq5J9eqrE6YZs4JBnFRzsU7MUKIvbGAfwGrShiqWWuUFvB0SE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=vRLNzW24; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=jacMLK20; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="vRLNzW24"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="jacMLK20" Message-ID: <20250309084110.204054172@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741509703; 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: references:references; bh=fFdeRnRhAOgqTfFMwz0jdJKn3mPpSCAhnyTgDYsDt9s=; b=vRLNzW24aeS98cJexbJM+M4R+Mn9apIOepOvhp96T23WvAEWhqyZPnlvLnGQbO/Nm5S8t5 EUp24WHUPN16hDK4PFryDy4e3dE73i3bBfjL/9rB7NRA5gR9CJ9IqdZ6L6UxlyQ7lAzl7k h3ws22FxOOtLbeQuKIx65PpGV/2Fg8ptfj2oZlnosQzSaqnEc+h8vkHV9luXnBtOnF5pIj xrfLSxjJsWQHmRPALB3hL6CkfPtk/exd1y/JsIAQUYOPAeqJDra8AOMr8+DrVp7hDOCRfy z07/+syNRnYeWgyN44SFBOt7Q6N4/iGFGkbDg/e6rBMhIDznwCgpq2C//4PZnQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741509703; 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: references:references; bh=fFdeRnRhAOgqTfFMwz0jdJKn3mPpSCAhnyTgDYsDt9s=; b=jacMLK20w0fuI5BleSJ94pud3jGuvlqvXCP+V95Vl9nBUvF7MsKHG485jWD1RoFdzw643J nBQn83bXJkB64rCA== From: Thomas Gleixner To: LKML Cc: Marc Zyngier , Nishanth Menon , Tero Kristo , Santosh Shilimkar , Jon Mason , Dave Jiang , Allen Hubbe , ntb@lists.linux.dev, Bjorn Helgaas , linux-pci@vger.kernel.org, Haiyang Zhang , Wei Liu , linux-hyperv@vger.kernel.org, Wei Huang , Manivannan Sadhasivam , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org Subject: [patch 01/10] genirq/msi: Make a few functions static References: <20250309083453.900516105@linutronix.de> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Sun, 9 Mar 2025 09:41:42 +0100 (CET) None of these functions are used outside of the MSI core. Signed-off-by: Thomas Gleixner --- include/linux/msi.h | 5 ----- kernel/irq/msi.c | 40 +++++++--------------------------------- 2 files changed, 7 insertions(+), 38 deletions(-) --- a/include/linux/msi.h +++ b/include/linux/msi.h @@ -81,7 +81,6 @@ struct device_attribute; struct irq_domain; struct irq_affinity_desc; -void __get_cached_msi_msg(struct msi_desc *entry, struct msi_msg *msg); #ifdef CONFIG_GENERIC_MSI_IRQ void get_cached_msi_msg(unsigned int irq, struct msi_msg *msg); #else @@ -603,8 +602,6 @@ void msi_remove_device_irq_domain(struct bool msi_match_device_irq_domain(struct device *dev, unsigned int domid, enum irq_domain_bus_token bus_token); -int msi_domain_alloc_irqs_range_locked(struct device *dev, unsigned int domid, - unsigned int first, unsigned int last); int msi_domain_alloc_irqs_range(struct device *dev, unsigned int domid, unsigned int first, unsigned int last); int msi_domain_alloc_irqs_all_locked(struct device *dev, unsigned int domid, int nirqs); @@ -613,8 +610,6 @@ struct msi_map msi_domain_alloc_irq_at(s const struct irq_affinity_desc *affdesc, union msi_instance_cookie *cookie); -void msi_domain_free_irqs_range_locked(struct device *dev, unsigned int domid, - unsigned int first, unsigned int last); void msi_domain_free_irqs_range(struct device *dev, unsigned int domid, unsigned int first, unsigned int last); void msi_domain_free_irqs_all_locked(struct device *dev, unsigned int domid); --- a/kernel/irq/msi.c +++ b/kernel/irq/msi.c @@ -270,16 +270,11 @@ static int msi_domain_add_simple_msi_des return ret; } -void __get_cached_msi_msg(struct msi_desc *entry, struct msi_msg *msg) -{ - *msg = entry->msg; -} - void get_cached_msi_msg(unsigned int irq, struct msi_msg *msg) { struct msi_desc *entry = irq_get_msi_desc(irq); - __get_cached_msi_msg(entry, msg); + *msg = entry->msg; } EXPORT_SYMBOL_GPL(get_cached_msi_msg); @@ -1352,21 +1347,17 @@ static int msi_domain_alloc_locked(struc } /** - * msi_domain_alloc_irqs_range_locked - Allocate interrupts from a MSI interrupt domain + * msi_domain_alloc_irqs_range - Allocate interrupts from a MSI interrupt domain * @dev: Pointer to device struct of the device for which the interrupts * are allocated * @domid: Id of the interrupt domain to operate on * @first: First index to allocate (inclusive) * @last: Last index to allocate (inclusive) * - * Must be invoked from within a msi_lock_descs() / msi_unlock_descs() - * pair. Use this for MSI irqdomains which implement their own descriptor - * allocation/free. - * * Return: %0 on success or an error code. */ -int msi_domain_alloc_irqs_range_locked(struct device *dev, unsigned int domid, - unsigned int first, unsigned int last) +int msi_domain_alloc_irqs_range(struct device *dev, unsigned int domid, + unsigned int first, unsigned int last) { struct msi_ctrl ctrl = { .domid = domid, @@ -1374,27 +1365,10 @@ int msi_domain_alloc_irqs_range_locked(s .last = last, .nirqs = last + 1 - first, }; - - return msi_domain_alloc_locked(dev, &ctrl); -} - -/** - * msi_domain_alloc_irqs_range - Allocate interrupts from a MSI interrupt domain - * @dev: Pointer to device struct of the device for which the interrupts - * are allocated - * @domid: Id of the interrupt domain to operate on - * @first: First index to allocate (inclusive) - * @last: Last index to allocate (inclusive) - * - * Return: %0 on success or an error code. - */ -int msi_domain_alloc_irqs_range(struct device *dev, unsigned int domid, - unsigned int first, unsigned int last) -{ int ret; msi_lock_descs(dev); - ret = msi_domain_alloc_irqs_range_locked(dev, domid, first, last); + ret = msi_domain_alloc_locked(dev, &ctrl); msi_unlock_descs(dev); return ret; } @@ -1618,8 +1592,8 @@ static void msi_domain_free_locked(struc * @first: First index to free (inclusive) * @last: Last index to free (inclusive) */ -void msi_domain_free_irqs_range_locked(struct device *dev, unsigned int domid, - unsigned int first, unsigned int last) +static void msi_domain_free_irqs_range_locked(struct device *dev, unsigned int domid, + unsigned int first, unsigned int last) { struct msi_ctrl ctrl = { .domid = domid, From patchwork Sun Mar 9 08:41:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 872104 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 038707602D; Sun, 9 Mar 2025 08:41:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741509708; cv=none; b=MD6YEGR31KAeGFBk2uFt7iSqeTDTRR4RjXc1iB6JxpdwgU4dzXYcUYBB/Gs+CGH+5bhLML6208qEhLRqLbswJ2rVe8cWnPpHZgblZj4dI/1mER6NcwY9eb6zvsx0EFFX943g1UhB+KSebPSKWEZYJRuy1GeAPenjN2U293VMLdI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741509708; c=relaxed/simple; bh=yhTutmLbPuDD8e9KZsQhCeBQ50tI0xIMIrtFLbsE5uE=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=JQ6lxGbXBKyvYt45qX1AeAuPtD6RWllYtvNchzEz/sr1HnAi2lyLksSVfn2a887r5UjORjJsV8FrSNQXiHfyTXw3eh8TwQtXhiRWRYFJK9fhfpWJOJPHLQ2Y4yy65TsAFTv9mrgzgoymeoGJM/Pbm1moGtAtW48k6lN8KPqTBFo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=g30MpAv4; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=uxPbO57Y; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="g30MpAv4"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="uxPbO57Y" Message-ID: <20250309084110.267883135@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741509705; 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: references:references; bh=5HgbCO3GucDQ3f+ypesBfas/LZzcvGRvpju3GSWRDNo=; b=g30MpAv49hltvf1O8aqxFhvdsDTpygJGwVpHVz9uT4EN5+nzw2fy+eJ6SFyed65cLjQ5oP D7/OUvaaeK0Nfi9IjTBf0xdAu3KNvv6CSpkg54dfajRMwZm9eVuyeVDe18v1gpaut7tpNY ifstLDrR7+OrIl7s8/cqovfDmEyzWUadnM4EyxR5hLuhRy9OoJP6OD6hTG94febMLvoLHN bnAzXVMB8+4p6/+xVu11uYIaqUnMu7zJUUs8vUhDBWRlFI3HDowzmO3Dw3cR/Zs1n+BoOm jzqAKMiZmkHn/V90A9ACVEj7dXyEA/+TtlxWfhAa9YUko4u7/H7ejfv8rqHsoQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741509705; 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: references:references; bh=5HgbCO3GucDQ3f+ypesBfas/LZzcvGRvpju3GSWRDNo=; b=uxPbO57YJDZOyJ3+EZf70esTx6uaG70a5Tj7b7HTPQ+QAJ6dkYb1J4w0GI62Hdu+Zb8k1v f+aa4Xte2S7xp7Bg== From: Thomas Gleixner To: LKML Cc: Marc Zyngier , Nishanth Menon , Tero Kristo , Santosh Shilimkar , Jon Mason , Dave Jiang , Allen Hubbe , ntb@lists.linux.dev, Bjorn Helgaas , linux-pci@vger.kernel.org, Haiyang Zhang , Wei Liu , linux-hyperv@vger.kernel.org, Wei Huang , Manivannan Sadhasivam , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org Subject: [patch 02/10] genirq/msi: Use lock guards for MSI descriptor locking References: <20250309083453.900516105@linutronix.de> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Sun, 9 Mar 2025 09:41:44 +0100 (CET) Provide a lock guard for MSI descriptor locking and update the core code accordingly. No functional change intended. Signed-off-by: Thomas Gleixner --- include/linux/msi.h | 3 + kernel/irq/msi.c | 104 +++++++++++++++++++--------------------------------- 2 files changed, 42 insertions(+), 65 deletions(-) --- a/include/linux/msi.h +++ b/include/linux/msi.h @@ -227,6 +227,9 @@ int msi_setup_device_data(struct device void msi_lock_descs(struct device *dev); void msi_unlock_descs(struct device *dev); +DEFINE_LOCK_GUARD_1(msi_descs_lock, struct device, msi_lock_descs(_T->lock), + msi_unlock_descs(_T->lock)); + struct msi_desc *msi_domain_first_desc(struct device *dev, unsigned int domid, enum msi_desc_filter filter); --- a/kernel/irq/msi.c +++ b/kernel/irq/msi.c @@ -443,7 +443,6 @@ EXPORT_SYMBOL_GPL(msi_next_desc); unsigned int msi_domain_get_virq(struct device *dev, unsigned int domid, unsigned int index) { struct msi_desc *desc; - unsigned int ret = 0; bool pcimsi = false; struct xarray *xa; @@ -457,7 +456,7 @@ unsigned int msi_domain_get_virq(struct if (dev_is_pci(dev) && domid == MSI_DEFAULT_DOMAIN) pcimsi = to_pci_dev(dev)->msi_enabled; - msi_lock_descs(dev); + guard(msi_descs_lock)(dev); xa = &dev->msi.data->__domains[domid].store; desc = xa_load(xa, pcimsi ? 0 : index); if (desc && desc->irq) { @@ -466,16 +465,12 @@ unsigned int msi_domain_get_virq(struct * PCI-MSIX and platform MSI use a descriptor per * interrupt. */ - if (pcimsi) { - if (index < desc->nvec_used) - ret = desc->irq + index; - } else { - ret = desc->irq; - } + if (!pcimsi) + return desc->irq; + if (index < desc->nvec_used) + return desc->irq + index; } - - msi_unlock_descs(dev); - return ret; + return 0; } EXPORT_SYMBOL_GPL(msi_domain_get_virq); @@ -1037,25 +1032,23 @@ bool msi_create_device_irq_domain(struct if (msi_setup_device_data(dev)) goto free_fwnode; - msi_lock_descs(dev); - - if (WARN_ON_ONCE(msi_get_device_domain(dev, domid))) - goto fail; - - if (!pops->init_dev_msi_info(dev, parent, parent, &bundle->info)) - goto fail; - - domain = __msi_create_irq_domain(fwnode, &bundle->info, IRQ_DOMAIN_FLAG_MSI_DEVICE, parent); - if (!domain) - goto fail; - - domain->dev = dev; - dev->msi.data->__domains[domid].domain = domain; - msi_unlock_descs(dev); - return true; + scoped_guard(msi_descs_lock, dev) { + if (WARN_ON_ONCE(msi_get_device_domain(dev, domid))) + goto free_fwnode; + + if (!pops->init_dev_msi_info(dev, parent, parent, &bundle->info)) + goto free_fwnode; + + domain = __msi_create_irq_domain(fwnode, &bundle->info, IRQ_DOMAIN_FLAG_MSI_DEVICE, + parent); + if (!domain) + goto free_fwnode; + + domain->dev = dev; + dev->msi.data->__domains[domid].domain = domain; + return true; + } -fail: - msi_unlock_descs(dev); free_fwnode: irq_domain_free_fwnode(fwnalloced); free_bundle: @@ -1074,12 +1067,10 @@ void msi_remove_device_irq_domain(struct struct msi_domain_info *info; struct irq_domain *domain; - msi_lock_descs(dev); - + guard(msi_descs_lock)(dev); domain = msi_get_device_domain(dev, domid); - if (!domain || !irq_domain_is_msi_device(domain)) - goto unlock; + return; dev->msi.data->__domains[domid].domain = NULL; info = domain->host_data; @@ -1088,9 +1079,6 @@ void msi_remove_device_irq_domain(struct irq_domain_remove(domain); irq_domain_free_fwnode(fwnode); kfree(container_of(info, struct msi_domain_template, info)); - -unlock: - msi_unlock_descs(dev); } /** @@ -1106,16 +1094,14 @@ bool msi_match_device_irq_domain(struct { struct msi_domain_info *info; struct irq_domain *domain; - bool ret = false; - msi_lock_descs(dev); + guard(msi_descs_lock)(dev); domain = msi_get_device_domain(dev, domid); if (domain && irq_domain_is_msi_device(domain)) { info = domain->host_data; - ret = info->bus_token == bus_token; + return info->bus_token == bus_token; } - msi_unlock_descs(dev); - return ret; + return false; } static int msi_domain_prepare_irqs(struct irq_domain *domain, struct device *dev, @@ -1365,12 +1351,9 @@ int msi_domain_alloc_irqs_range(struct d .last = last, .nirqs = last + 1 - first, }; - int ret; - msi_lock_descs(dev); - ret = msi_domain_alloc_locked(dev, &ctrl); - msi_unlock_descs(dev); - return ret; + guard(msi_descs_lock)(dev); + return msi_domain_alloc_locked(dev, &ctrl); } EXPORT_SYMBOL_GPL(msi_domain_alloc_irqs_range); @@ -1474,12 +1457,8 @@ struct msi_map msi_domain_alloc_irq_at(s const struct irq_affinity_desc *affdesc, union msi_instance_cookie *icookie) { - struct msi_map map; - - msi_lock_descs(dev); - map = __msi_domain_alloc_irq_at(dev, domid, index, affdesc, icookie); - msi_unlock_descs(dev); - return map; + guard(msi_descs_lock)(dev); + return __msi_domain_alloc_irq_at(dev, domid, index, affdesc, icookie); } /** @@ -1516,13 +1495,11 @@ int msi_device_domain_alloc_wired(struct icookie.value = ((u64)type << 32) | hwirq; - msi_lock_descs(dev); + guard(msi_descs_lock)(dev); if (WARN_ON_ONCE(msi_get_device_domain(dev, domid) != domain)) map.index = -EINVAL; else map = __msi_domain_alloc_irq_at(dev, domid, MSI_ANY_INDEX, NULL, &icookie); - msi_unlock_descs(dev); - return map.index >= 0 ? map.virq : map.index; } @@ -1615,9 +1592,8 @@ static void msi_domain_free_irqs_range_l void msi_domain_free_irqs_range(struct device *dev, unsigned int domid, unsigned int first, unsigned int last) { - msi_lock_descs(dev); + guard(msi_descs_lock)(dev); msi_domain_free_irqs_range_locked(dev, domid, first, last); - msi_unlock_descs(dev); } EXPORT_SYMBOL_GPL(msi_domain_free_irqs_all); @@ -1647,9 +1623,8 @@ void msi_domain_free_irqs_all_locked(str */ void msi_domain_free_irqs_all(struct device *dev, unsigned int domid) { - msi_lock_descs(dev); + guard(msi_descs_lock)(dev); msi_domain_free_irqs_all_locked(dev, domid); - msi_unlock_descs(dev); } /** @@ -1668,12 +1643,11 @@ void msi_device_domain_free_wired(struct if (WARN_ON_ONCE(!dev || !desc || domain->bus_token != DOMAIN_BUS_WIRED_TO_MSI)) return; - msi_lock_descs(dev); - if (!WARN_ON_ONCE(msi_get_device_domain(dev, MSI_DEFAULT_DOMAIN) != domain)) { - msi_domain_free_irqs_range_locked(dev, MSI_DEFAULT_DOMAIN, desc->msi_index, - desc->msi_index); - } - msi_unlock_descs(dev); + guard(msi_descs_lock)(dev); + if (WARN_ON_ONCE(msi_get_device_domain(dev, MSI_DEFAULT_DOMAIN) != domain)) + return; + msi_domain_free_irqs_range_locked(dev, MSI_DEFAULT_DOMAIN, desc->msi_index, + desc->msi_index); } /** From patchwork Sun Mar 9 08:41:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 872780 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 69AA719259F; Sun, 9 Mar 2025 08:41:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741509709; cv=none; b=rYNaQZ7WZq5OYmMNbuYf0avko51dYvhQsdp375+I8UiKHN2hwLhi+dzS5MRjHLPs14bg1fPH/Cq8D3kPQUCH5q5ipWdd6p9QRSjCSQ4xj9qUiAanPpGYpFWK9//PBCMexNbsuLt8N+1szn4up/Exzk6BY6ggiYkicuhQ9G6pUuo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741509709; c=relaxed/simple; bh=9tEtHFlJqE1o/MEINhiPD+GOmg1b1ALbpAOx4KFy+Sc=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=aXHs1u+9136L0beIvr79i11d9830YDqXJZxLDWFH8sZxjiU6ZY5sAWi3ZNKKgXYdn4ZG3njofp2X6i/FBno2Kay8NIhk8piihD2P0j71QxoLf6a31g03ENu1OPncB+rrRdSmbSMyFoyXuj9jCuYvukH5j7SRG07ExKvf/bdmVLs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=BrtQOnIK; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=0g6rJL9x; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="BrtQOnIK"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="0g6rJL9x" Message-ID: <20250309084110.330984023@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741509706; 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: references:references; bh=IiWbXtUeXooyeuJFwLf7yOIiWovf7ZPuVakAtiZcres=; b=BrtQOnIKYAJunATsXri4JzRzur6rakZw2kbALlr6ENNZp0zIxRgb5VWBvusyJE5JNrz0MM TudKe9G4/rZbycUNV1p65bSLEtPvACDRRgADscQznczRaXvas5LJtRSDZrN/5+kqnK6wW6 4wLY1ekEC4DWY4PnDt4CIrb08dE2P2t0XL+DfArlEsbgabGiwsTaT5IkjQXTUHF7C8X8gF +c3Wx+px9wssYP3HGBhVKCoJ24p7x6aTfFky41t7+aaPaNIfz14xgqFlP1/huyjfXZcZQG /Y4OpbdyLJ76pgSq9NKe2BkEHogPR7nJirrJ3nuukPjb8gbL3IzHNHPv5Jv1gw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741509706; 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: references:references; bh=IiWbXtUeXooyeuJFwLf7yOIiWovf7ZPuVakAtiZcres=; b=0g6rJL9xuERtADBm6475N2QyTn187OBtIxEGr6ib8mm4NkN7c+xU5SQo6EYiyGRkwsWPxB BkKdNL8YCXipvrAg== From: Thomas Gleixner To: LKML Cc: Marc Zyngier , Nishanth Menon , Tero Kristo , Santosh Shilimkar , Jon Mason , Dave Jiang , Allen Hubbe , ntb@lists.linux.dev, Bjorn Helgaas , linux-pci@vger.kernel.org, Haiyang Zhang , Wei Liu , linux-hyperv@vger.kernel.org, Wei Huang , Manivannan Sadhasivam , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org Subject: [patch 03/10] soc: ti: ti_sci_inta_msi: Switch MSI descriptor locking to guard() References: <20250309083453.900516105@linutronix.de> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Sun, 9 Mar 2025 09:41:46 +0100 (CET) Convert the code to use the new guard(msi_descs_lock). No functional change intended. Signed-off-by: Thomas Gleixner Cc: Nishanth Menon Cc: Tero Kristo Cc: Santosh Shilimkar --- drivers/soc/ti/ti_sci_inta_msi.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) --- a/drivers/soc/ti/ti_sci_inta_msi.c +++ b/drivers/soc/ti/ti_sci_inta_msi.c @@ -103,19 +103,15 @@ int ti_sci_inta_msi_domain_alloc_irqs(st if (ret) return ret; - msi_lock_descs(dev); + guard(msi_descs_lock)(dev); nvec = ti_sci_inta_msi_alloc_descs(dev, res); - if (nvec <= 0) { - ret = nvec; - goto unlock; - } + if (nvec <= 0) + return nvec; /* Use alloc ALL as it's unclear whether there are gaps in the indices */ ret = msi_domain_alloc_irqs_all_locked(dev, MSI_DEFAULT_DOMAIN, nvec); if (ret) dev_err(dev, "Failed to allocate IRQs %d\n", ret); -unlock: - msi_unlock_descs(dev); return ret; } EXPORT_SYMBOL_GPL(ti_sci_inta_msi_domain_alloc_irqs); From patchwork Sun Mar 9 08:41:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 872103 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 191CC1991CA; Sun, 9 Mar 2025 08:41:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741509711; cv=none; b=GU6QViRzRNrzkDSHw2dirrcy4GsSZhHk5iEkJXloIqBuwDoV0/25/ansXXyW20IlmJn/DGPjD3OtWj50iWJjwvw96jsbdXdZxoQTfFf6tK1p/LfyZGIotQ5ObxrDTfotEOrDucbH62CAqquh0iMyOq2R8C87DDMevPqqLWYEi+4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741509711; c=relaxed/simple; bh=+nP7eP6u8+unwJo2Ta244xNpgGRfZY4L4xYimrXTSHk=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=npdGnkHi+eMgHT+zV1nyQZE+5WDhb9fxH//bzukIHVzLzElhVE7TxhfBsOohr+nvIZMTzE/rEqFybeP494kV+30F/iy5SrRbpOZZ0oXWMptekyYZ2iSmnrlyMGYJOEG/lgIc5yj1mrzLuDBgj4f0bRUYdIdV9QIGv+h+CI2FYI4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=bfi+HSmu; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ykUCCtEe; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="bfi+HSmu"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ykUCCtEe" Message-ID: <20250309084110.394142327@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741509708; 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: references:references; bh=2Dbb0NJg9q7mf2SMbVQRSf39fkQi4mCO/oJygH7cKIA=; b=bfi+HSmuLMVZOrItd8U/XNpRymRRtOknOMYGqASLZsL6TC+eCkKv6Ek3fwX482iWUl1F6h 1yPo5cLnNSlsBM6zj5pzzzq1gCPO5eY8QA0u6HuLky+8J0FFTH2+PwFisK8bSxE3dlIz2t k71w6aBFI699T1VHP27O055Sy9HF5BxPHsW/AU7hcHTCD9uDVfkRKzFj+Lxn7JKy7mKeM0 nM6hOi2uCxlkX43WbHCP4EuGMY/JgjZhjTBH26uSUwBAqh8XFVt2kGmOCuYAAuR+214hze W1xhI9gwUAGpLks4yvt6Nc3inyj3o6qDYm7AMOV8yWu7y13eBHV4B+QLMGLRjA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741509708; 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: references:references; bh=2Dbb0NJg9q7mf2SMbVQRSf39fkQi4mCO/oJygH7cKIA=; b=ykUCCtEeVl3qZ/zFxc0YkYwXZgmyPG0vJjLKbGWVhfUb95jQetBHEJH46hQzHPTC+I0+GX e+OWsd+zwIQVw/Bg== From: Thomas Gleixner To: LKML Cc: Marc Zyngier , Jon Mason , Dave Jiang , Allen Hubbe , ntb@lists.linux.dev, Nishanth Menon , Tero Kristo , Santosh Shilimkar , Bjorn Helgaas , linux-pci@vger.kernel.org, Haiyang Zhang , Wei Liu , linux-hyperv@vger.kernel.org, Wei Huang , Manivannan Sadhasivam , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org Subject: [patch 04/10] NTB/msi: Switch MSI descriptor locking to lock guard() References: <20250309083453.900516105@linutronix.de> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Sun, 9 Mar 2025 09:41:48 +0100 (CET) Convert the code to use the new guard(msi_descs_lock). No functional change intended. Signed-off-by: Thomas Gleixner Cc: Jon Mason Cc: Dave Jiang Cc: Allen Hubbe Cc: ntb@lists.linux.dev Acked-by: Dave Jiang Reviewed-by: Logan Gunthorpe --- drivers/ntb/msi.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) --- a/drivers/ntb/msi.c +++ b/drivers/ntb/msi.c @@ -106,10 +106,10 @@ int ntb_msi_setup_mws(struct ntb_dev *nt if (!ntb->msi) return -EINVAL; - msi_lock_descs(&ntb->pdev->dev); - desc = msi_first_desc(&ntb->pdev->dev, MSI_DESC_ASSOCIATED); - addr = desc->msg.address_lo + ((uint64_t)desc->msg.address_hi << 32); - msi_unlock_descs(&ntb->pdev->dev); + scoped_guard (msi_descs_lock, &ntb->pdev->dev) { + desc = msi_first_desc(&ntb->pdev->dev, MSI_DESC_ASSOCIATED); + addr = desc->msg.address_lo + ((uint64_t)desc->msg.address_hi << 32); + } for (peer = 0; peer < ntb_peer_port_count(ntb); peer++) { peer_widx = ntb_peer_highest_mw_idx(ntb, peer); @@ -289,7 +289,7 @@ int ntbm_msi_request_threaded_irq(struct if (!ntb->msi) return -EINVAL; - msi_lock_descs(dev); + guard(msi_descs_lock)(dev); msi_for_each_desc(entry, dev, MSI_DESC_ASSOCIATED) { if (irq_has_action(entry->irq)) continue; @@ -307,17 +307,11 @@ int ntbm_msi_request_threaded_irq(struct ret = ntbm_msi_setup_callback(ntb, entry, msi_desc); if (ret) { devm_free_irq(&ntb->dev, entry->irq, dev_id); - goto unlock; + return ret; } - - ret = entry->irq; - goto unlock; + return entry->irq; } - ret = -ENODEV; - -unlock: - msi_unlock_descs(dev); - return ret; + return -ENODEV; } EXPORT_SYMBOL(ntbm_msi_request_threaded_irq); From patchwork Sun Mar 9 08:41:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 872779 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CDB471ABED7; Sun, 9 Mar 2025 08:41:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741509713; cv=none; b=Qx8HVU8e+AylBU3xciTSyAwPwjZOSjJ12idu4Zw8gxvxxqXv2nxaVA12KHFFqE42SOXG3GnMmaQJ7eGT1EHM+OXNUDH/iJLER0VskY/8olufLoNa0J12V7j1ZCNw4hpi5kNqv7JEtkWvAlS3oVnSIFgM+epD4VK6AtRo2G1yXoU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741509713; c=relaxed/simple; bh=t73ZIS0zDQ92hXUrOpkUBInvZr9WcsjDhaQgNkUS2JI=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=PP5sDRVNXJZQC/T/dQA7hGch1m6AafPEg6rWU8Q1CKt6AdUSBD4Lgz91nOhYDrJZJQijJeSazjaFy3+RrZrD8edBIN/UyFYzzXgUmdULVn7ksNXJp5XWIRyiVUpvK/kb9JoPy4IPrNWUaEYLRQLciNTT7YybimnrUoALjJZ1xuE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=CGP7fktP; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=w6pJqxYI; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="CGP7fktP"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="w6pJqxYI" Message-ID: <20250309084110.458224773@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741509710; 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: references:references; bh=hMPRSE2yqluKJvNyKUEzx8EXim9v5XNoKvqZd87YCug=; b=CGP7fktPRgXbVx8YfCdZwmahOqAPWuPufE/0GhS/GAP6MqzZtpD0Xng5rdOOOnDgqAwh23 2zNd1vJ/Jr73/ha+sofhlHAhZOEIAyL/n97Xhh/u+PLm4j8vTLt22tuNyMR8jAm+TK7DTL YHJu5Il0dOIrNIgSrBHv3BK4kmV3/jm0iOvQC0vyJqq/KIhvaBQIbXm1H4HDTKp7icq/Sr CzVrSRcY6IQN+ueaxznA4o5VljIkaFwNOBt1nSlvzsXG9S7DfJqCXcWFsW0ddeREln0NE1 RdnX8oc7UW8sBMQaulDlEXqm52uAexuFKMoUHVtJ/OBAl0wFy5JxZ0nPIzuzMQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741509710; 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: references:references; bh=hMPRSE2yqluKJvNyKUEzx8EXim9v5XNoKvqZd87YCug=; b=w6pJqxYIYl9SGBEVVmmqHGtzrMTqpswDtAYu7XKFhv8Heog9scrCRKtdGlVEUM6WkuJSJd RwzmopPSKvAVRHDA== From: Thomas Gleixner To: LKML Cc: Marc Zyngier , Bjorn Helgaas , linux-pci@vger.kernel.org, Nishanth Menon , Tero Kristo , Santosh Shilimkar , Jon Mason , Dave Jiang , Allen Hubbe , ntb@lists.linux.dev, Haiyang Zhang , Wei Liu , linux-hyperv@vger.kernel.org, Wei Huang , Manivannan Sadhasivam , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org Subject: [patch 05/10] PCI/MSI: Switch to MSI descriptor locking to guard() References: <20250309083453.900516105@linutronix.de> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Sun, 9 Mar 2025 09:41:49 +0100 (CET) Convert the code to use the new guard(msi_descs_lock). No functional change intended. Signed-off-by: Thomas Gleixner Cc: Bjorn Helgaas Cc: linux-pci@vger.kernel.org --- drivers/pci/msi/api.c | 6 ++---- drivers/pci/msi/msi.c | 30 ++++++++++++------------------ 2 files changed, 14 insertions(+), 22 deletions(-) --- a/drivers/pci/msi/api.c +++ b/drivers/pci/msi/api.c @@ -53,10 +53,9 @@ void pci_disable_msi(struct pci_dev *dev if (!pci_msi_enabled() || !dev || !dev->msi_enabled) return; - msi_lock_descs(&dev->dev); + guard(msi_descs_lock)(&dev->dev); pci_msi_shutdown(dev); pci_free_msi_irqs(dev); - msi_unlock_descs(&dev->dev); } EXPORT_SYMBOL(pci_disable_msi); @@ -196,10 +195,9 @@ void pci_disable_msix(struct pci_dev *de if (!pci_msi_enabled() || !dev || !dev->msix_enabled) return; - msi_lock_descs(&dev->dev); + guard(msi_descs_lock)(&dev->dev); pci_msix_shutdown(dev); pci_free_msi_irqs(dev); - msi_unlock_descs(&dev->dev); } EXPORT_SYMBOL(pci_disable_msix); --- a/drivers/pci/msi/msi.c +++ b/drivers/pci/msi/msi.c @@ -351,7 +351,7 @@ static int msi_verify_entries(struct pci static int msi_capability_init(struct pci_dev *dev, int nvec, struct irq_affinity *affd) { - struct irq_affinity_desc *masks = NULL; + struct irq_affinity_desc *masks __free(kfree) = NULL; struct msi_desc *entry, desc; int ret; @@ -369,7 +369,7 @@ static int msi_capability_init(struct pc if (affd) masks = irq_create_affinity_masks(nvec, affd); - msi_lock_descs(&dev->dev); + guard(msi_descs_lock)(&dev->dev); ret = msi_setup_msi_desc(dev, nvec, masks); if (ret) goto fail; @@ -399,16 +399,13 @@ static int msi_capability_init(struct pc pcibios_free_irq(dev); dev->irq = entry->irq; - goto unlock; + return 0; err: pci_msi_unmask(&desc, msi_multi_mask(&desc)); pci_free_msi_irqs(dev); fail: dev->msi_enabled = 0; -unlock: - msi_unlock_descs(&dev->dev); - kfree(masks); return ret; } @@ -669,13 +666,13 @@ static void msix_mask_all(void __iomem * static int msix_setup_interrupts(struct pci_dev *dev, struct msix_entry *entries, int nvec, struct irq_affinity *affd) { - struct irq_affinity_desc *masks = NULL; + struct irq_affinity_desc *masks __free(kfree) = NULL; int ret; if (affd) masks = irq_create_affinity_masks(nvec, affd); - msi_lock_descs(&dev->dev); + guard(msi_descs_lock)(&dev->dev); ret = msix_setup_msi_descs(dev, entries, nvec, masks); if (ret) goto out_free; @@ -690,13 +687,10 @@ static int msix_setup_interrupts(struct goto out_free; msix_update_entries(dev, entries); - goto out_unlock; + return 0; out_free: pci_free_msi_irqs(dev); -out_unlock: - msi_unlock_descs(&dev->dev); - kfree(masks); return ret; } @@ -871,13 +865,13 @@ void __pci_restore_msix_state(struct pci write_msg = arch_restore_msi_irqs(dev); - msi_lock_descs(&dev->dev); - msi_for_each_desc(entry, &dev->dev, MSI_DESC_ALL) { - if (write_msg) - __pci_write_msi_msg(entry, &entry->msg); - pci_msix_write_vector_ctrl(entry, entry->pci.msix_ctrl); + scoped_guard (msi_descs_lock, &dev->dev) { + msi_for_each_desc(entry, &dev->dev, MSI_DESC_ALL) { + if (write_msg) + __pci_write_msi_msg(entry, &entry->msg); + pci_msix_write_vector_ctrl(entry, entry->pci.msix_ctrl); + } } - msi_unlock_descs(&dev->dev); pci_msix_clear_and_set_ctrl(dev, PCI_MSIX_FLAGS_MASKALL, 0); } From patchwork Sun Mar 9 08:41:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 872102 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CAADD1AF0C0; Sun, 9 Mar 2025 08:41:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741509715; cv=none; b=KCwOTg1TDGnFB/ICXWVyYh7oWO1o0L+AtR7v9Uv5Qy5lwBbFUNnm9JhXiCt0h0nkO+yDE/RngCgGfPzwKv0SYSIJcXX6QL5TFOA1TW7Wxn/Ir9f0vukk4XH1FAR+bGAfvKW/GsPNu9T5PO1WJJwZF2fBgHGR5VxO2RMbTorCjQo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741509715; c=relaxed/simple; bh=cmacTxXIxce5OuCOlsFeMKlTtcskqKZQBd5w4CspMG8=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=M3JXv9sMUXB8gRjAOhAZErBdKGD9fxUBUHMjXAja8w96XpTYO5SK88Yeb2DHpMZXHQ6cXvahCIaZdtlsyYrUViMMV8g7W+nI+8fFreoBEAlaVr/QvP3h9ZxPKc2UoDxhxxdv8e2NFVbIku8w9yODzxT9fO+PPHFdu5H9fpWDJdk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=K2YtWH0a; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=+V1semF3; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="K2YtWH0a"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="+V1semF3" Message-ID: <20250309084110.521468021@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741509712; 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: references:references; bh=orv27tW3w4e5gK89wOdnKXG8n73hJW7aZdj9rhy7feg=; b=K2YtWH0a4l+FQiItA7EWn9vQ8BmUgGpW9GgnLLsG7Ge0el1FPT+aFS4WbjfJRR09H4jqwa BZh49etMSqqHMW3C2mLlpGIt91iqNvGWFS6PBtp5gC9tq93M2z6tqz7bRi6/fombnAxpON 0Zv6d6Wsulr6J9bwES9NF10PmCVS1qijcyP9PRJg3rPDxIjVrHAgHwTRLzUX1dpiFwd5xr fig+ldA2rmmPp/zDn8PrxB+0Tt45RYknA7jRV9DqZA8Ayj+VmSQewIRaQQlcuuvhOk1PQG vG32ed/TxJU4hh6khEDrNQ2k+rZRd0/J57VfD0wtM4TMdpOoif3nlz/ANTy5HQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741509712; 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: references:references; bh=orv27tW3w4e5gK89wOdnKXG8n73hJW7aZdj9rhy7feg=; b=+V1semF33MS8lCzLlGKkqy2+J7ifQfxoM0OqN2kWXuIrVrxHCl2aQhamUsLy4eUkbgawVh vik9ycw1n1h/YHAA== From: Thomas Gleixner To: LKML Cc: Marc Zyngier , Haiyang Zhang , Wei Liu , Bjorn Helgaas , linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, Nishanth Menon , Tero Kristo , Santosh Shilimkar , Jon Mason , Dave Jiang , Allen Hubbe , ntb@lists.linux.dev, Wei Huang , Manivannan Sadhasivam , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org Subject: [patch 06/10] PCI: hv: Switch MSI descriptor locking to guard() References: <20250309083453.900516105@linutronix.de> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Sun, 9 Mar 2025 09:41:51 +0100 (CET) Convert the code to use the new guard(msi_descs_lock). No functional change intended. Signed-off-by: Thomas Gleixner Cc: Haiyang Zhang Cc: Wei Liu Cc: Bjorn Helgaas Cc: linux-hyperv@vger.kernel.org Cc: linux-pci@vger.kernel.org Acked-by: Wei Liu Reviewed-by: Michael Kelley --- drivers/pci/controller/pci-hyperv.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -3976,24 +3976,18 @@ static int hv_pci_restore_msi_msg(struct { struct irq_data *irq_data; struct msi_desc *entry; - int ret = 0; if (!pdev->msi_enabled && !pdev->msix_enabled) return 0; - msi_lock_descs(&pdev->dev); + guard(msi_descs_lock)(&pdev->dev); msi_for_each_desc(entry, &pdev->dev, MSI_DESC_ASSOCIATED) { irq_data = irq_get_irq_data(entry->irq); - if (WARN_ON_ONCE(!irq_data)) { - ret = -EINVAL; - break; - } - + if (WARN_ON_ONCE(!irq_data)) + return -EINVAL; hv_compose_msi_msg(irq_data, &entry->msg); } - msi_unlock_descs(&pdev->dev); - - return ret; + return 0; } /* From patchwork Sun Mar 9 08:41:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 872778 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F6541B0F16; Sun, 9 Mar 2025 08:41:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741509717; cv=none; b=NVZwowTk+nNbkPxqbTRGVYZ8R5aI+GydXstD7y7hyWIEnA/ERoxd6NX45tGl5rKsG602W7x5f4kEu+/9VjKs866en2OLWfFVjbMCi4uHRG9pQ0raFFX+/lyGJC1K1gVJ5cOGm8AygwCCfkKdZkDFKJR9lz9Hr79smKG+LRqCfMc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741509717; c=relaxed/simple; bh=1HS7obeYKb42uw1IraPsN9L3DRfMjADODhtzMqrMiwM=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=CYA5xq8u8MHDqDLByU2VpjypIROM2l/bHy8o5/u+FY4o9ent0w0jB3sEM0reI4curSUB+ensrIJdsU0fJyEU+ILB4toSzQQ8eBxsFYvFND5tyeqKaJtboCHaLr0FuWxyQbfCy8qshAXaQ1Ktg1qEAprIhbMOqtTZrLs9PxDyYi4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=13JkA35W; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=HcA4OL9y; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="13JkA35W"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="HcA4OL9y" Message-ID: <20250309084110.584867364@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741509713; 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: references:references; bh=0qmkifLEMtx3Jy85H4q3Dgu6t8Utbc3eUX1wCcoYGzQ=; b=13JkA35W9MvGhNq3JF4ktAccWEDwqiIwdA0iigLvldNlsSFyhSE1kzkm6EcMKIeriMXuNp G5xQdSK1E7vSMYSe1oq4I+bFcdKIFR+FEsAc0qF6woy95DlVxqWj0bEZ+a+J7kubFazKcG 3IIajm3dPNVKam0afs23lQTkWoC/vZ9wu/y3gaRXN9dAUtEqgqHEZg9piPRY1dTGkmSVfh bwr4nnPofhy0FS/9spMXm2NMTHnPGOlA6jQvsgbMD9Mg9BVXldcCxz2wc0cENCAaoX9fWr zmMm8PGGISmhO3ABZZ/G+0ZvKdQxPLjvoJxRClTl/V2oMYX0XgoaamvXed9DZA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741509713; 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: references:references; bh=0qmkifLEMtx3Jy85H4q3Dgu6t8Utbc3eUX1wCcoYGzQ=; b=HcA4OL9y+8wbG550PPnhwe0RGfY+yMShbqDAWDOweFwmW4lbB4B6DolTo2K3jFd43dMtMf ERQq8+TwWZeulWBQ== From: Thomas Gleixner To: LKML Cc: Marc Zyngier , Bjorn Helgaas , Wei Huang , linux-pci@vger.kernel.org, Nishanth Menon , Tero Kristo , Santosh Shilimkar , Jon Mason , Dave Jiang , Allen Hubbe , ntb@lists.linux.dev, Haiyang Zhang , Wei Liu , linux-hyperv@vger.kernel.org, Manivannan Sadhasivam , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org Subject: [patch 07/10] PCI/MSI: Provide a sane mechanism for TPH References: <20250309083453.900516105@linutronix.de> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Sun, 9 Mar 2025 09:41:53 +0100 (CET) The PCI/TPH driver fiddles with the MSI-X control word of an active interrupt completely unserialized against concurrent operations issued from the interrupt core. It also brings the PCI/MSI-X internal cached control word out of sync. Provide a function, which has the required serialization and keeps the control word cache in sync. Unfortunately this requires to look up and lock the interrupt descriptor, which should be only done in the interrupt core code. But confining this particular oddity in the PCI/MSI core is the lesser of all evil. A interrupt core implementation would require a larger pile of infrastructure and indirections for dubious value. Signed-off-by: Thomas Gleixner Cc: Bjorn Helgaas Cc: Wei Huang Cc: linux-pci@vger.kernel.org --- drivers/pci/msi/msi.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/pci/pci.h | 9 +++++++++ 2 files changed, 56 insertions(+) --- a/drivers/pci/msi/msi.c +++ b/drivers/pci/msi/msi.c @@ -910,6 +910,53 @@ void pci_free_msi_irqs(struct pci_dev *d } } +#ifdef CONFIG_PCIE_TPH +/** + * pci_msix_write_tph_tag - Update the TPH tag for a given MSI-X vector + * @pdev: The PCIe device to update + * @index: The MSI-X index to update + * @tag: The tag to write + * + * Returns: 0 on success, error code on failure + */ +int pci_msix_write_tph_tag(struct pci_dev *pdev, unsigned int index, u16 tag) +{ + struct msi_desc *msi_desc; + struct irq_desc *irq_desc; + unsigned int virq; + + if (!pdev->msix_enabled) + return -ENXIO; + + guard(msi_descs_lock)(&pdev->dev); + virq = msi_get_virq(&pdev->dev, index); + if (!virq) + return -ENXIO; + /* + * This is a horrible hack, but short of implementing a PCI + * specific interrupt chip callback and a huge pile of + * infrastructure, this is the minor nuissance. It provides the + * protection against concurrent operations on this entry and keeps + * the control word cache in sync. + */ + irq_desc = irq_to_desc(virq); + if (!irq_desc) + return -ENXIO; + + guard(raw_spinlock_irq)(&irq_desc->lock); + msi_desc = irq_data_get_msi_desc(&irq_desc->irq_data); + if (!msi_desc || msi_desc->pci.msi_attrib.is_virtual) + return -ENXIO; + + msi_desc->pci.msix_ctrl &= ~PCI_MSIX_ENTRY_CTRL_ST; + msi_desc->pci.msix_ctrl |= FIELD_PREP(PCI_MSIX_ENTRY_CTRL_ST, tag); + pci_msix_write_vector_ctrl(msi_desc, msi_desc->pci.msix_ctrl); + /* Flush the write */ + readl(pci_msix_desc_addr(msi_desc)); + return 0; +} +#endif + /* Misc. infrastructure */ struct pci_dev *msi_desc_to_pci_dev(struct msi_desc *desc) --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -989,6 +989,15 @@ int pcim_request_region_exclusive(struct const char *name); void pcim_release_region(struct pci_dev *pdev, int bar); +#ifdef CONFIG_PCI_MSI +int pci_msix_write_tph_tag(struct pci_dev *pdev, unsigned int index, u16 tag); +#else +static inline int pci_msix_write_tph_tag(struct pci_dev *pdev, unsigned int index, u16 tag) +{ + return -ENODEV; +} +#endif + /* * Config Address for PCI Configuration Mechanism #1 * From patchwork Sun Mar 9 08:41:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 872101 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B992A192B71; Sun, 9 Mar 2025 08:41:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741509719; cv=none; b=Zb8ptpbtIFaVFXtbY/OD1scfVKIrh2spHvdNc/AlgIX8iABSHvtdh/+1Vuvr+aGGoF0XYUED829M5BPahlsZqGNQEIbFinv1h/e11wah2LcfqKEWUH0R8cnfSMD3RyNGwxOFBtY6+242UULgUjOQryLkGifmsUpoywuo3Mm409E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741509719; c=relaxed/simple; bh=5l7R6AdaqwRlGif5tU/xFQ/s9Ah8K7qa8CaWg309ca4=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=b/ZXUTX4xIBSRFYzBW4sYG2bwpbmd20G6FR9tt3edaRpeMuiy68sJ6fyt3FWU82De0cceg4BZDMyYWjs6+kxnxfBtMSUt6qQKi4PaKbiGgFySDWveZZaTJ1L1g/d6wyQ16JavS8maUlL5I5n0/Id6/UQKws0O7eayRyLgF/P6BM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=zCtQYWDN; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=bwhxlZzz; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="zCtQYWDN"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="bwhxlZzz" Message-ID: <20250309084110.648079737@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741509715; 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: references:references; bh=g042MrY1rHTcKBvw/cHhhjvItHiESxmK6Esu9o+YXlg=; b=zCtQYWDN7JpNg5tYfD+QYQgq5ZDZItLGDIRB5/t33mmDB1zXLa/rqpvjYrNwYSitaqcyFl 1JA/dH89iehlJyh3RrPjEwH4M2vQKjRX9ZTxoVZMQwQGO06wP23NwICGyLCyKYgFwiqH4S 7KniY+xnatIqXw/g8kx18AaZUU+whlNeWzme7OvRWJch15DLygGpqqHx83NlflyN+roKGc YtdZf9pDT1N2C6iJVCvX5fMZI4H889viOMXv48F84P34TZI9wUUknMVPMCE6X8n89bWEoY AUo3mQG6OHw703SddnakYTrMueteeDfDedY6tQNMSRftmGNH1E/on9zaPlN1DA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741509715; 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: references:references; bh=g042MrY1rHTcKBvw/cHhhjvItHiESxmK6Esu9o+YXlg=; b=bwhxlZzzlCxewlkNn2cRYMP6ONLol6B1H7iDXEKBMjO88mjhkHxKfcjZ27zDPpuwpOggLt 81O92heUwlnKXzCA== From: Thomas Gleixner To: LKML Cc: Marc Zyngier , Bjorn Helgaas , Wei Huang , linux-pci@vger.kernel.org, Nishanth Menon , Tero Kristo , Santosh Shilimkar , Jon Mason , Dave Jiang , Allen Hubbe , ntb@lists.linux.dev, Haiyang Zhang , Wei Liu , linux-hyperv@vger.kernel.org, Manivannan Sadhasivam , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org Subject: [patch 08/10] PCI/TPH: Replace the broken MSI-X control word update References: <20250309083453.900516105@linutronix.de> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Sun, 9 Mar 2025 09:41:54 +0100 (CET) The driver walks the MSI descriptors to test whether a descriptor exists for a given index. That's just abuse of the MSI internals. The same test can be done with a single function call by looking up whether there is a Linux interrupt number assigned at the index. What's worse is that the function is completely unserialized against modifications of the MSI-X control by operations issued from the interrupt core. It also brings the PCI/MSI-X internal cached control word out of sync. Remove the trainwreck and invoke the function provided by the PCI/MSI core to update it. Signed-off-by: Thomas Gleixner Cc: Bjorn Helgaas Cc: Wei Huang Cc: linux-pci@vger.kernel.org --- drivers/pci/tph.c | 44 +------------------------------------------- 1 file changed, 1 insertion(+), 43 deletions(-) --- a/drivers/pci/tph.c +++ b/drivers/pci/tph.c @@ -204,48 +204,6 @@ static u8 get_rp_completer_type(struct p return FIELD_GET(PCI_EXP_DEVCAP2_TPH_COMP_MASK, reg); } -/* Write ST to MSI-X vector control reg - Return 0 if OK, otherwise -errno */ -static int write_tag_to_msix(struct pci_dev *pdev, int msix_idx, u16 tag) -{ -#ifdef CONFIG_PCI_MSI - struct msi_desc *msi_desc = NULL; - void __iomem *vec_ctrl; - u32 val; - int err = 0; - - msi_lock_descs(&pdev->dev); - - /* Find the msi_desc entry with matching msix_idx */ - msi_for_each_desc(msi_desc, &pdev->dev, MSI_DESC_ASSOCIATED) { - if (msi_desc->msi_index == msix_idx) - break; - } - - if (!msi_desc) { - err = -ENXIO; - goto err_out; - } - - /* Get the vector control register (offset 0xc) pointed by msix_idx */ - vec_ctrl = pdev->msix_base + msix_idx * PCI_MSIX_ENTRY_SIZE; - vec_ctrl += PCI_MSIX_ENTRY_VECTOR_CTRL; - - val = readl(vec_ctrl); - val &= ~PCI_MSIX_ENTRY_CTRL_ST; - val |= FIELD_PREP(PCI_MSIX_ENTRY_CTRL_ST, tag); - writel(val, vec_ctrl); - - /* Read back to flush the update */ - val = readl(vec_ctrl); - -err_out: - msi_unlock_descs(&pdev->dev); - return err; -#else - return -ENODEV; -#endif -} - /* Write tag to ST table - Return 0 if OK, otherwise -errno */ static int write_tag_to_st_table(struct pci_dev *pdev, int index, u16 tag) { @@ -346,7 +304,7 @@ int pcie_tph_set_st_entry(struct pci_dev switch (loc) { case PCI_TPH_LOC_MSIX: - err = write_tag_to_msix(pdev, index, tag); + err = pci_msix_write_tph_tag(pdev, index, tag); break; case PCI_TPH_LOC_CAP: err = write_tag_to_st_table(pdev, index, tag); From patchwork Sun Mar 9 08:41:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 872777 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DED81194A44; Sun, 9 Mar 2025 08:41:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741509720; cv=none; b=kXmpnrLtiptgK58HXwqmQita7h1RBRkjjqnYNsf0bEH0T+mdInvJoF97LeFswWWG0MxHxcyiXHA0K2kDfPLy4GOhQhF0laEGA9Kh8fMtA28n8t9aI+Vy7ZQwY2dVDdabRK6cOLyefY6HIpSF7RuLngYVCpB7ataFpu6Cd0bostE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741509720; c=relaxed/simple; bh=opPu9VYnWue7EKlbtVjtKUat1AsEJ+ILNMXtzRwyk3M=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=KredIde5iQBth6zQFSI20oPqFYpQFEDmjF7BbTvaK+xnDCBvvTyol9MKAyRkGSw76cpBlKvb/uSVBBwAWSu7xWsXtaIgwers27yUuokWYsAf9n3V12NU2iI8tv4r5hF4SzAz5a730Y+WANG9FLK/7+M7+cwDkoVRc6iqGYEX+ns= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=qILzZitV; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=IZVKjvpH; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="qILzZitV"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="IZVKjvpH" Message-ID: <20250309084110.713285420@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741509717; 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: references:references; bh=qU6MLzFjPGyQ6J2nYIjhCB3n+cLTvszu11O5Zgu5RwQ=; b=qILzZitVRVMjRLFWfp+1nfr9F8c45d/IxAirAH7NLQA5b6sfpGeYvxg+auFQFMG0sd37D7 WlV4WgBGRlIeSz4QZZlcfiWgtMf/YE66C3cb/qppQEFWarSoHatKB5NT/IYBO6Nwpa2tZp Gk+mZSBZK0v/Pf+4VXyH/SHvILzDbWpqEUpKEwt9V4A3VuvRFBxbjO7KX8zdmbgBi3+xdn CEc+kPkE9RTqhI6Si6sO3fsmnkCyfQ2oJuSiHHo3ozzzDt0RXz4CVqjCkqWic03Y4S68nh J1zvlcj+vLKz3FVQ7QQ/e/U/Up5wJncTOZ7s7ZG5MeDLdgWwisBxSpb3whYXCw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741509717; 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: references:references; bh=qU6MLzFjPGyQ6J2nYIjhCB3n+cLTvszu11O5Zgu5RwQ=; b=IZVKjvpHbi6myLlb9hiROMhpSewOeVPq+BMTgJ1PIuJfrtPhng/ZMgdVf12zTbCTXap7QV GwoW6oe9homIyhCQ== From: Thomas Gleixner To: LKML Cc: Marc Zyngier , Manivannan Sadhasivam , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Nishanth Menon , Tero Kristo , Santosh Shilimkar , Jon Mason , Dave Jiang , Allen Hubbe , ntb@lists.linux.dev, Bjorn Helgaas , linux-pci@vger.kernel.org, Haiyang Zhang , Wei Liu , linux-hyperv@vger.kernel.org, Wei Huang Subject: [patch 09/10] scsi: ufs: qcom: Remove the MSI descriptor abuse References: <20250309083453.900516105@linutronix.de> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Sun, 9 Mar 2025 09:41:56 +0100 (CET) The driver abuses the MSI descriptors for internal purposes. Aside of core code and MSI providers nothing has to care about their existence. They have been encapsulated with a lot of effort because this kind of abuse caused all sorts of issues including a maintainability nightmare. Rewrite the code so it uses dedicated storage to hand the required information to the interrupt handler. No functional change intended. Signed-off-by: Thomas Gleixner Cc: Manivannan Sadhasivam Cc: "James E.J. Bottomley" Cc: "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org --- drivers/ufs/host/ufs-qcom.c | 77 ++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 37 deletions(-) --- a/drivers/ufs/host/ufs-qcom.c +++ b/drivers/ufs/host/ufs-qcom.c @@ -1782,15 +1782,19 @@ static void ufs_qcom_write_msi_msg(struc ufshcd_mcq_config_esi(hba, msg); } +struct ufs_qcom_irq { + unsigned int irq; + unsigned int idx; + struct ufs_hba *hba; +}; + static irqreturn_t ufs_qcom_mcq_esi_handler(int irq, void *data) { - struct msi_desc *desc = data; - struct device *dev = msi_desc_to_dev(desc); - struct ufs_hba *hba = dev_get_drvdata(dev); - u32 id = desc->msi_index; - struct ufs_hw_queue *hwq = &hba->uhq[id]; + struct ufs_qcom_irq *qi = data; + struct ufs_hba *hba = qi->hba; + struct ufs_hw_queue *hwq = &hba->uhq[qi->idx]; - ufshcd_mcq_write_cqis(hba, 0x1, id); + ufshcd_mcq_write_cqis(hba, 0x1, qi->idx); ufshcd_mcq_poll_cqe_lock(hba, hwq); return IRQ_HANDLED; @@ -1799,8 +1803,7 @@ static irqreturn_t ufs_qcom_mcq_esi_hand static int ufs_qcom_config_esi(struct ufs_hba *hba) { struct ufs_qcom_host *host = ufshcd_get_variant(hba); - struct msi_desc *desc; - struct msi_desc *failed_desc = NULL; + struct ufs_qcom_irq *qi; int nr_irqs, ret; if (host->esi_enabled) @@ -1811,47 +1814,47 @@ static int ufs_qcom_config_esi(struct uf * 2. Poll queues do not need ESI. */ nr_irqs = hba->nr_hw_queues - hba->nr_queues[HCTX_TYPE_POLL]; + qi = devm_kcalloc(hba->dev, nr_irqs, sizeof(*qi), GFP_KERNEL); + if (qi) + return -ENOMEM; + ret = platform_device_msi_init_and_alloc_irqs(hba->dev, nr_irqs, ufs_qcom_write_msi_msg); if (ret) { dev_err(hba->dev, "Failed to request Platform MSI %d\n", ret); - return ret; + goto cleanup; } - msi_lock_descs(hba->dev); - msi_for_each_desc(desc, hba->dev, MSI_DESC_ALL) { - ret = devm_request_irq(hba->dev, desc->irq, - ufs_qcom_mcq_esi_handler, - IRQF_SHARED, "qcom-mcq-esi", desc); + for (int idx = 0; idx < nr_irqs; idx++) { + qi[idx].irq = msi_get_virq(hba->dev, idx); + qi[idx].idx = idx; + qi[idx].hba = hba; + + ret = devm_request_irq(hba->dev, qi[idx].irq, ufs_qcom_mcq_esi_handler, + IRQF_SHARED, "qcom-mcq-esi", qi + idx); if (ret) { dev_err(hba->dev, "%s: Fail to request IRQ for %d, err = %d\n", - __func__, desc->irq, ret); - failed_desc = desc; - break; + __func__, qi[idx].irq, ret); + qi[idx].irq = 0; + goto cleanup; } } - msi_unlock_descs(hba->dev); - if (ret) { - /* Rewind */ - msi_lock_descs(hba->dev); - msi_for_each_desc(desc, hba->dev, MSI_DESC_ALL) { - if (desc == failed_desc) - break; - devm_free_irq(hba->dev, desc->irq, hba); - } - msi_unlock_descs(hba->dev); - platform_device_msi_free_irqs_all(hba->dev); - } else { - if (host->hw_ver.major == 6 && host->hw_ver.minor == 0 && - host->hw_ver.step == 0) - ufshcd_rmwl(hba, ESI_VEC_MASK, - FIELD_PREP(ESI_VEC_MASK, MAX_ESI_VEC - 1), - REG_UFS_CFG3); - ufshcd_mcq_enable_esi(hba); - host->esi_enabled = true; + if (host->hw_ver.major == 6 && host->hw_ver.minor == 0 && + host->hw_ver.step == 0) { + ufshcd_rmwl(hba, ESI_VEC_MASK, + FIELD_PREP(ESI_VEC_MASK, MAX_ESI_VEC - 1), + REG_UFS_CFG3); } - + ufshcd_mcq_enable_esi(hba); + host->esi_enabled = true; + return 0; + +cleanup: + for (int idx = 0; qi[idx].irq; idx++) + devm_free_irq(hba->dev, qi[idx].irq, hba); + platform_device_msi_free_irqs_all(hba->dev); + devm_kfree(hba->dev, qi); return ret; } From patchwork Sun Mar 9 08:41:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 872100 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 856321BD9D5; Sun, 9 Mar 2025 08:42:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741509722; cv=none; b=of5FjE0DUry6zPAnwya6m40Uzy77uygRPgwtFQQU2AhwNIlePU6OQKdWdZGafu5oHc8GznMx4mFBLigBcnNMpO2TPrfb+62AfVHDRwS/DO+BTpyLqASpFye5RIWzvuxLEthFIsk2EzR5y/otugtjmDUGs43BmNjE5evJciVqDEE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741509722; c=relaxed/simple; bh=P/rOGxNdXnldR+DeNhNviepPjE0vHadq42YajFsXEPI=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=F0I74/LY9CdMZyKe6n/KUHdNlrmFvV7Ya6IL75o0szVYAgH+dKbgpR3UkYfdxB9Tt+M/xDXb0owKdAn6jV0La25InPIdOAGMLjtp1e6VrY8PcRu5Ofl9Z1Yt/zoyF9ZgfMgS3oKTrV3t+SdCmlqFEaO+DOS9LIJftBCOhyk40DA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=wxP7VCEs; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=w6qQRwoP; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="wxP7VCEs"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="w6qQRwoP" Message-ID: <20250309084110.776899075@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741509718; 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: references:references; bh=WHx/ZLek9rTZSicxLe9SDvZcHmq8PvF1xQqeIkgVlJw=; b=wxP7VCEshsYUESaCV8USQtjLjj6uS1/7X5MZRe5ZyWPF55UU81dofZPadr8v6N5axfKkff LIN+KN/ywin+I8BzvCYH+Vyvpqx7cwUQb4TMQ0ErTacaI4tu4NUOrR8Rj2DhYD5AryavYz wCG6KsV+kfzmSf5JPHxPMihqCQ3Alfs2R6rKPqnCrU/76FlrvSg7ZCrgDWaiv0/62vuKSt 1ysHeb/4pBFE+eGJpPDZ8SE4zWaSOQxn3Mxu1ejKhUZhRP8wA4sgEz5pbek8OHLFaDsaI3 9kQP+7/J1qr86Oza/9FgHci7kxSxo5XmZSvSFIjygEcTUw5XDYDFSKGRzU/17A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741509718; 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: references:references; bh=WHx/ZLek9rTZSicxLe9SDvZcHmq8PvF1xQqeIkgVlJw=; b=w6qQRwoP8mQzKYqMlJRnRJWkeR1oSOl+lHl64JVZ/Jy2LWAQISDvY8GuXZJs6hC6ppHUuF 9w5QnPI10aHh6hAQ== From: Thomas Gleixner To: LKML Cc: Marc Zyngier , Nishanth Menon , Tero Kristo , Santosh Shilimkar , Jon Mason , Dave Jiang , Allen Hubbe , ntb@lists.linux.dev, Bjorn Helgaas , linux-pci@vger.kernel.org, Haiyang Zhang , Wei Liu , linux-hyperv@vger.kernel.org, Wei Huang , Manivannan Sadhasivam , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org Subject: [patch 10/10] genirq/msi: Rename msi_[un]lock_descs() References: <20250309083453.900516105@linutronix.de> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Sun, 9 Mar 2025 09:41:58 +0100 (CET) Now that all abuse is gone and the legit users are converted to guard(msi_descs_lock), rename the lock functions and document them as internal. No functional chance. Signed-off-by: Thomas Gleixner Reviewed-by: Jonathan Cameron --- include/linux/msi.h | 8 ++++---- kernel/irq/msi.c | 16 ++++++++++------ 2 files changed, 14 insertions(+), 10 deletions(-) --- a/include/linux/msi.h +++ b/include/linux/msi.h @@ -224,11 +224,11 @@ struct msi_dev_domain { int msi_setup_device_data(struct device *dev); -void msi_lock_descs(struct device *dev); -void msi_unlock_descs(struct device *dev); +void __msi_lock_descs(struct device *dev); +void __msi_unlock_descs(struct device *dev); -DEFINE_LOCK_GUARD_1(msi_descs_lock, struct device, msi_lock_descs(_T->lock), - msi_unlock_descs(_T->lock)); +DEFINE_LOCK_GUARD_1(msi_descs_lock, struct device, __msi_lock_descs(_T->lock), + __msi_unlock_descs(_T->lock)); struct msi_desc *msi_domain_first_desc(struct device *dev, unsigned int domid, enum msi_desc_filter filter); --- a/kernel/irq/msi.c +++ b/kernel/irq/msi.c @@ -337,26 +337,30 @@ int msi_setup_device_data(struct device } /** - * msi_lock_descs - Lock the MSI descriptor storage of a device + * __msi_lock_descs - Lock the MSI descriptor storage of a device * @dev: Device to operate on + * + * Internal function for guard(msi_descs_lock). Don't use in code. */ -void msi_lock_descs(struct device *dev) +void __msi_lock_descs(struct device *dev) { mutex_lock(&dev->msi.data->mutex); } -EXPORT_SYMBOL_GPL(msi_lock_descs); +EXPORT_SYMBOL_GPL(__msi_lock_descs); /** - * msi_unlock_descs - Unlock the MSI descriptor storage of a device + * __msi_unlock_descs - Unlock the MSI descriptor storage of a device * @dev: Device to operate on + * + * Internal function for guard(msi_descs_lock). Don't use in code. */ -void msi_unlock_descs(struct device *dev) +void __msi_unlock_descs(struct device *dev) { /* Invalidate the index which was cached by the iterator */ dev->msi.data->__iter_idx = MSI_XA_MAX_INDEX; mutex_unlock(&dev->msi.data->mutex); } -EXPORT_SYMBOL_GPL(msi_unlock_descs); +EXPORT_SYMBOL_GPL(__msi_unlock_descs); static struct msi_desc *msi_find_desc(struct msi_device_data *md, unsigned int domid, enum msi_desc_filter filter)