From patchwork Wed Nov 15 03:02:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 165148 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:a59:b0:164:83eb:24d7 with SMTP id 25csp2356959rwb; Tue, 14 Nov 2023 19:07:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IFVlgj081mE3l67+08yR5OEXna+2gs3LVrb1QptfEl1+1feIAFiHJCBE/HaLxKaNJyw9jiT X-Received: by 2002:a05:6358:d088:b0:16b:f6be:224d with SMTP id jc8-20020a056358d08800b0016bf6be224dmr4761158rwb.5.1700017668010; Tue, 14 Nov 2023 19:07:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700017667; cv=none; d=google.com; s=arc-20160816; b=SUiI5aH6sqBdmNHIaZ+hdQCfQBrpYAGDQGoXu7ERCMnmHJpkFYXVhJMmBPro8zM06O rsTNvlIQdOIwP0ecc4PYp0hrWUWsUs2VjvB8tAi96lf9XEvBxcvJw4rFV2Tw1cEM4eOQ E5njWwZ7PCr8QzsfWaImRbE4Y6DAHBdOxiNzQVunfvz7Jy8wrKs7OfO6vhZ69n4Dagj5 tAsdTZXe6iouUKh/wkPFCci21lbsCnwcqdEBoPChjl2TDC5K6qPs6lFmRoY29FgPJxeG AZQ7061+omMoXRPbv2BisGGvxnTD4HsOALQj/zQO6tP7Wr52En0AfkXYLmglhLOvVTJE kEng== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0wqEA/WL6sgNrbQx/E9hbGsocI62FPjO0/cZoc8KAYI=; fh=cKMEKjN6hA4p/tztquNSpzJ8m/owYvOs95994WQgEP4=; b=Y90DqCPrK+Lh6wqSeAHFxNdThM70gRSp3Y7uCu7+edfMwaY83vvlo81V0W1NBRrDxm hBzyW8P1wzMQfaUf6g8C869QjOtPvsr/4nLoHrVviT2pXdemO8MQXdZSpQYuT7t5TjGY 6hpjE3E5YP6fBZNRhaWHkMENmVC5Yzyf280Wy4Fidsle8aTBV1LYcvqyWwJb/aqNPmOx 0HTY10/NrmkZck2Vny35kyHYw5aJhZM4EJe2t5yfOREmXucYkkwxH2omjocV2gdm9DIi sAUt+j3qQwFLRPA4d230RkyqGKytrVwSC0NUbJP9DbT+dxcAvAq8tDdYQaM9BRNfHk2z 85wQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dJX5OjS8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id f6-20020a63e306000000b00566022bbcafsi8980881pgh.566.2023.11.14.19.07.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 19:07:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dJX5OjS8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 46443802C8D8; Tue, 14 Nov 2023 19:07:47 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234372AbjKODHm (ORCPT + 28 others); Tue, 14 Nov 2023 22:07:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234389AbjKODHa (ORCPT ); Tue, 14 Nov 2023 22:07:30 -0500 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA59CD67; Tue, 14 Nov 2023 19:07:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700017633; x=1731553633; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MqxBBweeeHli+iwsPxL1BHv7R18LtuVILt2tccac1D0=; b=dJX5OjS8I2F5mduf1PI3HcYoZbgkOt3TMOZTu44YxPCfzkHBd85mJqy2 fokMmKatScJjsSdLc/Rx6naHR6Pf4aQDzOhmpRHNZeR5aXpTLCBccLD9/ 9tuF/bGfEiN2kCTIJ+DcKVtc1hmmqiNvZyJwTdg/ytqmRMPkCvDEhvuKA ooGx+zGagxB2gL1BWNOaS1y7paGRcJhAtC0mz7NM0TQBvIgWyOXgxxV58 6zmgATUvNVhENTv3L55LTbG0W+adz5XmeliJlsXxTt4uv1a6ubomdXywi 157IH5j2SistrgM4pMANPUvXszVPEmcTmFBaLbRKJAASDHHJDHQQld+xk Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10894"; a="394715462" X-IronPort-AV: E=Sophos;i="6.03,303,1694761200"; d="scan'208";a="394715462" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Nov 2023 19:07:12 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10894"; a="1012128851" X-IronPort-AV: E=Sophos;i="6.03,303,1694761200"; d="scan'208";a="1012128851" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmsmga006.fm.intel.com with ESMTP; 14 Nov 2023 19:07:08 -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 , Yan Zhao , iommu@lists.linux.dev, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Lu Baolu , Jason Gunthorpe Subject: [PATCH v7 08/12] iommu: Prepare for separating SVA and IOPF Date: Wed, 15 Nov 2023 11:02:22 +0800 Message-Id: <20231115030226.16700-9-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231115030226.16700-1-baolu.lu@linux.intel.com> References: <20231115030226.16700-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Tue, 14 Nov 2023 19:07:47 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782597725822547064 X-GMAIL-MSGID: 1782597725822547064 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 Tested-by: Yan Zhao Reviewed-by:Yi 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 42b62bc8737a..0d3c5a56b078 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 c45977bb7da3..09e05f483b4f 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); } /**