Commit Graph

56 Commits

Author SHA1 Message Date
kib b0250c7356 Allow to specify PCP on packets not belonging to any VLAN.
According to 802.1Q-2014, VLAN tagged packets with VLAN id 0 should be
considered as untagged, and only PCP and DEI values from the VLAN tag
are meaningful.  See for instance
https://www.cisco.com/c/en/us/td/docs/switches/connectedgrid/cg-switch-sw-master/software/configuration/guide/vlan0/b_vlan_0.html.

Make it possible to specify PCP value for outgoing packets on an
ethernet interface.  When PCP is supplied, the tag is appended, VLAN
id set to 0, and PCP is filled by the supplied value.  The code to do
VLAN tag encapsulation is refactored from the if_vlan.c and moved into
if_ethersubr.c.

Drivers might have issues with filtering VID 0 packets on
receive.  This bug should be fixed for each driver.

Reviewed by:	ae (previous version), hselasky, melifaro
Sponsored by:	Mellanox Technologies
MFC after:	2 weeks
Differential revision:	https://reviews.freebsd.org/D14702
2018-08-24 15:00:03 +02:00
brooks 9cea1c4489 Move uio enums to sys/_uio.h.
Include _uio.h instead of uio.h in several headers to reduce header
polution.

Fix a few places that relied on header polution to get the uio.h header.

I have not moved struct uio as many more things that use it rely on
header polution to get other definitions from uio.h.

Reviewed by:	cem, kib, markj
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D14811
2018-08-24 15:00:03 +02:00
brooks 4d144963ea Add _IOC_NEWLEN() and _IOC_NEWTYPE() macros.
These macros take an existing ioctl(2) command and replace the length
with the specified length or length of the specified type respectively.
These can be used to define commands for 32-bit compatibility with fewer
opportunities for cut-and-paste errors then a whole new definition.

Reviewed by:	cem, kib
Obtained from:	CheriBSD
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D14706
2018-08-24 15:00:03 +02:00
pfg fba31eac2e sys/sys: further adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.
2018-08-24 15:00:03 +02:00
pfg 9f0f4785e8 sys: further adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.
2018-08-24 15:00:03 +02:00
kib 91e828be4f Use hardware timestamps to report packet timestamps
for SO_TIMESTAMP and other similar socket options.

Provide new control message SCM_TIME_INFO to supply information about
timestamp.  Currently it indicates that the timestamp was
hardware-assisted and high-precision, for software timestamps the
message is not returned.  Reserved fields are added to ABI to report
additional info about it, it is expected that raw hardware clock value
might be useful for some applications.

Reviewed by:	gallatin (previous version), hselasky
Sponsored by:	Mellanox Technologies
MFC after:	2 weeks
X-Differential revision:	https://reviews.freebsd.org/D12638
2018-08-24 15:00:02 +02:00
sephe 1182b9fe17 if: Add ioctls to get RSS key and hash type/function.
It will be needed by hn(4) to configure its RSS key and hash
type/function in the transparent VF mode in order to match VF's
RSS settings. The description of the transparent VF mode and
the RSS hash value issue are here:
https://svnweb.freebsd.org/base?view=revision&revision=322299
https://svnweb.freebsd.org/base?view=revision&revision=322485

These are generic enough to promise two independent IOCs instead
of abusing SIOCGDRVSPEC.

Setting RSS key and hash type/function is a different story,
which probably requires more discussion.

Comment about UDP_{IPV4,IPV6,IPV6_EX} were only in the patch
in the review request; these hash types are standardized now.

Reviewed by:	gallatin
MFC after:	1 week
Sponsored by:	Microsoft
Differential Revision:	https://reviews.freebsd.org/D12174
2018-08-24 15:00:02 +02:00
kib 471f29861e Relax visibility for some termios symbols.
They are defined by XSI or newer SUS.
This is a follow-up to r318780.

Reported by:	jbeich
Obtained from:	DragonflyBSD commit e08b3836c962
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2018-08-24 15:00:02 +02:00
kib eb82d7086c Implement address space guards.
Guard, requested by the MAP_GUARD mmap(2) flag, prevents the reuse of
the allocated address space, but does not allow instantiation of the
pages in the range.  It is useful for more explicit support for usual
two-stage reserve then commit allocators, since it prevents accidental
instantiation of the mapping, e.g. by mprotect(2).

Use guards to reimplement stack grow code.  Explicitely track stack
grow area with the guard, including the stack guard page.  On stack
grow, trivial shift of the guard map entry and stack map entry limits
makes the stack expansion.  Move the code to detect stack grow and
call vm_map_growstack(), from vm_fault() into vm_map_lookup().

As result, it is impossible to get random mapping to occur in the
stack grow area, or to overlap the stack guard page.

Enable stack guard page by default.

Reviewed by:	alc, markj
Man page update reviewed by:	alc, bjk, emaste, markj, pho
Tested by:	pho, Qualys
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D11306 (man pages)
2018-08-24 15:00:02 +02:00
glebius 99b9b925fe Listening sockets improvements.
o Separate fields of struct socket that belong to listening from
  fields that belong to normal dataflow, and unionize them.  This
  shrinks the structure a bit.
  - Take out selinfo's from the socket buffers into the socket. The
    first reason is to support braindamaged scenario when a socket is
    added to kevent(2) and then listen(2) is cast on it. The second
    reason is that there is future plan to make socket buffers pluggable,
    so that for a dataflow socket a socket buffer can be changed, and
    in this case we also want to keep same selinfos through the lifetime
    of a socket.
  - Remove struct struct so_accf. Since now listening stuff no longer
    affects struct socket size, just move its fields into listening part
    of the union.
  - Provide sol_upcall field and enforce that so_upcall_set() may be called
    only on a dataflow socket, which has buffers, and for listening sockets
    provide solisten_upcall_set().

o Remove ACCEPT_LOCK() global.
  - Add a mutex to socket, to be used instead of socket buffer lock to lock
    fields of struct socket that don't belong to a socket buffer.
  - Allow to acquire two socket locks, but the first one must belong to a
    listening socket.
  - Make soref()/sorele() to use atomic(9).  This allows in some situations
    to do soref() without owning socket lock.  There is place for improvement
    here, it is possible to make sorele() also to lock optionally.
  - Most protocols aren't touched by this change, except UNIX local sockets.
    See below for more information.

o Reduce copy-and-paste in kernel modules that accept connections from
  listening sockets: provide function solisten_dequeue(), and use it in
  the following modules: ctl(4), iscsi(4), ng_btsocket(4), ng_ksocket(4),
  infiniband, rpc.

o UNIX local sockets.
  - Removal of ACCEPT_LOCK() global uncovered several races in the UNIX
    local sockets.  Most races exist around spawning a new socket, when we
    are connecting to a local listening socket.  To cover them, we need to
    hold locks on both PCBs when spawning a third one.  This means holding
    them across sonewconn().  This creates a LOR between pcb locks and
    unp_list_lock.
  - To fix the new LOR, abandon the global unp_list_lock in favor of global
    unp_link_lock.  Indeed, separating these two locks didn't provide us any
    extra parralelism in the UNIX sockets.
  - Now call into uipc_attach() may happen with unp_link_lock hold if, we
    are accepting, or without unp_link_lock in case if we are just creating
    a socket.
  - Another problem in UNIX sockets is that uipc_close() basicly did nothing
    for a listening socket.  The vnode remained opened for connections.  This
    is fixed by removing vnode in uipc_close().  Maybe the right way would be
    to do it for all sockets (not only listening), simply move the vnode
    teardown from uipc_detach() to uipc_close()?

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D9770
2018-08-24 15:00:02 +02:00
delphij ca3b7a988a Implement INHERIT_ZERO for minherit(2).
INHERIT_ZERO is an OpenBSD feature.

When a page is marked as such, it would be zeroed
upon fork().

This would be used in new arc4random(3) functions.

