]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/log
FreeBSD/stable/10.git
7 years agoMFC r301607
arybchik [Fri, 17 Jun 2016 09:07:27 +0000 (09:07 +0000)]
MFC r301607

sfxge(4): host byte order is required for IP ID in TSO descriptors

Submitted by:   Artem V. Andreev <Artem.Andreev at oktetlabs.ru>
Sponsored by:   Solarflare Communications, Inc.

git-svn-id: svn://svn.freebsd.org/base/stable/10@301989 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r301604
arybchik [Fri, 17 Jun 2016 09:06:30 +0000 (09:06 +0000)]
MFC r301604

sfxge(4): cleanup: add missing probes to ef10_nvram_segment_write_tlv

Submitted by:   Andy Moreton <amoreton at solarflare.com>
Sponsored by:   Solarflare Communications, Inc.

git-svn-id: svn://svn.freebsd.org/base/stable/10@301988 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r301495
arybchik [Fri, 17 Jun 2016 09:05:26 +0000 (09:05 +0000)]
MFC r301495

sfxge(4): update TX vFIFO ULL tag location to avoid merge conflict

Sponsored by:   Solarflare Communications, Inc.

git-svn-id: svn://svn.freebsd.org/base/stable/10@301987 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r301427
arybchik [Fri, 17 Jun 2016 09:04:06 +0000 (09:04 +0000)]
MFC r301427

sfxge(4): allow firmware to auto-configure event queues on Medford

On Medford, licenses are required to enable RX and event cut through and to
disable RX batching. To avoid the need for the driver to make decisions based on
the licensing state, the MC_CMD_INIT_EVQ has been extended to allow us to leave
the decision to the firmware. If the adapter is licensed for low-latency use,
the firmware will choose the optimal settings for latency, otherwise it will use
the best settings for throughput.

For Huntington we still need to choose the settings ourselves.

Submitted by:   Mark Spender <mspender at solarflare.com>
Sponsored by:   Solarflare Communications, Inc.
Differential Revision:  https://reviews.freebsd.org/D6717

git-svn-id: svn://svn.freebsd.org/base/stable/10@301986 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r301309
arybchik [Fri, 17 Jun 2016 09:02:51 +0000 (09:02 +0000)]
MFC r301309

sfxge(4): always be ready to receive batched events

When the low-latency firmware variant is running, it is reported as not
being capable of batching RX events, but it can still do so if the
FORCE_EV_MERGING flag is set on an RXQ.  Therefore we need to handle
batched RX events even if the capability isn't set.

If this bug is fixed in the firmware such that the capability is set
even when running the low-latency firmware variant, it will almost
always be reported so I don't think we lose much by removing the check.

Submitted by:   Mark Spender <mspender at solarflare.com>
Sponsored by:   Solarflare Communications, Inc.
Differential Revision:  https://reviews.freebsd.org/D6705

git-svn-id: svn://svn.freebsd.org/base/stable/10@301985 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r301308
arybchik [Fri, 17 Jun 2016 09:01:11 +0000 (09:01 +0000)]
MFC r301308

sfxge(4): add helper to compute timer quantum

This also adjusts the timer values used to match the Linux net
driver implementation:
a) non-zero time intervals should result in at least one quantum
b) timer load/reload values are only zero biased for Falcon/Siena

Submitted by:   Andy Moreton <amoreton at solarflare.com>
Sponsored by:   Solarflare Communications, Inc.
Differential Revision:  https://reviews.freebsd.org/D6704

git-svn-id: svn://svn.freebsd.org/base/stable/10@301984 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r301237
arybchik [Fri, 17 Jun 2016 08:59:08 +0000 (08:59 +0000)]
MFC r301237

sfxge(4): support EVQ timer workaround via MCDI

Submitted by:   Andy Moreton <amoreton at solarflare.com>
Sponsored by:   Solarflare Communications, Inc.
Differential Revision:  https://reviews.freebsd.org/6675

git-svn-id: svn://svn.freebsd.org/base/stable/10@301983 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r301127
arybchik [Fri, 17 Jun 2016 08:57:52 +0000 (08:57 +0000)]
MFC r301127

sfxge(4): cleanup: remove unused variables in common code

Submitted by:   Andy Moreton <amoreton at solarflare.com>
Sponsored by:   Solarflare Communications, Inc.

git-svn-id: svn://svn.freebsd.org/base/stable/10@301982 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r301125
arybchik [Fri, 17 Jun 2016 08:56:47 +0000 (08:56 +0000)]
MFC r301125

sfxge(4): cleanup: add missing space after if keyword

Sponsored by:   Solarflare Communications, Inc.

git-svn-id: svn://svn.freebsd.org/base/stable/10@301981 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r301122
arybchik [Fri, 17 Jun 2016 08:56:01 +0000 (08:56 +0000)]
MFC r301122

sfxge(4): set moderation in efx_ev_qcreate

This simplifies setting an initial interrupt moderation value, and
avoids most calls to evx_ev_qmoderate from contexts where MCDI is
not allowed (MCDI is need for an EVQ timer workaround in a later patch).

Submitted by:   Andy Moreton <amoreton at solarflare.com>
Reviewed by:    gnn
Sponsored by:   Solarflare Communications, Inc.
Differential Revision:  https://reviews.freebsd.org/D6673

git-svn-id: svn://svn.freebsd.org/base/stable/10@301980 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r301061
arybchik [Fri, 17 Jun 2016 08:54:43 +0000 (08:54 +0000)]
MFC r301061

sfxge(4): regenerate MCDI headers from firmwaresrc .yml

Sponsored by:   Solarflare Communications, Inc.

git-svn-id: svn://svn.freebsd.org/base/stable/10@301979 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r301773 & r301775:
cy [Fri, 17 Jun 2016 02:48:57 +0000 (02:48 +0000)]
MFC r301773 & r301775:

Clarify the wording to be more accurate.

git-svn-id: svn://svn.freebsd.org/base/stable/10@301978 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r301291:
pfg [Fri, 17 Jun 2016 02:29:55 +0000 (02:29 +0000)]
MFC r301291:
libiberty: prevent integer overflow.

Take care of very old bug leading to heap-buffer overflow by
processing certain file headers via bfd binary.

PR: 200888
Obtained from: OpenBSD

git-svn-id: svn://svn.freebsd.org/base/stable/10@301976 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC 298039,298042
sephe [Thu, 16 Jun 2016 06:34:12 +0000 (06:34 +0000)]
MFC 298039,298042

298039
    hyperv/vmbus: Put multi-channel offer logging under bootverbose

    Suggested by:       Dexuan Cui <decui microsoft com>
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC

298042
    hyperv/hn: Hide ring to channel linkage message under bootverbose

    Suggested by:       Dexuan Cui <decui microsoft com>
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC

git-svn-id: svn://svn.freebsd.org/base/stable/10@301954 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agohyperv/hn: ifnet TSO configuration is available on 10-stable.
sephe [Thu, 16 Jun 2016 06:26:09 +0000 (06:26 +0000)]
hyperv/hn: ifnet TSO configuration is available on 10-stable.

Sponsored by: Microsoft OSTC

git-svn-id: svn://svn.freebsd.org/base/stable/10@301953 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC 297809,297810,297811
sephe [Thu, 16 Jun 2016 05:24:00 +0000 (05:24 +0000)]
MFC 297809,297810,297811

297809
    hyperv/hn: Cap default # of rings to 8.

    8 gives the best performance in both Azure and local Hyper-V on both
    10Ge and 40Ge. More rings are still allowed by manual configuration.

    Reviewed by:        Dexuan Cui <decui microsoft com>
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5879

297810
    hyperv/hn: By default enable multiple TX/RX rings, aka vRSS.

    Reviewed by:        Dexuan Cui <decui microsoft com>
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5880

297811
    hyperv/hn: Remove unnecessary NULL checks

    Submitted by:       Jun Su <junsu microsoft com>
    Reviewed by:        sephe
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5905

git-svn-id: svn://svn.freebsd.org/base/stable/10@301952 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC 297636,297800,297801,297805,297807,297808
sephe [Thu, 16 Jun 2016 05:12:28 +0000 (05:12 +0000)]
MFC 297636,297800,297801,297805,297807,297808

297636
    hyperv: Typo in r297634

    Noticed by: hiren
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC

297800
    hyperv/vmbus: Nuke unused function

    MFC after:  1 week
    Sponsored by:       Microsoft OSTC

297801
    hyperv/vmbus: Get rid of max_leaf detection; this is actually not used.

    It will be replaced by a new one.

    MFC after:  1 week
    Sponsored by:       Microsoft OSTC

297805
    hyperv: Break long line

    MFC after:  1 week
    Sponsored by:       Microsoft OSTC

297807
    hyperv: Print more features

    And add comment about the MSR features.

    MFC after:  1 week
    Sponsored by:       Microsoft OSTC

297808
    hyperv: Define macro for Hyper-V interface

    Suggested by:       rpokala
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC

git-svn-id: svn://svn.freebsd.org/base/stable/10@301951 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC 297334
sephe [Thu, 16 Jun 2016 04:32:11 +0000 (04:32 +0000)]
MFC 297334

    vt: Use textmode when we're running on hypervisors

    The graphic mode is noticeably slow on hypervisors, especially
    on Hyper-V (1 second to each line).

    Submitted by:       Dexuan Cui <decui microsoft com>
    Reviewed by:        kib, sephe, royger (early loader version)
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5739

git-svn-id: svn://svn.freebsd.org/base/stable/10@301950 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC 297265
sephe [Thu, 16 Jun 2016 04:21:27 +0000 (04:21 +0000)]
MFC 297265

    tcp/lro: Return TCP_LRO_NO_ENTRIES if we are short of LRO entries.

    So that callers could react accordingly.

    Reviewed by:        gallatin (no objection)
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5695

git-svn-id: svn://svn.freebsd.org/base/stable/10@301949 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC 297220
sephe [Thu, 16 Jun 2016 03:25:26 +0000 (03:25 +0000)]
MFC 297220

    hyperv/utils: Allow hint to disable individual utility

    Reviewed by:        kib, Dexuan Cui <decui microsoft com>
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5714

git-svn-id: svn://svn.freebsd.org/base/stable/10@301948 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC 297180,297181,297182
sephe [Thu, 16 Jun 2016 03:16:43 +0000 (03:16 +0000)]
MFC 297180,297181,297182

297180
    hyperv/hn: Reduce TCP segment aggregation limit for multiple RX rings

    This mainly used to improve ACK timeliness when multiple RX rings
    are enabled.

    This value gives the best performance in both Azure and Hyper-V
    environment, w/ both 10Ge and 40Ge using non-{INVARIANTS,WITNESS}
    kernel.

    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5691

297181
    hyperv/hn: Factor out hn_set_lro_lenlim()

    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5692

297182
    hyperv/hn: When short of mbufs on the RX path, don't spam the console.

    Instead, increase the IQDROPS counter.

    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5693

git-svn-id: svn://svn.freebsd.org/base/stable/10@301947 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC 297142,297143,297176,297177,297178,297221
sephe [Thu, 16 Jun 2016 03:04:16 +0000 (03:04 +0000)]
MFC 297142,297143,297176,297177,297178,297221

297142
    hyperv: Factor out snprinf_hv_guid()

    Submitted by:       Ju Sun <junsu microsoft com>
    Reviewed by:        Dexuan Cui <decui microsoft com>, sephe
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5651

297143
    hyperv/vmbus: Implement bus_child_pnpinfo_str method

    Submitted by:       Jun Su <junsu microsoft com>
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5669

