Received: by 2002:a05:7412:d008:b0:f9:6acb:47ec with SMTP id bd8csp284894rdb; Tue, 19 Dec 2023 17:28:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IHqMlreiY6OjmoQlEZqj35jgZmWN+QKFzndD72ue4J0a5FhtCCHT7hZLOnokY0CNY6HTX9A X-Received: by 2002:a50:cd8e:0:b0:552:f6df:a32d with SMTP id p14-20020a50cd8e000000b00552f6dfa32dmr3674352edi.21.1703035725832; Tue, 19 Dec 2023 17:28:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703035725; cv=none; d=google.com; s=arc-20160816; b=fU41RE1wJR21unPNfFZWZU+IszdkKRVpxmnvSRSMwiKrInH6V5CmldqTJ6qC1ixZLn At6t2BPAUAbqKwLzscToNsiZsIrNkS8153h8bO7xByxiPkMLxUt0IFvV0tW9jwrVI1vC ET+PHXLGIoqIlPIBbbNcfS+NbduNQfdk7LPI77GoQz7RBgdIn86YT5U5lUBCckPt2kNr aayfn/fdkaTvtn/Su5SRp4t/BsHVLVsVGEOKQl+2waceESUGJcyzL7wM+6DmkMZqNvdr zJUyBN/eUyLroPAfFhkn6uFR25Bgx5tJxWgxgIdoFryX+1wlcswFAfANWxDMX2NSSdbS lvGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=eE8urdK8RWKBgeV25U1TdTyPCa8eLNODSRcQM6oxrBs=; fh=K/qmpcI9AI+O4asH00/RnUuMoQe0aGwja9gZ0+Y3GjE=; b=YWg/0erdJznNZdX1XVOGX2dPLMLrSeUHi4SASgVju4/pHCGTDVuIKSamayHSkVawxl UZPnVLCJ9zOevx+nPXJh1O/0RQVlG9dBCSgn71c3RApbNvZB4p9I0Zimp/tH/0CQ65ze pU6/tC/lMid7aJ/GRcpUlWee3K74gXQQERbscGy5oLOlNKwZOiEUyIrQaDMDIxAxBnkO 0EFtzLJkPjlMLYnFVYfn23M8HU6mb1x3JiumIwqEYe9T28c0A5eN16tgwxCsDz8o83l7 Sr0m5wzHLz40tzkA+o4YoY0284qJzSZzH7Z7+xAM9h2jC4WO7IpA6QJudOHul7DkpEz+ TDKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WJdo2omT; spf=pass (google.com: domain of linux-kernel+bounces-6234-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6234-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id g7-20020a50d5c7000000b00553b51c17a3si434755edj.661.2023.12.19.17.28.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 17:28:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-6234-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WJdo2omT; spf=pass (google.com: domain of linux-kernel+bounces-6234-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6234-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 6BD1A1F25AB8 for ; Wed, 20 Dec 2023 01:28:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2AA956128; Wed, 20 Dec 2023 01:28:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="WJdo2omT" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (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 BFA5B5252; Wed, 20 Dec 2023 01:28:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1703035712; x=1734571712; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=1aH4PFeRXZv8XYBxr213qu3vMLQdqg4KdWeLBJkjeOA=; b=WJdo2omT/1WWZWK5djbebtucs4ViK4h6Hok46M8Wt9KdyM+O3LCEfhWc 88ygKO6NwsYZF5hfpSW3uPWTgz2cnbQ6U/Co9EmlVUan+uFvMpi523MCq zGjo1MgBdZRqxK2HMSvN+u16BcjW0IrJXNGAatcYpR7tPxGMWqcQnmiMb o9sLVtKTFuJyjXsksQiyeYgwnk31uZgNk5LGUPo+GodCYALTz4cEzWDcO 3IwHoxjnD7reVoX05pf/qPe2gNglhu4O1Se+cpp1Z2txEJBRX2KL8Ggxk xEyulopdjvbfHGoSw+A2Qfv+SZH1VWnABiznVOcUnsQaCLe/bo3VGrTDl Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10929"; a="2965706" X-IronPort-AV: E=Sophos;i="6.04,290,1695711600"; d="scan'208";a="2965706" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Dec 2023 17:28:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10929"; a="1023319048" X-IronPort-AV: E=Sophos;i="6.04,290,1695711600"; d="scan'208";a="1023319048" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmsmga006.fm.intel.com with ESMTP; 19 Dec 2023 17:28:26 -0800 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian , Jean-Philippe Brucker , Nicolin Chen Cc: Yi Liu , Jacob Pan , Longfang Liu , Yan Zhao , iommu@lists.linux.dev, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v9 00/14] iommu: Prepare to deliver page faults to user space Date: Wed, 20 Dec 2023 09:23:18 +0800 Message-Id: <20231220012332.168188-1-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit When a user-managed page table is attached to an IOMMU, it is necessary to deliver IO page faults to user space so that they can be handled appropriately. One use case for this is nested translation, which is currently being discussed in the mailing list. I have posted a RFC series [1] that describes the implementation of delivering page faults to user space through IOMMUFD. This series has received several comments on the IOMMU refactoring, which I am trying to address in this series. The major refactoring includes: - [PATCH 01 ~ 04] Move include/uapi/linux/iommu.h to include/linux/iommu.h. Remove the unrecoverable fault data definition. - [PATCH 05 ~ 06] Remove iommu_[un]register_device_fault_handler(). - [PATCH 07 ~ 10] Separate SVA and IOPF. Make IOPF a generic page fault handling framework. - [PATCH 11 ~ 14] Improve iopf framework. This is also available at github [2]. [1] https://lore.kernel.org/linux-iommu/20230530053724.232765-1-baolu.lu@linux.intel.com/ [2] https://github.com/LuBaolu/intel-iommu/commits/preparatory-io-pgfault-delivery-v9 Change log: v9: - Protecting the assignment of dev->iommu->fault_param with RCU. - Extending the fault parameter's lifetime to the entire path of iopf handling. - Since iopf_queue_flush_dev() can only be called before iopf_queue_remove_device(), there's no need to hold a reference count. - Improve iopf_queue_remove_device() as per Jason's comments on the device removal sequence from the iopf queue. This will likely require changes to the iommu drivers, which are supposed to be addressed in separate series. - Track the iopf_group as a whole instead of the last fault within the group to simplify the fault report and response paths. - PATCH 01 ~ 11 are in good shapes now. v8: https://lore.kernel.org/linux-iommu/20231207064308.313316-1-baolu.lu@linux.intel.com/ - Drop PATCH 12/12 as it is no longer necessary to drain page requests page requests during PASID translation changes. - Separate PATCH 11/12 into two distinct patches. The first patch refines locking scheme for protecting per-device fault data, while the second patch replaces mutex with RCU to enhance locking efficiency. - PATCH 01 ~ 10 are in good shapes now. v7: https://lore.kernel.org/linux-iommu/20231115030226.16700-1-baolu.lu@linux.intel.com/ - Rebase to v6.7-rc1. - Export iopf_group_response() for global use. - Release lock when calling iopf handler. - The whole series has been verified to work for SVA case on Intel platforms by Zhao Yan. Add her Tested-by to affected patches. v6: https://lore.kernel.org/linux-iommu/20230928042734.16134-1-baolu.lu@linux.intel.com/ - [PATCH 09/12] Check IS_ERR() against the iommu domain. [Jingqi/Jason] - [PATCH 12/12] Rename the comments and name of iopf_queue_flush_dev(), no functionality changes. [Kevin] - All patches rebased on the latest iommu/core branch. v5: https://lore.kernel.org/linux-iommu/20230914085638.17307-1-baolu.lu@linux.intel.com/ - Consolidate per-device fault data management. (New patch 11) - Improve iopf_queue_flush_dev(). (New patch 12) v4: https://lore.kernel.org/linux-iommu/20230825023026.132919-1-baolu.lu@linux.intel.com/ - Merge iommu_fault_event and iopf_fault. They are duplicate. - Move iommu_report_device_fault() and iommu_page_response() to io-pgfault.c. - Move iommu_sva_domain_alloc() to iommu-sva.c. - Add group->domain and use it directly in sva fault handler. - Misc code refactoring and refining. v3: https://lore.kernel.org/linux-iommu/20230817234047.195194-1-baolu.lu@linux.intel.com/ - Convert the fault data structures from uAPI to kAPI. - Merge iopf_device_param into iommu_fault_param. - Add debugging on domain lifetime for iopf. - Remove patch "iommu: Change the return value of dev_iommu_get()". - Remove patch "iommu: Add helper to set iopf handler for domain". - Misc code refactoring and refining. v2: https://lore.kernel.org/linux-iommu/20230727054837.147050-1-baolu.lu@linux.intel.com/ - Remove unrecoverable fault data definition as suggested by Kevin. - Drop the per-device fault cookie code considering that doesn't make much sense for SVA. - Make the IOMMU page fault handling framework generic. So that it can available for use cases other than SVA. v1: https://lore.kernel.org/linux-iommu/20230711010642.19707-1-baolu.lu@linux.intel.com/ Lu Baolu (14): iommu: Move iommu fault data to linux/iommu.h iommu/arm-smmu-v3: Remove unrecoverable faults reporting iommu: Remove unrecoverable fault data iommu: Cleanup iopf data structure definitions iommu: Merge iopf_device_param into iommu_fault_param iommu: Remove iommu_[un]register_device_fault_handler() iommu: Merge iommu_fault_event and iopf_fault iommu: Prepare for separating SVA and IOPF iommu: Make iommu_queue_iopf() more generic iommu: Separate SVA and IOPF iommu: Refine locking for per-device fault data management iommu: Use refcount for fault data access iommu: Improve iopf_queue_remove_device() iommu: Track iopf group instead of last fault include/linux/iommu.h | 265 ++++++++---- drivers/iommu/intel/iommu.h | 2 +- drivers/iommu/iommu-sva.h | 71 --- include/uapi/linux/iommu.h | 161 ------- .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 14 +- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 51 +-- drivers/iommu/intel/iommu.c | 28 +- drivers/iommu/intel/svm.c | 6 +- drivers/iommu/io-pgfault.c | 408 +++++++++++------- drivers/iommu/iommu-sva.c | 71 ++- drivers/iommu/iommu.c | 233 ---------- MAINTAINERS | 1 - drivers/iommu/Kconfig | 4 + drivers/iommu/Makefile | 3 +- drivers/iommu/intel/Kconfig | 1 + 15 files changed, 532 insertions(+), 787 deletions(-) delete mode 100644 drivers/iommu/iommu-sva.h delete mode 100644 include/uapi/linux/iommu.h -- 2.34.1