0

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:

  1. Is my address passing method correct? If not what should be changed to get the address of a page frame?
  2. 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.

Misbah
  • 1
  • 3

1 Answers1

1

You may have this call unavailable on your system. If syscall returns -1 you should check the errno:

#include <stdio.h>
#include <linux/kernel.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>

int main()
{
    long int amma = syscall(548);

    if ( amma == -1 )
        printf("syscall failed, errno = %d (%s)\n", errno, strerror(errno));
    else
        printf("address: %ld\n", amma);

    return 0;
}

I receive syscall failed, errno = 38 (Function not implemented) on two different systems, one of them being Ubuntu 20.04 x86_64.

Apart from that, I'm not sure whether amma should contain the returned address, as address shouldn't be signed, therefore it might be returned in one of the parameters (see syscall). Make sure you read the documentation or the source code.

rekmus
  • 71
  • 4