All of lore.kernel.org
 help / color / mirror / Atom feed
* Hypercall from HVM guest
@ 2008-09-25 14:55 Emre Can Sezer
  2008-09-25 14:58 ` Emre Can Sezer
  2008-09-25 18:40 ` Steve Ofsthun
  0 siblings, 2 replies; 7+ messages in thread
From: Emre Can Sezer @ 2008-09-25 14:55 UTC (permalink / raw)
  To: xen-devel

Hi,

I'm trying to communicate some information from an HVM guest to Xen. 
Passing a pointer to a buffer would suffice and the communication will be
single sided.  What is the best way to do this?

I've looked into making a hypercall from an HVM guest and came across this
post on this mailing list by Steve Ofsthun:

http://lists.xensource.com/archives/html/xen-devel/2006-04/msg00526.html

However, I'm unable to get this code to work.  I'm running a 64-bit system
with the linux-2.6.26 kernel downloaded from kernel.org on top of
xen-3.2.2.  When I compile, I get compilation errors resulting from
hypercall.h.  I believe this code is intended for 32 bit guests only as
the structure definitions are different fot the pte_t type.

The error was:
In file included from include/asm/xen/hypervisor.h:53,
                 from /home/ecsezer/kernels/vmcall/./features.c:11:
include/asm/xen/hypercall.h: In function 'HYPERVISOR_update_va_mapping':
include/asm/xen/hypercall.h:230: error: 'pte_t' has no member named 'pte_low'

I tried to modify this code to get rid of compilation errors but a final
warning still persists and loading the module causes a seg fault.  The
warning I get is:
  CC [M]  /home/ecsezer/kernels/hyper/./hypercall.o
{standard input}: Assembler messages:
{standard input}:149: Warning: indirect call without `*'

So I tried to compile with mercurial repository version linux-2.6.18-xen
and that compiles fine.  However, due to being a different version, I
can't use the resulting module.

I would appreciate any insight as to how to proceed.  What could be the
problem?  Perhaps there is an easier way of passing the information I want
without a full blown hypercall interface?

Thanks,

John

^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: Hypercall from HVM guest
@ 2008-09-25 20:51 Emre Can Sezer
  0 siblings, 0 replies; 7+ messages in thread
From: Emre Can Sezer @ 2008-09-25 20:51 UTC (permalink / raw)
  To: xen-devel

[-- Attachment #1: Type: text/plain, Size: 3492 bytes --]

> Emre Can Sezer wrote:
>> Hi,
>>
>> I'm trying to communicate some information from an HVM guest to Xen.
Passing a pointer to a buffer would suffice and the communication will
be
>> single sided.  What is the best way to do this?
>>
>> I've looked into making a hypercall from an HVM guest and came across this
>> post on this mailing list by Steve Ofsthun:
>>
>> http://lists.xensource.com/archives/html/xen-devel/2006-04/msg00526.html
>
> This code is quite old and much has changed since then.  You should
probably use the pv on hvm driver code as an example these days
> (xen/unmodified_drivers/linux-2.6/platform-pci).
>
> What hypercalls are you trying to use?  Note that HVM guests are
restricted to a subset of the normal PV guest hypercalls.
>
> Steve
>

I'm trying to pass some information about the guest kernel to the VMM and
thought that passing a single pointer to a buffer would suffice.  I plan
on introducing a new hypercall for my purposes and update vmx.c in Xen. If
there is a better way of doing it please let me know.

I put together some code, mainly from platform-pci.c and your previous
posts and I was able to capture the hypercall from Xen.  I've attached the
code below.  My problem was the xen related header files in the new linux
distributions from kernel.org.  So instead of including them, I copied the
relevant information to the source.  I've attached the code below.

I wonder if this is a bug or if 64-bit systems aren't supported or if they
don't support xen anymore.  The __HYPERCALL_ definitions for example are
lacking what you have in xen.h in linux-2.6.18-xen.  Although they've come
up with 2.6.26-5, the changelogs don't mention anything about xen header
files.

It would be great if there was a skeleton code that people could use. 
Perhaps someone would like to take this code and pretty it up? :)

Cheers,

John


>>
>> However, I'm unable to get this code to work.  I'm running a 64-bit system
>> with the linux-2.6.26 kernel downloaded from kernel.org on top of
xen-3.2.2.  When I compile, I get compilation errors resulting from
hypercall.h.  I believe this code is intended for 32 bit guests only as
the structure definitions are different fot the pte_t type.
>>
>> The error was:
>> In file included from include/asm/xen/hypervisor.h:53,
>>                  from /home/ecsezer/kernels/vmcall/./features.c:11:
>> include/asm/xen/hypercall.h: In function
'HYPERVISOR_update_va_mapping': include/asm/xen/hypercall.h:230: error:
'pte_t' has no member named 'pte_low'
>>
>> I tried to modify this code to get rid of compilation errors but a
final warning still persists and loading the module causes a seg fault.
 The warning I get is:
>>   CC [M]  /home/ecsezer/kernels/hyper/./hypercall.o
>> {standard input}: Assembler messages:
>> {standard input}:149: Warning: indirect call without `*'
>>
>> So I tried to compile with mercurial repository version
linux-2.6.18-xen and that compiles fine.  However, due to being a
different version, I can't use the resulting module.
>>
>> I would appreciate any insight as to how to proceed.  What could be the
problem?  Perhaps there is an easier way of passing the information I
want
>> without a full blown hypercall interface?
>>
>> Thanks,
>>
>> John
>>
>> _______________________________________________
>> Xen-devel mailing list
>> Xen-devel@lists.xensource.com
>> http://lists.xensource.com/xen-devel
>
>


