9 Commits

Author SHA1 Message Date
David van Moolenbroek
e3b8d4bb58 VFS: add BSD socket API, socket driver support
This patch adds the implementation of the BSD socket system calls
which have been introduced in an earlier patch.  At the same time, it
adds support for communication with socket drivers, using a new
"socket device" (SDEV_) protocol.  These two parts, implemented in
socket.c and sdev.c respectively, form the upper and lower halves of
the new BSD socket support in VFS.  New mapping functionality for
socket domains and drivers is added as well, implemented in smap.c.

The rest of the changes mainly facilitate the separation of character
and socket driver calls, and do not make any fundamental alterations.
For example, while this patch changes VFS's select.c rather heavily,
the new select logic for socket drivers is the exact same as for
character drivers; the changes mainly separate the driver type
specific parts from the generic select logic further than before.

Change-Id: I2f13084dd3c8d3a68bfc69da0621120c8291f707
2017-03-09 23:39:49 +00:00
Richard Sailer
a0814afb2e VFS: Convert K&R C -> ANSI C
Aditionally this removes all trailing whitespaces
using: sed -i 's/[[:space:]]*$//' *.c

Change-Id: I88451fdb6f6e79e61f8aae5bd5a7f2e3538f9944
2016-10-18 14:20:21 +02:00
David van Moolenbroek
232819dd49 VFS: store process suspension state as union
Previously, VFS would use various subsets of a number of fproc
structure fields to store state when the process is blocked
(suspended) for various reasons.  As a result, there was a fair
amount of abuse of fields, hidden state, and confusion as to
which fields were used with which suspension states.

Instead, the suspension state is now split into per-state
structures, which are then stored in a union.  Each of the union's
structures should be accessed only right before, during, and right
after the fp_blocked_on field is set to the corresponding blocking
type.  As a result, it is now very clear which fields are in use
at which times, and we even save a bit of memory as a side effect.

Change-Id: I5c24e353b6cb0c32eb41c70f89c5cfb23f6c93df
2016-08-05 11:15:15 +00:00
David van Moolenbroek
c33d6ef392 VFS: start off cleanup of pipe2 IPC message
There is no reason to use a single message for nonoverlapping requests
and replies combined, and in fact splitting them out allows reuse of
messages and avoids various problems with field layouts.  Since the
upcoming socketpair(2) system call will be using the same reply as
pipe2(2), split up the single message used for the latter.  In order
to keep the used parts of messages at the front, start a transitional
phase to move the pipe(2) flags field to the front of its request.

Change-Id: If3f1c3d348ec7e27b7f5b7147ce1b9ef490dfab9
2016-02-22 23:23:02 +00:00
David van Moolenbroek
10b7016b5a Fix soft faults in FSes resulting in partial I/O
In order to resolve page faults on file-mapped pages, VM may need to
communicate (through VFS) with a file system.  The file system must
therefore not be the one to cause, and thus end up being blocked on,
such page faults.  To resolve this potential deadlock, the safecopy
system was previously extended with the CPF_TRY flag, which causes the
kernel to return EFAULT to the caller of a safecopy function upon
getting a pagefault, bypassing VM and thus avoiding the loop.  VFS was
extended to repeat relevant file system calls that returned EFAULT,
after resolving the page fault, to keep these soft faults from being
exposed to applications.

However, general UNIX I/O semantics dictate that if an I/O transfer
partially succeeded before running into a failure, the partial result
is to be returned.  Proper file system implementations may therefore
end up returning partial success rather than the EFAULT code resulting
from a soft fault.  Since VFS does not get the EFAULT code in this
case, it does not know that a soft fault occurred, and thus does not
repeat the call either.  The end result is that an application may get
partial I/O results (e.g., a short read(2)) even on regular files.
Applications cannot reasonably be expected to deal with this.

Due to the fact that most of the current file system implementations
do not implement proper partial-failure semantics, this problem is not
yet widespread.  In fact, it has only occurred on direct block device
I/O so far.  However, the next generation of file system services will
be implementing proper I/O semantics, thus exacerbating the problem.

To remedy this situation, this patch changes the CPF_TRY semantics:
whenever the kernel experiences a soft fault during a safecopy call,
in addition to returning FAULT, the kernel also stores a mark in the
grant created with CPF_TRY.  Instead of testing on EFAULT, VFS checks
whether the grant was marked, as part of revoking the grant.  If the
grant was indeed marked by the kernel, VFS repeats the file system
operation, regardless of its initial return value.  Thus, the EFAULT
code now only serves to make the file system fail the call faster.

The approach is currently supported for both direct and magic grants,
but is used only with magic grants - arguably the only case where it
makes sense.  Indirect grants should not have CPF_TRY set; in a chain
of indirect grants, the original grant is marked, as it should be.
In order to avoid potential SMP issues, the mark stored in the grant
is its grant identifier, so as to discard outdated kernel writes.
Whether this is necessary or effective remains to be evaluated.

This patch also cleans up the grant structure a bit, removing reserved
space and thus making the structure slightly smaller.  The structure
is used internally between system services only, so there is no need
for binary compatibility.

Change-Id: I6bb3990dce67a80146d954546075ceda4d6567f8
2016-01-16 14:04:21 +01:00
Lionel Sambuc
81b1f87117 Fix noassert builds
Change-Id: I5626950ffa29afe7a0fb9e9144839b311824da92
2015-09-25 15:47:43 -07:00
David van Moolenbroek
253dbfc285 VFS: resolve noassert warning
Change-Id: I647f5a7b3c2935be3df032873705be83de9aaffb
2015-08-31 12:55:43 +00:00
David van Moolenbroek
bd851af48f VFS: merge scratchpad into fproc
There is no reason to keep these tightly coupled data structures
separate.  Moreover, there is no reason to have a union of file
descriptor and file pointer, since the second can be derived from
the first.  The result are somewhat cleaner VFS internals.

Change-Id: I854da7d8291177878eecfc3077ef0a9e0cc82aaa
2015-08-13 13:45:02 +00:00
Lionel Sambuc
433d6423c3 New sources layout
Change-Id: Ic716f336b7071063997cf5b4dae6d50e0b4631e9
2014-07-31 16:00:30 +02:00