Skip to contentSkip to conversation

Help With Custom Hyper Calls

DISCUSSION John Backes 3 participants 6 messages Aug 12, 2011 – Aug 15, 2011

lore
Share & tools
lore
#0 lore raw

Hello,

So I'm new to Xen development and want to play around with Xen Hypercalls, but havn't been able to find a whole lot of documentation related to creating custom Hypercalls. I've found that to create a custom Hypercall I need to define it with an unused Hypercall number in "xen/include/public/xen.h", but then I am unsure of the next steps (e.g., where to place the function to call with the Hypercall).

Can anyone point more towards some documentation or at least towards the correct locations for registering new Hypercalls? Thanks in advance.

- John

#1 lore raw
Quoted 11 lines · John Backes

Hello,

So I'm new to Xen development and want to play around with Xen Hypercalls, but havn't been able to find a whole lot of documentation related to creating custom Hypercalls. I've found that to create a custom Hypercall I need to define it with an unused Hypercall number in "xen/include/public/xen.h", but then I am unsure of the next steps (e.g., where to place the function to call with the Hypercall).

Can anyone point more towards some documentation or at least towards the correct locations for registering new Hypercalls? Thanks in advance.

Pick the name of a hypercall, e.g., update_va_mapping has a nice distinctive name. Recursive grep for that name in the Xen and Linux source trees. Should give you a pretty good start on the few places you need to register in the hypervisor and in the guest kernel.

-- Keir

Quoted 6 lines

- John

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#2 lore raw

So I greped through the s

I've altered the hypercall_table and hypercall_args_table to have an additional entry in xen/arch/x86/x86_32/entry.S and in xen/arch/x86/x86_64/entry.S:

to the hypercall_table:

...........................
.long do_sysctl /* 35 */
.long do_domctl
.long do_kexec_op
.long do_tmem_op
.long do_new_hyper /* 39 */
...........................

to the hypercall_args_table:

...........................

         .byte 1 /* do_sysctl            */  /* 35 */
         .byte 1 /* do_domctl            */
         .byte 2 /* do_kexec_op          */
         .byte 1 /* do_tmem_op           */
         .byte 0 /* do_new_hyper         */  /* 39 */

...........................

I've also registered the name in xen/include/public/xen.h

...........................
#define __HYPERVISOR_new_hyper 39
...........................

and I've added the following function to xen/arch/x86/mm.c

...........................
void do_new_hyper ( void )

{
      printk("NEW HYPERCALL RECEIVED\n");
}

...........................

To test this, I am running a fedora 14 dom0 and I wrote the following kernel module (so the code runs in ring 1):

...........................
#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>

MODULE_LICENSE("GPL");

#define SUCCESS 0

static int hyper_init(void){

int output;

  printk(KERN_ALERT "Testing Hypercall\n");

__asm__ ( "movl $39, %%eax;"

            "int $0x82;"
          : "=a" (output)
          );

return SUCCESS;
}

static void hyper_exit(void){
printk(KERN_ALERT "Removing Hypercall Module");

}

module_init(hyper_init);
module_exit(hyper_exit);
...........................

I then run "xm dmesg" to see if I can see the "NEW HYPERCALL RECEIVED" message, but nothing appears. Any thoughts?

- John

Quoted 30 lines · Keir Fraser
Quoted 11 lines · John Backes

Hello,

So I'm new to Xen development and want to play around with Xen Hypercalls, but havn't been able to find a whole lot of documentation related to creating custom Hypercalls. I've found that to create a custom Hypercall I need to define it with an unused Hypercall number in "xen/include/public/xen.h", but then I am unsure of the next steps (e.g., where to place the function to call with the Hypercall).

Can anyone point more towards some documentation or at least towards the correct locations for registering new Hypercalls? Thanks in advance.

Pick the name of a hypercall, e.g., update_va_mapping has a nice distinctive name. Recursive grep for that name in the Xen and Linux source trees. Should give you a pretty good start on the few places you need to register in the hypervisor and in the guest kernel.

-- Keir

Quoted 6 lines

- John

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#3 lore raw
Quoted 6 lines · John Backes

So I greped through the s

I've altered the hypercall_table and hypercall_args_table to have an additional entry in xen/arch/x86/x86_32/entry.S and in xen/arch/x86/x86_64/entry.S:

