Received: by 2002:a05:7412:7c14:b0:fa:6e18:a558 with SMTP id ii20csp180864rdb; Mon, 22 Jan 2024 00:05:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IHUuhMmb4+s94jnyjVg3Lye8xCmnZOFTYNgFu3ycCdj9YThl9sgF9zV8IVruI6k9MvqTGuL X-Received: by 2002:a17:902:b618:b0:1d4:cbfa:5b4 with SMTP id b24-20020a170902b61800b001d4cbfa05b4mr1543789pls.51.1705910752809; Mon, 22 Jan 2024 00:05:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705910752; cv=pass; d=google.com; s=arc-20160816; b=qW61xa2Snt+u1a1xkrD9lN9x+OoXG2nb3sySU60Iy4jNDRH6rVSSAS2OeCty+42Eii BCJE1Z7Ws39gzlwz2Amqxp76NTvD+KY0N4RHo0G8IhI1O/G0ehHYz9wpZK0v9OBHJ/x5 UnGSO/6uco2Fv2ByyLIb1wlDCXeqtPg0f/7N+eYv5dHWjSoKUK3Fxje8lfWf0kpjH59a q9yWoMLFtju/GfyrSy3fDrJPKm6jBe9/NPSqasZInH5eYO/L3k7hCja6vI3ji0GtcVuB 4bjbhlDOUjVU7FdE2/MByKgaoIbY6NsJjWHwVPeeebKQkIcItGKz0mWYlNWICmkBXAWW J6qw== ARC-Message-Signature: i=2; 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=1Ovnw+tKhBMfMscqMiO4LYnCVGxMyJ3RChjG2DF4+bY=; fh=0puWr8qDwzaogZbtOaymnvHkPoKpvOitlnMkTa2cyaw=; b=exRvKrUG9l10zbkOnIxSCaQR3g6x8UJR9uZRq9kvS4BSeIOHJDjIzODiN1eUSBWUu4 QwT2wCd//140VXyvWjOnabnRR0UjjhZqHsxAl+P32aQKasp9L0fd299I7ajESlnX/WIe 8ctvGZ0RRSv6+NK+YUZOH3mFc/0jIVPE2YZ3cWNH8l6RBwSREKz1v0s0nS3ExQy/FigD Gv4wK6m0EXBNTIUG22Q2Yd1bVoSgaEaZWgHiJLj2huzRS10gjirq/47tf9h5RmCNAd31 gNjXPWmYaN/stXiJRolXmJbSXN6iETr4+cOUKyinjxYHgI2DptYZzVOEBRnNqrsaACMa o/rg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WKD0imqa; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-32353-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32353-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id c11-20020a170902d48b00b001d7043abf5csi7833051plg.418.2024.01.22.00.05.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 00:05:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-32353-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WKD0imqa; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-32353-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32353-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 613F1B23DDE for ; Mon, 22 Jan 2024 05:52:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D2EC720DF6; Mon, 22 Jan 2024 05:49:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="WKD0imqa" Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) (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 4839220DE0; Mon, 22 Jan 2024 05:49:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=134.134.136.100 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705902550; cv=none; b=pH9UUAVMso+5BVOUumj6oDKUdFQ+U/eiF0TlMLwYCx9JhXugobOubPvGUnsrzccFVxeXcvhVXofRN8LZdbYwkM1i9Ui5E4qaAb4ULQR+mj9JeaqIwTCd+qjsMMCM3Wm3lnKt//2i/TWvJlrxsOqryZJ2q5a5vU8wmMtTO94NIV0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705902550; c=relaxed/simple; bh=/X4TrhX+nZJIzlXo68bwW7s6fFh3t8lvBg+xVPbIT+8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=E/r4XUU5i6WCmKBpjoHYm+3cF71IER0CpWZ/lwoU6+UdvvBd+S96PVPJbi8hQTYI809PKgbV7mFVuUQcfYdJW9jGtvGxO19izZKrn8K3wl1sWE/Ti0bTZmEj80rBce9ueoZyM2zlIOhqwY7nxAxOtdYHn+QNVyEAiBQ2VCFvH78= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=WKD0imqa; arc=none smtp.client-ip=134.134.136.100 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=1705902547; x=1737438547; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/X4TrhX+nZJIzlXo68bwW7s6fFh3t8lvBg+xVPbIT+8=; b=WKD0imqaRkSEcmQAU2WQM8quRs8CKW/uqVEp4UziwlZ0ieDRrq3kDu3C DRtCL7Nt1rNlqT9Pg6PFOOvFWktYuTetjkLiYt+3NCcQ1GCPQZRMsJmGw FQiGTQRDn+d657PPbxjvrVuLn0bf3UroIsbN7/22xKvmnyskveFF+wj0d 2oMJJaZJMEGExgXU+T25dtEeY9Wc2buFLdWlqDo9ecg+uUJ8pw4V5gDpm UHpezWQJ5njtEZvAoqILCido7lmsXA947XYIiz51+C8p+UGrFTYRoppEd mB+ZfgNHiMfkjdYaACKTZiB08mSwb+r/mzUdlHzu7DO6d1a8H572EMeMX g==; X-IronPort-AV: E=McAfee;i="6600,9927,10960"; a="467487146" X-IronPort-AV: E=Sophos;i="6.05,211,1701158400"; d="scan'208";a="467487146" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jan 2024 21:49:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10960"; a="1116763975" X-IronPort-AV: E=Sophos;i="6.05,211,1701158400"; d="scan'208";a="1116763975" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmsmga005.fm.intel.com with ESMTP; 21 Jan 2024 21:49:02 -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 , Jason Gunthorpe Subject: [PATCH v10 08/16] iommu: Prepare for separating SVA and IOPF Date: Mon, 22 Jan 2024 13:43:00 +0800 Message-Id: <20240122054308.23901-9-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240122054308.23901-1-baolu.lu@linux.intel.com> References: <20240122054308.23901-1-baolu.lu@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Move iopf_group data structure to iommu.h to make it a minimal set of faults that a domain's page fault handler should handle. Add a new function, iopf_free_group(), to free a fault group after all faults in the group are handled. This function will be made global so that it can be called from other files, such as iommu-sva.c. Move iopf_queue data structure to iommu.h to allow the workqueue to be scheduled out of this file. This will simplify the sequential patches. Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe Reviewed-by: Kevin Tian Reviewed-by: Yi Liu Tested-by: Yan Zhao Tested-by: Longfang Liu --- include/linux/iommu.h | 20 +++++++++++++++++++- drivers/iommu/io-pgfault.c | 37 +++++++++++++------------------------ 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 2320548a90f8..c9d4f175f121 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -41,7 +41,6 @@ struct iommu_dirty_ops; struct notifier_block; struct iommu_sva; struct iommu_dma_cookie; -struct iopf_queue; #define IOMMU_FAULT_PERM_READ (1 << 0) /* read */ #define IOMMU_FAULT_PERM_WRITE (1 << 1) /* write */ @@ -126,6 +125,25 @@ struct iopf_fault { struct list_head list; }; +struct iopf_group { + struct iopf_fault last_fault; + struct list_head faults; + struct work_struct work; + struct device *dev; +}; + +/** + * struct iopf_queue - IO Page Fault queue + * @wq: the fault workqueue + * @devices: devices attached to this queue + * @lock: protects the device list + */ +struct iopf_queue { + struct workqueue_struct *wq; + struct list_head devices; + struct mutex lock; +}; + /* iommu fault flags */ #define IOMMU_FAULT_READ 0x0 #define IOMMU_FAULT_WRITE 0x1 diff --git a/drivers/iommu/io-pgfault.c b/drivers/iommu/io-pgfault.c index 10d48eb72608..c7e6bbed5c05 100644 --- a/drivers/iommu/io-pgfault.c +++ b/drivers/iommu/io-pgfault.c @@ -13,24 +13,17 @@ #include "iommu-sva.h" -/** - * struct iopf_queue - IO Page Fault queue - * @wq: the fault workqueue - * @devices: devices attached to this queue - * @lock: protects the device list - */ -struct iopf_queue { - struct workqueue_struct *wq; - struct list_head devices; - struct mutex lock; -}; +static void iopf_free_group(struct iopf_group *group) +{ + struct iopf_fault *iopf, *next; -struct iopf_group { - struct iopf_fault last_fault; - struct list_head faults; - struct work_struct work; - struct device *dev; -}; + list_for_each_entry_safe(iopf, next, &group->faults, list) { + if (!(iopf->fault.prm.flags & IOMMU_FAULT_PAGE_REQUEST_LAST_PAGE)) + kfree(iopf); + } + + kfree(group); +} static int iopf_complete_group(struct device *dev, struct iopf_fault *iopf, enum iommu_page_response_code status) @@ -50,9 +43,9 @@ static int iopf_complete_group(struct device *dev, struct iopf_fault *iopf, static void iopf_handler(struct work_struct *work) { + struct iopf_fault *iopf; struct iopf_group *group; struct iommu_domain *domain; - struct iopf_fault *iopf, *next; enum iommu_page_response_code status = IOMMU_PAGE_RESP_SUCCESS; group = container_of(work, struct iopf_group, work); @@ -61,7 +54,7 @@ static void iopf_handler(struct work_struct *work) if (!domain || !domain->iopf_handler) status = IOMMU_PAGE_RESP_INVALID; - list_for_each_entry_safe(iopf, next, &group->faults, list) { + list_for_each_entry(iopf, &group->faults, list) { /* * For the moment, errors are sticky: don't handle subsequent * faults in the group if there is an error. @@ -69,14 +62,10 @@ static void iopf_handler(struct work_struct *work) if (status == IOMMU_PAGE_RESP_SUCCESS) status = domain->iopf_handler(&iopf->fault, domain->fault_data); - - if (!(iopf->fault.prm.flags & - IOMMU_FAULT_PAGE_REQUEST_LAST_PAGE)) - kfree(iopf); } iopf_complete_group(group->dev, &group->last_fault, status); - kfree(group); + iopf_free_group(group); } /** -- 2.34.1