linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] x86/build: Mark per-cpu symbols as absolute
       [not found] <20181219183509.GB31643@zn.tnic>
@ 2018-12-19 19:01 ` ndesaulniers
  2019-01-08 20:52   ` Nick Desaulniers
  0 siblings, 1 reply; 3+ messages in thread
From: ndesaulniers @ 2018-12-19 19:01 UTC (permalink / raw)
  To: bp
  Cc: rafael, x86, tglx, mingo, morbo, dima, hpa, matz, Tri Vo,
	Nick Desaulniers, Brijesh Singh, Masami Hiramatsu,
	Andy Lutomirski, Joerg Roedel, Cao jin, Masahiro Yamada,
	linux-kernel

From: Rafael Ávila de Espíndola <rafael@espindo.la>

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.

Reported-by: Dmitry Golovin <dima@golovin.in>
Tested-by: Dmitry Golovin <dima@golovin.in>
Suggested-by: Borislav Petkov <bp@alien8.de>
Suggested-by: Michael Matz <matz@suse.de>
Signed-off-by: Tri Vo <trong@android.com>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Rafael Ávila de Espíndola <rafael@espindo.la>
[nd: commit message updated as per Boris' and Michael's sugguestions]
---
Changes from v1 -> v2: commit message updated

 arch/x86/kernel/vmlinux.lds.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index 0d618ee634ac..ee3b5c7d662e 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -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


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

* Re: [PATCH v2] x86/build: Mark per-cpu symbols as absolute
  2018-12-19 19:01 ` [PATCH v2] x86/build: Mark per-cpu symbols as absolute ndesaulniers
@ 2019-01-08 20:52   ` Nick Desaulniers
  2019-01-14 21:47     ` Nick Desaulniers
  0 siblings, 1 reply; 3+ messages in thread
From: Nick Desaulniers @ 2019-01-08 20:52 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Rafael Avila de Espindola, x86, Thomas Gleixner, mingo,
	Bill Wendling, Dmitry Golovin, hpa, Michael Matz, Tri Vo,
	Brijesh Singh, Masami Hiramatsu, Andy Lutomirski, Joerg Roedel,
	Cao jin, Masahiro Yamada, LKML

On Wed, Dec 19, 2018 at 11:02 AM <ndesaulniers@google.com> wrote:
>
> From: Rafael Ávila de Espíndola <rafael@espindo.la>
>
> 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.
>
> Reported-by: Dmitry Golovin <dima@golovin.in>
> Tested-by: Dmitry Golovin <dima@golovin.in>
> Suggested-by: Borislav Petkov <bp@alien8.de>
> Suggested-by: Michael Matz <matz@suse.de>
> Signed-off-by: Tri Vo <trong@android.com>
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> Signed-off-by: Rafael Ávila de Espíndola <rafael@espindo.la>
> [nd: commit message updated as per Boris' and Michael's sugguestions]

Happy new year.  Bumping for review.

> ---
> Changes from v1 -> v2: commit message updated
>
>  arch/x86/kernel/vmlinux.lds.S | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
> index 0d618ee634ac..ee3b5c7d662e 100644
> --- a/arch/x86/kernel/vmlinux.lds.S
> +++ b/arch/x86/kernel/vmlinux.lds.S
> @@ -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
>


-- 
Thanks,
~Nick Desaulniers

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

* Re: [PATCH v2] x86/build: Mark per-cpu symbols as absolute
  2019-01-08 20:52   ` Nick Desaulniers
@ 2019-01-14 21:47     ` Nick Desaulniers
  0 siblings, 0 replies; 3+ messages in thread
From: Nick Desaulniers @ 2019-01-14 21:47 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Rafael Avila de Espindola, x86, Thomas Gleixner, mingo,
	Bill Wendling, Dmitry Golovin, hpa, Michael Matz, Tri Vo,
	Brijesh Singh, Masami Hiramatsu, Andy Lutomirski, Joerg Roedel,
	Cao jin, Masahiro Yamada, LKML

On Tue, Jan 8, 2019 at 12:52 PM Nick Desaulniers
<ndesaulniers@google.com> wrote:
> Happy new year.  Bumping for review.

https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/?h=x86/build&id=d071ae09a4a1414c1433d5ae9908959a7325b0ad
Thanks!
-- 
Thanks,
~Nick Desaulniers

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

end of thread, other threads:[~2019-01-14 21:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20181219183509.GB31643@zn.tnic>
2018-12-19 19:01 ` [PATCH v2] x86/build: Mark per-cpu symbols as absolute ndesaulniers
2019-01-08 20:52   ` Nick Desaulniers
2019-01-14 21:47     ` Nick Desaulniers

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).