Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1468070rdb; Wed, 6 Dec 2023 22:48:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IGxREQB5Tq/H5LA1Wv9fYG/dnkKe7Y3fN82ufGQL+VBzpt/gIW6cSUZLsbrnQlrD/tdd6Op X-Received: by 2002:a05:6a21:6d9d:b0:18f:afc:4e02 with SMTP id wl29-20020a056a216d9d00b0018f0afc4e02mr2417032pzb.125.1701931703807; Wed, 06 Dec 2023 22:48:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701931703; cv=none; d=google.com; s=arc-20160816; b=RAiS4tL12+MSW1e5zrJtELURxKqw6L9gB5cjdmJeE66AWU5kWHfG12PkELGsPOuuOS 66v/dKXTYnNkvtbqZH7vCCIoz4Uuzx+LgXIsfSo9Nxa2ugkWgY0ZmL/mm2rzvxIAtzPJ ZAk6DA/CV8N5va6f9tQd6OzyNFOIsryZDOvAVDTb2K+oDkIJU9kxuiP1Fmir46JOMjUz 6izelR/Uo/Qvzzzkda34Ndr158jUghVMmHrxIIGOzjP/2jn8t+Z0iYCaYXfXiTC27yMI 2Hge7G/6eRGExta5cke2eukY/mioSfWZwdVXeUnMUdOX3+CsAccSkhu08+LLAVN940RW 78JQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=n2GzHR5NpziD3/wK3LbrzmoBjUQxHH88UTQgtEX4Id4=; fh=K/qmpcI9AI+O4asH00/RnUuMoQe0aGwja9gZ0+Y3GjE=; b=sUve3/HVjh/6wGhG6HGt+/6uSECq98PxqFMoS1VJCQqipYUa3BN1r86O/sTy9sJf+a +uDjw+MrpPs3oOrrFuoCxqtD3Bif5LIILd+KZq2BWNmEj7frSlejLu//ifLTmtFgy2we uZ5iUH6nFtGMKrQgrezm9Em5VnFL4MQCzSBxbPu40ghVtJwSTq5HLKBj8nAK1fMPv7VP sxz1PK13KGIyt0uPhDrcg6Ujqdcs5QhiVR/MtBbrir0a2zFCibqtz6krWOzDdOYS1Lc6 ty/BwwAWb4amKNGmhvOftOZui3TBQaJNn94swVVKRzjusCbUdmjVXmnXtpOXyMLrGQ5A NG3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WOEO+DRv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id a16-20020a056a000c9000b006cd904d87ddsi733948pfv.44.2023.12.06.22.48.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 22:48:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WOEO+DRv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 8318980BD515; Wed, 6 Dec 2023 22:48:11 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229620AbjLGGru (ORCPT + 99 others); Thu, 7 Dec 2023 01:47:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbjLGGrs (ORCPT ); Thu, 7 Dec 2023 01:47:48 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C5ED137; Wed, 6 Dec 2023 22:47:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701931674; x=1733467674; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=TiGWAFZ8wUXfH4a/f6Y2gaB+BMEAe3q7aJwlZyWhLdU=; b=WOEO+DRvq5Jb2PszcoiMHOZf0lPOOvwiG89KBH+wlpNrIv1HO1/X26ui cMm2V/v5tXT6ZhzBH1MwrYbZf8HGN3YBsTzc/NahUEWvOCVl+Q3AKAdvW 5fP0ketN+MIGGNMq5diM2iXRgmxTfo+NhvXPUGI2mtpze6kz/U3zhRRFs 1+fLMCo4vGJPVF4plga8ZUILzvhvicipgmSj+INgaoTqtHfZos83UYnEj zXLcidA1xx+6FlrIU05QDVCj2zoz1ONMUV9eaH2ubtxV70X/iaj+UDb+I IQumftfIoc/T6PtBelAFa9VW7EcLGY+C58B4xqTfQ80iYH/cv3MH/Af2I Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10916"; a="1014877" X-IronPort-AV: E=Sophos;i="6.04,256,1695711600"; d="scan'208";a="1014877" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Dec 2023 22:47:54 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10916"; a="771611314" X-IronPort-AV: E=Sophos;i="6.04,256,1695711600"; d="scan'208";a="771611314" Received: from allen-box.sh.intel.com ([10.239.159.127]) by orsmga002.jf.intel.com with ESMTP; 06 Dec 2023 22:47:48 -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 v8 00/12] iommu: Prepare to deliver page faults to user space Date: Thu, 7 Dec 2023 14:42:56 +0800 Message-Id: <20231207064308.313316-1-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 06 Dec 2023 22:48:11 -0800 (PST) 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 ~ 12] Improve iopf framework for iommufd use. 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-v8 Change log: v8: - 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 (12): 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 include/linux/iommu.h | 267 +++++++++--- 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 | 25 +- drivers/iommu/intel/svm.c | 6 +- drivers/iommu/io-pgfault.c | 412 +++++++++++------- drivers/iommu/iommu-sva.c | 67 ++- drivers/iommu/iommu.c | 233 ---------- MAINTAINERS | 1 - drivers/iommu/Kconfig | 4 + drivers/iommu/Makefile | 3 +- drivers/iommu/intel/Kconfig | 1 + 15 files changed, 551 insertions(+), 767 deletions(-) delete mode 100644 drivers/iommu/iommu-sva.h delete mode 100644 include/uapi/linux/iommu.h -- 2.34.1