make vfs & filesystems use failable copying
Change the kernel to add features to vircopy and safecopies so that
transparent copy fixing won't happen to avoid deadlocks, and such copies
fail with EFAULT.
Transparently making copying work from filesystems (as normally done by
the kernel & VM when copying fails because of missing/readonly memory)
is problematic as it can happen that, for file-mapped ranges, that that
same filesystem that is blocked on the copy request is needed to satisfy
the memory range, leading to deadlock. Dito for VFS itself, if done with
a blocking call.
This change makes the copying done from a filesystem fail in such cases
with EFAULT by VFS adding the CPF_TRY flag to the grants. If a FS call
fails with EFAULT, VFS will then request the range to be made available
to VM after the FS is unblocked, allowing it to be used to satisfy the
range if need be in another VFS thread.
Similarly, for datacopies that VFS itself does, it uses the failable
vircopy variant and callers use a wrapper that talk to VM if necessary
to get the copy to work.
. kernel: add CPF_TRY flag to safecopies
. kernel: only request writable ranges to VM for the
target buffer when copying fails
. do copying in VFS TRY-first
. some fixes in VM to build SANITYCHECK mode
. add regression test for the cases where
- a FS system call needs memory mapped in a process that the
FS itself must map.
- such a range covers more than one file-mapped region.
. add 'try' mode to vircopy, physcopy
. add flags field to copy kernel call messages
. if CP_FLAG_TRY is set, do not transparently try
to fix memory ranges
. for use by VFS when accessing user buffers to avoid
deadlock
. remove some obsolete backwards compatability assignments
. VFS: let thread scheduling work for VM requests too
Allows VFS to make calls to VM while suspending and resuming
the currently running thread. Does currently not work for the
main thread.
. VM: add fix memory range call for use by VFS
Change-Id: I295794269cea51a3163519a9cfe5901301d90b32
This commit is contained in:
@@ -53,7 +53,7 @@ int libexec_alloc_mmap_ondemand(struct exec_info *execi, vir_bytes vaddr, size_t
|
||||
|
||||
int libexec_clearproc_vm_procctl(struct exec_info *execi)
|
||||
{
|
||||
return vm_procctl(execi->proc_e, VMPPARAM_CLEAR);
|
||||
return vm_procctl_clear(execi->proc_e);
|
||||
}
|
||||
|
||||
int libexec_clear_sys_memset(struct exec_info *execi, vir_bytes vaddr, size_t len)
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#define ACCESS_CHECK(a) { \
|
||||
if((a) & ~(CPF_READ|CPF_WRITE)) { \
|
||||
if((a) & ~(CPF_READ|CPF_WRITE|CPF_TRY)) { \
|
||||
errno = EINVAL; \
|
||||
return -1; \
|
||||
} \
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#include "syslib.h"
|
||||
|
||||
int sys_physcopy(src_proc, src_vir, dst_proc, dst_vir, bytes)
|
||||
int sys_physcopy(src_proc, src_vir, dst_proc, dst_vir, bytes, flags)
|
||||
endpoint_t src_proc; /* source process */
|
||||
vir_bytes src_vir; /* source virtual address */
|
||||
endpoint_t dst_proc; /* destination process */
|
||||
vir_bytes dst_vir; /* destination virtual address */
|
||||
phys_bytes bytes; /* how many bytes */
|
||||
int flags; /* copy flags */
|
||||
{
|
||||
/* Transfer a block of data. The source and destination can each either be a
|
||||
* process number or SELF (to indicate own process number). Virtual addresses
|
||||
@@ -21,12 +22,7 @@ phys_bytes bytes; /* how many bytes */
|
||||
copy_mess.CP_DST_ENDPT = dst_proc;
|
||||
copy_mess.CP_DST_ADDR = (long) dst_vir;
|
||||
copy_mess.CP_NR_BYTES = (long) bytes;
|
||||
|
||||
/* provide backwards compatability arguments to old
|
||||
* kernels based on process id's; NONE <=> physical
|
||||
*/
|
||||
copy_mess.CP_DST_SPACE_OBSOLETE = (dst_proc == NONE ? PHYS_SEG : D_OBSOLETE);
|
||||
copy_mess.CP_SRC_SPACE_OBSOLETE = (src_proc == NONE ? PHYS_SEG : D_OBSOLETE);
|
||||
copy_mess.CP_FLAGS = flags;
|
||||
|
||||
return(_kernel_call(SYS_PHYSCOPY, ©_mess));
|
||||
}
|
||||
|
||||
@@ -19,11 +19,6 @@ int sys_safecopyfrom(endpoint_t src_e,
|
||||
copy_mess.SCP_ADDRESS = (char *) address;
|
||||
copy_mess.SCP_BYTES = (long) bytes;
|
||||
|
||||
/* for older kernels that still need the 'seg' field
|
||||
* provide the right value.
|
||||
*/
|
||||
copy_mess.SCP_SEG_OBSOLETE = D_OBSOLETE;
|
||||
|
||||
return(_kernel_call(SYS_SAFECOPYFROM, ©_mess));
|
||||
|
||||
}
|
||||
@@ -44,11 +39,6 @@ int sys_safecopyto(endpoint_t dst_e,
|
||||
copy_mess.SCP_ADDRESS = (char *) address;
|
||||
copy_mess.SCP_BYTES = (long) bytes;
|
||||
|
||||
/* for older kernels that still need the 'seg' field
|
||||
* provide the right value.
|
||||
*/
|
||||
copy_mess.SCP_SEG_OBSOLETE = D_OBSOLETE;
|
||||
|
||||
return(_kernel_call(SYS_SAFECOPYTO, ©_mess));
|
||||
|
||||
}
|
||||
|
||||
@@ -1,30 +1,28 @@
|
||||
#include "syslib.h"
|
||||
|
||||
int sys_vircopy(src_proc, src_vir,
|
||||
dst_proc, dst_vir, bytes)
|
||||
dst_proc, dst_vir, bytes, flags)
|
||||
endpoint_t src_proc; /* source process */
|
||||
vir_bytes src_vir; /* source virtual address */
|
||||
endpoint_t dst_proc; /* destination process */
|
||||
vir_bytes dst_vir; /* destination virtual address */
|
||||
phys_bytes bytes; /* how many bytes */
|
||||
int flags; /* copy flags */
|
||||
{
|
||||
/* Transfer a block of data. The source and destination can each either be a
|
||||
* process number or SELF (to indicate own process number). Virtual addresses
|
||||
* are offsets within LOCAL_SEG (text, stack, data), or BIOS_SEG.
|
||||
* process number or SELF (to indicate own process number).
|
||||
*/
|
||||
|
||||
message copy_mess;
|
||||
|
||||
if (bytes == 0L) return(OK);
|
||||
memset(©_mess, 0, sizeof(copy_mess));
|
||||
copy_mess.CP_SRC_ENDPT = src_proc;
|
||||
copy_mess.CP_SRC_ADDR = (long) src_vir;
|
||||
copy_mess.CP_DST_ENDPT = dst_proc;
|
||||
copy_mess.CP_DST_ADDR = (long) dst_vir;
|
||||
copy_mess.CP_NR_BYTES = (long) bytes;
|
||||
|
||||
/* backwards compatability D segs */
|
||||
copy_mess.CP_DST_SPACE_OBSOLETE = D_OBSOLETE;
|
||||
copy_mess.CP_SRC_SPACE_OBSOLETE = D_OBSOLETE;
|
||||
copy_mess.CP_FLAGS = flags;
|
||||
|
||||
return(_kernel_call(SYS_VIRCOPY, ©_mess));
|
||||
}
|
||||
|
||||
@@ -5,9 +5,10 @@
|
||||
#include <string.h>
|
||||
|
||||
/*===========================================================================*
|
||||
* vm_exit *
|
||||
* vm_procctl *
|
||||
*===========================================================================*/
|
||||
int vm_procctl(endpoint_t ep, int param)
|
||||
static int vm_procctl(endpoint_t ep, int param,
|
||||
vir_bytes m1, vir_bytes len, int flags)
|
||||
{
|
||||
message m;
|
||||
int result;
|
||||
@@ -16,8 +17,22 @@ int vm_procctl(endpoint_t ep, int param)
|
||||
|
||||
m.VMPCTL_WHO = ep;
|
||||
m.VMPCTL_PARAM = param;
|
||||
m.VMPCTL_M1 = m1;
|
||||
m.VMPCTL_LEN = len;
|
||||
m.VMPCTL_FLAGS = flags;
|
||||
|
||||
result = _taskcall(VM_PROC_NR, VM_PROCCTL, &m);
|
||||
return(result);
|
||||
}
|
||||
|
||||
int vm_procctl_clear(endpoint_t ep)
|
||||
{
|
||||
return vm_procctl(ep, VMPPARAM_CLEAR, 0, 0, 0);
|
||||
}
|
||||
|
||||
int vm_procctl_handlemem(endpoint_t ep, vir_bytes m1, vir_bytes len,
|
||||
int writeflag)
|
||||
{
|
||||
return vm_procctl(ep, VMPPARAM_HANDLEMEM, m1, len, writeflag);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user