mbox series

[0/3] riscv: mm: Use hint address in mmap if available

Message ID 20240129-use_mmap_hint_address-v1-0-4c74da813ba1@rivosinc.com (mailing list archive)
Headers show
Series riscv: mm: Use hint address in mmap if available | expand

Message

Charlie Jenkins Jan. 30, 2024, 12:36 a.m. UTC
On riscv, mmap currently returns an address from the largest address
space that can fit entirely inside of the hint address. This makes it
such that the hint address is almost never returned. This patch raises
the mappable area up to and including the hint address. This allows mmap
to often return the hint address, which allows a performance improvement
over searching for a valid address as well as making the behavior more
similar to other architectures.

Signed-off-by: Charlie Jenkins <charlie@rivosinc.com>
---
Charlie Jenkins (3):
      riscv: mm: Use hint address in mmap if available
      selftests: riscv: Generalize mm selftests
      docs: riscv: Define behavior of mmap

 Documentation/arch/riscv/vm-layout.rst           | 16 ++--
 arch/riscv/include/asm/processor.h               | 21 ++----
 tools/testing/selftests/riscv/mm/mmap_bottomup.c | 20 +----
 tools/testing/selftests/riscv/mm/mmap_default.c  | 20 +----
 tools/testing/selftests/riscv/mm/mmap_test.h     | 93 +++++++++++++-----------
 5 files changed, 66 insertions(+), 104 deletions(-)
---
base-commit: 556e2d17cae620d549c5474b1ece053430cd50bc
change-id: 20240119-use_mmap_hint_address-f9f4b1b6f5f1

Comments

Stefan O'Rear Jan. 30, 2024, 2:04 a.m. UTC | #1
On Mon, Jan 29, 2024, at 7:36 PM, Charlie Jenkins wrote:
> On riscv, mmap currently returns an address from the largest address
> space that can fit entirely inside of the hint address. This makes it
> such that the hint address is almost never returned. This patch raises
> the mappable area up to and including the hint address. This allows mmap
> to often return the hint address, which allows a performance improvement
> over searching for a valid address as well as making the behavior more
> similar to other architectures.

This means that if an application or library opts in to Sv48 support by
passing a nonzero hint, it will lose the benefits of ASLR.

Allowing applications to opt in to a VA space smaller than the
architectural minimum seems like an independently useful feature.
Is there a reason to only add it for riscv64?

-s

> Signed-off-by: Charlie Jenkins <charlie@rivosinc.com>
> ---
> Charlie Jenkins (3):
>       riscv: mm: Use hint address in mmap if available
>       selftests: riscv: Generalize mm selftests
>       docs: riscv: Define behavior of mmap
>
>  Documentation/arch/riscv/vm-layout.rst           | 16 ++--
>  arch/riscv/include/asm/processor.h               | 21 ++----
>  tools/testing/selftests/riscv/mm/mmap_bottomup.c | 20 +----
>  tools/testing/selftests/riscv/mm/mmap_default.c  | 20 +----
>  tools/testing/selftests/riscv/mm/mmap_test.h     | 93 +++++++++++++-----------
>  5 files changed, 66 insertions(+), 104 deletions(-)
> ---
> base-commit: 556e2d17cae620d549c5474b1ece053430cd50bc
> change-id: 20240119-use_mmap_hint_address-f9f4b1b6f5f1
> -- 
> - Charlie
>
>
> _______________________________________________
> linux-riscv mailing list
> linux-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-riscv
Charlie Jenkins Jan. 30, 2024, 2:13 a.m. UTC | #2
On Mon, Jan 29, 2024 at 09:04:50PM -0500, Stefan O'Rear wrote:
> On Mon, Jan 29, 2024, at 7:36 PM, Charlie Jenkins wrote:
> > On riscv, mmap currently returns an address from the largest address
> > space that can fit entirely inside of the hint address. This makes it
> > such that the hint address is almost never returned. This patch raises
> > the mappable area up to and including the hint address. This allows mmap
> > to often return the hint address, which allows a performance improvement
> > over searching for a valid address as well as making the behavior more
> > similar to other architectures.
> 
> This means that if an application or library opts in to Sv48 support by
> passing a nonzero hint, it will lose the benefits of ASLR.

sv48 is default. However your statement stands for opting into sv57.
If they always pass the same hint address, only the first address will
be deterministic though, correct?

> 
> Allowing applications to opt in to a VA space smaller than the
> architectural minimum seems like an independently useful feature.
> Is there a reason to only add it for riscv64?
> 

If there is interest, it can be added to other architectures as well.

- Charlie

> -s
> 
> > Signed-off-by: Charlie Jenkins <charlie@rivosinc.com>
> > ---
> > Charlie Jenkins (3):
> >       riscv: mm: Use hint address in mmap if available
> >       selftests: riscv: Generalize mm selftests
> >       docs: riscv: Define behavior of mmap
> >
> >  Documentation/arch/riscv/vm-layout.rst           | 16 ++--
> >  arch/riscv/include/asm/processor.h               | 21 ++----
> >  tools/testing/selftests/riscv/mm/mmap_bottomup.c | 20 +----
> >  tools/testing/selftests/riscv/mm/mmap_default.c  | 20 +----
> >  tools/testing/selftests/riscv/mm/mmap_test.h     | 93 +++++++++++++-----------
> >  5 files changed, 66 insertions(+), 104 deletions(-)
> > ---
> > base-commit: 556e2d17cae620d549c5474b1ece053430cd50bc
> > change-id: 20240119-use_mmap_hint_address-f9f4b1b6f5f1
> > -- 
> > - Charlie
> >
> >
> > _______________________________________________
> > linux-riscv mailing list
> > linux-riscv@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/linux-riscv
Stefan O'Rear Jan. 30, 2024, 10:04 p.m. UTC | #3
On Mon, Jan 29, 2024, at 9:13 PM, Charlie Jenkins wrote:
> On Mon, Jan 29, 2024 at 09:04:50PM -0500, Stefan O'Rear wrote:
>> On Mon, Jan 29, 2024, at 7:36 PM, Charlie Jenkins wrote:
>> > On riscv, mmap currently returns an address from the largest address
>> > space that can fit entirely inside of the hint address. This makes it
>> > such that the hint address is almost never returned. This patch raises
>> > the mappable area up to and including the hint address. This allows mmap
>> > to often return the hint address, which allows a performance improvement
>> > over searching for a valid address as well as making the behavior more
>> > similar to other architectures.
>> 
>> This means that if an application or library opts in to Sv48 support by
>> passing a nonzero hint, it will lose the benefits of ASLR.
>
> sv48 is default. However your statement stands for opting into sv57.
> If they always pass the same hint address, only the first address will
> be deterministic though, correct?

