From patchwork Wed Mar 19 10:56:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 876451 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 3CFEF253F31; Wed, 19 Mar 2025 10:56:39 +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=1742381801; cv=none; b=GXbtvWlSn4RtG4tFzbPj2qcJHwSPVAZKeiE741Xe2xeVkSQu7FIbuPd68OdDjZLGop/HFWSOClxfQm0AM+4/1J9iSU1zfvI1mZcEk7PGkGcN63IYdE2aixPG3lAq8oPB9PhNiaRVCX96Wsge+uzucnbgQibXtXba94n3betxk2U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742381801; c=relaxed/simple; bh=Ehz6wGfNoZMQOJoQ8b6MOWl08l4/ri784urifvlmYZs=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=dwPynEkfidurL6YqsT0c2tWPCPl/oOPvW7P19GxJK7y9rmPMpCuMBvHcJXu3zjsYdhnRpP8OT/jxxhKjdYC0wmY6fyP5ZP1IPj78d//bwqGMhD9kGqCrRZthUfHGg3JKSGqHpDiZSFkZpuZVBeFakhFaeKO+2olC/v8AFWlnCB4= 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=UOd5M6Yp; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=LrfOFdIi; 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="UOd5M6Yp"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="LrfOFdIi" Message-ID: <20250319105506.083538907@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1742381798; 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=xUu3pje6wUy/ZavkO5yRoyA7cOqryRXhXYC4SRrMQk8=; b=UOd5M6YpT1A8Sso8t0kqBDVB4tb2/88/W+5HS4tZxGT2fAIg4I0zZXQSZ0+X8dyJYtIq02 QacjZaZPTsfoIEuZfV5t/ngRmFjRX4OuPEDvabRj6y9zmlPYYEExrQtUl15UVGiFsAwevp KL8AynJfrZNUw1SHR1a8g3G1fmPREjM28jJRPnoXaZqVXErTYCbEL8Gl1BW5As7oapT1a6 z49AnGvihi41AaQy9gQ2+hWUvz8AMyRhbvLVKs/QQDLikSt1LMxAs5EuSMVRQel5q7gkb1 QQXn6PrqDYqZotWrQGCfOi+7C1AAzIpgA9yO0axKLj+5aO+Xbl2qeyoXOcBR9A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1742381798; 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=xUu3pje6wUy/ZavkO5yRoyA7cOqryRXhXYC4SRrMQk8=; b=LrfOFdIint6AnnrXXaflm0yuoQSio41wFLV+D0y78vGc2P8B4atEfGX8rT0arbG8JFGdv8 Y3eYNpHVIX00r7DA== From: Thomas Gleixner To: LKML Cc: Marc Zyngier , Peter Zijlstra , Jonathan Cameron , Nishanth Menon , Dhruva Gole , Tero Kristo , Santosh Shilimkar , Logan Gunthorpe , Dave Jiang , Jon Mason , Allen Hubbe , ntb@lists.linux.dev, Michael Kelley , Wei Liu , Bjorn Helgaas , Haiyang Zhang , linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, Wei Huang , Manivannan Sadhasivam , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Jonathan Cameron Subject: [patch V4 01/14] cleanup: Provide retain_ptr() References: <20250319104921.201434198@linutronix.de> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Wed, 19 Mar 2025 11:56:38 +0100 (CET) In cases where an allocation is consumed by another function, the allocation needs to be retained on success or freed on failure. The code pattern is usually: struct foo *f = kzalloc(sizeof(*f), GFP_KERNEL); struct bar *b; ,,, // Initialize f ... if (ret) goto free; ... bar = bar_create(f); if (!bar) { ret = -ENOMEM; goto free; } ... return 0; free: kfree(f); return ret; This prevents using __free(kfree) on @f because there is no canonical way to tell the cleanup code that the allocation should not be freed. Abusing no_free_ptr() by force ignoring the return value is not really a sensible option either. Provide an explicit macro retain_ptr(), which NULLs the cleanup pointer. That makes it easy to analyze and reason about. Signed-off-by: Thomas Gleixner Reviewed-by: Jonathan Cameron Cc: Peter Zijlstra --- V4: Cast to void so can't be used as return_ptr() replacement - James --- include/linux/cleanup.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) --- a/include/linux/cleanup.h +++ b/include/linux/cleanup.h @@ -216,6 +216,22 @@ const volatile void * __must_check_fn(co #define return_ptr(p) return no_free_ptr(p) +/* + * Only for situations where an allocation is handed in to another function + * and consumed by that function on success. + * + * struct foo *f __free(kfree) = kzalloc(sizeof(*f), GFP_KERNEL); + * + * setup(f); + * if (some_condition) + * return -EINVAL; + * .... + * ret = bar(f); + * if (!ret) + * retain_ptr(f); + * return ret; + */ +#define retain_ptr(p) ((void)__get_and_null(p, NULL)) /* * DEFINE_CLASS(name, type, exit, init, init_args...): From patchwork Wed Mar 19 10:56:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 874920 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 DE1EC254AF0; Wed, 19 Mar 2025 10:56:41 +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=1742381803; cv=none; b=TQQecc0UWM9DoO9Zl1yBeEkXpGKUweU6U+wCDNKM5fUqn85RXoeXtpoeG4FG2TLcKAn6YONr1qJAn6lhLui/b9436BllKygvVRqcb29P4NGt/Dd0J0Skw0MmCoW+fJATnt7kX3L7jnvPfMnEHQOgQeOuIS/YsRS3kAZAOVH7VEI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742381803; c=relaxed/simple; bh=XKzwz2VVe0mCfyZF4/PFvWd0QKKoyMr9Yxg740T5G7U=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=lsAzx6DHZzRNrVMgyVqwSDbaeiekt+TVu2gyIo/LeKq4KYMS42rF5315F+0GyEiSNgSIT8GZenAkbbKh6TAEj0vpxFekHByQdbutDIul8xJ08PSMLlex1/kzLW1oxgxxbqzHTs4w/mm109lwSAYUUgUwKb9Ic37nHse7LfR42iQ= 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=PhNtYbze; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=cfWWzZAl; 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="PhNtYbze"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="cfWWzZAl" Message-ID: <20250319105506.144672678@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1742381800; 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=kq5hU59K/rHOOCm+QaVXkTyIqJ3TlxLoh0GIAo2/3MA=; b=PhNtYbzeTQS2yz1CkqdW8VPD0i/H9sHZBcJhgq+9X7N6GmF0we6nO2Nh8OjkFsZeWik6D6 GDiiGkYtMKlTnbZZ3ijk1pkC/SLXtaTKc1U3OwBOrbTc+xvernVX80XBVzQDxi1of3pL0t xjjJYSjIXEWi5z9Za0rD9rqvmSIs4ibMM1UMTTzCXH5O5koLnP+5c7kuQmR52wOv4+gjGw zZoBMoK64w9j8M+JlxDcDpH66DCXtO0+oaldKpEnV7kAzW1Rvfbm42B66vT1Jy5Vvk/4XW Qth/9/pC7Zzif7DhxXVSpftn/UXPQwspkapnuY18mmBbPuNaIX/uwcNECYJqsw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1742381800; 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=kq5hU59K/rHOOCm+QaVXkTyIqJ3TlxLoh0GIAo2/3MA=; b=cfWWzZAlnAhEqExmnf2S00axn/DLVl80M6oIUk8+ZI/DwnnIWpPjCYW3KvW681t/qPhFsU Y3ZdSKUkiRW9wgBg== From: Thomas Gleixner To: LKML Cc: Marc Zyngier , Peter Zijlstra , Jonathan Cameron , Nishanth Menon , Dhruva Gole , Tero Kristo , Santosh Shilimkar , Logan Gunthorpe , Dave Jiang , Jon Mason , Allen Hubbe , ntb@lists.linux.dev, Michael Kelley , Wei Liu , Bjorn Helgaas , Haiyang Zhang , linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, Wei Huang , Manivannan Sadhasivam , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Jonathan Cameron Subject: [patch V4 02/14] genirq/msi: Use lock guards for MSI descriptor locking References: <20250319104921.201434198@linutronix.de> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Wed, 19 Mar 2025 11:56:39 +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 Reviewed-by: Jonathan Cameron --- V2: Remove the gotos - Jonathan --- include/linux/irqdomain.h | 2 include/linux/msi.h | 3 + kernel/irq/msi.c | 109 ++++++++++++++++------------------------------ 3 files changed, 45 insertions(+), 69 deletions(-) --- a/include/linux/irqdomain.h +++ b/include/linux/irqdomain.h @@ -281,6 +281,8 @@ static inline struct fwnode_handle *irq_ void irq_domain_free_fwnode(struct fwnode_handle *fwnode); +DEFINE_FREE(irq_domain_free_fwnode, struct fwnode_handle *, if (_T) irq_domain_free_fwnode(_T)) + struct irq_domain_chip_generic_info; /** --- 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); @@ -993,9 +988,8 @@ bool msi_create_device_irq_domain(struct void *chip_data) { struct irq_domain *domain, *parent = dev->msi.domain; - struct fwnode_handle *fwnode, *fwnalloced = NULL; - struct msi_domain_template *bundle; const struct msi_parent_ops *pops; + struct fwnode_handle *fwnode; if (!irq_domain_is_msi_parent(parent)) return false; @@ -1003,7 +997,8 @@ bool msi_create_device_irq_domain(struct if (domid >= MSI_MAX_DEVICE_IRQDOMAINS) return false; - bundle = kmemdup(template, sizeof(*bundle), GFP_KERNEL); + struct msi_domain_template *bundle __free(kfree) = + kmemdup(template, sizeof(*bundle), GFP_KERNEL); if (!bundle) return false; @@ -1026,41 +1021,36 @@ bool msi_create_device_irq_domain(struct * node as they are not guaranteed to have a fwnode. They are never * looked up and always handled in the context of the device. */ - if (bundle->info.flags & MSI_FLAG_USE_DEV_FWNODE) - fwnode = dev->fwnode; + struct fwnode_handle *fwnode_alloced __free(irq_domain_free_fwnode) = NULL; + + if (!(bundle->info.flags & MSI_FLAG_USE_DEV_FWNODE)) + fwnode = fwnode_alloced = irq_domain_alloc_named_fwnode(bundle->name); else - fwnode = fwnalloced = irq_domain_alloc_named_fwnode(bundle->name); + fwnode = dev->fwnode; if (!fwnode) - goto free_bundle; + return false; if (msi_setup_device_data(dev)) - goto free_fwnode; - - msi_lock_descs(dev); + return false; + guard(msi_descs_lock)(dev); if (WARN_ON_ONCE(msi_get_device_domain(dev, domid))) - goto fail; + return false; if (!pops->init_dev_msi_info(dev, parent, parent, &bundle->info)) - goto fail; + return false; domain = __msi_create_irq_domain(fwnode, &bundle->info, IRQ_DOMAIN_FLAG_MSI_DEVICE, parent); if (!domain) - goto fail; + return false; + /* @bundle and @fwnode_alloced are now in use. Prevent cleanup */ + retain_ptr(bundle); + retain_ptr(fwnode_alloced); domain->dev = dev; dev->msi.data->__domains[domid].domain = domain; - msi_unlock_descs(dev); return true; - -fail: - msi_unlock_descs(dev); -free_fwnode: - irq_domain_free_fwnode(fwnalloced); -free_bundle: - kfree(bundle); - return false; } /** @@ -1074,12 +1064,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 +1076,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 +1091,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 +1348,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 +1454,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 +1492,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 +1589,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 +1620,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 +1640,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 Wed Mar 19 10:56: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: 876450 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 BD15D25523C; Wed, 19 Mar 2025 10:56: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=1742381806; cv=none; b=qLkdEgpHBLH/DzG2lf9ibK5OgnyBf6xxnOBcVGY3pA4nol2LtCmiZPNzHAqAGGqLPNY4iImMDTEAVASJ5+M8LQa0FtqUCXx/5cUHYrfYmLBBSxsETcpv5q8MKWe9LhJUBOozHhz3QHxE8bJLDx/AfTxVf3xAt7ILmjElCU00zg8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742381806; c=relaxed/simple; bh=gVMGNDCIzEC7gP1ELqJUnuWuiZU7ZW3gNVIXfeuimdA=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=K1eHIbw/p7bOKmixmQj9vnzevjfalrzw9wsGmzzEXiNXWO+2GZBClQ+BwSPouBcsTDQqm7tiPQDKBlXK9hssmEz7k2QRTkuMnOrg3NAfpMWUheYdbqFupU6zrQNdAgLz9CWjFX+tri5/TFbLYj3Q/U1izmxWHbuizaYPacSIYAI= 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=mSNqkk4o; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=iPMKH+Sf; 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="mSNqkk4o"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="iPMKH+Sf" Message-ID: <20250319105506.203802081@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1742381803; 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=3HVy4coZe9OEdGiZgYg3FWqwXg+pamrMoCzDhEhsOwI=; b=mSNqkk4oL7Li5xvEy0+K+0Fjkj68H31Qpffqbm3umEH25AXeTopx/PYDTLOkbywBA19+8u 4cxiftKlWdLnd8OwmspfoQw1KX53Kq3ucuK+/7sUO8Q1okwqPnoHnNkDchpIi2NQwwr6tN 30WDrI+h4z7ohSrK5xaDiFXQyATSq6HbHnZnoL2H3Qj0U3nyUMuBoVRgcDDIXgaiA3haoT 4jZiba+ynfxAvY2SxLopI9uwpOVlidvbQJV5ipDUTRrH0P+wfPy3++lhfR+cccijFnAJas TTGDqtksCzClW0mVJxW7SQ1f7Z9BJYLy2iY/rwi8pB+Ihw53FPCW1LiVTtgBVA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1742381803; 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=3HVy4coZe9OEdGiZgYg3FWqwXg+pamrMoCzDhEhsOwI=; b=iPMKH+SfUJS4QuY40+uh5VfF+embdT/2hEum93jHk27kjHtQ2XfXu/3A+cotayev8/Hm/+ NShPyJPzBz3xnnAw== From: Thomas Gleixner To: LKML Cc: Marc Zyngier , Peter Zijlstra , Nishanth Menon , Jonathan Cameron , Dhruva Gole , Tero Kristo , Santosh Shilimkar , Logan Gunthorpe , Dave Jiang , Jon Mason , Allen Hubbe , ntb@lists.linux.dev, Michael Kelley , Wei Liu , Bjorn Helgaas , Haiyang Zhang , linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, Wei Huang , Manivannan Sadhasivam , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Jonathan Cameron Subject: [patch V4 03/14] soc: ti: ti_sci_inta_msi: Switch MSI descriptor locking to guard() References: <20250319104921.201434198@linutronix.de> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Wed, 19 Mar 2025 11:56:42 +0100 (CET) Convert the code to use the new guard(msi_descs_lock). No functional change intended. Signed-off-by: Thomas Gleixner Tested-by: Nishanth Menon Reviewed-by: Jonathan Cameron Reviewed-by: Dhruva Gole 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 Wed Mar 19 10:56:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 874919 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 38C7B255257; Wed, 19 Mar 2025 10:56:47 +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=1742381808; cv=none; b=RW8AbyvolphkvVv3ShJ5QqatF8+nmjpMneLrhHztWoLUiGtdMQIIPw8WQpNbb50uFGK+lW7BssUeLAUOiTvhsBRB+sNaLHryTBxs7+TcVGsW196/eRBTNCtVhTivTjRnWd3ki8bUUIkUmqYIckVqLnYIvS2J0xrQivptlAaR4Kc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742381808; c=relaxed/simple; bh=ovwB1tIyY2DkaUqZOtFf3VDmTTRENXZLRtFJy4bku14=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=k8TR+B875dO2dMaV3zeEjOGcOM3OFnkZcp6kiAbbfzNak2vUDLp+a8w4eYLNPQ344yQXz+IBjhZ3XzwagZgQZZZHiEHWYpLIQtw7wr8pbqy3LXJCO2Oqi1ov9COKCgmczuuE5o25Jy0VOQ+euHq08kzU2NwnH/Shws+dfBE22Jo= 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=LT05L8wG; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=7sg4jJMm; 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="LT05L8wG"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="7sg4jJMm" Message-ID: <20250319105506.263456735@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1742381805; 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=7+z8oSyOI/6DQVHw5aTbTSzONFRdZw/C9vWt0+dJcNg=; b=LT05L8wG0Ux9NmrrxTx0Hf7ewM/tmZ8wyhaQeq1xj5tvSiAQCl1DYrH9sTXsYeFpzzUpDD Vj2WN/TNPhvk1j33n+XskXs65K7davOxNncO9NXDE88UrJqFDXO0DGbLrSCuHkWJpTTTlc ueD0hFk5ImGn5iXu0LH4bfsZR7bIuf1JKrYbMKYAAA6Ea1UEISSIjBiqkIO3FzzRnzKOn6 U0bs6JgbG6jgiwcXKBp2JBDVkNEygegLtRk/ku8lMhRORp4R9VzHCSWXgwymWMwnlM8mT0 osDkhTWuX5Ggh23WL6d8d2dIgZ9Oqu2kyoSiRCFYTlqb3l8g3Vuw1k0gcElAkw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1742381805; 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=7+z8oSyOI/6DQVHw5aTbTSzONFRdZw/C9vWt0+dJcNg=; b=7sg4jJMm9QQua9Rgrtc0zdBlqh+IMS8rj2JgF82TLVrs7iOc19s00ZasFxr49xSJzDEwSB 5ssAeWNletxGM8DA== From: Thomas Gleixner To: LKML Cc: Marc Zyngier , Peter Zijlstra , Jonathan Cameron , Logan Gunthorpe , Dave Jiang , Jon Mason , Allen Hubbe , ntb@lists.linux.dev, Nishanth Menon , Dhruva Gole , Tero Kristo , Santosh Shilimkar , Michael Kelley , Wei Liu , Bjorn Helgaas , Haiyang Zhang , linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, Wei Huang , Manivannan Sadhasivam , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Jonathan Cameron Subject: [patch V4 04/14] NTB/msi: Switch MSI descriptor locking to lock guard() References: <20250319104921.201434198@linutronix.de> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Wed, 19 Mar 2025 11:56:45 +0100 (CET) Convert the code to use the new guard(msi_descs_lock). No functional change intended. Signed-off-by: Thomas Gleixner Reviewed-by: Jonathan Cameron Reviewed-by: Logan Gunthorpe Acked-by: Dave Jiang Cc: Jon Mason Cc: Allen Hubbe Cc: ntb@lists.linux.dev --- 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 Wed Mar 19 10:56:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 876449 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 F17BA254874; Wed, 19 Mar 2025 10:56: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=1742381810; cv=none; b=OcweDmaWCc2/ZuUlsPmE35tu9b9nCYkfaOjrqhhs8h/Sn/ga80uH0Q8r7ItZ2T4kVIEz4iucogzIb/XYpicKjWJiwOVj0Xqr1wwkFaQlurGKvc7RC43yZprvlEkaxhXm2npDsR2cSOenBjwhGDAjwP9gCaBLsC9qoU3jS+RMhOs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742381810; c=relaxed/simple; bh=eZxa/kj9RNTSaRSLG6juKNzrX6ldOaWxsWzud0IlPTY=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=ept1QkArc5MVdpFdJuJaBu/5YTLEMsylL5moChryzWdCBG0EhiGKm1UwA9ggk47yltY9pAvuzdz2rUac8lPRqDe97hHUiL+Cw4moy7vjXc7h4ggFXZac6Z80PHrtpz3Ep3ZVBO4CnUh2GZP5mzdObdGZYZssrIQV6Ber5WGzoT8= 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=I8JlWdus; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=5NutwKoT; 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="I8JlWdus"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="5NutwKoT" Message-ID: <20250319105506.322536126@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1742381807; 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=zKgxDJTeWwx2nPph9Hc2qhKbbX8Dd6/qYocNy9HMAB8=; b=I8JlWdusEos8QurcjCkq6u+QlFvHyzvniLe7U1+C4YkR2i1rB2eNbI9nPKlHw2E67mSo3O DwVgMpBKShfMdLI4MIO/Y8W3Zaq+gEXav/YYDfdp9F4SU2YVe0BHygP1/V949fZLMTtldD W1T+q1eiiUw2IEd0tG4PqvAEAP2nHtm2Mkd2QUqcEAjMcYOUeXsPSFWAhsgbONShepIceP XlC5BgKx9CxXOIxWHOuiw8mO43qF07FYWcKsWknz6NcYk0isO413hqBsiwLMm7gAsjnoIJ tMk9U2SKxmLfcnPbbnL49xk9y8Nv1lEMICGvCaA5OCEWI4eqjrAN7DA1AosHHw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1742381807; 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=zKgxDJTeWwx2nPph9Hc2qhKbbX8Dd6/qYocNy9HMAB8=; b=5NutwKoTEimBlWWihYmwJuRHauBT15FrCz5l45R9kBEHCkTxjycmpoQawSaYncAlnYgPCx ImeJSRr+Pc4OlfCg== From: Thomas Gleixner To: LKML Cc: Marc Zyngier , Peter Zijlstra , Jonathan Cameron , Nishanth Menon , Dhruva Gole , Tero Kristo , Santosh Shilimkar , Logan Gunthorpe , Dave Jiang , Jon Mason , Allen Hubbe , ntb@lists.linux.dev, Michael Kelley , Wei Liu , Bjorn Helgaas , Haiyang Zhang , linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, Wei Huang , Manivannan Sadhasivam , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Jonathan Cameron Subject: [patch V4 05/14] PCI/MSI: Use guard(msi_desc_lock) where applicable References: <20250319104921.201434198@linutronix.de> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Wed, 19 Mar 2025 11:56:47 +0100 (CET) Convert the trivial cases of msi_desc_lock/unlock() pairs. No functional change. Signed-off-by: Thomas Gleixner --- V4: Split out from the previous combo patch --- drivers/pci/msi/api.c | 6 ++---- drivers/pci/msi/msi.c | 12 ++++++------ 2 files changed, 8 insertions(+), 10 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 @@ -871,13 +871,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 Wed Mar 19 10:56: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: 874918 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 F0DFF2561CD; Wed, 19 Mar 2025 10:56:50 +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=1742381812; cv=none; b=cPKvRowB2PMPxVvThU7zTlosZCkvPylLAxr7S+h/DOOT95X2NR9iasZ56pDrYU9vY1np9PFMnWw5z2j8nYWRzxb0KjWTfGW/E9zf8MQRqe2XWzUGZO8PKsQ2s1TnKtWzrJsyfvyzeKuPBsMrMOcCrBL0NZHaAwxfie8KyMlIffE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742381812; c=relaxed/simple; bh=TjGlI7+wBN100sMulKKh11WVPqLPLW/s15CV7f3Awe0=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=cxbNEh5uBpQt04UC2MDixgCCGhvXoV88LCbDWYx8fBEvIc5X6ybJfQaQI0KCMvZ6ZXKYvOYqRFi0VTf/7tmxvQIw4D4AfxbM8ETo3dhuIO1rCLJs8rMGrzvoD2lAzqa+CUvrsVT8rZqQfBwXuxZiESmcug+/ZUHUos8h9K5sMDw= 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=2oroJln3; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=qMJ9OS56; 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="2oroJln3"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="qMJ9OS56" Message-ID: <20250319105506.383222333@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1742381809; 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=2BkahZrPHwQRrSPKUbWuUmaZoNw9hAG/NP71MuXaP0M=; b=2oroJln3EJhZ9XjeIk+klr3MPY/WGK+IG6Hm3gIFDRIi4Pg7bwCZnLc9Vu+cDcl1hxlwvK zbkHUQrXNAoI42bcqZrrzhTUfqNfKiBEGuOt18pBtM8LJNsredNWZRSIV5RX9Tjx5b4Ovb 989OUpprIUJqUjGAGVnJq2olMKwSwbILQ4ne03iw5HuMClLlTNikrBh1NHZLf5Tas16CAa 7JCf0Schbfs4WYZkxXLmUECINbBrVvVNbkM/iJviVwaz4N6ey4XhKNyNXV0UoeXjxwwbWZ gdh7hzfnunuTuM/lYD4nnGweAcvrYt7Nepo9MvULFT45rnwiLrzDJcSN/MnJEQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1742381809; 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=2BkahZrPHwQRrSPKUbWuUmaZoNw9hAG/NP71MuXaP0M=; b=qMJ9OS56CUB9YGywm4vS48tVf8wNFqmSXYU6uPLokURE4s/hFRwZIBvLuXVfskKHWrJout 5jl2Kxlsnmaw2hDw== From: Thomas Gleixner To: LKML Cc: Marc Zyngier , Peter Zijlstra , Jonathan Cameron , Nishanth Menon , Dhruva Gole , Tero Kristo , Santosh Shilimkar , Logan Gunthorpe , Dave Jiang , Jon Mason , Allen Hubbe , ntb@lists.linux.dev, Michael Kelley , Wei Liu , Bjorn Helgaas , Haiyang Zhang , linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, Wei Huang , Manivannan Sadhasivam , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Jonathan Cameron Subject: [patch V4 06/14] PCI/MSI: Set pci_dev::msi_enabled late References: <20250319104921.201434198@linutronix.de> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Wed, 19 Mar 2025 11:56:49 +0100 (CET) The comment claiming that pci_dev::msi_enabled has to be set across setup is a leftover from ancient code versions. Nothing in the setup code requires the flag to be set anymore. Set it in the success path and remove the extra goto label. Signed-off-by: Thomas Gleixner --- V4: New patch --- drivers/pci/msi/msi.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) --- a/drivers/pci/msi/msi.c +++ b/drivers/pci/msi/msi.c @@ -359,12 +359,8 @@ static int msi_capability_init(struct pc if (nvec > 1 && !pci_msi_domain_supports(dev, MSI_FLAG_MULTI_PCI_MSI, ALLOW_LEGACY)) return 1; - /* - * Disable MSI during setup in the hardware, but mark it enabled - * so that setup code can evaluate it. - */ + /* Disable MSI during setup in the hardware to erase stale state */ pci_msi_set_enable(dev, 0); - dev->msi_enabled = 1; if (affd) masks = irq_create_affinity_masks(nvec, affd); @@ -372,7 +368,7 @@ static int msi_capability_init(struct pc msi_lock_descs(&dev->dev); ret = msi_setup_msi_desc(dev, nvec, masks); if (ret) - goto fail; + goto unlock; /* All MSIs are unmasked by default; mask them all */ entry = msi_first_desc(&dev->dev, MSI_DESC_ALL); @@ -394,6 +390,7 @@ static int msi_capability_init(struct pc goto err; /* Set MSI enabled bits */ + dev->msi_enabled = 1; pci_intx_for_msi(dev, 0); pci_msi_set_enable(dev, 1); @@ -404,8 +401,6 @@ static int msi_capability_init(struct pc 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); From patchwork Wed Mar 19 10:56:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 876448 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 0BC1B256C70; Wed, 19 Mar 2025 10:56:52 +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=1742381815; cv=none; b=mconUFIo2iDWjsnYqh2nCFl7D585uH1JBZFUM9vwkc+niijO1roJ2dRc8xUqthxezeAkcyl1ZpDs6thsKESjxaExUq2WtQZNxYCoOz+w9br3i59zGZqL0fwD4nsP/Dd8O284/RCT4XzS2XebkUiW0ILAqAsYhLMFUO81IZrBd/c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742381815; c=relaxed/simple; bh=0S6JBtftfWBjmYP+nFzM28W31kvZAZS+nbE4Ex10PHs=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=Wf/anke42qKv3++XfW5vdNMPRZ7KC3U+m5GHl1n+LR0zqKGQLYLBnFIHv1aYrohyw//i6WL9pPXNJHLAIB0I3AyWsZ6RqxRyCOEttp2k9iAw3S0do9BSMOvVQcchFes5DvIHHMa3QUeQIXjSLQs25LdYJVYOcRQIFPcyoZxRXU8= 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=xW0waZFT; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=bIZQnm5e; 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="xW0waZFT"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="bIZQnm5e" Message-ID: <20250319105506.444764312@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1742381811; 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=M3ZLyKNabp56RBqfhxFCqK7uWgjrNSEEvNrMzTPxxsE=; b=xW0waZFTl+vn2skuaRY82JwU6tGma4gtARdDiogSCFSBqR+MvCXAVJpNv+QChA70y/fTQs m1Edqe0ChWbeEvns9SkELJmr4hvXV2Z2xx/KV3ivWASs9qMMyfhf4HDy0GDwNAJTZ44+UZ QqUlSXfJ0lp88yj7ZFf3VfMuQ6DoPkkTMG0t48yqW0AKZZqhf8bMu6vUcyBEozaqrK05C6 Kh1w1u2GzZqqW/o+RxAt3yfW0zvhPMoGtWjKL4D3+hJD50n9+NyPGYeKED8ggwx6X9wP+R jd8Dz0tdtOwYQehKPMfmp0nDTf+n9A96bn7E3OYBeRg4sCDuDNv7+2jWwQTPEg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1742381811; 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=M3ZLyKNabp56RBqfhxFCqK7uWgjrNSEEvNrMzTPxxsE=; b=bIZQnm5eUNLCJTSvqssztPjZ4819Gx/Vyp/ijes+SDGzwzLkIwUvMGudPHerXgoSZYTUaf qfrcUXBXksmoB4Cw== From: Thomas Gleixner To: LKML Cc: Marc Zyngier , Peter Zijlstra , Jonathan Cameron , Nishanth Menon , Dhruva Gole , Tero Kristo , Santosh Shilimkar , Logan Gunthorpe , Dave Jiang , Jon Mason , Allen Hubbe , ntb@lists.linux.dev, Michael Kelley , Wei Liu , Bjorn Helgaas , Haiyang Zhang , linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, Wei Huang , Manivannan Sadhasivam , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Jonathan Cameron Subject: [patch V4 07/14] PCI/MSI: Use __free() for affinity masks References: <20250319104921.201434198@linutronix.de> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Wed, 19 Mar 2025 11:56:50 +0100 (CET) Let cleanup handle the freeing of the affinity mask. That prepares for switching the MSI descriptor locking to a guard(). No functional change. Signed-off-by: Thomas Gleixner --- V4: Split out of the previous combo patch --- drivers/pci/msi/msi.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) --- a/drivers/pci/msi/msi.c +++ b/drivers/pci/msi/msi.c @@ -351,7 +351,6 @@ 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 msi_desc *entry, desc; int ret; @@ -362,8 +361,8 @@ static int msi_capability_init(struct pc /* Disable MSI during setup in the hardware to erase stale state */ pci_msi_set_enable(dev, 0); - if (affd) - masks = irq_create_affinity_masks(nvec, affd); + struct irq_affinity_desc *masks __free(kfree) = + affd ? irq_create_affinity_masks(nvec, affd) : NULL; msi_lock_descs(&dev->dev); ret = msi_setup_msi_desc(dev, nvec, masks); @@ -403,7 +402,6 @@ static int msi_capability_init(struct pc pci_free_msi_irqs(dev); unlock: msi_unlock_descs(&dev->dev); - kfree(masks); return ret; } @@ -664,12 +662,10 @@ 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) = + affd ? irq_create_affinity_masks(nvec, affd) : NULL; int ret; - if (affd) - masks = irq_create_affinity_masks(nvec, affd); - msi_lock_descs(&dev->dev); ret = msix_setup_msi_descs(dev, entries, nvec, masks); if (ret) @@ -691,7 +687,6 @@ static int msix_setup_interrupts(struct pci_free_msi_irqs(dev); out_unlock: msi_unlock_descs(&dev->dev); - kfree(masks); return ret; } From patchwork Wed Mar 19 10:56: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: 874917 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 0B4E02571A7; Wed, 19 Mar 2025 10:56:54 +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=1742381817; cv=none; b=nyb1p71PIsJpNC4GqkkS8ffagx99weVuuvgdaSTIyx0JuEQJ9VAwddP7ltRn9GjrV5avuKYJPNUv7jAgryLBqLqO8t1sLD5qJxgWAJ6cYvQddPJTaiAMjPNmIaDYknuonWC6PhJO/F1ktIc2au65m5K4fR/AheFLosAh4/CaAlk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742381817; c=relaxed/simple; bh=HaoLq0D3RvhTFwiLdtEXdAhf531e3qdaeTOQWLUWAoc=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=AbLueEc6VrxO2ppEx20/mNjyf+25u7iT57IjHUIsSrKTpcPg34p5ERqEixnw7A/o+SJC+YnnqQx+k/QdXl7hPHWfFqi1epc2Siv2nvi5T0cCkzDduGzRWJjFh3pRgrToMBfVUZvFLkmlhChKJTtbwJ2Z9ZU/mUGFtmtnMQnJF3o= 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=Zdl4LTHT; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=nrxZP5By; 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="Zdl4LTHT"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="nrxZP5By" Message-ID: <20250319105506.504992208@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1742381813; 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=lBkrdbLZXVbEAH8J9x7p9bDWZWgworS88LcdnKmFb84=; b=Zdl4LTHTBFbnFX7IwjtsU1uMOk+lhulCfGrWhqzI2/b1oGarL1aiWpFeojjf0b5v6UQvVP YOW9YfUC/Ujl2YcpZbbFiYN0ngNgGXUgPEugTZXdWxz+S/ElofSnTLNwpc/pk5qXTJvyvy lgQKDJKo7iOOH7MLwLk4v/GUq9RcwUW5JXBU+spfJ6oQqSBuObIkiREyZmf3qcIF/ScOGs REvrGY0aw7/Oq1ykHvWiFn/6evsqKp2NCaJW6giYa/Q0M1g5nRk5xYBnqAphTXiy822sQc JrisJPqlCK/CPFa4TJpaM/0yRqnCg62D5YkJc5ozYNwrbzfO+nub6EI3PUW7xA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1742381813; 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=lBkrdbLZXVbEAH8J9x7p9bDWZWgworS88LcdnKmFb84=; b=nrxZP5Byd7khrEeUZ7PYH2gA7bnf9yccHSfbcXLhhpp0EXohMHKKgI+k5kt3pJjJhr45us 8cscixW3nh/ufKAw== From: Thomas Gleixner To: LKML Cc: Marc Zyngier , Peter Zijlstra , Jonathan Cameron , Nishanth Menon , Dhruva Gole , Tero Kristo , Santosh Shilimkar , Logan Gunthorpe , Dave Jiang , Jon Mason , Allen Hubbe , ntb@lists.linux.dev, Michael Kelley , Wei Liu , Bjorn Helgaas , Haiyang Zhang , linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, Wei Huang , Manivannan Sadhasivam , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Jonathan Cameron Subject: [patch V4 08/14] PCI/MSI: Switch msi_capability_init() to guard(msi_desc_lock) References: <20250319104921.201434198@linutronix.de> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Wed, 19 Mar 2025 11:56:53 +0100 (CET) Split the lock protected functionality of msi_capability_init() out into a helper function and use guard(msi_desc_lock) to replace the lock/unlock pair. No functional change intended. Signed-off-by: Thomas Gleixner --- V4: Split out from the previous combo patch --- drivers/pci/msi/msi.c | 68 ++++++++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 32 deletions(-) --- a/drivers/pci/msi/msi.c +++ b/drivers/pci/msi/msi.c @@ -336,38 +336,13 @@ static int msi_verify_entries(struct pci return !entry ? 0 : -EIO; } -/** - * msi_capability_init - configure device's MSI capability structure - * @dev: pointer to the pci_dev data structure of MSI device function - * @nvec: number of interrupts to allocate - * @affd: description of automatic IRQ affinity assignments (may be %NULL) - * - * Setup the MSI capability structure of the device with the requested - * number of interrupts. A return value of zero indicates the successful - * setup of an entry with the new MSI IRQ. A negative return value indicates - * an error, and a positive return value indicates the number of interrupts - * which could have been allocated. - */ -static int msi_capability_init(struct pci_dev *dev, int nvec, - struct irq_affinity *affd) +static int __msi_capability_init(struct pci_dev *dev, int nvec, struct irq_affinity_desc *masks) { + int ret = msi_setup_msi_desc(dev, nvec, masks); struct msi_desc *entry, desc; - int ret; - - /* Reject multi-MSI early on irq domain enabled architectures */ - if (nvec > 1 && !pci_msi_domain_supports(dev, MSI_FLAG_MULTI_PCI_MSI, ALLOW_LEGACY)) - return 1; - - /* Disable MSI during setup in the hardware to erase stale state */ - pci_msi_set_enable(dev, 0); - struct irq_affinity_desc *masks __free(kfree) = - affd ? irq_create_affinity_masks(nvec, affd) : NULL; - - msi_lock_descs(&dev->dev); - ret = msi_setup_msi_desc(dev, nvec, masks); if (ret) - goto unlock; + return ret; /* All MSIs are unmasked by default; mask them all */ entry = msi_first_desc(&dev->dev, MSI_DESC_ALL); @@ -395,16 +370,45 @@ 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); -unlock: - msi_unlock_descs(&dev->dev); return ret; } +/** + * msi_capability_init - configure device's MSI capability structure + * @dev: pointer to the pci_dev data structure of MSI device function + * @nvec: number of interrupts to allocate + * @affd: description of automatic IRQ affinity assignments (may be %NULL) + * + * Setup the MSI capability structure of the device with the requested + * number of interrupts. A return value of zero indicates the successful + * setup of an entry with the new MSI IRQ. A negative return value indicates + * an error, and a positive return value indicates the number of interrupts + * which could have been allocated. + */ +static int msi_capability_init(struct pci_dev *dev, int nvec, + struct irq_affinity *affd) +{ + /* Reject multi-MSI early on irq domain enabled architectures */ + if (nvec > 1 && !pci_msi_domain_supports(dev, MSI_FLAG_MULTI_PCI_MSI, ALLOW_LEGACY)) + return 1; + + /* + * Disable MSI during setup in the hardware, but mark it enabled + * so that setup code can evaluate it. + */ + pci_msi_set_enable(dev, 0); + + struct irq_affinity_desc *masks __free(kfree) = + affd ? irq_create_affinity_masks(nvec, affd) : NULL; + + guard(msi_descs_lock)(&dev->dev); + return __msi_capability_init(dev, nvec, masks); +} + int __pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec, struct irq_affinity *affd) { From patchwork Wed Mar 19 10:56: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: 876447 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 78E66256C98; Wed, 19 Mar 2025 10:56: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=1742381819; cv=none; b=YSpU4sV7MQL3X717RW5R0O7c6N0+Tcvi1vamV2vY3umabp8h3qDowBPZdD3joX+FKAcwN6t/EEgiTLGMwcFeJ5VC3CdtN/IAz23IizxpX7a2GLiGVQXzKNoHYyoneIX0jWXmMmprlxybZn8HCsTXJidyOqe7ygxocSr/g6wsg4I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742381819; c=relaxed/simple; bh=Yku/Dk38vOmdf/tGUWDs7VYaf6oF5NAwKcemJLCATBA=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=XffX6bOBfhHMTh+4pqcwtiWRtI6fiAvggSbSfZvzBJBxVBPuJ10+iBZpO88y4Q2wk1O4JyzueCHuoNxB1j8xnBQFzPCQq/HG/oB+EU68tRvyORe6DL7fVvGM8eeJs8c7eIrrl0nDOUDOVwqkpmQ+T1H5Xa8u0mL6FyCQE4HHBr0= 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=pMLNt4dY; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=aI2vjARS; 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="pMLNt4dY"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="aI2vjARS" Message-ID: <20250319105506.564105011@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1742381814; 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=WN2Id7Ic7+jh+7crblGSxwRPR1jdNZ1jmqlHS+u0MqA=; b=pMLNt4dY/Q52H70ecXsmMPj7z8+X4gMHQhWOE2R/aN+exlVZANNpTbZRrA/CuIGq8Dw/H3 5hkAxRaSH7Homfy8JEBc26oJQM1HD3Cms89ZtwMW+AUK+2UcmAPUnRfIMH+ytcV6jkjfbl dtHzzCA+AnOoVyxhqPIjGIwzKboQPfSpOZJJRJiuoD/UL1dkdYJytUlQWxTSiY0iN2G69f 8Bi6NkfKhYrqYOX06fTG2XSveL4CcjQ2nkWmnm961pXzxflSmvE4F7v92C8gQOY1S2LiV7 t/RKWa0tfQ2E+QuCr9ZQ7SzIR9gHisox/TyPPwNZEIf+1pZqnGctSIKqDnl3tg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1742381814; 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=WN2Id7Ic7+jh+7crblGSxwRPR1jdNZ1jmqlHS+u0MqA=; b=aI2vjARSZWWsVfBDHjbWorZRVdVYNQ3JL1TNiIjd4chDhAMywTAUd/hynu84kznQWMDysA 3bU7iZ/ooC6VDhAQ== From: Thomas Gleixner To: LKML Cc: Marc Zyngier , Peter Zijlstra , Jonathan Cameron , Nishanth Menon , Dhruva Gole , Tero Kristo , Santosh Shilimkar , Logan Gunthorpe , Dave Jiang , Jon Mason , Allen Hubbe , ntb@lists.linux.dev, Michael Kelley , Wei Liu , Bjorn Helgaas , Haiyang Zhang , linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, Wei Huang , Manivannan Sadhasivam , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Jonathan Cameron Subject: [patch V4 09/14] PCI/MSI: Switch msix_capability_init() to guard(msi_desc_lock) References: <20250319104921.201434198@linutronix.de> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Wed, 19 Mar 2025 11:56:54 +0100 (CET) Split the lock protected functionality of msix_capability_init() out into a helper function and use guard(msi_desc_lock) to replace the lock/unlock pair. Simplify the error path in the helper function by utilizing a custom cleanup to get rid of the remaining gotos. No functional change intended. Signed-off-by: Thomas Gleixner --- V4: Split out from the previous combo patch --- drivers/pci/msi/msi.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) --- a/drivers/pci/msi/msi.c +++ b/drivers/pci/msi/msi.c @@ -663,35 +663,39 @@ static void msix_mask_all(void __iomem * writel(ctrl, base + PCI_MSIX_ENTRY_VECTOR_CTRL); } -static int msix_setup_interrupts(struct pci_dev *dev, struct msix_entry *entries, - int nvec, struct irq_affinity *affd) +DEFINE_FREE(free_msi_irqs, struct pci_dev *, if (_T) pci_free_msi_irqs(_T)); + +static int __msix_setup_interrupts(struct pci_dev *__dev, struct msix_entry *entries, + int nvec, struct irq_affinity_desc *masks) { - struct irq_affinity_desc *masks __free(kfree) = - affd ? irq_create_affinity_masks(nvec, affd) : NULL; - int ret; + struct pci_dev *dev __free(free_msi_irqs) = __dev; - msi_lock_descs(&dev->dev); - ret = msix_setup_msi_descs(dev, entries, nvec, masks); + int ret = msix_setup_msi_descs(dev, entries, nvec, masks); if (ret) - goto out_free; + return ret; ret = pci_msi_setup_msi_irqs(dev, nvec, PCI_CAP_ID_MSIX); if (ret) - goto out_free; + return ret; /* Check if all MSI entries honor device restrictions */ ret = msi_verify_entries(dev); if (ret) - goto out_free; + return ret; + retain_ptr(dev); msix_update_entries(dev, entries); - goto out_unlock; + return 0; +} + +static int msix_setup_interrupts(struct pci_dev *dev, struct msix_entry *entries, + int nvec, struct irq_affinity *affd) +{ + struct irq_affinity_desc *masks __free(kfree) = + affd ? irq_create_affinity_masks(nvec, affd) : NULL; -out_free: - pci_free_msi_irqs(dev); -out_unlock: - msi_unlock_descs(&dev->dev); - return ret; + guard(msi_descs_lock)(&dev->dev); + return __msix_setup_interrupts(dev, entries, nvec, masks); } /** From patchwork Wed Mar 19 10:56:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 874916 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 95D092571C8; Wed, 19 Mar 2025 10:56:57 +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=1742381819; cv=none; b=BAtTunhu0ocJ3pQaEzmNrgKeJCY5zqlO7CVQ9+vZuOG4ZDz1viQEZ7h1WJSOK5peEEsUBq4N2nAz7BYsQ7tXIOkTyLrodAa3hOIx4vUmWKwRzlAdtnazMzG09GFmDOPcOoK+VF6zFx0B3xMdXqNLtWUWvWG327ZkQ/7CbbZqQzg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742381819; c=relaxed/simple; bh=hLSVkCmZq3sAZQvJDN0JoJ4G2z0ZgsLWhv3mMKL51JQ=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=cSGx3wD3CkU5IeJzRM/Ugowlswl3ZcByt69AoILl+CYNHOf0C8mfqEv/w5mKPMaNGriPBT9L/bM1hCk7YG/PDJipACfEJajokQ6A+7GmkDoDGfSnIfjy7jxrlr7W9xss5lFGDt5EBV2dxK47OyAHFqzigX8CPYsvd2L41qu9vvs= 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=bG/x4mi2; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=7TQdxDza; 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="bG/x4mi2"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="7TQdxDza" Message-ID: <20250319105506.624838146@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1742381816; 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=lVkhyqvX8Nx1WTN8VogxCpaEgAaZaZZ4hHPvZ1Nkv+M=; b=bG/x4mi2j7PLAIOEvQEIL2uiNI408Vb7y2bQPxAftORe42XzRMX2KgPF/MuRTfSxZAs4ZF UShesZf5jdlmDVZ9AGRd2edZFHcufYGs/INhHHvRtyMwwk72+ul/6ON+fX6HJMHG7Ti4J0 3+GtWq4cnFTwzgyOJkwOUU5fhOF/dsC3mRGaRoVxe2NX1aloDj359jry+kWsbFbCXNkEB2 Q6m8t5X6HlxTpoVflc590xSOblsHBoNGv4YAkVmnrraYATo3UD8y4URqJRJqJQYpH7e5Sc 3xFlWbuDjbPpwbjQYMMQ9kIVwasuC1/ksGRnsYDz518c0n0CYMbreahdlxp4Cw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1742381816; 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=lVkhyqvX8Nx1WTN8VogxCpaEgAaZaZZ4hHPvZ1Nkv+M=; b=7TQdxDzaZCmPNGySoOuULAIYOJhzDnT5up1+rHQR7uH7KkMSNdSTDaxjRdMYLbMItKzS3e UZt6RZphCDEK24Ag== From: Thomas Gleixner To: LKML Cc: Marc Zyngier , Peter Zijlstra , Jonathan Cameron , Michael Kelley , Wei Liu , Bjorn Helgaas , Haiyang Zhang , linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, Nishanth Menon , Dhruva Gole , Tero Kristo , Santosh Shilimkar , Logan Gunthorpe , Dave Jiang , Jon Mason , Allen Hubbe , ntb@lists.linux.dev, Wei Huang , Manivannan Sadhasivam , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Jonathan Cameron Subject: [patch V4 10/14] PCI: hv: Switch MSI descriptor locking to guard() References: <20250319104921.201434198@linutronix.de> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Wed, 19 Mar 2025 11:56:55 +0100 (CET) Convert the code to use the new guard(msi_descs_lock). No functional change intended. Signed-off-by: Thomas Gleixner Reviewed-by: Jonathan Cameron Reviewed-by: Michael Kelley Acked-by: Wei Liu Acked-by: Bjorn Helgaas Cc: Haiyang Zhang Cc: linux-hyperv@vger.kernel.org Cc: linux-pci@vger.kernel.org --- 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 Wed Mar 19 10:56:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 876446 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 647E325744B; Wed, 19 Mar 2025 10:56:59 +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=1742381821; cv=none; b=s4Rh9imOvkD8Ju7gZac6KmBUczT7msRhWJwv4+6YDsy7G1XhbPtFQHhkuK0MUjk9+Hi5BeRR1634ctxUjsTKZMCteDXXYJbIO6Lw5wZERS0KrpgTrqoDdQTpd9fKSVYMKnTAa4cWaYQW5wxKvroc9ZOyd1leyuqdSUcMTnLiWIs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742381821; c=relaxed/simple; bh=mhAnBDj7UNsieeEd6fsH6UA7xKJJMUAH06pexnkc/co=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=CxbqSYsMJa/VSGvRrHR9eTPAXKZWup5DxGPQXBIjTeP4kGHWFUiWsmNsDCkW/7EFvzV4CWAMwPkrw80bCRrTUrddgoPr+PR9H/BngP6Ob7+c+T4XpkPb66kjzWm76TecSKClfS5cjvEIhVzSpJzyfOJ//9RIcZ3Pc28kZ/4LPw8= 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=LayUfAC8; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=N59EZzs+; 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="LayUfAC8"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="N59EZzs+" Message-ID: <20250319105506.683663807@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1742381817; 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=7zYQHI6wysqOBWW3wWAAB2qCkqNkFBqgyapk6h+Eg7M=; b=LayUfAC8Hp3RHy5046WRS03AqnGIlHtVmyxnYeWvYS0ujlqp8JifuGGROP8YFU1WkVGuf5 YBw6/pdwXud1O8wqYoCrJmmKXpKwJX22RP87w8yCaPVoQiOoPM8QADwBQK4PmIRVJ9Opic jbpG/NPNszmVjDfmLtzDnx6wNgGpa2Oy0/rA9e7MyYD0UCaF4uaszDV4zi3qLyIaGrzMXa bd7rB4VMIaRkmXQANC/tC3baN4TtDXWpI82GAQdtbM7gBKcJ7NLcWt6bpaOdGxorHyYI7i SiEE9pZfhkuGz5dG/tlW9T/NprwcEx6kY5yX1deThqTSzBr3APesYmkbAcGUCQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1742381817; 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=7zYQHI6wysqOBWW3wWAAB2qCkqNkFBqgyapk6h+Eg7M=; b=N59EZzs+hpCJoTriuz/M3Lwke4VB2gJZxyTR5M16Qiwwvqwke9pkIGwCaeTX587IRYY1Et zA+WQY9vnnXgiQDA== From: Thomas Gleixner To: LKML Cc: Marc Zyngier , Peter Zijlstra , Bjorn Helgaas , Wei Huang , linux-pci@vger.kernel.org, Jonathan Cameron , Nishanth Menon , Dhruva Gole , Tero Kristo , Santosh Shilimkar , Logan Gunthorpe , Dave Jiang , Jon Mason , Allen Hubbe , ntb@lists.linux.dev, Michael Kelley , Wei Liu , Haiyang Zhang , linux-hyperv@vger.kernel.org, Manivannan Sadhasivam , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Jonathan Cameron Subject: [patch V4 11/14] PCI/MSI: Provide a sane mechanism for TPH References: <20250319104921.201434198@linutronix.de> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Wed, 19 Mar 2025 11:56:57 +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 Acked-by: 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 Wed Mar 19 10:56: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: 874915 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 75358257AF8; Wed, 19 Mar 2025 10:57: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=1742381823; cv=none; b=Uxqek66zsxxjuKiFs5I1xCQhpMkVXMdOBUszYkm2rg8GTUIdubiXsjjtdLhSEAt21msKwHatxQP1CYnvlidsywkcTrzy/rSaqW5w4GzheKmFkwvzBEj642EWo/5vbaRKhiU0ch83RG8VmrYwmsVqWuR8zdAFYR0xvMWsJe9GDck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742381823; c=relaxed/simple; bh=E6ojSlXDDpZwhps4bcq+Z1kJm8Jbl9Yz/9TMVcfaEXI=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=VOC9dwByKKeimdXZ/ZtamwZ3WLewVKXTcjgLfRHk27lpvQEotB/khkATGHLMQ3hponZPBFJCnUJ5pgMq2aBHq5chvI8212GscnC2pHlnH6IHK8XET4Xf/evzPkokxckItLv/pd0d3OWfWu3dKxJesZMUi6OY4ZopqA0F3PVu3YI= 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=RFRzkeWR; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=KFl+VRg8; 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="RFRzkeWR"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="KFl+VRg8" Message-ID: <20250319105506.744271447@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1742381819; 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=zEd2EPU9vSb5Rk/swNEbuNZK8DTDHgjmBk10fmc/doE=; b=RFRzkeWR+8zvWHDUaf1TYazFLDRiHEe6U8g9+kWOT1JYvBsPsa6OGa4S+0sK3kEQ9ZDf4V Wy/6we42WIs+D5+0qJpuL1aT+LjMAisogUnObTXLITt1A6OWdrHeQmiznUhWdzIO6U6PXk 1gu7L3keUYzfkbu3JLa6jniSU/C9ltRKncv/QK0Sjbjal9mCdc3M0bJFc/v0Opy9lJEQo4 ukgrCQqoy1poIoJhIIQNqC/DaJH76L+I1WzxdCBYT+gHXahP8qTIekAjUZWDXS5H/g55o2 GI2sllG3jmjQuUVRNsRedhl3bl9LOG1ek9woJY3V/QJltI1MtHSmB3S8bzC5pQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1742381819; 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=zEd2EPU9vSb5Rk/swNEbuNZK8DTDHgjmBk10fmc/doE=; b=KFl+VRg81tUYV77YxrIf/MMUm4DPgTuCfAM12XmU342QMGG8hQcm3O2OXdDPRlKuSqjPS7 fp9s8xoYcgQNwLAA== From: Thomas Gleixner To: LKML Cc: Marc Zyngier , Peter Zijlstra , Bjorn Helgaas , Wei Huang , linux-pci@vger.kernel.org, Jonathan Cameron , Nishanth Menon , Dhruva Gole , Tero Kristo , Santosh Shilimkar , Logan Gunthorpe , Dave Jiang , Jon Mason , Allen Hubbe , ntb@lists.linux.dev, Michael Kelley , Wei Liu , Haiyang Zhang , linux-hyperv@vger.kernel.org, Manivannan Sadhasivam , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Jonathan Cameron Subject: [patch V4 12/14] PCI/TPH: Replace the broken MSI-X control word update References: <20250319104921.201434198@linutronix.de> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Wed, 19 Mar 2025 11:56:58 +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 Acked-by: 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 Wed Mar 19 10:57:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 876445 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 0F0E62586CE; Wed, 19 Mar 2025 10:57:01 +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=1742381823; cv=none; b=lS/T8eQ0WmRSxcqhRCYLA4IxWxdTOqmZVjVHaosRmuDhCS8QWYFKVQwlgJrRMPruDcxv6e9bVeauJ8rqKR/DWZ9T2SqG19gdBrG7Ynti69DdLDCzqukxju2ASvjW0+Ps4x2r92pC0r4wTbt8KR07cY0rTtkvvjl5/mXBYF4klOs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742381823; c=relaxed/simple; bh=dNfcM8PpvFdc9/dBbg5dWxwPwXOwU8ZviHU26rWUaVw=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=bl+4CgkidDHI9TcQYTAKASv42Om81z2sC2Ejl0GcOObWUqpCG1K8/bDgPdYqittD6d1vkRH1tgJ/mZzEptbmIOr8iJbMfzqIElS1uQM4et5KBCiFeEudr8vuA8Ya25gXw8wOv1762k+5Vc8S5Y2dguFHg7AC5dqIZaJYiqNAONg= 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=t76/HqZa; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=rRrUV8bf; 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="t76/HqZa"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="rRrUV8bf" Message-ID: <20250319105506.805529593@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1742381820; 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=DT9Y4McgdSXWRdQEhAdRPvaJ55/Pj75U/vwMpJXDRBg=; b=t76/HqZa8NXhYd25BbUl0A9/9Zd0n7Bxi8x+rCMoHckA3uJCuobvsb5nMXxIqOkEpzceEK /cc5GCeSKEM/DaOBCsibjjyrGmbCnBQ8GIAv5n7r3dE2/RQjnyUvKCVC3zED+7aIVQSe/6 oF97uYv5k41T+b/2jKz7LATv+u1f3dk7iCvFkW9ch9T0TGHWryU9fG+0pjjtrMSzSP7G7O KGYTvk8ogmSPYCKLqu+t5E+eiaPjMIqLRF77FpJqKkiDTw6aClzchgSxbXqqT3CwjFelwf PZOC+xroddCkygwGAdCjQDqPDVp8/MilfQql1p+5cdQPSRDm2bIuk0BKJhJ8Eg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1742381820; 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=DT9Y4McgdSXWRdQEhAdRPvaJ55/Pj75U/vwMpJXDRBg=; b=rRrUV8bf8FBDzZXnOqUF2I8BggTG5p90ClpFET9GrQiFAg0OMVizxS+gHH3Xoeyf2r+217 tk4dt/kO0dT6s1CQ== From: Thomas Gleixner To: LKML Cc: Marc Zyngier , Peter Zijlstra , Manivannan Sadhasivam , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Jonathan Cameron , Nishanth Menon , Dhruva Gole , Tero Kristo , Santosh Shilimkar , Logan Gunthorpe , Dave Jiang , Jon Mason , Allen Hubbe , ntb@lists.linux.dev, Michael Kelley , Wei Liu , Bjorn Helgaas , Haiyang Zhang , linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, Wei Huang , Jonathan Cameron Subject: [patch V4 13/14] scsi: ufs: qcom: Remove the MSI descriptor abuse References: <20250319104921.201434198@linutronix.de> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Wed, 19 Mar 2025 11:57:00 +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 and use a custom cleanup function to simplify the error path. 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 --- V4: Fix inverse NULL pointer check and use __free() for error paths - James --- drivers/ufs/host/ufs-qcom.c | 85 ++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 37 deletions(-) --- a/drivers/ufs/host/ufs-qcom.c +++ b/drivers/ufs/host/ufs-qcom.c @@ -1782,25 +1782,38 @@ 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; } +static void ufs_qcom_irq_free(struct ufs_qcom_irq *uqi) +{ + for (struct ufs_qcom_irq *q = uqi; q->irq; q++) + devm_free_irq(q->hba->dev, q->irq, q->hba); + + platform_device_msi_free_irqs_all(uqi->hba->dev); + devm_kfree(uqi->hba->dev, uqi); +} + +DEFINE_FREE(ufs_qcom_irq, struct ufs_qcom_irq *, if (_T) ufs_qcom_irq_free(_T)) + 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; int nr_irqs, ret; if (host->esi_enabled) @@ -1811,6 +1824,14 @@ 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]; + + struct ufs_qcom_irq *qi __free(ufs_qcom_irq) = + devm_kcalloc(hba->dev, nr_irqs, sizeof(*qi), GFP_KERNEL); + if (!qi) + return -ENOMEM; + /* Preset so __free() has a pointer to hba in all error paths */ + qi[0].hba = hba; + ret = platform_device_msi_init_and_alloc_irqs(hba->dev, nr_irqs, ufs_qcom_write_msi_msg); if (ret) { @@ -1818,41 +1839,31 @@ static int ufs_qcom_config_esi(struct uf return ret; } - 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; + return ret; } } - 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; - } + retain_ptr(qi); - return ret; + 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; } /* From patchwork Wed Mar 19 10:57:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 874914 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 90B6625744B; Wed, 19 Mar 2025 10:57:04 +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=1742381826; cv=none; b=CT10r1+bQUm6jzB0oTfg8JdSjio7GHmhAtDzwltXNHCv6zLO59P0XkU1tVrLM/24luYgtyoVneV0S1AapsE+NCD6WVL+YgTxZxtYiWVcoFIW2TCV+uBwVV2T98YaIa2oKOCCby7MkVVvNU1+YNEi4lwy6Ep9+M9eq2ey7o30iCY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742381826; c=relaxed/simple; bh=ssriv9UH6GIB/QKdfAdOk80drmt5lDBuDkd1XkOsiE0=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=kc4Wv9bnq9R69gxBYEk2CWBffkWJ/qmvggcOyo9EcKoXG50sh47S21x9WAWRp7VNZ41fCeSlNLh+AhOcmOp82sYNnKZ1LDV6jTI31ShCkGZWalvmLE7gL7Y7MSzJ0ONLVgEUer/md3c6vYCm6swE7Y9EAf62upfRJZtxsFK6Qrw= 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=UpGxDyVF; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=1phf6hT4; 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="UpGxDyVF"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="1phf6hT4" Message-ID: <20250319105506.864699741@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1742381822; 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=DJS/MIuQIZyuzMhWo7bDK73OC9n1sTuX5FBXKqqm6mY=; b=UpGxDyVF0R1wBUxx66iI7swqRGmg9632kkYAxPyZAPgM4xJ27/xpYxecVg22I1J0eqdkil nAWOENQ+xaUKbQMhrd2UtL6sN+WLifNNgK0iAMAJL2yQGt6tyCrSdWBk4aUujiEWQ+1jAZ FSuoiAwlgAhLKVGCGFvEw9oe3pbN38pFIHbxf/t3TNpX7kyWQ4yGXe3BnIzN17ihzvhxNT B/0JeJbruwoEJzxNALqlHemGsXUlDZ81avSmgWqAjIrdFYzFPDTJBKX7YVXyfhLCLyV5X/ 7uMD8TC/EGrxQx8y5lpETp+uU/HCQkgF9JXZhNhGAp1Xu/nnSWW7f9yv5s7BiQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1742381822; 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=DJS/MIuQIZyuzMhWo7bDK73OC9n1sTuX5FBXKqqm6mY=; b=1phf6hT4SmXq+7Lh4D3JcBX7vfH4Rn2FSaEHLGg7yTbiCEULM2yawtTU3jI9pqeWFsKdp/ kKfaHAr2lfc8xPBw== From: Thomas Gleixner To: LKML Cc: Marc Zyngier , Peter Zijlstra , Jonathan Cameron , Jonathan Cameron , Nishanth Menon , Dhruva Gole , Tero Kristo , Santosh Shilimkar , Logan Gunthorpe , Dave Jiang , Jon Mason , Allen Hubbe , ntb@lists.linux.dev, Michael Kelley , Wei Liu , Bjorn Helgaas , Haiyang Zhang , linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, Wei Huang , Manivannan Sadhasivam , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org Subject: [patch V4 14/14] genirq/msi: Rename msi_[un]lock_descs() References: <20250319104921.201434198@linutronix.de> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Wed, 19 Mar 2025 11:57:01 +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 change. 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 @@ -338,26 +338,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)