x86/p2m: fix PoD accounting in guest_physmap_add_entry()
authorJan Beulich <jbeulich@suse.com>
Fri, 21 Feb 2020 16:09:28 +0000 (17:09 +0100)
committerJan Beulich <jbeulich@suse.com>
Fri, 21 Feb 2020 16:14:38 +0000 (17:14 +0100)
commitaea270e3f7c0db696c88a0e94b1ece7abd339c84
tree44e9b22a48f209360d627508001d0641a2a1b200
parent1a16fee21ce4b0c876ee04af912b3f0545118cd9
x86/p2m: fix PoD accounting in guest_physmap_add_entry()

The initial observation was that the mfn_valid() check comes too late:
Neither mfn_add() nor mfn_to_page() (let alone de-referencing the
result of the latter) are valid for MFNs failing this check. Move it up
and - noticing that there's no caller doing so - also add an assertion
that this should never produce "false" here.

In turn this would have meant that the "else" to that if() could now go
away, which didn't seem right at all. And indeed, considering callers
like memory_exchange() or various grant table functions, the PoD
accounting should have been outside of that if() from the very
beginning.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
xen/arch/x86/mm/p2m.c