From patchwork Mon Feb 12 01:22:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 199592 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2259765dyd; Sun, 11 Feb 2024 22:20:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IGeA9e2fp+lsN/ynEZFOe6JEADppjrd+JifNYqjrQwVA1KG14dLBN8nx0pEkVpX7xkioT6e X-Received: by 2002:a25:b10d:0:b0:dc7:47a2:ecbe with SMTP id g13-20020a25b10d000000b00dc747a2ecbemr5875068ybj.31.1707718800891; Sun, 11 Feb 2024 22:20:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707718800; cv=pass; d=google.com; s=arc-20160816; b=pj7xetjufttpxlcveZY+a21CJ/une/XjYZLiU52yDVWgHOzu+CVo6qxcQTIWFP6zrw 4b05jy6n3S2+DkUQEp9MXT3OLmtYHaRzMAlnMKFuHAGsPhmasu65pVIOdqE8UbvQjGWB 6X9R4ivGMMdsS60FErOJzMrNWCcjWoI+eP0jOS1ovA7eaNBlWo9ec671ZYfjZmefDiU2 B+UQAFid+oEUXcfQEgD54Ze6hSwOWnWl0DbkGrHB63clozPGS8Msdnd0YSuzauhDC4OD sHcY8QIlOIBgoKwcVfvjiRHDipMaoaRVH4/m7OSF9R5ctKr2LuyCt4Mi950ZUpiDQULp 31Dg== 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=jycPdUvo4tWfcNtpimJPkvEgKezXrDRgU1r+XygY1ns=; fh=H1hIhLIb7A+McipuKvnkASRWcgzWKD0rZXyuVqKO5Mw=; b=CJ9kjxxdwai16B0Crl/eNfRJbcZqMDgbj1h/tbS6JfzBFYayu0FispL4EdV2oDS7t1 rd8MJLVt/ckBF1LT2EJaW80dVqi+NSIkE2JoP9tiyPicgvPkgMYJSzlJb+AC6pZRShgo kit1NJckGo9NwXMe00V2slQ2JG2JNBqTTtxILI5rUuzh5sNKeHzn1VMrNfjMLGQXPbzy XPh/jih3nqzhRlpNGWCQsS2eemNABFjUCh08xwEi8RU0VP41tFI3xnj/7MJxtuoiOsfn i+aPZt08e6q82/cu7JrPBo2x+bZloaFIUn+GEiT5Id3NveDGUNTe1019W3gkVCQLEm7i 8hFA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VPkm9Hky; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61048-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61048-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCVR5iHu4jw3P37VGja+20jyi4b1aE0qQMexO1Zbf6s3rjwaIaW0x3oqAx0jH52ZRhsfoBhYaOJznomYCx2IRfFT0Y4CWA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id x37-20020a056a0018a500b006e04369998fsi4596833pfh.15.2024.02.11.22.20.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 22:20:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61048-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VPkm9Hky; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61048-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61048-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id E6B37285E97 for ; Mon, 12 Feb 2024 01:31:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6865B14293; Mon, 12 Feb 2024 01:28:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="VPkm9Hky" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (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 F3C0111717; Mon, 12 Feb 2024 01:28:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707701329; cv=none; b=nUUrEdWWB7RbYWrEeWxkole4JoOvv/JC3e3DT+6V4sYm27V41hhLK13qX0EZx31xJH4Bwj33ZkHvrz867/QNs5T9YgLCAfRop3ykgxJNvwP8XUub9gi/Al+BSnz+7z5NvyfOnJcdTfRLWQ+UvBKTOCgCJvLmylhXxUBV9kziWds= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707701329; c=relaxed/simple; bh=nQSnxdM7XSa1aWIb1v4mMY0nZGRWhXyXA4CN17vWMXQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BUYEkpWJrKWBZTsDDXz3mhLiuj2qAN2JreuHpbqyY+wKmEkyK5+3jTZBWo6NLvHs7yC7tyY0eIGXMHK7AnphvVAjZ1qSdAUy1D1GlOl+WbrFeFhEW+D9/lnQPxbagZSDDoZwrQCs3exzo509Qp4VDjdxMageU9DqDQMlUtz5wBs= 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=VPkm9Hky; arc=none smtp.client-ip=198.175.65.15 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=1707701329; x=1739237329; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nQSnxdM7XSa1aWIb1v4mMY0nZGRWhXyXA4CN17vWMXQ=; b=VPkm9HkyFl4niuPJPwc1mVdDwQ4uNaxlsUu7Ecj+5c40rqk/HDoiG2xv xzE1RI+WlZgaZncmOKZ8AJcwrAWnKX4q78QY+rtxtT6BciT0WCMm39Isb qpPGnzUgSOJCIsBHcOvk5beMxxiO63PlQUx5/SIRBluffE4b4CKSoCm+8 Hs1KbMJ2nv7jNbqX8nNkVZiqPjbv3x2DG4zvQJaBbHyrW79C7O1C1U3DW zM/DqxKyRHeztM5S7BUeOMCf0jyAzCkGXDXvrcHxrK9W/n2E6/4VOd100 mR/tA+3lb2Sz4v0B10E+ElTQ7ebBUZqjsWNRLXzOfK6sQOfF8o15OK6zT Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="5502133" X-IronPort-AV: E=Sophos;i="6.05,261,1701158400"; d="scan'208";a="5502133" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Feb 2024 17:28:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,261,1701158400"; d="scan'208";a="7132211" Received: from allen-box.sh.intel.com ([10.239.159.127]) by orviesa005.jf.intel.com with ESMTP; 11 Feb 2024 17:28:44 -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 v13 08/16] iommu: Prepare for separating SVA and IOPF Date: Mon, 12 Feb 2024 09:22:19 +0800 Message-Id: <20240212012227.119381-9-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240212012227.119381-1-baolu.lu@linux.intel.com> References: <20240212012227.119381-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790672949129522131 X-GMAIL-MSGID: 1790672949129522131 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 2e0cbd263962..b352198cb030 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); } /**