[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[XEN v8 2/5] xen/arm: Introduce choice to enable 64/32 bit physical addressing


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Ayan Kumar Halder <ayan.kumar.halder@xxxxxxx>
  • Date: Fri, 2 Jun 2023 13:07:51 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=BWP1sjTCJ1CHkECWL9AfJ/baJ6+ufKsVZ9CEBrQnu9w=; b=hFZ3ds6onvufH275g2v94ROIsYJ+WoKXeS3qPKSVPE8o96102BbZJG+4aaCpzXj/ksX7dOmkwCAsxtQneziaVMLuYFzHMlYcsMwV2pJj8+DSQXbvA1wfmBY4uZyUJqwTyjieKWoOIP0cl0vmuPjcHDeWUEbaMrgbFoawOizilfAGaRDetZDQDMT9sq/1YD6+bfEbiLfEiRdGHSR2TPo2ETJPVFtqICI13M4XtM0OIN3zIG+t+lYA8s6Y6qomga/Uwr4UIfdMamwxZgBu4diKr3LPAAABmtWIStKvdD/Ub+jv1fR+b8l5ISeAhK/2Ilu0qM1FLqIQUywKl0Jdn1nmrw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QWl9MsWQOEptry0CgWicNoOykTMCgS93GPcFBzq9sYA46kSG699ueTN98jesJhI3SxN5IeFL71Q1OnBjqWJUZLfTIFaZTncfHBS8xwPLS+ju7Ogw6Ealysiqn4ABIuxpzDUkp2oYeGsRLY+ucYpnmX+dLWV42cEOcJQOKOsp7gBnP0xn6gzllrrkTO+ICqToAdgbMvp0cMRquzFjh9/7sYqhD9OczM1TuRvm2tmD2KVpHw1i7rraC2pnChzm80V+JlZD0ij3h1TtPGp25hS9puofg6qx6wzrgVdje0k6GRKhrDzxnZCl4wiutoYIV9V8M3NFwEvpcwDkXWKQnJyoZw==
  • Cc: <sstabellini@xxxxxxxxxx>, <stefano.stabellini@xxxxxxx>, <julien@xxxxxxx>, <Volodymyr_Babchuk@xxxxxxxx>, <bertrand.marquis@xxxxxxx>, <andrew.cooper3@xxxxxxxxxx>, <george.dunlap@xxxxxxxxxx>, <jbeulich@xxxxxxxx>, <wl@xxxxxxx>, <rahul.singh@xxxxxxx>, Ayan Kumar Halder <ayan.kumar.halder@xxxxxxx>
  • Delivery-date: Fri, 02 Jun 2023 12:09:24 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Some Arm based hardware platforms which does not support LPAE
(eg Cortex-R52), uses 32 bit physical addresses.
Also, users may choose to use 32 bits to represent physical addresses
for optimization.

To support the above use cases, we have introduced arch independent
config to choose if the physical address can be represented using
32 bits (PHYS_ADDR_T_32) or 64 bits (!PHYS_ADDR_T_32).
For now only ARM_32 provides support to enable 32 bit physical
addressing.

When PHYS_ADDR_T_32 is defined, PADDR_BITS is set to 32. Note that we
use "unsigned long" (not "uint32_t") to denote the datatype of physical
address. This is done to avoid using a cast each time PAGE_* macros are
used on paddr_t. For eg PAGE_SIZE is defined as unsigned long. Thus,
each time PAGE_SIZE is used with paddr_t, the result will be
"unsigned long".
On 32-bit architecture, "unsigned long" is 32-bit wide. Thus, it can be
used to denote physical address.

When PHYS_ADDR_T_32 is not defined for ARM_32, PADDR_BITS is set to 40.
For ARM_64, PADDR_BITS is set to 48.
The last two are same as the current configuration used today on Xen.

Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@xxxxxxx>
Reviewed-by: Michal Orzel <michal.orzel@xxxxxxx>
---
Changes from -
v1 - 1. Extracted from "[XEN v1 8/9] xen/arm: Other adaptations required to 
support 32bit paddr".

v2 - 1. Introduced Kconfig choice. ARM_64 can select PHYS_ADDR_64 only whereas
ARM_32 can select PHYS_ADDR_32 or PHYS_ADDR_64.
2. For CONFIG_ARM_PA_32, paddr_t is defined as 'unsigned long'. 

v3 - 1. Allow user to define PADDR_BITS by selecting different config options
ARM_PA_BITS_32, ARM_PA_BITS_40 and ARM_PA_BITS_48.
2. Add the choice under "Architecture Features".

v4 - 1. Removed PHYS_ADDR_T_64 as !PHYS_ADDR_T_32 means PHYS_ADDR_T_32.

v5 - 1. Removed ARM_PA_BITS_48 as there is no choice for ARM_64.
2. In ARM_PA_BITS_32, "help" is moved to last, and "depends on" before "select".

v6 - 1. Explained why we use "unsigned long" to represent physical address
for ARM_32.

v7 - 1. Updated the reasoning for using "unsigned long" for paddr_t.
2. Added R-b by Michal.

 xen/arch/Kconfig                     |  3 +++
 xen/arch/arm/Kconfig                 | 33 ++++++++++++++++++++++++++++
 xen/arch/arm/include/asm/page-bits.h |  6 +----
 xen/arch/arm/include/asm/types.h     | 14 ++++++++++++
 xen/arch/arm/mm.c                    |  5 +++++
 5 files changed, 56 insertions(+), 5 deletions(-)

diff --git a/xen/arch/Kconfig b/xen/arch/Kconfig
index 7028f7b74f..67ba38f32f 100644
--- a/xen/arch/Kconfig
+++ b/xen/arch/Kconfig
@@ -1,6 +1,9 @@
 config 64BIT
        bool
 
+config PHYS_ADDR_T_32
+       bool
+
 config NR_CPUS
        int "Maximum number of CPUs"
        range 1 4095
diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig
index 239d3aed3c..1e87fe0247 100644
--- a/xen/arch/arm/Kconfig
+++ b/xen/arch/arm/Kconfig
@@ -26,6 +26,39 @@ config ARCH_DEFCONFIG
 
 menu "Architecture Features"
 
+choice
+       prompt "Physical address space size" if ARM_32
+       default ARM_PA_BITS_40 if ARM_32
+       help
+         User can choose to represent the width of physical address. This can
+         sometimes help in optimizing the size of image when user chooses a
+         smaller size to represent physical address.
+
+config ARM_PA_BITS_32
+       bool "32-bit"
+       depends on ARM_32
+       select PHYS_ADDR_T_32
+       help
+         On platforms where any physical address can be represented within 32 
bits,
+         user should choose this option. This will help in reduced size of the
+         binary.
+         Xen uses "unsigned long" and not "uint32_t" to denote the datatype of
+         physical address. This is done to avoid using a cast each time PAGE_*
+         macros are used on paddr_t. For eg PAGE_SIZE is defined as unsigned 
long.
+         On 32-bit architecture, "unsigned long" is 32-bit wide. Thus, it can 
be
+         used to denote physical address.
+
+config ARM_PA_BITS_40
+       bool "40-bit"
+       depends on ARM_32
+endchoice
+
+config PADDR_BITS
+       int
+       default 32 if ARM_PA_BITS_32
+       default 40 if ARM_PA_BITS_40
+       default 48 if ARM_64
+
 source "arch/Kconfig"
 
 config ACPI
diff --git a/xen/arch/arm/include/asm/page-bits.h 
b/xen/arch/arm/include/asm/page-bits.h
index 5d6477e599..deb381ceeb 100644
--- a/xen/arch/arm/include/asm/page-bits.h
+++ b/xen/arch/arm/include/asm/page-bits.h
@@ -3,10 +3,6 @@
 
 #define PAGE_SHIFT              12
 
-#ifdef CONFIG_ARM_64
-#define PADDR_BITS              48
-#else
-#define PADDR_BITS              40
-#endif
+#define PADDR_BITS              CONFIG_PADDR_BITS
 
 #endif /* __ARM_PAGE_SHIFT_H__ */
diff --git a/xen/arch/arm/include/asm/types.h b/xen/arch/arm/include/asm/types.h
index e218ed77bd..fb6618ef24 100644
--- a/xen/arch/arm/include/asm/types.h
+++ b/xen/arch/arm/include/asm/types.h
@@ -34,9 +34,23 @@ typedef signed long long s64;
 typedef unsigned long long u64;
 typedef u32 vaddr_t;
 #define PRIvaddr PRIx32
+#if defined(CONFIG_PHYS_ADDR_T_32)
+
+/*
+ * We use "unsigned long" and not "uint32_t" to denote the type. This is done
+ * to avoid having a cast each time PAGE_* macros are used on paddr_t. For eg
+ * PAGE_SIZE is defined as unsigned long.
+ * On 32-bit architecture, "unsigned long" is 32-bit wide. Thus, we can use it
+ * to denote physical address.
+ */
+typedef unsigned long paddr_t;
+#define INVALID_PADDR (~0UL)
+#define PRIpaddr "08lx"
+#else
 typedef u64 paddr_t;
 #define INVALID_PADDR (~0ULL)
 #define PRIpaddr "016llx"
+#endif
 typedef u32 register_t;
 #define PRIregister "08x"
 #elif defined (CONFIG_ARM_64)
diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c
index 74f6ff2c6f..5ef5fd8c49 100644
--- a/xen/arch/arm/mm.c
+++ b/xen/arch/arm/mm.c
@@ -703,6 +703,11 @@ void __init setup_frametable_mappings(paddr_t ps, paddr_t 
pe)
     const unsigned long mapping_size = frametable_size < MB(32) ? MB(2) : 
MB(32);
     int rc;
 
+    /*
+     * The size of paddr_t should be sufficient for the complete range of
+     * physical address.
+     */
+    BUILD_BUG_ON((sizeof(paddr_t) * BITS_PER_BYTE) < PADDR_BITS);
     BUILD_BUG_ON(sizeof(struct page_info) != PAGE_INFO_SIZE);
 
     if ( frametable_size > FRAMETABLE_SIZE )
-- 
2.17.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.