PR:	182610
Reviewed by:	kib (earlier version)
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D427
2018-08-24 15:00:02 +02:00
imp 16636ede3c Renumber copyright clause 4
Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by:	Jan Schaumann <jschauma@stevens.edu>
Pull Request:	https://github.com/freebsd/freebsd/pull/96
2018-08-24 15:00:02 +02:00
ed@FreeBSD.org 08139e557b mprotect(): Change prototype to comply to POSIX.
Our mprotect() function seems to take a "const void *" address to the
pages whose permissions need to be adjusted. POSIX uses "void *". Simply
stick to the POSIX one to prevent us from writing unportable code.

PR:		211423 (exp-run)
Tested by:	antoine@ (Thanks!)
2018-08-24 15:00:02 +02:00
kib c3df6d5155 Implement process-shared locks support
for libthr.so.3, without breaking the ABI. Special value is stored in
the lock pointer to indicate shared lock, and offline page in the shared
memory is allocated to store the actual lock.

Reviewed by:	vangyzen (previous version)
Discussed with:	deischen, emaste, jhb, rwatson,
	Martin Simmons <martin@lispworks.com>
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
2018-08-24 15:00:02 +02:00
jhb 7cfc736e89 Add a new file operations hook for mmap
operations. File type-specific logic is now placed in the mmap hook
implementation rather than requiring it to be placed in
sys/vm/vm_mmap.c. This hook allows new file types to support mmap() as
well as potentially allowing mmap() for existing file types that do not
currently support any mapping.

The vm_mmap() function is now split up into two functions.  A new
vm_mmap_object() function handles the "back half" of vm_mmap() and accepts
a referenced VM object to map rather than a (handle, handle_type) tuple.
vm_mmap() is now reduced to converting a (handle, handle_type) tuple to a
a VM object and then calling vm_mmap_object() to handle the actual mapping.
The vm_mmap() function remains for use by other parts of the kernel
(e.g. device drivers and exec) but now only supports mapping vnodes,
character devices, and anonymous memory.

The mmap() system call invokes vm_mmap_object() directly with a NULL object
for anonymous mappings.  For mappings using a file descriptor, the
descriptors fo_mmap() hook is invoked instead.  The fo_mmap() hook is
responsible for performing type-specific checks and adjustments to
arguments as well as possibly modifying mapping parameters such as flags
or the object offset.  The fo_mmap() hook routines then call
vm_mmap_object() to handle the actual mapping.

The fo_mmap() hook is optional.  If it is not set, then fo_mmap() will
fail with ENODEV.  A fo_mmap() hook is implemented for regular files,
character devices, and shared memory objects (created via shm_open()).

While here, consistently use the VM_PROT_* constants for the vm_prot_t
type for the 'prot' variable passed to vm_mmap() and vm_mmap_object()
as well as the vm_mmap_vnode() and vm_mmap_cdev() helper routines.
Previously some places were using the mmap()-specific PROT_* constants
instead.  While this happens to work because PROT_xx == VM_PROT_xx,
using VM_PROT_* is more correct.

Differential Revision:	https://reviews.freebsd.org/D2658
Reviewed by:	alc (glanced over), kib
MFC after:	1 month
Sponsored by:	Chelsio
2018-08-24 15:00:02 +02:00
jhb 60b466fbc2 Retire the unimplemented MAP_RENAME
and MAP_NORESERVE flags to mmap(2). Older binaries are still permitted
to use these flags.

PR:		193961 (exp-run in ports)
Differential Revision:	https://reviews.freebsd.org/D848
Reviewed by:	kib
2018-08-24 15:00:02 +02:00
jhb 3d5043e2cb Add a new fo_fill_kinfo fileops method
to add type-specific information to struct kinfo_file. - Move the
various fill_*_info() methods out of kern_descrip.c and into the various
file type implementations. - Rework the support for kinfo_ofile to
generate a suitable kinfo_file object for each file and then convert
that to a kinfo_ofile structure rather than keeping a second, different
set of code that directly manipulates type-specific file information. -
Remove the shm_path() and ksem_info() layering violations.

Differential Revision:	https://reviews.freebsd.org/D775
Reviewed by:	kib, glebius (earlier version)
2018-08-24 15:00:02 +02:00
kib de24ef326d Add MAP_EXCL flag for mmap(2).
It should be combined with MAP_FIXED, and prevents the request from
deleting existing mappings in the region, failing instead.

