x86/build: Mark per-cpu symbols as absolute
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v2 1/1 x86/build: Mark per-cpu symbols as absolute
From: Rafael Ávila de Espíndola <[email protected]>
The kernel has many variables that it wants to have per CPU. It is similar to how each thread wants a copy of a thread local variable.
To access such variable, the code has to find the offset of that variable in the per cpu block and add it to the address of the current brock for that cpu.
Section 3.10.8 of ld.bfd's documentation states:
``` For expressions involving numbers, relative addresses and absolute addresses, ld follows these rules to evaluate terms: Other binary operations, that is, between two relative addresses not in the same section, or between a relative address and an absolute address, first convert any non-absolute term to an absolute address before applying the operator." ```
Note that ld.lld does not implement this behavior. Instead, we can explicitly mark non-absolute terms ABSOLUTE via linker script. This is no functional change for ld.bfd which coverts the term to ABSOLUTE anyways as specified above.
---
Changes from v1 -> v2: commit message updated
arch/x86/kernel/vmlinux.lds.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/vmlinux.lds.S +1 -1
@@ -401,7 +401,7 @@ SECTIONS * Per-cpu symbols which need to be offset from __per_cpu_load * for the boot processor. */ -#define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load +#define INIT_PER_CPU(x) init_per_cpu__##x = ABSOLUTE(x) + __per_cpu_load INIT_PER_CPU(gdt_page); INIT_PER_CPU(irq_stack_union);
Signature · 1 line
2.20.1.415.g653613c723-goog
Quoted 26 lines · On Wed, Dec 19, 2018 at 11:02 AM <[email protected]> wrote:
From: Rafael Ávila de Espíndola <[email protected]>
The kernel has many variables that it wants to have per CPU. It is similar to how each thread wants a copy of a thread local variable.
To access such variable, the code has to find the offset of that variable in the per cpu block and add it to the address of the current brock for that cpu.
Section 3.10.8 of ld.bfd's documentation states:
``` For expressions involving numbers, relative addresses and absolute addresses, ld follows these rules to evaluate terms: Other binary operations, that is, between two relative addresses not in the same section, or between a relative address and an absolute address, first convert any non-absolute term to an absolute address before applying the operator." ```Note that ld.lld does not implement this behavior. Instead, we can explicitly mark non-absolute terms ABSOLUTE via linker script. This is no functional change for ld.bfd which coverts the term to ABSOLUTE anyways as specified above.
Quoted 8 lines
Reported-by Dmitry Golovin <[email protected]>Tested-by Dmitry Golovin <[email protected]>Suggested-by Borislav Petkov <[email protected]>Suggested-by Michael Matz <[email protected]>Signed-off-by Tri Vo <[email protected]>Signed-off-by Nick Desaulniers <[email protected]>Signed-off-by Rafael Ávila de Espíndola <[email protected]>[nd: commit message updated as per Boris' and Michael's sugguestions]
Happy new year. Bumping for review.
Quoted 22 lines
---
Changes from v1 -> v2: commit message updatedarch/x86/kernel/vmlinux.lds.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kernel/vmlinux.lds.S +1
-2@@ -401,7 +401,7 @@ SECTIONS * Per-cpu symbols which need to be offset from __per_cpu_load * for the boot processor. */ -#define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load +#define INIT_PER_CPU(x) init_per_cpu__##x = ABSOLUTE(x) + __per_cpu_load INIT_PER_CPU(gdt_page); INIT_PER_CPU(irq_stack_union); --2.20.1.415.g653613c723-goog
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 1 line · Nick Desaulniers
Happy new year. Bumping for review.
Signature · 2 lines
Thanks, ~Nick Desaulniers