mirror of
https://github.com/drasko/codezero.git
synced 2026-01-25 17:23:14 +01:00
Flushing pages to vfs will work, but the issue is that while vfs is
serving mm0, if it page faults, system deadlocks because mm0 is waiting to be served by vfs. FIX: To fix this, mm0 will need to fork itself and keep a separate thread solely for page fault handling.
This commit is contained in:
@@ -85,8 +85,8 @@ int ipc_send(l4id_t recv_tid)
|
|||||||
|
|
||||||
/* Do the work */
|
/* Do the work */
|
||||||
ipc_msg_copy(sleeper, current);
|
ipc_msg_copy(sleeper, current);
|
||||||
//printk("(%d) Waking up (%d)\n", current->tid,
|
printk("%s: (%d) Waking up (%d)\n", __FUNCTION__,
|
||||||
// sleeper->tid);
|
current->tid, sleeper->tid);
|
||||||
|
|
||||||
/* Wake it up, we can yield here. */
|
/* Wake it up, we can yield here. */
|
||||||
sched_resume_task(sleeper);
|
sched_resume_task(sleeper);
|
||||||
@@ -100,7 +100,7 @@ int ipc_send(l4id_t recv_tid)
|
|||||||
list_add_tail(&wq.task_list, &wqhs->task_list);
|
list_add_tail(&wq.task_list, &wqhs->task_list);
|
||||||
sched_notify_sleep(current);
|
sched_notify_sleep(current);
|
||||||
need_resched = 1;
|
need_resched = 1;
|
||||||
//printk("(%d) waiting for (%d)\n", current->tid, recv_tid);
|
printk("%s: (%d) waiting for (%d)\n", __FUNCTION__, current->tid, recv_tid);
|
||||||
spin_unlock(&wqhr->slock);
|
spin_unlock(&wqhr->slock);
|
||||||
spin_unlock(&wqhs->slock);
|
spin_unlock(&wqhs->slock);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -133,8 +133,8 @@ int ipc_recv(l4id_t senderid)
|
|||||||
|
|
||||||
/* Do the work */
|
/* Do the work */
|
||||||
ipc_msg_copy(current, sleeper);
|
ipc_msg_copy(current, sleeper);
|
||||||
//printk("(%d) Waking up (%d)\n", current->tid,
|
printk("%s: (%d) Waking up (%d)\n", __FUNCTION__,
|
||||||
// sleeper->tid);
|
current->tid, sleeper->tid);
|
||||||
|
|
||||||
/* Wake it up */
|
/* Wake it up */
|
||||||
sched_resume_task(sleeper);
|
sched_resume_task(sleeper);
|
||||||
@@ -149,7 +149,7 @@ int ipc_recv(l4id_t senderid)
|
|||||||
list_add_tail(&wq.task_list, &wqhr->task_list);
|
list_add_tail(&wq.task_list, &wqhr->task_list);
|
||||||
sched_notify_sleep(current);
|
sched_notify_sleep(current);
|
||||||
need_resched = 1;
|
need_resched = 1;
|
||||||
// printk("(%d) waiting for (%d) \n", current->tid, current->senderid);
|
printk("%s: (%d) waiting for (%d) \n", __FUNCTION__, current->tid, current->senderid);
|
||||||
spin_unlock(&wqhr->slock);
|
spin_unlock(&wqhr->slock);
|
||||||
spin_unlock(&wqhs->slock);
|
spin_unlock(&wqhs->slock);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ int pager_sys_open(l4id_t sender, int fd, unsigned long vnum, unsigned long size
|
|||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
printf("%s/%s\n", __TASKNAME__, __FUNCTION__);
|
||||||
|
|
||||||
l4_save_ipcregs();
|
l4_save_ipcregs();
|
||||||
|
|
||||||
write_mr(L4SYS_ARG0, sender);
|
write_mr(L4SYS_ARG0, sender);
|
||||||
@@ -104,6 +106,8 @@ int pager_sys_close(l4id_t sender, l4id_t closer, int fd)
|
|||||||
struct tcb *task;
|
struct tcb *task;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
printf("%s/%s\n", __TASKNAME__, __FUNCTION__);
|
||||||
|
|
||||||
BUG_ON(!(task = find_task(closer)));
|
BUG_ON(!(task = find_task(closer)));
|
||||||
|
|
||||||
printf("Deleting fd: %d\n", fd);
|
printf("Deleting fd: %d\n", fd);
|
||||||
@@ -132,6 +136,7 @@ int sys_open(l4id_t sender, const char *pathname, int flags, unsigned int mode)
|
|||||||
int fd;
|
int fd;
|
||||||
int retval, err;
|
int retval, err;
|
||||||
|
|
||||||
|
printf("%s/%s\n", __TASKNAME__, __FUNCTION__);
|
||||||
/* Get the task */
|
/* Get the task */
|
||||||
BUG_ON(!(task = find_task(sender)));
|
BUG_ON(!(task = find_task(sender)));
|
||||||
|
|
||||||
@@ -337,6 +342,7 @@ int pager_sys_read(l4id_t sender, unsigned long vnum, unsigned long f_offset,
|
|||||||
struct vnode *v;
|
struct vnode *v;
|
||||||
int err, retval = 0;
|
int err, retval = 0;
|
||||||
|
|
||||||
|
printf("%s/%s\n", __TASKNAME__, __FUNCTION__);
|
||||||
if (sender != PAGER_TID) {
|
if (sender != PAGER_TID) {
|
||||||
retval = -EINVAL;
|
retval = -EINVAL;
|
||||||
goto out;
|
goto out;
|
||||||
@@ -370,6 +376,7 @@ int pager_update_stats(l4id_t sender, unsigned long vnum,
|
|||||||
struct vnode *v;
|
struct vnode *v;
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
|
|
||||||
|
printf("%s/%s\n", __TASKNAME__, __FUNCTION__);
|
||||||
if (sender != PAGER_TID) {
|
if (sender != PAGER_TID) {
|
||||||
retval = -EINVAL;
|
retval = -EINVAL;
|
||||||
goto out;
|
goto out;
|
||||||
@@ -402,6 +409,7 @@ int pager_sys_write(l4id_t sender, unsigned long vnum, unsigned long f_offset,
|
|||||||
struct vnode *v;
|
struct vnode *v;
|
||||||
int err, retval = 0;
|
int err, retval = 0;
|
||||||
|
|
||||||
|
printf("%s/%s\n", __TASKNAME__, __FUNCTION__);
|
||||||
if (sender != PAGER_TID) {
|
if (sender != PAGER_TID) {
|
||||||
retval = -EINVAL;
|
retval = -EINVAL;
|
||||||
goto out;
|
goto out;
|
||||||
@@ -419,6 +427,9 @@ int pager_sys_write(l4id_t sender, unsigned long vnum, unsigned long f_offset,
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("%s/%s: Writing to vnode %lu, at pgoff 0x%x, %d pages, buf at 0x%x\n",
|
||||||
|
__TASKNAME__, __FUNCTION__, vnum, f_offset, npages, pagebuf);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the file is extended, write silently extends it.
|
* If the file is extended, write silently extends it.
|
||||||
* But we expect an explicit pager_update_stats from the
|
* But we expect an explicit pager_update_stats from the
|
||||||
@@ -430,7 +441,9 @@ int pager_sys_write(l4id_t sender, unsigned long vnum, unsigned long f_offset,
|
|||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
printf("%s/%s: Returning ipc result.\n", __TASKNAME__, __FUNCTION__);
|
||||||
l4_ipc_return(retval);
|
l4_ipc_return(retval);
|
||||||
|
printf("%s/%s: Done.\n", __TASKNAME__, __FUNCTION__);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -482,6 +495,7 @@ int sys_readdir(l4id_t sender, int fd, void *buf, int count)
|
|||||||
struct dentry *d;
|
struct dentry *d;
|
||||||
struct tcb *t;
|
struct tcb *t;
|
||||||
|
|
||||||
|
printf("%s/%s\n", __TASKNAME__, __FUNCTION__);
|
||||||
/* Get the task */
|
/* Get the task */
|
||||||
BUG_ON(!(t = find_task(sender)));
|
BUG_ON(!(t = find_task(sender)));
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ int vfs_read(unsigned long vnum, unsigned long file_offset,
|
|||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
printf("%s/%s\n", __TASKNAME__, __FUNCTION__);
|
||||||
|
|
||||||
l4_save_ipcregs();
|
l4_save_ipcregs();
|
||||||
|
|
||||||
write_mr(L4SYS_ARG0, vnum);
|
write_mr(L4SYS_ARG0, vnum);
|
||||||
@@ -90,6 +92,8 @@ int vfs_receive_sys_open(l4id_t sender, l4id_t opener, int fd,
|
|||||||
struct vm_file *vmfile;
|
struct vm_file *vmfile;
|
||||||
struct tcb *t;
|
struct tcb *t;
|
||||||
|
|
||||||
|
printf("%s/%s\n", __TASKNAME__, __FUNCTION__);
|
||||||
|
|
||||||
/* Check argument validity */
|
/* Check argument validity */
|
||||||
if (sender != VFS_TID) {
|
if (sender != VFS_TID) {
|
||||||
l4_ipc_return(-EPERM);
|
l4_ipc_return(-EPERM);
|
||||||
@@ -214,6 +218,7 @@ int vfs_write(unsigned long vnum, unsigned long file_offset,
|
|||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
printf("%s/%s\n", __TASKNAME__, __FUNCTION__);
|
||||||
l4_save_ipcregs();
|
l4_save_ipcregs();
|
||||||
|
|
||||||
write_mr(L4SYS_ARG0, vnum);
|
write_mr(L4SYS_ARG0, vnum);
|
||||||
@@ -241,6 +246,7 @@ int vfs_close(l4id_t sender, int fd)
|
|||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
printf("%s/%s Sending to %d\n", __TASKNAME__, __FUNCTION__, VFS_TID);
|
||||||
l4_save_ipcregs();
|
l4_save_ipcregs();
|
||||||
|
|
||||||
write_mr(L4SYS_ARG0, sender);
|
write_mr(L4SYS_ARG0, sender);
|
||||||
@@ -250,6 +256,7 @@ int vfs_close(l4id_t sender, int fd)
|
|||||||
printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, err);
|
printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, err);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
printf("%s/%s Received from %d\n", __TASKNAME__, __FUNCTION__, VFS_TID);
|
||||||
|
|
||||||
/* Check if syscall was successful */
|
/* Check if syscall was successful */
|
||||||
if ((err = l4_get_retval()) < 0) {
|
if ((err = l4_get_retval()) < 0) {
|
||||||
@@ -267,6 +274,7 @@ int vfs_update_file_stats(struct vm_file *f)
|
|||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
printf("%s/%s\n", __TASKNAME__, __FUNCTION__);
|
||||||
l4_save_ipcregs();
|
l4_save_ipcregs();
|
||||||
|
|
||||||
write_mr(L4SYS_ARG0, vm_file_to_vnum(f));
|
write_mr(L4SYS_ARG0, vm_file_to_vnum(f));
|
||||||
@@ -373,7 +381,7 @@ int sys_close(l4id_t sender, int fd)
|
|||||||
l4_ipc_return(retval);
|
l4_ipc_return(retval);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Close the file descriptor. */
|
/* Close the file descriptor. */
|
||||||
retval = fd_close(sender, fd);
|
retval = fd_close(sender, fd);
|
||||||
printf("%s: Closed fd %d. Returning %d\n",
|
printf("%s: Closed fd %d. Returning %d\n",
|
||||||
@@ -454,6 +462,7 @@ copy:
|
|||||||
copy_offset = (unsigned long)buf;
|
copy_offset = (unsigned long)buf;
|
||||||
page_copy(head, task_virt_to_page(task, copy_offset),
|
page_copy(head, task_virt_to_page(task, copy_offset),
|
||||||
cursor_offset, copy_offset & PAGE_MASK, copysize);
|
cursor_offset, copy_offset & PAGE_MASK, copysize);
|
||||||
|
head->flags |= VM_DIRTY;
|
||||||
left -= copysize;
|
left -= copysize;
|
||||||
last_pgoff = head->offset;
|
last_pgoff = head->offset;
|
||||||
|
|
||||||
@@ -473,6 +482,7 @@ copy:
|
|||||||
|
|
||||||
page_copy(this, task_virt_to_page(task, copy_offset),
|
page_copy(this, task_virt_to_page(task, copy_offset),
|
||||||
0, 0, copysize);
|
0, 0, copysize);
|
||||||
|
this->flags |= VM_DIRTY;
|
||||||
left -= copysize;
|
left -= copysize;
|
||||||
last_pgoff = this->offset;
|
last_pgoff = this->offset;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,9 +84,15 @@ int file_page_out(struct vm_object *vm_obj, unsigned long page_offset)
|
|||||||
if (!(page->flags & VM_DIRTY))
|
if (!(page->flags & VM_DIRTY))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
paddr = (void *)page_to_phys(page);
|
||||||
|
vaddr = phys_to_virt(paddr);
|
||||||
|
|
||||||
/* Map the page to vfs task */
|
/* Map the page to vfs task */
|
||||||
l4_map(paddr, vaddr, 1, MAP_USR_RW_FLAGS, VFS_TID);
|
l4_map(paddr, vaddr, 1, MAP_USR_RW_FLAGS, VFS_TID);
|
||||||
|
|
||||||
|
printf("%s/%s: Writing to vnode %d, at pgoff 0x%x, %d pages, buf at 0x%x\n",
|
||||||
|
__TASKNAME__, __FUNCTION__, vm_file_to_vnum(f), page_offset, 1, vaddr);
|
||||||
|
|
||||||
/* Syscall to vfs to write page back to file. */
|
/* Syscall to vfs to write page back to file. */
|
||||||
if ((err = vfs_write(vm_file_to_vnum(f), page_offset, 1, vaddr)) < 0)
|
if ((err = vfs_write(vm_file_to_vnum(f), page_offset, 1, vaddr)) < 0)
|
||||||
goto out_err;
|
goto out_err;
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ int fileio2(void)
|
|||||||
perror("OPEN");
|
perror("OPEN");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
printf("Created newfile.txt\n");
|
printf("Created newfile2.txt\n");
|
||||||
|
|
||||||
printf("%s: write.\n", __TASKNAME__);
|
printf("%s: write.\n", __TASKNAME__);
|
||||||
if ((int)(cnt = write(fd, str, strlen(str))) < 0) {
|
if ((int)(cnt = write(fd, str, strlen(str))) < 0) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
cd build
|
cd build
|
||||||
#arm-none-eabi-insight &
|
#arm-none-eabi-insight &
|
||||||
/opt/bin/qemu-system-arm -s -kernel final.axf -nographic -m 128 -M versatilepb &
|
/opt/qemu/bin/qemu-system-arm -s -kernel final.axf -nographic -m 128 -M versatilepb &
|
||||||
arm-none-linux-gnueabi-insight ; pkill qemu-system-arm
|
arm-none-linux-gnueabi-insight ; pkill qemu-system-arm
|
||||||
#arm-none-eabi-gdb ; pkill qemu-system-arm
|
#arm-none-eabi-gdb ; pkill qemu-system-arm
|
||||||
cd ..
|
cd ..
|
||||||
|
|||||||
Reference in New Issue
Block a user