From nobody Wed Jan 25 21:39:03 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 4P2HKN1Ll1z3bVy4; Wed, 25 Jan 2023 21:39:04 +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 4P2HKM6jrmz40rH; Wed, 25 Jan 2023 21:39:03 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674682744; 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=dK7/dPXImJemeau+S24E7AVUUHPVafJwxOlfHTdX8RM=; b=Zno3jIAhLhrTaDEjNzliDfK1OE4lLhEb1Mcz5mt6flvBWsOzR2GArY4qPzzQa5bpjnjrpk JawU0otBC9u5FniKbsbWwYr+rJa1cqJ3A1gfvJrDTQUR3Ggknpkht82DNe2IlKMP7KzHzQ y66t0f3m8+dPQGGL0WBdpIbX2oA7HyHewN6TCJoLAm2b8nC3yajZiGGaSt1z9aQVbtoThU QGn/t7UGi9ritux9iIU+Mlpgv7iRRwZViP9QRo0th32EfhtGal+Lp1UV6zSFMHnkmw7Hkh i3YZNOghd/4W+DWlBanAxG3qi6uJj8A8d0xcunUOxnFRTVNk1ojepKVgD/fkLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674682744; 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=dK7/dPXImJemeau+S24E7AVUUHPVafJwxOlfHTdX8RM=; b=s9GoHMtfEcR7w3oOL6wrRv+LdLD2pDkL8PAPV5qXs7dxwgc1jynhjb1p4RDpmqKe2ThM3m URTG0zNFyGNIdvFyUDXmwOUwCGdd9u+TR8rpvYfWYJSKpDhQ3Q9cUE28zxepoCP/HBhdwA 82TXed2Ar1fRAxFnhi9C0Uk26OnVpB6GIqHKjllLo8BpiMkjgcBsYStKYjYIC26SwUYwp6 7mZ2wf054wnHYRr0DUlGsS9Ud9TzOGF650dnMD0DQ9dnPPY50SGMONTi3E8R/BQr1v1cB9 ygwMrrMensmFbG3s9aMxhYBWWrU9+BW+mSJ/8gWAOcyKcEVPvdX+DhANgykKDQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674682744; a=rsa-sha256; cv=none; b=Vvbew4nxMRAfAYz6HYNUwGZBhmxS6PQGDBhkXz4IxnRjh/X1veLi9TblybvWdYZDGcmxEi RICOLhx5UMGoUPHb2UIZQvSkNqpxVnurcfMWc+cUVR9xNHFMW1kEtZwNk8RSxsIHF+StdH gIArZLwLmasNaj6uZndh+DOBzKNKSOrhibH4BAYQBPro5t5aAk++nttgqI2U3EpoENnUJj OyO2xY3HADVz/N1ksm9OkrKsR9DQ9Q4NedELo7LCYclvGlZIJYx99x8y8a8pQLLAP/bQ/y mx+/nLzK5kjNKKHTsBijCZ7lKxh3JSbMVLbjDeK5LXxthNbz+cF3PmUIevfYaw== 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 4P2HKM5psYz14Wm; Wed, 25 Jan 2023 21:39:03 +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 30PLd3F7007624; Wed, 25 Jan 2023 21:39:03 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30PLd3lU007623; Wed, 25 Jan 2023 21:39:03 GMT (envelope-from git) Date: Wed, 25 Jan 2023 21:39:03 GMT Message-Id: <202301252139.30PLd3lU007623@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Jean-S=C3=A9bastien=20P=C3=A9dron?= Subject: git: b99bc8623245 - main - 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/main X-Git-Reftype: branch X-Git-Commit: b99bc862324526b3ee6fad335618cbe85ad9e11e Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by dumbbell (ports committer): URL: https://cgit.FreeBSD.org/src/commit/?id=b99bc862324526b3ee6fad335618cbe85ad9e11e commit b99bc862324526b3ee6fad335618cbe85ad9e11e Author: Jean-Sébastien Pédron AuthorDate: 2023-01-14 12:22:19 +0000 Commit: Jean-Sébastien Pédron CommitDate: 2023-01-25 21:26:54 +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 --- .../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 930d588902af..5cf4453dc966 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 4c93d2f69354..c4d0d332af14 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