2012-10-11 15:15:49 +02:00
|
|
|
|
|
|
|
/* This file implements the methods of physically contiguous anonymous memory. */
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "proto.h"
|
|
|
|
#include "vm.h"
|
|
|
|
#include "region.h"
|
|
|
|
#include "glo.h"
|
|
|
|
|
2013-03-20 20:18:52 +01:00
|
|
|
static int anon_contig_reference(struct phys_region *, struct phys_region *);
|
2012-10-11 15:15:49 +02:00
|
|
|
static int anon_contig_unreference(struct phys_region *pr);
|
|
|
|
static int anon_contig_pagefault(struct vmproc *vmp, struct vir_region *region,
|
2013-06-25 14:41:01 +02:00
|
|
|
struct phys_region *ph, int write, vfs_callback_t cb, void *state,
|
|
|
|
int len, int *io);
|
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
2014-01-16 14:22:13 +01:00
|
|
|
static int anon_contig_sanitycheck(struct phys_region *pr, const char *file, int line);
|
2012-10-11 15:15:49 +02:00
|
|
|
static int anon_contig_writable(struct phys_region *pr);
|
|
|
|
static int anon_contig_resize(struct vmproc *vmp, struct vir_region *vr, vir_bytes l);
|
|
|
|
static int anon_contig_new(struct vir_region *vr);
|
2013-09-25 10:41:26 +02:00
|
|
|
static int anon_contig_pt_flags(struct vir_region *vr);
|
2012-10-11 15:15:49 +02:00
|
|
|
|
|
|
|
struct mem_type mem_type_anon_contig = {
|
|
|
|
.name = "anonymous memory (physically contiguous)",
|
|
|
|
.ev_new = anon_contig_new,
|
|
|
|
.ev_reference = anon_contig_reference,
|
|
|
|
.ev_unreference = anon_contig_unreference,
|
|
|
|
.ev_pagefault = anon_contig_pagefault,
|
|
|
|
.ev_resize = anon_contig_resize,
|
|
|
|
.ev_sanitycheck = anon_contig_sanitycheck,
|
2013-09-25 10:41:26 +02:00
|
|
|
.writable = anon_contig_writable,
|
|
|
|
.pt_flags = anon_contig_pt_flags,
|
2012-10-11 15:15:49 +02:00
|
|
|
};
|
|
|
|
|
2013-09-25 10:41:26 +02:00
|
|
|
static int anon_contig_pt_flags(struct vir_region *vr){
|
|
|
|
#if defined(__arm__)
|
|
|
|
return ARM_VM_PTE_DEVICE;
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-10-11 15:15:49 +02:00
|
|
|
static int anon_contig_pagefault(struct vmproc *vmp, struct vir_region *region,
|
2013-06-25 14:41:01 +02:00
|
|
|
struct phys_region *ph, int write, vfs_callback_t cb, void *state,
|
|
|
|
int len, int *io)
|
2012-10-11 15:15:49 +02:00
|
|
|
{
|
|
|
|
panic("anon_contig_pagefault: pagefault cannot happen");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int anon_contig_new(struct vir_region *region)
|
|
|
|
{
|
|
|
|
u32_t allocflags;
|
|
|
|
phys_bytes new_pages, new_page_cl, cur_ph;
|
2013-08-20 14:02:33 +02:00
|
|
|
phys_bytes p, pages;
|
2012-10-11 15:15:49 +02:00
|
|
|
|
|
|
|
allocflags = vrallocflags(region->flags);
|
|
|
|
|
|
|
|
pages = region->length/VM_PAGE_SIZE;
|
|
|
|
|
|
|
|
assert(physregions(region) == 0);
|
|
|
|
|
|
|
|
for(p = 0; p < pages; p++) {
|
|
|
|
struct phys_block *pb = pb_new(MAP_NONE);
|
|
|
|
struct phys_region *pr = NULL;
|
|
|
|
if(pb)
|
2013-03-20 20:18:52 +01:00
|
|
|
pr = pb_reference(pb, p * VM_PAGE_SIZE, region, &mem_type_anon_contig);
|
2012-10-11 15:15:49 +02:00
|
|
|
if(!pr) {
|
|
|
|
if(pb) pb_free(pb);
|
|
|
|
map_free(region);
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(physregions(region) == pages);
|
|
|
|
|
|
|
|
if((new_page_cl = alloc_mem(pages, allocflags)) == NO_MEM) {
|
|
|
|
map_free(region);
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
cur_ph = new_pages = CLICK2ABS(new_page_cl);
|
|
|
|
|
|
|
|
for(p = 0; p < pages; p++) {
|
2012-12-17 19:26:52 +01:00
|
|
|
struct phys_region *pr = physblock_get(region, p * VM_PAGE_SIZE);
|
2012-10-11 15:15:49 +02:00
|
|
|
assert(pr);
|
|
|
|
assert(pr->ph);
|
|
|
|
assert(pr->ph->phys == MAP_NONE);
|
|
|
|
assert(pr->offset == p * VM_PAGE_SIZE);
|
|
|
|
pr->ph->phys = cur_ph + pr->offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int anon_contig_resize(struct vmproc *vmp, struct vir_region *vr, vir_bytes l)
|
|
|
|
{
|
|
|
|
printf("VM: cannot resize physically contiguous memory.\n");
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
|
2013-03-20 20:18:52 +01:00
|
|
|
static int anon_contig_reference(struct phys_region *pr,
|
|
|
|
struct phys_region *newpr)
|
2012-10-11 15:15:49 +02:00
|
|
|
{
|
|
|
|
printf("VM: cannot fork with physically contig memory.\n");
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Methods inherited from the anonymous memory methods. */
|
|
|
|
|
|
|
|
static int anon_contig_unreference(struct phys_region *pr)
|
|
|
|
{
|
|
|
|
return mem_type_anon.ev_unreference(pr);
|
|
|
|
}
|
|
|
|
|
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
2014-01-16 14:22:13 +01:00
|
|
|
static int anon_contig_sanitycheck(struct phys_region *pr, const char *file, int line)
|
2012-10-11 15:15:49 +02:00
|
|
|
{
|
|
|
|
return mem_type_anon.ev_sanitycheck(pr, file, line);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int anon_contig_writable(struct phys_region *pr)
|
|
|
|
{
|
|
|
|
return mem_type_anon.writable(pr);
|
|
|
|
}
|
|
|
|
|