From nobody Thu Jun 4 00:36:23 2026 X-Original-To: dev-commits-src-branches@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 4gW5Gc29kMz6h61s for ; Thu, 04 Jun 2026 00:36:24 +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 "R13" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4gW5Gc07Hyz3prs for ; Thu, 04 Jun 2026 00:36:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1780533384; 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=8isxXw/4XanLrZfMFcKNluBB++8qnqNrdLSJcH3ZPkg=; b=nv6AkVkb5hrRi54cYI+eHaGqDZOv21roQi2yBgNAYsqEJbS8THOwQQxKDwgDu53jqfaU7q f603jcOodUhf/S8N5dzgtqVWhrrvVk6GFe2m4GNQAlLo/qt//IXkDtSRX6i4wZ8Prv3N0E RaA3ERoeMiBmHzqf5rNA5zOpqhNAlNZFWidRuvOGgvAbBhf6VtPQjRv9Inn4sBoOHTKklG CjV6NT8w1xtPzOuy6OT1XnLCc7VCP2nX7J5zm+tQLvqoTzYNbla4kPCSC6cxmy9did6kyw aa+6xaakPBlN6/3RZBH7HcwBn3f9JvjvxErWuaX48ADQ0D1bYJAnoR7DnE9Hqw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1780533384; a=rsa-sha256; cv=none; b=PJhDpUGYLGW+X6F+uURjbqYUqGkadXCvH6fZsn9Y+Mg5HbMidHj0Y22AzPF7SbsXsyjAYa cCS2f8GS0CQuPNJJyU5oP8wUONvxY25Q/NBvqQnhIWMYFZdWJYBRtjCRoc1q7L/I8CqynW HH7T5jsQZ92NE3kTXV50YdrLmKiDUXSNJp6W8dNwPz74G9TrrERgyRau6DxEClfWnGBdYa 4C+AotdPa3jWawNze5e2HPUvhKxakW5fb1PdaoaP735w0Du6QpKCq1XOjZWjjAKs+p0v5S EEgb0x3tcFGZDKcFyaNfiLbCN0RWK6aom17uSxr7kcc+zDFrWfBNljSXrBf9sw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1780533384; 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=8isxXw/4XanLrZfMFcKNluBB++8qnqNrdLSJcH3ZPkg=; b=V1e+3N9N8MiXdx/trmmNM+8tlPmyaVuU0Dlg6K5/+bbZx34bS+auzBCAtL/BChitXd+xIC 8G4PJXFviIuFHXjEEC/WIs+qkuPYPIa9BjR0OO23fH5zj2hNDHyFI0hJkvcU5QoJ3bAuY6 8Rg8gF1wIkayPPwHtxDm+ieh9X/J+OwMg41ZzsMqxv1zWMKN6BJxnME2aFprRbAx0EPPjo pGZSER1kYe5Ncy4QJ59xl1LU6XfwqP57UwoeeEqr0SLUr6bsCoyATs8v7xU57KLseJihYg J2/Es98VD5Y2gZv2D0U7RdoCW5I4DcW4eujFiC4fzmRpOtSPLXOYiW0zesDuJQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4gW5Gb6rRFzbtM for ; Thu, 04 Jun 2026 00:36:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 206c7 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 04 Jun 2026 00:36:23 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 9681364e4b6d - stable/15 - amd64: extract uiomove_mem() from memrw() List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: 9681364e4b6dfa78a23122b8e1310d37df849dc1 Auto-Submitted: auto-generated Date: Thu, 04 Jun 2026 00:36:23 +0000 Message-Id: <6a20c887.206c7.d13b1d2@gitrepo.freebsd.org> The branch stable/15 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=9681364e4b6dfa78a23122b8e1310d37df849dc1 commit 9681364e4b6dfa78a23122b8e1310d37df849dc1 Author: Konstantin Belousov AuthorDate: 2026-05-24 11:48:45 +0000 Commit: Konstantin Belousov CommitDate: 2026-06-04 00:34:43 +0000 amd64: extract uiomove_mem() from memrw() (cherry picked from commit 67d61d18bb8debb4ffc51ef2248aa37ed0bfb8f5) --- sys/amd64/amd64/mem.c | 103 +++++------------------------------------- sys/amd64/amd64/uio_machdep.c | 96 +++++++++++++++++++++++++++++++++++++++ sys/amd64/include/md_var.h | 6 +++ 3 files changed, 113 insertions(+), 92 deletions(-) diff --git a/sys/amd64/amd64/mem.c b/sys/amd64/amd64/mem.c index 851f2df0e6e1..7d1f0f42d01c 100644 --- a/sys/amd64/amd64/mem.c +++ b/sys/amd64/amd64/mem.c @@ -61,10 +61,6 @@ #include #include -#include -#include -#include - #include /* @@ -72,99 +68,22 @@ */ MALLOC_DEFINE(M_MEMDESC, "memdesc", "memory range descriptors"); -/* ARGSUSED */ int memrw(struct cdev *dev, struct uio *uio, int flags) { - struct iovec *iov; - void *p; - ssize_t orig_resid; - vm_prot_t prot; - u_long v, vd; - u_int c; - int error; - - error = 0; - orig_resid = uio->uio_resid; - while (uio->uio_resid > 0 && error == 0) { - iov = uio->uio_iov; - if (iov->iov_len == 0) { - uio->uio_iov++; - uio->uio_iovcnt--; - if (uio->uio_iovcnt < 0) - panic("memrw"); - continue; - } - v = uio->uio_offset; - c = ulmin(iov->iov_len, PAGE_SIZE - (u_int)(v & PAGE_MASK)); - - switch (dev2unit(dev)) { - case CDEV_MINOR_KMEM: - /* - * Since c is clamped to be less or equal than - * PAGE_SIZE, the uiomove() call does not - * access past the end of the direct map. - */ - if (v >= kva_layout.dmap_low && - v < kva_layout.dmap_high) { - error = uiomove((void *)v, c, uio); - break; - } - - switch (uio->uio_rw) { - case UIO_READ: - prot = VM_PROT_READ; - break; - case UIO_WRITE: - prot = VM_PROT_WRITE; - break; - } + enum uiomove_mem_req req; - if (!kernacc((void *)v, c, prot)) { - error = EFAULT; - break; - } - - /* - * If the extracted address is not accessible - * through the direct map, then we make a - * private (uncached) mapping because we can't - * depend on the existing kernel mapping - * remaining valid until the completion of - * uiomove(). - * - * XXX We cannot provide access to the - * physical page 0 mapped into KVA. - */ - v = pmap_extract(kernel_pmap, v); - if (v == 0) { - error = EFAULT; - break; - } - /* FALLTHROUGH */ - case CDEV_MINOR_MEM: - if (v < dmaplimit) { - vd = PHYS_TO_DMAP(v); - error = uiomove((void *)vd, c, uio); - break; - } - if (v > cpu_getmaxphyaddr()) { - error = EFAULT; - break; - } - p = pmap_mapdev(v, PAGE_SIZE); - error = uiomove(p, c, uio); - pmap_unmapdev(p, PAGE_SIZE); - break; - } + switch (dev2unit(dev)) { + case CDEV_MINOR_KMEM: + req = UIO_MEM_KMEM; + break; + case CDEV_MINOR_MEM: + req = UIO_MEM_MEM; + break; + default: + __unreachable(); } - /* - * Don't return error if any byte was written. Read and write - * can return error only if no i/o was performed. - */ - if (uio->uio_resid != orig_resid) - error = 0; - return (error); + return (uiomove_mem(req, uio)); } /* diff --git a/sys/amd64/amd64/uio_machdep.c b/sys/amd64/amd64/uio_machdep.c index 83795653fa28..0f29e7f7435f 100644 --- a/sys/amd64/amd64/uio_machdep.c +++ b/sys/amd64/amd64/uio_machdep.c @@ -44,9 +44,11 @@ #include #include +#include #include #include +#include /* * Implement uiomove(9) from physical memory using the direct map to @@ -141,3 +143,97 @@ out: td->td_pflags &= ~TDP_DEADLKTREAT; return (error); } + +int +uiomove_mem(enum uiomove_mem_req req, struct uio *uio) +{ + struct iovec *iov; + void *p, *vd; + ssize_t orig_resid; + vm_prot_t prot; + u_long v; + u_int c; + int error; + + error = 0; + orig_resid = uio->uio_resid; + while (uio->uio_resid > 0 && error == 0) { + iov = uio->uio_iov; + if (iov->iov_len == 0) { + uio->uio_iov++; + uio->uio_iovcnt--; + if (uio->uio_iovcnt < 0) + panic("memrw"); + continue; + } + v = uio->uio_offset; + c = ulmin(iov->iov_len, PAGE_SIZE - (u_int)(v & PAGE_MASK)); + + switch (req) { + case UIO_MEM_KMEM: + /* + * Since c is clamped to be less or equal than + * PAGE_SIZE, the uiomove() call does not + * access past the end of the direct map. + */ + if (v >= kva_layout.dmap_low && + v < kva_layout.dmap_high) { + error = uiomove((void *)v, c, uio); + break; + } + + switch (uio->uio_rw) { + case UIO_READ: + prot = VM_PROT_READ; + break; + case UIO_WRITE: + prot = VM_PROT_WRITE; + break; + } + + if (!kernacc((void *)v, c, prot)) { + error = EFAULT; + break; + } + + /* + * If the extracted address is not accessible + * through the direct map, then we make a + * private (uncached) mapping because we can't + * depend on the existing kernel mapping + * remaining valid until the completion of + * uiomove(). + * + * XXX We cannot provide access to the + * physical page 0 mapped into KVA. + */ + v = pmap_extract(kernel_pmap, v); + if (v == 0) { + error = EFAULT; + break; + } + /* FALLTHROUGH */ + case UIO_MEM_MEM: + if (v < dmaplimit) { + vd = (void *)PHYS_TO_DMAP(v); + error = uiomove(vd, c, uio); + break; + } + if (v > cpu_getmaxphyaddr()) { + error = EFAULT; + break; + } + p = pmap_mapdev(v, PAGE_SIZE); + error = uiomove(p, c, uio); + pmap_unmapdev(p, PAGE_SIZE); + break; + } + } + /* + * Don't return error if any byte was written. Read and write + * can return error only if no i/o was performed. + */ + if (uio->uio_resid != orig_resid) + error = 0; + return (error); +} diff --git a/sys/amd64/include/md_var.h b/sys/amd64/include/md_var.h index 46a30518b212..5a71b9109eba 100644 --- a/sys/amd64/include/md_var.h +++ b/sys/amd64/include/md_var.h @@ -107,6 +107,12 @@ void wrmsr_early_safe_start(void); void wrmsr_early_safe_end(void); int wrmsr_early_safe(u_int msr, uint64_t data); +enum uiomove_mem_req { + UIO_MEM_KMEM = 101, + UIO_MEM_MEM, +}; +int uiomove_mem(enum uiomove_mem_req req, struct uio *uio); + #endif /* !_MACHINE_MD_VAR_H_ */ #endif /* __i386__ */