diff mbox series

[V2,2/4] arm64: mm: Introduce DEFAULT_MAP_WINDOW

Message ID 20181017163459.20175-3-steve.capper@arm.com (mailing list archive)
State New, archived
Headers show
Series 52-bit userspace VAs | expand

Commit Message

Steve Capper Oct. 17, 2018, 4:34 p.m. UTC
We wish to introduce a 52-bit virtual address space for userspace but
maintain compatibility with software that assumes the maximum VA space
size is 48 bit.

In order to achieve this, on 52-bit VA systems, we make mmap behave as
if it were running on a 48-bit VA system (unless userspace explicitly
requests a VA where addr[51:48] != 0).

On a system running a 52-bit userspace we need TASK_SIZE to represent
the 52-bit limit as it is used in various places to distinguish between
kernelspace and userspace addresses.

Thus we need a new limit for mmap, stack, ELF loader and EFI (which uses
TTBR0) to represent the non-extended VA space.

This patch introduces DEFAULT_MAP_WINDOW and DEFAULT_MAP_WINDOW_64 and
switches the appropriate logic to use that instead of TASK_SIZE.

Signed-off-by: Steve Capper <steve.capper@arm.com>
---
 arch/arm64/include/asm/elf.h            | 2 +-
 arch/arm64/include/asm/processor.h      | 9 +++++++--
 drivers/firmware/efi/arm-runtime.c      | 2 +-
 drivers/firmware/efi/libstub/arm-stub.c | 2 +-
 4 files changed, 10 insertions(+), 5 deletions(-)

Comments

kernel test robot Oct. 18, 2018, 1:50 a.m. UTC | #1
Hi Steve,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on arm64/for-next/core]
[also build test ERROR on v4.19-rc8]
[cannot apply to next-20181017]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Steve-Capper/52-bit-userspace-VAs/20181018-061652
base:   https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/core
config: arm64-defconfig (attached as .config)
compiler: aarch64-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=7.2.0 make.cross ARCH=arm64 

All error/warnings (new ones prefixed by >>):

   In file included from include/linux/cache.h:5:0,
                    from include/linux/printk.h:9,
                    from include/linux/kernel.h:14,
                    from include/asm-generic/bug.h:18,
                    from arch/arm64/include/asm/bug.h:37,
                    from include/linux/bug.h:5,
                    from include/linux/thread_info.h:12,
                    from fs//hugetlbfs/inode.c:12:
   fs//hugetlbfs/inode.c: In function 'hugetlb_get_unmapped_area':
>> arch/arm64/include/asm/processor.h:63:50: error: 'tsk' undeclared (first use in this function)
    #define DEFAULT_MAP_WINDOW (test_tsk_thread_flag(tsk, TIF_32BIT) ? \
                                                     ^
   include/uapi/linux/kernel.h:11:41: note: in definition of macro '__ALIGN_KERNEL_MASK'
    #define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask))
                                            ^
>> include/linux/kernel.h:58:22: note: in expansion of macro '__ALIGN_KERNEL'
    #define ALIGN(x, a)  __ALIGN_KERNEL((x), (a))
                         ^~~~~~~~~~~~~~
>> include/linux/mm.h:144:26: note: in expansion of macro 'ALIGN'
    #define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE)
                             ^~~~~
>> arch/arm64/include/asm/processor.h:70:29: note: in expansion of macro 'PAGE_ALIGN'
    #define TASK_UNMAPPED_BASE (PAGE_ALIGN(DEFAULT_MAP_WINDOW / 4))
                                ^~~~~~~~~~
>> arch/arm64/include/asm/processor.h:70:40: note: in expansion of macro 'DEFAULT_MAP_WINDOW'
    #define TASK_UNMAPPED_BASE (PAGE_ALIGN(DEFAULT_MAP_WINDOW / 4))
                                           ^~~~~~~~~~~~~~~~~~
>> fs//hugetlbfs/inode.c:214:19: note: in expansion of macro 'TASK_UNMAPPED_BASE'
     info.low_limit = TASK_UNMAPPED_BASE;
                      ^~~~~~~~~~~~~~~~~~
   arch/arm64/include/asm/processor.h:63:50: note: each undeclared identifier is reported only once for each function it appears in
    #define DEFAULT_MAP_WINDOW (test_tsk_thread_flag(tsk, TIF_32BIT) ? \
                                                     ^
   include/uapi/linux/kernel.h:11:41: note: in definition of macro '__ALIGN_KERNEL_MASK'
    #define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask))
                                            ^
