Skip to content
This repository was archived by the owner on Jan 28, 2023. It is now read-only.

Support stand-alone memory mappings #197

Merged
merged 1 commit into from
Mar 28, 2019
Merged

Support stand-alone memory mappings #197

merged 1 commit into from
Mar 28, 2019

Conversation

raphaelning
Copy link
Contributor

@raphaelning raphaelning commented Mar 25, 2019

Android Emulator may dynamically create and destroy temporary
memory mappings at guest runtime for certain rendering tasks via
hax_user_backed_ram_map() and hax_user_backed_ram_unmap()
($AOSP/external/qemu/target/i386/hax-mem.c), e.g.:

hax_user_backed_ram_map() <1>
1.1) ADD_RAMBLOCK <1>: HVA 0x14e070000..0x16e070000
1.2) SET_RAM2 (map) <1>: GPA 0x7dffff000..0x7fffff000 =>
HVA 0x14e070000..0x16e070000
hax_user_backed_ram_unmap() <1>
1.3) SET_RAM2 (unmap) <1>: GPA 0x7dffff000..0x7fffff000
hax_user_backed_ram_map() <2>
2.1) ADD_RAMBLOCK <2>: HVA 0x14de70000..0x16de70000

The second ADD_RAMBLOCK call fails, because its HVA range overlaps
with that of the first ADD_RAMBLOCK call.

The problem is that the "map" step creates a RAM block, but the
"unmap" step doesn't destroy it. Instead of adding a DEL_RAMBLOCK
ioctl, simply exempt the caller from calling ADD_RAMBLOCK in the
first place:

  • Introduce a new hax_memslot flag for "stand-alone" mappings,
    along with a new capability flag for this API change.
  • Remove the ADD_RAMBLOCK call from hax_user_backed_ram_map().
    Instead, call SET_RAM2 with the new flag. (This will be done on
    the Android Emulator side.)
  • Internally, SET_RAM2 creates a stand-alone RAM block for each
    stand-alone mapping.
  • When the stand-alone mapping is unmapped, the reference count
    of the corresponding stand-alone RAM block will hit 0, which
    allows SET_RAM2 to destroy this temporary RAM block.
  • Replace HAX_RAM_INFO_xxx with HAX_MEMSLOT_xxx in code that is
    not directly in touch with user space.

@acrnsi
Copy link

acrnsi commented Mar 25, 2019

Can one of the admins verify this patch?

@krytarowski
Copy link
Contributor

Is this going to help to #171 ?

@raphaelning
Copy link
Contributor Author

Is this going to help to #171 ?

Sorry, no. This is to fix an issue specific to Android Emulator.

Android Emulator may dynamically create and destroy temporary
memory mappings at guest runtime for certain rendering tasks via
hax_user_backed_ram_map() and hax_user_backed_ram_unmap()
($AOSP/external/qemu/target/i386/hax-mem.c), e.g.:

 hax_user_backed_ram_map() <1>
 1.1) ADD_RAMBLOCK <1>:     HVA 0x14e070000..0x16e070000
 1.2) SET_RAM2 (map) <1>:   GPA 0x7dffff000..0x7fffff000 =>
                            HVA 0x14e070000..0x16e070000
 hax_user_backed_ram_unmap() <1>
 1.3) SET_RAM2 (unmap) <1>: GPA 0x7dffff000..0x7fffff000
 hax_user_backed_ram_map() <2>
 2.1) ADD_RAMBLOCK <2>:     HVA 0x14de70000..0x16de70000

The second ADD_RAMBLOCK call fails, because its HVA range overlaps
with that of the first ADD_RAMBLOCK call.

The problem is that the "map" step creates a RAM block, but the
"unmap" step doesn't destroy it. Instead of adding a DEL_RAMBLOCK
ioctl, simply exempt the caller from calling ADD_RAMBLOCK in the
first place:

 - Introduce a new hax_memslot flag for "stand-alone" mappings,
   along with a new capability flag for this API change.
 - Remove the ADD_RAMBLOCK call from hax_user_backed_ram_map().
   Instead, call SET_RAM2 with the new flag. (This will be done on
   the Android Emulator side.)
 - Internally, SET_RAM2 creates a stand-alone RAM block for each
   stand-alone mapping.
 - When the stand-alone mapping is unmapped, the reference count
   of the corresponding stand-alone RAM block will hit 0, which
   allows SET_RAM2 to destroy this temporary RAM block.

+ Replace HAX_RAM_INFO_xxx with HAX_MEMSLOT_xxx in code that is
  not directly in touch with user space.

Signed-off-by: Yu Ning <yu.ning@intel.com>
@wcwang wcwang merged commit 677588c into master Mar 28, 2019
@wcwang wcwang deleted the standalone-mapping branch March 28, 2019 09:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants