Skip to contentSkip to conversation

Confusion about copy_to/from_guest

DISCUSSION Tej 2 participants 3 messages Apr 26, 2010 – Apr 27, 2010

lore
Share & tools
lore

Tej

author
#0 lore raw

All,

Small and naive question about the semantics of copy_to/from_guest. In Kernel space I have created a linked list lets say 10 elements. Now I have created similar list in hypervisor.

Now passing the list_head from kernel using hypercall. Now how do I copy the element between kernel and hypervisor.

1. copy_from_guest(hyp_list_head, arg, 1) or copy_from_guest(hyp_list_head, arg, <num_of_elements_list>)
2. copy_to_guest(arg, hyp_list_head, 1) or copy_to_guest(arg, hyp_list_head, <num of element in list>)

2nd question:
I did first one, but first element of list was not accessible in hypervisor space, why?

It looks like I am doing something horribly wrong, so can someone point out that.

Thanks for any help
-tej

#1 lore raw
Quoted 7 lines · Tej

Now passing the list_head from kernel using hypercall. Now how do I copy the element between kernel and hypervisor.

1. copy_from_guest(hyp_list_head, arg, 1) or copy_from_guest(hyp_list_head, arg, <num_of_elements_list>)
2. copy_to_guest(arg, hyp_list_head, 1) or copy_to_guest(arg, hyp_list_head, <num of element in list>)

The first of these. Copy_{to,from}_guest can copy arrays of structures, but since this is a linked structure you'd have to do the copy one element at a time.

Quoted 3 lines

2nd question:
I did first one, but first element of list was not accessible in hypervisor space, why?

Well, if you are really only copying the list_head, the above should work.

-- Keir

author
#2 lore raw
Quoted 5 lines · Keir Fraser
Quoted 3 lines · Tej

Now passing the list_head from kernel using hypercall. Now how do I copy the element between kernel and hypervisor.

Quoted 8 lines
Quoted 4 lines

1. copy_from_guest(hyp_list_head, arg, 1) or copy_from_guest(hyp_list_head, arg, <num_of_elements_list>)
2. copy_to_guest(arg, hyp_list_head, 1) or copy_to_guest(arg, hyp_list_head, <num of element in list>)

The first of these. Copy_{to,from}_guest can copy arrays of structures, but since this is a linked structure you'd have to do the copy one element at a time.

you mean to say, in hypervisor space copy first element using copy_from_guest(hyp_list_head, arg, 1), extract the next address from it and then copy again the next element using "copy_from_guest(hyp_list_head->next, arg->next, 1)" ???

Quoted 6 lines
Quoted 4 lines

2nd question:
I did first one, but first element of list was not accessible in hypervisor space, why?

Well, if you are really only copying the list_head, the above should work.

Yes, I have carried out the sample test, by allocating small struct linked list and then passing between hypervisor and kernel copy_from_guest(hyp_list_head, arg, 1) is working correctly.

But my actial code is not working. Ok let me put some more effort, if not I will push the code for review.

Thanks for your help

Quoted 5 lines

 -- Keir