Machine specification: Ubuntu 16.04, kernel 4.17.4
I want to allocated page frames from kernel and use these frames into a user process such that some portion of the process (i.e. a function) uses those memory pages. The idea is taken from this paper: http://class.ece.iastate.edu/tyagi/cpre581/papers/HPCA16Catalyst.pdf
In that paper authors have allocated page frames in host machine and exposed those frames to virtual machine so that processes from VMs use those specific page frames for certain operations (necessary system calls are used). These page frame are protected using intel cache allocation technology (https://github.com/intel/intel-cmt-cat). I want to do the same thing except the VM part. My applications will run on host machine.
For allocating memory page, I have used alloc_pages() and made a system call to access from userspace. The code of the system call sys_allocate() for allocating page is as follows:
#include <linux/kernel.h>
#include <linux/module.h>
#include <asm/page.h>
struct page *page1;
asmlinkage long sys_allocate(void)
{
struct page *page;
page = alloc_pages(GFP_KERNEL, 0);
page1 = page;
return page;
}
The above code should allocate one page frame. I wanted to access the page frame using following code:
#include <stdio.h>
#include <linux/kernel.h>
#include <sys/syscall.h>
#include <unistd.h>
int main()
{
long int amma = syscall(548);
printf("address: %ld\n", amma);
return 0;
}
It is returning a negative number, I am assuming I have problem with data type. Now, my question has two parts:
- Is my address passing method correct? If not what should be changed to get the address of a page frame?
- How do I force a function to use that page frame? Here is an example function:
void foo()
{
custom_map()
..
..
..
custom_unmap()
}
using sys_allocate(), one page frame will be created when the machine boots up. And ** custom_map()** is the system call which will be used to force the variables, instructions etc. in the function to be loaded in the page frame. custom_unmap() will release the page frame so that other process can use it.