linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V3 07/17] riscv: compat: Re-implement TASK_SIZE for COMPAT_32BIT
@ 2022-01-20  7:39 guoren
  2022-01-20  9:31 ` Arnd Bergmann
  0 siblings, 1 reply; 6+ messages in thread
From: guoren @ 2022-01-20  7:39 UTC (permalink / raw)
  To: guoren, palmer, arnd, anup, gregkh, liush, wefu, drew,
	wangjunqiang, hch, hch
  Cc: linux-kernel, linux-riscv, linux-csky, linux-s390, sparclinux,
	linuxppc-dev, inux-parisc, linux-mips, linux-arm-kernel, x86,
	Guo Ren

From: Guo Ren <guoren@linux.alibaba.com>

Make TASK_SIZE from const to dynamic detect TIF_32BIT flag
function. Refer to arm64 to implement DEFAULT_MAP_WINDOW_64 for
efi-stub.

Limit 32-bit compatible process in 0-2GB virtual address range
(which is enough for real scenarios), because it could avoid
address sign extend problem when 32-bit enter 64-bit and ease
software design.

The standard 32-bit TASK_SIZE is 0x9dc00000:FIXADDR_START, and
compared to a compatible 32-bit, it increases 476MB for the
application's virtual address.

Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Guo Ren <guoren@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
---
 arch/riscv/include/asm/pgtable.h        | 11 ++++++++++-
 arch/riscv/include/asm/processor.h      |  6 ++++++
 drivers/firmware/efi/libstub/efi-stub.c |  2 +-
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
index 67f687aee673..e0add598e66a 100644
--- a/arch/riscv/include/asm/pgtable.h
+++ b/arch/riscv/include/asm/pgtable.h
@@ -669,7 +669,16 @@ static inline pmd_t pmdp_establish(struct vm_area_struct *vma,
  * Note that PGDIR_SIZE must evenly divide TASK_SIZE.
  */
 #ifdef CONFIG_64BIT
-#define TASK_SIZE (PGDIR_SIZE * PTRS_PER_PGD / 2)
+#define TASK_SIZE_64	(PGDIR_SIZE * PTRS_PER_PGD / 2)
+
+#ifdef CONFIG_COMPAT
+#define TASK_SIZE_32	(_AC(0x80000000, UL) - PAGE_SIZE)
+#define TASK_SIZE	(test_thread_flag(TIF_32BIT) ? \
+			 TASK_SIZE_32 : TASK_SIZE_64)
+#else
+#define TASK_SIZE	TASK_SIZE_64
+#endif
+
 #else
 #define TASK_SIZE FIXADDR_START
 #endif
diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h
index 0749924d9e55..8649436b8fcf 100644
--- a/arch/riscv/include/asm/processor.h
+++ b/arch/riscv/include/asm/processor.h
@@ -61,6 +61,12 @@ static inline void arch_thread_struct_whitelist(unsigned long *offset,
 extern void start_thread(struct pt_regs *regs,
 			unsigned long pc, unsigned long sp);
 
+#ifdef CONFIG_COMPAT
+#define DEFAULT_MAP_WINDOW_64 TASK_SIZE_64
+#else
+#define DEFAULT_MAP_WINDOW_64 TASK_SIZE
+#endif
+
 /* Free all resources held by a thread. */
 static inline void release_thread(struct task_struct *dead_task)
 {
diff --git a/drivers/firmware/efi/libstub/efi-stub.c b/drivers/firmware/efi/libstub/efi-stub.c
index e87e7f1b1a33..f57f85646a45 100644
--- a/drivers/firmware/efi/libstub/efi-stub.c
+++ b/drivers/firmware/efi/libstub/efi-stub.c
@@ -38,7 +38,7 @@
 #define EFI_RT_VIRTUAL_BASE	SZ_512M
 #define EFI_RT_VIRTUAL_SIZE	SZ_512M
 
-#ifdef CONFIG_ARM64
+#if defined(CONFIG_ARM64) || defined(CONFIG_RISCV)
 # define EFI_RT_VIRTUAL_LIMIT	DEFAULT_MAP_WINDOW_64
 #else
 # define EFI_RT_VIRTUAL_LIMIT	TASK_SIZE
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH V3 07/17] riscv: compat: Re-implement TASK_SIZE for COMPAT_32BIT
  2022-01-20  7:39 [PATCH V3 07/17] riscv: compat: Re-implement TASK_SIZE for COMPAT_32BIT guoren
@ 2022-01-20  9:31 ` Arnd Bergmann
  2022-01-20 12:53   ` David Laight
  0 siblings, 1 reply; 6+ messages in thread
From: Arnd Bergmann @ 2022-01-20  9:31 UTC (permalink / raw)
  To: Guo Ren
  Cc: Palmer Dabbelt, Arnd Bergmann, Anup Patel, gregkh, liush, Wei Fu,
	Drew Fustini, Wang Junqiang, Christoph Hellwig,
	Christoph Hellwig, Linux Kernel Mailing List, linux-riscv,
	linux-csky, linux-s390, sparclinux, linuxppc-dev, inux-parisc,
	open list:BROADCOM NVRAM DRIVER, Linux ARM,
	the arch/x86 maintainers, Guo Ren

On Thu, Jan 20, 2022 at 8:39 AM <guoren@kernel.org> wrote:
>
> From: Guo Ren <guoren@linux.alibaba.com>
>
> Make TASK_SIZE from const to dynamic detect TIF_32BIT flag
> function. Refer to arm64 to implement DEFAULT_MAP_WINDOW_64 for
> efi-stub.
>
> Limit 32-bit compatible process in 0-2GB virtual address range
> (which is enough for real scenarios), because it could avoid
> address sign extend problem when 32-bit enter 64-bit and ease
> software design.
>
> The standard 32-bit TASK_SIZE is 0x9dc00000:FIXADDR_START, and
> compared to a compatible 32-bit, it increases 476MB for the
> application's virtual address.
>
> Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
> Signed-off-by: Guo Ren <guoren@kernel.org>
> Cc: Arnd Bergmann <arnd@arndb.de>

Reviewed-by: Arnd Bergmann <arnd@arndb.de>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH V3 07/17] riscv: compat: Re-implement TASK_SIZE for COMPAT_32BIT
  2022-01-20  9:31 ` Arnd Bergmann
