]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
4 years agopmc: restore "unhalted-cycles" alias
Matt Macy [Thu, 15 Aug 2019 21:39:21 +0000 (21:39 +0000)]
pmc: restore "unhalted-cycles" alias

Reported by: mav@

4 years agoMFC r350576: ipfw: fix jail option after r348215
Kyle Evans [Thu, 15 Aug 2019 17:40:48 +0000 (17:40 +0000)]
MFC r350576: ipfw: fix jail option after r348215

r348215 changed jail_getid(3) to validate passed-in jids as active jails
(as the function is documented to return -1 if the jail does not exist).
This broke the jail option (in some cases?) as the jail historically hasn't
needed to exist at the time of rule parsing; jids will get stored and later
applied.

Fix this caller to attempt to parse *av as a number first and just use it
as-is to match historical behavior. jail_getid(3) must still be used in
order for name arguments to work, but it's strictly a fallback in case we
weren't given a number.

4 years agoMFC 348695: Support MSI-X for passthrough devices with a separate PBA BAR.
John Baldwin [Wed, 14 Aug 2019 23:31:53 +0000 (23:31 +0000)]
MFC 348695: Support MSI-X for passthrough devices with a separate PBA BAR.

pci_alloc_msix() requires both the table and PBA BARs to be allocated
by the driver.  ppt was only allocating the table BAR so would fail
for devices with the PBA in a separate BAR.  Fix this by allocating
the PBA BAR before pci_alloc_msix() if it is stored in a separate BAR.

While here, release BARs after calling pci_release_msi() instead of
before.  Also, don't call bus_teardown_intr() in error handling code
if bus_setup_intr() has just failed.

4 years agoMFC 348694: Don't simulate PBA access if the PBA is in a separate BAR.
John Baldwin [Wed, 14 Aug 2019 23:28:43 +0000 (23:28 +0000)]
MFC 348694: Don't simulate PBA access if the PBA is in a separate BAR.

bhyve has to virtualize the MSI-X table to trap reads and writes to
that table and map those to virtual interrupts that it maps real host
interrupts on to.  For the pending-bit-array (PBA), bhyve passes
accesses from the guest directly to the hardware.

bhyve's virtualization of the MSI-X table is done by intercepting all
reads and writes to the BAR holding the MSI-X table.  However, if the
PBA is stored in the same BAR as the MSI-X table, accesses to the PBA
portion of this BAR have to be forwarded to the real BAR.

However, in the case that the PBA was stored in a separate BAR and
it's offset in that separate BAR overlapped with the portion of the
MSI-X table BAR that the table used, the handlers for the table BAR
would incorrectly think that some accesses were PBA reads and writes.
This caused a crash in bhyve when it indirected a NULL pointer.  Fix
this case by never trying to handle PBA access if the PBA lives in a
separate BAR.

4 years agoMFC 347465: Apply r280991 to ip6_fragment.
John Baldwin [Wed, 14 Aug 2019 23:25:58 +0000 (23:25 +0000)]
MFC 347465: Apply r280991 to ip6_fragment.

This uses m_dup_pkthdr() to copy all of the metadata about a packet to
each of its fragments including VLAN tags, mbuf tags, etc. instead of
hand-copying a few fields.

4 years agoMFC 346360: Push down INP_WLOCK slightly in tcp_ctloutput.
John Baldwin [Wed, 14 Aug 2019 23:05:57 +0000 (23:05 +0000)]
MFC 346360: Push down INP_WLOCK slightly in tcp_ctloutput.

The inp lock is not needed for testing the V6 flag as that flag is set
once when the inp is created and never changes.  For non-TCP socket
options the lock is immediately dropped after checking that flag.
This just pushes the lock down to only be acquired for TCP socket
options.

This isn't a hot-path, more a cosmetic cleanup I noticed while reading
the code.

4 years agoMFC r350697:
Dimitry Andric [Wed, 14 Aug 2019 19:21:26 +0000 (19:21 +0000)]
MFC r350697:

Fix a possible segfault in wcsxfrm(3) and wcsxfrm_l(3).

If the length of the source wide character string, passed in via the
"size_t n" parameter, is set to zero, the function should only return
the required length for the destination wide character string.  In this
case, it should *not* attempt to write to the destination, so the "dst"
parameter is permitted to be NULL.

However, when the internally called _collate_wxfrm() function returns an
error, such as when using the "C" locale, as a fallback wcscpy(3) or
wcsncpy(3) are used.  But if the input length is zero, wcsncpy(3) will
be called with a length of -1!  If the "dst" parameter is NULL, this
will immediately result in a segfault, or if "dst" is a valid pointer,
it will most likely result in unexpectedly overwritten memory.

Fix this by explicitly checking for an input length greater than zero,
before calling wcsncpy(3).

Note that a similar situation does not occur in strxfrm(3), the plain
character version of this function, as it uses strlcpy(3) for the error
case.  The strlcpy(3) function does not write to the destination if the
input length is zero.

4 years agoMFC r350112, r350241, and r350242:
Andrew Turner [Wed, 14 Aug 2019 17:02:36 +0000 (17:02 +0000)]
MFC r350112, r350241, and r350242:

r350166:
arm64: Implement HWCAP

