Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4AA79C433F5 for ; Sat, 27 Nov 2021 01:29:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347963AbhK0BcZ (ORCPT ); Fri, 26 Nov 2021 20:32:25 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:40506 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348605AbhK0BaO (ORCPT ); Fri, 26 Nov 2021 20:30:14 -0500 Message-ID: <20211126232734.411769132@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1637976151; 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=dWlRgqR+0drt9PwtC3seDhr2BnCncrRnkVfFxsvT5DI=; b=ORqp+FjQyylJmjTUIXnpl2W3/2oMtLzKwyKbRsyw2DfIf8FbSlPGN20MYOubkIaQPtnOkx zi1LFX0B8c8xYYm+Qd8yJNCcGmBAQ1Y8Qsq0cF/8Do1hEYoxi7xwOQ0Ha7+7Q3adJ2H6wU 5Z/KA11NvzTWKJ3lERiA5rZKIQBlmEtyqTVAN1HDHLiz940Ee07vKvBYMlmZ/M9DRAekLJ pLRvpc+fvRECo+ew/XdgFL3hsx0xLGqb03CV5/TRk3NZWZhQvUyF7RPIgcLZhG/XCcUsmV AzMxSqYaJM/VltFXsFFe4tv++EUOcfHKTl1Dw6QK+TvhEDCCjhsNA8OPq2yRog== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1637976151; 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=dWlRgqR+0drt9PwtC3seDhr2BnCncrRnkVfFxsvT5DI=; b=oAwMdRVKeFKMPJ6Cy3BdvL9YEsvKROcJgbOIRSdt5ODq8RcJU0NdLrJrChsr+oNSSuygSc FIQvMP4ptDkZBaBw== From: Thomas Gleixner To: LKML Cc: Bjorn Helgaas , Marc Zygnier , Alex Williamson , Kevin Tian , Jason Gunthorpe , Megha Dey , Ashok Raj , linux-pci@vger.kernel.org, Greg Kroah-Hartman , linux-s390@vger.kernel.org, Heiko Carstens , Christian Borntraeger , Jon Mason , Dave Jiang , Allen Hubbe , linux-ntb@googlegroups.com Subject: [patch 02/32] genirq/msi: Add mutex for MSI list protection References: <20211126230957.239391799@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Sat, 27 Nov 2021 02:22:30 +0100 (CET) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For upcoming runtime extensions of MSI-X interrupts it's required to protect the MSI descriptor list. Add a mutex to struct msi_device_data and provide lock/unlock functions. Signed-off-by: Thomas Gleixner --- include/linux/msi.h | 6 ++++++ kernel/irq/msi.c | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) --- a/include/linux/msi.h +++ b/include/linux/msi.h @@ -3,6 +3,7 @@ #define LINUX_MSI_H #include +#include #include #include #include @@ -146,6 +147,7 @@ struct msi_desc { * @attrs: Pointer to the sysfs attribute group * @platform_data: Platform-MSI specific data * @list: List of MSI descriptors associated to the device + * @mutex: Mutex protecting the MSI list */ struct msi_device_data { raw_spinlock_t lock; @@ -153,6 +155,7 @@ struct msi_device_data { const struct attribute_group **attrs; struct platform_msi_priv_data *platform_data; struct list_head list; + struct mutex mutex; }; int msi_setup_device_data(struct device *dev); @@ -187,6 +190,9 @@ static inline unsigned int msi_get_virq( return ret < 0 ? 0 : ret; } +void msi_lock_descs(struct device *dev); +void msi_unlock_descs(struct device *dev); + /* Helpers to hide struct msi_desc implementation details */ #define msi_desc_to_dev(desc) ((desc)->dev) #define dev_to_msi_list(dev) (&(dev)->msi.data->list) --- a/kernel/irq/msi.c +++ b/kernel/irq/msi.c @@ -116,12 +116,37 @@ int msi_setup_device_data(struct device raw_spin_lock_init(&md->lock); INIT_LIST_HEAD(&md->list); + mutex_init(&md->mutex); dev->msi.data = md; devres_add(dev, md); return 0; } /** + * msi_lock_descs - Lock the MSI descriptor storage of a device + * @dev: Device to operate on + */ +void msi_lock_descs(struct device *dev) +{ + if (WARN_ON_ONCE(!dev->msi.data)) + return; + mutex_lock(&dev->msi.data->mutex); +} +EXPORT_SYMBOL_GPL(msi_lock_descs); + +/** + * msi_unlock_descs - Unlock the MSI descriptor storage of a device + * @dev: Device to operate on + */ +void msi_unlock_descs(struct device *dev) +{ + if (WARN_ON_ONCE(!dev->msi.data)) + return; + mutex_unlock(&dev->msi.data->mutex); +} +EXPORT_SYMBOL_GPL(msi_unlock_descs); + +/** * __msi_get_virq - Return Linux interrupt number of a MSI interrupt * @dev: Device to operate on * @index: MSI interrupt index to look for (0-based)