[-- Attachment #2: test --]
[-- Type: application/octet-stream, Size: 7030 bytes --]

--- "Makefile" ---

obj-m := test.o

all:
	$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
	$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean


--- "test.c" ---

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/vmalloc.h>
#include <linux/mm.h>
#include <asm/pgtable.h>

MODULE_AUTHOR("ecsezer@ncsu.edu");
MODULE_DESCRIPTION("Xen hypercall test for HVM guests");
MODULE_LICENSE("GPL");

char *hypercall_stubs;

/*
 * HYPERCALLS: Copied directly from 
 * linux-2.6.18-xen/include/xen/interface/xen.h
 */

#define __HYPERVISOR_set_trap_table        0
#define __HYPERVISOR_mmu_update            1
#define __HYPERVISOR_set_gdt               2
#define __HYPERVISOR_stack_switch          3
#define __HYPERVISOR_set_callbacks         4
#define __HYPERVISOR_fpu_taskswitch        5
#define __HYPERVISOR_sched_op_compat       6 /* compat since 0x00030101 */
#define __HYPERVISOR_platform_op           7
#define __HYPERVISOR_set_debugreg          8
#define __HYPERVISOR_get_debugreg          9
#define __HYPERVISOR_update_descriptor    10
#define __HYPERVISOR_memory_op            12
#define __HYPERVISOR_multicall            13
#define __HYPERVISOR_update_va_mapping    14
#define __HYPERVISOR_set_timer_op         15
#define __HYPERVISOR_event_channel_op_compat 16 /* compat since 0x00030202 */
#define __HYPERVISOR_xen_version          17
#define __HYPERVISOR_console_io           18
#define __HYPERVISOR_physdev_op_compat    19 /* compat since 0x00030202 */
#define __HYPERVISOR_grant_table_op       20
#define __HYPERVISOR_vm_assist            21
#define __HYPERVISOR_update_va_mapping_otherdomain 22
#define __HYPERVISOR_iret                 23 /* x86 only */
#define __HYPERVISOR_vcpu_op              24
#define __HYPERVISOR_set_segment_base     25 /* x86/64 only */
#define __HYPERVISOR_mmuext_op            26
#define __HYPERVISOR_xsm_op               27
#define __HYPERVISOR_nmi_op               28
#define __HYPERVISOR_sched_op             29
#define __HYPERVISOR_callback_op          30
#define __HYPERVISOR_xenoprof_op          31
#define __HYPERVISOR_event_channel_op     32
#define __HYPERVISOR_physdev_op           33
#define __HYPERVISOR_hvm_op               34
#define __HYPERVISOR_sysctl               35
#define __HYPERVISOR_domctl               36
#define __HYPERVISOR_kexec_op             37

/* Architecture-specific hypercall definitions. */
#define __HYPERVISOR_arch_0               48
#define __HYPERVISOR_arch_1               49
#define __HYPERVISOR_arch_2               50
#define __HYPERVISOR_arch_3               51
#define __HYPERVISOR_arch_4               52
#define __HYPERVISOR_arch_5               53
#define __HYPERVISOR_arch_6               54
#define __HYPERVISOR_arch_7               55


/*
 * The following macros were copied from 
 * linux-2.6.18-xen/include/asm-x86_64/mach-xen/asm/hypercall.h.
 * Normally including xen/hypercall.h should suffice, however,
 * linux-2.6.26 does not seem to support 64 bit architectures for
 * xen purposes.
 */

#define _hypercall0(type, name)			\
({						\
	type __res;				\
	asm volatile (				\
		HYPERCALL_STR(name)		\
		: "=a" (__res)			\
		:				\
		: "memory" );			\
	__res;					\
})

#define _hypercall1(type, name, a1)				\
({								\
	type __res;						\
	long __ign1;						\
	asm volatile (						\
		HYPERCALL_STR(name)				\
		: "=a" (__res), "=D" (__ign1)			\
		: "1" ((long)(a1))				\
		: "memory" );					\
	__res;							\
})

#define _hypercall2(type, name, a1, a2)				\
({								\
	type __res;						\
	long __ign1, __ign2;					\
	asm volatile (						\
		HYPERCALL_STR(name)				\
		: "=a" (__res), "=D" (__ign1), "=S" (__ign2)	\
		: "1" ((long)(a1)), "2" ((long)(a2))		\
		: "memory" );					\
	__res;							\
})

#define _hypercall3(type, name, a1, a2, a3)			\
({								\
	type __res;						\
	long __ign1, __ign2, __ign3;				\
	asm volatile (						\
		HYPERCALL_STR(name)				\
		: "=a" (__res), "=D" (__ign1), "=S" (__ign2), 	\
		"=d" (__ign3)					\
		: "1" ((long)(a1)), "2" ((long)(a2)),		\
		"3" ((long)(a3))				\
		: "memory" );					\
	__res;							\
})

#define _hypercall4(type, name, a1, a2, a3, a4)			\
({								\
	type __res;						\
	long __ign1, __ign2, __ign3;				\
	register long __arg4 asm("r10") = (long)(a4);		\
	asm volatile (						\
		HYPERCALL_STR(name)				\
		: "=a" (__res), "=D" (__ign1), "=S" (__ign2),	\
		  "=d" (__ign3), "+r" (__arg4)			\
		: "1" ((long)(a1)), "2" ((long)(a2)),		\
		  "3" ((long)(a3))				\
		: "memory" );					\
	__res;							\
})
#define HYPERCALL_STR(name)					\
	"mov $("__stringify(__HYPERVISOR_##name)" * 32),%%eax; "\
	"add hypercall_stubs(%%rip),%%rax; "			\
	"call *%%rax"

#define _hypercall5(type, name, a1, a2, a3, a4, a5)		\
({								\
	type __res;						\
	long __ign1, __ign2, __ign3;				\
	register long __arg4 asm("r10") = (long)(a4);		\
	register long __arg5 asm("r8") = (long)(a5);		\
	asm volatile (						\
		HYPERCALL_STR(name)				\
		: "=a" (__res), "=D" (__ign1), "=S" (__ign2),	\
		  "=d" (__ign3), "+r" (__arg4), "+r" (__arg5)	\
		: "1" ((long)(a1)), "2" ((long)(a2)),		\
		  "3" ((long)(a3))				\
		: "memory" );					\
	__res;							\
})

static inline int
HYPERVISOR_arg_test(long a, long b, long c, long d, long e)
{
        return _hypercall5(int, grant_table_op, a, b, c, d, e);
}


static int init_hypercall(void)
{
	uint32_t eax, ebx, ecx, edx, pages, msr, i;
	char signature[13];

	cpuid(0x40000000, &eax, &ebx, &ecx, &edx);
	*(uint32_t*)(signature + 0) = ebx;
	*(uint32_t*)(signature + 4) = ecx;
	*(uint32_t*)(signature + 8) = edx;
	signature[12] = 0;

	if (strcmp("XenVMMXenVMM", signature) || (eax < 0x40000002)) {
		printk(KERN_WARNING
		       "Detected Xen platform device but not Xen VMM?"
		       " (sig %s, eax %x)\n",
		       signature, eax);
		return -EINVAL;
	}

	cpuid(0x40000001, &eax, &ebx, &ecx, &edx);

	printk(KERN_INFO "Xen version %d.%d.\n", eax >> 16, eax & 0xffff);

	/*
	 * Find largest supported number of hypercall pages.
	 * We'll create as many as possible up to this number.
	 */
	cpuid(0x40000002, &pages, &msr, &ecx, &edx);

	/*
	 * Use __vmalloc() because vmalloc_exec() is not an exported symbol.
	 * PAGE_KERNEL_EXEC also is not exported, hence we use PAGE_KERNEL.
	 * hypercall_stubs = vmalloc_exec(pages * PAGE_SIZE);
	 */
	while (pages > 0) {
		hypercall_stubs = __vmalloc(
			pages * PAGE_SIZE,
			GFP_KERNEL, // | __GFP_HIGHMEM,
			__pgprot(__PAGE_KERNEL & ~_PAGE_NX));
		if (hypercall_stubs != NULL)
			break;
		pages--; /* vmalloc failed: try one fewer pages */
	}

	if (hypercall_stubs == NULL)
		return -ENOMEM;

	for (i = 0; i < pages; i++) {
		unsigned long pfn;
		pfn = vmalloc_to_pfn((char *)hypercall_stubs + i*PAGE_SIZE);
		wrmsrl(msr, ((u64)pfn << PAGE_SHIFT) + i);
	}

	printk(KERN_INFO "Hypercall area is %u pages.\n", pages);

	HYPERVISOR_arg_test(0x1111111111111111, 0x2222222222222222,
		0x3333333333333333, 0x4444444444444444, 0x5555555555555555);

	return 0;
}


module_init(init_hypercall);

-----------------------------------------------------------------

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 7+ messages in thread
* Hypercall from Hvm Guest
@ 2007-06-22 10:40 Koripella Srinivas
  2007-06-22 10:46 ` Cui, Dexuan
  2007-06-22 10:48 ` Petersson, Mats
  0 siblings, 2 replies; 7+ messages in thread
From: Koripella Srinivas @ 2007-06-22 10:40 UTC (permalink / raw)
  To: xen-devel


[-- Attachment #1.1: Type: text/plain, Size: 250 bytes --]

Can i make hypercalls from a HVM Guest?
I want to write a module in Linux and make hvm calls from that module.
Is it possible?

Thanks




      Once upon a time there was 1 GB storage on Yahoo! Mail. Go here for happy ending http://in.mail.yahoo.com

[-- Attachment #1.2: Type: text/html, Size: 511 bytes --]

[-- Attachment #2: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-09-25 20:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-25 14:55 Hypercall from HVM guest Emre Can Sezer
2008-09-25 14:58 ` Emre Can Sezer
2008-09-25 18:40 ` Steve Ofsthun
  -- strict thread matches above, loose matches on Subject: below --
2008-09-25 20:51 Emre Can Sezer
2007-06-22 10:40 Hypercall from Hvm Guest Koripella Srinivas
2007-06-22 10:46 ` Cui, Dexuan
2007-06-22 10:48 ` Petersson, Mats

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.