297176
    hyperv/evttimer: Use an independent message slot so that it can work

    Using the same message slot as the other types of the messages has
    the side effect that the event timer message could be deferred to
    the swi threads to run (lacking of trapframe and the original code
    didn't even handle that, so the event timer was actually broken).

    As of this commit we use an independent message slot for event timer,
    so that we could handle all of event timer messages in the interrupt
    handler directly.  Note, the message slot for event timer is still
    bind to the same interrupt vector as the other types of messages.

    Submitted by:       Jun Su <junsu microsoft com>
    Reviewed by:        sephe
    Discussed with: Jun Su <junsu microsoft com>, Dexuan Cui <decui microsoft com>
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5696

297177
    hyperv/vmbus: Use taskqueue_fast for non-performance critical messages

    This gets rid of the per-cpu SWIs.

    Submitted by:       Jun Su <junsu microsoft com>
    Reviewed by:        Dexuan Cui <decui microsoft com>, sephe
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5215

297178
    hyperv/vmbus: Remove NULL check for taskqueue_create_fast(M_WAITOK)

    Submitted by:       Jun Su <junsu microsoft com>
    Reviewed by:        Dexuan Cui <decui microsoft com>, sephe
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5215

297221
    hyperv/vmbus: Create per-cpu fast taskqueue for msg handling

    Using one taskqueue does not work, since the EOM MSR must be written
    on the msg's owner CPU.

    Noticed by: Jun Su <junsu microsoft com>
    Discussed with:     Jun Su <junsu microsoft com>, Dexuan Cui <decui microsoft com>
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC

git-svn-id: svn://svn.freebsd.org/base/stable/10@301946 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC 296379,296380,296381,296593,296594,296595
sephe [Thu, 16 Jun 2016 02:48:18 +0000 (02:48 +0000)]
MFC 296379,296380,296381,296593,296594,296595

296379
    hyperv/hn: Add multiple channel support, a.k.a. vRSS

    Each channel contains one RX ring and one TX ring.  And we
    try to distribute the channels to different evenly.

    Note: Currently we don't have enough information to extract
    the RSS type and RSS hash value from the received packets.

    This greatly improves the TX/RX performance for 8 virtual CPU
    Hyper-V over 10Ge: it can max out 10Ge for TCP when multiple
    RX/TX rings are enabled.

    This almost doubles the TX/RX performance for locally connected
    Hyper-Vs: was 6Gbps w/ 128 TCP streams, now 11Gbps w/ multiple
    RX/TX rings enabled.

    It is not enabled by default; it will be switched on after more
    tests.

    Collaborated with:  Hongjiang Zhang <honzhan microsoft com>
    MFC after:  2 week
    Sponsored by:       Microsoft OSTC

296380
    hyperv/hn: Pass channel to send done callbacks.

    Mainly to strigent the data packet send done check.

    MFC after:  2 weeks
    Sponsored by:       Microsoft OSTC

296381
    hyperv/hn: Add per-TX ring stats for # of transmitted packets

    MFC after:  2 weeks
    Sponsored by:       Microsoft OSTC

296593
    hyperv/hn: Move if_initname to an earlier place

    So that functions shared w/ attach path could use if_printf().

    While I'm here, remove unnecessary if_dunit and if_dname assignment.

    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5576

296594
    hyperv/hn: Factor out hn_channel_attach

    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5577

296595
    hyperv/hn: Make the # of TX rings configurable.

    Rename the tunables to avoid confusion.

    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5578

git-svn-id: svn://svn.freebsd.org/base/stable/10@301943 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC 297802,297803(297481),297804
sephe [Thu, 16 Jun 2016 01:57:16 +0000 (01:57 +0000)]
MFC 297802,297803(297481),297804

297802
    hyperv: Identify Hyper-V features and recommends properly

    Features bits will be used to detect devices, e.g. timers, which
    do not have corresponding event channels.

    Submitted by:       Jun Su <junsu microsoft com>
    Reviewed by:        sephe, Dexuan Cui <decui microsoft com>
    Rearranged by:      sephe
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC

279803(297481)
    hyperv: Register Hyper-V timer early enough for TSC freq calibration

    The i8254 simulation in Hyper-V is kinda broken and is not available
    in Generation 2 Hyper-V VMs, so Hyper-V timer must be registered early
    enough so that it can be used to do the TSC freq calibration.

    This fixes the notorious warning like this:
    calcru: runtime went backwards from 50 usec to 25 usec for pid 0 (kernel)

    Submitted by:       Dexuan Cui <decui microsoft com>
    Reviewed by:        kib, sephe
    Tested by:  kib, sephe
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5778

    =================

    hyperv: Resurrect r297481

    This time we make sure that the TIME_REF_COUNT MSR exists.

    Submitted by:       Jun Su <junsu microsoft com>
    Reviewed by:        sephe, Dexuan Cui <decui microsoft com>
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC

297804
    hyperv: Declare hyperv_{features,recommends} properly

    MFC after:  1 week
    Sponsored by:       Microsoft OSTC

git-svn-id: svn://svn.freebsd.org/base/stable/10@301942 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r301532
vangyzen [Wed, 15 Jun 2016 14:11:49 +0000 (14:11 +0000)]
MFC r301532

newsyslog: Eliminate unnecessary sleep(10) when -R and -s are specified

After going through the signal work list, during which do_sigwork()
is called and essentially does nothing because -s and -R were
specified on the command line, newsyslog will sleep for 10 seconds
as the (verbose) code says: "Pause 10 seconds to allow daemon(s)
to close log file(s)".

However, the man page verbiage for -R (and -s) seems quite clear
that this sleep() is unnecessary because the daemon was expected
to have already closed the log file before calling newsyslog.

PR: 210020
Submitted by: David A. Bright <david_a_bright@dell.com>
Sponsored by: Dell Inc.

git-svn-id: svn://svn.freebsd.org/base/stable/10@301926 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC 297635
sephe [Wed, 15 Jun 2016 09:52:01 +0000 (09:52 +0000)]
MFC 297635

    hyperv/vmbus: Use default mtx for channel message queue

    First of all sema_post() can't be called w/ spinlock, and the channel
    message queue processing is not on hot code path, i.e. spinlock is not
    necessary.

    Submitted by:       Jun Su <junsu microsoft com>
    Reviewed by:        sephe, Dexuan Cui <decui microsoft com>
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5812

git-svn-id: svn://svn.freebsd.org/base/stable/10@301925 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC 297219
sephe [Wed, 15 Jun 2016 09:39:41 +0000 (09:39 +0000)]
MFC 297219

    hyperv/vmbus: use a better retry method in hv_vmbus_post_message()

    Most often, hv_vmbus_post_message() doesn't fail.  However, it fails
    intermittently when GPADLs of large shared memory is to be established
    with the host, e.g. on the hn(4) attach path: a GPADL of 15MB sendbuf
    is created, for which lots of messages will be flooded to the host.
    The host side tries to throttle the message rate by returning
    HV_STATUS_INSUFFICIENT_BUFFERS.

    Before this commit, we do several retries for failed messages, but the
    delay between each retry is pretty/too low, which will cause sporadic
    message posting failure.  We now use large delay (>=1ms) between each
    retry to fix the message posting failure.

    Submitted by:       Dexuan Cui <decui microsoft com>
    Reviewed by:        sephe
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5715

git-svn-id: svn://svn.freebsd.org/base/stable/10@301924 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r301596
truckman [Wed, 15 Jun 2016 06:42:30 +0000 (06:42 +0000)]
MFC r301596

Don't leak olinep if malloc() fails.

If malloc() fails to allocate linep, then free olinep (if it exists)
before returning to avoid a memory leak.

Reported by: Coverity
CID: 1016716
Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D6755

git-svn-id: svn://svn.freebsd.org/base/stable/10@301921 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r301592
truckman [Wed, 15 Jun 2016 06:40:30 +0000 (06:40 +0000)]
MFC r301592

Don't leak addrinfo if ai->ai_addrlen <= minsiz test fails.

If the ai->ai_addrlen <= minsiz test fails, then freeaddrinfo()
does not get called to free the memory just allocated by getaddrinfo().
Fix by moving ai->ai_addrlen <= minsiz to a separate nested if
block, and keep freeaddrinfo() in the outer block so that freeaddrinfo()
will be called whenever getaddrinfo() succeeds.

Reported by: Coverity
CID: 1273652
Reviewed by: ume
Differential Revision: https://reviews.freebsd.org/D6756

git-svn-id: svn://svn.freebsd.org/base/stable/10@301920 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r301582
truckman [Wed, 15 Jun 2016 06:33:40 +0000 (06:33 +0000)]
MFC     r301582

Explicitly NUL terminate the buffer filled by fread().

The fix in r300649 was not sufficient to convince Coverity that the
buffer was NUL terminated, even with the buffer pre-zeroed.  Swap
the size and nmemb arguments to fread() so that a valid lenght is
returned, which we can use to terminate the string in the buffer
at the correct location.  This should also quiet the complaint about
the return value of fread() not being checked.

Reported by: Coverity
CID: 10190541009614
Secur3ty:
Sponsore dby:

git-svn-id: svn://svn.freebsd.org/base/stable/10@301919 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC 296293,296296,296297,296305
sephe [Wed, 15 Jun 2016 06:32:00 +0000 (06:32 +0000)]
MFC 296293,296296,296297,296305

296293
    hyperv/hn: Pass channel to hv_nv_on_receive_completion()

    While I'm here, staticize this function.

    Submitted by:       Hongjiang Zhang <honzhan microsoft com>
    Modified by:        sephe
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC

296296
    hyperv/hn: Make read buffer per-channel

    Submitted by:       Hongjiang Zhang <honzhan microsoft com>
    Reorganized by:     sephe
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC

296297
    hyperv/hn: Fix typo in comment

    MFC after:  1 week
    Sponsored by:       Microsoft OSTC

296305
    hyperv/hn: Make # of rings configurable

    And since the host may not being able to allocate the # of rings
    requested by us, save the # of rings allocated by the host in the
    ring_inuse counters; use ring_inuse counters for run time operation.

    This paves the way for the upcoming vRSS support.

    MFC after:  1 week
    Sponsored by:       Microsoft OSTC

git-svn-id: svn://svn.freebsd.org/base/stable/10@301918 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r299484, r301574
truckman [Wed, 15 Jun 2016 06:27:43 +0000 (06:27 +0000)]
MFC r299484, r301574

r299484 | cem | 2016-05-11 15:04:28 -0700 (Wed, 11 May 2016) | 13 lines

random(6): Fix double-close

In the case where a file lacks a trailing newline, there is some "evil" code to
reverse goto the tokenizing code ("make_token") for the final token in the
file.  In this case, 'fd' is closed more than once.  Use a negative sentinel
value to guard close(2), preventing the double close.

Ideally, this code would be restructured to avoid this ugly construction.

r301574 | truckman | 2016-06-07 19:14:05 -0700 (Tue, 07 Jun 2016) | 15 lines

Fix a (false positive?) Argument cannot be negative coverity defect.

Rather than guarding close(fd) with an fd >= 0 test and setting fd
to -1 when it is closed to avoid a potential double-close, just
move the close() call after the conditional "goto make_token".  This
moves the close() call totally outside the loop to avoid the
possibility of calling it twice.  This should also prevent a Coverity
warning about checking fd for validity after it was previously passed
to read().

Reported by: Coverity
CID: 10061231355335

git-svn-id: svn://svn.freebsd.org/base/stable/10@301917 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC 296291,301109
sephe [Wed, 15 Jun 2016 06:08:05 +0000 (06:08 +0000)]
MFC 296291,301109

296291
    hyperv/chan: Factor out the vcpu setting

    And use it for cpu0 assignment; it does not sound right to assume that
    cpu0 maps to vcpu0.  And this factored out function will be exposed to
    drivers, if driver specific CPU binding is needed, e.g. hn(4).

    Move default cpu select after saving channel offer message. This makes
    sure that all useful information of the channel has been setup.

    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5504

301109
    hyperv/channel: Only cpu0 is supported as channel target cpu on WIN7

    MFC after:  1 week
    Sponsored by:       Microsoft OSTC

git-svn-id: svn://svn.freebsd.org/base/stable/10@301916 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC 296181,296184,296187,296188,296252,296253,296289,296290
sephe [Wed, 15 Jun 2016 05:57:06 +0000 (05:57 +0000)]
MFC 296181,296184,296187,296188,296252,296253,296289,296290

296181
    hyperv/channel: Add debug sysctl nodes for channel indices

    It would serve as a debug tool, if the shared buffer ring's indices
    stopped updating.

    Submitted by:       HongJiang Zhang <honzhan microsoft com>
    Reviewed by:        sephe, Jun Su <junsu microsoft com>
    Modified by:        sephe
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5402

296184
    hyperv/hn: Switch to if_transmit by default after r296178

    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5485

296187
    hyperv/hn: Utilize mbuf flowid

    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5488

296188
    hyperv/channel: Add sysctl node for channel owner cpu

    And add sysctl node for sub-channel's channel id.

    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5489

296252
    hyperv/hn: Set hash per-packet-info for each packet transmission

    So that the host could dispatch the TX done back to this TX ring's
    owner channel

    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5498

296253
    hyperv/channel: Nuke useless stack variable

    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5499

296289
    hyperv/chan: Add sysctl node to check whether monitor is allocated or not

    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5502

296290
    hyperv/chan: Function renaming; no functional change

    The renamed function create a sysctl tree for channel, and many
    non-statistics nodes exists, so don't claim it only adds sysctl
    nodes for statistics.

    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5503

git-svn-id: svn://svn.freebsd.org/base/stable/10@301915 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC 296180,297634
sephe [Wed, 15 Jun 2016 05:31:35 +0000 (05:31 +0000)]
MFC 296180,297634

296180
    hyperv: Use proper fence function to keep store-load order for msgs

    sfence only makes sure about the store-store order, which is not
    sufficient here.  Use atomic_thread_fence_seq_cst() as suggested
    jhb and kib (a locked op in the nutshell, which should have the

    Reviewed by:        jhb, kib, Jun Su <junsu microsoft com>
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5436

297634
    hyperv: Use mb() instead of atomic_thread_fence_seq_cst()

    Since atomic_thread_fence_seq_cst() will become compiler fence on UP kernel.

    Reviewed by:        kib, Dexuan Cui <decui microsoft com>
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5852

git-svn-id: svn://svn.freebsd.org/base/stable/10@301914 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC 296178
sephe [Wed, 15 Jun 2016 05:16:37 +0000 (05:16 +0000)]
MFC 296178

    buf_ring/drbr: Add buf_ring_peek_clear_sc and use it in drbr_peek

    Unlike buf_ring_peek, it only supports single consumer mode, and it
    clears the cons_head if DEBUG_BUFRING/INVARIANTS is defined.

    The normal use case of drbr_peek for network drivers is:

    m = drbr_peek(br);
    err = hw_spec_encap(&m); /* could m_defrag/m_collapse */
    (*)
    if (err) {
        if (m == NULL)
            drbr_advance(br);
        else
            drbr_putback(br, m);
        /* break the loop */
    }
    drbr_advance(br);

    The race is:
    If hw_spec_encap() m_defrag or m_collapse the mbuf, i.e. the old mbuf
    was freed, or like the Hyper-V's network driver, that transmission-
    done does not even require the TX lock; then on the other CPU at the
    (*) time, the freed mbuf could be recycled and being drbr_enqueue even
    before the current CPU had the chance to call drbr_{advance,putback}.
    This triggers a panic in drbr_enqueue duplicated element check, if
    DEBUG_BUFRING/INVARIANTS is defined.

    Use buf_ring_peek_clear_sc() in drbr_peek() to fix the above race.

    This change is a NO-OP, if neither DEBUG_BUFRING nor INVARIANTS are
    defined.

    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5416

git-svn-id: svn://svn.freebsd.org/base/stable/10@301913 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC 296083,296084,296085,296086,296087,296088,296089
sephe [Wed, 15 Jun 2016 03:48:55 +0000 (03:48 +0000)]
MFC 296083,296084,296085,296086,296087,296088,296089

296083
    hyperv: Remove useless channel inbound_lock

    It serves no purpose.

    Reviewed by:        Hongjiang Zhang <honzhan microsoft com>
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5450

296084
    hyperv: Always set device for channels

    And unregister hv_device only for primary channels, who own the hv_device.

    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5451

296085
    hyperv/hn: Pass channel as the channel callback argument

    This is the preamble to pass channel back to hn(4) upon TX/RX done.

    Reviewed by:        Hongjiang Zhang <honzhan microsoft com>
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5452

296086
    hyperv/hn: Pass channel to TX/RX done

    This is preamble to associate the TX/RX rings to their channel.

    While I'm here, revoke unused netvsc_recv_rollup.

    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5453

296087
    hyperv/hn: Associate TX/RX ring with channel

    This fixes the TX/RX ring selection for TX/RX done.

    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5454

296088
    hyperv/hn: Remove the useless num_outstanding_sends

    We rely on taskqueue draining now.

    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5456

296089
    hyperv/hn: Make transmission path channel aware

    Chimney sending buffer still needs conversion, which will be done
    along with the upcoming vRSS support.

    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5457

git-svn-id: svn://svn.freebsd.org/base/stable/10@301912 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC 296022,296024,296076
sephe [Wed, 15 Jun 2016 03:17:05 +0000 (03:17 +0000)]
MFC 296022,296024,296076

296022
    hyperv/hn: Implement ifnet.if_transmit method

    It will be turned on by default later.

    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5415

296024
    hyperv/hn: Hold the TX ring lock then drain TX desc buf_ring

    Reported by:        Hongxiong Xian <v-hoxian microsoft com>
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC

296076
    hyperv: Use atomic_fetchadd_int to get GPADL id.

    Reviewed by:        Hongjiang Zhang <honzhan microsoft com>
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5439

git-svn-id: svn://svn.freebsd.org/base/stable/10@301911 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r301764:
jamie [Wed, 15 Jun 2016 01:59:55 +0000 (01:59 +0000)]
MFC r301764:

  Fix a vnode leak when giving a child jail a too-long path when
  debug.disablefullpath=1.

git-svn-id: svn://svn.freebsd.org/base/stable/10@301910 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r301760:
jamie [Wed, 15 Jun 2016 01:58:54 +0000 (01:58 +0000)]
MFC r301760:

  Re-order some jail parameter reading to prevent a vnode leak.

git-svn-id: svn://svn.freebsd.org/base/stable/10@301909 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r301758:
jamie [Wed, 15 Jun 2016 01:57:22 +0000 (01:57 +0000)]
MFC r301758:

  Clean up some logic in jail error messages, replacing a missing test and
  a redundant test with a single correct test.

git-svn-id: svn://svn.freebsd.org/base/stable/10@301908 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r301745:
jamie [Wed, 15 Jun 2016 01:56:20 +0000 (01:56 +0000)]
MFC r301745:

  Make sure the OSD methods for jail set and remove can't run concurrently,
  by holding allprison_lock exclusively (even if only for a moment before
  downgrading) on all paths that call PR_METHOD_REMOVE.  Since they may run
  on a downgraded lock, it's still possible for them to run concurrently
  with PR_METHOD_GET, which will need to use the prison lock.

git-svn-id: svn://svn.freebsd.org/base/stable/10@301907 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r301737:
jamie [Wed, 15 Jun 2016 01:54:17 +0000 (01:54 +0000)]
MFC r301737:

  Remove a comment that was part of copied code, and is misleading in
  the new location.

git-svn-id: svn://svn.freebsd.org/base/stable/10@301906 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r300983:
jamie [Wed, 15 Jun 2016 01:49:01 +0000 (01:49 +0000)]
MFC r300983:

  Mark jail(2), and the sysctls that it (and only it) uses as deprecated.
  jail(8) has long used jail_set(2), and those sysctl only cause confusion.

git-svn-id: svn://svn.freebsd.org/base/stable/10@301905 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r301293:
mav [Wed, 15 Jun 2016 01:42:53 +0000 (01:42 +0000)]
MFC r301293:
When negotiating NTB_SB01BASE_LOCKUP workaround, don't try to limit the
BAR size to 1MB.  According to Xeon v3 specifications and my tests, that
size register is write-once and so not writeable after BIOS written it.

Instead of that, make the code work with BAR of any sufficient size,
properly calculating offset within its base.  It also simplifies the code.

Sponsored by: iXsystems, Inc.

git-svn-id: svn://svn.freebsd.org/base/stable/10@301904 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r301292: When negotiating MSIX parameters, give other head time to see
mav [Wed, 15 Jun 2016 01:41:43 +0000 (01:41 +0000)]
MFC r301292: When negotiating MSIX parameters, give other head time to see
our NTB_MSIX_RECEIVED status, before making upper layers overwrite it.

This is not completely perfect, but now it works better then before.

Sponsored by: iXsystems, Inc.

git-svn-id: svn://svn.freebsd.org/base/stable/10@301903 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r300610: Re-enable write combining, disabled by default at r295486.
mav [Wed, 15 Jun 2016 01:39:43 +0000 (01:39 +0000)]
MFC r300610: Re-enable write combining, disabled by default at r295486.

if_ntb(4) strongly benefits from WC, improving throughput from 350Mbit/s
to 8-10Gbit/s on my tests.

git-svn-id: svn://svn.freebsd.org/base/stable/10@301902 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC 295919,295958,295964
sephe [Mon, 13 Jun 2016 09:02:08 +0000 (09:02 +0000)]
MFC 295919,295958,295964

295919
    hyperv/stor: Fix print format

    Detected by:        PVS Static Analysis
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5388

295958
    hyperv/utils: Code rearrange and cleanup

    Split heartbeat, shutdown and timesync out of utils code
    and name them properly.

    Submitted by:       Jun Su <junsu microsoft com>
    Reviewed by:        adrian, sephe, Hongjiang Zhang <honzhan microsoft com>
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5216

295964
    hyperv/vmbus: Use free(9) for interrupt page; it is allocated by malloc(9)

    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5417

git-svn-id: svn://svn.freebsd.org/base/stable/10@301866 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agohyperv/hn: Hide unused function
sephe [Mon, 13 Jun 2016 08:44:29 +0000 (08:44 +0000)]
hyperv/hn: Hide unused function

Sponsored by: Microsoft OSTC

git-svn-id: svn://svn.freebsd.org/base/stable/10@301865 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC 295875,295876,295877,295916,295918
sephe [Mon, 13 Jun 2016 08:38:04 +0000 (08:38 +0000)]
MFC 295875,295876,295877,295916,295918

295875
    hyperv/hn: Rename TX related function and struct fields a bit

    Preamble to implement the ifnet.if_transmit method.

    Reviewed by:        adrian
    Approved by:        adrian (mentor)
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5344

295876
    hyperv/hn: Staticize and rename packet TX done function

    It is only used in hv_netvsc_drv_freebsd.c; and rename it to hn_tx_done()
    mainly to reserve "xmit" for ifnet.if_transmit implement.

    While I'm here, remove unapplied comment.

    Reviewed by:        adrian
    Approved by:        adrian (mentor)
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5345

295877
    hyperv/hn: Add TX method for txeof processing.

    Preamble to implement ifnet.if_transmit method.

    Reviewed by:        adrian
    Approved by:        adrian (mentor)
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5346

295916
    hyperv/hn: Factor out hn_send_pkt() from hn_start_locked()

    It will be shared w/ the upcoming ifnet.if_transmit method
    implementation.

    No functional change.

    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5385

295918
    hyperv/hn: Use IFQ_DRV_PREPEND instead of IF_PREPEND

    IF_PREPEND promises out-of-order packet sending when the TX desc list
    is depleted. It was overlooked and copied blindly when the transmission
    path was partially rewritten.

    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5386

git-svn-id: svn://svn.freebsd.org/base/stable/10@301864 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agohyperv/hn: Fix mis-merge introduced by r301861.
sephe [Mon, 13 Jun 2016 08:18:45 +0000 (08:18 +0000)]
hyperv/hn: Fix mis-merge introduced by r301861.

git-svn-id: svn://svn.freebsd.org/base/stable/10@301863 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC 295748,295792,295793,295794
sephe [Mon, 13 Jun 2016 08:03:53 +0000 (08:03 +0000)]
MFC 295748,295792,295793,295794

295748
    hyperv/hn: Use buf_ring for txdesc list

    So one spinlock is avoided, which would be potentially dangerous for
    virtual machine, if the spinlock holder was scheduled out by the host,
    as noted by royger.

    Old spinlock based txdesc list is still kept around, so we could have
    a safe fallback.

    No performance regression nor improvement is observed.

    Reviewed by:        adrian
    Approved by:        adrian (mentor)
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5290

295792
    hyperv/hn: Add option to bind TX taskqueues to the specified CPU

    It will be used to help tracking host side transmission ring selection
    issue; and it will be turned on by default, once we have concrete result.

    Reviewed by:        adrian, Jun Su <junsu microsoft com>
    Approved by:        adrian (mento)
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5316

295793
    hyperv/hn: Enable IP header checksum offloading for WIN8 (WinServ2012)

    Tested on Windows Server 2012.

    Reviewed by:        adrian
    Approved by:        adrian (mentor)
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5317

295794
    hyperv/hn: Free the txdesc buf_ring when the TX ring is destroyed

    Reviewed by:        adrian
    Approved by:        adrian (mentor)
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5318

git-svn-id: svn://svn.freebsd.org/base/stable/10@301862 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC 295743,295744,295745,295746,295747
sephe [Mon, 13 Jun 2016 07:30:54 +0000 (07:30 +0000)]
MFC 295743,295744,295745,295746,295747

295743
    hyperv/hn: Change global tunable prefix to hw.hn

    And use SYSCTL+CTLFLAG_RDTUN for them.

    Suggested by:       adrian
    Reviewed by:        adrian, Hongjiang Zhang <honzhan microsoft com>
    Approved by:        adrian (mentor)
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5274

295744
    hyperv/hn: Split RX ring data structure out of softc

    This paves the way for upcoming vRSS stuffs and eases more code cleanup.

    Reviewed by:        adrian
    Approved by:        adrian (mentor)
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5275

295745
    hyperv/hn: Use taskqueue_enqueue()

    This also eases experiment on the non-fast taskqueue.

    Reviewed by:        adrian, Jun Su <junsu microsoft com>
    Approved by:        adrian (mentor)
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5276

295746
    hyperv/hn: Use non-fast taskqueue for transmission

    Performance stays same; so no need to use fast taskqueue here.

295747
    hyperv/hn: Split TX ring data structure out of softc

    This paves the way for upcoming vRSS stuffs and eases more code cleanup.

    Reviewed by:        adrian
    Approved by:        adrian (mentor)
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5283

git-svn-id: svn://svn.freebsd.org/base/stable/10@301861 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC 295740,295741,295742
sephe [Mon, 13 Jun 2016 07:03:00 +0000 (07:03 +0000)]
MFC 295740,295741,295742

295740
    hyperv/hn: Set the TCP ACK/data segment aggregation limit

    Set TCP ACK append limit to 1, i.e. aggregate 2 ACKs at most.  Aggregating
    anything more than 2 hurts TCP sending performance in hyperv.  This
    significantly improves the TCP sending performance when the number of
    concurrent connetion is low (2~8).  And it greatly stabilizes the TCP
    sending performance in other cases.

    Set TCP data segments aggregation length limit to 37500.  Without this
    limitation, hn(4) could aggregate ~45 TCP data segments for each
    connection (even at 64 or more connections) before dispatching them to
    socket code; large aggregation slows down ACK sending and eventually
    hurts/destabilizes TCP reception performance.  This setting stabilizes
    and improves TCP reception performance for >4 concurrent connections
    significantly.

    Make them sysctls so they could be adjusted.

    Reviewed by:        adrian, gallatin (previous version), hselasky (previous version)
    Approved by:        adrian (mentor)
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5185

295741
    hyperv/hn: Add option to allow sharing TX taskq between hn instances

    It is off by default.  This eases further experimenting on this driver.

    Reviewed by:        adrian
    Approved by:        adrian (mentor)
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5272

295742
    hyperv/hn: Always do transmission scheduling.

    This one gives the best performance so far.

    Reviewed by:        adrian
    Approved by:        adrian (mentor)
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5273

git-svn-id: svn://svn.freebsd.org/base/stable/10@301860 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC 295307,295308,295309,295606
sephe [Mon, 13 Jun 2016 06:38:46 +0000 (06:38 +0000)]
MFC 295307,295308,295309,295606

295307
    hyperv: Use standard taskqueue instead of hv_work_queue

    HyperV code was ported from Linux.  There is an implementation of
    work queue called hv_work_queue.  In FreeBSD, taskqueue could be
    used for the same purpose.  Convert all the consumer of hv_work_queue
    to use taskqueue, and remove work queue implementation.

    Submitted by:       Jun Su <junsu microsoft com>
    Reviewed by:        adrian, Hongjiang Zhang <honzhan microsoft com>
    Approved by:        adrian (mentor)
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D4963

295308
    hyperv: Use WAITOK in the places where we can wait

    And convert rndis non-hot path spinlock to mutex.

    Submitted by:       Jun Su <junsu microsoft com>
    Reviewed by:        adrian, sephe
    Approved by:        adrian (mentor)
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5081

295309
    hyperv: Use malloc for page allocation.

    We will eventually convert them to use busdma.

    Submitted by:       Jun Su <junsu microsoft com>
    Reviewed by:        adrian, sephe, Dexuan Cui <decui microsoft com>
    Approved by:        adrian (mentor)
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5087

295606
    hyperv/hn: Fix typo in comment

    Noticed by: avos
    Reviewed by:        adrian, avos, Hongjiang Zhang <honzhan microsoft com>
    Approved by:        adrian
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5199

git-svn-id: svn://svn.freebsd.org/base/stable/10@301859 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC 295304,295305,295306
sephe [Mon, 13 Jun 2016 06:24:41 +0000 (06:24 +0000)]
MFC 295304,295305,295306

295304
    hyperv/hn: Increase LRO entry count to 128 by default

    hn(4) only has one RX ring currently, so default 8 LRO entries
    are too small.

    Reviewed by:        adrian
    Approved by:        adrian (mentor)
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5166

295305
    hyperv/hn: Move LRO flush to the channel processing rollup

    This significantly increases LRO aggregation ratio when there are
    large amount of connections (improves reception performance a lot).

    Reviewed by:        adrian
    Approved by:        adrian (mentor)
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5167

295306
    hyperv/hn: Add an option to always do transmission scheduling

    It is off by default. This eases more experiment on hn(4).

    Reviewed by:        adrian, Hongjiang Zhang <honzhan microsoft com>
    Approved by:        adrian (mentor)
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5175

git-svn-id: svn://svn.freebsd.org/base/stable/10@301858 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC 295302,295303
sephe [Mon, 13 Jun 2016 06:09:02 +0000 (06:09 +0000)]
MFC 295302,295303

295302
    hyperv/hn: Factor out hn_encap() from hn_start_locked()

    It will be shared w/ upcoming ifnet.if_transmit implementaion.

    No functional changes.

    Reviewed by:        adrian
    Approved by:        adrian (mentor)
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5158

295303
    hyperv/hn: Recover half of the chimney sending space

    We lost half of the chimney sending space, because we mis-used
    ffs() on a 64 bits mask, where ffsl() should be used.

    While I'm here:
    - Use system atomic operation instead.
    - Stringent chimney sending index assertion.

    Reviewed by:        adrian
    Approved by:        adrian (mentor)
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5159

git-svn-id: svn://svn.freebsd.org/base/stable/10@301857 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC 295296,295297,295298,295299,295300,295301
sephe [Mon, 13 Jun 2016 05:43:42 +0000 (05:43 +0000)]
MFC 295296,295297,295298,295299,295300,295301

295296
    hyperv/hn: Avoid duplicate csum features settings

    - Record csum features in softc, so we don't need to duplicate the
      logic from attach path to ioctl path.
    - Protect if_capenable and if_hwassist changes by main lock.
    - Prefer turn on/off bits in if_hwassist explicitly instead of using
      XOR.

    Reviewed by:        adrian, Hongjiang Zhang <honzhan microsoft com>
    Approved by:        adrian (mentor)
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5085

295297
    hyperv/hn: Reorganize TX csum offloading

    - For non-TSO offloading, we don't need to access mbuf to know
      which csum offloading is requested, we can just use the
      CSUM_{IP,TCP,UDP} in the csum_flags.
    - For TSO offloading, we still can depend on CSUM_{TSO4,TSO6}
      in the csum_flags to tell whether the TSO packet is an IPv4
      TSO packet or an IPv6 TSO packet.

    This streamlines csum offloading handling (remove the two goto)
    and allows us the nuke the unnecessary get_transport_proto_type().

    Reviewed by:        adrian, Hongjiang Zhang <honzhan microsoft com>
    Approved by:        adrian (mentor)
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5098

295298
    hyperv/hn: Enable IP header checksum offloading

    So that:
    - TCP/IP stack will not do unnecessary IP header checksum for TSO
      packets.
    - Reduce guest load for non-TSO IP packets.

    Reviewed by:        adrian
    Approved by:        adrian (mentor)
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5099

295299
    hyperv/hn: Enable UDP RXCSUM

    Reviewed by:        adrian
    Approved by:        adrian (mentor)
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5102

295300
    hyperv/hn: Add sysctls to trust host side UDP and IP csum verification

    Reviewed by:        adrian, Hongjiang Zhang <honzhan microsoft com>
    Approved by:        adrian (mentor)
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5103

295301
    hyperv/hn: Obey IFCAP_RXCSUM configure

    Reviewed by:        adrian
    Approved by:        adrian (mentor)
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5104

git-svn-id: svn://svn.freebsd.org/base/stable/10@301856 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC 295295
sephe [Mon, 13 Jun 2016 05:13:52 +0000 (05:13 +0000)]
MFC 295295

    hyperv/stor: Fix the NULL pointer dereference

    Reported by:        Netapp
    Submitted by:       Hongjiang Zhang <honzhan microsoft com>
    Reviewed by:        adrian, sephe, Dexuan Cui <decui microsoft com>
    Approved by:        adrian (mentor)
    MFC after:  1 week
    Sponsored by:       Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5097

git-svn-id: svn://svn.freebsd.org/base/stable/10@301855 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC 294886
sephe [Mon, 13 Jun 2016 05:06:07 +0000 (05:06 +0000)]
MFC 294886

    hyperv/vmbus: Event handling code refactor.

    - Use taskqueue instead of swi for event handling.
    - Scan the interrupt flags in filter
    - Disable ringbuffer interrupt mask in filter to ensure no unnecessary
      interrupts.

    Submitted by:               Jun Su <junsu microsoft com>
    Reviewed by:                adrian, sephe, Dexuan <decui microsoft com>
    Approved by:                adrian (mentor)
    MFC after:          2 weeks
    Sponsored by:               Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D4920

git-svn-id: svn://svn.freebsd.org/base/stable/10@301854 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC 294701,294702,294703,294705,294788
sephe [Mon, 13 Jun 2016 03:28:37 +0000 (03:28 +0000)]
MFC 294701,294702,294703,294705,294788

294701
    hyperv/hn: Use m_copydata for chimney sending.

    While I'm here, move stack variables near their usage.

    Reviewed by:                adrian, delphij, Jun Su <junsu microsoft com>
    Approved by:                adrian (mentor)
    Sponsored by:               Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D4977

294702
    hyperv/hn: Remove unnecessary zeroing out the netvsc_packet

    All used fields are setup one by one, so there is no need to zero
    out this large struct.

    While I'm here, move the stack variable near its usage.

    Reviewed by:                adrian, delphij, Jun Su <junsu microsoft com>
    Approved by:                adrian (mentor)
    Sponsored by:               Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D4978

294703
    hyperv/hn: Trust host TCP segment checksum verification by default.

    According to all available information, VMSWITCH always does the
    TCP segment checksum verification before sending the segment to
    guest.

    Reviewed by:                adrian, delphij, Hongjiang Zhang <honzhan microsoft com>
    Approved by:                adrian (mentor)
    Sponsored by:               Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D4991

294705
    hyperv/vmbus: Avoid extra copy of page information.

    The page information array could contain up to 32 elements (i.e. 512B).
    And on network side w/ TSO, 11+ (176B+) elements, i.e. ~44K TSO packet,
    in the page information array is quite common.

    This saves us some cpu cycles.

    Reviewed by:                adrian, delphij
    Approved by:                adrian (mentor)
    Sponsored by:               Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D4992

294788
    hyperv/hn: Improve sending performance

    - Avoid main lock contention by trylock for if_start, if that fails,
      schedule TX taskqueue for if_start
    - Don't do direct sending if the packet to be sent is large, e.g.
      TSO packet.

    This change gives me stable 9.1Gbps TCP sending performance w/ TSO
    over a 10Gbe directly connected network (the performance fluctuated
    between 4Gbps and 9Gbps before this commit). It also improves non-
    TSO TCP sending performance a lot.

    Reviewed by:                adrian, royger
    Approved by:                adrian (mentor)
    Sponsored by:               Microsoft OSTC
    Differential Revision:      https://reviews.freebsd.org/D5074

git-svn-id: svn://svn.freebsd.org/base/stable/10@301850 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC 300985, 301103
sephe [Mon, 13 Jun 2016 03:03:08 +0000 (03:03 +0000)]
MFC 300985, 301103

r300985
bge: Support 5717 C0, which is almost same as 5720 A0

PR:         209758
Obtained from:      DragonFlyBSD d79f5d8f5fe94cd6769207b2901422977d502bc0
MFC after:  1 week

============

r301103
bge: Force chipid to 5720 A0 for 5717 C0 in an early place

Discussed with:     yongari
MFC after:  1 week
Sponsored by:       Microsoft OSTC

git-svn-id: svn://svn.freebsd.org/base/stable/10@301848 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC 293653
sephe [Mon, 13 Jun 2016 02:54:58 +0000 (02:54 +0000)]
MFC 293653

hyperv/kvp_daemon: Make poll(2) block indefinitely

Submitted by:       Jun Su <junsu microsoft com>
Reviewed by:        Dexuan Cui <decui microsoft com>, me, adrain
Approved by:        adrian
Sponsored by:       Microsoft OSTC
Differential Revision:      https://reviews.freebsd.org/D4762

git-svn-id: svn://svn.freebsd.org/base/stable/10@301847 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r300967:
dim [Sun, 12 Jun 2016 11:45:45 +0000 (11:45 +0000)]
MFC r300967:

Stop exposing the C11 _Atomic() macro in <sys/cdefs.h>, when compiling
for C++.  It clashes with the one in libc++'s <atomic> header.

(Previously, the _Atomic() macro was defined in <stdatomic.h>, which is
only for use with C11, but for various reasons it was moved to its
current location in r251804.)

Discussed with: bdrewery, ed

git-svn-id: svn://svn.freebsd.org/base/stable/10@301839 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r300395:
ngie [Sun, 12 Jun 2016 05:57:42 +0000 (05:57 +0000)]
MFC r300395:

Silence top(1) compiler warnings

The contrib/top code is no longer maintained upstream (last pulled 16 years
ago). The K&R-style followed by the code spews -Wimplicit-int and -Wreturn-type
warnings, amongst others. This silences 131 warnings with as little modification
as possible by adding necessary return types, definitions, headers, and header
guards, and missing header includes.

The 5 warnings that remain are due to undeclared ncurses references. I didn't
include curses.h and term.h because there are several local functions and macros
that conflict with those definitions.

git-svn-id: svn://svn.freebsd.org/base/stable/10@301836 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r301457:
kib [Sun, 12 Jun 2016 02:42:08 +0000 (02:42 +0000)]
MFC r301457:
Avoid spurious EINVAL in amd64 pmap_change_attr().

git-svn-id: svn://svn.freebsd.org/base/stable/10@301835 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoRedo MFC r300220,r300223:
ngie [Sat, 11 Jun 2016 11:28:29 +0000 (11:28 +0000)]
Redo MFC r300220,r300223:

Differential Revision: https://reviews.freebsd.org/D6803
Reviewed by: alc, kib
Sponsored by: EMC / Isilon Storage Division

r300220 (by cem):

sys/vmmeter.h: Fix trivial '-Wsign-compare' warning in common header

Frankly, it doesn't make sense for vm_pageout_wakeup_thresh to have a negative
value (it is only ever set to a fraction of v_free_min, which is unsigned and
also obviously non-negative). But I'm not going to try and convert every
non-negative scalar in the VM to unsigned today, so just cast it for the
comparison.

r300223 (by cem):

vm/vm_page.h: Fix trivial '-Wpointer-sign' warning

pq_vcnt, as a count of real things, has no business being negative. It is only
ever initialized by a u_int counter.

The warning came from the atomic_add_int() in vm_pagequeue_cnt_add().

Rectify the warning by changing the variable to u_int. No functional change.

Suggested by: Clang 3.3

git-svn-id: svn://svn.freebsd.org/base/stable/10@301833 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoRevert r301831 -- I forgot to add the diff from Phabricator
ngie [Sat, 11 Jun 2016 11:25:49 +0000 (11:25 +0000)]
Revert r301831 -- I forgot to add the diff from Phabricator

Pointyhat to: ngie (never commit without svn status half asleep)

git-svn-id: svn://svn.freebsd.org/base/stable/10@301832 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r300220,r300223:
ngie [Sat, 11 Jun 2016 11:24:30 +0000 (11:24 +0000)]
MFC r300220,r300223:

Differential Revision: https://reviews.freebsd.org/D6803
Reviewed by: alc, kib
Sponsored by: EMC / Isilon Storage Division

r300220 (by cem):

sys/vmmeter.h: Fix trivial '-Wsign-compare' warning in common header

Frankly, it doesn't make sense for vm_pageout_wakeup_thresh to have a negative
value (it is only ever set to a fraction of v_free_min, which is unsigned and
also obviously non-negative). But I'm not going to try and convert every
non-negative scalar in the VM to unsigned today, so just cast it for the
comparison.

r300223 (by cem):

vm/vm_page.h: Fix trivial '-Wpointer-sign' warning

pq_vcnt, as a count of real things, has no business being negative. It is only
ever initialized by a u_int counter.

The warning came from the atomic_add_int() in vm_pagequeue_cnt_add().

Rectify the warning by changing the variable to u_int. No functional change.

Suggested by: Clang 3.3

git-svn-id: svn://svn.freebsd.org/base/stable/10@301831 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r301584: Apply mergemaster r255428:
delphij [Sat, 11 Jun 2016 05:53:50 +0000 (05:53 +0000)]
MFC r301584: Apply mergemaster r255428:

Pass -n (do not emit comments) when saving mtree information for future
mergemaster(8) runs.

git-svn-id: svn://svn.freebsd.org/base/stable/10@301824 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r301570:
pfg [Sat, 11 Jun 2016 03:58:59 +0000 (03:58 +0000)]
MFC r301570:
libsupc++: Fix typo in symbol map.

This went mostly unnoticed with the deprecation of the GNU toolchain
in tier 1 platforms. Fix it now for the rest.

PR: 169901

git-svn-id: svn://svn.freebsd.org/base/stable/10@301822 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r301704:
ngie [Sat, 11 Jun 2016 01:37:59 +0000 (01:37 +0000)]
MFC r301704:

Test for strchr(3) returning NULL, not 0

git-svn-id: svn://svn.freebsd.org/base/stable/10@301820 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r301683:
ngie [Sat, 11 Jun 2016 01:34:41 +0000 (01:34 +0000)]
MFC r301683:

Fix typo with description for $ipv6_cpe_wanif (upstram -> upstream)

PR: 210146

git-svn-id: svn://svn.freebsd.org/base/stable/10@301818 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r300301, r300319:
pfg [Fri, 10 Jun 2016 22:07:17 +0000 (22:07 +0000)]
MFC r300301, r300319:
GCC: Add support for named initializers for anonymous structs/unions.

This is a C11 feature that is starting to get used in places such as Mesa.
This implementation takes a different approach to upstream and is
therefore not covered by GPLv3.

Obtained from: OpenBSD (CVS rev. 1.2)

git-svn-id: svn://svn.freebsd.org/base/stable/10@301817 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r300333:
pfg [Fri, 10 Jun 2016 21:47:37 +0000 (21:47 +0000)]
MFC r300333:
gas: Implement the .inst assembler directive for arm.

We normally use the binutils from ports but on other systems this
is required for building gcc 4.9.

Obtained from: OpenBSD (CVS rev. 1.5)

git-svn-id: svn://svn.freebsd.org/base/stable/10@301816 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoRecord mergeinfo for all complete commits done in the ioat(4) merge
ngie [Fri, 10 Jun 2016 18:47:11 +0000 (18:47 +0000)]
Record mergeinfo for all complete commits done in the ioat(4) merge
in r300661

This will make it easier for someone to determine what's missing when
running `svn mergeinfo --show-revs eligible`

r299353 wasn't recorded intentionally because it was only a "partial"
merge

Sponsored by: EMC / Isilon Storage Division

git-svn-id: svn://svn.freebsd.org/base/stable/10@301813 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r301296,r301297,r301300:
ngie [Fri, 10 Jun 2016 18:40:03 +0000 (18:40 +0000)]
MFC r301296,r301297,r301300:

r301296 (by cem):

ioat(4): Make channel indices unsigned

r301297 (by cem):

ioat(4): Export the number of available channels

r301300 (by cem):

ioat(4): Always log capabilities on attach

Different, relatively recent Intel Xeon hardware support radically different
features.  E.g., BDX support CRC32 while BDX-DE does not.

git-svn-id: svn://svn.freebsd.org/base/stable/10@301812 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r295618,r300100,r300531:
ngie [Fri, 10 Jun 2016 18:34:31 +0000 (18:34 +0000)]
MFC r295618,r300100,r300531:

r295618 (by cem):

NTB: workaround for high traffic hardware hang

This patch comes from Dave Jiang's Linux tree, davejiang/ntb.  It hasn't
been accepted into Linus' tree, so I do not have an authoritative SHA1
to point at.  Original commit log:

=====================================================================
A hardware errata causes the NTB to hang when heavy bi-directional
traffic in addition to the usage of BAR0/1 (where the registers reside,
including the doorbell registers to trigger interrupts).

This workaround is only available on Haswell and Broadwell platform.
The workaround is to enable split BAR in the BIOS to allow the 64bit
BAR4 to be split into two 32bit BAR4 and BAR5. The BAR4 shall be pointed
to LAPIC region of the remote host. We will bypass the db mechanism and
directly trigger the MSIX interrupts. The offsets and vectors are
exchanged during transport scratch pad negotiation. The scratch pads are
now overloaded in order to allow the exchange of the information. This
gets around using the doorbell and prevents the lockup with additional
pcode changes in BIOS.

Signed-off-by: Dave Jiang <dave.jiang@intel.com>
=====================================================================

Notable changes in the FreeBSD version of this patch:
* The MSIX BAR is configurable, like hw.ntb.b2b_mw_idx (msix_mw_idx).
  The Linux version of the patch only uses BAR4.
* MSIX negotiation aborts if the link goes down.

Obtained from: Linux (Dual BSD/GPL driver)

r300100 (by cem):

ntb_hw(4): Add sysctls for administrative/test link config, state

dev.ntb_hw.0.admin_up=0/1: Like ifconfig UP/DOWN.
dev.ntb_hw.0.active=0/1:   Like ifconfig 'status'

r300531 (by cem):

ntb_hw(4): Only record the first three MSIX vectors

Don't overrun the msix_data array by reading the (unused) link state
interrupt information.

git-svn-id: svn://svn.freebsd.org/base/stable/10@301811 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r299513,r299515:
ngie [Fri, 10 Jun 2016 18:21:05 +0000 (18:21 +0000)]
MFC r299513,r299515:

r299513 (by cem):

rtadvd(8): Don't use-after-free

This whole block of code as committed fully formed in r224144.  I'm not really
sure what the intent was, but it seems plausible that !persist ifis could need
other member cleanup.  Don't free the object until after we've finished
cleaning its members.

CID: 1006079

r299515 (by cem):

rtadvd(8): Fix use-after-close in cm_handler_client

cm_send() closes 'fd' on error.  In that case, bail out early without trying to
recv from or close 'fd' again.

CID: 1006078

git-svn-id: svn://svn.freebsd.org/base/stable/10@301809 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r299511:
ngie [Fri, 10 Jun 2016 18:13:41 +0000 (18:13 +0000)]
MFC r299511:
r299511 (by cem):

print_positional_test: Fix misuse of wchar APIs

These APIs take unit length, not byte length parameters.

CIDs: 133854313385441338545

git-svn-id: svn://svn.freebsd.org/base/stable/10@301808 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r299510:
ngie [Fri, 10 Jun 2016 18:10:32 +0000 (18:10 +0000)]
MFC r299510:
r299510 (by cem):

libmp: Fix trivial buffer overrun

fgetln yields a non-NUL-terminated buffer and its length.  This routine
attempted to NUL-terminate it, but did not allocate space for the NUL.  So,
allocate space for the NUL.

CID: 1017457

git-svn-id: svn://svn.freebsd.org/base/stable/10@301806 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r299508:
ngie [Fri, 10 Jun 2016 18:07:35 +0000 (18:07 +0000)]
MFC r299508:
r299508 (by cem):

kern_descrip_test: Fix trivial buffer overrun with readlink(2)

CID: 12299651229972

git-svn-id: svn://svn.freebsd.org/base/stable/10@301805 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r299507:
ngie [Fri, 10 Jun 2016 18:02:51 +0000 (18:02 +0000)]
MFC r299507:
r299507 (by cem):

rtadvd(8): Fix a typo in full msg receive logic

Check against the size of the struct, not the pointer.  Previously, a message
with a cm_len between 9 and 23 (inclusive) could cause int msglen to underflow
and read(2) to be invoked with msglen size (implicitly cast to signed),
overrunning the caller-provided buffer.

All users of cm_recv() supply a stack buffer.

On the other hand, the rtadvd control socket appears to only be writable by the
owner, who is probably root.

While here, correct some types to be size_t or ssize_t.

CID: 1008477
Security: unix socket remotes may overflow stack in rtadvd

git-svn-id: svn://svn.freebsd.org/base/stable/10@301803 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r300836:
ngie [Fri, 10 Jun 2016 17:57:50 +0000 (17:57 +0000)]
MFC r300836:

Quell false positives in svc_vc_create and svc_vc_create_conn with cd and xprt

Both cd and xprt will be non-NULL after their respective malloc(9) wrappers are
called (mem_alloc and svc_xprt_alloc, which calls mem_alloc) as mem_alloc
always gets called with M_WAITOK|M_ZERO today. Thus, testing for them being
non-NULL is incorrect -- it misleads Coverity and it misleads the reader.

Remove some unnecessary NULL initializations as a follow up to help solidify
the fact that these pointers will be initialized properly in sys/rpc/.. with
the interfaces the way they are currently.

CID: 100733810073391007340

git-svn-id: svn://svn.freebsd.org/base/stable/10@301801 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r299503,r299504:
ngie [Fri, 10 Jun 2016 15:47:20 +0000 (15:47 +0000)]
MFC r299503,r299504:

r299503 (by cem):

snd_hda(4): Don't pass bogus sizeof()s to unused sysctl arg2 parameter

None of the sysctl handlers in hdaa use the arg2 parameter, so just pass zero
instead.  Additionally, the sizes being passed in were suspect (size of the
pointer rather than the value).

CIDs: 10076941009679

r299504 (by cem):

snd_hda(4): Don't pass bogus sizeof()s to unused sysctl arg2 parameter (again)

More of the same sort of issue as r299503, just missed some sysctls added in a
different place than the others.

CIDs: 100769210096771009678

git-svn-id: svn://svn.freebsd.org/base/stable/10@301799 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r299502:
ngie [Fri, 10 Jun 2016 15:42:17 +0000 (15:42 +0000)]
MFC r299502:
r299502 (by cem):

nss/gethostby_test: fix broken vector iteration of gethostbyaddr h_aliases

h_aliases is a NULL-terminated rather than fixed-length array.  nitems() is not
a valid way to determine its end; instead, check for NULL.

CID: 1346578

git-svn-id: svn://svn.freebsd.org/base/stable/10@301798 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r301295:
cy [Fri, 10 Jun 2016 15:03:18 +0000 (15:03 +0000)]
MFC r301295:

Enable daily_ntpd_leapfile_enable by default. Otherwise an expired
leapfile will be ignored and ntpd will behave as if it has no
leapfile.

While here, remove an extraneous blank line.

Suggested by: ache

git-svn-id: svn://svn.freebsd.org/base/stable/10@301795 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r299496:
ngie [Fri, 10 Jun 2016 14:51:11 +0000 (14:51 +0000)]
MFC r299496:
r299496 (by cem):

atf map: Fix double-free in low memory error path

If atf_list_append(, X, ) fails, X is freed.  Don't free it again.

CID: 979936

git-svn-id: svn://svn.freebsd.org/base/stable/10@301793 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r299495:
ngie [Fri, 10 Jun 2016 14:48:10 +0000 (14:48 +0000)]
MFC r299495:
r299495 (by cem):

libkrb5: Fix potential double-free

If krb5_make_principal fails, tmp_creds.server may remain a pointer to freed
memory and then be double-freed.  After freeing it the first time, initialize
it to NULL, which causes subsequent krb5_free_principal calls to do the right
thing.

CID: 1273430

git-svn-id: svn://svn.freebsd.org/base/stable/10@301792 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r299494:
ngie [Fri, 10 Jun 2016 14:45:20 +0000 (14:45 +0000)]
MFC r299494:
r299494 (by cem):

subr_vmem: Fix double-free in error case of vmem_create

If vmem_init() fails, 'vm' is already destroyed and freed.  Don't free it
again.

CID: 1042110

git-svn-id: svn://svn.freebsd.org/base/stable/10@301791 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r299491:
ngie [Fri, 10 Jun 2016 14:40:41 +0000 (14:40 +0000)]
MFC r299491:
r299491 (by cem):

route6d(8): Fix potential double-free

In the case that the subsequent sysctl(3) call failed, 'buf' could be free(3)ed
repeatedly.  It isn't clear to me that that case is possible, but be clear and
do the right thing in case it is.

CID: 272537

git-svn-id: svn://svn.freebsd.org/base/stable/10@301789 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r299490:
ngie [Fri, 10 Jun 2016 14:33:21 +0000 (14:33 +0000)]
MFC r299490:
r299490 (by cem):

camcontrol(8): Fix another trivial double-free

CID: 1331222

git-svn-id: svn://svn.freebsd.org/base/stable/10@301788 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r299489:
ngie [Fri, 10 Jun 2016 14:31:03 +0000 (14:31 +0000)]
MFC r299489:
r299489 (by cem):

camcontrol(8): Fix trival double-free

CID: 1331223

git-svn-id: svn://svn.freebsd.org/base/stable/10@301786 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r299461:
ngie [Fri, 10 Jun 2016 14:13:24 +0000 (14:13 +0000)]
MFC r299461:
r299461 (by cem):

ffs_bswap: Copy one UFS dinode member at a time

No functional change.

CIDs: 974635, 974636, 977396, 977397, 977398, 977399

git-svn-id: svn://svn.freebsd.org/base/stable/10@301784 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r299460:
ngie [Fri, 10 Jun 2016 14:08:41 +0000 (14:08 +0000)]
MFC r299460:
r299460 (by cem):

fsck_ffs: Don't overrun mount device buffer

Maybe this case is impossible.  Either way, when attempting to "/dev/"-prefix a
non-global device name, check that we do not overrun the f_mntfromname buffer.

In this case, truncating (with strlcpy or similar) would not be useful, since
the f_mntfromname result of getmntpt() is passed directly to open(2) later.

CID: 1006789

git-svn-id: svn://svn.freebsd.org/base/stable/10@301782 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r299387:
ngie [Fri, 10 Jun 2016 13:57:56 +0000 (13:57 +0000)]
MFC r299387:
r299387 (by cem):

netipsec: Fix minor style nit

Coverity points out that 'continue' is equivalent to 'break' in a do {}
while(false) loop.

CID: 1354983

git-svn-id: svn://svn.freebsd.org/base/stable/10@301780 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r301278
kib [Fri, 10 Jun 2016 04:04:55 +0000 (04:04 +0000)]
MFC r301278
Reduce number of iterations used for calibrating ICR read loop.

MFC r301279:
Record correct commit message for r301278.

git-svn-id: svn://svn.freebsd.org/base/stable/10@301776 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r300779, r300781, r300783, r300784, r300949, r301162, r301180
truckman [Fri, 10 Jun 2016 00:00:25 +0000 (00:00 +0000)]
MFC r300779, r300781, r300783, r300784, r300949, r301162, r301180

r300779 | truckman | 2016-05-26 14:40:13 -0700 (Thu, 26 May 2016) | 64 lines

Import Dummynet AQM version 0.2.1 (CoDel, FQ-CoDel, PIE and FQ-PIE).

Centre for Advanced Internet Architectures

Implementing AQM in FreeBSD

* Overview <http://caia.swin.edu.au/freebsd/aqm/index.html>

* Articles, Papers and Presentations
  <http://caia.swin.edu.au/freebsd/aqm/papers.html>

* Patches and Tools <http://caia.swin.edu.au/freebsd/aqm/downloads.html>

Overview

Recent years have seen a resurgence of interest in better managing
the depth of bottleneck queues in routers, switches and other places
that get congested. Solutions include transport protocol enhancements
at the end-hosts (such as delay-based or hybrid congestion control
schemes) and active queue management (AQM) schemes applied within
bottleneck queues.

The notion of AQM has been around since at least the late 1990s
(e.g. RFC 2309). In recent years the proliferation of oversized
buffers in all sorts of network devices (aka bufferbloat) has
stimulated keen community interest in four new AQM schemes -- CoDel,
FQ-CoDel, PIE and FQ-PIE.

The IETF AQM working group is looking to document these schemes,
and independent implementations are a corner-stone of the IETF's
process for confirming the clarity of publicly available protocol
descriptions. While significant development work on all three schemes
has occured in the Linux kernel, there is very little in FreeBSD.

Project Goals

This project began in late 2015, and aims to design and implement
functionally-correct versions of CoDel, FQ-CoDel, PIE and FQ_PIE
in FreeBSD (with code BSD-licensed as much as practical). We have
chosen to do this as extensions to FreeBSD's ipfw/dummynet firewall
and traffic shaper. Implementation of these AQM schemes in FreeBSD
will:
* Demonstrate whether the publicly available documentation is
  sufficient to enable independent, functionally equivalent implementations

* Provide a broader suite of AQM options for sections the networking
  community that rely on FreeBSD platforms

Program Members:

* Rasool Al Saadi (developer)

* Grenville Armitage (project lead)

Acknowledgements:

This project has been made possible in part by a gift from the
Comcast Innovation Fund.

Submitted by: Rasool Al-Saadi <ralsaadi@swin.edu.au>
X-No objection: core
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D6388

[Remove some code that was added to the mq_append() inline function in
HEAD by r258457, which was not merged to stable/10.  The AQM patch
moved mq_append() from ip_dn_io.c to the new file ip_dn_private.h, so
we need to remove that copy of the r258457 changes.]
------------------------------------------------------------------------
r300781 | truckman | 2016-05-26 14:44:52 -0700 (Thu, 26 May 2016) | 7 lines

Modify BOUND_VAR() macro to wrap all of its arguments in () and tweak
its expression to work on powerpc and sparc64 (gcc compatibility).

Correct a typo in a nearby comment.

MFC after: 2 weeks (with r300779)

------------------------------------------------------------------------
r300783 | truckman | 2016-05-26 15:03:28 -0700 (Thu, 26 May 2016) | 4 lines

Correct a typo in a comment.

MFC after: 2 weeks (with r300779)

------------------------------------------------------------------------
r300784 | truckman | 2016-05-26 15:07:09 -0700 (Thu, 26 May 2016) | 5 lines

Include the new AQM files when compiling a kernel with options DUMMYNET.

Reported by: Nikolay Denev <nike_d AT cytexbg DOT com>
MFC after: 2 weeks (with r300779)

------------------------------------------------------------------------
r300949 | truckman | 2016-05-29 00:23:56 -0700 (Sun, 29 May 2016) | 10 lines

Cast some expressions that multiply a long long constant by a
floating point constant to int64_t.  This avoids the runtime
conversion of the the other operand in a set of comparisons from
int64_t to floating point and doing the comparisions in floating
point.

Suggested by: lidl
Submitted by: Rasool Al-Saadi <ralsaadi@swin.edu.au>
MFC after: 2 weeks (with r300779)

------------------------------------------------------------------------
r301162 | truckman | 2016-06-01 13:04:24 -0700 (Wed, 01 Jun 2016) | 9 lines

Replace constant expressions that contain multiplications by
fractional floating point values with integer divides.  This will
eliminate any chance that the compiler will generate code to evaluate
the expression using floating point at runtime.

Suggested by: bde
Submitted by: Rasool Al-Saadi <ralsaadi@swin.edu.au>
MFC after: 8 days (with r300779 and r300949)

------------------------------------------------------------------------
r301180 | truckman | 2016-06-01 17:42:15 -0700 (Wed, 01 Jun 2016) | 2 lines

Belatedly bump .Dd date for Dummynet AQM import in r300779.

Relnotes: yes

git-svn-id: svn://svn.freebsd.org/base/stable/10@301772 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r301513:
pfg [Thu, 9 Jun 2016 16:29:19 +0000 (16:29 +0000)]
MFC r301513:
indent(1): Fix old typo.

It's typedef, not typdef.

Obtained from: NetBSD (CVS rev. 1.14)

git-svn-id: svn://svn.freebsd.org/base/stable/10@301743 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f

7 years agoMFC r301465:
bdrewery [Thu, 9 Jun 2016 15:43:00 +0000 (15:43 +0000)]
MFC r301465:

  Fix bmake version upgrade logic to use the new bmake.

The '${WANT_MAKE} != "bmake"' logic seems wrong but is not being modified.

git-svn-id: svn://svn.freebsd.org/base/stable/10@301738 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f