Skip to contentSkip to conversation

QEMU commit 04bf2526ce breaks use of xen-mapcache

Qemu-devel Anthony PERARD 3 participants 6 messages Jul 25, 2017

lore
Share & tools
lore
#0 lore raw

Hi,

Commits 04bf2526ce (exec: use qemu_ram_ptr_length to access guest ram) start using qemu_ram_ptr_length() instead of qemu_map_ram_ptr(). That result in calling xen_map_cache() with lock=true, but this mapping is never invalidated.
So QEMU use more and more RAM until it stop working for a reason or an other. (crash if host have little RAM or stop emulating but no crash)

I don't know if calling xen_invalidate_map_cache_entry() in address_space_read_continue() and address_space_write_continue() is the right answer. Is there something better to do ?

(A good way to reproduce: Install Windows, so without pv driver.)

Thanks,

Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw
Quoted 9 lines

Hi,

Commits 04bf2526ce (exec: use qemu_ram_ptr_length to access guest ram) start using qemu_ram_ptr_length() instead of qemu_map_ram_ptr(). That result in calling xen_map_cache() with lock=true, but this mapping is never invalidated.
So QEMU use more and more RAM until it stop working for a reason or an other. (crash if host have little RAM or stop emulating but no crash)

Quoted 3 lines

I don't know if calling xen_invalidate_map_cache_entry() in address_space_read_continue() and address_space_write_continue() is the right answer. Is there something better to do ?

I think it's correct for dma to be true... maybe add a lock argument to qemu_ram_ptr_length, so that make address_space_{read,write}_continue can pass 0 and everyone else passes 1?

Paolo

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

#2 lore raw
Quoted 9 lines · Paolo Bonzini
Quoted 9 lines

Hi,

Commits 04bf2526ce (exec: use qemu_ram_ptr_length to access guest ram) start using qemu_ram_ptr_length() instead of qemu_map_ram_ptr(). That result in calling xen_map_cache() with lock=true, but this mapping is never invalidated.
So QEMU use more and more RAM until it stop working for a reason or an other. (crash if host have little RAM or stop emulating but no crash)

Quoted 7 lines
Quoted 3 lines

I don't know if calling xen_invalidate_map_cache_entry() in address_space_read_continue() and address_space_write_continue() is the right answer. Is there something better to do ?

I think it's correct for dma to be true... maybe add a lock argument to qemu_ram_ptr_length, so that make address_space_{read,write}_continue can pass 0 and everyone else passes 1?

I think that is a great suggestion. That way, the difference between locked mappings and unlocked mappings would be explicit, rather than relying on callers to use qemu_map_ram_ptr for unlocked mappings and qemu_ram_ptr_length for locked mappings. And there aren't that many callers of qemu_ram_ptr_length, so adding a parameter wouldn't be an issue.

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

#3 lore raw

----- Original Message -----

Quoted 25 lines

From: "Stefano Stabellini" <[email protected]>
To: "Paolo Bonzini" <[email protected]>
Cc: "Anthony PERARD" <[email protected]>, "Stefano Stabellini" <[email protected]>, [email protected], [email protected]
Sent: Tuesday, July 25, 2017 8:08:21 PM
Subject: Re: QEMU commit 04bf2526ce breaks use of xen-mapcache

Quoted 9 lines · Paolo Bonzini
Quoted 9 lines

Hi,

Commits 04bf2526ce (exec: use qemu_ram_ptr_length to access guest ram) start using qemu_ram_ptr_length() instead of qemu_map_ram_ptr(). That result in calling xen_map_cache() with lock=true, but this mapping is never invalidated.
So QEMU use more and more RAM until it stop working for a reason or an other. (crash if host have little RAM or stop emulating but no crash)

Quoted 7 lines
Quoted 3 lines

I don't know if calling xen_invalidate_map_cache_entry() in address_space_read_continue() and address_space_write_continue() is the right answer. Is there something better to do ?

I think it's correct for dma to be true... maybe add a lock argument to qemu_ram_ptr_length, so that make address_space_{read,write}_continue can pass 0 and everyone else passes 1?

Quoted 6 lines