>> include/linux/kernel.h:58:22: note: in expansion of macro '__ALIGN_KERNEL'
    #define ALIGN(x, a)  __ALIGN_KERNEL((x), (a))
                         ^~~~~~~~~~~~~~
>> include/linux/mm.h:144:26: note: in expansion of macro 'ALIGN'
    #define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE)
                             ^~~~~
>> arch/arm64/include/asm/processor.h:70:29: note: in expansion of macro 'PAGE_ALIGN'
    #define TASK_UNMAPPED_BASE (PAGE_ALIGN(DEFAULT_MAP_WINDOW / 4))
                                ^~~~~~~~~~
>> arch/arm64/include/asm/processor.h:70:40: note: in expansion of macro 'DEFAULT_MAP_WINDOW'
    #define TASK_UNMAPPED_BASE (PAGE_ALIGN(DEFAULT_MAP_WINDOW / 4))
                                           ^~~~~~~~~~~~~~~~~~
>> fs//hugetlbfs/inode.c:214:19: note: in expansion of macro 'TASK_UNMAPPED_BASE'
     info.low_limit = TASK_UNMAPPED_BASE;
                      ^~~~~~~~~~~~~~~~~~
--
   In file included from include/linux/cache.h:5:0,
                    from include/linux/printk.h:9,
                    from include/linux/kernel.h:14,
                    from include/asm-generic/bug.h:18,
                    from arch/arm64/include/asm/bug.h:37,
                    from include/linux/bug.h:5,
                    from include/linux/thread_info.h:12,
                    from fs/hugetlbfs/inode.c:12:
   fs/hugetlbfs/inode.c: In function 'hugetlb_get_unmapped_area':
>> arch/arm64/include/asm/processor.h:63:50: error: 'tsk' undeclared (first use in this function)
    #define DEFAULT_MAP_WINDOW (test_tsk_thread_flag(tsk, TIF_32BIT) ? \
                                                     ^
   include/uapi/linux/kernel.h:11:41: note: in definition of macro '__ALIGN_KERNEL_MASK'
    #define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask))
                                            ^
>> include/linux/kernel.h:58:22: note: in expansion of macro '__ALIGN_KERNEL'
    #define ALIGN(x, a)  __ALIGN_KERNEL((x), (a))
                         ^~~~~~~~~~~~~~
>> include/linux/mm.h:144:26: note: in expansion of macro 'ALIGN'
    #define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE)
                             ^~~~~
>> arch/arm64/include/asm/processor.h:70:29: note: in expansion of macro 'PAGE_ALIGN'
    #define TASK_UNMAPPED_BASE (PAGE_ALIGN(DEFAULT_MAP_WINDOW / 4))
                                ^~~~~~~~~~
>> arch/arm64/include/asm/processor.h:70:40: note: in expansion of macro 'DEFAULT_MAP_WINDOW'
    #define TASK_UNMAPPED_BASE (PAGE_ALIGN(DEFAULT_MAP_WINDOW / 4))
                                           ^~~~~~~~~~~~~~~~~~
   fs/hugetlbfs/inode.c:214:19: note: in expansion of macro 'TASK_UNMAPPED_BASE'
     info.low_limit = TASK_UNMAPPED_BASE;
                      ^~~~~~~~~~~~~~~~~~
   arch/arm64/include/asm/processor.h:63:50: note: each undeclared identifier is reported only once for each function it appears in
    #define DEFAULT_MAP_WINDOW (test_tsk_thread_flag(tsk, TIF_32BIT) ? \
                                                     ^
   include/uapi/linux/kernel.h:11:41: note: in definition of macro '__ALIGN_KERNEL_MASK'
    #define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask))
                                            ^
>> include/linux/kernel.h:58:22: note: in expansion of macro '__ALIGN_KERNEL'
    #define ALIGN(x, a)  __ALIGN_KERNEL((x), (a))
                         ^~~~~~~~~~~~~~
>> include/linux/mm.h:144:26: note: in expansion of macro 'ALIGN'
    #define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE)
                             ^~~~~
