Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2383476pxb; Sat, 27 Feb 2021 22:43:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJzwKUYQgGBaopQz5X9WHyVzfyWeN7Ry2vq63YbTeY8ygN/E+ErvtYh+LKf77dxUVXXRYE1L X-Received: by 2002:a17:906:f10c:: with SMTP id gv12mr10484912ejb.407.1614494581443; Sat, 27 Feb 2021 22:43:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614494581; cv=none; d=google.com; s=arc-20160816; b=q4m+q8k1OGWSIxPodNU6ERq5sxEqnY1RXfkHj1kiqdyk8as0S/jKxzK4BSaX43Wp4e 6BJ4mpyvuTsFevICus+/9O1Ery7e0yIibV1xLaZU0MrExo4FN/e7GyFpFK+9g5BM2Uax +iO6FzLka/aun94egnp4LZydm53wq5ukh7AeA9jsshweFZUSDN4qxHcGwY130LQ5jEAP 4AHX8h1f8qgOi4K+eHOavytbXp8bkBtTZ++etgebzQMLjQjZPC+ellCl+B9oXpF2U+C4 AwR4IE1GGNuUi5G2yILKBl+gt9mypTDWIGon/W5s25HjGMt8bSpaxaWs4Jb9dP4NX49D jc6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:ironport-sdr:ironport-sdr; bh=D7k8fEIrQTStuDL8htC4ZA3ydRtgxozMwmaw5D3B1Dc=; b=s7WKQ4G31alLy3qhLbZau9sxlb6TFm1aUXTSu7W0WYWx3l8wo0oy9ukIFnA2qHtP0I od7+e7JS4cci4XFN+I9vZ1Htik+cCPZ4DMI7HyvaAeu7vsBkPSQ1b2kv39PXkmspwytw ru6cDrOSGU16qf0Df1djhAbFFzN1UFWVRsAKpGsy4wf81t6xbdVXmJMn5+VwZ9h51/JG iiyh0jfDB388QtQRmr074SBgQfuZq0ESvKG7+MtqdBUUJ83ov/HF7otozOzvQ8budp7s 9nFzcgGJVVdiTJPVSFxA+4OdnIYXdfwqikefu+I+q7xo1T5V0xFgnE1AMFm1mRCTEuR5 E7qg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e7si8980245ejz.428.2021.02.27.22.42.39; Sat, 27 Feb 2021 22:43:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230408AbhB1GlV (ORCPT + 99 others); Sun, 28 Feb 2021 01:41:21 -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