Received: by 2002:a05:7412:2a8a:b0:fc:a2b0:25d7 with SMTP id u10csp103161rdh; Tue, 6 Feb 2024 21:41:26 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCViZ45DDtEWcR6iajBkE/mI8Yknpe2wSv88vVlCJcVM4kA+j7myKI0ZY2sbuwH8T8bVlBEjhJ/BDbyhP2U9LPaUqNe+gv/NrnDF6VmNbQ== X-Google-Smtp-Source: AGHT+IFoWP+Zd7wcYq7h88Guae8wMrAmkUVfzshqg9YNEmIs/cil3ctTK+vRTeUVZYka1DIDDL5b X-Received: by 2002:a17:906:2111:b0:a38:406d:5dd4 with SMTP id 17-20020a170906211100b00a38406d5dd4mr1899597ejt.36.1707284486534; Tue, 06 Feb 2024 21:41:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707284486; cv=pass; d=google.com; s=arc-20160816; b=ee5W5Hqb1IWFnE8LcNJimtyfJ9EIBdLOPkOcXPUizglmRgLF8wDrfUDYGUCC6L/rUg 33brVjq9rXu07s7ieawy5R0Upka9TE/dd06CmA/y3lPdP0tQ97nfpvE+pQcbtX1XMZmo juzePzGrhU2aOHH8HQyweh12ZGqm1uQhLUdOlKsKeXD8b4FhLkU2nnNNtD/SgP7+Wr90 jHfeXQlwiAqtwxFvzfpjwwPYTPsefRqKVbk0lvMkKQCkMlf+BMr6+nL8GiNpg0Yb1+Zv ZWTjdPQIrFG3aOmQAQoiTWwBn2fTyVrojxSstDp1btANCoIuZxlqfC/7GimuHAy+RY1s 4iOg== 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=Zx5GRXnWUOd/uBEcPP1EbmX0fuOmpD0Y9RuWQ1YiO24=; b=bG97Yd8aan1l+VjwZ7wCkNRX4j/HNHNLXeyzweUlHd6sJEDWLeC3ScL/6xdyD7A4Cc LJC8vhPbq5idncL8KkH7bXYBtiPj9PciHS7XL0DZNt7dAVWppYl8LyYQMa4jN5vepC6+ pjPHGjX4esnwr2fFlvAS3/sJiompi6TFWOasOY/JfZ2uOB7pmobuh3UaZxKgun+app3G gDWnlc0Nlb6M/3p3nrKs4yE2CLMEOzqDAql2H/7wa2bPn0qlreNvapI6Swh2FL/dbK0x EOnRmWdEEzzczrnvwIt2hzEoSRzLcE7EQcUIlu1NTi1SWsEBqZTPU1QAHdQIozqpyduE CHow==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=lawxtIYs; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-55810-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55810-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCUovJuawMJxfH9Kbb2cZkKdh59k5N7F8N1+LSyHnG92PU1DCtqcAywrwlO37sWZUHo/MO5iotWuL5Ghy0yjNOtJOVEHsGTfmcNyuMke0A== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id g14-20020a1709063b0e00b00a34a303509fsi415914ejf.990.2024.02.06.21.41.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 21:41:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55810-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=lawxtIYs; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-55810-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55810-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 7B9161F278F2 for ; Wed, 7 Feb 2024 01:42:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 868D61D55C; Wed, 7 Feb 2024 01:39:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="lawxtIYs" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (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 01F531CFB9; Wed, 7 Feb 2024 01:39:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707269987; cv=none; b=Vxd7ex12bAljOXkexnjhKCfJSYvmqDUUTAb+h8L0Fafpr3YubAAMhR1go8TlGVTC+1Hb1NMOGG/1mhL0GwRcao6ZJA0zDUxOQLpoaXMFI/4oM2gpQgUAj7qi1VLhCVVgme2X8KsGKXrpNE6j8MpuEoYb2tmmNg8lBHNbByqBwGo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707269987; c=relaxed/simple; bh=/X4TrhX+nZJIzlXo68bwW7s6fFh3t8lvBg+xVPbIT+8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=u9HTLxf/S/YNYQYa3qMTl69BhZULBmPlx7IMrQfGcp6aAm62w2RF0YlsHEf1gZQg752Kx7gQaDD9ne3Q33By+RXbExWXiyZ/cKuYLMhWrSJkEvOXXJfRjx6MgGn5rJICvr4Gz1YFlnA/qrD7pI4J1uP1eU4zuhaQFHaDPVwScqM= 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=lawxtIYs; arc=none smtp.client-ip=192.198.163.11 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=1707269986; x=1738805986; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/X4TrhX+nZJIzlXo68bwW7s6fFh3t8lvBg+xVPbIT+8=; b=lawxtIYsYcOMBFrpMCX/tHLH92FH7NQeGK3X8wICComTT1uBWnhsKEnO l8dnyleDihIYf/ExVnc4dBjmfBJnwtEDmqzZn9KVGwfCp9bq5EbHNtWjU N6sCGNvOL9hFvxnAnxVjj9PFC4YttnWyYoAazJtPSSfwBR6agwm5u4qGO xmCkUFwfBlMdJIkDjkSf/q4B+vERN0z+6GwuaiT3V+04Hlic+tEQv5/Tr t/DvY0iFwQifvMQGg5xeP6nH4FZR+yIOx4jOO/hLd1uUS6b5eeMiRCNo+ q5hBwpxhbA6YQtSGPd81xi12quC5BeMLYtae/KoW7OrP+V2vXBNaIK4ML g==; X-IronPort-AV: E=McAfee;i="6600,9927,10976"; a="11534155" X-IronPort-AV: E=Sophos;i="6.05,248,1701158400"; d="scan'208";a="11534155" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2024 17:39:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,248,1701158400"; d="scan'208";a="1190677" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmviesa010.fm.intel.com with ESMTP; 06 Feb 2024 17:39:41 -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 , Joel Granados , iommu@lists.linux.dev, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Lu Baolu , Jason Gunthorpe Subject: [PATCH v12 08/16] iommu: Prepare for separating SVA and IOPF Date: Wed, 7 Feb 2024 09:33:17 +0800 Message-Id: <20240207013325.95182-9-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240207013325.95182-1-baolu.lu@linux.intel.com> References: <20240207013325.95182-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