>> arch/arm64/include/asm/processor.h:70:29: note: in expansion of macro 'PAGE_ALIGN'
    #define TASK_UNMAPPED_BASE (PAGE_ALIGN(DEFAULT_MAP_WINDOW / 4))
                                ^~~~~~~~~~
>> arch/arm64/include/asm/processor.h:70:40: note: in expansion of macro 'DEFAULT_MAP_WINDOW'
    #define TASK_UNMAPPED_BASE (PAGE_ALIGN(DEFAULT_MAP_WINDOW / 4))
                                           ^~~~~~~~~~~~~~~~~~
   fs/hugetlbfs/inode.c:214:19: note: in expansion of macro 'TASK_UNMAPPED_BASE'
     info.low_limit = TASK_UNMAPPED_BASE;
                      ^~~~~~~~~~~~~~~~~~

vim +/tsk +63 arch/arm64/include/asm/processor.h

    52	
    53	/*
    54	 * TASK_SIZE - the maximum size of a user space task.
    55	 * TASK_UNMAPPED_BASE - the lower boundary of the mmap VM area.
    56	 */
    57	#ifdef CONFIG_COMPAT
    58	#define TASK_SIZE_32		UL(0x100000000)
    59	#define TASK_SIZE		(test_thread_flag(TIF_32BIT) ? \
    60					TASK_SIZE_32 : TASK_SIZE_64)
    61	#define TASK_SIZE_OF(tsk)	(test_tsk_thread_flag(tsk, TIF_32BIT) ? \
    62					TASK_SIZE_32 : TASK_SIZE_64)
  > 63	#define DEFAULT_MAP_WINDOW	(test_tsk_thread_flag(tsk, TIF_32BIT) ? \
    64					TASK_SIZE_32 : DEFAULT_MAP_WINDOW_64)
    65	#else
    66	#define TASK_SIZE		TASK_SIZE_64
    67	#define DEFAULT_MAP_WINDOW	DEFAULT_MAP_WINDOW_64
    68	#endif /* CONFIG_COMPAT */
    69	
  > 70	#define TASK_UNMAPPED_BASE	(PAGE_ALIGN(DEFAULT_MAP_WINDOW / 4))
    71	#define STACK_TOP_MAX		DEFAULT_MAP_WINDOW_64
    72	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
kernel test robot Oct. 18, 2018, 2:09 a.m. UTC | #2
Hi Steve,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on arm64/for-next/core]
[also build test WARNING on v4.19-rc8]
[cannot apply to next-20181017]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Steve-Capper/52-bit-userspace-VAs/20181018-061652
base:   https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/core
config: arm64-defconfig (attached as .config)
compiler: aarch64-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=7.2.0 make.cross ARCH=arm64 

All warnings (new ones prefixed by >>):

   In file included from include/linux/cache.h:5:0,
                    from include/linux/printk.h:9,
                    from include/linux/kernel.h:14,
                    from include/asm-generic/bug.h:18,
                    from arch/arm64/include/asm/bug.h:37,
                    from include/linux/bug.h:5,
                    from arch/arm64/include/asm/ptrace.h:90,
                    from arch/arm64/include/asm/elf.h:24,
                    from include/linux/elf.h:5,
                    from arch/arm64/mm/mmap.c:19:
   arch/arm64/mm/mmap.c: In function 'arch_pick_mmap_layout':
   arch/arm64/include/asm/processor.h:63:50: error: 'tsk' undeclared (first use in this function)
    #define DEFAULT_MAP_WINDOW (test_tsk_thread_flag(tsk, TIF_32BIT) ? \
                                                     ^
   include/uapi/linux/kernel.h:11:41: note: in definition of macro '__ALIGN_KERNEL_MASK'
    #define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask))
                                            ^
   include/linux/kernel.h:58:22: note: in expansion of macro '__ALIGN_KERNEL'
    #define ALIGN(x, a)  __ALIGN_KERNEL((x), (a))
                         ^~~~~~~~~~~~~~
   include/linux/mm.h:144:26: note: in expansion of macro 'ALIGN'
    #define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE)
                             ^~~~~
   arch/arm64/include/asm/processor.h:70:29: note: in expansion of macro 'PAGE_ALIGN'
    #define TASK_UNMAPPED_BASE (PAGE_ALIGN(DEFAULT_MAP_WINDOW / 4))
                                ^~~~~~~~~~
   arch/arm64/include/asm/processor.h:70:40: note: in expansion of macro 'DEFAULT_MAP_WINDOW'
    #define TASK_UNMAPPED_BASE (PAGE_ALIGN(DEFAULT_MAP_WINDOW / 4))
                                           ^~~~~~~~~~~~~~~~~~
