x86/altp2m: aggregate get entry and populate into common funcs
authorAlexandru Isaila <aisaila@bitdefender.com>
Mon, 13 May 2019 07:55:24 +0000 (09:55 +0200)
committerJan Beulich <jbeulich@suse.com>
Mon, 13 May 2019 07:55:24 +0000 (09:55 +0200)
commitce65c0226db8d112c28a588802e43a482b210621
tree41eca96cd3351bc4a3e5deb2c0cb48b50d874fc0
parentf3d880bf2be92534c5bacf11de2f561cbad550fb
x86/altp2m: aggregate get entry and populate into common funcs

The code for getting the entry and then populating was repeated in
p2m_change_altp2m_gfn() and in p2m_set_altp2m_mem_access().

The code is now in one place with a bool param that lets the caller choose
if it populates after get_entry().

If remapping is being done then both the old and new gfn's should be
unshared in the hostp2m for keeping things consistent. The page type
of old_gfn was already checked whether it's p2m_ram_rw and bail if it
wasn't so functionality-wise this just simplifies things as a user
doesn't have to request unsharing manually before remapping.
Now, if the new_gfn is invalid it shouldn't query the hostp2m as
that is effectively a request to remove the entry from the altp2m.
But provided that scenario is used only when removing entries that
were previously remapped/copied to the altp2m, those entries already
went through P2M_ALLOC | P2M_UNSHARE before, so it won't have an
affect so the core function get_altp2m_entry() is calling
__get_gfn_type_access() with P2M_ALLOC | P2M_UNSHARE.

altp2m_get_entry_direct() is also called in p2m_set_suppress_ve()
because on a new altp2m view the function will fail with invalid mfn if
p2m->set_entry() was not called before.

Signed-off-by: Alexandru Isaila <aisaila@bitdefender.com>
Signed-off-by: George Dunlap <george.dunlap@citrix.com>
Reviewed-by: George Dunlap <george.dunlap@citrix.com>
Acked-by: Tamas K Lengyel <tamas@tklengyel.com>
xen/arch/x86/mm/mem_access.c
xen/arch/x86/mm/p2m.c
xen/include/asm-x86/p2m.h