x86/shadow: correct GFN use by sh_unshadow_for_p2m_change()
authorJan Beulich <jbeulich@suse.com>
Fri, 30 Oct 2020 13:27:23 +0000 (14:27 +0100)
committerJan Beulich <jbeulich@suse.com>
Fri, 30 Oct 2020 13:27:23 +0000 (14:27 +0100)
Luckily sh_remove_all_mappings()'s use of the parameter is limited to
generation of log messages. Nevertheless we'd better pass correct GFNs
around:
- the incoming GFN, when replacing a large page, may not be large page
  aligned,
- incrementing by page-size-scaled values can't be right.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Tim Deegan <tim@xen.org>
xen/arch/x86/mm/shadow/common.c

index 0d59dea6ad07b2d6d875979b965f07f47f8911d4..9c3d9a7cfdae7460c16f4d1913bc7ac0a3f6fac0 100644 (file)
@@ -3121,6 +3121,8 @@ static void sh_unshadow_for_p2m_change(struct domain *d, unsigned long gfn,
                  && mfn_valid(nmfn) )
                 npte = map_domain_page(nmfn);
 
+            gfn &= ~(L1_PAGETABLE_ENTRIES - 1);
+
             for ( i = 0; i < L1_PAGETABLE_ENTRIES; i++ )
             {
                 if ( !npte
@@ -3129,8 +3131,7 @@ static void sh_unshadow_for_p2m_change(struct domain *d, unsigned long gfn,
                 {
                     /* This GFN->MFN mapping has gone away */
                     sh_remove_all_shadows_and_parents(d, omfn);
-                    if ( sh_remove_all_mappings(d, omfn,
-                                                _gfn(gfn + (i << PAGE_SHIFT))) )
+                    if ( sh_remove_all_mappings(d, omfn, _gfn(gfn + i)) )
                         cpumask_or(&flushmask, &flushmask, d->dirty_cpumask);
                 }
                 omfn = mfn_add(omfn, 1);