Skip to contentSkip to conversation

gnttab_end_foreign_access/unmap fails for GNTMAP_device_map?

DISCUSSION Oleksandr Andrushchenko 2 participants 3 messages Dec 14, 2016

lore
Share & tools
lore
#0 lore raw

Hi, all!

I am trying to map and then unmap grant refs in Dom0 from DomU which are used for DMA by a real device in Dom0 (x86_64). Mapping is done with GNTMAP_host_map | GNTMAP_device_map flags and device can successfully access the pages and do DMA. The problem is I cannot unmap the buffer back: Dom0 says unmapping was done w/o errors, but when DomU tries to gnttab_end_foreign_access I see lots of

[   55.052979] xen:grant_table: WARNING: g.e. 0xdce still in use!
[   55.052984] deferring g.e. 0xdce (pfn 0xffffffffffffffff)

messages in DomU and those grefs are never freed and system gets exhausted at some point.

The same code, but with only GNTMAP_host_map flag is able to release references as expected. Even if I don't give the buffer to any HW device in Dom0 the use of GNTMAP_device_map flag makes troubles. I also tried to add GNTMAP_readonly, but it didn't help. In DomU right before doing gnttab_end_foreign_access I am checking flags with gnttab_query_foreign_access: both GTF_reading and GTF_writing are set. With GNTMAP_readonly only GTF_reading (which I believe is expected).
I tried to look at the Xen sources and thought that it could probably be related to pin/unpin?
Can anyone please shed some light if anything additional needs to be done in case GNTMAP_device_map is in use or point me to what needs to checked so I can find the root cause?

Thank you,
Oleksandr

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#1 lore raw
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 14.12.16 at 15:46, <[email protected]> wrote:

Hi, all!

I am trying to map and then unmap grant refs in Dom0 from DomU which are used for DMA by a real device in Dom0 (x86_64). Mapping is done with GNTMAP_host_map | GNTMAP_device_map flags and device can successfully access the pages and do DMA. The problem is I cannot unmap the buffer back: Dom0 says unmapping was done w/o errors, but when DomU tries to gnttab_end_foreign_access I see lots of

[   55.052979] xen:grant_table: WARNING: g.e. 0xdce still in use!
[   55.052984] deferring g.e. 0xdce (pfn 0xffffffffffffffff)

messages in DomU and those grefs are never freed and system gets exhausted at some point.

Quoted 10 lines

The same code, but with only GNTMAP_host_map flag is able to release references as expected. Even if I don't give the buffer to any HW device in Dom0 the use of GNTMAP_device_map flag makes troubles. I also tried to add GNTMAP_readonly, but it didn't help. In DomU right before doing gnttab_end_foreign_access I am checking flags with gnttab_query_foreign_access: both GTF_reading and GTF_writing are set. With GNTMAP_readonly only GTF_reading (which I believe is expected).
I tried to look at the Xen sources and thought that it could probably be related to pin/unpin?

Possibly - looking at __gnttab_unmap_common(), are you passing GNTMAP_device_map also to the unmap operation (together with the frame number, or else the flag would be ignored)?

Jan

Quoted 6 lines

Can anyone please shed some light if anything additional needs to be done in case GNTMAP_device_map is in use or point me to what needs to checked so I can find the root cause?

Thank you,
Oleksandr

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#2 lore raw

Hi, Jan!

Quoted 25 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 14.12.16 at 15:46, <[email protected]> wrote:

Hi, all!

I am trying to map and then unmap grant refs in Dom0 from DomU which are used for DMA by a real device in Dom0 (x86_64). Mapping is done with GNTMAP_host_map | GNTMAP_device_map flags and device can successfully access the pages and do DMA. The problem is I cannot unmap the buffer back: Dom0 says unmapping was done w/o errors, but when DomU tries to gnttab_end_foreign_access I see lots of

[   55.052979] xen:grant_table: WARNING: g.e. 0xdce still in use!
[   55.052984] deferring g.e. 0xdce (pfn 0xffffffffffffffff)

messages in DomU and those grefs are never freed and system gets exhausted at some point.

Quoted 10 lines

The same code, but with only GNTMAP_host_map flag is able to release references as expected. Even if I don't give the buffer to any HW device in Dom0 the use of GNTMAP_device_map flag makes troubles. I also tried to add GNTMAP_readonly, but it didn't help. In DomU right before doing gnttab_end_foreign_access I am checking flags with gnttab_query_foreign_access: both GTF_reading and GTF_writing are set. With GNTMAP_readonly only GTF_reading (which I believe is expected).
I tried to look at the Xen sources and thought that it could probably be related to pin/unpin?

Quoted 5 lines

Possibly - looking at __gnttab_unmap_common(), are you passing GNTMAP_device_map also to the unmap operation (together with the frame number, or else the flag would be ignored)?

Jan

Indeed, it helped:
gnttab_set_unmap_op(&unmap_ops[i], addr,
GNTMAP_host_map | GNTMAP_device_map, xen_obj->map_handles[i]);
*unmap_ops[i].dev_bus_addr = xen_obj->dev_bus_addr[i];* I was confused by gnttab_set_unmap_op which unmap->dev_bus_addr = 0;

Quoted 7 lines
Quoted 6 lines

Can anyone please shed some light if anything additional needs to be done in case GNTMAP_device_map is in use or point me to what needs to checked so I can find the root cause?

Thank you,
Oleksandr

Thank you,
Oleksandr

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel