2021-10-27 11:20:51

by Palmer Dabbelt

[permalink] [raw]
Subject: [PATCH] RISC-V: Make CONFIG_RELOCATABLE user selectable

From: Palmer Dabbelt <[email protected]>

This should really be up to the user, as it trades off portability for
performance.

Signed-off-by: Palmer Dabbelt <[email protected]>
---
arch/riscv/Kconfig | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index 5dea03549493..f8a36034d54b 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -212,18 +212,6 @@ config PGTABLE_LEVELS
config LOCKDEP_SUPPORT
def_bool y

-config RELOCATABLE
- bool
- depends on MMU && 64BIT && !XIP_KERNEL
- help
- This builds a kernel as a Position Independent Executable (PIE),
- which retains all relocation metadata required to relocate the
- kernel binary at runtime to a different virtual address than the
- address it was linked at.
- Since RISCV uses the RELA relocation format, this requires a
- relocation pass at runtime even if the kernel is loaded at the
- same address it was linked at.
-
source "arch/riscv/Kconfig.socs"
source "arch/riscv/Kconfig.erratas"

@@ -433,6 +421,18 @@ config CRASH_DUMP

For more details see Documentation/admin-guide/kdump/kdump.rst

+config RELOCATABLE
+ bool "Build a relocatable kernel"
+ depends on MMU && 64BIT && !XIP_KERNEL
+ help
+ This builds a kernel as a Position Independent Executable (PIE),
+ which retains all relocation metadata required to relocate the
+ kernel binary at runtime to a different virtual address than the
+ address it was linked at.
+ Since RISCV uses the RELA relocation format, this requires a
+ relocation pass at runtime even if the kernel is loaded at the
+ same address it was linked at.
+
endmenu

menu "Boot options"
--
2.33.0.1079.g6e70778dc9-goog


2021-10-27 17:30:39

by Alexandre Ghiti

[permalink] [raw]
Subject: Re: [PATCH] RISC-V: Make CONFIG_RELOCATABLE user selectable

Hi Palmer,

On 10/26/21 11:28 PM, Palmer Dabbelt wrote:
> From: Palmer Dabbelt <[email protected]>
>
> This should really be up to the user, as it trades off portability for
> performance.
>
> Signed-off-by: Palmer Dabbelt <[email protected]>
> ---
> arch/riscv/Kconfig | 24 ++++++++++++------------
> 1 file changed, 12 insertions(+), 12 deletions(-)
>
> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> index 5dea03549493..f8a36034d54b 100644
> --- a/arch/riscv/Kconfig
> +++ b/arch/riscv/Kconfig
> @@ -212,18 +212,6 @@ config PGTABLE_LEVELS
> config LOCKDEP_SUPPORT
> def_bool y
>
> -config RELOCATABLE
> - bool
> - depends on MMU && 64BIT && !XIP_KERNEL
> - help
> - This builds a kernel as a Position Independent Executable (PIE),
> - which retains all relocation metadata required to relocate the
> - kernel binary at runtime to a different virtual address than the
> - address it was linked at.
> - Since RISCV uses the RELA relocation format, this requires a
> - relocation pass at runtime even if the kernel is loaded at the
> - same address it was linked at.
> -
> source "arch/riscv/Kconfig.socs"
> source "arch/riscv/Kconfig.erratas"
>
> @@ -433,6 +421,18 @@ config CRASH_DUMP
>
> For more details see Documentation/admin-guide/kdump/kdump.rst
>
> +config RELOCATABLE
> + bool "Build a relocatable kernel"
> + depends on MMU && 64BIT && !XIP_KERNEL
> + help
> + This builds a kernel as a Position Independent Executable (PIE),
> + which retains all relocation metadata required to relocate the
> + kernel binary at runtime to a different virtual address than the
> + address it was linked at.
> + Since RISCV uses the RELA relocation format, this requires a
> + relocation pass at runtime even if the kernel is loaded at the
> + same address it was linked at.
> +
> endmenu
>
> menu "Boot options"


Agreed, you can add:

Reviewed-by: Alexandre Ghiti <[email protected]>

Thanks for the patch,

Alex

2021-10-27 20:52:32

by Andreas Schwab

[permalink] [raw]
Subject: Re: [PATCH] RISC-V: Make CONFIG_RELOCATABLE user selectable

On Okt 26 2021, Palmer Dabbelt wrote:

