Of course, I forgot to attach the code.

On Tue, May 1, 2012 at 11:16 AM, Ribhi Kamal <[email protected]> wrote:

> Hi, I know that you are very busy but I would really appreciate it if
> someone could find the time to make sure that I'm the right path.
>
> As an exercise, I'm implementing Page Fusion for Linux guests. I setup my
> dev environment (with UML) and wrote some code to pull the physical address
> of each memory area for each process. There is still a lot of work to be
> done before I merge my stuff to vboxguest, like the following:
> 1- Ignore the vboxguest module/service: The windows guest additions do
> this, is it really needed?
> 2- Filter out pages that are NOT read or execute only.
> 3- Find out if the code is safe (locking wise)
> 4- ?
>
> Questions:
> (A) My most important question is what exactly I should be passing down to
> the hypervisor? The physical address of the pages and their length,
> correct? So in the case of "/lib/libc-2.11.3.so" below, I would
> be registering four pages -- 0x37ff3000, 0x38131000, 0x38132000
> and 0x38134000 -- each one has a PAGH_SIZE length.
>
> (B) For scanning processes, is it safe to just add all the pages for files
> under /lib /bin /usr and /sbin?
>
> (C) Is my attached code accessing vm_area_struct safely?
>
> Again, I appreciate any comments/help.
>
> My test module populates the list of physical address an output like below.
>  udevd [411]
>   '/lib/libc-2.11.3.so' vm_mm:0x726ee9c  mmap_base:0x40000000
>  vm_start:0x4003b000 vm_end:0x40179000
>  phy_start:0x37ff3000 phy_end:0x38131000
>   '/lib/libc-2.11.3.so' vm_mm:0x726ee9c  mmap_base:0x40000000
>  vm_start:0x40179000 vm_end:0x4017a000
>  phy_start:0x38131000 phy_end:0x38132000
>   '/lib/libc-2.11.3.so' vm_mm:0x726ee9c  mmap_base:0x40000000
>  vm_start:0x4017a000 vm_end:0x4017c000
>  phy_start:0x38132000 phy_end:0x38134000
>   '/lib/libc-2.11.3.so' vm_mm:0x726ee9c  mmap_base:0x40000000
>  vm_start:0x4017c000 vm_end:0x4017d000
>  phy_start:0x38134000 phy_end:0x38135000
>
>
> udevd [412]
>   '/lib/libc-2.11.3.so' vm_mm:0x726e2cc  mmap_base:0x40000000
>  vm_start:0x4003b000 vm_end:0x40179000
>  phy_start:0x37ff3000 phy_end:0x38131000
>   '/lib/libc-2.11.3.so' vm_mm:0x726e2cc  mmap_base:0x40000000
>  vm_start:0x40179000 vm_end:0x4017a000
>  phy_start:0x38131000 phy_end:0x38132000
>   '/lib/libc-2.11.3.so' vm_mm:0x726e2cc  mmap_base:0x40000000
>  vm_start:0x4017a000 vm_end:0x4017c000
>  phy_start:0x38132000 phy_end:0x38134000
>   '/lib/libc-2.11.3.so' vm_mm:0x726e2cc  mmap_base:0x40000000
>  vm_start:0x4017c000 vm_end:0x4017d000
>  phy_start:0x38134000 phy_end:0x38135000
>
>
> --
> -- Ribhi
>



-- 
-- Ribhi
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/fdtable.h>
#include <linux/memory.h>
#include <linux/mm.h>
#include <asm-generic/io.h>

#ifndef PAGE_SIZE
#define PAGE_SIZE 4096
#endif

static char filePathBuf[PAGE_SIZE]; // This must be PAGE_SIZE

int init_module(void)
{
	int idx = 0;
    struct task_struct * task = NULL;
    struct file * pFile = NULL;
    char * filePath = NULL;
    struct vm_area_struct * memArea = NULL;

    for_each_process(task)
    {
    	// The following is not needed
    	memArea = NULL;
    	pFile = NULL;
    	filePath = NULL;

    	task_lock(task);

    	//-1 unrunnable, 0 runnable, >0 stopped
    	if (task->state == -1)
    		printk("unrunnable " );
    	else if (task->state == 0)
    		printk("runnable   " );
    	else if (task->state > 0)
    		printk("stopped    " );
    	else
    		printk("unknown    " );

    	printk("%s [%d]", task->comm, task->pid);

    	// Will not be used for vbox
    	if (task->files) {
    		printk(" - open file count %i",task->files->count.counter);

    		for ( idx = 0; idx < task->files->count.counter; idx++){
    			rcu_read_lock();
    			pFile = fcheck_files(task->files, idx);

    			if (pFile) {
    				filePathBuf[0] = '\0';
    				filePath = d_path(&pFile->f_path, (char *)filePathBuf , PAGE_SIZE );
    				if (filePath)
    					printk("\n\t'%s'", filePath);
    			}
    			rcu_read_unlock();
    		}

    	}

    	if (task->mm) {
    		printk("\nPrinting Memory Mapped Files\n");
    		for (idx=0;; idx++)
    		{
    			if (idx > 0)
    				// Move on to the next area
    				memArea = memArea->vm_next;
    			else
    				// Get the first area
    				memArea = task->mm->mmap;

    			if (memArea == NULL)
    				break;

    			// Here we care about any file-blacked area meaning that Text and
    			// Data are of interest and all pf memory mapping.
    			// So BSS, Heap and stack are ignored.
    			pFile = memArea->vm_file;
    			if (pFile == NULL)
    				continue;

    			rcu_read_lock();
    			filePathBuf[0] = '\0';
				filePath = d_path(&pFile->f_path, (char *)filePathBuf , PAGE_SIZE );
				rcu_read_unlock();

				if (filePath) {
					printk("  '%s'\n", filePath);
				}

				printk("\t vm_start:0x%lx vm_end:0x%lx\n",
						memArea->vm_start,
						memArea->vm_end);

				printk("\t phy_start:0x%lx phy_end:0x%lx\n",
						virt_to_phys((void *)memArea->vm_start),
						virt_to_phys((void *)memArea->vm_end));


    		}

    		printk("Found %d memory areas\n", idx);
    	}

    	printk("\n\n");
    	task_unlock(task);

    }

    printk("\n");

    return 0;
}

void cleanup_module(void)
{
    printk(KERN_INFO "Cleaning Up.\n");
}
_______________________________________________
vbox-dev mailing list
[email protected]
https://www.virtualbox.org/mailman/listinfo/vbox-dev

Reply via email to