From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.2 required=3.0 tests=BAYES_00,DATE_IN_PAST_06_12, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8989C433DB for ; Sun, 28 Feb 2021 06:41:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9645C64DFF for ; Sun, 28 Feb 2021 06:41:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230442AbhB1GlZ (ORCPT ); Sun, 28 Feb 2021 01:41:25 -0500 Received: from mga09.intel.com ([134.134.136.24]:22647 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230423AbhB1GlO (ORCPT ); Sun, 28 Feb 2021 01:41:14 -0500 IronPort-SDR: 815xBiSbry//imiBAL5cGslhdyf3r0qVCTsXltCIuOW84wnCz6LJnGAUiFZ/Gnvv62XyAH5+Vj RdDf5tE01ozA== X-IronPort-AV: E=McAfee;i="6000,8403,9908"; a="186323905" X-IronPort-AV: E=Sophos;i="5.81,211,1610438400"; d="scan'208";a="186323905" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2021 22:33:10 -0800 IronPort-SDR: nuEUzNsKDtMUhF1RUH0X9vun2GR3Nd9i1TG6TUlh3vQvNaz+wKrJkzsPMRrEKHdic1AsTQ4egz ou1Ew5FbN91g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,211,1610438400"; d="scan'208";a="517029734" Received: from otc-wp-03.jf.intel.com ([10.54.39.79]) by orsmga004.jf.intel.com with ESMTP; 27 Feb 2021 22:33:10 -0800 From: Jacob Pan To: LKML , Joerg Roedel , "Lu Baolu" , David Woodhouse , iommu@lists.linux-foundation.org, cgroups@vger.kernel.org, Tejun Heo , Li Zefan , Johannes Weiner , Jean-Philippe Brucker Cc: Alex Williamson , Eric Auger , Jason Gunthorpe , Jonathan Corbet , Raj Ashok , "Tian, Kevin" , Yi Liu , Wu Hao , Dave Jiang , Jacob Pan Subject: [PATCH V4 13/18] iommu/ioasid: Add a workqueue for cleanup work Date: Sat, 27 Feb 2021 14:01:21 -0800 Message-Id: <1614463286-97618-14-git-send-email-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1614463286-97618-1-git-send-email-jacob.jun.pan@linux.intel.com> References: <1614463286-97618-1-git-send-email-jacob.jun.pan@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org An IOASID can have multiple users, such as IOMMU driver, KVM, and device drivers. The atomic IOASID notifier is used to inform users of IOASID state change. For example, the IOASID_NOTIFY_UNBIND event is issued when the IOASID is no longer bound to an address space. This requires ordered actions among users to tear down their contexts. Not all work can be handled in the atomic notifier handler. This patch introduces a shared, ordered workqueue for all IOASID users who wish to perform work asynchronously upon notification. Signed-off-by: Jacob Pan --- drivers/iommu/ioasid.c | 25 +++++++++++++++++++++++++ include/linux/ioasid.h | 1 + 2 files changed, 26 insertions(+) diff --git a/drivers/iommu/ioasid.c b/drivers/iommu/ioasid.c index 28a2e9b6594d..d42b39ca2c8b 100644 --- a/drivers/iommu/ioasid.c +++ b/drivers/iommu/ioasid.c @@ -32,6 +32,9 @@ static ioasid_t ioasid_capacity = PCI_PASID_MAX; static ioasid_t ioasid_capacity_avail = PCI_PASID_MAX; static DEFINE_XARRAY_ALLOC(ioasid_sets); +/* Workqueue for IOASID users to do cleanup upon notification */ +static struct workqueue_struct *ioasid_wq; + struct ioasid_set_nb { struct list_head list; struct notifier_block *nb; @@ -1281,6 +1284,12 @@ int ioasid_register_notifier_mm(struct mm_struct *mm, struct notifier_block *nb) } EXPORT_SYMBOL_GPL(ioasid_register_notifier_mm); +bool ioasid_queue_work(struct work_struct *work) +{ + return queue_work(ioasid_wq, work); +} +EXPORT_SYMBOL_GPL(ioasid_queue_work); + void ioasid_unregister_notifier_mm(struct mm_struct *mm, struct notifier_block *nb) { struct ioasid_set_nb *curr; @@ -1303,7 +1312,23 @@ void ioasid_unregister_notifier_mm(struct mm_struct *mm, struct notifier_block * } EXPORT_SYMBOL_GPL(ioasid_unregister_notifier_mm); +static int __init ioasid_init(void) +{ + ioasid_wq = alloc_ordered_workqueue("ioasid_wq", 0); + if (!ioasid_wq) + return -ENOMEM; + + return 0; +} + +static void __exit ioasid_cleanup(void) +{ + destroy_workqueue(ioasid_wq); +} + MODULE_AUTHOR("Jean-Philippe Brucker "); MODULE_AUTHOR("Jacob Pan "); MODULE_DESCRIPTION("IO Address Space ID (IOASID) allocator"); MODULE_LICENSE("GPL"); +module_init(ioasid_init); +module_exit(ioasid_cleanup); diff --git a/include/linux/ioasid.h b/include/linux/ioasid.h index 9624b665f810..4547086797df 100644 --- a/include/linux/ioasid.h +++ b/include/linux/ioasid.h @@ -135,6 +135,7 @@ void ioasid_set_for_each_ioasid(struct ioasid_set *sdata, void *data); int ioasid_register_notifier_mm(struct mm_struct *mm, struct notifier_block *nb); void ioasid_unregister_notifier_mm(struct mm_struct *mm, struct notifier_block *nb); +bool ioasid_queue_work(struct work_struct *work); #else /* !CONFIG_IOASID */ static inline void ioasid_install_capacity(ioasid_t total) { -- 2.25.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.2 required=3.0 tests=BAYES_00,DATE_IN_PAST_06_12, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08EF2C43381 for ; Sun, 28 Feb 2021 06:33:28 +0000 (UTC) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BA15B64E58 for ; Sun, 28 Feb 2021 06:33:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BA15B64E58 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=iommu-bounces@lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 4718E84044; Sun, 28 Feb 2021 06:33:27 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id BMQMc5v-lRBa; Sun, 28 Feb 2021 06:33:25 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTP id CFC028403B; Sun, 28 Feb 2021 06:33:24 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id F3830C000B; Sun, 28 Feb 2021 06:33:23 +0000 (UTC) Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 07283C000B for ; Sun, 28 Feb 2021 06:33:18 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id BC3A44F0A4 for ; Sun, 28 Feb 2021 06:33:13 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 7hiCYzS6vbBp for ; Sun, 28 Feb 2021 06:33:12 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by smtp4.osuosl.org (Postfix) with ESMTPS id B01B24F0A3 for ; Sun, 28 Feb 2021 06:33:11 +0000 (UTC) IronPort-SDR: B4CCPnYEc6NIVlff5ghS5SOhODzf7F4pgsUSvjc0zrZco9E7k1Qk0HQe6L3UMdEv9anXSg3YTC k2MO6iw/Mf7w== X-IronPort-AV: E=McAfee;i="6000,8403,9908"; a="183755904" X-IronPort-AV: E=Sophos;i="5.81,211,1610438400"; d="scan'208";a="183755904" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2021 22:33:10 -0800 IronPort-SDR: nuEUzNsKDtMUhF1RUH0X9vun2GR3Nd9i1TG6TUlh3vQvNaz+wKrJkzsPMRrEKHdic1AsTQ4egz ou1Ew5FbN91g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,211,1610438400"; d="scan'208";a="517029734" Received: from otc-wp-03.jf.intel.com ([10.54.39.79]) by orsmga004.jf.intel.com with ESMTP; 27 Feb 2021 22:33:10 -0800 From: Jacob Pan To: LKML , Joerg Roedel , "Lu Baolu" , David Woodhouse , iommu@lists.linux-foundation.org, cgroups@vger.kernel.org, Tejun Heo , Li Zefan , Johannes Weiner , Jean-Philippe Brucker Subject: [PATCH V4 13/18] iommu/ioasid: Add a workqueue for cleanup work Date: Sat, 27 Feb 2021 14:01:21 -0800 Message-Id: <1614463286-97618-14-git-send-email-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1614463286-97618-1-git-send-email-jacob.jun.pan@linux.intel.com> References: <1614463286-97618-1-git-send-email-jacob.jun.pan@linux.intel.com> Cc: "Tian, Kevin" , Dave Jiang , Raj Ashok , Jonathan Corbet , Alex Williamson , Jason Gunthorpe , Wu Hao X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Development issues for Linux IOMMU support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: iommu-bounces@lists.linux-foundation.org Sender: "iommu" An IOASID can have multiple users, such as IOMMU driver, KVM, and device drivers. The atomic IOASID notifier is used to inform users of IOASID state change. For example, the IOASID_NOTIFY_UNBIND event is issued when the IOASID is no longer bound to an address space. This requires ordered actions among users to tear down their contexts. Not all work can be handled in the atomic notifier handler. This patch introduces a shared, ordered workqueue for all IOASID users who wish to perform work asynchronously upon notification. Signed-off-by: Jacob Pan --- drivers/iommu/ioasid.c | 25 +++++++++++++++++++++++++ include/linux/ioasid.h | 1 + 2 files changed, 26 insertions(+) diff --git a/drivers/iommu/ioasid.c b/drivers/iommu/ioasid.c index 28a2e9b6594d..d42b39ca2c8b 100644 --- a/drivers/iommu/ioasid.c +++ b/drivers/iommu/ioasid.c @@ -32,6 +32,9 @@ static ioasid_t ioasid_capacity = PCI_PASID_MAX; static ioasid_t ioasid_capacity_avail = PCI_PASID_MAX; static DEFINE_XARRAY_ALLOC(ioasid_sets); +/* Workqueue for IOASID users to do cleanup upon notification */ +static struct workqueue_struct *ioasid_wq; + struct ioasid_set_nb { struct list_head list; struct notifier_block *nb; @@ -1281,6 +1284,12 @@ int ioasid_register_notifier_mm(struct mm_struct *mm, struct notifier_block *nb) } EXPORT_SYMBOL_GPL(ioasid_register_notifier_mm); +bool ioasid_queue_work(struct work_struct *work) +{ + return queue_work(ioasid_wq, work); +} +EXPORT_SYMBOL_GPL(ioasid_queue_work); + void ioasid_unregister_notifier_mm(struct mm_struct *mm, struct notifier_block *nb) { struct ioasid_set_nb *curr; @@ -1303,7 +1312,23 @@ void ioasid_unregister_notifier_mm(struct mm_struct *mm, struct notifier_block * } EXPORT_SYMBOL_GPL(ioasid_unregister_notifier_mm); +static int __init ioasid_init(void) +{ + ioasid_wq = alloc_ordered_workqueue("ioasid_wq", 0); + if (!ioasid_wq) + return -ENOMEM; + + return 0; +} + +static void __exit ioasid_cleanup(void) +{ + destroy_workqueue(ioasid_wq); +} + MODULE_AUTHOR("Jean-Philippe Brucker "); MODULE_AUTHOR("Jacob Pan "); MODULE_DESCRIPTION("IO Address Space ID (IOASID) allocator"); MODULE_LICENSE("GPL"); +module_init(ioasid_init); +module_exit(ioasid_cleanup); diff --git a/include/linux/ioasid.h b/include/linux/ioasid.h index 9624b665f810..4547086797df 100644 --- a/include/linux/ioasid.h +++ b/include/linux/ioasid.h @@ -135,6 +135,7 @@ void ioasid_set_for_each_ioasid(struct ioasid_set *sdata, void *data); int ioasid_register_notifier_mm(struct mm_struct *mm, struct notifier_block *nb); void ioasid_unregister_notifier_mm(struct mm_struct *mm, struct notifier_block *nb); +bool ioasid_queue_work(struct work_struct *work); #else /* !CONFIG_IOASID */ static inline void ioasid_install_capacity(ioasid_t total) { -- 2.25.1 _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jacob Pan Subject: [PATCH V4 13/18] iommu/ioasid: Add a workqueue for cleanup work Date: Sat, 27 Feb 2021 14:01:21 -0800 Message-ID: <1614463286-97618-14-git-send-email-jacob.jun.pan@linux.intel.com> References: <1614463286-97618-1-git-send-email-jacob.jun.pan@linux.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1614463286-97618-1-git-send-email-jacob.jun.pan-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: iommu-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org Sender: "iommu" To: LKML , Joerg Roedel , Lu Baolu , David Woodhouse , iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org, cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Tejun Heo , Li Zefan , Johannes Weiner , Jean-Philippe Brucker Cc: "Tian, Kevin" , Dave Jiang , Raj Ashok , Jonathan Corbet , Alex Williamson , Jason Gunthorpe , Wu Hao An IOASID can have multiple users, such as IOMMU driver, KVM, and device drivers. The atomic IOASID notifier is used to inform users of IOASID state change. For example, the IOASID_NOTIFY_UNBIND event is issued when the IOASID is no longer bound to an address space. This requires ordered actions among users to tear down their contexts. Not all work can be handled in the atomic notifier handler. This patch introduces a shared, ordered workqueue for all IOASID users who wish to perform work asynchronously upon notification. Signed-off-by: Jacob Pan --- drivers/iommu/ioasid.c | 25 +++++++++++++++++++++++++ include/linux/ioasid.h | 1 + 2 files changed, 26 insertions(+) diff --git a/drivers/iommu/ioasid.c b/drivers/iommu/ioasid.c index 28a2e9b6594d..d42b39ca2c8b 100644 --- a/drivers/iommu/ioasid.c +++ b/drivers/iommu/ioasid.c @@ -32,6 +32,9 @@ static ioasid_t ioasid_capacity = PCI_PASID_MAX; static ioasid_t ioasid_capacity_avail = PCI_PASID_MAX; static DEFINE_XARRAY_ALLOC(ioasid_sets); +/* Workqueue for IOASID users to do cleanup upon notification */ +static struct workqueue_struct *ioasid_wq; + struct ioasid_set_nb { struct list_head list; struct notifier_block *nb; @@ -1281,6 +1284,12 @@ int ioasid_register_notifier_mm(struct mm_struct *mm, struct notifier_block *nb) } EXPORT_SYMBOL_GPL(ioasid_register_notifier_mm); +bool ioasid_queue_work(struct work_struct *work) +{ + return queue_work(ioasid_wq, work); +} +EXPORT_SYMBOL_GPL(ioasid_queue_work); + void ioasid_unregister_notifier_mm(struct mm_struct *mm, struct notifier_block *nb) { struct ioasid_set_nb *curr; @@ -1303,7 +1312,23 @@ void ioasid_unregister_notifier_mm(struct mm_struct *mm, struct notifier_block * } EXPORT_SYMBOL_GPL(ioasid_unregister_notifier_mm); +static int __init ioasid_init(void) +{ + ioasid_wq = alloc_ordered_workqueue("ioasid_wq", 0); + if (!ioasid_wq) + return -ENOMEM; + + return 0; +} + +static void __exit ioasid_cleanup(void) +{ + destroy_workqueue(ioasid_wq); +} + MODULE_AUTHOR("Jean-Philippe Brucker "); MODULE_AUTHOR("Jacob Pan "); MODULE_DESCRIPTION("IO Address Space ID (IOASID) allocator"); MODULE_LICENSE("GPL"); +module_init(ioasid_init); +module_exit(ioasid_cleanup); diff --git a/include/linux/ioasid.h b/include/linux/ioasid.h index 9624b665f810..4547086797df 100644 --- a/include/linux/ioasid.h +++ b/include/linux/ioasid.h @@ -135,6 +135,7 @@ void ioasid_set_for_each_ioasid(struct ioasid_set *sdata, void *data); int ioasid_register_notifier_mm(struct mm_struct *mm, struct notifier_block *nb); void ioasid_unregister_notifier_mm(struct mm_struct *mm, struct notifier_block *nb); +bool ioasid_queue_work(struct work_struct *work); #else /* !CONFIG_IOASID */ static inline void ioasid_install_capacity(ioasid_t total) { -- 2.25.1