x86/p2m: fix xenmem_add_to_physmap_one double page removal
authorRoger Pau Monné <roger.pau@citrix.com>
Wed, 15 Sep 2021 13:13:14 +0000 (15:13 +0200)
committerJan Beulich <jbeulich@suse.com>
Wed, 15 Sep 2021 13:13:14 +0000 (15:13 +0200)
commit3e910b648b99393561e7c523756c1ea49a6c1305
treef81733f0ccd5ff2a0576ee8bc14c856cc13228af
parent6254920587c33bcc7ab884e6c9a11cfc0d5867ab
x86/p2m: fix xenmem_add_to_physmap_one double page removal

If the new gfn matches the previous one (ie: gpfn == old_gpfn)
xenmem_add_to_physmap_one will issue a duplicated call to
guest_physmap_remove_page with the same guest frame number, because
the get_gpfn_from_mfn call has been moved by commit f8582da041 to be
performed before the original page is removed. This leads to the
second guest_physmap_remove_page failing, which was not the case
before commit f8582da041.

Fix this by adding a check that prevents a second call to
guest_physmap_remove_page if the previous one has already removed the
backing page from that gfn.

Fixes: f8582da041 ('x86/mm: pull a sanity check earlier in xenmem_add_to_physmap_one()')
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/mm/p2m.c