* [PATCH] x86/mm: Refine address alignment checks in modify_xen_mappings_lite()
@ 2024-03-19 19:58 Andrew Cooper
2024-03-19 20:04 ` Andrew Cooper
2024-03-20 8:11 ` Roger Pau Monné
0 siblings, 2 replies; 3+ messages in thread
From: Andrew Cooper @ 2024-03-19 19:58 UTC (permalink / raw)
To: Xen-devel; +Cc: Andrew Cooper, Jan Beulich, Roger Pau Monné
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
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] x86/mm: Refine address alignment checks in modify_xen_mappings_lite()
2024-03-19 19:58 [PATCH] x86/mm: Refine address alignment checks in modify_xen_mappings_lite() Andrew Cooper
@ 2024-03-19 20:04 ` Andrew Cooper
2024-03-20 8:11 ` Roger Pau Monné
1 sibling, 0 replies; 3+ messages in thread
From: Andrew Cooper @ 2024-03-19 20:04 UTC (permalink / raw)
To: Xen-devel; +Cc: Jan Beulich, Roger Pau Monné
On 19/03/2024 7:58 pm, Andrew Cooper wrote:
> 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
"Remove". Fixed locally.
> 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>
Code-gen wise, this drops 2x
48 8d b0 ff 0f 00 00 lea 0xfff(%rax),%rsi
48 81 e6 00 f0 ff ff and $0xfffffffffffff000,%rsi
from {relax,tighten}_virtual_region_perms().
~Andrew
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] x86/mm: Refine address alignment checks in modify_xen_mappings_lite()
2024-03-19 19:58 [PATCH] x86/mm: Refine address alignment checks in modify_xen_mappings_lite() Andrew Cooper
2024-03-19 20:04 ` Andrew Cooper
@ 2024-03-20 8:11 ` Roger Pau Monné
1 sibling, 0 replies; 3+ messages in thread
From: Roger Pau Monné @ 2024-03-20 8:11 UTC (permalink / raw)
To: Andrew Cooper; +Cc: Xen-devel, Jan Beulich
On Tue, Mar 19, 2024 at 07:58:56PM +0000, Andrew Cooper wrote:
> 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>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
One suggestion below.
> ---
> 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'.
Instead of mentioning 'anything interesting' I would just state that
'e' will be extended to the next page/superpage boundary:
"It is the callers repsonsibility to pass 's' on a PAGE/SUPERPAGE boundary,
note that 'e' will be rounded up to the next PAGE/SUPERPAGE boundary."
Thanks, Roger.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-03-20 8:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-19 19:58 [PATCH] x86/mm: Refine address alignment checks in modify_xen_mappings_lite() Andrew Cooper
2024-03-19 20:04 ` Andrew Cooper
2024-03-20 8:11 ` Roger Pau Monné
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.