Add HWCAP support for arm64.
defines are the same as in Linux and a userland program can use
elf_aux_info to get the data.
We only save the common denominator for all cores in case the
big and little cluster have different support (this is known to
exists even if we don't support those SoCs in FreeBSD)

Differential Revision: https://reviews.freebsd.org/D17137

r350241:
Ensure the arm64 ID register fields are 64 bit types.

Previously only some of the ID register fields were 64 bit. To allow
for a script to generate these mark them all 64 bit. To allow for their
use in assembly we need to use the UINT64_C macro via a new UL macro
to stop the lines from being too long.

Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D20977

r350242:
As with r350241 use the new UL macro on the main register mask.

Sponsored by: DARPA, AFRL

4 years agoMFC r345510:
Andrew Turner [Wed, 14 Aug 2019 16:54:51 +0000 (16:54 +0000)]
MFC r345510:
Sort printing of the ID registers on arm64 to be identical to the
documentation. This will simplify checking new fields when they are added.

4 years agoMFC r339593:
Andrew Turner [Wed, 14 Aug 2019 16:45:16 +0000 (16:45 +0000)]
MFC r339593:
Fix the ID_AA64ISAR0_EL1 dot product field shift.

It's 44 in the documentation, use this correct value.

4 years agoMFC r339592:
Andrew Turner [Wed, 14 Aug 2019 16:40:23 +0000 (16:40 +0000)]
MFC r339592:
Correctly set the DAIF bits in new threads

We should only unmask interrupts when creating a new thread and leave the
other exceptions in teh same state as before creating the thread.

4 years agoMFC r350497: ppp: correct echo-req magic number on big endian archs
Ed Maste [Wed, 14 Aug 2019 13:14:47 +0000 (13:14 +0000)]
MFC r350497: ppp: correct echo-req magic number on big endian archs

The magic number is a 32-bit quantity; use uint32_t to match hton's
return type and avoid sending zeros (upper 32 bits) on big-endian
architectures.

PR: 184141
Sponsored by: The FreeBSD Foundation

4 years agoMFC r350484, r350607, r350608:
Konstantin Belousov [Wed, 14 Aug 2019 09:56:58 +0000 (09:56 +0000)]
MFC r350484, r350607, r350608:
Make randomized stack gap between strings and pointers to argv/envs.

4 years agoMFC r350757:
Konstantin Belousov [Wed, 14 Aug 2019 09:49:28 +0000 (09:49 +0000)]
MFC r350757:
Update comment explaining create_init().

4 years agoMFC r350758:
Konstantin Belousov [Wed, 14 Aug 2019 09:44:48 +0000 (09:44 +0000)]
MFC r350758:
Fix stack grow for init.

4 years agoMFC r350675:
Hans Petter Selasky [Wed, 14 Aug 2019 09:43:27 +0000 (09:43 +0000)]
MFC r350675:
Correct PCI device ID for XHCI USB controller.

Submitted by: Dmitry Luhtionov <dmitryluhtionov@gmail.com>
Sponsored by: Mellanox Technologies

4 years agoMFC r350396:
Hans Petter Selasky [Wed, 14 Aug 2019 09:40:12 +0000 (09:40 +0000)]
MFC r350396:
Add support for tethering with Nokia 7 plus and the alike.

PR: 239495
Sponsored by: Mellanox Technologies

4 years agoMFC r350861:
Konstantin Belousov [Wed, 14 Aug 2019 09:39:39 +0000 (09:39 +0000)]
MFC r350861:
wait(2): clarify reparenting of children of the exiting process.

4 years agoMFC r350860:
Konstantin Belousov [Wed, 14 Aug 2019 09:38:55 +0000 (09:38 +0000)]
MFC r350860:
wait(2): split long line by using .Fo/.Fa instead of .Ft.

4 years agoMFC r350481, r350483:
Konstantin Belousov [Wed, 14 Aug 2019 09:37:43 +0000 (09:37 +0000)]
MFC r350481, r350483:
Avoid conflicts with libc symbols in libthr jump table.

4 years agoMFC r350855: Upgrade to Bzip2 version 1.0.8.
Xin LI [Wed, 14 Aug 2019 06:39:20 +0000 (06:39 +0000)]
MFC r350855: Upgrade to Bzip2 version 1.0.8.

4 years agoMFC r350961: Missed part of r350523.
Alexander Motin [Tue, 13 Aug 2019 19:17:44 +0000 (19:17 +0000)]
MFC r350961: Missed part of r350523.

4 years agoMFC r350639:
Konstantin Belousov [Tue, 13 Aug 2019 13:47:03 +0000 (13:47 +0000)]
MFC r350639:
amd64: prevents speculations over swapgs reload of %gs base.

4 years agoMFC r348250:
Piotr Kubaj [Mon, 12 Aug 2019 23:44:03 +0000 (23:44 +0000)]
MFC r348250:
Add snd_hda(4) to GENERIC64 used by powerpc64.

amd64 also has snd_hda(4) in GENERIC.

Approved by: jhibbits (src committer), linimon (mentor)

4 years agoMFC r350207:
Alan Somers [Mon, 12 Aug 2019 20:32:47 +0000 (20:32 +0000)]
MFC r350207:

VOP_PATHCONF.9: correct the type of the retval argument

It was changed from int to register_t in r22521 and from register_t to long
in r328099, but the man page wasn't updated either time.

4 years agoMFC r349248, r349391, r350088
Alan Somers [Mon, 12 Aug 2019 20:31:12 +0000 (20:31 +0000)]
MFC r349248, r349391, r350088

r349248:
fcntl: fix overflow when setting F_READAHEAD

VOP_READ and VOP_WRITE take the seqcount in blocks in a 16-bit field.
However, fcntl allows you to set the seqcount in bytes to any nonnegative
31-bit value. The result can be a 16-bit overflow, which will be
sign-extended in functions like ffs_read. Fix this by sanitizing the
argument in kern_fcntl. As a matter of policy, limit to IO_SEQMAX rather
than INT16_MAX.

Also, fifos have overloaded the f_seqcount field for a completely different
purpose ever since r238936.  Formalize that by using a union type.

Reviewed by: cem
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D20710

r349391:
fcntl: style changes to r349248

Reported by: bde
MFC-With: 349248
Sponsored by: The FreeBSD Foundation

r350088:
F_READAHEAD: Fix r349248's overflow protection, broken by r349391

I accidentally broke the main point of r349248 when making stylistic changes
in r349391.  Restore the original behavior, and also fix an additional
overflow that was possible when uio->uio_resid was nearly SSIZE_MAX.

Reported by: cem
Reviewed by: bde
MFC-With: 349248
Sponsored by: The FreeBSD Foundation

4 years agoMFC r349231, r349233, r349280, r349478
Alan Somers [Mon, 12 Aug 2019 20:21:36 +0000 (20:21 +0000)]
MFC r349231, r349233, r349280, r349478

r349231:
Add FIOBMAP2 ioctl

This ioctl exposes VOP_BMAP information to userland. It can be used by
programs like fragmentation analyzers and optimized cp implementations. But
I'm using it to test fusefs's VOP_BMAP implementation. The "2" in the name
distinguishes it from the similar but incompatible FIBMAP ioctls in NetBSD
and Linux.  FIOBMAP2 differs from FIBMAP in that it uses a 64-bit block
number instead of 32-bit, and it also returns runp and runb.

Reviewed by: mckusick
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D20705

r349233:
#include <sys/types.h> from sys/filio.h

This fixes world build after r349231

Reported by: Jenkins
MFC-With: 349231
Sponsored by: The FreeBSD Foundation

r349280:
Reduce namespace pollution from r349233

Define __daddr_t in _types.h and use it in filio.h

Reported by: ian, bde
Reviewed by: ian, imp, cem
MFC-With: 349233
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D20715

r349478:
FIOBMAP2: inline vn_ioc_bmap2

Reported by: kib
Reviewed by: kib
MFC-With: 349238
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D20783

4 years agoMFC r350652 (by imp): Fix mismerge.
Alexander Motin [Mon, 12 Aug 2019 19:44:57 +0000 (19:44 +0000)]
MFC r350652 (by imp): Fix mismerge.

I merged passthru.c from the wrong branch (it was a branch that went further in
a direction I wound up not taking). Fix the mismerge and turn passthru on.

4 years agoMFC r350599, r350609: Add `nvmecontrol resv` to handle NVMe reservations.
Alexander Motin [Mon, 12 Aug 2019 19:44:28 +0000 (19:44 +0000)]
MFC r350599, r350609: Add `nvmecontrol resv` to handle NVMe reservations.

NVMe reservations are quite alike to SCSI persistent reservations and
can be used in clustered setups with shared multiport storage.

Relnotes: yes

4 years agoMFC r350563: Add `nvmecontrol sanitize` command.
Alexander Motin [Mon, 12 Aug 2019 19:43:25 +0000 (19:43 +0000)]
MFC r350563: Add `nvmecontrol sanitize` command.

It allows to delete all user data from NVM subsystem in one of 3 methods.
It is a close equivalent of SCSI SANITIZE command of `camcontrol sanitize`,
so I tried to keep arguments as close as possible.

While there, fix supported sanitize methods reporting in `identify`.

MFC after: yes

4 years agoMFC r350555: Fix parameter check broken at r350057.
Alexander Motin [Mon, 12 Aug 2019 19:42:43 +0000 (19:42 +0000)]
MFC r350555: Fix parameter check broken at r350057.

4 years agoMFC r350553: Add more random bits from NVMe 1.4.
Alexander Motin [Mon, 12 Aug 2019 19:42:07 +0000 (19:42 +0000)]
MFC r350553: Add more random bits from NVMe 1.4.

4 years agoMFC r350541: Decode few more NVMe log pages.
Alexander Motin [Mon, 12 Aug 2019 19:41:35 +0000 (19:41 +0000)]
MFC r350541: Decode few more NVMe log pages.

In particular: Changed Namespace List, Commands Supported and Effects,
Reservation Notification, Sanitize Status.

Add few new arguments to `nvmecontrol log` subcommand.

4 years agoMFC r350529, r350530: Add more new fields and values from NVMe 1.4.
Alexander Motin [Mon, 12 Aug 2019 19:40:40 +0000 (19:40 +0000)]
MFC r350529, r350530: Add more new fields and values from NVMe 1.4.

4 years agoMFC r350523, r350524: Add IOCTL to translate nvdX into nvmeY and NSID.
Alexander Motin [Mon, 12 Aug 2019 19:39:31 +0000 (19:39 +0000)]
MFC r350523, r350524: Add IOCTL to translate nvdX into nvmeY and NSID.

While very useful by itself, it also makes `nvmecontrol` not depend on
hardcoded device names parsing, that in its turn makes simple to take
nvdX (and potentially any other) device names as arguments.

Also added IOCTL bypass from nvdX to respective nvmeYnsZ makes them
interchangeable for management purposes.

4 years agoMFC r350477: Feature-complete NVMe Namespace Management.
Alexander Motin [Mon, 12 Aug 2019 19:38:10 +0000 (19:38 +0000)]
MFC r350477: Feature-complete NVMe Namespace Management.

This adds several previously missed but important subcommands to list
namespaces and controllers.  It also fixes few previously added but
just found with real testing to be broken subcommands.

Also while there, add possibility to explicitly specify nsid for
`nvmecontrol identify` subcommand.  It may be useful to specify nsids
not having own devices, for example 0xffffffff, or just newly created
ones.

4 years agoMFC r350462: Tune some commands desctiption.
Alexander Motin [Mon, 12 Aug 2019 18:59:20 +0000 (18:59 +0000)]
MFC r350462: Tune some commands desctiption.

4 years agoMFC r350461: Fix usage printing for nested subcommands.
Alexander Motin [Mon, 12 Aug 2019 18:58:51 +0000 (18:58 +0000)]
MFC r350461: Fix usage printing for nested subcommands.

Instead of `nvmecontrol create` should be `nvmecontrol ns create`, etc.

4 years agoMFC r350399: Add some new fields and bits from NVMe 1.4.
Alexander Motin [Mon, 12 Aug 2019 18:58:20 +0000 (18:58 +0000)]
MFC r350399: Add some new fields and bits from NVMe 1.4.

4 years agoMFC r350333 (by imp): Widen the type for to.
Alexander Motin [Mon, 12 Aug 2019 18:57:46 +0000 (18:57 +0000)]
MFC r350333 (by imp): Widen the type for to.

The timeout field in the CAPS register is defined to be 8 bits, so its type was
uint8_t. We recently started adding 1 to it to cope with rogue devices that
listed 0 timeout time (which is impossible). However, in so doing, other devices
that list 0xff (for a 2 minute timeout) were broken when adding 1
overflowed. Widen the type to be uint32_t like its source register to avoid the
issue.

4 years agoMFC r350311 (by imp):
Alexander Motin [Mon, 12 Aug 2019 18:56:46 +0000 (18:56 +0000)]
MFC r350311 (by imp):
Fix the fix to the logic bug. Upon further testing, the bug is that we shadoow
opt.vendor with vendor. We shouldn't. Delete the latter and use the former
everywhere and restore the prior logic which is now correct.

4 years agoMFC r350309 (by imp): Fix several related coverity issues:
Alexander Motin [Mon, 12 Aug 2019 18:56:11 +0000 (18:56 +0000)]
MFC r350309 (by imp): Fix several related coverity issues:

Make sure to always free shortopts and lopts when returning.
Fix minor logic bug to guard against NULLs properly.

CID: 140365414036561403658

4 years agoMFC r350147 (by imp): Keep track of the number of commands that exhaust their retry...
Alexander Motin [Mon, 12 Aug 2019 18:55:36 +0000 (18:55 +0000)]
MFC r350147 (by imp): Keep track of the number of commands that exhaust their retry limit.

While we print failure messages on the console, sometimes logs are lost or
overwhelmed. Keeping a count of how many times we've failed retriable commands
helps get a magnitude of the problem.

4 years agoMFC r350146 (by imp): Keep track of the number of retried commands.
Alexander Motin [Mon, 12 Aug 2019 18:54:58 +0000 (18:54 +0000)]
MFC r350146 (by imp): Keep track of the number of retried commands.

Retried commands can indicate a performance degredation of an nvme drive. Keep
track of the number of retries and report it out via sysctl, just like number of
commands an interrupts.

4 years agoMFC r350120 (by imp): Use sysctl + CTLRWTUN for hw.nvme.verbose_cmd_dump.
Alexander Motin [Mon, 12 Aug 2019 18:54:24 +0000 (18:54 +0000)]
MFC r350120 (by imp): Use sysctl + CTLRWTUN for hw.nvme.verbose_cmd_dump.

Also convert it to a bool. While the rest of the driver isn't yet bool clean,
this will help.

4 years agoMFC r350118 (by imp): Provide new tunable hw.nvme.verbose_cmd_dump
Alexander Motin [Mon, 12 Aug 2019 18:53:53 +0000 (18:53 +0000)]
MFC r350118 (by imp): Provide new tunable hw.nvme.verbose_cmd_dump

The nvme drive dumps only the most relevant details about a command when it
fails. However, there are times this is not sufficient (such as debugging weird
issues for a new drive with a vendor). Setting hw.nvme.verbose_cmd_dump=1
in loader.conf will enable more complete debugging information about each
command that fails.

4 years agoMFC r350114 (by imp):
Alexander Motin [Mon, 12 Aug 2019 18:53:01 +0000 (18:53 +0000)]
MFC r350114 (by imp):
Provide macros to extract the sub-fields of the CAP_LO and CAP_HI registers.

These macros make places where we extract these easier to read. The shift and
mask stuff is also a bit tedious and error prone. Start with the CAP_LO and
CAP_HI registers since their scope is somewhat constrained. This is style
chagne only, no functional changes.

4 years agoMFC r350094 (by imp): Remove now-obsolete comment.
Alexander Motin [Mon, 12 Aug 2019 18:52:10 +0000 (18:52 +0000)]
MFC r350094 (by imp): Remove now-obsolete comment.

4 years agoMFC r350068 (by imp): Assume that the timeout value from the capacity is 1-based
Alexander Motin [Mon, 12 Aug 2019 18:51:35 +0000 (18:51 +0000)]
MFC r350068 (by imp): Assume that the timeout value from the capacity is 1-based

Neither the 1.3 or 1.4 standards say this number is 1's based, but adding 1
costs little and copes with those NVMe drives that report '0' in this field
cheaply. This is consistent with what the Linux driver does as well.

4 years agoMFC r350058 (by imp): Implement {io,admin}-passthru commands.
Alexander Motin [Mon, 12 Aug 2019 18:50:57 +0000 (18:50 +0000)]
MFC r350058 (by imp): Implement {io,admin}-passthru commands.

These are mostly compatible with Linux, with three exceptions.
1. We don't do metadata segment stuff. Our passthrough interface
   doesn't cope. The code is there, but generates an error.
2. Linux lets you specify a namespace ID for the command. We current
   do not: we get ours from the namespace device, or pass in a generic
   one. Generally, this will lead to the same command, but FreeBSD's
   is safer since you can't specify the wrong id.
3. --show-command outputs to stderr instead of stdout so you can both
   see your command, and capture its output with a simple redirect.

4 years agoMFC r350057 (by imp): Create generic command / arg parsing routines
Alexander Motin [Mon, 12 Aug 2019 18:50:26 +0000 (18:50 +0000)]
MFC r350057 (by imp): Create generic command / arg parsing routines

Create a set of routines and structures to hold the data for the args
for a command. Use them to generate help and to parse args. Convert
all the current commands over to the new format. "comnd" is a hat-tip
to the TOPS-20 %COMND JSYS that (very) loosely inspired much of the
subsequent command line notions in the industry, but this is far
simpler (the %COMND man page is longer than this code) and not in the
kernel... Also, it implements today's de-facto
        command [verb]+ [opts]* [args]*
format rather than the old, archaic TOPS-20 command format :)

This is a snapshot of a work in progress to get the nvme passthru
stuff committed. In time it will become a private library and used
by some other programs in the tree that conform to the above pattern.

4 years agoMFC r348495 (by imp):
Alexander Motin [Mon, 12 Aug 2019 18:49:32 +0000 (18:49 +0000)]
MFC r348495 (by imp):
Since a fatal trap can happen at aribtrary times, don't panic when the
completions are not in a consistent state. Cope with the different
places the normal I/O completion polling thread can be interrupted and
then re-entered during a kernel panic + dump.

4 years agoMFC r347939 (by scottl): Better formatting for the logpage section
Alexander Motin [Mon, 12 Aug 2019 18:48:47 +0000 (18:48 +0000)]
MFC r347939 (by scottl): Better formatting for the logpage section

4 years agoMFC r347369 (by imp): rename nvme_ctrlr_destroy_qpair to nvme_ctrlr_destroy_qpairs
Alexander Motin [Mon, 12 Aug 2019 18:48:17 +0000 (18:48 +0000)]
MFC r347369 (by imp): rename nvme_ctrlr_destroy_qpair to nvme_ctrlr_destroy_qpairs

Maintain symmetry with nvme_ctrlr_create_qpairs, making it easier to
match init/uninit scenarios.

4 years agoMFC r344955 (by imp):
Alexander Motin [Mon, 12 Aug 2019 18:47:40 +0000 (18:47 +0000)]
MFC r344955 (by imp):
Don't print all the I/O we abort on a reset, unless we're out of
retries.