> +config RELOCATABLE
> + bool "Build a relocatable kernel"
> + depends on MMU && 64BIT && !XIP_KERNEL
> + help
> + This builds a kernel as a Position Independent Executable (PIE),
> + which retains all relocation metadata required to relocate the
> + kernel binary at runtime to a different virtual address than the
> + address it was linked at.
> + Since RISCV uses the RELA relocation format, this requires a
> + relocation pass at runtime even if the kernel is loaded at the
> + same address it was linked at.

When in doubt, do what?

Andreas.

--
Andreas Schwab, [email protected]
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."

2021-10-27 21:20:44

by Alexandre Ghiti

[permalink] [raw]
Subject: Re: [PATCH] RISC-V: Make CONFIG_RELOCATABLE user selectable

On Wed, Oct 27, 2021 at 10:03 AM Andreas Schwab <[email protected]> wrote:
>
> On Okt 26 2021, Palmer Dabbelt wrote:
>
> > +config RELOCATABLE
> > + bool "Build a relocatable kernel"
> > + depends on MMU && 64BIT && !XIP_KERNEL
> > + help
> > + This builds a kernel as a Position Independent Executable (PIE),
> > + which retains all relocation metadata required to relocate the
> > + kernel binary at runtime to a different virtual address than the
> > + address it was linked at.
> > + Since RISCV uses the RELA relocation format, this requires a
> > + relocation pass at runtime even if the kernel is loaded at the
> > + same address it was linked at.
>
> When in doubt, do what?

Then do not enable. it will be automatically selected by other configs
like KASLR, but otherwise you should not say yes since you'll just
have an identical slightly slower kernel.

But I imagine you mean adding a default value for this config? That
sounds right and it should be "default n".

Alex

>
> Andreas.
>
> --
> Andreas Schwab, [email protected]
> GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
> "And now for something completely different."
>
> _______________________________________________
> linux-riscv mailing list
> [email protected]
> http://lists.infradead.org/mailman/listinfo/linux-riscv

2021-10-27 21:22:05

by Andreas Schwab

[permalink] [raw]
Subject: Re: [PATCH] RISC-V: Make CONFIG_RELOCATABLE user selectable

On Okt 27 2021, Alexandre Ghiti wrote:

> On Wed, Oct 27, 2021 at 10:03 AM Andreas Schwab <[email protected]> wrote:
>>
>> On Okt 26 2021, Palmer Dabbelt wrote:
>>
>> > +config RELOCATABLE
>> > + bool "Build a relocatable kernel"
>> > + depends on MMU && 64BIT && !XIP_KERNEL
>> > + help
>> > + This builds a kernel as a Position Independent Executable (PIE),
>> > + which retains all relocation metadata required to relocate the
>> > + kernel binary at runtime to a different virtual address than the
>> > + address it was linked at.
>> > + Since RISCV uses the RELA relocation format, this requires a
>> > + relocation pass at runtime even if the kernel is loaded at the
>> > + same address it was linked at.
>>
>> When in doubt, do what?
>
> Then do not enable.

Please add that to the help string.

Andreas.

--
Andreas Schwab, [email protected]
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."

2021-10-27 23:11:20

by Palmer Dabbelt

[permalink] [raw]
Subject: Re: [PATCH] RISC-V: Make CONFIG_RELOCATABLE user selectable

On Wed, 27 Oct 2021 02:45:27 PDT (-0700), [email protected] wrote:
> On Okt 27 2021, Alexandre Ghiti wrote:
>
>> On Wed, Oct 27, 2021 at 10:03 AM Andreas Schwab <[email protected]> wrote:
>>>
>>> On Okt 26 2021, Palmer Dabbelt wrote:
>>>
>>> > +config RELOCATABLE
>>> > + bool "Build a relocatable kernel"
>>> > + depends on MMU && 64BIT && !XIP_KERNEL
>>> > + help
>>> > + This builds a kernel as a Position Independent Executable (PIE),
>>> > + which retains all relocation metadata required to relocate the
>>> > + kernel binary at runtime to a different virtual address than the
>>> > + address it was linked at.
>>> > + Since RISCV uses the RELA relocation format, this requires a
>>> > + relocation pass at runtime even if the kernel is loaded at the
>>> > + same address it was linked at.
>>>
>>> When in doubt, do what?
>>
>> Then do not enable.
>
> Please add that to the help string.

Thanks, I forgot about that. I've added it, but this is still a bit in
flux so I'm not going to send a v2 right now (it's on top of Alex's
other patches and should probably be squashed in, anyway).