From patchwork Sat Nov 27 01:22:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 1560548 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=ORqp+FjQ; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=oAwMdRVK; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4J1DY30Mhbz9sRR for ; Sat, 27 Nov 2021 12:29:11 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348896AbhK0BcT (ORCPT ); Fri, 26 Nov 2021 20:32:19 -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 Date: Sat, 27 Nov 2021 02:22:30 +0100 (CET) Precedence: bulk List-ID: X-Mailing-List: linux-pci@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)