Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp883537pxb; Fri, 22 Apr 2022 13:22:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5Ihe63tdg9Y2VuprWgOvaso3NDceuzSpwH6975KQgenNALYNuRpXjdyvwfA9P1McpcdxL X-Received: by 2002:a05:6a00:1a56:b0:50a:436f:6956 with SMTP id h22-20020a056a001a5600b0050a436f6956mr6744007pfv.20.1650658971787; Fri, 22 Apr 2022 13:22:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650658971; cv=none; d=google.com; s=arc-20160816; b=efJ2A72s5gIQ4DVL4M6Bf3BKb1VhpERM6vzgJxV7pSrOipKn+y93PDyoa6kmHXaYbP +Dj6JoDHkc4l0jE8LgFo3etLSDMUeT5YX32LoBANtazFeWCztQ+E4qI+3WmoojjOElN8 ti9wlW81HPbOXKfFcYZNd8vv1UBcMvpq2JkR3ZJzOYObFID9s6HnkyKwrENzqezd4B8r pcwXyYvlKFM80KtfBrY6ieFYfPH/ZVZPqaOjujZ6q8cTg30h0rck6usNnTvXevFKdgNo Wp8bByMlHizxj1k8bxv4hc1SLVXEqq6cpbM+Fb1/VH+dUEsK2d8g2c5pLYLA/pExFrXE Vk0A== 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=aGFccBGuNEoZwiYFpQXJtwDFG3cl6E6zHNC5fsfyUMA=; b=uPtsV6+7ksv27qggsA9lw4pY7Mgh/AamtT1dSvL9190m1RNdvURIyNnchsRtRn36Hn 5VpD4XP1P5xjHc2pBlWFPMG3yoJeKbJDPl9KsPuXcMA7de6p1hF1Xh/eCX1HBIyScWBs b/18DapNzxKIdKwEYph4TYoVKwY+XjHlA000k0SULvdvf57TkG6ICCeHVjlKdq2UdDSj 5doJYBNtkCAIeKx3rnPKUQeRQV7tYAbD3IpAD3H5fLO2Bew6OoO0+FEfLJUV1iSrDowr Z6Y1ioWuLmlr6EWhbADtymypdYYaFIxJN0PurKIVNhwibyH2ifhmWpYtfVHMJP+79AhB MkqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LHjLJ5Z3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id d24-20020a631d58000000b003aadad65e11si1361989pgm.563.2022.04.22.13.22.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 13:22:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LHjLJ5Z3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AD20E260A8E; Fri, 22 Apr 2022 12:09:21 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1384466AbiDUF1y (ORCPT + 99 others); Thu, 21 Apr 2022 01:27:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1384450AbiDUF1e (ORCPT ); Thu, 21 Apr 2022 01:27:34 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34F6FDFAF for ; Wed, 20 Apr 2022 22:24:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650518686; x=1682054686; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ie9hUcU3U434de5/sN8Ft/NK7xY4WVe8K4mAecxVaZ0=; b=LHjLJ5Z3QCi2ct0f+cbcQIW+DNI1Xx5DWCvptRcfYm4BtwvhmdHsVSsC uOtQgTVEFbWe9yMJsc5NqS15rdAhcRrpQepDXI9VRKrnFyXAGDteGFV76 UQ8bmwJGzDNc4QzBNuhra9lsn/idnfomosgLfY9SwxhDXY+p3tHAH3J83 4kal+jb9hkqkzoCnptqmi4Iwzqil4Ib2179ylCeVzm/gB8Dpnr/WjqHgc DZixpB5iobwlPNoEr77VG7KnQjEGPnU/5tCtblX76j1i6yoeeM34YaklA W3H9naKfoST0ABtHZWdTKMlVxvUcy8LwcwuLY6vD++A367wmPPDqlpgAY w==; X-IronPort-AV: E=McAfee;i="6400,9594,10323"; a="246135725" X-IronPort-AV: E=Sophos;i="5.90,277,1643702400"; d="scan'208";a="246135725" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Apr 2022 22:24:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,277,1643702400"; d="scan'208";a="702944191" Received: from allen-box.sh.intel.com ([10.239.159.48]) by fmsmga001.fm.intel.com with ESMTP; 20 Apr 2022 22:24:42 -0700 From: Lu Baolu To: Joerg Roedel , Jason Gunthorpe , Christoph Hellwig , Kevin Tian , Ashok Raj , Will Deacon , Robin Murphy , Jean-Philippe Brucker Cc: Eric Auger , Liu Yi L , Jacob jun Pan , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v4 11/12] iommu: Per-domain I/O page fault handling Date: Thu, 21 Apr 2022 13:21:20 +0800 Message-Id: <20220421052121.3464100-12-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220421052121.3464100-1-baolu.lu@linux.intel.com> References: <20220421052121.3464100-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE autolearn=unavailable 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. Signed-off-by: Lu Baolu --- drivers/iommu/iommu-sva-lib.h | 1 - drivers/iommu/io-pgfault.c | 69 ++++++----------------------------- drivers/iommu/iommu-sva-lib.c | 20 ---------- 3 files changed, 12 insertions(+), 78 deletions(-) diff --git a/drivers/iommu/iommu-sva-lib.h b/drivers/iommu/iommu-sva-lib.h index 0f33472e5212..90d4bd3a61b1 100644 --- a/drivers/iommu/iommu-sva-lib.h +++ b/drivers/iommu/iommu-sva-lib.h @@ -8,7 +8,6 @@ #include #include -struct mm_struct *iommu_sva_find(ioasid_t pasid); struct mm_struct *iommu_sva_domain_mm(struct iommu_domain *domain); /* I/O Page fault */ diff --git a/drivers/iommu/io-pgfault.c b/drivers/iommu/io-pgfault.c index 1df8c1dcae77..fc1b2bdeedf8 100644 --- a/drivers/iommu/io-pgfault.c +++ b/drivers/iommu/io-pgfault.c @@ -69,62 +69,6 @@ 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; @@ -134,12 +78,23 @@ static void iopf_handle_group(struct work_struct *work) group = container_of(work, struct iopf_group, work); list_for_each_entry_safe(iopf, next, &group->faults, list) { + struct iommu_domain *domain; + + domain = iommu_get_domain_for_dev_pasid_async(group->dev, + iopf->fault.prm.pasid); + if (!domain || !domain->iopf_handler) + status = IOMMU_PAGE_RESP_INVALID; + /* * For the moment, errors are sticky: don't handle subsequent * 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 (domain) + iommu_domain_put_async(domain); if (!(iopf->fault.prm.flags & IOMMU_FAULT_PAGE_REQUEST_LAST_PAGE)) diff --git a/drivers/iommu/iommu-sva-lib.c b/drivers/iommu/iommu-sva-lib.c index 1024c61519dc..d84cffaeb331 100644 --- a/drivers/iommu/iommu-sva-lib.c +++ b/drivers/iommu/iommu-sva-lib.c @@ -69,26 +69,6 @@ static int iommu_sva_alloc_pasid(struct mm_struct *mm, return ret; } -/* ioasid_find getter() requires a void * argument */ -static bool __mmget_not_zero(void *mm) -{ - return mmget_not_zero(mm); -} - -/** - * iommu_sva_find() - Find mm associated to the given PASID - * @pasid: Process Address Space ID assigned to the mm - * - * On success a reference to the mm is taken, and must be released with mmput(). - * - * Returns the mm corresponding to this PASID, or an error if not found. - */ -struct mm_struct *iommu_sva_find(ioasid_t pasid) -{ - return ioasid_find(&iommu_sva_pasid, pasid, __mmget_not_zero); -} -EXPORT_SYMBOL_GPL(iommu_sva_find); - /* * Get or put an ioas for a shared memory. */ -- 2.25.1