Reviewed by:	alc
Discussed with:	jhb
Tested by:	markj, pho (previous version, as part of the bigger patch)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2018-08-24 15:00:02 +02:00
jhb 472476a5a7 Add a mmap flag (MAP_32BIT) on 64-bit platforms
to request that a mapping use an address in the first 2GB of the
process's address space. This flag should have the same semantics as the
same flag on Linux.

To facilitate this, add a new parameter to vm_map_find() that specifies an
optional maximum virtual address.  While here, fix several callers of
vm_map_find() to use a VMFS_* constant for the findspace argument instead of
TRUE and FALSE.

Reviewed by:	alc
Approved by:	re (kib)
2018-08-24 15:00:02 +02:00
kib e6a85661ce Implement read(2)/write(2) and neccessary lseek(2)
for posix shmfd. Add MAC framework entries for posix shm read and write.

Do not allow implicit extension of the underlying memory segment past
the limit set by ftruncate(2) by either of the syscalls.  Read and
write returns short i/o, lseek(2) fails with EINVAL when resulting
offset does not fit into the limit.

Discussed with:	alc
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
2018-08-24 15:00:02 +02:00
Joel Sherrill 5b97e36239 rtems/.../dirent.h: Add alphasort() prototype 2018-03-13 09:11:47 -05:00
Sebastian Huber dadc9e7e4a RTEMS: Add semaphore <sys/lock.h> functions
Declare semaphore try wait and post binary functions.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-11-30 07:00:45 +01:00
Sebastian Huber 5a2ab9d55e RTEMS: Timed wait by ticks <sys/lock.h> functions
Declare timed wait by ticks functions.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-11-30 07:00:45 +01:00
Sebastian Huber 186166f67a RTEMS: Add set/get name <sys/lock.h> functions
Add inline functions to set/get the name.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-11-30 07:00:45 +01:00
Sebastian Huber c165a27c01 RTEMS: Fix _PTHREAD_MUTEX_INITIALIZER
Add missing braces around initializer.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-10-13 08:07:13 +02:00
Sebastian Huber 3a79700c2d RTEMS: Make pthread_mutex_t self-contained
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-10-05 14:56:13 +02:00
Sebastian Huber 55c5dda9b5 RTEMS: Make pthread_cond_t self-contained
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-10-05 14:56:13 +02:00
Sebastian Huber d902eef093 RTEMS: Make pthread_rwlock_t self-contained
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-10-05 14:56:13 +02:00
Sebastian Huber 9187bb23a0 RTEMS: Make pthread_barrier_t self-contained
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-10-05 14:56:13 +02:00
Sebastian Huber 4fef7312b3 RTEMS: Optimize pthread_once_t
Reduce size of pthread_once_t and make it zero-initialized.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-10-05 14:56:12 +02:00
Sebastian Huber a3617d7bde Synchronize RTEMS <sys/bitset.h> with FreeBSD
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-07-12 08:04:45 +02:00
Sebastian Huber 1d49ce4d6b Synchronize RTEMS <sys/bitset.h> with FreeBSD
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-07-10 07:18:10 +02:00
Sebastian Huber e9085e0ccd Fix RTEMS ioctl() declaration
Using uint32_t for ioctl_command_t does not work well on 64-bit targets.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-06-07 15:46:20 +02:00
Sebastian Huber dc93d7adff Update FreeBSD revision of RTEMS <sys/bitset.h>
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-06-07 15:46:20 +02:00
Sebastian Huber fd5d052d40 Fix some RTEMS CPUSET(9) macros
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-06-07 15:46:19 +02:00
Sebastian Huber c29f5b219d Fix RTEMS CPU_EQUAL_S()
According to the FreeBSD man page BIT_CMP() returns true in case the two
sets are NOT equal.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-06-07 15:46:19 +02:00
Sebastian Huber d70983ea1b Add de-facto standard <sys/ioctl.h> for RTEMS
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-05-25 12:42:08 -04:00
Sebastian Huber fa88e93d3d Add some POSIX header files for RTEMS
Add the POSIX header files

  * arpa/inet.h
  * net/if.h
  * netdb.h
  * netinet/in.h
  * netinet/tcp.h
  * sys/socket.h
  * sys/syslog.h
  * sys/uio.h
  * sys/un.h
  * syslog.h
  * termios.h

