]> xenbits.xensource.com Git - people/royger/xen.git/commitdiff
x86/mm: Refine address alignment checks in modify_xen_mappings_lite()
authorAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 19 Mar 2024 19:38:48 +0000 (19:38 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 28 Mar 2024 11:25:07 +0000 (11:25 +0000)
Require 's' to be superpage aligned if given over a superpage mapping.  This
is expected to be the case in practice, and prevents v getting misaligned over
superpages during the processing loop.

Remove the requirement for 'e' to be page aligned.  All this is doing is
forcing work for the caller just to satisfy an assertion.

Reported-by: Jan Beulich <JBeulich@suse.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
xen/arch/x86/mm.c
xen/common/virtual_region.c

index 62f5b811bbe885b6292772647d961142533cb5cd..631da8d7d26d116f33222da6ca4cf374f4e15e55 100644 (file)
@@ -5900,9 +5900,10 @@ int destroy_xen_mappings(unsigned long s, unsigned long e)
  *
  * Must be limited to XEN_VIRT_{START,END}, i.e. over l2_xenmap[].
  * Must be called with present flags, and over present mappings.
- * It is the callers responsibility to not pass s or e in the middle of
- * superpages if changing the permission on the whole superpage is going to be
- * a problem.
+ * Must be called with 's' on a page/superpage boundary.
+ *
+ * 'e' has no alignment requirements, but the whole page/superpage containing
+ * the non-inclusive boundary will be updated.
  */
 void init_or_livepatch modify_xen_mappings_lite(
     unsigned long s, unsigned long e, unsigned int nf)
@@ -5917,7 +5918,7 @@ void init_or_livepatch modify_xen_mappings_lite(
 
     ASSERT(flags & _PAGE_PRESENT);
     ASSERT(IS_ALIGNED(s, PAGE_SIZE) && s >= XEN_VIRT_START);
-    ASSERT(IS_ALIGNED(e, PAGE_SIZE) && e <= XEN_VIRT_END);
+    ASSERT(e <= XEN_VIRT_END);
 
     while ( v < e )
     {
@@ -5929,6 +5930,8 @@ void init_or_livepatch modify_xen_mappings_lite(
 
         if ( l2e_get_flags(l2e) & _PAGE_PSE )
         {
+            ASSERT(IS_ALIGNED(v, 1UL << L2_PAGETABLE_SHIFT));
+
             l2e_write_atomic(pl2e, l2e_from_intpte((l2e.l2 & ~fm) | flags));
 
             v += 1UL << L2_PAGETABLE_SHIFT;
index b4325bcda71ea6c30213ea5ba1af0069b1a34be5..142f21e1815340d75224a44ae7a0490bdfcd049e 100644 (file)
@@ -93,11 +93,11 @@ void relax_virtual_region_perms(void)
     list_for_each_entry_rcu( region, &virtual_region_list, list )
     {
         modify_xen_mappings_lite((unsigned long)region->text_start,
-                                 PAGE_ALIGN((unsigned long)region->text_end),
+                                 (unsigned long)region->text_end,
                                  PAGE_HYPERVISOR_RWX);
         if ( region->rodata_start )
             modify_xen_mappings_lite((unsigned long)region->rodata_start,
-                                     PAGE_ALIGN((unsigned long)region->rodata_end),
+                                     (unsigned long)region->rodata_end,
                                      PAGE_HYPERVISOR_RW);
     }
     rcu_read_unlock(&rcu_virtual_region_lock);
@@ -111,11 +111,11 @@ void tighten_virtual_region_perms(void)
     list_for_each_entry_rcu( region, &virtual_region_list, list )
     {
         modify_xen_mappings_lite((unsigned long)region->text_start,
-                                 PAGE_ALIGN((unsigned long)region->text_end),
+                                 (unsigned long)region->text_end,
                                  PAGE_HYPERVISOR_RX);
         if ( region->rodata_start )
             modify_xen_mappings_lite((unsigned long)region->rodata_start,
-                                     PAGE_ALIGN((unsigned long)region->rodata_end),
+                                     (unsigned long)region->rodata_end,
                                      PAGE_HYPERVISOR_RO);
     }
     rcu_read_unlock(&rcu_virtual_region_lock);