From nobody Thu Feb 16 11:55:48 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PHYLD6Dh2z3q5J4; Thu, 16 Feb 2023 11:55:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PHYLD5Tmtz48N4; Thu, 16 Feb 2023 11:55:48 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676548548; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=8EGUER1Mk9lkDwWFNTWDYxFnkvimmiYPLFwEbqFIsfk=; b=ndwUMhf9/FnjR1OjYzYk7v7wE2Q8U2Dgxcv+y7fLylILlsiiBHg9AGlhh1+G/WsKKA91di PhzAJ6nBWZ/bvZJoqaEQibU2C5ORqg4yU0X/2C14ut5hPShdeBi0dqimlr9osKRsv33VTw NihGlE+ACa0dYsRhp8en61a67FUUq/OVyIpyvp10IdGQptxyn+75fz37RM8qRbZxM7hEqw c+X2rX0/iayG+dSeTBlzjhCckzaVF4mzKvTnnSw6NKeDIWtfn0VKzVGMGGP8CdE5c3qppz trq7nFPo5wMmay1Wph6FiLfmXf6oCtoV5MGAsiWuKfaK77fSZlYAq7IqH48bZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676548548; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=8EGUER1Mk9lkDwWFNTWDYxFnkvimmiYPLFwEbqFIsfk=; b=G4zHJpkWHqyLoUPBG8mFixjeRqT4b8Ut5MbNSu/onLSgvhWN1YdOMN/wQYkV7c4H9CAw6B umjKDucKE10SfaR6HSpcqciBRS2ML6GbHb+fm87zzCi1L8/Cm29bzYF1poYOfIOuZ+rHFB PlbnyQaRtMpUP6WQgO0XIF7eMHn7xPAfxq/dtiaQlrt11HYqPDWVGZVaRf/vba7UfMPhWu 1uCwyVe7fz/q7IcJVtQaFWBcAsyB/rzvUOcMUMwpoe1Qpic3q+Xo8/sOsAeYp/MS5Hz9No YogFljIHvvD8gHuajCbpnxg4NlNUacZWmeitb8NU5rScDSI8nuCgg/pfjjWJow== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1676548548; a=rsa-sha256; cv=none; b=xZQ74bEhKyXlmK1rc/uKvzr607J8xMLdw7/vTrWdHbg6V6+XU8UDE50i6n/8umSX8egfhD LzbYJBFqLk4GCV8S+3AHlZ78RASPlXQ4UcNYIa3GgzI8+gkSWURPnmF+Z6MfuX1MEkElfC MEDkp1/zXTSS7fkBPAPrS6+Orc1mURcF/yHPgmIh4nWRTD7l6FNw1iymqZ1Tz7mEm/pUcn z83NGj1ULcnmmhEcuZRxPRU18BPg9UFGRU5xwZaCN7Kignge0nulR9dGieWjt4d2oZqUfs xUUq2G/Vg4xi3C0ovq2AxW71lMBV1a2Ajhjb3jUHDC7scxvtkVcfUVo3zL7bTQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4PHYLD4NPKz12W3; Thu, 16 Feb 2023 11:55:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 31GBtmQX055125; Thu, 16 Feb 2023 11:55:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31GBtmgo055124; Thu, 16 Feb 2023 11:55:48 GMT (envelope-from git) Date: Thu, 16 Feb 2023 11:55:48 GMT Message-Id: <202302161155.31GBtmgo055124@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: =?utf-8?Q?Jean-S=C3=A9bastien=20P=C3=A9dron?= Subject: git: cc32cc0f8e96 - stable/13 - linuxkpi: Add `io_mapping_map_user()` and `remap_pfn_range()` List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dumbbell X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: cc32cc0f8e965b5c3d0a7ac6595ae97997a76d1b Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by dumbbell (ports committer): URL: https://cgit.FreeBSD.org/src/commit/?id=cc32cc0f8e965b5c3d0a7ac6595ae97997a76d1b commit cc32cc0f8e965b5c3d0a7ac6595ae97997a76d1b Author: Jean-Sébastien Pédron AuthorDate: 2023-01-14 12:22:19 +0000 Commit: Jean-Sébastien Pédron CommitDate: 2023-02-16 11:55:13 +0000 linuxkpi: Add `io_mapping_map_user()` and `remap_pfn_range()` The code comes from the i915 DRM driver. In Linux commits b739f125e4ebd73d10ed30a856574e13649119ed and b12d691ea5e01db42ccf3b4207e57cb3ce7cfe91 (Linux 5.13), the i915 DRM driver dropped specific implementations to use Linux generic functions. Therefore I moved the FreeBSD code from that i915 driver to linuxkpi. However, these commits were later reverted (also in Linux 5.13) so the i915 driver doesn't use these functions. But perhaps it will help in the future. To sum up, the code comes from the i915 DRM driver but it doesn't use it (i.e. it continues to use its internal implementation). Reviewed by: manu Approved by: manu Differential Revision: https://reviews.freebsd.org/D38088 (cherry picked from commit b99bc862324526b3ee6fad335618cbe85ad9e11e) --- .../linuxkpi/common/include/linux/io-mapping.h | 12 +++++ sys/compat/linuxkpi/common/include/linux/mm.h | 6 ++- sys/compat/linuxkpi/common/src/linux_page.c | 58 ++++++++++++++++++++++ 3 files changed, 75 insertions(+), 1 deletion(-) diff --git a/sys/compat/linuxkpi/common/include/linux/io-mapping.h b/sys/compat/linuxkpi/common/include/linux/io-mapping.h index 5c24f1ff8659..e874c5bcadc7 100644 --- a/sys/compat/linuxkpi/common/include/linux/io-mapping.h +++ b/sys/compat/linuxkpi/common/include/linux/io-mapping.h @@ -37,6 +37,7 @@ #include #include +#include #include struct io_mapping { @@ -100,6 +101,17 @@ io_mapping_map_wc(struct io_mapping *mapping, unsigned long offset, return ((char *)mapping->mem + offset); } +int lkpi_io_mapping_map_user(struct io_mapping *iomap, + struct vm_area_struct *vma, unsigned long addr, unsigned long pfn, + unsigned long size); + +static inline int +io_mapping_map_user(struct io_mapping *iomap, struct vm_area_struct *vma, + unsigned long addr, unsigned long pfn, unsigned long size) +{ + return (lkpi_io_mapping_map_user(iomap, vma, addr, pfn, size)); +} + static inline void io_mapping_unmap(void *vaddr) { diff --git a/sys/compat/linuxkpi/common/include/linux/mm.h b/sys/compat/linuxkpi/common/include/linux/mm.h index 4afc1a953f8e..8bee6188c9cd 100644 --- a/sys/compat/linuxkpi/common/include/linux/mm.h +++ b/sys/compat/linuxkpi/common/include/linux/mm.h @@ -218,11 +218,15 @@ apply_to_page_range(struct mm_struct *mm, unsigned long address, int zap_vma_ptes(struct vm_area_struct *vma, unsigned long address, unsigned long size); +int lkpi_remap_pfn_range(struct vm_area_struct *vma, + unsigned long start_addr, unsigned long start_pfn, unsigned long size, + pgprot_t prot); + static inline int remap_pfn_range(struct vm_area_struct *vma, unsigned long addr, unsigned long pfn, unsigned long size, pgprot_t prot) { - return (-ENOTSUP); + return (lkpi_remap_pfn_range(vma, addr, pfn, size, prot)); } static inline unsigned long diff --git a/sys/compat/linuxkpi/common/src/linux_page.c b/sys/compat/linuxkpi/common/src/linux_page.c index 5fa370147045..8b2006668f8f 100644 --- a/sys/compat/linuxkpi/common/src/linux_page.c +++ b/sys/compat/linuxkpi/common/src/linux_page.c @@ -67,6 +67,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #ifdef __i386__ DEFINE_IDR(mtrr_idr); @@ -334,6 +335,63 @@ retry: return (VM_FAULT_NOPAGE); } +int +lkpi_remap_pfn_range(struct vm_area_struct *vma, unsigned long start_addr, + unsigned long start_pfn, unsigned long size, pgprot_t prot) +{ + vm_object_t vm_obj; + unsigned long addr, pfn; + int err = 0; + + vm_obj = vma->vm_obj; + + VM_OBJECT_WLOCK(vm_obj); + for (addr = start_addr, pfn = start_pfn; + addr < start_addr + size; + addr += PAGE_SIZE) { + vm_fault_t ret; +retry: + ret = lkpi_vmf_insert_pfn_prot_locked(vma, addr, pfn, prot); + + if ((ret & VM_FAULT_OOM) != 0) { + VM_OBJECT_WUNLOCK(vm_obj); + vm_wait(NULL); + VM_OBJECT_WLOCK(vm_obj); + goto retry; + } + + if ((ret & VM_FAULT_ERROR) != 0) { + err = -EFAULT; + break; + } + + pfn++; + } + VM_OBJECT_WUNLOCK(vm_obj); + + if (unlikely(err)) { + zap_vma_ptes(vma, start_addr, + (pfn - start_pfn) << PAGE_SHIFT); + return (err); + } + + return (0); +} + +int +lkpi_io_mapping_map_user(struct io_mapping *iomap, + struct vm_area_struct *vma, unsigned long addr, + unsigned long pfn, unsigned long size) +{ + pgprot_t prot; + int ret; + + prot = cachemode2protval(iomap->attr); + ret = lkpi_remap_pfn_range(vma, addr, pfn, size, prot); + + return (ret); +} + /* * Although FreeBSD version of unmap_mapping_range has semantics and types of * parameters compatible with Linux version, the values passed in are different