All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xenproject.org>
Cc: "Andrew Cooper" <andrew.cooper3@citrix.com>,
	"Jan Beulich" <JBeulich@suse.com>,
	"Roger Pau Monné" <roger.pau@citrix.com>
Subject: [PATCH] x86/mm: Refine address alignment checks in modify_xen_mappings_lite()
Date: Tue, 19 Mar 2024 19:58:56 +0000	[thread overview]
Message-ID: <20240319195856.4172284-1-andrew.cooper3@citrix.com> (raw)

Require 's' to be superpage aligned if given over a superpage mapping.  This
is expected to be the case in practice, and prevents the v getting misaligned
over superpages during the processing loop.

Rmove 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>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/mm.c           | 10 ++++++----
 xen/common/virtual_region.c |  8 ++++----
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index 62f5b811bbe8..018d21f8bd92 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -5900,9 +5900,9 @@ 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.
+ * It is the callers repsonsibility to pass 's' on a PAGE/SUPERPAGE boundary,
+ * and for there to not be anything interesting in the PAGE/SUPERPAGE
+ * following 'e'.
  */
 void init_or_livepatch modify_xen_mappings_lite(
     unsigned long s, unsigned long e, unsigned int nf)
@@ -5917,7 +5917,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 +5929,8 @@ void init_or_livepatch modify_xen_mappings_lite(
 
         if ( l2e_get_flags(l2e) & _PAGE_PSE )
         {
+            ASSERT(IS_ALIGNED(v, 1 << L2_PAGETABLE_SHIFT));
+
             l2e_write_atomic(pl2e, l2e_from_intpte((l2e.l2 & ~fm) | flags));
 
             v += 1UL << L2_PAGETABLE_SHIFT;
diff --git a/xen/common/virtual_region.c b/xen/common/virtual_region.c
index b4325bcda71e..142f21e18153 100644
--- a/xen/common/virtual_region.c
+++ b/xen/common/virtual_region.c
@@ -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);

base-commit: 188fa82305e72b725473db9146e20cc9abf7bff3
-- 
2.30.2



             reply	other threads:[~2024-03-19 19:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-19 19:58 Andrew Cooper [this message]
2024-03-19 20:04 ` [PATCH] x86/mm: Refine address alignment checks in modify_xen_mappings_lite() Andrew Cooper
2024-03-20  8:11 ` Roger Pau Monné

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240319195856.4172284-1-andrew.cooper3@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=roger.pau@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.