Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3904117iog; Tue, 21 Jun 2022 08:11:09 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tKKkQEcgdMuvx3QWBHB8lGCxD/YldR/oYyxwI9M/lrUCBhSBHFOqzvgUxBxeV4/2uVcWyF X-Received: by 2002:a17:907:9606:b0:70a:e140:6329 with SMTP id gb6-20020a170907960600b0070ae1406329mr26142826ejc.471.1655824269564; Tue, 21 Jun 2022 08:11:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655824269; cv=none; d=google.com; s=arc-20160816; b=Eeny5KZz5qbYzJr4yl1Y1mFG3B9XL28qOmXWNLlkSpFtFKyCm7GxMoPiiWeN3SBHkP qV2y9GJ1yl0HBJqjNkSz3hRTeCpkekY6GAYR9Tgmf5H8y53NLqMoGj2is7Co5JEal2LX WmJQdfs8Pa2F2wt48CQh8eCPt/BSsqXykjogbJQLTFEpbAep4VV1OLxqVQAzMJC2vvg9 1Ld54FlntsBK6uR4YEQxCQIxsgBsLO3B+nLT8PC42E5hfZUxrQhDa2E2PRmzo7BDenO1 jOtX+J8E4Y1ULxdnS1UxJdtPuvN6df5/0Ans3tXuvOWnNOTJh6+Ed1JH4NR/aW21ZRnM F2fQ== 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=2hE7X+qYH97/ssXkVMpGHTOvFVMtXMZL6eurxIeAdhc=; b=V5y6xvsGr2KxkRjKzaS/3RY9aZNiPA6oXNUlXa51CRaOmIRkR6Yx7fDjzcWl6i5RXN bHkxUbPPKo7ddl0AtVrCMwKAl+fWWBf47lnd59F+h/Y/pEb1Qb5Zj/U1jxjny5sHQEEJ YAOcO7tW3VYrUcwwud3+6iau+fjTa8o159Xws0RcqS8aYIucQ4pA+oLIXf8uErxxxLzz 0vY+LWtQhCQs/BcjVfHVt11yErktUTHlipLq4uS+ZFO5OPCZafEGqLNwDZCjZxSnNLOd wpv/s3QHGesW2XMYPO4M4dch32lFCu9cp6DvTf5agBQ0H62teI53Mq/qjCjHhPpB2P3P 5xmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=TfVkxQiM; 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 ss28-20020a170907c01c00b00722e7756f3dsi824162ejc.462.2022.06.21.08.10.39; Tue, 21 Jun 2022 08:11:09 -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=TfVkxQiM; 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 S1352034AbiFUOtQ (ORCPT + 99 others); Tue, 21 Jun 2022 10:49:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351961AbiFUOsp (ORCPT ); Tue, 21 Jun 2022 10:48:45 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71EC8101C6 for ; Tue, 21 Jun 2022 07:48:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1655822924; x=1687358924; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZhVJrH8ZIL7/etGs0byavRR7lBKr0I4+Mu5OuvDVjHU=; b=TfVkxQiMPRLQz567vckTF3JynPockaZ97NsOLnhXRWEkzubY4M3j3dR8 D2gidgy8eEt+gSdbC9PU1woQUlRMuYvoZnAtHAgeSEBPYun3TqJtZtsub T4KKGAMwnnXWXbGu6jo/aKd6D+0Z/fHFM9qQjkr4TPCRu2lV6L4+Q6bi3 dNykv9RXlI9XDOCxkwBL6hYeFQbgYTq+L/bcJqWYDryOHsvO5/5kR/db4 81W1+uimiKJ5JgLXy6q7XVeiOmnwcT7/kpDmdWoP/tAEJn/HZy+l3JHM8 1GbCYS1reYmvPNZW8ap/yN5tydSj+G7FQJDexg4bzqwLfsi2PkVqzbfD9 g==; X-IronPort-AV: E=McAfee;i="6400,9594,10384"; a="260566727" X-IronPort-AV: E=Sophos;i="5.92,209,1650956400"; d="scan'208";a="260566727" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jun 2022 07:48:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,209,1650956400"; d="scan'208";a="643659706" Received: from allen-box.sh.intel.com ([10.239.159.48]) by fmsmga008.fm.intel.com with ESMTP; 21 Jun 2022 07:48:40 -0700 From: Lu Baolu To: Joerg Roedel , Jason Gunthorpe , Christoph Hellwig , Kevin Tian , Ashok Raj , Will Deacon , Robin Murphy , Jean-Philippe Brucker , Dave Jiang , Vinod Koul Cc: Eric Auger , Liu Yi L , Jacob jun Pan , iommu@lists.linux-foundation.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Lu Baolu , Jean-Philippe Brucker Subject: [PATCH v9 10/11] iommu: Per-domain I/O page fault handling Date: Tue, 21 Jun 2022 22:43:52 +0800 Message-Id: <20220621144353.17547-11-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220621144353.17547-1-baolu.lu@linux.intel.com> References: <20220621144353.17547-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.9 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 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 Tweak the I/O page fault handling framework to route the page faults to the domain and call the page fault handler retrieved from the domain. This makes the I/O page fault handling framework possible to serve more usage scenarios as long as they have an IOMMU domain and install a page fault handler in it. Some unused functions are also removed to avoid dead code. The iommu_get_domain_for_dev_pasid() which retrieves attached domain for a {device, PASID} pair is used. It will be used by the page fault handling framework which knows {device, PASID} reported from the iommu driver. We have a guarantee that the SVA domain doesn't go away during IOPF handling, because unbind() waits for pending faults with iopf_queue_flush_dev() before freeing the domain. Hence, there's no need to synchronize life cycle of the iommu domains between the unbind() and the interrupt threads. Signed-off-by: Lu Baolu Reviewed-by: Jean-Philippe Brucker --- drivers/iommu/io-pgfault.c | 64 +++++--------------------------------- 1 file changed, 7 insertions(+), 57 deletions(-) diff --git a/drivers/iommu/io-pgfault.c b/drivers/iommu/io-pgfault.c index aee9e033012f..4f24ec703479 100644 --- a/drivers/iommu/io-pgfault.c +++ b/drivers/iommu/io-pgfault.c @@ -69,69 +69,18 @@ static int iopf_complete_group(struct device *dev, struct iopf_fault *iopf, return iommu_page_response(dev, &resp); } -static enum iommu_page_response_code -iopf_handle_single(struct iopf_fault *iopf) -{ - vm_fault_t ret; - struct mm_struct *mm; - struct vm_area_struct *vma; - unsigned int access_flags = 0; - unsigned int fault_flags = FAULT_FLAG_REMOTE; - struct iommu_fault_page_request *prm = &iopf->fault.prm; - enum iommu_page_response_code status = IOMMU_PAGE_RESP_INVALID; - - if (!(prm->flags & IOMMU_FAULT_PAGE_REQUEST_PASID_VALID)) - return status; - - mm = iommu_sva_find(prm->pasid); - if (IS_ERR_OR_NULL(mm)) - return status; - - mmap_read_lock(mm); - - vma = find_extend_vma(mm, prm->addr); - if (!vma) - /* Unmapped area */ - goto out_put_mm; - - if (prm->perm & IOMMU_FAULT_PERM_READ) - access_flags |= VM_READ; - - if (prm->perm & IOMMU_FAULT_PERM_WRITE) { - access_flags |= VM_WRITE; - fault_flags |= FAULT_FLAG_WRITE; - } - - if (prm->perm & IOMMU_FAULT_PERM_EXEC) { - access_flags |= VM_EXEC; - fault_flags |= FAULT_FLAG_INSTRUCTION; - } - - if (!(prm->perm & IOMMU_FAULT_PERM_PRIV)) - fault_flags |= FAULT_FLAG_USER; - - if (access_flags & ~vma->vm_flags) - /* Access fault */ - goto out_put_mm; - - ret = handle_mm_fault(vma, prm->addr, fault_flags, NULL); - status = ret & VM_FAULT_ERROR ? IOMMU_PAGE_RESP_INVALID : - IOMMU_PAGE_RESP_SUCCESS; - -out_put_mm: - mmap_read_unlock(mm); - mmput(mm); - - return status; -} - static void iopf_handle_group(struct work_struct *work) { 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); + domain = iommu_get_domain_for_dev_pasid(group->dev, + group->last_fault.fault.prm.pasid); + if (!domain || !domain->iopf_handler) + status = IOMMU_PAGE_RESP_INVALID; list_for_each_entry_safe(iopf, next, &group->faults, list) { /* @@ -139,7 +88,8 @@ static void iopf_handle_group(struct work_struct *work) * faults in the group if there is an error. */ if (status == IOMMU_PAGE_RESP_SUCCESS) - status = iopf_handle_single(iopf); + status = domain->iopf_handler(&iopf->fault, + domain->fault_data); if (!(iopf->fault.prm.flags & IOMMU_FAULT_PAGE_REQUEST_LAST_PAGE)) -- 2.25.1