and their dependencies for RTEMS.  The origin of these files is the
latest FreeBSD.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-05-25 12:41:33 -04:00
Sebastian Huber 0b915d6be0 FreeBSD compatibility for RTEMS <sys/cpuset.h>
Make the RTEMS <sys/cpuset.h> compatible with the latest FreeBSD
version.

Fix the CPU_COPY() parameter order, see also:

https://devel.rtems.org/ticket/3023

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-05-25 12:36:27 -04:00
Sebastian Huber 0008601042 Increase MSIZE for RTEMS
Increase the MSIZE for RTEMS to be in line with the latest FreeBSD
version.  The legacy network stack of RTEMS will provides its own
definition.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-05-25 12:33:59 -04:00
Sebastian Huber 2efb117047 FreeBSD compatibility for RTEMS <sys/param.h>
Update the RTEMS <machine/param.h> and <sys/param.h> to be compatible
with the latest FreeBSD version.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-05-25 12:33:40 -04:00
Sebastian Huber e692cfc121 RTEMS: Harmonize MAXNAMLEN and NAME_MAX
Override MAXNAMLEN definition in <dirent.h> and make sure it equals
NAME_MAX.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-01-25 12:36:37 +01:00
Sebastian Huber 69dabb3e30 RTEMS: Add user-defined name to thread queues
Add a user-defined name to the self-contained synchronization objects in
order to make system diagnostics, tracing and debugging more user
friendly.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-01-09 16:11:50 +01:00
Sebastian Huber 724e21493a Self-contained pthread_spinlock_t for RTEMS
Turn pthread_spinlock_t into a self-contained object.  On uni-processor
configurations, interrupts are disabled in the lock/trylock operations
and the previous interrupt status is restored in the corresponding
unlock operations.  On SMP configurations, a ticket lock is a acquired
and released in addition.

See also:

https://devel.rtems.org/ticket/2674

This implementation is simple and efficient.  However, this test case of
the Linux Test Project would fail due to call of printf() and sleep()
during spin lock ownership:

https://github.com/linux-test-project/ltp/blob/master/testcases/open_posix_testsuite/conformance/interfaces/pthread_spin_lock/1-2.c

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2016-11-24 16:57:51 +01:00
Sebastian Huber e655d3d34b Move pthread types to <sys/_pthreadtypes.h>
This makes it possible provide operating system specific types for
<pthread.h>.  It is in line with the FreeBSD header file structure and
allows a future cleanup of <pthread.h> to not expose unrelated things
via <sys/types.h> and <unistd.h>.  Glibc uses the similar
<bits/pthreadtypes.h> for this purpose.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2016-11-17 11:33:15 +01:00
Sebastian Huber ba49de472f Add _TICKET_LOCK_INITIALIZER to <sys/lock.h>
Add _TICKET_LOCK_INITIALIZER to statically initialize a
_Ticket_lock_Control structure.  This makes it possible to embed a
ticket lock in other structures outside of <sys/lock.h>.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2016-11-17 11:28:45 +01:00
Sebastian Huber 9bbc5a34f2 Use __inline in <sys/lock.h> for RTEMS
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2016-11-17 11:28:21 +01:00
Sebastian Huber 4b3a664a20 Add kernel space header for <sys/lock.h> for RTEMS
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2016-11-07 14:03:54 +01:00
Gedare Bloom 644e40dd9c rtems: add sys/mman.h
This file was copied verbatim from FreeBSD and is in sync
	with the FreeBSD svn version used by rtems-libbsd.

Signed-off-by: Joel Sherrill <joelemail@rtems.org>
2016-08-08 11:11:48 -05:00
Jeff Johnston de2a5d6cd3 Add _Thread_queue_Queue::_owner for RTEMS
Add _Thread_queue_Queue::_owner which will be used for the upcomming
priority inheritance implementation and an O(m) independence-preserving
protocol (OMIP) implementation.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2016-05-03 14:21:17 -04:00