From nobody Sat Feb 10 16:38:25 2024 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 4TXGcd4bVTz59y3t; Sat, 10 Feb 2024 16:38:25 +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 4TXGcd47Frz3x98; Sat, 10 Feb 2024 16:38:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1707583105; 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=RVyZsxjMM8eUDr9VsQ1JBy/Y+OMcyeGPBH5TtGWDLHU=; b=CR0d7Jj2f0Djn0n+ACbQQkVIH+0laBQQ77pzFvI5YmTfu/gjKrgM1ic64NBBo91VIbyWjM 6rp5HDabFkhPHXzZHVXtcEGTXk6JhGEc54Rc1KCwn0mU/U/q+YmGY/9qSo+8LPEDjIdcar kT+WKlLvkHA8XMhs9dadR364izIh+zN+w8PHsEdDrk4XmqTz6qA+Y3kkr8ZcOAMNWrb7he s5Ngh3XsyiNx0ZJ5D4hFF4o8nUD5+KwfJrqCN3iwjhiqqXKookxBv8chP1eZ0Q3XCfKIT+ 6mCnh5fAa1EcYvO8RmVMAWbu2enHY4Rn2cScsKzdhuzquK41uJR+2OxjWPAEZg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1707583105; a=rsa-sha256; cv=none; b=jmLbGy5+oNiyRMyyYGr7WstuCDIpa5XU6q9aQU9AbbKflTwzGjflFvPBYrKMeUtj7d0A6x K9MC4pZNUqNYtBQB6CQuIjMWKv44Wa393Qx2yscuQla8ztLGCkukU+Qgx5lXPF0NwjXS8o 8J1pS7P5FusCLtZB3/8h5wfN+Tqd1K9rTPjPdf8dxlGxdN5HRZGPMTcAHa6JkCVoe2envS EmaCbUvqf9XH2zi5bCJr1fUhbnWkDIC6fK3bePlSAp7P83FzjYe8q4PDbbEfGDGT5Yu4IE eXKIiASbHTxQVWnGOStXKzyDBSQU6Vong8slWaBYeGsRYqPDHz1mts4X64DaRw== 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=1707583105; 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=RVyZsxjMM8eUDr9VsQ1JBy/Y+OMcyeGPBH5TtGWDLHU=; b=KnTR9MBcWvEdT48XmnDJsCfpCp8yQRjYJkIxyoJev4//mkpeecdHDo12B4X38G0kaEEoip f9JPAQS8td8+dwvhEJgy4zH6YaGWZxkuJTe7eMNMA0gcKlYrAaXrln+5++3Mh1UqRoWBS+ OPUkQ6c257FzTly6wPCYlBVlzfXRPHdaOt011zRQox0AGYSBMqMOy/qRmKPZ6sky/L7OiF YTT8y7nplD7ydNens+wohJPLWwlb8wPViuWMBEuNsVVwJRmS1t8KJPTAw1esmVsGveZ5VX 6/bqD7lFsEQ+M8VM364vxlbMXlC0dd06tsUiZuBlK3YQ/odxRFDQx+BrXXF/TQ== 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 4TXGcd3Cb2zN3y; Sat, 10 Feb 2024 16:38:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 41AGcPOG050153; Sat, 10 Feb 2024 16:38:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41AGcPqR050149; Sat, 10 Feb 2024 16:38:25 GMT (envelope-from git) Date: Sat, 10 Feb 2024 16:38:25 GMT Message-Id: <202402101638.41AGcPqR050149@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 61cc4830a7b1 - main - Abstract UIO allocation and deallocation. 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 61cc4830a7b16400efade3d884a59fda6d80d651 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=61cc4830a7b16400efade3d884a59fda6d80d651 commit 61cc4830a7b16400efade3d884a59fda6d80d651 Author: Alfredo Mazzinghi AuthorDate: 2024-01-18 13:04:41 +0000 Commit: Mark Johnston CommitDate: 2024-02-10 16:38:04 +0000 Abstract UIO allocation and deallocation. Introduce the allocuio() and freeuio() functions to allocate and deallocate struct uio. This hides the actual allocator interface, so it is easier to modify the sub-allocation layout of struct uio and the corresponding iovec array. Obtained from: CheriBSD Reviewed by: kib, markj MFC after: 2 weeks Sponsored by: CHaOS, EPSRC grant EP/V000292/1 Differential Revision: https://reviews.freebsd.org/D43711 --- sys/amd64/linux32/linux32_machdep.c | 2 +- sys/cddl/compat/opensolaris/kern/opensolaris_uio.c | 2 +- sys/compat/freebsd32/freebsd32_misc.c | 29 ++++++++--------- sys/compat/linux/linux_file.c | 6 ++-- sys/kern/kern_jail.c | 6 ++-- sys/kern/kern_ktrace.c | 4 +-- sys/kern/kern_sendfile.c | 4 +-- sys/kern/subr_prf.c | 2 +- sys/kern/subr_uio.c | 38 +++++++++++++++++----- sys/kern/sys_generic.c | 8 ++--- sys/kern/vfs_aio.c | 4 +-- sys/kern/vfs_mount.c | 2 +- sys/kern/vfs_vnops.c | 2 +- sys/sys/uio.h | 2 ++ 14 files changed, 66 insertions(+), 45 deletions(-) diff --git a/sys/amd64/linux32/linux32_machdep.c b/sys/amd64/linux32/linux32_machdep.c index ba4dcc61af76..7f1c85cee201 100644 --- a/sys/amd64/linux32/linux32_machdep.c +++ b/sys/amd64/linux32/linux32_machdep.c @@ -106,7 +106,7 @@ linux_readv(struct thread *td, struct linux_readv_args *uap) if (error) return (error); error = kern_readv(td, uap->fd, auio); - free(auio, M_IOV); + freeuio(auio); return (error); } diff --git a/sys/cddl/compat/opensolaris/kern/opensolaris_uio.c b/sys/cddl/compat/opensolaris/kern/opensolaris_uio.c index e1cc8f802762..b2a08a55bba4 100644 --- a/sys/cddl/compat/opensolaris/kern/opensolaris_uio.c +++ b/sys/cddl/compat/opensolaris/kern/opensolaris_uio.c @@ -68,7 +68,7 @@ uiocopy(void *p, size_t n, enum uio_rw rw, struct uio *uio, size_t *cbytes) error = vn_io_fault_uiomove(p, n, uio_clone); *cbytes = uio->uio_resid - uio_clone->uio_resid; if (uio_clone != &small_uio_clone) - free(uio_clone, M_IOV); + freeuio(uio_clone); return (error); } diff --git a/sys/compat/freebsd32/freebsd32_misc.c b/sys/compat/freebsd32/freebsd32_misc.c index f2d66cf74b2b..facbf00a4c51 100644 --- a/sys/compat/freebsd32/freebsd32_misc.c +++ b/sys/compat/freebsd32/freebsd32_misc.c @@ -1196,32 +1196,29 @@ freebsd32_copyinuio(struct iovec32 *iovp, u_int iovcnt, struct uio **uiop) struct iovec32 iov32; struct iovec *iov; struct uio *uio; - u_int iovlen; int error, i; *uiop = NULL; if (iovcnt > UIO_MAXIOV) return (EINVAL); - iovlen = iovcnt * sizeof(struct iovec); - uio = malloc(iovlen + sizeof *uio, M_IOV, M_WAITOK); - iov = (struct iovec *)(uio + 1); + uio = allocuio(iovcnt); + iov = uio->uio_iov; for (i = 0; i < iovcnt; i++) { error = copyin(&iovp[i], &iov32, sizeof(struct iovec32)); if (error) { - free(uio, M_IOV); + freeuio(uio); return (error); } iov[i].iov_base = PTRIN(iov32.iov_base); iov[i].iov_len = iov32.iov_len; } - uio->uio_iov = iov; uio->uio_iovcnt = iovcnt; uio->uio_segflg = UIO_USERSPACE; uio->uio_offset = -1; uio->uio_resid = 0; for (i = 0; i < iovcnt; i++) { if (iov->iov_len > INT_MAX - uio->uio_resid) { - free(uio, M_IOV); + freeuio(uio); return (EINVAL); } uio->uio_resid += iov->iov_len; @@ -1241,7 +1238,7 @@ freebsd32_readv(struct thread *td, struct freebsd32_readv_args *uap) if (error) return (error); error = kern_readv(td, uap->fd, auio); - free(auio, M_IOV); + freeuio(auio); return (error); } @@ -1255,7 +1252,7 @@ freebsd32_writev(struct thread *td, struct freebsd32_writev_args *uap) if (error) return (error); error = kern_writev(td, uap->fd, auio); - free(auio, M_IOV); + freeuio(auio); return (error); } @@ -1269,7 +1266,7 @@ freebsd32_preadv(struct thread *td, struct freebsd32_preadv_args *uap) if (error) return (error); error = kern_preadv(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset)); - free(auio, M_IOV); + freeuio(auio); return (error); } @@ -1283,7 +1280,7 @@ freebsd32_pwritev(struct thread *td, struct freebsd32_pwritev_args *uap) if (error) return (error); error = kern_pwritev(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset)); - free(auio, M_IOV); + freeuio(auio); return (error); } @@ -2199,9 +2196,9 @@ freebsd32_do_sendfile(struct thread *td, out: if (hdr_uio) - free(hdr_uio, M_IOV); + freeuio(hdr_uio); if (trl_uio) - free(trl_uio, M_IOV); + freeuio(trl_uio); return (error); } @@ -2780,7 +2777,7 @@ freebsd32_jail_set(struct thread *td, struct freebsd32_jail_set_args *uap) if (error) return (error); error = kern_jail_set(td, auio, uap->flags); - free(auio, M_IOV); + freeuio(auio); return (error); } @@ -2807,7 +2804,7 @@ freebsd32_jail_get(struct thread *td, struct freebsd32_jail_get_args *uap) if (error != 0) break; } - free(auio, M_IOV); + freeuio(auio); return (error); } @@ -3540,7 +3537,7 @@ freebsd32_nmount(struct thread *td, return (error); error = vfs_donmount(td, flags, auio); - free(auio, M_IOV); + freeuio(auio); return error; } diff --git a/sys/compat/linux/linux_file.c b/sys/compat/linux/linux_file.c index 6eab8980a5c5..1279490ae8be 100644 --- a/sys/compat/linux/linux_file.c +++ b/sys/compat/linux/linux_file.c @@ -1038,7 +1038,7 @@ linux_preadv(struct thread *td, struct linux_preadv_args *uap) if (error != 0) return (error); error = kern_preadv(td, uap->fd, auio, offset); - free(auio, M_IOV); + freeuio(auio); return (error); } @@ -1065,7 +1065,7 @@ linux_pwritev(struct thread *td, struct linux_pwritev_args *uap) if (error != 0) return (error); error = kern_pwritev(td, uap->fd, auio, offset); - free(auio, M_IOV); + freeuio(auio); return (linux_enobufs2eagain(td, uap->fd, error)); } @@ -1872,6 +1872,6 @@ linux_writev(struct thread *td, struct linux_writev_args *args) if (error != 0) return (error); error = kern_writev(td, args->fd, auio); - free(auio, M_IOV); + freeuio(auio); return (linux_enobufs2eagain(td, args->fd, error)); } diff --git a/sys/kern/kern_jail.c b/sys/kern/kern_jail.c index fb674b991a73..90a043394792 100644 --- a/sys/kern/kern_jail.c +++ b/sys/kern/kern_jail.c @@ -537,7 +537,7 @@ sys_jail_set(struct thread *td, struct jail_set_args *uap) if (error) return (error); error = kern_jail_set(td, auio, uap->flags); - free(auio, M_IOV); + freeuio(auio); return (error); } @@ -2296,8 +2296,8 @@ sys_jail_get(struct thread *td, struct jail_get_args *uap) error = kern_jail_get(td, auio, uap->flags); if (error == 0) error = copyout(auio->uio_iov, uap->iovp, - uap->iovcnt * sizeof (struct iovec)); - free(auio, M_IOV); + uap->iovcnt * sizeof(struct iovec)); + freeuio(auio); return (error); } diff --git a/sys/kern/kern_ktrace.c b/sys/kern/kern_ktrace.c index eb14d60433dd..877a25ffa4cd 100644 --- a/sys/kern/kern_ktrace.c +++ b/sys/kern/kern_ktrace.c @@ -768,7 +768,7 @@ ktrgenio(int fd, enum uio_rw rw, struct uio *uio, int error) char *buf; if (error) { - free(uio, M_IOV); + freeuio(uio); return; } uio->uio_offset = 0; @@ -776,7 +776,7 @@ ktrgenio(int fd, enum uio_rw rw, struct uio *uio, int error) datalen = MIN(uio->uio_resid, ktr_geniosize); buf = malloc(datalen, M_KTRACE, M_WAITOK); error = uiomove(buf, datalen, uio); - free(uio, M_IOV); + freeuio(uio); if (error) { free(buf, M_KTRACE); return; diff --git a/sys/kern/kern_sendfile.c b/sys/kern/kern_sendfile.c index f6f6b57adfc7..323e7fcde07b 100644 --- a/sys/kern/kern_sendfile.c +++ b/sys/kern/kern_sendfile.c @@ -1331,8 +1331,8 @@ sendfile(struct thread *td, struct sendfile_args *uap, int compat) (void)copyout(&sbytes, uap->sbytes, sizeof(off_t)); out: - free(hdr_uio, M_IOV); - free(trl_uio, M_IOV); + freeuio(hdr_uio); + freeuio(trl_uio); return (error); } diff --git a/sys/kern/subr_prf.c b/sys/kern/subr_prf.c index 57ca158c6315..e291a1fa00a6 100644 --- a/sys/kern/subr_prf.c +++ b/sys/kern/subr_prf.c @@ -386,7 +386,7 @@ log_console(struct uio *uio) msglogstr(consbuffer, pri, /*filter_cr*/ 1); } msgbuftrigger = 1; - free(uio, M_IOV); + freeuio(uio); free(consbuffer, M_TEMP); } diff --git a/sys/kern/subr_uio.c b/sys/kern/subr_uio.c index e7c7de406d47..cbc4b0c0ed8e 100644 --- a/sys/kern/subr_uio.c +++ b/sys/kern/subr_uio.c @@ -373,21 +373,20 @@ copyinuio(const struct iovec *iovp, u_int iovcnt, struct uio **uiop) if (iovcnt > UIO_MAXIOV) return (EINVAL); iovlen = iovcnt * sizeof(struct iovec); - uio = malloc(iovlen + sizeof(*uio), M_IOV, M_WAITOK); - iov = (struct iovec *)(uio + 1); + uio = allocuio(iovcnt); + iov = uio->uio_iov; error = copyin(iovp, iov, iovlen); - if (error) { - free(uio, M_IOV); + if (error != 0) { + freeuio(uio); return (error); } - uio->uio_iov = iov; uio->uio_iovcnt = iovcnt; uio->uio_segflg = UIO_USERSPACE; uio->uio_offset = -1; uio->uio_resid = 0; for (i = 0; i < iovcnt; i++) { if (iov->iov_len > IOSIZE_MAX - uio->uio_resid) { - free(uio, M_IOV); + freeuio(uio); return (EINVAL); } uio->uio_resid += iov->iov_len; @@ -397,16 +396,39 @@ copyinuio(const struct iovec *iovp, u_int iovcnt, struct uio **uiop) return (0); } +struct uio * +allocuio(u_int iovcnt) +{ + struct uio *uio; + int iovlen; + + KASSERT(iovcnt <= UIO_MAXIOV, + ("Requested %u iovecs exceed UIO_MAXIOV", iovcnt)); + iovlen = iovcnt * sizeof(struct iovec); + uio = malloc(iovlen + sizeof(*uio), M_IOV, M_WAITOK); + uio->uio_iov = (struct iovec *)(uio + 1); + + return (uio); +} + +void +freeuio(struct uio *uio) +{ + free(uio, M_IOV); +} + struct uio * cloneuio(struct uio *uiop) { + struct iovec *iov; struct uio *uio; int iovlen; iovlen = uiop->uio_iovcnt * sizeof(struct iovec); - uio = malloc(iovlen + sizeof(*uio), M_IOV, M_WAITOK); + uio = allocuio(uiop->uio_iovcnt); + iov = uio->uio_iov; *uio = *uiop; - uio->uio_iov = (struct iovec *)(uio + 1); + uio->uio_iov = iov; bcopy(uiop->uio_iov, uio->uio_iov, iovlen); return (uio); } diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c index e185900b93be..9c0cb4e739e0 100644 --- a/sys/kern/sys_generic.c +++ b/sys/kern/sys_generic.c @@ -271,7 +271,7 @@ sys_readv(struct thread *td, struct readv_args *uap) if (error) return (error); error = kern_readv(td, uap->fd, auio); - free(auio, M_IOV); + freeuio(auio); return (error); } @@ -310,7 +310,7 @@ sys_preadv(struct thread *td, struct preadv_args *uap) if (error) return (error); error = kern_preadv(td, uap->fd, auio, uap->offset); - free(auio, M_IOV); + freeuio(auio); return (error); } @@ -473,7 +473,7 @@ sys_writev(struct thread *td, struct writev_args *uap) if (error) return (error); error = kern_writev(td, uap->fd, auio); - free(auio, M_IOV); + freeuio(auio); return (error); } @@ -512,7 +512,7 @@ sys_pwritev(struct thread *td, struct pwritev_args *uap) if (error) return (error); error = kern_pwritev(td, uap->fd, auio, uap->offset); - free(auio, M_IOV); + freeuio(auio); return (error); } diff --git a/sys/kern/vfs_aio.c b/sys/kern/vfs_aio.c index 13f99a71ef04..1195d92d54ab 100644 --- a/sys/kern/vfs_aio.c +++ b/sys/kern/vfs_aio.c @@ -555,7 +555,7 @@ aio_free_entry(struct kaiocb *job) fdrop(job->fd_file, curthread); crfree(job->cred); if (job->uiop != &job->uio) - free(job->uiop, M_IOV); + freeuio(job->uiop); uma_zfree(aiocb_zone, job); AIO_LOCK(ki); @@ -1728,7 +1728,7 @@ err3: knlist_delete(&job->klist, curthread, 0); err2: if (job->uiop != &job->uio) - free(job->uiop, M_IOV); + freeuio(job->uiop); uma_zfree(aiocb_zone, job); err1: ops->store_error(ujob, error); diff --git a/sys/kern/vfs_mount.c b/sys/kern/vfs_mount.c index 347ec7f70aaf..2b235d398332 100644 --- a/sys/kern/vfs_mount.c +++ b/sys/kern/vfs_mount.c @@ -473,7 +473,7 @@ sys_nmount(struct thread *td, struct nmount_args *uap) } error = vfs_donmount(td, flags, auio); - free(auio, M_IOV); + freeuio(auio); return (error); } diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index dc2efee038bb..77e4dd21f276 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -1442,7 +1442,7 @@ vn_io_fault1(struct vnode *vp, struct uio *uio, struct vn_io_fault_args *args, td->td_ma_cnt = prev_td_ma_cnt; curthread_pflags_restore(saveheld); out: - free(uio_clone, M_IOV); + freeuio(uio_clone); return (error); } diff --git a/sys/sys/uio.h b/sys/sys/uio.h index e7bb74c908d8..42ab0cda8e38 100644 --- a/sys/sys/uio.h +++ b/sys/sys/uio.h @@ -76,6 +76,8 @@ struct vm_object; struct vm_page; struct bus_dma_segment; +struct uio *allocuio(u_int iovcnt); +void freeuio(struct uio *uio); struct uio *cloneuio(struct uio *uiop); int copyiniov(const struct iovec *iovp, u_int iovcnt, struct iovec **iov, int error);