x86/mm: fix race condition in modify_xen_mappings()
authorYu Zhang <yu.c.zhang@linux.intel.com>
Tue, 14 Nov 2017 16:11:26 +0000 (17:11 +0100)
committerJan Beulich <jbeulich@suse.com>
Tue, 14 Nov 2017 16:11:26 +0000 (17:11 +0100)
commitb9ee1fd7b98064cf27d0f8f1adf1f5359b72c97f
tree2386006f73aef46969100d35311f757f63469db4
parenta5114662297ad03efc36b52ad365ffa05fb357b7
x86/mm: fix race condition in modify_xen_mappings()

In modify_xen_mappings(), a L1/L2 page table shall be freed,
if all entries of this page table are empty. Corresponding
L2/L3 PTE will need be cleared in such scenario.

However, concurrent paging structure modifications on different
CPUs may cause the L2/L3 PTEs to be already be cleared or set
to reference a superpage.

Therefore the logic to enumerate the L1/L2 page table and to
reset the corresponding L2/L3 PTE need to be protected with
spinlock. And the _PAGE_PRESENT and _PAGE_PSE flags need be
checked after the lock is obtained.

Suggested-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Yu Zhang <yu.c.zhang@linux.intel.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Release-acked-by: Julien Grall <julien.grall@linaro.org>
xen/arch/x86/mm.c