Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4056323rwd; Mon, 29 May 2023 23:05:11 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Lz6bcJp87uN6+Lu5L0UUzU7dkKVFKYosmA3yLq0DOmap29WgdDeugnJRi/rcrRcL8zctl X-Received: by 2002:a05:6a00:2e05:b0:64f:4197:8d93 with SMTP id fc5-20020a056a002e0500b0064f41978d93mr1568747pfb.24.1685426711027; Mon, 29 May 2023 23:05:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685426711; cv=none; d=google.com; s=arc-20160816; b=yGSg2P09wx47E8aLBxlHsqBLip6bJgRIZgiY0IkJAiNqzNrBcgXDS6ECtI57d9onnJ NdyFSLFWP2oLuBT9bHoVYls8onoAXa9Gx6Z8rV2rRCXTSDdBRTm7KEnTUkq9KLcqGceo enaP+s0zl7yCM19DRac4lQpG6ybj14CrOgpIyJCCWbowS9R6zNPIYMy4Jvyg6IoRinoV 0TgftbYJjvMZ/ngB4031QmJNC8+zAH8C3+p7j18TWhmeqMaSRGu/pqH+6MCrdpaDaigW up2OxZ6NuFgFF8ktD8Sx/BnPOBexJzlJfLZW9PtlRkTeRT1y1yYgKcX32C4rjvYep3VV hUiw== 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=2zkMWBECc90MoVvfjOmRSxTVSkbABlKryCdqJJA/cRI=; b=nkyhIWSXk389FwgXQ/ECfWegLhvVBqitlOwPgpmCiklUnaNG7TxnJvedSuIUN4ZUoM ON/f90bnYXtc3EpUB3HFE7hqvG8uhSEPWQwhlhzAddwuARQYAJWa+cMYgsu/450UbAwr Z6IRUGzKV/LOrQazTP1231MbNTS9F3FhWSXstAK1mMNYV0npXQP2HJ4A26Z5Mfmr1tg6 kvVLuf19Dg5HkJbdexWYoDLhut9CcfDzu1HA44PG6WbXPU8pO9wtr+FE+NXFJA4tBpky TtMk9kC7eCvLYHMata2pzpJ9mFiwm1WIk4TXk+itkBwFIG1mcaeesHmClgYhAPBOsu3G JA7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XUig3CMz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 203-20020a6218d4000000b0064d44ee66b1si1010771pfy.225.2023.05.29.23.04.57; Mon, 29 May 2023 23:05:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XUig3CMz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230417AbjE3Flj (ORCPT + 99 others); Tue, 30 May 2023 01:41:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230301AbjE3Fkk (ORCPT ); Tue, 30 May 2023 01:40:40 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1684011C; Mon, 29 May 2023 22:40:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685425221; x=1716961221; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=m2M+k/wNJUpLwNpk+M4ahpND6qZ7v9d+7FJR9k8IhpI=; b=XUig3CMzlCFHMc2SGR3BCTOkCeVg+Rjbuu8FNXcIjeS8lUD9ivQ4z0+2 ZaGMW9S/S6Rf7sbJb+M02dQt/oMWPwiZfaXpI0WOlhbzFEVRrRjJg4nrA dnxcLxWjH/bOZJtOtKq0iR6ag5SYPwUJz8N9fi+SK4q1/bgC+Lxc5b0vw Mvn/Is7boI6zjjWQ7DPVsNo6uqzQoMYY3AJZrIBRUDjU4GatCFPejCMHY x8EIk9OOv6iEizearEIB4j05gaHE0/cpcXBezM2E2IljQbV/aaO8xBJgO j3W2BLO/YBcJUTRrJrNhLhgM3tKGnLP4VcKp+wxEAhAI75VEa2nJjhXy9 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10725"; a="420579880" X-IronPort-AV: E=Sophos;i="6.00,203,1681196400"; d="scan'208";a="420579880" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 May 2023 22:39:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10725"; a="739369909" X-IronPort-AV: E=Sophos;i="6.00,203,1681196400"; d="scan'208";a="739369909" Received: from allen-box.sh.intel.com ([10.239.159.127]) by orsmga001.jf.intel.com with ESMTP; 29 May 2023 22:39:15 -0700 From: Lu Baolu To: Jason Gunthorpe , Kevin Tian , Joerg Roedel , Will Deacon , Robin Murphy , Jean-Philippe Brucker , Nicolin Chen , Yi Liu , Jacob Pan Cc: iommu@lists.linux.dev, linux-kselftest@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [RFC PATCHES 14/17] iommufd: Drain all pending faults when destroying hwpt Date: Tue, 30 May 2023 13:37:21 +0800 Message-Id: <20230530053724.232765-15-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230530053724.232765-1-baolu.lu@linux.intel.com> References: <20230530053724.232765-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 When a HWPT is unexpectedly destroyed, drain all faults in the pending lists. It is safe because the iommu domain has been released and there will never be new io page faults anymore. Signed-off-by: Lu Baolu --- drivers/iommu/iommufd/hw_pagetable.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/iommufd/hw_pagetable.c b/drivers/iommu/iommufd/hw_pagetable.c index 8c441fd72e1f..7f18e6bd76ec 100644 --- a/drivers/iommu/iommufd/hw_pagetable.c +++ b/drivers/iommu/iommufd/hw_pagetable.c @@ -574,11 +574,26 @@ static struct hw_pgtable_fault *hw_pagetable_fault_alloc(int eventfd) return ERR_PTR(rc); } +static void iommufd_fault_list_destroy(struct hw_pgtable_fault *fault, + struct list_head *list) +{ + struct iommufd_fault *ifault; + + mutex_lock(&fault->mutex); + while (!list_empty(list)) { + ifault = list_first_entry(list, struct iommufd_fault, item); + if (iommufd_fault_timer_teardown(ifault)) + drain_iopf_fault(ifault); + list_del_init(&ifault->item); + iommufd_put_fault(ifault); + } + mutex_unlock(&fault->mutex); +} + static void hw_pagetable_fault_free(struct hw_pgtable_fault *fault) { - WARN_ON(!list_empty(&fault->deliver)); - WARN_ON(!list_empty(&fault->response)); - + iommufd_fault_list_destroy(fault, &fault->deliver); + iommufd_fault_list_destroy(fault, &fault->response); eventfd_ctx_put(fault->trigger); kfree(fault); } -- 2.34.1