From patchwork Wed Feb 7 01:33:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 197787 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2063947dyb; Tue, 6 Feb 2024 23:39:28 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUo9lfb6490xSj4LcpcSpRNpN8n6uA6qSoEER7hlv1YpmqDTF5HQWZPGIzEcZGfzWQ8zIbyNUVu3eql5g+Hj7Ol/LqujQ== X-Google-Smtp-Source: AGHT+IEGawIJgirbUyCINWdt3hyb4rMQmASUmRK93HZRwC+TXmnE7vYylgLrXnzFG3+utxm/xcNX X-Received: by 2002:a05:6870:63aa:b0:219:7a41:348e with SMTP id t42-20020a05687063aa00b002197a41348emr5313442oap.49.1707291568422; Tue, 06 Feb 2024 23:39:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707291568; cv=pass; d=google.com; s=arc-20160816; b=vm3H1RfORzYhkl0qIPbd1TQvHeE1XGrcOUSJ1XAYqLw6s5M5hWhbNgg5Ly1RLe6pF4 Rw7JwUjfCRMABnAh+4cmKOSXFOQkLUV5d0AXCdggZUjMr8GsQ8XJVyl6q5pwWmTg4UE8 Qe4Ps21U7zS2anoXTIs1zoinf3pGhVZLhQePrDU+nvmXfSMb8Y8w3lrn+ktf8jl+/bAa 84sH2WdEvbBkGgATBByBHYfwwN2btW73k9sfoWqRQpBNcunaJfDcRuUWJWITXi3FEqDP 6U4zYz0NTRQmP6K2ocTSkp1htrnmm7ybOJLSIdyGf7wxvoTkiHXBFlpXNcG9dKIus5N/ WD9A== 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=LNBirm4dY9EaS3ToM1rmvonCT7ZCWCdW9T6+kEiPS6A=; b=ywMuea9swR1MLHgV+WFIOanvuUUngS+lEi55uYyJzhycOkKyGVYqvDgh9rETSL+Ne2 osDVmyslPxFLsoSdDljKQR3GFWs8fpW6C01J/lMJwfDxKe1Ip0/VKFqg4fX+92FNAg3Y BuWI25IFCOuUmmnGzeaaRcqZKan8/RtcSQ4ZCA9OVBxH+qyDEaFQfkz81KcMJzr1aGYS bHdgUEY8ewLtxFJGtDDD042e1QVOSgyoAG2E9g4IvijI8vm8NcI3Hb8QEerD5O+Kr+/4 w2sjNcxlpJtR78GtPUwHGwtibzVnKugobsBZkURIWk69vhhiMW4JFyG/VB1BMXmR3eA1 ZRgg==; 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-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55810-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCVvft2r9VsZ4rC3A3v84suYQeTxLZ+YfUYDgGxfNGSro7yS0WQntxwD4QmYov/RNntt2NwZP9mp6UVrQJ4iA6JFkFlM0g== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id x24-20020a63b218000000b005d849f5352csi908270pge.795.2024.02.06.23.39.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 23:39:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55810-ouuuleilei=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=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-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55810-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 40153B27851 for ; Wed, 7 Feb 2024 01:42:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A27281EB40; Wed, 7 Feb 2024 01:39:50 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790224963418058589 X-GMAIL-MSGID: 1790224963418058589 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); } /**