From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (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 08172172767 for ; Tue, 30 Apr 2024 14:59:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=140.211.166.138 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714489142; cv=none; b=RBYmcHmrWSZOEmD5t2s2LNJj1oKq7kHLj8LMLZ8/oN557ZuTp+AUF96xnHj1ict0V/7AzgcauKFYaxqO3bM0sSVAPqkuC0052GV4Ut+oqC+BmEWkidGMiBzwfiAvzYd+bjxAXNvkMjEIwFdV2odvExF9gpkuuRZ89mlLFGcZ6c0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714489142; c=relaxed/simple; bh=H+AJrUc9ZCkByr7T1GCK++YEnrHUWVMDktf/LRmmeCw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gp6yRem7jSc5VWTBwsXIYjQOe1Y07xG3MeZZ9/S6y6ut2fUbDzMlgR2KWjO3U6NGT/MzlfXS2jKQoS2eo9oYvDdY6mM+P31qzAmGyuhtIDHkjrlHha5TTm/Ah/07fP8tq7ghiP5XiT0mMNVgocoN2MDDpJcGTavBO+8FJiQuxs0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=jP10sAtg; arc=none smtp.client-ip=140.211.166.138 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="jP10sAtg" Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id DAC3480C25 for ; Tue, 30 Apr 2024 14:59:00 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org X-Spam-Flag: NO X-Spam-Score: -4.299 X-Spam-Level: Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id FXmchDYQcq-I for ; Tue, 30 Apr 2024 14:59:00 +0000 (UTC) Received-SPF: None (mailfrom) identity=mailfrom; client-ip=198.175.65.19; helo=mgamail.intel.com; envelope-from=baolu.lu@linux.intel.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp1.osuosl.org 10EDB80C14 Authentication-Results: smtp1.osuosl.org; dmarc=none (p=none dis=none) header.from=linux.intel.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 10EDB80C14 Authentication-Results: smtp1.osuosl.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=jP10sAtg Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) by smtp1.osuosl.org (Postfix) with ESMTPS id 10EDB80C14 for ; Tue, 30 Apr 2024 14:58:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1714489140; x=1746025140; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=H+AJrUc9ZCkByr7T1GCK++YEnrHUWVMDktf/LRmmeCw=; b=jP10sAtg+6HCcCvOF701rKVOcplrohFmK3OJ4VgbEfNvqtSoDQKnrnYE pl1+T/GbY1LGA6qQ4Ey2DfvXS4uXnBGmiDsQ393BE+pa6Y5Ve7Qn3XjHX FbMFvlhrAz/JTt4VmlL/YZUcDHMynM7PyuG/pMiLpTTKyqc/D91RCXW7y DoIgmTKST4ZDOsDSn4hfmrQpOedCZvEHEldBYbMPAl3ZpHYYCFoJorYiA qd3PdaXBSUVu7bAJgTfLgj/by+dvoeYo4oy0myqlDrzRIAADbRYrhzsZp jISqgqNDsN+FzVQp6PUITS37CkOfN+uj6fOYfeST+Ln5sU1/YWwv9+ytk w==; X-CSE-ConnectionGUID: jJKr18XKRL2X6iwxJLeQxQ== X-CSE-MsgGUID: N91kXy9lR5GkUb2v0gXFIw== X-IronPort-AV: E=McAfee;i="6600,9927,11060"; a="10059873" X-IronPort-AV: E=Sophos;i="6.07,242,1708416000"; d="scan'208";a="10059873" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Apr 2024 07:59:00 -0700 X-CSE-ConnectionGUID: KfyaQy1YRHSL8PrqPvEEdg== X-CSE-MsgGUID: P4r+VsbnSnGfOXnmSJh19Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,242,1708416000"; d="scan'208";a="31282179" Received: from unknown (HELO allen-box.sh.intel.com) ([10.239.159.127]) by orviesa004.jf.intel.com with ESMTP; 30 Apr 2024 07:58:56 -0700 From: Lu Baolu To: Jason Gunthorpe , Kevin Tian , Joerg Roedel , Will Deacon , Robin Murphy , Jean-Philippe Brucker , Nicolin Chen , Yi Liu , Jacob Pan , Joel Granados Cc: iommu@lists.linux.dev, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v5 3/9] iommu: Add attachment handle to struct iopf_group Date: Tue, 30 Apr 2024 22:57:04 +0800 Message-Id: <20240430145710.68112-4-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240430145710.68112-1-baolu.lu@linux.intel.com> References: <20240430145710.68112-1-baolu.lu@linux.intel.com> Precedence: bulk X-Mailing-List: virtualization@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Previously, the domain that a page fault targets is stored in an iopf_group, which represents a minimal set of page faults. With the introduction of attachment handle, replace the domain with the handle so that the fault handler can obtain more information as needed when handling the faults. iommu_report_device_fault() is currently used for SVA page faults, which handles the page fault in an internal cycle. The domain is retrieved with iommu_get_domain_for_dev_pasid() if the pasid in the fault message is valid. This doesn't work in IOMMUFD case, where if the pasid table of a device is wholly managed by user space, there is no domain attached to the PASID of the device. Improve this code to try fetching the attachment handle on a PASID if possible, otherwise try it on the RID. Signed-off-by: Lu Baolu --- include/linux/iommu.h | 1 + drivers/iommu/io-pgfault.c | 34 ++++++++++++++-------------------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index be9c9a10169d..4ff68d50ae39 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -128,6 +128,7 @@ struct iopf_group { struct list_head pending_node; struct work_struct work; struct iommu_domain *domain; + struct iommu_attach_handle *attach_handle; /* The device's fault data parameter. */ struct iommu_fault_param *fault_param; }; diff --git a/drivers/iommu/io-pgfault.c b/drivers/iommu/io-pgfault.c index 06d78fcc79fd..f19215d4ffa2 100644 --- a/drivers/iommu/io-pgfault.c +++ b/drivers/iommu/io-pgfault.c @@ -59,28 +59,19 @@ void iopf_free_group(struct iopf_group *group) } EXPORT_SYMBOL_GPL(iopf_free_group); -static struct iommu_domain *get_domain_for_iopf(struct device *dev, - struct iommu_fault *fault) +static int get_attach_handle_for_iopf(struct device *dev, ioasid_t pasid, + struct iopf_group *group) { - struct iommu_domain *domain; + struct iommu_attach_handle *handle; - if (fault->prm.flags & IOMMU_FAULT_PAGE_REQUEST_PASID_VALID) { - domain = iommu_get_domain_for_dev_pasid(dev, fault->prm.pasid, 0); - if (IS_ERR(domain)) - domain = NULL; - } else { - domain = iommu_get_domain_for_dev(dev); - } + handle = iommu_attach_handle_get(dev->iommu_group, pasid, 0); + if (IS_ERR(handle)) + return PTR_ERR(handle); - if (!domain || !domain->iopf_handler) { - dev_warn_ratelimited(dev, - "iopf (pasid %d) without domain attached or handler installed\n", - fault->prm.pasid); + group->attach_handle = handle; + group->domain = handle->domain; - return NULL; - } - - return domain; + return 0; } /* Non-last request of a group. Postpone until the last one. */ @@ -206,8 +197,11 @@ void iommu_report_device_fault(struct device *dev, struct iopf_fault *evt) if (group == &abort_group) goto err_abort; - group->domain = get_domain_for_iopf(dev, fault); - if (!group->domain) + if (!(fault->prm.flags & IOMMU_FAULT_PAGE_REQUEST_PASID_VALID) || + get_attach_handle_for_iopf(dev, fault->prm.pasid, group)) + get_attach_handle_for_iopf(dev, IOMMU_NO_PASID, group); + + if (!group->attach_handle || !group->domain->iopf_handler) goto err_abort; /* -- 2.34.1