When resetting the controller, we abort I/O. Prior to this fix, we
printed a ton of abort messages for I/O that we're going to
retry. This imparts no useful information. Stop printing them unless
our retry count is exhausted. Clarify code for when we don't retry,
and remove useless arg to a routine that's always called with it
as 'true'. All the other debug is still printed (including multiple
reset messages if we have multiple timeouts before the taskqueue
runs the actual reset) so that we know when we reset.

4 years agoMFC r344469 (by imp): Rework logpage extensibility.
Alexander Motin [Mon, 12 Aug 2019 17:56:16 +0000 (17:56 +0000)]
MFC r344469 (by imp): Rework logpage extensibility.

Move from using a linker set to a constructor function that's
called. This simplifies the code and is slightly more obvious.  We now
keep a list of page decoders rather than having an array we managed
before. Commands will move to something similar in the future.

4 years agoMFC r344191 (by imp): Remove write-only s_flag.
Alexander Motin [Mon, 12 Aug 2019 17:55:25 +0000 (17:55 +0000)]
MFC r344191 (by imp): Remove write-only s_flag.

4 years agoMFC r342358 (by imp): Try the first 256 units with nvmecontrol devlist.
Alexander Motin [Mon, 12 Aug 2019 17:54:28 +0000 (17:54 +0000)]
MFC r342358 (by imp): Try the first 256 units with nvmecontrol devlist.

