Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp2090470lqa; Tue, 30 Apr 2024 07:59:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVUw6X6RKbZLqZOmgHKUxtgYT0ddoO47ioyf7RzbIXvJr1se41ndWeAwJnvRQb1WyzgK4ox0sU0HTFFEZ05DrYLUJ06x7pyWiz56sGAXg== X-Google-Smtp-Source: AGHT+IFY1dsmFNIKu1SIq1Gykt9/SlAMc59dsrvM4iYGrnNOqXgDZ9aqeqpt2fPtsnd/hrW8vq/9 X-Received: by 2002:a17:906:da09:b0:a58:7249:25df with SMTP id fi9-20020a170906da0900b00a58724925dfmr2245551ejb.49.1714489193199; Tue, 30 Apr 2024 07:59:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714489193; cv=pass; d=google.com; s=arc-20160816; b=y9l9qlw5cSEYLt1Tf48x7tfHxMWNSduhjJuiphBXRWlJnILDdoKMIsPGa/zMDA7tld /7fGAUXcDXZJMBKDO6RrbvPhNKwhcEmbDbQ3NHlWzUOEBXAZuuFhJdFdBcxx82wUGrK9 f7j7Mhx38qFuwfkZyD3CN0JIutoA0edrBVCtsj/UnEeRXE5mblFcf5Ftk0eT9lRa3VXo Wl6iHYQ51x0YQ9+8WeKhAtrIcinwzJ7iv1I6lODvsQfBvemT2O0v5mcq+Srcy2aQDYeo CWvkdAmdS5zDfV6igMik3ymHgdd2InA6CNSNSAJAgcN6slzYU4Pw26N9BKIfgrZ8H3mC D2mg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=BCQIvbNhWwReex1EQ7rguJY2bMqOrh4nvml+b13rxQ8=; fh=tXslIEC/iII+0o9YvlUtRXapl6zSPusBr1yEidN1Q7w=; b=o6Jh2IU62r3XY5c20P8QmTNGJqu49jMsWYpp480cO4NdjVd9xMOdkzvn23NhrzHbIP wMyN9kU5Yrfz7/MOzSNEBtKVbM6tInDxbBlp/GTvN7DddQNTtDQN0jeToqMU6wH+5wHQ DwKWG5xABYD/sX0jxmaZsh1grRcdL0FCLlwRv45XD4HYsbPy2UpHSddwwJBkC+t4qbbt FwXrpntvYM705u92uTYpSp5Knep3v+e1OLNE5etEDOcAprk2EeDGFgVYCCuldmj8Bowo 8TRko14xnEaIxkIM3ctee/rakb3McvaL17H0/QAe+BRdHhoNSveIBz5TGk4B5YdLGJSO XRAg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jP10sAtg; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-164212-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164212-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id mp17-20020a1709071b1100b00a58bbfce92esi7299488ejc.401.2024.04.30.07.59.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 07:59:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-164212-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jP10sAtg; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-164212-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164212-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id C91EE1F239B4 for ; Tue, 30 Apr 2024 14:59:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2235C172BD6; Tue, 30 Apr 2024 14:59:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="jP10sAtg" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (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 ED89F77117 for ; Tue, 30 Apr 2024 14:58:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714489141; cv=none; b=eWyqqAEpmsfNf4U3fdoV+lpaPQJyjQFJaNMgDHnbtjXuO3Xe83fYz4nYERVZoe6Fu4oq8mwnvZkRhYcIXrOIpyjLhXaFSWRhVZcLJgT2rL+/DA9tmyz89+knChaFT02PrpJZhkQfg8Ms5IGvw1I8d3uNfrTgM6Sircd2G14T+Jo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714489141; c=relaxed/simple; bh=H+AJrUc9ZCkByr7T1GCK++YEnrHUWVMDktf/LRmmeCw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iTf8NvdzmvBpsLGPd4eEbTrHoMNKQiyy451BFeJ9Q4ri4a7b8EgFLh0KeG/Z9AcPuhUvigSHH1pE+G3wQnCau/TKyUZrLdokZzSYW1a2KD4Fsl7dXFjFphbjXcfFEA+fyEwFLMDngj0n7AntWCa26UaGMzsbsVKCgI0ny6JPxh8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=jP10sAtg; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com 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: wn6QA7NHRdef7HHM9OPnMA== X-CSE-MsgGUID: KrB8Zwe0QnS34lHvHAXNnw== X-IronPort-AV: E=McAfee;i="6600,9927,11060"; a="10059868" X-IronPort-AV: E=Sophos;i="6.07,242,1708416000"; d="scan'208";a="10059868" 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: linux-kernel@vger.kernel.org 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