Index: etc/defaults/periodic.conf =================================================================== --- etc/defaults/periodic.conf +++ etc/defaults/periodic.conf @@ -134,6 +134,11 @@ daily_status_mail_rejects_logs=3 # How many logs to check daily_status_mail_rejects_shorten="NO" # Shorten output +# 480.leapfile-ntpd +daily_ntpd_leapfile_enable="NO" # Fetch NTP leapfile +daily_ntpd_avoid_congestion="YES" # Avoid congesting + # leapfile sources + # 480.status-ntpd daily_status_ntpd_enable="NO" # Check NTP status Index: etc/defaults/rc.conf =================================================================== --- etc/defaults/rc.conf +++ etc/defaults/rc.conf @@ -362,6 +362,15 @@ ntpd_sync_on_start="NO" # Sync time on ntpd startup, even if offset is high ntpd_flags="-p /var/run/ntpd.pid -f /var/db/ntpd.drift" # Flags to ntpd (if enabled). +ntp_src_leapfile="/etc/ntp/leap-seconds" + # Initial source for ntpd leapfile +ntp_db_leapfile="/var/db/ntpd.leap-seconds.list" + # Working copy (updated weekly) leapfile +ntp_leapfile_sources="https://www.ietf.org/timezones/data/leap-seconds.list" + # Source from which to fetch leapfile +ntp_leapfile_expiry_days=30 # Check for new leapfile 30 days prior to + # expiry. +ntp_leapfile_fetch_verbose="NO" # Be verbose during NTP leapfile fetch # Network Information Services (NIS) options: All need rpcbind_enable="YES" ### nis_client_enable="NO" # We're an NIS client (or NO). Index: etc/ntp.conf =================================================================== --- etc/ntp.conf +++ etc/ntp.conf @@ -81,4 +81,6 @@ # See http://support.ntp.org/bin/view/Support/ConfiguringNTP#Section_6.14. # for documentation regarding leapfile. Updates to the file can be obtained # from ftp://time.nist.gov/pub/ or ftp://tycho.usno.navy.mil/pub/ntp/. -leapfile "/etc/ntp/leap-seconds" +# Use either leapfile in /etc/ntp or weekly updated leapfile in /var/db. +#leapfile "/etc/ntp/leap-seconds" +leapfile "/var/db/ntpd.leap-seconds.list" Index: etc/periodic/daily/480.leapfile-ntpd =================================================================== --- /dev/null +++ etc/periodic/daily/480.leapfile-ntpd @@ -0,0 +1,28 @@ +#!/bin/sh +# +# $FreeBSD$ +# + +# If there is a global system configuration file, suck it in. +# +if [ -r /etc/defaults/periodic.conf ] +then + . /etc/defaults/periodic.conf + source_periodic_confs +fi + +case "$daily_ntpd_leapfile_enable" in + [Yy][Ee][Ss]) + case "$daily_ntpd_avoid_congestion" in + [Yy][Ee][Ss]) + # Avoid dogpiling + (sleep $(jot -r 1 0 86400); service ntpd fetch) & + ;; + *) + service ntpd fetch + ;; + esac + ;; +esac + +exit $rc Index: etc/periodic/daily/Makefile =================================================================== --- etc/periodic/daily/Makefile +++ etc/periodic/daily/Makefile @@ -35,7 +35,8 @@ .endif .if ${MK_NTP} != "no" -FILES+= 480.status-ntpd +FILES+= 480.status-ntpd \ + 480.leapfile-ntpd .endif .if ${MK_RCMDS} != "no" Index: etc/rc.d/ntpd =================================================================== --- etc/rc.d/ntpd +++ etc/rc.d/ntpd @@ -14,6 +14,8 @@ rcvar="ntpd_enable" command="/usr/sbin/${name}" pidfile="/var/run/${name}.pid" +extra_commands="fetch" +fetch_cmd="ntpd_fetch_leapfile" start_precmd="ntpd_precmd" load_rc_config $name @@ -30,6 +32,10 @@ return 0; fi + if [ ! -f $ntp_db_leapfile ]; then + ntpd_fetch_leapfile + fi + # If running in a chroot cage, ensure that the appropriate files # exist inside the cage, as well as helper symlinks into the cage # from outside. @@ -44,10 +50,71 @@ ( cd /dev ; /bin/pax -rw -pe clockctl "${ntpd_chrootdir}/dev" ) fi ln -fs "${ntpd_chrootdir}/var/db/ntp.drift" /var/db/ntp.drift + ln -fs "${ntpd_chrootdir}${ntp_tmp_leapfile}" ${ntp_tmp_leapfile} # Change run_rc_commands()'s internal copy of $ntpd_flags # rc_flags="-u ntpd:ntpd -i ${ntpd_chrootdir} $rc_flags" } +current_ntp_ts() { + # Seconds between 1900-01-01 and 1970-01-01 + # echo $(((70*365+17)*86400)) + ntp_to_unix=2208988800 + + echo $(($(date -u +%s)+$ntp_to_unix)) +} + +get_ntp_leapfile_ver() { + expr "$(awk '$1 == "#$" { print $2 }' "$1" 2>/dev/null)" : \ + '^\([1-9][0-9]*\)$' \| 0 +} + +get_ntp_leapfile_expiry() { + expr "$(awk '$1 == "#@" { print $2 }' "$1" 2>/dev/null)" : \ + '^\([1-9][0-9]*\)$' \| 0 +} + +ntpd_fetch_leapfile() { + local ntp_tmp_leapfile rc verbose + + if checkyesno ntp_leapfile_fetch_verbose; then + verbose=echo + else + verbose=: + fi + + ntp_tmp_leapfile="/var/run/ntpd.leap-seconds.list" + + ntp_ver_no_src=$(get_ntp_leapfile_ver $ntp_src_leapfile) + ntp_ver_no_db=$(get_ntp_leapfile_ver $ntp_db_leapfile) + $verbose ntp_src_leapfile version is $ntp_ver_no_src + $verbose ntp_db_leapfile version is $ntp_ver_no_db + + if [ "$ntp_ver_no_src" -gt "$ntp_ver_no_db" ]; then + $verbose replacing $ntp_db_leapfile with $ntp_src_leapfile + cp -p $ntp_src_leapfile $ntp_db_leapfile + ntp_ver_no_db=$ntp_ver_no_src + else + $verbose not replacing $ntp_db_leapfile with $ntp_src_leapfile + fi + ntp_leap_expiry=$(get_ntp_leapfile_expiry $ntp_db_leapfile) + ntp_leapfile_expiry_seconds=$((ntp_leapfile_expiry_days*86400)) + ntp_leap_fetch_date=$((ntp_leap_expiry-ntp_leapfile_expiry_seconds)) + if [ $(current_ntp_ts) -ge $ntp_leap_fetch_date ]; then + $verbose Within ntp leapfile expiry limit, initiating fetch + for url in $ntp_leapfile_sources ; do + $verbose fetching $url + fetch -mqo $ntp_tmp_leapfile $url && break + done + ntp_ver_no_tmp=$(get_ntp_leapfile_ver $ntp_tmp_leapfile) + if [ "$ntp_ver_no_tmp" -gt "$ntp_ver_no_db" ]; then + $verbose using $url as $ntp_db_leapfile + mv $ntp_tmp_leapfile $ntp_db_leapfile + else + $verbose using existing $ntp_db_leapfile + fi + fi +} + run_rc_command "$1" Index: lib/libc/sys/revoke.2 =================================================================== --- lib/libc/sys/revoke.2 +++ lib/libc/sys/revoke.2 @@ -31,7 +31,7 @@ .\" @(#)revoke.2 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd June 4, 1993 +.Dd Jan 25, 2016 .Dt REVOKE 2 .Os .Sh NAME @@ -59,7 +59,8 @@ system call will succeed. If the file is a special file for a device which is open, the device close function -is called as if all open references to the file had been closed. +is called as if all open references to the file had been closed +using a special close method which does not block. .Pp Access to a file may be revoked only by its owner or the super user. The @@ -104,3 +105,6 @@ .Fn revoke system call first appeared in .Bx 4.3 Reno . +.Sh BUGS +The non-blocking close method is only correctly implemented for +terminal devices. Index: sys/arm/arm/pmap-v6-new.c =================================================================== --- sys/arm/arm/pmap-v6-new.c +++ sys/arm/arm/pmap-v6-new.c @@ -3799,14 +3799,19 @@ * is set. Do it now, before the mapping is stored and made * valid for hardware table walk. If done later, there is a race * for other threads of current process in lazy loading case. + * Don't do it for kernel memory which is mapped with exec + * permission even if the memory isn't going to hold executable + * code. The only time when icache sync is needed is after + * kernel module is loaded and the relocation info is processed. + * And it's done in elf_cpu_load_file(). * * QQQ: (1) Does it exist any better way where * or how to sync icache? * (2) Now, we do it on a page basis. */ - if ((prot & VM_PROT_EXECUTE) && - (m->md.pat_mode == PTE2_ATTR_WB_WA) && - ((opa != pa) || (opte2 & PTE2_NX))) + if ((prot & VM_PROT_EXECUTE) && pmap != kernel_pmap && + m->md.pat_mode == PTE2_ATTR_WB_WA && + (opa != pa || (opte2 & PTE2_NX))) cache_icache_sync_fresh(va, pa, PAGE_SIZE); npte2 |= PTE2_A; @@ -4405,7 +4410,7 @@ l2prot |= PTE2_U | PTE2_NG; if ((prot & VM_PROT_EXECUTE) == 0) l2prot |= PTE2_NX; - else if (m->md.pat_mode == PTE2_ATTR_WB_WA) { + else if (m->md.pat_mode == PTE2_ATTR_WB_WA && pmap != kernel_pmap) { /* * Sync icache if exec permission and attribute PTE2_ATTR_WB_WA * is set. QQQ: For more info, see comments in pmap_enter(). @@ -4476,7 +4481,7 @@ l1prot |= PTE1_U | PTE1_NG; if ((prot & VM_PROT_EXECUTE) == 0) l1prot |= PTE1_NX; - else if (m->md.pat_mode == PTE2_ATTR_WB_WA) { + else if (m->md.pat_mode == PTE2_ATTR_WB_WA && pmap != kernel_pmap) { /* * Sync icache if exec permission and attribute PTE2_ATTR_WB_WA * is set. QQQ: For more info, see comments in pmap_enter(). Index: sys/arm/arm/pmap-v6.c =================================================================== --- sys/arm/arm/pmap-v6.c +++ sys/arm/arm/pmap-v6.c @@ -3446,14 +3446,10 @@ pte = ptep[l2pte_index(va)]; if (pte == 0) return (0); - switch (pte & L2_TYPE_MASK) { - case L2_TYPE_L: + if ((pte & L2_TYPE_MASK) == L2_TYPE_L) pa = (pte & L2_L_FRAME) | (va & L2_L_OFFSET); - break; - default: + else pa = (pte & L2_S_FRAME) | (va & L2_S_OFFSET); - break; - } } return (pa); } @@ -3515,20 +3511,15 @@ PMAP_UNLOCK(pmap); return (NULL); } else { - switch (pte & L2_TYPE_MASK) { - case L2_TYPE_L: + if ((pte & L2_TYPE_MASK) == L2_TYPE_L) panic("extract and hold section mapping"); - break; - default: + else pa = (pte & L2_S_FRAME) | (va & L2_S_OFFSET); - break; - } if (vm_page_pa_tryrelock(pmap, pa & PG_FRAME, &paddr)) goto retry; m = PHYS_TO_VM_PAGE(pa); vm_page_hold(m); } - } PMAP_UNLOCK(pmap); @@ -3567,14 +3558,10 @@ pa = 0; goto out; } - switch (pte & L2_TYPE_MASK) { - case L2_TYPE_L: + if ((pte & L2_TYPE_MASK) == L2_TYPE_L) pa = (pte & L2_L_FRAME) | (va & L2_L_OFFSET); - break; - default: + else pa = (pte & L2_S_FRAME) | (va & L2_S_OFFSET); - break; - } } out: if (pte2p != NULL) Index: sys/arm/arm/pmap.c =================================================================== --- sys/arm/arm/pmap.c +++ sys/arm/arm/pmap.c @@ -2787,18 +2787,14 @@ pte = &l2b->l2b_kva[l2pte_index(va)]; opte = *pte; if (l2pte_valid(opte)) { - /* pa = vtophs(va) taken from pmap_extract() */ - switch (opte & L2_TYPE_MASK) { - case L2_TYPE_L: + /* pa = vtophs(va) taken from pmap_extract() */ + if ((opte & L2_TYPE_MASK) == L2_TYPE_L) pa = (opte & L2_L_FRAME) | (va & L2_L_OFFSET); - break; - default: + else pa = (opte & L2_S_FRAME) | (va & L2_S_OFFSET); - break; - } - /* note: should never have to remove an allocation - * before the pvzone is initialized. - */ + /* note: should never have to remove an allocation + * before the pvzone is initialized. + */ rw_wlock(&pvh_global_lock); PMAP_LOCK(pmap_kernel()); if (pvzone != NULL && (m = vm_phys_paddr_to_vm_page(pa)) && @@ -3645,14 +3641,10 @@ pte = ptep[l2pte_index(va)]; if (pte == 0) return (0); - switch (pte & L2_TYPE_MASK) { - case L2_TYPE_L: + if ((pte & L2_TYPE_MASK) == L2_TYPE_L) pa = (pte & L2_L_FRAME) | (va & L2_L_OFFSET); - break; - default: + else pa = (pte & L2_S_FRAME) | (va & L2_S_OFFSET); - break; - } } return (pa); } @@ -3717,15 +3709,10 @@ return (NULL); } if (pte & L2_S_PROT_W || (prot & VM_PROT_WRITE) == 0) { - switch (pte & L2_TYPE_MASK) { - case L2_TYPE_L: + if ((pte & L2_TYPE_MASK) == L2_TYPE_L) pa = (pte & L2_L_FRAME) | (va & L2_L_OFFSET); - break; - - default: + else pa = (pte & L2_S_FRAME) | (va & L2_S_OFFSET); - break; - } if (vm_page_pa_tryrelock(pmap, pa & PG_FRAME, &paddr)) goto retry; m = PHYS_TO_VM_PAGE(pa); @@ -3769,14 +3756,10 @@ pa = 0; goto out; } - switch (pte & L2_TYPE_MASK) { - case L2_TYPE_L: + if ((pte & L2_TYPE_MASK) == L2_TYPE_L) pa = (pte & L2_L_FRAME) | (va & L2_L_OFFSET); - break; - default: + else pa = (pte & L2_S_FRAME) | (va & L2_S_OFFSET); - break; - } } out: if (pte2p != NULL) Index: sys/boot/arm/at91/boot2/boot2.c =================================================================== --- sys/boot/arm/at91/boot2/boot2.c +++ sys/boot/arm/at91/boot2/boot2.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2008 John Hay - * Copyright (c) 2006 Warner Losh + * Copyright (c) 2006 M Warner Losh * Copyright (c) 1998 Robert Nordier * All rights reserved. * @@ -30,52 +30,16 @@ #include "lib.h" #include "board.h" +#include "paths.h" +#include "rbx.h" -#define RBX_ASKNAME 0x0 /* -a */ -#define RBX_SINGLE 0x1 /* -s */ -/* 0x2 is reserved for log2(RB_NOSYNC). */ -/* 0x3 is reserved for log2(RB_HALT). */ -/* 0x4 is reserved for log2(RB_INITNAME). */ -#define RBX_DFLTROOT 0x5 /* -r */ -/* #define RBX_KDB 0x6 -d */ -/* 0x7 is reserved for log2(RB_RDONLY). */ -/* 0x8 is reserved for log2(RB_DUMP). */ -/* 0x9 is reserved for log2(RB_MINIROOT). */ -#define RBX_CONFIG 0xa /* -c */ -#define RBX_VERBOSE 0xb /* -v */ -/* #define RBX_SERIAL 0xc -h */ -/* #define RBX_CDROM 0xd -C */ -/* 0xe is reserved for log2(RB_POWEROFF). */ -#define RBX_GDB 0xf /* -g */ -/* #define RBX_MUTE 0x10 -m */ -/* 0x11 is reserved for log2(RB_SELFTEST). */ -/* 0x12 is reserved for boot programs. */ -/* 0x13 is reserved for boot programs. */ -/* #define RBX_PAUSE 0x14 -p */ -/* #define RBX_QUIET 0x15 -q */ -#define RBX_NOINTR 0x1c /* -n */ -/* 0x1d is reserved for log2(RB_MULTIPLE) and is just misnamed here. */ -/* #define RBX_DUAL 0x1d -D */ -/* 0x1f is reserved for log2(RB_BOOTINFO). */ - -/* pass: -a, -s, -r, -v, -g */ -#define RBX_MASK (OPT_SET(RBX_ASKNAME) | OPT_SET(RBX_SINGLE) | \ - OPT_SET(RBX_DFLTROOT) | \ - OPT_SET(RBX_VERBOSE) | \ - OPT_SET(RBX_GDB)) - -#define PATH_DOTCONFIG "/boot.config" -#define PATH_CONFIG "/boot/config" -//#define PATH_KERNEL "/boot/kernel/kernel" +#undef PATH_KERNEL #define PATH_KERNEL "/boot/kernel/kernel.gz.tramp" extern uint32_t _end; #define NOPT 6 -#define OPT_SET(opt) (1 << (opt)) -#define OPT_CHECK(opt) ((opts) & OPT_SET(opt)) - static const char optstr[NOPT] = "agnrsv"; static const unsigned char bootflags[NOPT] = { RBX_ASKNAME, Index: sys/boot/arm/ixp425/boot2/boot2.c =================================================================== --- sys/boot/arm/ixp425/boot2/boot2.c +++ sys/boot/arm/ixp425/boot2/boot2.c @@ -28,51 +28,13 @@ #include #include "lib.h" - -#define RBX_ASKNAME 0x0 /* -a */ -#define RBX_SINGLE 0x1 /* -s */ -/* 0x2 is reserved for log2(RB_NOSYNC). */ -/* 0x3 is reserved for log2(RB_HALT). */ -/* 0x4 is reserved for log2(RB_INITNAME). */ -#define RBX_DFLTROOT 0x5 /* -r */ -/* #define RBX_KDB 0x6 -d */ -/* 0x7 is reserved for log2(RB_RDONLY). */ -/* 0x8 is reserved for log2(RB_DUMP). */ -/* 0x9 is reserved for log2(RB_MINIROOT). */ -#define RBX_CONFIG 0xa /* -c */ -#define RBX_VERBOSE 0xb /* -v */ -/* #define RBX_SERIAL 0xc -h */ -/* #define RBX_CDROM 0xd -C */ -/* 0xe is reserved for log2(RB_POWEROFF). */ -#define RBX_GDB 0xf /* -g */ -/* #define RBX_MUTE 0x10 -m */ -/* 0x11 is reserved for log2(RB_SELFTEST). */ -/* 0x12 is reserved for boot programs. */ -/* 0x13 is reserved for boot programs. */ -/* #define RBX_PAUSE 0x14 -p */ -/* #define RBX_QUIET 0x15 -q */ -#define RBX_NOINTR 0x1c /* -n */ -/* 0x1d is reserved for log2(RB_MULTIPLE) and is just misnamed here. */ -/* #define RBX_DUAL 0x1d -D */ -/* 0x1f is reserved for log2(RB_BOOTINFO). */ - -/* pass: -a, -s, -r, -v, -g */ -#define RBX_MASK (OPT_SET(RBX_ASKNAME) | OPT_SET(RBX_SINGLE) | \ - OPT_SET(RBX_DFLTROOT) | \ - OPT_SET(RBX_VERBOSE) | \ - OPT_SET(RBX_GDB)) - -#define PATH_DOTCONFIG "/boot.config" -#define PATH_CONFIG "/boot/config" -#define PATH_KERNEL "/boot/kernel/kernel" +#include "paths.h" +#include "rbx.h" extern uint32_t _end; #define NOPT 6 -#define OPT_SET(opt) (1 << (opt)) -#define OPT_CHECK(opt) ((opts) & OPT_SET(opt)) - static const char optstr[NOPT] = "agnrsv"; static const unsigned char flags[NOPT] = { RBX_ASKNAME, Index: sys/boot/common/paths.h =================================================================== --- /dev/null +++ sys/boot/common/paths.h @@ -0,0 +1,39 @@ +/*- + * Copyright (c) 2016 M. Warner Losh + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS 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 AUTHORS 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. + * + * $FreeBSD$ + */ + +#ifndef _PATHS_H_ +#define _PATHS_H_ + +#define PATH_DOTCONFIG "/boot.config" +#define PATH_CONFIG "/boot/config" +#define PATH_BOOT3 "/boot/loader" +#define PATH_LOADER "/boot/loader" +#define PATH_LOADER_EFI "/boot/loader.efi" +#define PATH_KERNEL "/boot/kernel/kernel" + +#endif /* _PATHS_H_ */ Index: sys/boot/efi/boot1/boot1.c =================================================================== --- sys/boot/efi/boot1/boot1.c +++ sys/boot/efi/boot1/boot1.c @@ -31,8 +31,7 @@ #include #include "boot_module.h" - -#define _PATH_LOADER "/boot/loader.efi" +#include "paths.h" static const boot_module_t *boot_modules[] = { @@ -92,20 +91,48 @@ void try_load(const boot_module_t *mod) { - size_t bufsize; + size_t bufsize, cmdsize; void *buf; + char *cmd; dev_info_t *dev; EFI_HANDLE loaderhandle; EFI_LOADED_IMAGE *loaded_image; EFI_STATUS status; - status = mod->load(_PATH_LOADER, &dev, &buf, &bufsize); + /* + * Read in and parse the command line from /boot.config or /boot/config, + * if present. We'll pass it the next stage via a simple ASCII + * string. loader.efi has a hack for ASCII strings, so we'll use that to + * keep the size down here. We only try to read the alternate file if + * we get EFI_NOT_FOUND because all other errors mean that the boot_module + * had troubles with the filesystem. We could return early, but we'll let + * loading the actual kernel sort all that out. Since these files are + * optional, we don't report errors in trying to read them. + */ + cmd = NULL; + cmdsize = 0; + status = mod->load(PATH_DOTCONFIG, &dev, &buf, &bufsize); + if (status == EFI_NOT_FOUND) + status = mod->load(PATH_CONFIG, &dev, &buf, &bufsize); + if (status == EFI_SUCCESS) { + cmdsize = bufsize + 1; + cmd = malloc(cmdsize); + if (cmd == NULL) { + free(buf); + return; + } + memcpy(cmd, buf, bufsize); + cmd[bufsize] = '\0'; + free(buf); + } + + status = mod->load(PATH_LOADER_EFI, &dev, &buf, &bufsize); if (status == EFI_NOT_FOUND) return; if (status != EFI_SUCCESS) { - printf("%s failed to load %s (%lu)\n", mod->name, _PATH_LOADER, - EFI_ERROR_CODE(status)); + printf("%s failed to load %s (%lu)\n", mod->name, + PATH_LOADER_EFI, EFI_ERROR_CODE(status)); return; } @@ -116,6 +143,9 @@ return; } + if (cmd != NULL) + printf(" command args: %s\n", cmd); + if ((status = bs->HandleProtocol(loaderhandle, &LoadedImageGUID, (VOID**)&loaded_image)) != EFI_SUCCESS) { printf("Failed to query LoadedImage provided by %s (%lu)\n", @@ -124,11 +154,16 @@ } loaded_image->DeviceHandle = dev->devhandle; + loaded_image->LoadOptionsSize = cmdsize; + loaded_image->LoadOptions = cmd; if ((status = bs->StartImage(loaderhandle, NULL, NULL)) != EFI_SUCCESS) { printf("Failed to start image provided by %s (%lu)\n", mod->name, EFI_ERROR_CODE(status)); + free(cmd); + loaded_image->LoadOptionsSize = 0; + loaded_image->LoadOptions = NULL; return; } } @@ -174,7 +209,7 @@ conout->ClearScreen(conout); printf("\n>> FreeBSD EFI boot block\n"); - printf(" Loader path: %s\n\n", _PATH_LOADER); + printf(" Loader path: %s\n\n", PATH_LOADER_EFI); printf(" Initializing modules:"); for (i = 0; i < NUM_BOOT_MODULES; i++) { if (boot_modules[i] == NULL) Index: sys/boot/efi/libefi/libefi.c =================================================================== --- sys/boot/efi/libefi/libefi.c +++ sys/boot/efi/libefi/libefi.c @@ -44,7 +44,7 @@ arg_skipsep(CHAR16 *argp) { - while (*argp == ' ' || *argp == '\t') + while (*argp == ' ' || *argp == '\t' || *argp == '\n') argp++; return (argp); } @@ -53,7 +53,7 @@ arg_skipword(CHAR16 *argp) { - while (*argp && *argp != ' ' && *argp != '\t') + while (*argp && *argp != ' ' && *argp != '\t' && *argp != '\n') argp++; return (argp); } Index: sys/boot/efi/loader/main.c =================================================================== --- sys/boot/efi/loader/main.c +++ sys/boot/efi/loader/main.c @@ -29,6 +29,8 @@ __FBSDID("$FreeBSD$"); #include +#include +#include #include #include #include @@ -83,13 +85,22 @@ printf("%c", (char)str[i]); } +static void +cp16to8(const CHAR16 *src, char *dst, size_t len) +{ + size_t i; + + for (i = 0; i < len && src[i]; i++) + dst[i] = (char)src[i]; +} + EFI_STATUS main(int argc, CHAR16 *argv[]) { char var[128]; EFI_LOADED_IMAGE *img; EFI_GUID *guid; - int i, j, vargood, unit; + int i, j, vargood, unit, howto; struct devsw *dev; uint64_t pool_guid; UINTN k; @@ -113,27 +124,97 @@ cons_probe(); /* + * Parse the args to set the console settings, etc + * boot1.efi passes these in, if it can read /boot.config or /boot/config + * or iPXE may be setup to pass these in. + * * Loop through the args, and for each one that contains an '=' that is * not the first character, add it to the environment. This allows * loader and kernel env vars to be passed on the command line. Convert * args from UCS-2 to ASCII (16 to 8 bit) as they are copied. */ + howto = 0; for (i = 1; i < argc; i++) { - vargood = 0; - for (j = 0; argv[i][j] != 0; j++) { - if (j == sizeof(var)) { - vargood = 0; - break; + if (argv[i][0] == '-') { + for (j = 1; argv[i][j] != 0; j++) { + int ch; + + ch = argv[i][j]; + switch (ch) { + case 'a': + howto |= RB_ASKNAME; + break; + case 'd': + howto |= RB_KDB; + break; + case 'D': + howto |= RB_MULTIPLE; + break; + case 'm': + howto |= RB_MUTE; + break; + case 'h': + howto |= RB_SERIAL; + break; + case 'p': + howto |= RB_PAUSE; + break; + case 'r': + howto |= RB_DFLTROOT; + break; + case 's': + howto |= RB_SINGLE; + break; + case 'S': + if (argv[i][j + 1] == 0) { + if (i + 1 == argc) { + setenv("comconsole_speed", "115200", 1); + } else { + cp16to8(&argv[i + 1][0], var, + sizeof(var)); + setenv("comconsole_speedspeed", var, 1); + } + i++; + break; + } else { + cp16to8(&argv[i][j + 1], var, + sizeof(var)); + setenv("comconsole_speed", var, 1); + break; + } + case 'v': + howto |= RB_VERBOSE; + break; + } + } + } else { + vargood = 0; + for (j = 0; argv[i][j] != 0; j++) { + if (j == sizeof(var)) { + vargood = 0; + break; + } + if (j > 0 && argv[i][j] == '=') + vargood = 1; + var[j] = (char)argv[i][j]; + } + if (vargood) { + var[j] = 0; + putenv(var); } - if (j > 0 && argv[i][j] == '=') - vargood = 1; - var[j] = (char)argv[i][j]; - } - if (vargood) { - var[j] = 0; - putenv(var); } } + for (i = 0; howto_names[i].ev != NULL; i++) + if (howto & howto_names[i].mask) + setenv(howto_names[i].ev, "YES", 1); + if (howto & RB_MULTIPLE) { + if (howto & RB_SERIAL) + setenv("console", "comconsole efi" , 1); + else + setenv("console", "efi comconsole" , 1); + } else if (howto & RB_SERIAL) { + setenv("console", "comconsole" , 1); + } if (efi_copy_init()) { printf("failed to allocate staging area\n"); Index: sys/boot/i386/boot2/boot2.c =================================================================== --- sys/boot/i386/boot2/boot2.c +++ sys/boot/i386/boot2/boot2.c @@ -33,6 +33,8 @@ #include "boot2.h" #include "lib.h" +#include "paths.h" +#include "rbx.h" /* Define to 0 to omit serial support */ #ifndef SERIAL @@ -52,46 +54,6 @@ #define SECOND 18 /* Circa that many ticks in a second. */ -#define RBX_ASKNAME 0x0 /* -a */ -#define RBX_SINGLE 0x1 /* -s */ -/* 0x2 is reserved for log2(RB_NOSYNC). */ -/* 0x3 is reserved for log2(RB_HALT). */ -/* 0x4 is reserved for log2(RB_INITNAME). */ -#define RBX_DFLTROOT 0x5 /* -r */ -#define RBX_KDB 0x6 /* -d */ -/* 0x7 is reserved for log2(RB_RDONLY). */ -/* 0x8 is reserved for log2(RB_DUMP). */ -/* 0x9 is reserved for log2(RB_MINIROOT). */ -#define RBX_CONFIG 0xa /* -c */ -#define RBX_VERBOSE 0xb /* -v */ -#define RBX_SERIAL 0xc /* -h */ -#define RBX_CDROM 0xd /* -C */ -/* 0xe is reserved for log2(RB_POWEROFF). */ -#define RBX_GDB 0xf /* -g */ -#define RBX_MUTE 0x10 /* -m */ -/* 0x11 is reserved for log2(RB_SELFTEST). */ -/* 0x12 is reserved for boot programs. */ -/* 0x13 is reserved for boot programs. */ -#define RBX_PAUSE 0x14 /* -p */ -#define RBX_QUIET 0x15 /* -q */ -#define RBX_NOINTR 0x1c /* -n */ -/* 0x1d is reserved for log2(RB_MULTIPLE) and is just misnamed here. */ -#define RBX_DUAL 0x1d /* -D */ -/* 0x1f is reserved for log2(RB_BOOTINFO). */ - -/* pass: -a, -s, -r, -d, -c, -v, -h, -C, -g, -m, -p, -D */ -#define RBX_MASK (OPT_SET(RBX_ASKNAME) | OPT_SET(RBX_SINGLE) | \ - OPT_SET(RBX_DFLTROOT) | OPT_SET(RBX_KDB ) | \ - OPT_SET(RBX_CONFIG) | OPT_SET(RBX_VERBOSE) | \ - OPT_SET(RBX_SERIAL) | OPT_SET(RBX_CDROM) | \ - OPT_SET(RBX_GDB ) | OPT_SET(RBX_MUTE) | \ - OPT_SET(RBX_PAUSE) | OPT_SET(RBX_DUAL)) - -#define PATH_DOTCONFIG "/boot.config" -#define PATH_CONFIG "/boot/config" -#define PATH_BOOT3 "/boot/loader" -#define PATH_KERNEL "/boot/kernel/kernel" - #define ARGS 0x900 #define NOPT 14 #define NDEV 3 @@ -106,9 +68,6 @@ #define TYPE_MAXHARD TYPE_DA #define TYPE_FD 2 -#define OPT_SET(opt) (1 << (opt)) -#define OPT_CHECK(opt) ((opts) & OPT_SET(opt)) - extern uint32_t _end; static const char optstr[NOPT] = "DhaCcdgmnpqrsv"; /* Also 'P', 'S' */ @@ -143,7 +102,7 @@ } dsk; static char cmd[512], cmddup[512], knamebuf[1024]; static const char *kname; -static uint32_t opts; +uint32_t opts; static struct bootinfo bootinfo; #if SERIAL static int comspeed = SIOSPD; Index: sys/boot/i386/common/rbx.h =================================================================== --- /dev/null +++ sys/boot/i386/common/rbx.h @@ -1,61 +0,0 @@ -/*- - * Copyright (c) 1998 Robert Nordier - * All rights reserved. - * - * Redistribution and use in source and binary forms are freely - * permitted provided that the above copyright notice and this - * paragraph and the following disclaimer are duplicated in all - * such forms. - * - * This software is provided "AS IS" and without any express or - * implied warranties, including, without limitation, the implied - * warranties of merchantability and fitness for a particular - * purpose. - * - * $FreeBSD$ - */ - -#ifndef _RBX_H_ -#define _RBX_H_ - -#define RBX_ASKNAME 0x0 /* -a */ -#define RBX_SINGLE 0x1 /* -s */ -/* 0x2 is reserved for log2(RB_NOSYNC). */ -/* 0x3 is reserved for log2(RB_HALT). */ -/* 0x4 is reserved for log2(RB_INITNAME). */ -#define RBX_DFLTROOT 0x5 /* -r */ -#define RBX_KDB 0x6 /* -d */ -/* 0x7 is reserved for log2(RB_RDONLY). */ -/* 0x8 is reserved for log2(RB_DUMP). */ -/* 0x9 is reserved for log2(RB_MINIROOT). */ -#define RBX_CONFIG 0xa /* -c */ -#define RBX_VERBOSE 0xb /* -v */ -#define RBX_SERIAL 0xc /* -h */ -#define RBX_CDROM 0xd /* -C */ -/* 0xe is reserved for log2(RB_POWEROFF). */ -#define RBX_GDB 0xf /* -g */ -#define RBX_MUTE 0x10 /* -m */ -/* 0x11 is reserved for log2(RB_SELFTEST). */ -/* 0x12 is reserved for boot programs. */ -/* 0x13 is reserved for boot programs. */ -#define RBX_PAUSE 0x14 /* -p */ -#define RBX_QUIET 0x15 /* -q */ -#define RBX_NOINTR 0x1c /* -n */ -/* 0x1d is reserved for log2(RB_MULTIPLE) and is just misnamed here. */ -#define RBX_DUAL 0x1d /* -D */ -/* 0x1f is reserved for log2(RB_BOOTINFO). */ - -/* pass: -a, -s, -r, -d, -c, -v, -h, -C, -g, -m, -p, -D */ -#define RBX_MASK (OPT_SET(RBX_ASKNAME) | OPT_SET(RBX_SINGLE) | \ - OPT_SET(RBX_DFLTROOT) | OPT_SET(RBX_KDB ) | \ - OPT_SET(RBX_CONFIG) | OPT_SET(RBX_VERBOSE) | \ - OPT_SET(RBX_SERIAL) | OPT_SET(RBX_CDROM) | \ - OPT_SET(RBX_GDB ) | OPT_SET(RBX_MUTE) | \ - OPT_SET(RBX_PAUSE) | OPT_SET(RBX_DUAL)) - -#define OPT_SET(opt) (1 << (opt)) -#define OPT_CHECK(opt) ((opts) & OPT_SET(opt)) - -extern uint32_t opts; - -#endif /* !_RBX_H_ */ Index: sys/boot/i386/gptboot/gptboot.c =================================================================== --- sys/boot/i386/gptboot/gptboot.c +++ sys/boot/i386/gptboot/gptboot.c @@ -37,11 +37,7 @@ #include "util.h" #include "cons.h" #include "gpt.h" - -#define PATH_DOTCONFIG "/boot.config" -#define PATH_CONFIG "/boot/config" -#define PATH_BOOT3 "/boot/loader" -#define PATH_KERNEL "/boot/kernel/kernel" +#include "paths.h" #define ARGS 0x900 #define NOPT 14 Index: sys/boot/i386/zfsboot/zfsboot.c =================================================================== --- sys/boot/i386/zfsboot/zfsboot.c +++ sys/boot/i386/zfsboot/zfsboot.c @@ -42,14 +42,10 @@ #include "util.h" #include "cons.h" #include "bootargs.h" +#include "paths.h" #include "libzfs.h" -#define PATH_DOTCONFIG "/boot.config" -#define PATH_CONFIG "/boot/config" -#define PATH_BOOT3 "/boot/zfsloader" -#define PATH_KERNEL "/boot/kernel/kernel" - #define ARGS 0x900 #define NOPT 14 #define NDEV 3 Index: sys/boot/mips/beri/boot2/boot2.c =================================================================== --- sys/boot/mips/beri/boot2/boot2.c +++ sys/boot/mips/beri/boot2/boot2.c @@ -64,6 +64,9 @@ #include #include +#include "paths.h" +#include "rbx.h" + static int beri_argc; static const char **beri_argv, **beri_envv; static uint64_t beri_memsize; @@ -73,46 +76,6 @@ #define SECOND 1 /* Circa that many ticks in a second. */ -#define RBX_ASKNAME 0x0 /* -a */ -#define RBX_SINGLE 0x1 /* -s */ -/* 0x2 is reserved for log2(RB_NOSYNC). */ -/* 0x3 is reserved for log2(RB_HALT). */ -/* 0x4 is reserved for log2(RB_INITNAME). */ -#define RBX_DFLTROOT 0x5 /* -r */ -#define RBX_KDB 0x6 /* -d */ -/* 0x7 is reserved for log2(RB_RDONLY). */ -/* 0x8 is reserved for log2(RB_DUMP). */ -/* 0x9 is reserved for log2(RB_MINIROOT). */ -#define RBX_CONFIG 0xa /* -c */ -#define RBX_VERBOSE 0xb /* -v */ -#define RBX_SERIAL 0xc /* -h */ -#define RBX_CDROM 0xd /* -C */ -/* 0xe is reserved for log2(RB_POWEROFF). */ -#define RBX_GDB 0xf /* -g */ -#define RBX_MUTE 0x10 /* -m */ -/* 0x11 is reserved for log2(RB_SELFTEST). */ -/* 0x12 is reserved for boot programs. */ -/* 0x13 is reserved for boot programs. */ -#define RBX_PAUSE 0x14 /* -p */ -#define RBX_QUIET 0x15 /* -q */ -#define RBX_NOINTR 0x1c /* -n */ -/* 0x1d is reserved for log2(RB_MULTIPLE) and is just misnamed here. */ -#define RBX_DUAL 0x1d /* -D */ -/* 0x1f is reserved for log2(RB_BOOTINFO). */ - -/* pass: -a, -s, -r, -d, -c, -v, -h, -C, -g, -m, -p, -D */ -#define RBX_MASK (OPT_SET(RBX_ASKNAME) | OPT_SET(RBX_SINGLE) | \ - OPT_SET(RBX_DFLTROOT) | OPT_SET(RBX_KDB ) | \ - OPT_SET(RBX_CONFIG) | OPT_SET(RBX_VERBOSE) | \ - OPT_SET(RBX_SERIAL) | OPT_SET(RBX_CDROM) | \ - OPT_SET(RBX_GDB ) | OPT_SET(RBX_MUTE) | \ - OPT_SET(RBX_PAUSE) | OPT_SET(RBX_DUAL)) - -#define PATH_DOTCONFIG "/boot.config" -#define PATH_CONFIG "/boot/config" -#define PATH_BOOT3 "/boot/loader" -#define PATH_KERNEL "/boot/kernel/kernel" - #define ARGS 0x900 #define NOPT 14 #define MEM_BASE 0x12 @@ -131,9 +94,6 @@ /* Hard-coded assumption about location of JTAG-loaded kernel. */ #define DRAM_KERNEL_ADDR ((void *)mips_phys_to_cached(0x20000)) -#define OPT_SET(opt) (1 << (opt)) -#define OPT_CHECK(opt) ((opts) & OPT_SET(opt)) - extern uint32_t _end; static const char optstr[NOPT] = "DhaCcdgmnpqrsv"; /* Also 'P', 'S' */ Index: sys/boot/pc98/boot2/boot2.c =================================================================== --- sys/boot/pc98/boot2/boot2.c +++ sys/boot/pc98/boot2/boot2.c @@ -35,6 +35,8 @@ #include "boot2.h" #include "lib.h" +#include "paths.h" +#include "rbx.h" /* Define to 0 to omit serial support */ #ifndef SERIAL @@ -54,46 +56,6 @@ #define SECOND 1 /* Circa that many ticks in a second. */ -#define RBX_ASKNAME 0x0 /* -a */ -#define RBX_SINGLE 0x1 /* -s */ -/* 0x2 is reserved for log2(RB_NOSYNC). */ -/* 0x3 is reserved for log2(RB_HALT). */ -/* 0x4 is reserved for log2(RB_INITNAME). */ -#define RBX_DFLTROOT 0x5 /* -r */ -#define RBX_KDB 0x6 /* -d */ -/* 0x7 is reserved for log2(RB_RDONLY). */ -/* 0x8 is reserved for log2(RB_DUMP). */ -/* 0x9 is reserved for log2(RB_MINIROOT). */ -#define RBX_CONFIG 0xa /* -c */ -#define RBX_VERBOSE 0xb /* -v */ -#define RBX_SERIAL 0xc /* -h */ -#define RBX_CDROM 0xd /* -C */ -/* 0xe is reserved for log2(RB_POWEROFF). */ -#define RBX_GDB 0xf /* -g */ -#define RBX_MUTE 0x10 /* -m */ -/* 0x11 is reserved for log2(RB_SELFTEST). */ -/* 0x12 is reserved for boot programs. */ -/* 0x13 is reserved for boot programs. */ -#define RBX_PAUSE 0x14 /* -p */ -#define RBX_QUIET 0x15 /* -q */ -#define RBX_NOINTR 0x1c /* -n */ -/* 0x1d is reserved for log2(RB_MULTIPLE) and is just misnamed here. */ -#define RBX_DUAL 0x1d /* -D */ -/* 0x1f is reserved for log2(RB_BOOTINFO). */ - -/* pass: -a, -s, -r, -d, -c, -v, -h, -C, -g, -m, -p, -D */ -#define RBX_MASK (OPT_SET(RBX_ASKNAME) | OPT_SET(RBX_SINGLE) | \ - OPT_SET(RBX_DFLTROOT) | OPT_SET(RBX_KDB ) | \ - OPT_SET(RBX_CONFIG) | OPT_SET(RBX_VERBOSE) | \ - OPT_SET(RBX_SERIAL) | OPT_SET(RBX_CDROM) | \ - OPT_SET(RBX_GDB ) | OPT_SET(RBX_MUTE) | \ - OPT_SET(RBX_PAUSE) | OPT_SET(RBX_DUAL)) - -#define PATH_DOTCONFIG "/boot.config" -#define PATH_CONFIG "/boot/config" -#define PATH_BOOT3 "/boot/loader" -#define PATH_KERNEL "/boot/kernel/kernel" - #define ARGS 0x900 #define NOPT 14 #define NDEV 3 @@ -105,9 +67,6 @@ #define TYPE_DA 1 #define TYPE_FD 2 -#define OPT_SET(opt) (1 << (opt)) -#define OPT_CHECK(opt) ((opts) & OPT_SET(opt)) - extern uint32_t _end; static const char optstr[NOPT] = "DhaCcdgmnpqrsv"; /* Also 'P', 'S' */ Index: sys/boot/powerpc/boot1.chrp/boot1.c =================================================================== --- sys/boot/powerpc/boot1.chrp/boot1.c +++ sys/boot/powerpc/boot1.chrp/boot1.c @@ -23,8 +23,7 @@ #include #include -#define _PATH_LOADER "/boot/loader" -#define _PATH_KERNEL "/boot/kernel/kernel" +#include "paths.h" #define BSIZEMAX 16384 @@ -396,7 +395,7 @@ char bootpath_full[255]; int i, len; - path = _PATH_LOADER; + path = PATH_LOADER; for (i = 0; i < ac; i++) { switch (av[i][0]) { case '-': Index: sys/boot/sparc64/boot1/boot1.c =================================================================== --- sys/boot/sparc64/boot1/boot1.c +++ sys/boot/sparc64/boot1/boot1.c @@ -24,8 +24,8 @@ #include #include -#define _PATH_LOADER "/boot/loader" -#define _PATH_KERNEL "/boot/kernel/kernel" +#include "paths.h" + #define READ_BUF_SIZE 8192 typedef int putc_func_t(char c, void *arg); @@ -324,7 +324,7 @@ const char *path; int i; - path = _PATH_LOADER; + path = PATH_LOADER; for (i = 0; i < ac; i++) { switch (av[i][0]) { case '-': Index: sys/dev/hyperv/netvsc/hv_net_vsc.h =================================================================== --- sys/dev/hyperv/netvsc/hv_net_vsc.h +++ sys/dev/hyperv/netvsc/hv_net_vsc.h @@ -39,9 +39,11 @@ #define __HV_NET_VSC_H__ #include +#include #include #include #include +#include #include #include @@ -1008,7 +1010,6 @@ struct hv_device *hn_dev_obj; netvsc_dev *net_dev; - int hn_txdesc_cnt; struct hn_txdesc *hn_txdesc; bus_dma_tag_t hn_tx_data_dtag; bus_dma_tag_t hn_tx_rndis_dtag; @@ -1017,9 +1018,15 @@ struct mtx hn_txlist_spin; struct hn_txdesc_list hn_txlist; + int hn_txdesc_cnt; int hn_txdesc_avail; int hn_txeof; + int hn_direct_tx_size; + struct taskqueue *hn_tx_taskq; + struct task hn_start_task; + struct task hn_txeof_task; + struct lro_ctrl hn_lro; int hn_lro_hiwat; Index: sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c =================================================================== --- sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c +++ sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c @@ -146,6 +146,8 @@ #define HN_TX_DATA_SEGCNT_MAX \ (NETVSC_PACKET_MAXPAGE - HV_RF_NUM_TX_RESERVED_PAGE_BUFS) +#define HN_DIRECT_TX_SIZE_DEF 128 + struct hn_txdesc { SLIST_ENTRY(hn_txdesc) link; struct mbuf *m; @@ -194,6 +196,7 @@ #define NV_LOCK_INIT(_sc, _name) \ mtx_init(&(_sc)->hn_lock, _name, MTX_NETWORK_LOCK, MTX_DEF) #define NV_LOCK(_sc) mtx_lock(&(_sc)->hn_lock) +#define NV_TRYLOCK(_sc) mtx_trylock(&(_sc)->hn_lock) #define NV_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->hn_lock, MA_OWNED) #define NV_UNLOCK(_sc) mtx_unlock(&(_sc)->hn_lock) #define NV_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->hn_lock) @@ -219,6 +222,10 @@ static int hn_tx_chimney_size = 0; TUNABLE_INT("dev.hn.tx_chimney_size", &hn_tx_chimney_size); +/* Limit the size of packet for direct transmission */ +static int hn_direct_tx_size = HN_DIRECT_TX_SIZE_DEF; +TUNABLE_INT("dev.hn.direct_tx_size", &hn_direct_tx_size); + /* * Forward declarations */ @@ -226,8 +233,9 @@ static void hn_ifinit_locked(hn_softc_t *sc); static void hn_ifinit(void *xsc); static int hn_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data); -static void hn_start_locked(struct ifnet *ifp); +static int hn_start_locked(struct ifnet *ifp, int len); static void hn_start(struct ifnet *ifp); +static void hn_start_txeof(struct ifnet *ifp); static int hn_ifmedia_upd(struct ifnet *ifp); static void hn_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr); #ifdef HN_LRO_HIWAT @@ -237,6 +245,8 @@ static int hn_check_iplen(const struct mbuf *, int); static int hn_create_tx_ring(struct hn_softc *sc); static void hn_destroy_tx_ring(struct hn_softc *sc); +static void hn_start_taskfunc(void *xsc, int pending); +static void hn_txeof_taskfunc(void *xsc, int pending); static __inline void hn_set_lro_hiwat(struct hn_softc *sc, int hiwat) @@ -384,6 +394,14 @@ sc->hn_dev = dev; sc->hn_lro_hiwat = HN_LRO_HIWAT_DEF; sc->hn_trust_hosttcp = hn_trust_hosttcp; + sc->hn_direct_tx_size = hn_direct_tx_size; + + sc->hn_tx_taskq = taskqueue_create_fast("hn_tx", M_WAITOK, + taskqueue_thread_enqueue, &sc->hn_tx_taskq); + taskqueue_start_threads(&sc->hn_tx_taskq, 1, PI_NET, "%s tx", + device_get_nameunit(dev)); + TASK_INIT(&sc->hn_start_task, 0, hn_start_taskfunc, sc); + TASK_INIT(&sc->hn_txeof_task, 0, hn_txeof_taskfunc, sc); error = hn_create_tx_ring(sc); if (error) @@ -524,6 +542,9 @@ SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "tx_chimney_size", CTLTYPE_INT | CTLFLAG_RW, sc, 0, hn_tx_chimney_size_sysctl, "I", "Chimney send packet size limit"); + SYSCTL_ADD_INT(ctx, child, OID_AUTO, "direct_tx_size", + CTLFLAG_RW, &sc->hn_direct_tx_size, 0, + "Size of the packet for direct transmission"); if (unit == 0) { struct sysctl_ctx_list *dc_ctx; @@ -548,6 +569,9 @@ SYSCTL_ADD_INT(dc_ctx, dc_child, OID_AUTO, "tso_maxlen", CTLFLAG_RD, &hn_tso_maxlen, 0, "TSO burst limit"); #endif + SYSCTL_ADD_INT(dc_ctx, dc_child, OID_AUTO, "direct_tx_size", + CTLFLAG_RD, &hn_direct_tx_size, 0, + "Size of the packet for direct transmission"); } return (0); @@ -583,6 +607,10 @@ hv_rf_on_device_remove(hv_device, HV_RF_NV_DESTROY_CHANNEL); + taskqueue_drain(sc->hn_tx_taskq, &sc->hn_start_task); + taskqueue_drain(sc->hn_tx_taskq, &sc->hn_txeof_task); + taskqueue_free(sc->hn_tx_taskq); + ifmedia_removeall(&sc->hn_media); #if defined(INET) || defined(INET6) tcp_lro_free(&sc->hn_lro); @@ -733,24 +761,19 @@ netvsc_channel_rollup(struct hv_device *device_ctx) { struct hn_softc *sc = device_get_softc(device_ctx->device); - struct ifnet *ifp; if (!sc->hn_txeof) return; sc->hn_txeof = 0; - ifp = sc->hn_ifp; - NV_LOCK(sc); - ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; - hn_start_locked(ifp); - NV_UNLOCK(sc); + hn_start_txeof(sc->hn_ifp); } /* * Start a transmit of one or more packets */ -static void -hn_start_locked(struct ifnet *ifp) +static int +hn_start_locked(struct ifnet *ifp, int len) { hn_softc_t *sc = ifp->if_softc; struct hv_device *device_ctx = vmbus_get_devctx(sc->hn_dev); @@ -768,7 +791,7 @@ if ((ifp->if_drv_flags & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) != IFF_DRV_RUNNING) - return; + return 0; while (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) { bus_dma_segment_t segs[HN_TX_DATA_SEGCNT_MAX]; @@ -781,11 +804,21 @@ if (m_head == NULL) break; + if (len > 0 && m_head->m_pkthdr.len > len) { + /* + * This sending could be time consuming; let callers + * dispatch this packet sending (and sending of any + * following up packets) to tx taskqueue. + */ + IF_PREPEND(&ifp->if_snd, m_head); + return 1; + } + txd = hn_txdesc_get(sc); if (txd == NULL) { sc->hn_no_txdescs++; IF_PREPEND(&ifp->if_snd, m_head); - ifp->if_drv_flags |= IFF_DRV_OACTIVE; + atomic_set_int(&ifp->if_drv_flags, IFF_DRV_OACTIVE); break; } @@ -1060,10 +1093,11 @@ sc->hn_send_failed++; IF_PREPEND(&ifp->if_snd, m_head); - ifp->if_drv_flags |= IFF_DRV_OACTIVE; + atomic_set_int(&ifp->if_drv_flags, IFF_DRV_OACTIVE); break; } } + return 0; } /* @@ -1555,7 +1589,8 @@ if (bootverbose) printf(" Closing Device ...\n"); - ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE); + atomic_clear_int(&ifp->if_drv_flags, + (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)); if_link_state_change(ifp, LINK_STATE_DOWN); sc->hn_initdone = 0; @@ -1571,13 +1606,43 @@ hn_softc_t *sc; sc = ifp->if_softc; - NV_LOCK(sc); - if (sc->temp_unusable) { + if (NV_TRYLOCK(sc)) { + int sched; + + sched = hn_start_locked(ifp, sc->hn_direct_tx_size); NV_UNLOCK(sc); - return; + if (!sched) + return; + } + taskqueue_enqueue_fast(sc->hn_tx_taskq, &sc->hn_start_task); +} + +static void +hn_start_txeof(struct ifnet *ifp) +{ + hn_softc_t *sc; + + sc = ifp->if_softc; + if (NV_TRYLOCK(sc)) { + int sched; + + atomic_clear_int(&ifp->if_drv_flags, IFF_DRV_OACTIVE); + sched = hn_start_locked(ifp, sc->hn_direct_tx_size); + NV_UNLOCK(sc); + if (sched) { + taskqueue_enqueue_fast(sc->hn_tx_taskq, + &sc->hn_start_task); + } + } else { + /* + * Release the OACTIVE earlier, with the hope, that + * others could catch up. The task will clear the + * flag again with the NV_LOCK to avoid possible + * races. + */ + atomic_clear_int(&ifp->if_drv_flags, IFF_DRV_OACTIVE); + taskqueue_enqueue_fast(sc->hn_tx_taskq, &sc->hn_txeof_task); } - hn_start_locked(ifp); - NV_UNLOCK(sc); } /* @@ -1604,8 +1669,8 @@ } else { sc->hn_initdone = 1; } - ifp->if_drv_flags |= IFF_DRV_RUNNING; - ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; + atomic_clear_int(&ifp->if_drv_flags, IFF_DRV_OACTIVE); + atomic_set_int(&ifp->if_drv_flags, IFF_DRV_RUNNING); if_link_state_change(ifp, LINK_STATE_UP); } @@ -1907,6 +1972,28 @@ mtx_destroy(&sc->hn_txlist_spin); } +static void +hn_start_taskfunc(void *xsc, int pending __unused) +{ + struct hn_softc *sc = xsc; + + NV_LOCK(sc); + hn_start_locked(sc->hn_ifp, 0); + NV_UNLOCK(sc); +} + +static void +hn_txeof_taskfunc(void *xsc, int pending __unused) +{ + struct hn_softc *sc = xsc; + struct ifnet *ifp = sc->hn_ifp; + + NV_LOCK(sc); + atomic_clear_int(&ifp->if_drv_flags, IFF_DRV_OACTIVE); + hn_start_locked(ifp, 0); + NV_UNLOCK(sc); +} + static device_method_t netvsc_methods[] = { /* Device interface */ DEVMETHOD(device_probe, netvsc_probe), Index: sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c =================================================================== --- sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c +++ sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c @@ -69,13 +69,12 @@ static hv_setup_args setup_args; /* only CPU 0 supported at this time */ static char *vmbus_ids[] = { "VMBUS", NULL }; - /** * @brief Software interrupt thread routine to handle channel messages from * the hypervisor. */ static void -vmbus_msg_swintr(void *arg) +vmbus_msg_swintr(void *arg, int pending) { int cpu; void* page_addr; @@ -219,7 +218,7 @@ } if (msg->header.message_type != HV_MESSAGE_TYPE_NONE) { - swi_sched(hv_vmbus_g_context.msg_swintr[cpu], 0); + taskqueue_enqueue_fast(hv_vmbus_g_context.hv_msg_queue[cpu], &hv_vmbus_g_context.hv_msg_task[cpu]); } return (FILTER_HANDLED); @@ -510,9 +509,7 @@ CPU_FOREACH(j) { hv_vmbus_swintr_event_cpu[j] = 0; hv_vmbus_g_context.hv_event_intr_event[j] = NULL; - hv_vmbus_g_context.hv_msg_intr_event[j] = NULL; hv_vmbus_g_context.event_swintr[j] = NULL; - hv_vmbus_g_context.msg_swintr[j] = NULL; snprintf(buf, sizeof(buf), "cpu%d:hyperv", j); intrcnt_add(buf, &hv_vmbus_intr_cpu[j]); @@ -525,45 +522,43 @@ * Per cpu setup. */ CPU_FOREACH(j) { - /* - * Setup software interrupt thread and handler for msg handling. - */ - ret = swi_add(&hv_vmbus_g_context.hv_msg_intr_event[j], - "hv_msg", vmbus_msg_swintr, (void *)(long)j, SWI_CLOCK, 0, - &hv_vmbus_g_context.msg_swintr[j]); - if (ret) { + hv_vmbus_g_context.hv_msg_queue[j] = taskqueue_create_fast("hyperv msg", + M_WAITOK, taskqueue_thread_enqueue, &hv_vmbus_g_context.hv_msg_queue[j]); + if (hv_vmbus_g_context.hv_msg_queue[j] == NULL) { if(bootverbose) - printf("VMBUS: failed to setup msg swi for " - "cpu %d\n", j); + printf("VMBUS: failed to create message task queue for " + "cpu %d\n", j); goto cleanup1; } - - /* - * Bind the swi thread to the cpu. - */ - ret = intr_event_bind(hv_vmbus_g_context.hv_msg_intr_event[j], - j); - if (ret) { + if (taskqueue_start_threads(&hv_vmbus_g_context.hv_msg_queue[j], 1, + PI_DISK, "hvmsg%d", j) != 0) { if(bootverbose) - printf("VMBUS: failed to bind msg swi thread " - "to cpu %d\n", j); + printf("VMBUS: fail to start message task queue for " + "cpu %d\n", j); goto cleanup1; } - + TASK_INIT(&hv_vmbus_g_context.hv_msg_task[j], 0, vmbus_msg_swintr, (void *)(long)j); /* * Setup software interrupt thread and handler for * event handling. */ ret = swi_add(&hv_vmbus_g_context.hv_event_intr_event[j], "hv_event", hv_vmbus_on_events, (void *)(long)j, - SWI_CLOCK, 0, &hv_vmbus_g_context.event_swintr[j]); + SWI_NET, INTR_MPSAFE, &hv_vmbus_g_context.event_swintr[j]); if (ret) { if(bootverbose) printf("VMBUS: failed to setup event swi for " "cpu %d\n", j); goto cleanup1; } - + ret = intr_event_bind(hv_vmbus_g_context.hv_event_intr_event[j], + j); + if (ret) { + if(bootverbose) + printf("VMBUS: failed to bind event swi thread " + "to cpu %d\n", j); + goto cleanup1; + } /* * Prepare the per cpu msg and event pages to be called on each cpu. */ @@ -607,11 +602,12 @@ * remove swi and vmbus callback vector; */ CPU_FOREACH(j) { - if (hv_vmbus_g_context.msg_swintr[j] != NULL) - swi_remove(hv_vmbus_g_context.msg_swintr[j]); if (hv_vmbus_g_context.event_swintr[j] != NULL) swi_remove(hv_vmbus_g_context.event_swintr[j]); - hv_vmbus_g_context.hv_msg_intr_event[j] = NULL; + if (hv_vmbus_g_context.hv_msg_queue[j] != NULL) { + taskqueue_free(hv_vmbus_g_context.hv_msg_queue[j]); + hv_vmbus_g_context.hv_msg_queue[j] = NULL; + } hv_vmbus_g_context.hv_event_intr_event[j] = NULL; } @@ -677,11 +673,12 @@ /* remove swi */ CPU_FOREACH(i) { - if (hv_vmbus_g_context.msg_swintr[i] != NULL) - swi_remove(hv_vmbus_g_context.msg_swintr[i]); if (hv_vmbus_g_context.event_swintr[i] != NULL) swi_remove(hv_vmbus_g_context.event_swintr[i]); - hv_vmbus_g_context.hv_msg_intr_event[i] = NULL; + if (hv_vmbus_g_context.hv_msg_queue[i] != NULL) { + taskqueue_free(hv_vmbus_g_context.hv_msg_queue[i]); + hv_vmbus_g_context.hv_msg_queue[i] = NULL; + } hv_vmbus_g_context.hv_event_intr_event[i] = NULL; } Index: sys/dev/hyperv/vmbus/hv_vmbus_priv.h =================================================================== --- sys/dev/hyperv/vmbus/hv_vmbus_priv.h +++ sys/dev/hyperv/vmbus/hv_vmbus_priv.h @@ -203,9 +203,9 @@ * event and msg handling. */ struct intr_event *hv_event_intr_event[MAXCPU]; - struct intr_event *hv_msg_intr_event[MAXCPU]; + struct taskqueue *hv_msg_queue[MAXCPU]; + struct task hv_msg_task[MAXCPU]; void *event_swintr[MAXCPU]; - void *msg_swintr[MAXCPU]; /* * Host use this vector to intrrupt guest for vmbus channel * event and msg. Index: sys/kern/tty.c =================================================================== --- sys/kern/tty.c +++ sys/kern/tty.c @@ -126,7 +126,7 @@ tty_drain(struct tty *tp, int leaving) { size_t bytesused; - int error, revokecnt; + int error; if (ttyhook_hashook(tp, getc_inject)) /* buffer is inaccessible */ @@ -141,18 +141,10 @@ /* Wait for data to be drained. */ if (leaving) { - revokecnt = tp->t_revokecnt; error = tty_timedwait(tp, &tp->t_outwait, hz); - switch (error) { - case ERESTART: - if (revokecnt != tp->t_revokecnt) - error = 0; - break; - case EWOULDBLOCK: - if (ttyoutq_bytesused(&tp->t_outq) < bytesused) - error = 0; - break; - } + if (error == EWOULDBLOCK && + ttyoutq_bytesused(&tp->t_outq) < bytesused) + error = 0; } else error = tty_wait(tp, &tp->t_outwait); @@ -356,6 +348,10 @@ return (0); } + /* If revoking, flush output now to avoid draining it later. */ + if (fflag & FREVOKE) + tty_flush(tp, FWRITE); + /* * This can only be called once. The callin and the callout * devices cannot be opened at the same time. @@ -1460,13 +1456,16 @@ tp->t_flags &= ~TF_HIWAT_OUT; ttyoutq_flush(&tp->t_outq); tty_wakeup(tp, FWRITE); - ttydevsw_pktnotify(tp, TIOCPKT_FLUSHWRITE); + if (!tty_gone(tp)) + ttydevsw_pktnotify(tp, TIOCPKT_FLUSHWRITE); } if (flags & FREAD) { tty_hiwat_in_unblock(tp); ttyinq_flush(&tp->t_inq); - ttydevsw_inwakeup(tp); - ttydevsw_pktnotify(tp, TIOCPKT_FLUSHREAD); + if (!tty_gone(tp)) { + ttydevsw_inwakeup(tp); + ttydevsw_pktnotify(tp, TIOCPKT_FLUSHREAD); + } } } Index: tools/tools/nanobsd/embedded/qemu-amd64.cfg =================================================================== --- tools/tools/nanobsd/embedded/qemu-amd64.cfg +++ tools/tools/nanobsd/embedded/qemu-amd64.cfg @@ -29,6 +29,6 @@ NANO_ARCH=amd64 NANO_NAME=qemu-amd64 -qemu_env +. common # Pull in common definitions -. common # Pull in common definitions, keep last +qemu_env Index: tools/tools/nanobsd/embedded/qemu-i386.cfg =================================================================== --- tools/tools/nanobsd/embedded/qemu-i386.cfg +++ tools/tools/nanobsd/embedded/qemu-i386.cfg @@ -29,6 +29,6 @@ NANO_ARCH=i386 NANO_NAME=qemu-i386 -qemu_env +. common # Pull in common definitions -. common # Pull in common definitions, keep last +qemu_env Index: tools/tools/nanobsd/embedded/qemu-mips.cfg =================================================================== --- tools/tools/nanobsd/embedded/qemu-mips.cfg +++ tools/tools/nanobsd/embedded/qemu-mips.cfg @@ -31,6 +31,6 @@ NANO_DRIVE=ada0 NANO_NAME=qemu-mips -qemu_env +. common # Pull in common definitions -. common # Pull in common definitions, keep last +qemu_env Index: tools/tools/nanobsd/embedded/qemu-mips64.cfg =================================================================== --- tools/tools/nanobsd/embedded/qemu-mips64.cfg +++ tools/tools/nanobsd/embedded/qemu-mips64.cfg @@ -31,6 +31,6 @@ NANO_DRIVE=ada0 NANO_NAME=qemu-mips64 -qemu_env +. common # Pull in common definitions -. common # Pull in common definitions, keep last +qemu_env Index: tools/tools/nanobsd/embedded/qemu-powerpc.cfg =================================================================== --- tools/tools/nanobsd/embedded/qemu-powerpc.cfg +++ tools/tools/nanobsd/embedded/qemu-powerpc.cfg @@ -32,6 +32,6 @@ NANO_DRIVE=ada0 NANO_NAME=qemu-powerpc -qemu_env +. common # Pull in common definitions -. common # Pull in common definitions, keep last +qemu_env Index: tools/tools/nanobsd/embedded/qemu-powerpc64.cfg =================================================================== --- tools/tools/nanobsd/embedded/qemu-powerpc64.cfg +++ tools/tools/nanobsd/embedded/qemu-powerpc64.cfg @@ -31,6 +31,6 @@ NANO_DRIVE=ada0 NANO_NAME=qemu-powerpc64 -NANO_DISKIMAGE_FORMAT=qcow2 +. common # Pull in common definitions -. common # Pull in common definitions, keep last +qemu_env Index: tools/tools/nanobsd/embedded/qemu-sparc64.cfg =================================================================== --- tools/tools/nanobsd/embedded/qemu-sparc64.cfg +++ tools/tools/nanobsd/embedded/qemu-sparc64.cfg @@ -31,6 +31,6 @@ NANO_DRIVE=ada0 NANO_NAME=qemu-sparc64 -qemu_env +. common # Pull in common definitions -. common # Pull in common definitions, keep last +qemu_env Index: usr.sbin/bhyve/block_if.c =================================================================== --- usr.sbin/bhyve/block_if.c +++ usr.sbin/bhyve/block_if.c @@ -692,9 +692,7 @@ blockif_close(struct blockif_ctxt *bc) { void *jval; - int err, i; - - err = 0; + int i; assert(bc->bc_magic == BLOCKIF_SIG); Index: usr.sbin/bhyve/pci_ahci.c =================================================================== --- usr.sbin/bhyve/pci_ahci.c +++ usr.sbin/bhyve/pci_ahci.c @@ -1201,10 +1201,9 @@ { int msf, size; uint64_t sectors; - uint8_t start_track, *bp, buf[50]; + uint8_t *bp, buf[50]; msf = (acmd[1] >> 1) & 1; - start_track = acmd[6]; bp = buf + 2; *bp++ = 1; *bp++ = 1; @@ -1312,13 +1311,11 @@ struct ahci_cmd_hdr *hdr; struct ahci_prdt_entry *prdt; struct blockif_req *breq; - struct pci_ahci_softc *sc; uint8_t *acmd; uint64_t lba; uint32_t len; int err; - sc = p->pr_sc; acmd = cfis + 0x40; hdr = (struct ahci_cmd_hdr *)(p->cmd_lst + slot * AHCI_CL_SIZE); prdt = (struct ahci_prdt_entry *)(cfis + 0x80);