>> arch/arm64/mm/mmap.c:98:19: note: in expansion of macro 'TASK_UNMAPPED_BASE'
      mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
                      ^~~~~~~~~~~~~~~~~~
   arch/arm64/include/asm/processor.h:63:50: note: each undeclared identifier is reported only once for each function it appears in
    #define DEFAULT_MAP_WINDOW (test_tsk_thread_flag(tsk, TIF_32BIT) ? \
                                                     ^
   include/uapi/linux/kernel.h:11:41: note: in definition of macro '__ALIGN_KERNEL_MASK'
    #define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask))
                                            ^
   include/linux/kernel.h:58:22: note: in expansion of macro '__ALIGN_KERNEL'
    #define ALIGN(x, a)  __ALIGN_KERNEL((x), (a))
                         ^~~~~~~~~~~~~~
   include/linux/mm.h:144:26: note: in expansion of macro 'ALIGN'
    #define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE)
                             ^~~~~
   arch/arm64/include/asm/processor.h:70:29: note: in expansion of macro 'PAGE_ALIGN'
    #define TASK_UNMAPPED_BASE (PAGE_ALIGN(DEFAULT_MAP_WINDOW / 4))
                                ^~~~~~~~~~
   arch/arm64/include/asm/processor.h:70:40: note: in expansion of macro 'DEFAULT_MAP_WINDOW'
    #define TASK_UNMAPPED_BASE (PAGE_ALIGN(DEFAULT_MAP_WINDOW / 4))
                                           ^~~~~~~~~~~~~~~~~~
>> arch/arm64/mm/mmap.c:98:19: note: in expansion of macro 'TASK_UNMAPPED_BASE'
      mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
                      ^~~~~~~~~~~~~~~~~~

vim +/TASK_UNMAPPED_BASE +98 arch/arm64/mm/mmap.c

1d18c47c Catalin Marinas 2012-03-05   81  
1d18c47c Catalin Marinas 2012-03-05   82  /*
1d18c47c Catalin Marinas 2012-03-05   83   * This function, called very early during the creation of a new process VM
1d18c47c Catalin Marinas 2012-03-05   84   * image, sets up which VM layout function to use:
1d18c47c Catalin Marinas 2012-03-05   85   */
8f2af155 Kees Cook       2018-04-10   86  void arch_pick_mmap_layout(struct mm_struct *mm, struct rlimit *rlim_stack)
1d18c47c Catalin Marinas 2012-03-05   87  {
dd04cff1 Kees Cook       2015-04-14   88  	unsigned long random_factor = 0UL;
dd04cff1 Kees Cook       2015-04-14   89  
dd04cff1 Kees Cook       2015-04-14   90  	if (current->flags & PF_RANDOMIZE)
2b68f6ca Kees Cook       2015-04-14   91  		random_factor = arch_mmap_rnd();
dd04cff1 Kees Cook       2015-04-14   92  
1d18c47c Catalin Marinas 2012-03-05   93  	/*
1d18c47c Catalin Marinas 2012-03-05   94  	 * Fall back to the standard layout if the personality bit is set, or
1d18c47c Catalin Marinas 2012-03-05   95  	 * if the expected stack growth is unlimited:
1d18c47c Catalin Marinas 2012-03-05   96  	 */
8f2af155 Kees Cook       2018-04-10   97  	if (mmap_is_legacy(rlim_stack)) {
dd04cff1 Kees Cook       2015-04-14  @98  		mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
1d18c47c Catalin Marinas 2012-03-05   99  		mm->get_unmapped_area = arch_get_unmapped_area;
1d18c47c Catalin Marinas 2012-03-05  100  	} else {
8f2af155 Kees Cook       2018-04-10  101  		mm->mmap_base = mmap_base(random_factor, rlim_stack);
1d18c47c Catalin Marinas 2012-03-05  102  		mm->get_unmapped_area = arch_get_unmapped_area_topdown;
1d18c47c Catalin Marinas 2012-03-05  103  	}
1d18c47c Catalin Marinas 2012-03-05  104  }
1d18c47c Catalin Marinas 2012-03-05  105  

