Re: [Xen-devel] [PATCH v5 09/14] jump_label: port __jump_table to linker tables

2017-01-03 Thread Luis R. Rodriguez
On Thu, Dec 22, 2016 at 04:08:22PM +0200, Andy Shevchenko wrote:
> On Wed, 2016-12-21 at 18:38 -0800, Luis R. Rodriguez wrote:
> > Move the __jump_table from the a custom section solution
> > to a generic solution, this avoiding extra vmlinux.lds.h
> > customizations.
> > 
> > This also demos the use of the .data linker table and of
> > the shared asm call push_section_tbl().
> > 
> 
> >  {
> >     asm_volatile_goto("1:\n\t"
> >      WASM(nop) "\n\t"
> > -    ".pushsection __jump_table,  \"aw\"\n\t"
> > +    push_section_tbl_any(.data, __jump_table, aw)
> >      ".word 1b, %l[l_yes], %c0\n\t"
> >      ".popsection\n\t"
> >      : :  "i" (&((char *)key)[branch]) :  : l_yes);
> > @@ -26,7 +28,7 @@ static __always_inline bool
> > arch_static_branch_jump(struct static_key *key, bool
> >  {
> >     asm_volatile_goto("1:\n\t"
> >      WASM(b) " %l[l_yes]\n\t"
> > -    ".pushsection __jump_table,  \"aw\"\n\t"
> > +    push_section_tbl_any(.data, __jump_table, aw)
> >      ".word 1b, %l[l_yes], %c0\n\t"
> >      ".popsection\n\t"
> 
> Does it make sense to introduce something like
> 
> #define pop_section_tbl ".popsection\n\t"
> #define pop_section_tbl_any pop_section_tbl

Absolutely ! However this would be an evolution, and I would much
prefer to add this later as an atomic step later to enable other
users to also be using this shared macro. I did not have an immediate
need for a pop_section_tbl() macro as its not section specific.

  Luis

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


Re: [Xen-devel] [PATCH v5 09/14] jump_label: port __jump_table to linker tables

2016-12-22 Thread Andy Shevchenko
On Wed, 2016-12-21 at 18:38 -0800, Luis R. Rodriguez wrote:
> Move the __jump_table from the a custom section solution
> to a generic solution, this avoiding extra vmlinux.lds.h
> customizations.
> 
> This also demos the use of the .data linker table and of
> the shared asm call push_section_tbl().
> 

>  {
>   asm_volatile_goto("1:\n\t"
>    WASM(nop) "\n\t"
> -  ".pushsection __jump_table,  \"aw\"\n\t"
> +  push_section_tbl_any(.data, __jump_table, aw)
>    ".word 1b, %l[l_yes], %c0\n\t"
>    ".popsection\n\t"
>    : :  "i" (&((char *)key)[branch]) :  : l_yes);
> @@ -26,7 +28,7 @@ static __always_inline bool
> arch_static_branch_jump(struct static_key *key, bool
>  {
>   asm_volatile_goto("1:\n\t"
>    WASM(b) " %l[l_yes]\n\t"
> -  ".pushsection __jump_table,  \"aw\"\n\t"
> +  push_section_tbl_any(.data, __jump_table, aw)
>    ".word 1b, %l[l_yes], %c0\n\t"
>    ".popsection\n\t"

Does it make sense to introduce something like

#define pop_section_tbl ".popsection\n\t"
#define pop_section_tbl_any pop_section_tbl

?

-- 
Andy Shevchenko 
Intel Finland Oy

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v5 09/14] jump_label: port __jump_table to linker tables

2016-12-21 Thread Luis R. Rodriguez
Move the __jump_table from the a custom section solution
to a generic solution, this avoiding extra vmlinux.lds.h
customizations.

This also demos the use of the .data linker table and of
the shared asm call push_section_tbl().

Built-in kernel functionality was tested with CONFIG_STATIC_KEYS_SELFTEST.
Moduler  kernel functionality was tested with CONFIG_TEST_STATIC_KEYS.
Both work as expected.

Since __jump_table sections are also supported per
module this also required expanding module-common.lds.S
to capture and fold all .data.tlb.__jump_table.* onto
the the section __jump_table -- in this case for modules
need to keep a reference in place, given the alternative
is to use DEFINE_LINKTABLE(struct jump_entry, __jump_table)
per module -- and later through macro hacks instantiate
the jump entries per module upon init. This is doable but
we'd loose out on the sorting of the table using the
linker, to sort we'd always still need to expand the
module common linker script. An alternative mechanism
is possible which would make these custom module sections
extensions dynamic without requiring manual changes, this
however is best done later through a separate evolution
once linker tables are in place.

A careful reviewer may note that some architectures use
"\n\t" to separate asm code, while others just use a new line.
Upon review last time it was deemed reasonable to for all
architectures to just use "\n", this is defined as ASM_CMD_SEP,
and if an architecture needs to override they can do so on their
architecture sections.h prior to including asm-generic/sections.h

v5:

o Use ..tbl instead of .tbl as suggested by Nicholas Piggin.
  This is the typical way to avoid clash with compiler generated
  section.

o Replace section macros with section names

o Use LINKTABLE_START() and LINKTABLE_END()

o fixed tile jump label port -- tile got jump label support as of commit
  65a792e84f25d1 ("tile/jump_label: add jump label support for TILE-Gx"),
  as such we just needed to adjust the asm to account for the new
  linker table API use. This commit was merged as of v4.5-rc1.

v4:

o Some architectures allow linker scripts to follow including header
  files, some others do not, so if you need a helper on a linker script
  you need to explicitly include it. So for instance although
  scripts/module-common.lds.S includes  and this file
  includes , you still need to explicitly
  include it on the linker script. This issue is present on ARM.

o as per Josh Poimboeuf open code the section table name instead
  of including the kernel section headers, the simplicity and
  independence from the kernel is preferred.

v3:

o More elaborate tests performed
o first modular support use case, module tested was
  CONFIG_TEST_STATIC_KEYS (lib/test_static_keys.ko), this
  required us to extend module-common.lds.S
o use generic push_section_tbl_any() for all architectures
o Makes use of ASM_CMD_SEP to enable architectures to override later
  if needed
o guard tables.h inclusion and table definition with __KERNEL__

v2: introduced in this series

Signed-off-by: Luis R. Rodriguez 
---
 arch/arm/include/asm/jump_label.h |  6 --
 arch/arm64/include/asm/jump_label.h   |  6 --
 arch/mips/include/asm/jump_label.h|  6 --
 arch/powerpc/include/asm/jump_label.h |  8 +---
 arch/s390/include/asm/jump_label.h|  6 --
 arch/sparc/include/asm/jump_label.h   |  6 --
 arch/tile/include/asm/jump_label.h|  5 +++--
 arch/x86/include/asm/jump_label.h | 10 ++
 include/asm-generic/vmlinux.lds.h |  5 -
 include/linux/jump_label.h|  4 ++--
 kernel/jump_label.c   | 17 ++---
 scripts/module-common.lds |  1 +
 tools/objtool/special.c   |  2 +-
 13 files changed, 48 insertions(+), 34 deletions(-)

diff --git a/arch/arm/include/asm/jump_label.h 
b/arch/arm/include/asm/jump_label.h
index 34f7b6980d21..609e0592a942 100644
--- a/arch/arm/include/asm/jump_label.h
+++ b/arch/arm/include/asm/jump_label.h
@@ -1,6 +1,8 @@
 #ifndef _ASM_ARM_JUMP_LABEL_H
 #define _ASM_ARM_JUMP_LABEL_H
 
+#include 
+
 #ifndef __ASSEMBLY__
 
 #include 
@@ -12,7 +14,7 @@ static __always_inline bool arch_static_branch(struct 
static_key *key, bool bran
 {
asm_volatile_goto("1:\n\t"
 WASM(nop) "\n\t"
-".pushsection __jump_table,  \"aw\"\n\t"
+push_section_tbl_any(.data, __jump_table, aw)
 ".word 1b, %l[l_yes], %c0\n\t"
 ".popsection\n\t"
 : :  "i" (&((char *)key)[branch]) :  : l_yes);
@@ -26,7 +28,7 @@ static __always_inline bool arch_static_branch_jump(struct 
static_key *key, bool
 {
asm_volatile_goto("1:\n\t"
 WASM(b) " %l[l_yes]\n\t"
-".pushsection __jump_table,  \"aw\"\n\t"
+push_section_tbl_any(.data, __jump_table, aw)
 ".word 1b, %l[l_yes], %c0\n\t"