You also need to edit xen/arch/x86/x86_64/compat/entry.S, for the case where Xen is 64-bit and dom0 kernel is 32-bit.

Quoted 10 lines

static int hyper_init(void){

int output;

  printk(KERN_ALERT "Testing Hypercall\n");

__asm__ ( "movl $39, %%eax;"

            "int $0x82;"
          : "=a" (output)
          );

While this should work, you probably ought to be using the hypercall page (and the existing kernel mechanisms) to make hypercalls.

Quoted 7 lines

return SUCCESS;
}

static void hyper_exit(void){
printk(KERN_ALERT "Removing Hypercall Module");

Quoted 8 lines

}

module_init(hyper_init);
module_exit(hyper_exit);
...........................

I then run "xm dmesg" to see if I can see the "NEW HYPERCALL RECEIVED" message, but nothing appears. Any thoughts?

You could print the return value from the hypercall in your module?

Tim.

Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, Xen Platform Team
Citrix Systems UK Ltd.  (Company #02937203, SL9 0BG)
#4 lore raw

I changed the table entries in both xen/arch/x86/x86_32/entry.S and xen/arch/x86/x86_64/entry.S. Could you point me towards these existing kernel mechanisms for issuing hypercalls? Thanks.

- John

Quoted 45 lines · Tim Deegan
Quoted 6 lines · John Backes

So I greped through the s

I've altered the hypercall_table and hypercall_args_table to have an additional entry in xen/arch/x86/x86_32/entry.S and in xen/arch/x86/x86_64/entry.S:

You also need to edit xen/arch/x86/x86_64/compat/entry.S, for the case where Xen is 64-bit and dom0 kernel is 32-bit.

Quoted 10 lines

static int hyper_init(void){

int output;

  printk(KERN_ALERT "Testing Hypercall\n");

__asm__ ( "movl $39, %%eax;"

            "int $0x82;"
          : "=a" (output)
          );

While this should work, you probably ought to be using the hypercall page (and the existing kernel mechanisms) to make hypercalls.

Quoted 7 lines

return SUCCESS;
}

static void hyper_exit(void){
printk(KERN_ALERT "Removing Hypercall Module");

Quoted 8 lines

}

module_init(hyper_init);
module_exit(hyper_exit);
...........................

I then run "xm dmesg" to see if I can see the "NEW HYPERCALL RECEIVED" message, but nothing appears. Any thoughts?

You could print the return value from the hypercall in your module?

Tim.

#5 lore raw

Hi,

Please don't top-post.

Quoted 2 lines · John Backes

I changed the table entries in both xen/arch/x86/x86_32/entry.S and xen/arch/x86/x86_64/entry.S.

Yes; you also need to edit xen/arch/x86/x86_64/compat/entry.S

Quoted 2 lines

Could you point me towards these existing
kernel mechanisms for issuing hypercalls? Thanks.

In linux: arch/x86/include/asm/xen/hypercall.h

Cheers,

Tim.

Quoted 46 lines · Tim Deegan
Quoted 45 lines
Quoted 6 lines · John Backes

So I greped through the s

I've altered the hypercall_table and hypercall_args_table to have an additional entry in xen/arch/x86/x86_32/entry.S and in xen/arch/x86/x86_64/entry.S:

You also need to edit xen/arch/x86/x86_64/compat/entry.S, for the case where Xen is 64-bit and dom0 kernel is 32-bit.

Quoted 10 lines

static int hyper_init(void){

int output;

  printk(KERN_ALERT "Testing Hypercall\n");

__asm__ ( "movl $39, %%eax;"

            "int $0x82;"
          : "=a" (output)
          );

While this should work, you probably ought to be using the hypercall page (and the existing kernel mechanisms) to make hypercalls.

Quoted 7 lines

return SUCCESS;
}

static void hyper_exit(void){
printk(KERN_ALERT "Removing Hypercall Module");

Quoted 8 lines

}

module_init(hyper_init);
module_exit(hyper_exit);
...........................

I then run "xm dmesg" to see if I can see the "NEW HYPERCALL RECEIVED" message, but nothing appears. Any thoughts?

You could print the return value from the hypercall in your module?

Tim.

Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, Xen Platform Team
Citrix Systems UK Ltd.  (Company #02937203, SL9 0BG)