:::::: The code at line 98 was first introduced by commit
:::::: dd04cff1dceab18226853b555cf07914648a235f arm64: standardize mmap_rnd() usage

:::::: TO: Kees Cook <keescook@chromium.org>
:::::: CC: Linus Torvalds <torvalds@linux-foundation.org>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
Steve Capper Oct. 18, 2018, 10:47 a.m. UTC | #3
On Wed, Oct 17, 2018 at 05:34:57PM +0100, Steve Capper wrote:
> We wish to introduce a 52-bit virtual address space for userspace but
> maintain compatibility with software that assumes the maximum VA space
> size is 48 bit.
> 
> In order to achieve this, on 52-bit VA systems, we make mmap behave as
> if it were running on a 48-bit VA system (unless userspace explicitly
> requests a VA where addr[51:48] != 0).
> 
> On a system running a 52-bit userspace we need TASK_SIZE to represent
> the 52-bit limit as it is used in various places to distinguish between
> kernelspace and userspace addresses.
> 
> Thus we need a new limit for mmap, stack, ELF loader and EFI (which uses
> TTBR0) to represent the non-extended VA space.
> 
> This patch introduces DEFAULT_MAP_WINDOW and DEFAULT_MAP_WINDOW_64 and
> switches the appropriate logic to use that instead of TASK_SIZE.
> 
> Signed-off-by: Steve Capper <steve.capper@arm.com>

Whilst testing this series I inadvertantly dropped CONFIG_COMPAT which
has led to some kbuild errors with defconfig.

I will make the following changes to this patch.

[...]
> diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h
> index 79657ad91397..46c9d9ff028c 100644
> --- a/arch/arm64/include/asm/processor.h
> +++ b/arch/arm64/include/asm/processor.h
> @@ -26,6 +26,8 @@
>  
>  #ifndef __ASSEMBLY__
>  
> +#define DEFAULT_MAP_WINDOW_64	(UL(1) << VA_BITS)
> +
>  /*
>   * Default implementation of macro that returns current
>   * instruction pointer ("program counter").
> @@ -58,13 +60,16 @@
>  				TASK_SIZE_32 : TASK_SIZE_64)
>  #define TASK_SIZE_OF(tsk)	(test_tsk_thread_flag(tsk, TIF_32BIT) ? \
>  				TASK_SIZE_32 : TASK_SIZE_64)
> +#define DEFAULT_MAP_WINDOW	(test_tsk_thread_flag(tsk, TIF_32BIT) ? \
> +				TASK_SIZE_32 : DEFAULT_MAP_WINDOW_64)

Instead of test_tsk_thread_flag I will use test_thread_flag for
DEFAULT_MAP_WINDOW.

>  #else
>  #define TASK_SIZE		TASK_SIZE_64
> +#define DEFAULT_MAP_WINDOW	DEFAULT_MAP_WINDOW_64
>  #endif /* CONFIG_COMPAT */
>  
> -#define TASK_UNMAPPED_BASE	(PAGE_ALIGN(TASK_SIZE / 4))
> +#define TASK_UNMAPPED_BASE	(PAGE_ALIGN(DEFAULT_MAP_WINDOW / 4))
> +#define STACK_TOP_MAX		DEFAULT_MAP_WINDOW_64
>  
> -#define STACK_TOP_MAX		TASK_SIZE_64
>  #ifdef CONFIG_COMPAT
>  #define AARCH32_VECTORS_BASE	0xffff0000
>  #define STACK_TOP		(test_thread_flag(TIF_32BIT) ? \
> diff --git a/drivers/firmware/efi/arm-runtime.c b/drivers/firmware/efi/arm-runtime.c
> index 922cfb813109..952cec5b611a 100644
> --- a/drivers/firmware/efi/arm-runtime.c
> +++ b/drivers/firmware/efi/arm-runtime.c
> @@ -38,7 +38,7 @@ static struct ptdump_info efi_ptdump_info = {
>  	.mm		= &efi_mm,
>  	.markers	= (struct addr_marker[]){
>  		{ 0,		"UEFI runtime start" },
> -		{ TASK_SIZE_64,	"UEFI runtime end" }
> +		{ DEFAULT_MAP_WINDOW_64, "UEFI runtime end" }
>  	},
>  	.base_addr	= 0,
>  };
[...]

