Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1468390rdb; Wed, 6 Dec 2023 22:49:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IE8GpRYe5stFKUT1ZS8FuEA2p2lzCNXQBHf0hlON+ioyCbgGUyyyuhIgAs7CNqRSo+c5Ha/ X-Received: by 2002:a17:902:7887:b0:1d1:cdb2:a93c with SMTP id q7-20020a170902788700b001d1cdb2a93cmr1921396pll.130.1701931760731; Wed, 06 Dec 2023 22:49:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701931760; cv=none; d=google.com; s=arc-20160816; b=sNAqR+HxJdmBtrxqDmbvDFtjCBw7eKn0tHdR5VooAZ+ZBoroSg5BI5ZQI6tFfsbNgV D/bpe9A+t3G42xv1avU/HY4TqQRDPhlVncVj//zOcdq2gHWFFv1G0CpfBcQopG1OSpJL I/DbG/5HcfukBH9RSDBDq0dZ1geT+hCpKZNkDIC1gVZv9qNoR3SAp1aXoVIXqs0fbKqX MzXBnxOBjflz9LLa/LOfjjm4wPa9cCb0fenzBKRZaTTqqigCyG9F9EGe64DWycZfLu6o OALV+vVMMZyNljR6NBm56v3vpAQPB0+N5mAU57vdp46lPFSq9LrSTxk83NQHG/ty5ryp hUmg== 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=/piUoJzD5DdE3pMaSGk+VOZ5UEWPwDnUwuwTuXdKIdY=; fh=0puWr8qDwzaogZbtOaymnvHkPoKpvOitlnMkTa2cyaw=; b=LhsaVMT7MuY5URj16AcNEGUi4EPl9o393hd4HPIJ38KudCM4LwWD40cZ+w6NZ6+6+p WPOi6yibqADZV2V9egFvjXHuuZ26LyZaTAdKqGf4DLIC+5RXLjklpJwn410J7M2vF9B3 W2MlD0ciITZLgxBig5B6wf1bDuUQYr9vKCnce4MEx0S+WxJD+MndrLNPe4TgyKYhEtK2 VUfnaGTHCXt1iztds6UhMRth/tiVbVo17oC3OvBu5iXF5d8hBwuIWeqWEA1VoBzflVV0 v6zwqYKPNfVk+98QkyWN2GReLAflkWOhLkxI8JV5rrAX0l+uQsM1zt1fXShYjEPP1XLw sjqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MUwkaMWv; 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 Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id m8-20020a170902bb8800b001d07ebef61csi583344pls.502.2023.12.06.22.49.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 22:49:20 -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=MUwkaMWv; 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 720F580DFF58; Wed, 6 Dec 2023 22:49:11 -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 S229620AbjLGGsy (ORCPT + 99 others); Thu, 7 Dec 2023 01:48:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377734AbjLGGsg (ORCPT ); Thu, 7 Dec 2023 01:48:36 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0319410CE; Wed, 6 Dec 2023 22:48:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701931723; x=1733467723; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=l/PKXYSQkj8WE84rhRPnGLZE7qeFZuc05zxQkP43Yjs=; b=MUwkaMWvD6l7u3j/9ogZVFHM/l/JZKa0FuKgZ0OBNxfJMhDu42wAmu0b fdXFMczQeptX+sWwJ9ks7ZN6J9INmGPXvp+V1W5q4MpAsVKSOJKmqzK25 dqyJFxlO9tfkHzVMIJnIo0kSGVlaEt5d3adw1vTk2Cvs/UgM7GVdBS2Qd wTkXE5eGvXl3ZE7IvSnm5hOj4wIPkTzxJpGE/HRWSItAWKHVrYGKoBum0 Drch5sjT91NvfsBrSLxPH7+R95lcdXdlfWx03RZNgEcdKRbFQ7cDlD/mR YTN3h49waXwngTf9c5FdEXGQOWwMK3t479iOITLrufixBOF7ANB2orsp/ A==; X-IronPort-AV: E=McAfee;i="6600,9927,10916"; a="1015019" X-IronPort-AV: E=Sophos;i="6.04,256,1695711600"; d="scan'208";a="1015019" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Dec 2023 22:48:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10916"; a="771611737" X-IronPort-AV: E=Sophos;i="6.04,256,1695711600"; d="scan'208";a="771611737" Received: from allen-box.sh.intel.com ([10.239.159.127]) by orsmga002.jf.intel.com with ESMTP; 06 Dec 2023 22:48:36 -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 v8 08/12] iommu: Prepare for separating SVA and IOPF Date: Thu, 7 Dec 2023 14:43:04 +0800 Message-Id: <20231207064308.313316-9-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231207064308.313316-1-baolu.lu@linux.intel.com> References: <20231207064308.313316-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,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]); Wed, 06 Dec 2023 22:49:11 -0800 (PST) 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 d0d120efce11..c17a99648e44 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