From patchwork Thu Dec 7 06:43:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 174958 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4594631vqy; Wed, 6 Dec 2023 22:49:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IEFjWcgqZAIVPZNJYMtCJ3p7B2i+OZDWRYxo45oqmHv0MPzL9ZIbbt4upsyGAesGcEnewnT X-Received: by 2002:a05:6a20:8e1c:b0:18f:f359:bca5 with SMTP id y28-20020a056a208e1c00b0018ff359bca5mr1445532pzj.64.1701931759049; Wed, 06 Dec 2023 22:49:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701931759; cv=none; d=google.com; s=arc-20160816; b=fYW/Rwmvh/fXQ/Tgr1PwT9TpP9qt+yZFr1HLpy9uvj/lef7Ztd9xEgK7o3WcX7MmCv lCxKhqee/ilMPP5lcAHrL3U7jR3p29l3HbbIQJN48TwKojqG4heOOo0jBFjk6duLxBXV fDHEQM0dekmapn4iWKBRV80Fv4820YYoXzf9AWPdYmWKIeLER+9vqv82o4dzAfC3fe4R nwnCIR6tBJNKQJHJUKTXyvES6Ax5wvSTxYG6GfJwMVaEYeaiebkUQ+JcQcrrkJfdDtGK T89Ru/N8RymV7RvZ+vE+dj45mdJ6UPqOWeOdarso47oroK49MoEveTOL6hks1ivPg8Vw AMzw== 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 Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id p63-20020a634242000000b005c624eec079si634984pga.724.2023.12.06.22.49.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 22:49:19 -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 1566180DFF55; Wed, 6 Dec 2023 22:49:10 -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 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:10 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784604796121856877 X-GMAIL-MSGID: 1784604796121856877 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); } /**