From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 1F8C2158A37; Tue, 23 Jul 2024 18:39:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721759989; cv=none; b=AYEUAFY7oc67ruUlBn4W1Ewqr+TclrDRhl/E7/UKyx/9UHV2hj7LDkfcX8V09l/tgH4pqKXXYJJhy8SyAEpK/cr3ufzoKnpDax9YQ6GEgXWq00NAIM5xEtEH6xfJ0r87Hjh6s1305ZcTZTAJXK55flSQ09iVWkdKnCIPKL1eoIM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721759989; c=relaxed/simple; bh=X+etflOk4Jkbj8w4blOdUvaal54FyJHxo8Cj1WJlXdw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oodjnlpY95/AX+E3f5VEjaUFfQWjJ7AnnlpEMO7uay7AQc6yL/d7arqAAaJYSD6AKxYksIbbqUFAg2O//auYHKc0zjBscRVIAr2petWTqJbAch0J2dBCebFkhwYnIK+uMtMInMluqBbuqBok1w+bcFO/8OxpeAkAxaiiaQJ4gMw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=e6gM9++9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="e6gM9++9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B1E1C4AF0B; Tue, 23 Jul 2024 18:39:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1721759989; bh=X+etflOk4Jkbj8w4blOdUvaal54FyJHxo8Cj1WJlXdw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e6gM9++9GjVh6CHx0G5tI92CETrsopj6kHAyUMdd1YSJiXeZ+Dw1W3AkVKcXG150I xi/QqM9eR/VrCMqKvqc0jSlgwCirEgKGqBjIv1QPyGD8nzG5ASXh5yEwbq9iPyrqeD ML/0EyEKr0JLaHCu1ApCo4YndYRYv+jPKushTR6s= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yan Zhao , Alex Williamson , Sasha Levin Subject: [PATCH 6.9 064/163] vfio/pci: Insert full vma on mmapd MMIO fault Date: Tue, 23 Jul 2024 20:23:13 +0200 Message-ID: <20240723180145.943755294@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240723180143.461739294@linuxfoundation.org> References: <20240723180143.461739294@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alex Williamson [ Upstream commit d71a989cf5d961989c273093cdff2550acdde314 ] In order to improve performance of typical scenarios we can try to insert the entire vma on fault. This accelerates typical cases, such as when the MMIO region is DMA mapped by QEMU. The vfio_iommu_type1 driver will fault in the entire DMA mapped range through fixup_user_fault(). In synthetic testing, this improves the time required to walk a PCI BAR mapping from userspace by roughly 1/3rd. This is likely an interim solution until vmf_insert_pfn_{pmd,pud}() gain support for pfnmaps. Suggested-by: Yan Zhao Link: https://lore.kernel.org/all/Zl6XdUkt%2FzMMGOLF@yzhao56-desk.sh.intel.com/ Reviewed-by: Yan Zhao Link: https://lore.kernel.org/r/20240607035213.2054226-1-alex.williamson@redhat.com Signed-off-by: Alex Williamson Signed-off-by: Sasha Levin --- drivers/vfio/pci/vfio_pci_core.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index 727a51ce9ad71..680b15ca4fcea 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -1659,6 +1659,7 @@ static vm_fault_t vfio_pci_mmap_fault(struct vm_fault *vmf) struct vm_area_struct *vma = vmf->vma; struct vfio_pci_core_device *vdev = vma->vm_private_data; unsigned long pfn, pgoff = vmf->pgoff - vma->vm_pgoff; + unsigned long addr = vma->vm_start; vm_fault_t ret = VM_FAULT_SIGBUS; pfn = vma_to_pfn(vma); @@ -1666,11 +1667,25 @@ static vm_fault_t vfio_pci_mmap_fault(struct vm_fault *vmf) down_read(&vdev->memory_lock); if (vdev->pm_runtime_engaged || !__vfio_pci_memory_enabled(vdev)) - goto out_disabled; + goto out_unlock; ret = vmf_insert_pfn(vma, vmf->address, pfn + pgoff); + if (ret & VM_FAULT_ERROR) + goto out_unlock; -out_disabled: + /* + * Pre-fault the remainder of the vma, abort further insertions and + * supress error if fault is encountered during pre-fault. + */ + for (; addr < vma->vm_end; addr += PAGE_SIZE, pfn++) { + if (addr == vmf->address) + continue; + + if (vmf_insert_pfn(vma, addr, pfn) & VM_FAULT_ERROR) + break; + } + +out_unlock: up_read(&vdev->memory_lock); return ret; -- 2.43.0