Also I will modify arch/arm64/mm/init.c:615 to be:
BUILD_BUG_ON(TASK_SIZE_32 > DEFAULT_MAP_WINDOW_64);

The above give me a working kernel with defconig. I will perform more tests
on COMPAT before sending a revised series out.

Cheers,
diff mbox series

Patch

diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h
index 433b9554c6a1..bc9bd9e77d9d 100644
--- a/arch/arm64/include/asm/elf.h
+++ b/arch/arm64/include/asm/elf.h
@@ -117,7 +117,7 @@ 
  * 64-bit, this is above 4GB to leave the entire 32-bit address
  * space open for things that want to use the area for 32-bit pointers.
  */
-#define ELF_ET_DYN_BASE		(2 * TASK_SIZE_64 / 3)
+#define ELF_ET_DYN_BASE		(2 * DEFAULT_MAP_WINDOW_64 / 3)
 
 #ifndef __ASSEMBLY__
 
diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h
index 79657ad91397..46c9d9ff028c 100644
--- a/arch/arm64/include/asm/processor.h
+++ b/arch/arm64/include/asm/processor.h
@@ -26,6 +26,8 @@ 
 
 #ifndef __ASSEMBLY__
 
+#define DEFAULT_MAP_WINDOW_64	(UL(1) << VA_BITS)
+
 /*
  * Default implementation of macro that returns current
  * instruction pointer ("program counter").
@@ -58,13 +60,16 @@ 
 				TASK_SIZE_32 : TASK_SIZE_64)
 #define TASK_SIZE_OF(tsk)	(test_tsk_thread_flag(tsk, TIF_32BIT) ? \
 				TASK_SIZE_32 : TASK_SIZE_64)
+#define DEFAULT_MAP_WINDOW	(test_tsk_thread_flag(tsk, TIF_32BIT) ? \
+				TASK_SIZE_32 : DEFAULT_MAP_WINDOW_64)
 #else
 #define TASK_SIZE		TASK_SIZE_64
+#define DEFAULT_MAP_WINDOW	DEFAULT_MAP_WINDOW_64
 #endif /* CONFIG_COMPAT */
 
-#define TASK_UNMAPPED_BASE	(PAGE_ALIGN(TASK_SIZE / 4))
+#define TASK_UNMAPPED_BASE	(PAGE_ALIGN(DEFAULT_MAP_WINDOW / 4))
+#define STACK_TOP_MAX		DEFAULT_MAP_WINDOW_64
 
-#define STACK_TOP_MAX		TASK_SIZE_64
 #ifdef CONFIG_COMPAT
 #define AARCH32_VECTORS_BASE	0xffff0000
 #define STACK_TOP		(test_thread_flag(TIF_32BIT) ? \
diff --git a/drivers/firmware/efi/arm-runtime.c b/drivers/firmware/efi/arm-runtime.c
index 922cfb813109..952cec5b611a 100644
--- a/drivers/firmware/efi/arm-runtime.c
+++ b/drivers/firmware/efi/arm-runtime.c
@@ -38,7 +38,7 @@  static struct ptdump_info efi_ptdump_info = {
 	.mm		= &efi_mm,
 	.markers	= (struct addr_marker[]){
 		{ 0,		"UEFI runtime start" },
-		{ TASK_SIZE_64,	"UEFI runtime end" }
+		{ DEFAULT_MAP_WINDOW_64, "UEFI runtime end" }
 	},
 	.base_addr	= 0,
 };
diff --git a/drivers/firmware/efi/libstub/arm-stub.c b/drivers/firmware/efi/libstub/arm-stub.c
index 6920033de6d4..ac297c20ab1e 100644
--- a/drivers/firmware/efi/libstub/arm-stub.c
+++ b/drivers/firmware/efi/libstub/arm-stub.c
@@ -33,7 +33,7 @@ 
 #define EFI_RT_VIRTUAL_SIZE	SZ_512M
 
 #ifdef CONFIG_ARM64
-# define EFI_RT_VIRTUAL_LIMIT	TASK_SIZE_64
+# define EFI_RT_VIRTUAL_LIMIT	DEFAULT_MAP_WINDOW_64
 #else
 # define EFI_RT_VIRTUAL_LIMIT	TASK_SIZE
 #endif