Skip to contentSkip to conversation

tmem: invocations of tmem code from existing xen code

PATCH In review Dan Magenheimer 2 participants 7 messages Feb 6, 2009 – Feb 9, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 8/9 tmem: invocations of tmem code from existing xen code

[8] invocations of tmem code from existing xen code

xen/arch/x86/setup.c +3 -0
diff -r c8962b24fb50 xen/arch/x86/setup.c
@@ -109,6 +109,7 @@ extern void early_cpu_init(void);
 extern void early_cpu_init(void);
 extern void vesa_init(void);
 extern void vesa_mtrr_init(void);
+extern void init_tmem(void);
 
 DEFINE_PER_CPU(struct desc_struct *, gdt_table) = boot_cpu_gdt_table;
 #ifdef CONFIG_COMPAT
@@ -1056,6 +1057,8 @@ void __init __start_xen(unsigned long mb
 
     init_trace_bufs();
 
+    init_tmem();
+
     console_endboot();
 
     /* Hide UART from DOM0 if we're using it */
xen/arch/x86/x86_32/entry.S +2 -0
diff -r c8962b24fb50 xen/arch/x86/x86_32/entry.S
@@ -703,6 +703,7 @@ ENTRY(hypercall_table)
         .long do_sysctl             /* 35 */
         .long do_domctl
         .long do_kexec_op
+        .long do_tmem_op
         .rept __HYPERVISOR_arch_0-((.-hypercall_table)/4)
         .long do_ni_hypercall
         .endr
@@ -750,6 +751,7 @@ ENTRY(hypercall_args_table)
         .byte 1 /* do_sysctl            */  /* 35 */
         .byte 1 /* do_domctl            */
         .byte 2 /* do_kexec_op          */
+        .byte 1 /* do_tmem_op           */
         .rept __HYPERVISOR_arch_0-(.-hypercall_args_table)
         .byte 0 /* do_ni_hypercall      */
         .endr
xen/arch/x86/x86_64/compat/entry.S +2 -0
diff -r c8962b24fb50 xen/arch/x86/x86_64/compat/entry.S
@@ -408,6 +408,7 @@ ENTRY(compat_hypercall_table)
         .quad do_sysctl                 /* 35 */
         .quad do_domctl
         .quad compat_kexec_op
+        .quad do_tmem_op
         .rept __HYPERVISOR_arch_0-((.-compat_hypercall_table)/8)
         .quad compat_ni_hypercall
         .endr
@@ -455,6 +456,7 @@ ENTRY(compat_hypercall_args_table)
         .byte 1 /* do_sysctl                */  /* 35 */
         .byte 1 /* do_domctl                */
         .byte 2 /* compat_kexec_op          */
+        .byte 1 /* do_tmem_op               */
         .rept __HYPERVISOR_arch_0-(.-compat_hypercall_args_table)
         .byte 0 /* compat_ni_hypercall      */
         .endr
xen/arch/x86/x86_64/entry.S +2 -1
diff -r c8962b24fb50 xen/arch/x86/x86_64/entry.S
@@ -692,6 +692,7 @@ ENTRY(hypercall_table)
         .quad do_sysctl             /* 35 */
         .quad do_domctl
         .quad do_kexec_op
+        .quad do_tmem_op
         .rept __HYPERVISOR_arch_0-((.-hypercall_table)/8)
         .quad do_ni_hypercall
         .endr
@@ -739,7 +740,7 @@ ENTRY(hypercall_args_table)
         .byte 1 /* do_sysctl            */  /* 35 */
         .byte 1 /* do_domctl            */
         .byte 2 /* do_kexec             */
-        .byte 1 /* do_xsm_op            */
+        .byte 1 /* do_tmem_op           */
         .rept __HYPERVISOR_arch_0-(.-hypercall_args_table)
         .byte 0 /* do_ni_hypercall      */
         .endr
xen/common/Makefile +4 -0
diff -r c8962b24fb50 xen/common/Makefile
@@ -28,6 +28,10 @@ obj-y += vsprintf.o
 obj-y += vsprintf.o
 obj-y += xmalloc_tlsf.o
 obj-y += rcupdate.o
+obj-y += tmem.o
+obj-y += tmem_xen.o
+obj-y += radix-tree.o
+obj-y += lzo.o
 
 obj-$(perfc)       += perfc.o
 obj-$(crash_debug) += gdbstub.o
xen/common/domain.c +4 -0
diff -r c8962b24fb50 xen/common/domain.c
@@ -30,6 +30,7 @@
 #include <public/sched.h>
 #include <public/vcpu.h>
 #include <xsm/xsm.h>
+#include <xen/tmem.h>
 
 /* Linux config option: propageted to domain0 */
 /* xen_processor_pmbits: xen control Cx, Px, ... */
@@ -569,6 +570,9 @@ static void complete_domain_destroy(stru
 
     grant_table_destroy(d);
 
+    if ( d->tmem != NULL )
+        tmem_destroy(d->tmem);
+
     arch_domain_destroy(d);
 
     rangeset_domain_destroy(d);
xen/include/xen/hypercall.h +4 -0
diff -r c8962b24fb50 xen/include/xen/hypercall.h
@@ -117,6 +117,10 @@ do_xsm_op(
 do_xsm_op(
     XEN_GUEST_HANDLE(xsm_op_t) u_xsm_op);
 
+extern long
+do_tmem_op(
+    XEN_GUEST_HANDLE(tmem_op_t) uops);
+
 #ifdef CONFIG_COMPAT
 
 extern int

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

#1 lore raw

Re: [PATCH 8/9] tmem: invocations of tmem code fromexisting xen code

Quoted 2 lines
Quoted 1 line
Quoted 1 line

Dan Magenheimer <[email protected]> 06.02.09 01:47 >>>

[8] invocations of tmem code from existing xen code

You use do_tmem_op() directly for 32-on-64 mode, which I think is wrong given the definition of the interface structure (you'd minimally have to use XEN_GUEST_HANDLE_64 in order for this to be correct). But even if it was right (or if you make it so), it would in my opinion be a requirement to assure it is by adding a respective entry to xen/include/xlat.lst.

Jan

#2 lore raw

RE: [PATCH 8/9] tmem: invocations of tmem code fromexisting xen code

Quoted 9 lines

You use do_tmem_op() directly for 32-on-64 mode, which I think is wrong
given the definition of the interface structure (you'd minimally have to use
XEN_GUEST_HANDLE_64 in order for this to be correct). But even if it was
right (or if you make it so), it would in my opinion be a requirement to
assure it is by adding a respective entry to xen/include/xlat.lst.

I have to admit I am baffled by all aspects of XEN_GUEST_HANDLE and just hacked on it until the code worked. I would be grateful for either an explanation of xen/include/xlat.lst or a pointer to an explanation... or, even better, hints on how to fix my code to properly use XEN_GUEST_HANDLE_64.

I would like the code to definitely support 32-on-64 and 64-on-64. 32-on-32 is optional; because of xenheap limitations it is largely a toy, but still useful for testing.

All of this works today, but possibly only due to hackery, which I am eager to fix properly if told how.

Thanks,
Dan

#3 lore raw

RE: [PATCH 8/9] tmem: invocations of tmem codefromexisting xen code

Quoted 6 lines
Quoted 1 line
Quoted 1 line

Dan Magenheimer <[email protected]> 06.02.09 15:25 >>>

I have to admit I am baffled by all aspects of XEN_GUEST_HANDLE and just hacked on it until the code worked. I would be grateful for either an explanation of xen/include/xlat.lst or a pointer to an explanation... or, even better, hints on how to fix my code to properly use XEN_GUEST_HANDLE_64.

The easiest thing is certainly to simply replace XEN_GUEST_HANDLE by XEN_GUEST_HANDLE_64.

As to xlat.lst, just add ? entry there - the ? says the type needs to be checked, and it is followed by the type's name and the header it is found in. This will generate a CHECK_<typename> macro in xen/include/compat/xlat.h, which you then ought to use somewhere in the source code. Just pick one of the existing entries to see how this works.

Jan

#4 lore raw

RE: [PATCH 8/9] tmem: invocations of tmem codefromexisting xen code

Quoted 9 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line

Dan Magenheimer <[email protected]> 06.02.09 15:25 >>>

I have to admit I am baffled by all aspects of XEN_GUEST_HANDLE and just hacked on it until the code worked. I would be grateful for either an explanation of xen/include/xlat.lst or a pointer to an explanation... or, even better, hints on how to fix my code to properly use XEN_GUEST_HANDLE_64.

The easiest thing is certainly to simply replace XEN_GUEST_HANDLE by XEN_GUEST_HANDLE_64.

OK, I did that and it compiles fine. What's the difference between the two? Is the _64 version used when the structure contains a 64-bit value that might not be aligned on a 64-bit boundary?

Quoted 7 lines

As to xlat.lst, just add ? entry there - the ? says the type needs to be
checked, and it is followed by the type's name and the header it is found in. This will generate a CHECK_<typename> macro in xen/include/compat/xlat.h, which you then ought to use somewhere in the source code. Just pick one of the existing entries to see how this works.

I'm afraid that after an hour or two of trying to understand this xlat code (and why it exists*) and trying to duplicate it for tmem (which works without it), I'm still not able to get anything to compile, probably because I don't really understand what's going on. Could you be a bit more precise as to what is needed? Perhaps a README or wiki page would be useful.

Just adding tmem_op...tmem.h to xlat.lst and adding a new common/compat/tmem_xen.c with:

#define xen_tmem_op tmem_op
CHECK_tmem_op;
#undef xen_tmem_op

doesn't seem to work (generates "sed: can't read compat/tmem.h"), so please define "use somewhere" more precisely. The existing entries don't provide much guidance as they all seem to be doing complex things, that I don't think I need.

Also, ignoring the structure alignment/packing rules, is this supposed to get rid of the masking I do in cli_mfn_to_va() when the hypercall is made by a 32-bit guest?

Thanks,
Dan

* I guess I come from an era where it is the system programmer's responsibility to ensure that data structures are defined to ensure they meet all the packing and alignment restrictions of all the architectures they are intended to run on. While I'm all for compile-time checks to catch poor programming or old 16- and 32-bit code that now needs to run on a 64-bit machine, this seems, well, a bit overboard imho.

#5 lore raw

RE: [PATCH 8/9] tmem: invocations of tmemcodefromexisting xen code

Quoted 5 lines
Quoted 1 line
Quoted 1 line

Dan Magenheimer <[email protected]> 06.02.09 20:00 >>>

OK, I did that and it compiles fine. What's the difference between the two? Is the _64 version used when the structure contains a 64-bit value that might not be aligned on a 64-bit boundary?

Not only, it's also widening the field to 64-bits to make sure the (native) 64-bit accessors can be used on it.

Quoted 8 lines

Just adding tmem_op...tmem.h to xlat.lst and adding a new common/compat/tmem_xen.c with:

#define xen_tmem_op tmem_op
CHECK_tmem_op;
#undef xen_tmem_op

doesn't seem to work (generates "sed: can't read compat/tmem.h"),

Yeah, I forgot that with a new header you'd have to also add that new header's name to header-y in xen/include/Makefile, so that a compat header would be generated.

Quoted 3 lines

so please define "use somewhere" more precisely. The existing entries don't provide much guidance as they all seem to be doing complex things, that I don't think I need.

If it seems to cumbersome, just leave it off for the moment, and I'll submit a fixup patch after it got merged.

Quoted 3 lines

Also, ignoring the structure alignment/packing rules, is this supposed to get rid of the masking I do in cli_mfn_to_va() when the hypercall is made by a 32-bit guest?

I thought it was (I didn't invent it), but it appears it isn't. Though there also shouldn't be a need to - all the guest can clobber by specifying a handle that doesn't have the upper 32 bits clear is its argument translation area, which means it can only shoot itself in the foot. But you ought to be using guest_handle_cast there (and perhaps elsewhere) anyway (rather than referencing handle.p directly), which would allow hiding any masking in case it would turn out necessary.

Jan

#6 lore raw

RE: [PATCH 8/9] tmem: invocations of tmemcodefromexisting xen code

Quoted 3 lines

If it seems to cumbersome, just leave it off for the moment, and I'll submit
a fixup patch after it got merged.

Thanks very much! I'll leave my partially complete compat changes in the next round as there are probably just one or two things I am missing.

Quoted 5 lines

But you ought to be using
guest_handle_cast there (and perhaps elsewhere) anyway (rather than referencing handle.p directly), which would allow hiding any masking in
case it would turn out necessary.

I think cli_mfn_to_va() is the only place. Since the current code works and my attempts to fix it to use guest_handle_cast have failed, I'd appreciate post-merge fixup help here too!

Thanks,
Dan