svn commit: r365749 - head/usr.bin/posixshmcontrol
Author: markj Date: Tue Sep 15 13:36:19 2020 New Revision: 365749 URL: https://svnweb.freebsd.org/changeset/base/365749 Log: Fix some posixshmcontrol nits. - Exit with an error if no path is specified. - Man page typo. - Error message typo. Reviewed by: kib Sponsored by: Juniper Networks, Inc. Sponsored by: Klara, Inc. MFC after:1 week Differential Revision:https://reviews.freebsd.org/D26376 Modified: head/usr.bin/posixshmcontrol/posixshmcontrol.1 head/usr.bin/posixshmcontrol/posixshmcontrol.c Modified: head/usr.bin/posixshmcontrol/posixshmcontrol.1 == --- head/usr.bin/posixshmcontrol/posixshmcontrol.1 Tue Sep 15 12:34:01 2020(r365748) +++ head/usr.bin/posixshmcontrol/posixshmcontrol.1 Tue Sep 15 13:36:19 2020(r365749) @@ -120,7 +120,7 @@ using name-switch services, instead the raw numeric va To show content of the shared memory segment with the path .Pa /1 , use the command -.Dl "posixshmcontrol dump /q | hexdump -C" +.Dl "posixshmcontrol dump /1 | hexdump -C" .It To create a segment with the path .Pa /2 Modified: head/usr.bin/posixshmcontrol/posixshmcontrol.c == --- head/usr.bin/posixshmcontrol/posixshmcontrol.c Tue Sep 15 12:34:01 2020(r365748) +++ head/usr.bin/posixshmcontrol/posixshmcontrol.c Tue Sep 15 13:36:19 2020(r365749) @@ -147,9 +147,14 @@ create_shm(int argc, char **argv) return (2); } } - argc -= optind; argv += optind; + + if (argc == 0) { + usage(); + return (2); + } + ret = 0; for (i = 0; i < argc; i++) { ret1 = create_one_shm(argv[i], mode, idx); @@ -179,6 +184,11 @@ delete_shm(int argc, char **argv) { int i, ret, ret1; + if (argc == 1) { + usage(); + return (2); + } + ret = 0; for (i = 1; i < argc; i++) { ret1 = delete_one_shm(argv[i]); @@ -347,6 +357,11 @@ read_shm(int argc, char **argv) { int i, ret, ret1; + if (argc == 1) { + usage(); + return (2); + } + ret = 0; for (i = 1; i < argc; i++) { ret1 = read_one_shm(argv[i]); @@ -433,6 +448,11 @@ stat_shm(int argc, char **argv) argc -= optind; argv += optind; + if (argc == 0) { + usage(); + return (2); + } + ret = 0; for (i = 0; i < argc; i++) { ret1 = stat_one_shm(argv[i], hsize, uname); @@ -473,16 +493,21 @@ truncate_shm(int argc, char **argv) switch (c) { case 's': if (expand_number(optarg, &newsize) == -1) - err(1, "size:"); + err(1, "size"); break; case '?': default: return (2); } } - argc -= optind; argv += optind; + + if (argc == 0) { + usage(); + return (2); + } + ret = 0; for (i = 0; i < argc; i++) { ret1 = truncate_one_shm(argv[i], newsize); ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r365750 - head/sys/arm64/arm64
Author: andrew Date: Tue Sep 15 14:15:04 2020 New Revision: 365750 URL: https://svnweb.freebsd.org/changeset/base/365750 Log: Use ATTR_DEFAULT in the arm64 locore.S We can use ATTR_DEFAULT directly in locore.S as it fits within an orr instruction operand. Sponsored by: Innovate UK Modified: head/sys/arm64/arm64/locore.S Modified: head/sys/arm64/arm64/locore.S == --- head/sys/arm64/arm64/locore.S Tue Sep 15 13:36:19 2020 (r365749) +++ head/sys/arm64/arm64/locore.S Tue Sep 15 14:15:04 2020 (r365750) @@ -614,10 +614,7 @@ build_l1_block_pagetable: /* Build the L1 block entry */ orr x12, x7, #L1_BLOCK - orr x12, x12, #(ATTR_AF) -#ifdef SMP - orr x12, x12, ATTR_SH(ATTR_SH_IS) -#endif + orr x12, x12, #(ATTR_DEFAULT) /* Only use the output address bits */ lsr x9, x9, #L1_SHIFT @@ -655,11 +652,8 @@ build_l2_block_pagetable: /* Build the L2 block entry */ lsl x12, x7, #2 orr x12, x12, #L2_BLOCK - orr x12, x12, #(ATTR_AF) + orr x12, x12, #(ATTR_DEFAULT) orr x12, x12, #(ATTR_S1_UXN) -#ifdef SMP - orr x12, x12, ATTR_SH(ATTR_SH_IS) -#endif /* Only use the output address bits */ lsr x9, x9, #L2_SHIFT ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
Re: svn commit: r364944 - head/sys/kern
On Sat, Aug 29, 2020 at 04:29:53AM +, Warner Losh wrote: > Author: imp > Date: Sat Aug 29 04:29:53 2020 > New Revision: 364944 > URL: https://svnweb.freebsd.org/changeset/base/364944 > > Log: > devctl: move to using a uma zone > > Convert the memory management of devctl. Rewrite if to make better > use of memory. This eliminates several mallocs (5? worse case) needed > to send a message. It's now possible to always send a message, though > if things are really backed up the oldest message will be dropped to > free up space for the newest. > > Add a static bus_child_{location,pnpinfo}_sb to start migrating to > sbuf instead of buffer + length. Use it in the new code. Other code > will be converted later (bus_child_*_str is only used inside of > subr_bus.c, though implemented in ~100 places in the tree). > > Reviewed by: markj@ > Differential Revision: https://reviews.freebsd.org/D26140 > > Modified: > head/sys/kern/subr_bus.c > > + } else { > + /* dei can't be NULL -- we know we have at least one in the > zone */ > + dei = uma_zalloc(devsoftc.zone, M_NOWAIT); > + MPASS(dei != NULL); This does not work. I believe you need to disable per-cpu cache for the zone, at least. But I am not sure it is enough. https://people.freebsd.org/~pho/stress/log/kostik1314.txt ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
Re: svn commit: r364944 - head/sys/kern
On Tue, Sep 15, 2020 at 05:15:30PM +0300, Konstantin Belousov wrote: > On Sat, Aug 29, 2020 at 04:29:53AM +, Warner Losh wrote: > > Author: imp > > Date: Sat Aug 29 04:29:53 2020 > > New Revision: 364944 > > URL: https://svnweb.freebsd.org/changeset/base/364944 > > > > Log: > > devctl: move to using a uma zone > > > > Convert the memory management of devctl. Rewrite if to make better > > use of memory. This eliminates several mallocs (5? worse case) needed > > to send a message. It's now possible to always send a message, though > > if things are really backed up the oldest message will be dropped to > > free up space for the newest. > > > > Add a static bus_child_{location,pnpinfo}_sb to start migrating to > > sbuf instead of buffer + length. Use it in the new code. Other code > > will be converted later (bus_child_*_str is only used inside of > > subr_bus.c, though implemented in ~100 places in the tree). > > > > Reviewed by: markj@ > > Differential Revision: https://reviews.freebsd.org/D26140 > > > > Modified: > > head/sys/kern/subr_bus.c > > > > > + } else { > > + /* dei can't be NULL -- we know we have at least one in the > > zone */ > > + dei = uma_zalloc(devsoftc.zone, M_NOWAIT); > > + MPASS(dei != NULL); > This does not work. I believe you need to disable per-cpu cache for the > zone, at least. But I am not sure it is enough. >From the report we have: db:0:pho> show uma Zone SizeUsedFreeRequests Sleeps Bucket Total MemXFree DEVCTL 1024 6415164 0 6416203 0 16 65691279360 so it looks like the primary problem is a leak. > https://people.freebsd.org/~pho/stress/log/kostik1314.txt ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
Re: svn commit: r364944 - head/sys/kern
On Tue, Sep 15, 2020 at 10:22:09AM -0400, Mark Johnston wrote: > On Tue, Sep 15, 2020 at 05:15:30PM +0300, Konstantin Belousov wrote: > > On Sat, Aug 29, 2020 at 04:29:53AM +, Warner Losh wrote: > > > Author: imp > > > Date: Sat Aug 29 04:29:53 2020 > > > New Revision: 364944 > > > URL: https://svnweb.freebsd.org/changeset/base/364944 > > > > > > Log: > > > devctl: move to using a uma zone > > > > > > Convert the memory management of devctl. Rewrite if to make better > > > use of memory. This eliminates several mallocs (5? worse case) needed > > > to send a message. It's now possible to always send a message, though > > > if things are really backed up the oldest message will be dropped to > > > free up space for the newest. > > > > > > Add a static bus_child_{location,pnpinfo}_sb to start migrating to > > > sbuf instead of buffer + length. Use it in the new code. Other code > > > will be converted later (bus_child_*_str is only used inside of > > > subr_bus.c, though implemented in ~100 places in the tree). > > > > > > Reviewed by: markj@ > > > Differential Revision: https://reviews.freebsd.org/D26140 > > > > > > Modified: > > > head/sys/kern/subr_bus.c > > > > > > > > + } else { > > > + /* dei can't be NULL -- we know we have at least one in the > > > zone */ > > > + dei = uma_zalloc(devsoftc.zone, M_NOWAIT); > > > + MPASS(dei != NULL); > > This does not work. I believe you need to disable per-cpu cache for the > > zone, at least. But I am not sure it is enough. > > From the report we have: > > db:0:pho> show uma > Zone SizeUsedFreeRequests Sleeps Bucket Total > MemXFree > DEVCTL 1024 6415164 0 6416203 0 16 > 65691279360 > > so it looks like the primary problem is a leak. > > > https://people.freebsd.org/~pho/stress/log/kostik1314.txt devctl_queue() does not maintain the queue length bound, so if devd goes away (due to an OOM kill in this case), we can end up with a large backlog. This hack might be sufficient. diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c index 19c056ab9974..91c57cdfae5b 100644 --- a/sys/kern/subr_bus.c +++ b/sys/kern/subr_bus.c @@ -635,7 +635,14 @@ devctl_queue(struct dev_event_info *dei) { mtx_lock(&devsoftc.mtx); STAILQ_INSERT_TAIL(&devsoftc.devq, dei, dei_link); - devsoftc.queued++; + if (devctl_queue_length != 0 && + devctl_queue_length == devsoftc.queued) { + dei = STAILQ_FIRST(&devsoftc.devq); + STAILQ_REMOVE_HEAD(&devsoftc.devq, dei_link); + uma_zfree(devsoftc.zone, dei); + } else { + devsoftc.queued++; + } cv_broadcast(&devsoftc.cv); KNOTE_LOCKED(&devsoftc.sel.si_note, 0); mtx_unlock(&devsoftc.mtx); ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
Re: svn commit: r364944 - head/sys/kern
On Tue, Sep 15, 2020, 8:22 AM Mark Johnston wrote: > On Tue, Sep 15, 2020 at 05:15:30PM +0300, Konstantin Belousov wrote: > > On Sat, Aug 29, 2020 at 04:29:53AM +, Warner Losh wrote: > > > Author: imp > > > Date: Sat Aug 29 04:29:53 2020 > > > New Revision: 364944 > > > URL: https://svnweb.freebsd.org/changeset/base/364944 > > > > > > Log: > > > devctl: move to using a uma zone > > > > > > Convert the memory management of devctl. Rewrite if to make better > > > use of memory. This eliminates several mallocs (5? worse case) needed > > > to send a message. It's now possible to always send a message, though > > > if things are really backed up the oldest message will be dropped to > > > free up space for the newest. > > > > > > Add a static bus_child_{location,pnpinfo}_sb to start migrating to > > > sbuf instead of buffer + length. Use it in the new code. Other code > > > will be converted later (bus_child_*_str is only used inside of > > > subr_bus.c, though implemented in ~100 places in the tree). > > > > > > Reviewed by: markj@ > > > Differential Revision: https://reviews.freebsd.org/D26140 > > > > > > Modified: > > > head/sys/kern/subr_bus.c > > > > > > > > + } else { > > > + /* dei can't be NULL -- we know we have at least one in > the zone */ > > > + dei = uma_zalloc(devsoftc.zone, M_NOWAIT); > > > + MPASS(dei != NULL); > > This does not work. I believe you need to disable per-cpu cache for the > > zone, at least. But I am not sure it is enough. > > From the report we have: > > db:0:pho> show uma > Zone SizeUsedFreeRequests Sleeps Bucket > Total MemXFree > DEVCTL 1024 6415164 0 6416203 0 16 > 65691279360 > > so it looks like the primary problem is a leak. > > > https://people.freebsd.org/~pho/stress/log/kostik1314.txt I'll look into it. Warner > > ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
Re: svn commit: r364944 - head/sys/kern
On Tue, Sep 15, 2020 at 8:37 AM Mark Johnston wrote: > On Tue, Sep 15, 2020 at 10:22:09AM -0400, Mark Johnston wrote: > > On Tue, Sep 15, 2020 at 05:15:30PM +0300, Konstantin Belousov wrote: > > > On Sat, Aug 29, 2020 at 04:29:53AM +, Warner Losh wrote: > > > > Author: imp > > > > Date: Sat Aug 29 04:29:53 2020 > > > > New Revision: 364944 > > > > URL: https://svnweb.freebsd.org/changeset/base/364944 > > > > > > > > Log: > > > > devctl: move to using a uma zone > > > > > > > > Convert the memory management of devctl. Rewrite if to make better > > > > use of memory. This eliminates several mallocs (5? worse case) > needed > > > > to send a message. It's now possible to always send a message, > though > > > > if things are really backed up the oldest message will be dropped > to > > > > free up space for the newest. > > > > > > > > Add a static bus_child_{location,pnpinfo}_sb to start migrating to > > > > sbuf instead of buffer + length. Use it in the new code. Other > code > > > > will be converted later (bus_child_*_str is only used inside of > > > > subr_bus.c, though implemented in ~100 places in the tree). > > > > > > > > Reviewed by: markj@ > > > > Differential Revision: https://reviews.freebsd.org/D26140 > > > > > > > > Modified: > > > > head/sys/kern/subr_bus.c > > > > > > > > > > > + } else { > > > > + /* dei can't be NULL -- we know we have at least one in > the zone */ > > > > + dei = uma_zalloc(devsoftc.zone, M_NOWAIT); > > > > + MPASS(dei != NULL); > > > This does not work. I believe you need to disable per-cpu cache for > the > > > zone, at least. But I am not sure it is enough. > > > > From the report we have: > > > > db:0:pho> show uma > > Zone SizeUsedFreeRequests Sleeps Bucket > Total MemXFree > > DEVCTL 1024 6415164 0 6416203 0 16 > 65691279360 > > > > so it looks like the primary problem is a leak. > > > > > https://people.freebsd.org/~pho/stress/log/kostik1314.txt > > devctl_queue() does not maintain the queue length bound, so if devd goes > away (due to an OOM kill in this case), we can end up with a large > backlog. This hack might be sufficient. > > diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c > index 19c056ab9974..91c57cdfae5b 100644 > --- a/sys/kern/subr_bus.c > +++ b/sys/kern/subr_bus.c > @@ -635,7 +635,14 @@ devctl_queue(struct dev_event_info *dei) > { > mtx_lock(&devsoftc.mtx); > STAILQ_INSERT_TAIL(&devsoftc.devq, dei, dei_link); > - devsoftc.queued++; > + if (devctl_queue_length != 0 && > + devctl_queue_length == devsoftc.queued) { > + dei = STAILQ_FIRST(&devsoftc.devq); > + STAILQ_REMOVE_HEAD(&devsoftc.devq, dei_link); > + uma_zfree(devsoftc.zone, dei); > + } else { > + devsoftc.queued++; > + } > cv_broadcast(&devsoftc.cv); > KNOTE_LOCKED(&devsoftc.sel.si_note, 0); > mtx_unlock(&devsoftc.mtx); > I've come to a similar conclusion... You can't queue w/o allocating... and that's where we're supposed to pop off the oldest, free it so we can allocate. So this isn't the right place for this fix, and the 'queued' name may be a bad name since it's from before. It's now supposed to be closer to 'allocated'. Warner ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r365751 - head/sys/opencrypto
Author: imp Date: Tue Sep 15 15:21:29 2020 New Revision: 365751 URL: https://svnweb.freebsd.org/changeset/base/365751 Log: Include sys/types.h here It's included by header pollution in most of the compile environments. However, in the standalone envirnment, it's not included. Go ahead and include it always since the overhead is low and it is simpler that way. MFC After: 3 days Modified: head/sys/opencrypto/xform_aes_xts.c Modified: head/sys/opencrypto/xform_aes_xts.c == --- head/sys/opencrypto/xform_aes_xts.c Tue Sep 15 14:15:04 2020 (r365750) +++ head/sys/opencrypto/xform_aes_xts.c Tue Sep 15 15:21:29 2020 (r365751) @@ -50,6 +50,7 @@ #include __FBSDID("$FreeBSD$"); +#include #include static int aes_xts_setkey(void *, const uint8_t *, int); ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r365753 - head/tools/build/options
Author: se Date: Tue Sep 15 16:22:05 2020 New Revision: 365753 URL: https://svnweb.freebsd.org/changeset/base/365753 Log: Add descriptions of the WITH_(OUT)_GH_BC options that exist in -CURRENT (default: WITH_GH_BC) and 12-STABLE (default: WITHOUT_GH_BC). Since the new implementation of bc and dc is optionally available in 12-STABLE, I intend to MFC these descriptions for inclusion in 12.2. MFC after:3 days Added: head/tools/build/options/WITHOUT_GH_BC (contents, props changed) head/tools/build/options/WITH_GH_BC (contents, props changed) Added: head/tools/build/options/WITHOUT_GH_BC == --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/build/options/WITHOUT_GH_BC Tue Sep 15 16:22:05 2020 (r365753) @@ -0,0 +1,6 @@ +.\" $FreeBSD$ +Do not install the enhanced +.Xr bc +and +.Xr dc +programs instead of the traditional FreeBSD versions. Added: head/tools/build/options/WITH_GH_BC == --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/build/options/WITH_GH_BC Tue Sep 15 16:22:05 2020 (r365753) @@ -0,0 +1,6 @@ +.\" $FreeBSD$ +Install the enhanced +.Xr bc +and +.Xr dc +programs instead of the traditional FreeBSD versions. ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r365754 - head/share/man/man5
Author: se Date: Tue Sep 15 16:38:44 2020 New Revision: 365754 URL: https://svnweb.freebsd.org/changeset/base/365754 Log: src.conf.5: regen after r365753 Modified: head/share/man/man5/src.conf.5 Modified: head/share/man/man5/src.conf.5 == --- head/share/man/man5/src.conf.5 Tue Sep 15 16:22:05 2020 (r365753) +++ head/share/man/man5/src.conf.5 Tue Sep 15 16:38:44 2020 (r365754) @@ -1,6 +1,6 @@ .\" DO NOT EDIT-- this file is @generated by tools/build/options/makeman. .\" $FreeBSD$ -.Dd September 14, 2020 +.Dd September 15, 2020 .Dt SRC.CONF 5 .Os .Sh NAME @@ -668,6 +668,12 @@ Set to build .Pp This is a default setting on amd64/amd64, arm/armv6, arm/armv7, i386/i386, mips/mips, mips/mips64, powerpc/powerpc and powerpc/powerpc64. +.It Va WITHOUT_GH_BC +Do not install the enhanced +.Xr bc +and +.Xr dc +programs instead of the traditional FreeBSD versions. .It Va WITHOUT_GNU_DIFF Set to not build GNU .Xr diff3 1 . ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r365755 - in head/sys: amd64/amd64 amd64/linux amd64/linux32 arm/arm arm64/arm64 arm64/linux i386/i386 i386/linux powerpc/powerpc
Author: trasz Date: Tue Sep 15 16:41:21 2020 New Revision: 365755 URL: https://svnweb.freebsd.org/changeset/base/365755 Log: Move SV_ABI_ERRNO translation into linux-specific code, to simplify the syscall path and declutter it a bit. No functional changes intended. Reviewed by: kib (earlier version) MFC after:2 weeks Sponsored by: DARPA Differential Revision:https://reviews.freebsd.org/D26378 Modified: head/sys/amd64/amd64/vm_machdep.c head/sys/amd64/linux/linux_sysvec.c head/sys/amd64/linux32/linux32_sysvec.c head/sys/arm/arm/vm_machdep.c head/sys/arm64/arm64/vm_machdep.c head/sys/arm64/linux/linux_sysvec.c head/sys/i386/i386/vm_machdep.c head/sys/i386/linux/linux_sysvec.c head/sys/powerpc/powerpc/exec_machdep.c Modified: head/sys/amd64/amd64/vm_machdep.c == --- head/sys/amd64/amd64/vm_machdep.c Tue Sep 15 16:38:44 2020 (r365754) +++ head/sys/amd64/amd64/vm_machdep.c Tue Sep 15 16:41:21 2020 (r365755) @@ -543,7 +543,7 @@ cpu_set_syscall_retval(struct thread *td, int error) break; default: - frame->tf_rax = SV_ABI_ERRNO(td->td_proc, error); + frame->tf_rax = error; frame->tf_rflags |= PSL_C; break; } Modified: head/sys/amd64/linux/linux_sysvec.c == --- head/sys/amd64/linux/linux_sysvec.c Tue Sep 15 16:38:44 2020 (r365754) +++ head/sys/amd64/linux/linux_sysvec.c Tue Sep 15 16:41:21 2020 (r365755) @@ -219,6 +219,11 @@ linux_set_syscall_retval(struct thread *td, int error) cpu_set_syscall_retval(td, error); + if (__predict_false(error != 0)) { + if (error != ERESTART && error != EJUSTRETURN) + frame->tf_rax = SV_ABI_ERRNO(td->td_proc, error); + } + /* Restore all registers. */ set_pcb_flags(td->td_pcb, PCB_FULL_IRET); } Modified: head/sys/amd64/linux32/linux32_sysvec.c == --- head/sys/amd64/linux32/linux32_sysvec.c Tue Sep 15 16:38:44 2020 (r365754) +++ head/sys/amd64/linux32/linux32_sysvec.c Tue Sep 15 16:41:21 2020 (r365755) @@ -112,6 +112,7 @@ static void linux32_fixlimit(struct rlimit *rl, int wh static boollinux32_trans_osrel(const Elf_Note *note, int32_t *osrel); static voidlinux_vdso_install(void *param); static voidlinux_vdso_deinstall(void *param); +static voidlinux32_set_syscall_retval(struct thread *td, int error); #define LINUX_T_UNKNOWN 255 static int _bsd_to_linux_trapcode[] = { @@ -669,6 +670,19 @@ linux32_fetch_syscall_args(struct thread *td) return (0); } +static void +linux32_set_syscall_retval(struct thread *td, int error) +{ + struct trapframe *frame = td->td_frame; + + cpu_set_syscall_retval(td, error); + + if (__predict_false(error != 0)) { + if (error != ERESTART && error != EJUSTRETURN) + frame->tf_rax = SV_ABI_ERRNO(td->td_proc, error); + } +} + /* * Clear registers on exec * XXX copied from ia32_signal.c. @@ -906,7 +920,7 @@ struct sysentvec elf_linux_sysvec = { .sv_fixlimit= linux32_fixlimit, .sv_maxssiz = &linux32_maxssiz, .sv_flags = SV_ABI_LINUX | SV_ILP32 | SV_IA32 | SV_SHP, - .sv_set_syscall_retval = cpu_set_syscall_retval, + .sv_set_syscall_retval = linux32_set_syscall_retval, .sv_fetch_syscall_args = linux32_fetch_syscall_args, .sv_syscallnames = NULL, .sv_shared_page_base = LINUX32_SHAREDPAGE, Modified: head/sys/arm/arm/vm_machdep.c == --- head/sys/arm/arm/vm_machdep.c Tue Sep 15 16:38:44 2020 (r365754) +++ head/sys/arm/arm/vm_machdep.c Tue Sep 15 16:41:21 2020 (r365755) @@ -219,7 +219,7 @@ cpu_set_syscall_retval(struct thread *td, int error) /* nothing to do */ break; default: - frame->tf_r0 = SV_ABI_ERRNO(td->td_proc, error); + frame->tf_r0 = error; frame->tf_spsr |= PSR_C;/* carry bit */ break; } Modified: head/sys/arm64/arm64/vm_machdep.c == --- head/sys/arm64/arm64/vm_machdep.c Tue Sep 15 16:38:44 2020 (r365754) +++ head/sys/arm64/arm64/vm_machdep.c Tue Sep 15 16:41:21 2020 (r365755) @@ -153,7 +153,7 @@ cpu_set_syscall_retval(struct thread *td, int error) break; default: frame->tf_spsr |= PSR_C;/* carry bit */ - frame->tf_x[0] = SV_ABI_ERRNO(td->td_proc, error); + frame->tf_x[0] = error; break;
svn commit: r365756 - head/usr.sbin/certctl
Author: kevans Date: Tue Sep 15 17:13:29 2020 New Revision: 365756 URL: https://svnweb.freebsd.org/changeset/base/365756 Log: certctl: fix unprivileged mode The first issue was lack of quoting around INSTALLFLAGS, which set it incorrectly and produced an error on -M. The second issue was that we weren't actually doing the install in unprivileged mode, making it effectively useless. This was designed to pass through the proper metalog/unpriv flags to install(1), so just let it happen. MFC after:3 days Modified: head/usr.sbin/certctl/certctl.sh Modified: head/usr.sbin/certctl/certctl.sh == --- head/usr.sbin/certctl/certctl.shTue Sep 15 16:41:21 2020 (r365755) +++ head/usr.sbin/certctl/certctl.shTue Sep 15 17:13:29 2020 (r365756) @@ -129,7 +129,7 @@ do_scan() [ -d "$CPATH" ] || continue echo "Scanning $CPATH for certificates..." for CFILE in $(ls -1 "${CPATH}" | grep -Ee "${FILEPAT}"); do - [ -e "$CPATH/$CFILE" -a $UNPRIV -eq 0 ] || continue + [ -e "$CPATH/$CFILE" ] || continue [ $VERBOSE -gt 0 ] && echo "Reading $CFILE" "$CFUNC" "$CPATH/$CFILE" done @@ -263,7 +263,7 @@ shift $(( $OPTIND - 1 )) : ${METALOG:=${DESTDIR}/METALOG} INSTALLFLAGS= -[ $UNPRIV -eq 1 ] && INSTALLFLAGS=-U -M ${METALOG} -D ${DESTDIR} +[ $UNPRIV -eq 1 ] && INSTALLFLAGS="-U -M ${METALOG} -D ${DESTDIR}" : ${TRUSTPATH:=${DESTDIR}/usr/share/certs/trusted:${DESTDIR}/usr/local/share/certs:${DESTDIR}/usr/local/etc/ssl/certs} : ${BLACKLISTPATH:=${DESTDIR}/usr/share/certs/blacklisted:${DESTDIR}/usr/local/etc/ssl/blacklisted} : ${CERTDESTDIR:=${DESTDIR}/etc/ssl/certs} ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r365759 - in head/sys: kern sys
Author: markj Date: Tue Sep 15 19:21:33 2020 New Revision: 365759 URL: https://svnweb.freebsd.org/changeset/base/365759 Log: Update unix domain socket locking comments. - Define a locking key for unpcb members. - Rewrite some of the locking protocol description to make it less verbose and avoid referencing some subroutines which will be renamed. - Reorder includes. Reviewed by: glebius, kevans, kib Tested by:pho Sponsored by: The FreeBSD Foundation Differential Revision:https://reviews.freebsd.org/D26294 Modified: head/sys/kern/uipc_usrreq.c head/sys/sys/unpcb.h Modified: head/sys/kern/uipc_usrreq.c == --- head/sys/kern/uipc_usrreq.c Tue Sep 15 18:56:14 2020(r365758) +++ head/sys/kern/uipc_usrreq.c Tue Sep 15 19:21:33 2020(r365759) @@ -65,13 +65,13 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include -#include /* XXX must be before */ #include +#include #include #include #include #include +#include #include #include #include @@ -106,9 +106,7 @@ __FBSDID("$FreeBSD$"); MALLOC_DECLARE(M_FILECAPS); /* - * Locking key: - * (l) Locked using list lock - * (g) Locked using linkage lock + * See unpcb.h for the locking key. */ static uma_zone_t unp_zone; @@ -196,40 +194,31 @@ SYSCTL_INT(_net_local, OID_AUTO, deferred, CTLFLAG_RD, /* * Locking and synchronization: * - * Three types of locks exist in the local domain socket implementation: a - * a global linkage rwlock, the mtxpool lock, and per-unpcb mutexes. - * The linkage lock protects the socket count, global generation number, - * and stream/datagram global lists. + * Several types of locks exist in the local domain socket implementation: + * - a global linkage lock + * - a global connection list lock + * - the mtxpool lock + * - per-unpcb mutexes * - * The mtxpool lock protects the vnode from being modified while referenced. - * Lock ordering requires that it be acquired before any unpcb locks. + * The linkage lock protects the global socket lists, the generation number + * counter and garbage collector state. * - * The unpcb lock (unp_mtx) protects all fields in the unpcb. Of particular - * note is that this includes the unp_conn field. So long as the unpcb lock - * is held the reference to the unpcb pointed to by unp_conn is valid. If we - * require that the unpcb pointed to by unp_conn remain live in cases where - * we need to drop the unp_mtx as when we need to acquire the lock for a - * second unpcb the caller must first acquire an additional reference on the - * second unpcb and then revalidate any state (typically check that unp_conn - * is non-NULL) upon requiring the initial unpcb lock. The lock ordering - * between unpcbs is the conventional ascending address order. Two helper - * routines exist for this: + * The connection list lock protects the list of referring sockets in a datagram + * socket PCB. This lock is also overloaded to protect a global list of + * sockets whose buffers contain socket references in the form of SCM_RIGHTS + * messages. To avoid recursion, such references are released by a dedicated + * thread. * - * - unp_pcb_lock2(unp, unp2) - which just acquires the two locks in the - * safe ordering. + * The mtxpool lock protects the vnode from being modified while referenced. + * Lock ordering rules require that it be acquired before any PCB locks. * - * - unp_pcb_owned_lock2(unp, unp2, freed) - the lock for unp is held - * when called. If unp is unlocked and unp2 is subsequently freed - * freed will be set to 1. - * - * The helper routines for references are: - * - * - unp_pcb_hold(unp): Can be called any time we currently hold a valid - * reference to unp. - * - *- unp_pcb_rele(unp): The caller must hold the unp lock. If we are - * releasing the last reference, detach must have been called thus - * unp->unp_socket be NULL. + * The unpcb lock (unp_mtx) protects the most commonly referenced fields in the + * unpcb. This includes the unp_conn field, which either links two connected + * PCBs together (for connected socket types) or points at the destination + * socket (for connectionless socket types). The operations of creating or + * destroying a connection therefore involve locking multiple PCBs. To avoid + * lock order reversals, in some cases this involves dropping a PCB lock and + * using a reference counter to maintain liveness. * * UNIX domain sockets each have an unpcb hung off of their so_pcb pointer, * allocated in pru_attach() and freed in pru_detach(). The validity of that Modified: head/sys/sys/unpcb.h == --- head/sys/sys/unpcb.hTue Sep 15 18:56:14 2020(r365758) +++ head/sys/sys/unpcb.hTue Sep 15 19:21:33 2020(r365759) @@ -65,30 +65,37 @@ typedef uint64_t
svn commit: r365760 - head/sys/kern
Author: markj Date: Tue Sep 15 19:21:58 2020 New Revision: 365760 URL: https://svnweb.freebsd.org/changeset/base/365760 Log: Improve unix socket PCB refcounting. - Use refcount_init(). - Define an INVARIANTS-only zone destructor to assert that various bits of PCB state aren't left dangling. - Annotate unp_pcb_rele() with __result_use_check. - Simplify control flow. Reviewed by: glebius, kevans, kib Tested by:pho Sponsored by: The FreeBSD Foundation Differential Revision:https://reviews.freebsd.org/D26295 Modified: head/sys/kern/uipc_usrreq.c Modified: head/sys/kern/uipc_usrreq.c == --- head/sys/kern/uipc_usrreq.c Tue Sep 15 19:21:33 2020(r365759) +++ head/sys/kern/uipc_usrreq.c Tue Sep 15 19:21:58 2020(r365760) @@ -313,25 +313,25 @@ static void unp_process_defers(void * __unused, int); static void unp_pcb_hold(struct unpcb *unp) { - MPASS(unp->unp_refcount); - refcount_acquire(&unp->unp_refcount); + u_int old __unused; + + old = refcount_acquire(&unp->unp_refcount); + KASSERT(old > 0, ("%s: unpcb %p has no references", __func__, unp)); } -static int +static __result_use_check bool unp_pcb_rele(struct unpcb *unp) { - int freed; + bool ret; UNP_PCB_LOCK_ASSERT(unp); - MPASS(unp->unp_refcount); - if ((freed = refcount_release(&unp->unp_refcount))) { - /* we got here with having detached? */ - MPASS(unp->unp_socket == NULL); + + if ((ret = refcount_release(&unp->unp_refcount))) { UNP_PCB_UNLOCK(unp); UNP_PCB_LOCK_DESTROY(unp); uma_zfree(unp_zone, unp); } - return (freed); + return (ret); } static void @@ -514,7 +514,7 @@ uipc_attach(struct socket *so, int proto, struct threa UNP_PCB_LOCK_INIT(unp); unp->unp_socket = so; so->so_pcb = unp; - unp->unp_refcount = 1; + refcount_init(&unp->unp_refcount, 1); if ((locked = UNP_LINK_WOWNED()) == false) UNP_LINK_WLOCK(); @@ -1814,7 +1814,7 @@ unp_pcblist(SYSCTL_HANDLER_ARGS) struct unp_head *head; struct xunpcb *xu; u_int i; - int error, freeunp, n; + int error, n; switch ((intptr_t)arg1) { case SOCK_STREAM: @@ -1891,9 +1891,10 @@ unp_pcblist(SYSCTL_HANDLER_ARGS) for (i = 0; i < n; i++) { unp = unp_list[i]; UNP_PCB_LOCK(unp); - freeunp = unp_pcb_rele(unp); + if (unp_pcb_rele(unp)) + continue; - if (freeunp == 0 && unp->unp_gencnt <= gencnt) { + if (unp->unp_gencnt <= gencnt) { xu->xu_len = sizeof *xu; xu->xu_unpp = (uintptr_t)unp; /* @@ -1920,8 +1921,9 @@ unp_pcblist(SYSCTL_HANDLER_ARGS) sotoxsocket(unp->unp_socket, &xu->xu_socket); UNP_PCB_UNLOCK(unp); error = SYSCTL_OUT(req, xu, sizeof *xu); - } else if (freeunp == 0) + } else { UNP_PCB_UNLOCK(unp); + } } free(xu, M_TEMP); if (!error) { @@ -2137,18 +2139,44 @@ unp_zone_change(void *tag) uma_zone_set_max(unp_zone, maxsockets); } +#ifdef INVARIANTS static void +unp_zdtor(void *mem, int size __unused, void *arg __unused) +{ + struct unpcb *unp; + + unp = mem; + + KASSERT(LIST_EMPTY(&unp->unp_refs), + ("%s: unpcb %p has lingering refs", __func__, unp)); + KASSERT(unp->unp_socket == NULL, + ("%s: unpcb %p has socket backpointer", __func__, unp)); + KASSERT(unp->unp_vnode == NULL, + ("%s: unpcb %p has vnode references", __func__, unp)); + KASSERT(unp->unp_conn == NULL, + ("%s: unpcb %p is still connected", __func__, unp)); + KASSERT(unp->unp_addr == NULL, + ("%s: unpcb %p has leaked addr", __func__, unp)); +} +#endif + +static void unp_init(void) { + uma_dtor dtor; #ifdef VIMAGE if (!IS_DEFAULT_VNET(curvnet)) return; #endif - unp_zone = uma_zcreate("unpcb", sizeof(struct unpcb), NULL, NULL, + +#ifdef INVARIANTS + dtor = unp_zdtor; +#else + dtor = NULL; +#endif + unp_zone = uma_zcreate("unpcb", sizeof(struct unpcb), NULL, dtor, NULL, NULL, UMA_ALIGN_CACHE, 0); - if (unp_zone == NULL) - panic("unp_init"); uma_zone_set_max(unp_zone, maxsockets); uma_zone_set_warning(unp_zone, "kern.ipc.maxsockets limit reached"); EVENTHANDLER_REGISTER(maxsockets_change, unp_zone_change, ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send an
svn commit: r365761 - head/sys/kern
Author: markj Date: Tue Sep 15 19:22:16 2020 New Revision: 365761 URL: https://svnweb.freebsd.org/changeset/base/365761 Log: Rename unp_pcb_lock2(). unp_pcb_lock_pair() seems like a better name. Also make it handle the case where the two sockets are the same instead of making callers do it. No functional change intended. Reviewed by: glebius, kevans, kib Tested by:pho Sponsored by: The FreeBSD Foundation Differential Revision:https://reviews.freebsd.org/D26296 Modified: head/sys/kern/uipc_usrreq.c Modified: head/sys/kern/uipc_usrreq.c == --- head/sys/kern/uipc_usrreq.c Tue Sep 15 19:21:58 2020(r365760) +++ head/sys/kern/uipc_usrreq.c Tue Sep 15 19:22:16 2020(r365761) @@ -335,13 +335,15 @@ unp_pcb_rele(struct unpcb *unp) } static void -unp_pcb_lock2(struct unpcb *unp, struct unpcb *unp2) +unp_pcb_lock_pair(struct unpcb *unp, struct unpcb *unp2) { - MPASS(unp != unp2); UNP_PCB_UNLOCK_ASSERT(unp); UNP_PCB_UNLOCK_ASSERT(unp2); - if ((uintptr_t)unp2 > (uintptr_t)unp) { + + if (unp == unp2) { UNP_PCB_LOCK(unp); + } else if ((uintptr_t)unp2 > (uintptr_t)unp) { + UNP_PCB_LOCK(unp); UNP_PCB_LOCK(unp2); } else { UNP_PCB_LOCK(unp2); @@ -349,6 +351,14 @@ unp_pcb_lock2(struct unpcb *unp, struct unpcb *unp2) } } +static void +unp_pcb_unlock_pair(struct unpcb *unp, struct unpcb *unp2) +{ + UNP_PCB_UNLOCK(unp); + if (unp != unp2) + UNP_PCB_UNLOCK(unp2); +} + static __noinline void unp_pcb_owned_lock2_slowpath(struct unpcb *unp, struct unpcb **unp2p, int *freed) @@ -738,14 +748,9 @@ uipc_connect2(struct socket *so1, struct socket *so2) KASSERT(unp != NULL, ("uipc_connect2: unp == NULL")); unp2 = so2->so_pcb; KASSERT(unp2 != NULL, ("uipc_connect2: unp2 == NULL")); - if (unp != unp2) - unp_pcb_lock2(unp, unp2); - else - UNP_PCB_LOCK(unp); + unp_pcb_lock_pair(unp, unp2); error = unp_connect2(so1, so2, PRU_CONNECT2); - if (unp != unp2) - UNP_PCB_UNLOCK(unp2); - UNP_PCB_UNLOCK(unp); + unp_pcb_unlock_pair(unp, unp2); return (error); } @@ -1640,7 +1645,7 @@ unp_connectat(int fd, struct socket *so, struct sockad goto bad2; } unp3 = sotounpcb(so2); - unp_pcb_lock2(unp2, unp3); + unp_pcb_lock_pair(unp2, unp3); if (unp2->unp_addr != NULL) { bcopy(unp2->unp_addr, sa, unp2->unp_addr->sun_len); unp3->unp_addr = (struct sockaddr_un *) sa; @@ -1662,18 +1667,13 @@ unp_connectat(int fd, struct socket *so, struct sockad mac_socketpeer_set_from_socket(so2, so); #endif } else { - if (unp == unp2) - UNP_PCB_LOCK(unp); - else - unp_pcb_lock2(unp, unp2); + unp_pcb_lock_pair(unp, unp2); } KASSERT(unp2 != NULL && so2 != NULL && unp2->unp_socket == so2 && sotounpcb(so2) == unp2, ("%s: unp2 %p so2 %p", __func__, unp2, so2)); error = unp_connect2(so, so2, PRU_CONNECT); - if (unp != unp2) - UNP_PCB_UNLOCK(unp2); - UNP_PCB_UNLOCK(unp); + unp_pcb_unlock_pair(unp, unp2); bad2: mtx_unlock(vplock); bad: ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r365763 - head/sys/kern
Author: markj Date: Tue Sep 15 19:23:01 2020 New Revision: 365763 URL: https://svnweb.freebsd.org/changeset/base/365763 Log: Avoid an unnecessary malloc() when connecting dgram sockets. The allocated memory is only required for SOCK_STREAM and SOCK_SEQPACKET sockets. Reviewed by: kevans Tested by:pho Sponsored by: The FreeBSD Foundation Differential Revision:https://reviews.freebsd.org/D26298 Modified: head/sys/kern/uipc_usrreq.c Modified: head/sys/kern/uipc_usrreq.c == --- head/sys/kern/uipc_usrreq.c Tue Sep 15 19:22:37 2020(r365762) +++ head/sys/kern/uipc_usrreq.c Tue Sep 15 19:23:01 2020(r365763) @@ -1557,7 +1557,8 @@ static int unp_connectat(int fd, struct socket *so, struct sockaddr *nam, struct thread *td) { - struct sockaddr_un *soun = (struct sockaddr_un *)nam; + struct mtx *vplock; + struct sockaddr_un *soun; struct vnode *vp; struct socket *so2; struct unpcb *unp, *unp2, *unp3; @@ -1566,7 +1567,7 @@ unp_connectat(int fd, struct socket *so, struct sockad struct sockaddr *sa; cap_rights_t rights; int error, len, freed; - struct mtx *vplock; + bool connreq; if (nam->sa_family != AF_UNIX) return (EAFNOSUPPORT); @@ -1575,6 +1576,7 @@ unp_connectat(int fd, struct socket *so, struct sockad len = nam->sa_len - offsetof(struct sockaddr_un, sun_path); if (len <= 0) return (EINVAL); + soun = (struct sockaddr_un *)nam; bcopy(soun->sun_path, buf, len); buf[len] = 0; @@ -1587,7 +1589,11 @@ unp_connectat(int fd, struct socket *so, struct sockad unp->unp_flags |= UNP_CONNECTING; UNP_PCB_UNLOCK(unp); - sa = malloc(sizeof(struct sockaddr_un), M_SONAME, M_WAITOK); + connreq = (so->so_proto->pr_flags & PR_CONNREQUIRED) != 0; + if (connreq) + sa = malloc(sizeof(struct sockaddr_un), M_SONAME, M_WAITOK); + else + sa = NULL; NDINIT_ATRIGHTS(&nd, LOOKUP, FOLLOW | LOCKSHARED | LOCKLEAF, UIO_SYSSPACE, buf, fd, cap_rights_init(&rights, CAP_CONNECTAT), td); error = namei(&nd); @@ -1628,7 +1634,7 @@ unp_connectat(int fd, struct socket *so, struct sockad error = EPROTOTYPE; goto bad2; } - if (so->so_proto->pr_flags & PR_CONNREQUIRED) { + if (connreq) { if (so2->so_options & SO_ACCEPTCONN) { CURVNET_SET(so2->so_vnet); so2 = sonewconn(so2, 0); ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r365762 - head/sys/kern
Author: markj Date: Tue Sep 15 19:22:37 2020 New Revision: 365762 URL: https://svnweb.freebsd.org/changeset/base/365762 Log: Simplify unp_disconnect() callers. In all cases, PCBs are unlocked after unp_disconnect() returns. Since unp_disconnect() may release the last PCB reference, callers may have to bump the refcount before the call just so that they can release them again. Change unp_disconnect() to release PCB locks as well as connection references; this lets us remove several refcount manipulations. Tighten assertions. Tested by:pho Sponsored by: The FreeBSD Foundation Differential Revision:https://reviews.freebsd.org/D26297 Modified: head/sys/kern/uipc_usrreq.c Modified: head/sys/kern/uipc_usrreq.c == --- head/sys/kern/uipc_usrreq.c Tue Sep 15 19:22:16 2020(r365761) +++ head/sys/kern/uipc_usrreq.c Tue Sep 15 19:22:37 2020(r365762) @@ -335,6 +335,15 @@ unp_pcb_rele(struct unpcb *unp) } static void +unp_pcb_rele_notlast(struct unpcb *unp) +{ + bool ret __unused; + + ret = refcount_release(&unp->unp_refcount); + KASSERT(!ret, ("%s: unpcb %p has no references", __func__, unp)); +} + +static void unp_pcb_lock_pair(struct unpcb *unp, struct unpcb *unp2) { UNP_PCB_UNLOCK_ASSERT(unp); @@ -720,18 +729,14 @@ uipc_close(struct socket *so) unp->unp_vnode = NULL; } unp2 = unp->unp_conn; - unp_pcb_hold(unp); if (__predict_false(unp == unp2)) { unp_disconnect(unp, unp2); } else if (unp2 != NULL) { - unp_pcb_hold(unp2); unp_pcb_owned_lock2(unp, unp2, freed); unp_disconnect(unp, unp2); - if (unp_pcb_rele(unp2) == 0) - UNP_PCB_UNLOCK(unp2); - } - if (unp_pcb_rele(unp) == 0) + } else { UNP_PCB_UNLOCK(unp); + } if (vp) { mtx_unlock(vplock); vrele(vp); @@ -816,14 +821,11 @@ uipc_detach(struct socket *so) unp2 = NULL; } unp_pcb_hold(unp); - if (unp2 != NULL) { - unp_pcb_hold(unp2); + if (unp2 != NULL) unp_disconnect(unp, unp2); - if (unp_pcb_rele(unp2) == 0) - UNP_PCB_UNLOCK(unp2); - } + else + UNP_PCB_UNLOCK(unp); } - UNP_PCB_UNLOCK(unp); UNP_REF_LIST_LOCK(); while (!LIST_EMPTY(&unp->unp_refs)) { struct unpcb *ref = LIST_FIRST(&unp->unp_refs); @@ -876,14 +878,8 @@ uipc_disconnect(struct socket *so) UNP_PCB_UNLOCK(unp); return (0); } - unp_pcb_hold(unp2); } - unp_pcb_hold(unp); unp_disconnect(unp, unp2); - if (unp_pcb_rele(unp) == 0) - UNP_PCB_UNLOCK(unp); - if ((unp != unp2) && unp_pcb_rele(unp2) == 0) - UNP_PCB_UNLOCK(unp2); return (0); } @@ -1122,9 +1118,8 @@ uipc_send(struct socket *so, int flags, struct mbuf *m } if (nam != NULL) unp_disconnect(unp, unp2); - if (__predict_true(unp != unp2)) - UNP_PCB_UNLOCK(unp2); - UNP_PCB_UNLOCK(unp); + else + unp_pcb_unlock_pair(unp, unp2); break; } @@ -1756,23 +1751,29 @@ static void unp_disconnect(struct unpcb *unp, struct unpcb *unp2) { struct socket *so, *so2; - int freed __unused; +#ifdef INVARIANTS + struct unpcb *unptmp; +#endif - KASSERT(unp2 != NULL, ("unp_disconnect: unp2 == NULL")); - UNP_PCB_LOCK_ASSERT(unp); UNP_PCB_LOCK_ASSERT(unp2); + KASSERT(unp->unp_conn == unp2, + ("%s: unpcb %p is not connected to %p", __func__, unp, unp2)); - if (unp->unp_conn == NULL && unp2->unp_conn == NULL) - return; - - MPASS(unp->unp_conn == unp2); unp->unp_conn = NULL; so = unp->unp_socket; so2 = unp2->unp_socket; switch (unp->unp_socket->so_type) { case SOCK_DGRAM: UNP_REF_LIST_LOCK(); +#ifdef INVARIANTS + LIST_FOREACH(unptmp, &unp2->unp_refs, unp_reflink) { + if (unptmp == unp) + break; + } + KASSERT(unptmp != NULL, + ("%s: %p not found in reflist of %p", __func__, unp, unp2)); +#endif LIST_REMOVE(unp, unp_reflink); UNP_REF_LIST_UNLOCK(); if (so) { @@ -1792,10 +1793,17 @@ unp_disconnect(struct unpcb *unp, struct unpcb *unp2) soisdisconnected(so2); break;
svn commit: r365764 - in head/sys: kern sys
Author: markj Date: Tue Sep 15 19:23:22 2020 New Revision: 365764 URL: https://svnweb.freebsd.org/changeset/base/365764 Log: Simplify unix socket connection peer locking. unp_pcb_owned_lock2() has some sharp edges and forces callers to deal with a bunch of cases. Simplify it: - Rename to unp_pcb_lock_peer(). - Return the connected peer instead of forcing callers to load it beforehand. - Handle self-connected sockets. - In unp_connectat(), just lock the accept socket directly. It should not be possible for the nascent socket to participate in any other lock orders. - Get rid of connect_internal(). It does not provide any useful checking anymore. - Block in unp_connectat() when a different thread is concurrently attempting to lock both sides of a connection. This provides simpler semantics for callers of unp_pcb_lock_peer(). - Make unp_connectat() return EISCONN if the socket is already connected. This fixes a race[1] when multiple threads attempt to connect() to different addresses using the same datagram socket. Upper layers will disconnect a connected datagram socket before calling the protocol connect's method, but there is no synchronization between this and protocol-layer code. Reported by: syzkaller [1] Tested by:pho Sponsored by: The FreeBSD Foundation Differential Revision:https://reviews.freebsd.org/D26299 Modified: head/sys/kern/uipc_usrreq.c head/sys/sys/unpcb.h Modified: head/sys/kern/uipc_usrreq.c == --- head/sys/kern/uipc_usrreq.c Tue Sep 15 19:23:01 2020(r365763) +++ head/sys/kern/uipc_usrreq.c Tue Sep 15 19:23:22 2020(r365764) @@ -279,6 +279,7 @@ static struct mtx unp_defers_lock; "unp", "unp", \ MTX_DUPOK|MTX_DEF) #defineUNP_PCB_LOCK_DESTROY(unp) mtx_destroy(&(unp)->unp_mtx) +#defineUNP_PCB_LOCKPTR(unp)(&(unp)->unp_mtx) #defineUNP_PCB_LOCK(unp) mtx_lock(&(unp)->unp_mtx) #defineUNP_PCB_TRYLOCK(unp)mtx_trylock(&(unp)->unp_mtx) #defineUNP_PCB_UNLOCK(unp) mtx_unlock(&(unp)->unp_mtx) @@ -368,35 +369,55 @@ unp_pcb_unlock_pair(struct unpcb *unp, struct unpcb *u UNP_PCB_UNLOCK(unp2); } -static __noinline void -unp_pcb_owned_lock2_slowpath(struct unpcb *unp, struct unpcb **unp2p, -int *freed) +/* + * Try to lock the connected peer of an already locked socket. In some cases + * this requires that we unlock the current socket. The pairbusy counter is + * used to block concurrent connection attempts while the lock is dropped. The + * caller must be careful to revalidate PCB state. + */ +static struct unpcb * +unp_pcb_lock_peer(struct unpcb *unp) { struct unpcb *unp2; - unp2 = *unp2p; + UNP_PCB_LOCK_ASSERT(unp); + unp2 = unp->unp_conn; + if (__predict_false(unp2 == NULL)) + return (NULL); + if (__predict_false(unp == unp2)) + return (unp); + + UNP_PCB_UNLOCK_ASSERT(unp2); + + if (__predict_true(UNP_PCB_TRYLOCK(unp2))) + return (unp2); + if ((uintptr_t)unp2 > (uintptr_t)unp) { + UNP_PCB_LOCK(unp2); + return (unp2); + } + unp->unp_pairbusy++; unp_pcb_hold(unp2); UNP_PCB_UNLOCK(unp); + UNP_PCB_LOCK(unp2); UNP_PCB_LOCK(unp); - *freed = unp_pcb_rele(unp2); - if (*freed) - *unp2p = NULL; + KASSERT(unp->unp_conn == unp2 || unp->unp_conn == NULL, + ("%s: socket %p was reconnected", __func__, unp)); + if (--unp->unp_pairbusy == 0 && (unp->unp_flags & UNP_WAITING) != 0) { + unp->unp_flags &= ~UNP_WAITING; + wakeup(unp); + } + if (unp_pcb_rele(unp2)) { + /* unp2 is unlocked. */ + return (NULL); + } + if (unp->unp_conn == NULL) { + UNP_PCB_UNLOCK(unp2); + return (NULL); + } + return (unp2); } -#define unp_pcb_owned_lock2(unp, unp2, freed) do { \ - freed = 0; \ - UNP_PCB_LOCK_ASSERT(unp); \ - UNP_PCB_UNLOCK_ASSERT(unp2);\ - MPASS((unp) != (unp2)); \ - if (__predict_true(UNP_PCB_TRYLOCK(unp2))) \ - break; \ - else if ((uintptr_t)(unp2) > (uintptr_t)(unp)) \ - UNP_PCB_LOCK(unp2); \ - else\ - unp_pcb_owned_lock2_slowpath((un
svn commit: r365765 - head/sys/kern
Author: markj Date: Tue Sep 15 19:23:42 2020 New Revision: 365765 URL: https://svnweb.freebsd.org/changeset/base/365765 Log: Fix locking in uipc_accept(). This function wasn't converted to use the new locking protocol in r333744. Make it use the PCB lock for synchronizing connection state. Tested by:pho Sponsored by: The FreeBSD Foundation Differential Revision:https://reviews.freebsd.org/D26300 Modified: head/sys/kern/uipc_usrreq.c Modified: head/sys/kern/uipc_usrreq.c == --- head/sys/kern/uipc_usrreq.c Tue Sep 15 19:23:22 2020(r365764) +++ head/sys/kern/uipc_usrreq.c Tue Sep 15 19:23:42 2020(r365765) @@ -499,18 +499,14 @@ uipc_accept(struct socket *so, struct sockaddr **nam) KASSERT(unp != NULL, ("uipc_accept: unp == NULL")); *nam = malloc(sizeof(struct sockaddr_un), M_SONAME, M_WAITOK); - UNP_LINK_RLOCK(); - unp2 = unp->unp_conn; - if (unp2 != NULL && unp2->unp_addr != NULL) { - UNP_PCB_LOCK(unp2); - sa = (struct sockaddr *) unp2->unp_addr; - bcopy(sa, *nam, sa->sa_len); - UNP_PCB_UNLOCK(unp2); - } else { + UNP_PCB_LOCK(unp); + unp2 = unp_pcb_lock_peer(unp); + if (unp2 != NULL && unp2->unp_addr != NULL) + sa = (struct sockaddr *)unp2->unp_addr; + else sa = &sun_noname; - bcopy(sa, *nam, sa->sa_len); - } - UNP_LINK_RUNLOCK(); + bcopy(sa, *nam, sa->sa_len); + unp_pcb_unlock_pair(unp, unp2); return (0); } ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r365766 - head/sys/amd64/vmm/amd
Author: kib Date: Tue Sep 15 20:22:50 2020 New Revision: 365766 URL: https://svnweb.freebsd.org/changeset/base/365766 Log: bhyve: intercept AMD SVM instructions. Intercept and report #UD to VM on SVM/AMD in case VM tried to execute an SVM instruction. Otherwise, SVM allows execution of them, and instructions operate on host physical addresses despite being executed in guest mode. Reported by: Maxime Villard admbug: 972 CVE: CVE-2020-7467 Reviewed by: grehan, markj Differential revision:https://reviews.freebsd.org/D26313 Modified: head/sys/amd64/vmm/amd/svm.c head/sys/amd64/vmm/amd/vmcb.h Modified: head/sys/amd64/vmm/amd/svm.c == --- head/sys/amd64/vmm/amd/svm.cTue Sep 15 19:23:42 2020 (r365765) +++ head/sys/amd64/vmm/amd/svm.cTue Sep 15 20:22:50 2020 (r365766) @@ -488,11 +488,24 @@ vmcb_init(struct svm_softc *sc, int vcpu, uint64_t iop svm_enable_intercept(sc, vcpu, VMCB_CTRL1_INTCPT, VMCB_INTCPT_SHUTDOWN); svm_enable_intercept(sc, vcpu, VMCB_CTRL1_INTCPT, VMCB_INTCPT_FERR_FREEZE); + svm_enable_intercept(sc, vcpu, VMCB_CTRL1_INTCPT, VMCB_INTCPT_INVD); + svm_enable_intercept(sc, vcpu, VMCB_CTRL1_INTCPT, VMCB_INTCPT_INVLPGA); svm_enable_intercept(sc, vcpu, VMCB_CTRL2_INTCPT, VMCB_INTCPT_MONITOR); svm_enable_intercept(sc, vcpu, VMCB_CTRL2_INTCPT, VMCB_INTCPT_MWAIT); /* +* Intercept SVM instructions since AMD enables them in guests otherwise. +* Non-intercepted VMMCALL causes #UD, skip it. +*/ + svm_enable_intercept(sc, vcpu, VMCB_CTRL2_INTCPT, VMCB_INTCPT_VMLOAD); + svm_enable_intercept(sc, vcpu, VMCB_CTRL2_INTCPT, VMCB_INTCPT_VMSAVE); + svm_enable_intercept(sc, vcpu, VMCB_CTRL2_INTCPT, VMCB_INTCPT_STGI); + svm_enable_intercept(sc, vcpu, VMCB_CTRL2_INTCPT, VMCB_INTCPT_CLGI); + svm_enable_intercept(sc, vcpu, VMCB_CTRL2_INTCPT, VMCB_INTCPT_SKINIT); + svm_enable_intercept(sc, vcpu, VMCB_CTRL2_INTCPT, VMCB_INTCPT_ICEBP); + + /* * From section "Canonicalization and Consistency Checks" in APMv2 * the VMRUN intercept bit must be set to pass the consistency check. */ @@ -1236,43 +1249,45 @@ emulate_rdmsr(struct svm_softc *sc, int vcpu, u_int nu static const char * exit_reason_to_str(uint64_t reason) { + int i; static char reasonbuf[32]; + static const struct { + int reason; + const char *str; + } reasons[] = { + { .reason = VMCB_EXIT_INVALID, .str = "invalvmcb" }, + { .reason = VMCB_EXIT_SHUTDOWN, .str = "shutdown" }, + { .reason = VMCB_EXIT_NPF, .str = "nptfault" }, + { .reason = VMCB_EXIT_PAUSE,.str = "pause" }, + { .reason = VMCB_EXIT_HLT, .str = "hlt" }, + { .reason = VMCB_EXIT_CPUID,.str = "cpuid" }, + { .reason = VMCB_EXIT_IO, .str = "inout" }, + { .reason = VMCB_EXIT_MC, .str = "mchk" }, + { .reason = VMCB_EXIT_INTR, .str = "extintr" }, + { .reason = VMCB_EXIT_NMI, .str = "nmi" }, + { .reason = VMCB_EXIT_VINTR,.str = "vintr" }, + { .reason = VMCB_EXIT_MSR, .str = "msr" }, + { .reason = VMCB_EXIT_IRET, .str = "iret" }, + { .reason = VMCB_EXIT_MONITOR, .str = "monitor" }, + { .reason = VMCB_EXIT_MWAIT,.str = "mwait" }, + { .reason = VMCB_EXIT_VMRUN,.str = "vmrun" }, + { .reason = VMCB_EXIT_VMMCALL, .str = "vmmcall" }, + { .reason = VMCB_EXIT_VMLOAD, .str = "vmload" }, + { .reason = VMCB_EXIT_VMSAVE, .str = "vmsave" }, + { .reason = VMCB_EXIT_STGI, .str = "stgi" }, + { .reason = VMCB_EXIT_CLGI, .str = "clgi" }, + { .reason = VMCB_EXIT_SKINIT, .str = "skinit" }, + { .reason = VMCB_EXIT_ICEBP,.str = "icebp" }, + { .reason = VMCB_EXIT_INVD, .str = "invd" }, + { .reason = VMCB_EXIT_INVLPGA, .str = "invlpga" }, + }; - switch (reason) { - case VMCB_EXIT_INVALID: - return ("invalvmcb"); - case VMCB_EXIT_SHUTDOWN: - return ("shutdown"); - case VMCB_EXIT_NPF: - return ("nptfault"); - case VMCB_EXIT_PAUSE: - return ("pause"); - case VMCB_EXIT_HLT: - return ("hlt"); - case VMCB_EXIT_CPUID: - return ("cpuid"); - case VMCB_EXIT_IO: - return ("inout"); - case VMCB_EXIT_MC: - return ("mchk"); - case VMCB_EXIT_INTR: - return ("extintr"); - case VMCB_EXIT_NMI: - return ("nmi"); - case VMCB_EXIT_VINTR: -
svn commit: r365768 - head/sys/powerpc/aim
Author: bdragon Date: Tue Sep 15 20:25:38 2020 New Revision: 365768 URL: https://svnweb.freebsd.org/changeset/base/365768 Log: [PowerPC64LE] Set up the powernv partition table correctly. The partition table is always big endian. Sponsored by: Tag1 Consulting, Inc. Modified: head/sys/powerpc/aim/moea64_native.c Modified: head/sys/powerpc/aim/moea64_native.c == --- head/sys/powerpc/aim/moea64_native.cTue Sep 15 20:25:30 2020 (r365767) +++ head/sys/powerpc/aim/moea64_native.cTue Sep 15 20:25:38 2020 (r365768) @@ -556,9 +556,9 @@ moea64_bootstrap_native(vm_offset_t kernelstart, vm_of sizeof(struct lpteg)); if (cpu_features2 & PPC_FEATURE2_ARCH_3_00) { bzero(__DEVOLATILE(void *, moea64_part_table), PART_SIZE); - moea64_part_table[0].pagetab = + moea64_part_table[0].pagetab = htobe64( (DMAP_TO_PHYS((vm_offset_t)moea64_pteg_table)) | - (uintptr_t)(flsl((moea64_pteg_count - 1) >> 11)); + (uintptr_t)(flsl((moea64_pteg_count - 1) >> 11))); } ENABLE_TRANS(msr); ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r365770 - head/sys/powerpc/powerpc
Author: bdragon Date: Tue Sep 15 20:47:33 2020 New Revision: 365770 URL: https://svnweb.freebsd.org/changeset/base/365770 Log: [PowerPC64LE] Use correct in_masks table on LE to fix checksumming Due to a check that should have been an endian check being an #if 0, the wrong checksum mask table was being used on LE, which was causing extreme strangeness in DNS resolution -- *some* hosts would be resolvable, but most would not. This fixes DNS resolution. (I am committing some parts of the LE patchset ahead of time to reduce the amount of work I have to do while committing the main patchset.) Sponsored by: Tag1 Consulting, Inc. Modified: head/sys/powerpc/powerpc/in_cksum.c Modified: head/sys/powerpc/powerpc/in_cksum.c == --- head/sys/powerpc/powerpc/in_cksum.c Tue Sep 15 20:26:31 2020 (r365769) +++ head/sys/powerpc/powerpc/in_cksum.c Tue Sep 15 20:47:33 2020 (r365770) @@ -42,6 +42,7 @@ #include /* RCS ID & Copyright macro defns */ +#include #include #include #include @@ -73,7 +74,7 @@ } static const u_int32_t in_masks[] = { -#if 0 +#if _BYTE_ORDER == _LITTLE_ENDIAN /*0 bytes*/ /*1 byte*/ /*2 bytes*/ /*3 bytes*/ 0x, 0x00FF, 0x, 0x00FF, /* offset 0 */ 0x, 0xFF00, 0x0000, 0xFF00, /* offset 1 */ ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r365771 - head/libexec/ftpd
Author: markj Date: Tue Sep 15 20:54:18 2020 New Revision: 365771 URL: https://svnweb.freebsd.org/changeset/base/365771 Log: ftpd: Exit during authentication if an error occurs after chroot(). admbug: 969 Security: CVE-2020-7468 Modified: head/libexec/ftpd/ftpd.c Modified: head/libexec/ftpd/ftpd.c == --- head/libexec/ftpd/ftpd.cTue Sep 15 20:47:33 2020(r365770) +++ head/libexec/ftpd/ftpd.cTue Sep 15 20:54:18 2020(r365771) @@ -1595,13 +1595,20 @@ skip: *(uid 0 has no root power over NFS if not mapped explicitly.) */ if (seteuid(pw->pw_uid) < 0) { - reply(550, "Can't set uid."); - goto bad; + if (guest || dochroot) { + fatalerror("Can't set uid."); + } else { + reply(550, "Can't set uid."); + goto bad; + } } + /* +* Do not allow the session to live if we're chroot()'ed and chdir() +* fails. Otherwise the chroot jail can be escaped. +*/ if (chdir(homedir) < 0) { if (guest || dochroot) { - reply(550, "Can't change to base directory."); - goto bad; + fatalerror("Can't change to base directory."); } else { if (chdir("/") < 0) { reply(550, "Root is inaccessible."); ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r365774 - head/sys/dev/e1000
Author: erj Date: Tue Sep 15 21:00:25 2020 New Revision: 365774 URL: https://svnweb.freebsd.org/changeset/base/365774 Log: igb(4): Fix define and includes with RSS option enabled This re-adds the opt_rss.h header to the driver and includes some RSS-specific headers when RSS is defined. PR: 249191 Submitted by: Milosz Kaniewski MFC after:3 days Modified: head/sys/dev/e1000/if_em.h Modified: head/sys/dev/e1000/if_em.h == --- head/sys/dev/e1000/if_em.h Tue Sep 15 20:56:14 2020(r365773) +++ head/sys/dev/e1000/if_em.h Tue Sep 15 21:00:25 2020(r365774) @@ -30,6 +30,7 @@ #include "opt_ddb.h" #include "opt_inet.h" #include "opt_inet6.h" +#include "opt_rss.h" #ifdef HAVE_KERNEL_OPTION_HEADERS #include "opt_device_polling.h" @@ -69,6 +70,10 @@ #include #include #include +#ifdef RSS +#include +#include +#endif #include #include ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r365775 - in head/sys/amd64/vmm: amd intel
Author: emaste Date: Tue Sep 15 21:04:27 2020 New Revision: 365775 URL: https://svnweb.freebsd.org/changeset/base/365775 Log: bhyve: do not permit write access to VMCB / VMCS Reported by: Patrick Mooney Submitted by: jhb Security: CVE-2020-24718 Modified: head/sys/amd64/vmm/amd/svm.c head/sys/amd64/vmm/intel/vmx.c Modified: head/sys/amd64/vmm/amd/svm.c == --- head/sys/amd64/vmm/amd/svm.cTue Sep 15 21:00:25 2020 (r365774) +++ head/sys/amd64/vmm/amd/svm.cTue Sep 15 21:04:27 2020 (r365775) @@ -2227,8 +2227,11 @@ svm_setreg(void *arg, int vcpu, int ident, uint64_t va return (svm_modify_intr_shadow(svm_sc, vcpu, val)); } - if (vmcb_write(svm_sc, vcpu, ident, val) == 0) { - return (0); + /* Do not permit user write access to VMCB fields by offset. */ + if (!VMCB_ACCESS_OK(ident)) { + if (vmcb_write(svm_sc, vcpu, ident, val) == 0) { + return (0); + } } reg = swctx_regptr(svm_get_guest_regctx(svm_sc, vcpu), ident); Modified: head/sys/amd64/vmm/intel/vmx.c == --- head/sys/amd64/vmm/intel/vmx.c Tue Sep 15 21:00:25 2020 (r365774) +++ head/sys/amd64/vmm/intel/vmx.c Tue Sep 15 21:04:27 2020 (r365775) @@ -3341,6 +3341,10 @@ vmx_setreg(void *arg, int vcpu, int reg, uint64_t val) if (vmxctx_setreg(&vmx->ctx[vcpu], reg, val) == 0) return (0); + /* Do not permit user write access to VMCS fields by offset. */ + if (reg < 0) + return (EINVAL); + error = vmcs_setreg(&vmx->vmcs[vcpu], running, reg, val); if (error == 0) { ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r365776 - head/sys/dev/e1000
Author: erj Date: Tue Sep 15 21:07:30 2020 New Revision: 365776 URL: https://svnweb.freebsd.org/changeset/base/365776 Log: e1000: Properly retain promisc flag From Franco: The iflib rewrite forced the promisc flag but it was not reported to the system. Noticed on a stock VM that went into unsolicited promisc mode when dhclient was started during bootup. PR: 248869 Submitted by: Franco Fichtner Reviewed by: erj@ MFC after:3 days Modified: head/sys/dev/e1000/if_em.c Modified: head/sys/dev/e1000/if_em.c == --- head/sys/dev/e1000/if_em.c Tue Sep 15 21:04:27 2020(r365775) +++ head/sys/dev/e1000/if_em.c Tue Sep 15 21:07:30 2020(r365776) @@ -1342,7 +1342,7 @@ em_if_init(if_ctx_t ctx) } /* Don't lose promiscuous settings */ - em_if_set_promisc(ctx, IFF_PROMISC); + em_if_set_promisc(ctx, if_getflags(ifp)); e1000_clear_hw_cntrs_base_generic(&adapter->hw); /* MSI-X configuration for 82574 */ ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r365783 - in head/sys: contrib/openzfs/module/os/freebsd/zfs fs/nfs kern sys ufs/ffs
Author: kib Date: Tue Sep 15 21:55:21 2020 New Revision: 365783 URL: https://svnweb.freebsd.org/changeset/base/365783 Log: Do not copy vp into f_data for DTYPE_VNODE files. The pointer to vnode is already stored into f_vnode, so f_data can be reused. Fix all found users of f_data for DTYPE_VNODE. Provide finit_vnode() helper to initialize file of DTYPE_VNODE type. Reviewed by: markj (previous version) Discussed with: freqlabs (openzfs chunk) Tested by:pho (previous version) Sponsored by: The FreeBSD Foundation Differential revision:https://reviews.freebsd.org/D26346 Modified: head/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_file_os.c head/sys/fs/nfs/nfsdport.h head/sys/kern/kern_descrip.c head/sys/kern/vfs_syscalls.c head/sys/sys/file.h head/sys/ufs/ffs/ffs_alloc.c Modified: head/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_file_os.c == --- head/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_file_os.cTue Sep 15 21:48:24 2020(r365782) +++ head/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_file_os.cTue Sep 15 21:55:21 2020(r365783) @@ -239,7 +239,7 @@ zfs_file_fsync(zfs_file_t *fp, int flags) if (fp->f_type != DTYPE_VNODE) return (EINVAL); - v = fp->f_data; + v = fp->f_vnode; return (zfs_vop_fsync(v)); } Modified: head/sys/fs/nfs/nfsdport.h == --- head/sys/fs/nfs/nfsdport.h Tue Sep 15 21:48:24 2020(r365782) +++ head/sys/fs/nfs/nfsdport.h Tue Sep 15 21:55:21 2020(r365783) @@ -94,7 +94,7 @@ struct nfsexstuff { #defineNFSLOCKHASH(f) \ (&nfslockhash[nfsrv_hashfh(f) % nfsrv_lockhashsize]) -#defineNFSFPVNODE(f) ((struct vnode *)((f)->f_data)) +#defineNFSFPVNODE(f) ((f)->f_vnode) #defineNFSFPCRED(f)((f)->f_cred) #defineNFSFPFLAG(f)((f)->f_flag) Modified: head/sys/kern/kern_descrip.c == --- head/sys/kern/kern_descrip.cTue Sep 15 21:48:24 2020 (r365782) +++ head/sys/kern/kern_descrip.cTue Sep 15 21:55:21 2020 (r365783) @@ -2622,6 +2622,15 @@ finit(struct file *fp, u_int flag, short type, void *d atomic_store_rel_ptr((volatile uintptr_t *)&fp->f_ops, (uintptr_t)ops); } +void +finit_vnode(struct file *fp, u_int flag, void *data, struct fileops *ops) +{ + fp->f_seqcount[UIO_READ] = 1; + fp->f_seqcount[UIO_WRITE] = 1; + finit(fp, (flag & FMASK) | (fp->f_flag & FHASLOCK), DTYPE_VNODE, + data, ops); +} + int fget_cap_locked(struct filedesc *fdp, int fd, cap_rights_t *needrightsp, struct file **fpp, struct filecaps *havecapsp) Modified: head/sys/kern/vfs_syscalls.c == --- head/sys/kern/vfs_syscalls.cTue Sep 15 21:48:24 2020 (r365782) +++ head/sys/kern/vfs_syscalls.cTue Sep 15 21:55:21 2020 (r365783) @@ -1163,10 +1163,7 @@ kern_openat(struct thread *td, int fd, const char *pat */ if (fp->f_ops == &badfileops) { KASSERT(vp->v_type != VFIFO, ("Unexpected fifo.")); - fp->f_seqcount[UIO_READ] = 1; - fp->f_seqcount[UIO_WRITE] = 1; - finit(fp, (flags & FMASK) | (fp->f_flag & FHASLOCK), - DTYPE_VNODE, vp, &vnops); + finit_vnode(fp, flags, NULL, &vnops); } VOP_UNLOCK(vp); @@ -4138,7 +4135,6 @@ unionread: vp = vp->v_mount->mnt_vnodecovered; VREF(vp); fp->f_vnode = vp; - fp->f_data = vp; foffset = 0; vput(tvp); goto unionread; @@ -4502,10 +4498,7 @@ sys_fhopen(struct thread *td, struct fhopen_args *uap) td->td_dupfd = 0; #endif fp->f_vnode = vp; - fp->f_seqcount[UIO_READ] = 1; - fp->f_seqcount[UIO_WRITE] = 1; - finit(fp, (fmode & FMASK) | (fp->f_flag & FHASLOCK), DTYPE_VNODE, vp, - &vnops); + finit_vnode(fp, fmode, NULL, &vnops); VOP_UNLOCK(vp); if ((fmode & O_TRUNC) != 0) { error = fo_truncate(fp, 0, td->td_ucred, td); Modified: head/sys/sys/file.h == --- head/sys/sys/file.h Tue Sep 15 21:48:24 2020(r365782) +++ head/sys/sys/file.h Tue Sep 15 21:55:21 2020(r365783) @@ -268,6 +268,7 @@ fo_fill_kinfo_t vn_fill_kinfo; int vn_fill_kinfo_vnode(struct vnode *vp, struct kinfo_file *kif); void finit(struct file *, u_int, short, void *, struct fileops *); +void finit_vnode(struct file *, u_int, void *, struct fileops *); int fgetvp(struct thread
svn commit: r365784 - in head/sys: kern sys
Author: kib Date: Tue Sep 15 22:00:58 2020 New Revision: 365784 URL: https://svnweb.freebsd.org/changeset/base/365784 Log: vfs_subr.c: export io_hold_cnt and vn_read_from_obj(). Reviewed by: markj Tested by:pho Sponsored by: The FreeBSD Foundation Differential revision:https://reviews.freebsd.org/D26346 Modified: head/sys/kern/vfs_vnops.c head/sys/sys/vnode.h Modified: head/sys/kern/vfs_vnops.c == --- head/sys/kern/vfs_vnops.c Tue Sep 15 21:55:21 2020(r365783) +++ head/sys/kern/vfs_vnops.c Tue Sep 15 22:00:58 2020(r365784) @@ -125,7 +125,7 @@ struct fileops vnops = { .fo_flags = DFLAG_PASSABLE | DFLAG_SEEKABLE }; -static const int io_hold_cnt = 16; +const u_int io_hold_cnt = 16; static int vn_io_fault_enable = 1; SYSCTL_INT(_debug, OID_AUTO, vn_io_fault_enable, CTLFLAG_RWTUN, &vn_io_fault_enable, 0, "Enable vn_io_fault lock avoidance"); @@ -848,7 +848,7 @@ get_advice(struct file *fp, struct uio *uio) return (ret); } -static int +int vn_read_from_obj(struct vnode *vp, struct uio *uio) { vm_object_t obj; Modified: head/sys/sys/vnode.h == --- head/sys/sys/vnode.hTue Sep 15 21:55:21 2020(r365783) +++ head/sys/sys/vnode.hTue Sep 15 22:00:58 2020(r365784) @@ -392,6 +392,7 @@ MALLOC_DECLARE(M_VNODE); #endif extern u_int ncsizefactor; +extern const u_int io_hold_cnt; /* * Convert between vnode types and inode formats (since POSIX.1 @@ -734,7 +735,8 @@ int vn_rdwr_inchunks(enum uio_rw rw, struct vnode *vp, size_t len, off_t offset, enum uio_seg segflg, int ioflg, struct ucred *active_cred, struct ucred *file_cred, size_t *aresid, struct thread *td); -intvn_rlimit_fsize(const struct vnode *vn, const struct uio *uio, +intvn_read_from_obj(struct vnode *vp, struct uio *uio); +intvn_rlimit_fsize(const struct vnode *vp, const struct uio *uio, struct thread *td); intvn_start_write(struct vnode *vp, struct mount **mpp, int flags); intvn_start_secondary_write(struct vnode *vp, struct mount **mpp, ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r365785 - in head/sys: kern sys ufs/ufs
Author: kib Date: Tue Sep 15 22:06:36 2020 New Revision: 365785 URL: https://svnweb.freebsd.org/changeset/base/365785 Log: Convert page cache read to VOP. There are several negative side-effects of not calling into VOP layer at all for page cache reads. The biggest is the missed activation of EVFILT_READ knotes. Also, it allows filesystem to make more fine grained decision to refuse read from page cache. Keep VIRF_PGREAD flag around, it is still useful for nullfs, and for asserts. Reviewed by: markj Tested by:pho Discussed with: mjg Sponsored by: The FreeBSD Foundation Differential revision:https://reviews.freebsd.org/D26346 Modified: head/sys/kern/vfs_default.c head/sys/kern/vfs_subr.c head/sys/kern/vfs_vnops.c head/sys/kern/vnode_if.src head/sys/sys/vnode.h head/sys/ufs/ufs/ufs_vnops.c Modified: head/sys/kern/vfs_default.c == --- head/sys/kern/vfs_default.c Tue Sep 15 22:00:58 2020(r365784) +++ head/sys/kern/vfs_default.c Tue Sep 15 22:06:36 2020(r365785) @@ -90,6 +90,7 @@ static int vop_stdadd_writecount(struct vop_add_writec static int vop_stdcopy_file_range(struct vop_copy_file_range_args *ap); static int vop_stdfdatasync(struct vop_fdatasync_args *ap); static int vop_stdgetpages_async(struct vop_getpages_async_args *ap); +static int vop_stdread_pgcache(struct vop_read_pgcache_args *ap); static int vop_stdstat(struct vop_stat_args *ap); /* @@ -135,6 +136,7 @@ struct vop_vector default_vnodeops = { .vop_poll = vop_nopoll, .vop_putpages = vop_stdputpages, .vop_readlink = VOP_EINVAL, + .vop_read_pgcache = vop_stdread_pgcache, .vop_rename = vop_norename, .vop_revoke = VOP_PANIC, .vop_strategy = vop_nostrategy, @@ -1574,4 +1576,10 @@ vop_stdstat(struct vop_stat_args *a) sb->st_gen = vap->va_gen; out: return (vop_stat_helper_post(a, error)); +} + +static int +vop_stdread_pgcache(struct vop_read_pgcache_args *ap __unused) +{ + return (EJUSTRETURN); } Modified: head/sys/kern/vfs_subr.c == --- head/sys/kern/vfs_subr.cTue Sep 15 22:00:58 2020(r365784) +++ head/sys/kern/vfs_subr.cTue Sep 15 22:06:36 2020(r365785) @@ -5839,6 +5839,15 @@ vop_read_post(void *ap, int rc) } void +vop_read_pgcache_post(void *ap, int rc) +{ + struct vop_read_pgcache_args *a = ap; + + if (!rc) + VFS_KNOTE_UNLOCKED(a->a_vp, NOTE_READ); +} + +void vop_readdir_post(void *ap, int rc) { struct vop_readdir_args *a = ap; Modified: head/sys/kern/vfs_vnops.c == --- head/sys/kern/vfs_vnops.c Tue Sep 15 22:00:58 2020(r365784) +++ head/sys/kern/vfs_vnops.c Tue Sep 15 22:06:36 2020(r365785) @@ -951,15 +951,6 @@ out_pip: return (uio->uio_resid == 0 ? 0 : EJUSTRETURN); } -static bool -do_vn_read_from_pgcache(struct vnode *vp, struct uio *uio, struct file *fp) -{ - return ((vp->v_irflag & (VIRF_DOOMED | VIRF_PGREAD)) == VIRF_PGREAD && - !mac_vnode_check_read_enabled() && - uio->uio_resid <= ptoa(io_hold_cnt) && uio->uio_offset >= 0 && - (fp->f_flag & O_DIRECT) == 0 && vn_io_pgcache_read_enable); -} - /* * File table vnode read routine. */ @@ -976,8 +967,19 @@ vn_read(struct file *fp, struct uio *uio, struct ucred uio->uio_td, td)); KASSERT(flags & FOF_OFFSET, ("No FOF_OFFSET")); vp = fp->f_vnode; - if (do_vn_read_from_pgcache(vp, uio, fp)) { - error = vn_read_from_obj(vp, uio); + ioflag = 0; + if (fp->f_flag & FNONBLOCK) + ioflag |= IO_NDELAY; + if (fp->f_flag & O_DIRECT) + ioflag |= IO_DIRECT; + + /* +* Try to read from page cache. VIRF_DOOMED check is racy but +* allows us to avoid unneeded work outright. +*/ + if (vn_io_pgcache_read_enable && !mac_vnode_check_read_enabled() && + (vp->v_irflag & (VIRF_DOOMED | VIRF_PGREAD)) == VIRF_PGREAD) { + error = VOP_READ_PGCACHE(vp, uio, ioflag, fp->f_cred); if (error == 0) { fp->f_nextoff[UIO_READ] = uio->uio_offset; return (0); @@ -985,11 +987,7 @@ vn_read(struct file *fp, struct uio *uio, struct ucred if (error != EJUSTRETURN) return (error); } - ioflag = 0; - if (fp->f_flag & FNONBLOCK) - ioflag |= IO_NDELAY; - if (fp->f_flag & O_DIRECT) - ioflag |= IO_DIRECT; + advice = get_advice(fp, uio); vn_lock(vp, LK_SHARED | LK_RETRY); Modified: head/sys/kern/vnode_if.src ===
svn commit: r365786 - head/sys/fs/tmpfs
Author: kib Date: Tue Sep 15 22:13:21 2020 New Revision: 365786 URL: https://svnweb.freebsd.org/changeset/base/365786 Log: Microoptimize tmpfs node ref/unref by using atomics. Avoid tmpfs mount and node locks when ref count is greater than zero, which is the case until node is being destroyed by unlink or unmount. Reviewed by: markj Tested by:pho Sponsored by: The FreeBSD Foundation Differential revision:https://reviews.freebsd.org/D26346 Modified: head/sys/fs/tmpfs/tmpfs.h head/sys/fs/tmpfs/tmpfs_subr.c head/sys/fs/tmpfs/tmpfs_vnops.c Modified: head/sys/fs/tmpfs/tmpfs.h == --- head/sys/fs/tmpfs/tmpfs.h Tue Sep 15 22:06:36 2020(r365785) +++ head/sys/fs/tmpfs/tmpfs.h Tue Sep 15 22:13:21 2020(r365786) @@ -228,7 +228,7 @@ struct tmpfs_node { int tn_vpstate; /* (i) */ /* Transient refcounter on this node. */ - u_int tn_refcount;/* (m) + (i) */ + u_int tn_refcount;/* 0<->1 (m) + (i) */ /* misc data field for different tn_type node */ union { @@ -412,7 +412,6 @@ struct tmpfs_dir_cursor { */ void tmpfs_ref_node(struct tmpfs_node *node); -void tmpfs_ref_node_locked(struct tmpfs_node *node); inttmpfs_alloc_node(struct mount *mp, struct tmpfs_mount *, enum vtype, uid_t uid, gid_t gid, mode_t mode, struct tmpfs_node *, const char *, dev_t, struct tmpfs_node **); Modified: head/sys/fs/tmpfs/tmpfs_subr.c == --- head/sys/fs/tmpfs/tmpfs_subr.c Tue Sep 15 22:06:36 2020 (r365785) +++ head/sys/fs/tmpfs/tmpfs_subr.c Tue Sep 15 22:13:21 2020 (r365786) @@ -49,6 +49,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -211,23 +212,17 @@ tmpfs_pages_check_avail(struct tmpfs_mount *tmp, size_ void tmpfs_ref_node(struct tmpfs_node *node) { +#ifdef INVARIANTS + u_int old; - TMPFS_NODE_LOCK(node); - tmpfs_ref_node_locked(node); - TMPFS_NODE_UNLOCK(node); + old = +#endif + refcount_acquire(&node->tn_refcount); +#ifdef INVARIANTS + KASSERT(old > 0, ("node %p zero refcount", node)); +#endif } -void -tmpfs_ref_node_locked(struct tmpfs_node *node) -{ - - TMPFS_NODE_ASSERT_LOCKED(node); - KASSERT(node->tn_refcount > 0, ("node %p zero refcount", node)); - KASSERT(node->tn_refcount < UINT_MAX, ("node %p refcount %u", node, - node->tn_refcount)); - node->tn_refcount++; -} - /* * Allocates a new node of type 'type' inside the 'tmp' mount point, with * its owner set to 'uid', its group to 'gid' and its mode set to 'mode', @@ -370,6 +365,8 @@ tmpfs_alloc_node(struct mount *mp, struct tmpfs_mount void tmpfs_free_node(struct tmpfs_mount *tmp, struct tmpfs_node *node) { + if (refcount_release_if_not_last(&node->tn_refcount)) + return; TMPFS_LOCK(tmp); TMPFS_NODE_LOCK(node); @@ -384,19 +381,19 @@ tmpfs_free_node_locked(struct tmpfs_mount *tmp, struct bool detach) { vm_object_t uobj; + bool last; TMPFS_MP_ASSERT_LOCKED(tmp); TMPFS_NODE_ASSERT_LOCKED(node); - KASSERT(node->tn_refcount > 0, ("node %p refcount zero", node)); - node->tn_refcount--; - if (node->tn_attached && (detach || node->tn_refcount == 0)) { + last = refcount_release(&node->tn_refcount); + if (node->tn_attached && (detach || last)) { MPASS(tmp->tm_nodes_inuse > 0); tmp->tm_nodes_inuse--; LIST_REMOVE(node, tn_entries); node->tn_attached = false; } - if (node->tn_refcount > 0) + if (!last) return (false); #ifdef INVARIANTS @@ -596,7 +593,7 @@ tmpfs_alloc_vp(struct mount *mp, struct tmpfs_node *no error = 0; tm = VFS_TO_TMPFS(mp); TMPFS_NODE_LOCK(node); - tmpfs_ref_node_locked(node); + tmpfs_ref_node(node); loop: TMPFS_NODE_ASSERT_LOCKED(node); if ((vp = node->tn_vnode) != NULL) { Modified: head/sys/fs/tmpfs/tmpfs_vnops.c == --- head/sys/fs/tmpfs/tmpfs_vnops.c Tue Sep 15 22:06:36 2020 (r365785) +++ head/sys/fs/tmpfs/tmpfs_vnops.c Tue Sep 15 22:13:21 2020 (r365786) @@ -1663,7 +1663,7 @@ restart: if (tnp->tn_type != VDIR) continue; TMPFS_NODE_LOCK(tnp); - tmpfs_ref_node_locked(tnp); + tmpfs_ref_node(tnp); /* * tn_vnode cannot be instantiated while we hold the ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/lis
svn commit: r365787 - head/sys/fs/tmpfs
Author: kib Date: Tue Sep 15 22:19:16 2020 New Revision: 365787 URL: https://svnweb.freebsd.org/changeset/base/365787 Log: Add tmpfs page cache read support. Or it could be explained as lockless (for vnode lock) reads. Reads are performed from the node tn_obj object. Tmpfs regular vnode object lifecycle is significantly different from the normal OBJT_VNODE: it is alive as far as ref_count > 0. Ensure liveness of the tmpfs VREG node and consequently v_object inside VOP_READ_PGCACHE by referencing tmpfs node in tmpfs_open(). Provide custom tmpfs fo_close() method on file, to ensure that close is paired with open. Add tmpfs VOP_READ_PGCACHE that takes advantage of all tmpfs quirks. It is quite cheap in code size sense to support page-ins for read for tmpfs even if we do not own tmpfs vnode lock. Also, we can handle holes in tmpfs node without additional efforts, and do not have limitation of the transfer size. Reviewed by: markj Discussed with and benchmarked by:mjg (previous version) Tested by:pho Sponsored by: The FreeBSD Foundation Differential revision:https://reviews.freebsd.org/D26346 Modified: head/sys/fs/tmpfs/tmpfs.h head/sys/fs/tmpfs/tmpfs_subr.c head/sys/fs/tmpfs/tmpfs_vfsops.c head/sys/fs/tmpfs/tmpfs_vnops.c Modified: head/sys/fs/tmpfs/tmpfs.h == --- head/sys/fs/tmpfs/tmpfs.h Tue Sep 15 22:13:21 2020(r365786) +++ head/sys/fs/tmpfs/tmpfs.h Tue Sep 15 22:19:16 2020(r365787) @@ -287,6 +287,7 @@ struct tmpfs_node { * a position within the file is accessed. */ vm_object_t tn_aobj;/* (c) */ + struct tmpfs_mount *tn_tmp;/* (c) */ } tn_reg; } tn_spec; /* (v) */ }; @@ -415,6 +416,7 @@ voidtmpfs_ref_node(struct tmpfs_node *node); inttmpfs_alloc_node(struct mount *mp, struct tmpfs_mount *, enum vtype, uid_t uid, gid_t gid, mode_t mode, struct tmpfs_node *, const char *, dev_t, struct tmpfs_node **); +inttmpfs_fo_close(struct file *fp, struct thread *td); void tmpfs_free_node(struct tmpfs_mount *, struct tmpfs_node *); bool tmpfs_free_node_locked(struct tmpfs_mount *, struct tmpfs_node *, bool); void tmpfs_free_tmp(struct tmpfs_mount *); @@ -557,6 +559,8 @@ tmpfs_update_getattr(struct vnode *vp) if (__predict_false(node->tn_status & update_flags) != 0) tmpfs_update(vp); } + +extern struct fileops tmpfs_fnops; #endif /* _KERNEL */ Modified: head/sys/fs/tmpfs/tmpfs_subr.c == --- head/sys/fs/tmpfs/tmpfs_subr.c Tue Sep 15 22:13:21 2020 (r365786) +++ head/sys/fs/tmpfs/tmpfs_subr.c Tue Sep 15 22:19:16 2020 (r365787) @@ -51,6 +51,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -340,6 +341,7 @@ tmpfs_alloc_node(struct mount *mp, struct tmpfs_mount /* OBJ_TMPFS is set together with the setting of vp->v_object */ vm_object_set_flag(obj, OBJ_TMPFS_NODE); VM_OBJECT_WUNLOCK(obj); + nnode->tn_reg.tn_tmp = tmp; break; default: @@ -697,6 +699,7 @@ loop: vp->v_object = object; object->un_pager.swp.swp_tmpfs = vp; vm_object_set_flag(object, OBJ_TMPFS); + vp->v_irflag |= VIRF_PGREAD; VI_UNLOCK(vp); VM_OBJECT_WUNLOCK(object); break; Modified: head/sys/fs/tmpfs/tmpfs_vfsops.c == --- head/sys/fs/tmpfs/tmpfs_vfsops.cTue Sep 15 22:13:21 2020 (r365786) +++ head/sys/fs/tmpfs/tmpfs_vfsops.cTue Sep 15 22:19:16 2020 (r365787) @@ -51,6 +51,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -662,6 +663,8 @@ static int tmpfs_init(struct vfsconf *conf) { tmpfs_subr_init(); + memcpy(&tmpfs_fnops, &vnops, sizeof(struct fileops)); + tmpfs_fnops.fo_close = tmpfs_fo_close; return (0); } Modified: head/sys/fs/tmpfs/tmpfs_vnops.c == --- head/sys/fs/tmpfs/tmpfs_vnops.c Tue Sep 15 22:13:21 2020 (r365786) +++ head/sys/fs/tmpfs/tmpfs_vnops.c Tue Sep 15 22:19:16 2020 (r365787) @@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -276,22 +277,25 @@ tmpfs_mknod(struct vop_mknod_args *v) return tmpfs_alloc_file(dvp, vpp, vap, cnp, NULL); } +struct fileops tmpfs_fnops; + static int tmpfs_open(struct vop_open_args *v) { -
svn commit: r365788 - head/sys/kern
Author: markj Date: Tue Sep 15 23:03:56 2020 New Revision: 365788 URL: https://svnweb.freebsd.org/changeset/base/365788 Log: Fix locking in uipc_accept(). Reported by: cy MFC after:1 week Sponsored by: The FreeBSD Foundation Modified: head/sys/kern/uipc_usrreq.c Modified: head/sys/kern/uipc_usrreq.c == --- head/sys/kern/uipc_usrreq.c Tue Sep 15 22:19:16 2020(r365787) +++ head/sys/kern/uipc_usrreq.c Tue Sep 15 23:03:56 2020(r365788) @@ -506,7 +506,10 @@ uipc_accept(struct socket *so, struct sockaddr **nam) else sa = &sun_noname; bcopy(sa, *nam, sa->sa_len); - unp_pcb_unlock_pair(unp, unp2); + if (unp2 != NULL) + unp_pcb_unlock_pair(unp, unp2); + else + UNP_PCB_UNLOCK(unp); return (0); } ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r365789 - head/sys/fs/nfsserver
Author: rmacklem Date: Wed Sep 16 02:25:18 2020 New Revision: 365789 URL: https://svnweb.freebsd.org/changeset/base/365789 Log: Fix a LOR between the NFS server and server side krpc. Recent testing of the NFS-over-TLS code found a LOR between the mutex lock used for sessions and the sleep lock used for server side krpc socket structures. The code in nfsrv_checksequence() would call SVC_RELEASE() with the mutex held. Normally this is ok, since all that happens is SVC_RELEASE() decrements a reference count. However, if the socket has just been shut down, SVC_RELEASE() drops the reference count to 0 and acquires a sleep lock during destruction of the server side krpc structure. This patch fixes the problem by moving the SVC_RELEASE() call in nfsrv_checksequence() down a few lines to below where the mutex is released. MFC after:1 week Modified: head/sys/fs/nfsserver/nfs_nfsdstate.c Modified: head/sys/fs/nfsserver/nfs_nfsdstate.c == --- head/sys/fs/nfsserver/nfs_nfsdstate.c Tue Sep 15 23:03:56 2020 (r365788) +++ head/sys/fs/nfsserver/nfs_nfsdstate.c Wed Sep 16 02:25:18 2020 (r365789) @@ -6233,6 +6233,7 @@ nfsrv_checksequence(struct nfsrv_descript *nd, uint32_ * bound as well, do the implicit binding unless a * BindConnectiontoSession has already been done on the session. */ + savxprt = NULL; if (sep->sess_clp->lc_req.nr_client != NULL && sep->sess_cbsess.nfsess_xprt != nd->nd_xprt && (sep->sess_crflags & NFSV4CRSESS_CONNBACKCHAN) != 0 && @@ -6245,14 +6246,14 @@ nfsrv_checksequence(struct nfsrv_descript *nd, uint32_ sep->sess_clp->lc_req.nr_client->cl_private; nd->nd_xprt->xp_idletimeout = 0;/* Disable timeout. */ sep->sess_cbsess.nfsess_xprt = nd->nd_xprt; - if (savxprt != NULL) - SVC_RELEASE(savxprt); } *sflagsp = 0; if (sep->sess_clp->lc_req.nr_client == NULL) *sflagsp |= NFSV4SEQ_CBPATHDOWN; NFSUNLOCKSESSION(shp); + if (savxprt != NULL) + SVC_RELEASE(savxprt); if (error == NFSERR_EXPIRED) { *sflagsp |= NFSV4SEQ_EXPIREDALLSTATEREVOKED; error = 0; ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r365790 - in head/sys: kern sys
Author: imp Date: Wed Sep 16 06:02:30 2020 New Revision: 365790 URL: https://svnweb.freebsd.org/changeset/base/365790 Log: Use standard bool type, instead of non-standard boolean_t Modified: head/sys/kern/subr_bus.c head/sys/sys/devctl.h Modified: head/sys/kern/subr_bus.c == --- head/sys/kern/subr_bus.cWed Sep 16 02:25:18 2020(r365789) +++ head/sys/kern/subr_bus.cWed Sep 16 06:02:30 2020(r365790) @@ -584,7 +584,7 @@ filt_devctl_read(struct knote *kn, long hint) /** * @brief Return whether the userland process is running */ -boolean_t +bool devctl_process_running(void) { return (devsoftc.inuse == 1); Modified: head/sys/sys/devctl.h == --- head/sys/sys/devctl.h Wed Sep 16 02:25:18 2020(r365789) +++ head/sys/sys/devctl.h Wed Sep 16 06:02:30 2020(r365790) @@ -35,7 +35,7 @@ * devctl hooks. Typically one should use the devctl_notify * hook to send the message. */ -boolean_t devctl_process_running(void); +bool devctl_process_running(void); void devctl_notify(const char *__system, const char *__subsystem, const char *__type, const char *__data); struct sbuf; ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"