I think that is a great suggestion. That way, the difference between locked mappings and unlocked mappings would be explicit, rather than relying on callers to use qemu_map_ram_ptr for unlocked mappings and qemu_ram_ptr_length for locked mappings. And there aren't that many callers of qemu_ram_ptr_length, so adding a parameter wouldn't be an issue.

Thanks---however, after re-reading xen-mapcache.c, dma needs to be false for unlocked mappings.

Paolo

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

#4 lore raw
Quoted 33 lines · Paolo Bonzini

----- Original Message -----

Quoted 25 lines

From: "Stefano Stabellini" <[email protected]>
To: "Paolo Bonzini" <[email protected]>
Cc: "Anthony PERARD" <[email protected]>, "Stefano Stabellini" <[email protected]>, [email protected], [email protected]
Sent: Tuesday, July 25, 2017 8:08:21 PM
Subject: Re: QEMU commit 04bf2526ce breaks use of xen-mapcache

Quoted 9 lines · Paolo Bonzini
Quoted 9 lines

Hi,

Commits 04bf2526ce (exec: use qemu_ram_ptr_length to access guest ram) start using qemu_ram_ptr_length() instead of qemu_map_ram_ptr(). That result in calling xen_map_cache() with lock=true, but this mapping is never invalidated.
So QEMU use more and more RAM until it stop working for a reason or an other. (crash if host have little RAM or stop emulating but no crash)

Quoted 7 lines
Quoted 3 lines

I don't know if calling xen_invalidate_map_cache_entry() in address_space_read_continue() and address_space_write_continue() is the right answer. Is there something better to do ?

I think it's correct for dma to be true... maybe add a lock argument to qemu_ram_ptr_length, so that make address_space_{read,write}_continue can pass 0 and everyone else passes 1?

Quoted 6 lines

I think that is a great suggestion. That way, the difference between locked mappings and unlocked mappings would be explicit, rather than relying on callers to use qemu_map_ram_ptr for unlocked mappings and qemu_ram_ptr_length for locked mappings. And there aren't that many callers of qemu_ram_ptr_length, so adding a parameter wouldn't be an issue.

Quoted 2 lines

Thanks---however, after re-reading xen-mapcache.c, dma needs to be false for unlocked mappings.

If there is a DMA operation already in progress, it means that we'll already have a locked mapping for it.

When address_space_write_continue is called, which in turn would call qemu_map_ram_ptr, or qemu_ram_ptr_length(unlocked), if the start and size of the requested mapping matches the one of the previously created locked mapping, then a pointer to the locked mapping will be returned.

If they don't match, a new unlocked mapping will be created and a pointer to it will be returned. (Arguably the algorithm could be improved so that a new mapping is not created if the address and size are contained within the locked mapping. This is a missing optimization today.)

It doesn't matter if a new unlocked mapping is created, or if the locked mapping is returned, because the pointer returned by qemu_ram_ptr_length(unlocked) is only used to do the memcpy, and never again. So I don't think this is a problem.

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

#5 lore raw
Quoted 6 lines
Quoted 3 lines

Thanks---however, after re-reading xen-mapcache.c, dma needs to be false for unlocked mappings.

If there is a DMA operation already in progress, it means that we'll already have a locked mapping for it.

Yes, I only wanted to say that qemu_ram_ptr_length should pass dma=false when called by address_space_*_continue (i.e. with locked=false).

Paolo

Quoted 11 lines

When address_space_write_continue is called, which in turn would call qemu_map_ram_ptr, or qemu_ram_ptr_length(unlocked), if the start and size of the requested mapping matches the one of the previously created locked mapping, then a pointer to the locked mapping will be returned.

If they don't match, a new unlocked mapping will be created and a pointer to it will be returned. (Arguably the algorithm could be improved so that a new mapping is not created if the address and size are contained within the locked mapping. This is a missing optimization today.)

Quoted 5 lines

It doesn't matter if a new unlocked mapping is created, or if the locked mapping is returned, because the pointer returned by qemu_ram_ptr_length(unlocked) is only used to do the memcpy, and never again. So I don't think this is a problem.

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