The nvmecontrol code that did the devlist assumed that we had a
tightly-packed allocation of units. Since pci writing exists, this
isn't the case. Loop over the first 256 units, which is a reasonable
number of possible units.

4 years agoMFC r341664 (by imp):
Alexander Motin [Mon, 12 Aug 2019 17:53:23 +0000 (17:53 +0000)]
MFC r341664 (by imp):
Update paths based on last-minute changes from libexec to lib.

4 years agoMFC r341663 (by imp):
Alexander Motin [Mon, 12 Aug 2019 17:52:45 +0000 (17:52 +0000)]
MFC r341663 (by imp):
Declare global function print_intel_add_smart in header

4 years agoMFC r341662 (by imp): Use proper prototypes.
Alexander Motin [Mon, 12 Aug 2019 17:52:03 +0000 (17:52 +0000)]
MFC r341662 (by imp): Use proper prototypes.

4 years agoMFC r341661 (by imp): It's useful to have this be a global function.
Alexander Motin [Mon, 12 Aug 2019 17:51:28 +0000 (17:51 +0000)]
MFC r341661 (by imp): It's useful to have this be a global function.

Other vendors base their additional smart info pages on what Intel did
plus some other bits. So it's convenient to have this be global.

4 years agoMFC r341660 (by imp): This is not a samsung standard, so remove that alias.
Alexander Motin [Mon, 12 Aug 2019 17:50:18 +0000 (17:50 +0000)]
MFC r341660 (by imp): This is not a samsung standard, so remove that alias.

This was never documented, and isn't needed, so it's best removed to
avoid confusion.

4 years agoMFC r341659 (by imp): Move intel and wdc files to their own modules
Alexander Motin [Mon, 12 Aug 2019 17:49:44 +0000 (17:49 +0000)]
MFC r341659 (by imp): Move intel and wdc files to their own modules

Move the intel and wdc vendor specific stuff to their own modules.

4 years agoMFC r341658 (by imp): Const poison the command interface
Alexander Motin [Mon, 12 Aug 2019 17:49:06 +0000 (17:49 +0000)]
MFC r341658 (by imp): Const poison the command interface

Make the pointers we pass into the commands const, also make the
linker set mirrors const.

4 years agoMFC r341657 (by imp): Dynamically load .so modules to expand functionality
Alexander Motin [Mon, 12 Aug 2019 17:48:14 +0000 (17:48 +0000)]
MFC r341657 (by imp): Dynamically load .so modules to expand functionality

o Dynamically load all the .so files found in /libexec/nvmecontrol and
  /usr/local/libexec/nvmecontrol.
o Link nvmecontrol -rdynamic so that its symbols are visible to the
  libraries we load.
o Create concatinated linker sets that we dynamically expand.
o Add the linked-in top and logpage linker sets to the mirrors for them
  and add those sets to the mirrors when we load a new .so.
o Add some macros to help hide the names of the linker sets.
o Update the man page.

4 years agoMFC r341416 (by imp): Fix typo in comment
Alexander Motin [Mon, 12 Aug 2019 17:42:44 +0000 (17:42 +0000)]
MFC r341416 (by imp): Fix typo in comment

4 years agoMFC r341415 (by imp): Delete the undocumented alias 'wds'.
Alexander Motin [Mon, 12 Aug 2019 17:41:57 +0000 (17:41 +0000)]
MFC r341415 (by imp): Delete the undocumented alias 'wds'.

This was a typo for wdc. Eliminate it since it was in error. People
should use either 'wdc' or 'hgst' for the vendor from now on. 'hgst'
works for all versions this functionality is present for.

4 years agoMFC r341414 (by imp): Move Intel specific log pages to intel.c
Alexander Motin [Mon, 12 Aug 2019 17:41:26 +0000 (17:41 +0000)]
MFC r341414 (by imp): Move Intel specific log pages to intel.c

Move the Intel specific log pages (including the one that samsung
implements) to intel.c. Add comment to the samsung vendor that it will
be going away soon.

4 years agoMFC r341413 (by imp): Usage cleanup pt 2
Alexander Motin [Mon, 12 Aug 2019 17:40:52 +0000 (17:40 +0000)]
MFC r341413 (by imp): Usage cleanup pt 2

Eliminage redundant spaces and nvmecontrol at start of all the usage
strings. Update the usage printing code to add them back when
presenting to the user. Allow multi-line usage messages and print
proper leading spaces for lines starting with a space.

4 years agoMFC r341412 (by imp): Usage cleanup pt 1
Alexander Motin [Mon, 12 Aug 2019 17:40:22 +0000 (17:40 +0000)]
MFC r341412 (by imp): Usage cleanup pt 1

Provide a usage() function that takes a struct nvme_function pointer
and produces a usage mssage. Eliminate all now-redundant usage
functions. Propigate the new argument through the program as needed.
Use common routine to print usage.

4 years agoMFC r341411 (by imp): Return after we find the dispatched function.
Alexander Motin [Mon, 12 Aug 2019 17:39:50 +0000 (17:39 +0000)]
MFC r341411 (by imp): Return after we find the dispatched function.

If the dispatched function doesn't exit, then we get can get a
spurious function not found message. They all do exit, but this is a
little cleaner.

4 years agoMFC r341410 (by imp): Move the hgst/wdc log page printing code into wdc.c
Alexander Motin [Mon, 12 Aug 2019 17:39:16 +0000 (17:39 +0000)]
MFC r341410 (by imp): Move the hgst/wdc log page printing code into wdc.c

These are all hgst/wdc specific, so move them into the wdc.c to live
with the wdc command.

4 years agoMFC r341409 (by imp): Move common logpage routines into nvmecontrol.h
Alexander Motin [Mon, 12 Aug 2019 17:38:48 +0000 (17:38 +0000)]
MFC r341409 (by imp): Move common logpage routines into nvmecontrol.h

For the upcoming move of vendor specific code into vendor specific
files, make the common logpage routines global and move them to
nvmecontrol.h.

4 years agoMFC r341408 (by imp): Make logpage functions a linker set.
Alexander Motin [Mon, 12 Aug 2019 17:38:08 +0000 (17:38 +0000)]
MFC r341408 (by imp): Make logpage functions a linker set.

Move logpage function def to header. Convert all the logpage_function
elements to elements of the linker set. Leave them all in logpage.c
for the moment.

4 years agoMFC r341407 (by imp): Move nvmecontrol to using linker sets for commands
Alexander Motin [Mon, 12 Aug 2019 17:37:35 +0000 (17:37 +0000)]
MFC r341407 (by imp): Move nvmecontrol to using linker sets for commands

More commands will be added to nvmecontrol. Also, there will be a few
more vendor commands (some of which may need to remain private to
companies writing them). The first step on that journey is to move to
using linker sets to dispatch commands. The next step will be using
dlopen to bring in the .so's that have the command that might need
to remain private for seamless integration.

Similar changes to this will be needed for vendor specific log pages.

4 years agonandfs: avoid integer overflow in nandfs_get_dat_bdescs_ioctl
Ed Maste [Mon, 12 Aug 2019 17:25:32 +0000 (17:25 +0000)]
nandfs: avoid integer overflow in nandfs_get_dat_bdescs_ioctl

nandfs was removed in head in r349352 and in any case was not built by
default, but address the potential integer overflow in case someone does
enable it and manages to avoid a panic from other nandfs issues.

admbugs: 815
Reported by: Ilja Van Sprundel <ivansprundel@ioactive.com>
Reviewed by: imp
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D21232

4 years agoMFC r350498: telnet: use asprintf for r350139 [MFC of r349890] change
Ed Maste [Mon, 12 Aug 2019 15:52:21 +0000 (15:52 +0000)]
MFC r350498: telnet: use asprintf for r350139 [MFC of r349890] change

Sponsored by: The FreeBSD Foundation

4 years agoMFC r349571: upgrade the warning printf-s in bus accessors to KASSERT-s, take 2
Andriy Gapon [Mon, 12 Aug 2019 09:20:02 +0000 (09:20 +0000)]
MFC r349571: upgrade the warning printf-s in bus accessors to KASSERT-s, take 2

After this change sys/bus.h includes sys/systm.h when _KERNEL is
defined.

4 years agoMFC r350025: bge: check that the bus is a pci bus before using it as such
Andriy Gapon [Mon, 12 Aug 2019 08:43:00 +0000 (08:43 +0000)]
MFC r350025: bge: check that the bus is a pci bus before using it as such

4 years agoMFC r349886: linuxcommon: add module version
Andriy Gapon [Mon, 12 Aug 2019 08:36:16 +0000 (08:36 +0000)]
MFC r349886: linuxcommon: add module version

4 years agoMFC r349883: owc_gpiobus: small formatting cleanup
Andriy Gapon [Mon, 12 Aug 2019 08:28:26 +0000 (08:28 +0000)]
MFC r349883: owc_gpiobus: small formatting cleanup

4 years agoMFC r349807, r349974, r349976, r350324, r350361, r350445
Ian Lepore [Sun, 11 Aug 2019 23:01:31 +0000 (23:01 +0000)]
MFC r349807, r349974, r349976, r350324, r350361, r350445

r349807:
Eliminate spurious periodic.daily error message for rotating accounting log.

In 2011, r218961 removed local code for rotating logs in favor of using the
rotate_log command in etc/rc.d/accounting.  If the accounting service is
activated then subsequently de-activated in rc.conf but still remains active
in periodic.conf, then you get an error message every day in the periodic
jobs about being unable to rotate the logs.

With this change to use "onerotate_log", the log rotation will happen the
first time periodic daily runs after accounting was disabled but periodic
accounting was left enabled.  After that happens once, the /var/account/acct
will no longer exist, which results in a different path through the periodic
code and no more error messages will appear (unless daily_show_badconfig is
set, in which case the admin will be told that periodic security processing
is enabled but the accounting file is not present).

This is only a partial fix for the problems reported in PR 202203.

PR: 202203

r349974:
Limit access to system accounting files.

In 2013 the security chapter of the Handbook was updated in r42501 to
suggest limiting access to the system accounting file [*1] by creating the
initial file with a mode of 0600. This was in part based on a discussion in
the forums [*2]. Unfortunately, this advice is overridden by the fact that a
new file is created as part of periodic daily processing, and the file mode
is set by the rc.d/accounting script.

These changes update the accounting script to create the directory with mode
0750 if it doesn't already exist, and to create the daily file with mode
0640. This limits write access to root only, read access to root and members
of wheel, and eliminates world access completely. For admins who want to
prevent even members of wheel from accessing the files, the mode of the
/var/account directory can be manually changed to 0700, because the script
never creates or changes that directory if it already exists.

The accounting_rotate_log() function now also handles the error cases of no
existing log file to rotate, and attempting to rotate the file multiple
times (.0 file already exists).

Another small change here eliminates the complexity of the mktemp/chmod/mv
sequence for creating a new acct file by using install(1) with the flags
needed to directly create the file with the desired ownership and
modes. That allows coalescing two separate if checkyesno accounting_enable
blocks into one.

These changes were inspired by my investigation of PR 202203.

[1] https://www.freebsd.org/doc/handbook/security-accounting.html
[2] http://forums.freebsd.org/showthread.php?t=41059

PR: 202203
Differential Revision: https://reviews.freebsd.org/D20876

r349976:
Add an entry mentioning the permission/mode change to daily accounting files.

r350324:
Fix indentation (spaces->tab).

r350361:
Re-wrap the text at 80 columns after fixing the indent in the prior commit.

r350445:
Create the /var/account dir with mode 0750; this is a followup to r349974.

The rc.d/account script contains code to create the /var/account dir, so
it hadn't occurred to me that it is normally created via mtree; thanks to
jilles@ for pointing it out.

4 years agoMFC r349891, r349972
Ian Lepore [Sun, 11 Aug 2019 22:46:58 +0000 (22:46 +0000)]
MFC r349891, r349972

r349891:
Reorganize the SRCS lists as one file per line, and then alphabetize them.
No functional changes.

r349972:
Add arm_sync_icache() and arm_drain_writebuf() sysarch syscall wrappers.

NetBSD and OpenBSD have libc wrapper functions for the ARM_SYNC_ICACHE and
ARM_DRAIN_WRITEBUF sysarch operations. This change adds compatible functions
to our library. This should make it easier for various upstream sources to
support *BSD operating systems with a single variation of cache maintence
code in tools like interpreters and JIT compilers.

I consider the argument types passed to arm_sync_icache() to be especially
unfortunate, but this is intended to match the other BSDs.

Differential Revision: https://reviews.freebsd.org/D20906

4 years agoMFC r350231: Correct spelling, partion -> partition.
Ian Lepore [Sun, 11 Aug 2019 22:32:52 +0000 (22:32 +0000)]
MFC r350231: Correct spelling, partion -> partition.

4 years agoMFC r350104, r350106, r350185, r350203
Ian Lepore [Sun, 11 Aug 2019 22:31:38 +0000 (22:31 +0000)]
MFC r350104, r350106, r350185, r350203

r350104:
Handle the PCF2127 RTC chip the same as PCF2129 when init'ing the chip.

This affects the detection of 24-hour vs AM/PM mode... the ampm bit is in a
different location on 2127 and 2129 chips compared to other nxp rtc chips.
I noticed the 2127 case wasn't being handled correctly when I accidentally
misconfiged my system by claiming my PCF2129 was a 2127.

r350106:
Fix a paste-o, set is212x = false for other chip types.  Doh!

r350185:
Rewrite the nxprtc chip init to extend battery life by using power-saving
features offered by the chips.

For 2127 and 2129 chips, fix the detection of when chip-init is needed.  The
chip config needs to be reset whenever power was lost, but the logic was
wrong for 212x chips (it only worked for 8523).  Now the "oscillator
stopped" bit rather than the power manager mode is used to detect startup
after powerfail.

For all chips, disable the clock output pin.

For chips that have a timestamp/tamper-monitor feature, turn off monitoring
of the timestamp trigger pin.

The 8523, 2127, and 2129 chips have a "power manager" feature that offers
several options.  We've been using the default mode which enables
everything.  Now the code sets the power manager options to

 - direct-switch (when Vdd < Vbat, without extra threshold check)
 - no battery monitor
 - no external powerfail monitor

This reduces the current draw while running on battery from 1930nA to 880nA,
which should roughly double the lifespan of the battery under load.

Because battery checking is a nice thing to have, the code now does a check
at startup, and then once a day after that, instead of checking continuously
(but only actually reporting at startup).  The battery check is now done by
setting the power manager back to default mode, sleeping briefly while it
makes a voltage measurement, then switching back to power-saving mode.

r350203:
Add support for setting the aging/frequency-offset register via sysctl.

The 2127 and 2129 chips support a frequency tuning value in the range of
-7 through +8 PPM; add a sysctl handler to read and set the value.

4 years agoMFC r350015-r350016
Ian Lepore [Sun, 11 Aug 2019 22:19:54 +0000 (22:19 +0000)]
MFC r350015-r350016

r350015:
Fix nxprtc(4) on systems that support i2c repeat-start correctly.

An obscure footnote in the datasheets for the PCx2127, PCx2129, and
PCF8523 rtc chips states that the chips do not support i2c repeat-start
operations.  When the driver was originally written and tested, the i2c
bus on that system also didn't support repeat-start and just quietly
turned repeat-start operations into a stop-then-start, making it appear
that the nxprtc driver was working properly.

The repeat-start situation only comes up on reads, so instead of using
the standard iicdev_readfrom(), use a local nxprtc_readfrom(), which is
just a cut-and-pasted copy of iicdev_readfrom(), modified to send two
separate start-data-stop sequences instead of using repeat-start.

r350016:
In nxprtc(4), use the countdown timer for better timekeeping resolution
on PCx2129 chips too.

The datasheet for the PCx2129 chips says that there is only a watchdog
timer, no countdown timer.  It turns out the countdown timer hardware is
there and works just the same as it does on a PCx2127 chip, except that you
can't use it to trigger an interrupt or toggle an output pin.  We don't need
interrupts or output pins, we only need to read the timer register to get
sub-second resolution.  So start treating the 2129 chips the same as 2127.

4 years agoMFC r349887:
Ian Lepore [Sun, 11 Aug 2019 22:11:59 +0000 (22:11 +0000)]
MFC r349887:

De-pollute arm's sysarch.h.

Instead of including stdint.h for uintptr_t, include sys/_types.h and use
__types for everything that isn't a native C keyword type.

Remove the #include of cdefs.h.  It appears after the include of armreg.h
which has a precondition of cdefs.h being included before it, so everyone
including sysarch.h is already including cdefs.h.  (When armv5 support
goes away, there will be no need include armreg.h here either.)

Unfortunately, the unprefixed struct member names "addr" and "len" cannot
be changed, because 3rd-party software is relying on them (libcompiler_rt
is one known consumer).

4 years agoMFC r349873:
Ian Lepore [Sun, 11 Aug 2019 21:40:18 +0000 (21:40 +0000)]
MFC r349873:

Add pwm.9, it was also deleted during the big round of pwm changes.

4 years agoMFC r349116:
Ian Lepore [Sun, 11 Aug 2019 21:24:44 +0000 (21:24 +0000)]
MFC r349116:

In detach(), call bus_generic_detach() before deleting the iicbus child.
This gives the bus and its children the chance to return EBUSY to abort
the detach if they're in the middle of doing some IO.

4 years agoMFC r349839, r349850
Ian Lepore [Sun, 11 Aug 2019 21:21:32 +0000 (21:21 +0000)]
MFC r349839, r349850

r349839:
Call device_unbusy() on the error exit path, because if iicbus_request_bus()
returns an error, iicbus_release_bus() is not going to be called.

r349850:
Restore the ability for i2c slave devices to do IO from their probe method.

r348164 added code to iicbus_request_bus/iicbus_release_bus to automatically
call device_busy()/device_unbusy() as part of aquiring exclusive use of the
bus (so modules can't be unloaded while the bus is exclusively owned and/or
IO is in progress).  That broke the ability to do i2c IO from a slave device
probe method, because the slave isn't attached yet, so calling device_busy()
triggers a sanity-check panic for trying to busy a non-attached device.

Now we check whether the device status is < DS_ATTACHING, and if so we busy
the iicbus rather than the slave device.  I think this leaves a small window
where a module could be unloaded while probing is in progress.  But I think
that's true of all devices, and probably should be fixed by introducing a
DS_PROBING state for devices, and handling that at various points in the
newbus code.

4 years agoMFC r349319, r349328-r349330
Ian Lepore [Sun, 11 Aug 2019 21:15:30 +0000 (21:15 +0000)]
MFC r349319, r349328-r349330

r349319:
Add some i2c slave-device drivers that were missing from NOTES.

r349328:
The gpiopps(4) driver currently has probe and attach code only for FDT based
systems, so conditionalize it accordingly in conf/files.

r349329:
Add gpio(4) and related drivers to NOTES.

r349330:
Add pwm devices to NOTES.

4 years agoMFC r349072, r349316-r349318
Ian Lepore [Sun, 11 Aug 2019 21:12:29 +0000 (21:12 +0000)]
MFC r349072, r349316-r349318

r349072:
Remove pcf8563reg.h, the driver it was associated with was replaced in 2017
with the nxprtc multi-chip driver.

r349316:
Remove some unused header files from the ad7418 driver.

r349317:
Add the rtc8583 driver to conf/files.  Also, move sy8106a from
file.allwinner to conf/files... it's not allwinner-specific, some day
other platforms could use the same regulator chip.

r349318:
The sy8106a and syr827 drviers require FDT and the ext_resources subsystem.

4 years agoMFC r349325, r349327
Ian Lepore [Sun, 11 Aug 2019 20:50:41 +0000 (20:50 +0000)]
MFC r349325, r349327

r349325:
Allow compiling ukbdmap.h on arm, since it appears to work fine.

r349327:
Build an armv7 LINT kernel in addition to armv5 LINT.  You might think this
had been done years ago.  I did.  All this time we've only compiled a LINT
kernel for TARGET_ARCH=arm.  Now separate LINT-V5 and LINT-V7 configs are
generated and built.

There are two new files in arm/conf, NOTES.armv5 and NOTES.armv7, containing
some of what used to be in the arm NOTES file.  That file now contains only
the bits that are common to v5 and v7.

The makeLINT.mk file now creates the LINT-V5 and LINT-V7 files by concatening
sys/conf/NOTES, arm/conf/NOTES, and arm/conf/NOTES.armv{5,7} in that order.

4 years agoMFC r342102 (by gonzo):
Ian Lepore [Sun, 11 Aug 2019 20:47:01 +0000 (20:47 +0000)]
MFC r342102 (by gonzo):

[twsi] Make extres/clk part conditional based on the EXT_RESOURCES option value

This should fix kernel build for ARMADA38X and possibly some other ARM configs

4 years agoMFC: 350557
George V. Neville-Neil [Sun, 11 Aug 2019 20:34:16 +0000 (20:34 +0000)]
MFC: 350557

Properly validate arguments for route deletion

Reported by: Liang Zhuo brightiup.zhuo@gmail.com

4 years agoMFC r343667:
Konstantin Belousov [Sun, 11 Aug 2019 08:24:56 +0000 (08:24 +0000)]
MFC r343667:
x86: correctly limit max memory resource address.

4 years agoMFC of 350682
Kirk McKusick [Sat, 10 Aug 2019 23:06:52 +0000 (23:06 +0000)]
MFC of 350682

Correct first superblock backup location in fsck_ffs.8.

4 years agoMFC of 350490
Kirk McKusick [Sat, 10 Aug 2019 23:03:23 +0000 (23:03 +0000)]
MFC of 350490

Set FORCE in chk[id]q when returning inodes and blocks.

4 years agoMFC r350229-r350230, r350408, r350410, r350673-r350674
Emmanuel Vadot [Sat, 10 Aug 2019 13:50:15 +0000 (13:50 +0000)]
MFC r350229-r350230, r350408, r350410, r350673-r350674

r350229:
arm: ti: Get the hwmods property from the parent node

Since the Linux 5.0 dts the ti,hwmods property is on the parent
ti.sysc node.

r350230:
arm: ti: Add a driver for ti,sysc bus

ti,sysc is a simple-bus like driver.
Add a driver for it so child nodes can attach.

r350408:
arm: ti: Get the hwmods property either from the node or the parent

r350229 changed the code to lookup the ti,hwmods property in the parent
as it's now like that in the DTS from >= Linux 5.0, allow the property
to be also in the node itself so we can boot with an older DTB.

Reported by: "Dr. Rolf Jansen" <rj@obsigna.com>

r350410:
arm: ti: cpsw: Check the new slave node address

Since DTS from >= Linux 5.0 the slave address are relative to the parent
node address and aren't the full ones.
Check both so the cpsw driver can find the phy id.

r350673:
arm: dts: am33xx: Fix the region for uart0

The region for uart0 is declared to be 0x2000 in size but the parent
node only declare 0x1000.
As the parent only declare a size of 0x1000 in the ranges for it's children
this cause the device to not be mappable.

https://patchwork.kernel.org/patch/11056769/

r350674:
ofw: ofw_reg_to_paddr: Use a 256 static array for the cell

Some hardware needs more than 32, bump this value.

We cannot use the _alloc for of getencprop as this function is called
too early in the boot before pmap is initialized and we only have
2k of stack when cninit is called.

Discussed with:     ian