Page MenuHomeFreeBSD

D57688.id180110.diff
No OneTemporary

D57688.id180110.diff

diff --git a/sys/amd64/amd64/uio_machdep.c b/sys/amd64/amd64/uio_machdep.c
--- a/sys/amd64/amd64/uio_machdep.c
+++ b/sys/amd64/amd64/uio_machdep.c
@@ -42,6 +42,7 @@
#include <sys/proc.h>
#include <sys/systm.h>
#include <sys/uio.h>
+#include <sys/_uio_common.h>
#include <vm/vm.h>
#include <vm/vm_extern.h>
@@ -96,33 +97,10 @@
&ma[offset >> PAGE_SHIFT], &vaddr, 1, true);
cp = (char *)vaddr + page_offset;
}
- switch (uio->uio_segflg) {
- case UIO_USERSPACE:
- maybe_yield();
- switch (uio->uio_rw) {
- case UIO_READ:
- error = copyout(cp, iov->iov_base, cnt);
- break;
- case UIO_WRITE:
- error = copyin(iov->iov_base, cp, cnt);
- break;
- }
- if (error)
- goto out;
- break;
- case UIO_SYSSPACE:
- switch (uio->uio_rw) {
- case UIO_READ:
- bcopy(cp, iov->iov_base, cnt);
- break;
- case UIO_WRITE:
- bcopy(iov->iov_base, cp, cnt);
- break;
- }
- break;
- case UIO_NOCOPY:
- break;
- }
+ error = uiomove_docopy(uio->uio_segflg, uio->uio_rw, cp,
+ iov->iov_base, cnt);
+ if (error != 0)
+ goto out;
if (__predict_false(mapped)) {
pmap_unmap_io_transient(&ma[offset >> PAGE_SHIFT],
&vaddr, 1, true);
diff --git a/sys/arm/arm/uio_machdep.c b/sys/arm/arm/uio_machdep.c
--- a/sys/arm/arm/uio_machdep.c
+++ b/sys/arm/arm/uio_machdep.c
@@ -43,6 +43,7 @@
#include <sys/systm.h>
#include <sys/uio.h>
#include <sys/sf_buf.h>
+#include <sys/_uio_common.h>
#include <vm/vm.h>
#include <vm/vm_page.h>
@@ -91,35 +92,10 @@
cnt = min(cnt, PAGE_SIZE - page_offset);
sf = sf_buf_alloc(ma[offset >> PAGE_SHIFT], 0);
cp = (char*)sf_buf_kva(sf) + page_offset;
- switch (uio->uio_segflg) {
- case UIO_USERSPACE:
- maybe_yield();
- switch (uio->uio_rw) {
- case UIO_READ:
- error = copyout(cp, iov->iov_base, cnt);
- break;
- case UIO_WRITE:
- error = copyin(iov->iov_base, cp, cnt);
- break;
- }
- if (error) {
- sf_buf_free(sf);
- goto out;
- }
- break;
- case UIO_SYSSPACE:
- switch (uio->uio_rw) {
- case UIO_READ:
- bcopy(cp, iov->iov_base, cnt);
- break;
- case UIO_WRITE:
- bcopy(iov->iov_base, cp, cnt);
- break;
- }
- break;
- case UIO_NOCOPY:
- break;
- }
+ error = uiomove_docopy(uio->uio_segflg, uio->uio_rw, cp,
+ iov->iov_base, cnt);
+ if (error != 0)
+ goto out;
sf_buf_free(sf);
iov->iov_base = (char *)iov->iov_base + cnt;
iov->iov_len -= cnt;
diff --git a/sys/arm64/arm64/uio_machdep.c b/sys/arm64/arm64/uio_machdep.c
--- a/sys/arm64/arm64/uio_machdep.c
+++ b/sys/arm64/arm64/uio_machdep.c
@@ -40,6 +40,7 @@
#include <sys/proc.h>
#include <sys/systm.h>
#include <sys/uio.h>
+#include <sys/_uio_common.h>
#include <vm/vm.h>
#include <vm/vm_page.h>
@@ -92,33 +93,10 @@
&ma[offset >> PAGE_SHIFT], &vaddr, 1, true);
cp = (char *)vaddr + page_offset;
}
- switch (uio->uio_segflg) {
- case UIO_USERSPACE:
- maybe_yield();
- switch (uio->uio_rw) {
- case UIO_READ:
- error = copyout(cp, iov->iov_base, cnt);
- break;
- case UIO_WRITE:
- error = copyin(iov->iov_base, cp, cnt);
- break;
- }
- if (error)
- goto out;
- break;
- case UIO_SYSSPACE:
- switch (uio->uio_rw) {
- case UIO_READ:
- bcopy(cp, iov->iov_base, cnt);
- break;
- case UIO_WRITE:
- bcopy(iov->iov_base, cp, cnt);
- break;
- }
- break;
- case UIO_NOCOPY:
- break;
- }
+ error = uiomove_docopy(uio->uio_segflg, uio->uio_rw, cp,
+ iov->iov_base, cnt);
+ if (error != 0)
+ goto out;
if (__predict_false(mapped)) {
pmap_unmap_io_transient(&ma[offset >> PAGE_SHIFT],
&vaddr, 1, true);
diff --git a/sys/i386/i386/uio_machdep.c b/sys/i386/i386/uio_machdep.c
--- a/sys/i386/i386/uio_machdep.c
+++ b/sys/i386/i386/uio_machdep.c
@@ -44,6 +44,7 @@
#include <sys/sched.h>
#include <sys/sf_buf.h>
#include <sys/uio.h>
+#include <sys/_uio_common.h>
#include <vm/vm.h>
#include <vm/vm_page.h>
@@ -91,36 +92,10 @@
sched_pin();
sf = sf_buf_alloc(ma[offset >> PAGE_SHIFT], SFB_CPUPRIVATE);
cp = (char *)sf_buf_kva(sf) + page_offset;
- switch (uio->uio_segflg) {
- case UIO_USERSPACE:
- maybe_yield();
- switch (uio->uio_rw) {
- case UIO_READ:
- error = copyout(cp, iov->iov_base, cnt);
- break;
- case UIO_WRITE:
- error = copyin(iov->iov_base, cp, cnt);
- break;
- }
- if (error) {
- sf_buf_free(sf);
- sched_unpin();
- goto out;
- }
- break;
- case UIO_SYSSPACE:
- switch (uio->uio_rw) {
- case UIO_READ:
- bcopy(cp, iov->iov_base, cnt);
- break;
- case UIO_WRITE:
- bcopy(iov->iov_base, cp, cnt);
- break;
- }
- break;
- case UIO_NOCOPY:
- break;
- }
+ error = uiomove_docopy(uio->uio_segflg, uio->uio_rw, cp,
+ iov->iov_base, cnt);
+ if (error != 0)
+ goto out;
sf_buf_free(sf);
sched_unpin();
iov->iov_base = (char *)iov->iov_base + cnt;
diff --git a/sys/kern/subr_uio.c b/sys/kern/subr_uio.c
--- a/sys/kern/subr_uio.c
+++ b/sys/kern/subr_uio.c
@@ -51,6 +51,7 @@
#include <sys/sched.h>
#include <sys/sysctl.h>
#include <sys/vnode.h>
+#include <sys/_uio_common.h>
#include <vm/vm.h>
#include <vm/vm_param.h>
@@ -246,34 +247,10 @@
if (cnt > n)
cnt = n;
- switch (uio->uio_segflg) {
- case UIO_USERSPACE:
- maybe_yield();
- switch (uio->uio_rw) {
- case UIO_READ:
- error = copyout(cp, iov->iov_base, cnt);
- break;
- case UIO_WRITE:
- error = copyin(iov->iov_base, cp, cnt);
- break;
- }
- if (error)
- goto out;
- break;
-
- case UIO_SYSSPACE:
- switch (uio->uio_rw) {
- case UIO_READ:
- bcopy(cp, iov->iov_base, cnt);
- break;
- case UIO_WRITE:
- bcopy(iov->iov_base, cp, cnt);
- break;
- }
- break;
- case UIO_NOCOPY:
- break;
- }
+ error = uiomove_docopy(uio->uio_segflg, uio->uio_rw, cp,
+ iov->iov_base, cnt);
+ if (error != 0)
+ goto out;
iov->iov_base = (char *)iov->iov_base + cnt;
iov->iov_len -= cnt;
uio->uio_resid -= cnt;
diff --git a/sys/powerpc/powerpc/uio_machdep.c b/sys/powerpc/powerpc/uio_machdep.c
--- a/sys/powerpc/powerpc/uio_machdep.c
+++ b/sys/powerpc/powerpc/uio_machdep.c
@@ -43,6 +43,7 @@
#include <sys/proc.h>
#include <sys/uio.h>
#include <sys/sf_buf.h>
+#include <sys/_uio_common.h>
#include <vm/vm.h>
#include <vm/vm_page.h>
@@ -97,35 +98,10 @@
sf = sf_buf_alloc(m, 0);
cp = (char*)sf_buf_kva(sf) + page_offset;
- switch (uio->uio_segflg) {
- case UIO_USERSPACE:
- maybe_yield();
- switch (uio->uio_rw) {
- case UIO_READ:
- error = copyout(cp, iov->iov_base, cnt);
- break;
- case UIO_WRITE:
- error = copyin(iov->iov_base, cp, cnt);
- break;
- }
- if (error) {
- sf_buf_free(sf);
- goto out;
- }
- break;
- case UIO_SYSSPACE:
- switch (uio->uio_rw) {
- case UIO_READ:
- bcopy(cp, iov->iov_base, cnt);
- break;
- case UIO_WRITE:
- bcopy(iov->iov_base, cp, cnt);
- break;
- }
- break;
- case UIO_NOCOPY:
- break;
- }
+ error = uiomove_docopy(uio->uio_segflg, uio->uio_rw, cp,
+ iov->iov_base, cnt);
+ if (error != 0)
+ goto out;
sf_buf_free(sf);
iov->iov_base = (char *)iov->iov_base + cnt;
iov->iov_len -= cnt;
diff --git a/sys/riscv/riscv/uio_machdep.c b/sys/riscv/riscv/uio_machdep.c
--- a/sys/riscv/riscv/uio_machdep.c
+++ b/sys/riscv/riscv/uio_machdep.c
@@ -40,6 +40,7 @@
#include <sys/proc.h>
#include <sys/systm.h>
#include <sys/uio.h>
+#include <sys/_uio_common.h>
#include <vm/vm.h>
#include <vm/vm_page.h>
@@ -92,33 +93,10 @@
&ma[offset >> PAGE_SHIFT], &vaddr, 1, true);
cp = (char *)vaddr + page_offset;
}
- switch (uio->uio_segflg) {
- case UIO_USERSPACE:
- maybe_yield();
- switch (uio->uio_rw) {
- case UIO_READ:
- error = copyout(cp, iov->iov_base, cnt);
- break;
- case UIO_WRITE:
- error = copyin(iov->iov_base, cp, cnt);
- break;
- }
- if (error)
- goto out;
- break;
- case UIO_SYSSPACE:
- switch (uio->uio_rw) {
- case UIO_READ:
- bcopy(cp, iov->iov_base, cnt);
- break;
- case UIO_WRITE:
- bcopy(iov->iov_base, cp, cnt);
- break;
- }
- break;
- case UIO_NOCOPY:
- break;
- }
+ error = uiomove_docopy(uio->uio_segflg, uio->uio_rw, cp,
+ iov->iov_base, cnt);
+ if (error != 0)
+ goto out;
if (__predict_false(mapped)) {
pmap_unmap_io_transient(&ma[offset >> PAGE_SHIFT],
&vaddr, 1, true);
diff --git a/sys/sys/_uio_common.h b/sys/sys/_uio_common.h
new file mode 100644
--- /dev/null
+++ b/sys/sys/_uio_common.h
@@ -0,0 +1,79 @@
+/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 1982, 1986, 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _SYS__UIO_COMMON_H_
+#define _SYS__UIO_COMMON_H_
+
+#ifdef _KERNEL
+
+static inline int
+uiomove_docopy(enum uio_seg segflg, enum uio_rw rw, void *cp, void *base,
+ size_t cnt)
+{
+ int error = 0;
+
+ switch (segflg) {
+ case UIO_USERSPACE:
+ maybe_yield();
+ switch (rw) {
+ case UIO_READ:
+ error = copyout(cp, base, cnt);
+ break;
+ case UIO_WRITE:
+ error = copyin(base, cp, cnt);
+ break;
+ }
+ break;
+ case UIO_SYSSPACE:
+ switch (rw) {
+ case UIO_READ:
+ memcpy(base, cp, cnt);
+ break;
+ case UIO_WRITE:
+ memcpy(cp, base, cnt);
+ break;
+ }
+ break;
+ case UIO_NOCOPY:
+ break;
+ }
+
+ return (error);
+}
+
+#endif /* _KERNEL */
+
+#endif /* !_SYS_UIO_COMMON_H_ */

File Metadata

Mime Type
text/plain
Expires
Thu, Jun 25, 8:09 AM (9 h, 12 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34315792
Default Alt Text
D57688.id180110.diff (10 KB)

Event Timeline