From: Alejandro Vallejo <alejandro.vallejo@cloud.com>
To: Xen-devel <xen-devel@lists.xenproject.org>
Cc: "Alejandro Vallejo" <alejandro.vallejo@cloud.com>,
"Jan Beulich" <jbeulich@suse.com>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"Roger Pau Monné" <roger.pau@citrix.com>, "Wei Liu" <wl@xen.org>,
"George Dunlap" <george.dunlap@citrix.com>,
"Julien Grall" <julien@xen.org>,
"Stefano Stabellini" <sstabellini@kernel.org>
Subject: [PATCH 6/8] mm/pdx: Standardize region validation wrt pdx compression
Date: Mon, 17 Jul 2023 17:03:16 +0100 [thread overview]
Message-ID: <20230717160318.2113-7-alejandro.vallejo@cloud.com> (raw)
In-Reply-To: <20230717160318.2113-1-alejandro.vallejo@cloud.com>
Regions must be occasionally validated for pdx compression validity. That
is, whether any of the machine addresses spanning the region have a bit set
in the pdx "hole" (which is expected to always contain zeroes). There are
a few such tests through the code, and they all check for different things.
This patch replaces all such occurences with a call to a centralized
function that checks a region for validity.
Signed-off-by: Alejandro Vallejo <alejandro.vallejo@cloud.com>
---
xen/arch/x86/x86_64/mm.c | 2 +-
xen/common/efi/boot.c | 6 +++---
xen/common/pdx.c | 13 +++++++++++--
xen/include/xen/pdx.h | 9 +++++++++
4 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c
index 60db439af3..914e65c26c 100644
--- a/xen/arch/x86/x86_64/mm.c
+++ b/xen/arch/x86/x86_64/mm.c
@@ -1168,7 +1168,7 @@ static int mem_hotadd_check(unsigned long spfn, unsigned long epfn)
if ( (spfn | epfn) & ((1UL << PAGETABLE_ORDER) - 1) )
return 0;
- if ( (spfn | epfn) & pfn_hole_mask )
+ if ( !pdx_is_region_compressible(spfn, epfn) )
return 0;
/* Make sure the new range is not present now */
diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c
index 24169b7b50..b098a8c030 100644
--- a/xen/common/efi/boot.c
+++ b/xen/common/efi/boot.c
@@ -14,6 +14,7 @@
#include <xen/multiboot.h>
#include <xen/param.h>
#include <xen/pci_regs.h>
+#include <xen/pdx.h>
#include <xen/pfn.h>
#if EFI_PAGE_SIZE != PAGE_SIZE
# error Cannot use xen/pfn.h here!
@@ -1647,7 +1648,7 @@ static bool __init cf_check ram_range_valid(unsigned long smfn, unsigned long em
{
unsigned long sz = pfn_to_pdx(emfn - 1) / PDX_GROUP_COUNT + 1;
- return !(smfn & pfn_hole_mask) &&
+ return pdx_is_region_compressible(smfn, emfn) &&
find_next_bit(pdx_group_valid, sz,
pfn_to_pdx(smfn) / PDX_GROUP_COUNT) < sz;
}
@@ -1759,8 +1760,7 @@ void __init efi_init_memory(void)
prot |= _PAGE_NX;
if ( pfn_to_pdx(emfn - 1) < (DIRECTMAP_SIZE >> PAGE_SHIFT) &&
- !(smfn & pfn_hole_mask) &&
- !((smfn ^ (emfn - 1)) & ~pfn_pdx_bottom_mask) )
+ pdx_is_region_compressible(smfn, emfn))
{
if ( (unsigned long)mfn_to_virt(emfn - 1) >= HYPERVISOR_VIRT_END )
prot &= ~_PAGE_GLOBAL;
diff --git a/xen/common/pdx.c b/xen/common/pdx.c
index 99d4a90a50..72845e4bab 100644
--- a/xen/common/pdx.c
+++ b/xen/common/pdx.c
@@ -88,7 +88,7 @@ bool __mfn_valid(unsigned long mfn)
}
/* Sets all bits from the most-significant 1-bit down to the LSB */
-static uint64_t __init fill_mask(uint64_t mask)
+static uint64_t fill_mask(uint64_t mask)
{
while (mask & (mask + 1))
mask |= mask + 1;
@@ -96,6 +96,15 @@ static uint64_t __init fill_mask(uint64_t mask)
return mask;
}
+bool pdx_is_region_compressible(unsigned long smfn, unsigned long emfn)
+{
+ uint64_t base = smfn << PAGE_SHIFT;
+ uint64_t len = (emfn - smfn) << PAGE_SHIFT;
+
+ return !(smfn & pfn_hole_mask) &&
+ !(pdx_region_mask(base, len) & ~ma_va_bottom_mask);
+}
+
/* We don't want to compress the low MAX_ORDER bits of the addresses. */
uint64_t __init pdx_init_mask(uint64_t base_addr)
{
@@ -103,7 +112,7 @@ uint64_t __init pdx_init_mask(uint64_t base_addr)
(uint64_t)1 << (MAX_ORDER + PAGE_SHIFT)) - 1);
}
-uint64_t __init pdx_region_mask(uint64_t base, uint64_t len)
+uint64_t pdx_region_mask(uint64_t base, uint64_t len)
{
/*
* We say a bit "moves" in a range if there exist 2 addresses in that
diff --git a/xen/include/xen/pdx.h b/xen/include/xen/pdx.h
index f8ca0f5821..5378e664c2 100644
--- a/xen/include/xen/pdx.h
+++ b/xen/include/xen/pdx.h
@@ -77,6 +77,15 @@ extern unsigned long pfn_top_mask, ma_top_mask;
(sizeof(*frame_table) & -sizeof(*frame_table)))
extern unsigned long pdx_group_valid[];
+/**
+ * Validate a region's compatibility with the current compression runtime
+ *
+ * @param smfn Start mfn
+ * @param emfn End mfn (non-inclusive)
+ * @return True iff the region can be used with the current compression
+ */
+bool pdx_is_region_compressible(unsigned long smfn, unsigned long emfn);
+
/**
* Calculates a mask covering "moving" bits of all addresses of a region
*
--
2.34.1
next prev parent reply other threads:[~2023-07-17 16:03 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-17 16:03 [PATCH 0/8] Make PDX compression optional Alejandro Vallejo
2023-07-17 16:03 ` [PATCH 1/8] mm/pdx: Add comments throughout the codebase for pdx Alejandro Vallejo
2023-07-18 9:14 ` Jan Beulich
2023-07-17 16:03 ` [PATCH 2/8] arm/mm: Document the differences between arm32 and arm64 directmaps Alejandro Vallejo
2023-07-20 20:05 ` Julien Grall
2023-07-21 15:09 ` Alejandro Vallejo
2023-07-21 17:51 ` Julien Grall
2023-07-17 16:03 ` [PATCH 3/8] pdx: Mark pdx hole description globals readonly after boot Alejandro Vallejo
2023-07-18 9:14 ` Jan Beulich
2023-07-17 16:03 ` [PATCH 4/8] build: Remove CONFIG_HAS_PDX Alejandro Vallejo
2023-07-18 9:19 ` Jan Beulich
2023-07-18 9:35 ` Andrew Cooper
2023-07-18 9:38 ` Jan Beulich
2023-07-18 13:35 ` Alejandro Vallejo
2023-07-17 16:03 ` [PATCH 5/8] mm: Factor out the pdx compression logic in ma/va converters Alejandro Vallejo
2023-07-21 16:11 ` Julien Grall
2023-07-17 16:03 ` Alejandro Vallejo [this message]
2023-07-21 17:05 ` [PATCH 6/8] mm/pdx: Standardize region validation wrt pdx compression Julien Grall
2023-07-24 12:18 ` Alejandro Vallejo
2023-07-24 18:20 ` Julien Grall
2023-07-25 6:51 ` Jan Beulich
2023-07-25 14:27 ` Julien Grall
2023-07-25 14:34 ` Jan Beulich
2023-07-27 10:14 ` Alejandro Vallejo
2023-07-27 10:19 ` Jan Beulich
2023-07-17 16:03 ` [PATCH 7/8] pdx: Reorder pdx.[ch] Alejandro Vallejo
2023-07-17 16:24 ` Alejandro Vallejo
2023-07-17 16:03 ` [PATCH 8/8] pdx: Add CONFIG_HAS_PDX_COMPRESSION as a Kconfig option Alejandro Vallejo
2023-07-18 9:33 ` [PATCH 0/8] Make PDX compression optional Jan Beulich
2023-07-18 12:58 ` Alejandro Vallejo
2023-07-18 13:06 ` Jan Beulich
2023-07-18 13:40 ` Alejandro Vallejo
2023-07-20 22:00 ` Julien Grall
2023-07-20 22:13 ` Andrew Cooper
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=20230717160318.2113-7-alejandro.vallejo@cloud.com \
--to=alejandro.vallejo@cloud.com \
--cc=andrew.cooper3@citrix.com \
--cc=george.dunlap@citrix.com \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=roger.pau@citrix.com \
--cc=sstabellini@kernel.org \
--cc=wl@xen.org \
--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.