Deep Narayan Dubey |
01-04-2011 05:17 AM |
Error while saving memory pages of a process- Sleeping in memory from invalid context
Hi,
I am trying to checkpoint process state in a file so that I can restore it later. I am able to save the registers, open files, signals of a process. I am also able to save the task->mm information and the vma start, end and offset but when I am trying to save pages I am getting following error -
Sleeping function is called from invalid context
My code for saving page is following -
Code:
/*
* This function saves the memory pages in the region of memory specified by vma
*/
int save_pages(struct task_struct *task, struct vm_area_struct *vma, struct segments *seg) {
int ret = 0;
int len = PAGE_SIZE;
struct mm_struct *mm;
unsigned long addr;
struct page *page;
pte_t * pte;
if(!(vma->vm_flags & VM_WRITE) || get_fd(task,vma->vm_file) != -1) {
return(0);
}
mm = task->mm;
if(!mm) {
return -1;
}
for(addr = vma->vm_start ; addr < vma->vm_end ; addr = addr + PAGE_SIZE) {
seg->num_pages++;
pte = chkpt_get_pte(vma,addr);
if(pte && pte_present(*pte)) {
page = pfn_to_page(pte_pfn(*pte));
if(page_mapped(page)) {
if(addr + PAGE_SIZE > vma->vm_end) {
len = vma->vm_end - addr;
}
else {
len = PAGE_SIZE;
}
if(vma->vm_flags & VM_MAYREAD) {
if(copy_from_user(buffer, (void *)addr, len) != 0) {
printk(KERN_ALERT "Error while copying pages from used addr %lu to buffer\n", addr);
return -1;
}
ret = chkpt_write(filp,&addr,sizeof(unsigned long));
if(ret < 0) {
printk(KERN_ALERT "Error while saving the address = %lu\n", addr);
return(ret);
}
ret = chkpt_write(filp, buffer, PAGE_SIZE);
if(ret < 0) {
printk(KERN_ALERT "Error while saving the page\n");
return(ret);
}
}
}
}
}
return(ret);
}
I have created a lock before saving memory using down_read(&task->mm->mmap_sem);
The stack trace printed after the above error gives that the above error has occurred when copy_from_user() function is called. It internally invokes the might_sleep() function and this function prints the above error.
Please, help so that I can remove the above error and save the memory pages.
Thanks in advance for any help.
|