@ 2022-01-20 12:53   ` David Laight
  2022-01-20 13:27     ` Guo Ren
  0 siblings, 1 reply; 6+ messages in thread
From: David Laight @ 2022-01-20 12:53 UTC (permalink / raw)
  To: 'Arnd Bergmann', Guo Ren
  Cc: Palmer Dabbelt, Anup Patel, gregkh, liush, Wei Fu, Drew Fustini,
	Wang Junqiang, Christoph Hellwig, Christoph Hellwig,
	Linux Kernel Mailing List, linux-riscv, linux-csky, linux-s390,
	sparclinux, linuxppc-dev, inux-parisc,
	open list:BROADCOM NVRAM DRIVER, Linux ARM,
	the arch/x86 maintainers, Guo Ren

> > Limit 32-bit compatible process in 0-2GB virtual address range
> > (which is enough for real scenarios), because it could avoid
> > address sign extend problem when 32-bit enter 64-bit and ease
> > software design.

Eh?
I thought nearly all the other 32bit unix ports (of any flavour)
put the user-kernel boundary at 3GB.
(Apart from some very old sparc ones that use 3.5GB.)

2GB is used by Windows.

I think the x86-64 32bit compat code even puts the boundary at 4GB.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH V3 07/17] riscv: compat: Re-implement TASK_SIZE for COMPAT_32BIT
  2022-01-20 12:53   ` David Laight
@ 2022-01-20 13:27     ` Guo Ren
  2022-01-20 14:57       ` Arnd Bergmann
  0 siblings, 1 reply; 6+ messages in thread
From: Guo Ren @ 2022-01-20 13:27 UTC (permalink / raw)
  To: David Laight
  Cc: Arnd Bergmann, Palmer Dabbelt, Anup Patel, gregkh, liush, Wei Fu,
	Drew Fustini, Wang Junqiang, Christoph Hellwig,
	Christoph Hellwig, Linux Kernel Mailing List, linux-riscv,
	linux-csky, linux-s390, sparclinux, linuxppc-dev, inux-parisc,
	open list:BROADCOM NVRAM DRIVER, Linux ARM,
	the arch/x86 maintainers, Guo Ren

On Thu, Jan 20, 2022 at 8:53 PM David Laight <David.Laight@aculab.com> wrote:
>
> > > Limit 32-bit compatible process in 0-2GB virtual address range
> > > (which is enough for real scenarios), because it could avoid
> > > address sign extend problem when 32-bit enter 64-bit and ease
> > > software design.
>
> Eh?
> I thought nearly all the other 32bit unix ports (of any flavour)
> put the user-kernel boundary at 3GB.
No, riscv32 is about 2.4G, csky is 2G/2.5G.

> (Apart from some very old sparc ones that use 3.5GB.)
>
> 2GB is used by Windows.
>
> I think the x86-64 32bit compat code even puts the boundary at 4GB.
Yes, we could give rv32 compat for 4GB with some effort. But it's unnecessary.

There are no history issues for rv32, we use compat mode to reduce
memory footprint. eg: only 64MB memory available.

At end compat for 4GB is another topic, let's give the initial compat
for 2GB support to riscv.

>
>         David
>
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)



-- 
Best Regards
 Guo Ren

ML: https://lore.kernel.org/linux-csky/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH V3 07/17] riscv: compat: Re-implement TASK_SIZE for COMPAT_32BIT
  2022-01-20 13:27     ` Guo Ren
@ 2022-01-20 14:57       ` Arnd Bergmann
  2022-01-20 15:46         ` David Laight
  0 siblings, 1 reply; 6+ messages in thread
From: Arnd Bergmann @ 2022-01-20 14:57 UTC (permalink / raw)
  To: Guo Ren
  Cc: David Laight, Arnd Bergmann, Palmer Dabbelt, Anup Patel, gregkh,
	liush, Wei Fu, Drew Fustini, Wang Junqiang, Christoph Hellwig,
	Christoph Hellwig, Linux Kernel Mailing List, linux-riscv,
	linux-csky, linux-s390, sparclinux, linuxppc-dev, inux-parisc,
	open list:BROADCOM NVRAM DRIVER, Linux ARM,
	the arch/x86 maintainers, Guo Ren

On Thu, Jan 20, 2022 at 2:27 PM Guo Ren <guoren@kernel.org> wrote:
> On Thu, Jan 20, 2022 at 8:53 PM David Laight <David.Laight@aculab.com> wrote:
> > I think the x86-64 32bit compat code even puts the boundary at 4GB.
> Yes, we could give rv32 compat for 4GB with some effort. But it's unnecessary.
>
> There are no history issues for rv32, we use compat mode to reduce
> memory footprint. eg: only 64MB memory available.
>
> At end compat for 4GB is another topic, let's give the initial compat
> for 2GB support to riscv.

I think it's fine either way. Having the entire 4GB space available is nice
when you are trying to build 32-bit software natively rather then using a
cross-compiler, as you can just do it on a larger machine that supports both.

One example of software that runs into virtual memory size limitations is
the gnu linker when building large applications, but it's unlikely that you'll
actually need to run applications that run into this, while also needing to
build them natively.

Using the same limit as on native 32-bit machines can help with compatibility
of certain software, but again this is rarely a problem and I have not seen any
reports of issues with the 4GB TASK_SIZE_32 on arm64. On x86, there
is an option to use the native 3GB TASK_SIZE for compat tasks. This was
introduced to work around buggy applications a long time ago, but is
probably not used any more in practice.

       Arnd

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH V3 07/17] riscv: compat: Re-implement TASK_SIZE for COMPAT_32BIT
  2022-01-20 14:57       ` Arnd Bergmann
@ 2022-01-20 15:46         ` David Laight
  0 siblings, 0 replies; 6+ messages in thread
From: David Laight @ 2022-01-20 15:46 UTC (permalink / raw)
  To: 'Arnd Bergmann', Guo Ren
  Cc: Palmer Dabbelt, Anup Patel, gregkh, liush, Wei Fu, Drew Fustini,
	Wang Junqiang, Christoph Hellwig, Christoph Hellwig,
	Linux Kernel Mailing List, linux-riscv, linux-csky, linux-s390,
	sparclinux, linuxppc-dev, inux-parisc,
	open list:BROADCOM NVRAM DRIVER, Linux ARM,
	the arch/x86 maintainers, Guo Ren

...
> One example of software that runs into virtual memory size limitations is
> the gnu linker when building large applications, but it's unlikely that you'll
> actually need to run applications that run into this, while also needing to
> build them natively.

There are also database programs that want to mmap() large sparse files.
To some extent that is where the pressure for 64bit addresses comes from.

While (I think) most of the current riscv systems are 'toy' ones
there are definitely press reports of some quite high power systems.

I suspect they are less 'toy' than the Altera (Intel) Nios processors
we use on out fpga - you can run linux on the Nios cpu, but you probably
don't really want to do so.
Better to find an fpga with a 'proper' ARM core in the corner.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-01-20 15:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-20  7:39 [PATCH V3 07/17] riscv: compat: Re-implement TASK_SIZE for COMPAT_32BIT guoren
2022-01-20  9:31 ` Arnd Bergmann
2022-01-20 12:53   ` David Laight
2022-01-20 13:27     ` Guo Ren
2022-01-20 14:57       ` Arnd Bergmann
2022-01-20 15:46         ` David Laight

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).