I think this is correct.

>> 
>> Allowing applications to opt in to a VA space smaller than the
>> architectural minimum seems like an independently useful feature.
>> Is there a reason to only add it for riscv64?
>> 
>
> If there is interest, it can be added to other architectures as well.

I meant as opposed to riscv32.

-s

> - Charlie
>
>> -s
>> 
>> > Signed-off-by: Charlie Jenkins <charlie@rivosinc.com>
>> > ---
>> > Charlie Jenkins (3):
>> >       riscv: mm: Use hint address in mmap if available
>> >       selftests: riscv: Generalize mm selftests
>> >       docs: riscv: Define behavior of mmap
>> >
>> >  Documentation/arch/riscv/vm-layout.rst           | 16 ++--
>> >  arch/riscv/include/asm/processor.h               | 21 ++----
>> >  tools/testing/selftests/riscv/mm/mmap_bottomup.c | 20 +----
>> >  tools/testing/selftests/riscv/mm/mmap_default.c  | 20 +----
>> >  tools/testing/selftests/riscv/mm/mmap_test.h     | 93 +++++++++++++-----------
>> >  5 files changed, 66 insertions(+), 104 deletions(-)
>> > ---
>> > base-commit: 556e2d17cae620d549c5474b1ece053430cd50bc
>> > change-id: 20240119-use_mmap_hint_address-f9f4b1b6f5f1
>> > -- 
>> > - Charlie
>> >
>> >
>> > _______________________________________________
>> > linux-riscv mailing list
>> > linux-riscv@lists.infradead.org
>> > http://lists.infradead.org/mailman/listinfo/linux-riscv
>
> _______________________________________________
> linux-riscv mailing list
> linux-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-riscv
Charlie Jenkins Jan. 30, 2024, 10:10 p.m. UTC | #4
On Tue, Jan 30, 2024 at 05:04:55PM -0500, Stefan O'Rear wrote:
> On Mon, Jan 29, 2024, at 9:13 PM, Charlie Jenkins wrote:
> > On Mon, Jan 29, 2024 at 09:04:50PM -0500, Stefan O'Rear wrote:
> >> On Mon, Jan 29, 2024, at 7:36 PM, Charlie Jenkins wrote:
> >> > On riscv, mmap currently returns an address from the largest address
> >> > space that can fit entirely inside of the hint address. This makes it
> >> > such that the hint address is almost never returned. This patch raises
> >> > the mappable area up to and including the hint address. This allows mmap
> >> > to often return the hint address, which allows a performance improvement
> >> > over searching for a valid address as well as making the behavior more
> >> > similar to other architectures.
> >> 
> >> This means that if an application or library opts in to Sv48 support by
> >> passing a nonzero hint, it will lose the benefits of ASLR.
> >
> > sv48 is default. However your statement stands for opting into sv57.
> > If they always pass the same hint address, only the first address will
> > be deterministic though, correct?
> 
> I think this is correct.
> 
> >> 
> >> Allowing applications to opt in to a VA space smaller than the
> >> architectural minimum seems like an independently useful feature.
> >> Is there a reason to only add it for riscv64?
> >> 
> >
> > If there is interest, it can be added to other architectures as well.
> 
> I meant as opposed to riscv32.

That is a good point. I can include rv32 as well.

- Charlie

> 
> -s
> 
> > - Charlie
> >
> >> -s
> >> 
> >> > Signed-off-by: Charlie Jenkins <charlie@rivosinc.com>
> >> > ---
> >> > Charlie Jenkins (3):
> >> >       riscv: mm: Use hint address in mmap if available
> >> >       selftests: riscv: Generalize mm selftests
> >> >       docs: riscv: Define behavior of mmap
> >> >
> >> >  Documentation/arch/riscv/vm-layout.rst           | 16 ++--
> >> >  arch/riscv/include/asm/processor.h               | 21 ++----
> >> >  tools/testing/selftests/riscv/mm/mmap_bottomup.c | 20 +----
> >> >  tools/testing/selftests/riscv/mm/mmap_default.c  | 20 +----
> >> >  tools/testing/selftests/riscv/mm/mmap_test.h     | 93 +++++++++++++-----------
> >> >  5 files changed, 66 insertions(+), 104 deletions(-)
> >> > ---
> >> > base-commit: 556e2d17cae620d549c5474b1ece053430cd50bc
> >> > change-id: 20240119-use_mmap_hint_address-f9f4b1b6f5f1
> >> > -- 
> >> > - Charlie
> >> >
> >> >
> >> > _______________________________________________
> >> > linux-riscv mailing list
> >> > linux-riscv@lists.infradead.org
> >> > http://lists.infradead.org/mailman/listinfo/linux-riscv
> >
> > _______________________________________________
> > linux-riscv mailing list
> > linux-riscv@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/linux-riscv