From: Alejandro Vallejo <alejandro.vallejo@cloud.com>
To: Xen-devel <xen-devel@lists.xenproject.org>
Cc: "Alejandro Vallejo" <alejandro.vallejo@cloud.com>,
"Stefano Stabellini" <sstabellini@kernel.org>,
"Julien Grall" <julien@xen.org>,
"Bertrand Marquis" <bertrand.marquis@arm.com>,
"Volodymyr Babchuk" <Volodymyr_Babchuk@epam.com>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"George Dunlap" <george.dunlap@citrix.com>,
"Jan Beulich" <jbeulich@suse.com>, "Wei Liu" <wl@xen.org>,
"Roger Pau Monné" <roger.pau@citrix.com>,
"Julien Grall" <jgrall@amazon.com>
Subject: [PATCH v3 1/4] mm: Factor out the pdx compression logic in ma/va converters
Date: Tue, 8 Aug 2023 14:02:17 +0100 [thread overview]
Message-ID: <20230808130220.27891-2-alejandro.vallejo@cloud.com> (raw)
In-Reply-To: <20230808130220.27891-1-alejandro.vallejo@cloud.com>
This patch factors out the pdx compression logic hardcoded in both ports
for the maddr<->vaddr conversion functions.
Touches both x86 and arm ports.
Signed-off-by: Alejandro Vallejo <alejandro.vallejo@cloud.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
---
v3:
* size_t -> unsigned long (Jan)
* uint64_t -> paddr_t (Jan)
---
xen/arch/arm/include/asm/mm.h | 3 +--
xen/arch/x86/include/asm/x86_64/page.h | 28 +++++++++++---------------
xen/include/xen/pdx.h | 25 +++++++++++++++++++++++
3 files changed, 38 insertions(+), 18 deletions(-)
diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h
index 5b530f0f40..c0d7f0f181 100644
--- a/xen/arch/arm/include/asm/mm.h
+++ b/xen/arch/arm/include/asm/mm.h
@@ -319,8 +319,7 @@ static inline void *maddr_to_virt(paddr_t ma)
(DIRECTMAP_SIZE >> PAGE_SHIFT));
return (void *)(XENHEAP_VIRT_START -
(directmap_base_pdx << PAGE_SHIFT) +
- ((ma & ma_va_bottom_mask) |
- ((ma & ma_top_mask) >> pfn_pdx_hole_shift)));
+ maddr_to_directmapoff(ma));
}
#endif
diff --git a/xen/arch/x86/include/asm/x86_64/page.h b/xen/arch/x86/include/asm/x86_64/page.h
index 53faa7875b..e40b451221 100644
--- a/xen/arch/x86/include/asm/x86_64/page.h
+++ b/xen/arch/x86/include/asm/x86_64/page.h
@@ -36,26 +36,22 @@ static inline unsigned long __virt_to_maddr(unsigned long va)
{
ASSERT(va < DIRECTMAP_VIRT_END);
if ( va >= DIRECTMAP_VIRT_START )
- va -= DIRECTMAP_VIRT_START;
- else
- {
- BUILD_BUG_ON(XEN_VIRT_END - XEN_VIRT_START != GB(1));
- /* Signed, so ((long)XEN_VIRT_START >> 30) fits in an imm32. */
- ASSERT(((long)va >> (PAGE_ORDER_1G + PAGE_SHIFT)) ==
- ((long)XEN_VIRT_START >> (PAGE_ORDER_1G + PAGE_SHIFT)));
-
- va += xen_phys_start - XEN_VIRT_START;
- }
- return (va & ma_va_bottom_mask) |
- ((va << pfn_pdx_hole_shift) & ma_top_mask);
+ return directmapoff_to_maddr(va - DIRECTMAP_VIRT_START);
+
+ BUILD_BUG_ON(XEN_VIRT_END - XEN_VIRT_START != GB(1));
+ /* Signed, so ((long)XEN_VIRT_START >> 30) fits in an imm32. */
+ ASSERT(((long)va >> (PAGE_ORDER_1G + PAGE_SHIFT)) ==
+ ((long)XEN_VIRT_START >> (PAGE_ORDER_1G + PAGE_SHIFT)));
+
+ return xen_phys_start + va - XEN_VIRT_START;
}
static inline void *__maddr_to_virt(unsigned long ma)
{
- ASSERT(pfn_to_pdx(ma >> PAGE_SHIFT) < (DIRECTMAP_SIZE >> PAGE_SHIFT));
- return (void *)(DIRECTMAP_VIRT_START +
- ((ma & ma_va_bottom_mask) |
- ((ma & ma_top_mask) >> pfn_pdx_hole_shift)));
+ /* Offset in the direct map, accounting for pdx compression */
+ unsigned long va_offset = maddr_to_directmapoff(ma);
+ ASSERT(va_offset < DIRECTMAP_SIZE);
+ return (void *)(DIRECTMAP_VIRT_START + va_offset);
}
/* read access (should only be used for debug printk's) */
diff --git a/xen/include/xen/pdx.h b/xen/include/xen/pdx.h
index de5439a5e5..8f29598230 100644
--- a/xen/include/xen/pdx.h
+++ b/xen/include/xen/pdx.h
@@ -160,6 +160,31 @@ static inline unsigned long pdx_to_pfn(unsigned long pdx)
#define mfn_to_pdx(mfn) pfn_to_pdx(mfn_x(mfn))
#define pdx_to_mfn(pdx) _mfn(pdx_to_pfn(pdx))
+/**
+ * Computes the offset into the direct map of an maddr
+ *
+ * @param ma Machine address
+ * @return Offset on the direct map where that
+ * machine address can be accessed
+ */
+static inline unsigned long maddr_to_directmapoff(paddr_t ma)
+{
+ return ((ma & ma_top_mask) >> pfn_pdx_hole_shift) |
+ (ma & ma_va_bottom_mask);
+}
+
+/**
+ * Computes a machine address given a direct map offset
+ *
+ * @param offset Offset into the direct map
+ * @return Corresponding machine address of that virtual location
+ */
+static inline paddr_t directmapoff_to_maddr(unsigned long offset)
+{
+ return (((paddr_t)offset << pfn_pdx_hole_shift) & ma_top_mask) |
+ (offset & ma_va_bottom_mask);
+}
+
/**
* Initializes global variables with information about the compressible
* range of the current memory regions.
--
2.34.1
next prev parent reply other threads:[~2023-08-08 13:02 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-08 13:02 [PATCH v3 0/4] Make PDX compression optional Alejandro Vallejo
2023-08-08 13:02 ` Alejandro Vallejo [this message]
2023-08-08 13:02 ` [PATCH v3 2/4] mm/pdx: Standardize region validation wrt pdx compression Alejandro Vallejo
2023-08-08 13:02 ` [PATCH v3 3/4] pdx: Reorder pdx.[ch] Alejandro Vallejo
2023-08-08 13:02 ` [PATCH v3 4/4] pdx: Add CONFIG_PDX_COMPRESSION as a common Kconfig option Alejandro Vallejo
2023-09-22 20:03 ` Andrew Cooper
2023-09-25 6:36 ` Jan Beulich
2023-09-25 9:46 ` Roger Pau Monné
2023-09-25 9:59 ` Jan Beulich
2023-09-25 10:01 ` Andrew Cooper
2023-09-25 10:15 ` Jan Beulich
2023-09-25 17:37 ` Shawn Anastasio
2023-10-06 13:20 ` Andrew Cooper
2023-08-16 9:36 ` [PATCH v3 0/4] Make PDX compression optional Alejandro Vallejo
2023-08-16 9:43 ` Jan Beulich
2023-08-16 11:12 ` Julien Grall
2023-08-16 11:27 ` Jan Beulich
2023-08-16 13:06 ` Julien Grall
2023-08-16 13:14 ` Jan Beulich
2023-08-16 13:38 ` Julien Grall
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=20230808130220.27891-2-alejandro.vallejo@cloud.com \
--to=alejandro.vallejo@cloud.com \
--cc=Volodymyr_Babchuk@epam.com \
--cc=andrew.cooper3@citrix.com \
--cc=bertrand.marquis@arm.com \
--cc=george.dunlap@citrix.com \
--cc=jbeulich@suse.com \
--cc=jgrall@amazon.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.