x86/mm: Refine address alignment checks in modify_xen_mappings_lite()
PATCH 1/1 x86/mm: Refine address alignment checks in modify_xen_mappings_lite()
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.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
--- xen/arch/x86/mm.c | 10 ++++++---- xen/common/virtual_region.c | 8 ++++---- 2 files changed, 10 insertions(+), 8 deletions(-)
xen/arch/x86/mm.c +6 -4
@@ -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 ;
xen/common/virtual_region.c +4 -4
@@ -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
Signature · 1 line
2.30.2
Quoted 5 lines · Andrew Cooper
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.
Quoted 7 lines
forcing work for the caller just to satisfy an assertion.
Reported-by Jan Beulich <[email protected]>Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
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
Quoted 9 lines · Andrew Cooper
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 <[email protected]>Signed-off-by Andrew Cooper <[email protected]>
One suggestion below.
Quoted 13 lines
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>--- xen/arch/x86/mm.c | 10 ++++++---- xen/common/virtual_region.c | 8 ++++---- 2 files changed, 10 insertions(+), 8 deletions(-)xen/arch/x86/mm.c +0
-0
xen/arch/x86/mm.c int destroy_xen_mappings(unsigned long s, unsigned long e) · line 5905
Quoted 9 lines
xen/arch/x86/mm.c +3
-3@@ -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.