[tip:x86/boot] x86/e820: Use much less memory for e820/e820_saved, save up to 120k

2016-09-21 Thread tip-bot for Denys Vlasenko
Commit-ID:  1827822902cf659d60d3413fd42c7e6cbd18df4d
Gitweb: http://git.kernel.org/tip/1827822902cf659d60d3413fd42c7e6cbd18df4d
Author: Denys Vlasenko 
AuthorDate: Sun, 18 Sep 2016 20:21:25 +0200
Committer:  Ingo Molnar 
CommitDate: Wed, 21 Sep 2016 15:02:12 +0200

x86/e820: Use much less memory for e820/e820_saved, save up to 120k

The maximum size of e820 map array for EFI systems is defined as
E820_X_MAX (E820MAX + 3 * MAX_NUMNODES).

In x86_64 defconfig, this ends up with E820_X_MAX = 320, e820 and e820_saved
are 6404 bytes each.

With larger configs, for example Fedora kernels, E820_X_MAX = 3200, e820
and e820_saved are 64004 bytes each. Most of this space is wasted.
Typical machines have some 20-30 e820 areas at most.

After previous patch, e820 and e820_saved are pointers to e280 maps.

Change them to initially point to maps which are __initdata.

At the very end of kernel init, just before __init[data] sections are freed
in free_initmem(), allocate smaller blocks, copy maps there,
and change pointers.

The late switch makes sure that all functions which can be used to change
e820 maps are no longer accessible (they are all __init functions).

Run-tested.

Signed-off-by: Denys Vlasenko 
Acked-by: Thomas Gleixner 
Cc: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: H. Peter Anvin 
Cc: Josh Poimboeuf 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Yinghai Lu 
Cc: linux-kernel@vger.kernel.org
Link: http://lkml.kernel.org/r/20160918182125.21000-1-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/kernel/e820.c | 8 
 arch/x86/mm/init.c | 4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 585000c9..bb8c690 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -40,10 +40,10 @@
  * user can e.g. boot the original kernel with mem=1G while still booting the
  * next kernel with full memory.
  */
-static struct e820map initial_e820;
-static struct e820map initial_e820_saved;
-struct e820map *e820 = _e820;
-struct e820map *e820_saved = _e820_saved;
+static struct e820map initial_e820  __initdata;
+static struct e820map initial_e820_saved  __initdata;
+struct e820map *e820 __refdata = _e820;
+struct e820map *e820_saved __refdata = _e820_saved;
 
 /* For PCI or other memory-mapped resources */
 unsigned long pci_mem_start = 0xaeedbabe;
diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index 167deae..22af912 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -699,9 +699,9 @@ void free_init_pages(char *what, unsigned long begin, 
unsigned long end)
}
 }
 
-void free_initmem(void)
+void __ref free_initmem(void)
 {
-   /* e820_reallocate_tables(); - disabled for now */
+   e820_reallocate_tables();
 
free_init_pages("unused kernel",
(unsigned long)(&__init_begin),


[tip:x86/boot] x86/e820: Prepare e280 code for switch to dynamic storage

2016-09-21 Thread tip-bot for Denys Vlasenko
Commit-ID:  475339684ef19e46f4702e2d185a869a5c454688
Gitweb: http://git.kernel.org/tip/475339684ef19e46f4702e2d185a869a5c454688
Author: Denys Vlasenko 
AuthorDate: Sat, 17 Sep 2016 23:39:26 +0200
Committer:  Ingo Molnar 
CommitDate: Wed, 21 Sep 2016 15:02:12 +0200

x86/e820: Prepare e280 code for switch to dynamic storage

This patch turns e820 and e820_saved into pointers to e820 tables,
of the same size as before.

Signed-off-by: Denys Vlasenko 
Acked-by: Thomas Gleixner 
Cc: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: H. Peter Anvin 
Cc: Josh Poimboeuf 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Yinghai Lu 
Cc: linux-kernel@vger.kernel.org
Link: http://lkml.kernel.org/r/20160917213927.1787-2-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/include/asm/e820.h   |   6 +-
 arch/x86/kernel/e820.c| 125 +++---
 arch/x86/kernel/early-quirks.c|   2 +-
 arch/x86/kernel/kexec-bzimage64.c |   4 +-
 arch/x86/kernel/resource.c|   4 +-
 arch/x86/kernel/setup.c   |   8 +--
 arch/x86/kernel/tboot.c   |   8 +--
 arch/x86/mm/init.c|   2 +
 arch/x86/platform/efi/efi.c   |   2 +-
 arch/x86/xen/setup.c  |   2 +-
 10 files changed, 98 insertions(+), 65 deletions(-)

diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
index 3ab0537..476b574 100644
--- a/arch/x86/include/asm/e820.h
+++ b/arch/x86/include/asm/e820.h
@@ -10,8 +10,8 @@
 #include 
 #ifndef __ASSEMBLY__
 /* see comment in arch/x86/kernel/e820.c */
-extern struct e820map e820;
-extern struct e820map e820_saved;
+extern struct e820map *e820;
+extern struct e820map *e820_saved;
 
 extern unsigned long pci_mem_start;
 extern int e820_any_mapped(u64 start, u64 end, unsigned type);
@@ -53,6 +53,8 @@ extern void e820_reserve_resources_late(void);
 extern void setup_memory_map(void);
 extern char *default_machine_specific_memory_setup(void);
 
+extern void e820_reallocate_tables(void);
+
 /*
  * Returns true iff the specified range [s,e) is completely contained inside
  * the ISA region.
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 4d3dd9a..585000c9 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -40,8 +40,10 @@
  * user can e.g. boot the original kernel with mem=1G while still booting the
  * next kernel with full memory.
  */
-struct e820map e820;
-struct e820map e820_saved;
+static struct e820map initial_e820;
+static struct e820map initial_e820_saved;
+struct e820map *e820 = _e820;
+struct e820map *e820_saved = _e820_saved;
 
 /* For PCI or other memory-mapped resources */
 unsigned long pci_mem_start = 0xaeedbabe;
@@ -58,8 +60,8 @@ e820_any_mapped(u64 start, u64 end, unsigned type)
 {
int i;
 
-   for (i = 0; i < e820.nr_map; i++) {
-   struct e820entry *ei = [i];
+   for (i = 0; i < e820->nr_map; i++) {
+   struct e820entry *ei = >map[i];
 
if (type && ei->type != type)
continue;
@@ -81,8 +83,8 @@ int __init e820_all_mapped(u64 start, u64 end, unsigned type)
 {
int i;
 
-   for (i = 0; i < e820.nr_map; i++) {
-   struct e820entry *ei = [i];
+   for (i = 0; i < e820->nr_map; i++) {
+   struct e820entry *ei = >map[i];
 
if (type && ei->type != type)
continue;
@@ -128,7 +130,7 @@ static void __init __e820_add_region(struct e820map *e820x, 
u64 start, u64 size,
 
 void __init e820_add_region(u64 start, u64 size, int type)
 {
-   __e820_add_region(, start, size, type);
+   __e820_add_region(e820, start, size, type);
 }
 
 static void __init e820_print_type(u32 type)
@@ -164,12 +166,12 @@ void __init e820_print_map(char *who)
 {
int i;
 
-   for (i = 0; i < e820.nr_map; i++) {
+   for (i = 0; i < e820->nr_map; i++) {
printk(KERN_INFO "%s: [mem %#018Lx-%#018Lx] ", who,
-  (unsigned long long) e820.map[i].addr,
+  (unsigned long long) e820->map[i].addr,
   (unsigned long long)
-  (e820.map[i].addr + e820.map[i].size - 1));
-   e820_print_type(e820.map[i].type);
+  (e820->map[i].addr + e820->map[i].size - 1));
+   e820_print_type(e820->map[i].type);
printk(KERN_CONT "\n");
}
 }
@@ -493,13 +495,13 @@ static u64 __init __e820_update_range(struct e820map 
*e820x, u64 start,
 u64 __init e820_update_range(u64 start, u64 size, unsigned old_type,
 unsigned new_type)
 {
-   return __e820_update_range(, start, 

[tip:x86/boot] x86/e820: Use much less memory for e820/e820_saved, save up to 120k

2016-09-21 Thread tip-bot for Denys Vlasenko
Commit-ID:  1827822902cf659d60d3413fd42c7e6cbd18df4d
Gitweb: http://git.kernel.org/tip/1827822902cf659d60d3413fd42c7e6cbd18df4d
Author: Denys Vlasenko 
AuthorDate: Sun, 18 Sep 2016 20:21:25 +0200
Committer:  Ingo Molnar 
CommitDate: Wed, 21 Sep 2016 15:02:12 +0200

x86/e820: Use much less memory for e820/e820_saved, save up to 120k

The maximum size of e820 map array for EFI systems is defined as
E820_X_MAX (E820MAX + 3 * MAX_NUMNODES).

In x86_64 defconfig, this ends up with E820_X_MAX = 320, e820 and e820_saved
are 6404 bytes each.

With larger configs, for example Fedora kernels, E820_X_MAX = 3200, e820
and e820_saved are 64004 bytes each. Most of this space is wasted.
Typical machines have some 20-30 e820 areas at most.

After previous patch, e820 and e820_saved are pointers to e280 maps.

Change them to initially point to maps which are __initdata.

At the very end of kernel init, just before __init[data] sections are freed
in free_initmem(), allocate smaller blocks, copy maps there,
and change pointers.

The late switch makes sure that all functions which can be used to change
e820 maps are no longer accessible (they are all __init functions).

Run-tested.

Signed-off-by: Denys Vlasenko 
Acked-by: Thomas Gleixner 
Cc: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: H. Peter Anvin 
Cc: Josh Poimboeuf 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Yinghai Lu 
Cc: linux-kernel@vger.kernel.org
Link: http://lkml.kernel.org/r/20160918182125.21000-1-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/kernel/e820.c | 8 
 arch/x86/mm/init.c | 4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 585000c9..bb8c690 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -40,10 +40,10 @@
  * user can e.g. boot the original kernel with mem=1G while still booting the
  * next kernel with full memory.
  */
-static struct e820map initial_e820;
-static struct e820map initial_e820_saved;
-struct e820map *e820 = _e820;
-struct e820map *e820_saved = _e820_saved;
+static struct e820map initial_e820  __initdata;
+static struct e820map initial_e820_saved  __initdata;
+struct e820map *e820 __refdata = _e820;
+struct e820map *e820_saved __refdata = _e820_saved;
 
 /* For PCI or other memory-mapped resources */
 unsigned long pci_mem_start = 0xaeedbabe;
diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index 167deae..22af912 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -699,9 +699,9 @@ void free_init_pages(char *what, unsigned long begin, 
unsigned long end)
}
 }
 
-void free_initmem(void)
+void __ref free_initmem(void)
 {
-   /* e820_reallocate_tables(); - disabled for now */
+   e820_reallocate_tables();
 
free_init_pages("unused kernel",
(unsigned long)(&__init_begin),


[tip:x86/boot] x86/e820: Prepare e280 code for switch to dynamic storage

2016-09-21 Thread tip-bot for Denys Vlasenko
Commit-ID:  475339684ef19e46f4702e2d185a869a5c454688
Gitweb: http://git.kernel.org/tip/475339684ef19e46f4702e2d185a869a5c454688
Author: Denys Vlasenko 
AuthorDate: Sat, 17 Sep 2016 23:39:26 +0200
Committer:  Ingo Molnar 
CommitDate: Wed, 21 Sep 2016 15:02:12 +0200

x86/e820: Prepare e280 code for switch to dynamic storage

This patch turns e820 and e820_saved into pointers to e820 tables,
of the same size as before.

Signed-off-by: Denys Vlasenko 
Acked-by: Thomas Gleixner 
Cc: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: H. Peter Anvin 
Cc: Josh Poimboeuf 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Yinghai Lu 
Cc: linux-kernel@vger.kernel.org
Link: http://lkml.kernel.org/r/20160917213927.1787-2-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/include/asm/e820.h   |   6 +-
 arch/x86/kernel/e820.c| 125 +++---
 arch/x86/kernel/early-quirks.c|   2 +-
 arch/x86/kernel/kexec-bzimage64.c |   4 +-
 arch/x86/kernel/resource.c|   4 +-
 arch/x86/kernel/setup.c   |   8 +--
 arch/x86/kernel/tboot.c   |   8 +--
 arch/x86/mm/init.c|   2 +
 arch/x86/platform/efi/efi.c   |   2 +-
 arch/x86/xen/setup.c  |   2 +-
 10 files changed, 98 insertions(+), 65 deletions(-)

diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
index 3ab0537..476b574 100644
--- a/arch/x86/include/asm/e820.h
+++ b/arch/x86/include/asm/e820.h
@@ -10,8 +10,8 @@
 #include 
 #ifndef __ASSEMBLY__
 /* see comment in arch/x86/kernel/e820.c */
-extern struct e820map e820;
-extern struct e820map e820_saved;
+extern struct e820map *e820;
+extern struct e820map *e820_saved;
 
 extern unsigned long pci_mem_start;
 extern int e820_any_mapped(u64 start, u64 end, unsigned type);
@@ -53,6 +53,8 @@ extern void e820_reserve_resources_late(void);
 extern void setup_memory_map(void);
 extern char *default_machine_specific_memory_setup(void);
 
+extern void e820_reallocate_tables(void);
+
 /*
  * Returns true iff the specified range [s,e) is completely contained inside
  * the ISA region.
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 4d3dd9a..585000c9 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -40,8 +40,10 @@
  * user can e.g. boot the original kernel with mem=1G while still booting the
  * next kernel with full memory.
  */
-struct e820map e820;
-struct e820map e820_saved;
+static struct e820map initial_e820;
+static struct e820map initial_e820_saved;
+struct e820map *e820 = _e820;
+struct e820map *e820_saved = _e820_saved;
 
 /* For PCI or other memory-mapped resources */
 unsigned long pci_mem_start = 0xaeedbabe;
@@ -58,8 +60,8 @@ e820_any_mapped(u64 start, u64 end, unsigned type)
 {
int i;
 
-   for (i = 0; i < e820.nr_map; i++) {
-   struct e820entry *ei = [i];
+   for (i = 0; i < e820->nr_map; i++) {
+   struct e820entry *ei = >map[i];
 
if (type && ei->type != type)
continue;
@@ -81,8 +83,8 @@ int __init e820_all_mapped(u64 start, u64 end, unsigned type)
 {
int i;
 
-   for (i = 0; i < e820.nr_map; i++) {
-   struct e820entry *ei = [i];
+   for (i = 0; i < e820->nr_map; i++) {
+   struct e820entry *ei = >map[i];
 
if (type && ei->type != type)
continue;
@@ -128,7 +130,7 @@ static void __init __e820_add_region(struct e820map *e820x, 
u64 start, u64 size,
 
 void __init e820_add_region(u64 start, u64 size, int type)
 {
-   __e820_add_region(, start, size, type);
+   __e820_add_region(e820, start, size, type);
 }
 
 static void __init e820_print_type(u32 type)
@@ -164,12 +166,12 @@ void __init e820_print_map(char *who)
 {
int i;
 
-   for (i = 0; i < e820.nr_map; i++) {
+   for (i = 0; i < e820->nr_map; i++) {
printk(KERN_INFO "%s: [mem %#018Lx-%#018Lx] ", who,
-  (unsigned long long) e820.map[i].addr,
+  (unsigned long long) e820->map[i].addr,
   (unsigned long long)
-  (e820.map[i].addr + e820.map[i].size - 1));
-   e820_print_type(e820.map[i].type);
+  (e820->map[i].addr + e820->map[i].size - 1));
+   e820_print_type(e820->map[i].type);
printk(KERN_CONT "\n");
}
 }
@@ -493,13 +495,13 @@ static u64 __init __e820_update_range(struct e820map 
*e820x, u64 start,
 u64 __init e820_update_range(u64 start, u64 size, unsigned old_type,
 unsigned new_type)
 {
-   return __e820_update_range(, start, size, old_type, new_type);
+   return __e820_update_range(e820, start, size, old_type, new_type);
 }
 
 static u64 __init e820_update_range_saved(u64 start, u64 size,
  unsigned old_type, unsigned new_type)
 {
-   return 

[tip:x86/boot] x86/e820: Mark some static functions __init

2016-09-21 Thread tip-bot for Denys Vlasenko
Commit-ID:  8c2103f224216a45c1a4d7aebbc13f3e007cde34
Gitweb: http://git.kernel.org/tip/8c2103f224216a45c1a4d7aebbc13f3e007cde34
Author: Denys Vlasenko 
AuthorDate: Sat, 17 Sep 2016 23:39:25 +0200
Committer:  Ingo Molnar 
CommitDate: Wed, 21 Sep 2016 15:02:11 +0200

x86/e820: Mark some static functions __init

They are all called only from other __init functions in e820.c

Signed-off-by: Denys Vlasenko 
Acked-by: Thomas Gleixner 
Cc: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: H. Peter Anvin 
Cc: Josh Poimboeuf 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Yinghai Lu 
Cc: linux-kernel@vger.kernel.org
Link: http://lkml.kernel.org/r/20160917213927.1787-1-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/kernel/e820.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 871f186..4d3dd9a 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -802,7 +802,7 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
return e820_end_pfn(1UL << (32-PAGE_SHIFT));
 }
 
-static void early_panic(char *msg)
+static void __init early_panic(char *msg)
 {
early_printk(msg);
panic(msg);
@@ -912,7 +912,7 @@ void __init finish_e820_parsing(void)
}
 }
 
-static const char *e820_type_to_string(int e820_type)
+static const char *__init e820_type_to_string(int e820_type)
 {
switch (e820_type) {
case E820_RESERVED_KERN:
@@ -926,7 +926,7 @@ static const char *e820_type_to_string(int e820_type)
}
 }
 
-static unsigned long e820_type_to_iomem_type(int e820_type)
+static unsigned long __init e820_type_to_iomem_type(int e820_type)
 {
switch (e820_type) {
case E820_RESERVED_KERN:
@@ -942,7 +942,7 @@ static unsigned long e820_type_to_iomem_type(int e820_type)
}
 }
 
-static unsigned long e820_type_to_iores_desc(int e820_type)
+static unsigned long __init e820_type_to_iores_desc(int e820_type)
 {
switch (e820_type) {
case E820_ACPI:
@@ -961,7 +961,7 @@ static unsigned long e820_type_to_iores_desc(int e820_type)
}
 }
 
-static bool do_mark_busy(u32 type, struct resource *res)
+static bool __init do_mark_busy(u32 type, struct resource *res)
 {
/* this is the legacy bios/dos rom-shadow + mmio region */
if (res->start < (1ULL<<20))
@@ -1027,7 +1027,7 @@ void __init e820_reserve_resources(void)
 }
 
 /* How much should we pad RAM ending depending on where it is? */
-static unsigned long ram_alignment(resource_size_t pos)
+static unsigned long __init ram_alignment(resource_size_t pos)
 {
unsigned long mb = pos >> 20;
 


[tip:x86/boot] x86/e820: Mark some static functions __init

2016-09-21 Thread tip-bot for Denys Vlasenko
Commit-ID:  8c2103f224216a45c1a4d7aebbc13f3e007cde34
Gitweb: http://git.kernel.org/tip/8c2103f224216a45c1a4d7aebbc13f3e007cde34
Author: Denys Vlasenko 
AuthorDate: Sat, 17 Sep 2016 23:39:25 +0200
Committer:  Ingo Molnar 
CommitDate: Wed, 21 Sep 2016 15:02:11 +0200

x86/e820: Mark some static functions __init

They are all called only from other __init functions in e820.c

Signed-off-by: Denys Vlasenko 
Acked-by: Thomas Gleixner 
Cc: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: H. Peter Anvin 
Cc: Josh Poimboeuf 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Yinghai Lu 
Cc: linux-kernel@vger.kernel.org
Link: http://lkml.kernel.org/r/20160917213927.1787-1-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/kernel/e820.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 871f186..4d3dd9a 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -802,7 +802,7 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
return e820_end_pfn(1UL << (32-PAGE_SHIFT));
 }
 
-static void early_panic(char *msg)
+static void __init early_panic(char *msg)
 {
early_printk(msg);
panic(msg);
@@ -912,7 +912,7 @@ void __init finish_e820_parsing(void)
}
 }
 
-static const char *e820_type_to_string(int e820_type)
+static const char *__init e820_type_to_string(int e820_type)
 {
switch (e820_type) {
case E820_RESERVED_KERN:
@@ -926,7 +926,7 @@ static const char *e820_type_to_string(int e820_type)
}
 }
 
-static unsigned long e820_type_to_iomem_type(int e820_type)
+static unsigned long __init e820_type_to_iomem_type(int e820_type)
 {
switch (e820_type) {
case E820_RESERVED_KERN:
@@ -942,7 +942,7 @@ static unsigned long e820_type_to_iomem_type(int e820_type)
}
 }
 
-static unsigned long e820_type_to_iores_desc(int e820_type)
+static unsigned long __init e820_type_to_iores_desc(int e820_type)
 {
switch (e820_type) {
case E820_ACPI:
@@ -961,7 +961,7 @@ static unsigned long e820_type_to_iores_desc(int e820_type)
}
 }
 
-static bool do_mark_busy(u32 type, struct resource *res)
+static bool __init do_mark_busy(u32 type, struct resource *res)
 {
/* this is the legacy bios/dos rom-shadow + mmio region */
if (res->start < (1ULL<<20))
@@ -1027,7 +1027,7 @@ void __init e820_reserve_resources(void)
 }
 
 /* How much should we pad RAM ending depending on where it is? */
-static unsigned long ram_alignment(resource_size_t pos)
+static unsigned long __init ram_alignment(resource_size_t pos)
 {
unsigned long mb = pos >> 20;
 


[tip:x86/apic] x86/apic: Get rid of apic_version[] array

2016-09-19 Thread tip-bot for Denys Vlasenko
Commit-ID:  cff9ab2b291e64259d97add48fe073c081afe4e2
Gitweb: http://git.kernel.org/tip/cff9ab2b291e64259d97add48fe073c081afe4e2
Author: Denys Vlasenko 
AuthorDate: Tue, 13 Sep 2016 20:12:32 +0200
Committer:  Thomas Gleixner 
CommitDate: Tue, 20 Sep 2016 00:31:19 +0200

x86/apic: Get rid of apic_version[] array

The array has a size of MAX_LOCAL_APIC, which can be as large as 32k, so it
can consume up to 128k.

The array has been there forever and was never used for anything useful
other than a version mismatch check which was introduced in 2009.

There is no reason to store the version in an array. The kernel is not
prepared to handle different APIC versions anyway, so the real important
part is to detect a version mismatch and warn about it, which can be done
with a single variable as well.

[ tglx: Massaged changelog ]

Signed-off-by: Denys Vlasenko 
CC: Andy Lutomirski 
CC: Borislav Petkov 
CC: Brian Gerst 
CC: Mike Travis 
Link: http://lkml.kernel.org/r/20160913181232.30815-1-dvlas...@redhat.com
Signed-off-by: Thomas Gleixner 

---
 arch/x86/include/asm/mpspec.h   |  2 +-
 arch/x86/kernel/acpi/boot.c |  2 +-
 arch/x86/kernel/apic/apic.c | 17 +++--
 arch/x86/kernel/apic/io_apic.c  |  4 ++--
 arch/x86/kernel/apic/probe_32.c |  2 +-
 arch/x86/kernel/smpboot.c   | 10 +-
 6 files changed, 17 insertions(+), 20 deletions(-)

diff --git a/arch/x86/include/asm/mpspec.h b/arch/x86/include/asm/mpspec.h
index b07233b..c2f94dc 100644
--- a/arch/x86/include/asm/mpspec.h
+++ b/arch/x86/include/asm/mpspec.h
@@ -6,7 +6,6 @@
 #include 
 #include 
 
-extern int apic_version[];
 extern int pic_mode;
 
 #ifdef CONFIG_X86_32
@@ -40,6 +39,7 @@ extern int mp_bus_id_to_type[MAX_MP_BUSSES];
 extern DECLARE_BITMAP(mp_bus_not_pci, MAX_MP_BUSSES);
 
 extern unsigned int boot_cpu_physical_apicid;
+extern u8 boot_cpu_apic_version;
 extern unsigned long mp_lapic_addr;
 
 #ifdef CONFIG_X86_LOCAL_APIC
diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
index 1ad5fe2..0447e31 100644
--- a/arch/x86/kernel/acpi/boot.c
+++ b/arch/x86/kernel/acpi/boot.c
@@ -182,7 +182,7 @@ static int acpi_register_lapic(int id, u32 acpiid, u8 
enabled)
}
 
if (boot_cpu_physical_apicid != -1U)
-   ver = apic_version[boot_cpu_physical_apicid];
+   ver = boot_cpu_apic_version;
 
cpu = generic_processor_info(id, ver);
if (cpu >= 0)
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 1cbae30..779dae5 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -64,6 +64,8 @@ unsigned disabled_cpus;
 unsigned int boot_cpu_physical_apicid = -1U;
 EXPORT_SYMBOL_GPL(boot_cpu_physical_apicid);
 
+u8 boot_cpu_apic_version;
+
 /*
  * The highest APIC ID seen during enumeration.
  */
@@ -1812,8 +1814,7 @@ void __init init_apic_mappings(void)
 * since smp_sanity_check is prepared for such a case
 * and disable smp mode
 */
-   apic_version[new_apicid] =
-GET_APIC_VERSION(apic_read(APIC_LVR));
+   boot_cpu_apic_version = GET_APIC_VERSION(apic_read(APIC_LVR));
}
 }
 
@@ -1828,13 +1829,10 @@ void __init register_lapic_address(unsigned long 
address)
}
if (boot_cpu_physical_apicid == -1U) {
boot_cpu_physical_apicid  = read_apic_id();
-   apic_version[boot_cpu_physical_apicid] =
-GET_APIC_VERSION(apic_read(APIC_LVR));
+   boot_cpu_apic_version = GET_APIC_VERSION(apic_read(APIC_LVR));
}
 }
 
-int apic_version[MAX_LOCAL_APIC];
-
 /*
  * Local APIC interrupts
  */
@@ -2124,11 +2122,10 @@ int generic_processor_info(int apicid, int version)
   cpu, apicid);
version = 0x10;
}
-   apic_version[apicid] = version;
 
-   if (version != apic_version[boot_cpu_physical_apicid]) {
+   if (version != boot_cpu_apic_version) {
pr_warning("BIOS bug: APIC version mismatch, boot CPU: %x, CPU 
%d: version %x\n",
-   apic_version[boot_cpu_physical_apicid], cpu, version);
+   boot_cpu_apic_version, cpu, version);
}
 
physid_set(apicid, phys_cpu_present_map);
@@ -2271,7 +2268,7 @@ int __init APIC_init_uniprocessor(void)
 * Complain if the BIOS pretends there is one.
 */
if (!boot_cpu_has(X86_FEATURE_APIC) &&
-   APIC_INTEGRATED(apic_version[boot_cpu_physical_apicid])) {
+   APIC_INTEGRATED(boot_cpu_apic_version)) {
pr_err("BIOS bug, local APIC 0x%x not detected!...\n",
boot_cpu_physical_apicid);
return -1;
diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c

[tip:x86/apic] x86/apic: Get rid of apic_version[] array

2016-09-19 Thread tip-bot for Denys Vlasenko
Commit-ID:  cff9ab2b291e64259d97add48fe073c081afe4e2
Gitweb: http://git.kernel.org/tip/cff9ab2b291e64259d97add48fe073c081afe4e2
Author: Denys Vlasenko 
AuthorDate: Tue, 13 Sep 2016 20:12:32 +0200
Committer:  Thomas Gleixner 
CommitDate: Tue, 20 Sep 2016 00:31:19 +0200

x86/apic: Get rid of apic_version[] array

The array has a size of MAX_LOCAL_APIC, which can be as large as 32k, so it
can consume up to 128k.

The array has been there forever and was never used for anything useful
other than a version mismatch check which was introduced in 2009.

There is no reason to store the version in an array. The kernel is not
prepared to handle different APIC versions anyway, so the real important
part is to detect a version mismatch and warn about it, which can be done
with a single variable as well.

[ tglx: Massaged changelog ]

Signed-off-by: Denys Vlasenko 
CC: Andy Lutomirski 
CC: Borislav Petkov 
CC: Brian Gerst 
CC: Mike Travis 
Link: http://lkml.kernel.org/r/20160913181232.30815-1-dvlas...@redhat.com
Signed-off-by: Thomas Gleixner 

---
 arch/x86/include/asm/mpspec.h   |  2 +-
 arch/x86/kernel/acpi/boot.c |  2 +-
 arch/x86/kernel/apic/apic.c | 17 +++--
 arch/x86/kernel/apic/io_apic.c  |  4 ++--
 arch/x86/kernel/apic/probe_32.c |  2 +-
 arch/x86/kernel/smpboot.c   | 10 +-
 6 files changed, 17 insertions(+), 20 deletions(-)

diff --git a/arch/x86/include/asm/mpspec.h b/arch/x86/include/asm/mpspec.h
index b07233b..c2f94dc 100644
--- a/arch/x86/include/asm/mpspec.h
+++ b/arch/x86/include/asm/mpspec.h
@@ -6,7 +6,6 @@
 #include 
 #include 
 
-extern int apic_version[];
 extern int pic_mode;
 
 #ifdef CONFIG_X86_32
@@ -40,6 +39,7 @@ extern int mp_bus_id_to_type[MAX_MP_BUSSES];
 extern DECLARE_BITMAP(mp_bus_not_pci, MAX_MP_BUSSES);
 
 extern unsigned int boot_cpu_physical_apicid;
+extern u8 boot_cpu_apic_version;
 extern unsigned long mp_lapic_addr;
 
 #ifdef CONFIG_X86_LOCAL_APIC
diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
index 1ad5fe2..0447e31 100644
--- a/arch/x86/kernel/acpi/boot.c
+++ b/arch/x86/kernel/acpi/boot.c
@@ -182,7 +182,7 @@ static int acpi_register_lapic(int id, u32 acpiid, u8 
enabled)
}
 
if (boot_cpu_physical_apicid != -1U)
-   ver = apic_version[boot_cpu_physical_apicid];
+   ver = boot_cpu_apic_version;
 
cpu = generic_processor_info(id, ver);
if (cpu >= 0)
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 1cbae30..779dae5 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -64,6 +64,8 @@ unsigned disabled_cpus;
 unsigned int boot_cpu_physical_apicid = -1U;
 EXPORT_SYMBOL_GPL(boot_cpu_physical_apicid);
 
+u8 boot_cpu_apic_version;
+
 /*
  * The highest APIC ID seen during enumeration.
  */
@@ -1812,8 +1814,7 @@ void __init init_apic_mappings(void)
 * since smp_sanity_check is prepared for such a case
 * and disable smp mode
 */
-   apic_version[new_apicid] =
-GET_APIC_VERSION(apic_read(APIC_LVR));
+   boot_cpu_apic_version = GET_APIC_VERSION(apic_read(APIC_LVR));
}
 }
 
@@ -1828,13 +1829,10 @@ void __init register_lapic_address(unsigned long 
address)
}
if (boot_cpu_physical_apicid == -1U) {
boot_cpu_physical_apicid  = read_apic_id();
-   apic_version[boot_cpu_physical_apicid] =
-GET_APIC_VERSION(apic_read(APIC_LVR));
+   boot_cpu_apic_version = GET_APIC_VERSION(apic_read(APIC_LVR));
}
 }
 
-int apic_version[MAX_LOCAL_APIC];
-
 /*
  * Local APIC interrupts
  */
@@ -2124,11 +2122,10 @@ int generic_processor_info(int apicid, int version)
   cpu, apicid);
version = 0x10;
}
-   apic_version[apicid] = version;
 
-   if (version != apic_version[boot_cpu_physical_apicid]) {
+   if (version != boot_cpu_apic_version) {
pr_warning("BIOS bug: APIC version mismatch, boot CPU: %x, CPU 
%d: version %x\n",
-   apic_version[boot_cpu_physical_apicid], cpu, version);
+   boot_cpu_apic_version, cpu, version);
}
 
physid_set(apicid, phys_cpu_present_map);
@@ -2271,7 +2268,7 @@ int __init APIC_init_uniprocessor(void)
 * Complain if the BIOS pretends there is one.
 */
if (!boot_cpu_has(X86_FEATURE_APIC) &&
-   APIC_INTEGRATED(apic_version[boot_cpu_physical_apicid])) {
+   APIC_INTEGRATED(boot_cpu_apic_version)) {
pr_err("BIOS bug, local APIC 0x%x not detected!...\n",
boot_cpu_physical_apicid);
return -1;
diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
index 7491f41..48e6d84 100644
--- a/arch/x86/kernel/apic/io_apic.c
+++ b/arch/x86/kernel/apic/io_apic.c
@@ -1593,7 +1593,7 @@ void __init 

[tip:perf/urgent] uprobes/x86: Fix RIP-relative handling of EVEX-encoded instructions

2016-08-12 Thread tip-bot for Denys Vlasenko
Commit-ID:  68187872c76a96ed4db7bfb064272591f02e208b
Gitweb: http://git.kernel.org/tip/68187872c76a96ed4db7bfb064272591f02e208b
Author: Denys Vlasenko 
AuthorDate: Thu, 11 Aug 2016 17:45:21 +0200
Committer:  Ingo Molnar 
CommitDate: Fri, 12 Aug 2016 08:29:24 +0200

uprobes/x86: Fix RIP-relative handling of EVEX-encoded instructions

Since instruction decoder now supports EVEX-encoded instructions, two fixes
are needed to correctly handle them in uprobes.

Extended bits for MODRM.rm field need to be sanitized just like we do it
for VEX3, to avoid encoding wrong register for register-relative access.

EVEX has _two_ extended bits: b and x. Theoretically, EVEX.x should be
ignored by the CPU (since GPRs go only up to 15, not 31), but let's be
paranoid here: proper encoding for register-relative access
should have EVEX.x = 1.

Secondly, we should fetch vex. for EVEX too.
This is now super easy because instruction decoder populates
vex_prefix.bytes[2] for all flavors of (e)vex encodings, even for VEX2.

Signed-off-by: Denys Vlasenko 
Acked-by: Masami Hiramatsu 
Acked-by: Srikar Dronamraju 
Cc: Alexander Shishkin 
Cc: Andy Lutomirski 
Cc: Arnaldo Carvalho de Melo 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: H. Peter Anvin 
Cc: Jim Keniston 
Cc: Jiri Olsa 
Cc: Josh Poimboeuf 
Cc: Linus Torvalds 
Cc: Masami Hiramatsu 
Cc: Oleg Nesterov 
Cc: Peter Zijlstra 
Cc: Stephane Eranian 
Cc: Thomas Gleixner 
Cc: Vince Weaver 
Cc: linux-kernel@vger.kernel.org
Cc:  # v4.1+
Fixes: 8a764a875fe3 ("x86/asm/decoder: Create artificial 3rd byte for 2-byte 
VEX")
Link: http://lkml.kernel.org/r/20160811154521.20469-1-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/kernel/uprobes.c | 22 +++---
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
index 6c1ff31..495c776 100644
--- a/arch/x86/kernel/uprobes.c
+++ b/arch/x86/kernel/uprobes.c
@@ -357,20 +357,22 @@ static void riprel_analyze(struct arch_uprobe *auprobe, 
struct insn *insn)
*cursor &= 0xfe;
}
/*
-* Similar treatment for VEX3 prefix.
-* TODO: add XOP/EVEX treatment when insn decoder supports them
+* Similar treatment for VEX3/EVEX prefix.
+* TODO: add XOP treatment when insn decoder supports them
 */
-   if (insn->vex_prefix.nbytes == 3) {
+   if (insn->vex_prefix.nbytes >= 3) {
/*
 * vex2: c5rLpp   (has no b bit)
 * vex3/xop: c4/8f rxbm wLpp
 * evex: 62rxbR00mm w1pp zllBVaaa
-*   (evex will need setting of both b and x since
-*   in non-sib encoding evex.x is 4th bit of MODRM.rm)
-* Setting VEX3.b (setting because it has inverted meaning):
+* Setting VEX3.b (setting because it has inverted meaning).
+* Setting EVEX.x since (in non-SIB encoding) EVEX.x
+* is the 4th bit of MODRM.rm, and needs the same treatment.
+* For VEX3-encoded insns, VEX3.x value has no effect in
+* non-SIB encoding, the change is superfluous but harmless.
 */
cursor = auprobe->insn + insn_offset_vex_prefix(insn) + 1;
-   *cursor |= 0x20;
+   *cursor |= 0x60;
}
 
/*
@@ -415,12 +417,10 @@ static void riprel_analyze(struct arch_uprobe *auprobe, 
struct insn *insn)
 
reg = MODRM_REG(insn);  /* Fetch modrm.reg */
reg2 = 0xff;/* Fetch vex. */
-   if (insn->vex_prefix.nbytes == 2)
-   reg2 = insn->vex_prefix.bytes[1];
-   else if (insn->vex_prefix.nbytes == 3)
+   if (insn->vex_prefix.nbytes)
reg2 = insn->vex_prefix.bytes[2];
/*
-* TODO: add XOP, EXEV  reading.
+* TODO: add XOP  reading.
 *
 * vex. field is in bits 6-3, bits are inverted.
 * But in 32-bit mode, high-order bit may be ignored.


[tip:perf/urgent] uprobes/x86: Fix RIP-relative handling of EVEX-encoded instructions

2016-08-12 Thread tip-bot for Denys Vlasenko
Commit-ID:  68187872c76a96ed4db7bfb064272591f02e208b
Gitweb: http://git.kernel.org/tip/68187872c76a96ed4db7bfb064272591f02e208b
Author: Denys Vlasenko 
AuthorDate: Thu, 11 Aug 2016 17:45:21 +0200
Committer:  Ingo Molnar 
CommitDate: Fri, 12 Aug 2016 08:29:24 +0200

uprobes/x86: Fix RIP-relative handling of EVEX-encoded instructions

Since instruction decoder now supports EVEX-encoded instructions, two fixes
are needed to correctly handle them in uprobes.

Extended bits for MODRM.rm field need to be sanitized just like we do it
for VEX3, to avoid encoding wrong register for register-relative access.

EVEX has _two_ extended bits: b and x. Theoretically, EVEX.x should be
ignored by the CPU (since GPRs go only up to 15, not 31), but let's be
paranoid here: proper encoding for register-relative access
should have EVEX.x = 1.

Secondly, we should fetch vex. for EVEX too.
This is now super easy because instruction decoder populates
vex_prefix.bytes[2] for all flavors of (e)vex encodings, even for VEX2.

Signed-off-by: Denys Vlasenko 
Acked-by: Masami Hiramatsu 
Acked-by: Srikar Dronamraju 
Cc: Alexander Shishkin 
Cc: Andy Lutomirski 
Cc: Arnaldo Carvalho de Melo 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: H. Peter Anvin 
Cc: Jim Keniston 
Cc: Jiri Olsa 
Cc: Josh Poimboeuf 
Cc: Linus Torvalds 
Cc: Masami Hiramatsu 
Cc: Oleg Nesterov 
Cc: Peter Zijlstra 
Cc: Stephane Eranian 
Cc: Thomas Gleixner 
Cc: Vince Weaver 
Cc: linux-kernel@vger.kernel.org
Cc:  # v4.1+
Fixes: 8a764a875fe3 ("x86/asm/decoder: Create artificial 3rd byte for 2-byte 
VEX")
Link: http://lkml.kernel.org/r/20160811154521.20469-1-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/kernel/uprobes.c | 22 +++---
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
index 6c1ff31..495c776 100644
--- a/arch/x86/kernel/uprobes.c
+++ b/arch/x86/kernel/uprobes.c
@@ -357,20 +357,22 @@ static void riprel_analyze(struct arch_uprobe *auprobe, 
struct insn *insn)
*cursor &= 0xfe;
}
/*
-* Similar treatment for VEX3 prefix.
-* TODO: add XOP/EVEX treatment when insn decoder supports them
+* Similar treatment for VEX3/EVEX prefix.
+* TODO: add XOP treatment when insn decoder supports them
 */
-   if (insn->vex_prefix.nbytes == 3) {
+   if (insn->vex_prefix.nbytes >= 3) {
/*
 * vex2: c5rLpp   (has no b bit)
 * vex3/xop: c4/8f rxbm wLpp
 * evex: 62rxbR00mm w1pp zllBVaaa
-*   (evex will need setting of both b and x since
-*   in non-sib encoding evex.x is 4th bit of MODRM.rm)
-* Setting VEX3.b (setting because it has inverted meaning):
+* Setting VEX3.b (setting because it has inverted meaning).
+* Setting EVEX.x since (in non-SIB encoding) EVEX.x
+* is the 4th bit of MODRM.rm, and needs the same treatment.
+* For VEX3-encoded insns, VEX3.x value has no effect in
+* non-SIB encoding, the change is superfluous but harmless.
 */
cursor = auprobe->insn + insn_offset_vex_prefix(insn) + 1;
-   *cursor |= 0x20;
+   *cursor |= 0x60;
}
 
/*
@@ -415,12 +417,10 @@ static void riprel_analyze(struct arch_uprobe *auprobe, 
struct insn *insn)
 
reg = MODRM_REG(insn);  /* Fetch modrm.reg */
reg2 = 0xff;/* Fetch vex. */
-   if (insn->vex_prefix.nbytes == 2)
-   reg2 = insn->vex_prefix.bytes[1];
-   else if (insn->vex_prefix.nbytes == 3)
+   if (insn->vex_prefix.nbytes)
reg2 = insn->vex_prefix.bytes[2];
/*
-* TODO: add XOP, EXEV  reading.
+* TODO: add XOP  reading.
 *
 * vex. field is in bits 6-3, bits are inverted.
 * But in 32-bit mode, high-order bit may be ignored.


[tip:x86/asm] x86/asm/entry/32: Simplify pushes of zeroed pt_regs->REGs

2016-05-03 Thread tip-bot for Denys Vlasenko
Commit-ID:  778843f934e362ed4ed734520f60a44a78a074b4
Gitweb: http://git.kernel.org/tip/778843f934e362ed4ed734520f60a44a78a074b4
Author: Denys Vlasenko 
AuthorDate: Mon, 2 May 2016 16:56:50 +0200
Committer:  Ingo Molnar 
CommitDate: Tue, 3 May 2016 08:19:40 +0200

x86/asm/entry/32: Simplify pushes of zeroed pt_regs->REGs

Use of a temporary R8 register here seems to be unnecessary.

"push %r8" is a two-byte insn (it needs REX prefix to specify R8),
"push $0" is two-byte too. It seems just using the latter would be
no worse.

Thus, code had an unnecessary "xorq %r8,%r8" insn.
It probably costs nothing in execution time here since we are probably
limited by store bandwidth at this point, but still.

Run-tested under QEMU: 32-bit calls still work:

 / # ./test_syscall_vdso32
 [RUN]  Executing 6-argument 32-bit syscall via VDSO
 [OK]   Arguments are preserved across syscall
 [NOTE] R11 has changed:00200ed7 - assuming clobbered by SYSRET insn
 [OK]   R8..R15 did not leak kernel data
 [RUN]  Executing 6-argument 32-bit syscall via INT 80
 [OK]   Arguments are preserved across syscall
 [OK]   R8..R15 did not leak kernel data
 [RUN]  Running tests under ptrace
 [RUN]  Executing 6-argument 32-bit syscall via VDSO
 [OK]   Arguments are preserved across syscall
 [NOTE] R11 has changed:00200ed7 - assuming clobbered by SYSRET insn
 [OK]   R8..R15 did not leak kernel data
 [RUN]  Executing 6-argument 32-bit syscall via INT 80
 [OK]   Arguments are preserved across syscall
 [OK]   R8..R15 did not leak kernel data

Signed-off-by: Denys Vlasenko 
Acked-by: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Frederic Weisbecker 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Cc: Thomas Gleixner 
Cc: Will Drewry 
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1462201010-16846-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/entry/entry_64_compat.S | 45 +++-
 1 file changed, 21 insertions(+), 24 deletions(-)

diff --git a/arch/x86/entry/entry_64_compat.S b/arch/x86/entry/entry_64_compat.S
index 847f2f0..e1721da 100644
--- a/arch/x86/entry/entry_64_compat.S
+++ b/arch/x86/entry/entry_64_compat.S
@@ -72,24 +72,23 @@ ENTRY(entry_SYSENTER_compat)
pushfq  /* pt_regs->flags (except IF = 0) */
orl $X86_EFLAGS_IF, (%rsp)  /* Fix saved flags */
pushq   $__USER32_CS/* pt_regs->cs */
-   xorq%r8,%r8
-   pushq   %r8 /* pt_regs->ip = 0 (placeholder) */
+   pushq   $0  /* pt_regs->ip = 0 (placeholder) */
pushq   %rax/* pt_regs->orig_ax */
pushq   %rdi/* pt_regs->di */
pushq   %rsi/* pt_regs->si */
pushq   %rdx/* pt_regs->dx */
pushq   %rcx/* pt_regs->cx */
pushq   $-ENOSYS/* pt_regs->ax */
-   pushq   %r8 /* pt_regs->r8  = 0 */
-   pushq   %r8 /* pt_regs->r9  = 0 */
-   pushq   %r8 /* pt_regs->r10 = 0 */
-   pushq   %r8 /* pt_regs->r11 = 0 */
+   pushq   $0  /* pt_regs->r8  = 0 */
+   pushq   $0  /* pt_regs->r9  = 0 */
+   pushq   $0  /* pt_regs->r10 = 0 */
+   pushq   $0  /* pt_regs->r11 = 0 */
pushq   %rbx/* pt_regs->rbx */
pushq   %rbp/* pt_regs->rbp (will be overwritten) */
-   pushq   %r8 /* pt_regs->r12 = 0 */
-   pushq   %r8 /* pt_regs->r13 = 0 */
-   pushq   %r8 /* pt_regs->r14 = 0 */
-   pushq   %r8 /* pt_regs->r15 = 0 */
+   pushq   $0  /* pt_regs->r12 = 0 */
+   pushq   $0  /* pt_regs->r13 = 0 */
+   pushq   $0  /* pt_regs->r14 = 0 */
+   pushq   $0  /* pt_regs->r15 = 0 */
cld
 
/*
@@ -205,17 +204,16 @@ ENTRY(entry_SYSCALL_compat)
pushq   %rdx/* pt_regs->dx */
pushq   %rbp/* pt_regs->cx (stashed in bp) */
pushq   $-ENOSYS/* pt_regs->ax */
-   xorq%r8,%r8
-   pushq   %r8 /* pt_regs->r8  = 0 */
-   pushq   %r8 /* pt_regs->r9  = 0 */
-   pushq   %r8 /* 

[tip:x86/asm] x86/asm/entry/32: Simplify pushes of zeroed pt_regs->REGs

2016-05-03 Thread tip-bot for Denys Vlasenko
Commit-ID:  778843f934e362ed4ed734520f60a44a78a074b4
Gitweb: http://git.kernel.org/tip/778843f934e362ed4ed734520f60a44a78a074b4
Author: Denys Vlasenko 
AuthorDate: Mon, 2 May 2016 16:56:50 +0200
Committer:  Ingo Molnar 
CommitDate: Tue, 3 May 2016 08:19:40 +0200

x86/asm/entry/32: Simplify pushes of zeroed pt_regs->REGs

Use of a temporary R8 register here seems to be unnecessary.

"push %r8" is a two-byte insn (it needs REX prefix to specify R8),
"push $0" is two-byte too. It seems just using the latter would be
no worse.

Thus, code had an unnecessary "xorq %r8,%r8" insn.
It probably costs nothing in execution time here since we are probably
limited by store bandwidth at this point, but still.

Run-tested under QEMU: 32-bit calls still work:

 / # ./test_syscall_vdso32
 [RUN]  Executing 6-argument 32-bit syscall via VDSO
 [OK]   Arguments are preserved across syscall
 [NOTE] R11 has changed:00200ed7 - assuming clobbered by SYSRET insn
 [OK]   R8..R15 did not leak kernel data
 [RUN]  Executing 6-argument 32-bit syscall via INT 80
 [OK]   Arguments are preserved across syscall
 [OK]   R8..R15 did not leak kernel data
 [RUN]  Running tests under ptrace
 [RUN]  Executing 6-argument 32-bit syscall via VDSO
 [OK]   Arguments are preserved across syscall
 [NOTE] R11 has changed:00200ed7 - assuming clobbered by SYSRET insn
 [OK]   R8..R15 did not leak kernel data
 [RUN]  Executing 6-argument 32-bit syscall via INT 80
 [OK]   Arguments are preserved across syscall
 [OK]   R8..R15 did not leak kernel data

Signed-off-by: Denys Vlasenko 
Acked-by: Andy Lutomirski 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Frederic Weisbecker 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Cc: Thomas Gleixner 
Cc: Will Drewry 
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1462201010-16846-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/entry/entry_64_compat.S | 45 +++-
 1 file changed, 21 insertions(+), 24 deletions(-)

diff --git a/arch/x86/entry/entry_64_compat.S b/arch/x86/entry/entry_64_compat.S
index 847f2f0..e1721da 100644
--- a/arch/x86/entry/entry_64_compat.S
+++ b/arch/x86/entry/entry_64_compat.S
@@ -72,24 +72,23 @@ ENTRY(entry_SYSENTER_compat)
pushfq  /* pt_regs->flags (except IF = 0) */
orl $X86_EFLAGS_IF, (%rsp)  /* Fix saved flags */
pushq   $__USER32_CS/* pt_regs->cs */
-   xorq%r8,%r8
-   pushq   %r8 /* pt_regs->ip = 0 (placeholder) */
+   pushq   $0  /* pt_regs->ip = 0 (placeholder) */
pushq   %rax/* pt_regs->orig_ax */
pushq   %rdi/* pt_regs->di */
pushq   %rsi/* pt_regs->si */
pushq   %rdx/* pt_regs->dx */
pushq   %rcx/* pt_regs->cx */
pushq   $-ENOSYS/* pt_regs->ax */
-   pushq   %r8 /* pt_regs->r8  = 0 */
-   pushq   %r8 /* pt_regs->r9  = 0 */
-   pushq   %r8 /* pt_regs->r10 = 0 */
-   pushq   %r8 /* pt_regs->r11 = 0 */
+   pushq   $0  /* pt_regs->r8  = 0 */
+   pushq   $0  /* pt_regs->r9  = 0 */
+   pushq   $0  /* pt_regs->r10 = 0 */
+   pushq   $0  /* pt_regs->r11 = 0 */
pushq   %rbx/* pt_regs->rbx */
pushq   %rbp/* pt_regs->rbp (will be overwritten) */
-   pushq   %r8 /* pt_regs->r12 = 0 */
-   pushq   %r8 /* pt_regs->r13 = 0 */
-   pushq   %r8 /* pt_regs->r14 = 0 */
-   pushq   %r8 /* pt_regs->r15 = 0 */
+   pushq   $0  /* pt_regs->r12 = 0 */
+   pushq   $0  /* pt_regs->r13 = 0 */
+   pushq   $0  /* pt_regs->r14 = 0 */
+   pushq   $0  /* pt_regs->r15 = 0 */
cld
 
/*
@@ -205,17 +204,16 @@ ENTRY(entry_SYSCALL_compat)
pushq   %rdx/* pt_regs->dx */
pushq   %rbp/* pt_regs->cx (stashed in bp) */
pushq   $-ENOSYS/* pt_regs->ax */
-   xorq%r8,%r8
-   pushq   %r8 /* pt_regs->r8  = 0 */
-   pushq   %r8 /* pt_regs->r9  = 0 */
-   pushq   %r8 /* pt_regs->r10 = 0 */
-   pushq   %r8 /* pt_regs->r11 = 0 */
+   pushq   $0  /* pt_regs->r8  = 0 */
+   pushq   $0  /* pt_regs->r9  = 0 */
+   pushq   $0  /* pt_regs->r10 = 0 */
+   pushq   $0  /* 

[tip:x86/cleanups] x86: Fix non-static inlines

2016-04-16 Thread tip-bot for Denys Vlasenko
Commit-ID:  a3819e3e71d5000c176918309284a1fa2f133fcf
Gitweb: http://git.kernel.org/tip/a3819e3e71d5000c176918309284a1fa2f133fcf
Author: Denys Vlasenko 
AuthorDate: Fri, 15 Apr 2016 19:00:26 +0200
Committer:  Ingo Molnar 
CommitDate: Sat, 16 Apr 2016 13:21:40 +0200

x86: Fix non-static inlines

Four instances of incorrect usage of non-static "inline" crept up
in arch/x86, all trivial; cleaning them up:

EVT_TO_HPET_DEV() - made static, it is only used in kernel/hpet.c

Debug version of check_iommu_entries() is an __init function.
Non-debug dummy empty version of it is declared "inline" instead -
which doesn't help to eliminate it (the caller is in a different unit,
inlining doesn't happen).
Switch to non-inlined __init function, which does eliminate it
(by discarding it as part of __init section).

crypto/sha-mb/sha1_mb.c: looks like they just forgot to add "static"
to their two internal inlines, which emitted two unused functions into
vmlinux.

  text data  bss   dec hex filename
  95903394 20860288 35991552 152755234 91adc22 vmlinux_before
  95903266 20860288 35991552 152755106 91adba2 vmlinux

Signed-off-by: Denys Vlasenko 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: H. Peter Anvin 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1460739626-12179-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/crypto/sha-mb/sha1_mb.c  | 4 ++--
 arch/x86/kernel/hpet.c| 2 +-
 arch/x86/kernel/pci-iommu_table.c | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/x86/crypto/sha-mb/sha1_mb.c b/arch/x86/crypto/sha-mb/sha1_mb.c
index a8a0224..fb9c7a8 100644
--- a/arch/x86/crypto/sha-mb/sha1_mb.c
+++ b/arch/x86/crypto/sha-mb/sha1_mb.c
@@ -102,14 +102,14 @@ static asmlinkage struct job_sha1* 
(*sha1_job_mgr_submit)(struct sha1_mb_mgr *st
 static asmlinkage struct job_sha1* (*sha1_job_mgr_flush)(struct sha1_mb_mgr 
*state);
 static asmlinkage struct job_sha1* (*sha1_job_mgr_get_comp_job)(struct 
sha1_mb_mgr *state);
 
-inline void sha1_init_digest(uint32_t *digest)
+static inline void sha1_init_digest(uint32_t *digest)
 {
static const uint32_t initial_digest[SHA1_DIGEST_LENGTH] = {SHA1_H0,
SHA1_H1, SHA1_H2, SHA1_H3, SHA1_H4 };
memcpy(digest, initial_digest, sizeof(initial_digest));
 }
 
-inline uint32_t sha1_pad(uint8_t padblock[SHA1_BLOCK_SIZE * 2],
+static inline uint32_t sha1_pad(uint8_t padblock[SHA1_BLOCK_SIZE * 2],
 uint32_t total_len)
 {
uint32_t i = total_len & (SHA1_BLOCK_SIZE - 1);
diff --git a/arch/x86/kernel/hpet.c b/arch/x86/kernel/hpet.c
index a1f0e4a..130f2b4 100644
--- a/arch/x86/kernel/hpet.c
+++ b/arch/x86/kernel/hpet.c
@@ -54,7 +54,7 @@ struct hpet_dev {
charname[10];
 };
 
-inline struct hpet_dev *EVT_TO_HPET_DEV(struct clock_event_device *evtdev)
+static inline struct hpet_dev *EVT_TO_HPET_DEV(struct clock_event_device 
*evtdev)
 {
return container_of(evtdev, struct hpet_dev, evt);
 }
diff --git a/arch/x86/kernel/pci-iommu_table.c 
b/arch/x86/kernel/pci-iommu_table.c
index 35ccf75..f712dfd 100644
--- a/arch/x86/kernel/pci-iommu_table.c
+++ b/arch/x86/kernel/pci-iommu_table.c
@@ -72,7 +72,7 @@ void __init check_iommu_entries(struct iommu_table_entry 
*start,
}
 }
 #else
-inline void check_iommu_entries(struct iommu_table_entry *start,
+void __init check_iommu_entries(struct iommu_table_entry *start,
   struct iommu_table_entry *finish)
 {
 }


[tip:x86/cleanups] x86: Fix non-static inlines

2016-04-16 Thread tip-bot for Denys Vlasenko
Commit-ID:  a3819e3e71d5000c176918309284a1fa2f133fcf
Gitweb: http://git.kernel.org/tip/a3819e3e71d5000c176918309284a1fa2f133fcf
Author: Denys Vlasenko 
AuthorDate: Fri, 15 Apr 2016 19:00:26 +0200
Committer:  Ingo Molnar 
CommitDate: Sat, 16 Apr 2016 13:21:40 +0200

x86: Fix non-static inlines

Four instances of incorrect usage of non-static "inline" crept up
in arch/x86, all trivial; cleaning them up:

EVT_TO_HPET_DEV() - made static, it is only used in kernel/hpet.c

Debug version of check_iommu_entries() is an __init function.
Non-debug dummy empty version of it is declared "inline" instead -
which doesn't help to eliminate it (the caller is in a different unit,
inlining doesn't happen).
Switch to non-inlined __init function, which does eliminate it
(by discarding it as part of __init section).

crypto/sha-mb/sha1_mb.c: looks like they just forgot to add "static"
to their two internal inlines, which emitted two unused functions into
vmlinux.

  text data  bss   dec hex filename
  95903394 20860288 35991552 152755234 91adc22 vmlinux_before
  95903266 20860288 35991552 152755106 91adba2 vmlinux

Signed-off-by: Denys Vlasenko 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: H. Peter Anvin 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1460739626-12179-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/crypto/sha-mb/sha1_mb.c  | 4 ++--
 arch/x86/kernel/hpet.c| 2 +-
 arch/x86/kernel/pci-iommu_table.c | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/x86/crypto/sha-mb/sha1_mb.c b/arch/x86/crypto/sha-mb/sha1_mb.c
index a8a0224..fb9c7a8 100644
--- a/arch/x86/crypto/sha-mb/sha1_mb.c
+++ b/arch/x86/crypto/sha-mb/sha1_mb.c
@@ -102,14 +102,14 @@ static asmlinkage struct job_sha1* 
(*sha1_job_mgr_submit)(struct sha1_mb_mgr *st
 static asmlinkage struct job_sha1* (*sha1_job_mgr_flush)(struct sha1_mb_mgr 
*state);
 static asmlinkage struct job_sha1* (*sha1_job_mgr_get_comp_job)(struct 
sha1_mb_mgr *state);
 
-inline void sha1_init_digest(uint32_t *digest)
+static inline void sha1_init_digest(uint32_t *digest)
 {
static const uint32_t initial_digest[SHA1_DIGEST_LENGTH] = {SHA1_H0,
SHA1_H1, SHA1_H2, SHA1_H3, SHA1_H4 };
memcpy(digest, initial_digest, sizeof(initial_digest));
 }
 
-inline uint32_t sha1_pad(uint8_t padblock[SHA1_BLOCK_SIZE * 2],
+static inline uint32_t sha1_pad(uint8_t padblock[SHA1_BLOCK_SIZE * 2],
 uint32_t total_len)
 {
uint32_t i = total_len & (SHA1_BLOCK_SIZE - 1);
diff --git a/arch/x86/kernel/hpet.c b/arch/x86/kernel/hpet.c
index a1f0e4a..130f2b4 100644
--- a/arch/x86/kernel/hpet.c
+++ b/arch/x86/kernel/hpet.c
@@ -54,7 +54,7 @@ struct hpet_dev {
charname[10];
 };
 
-inline struct hpet_dev *EVT_TO_HPET_DEV(struct clock_event_device *evtdev)
+static inline struct hpet_dev *EVT_TO_HPET_DEV(struct clock_event_device 
*evtdev)
 {
return container_of(evtdev, struct hpet_dev, evt);
 }
diff --git a/arch/x86/kernel/pci-iommu_table.c 
b/arch/x86/kernel/pci-iommu_table.c
index 35ccf75..f712dfd 100644
--- a/arch/x86/kernel/pci-iommu_table.c
+++ b/arch/x86/kernel/pci-iommu_table.c
@@ -72,7 +72,7 @@ void __init check_iommu_entries(struct iommu_table_entry 
*start,
}
 }
 #else
-inline void check_iommu_entries(struct iommu_table_entry *start,
+void __init check_iommu_entries(struct iommu_table_entry *start,
   struct iommu_table_entry *finish)
 {
 }


[tip:locking/core] locking/lockdep: Deinline register_lock_class(), save 2328 bytes

2016-04-13 Thread tip-bot for Denys Vlasenko
Commit-ID:  c003ed928962a55eb446e78c544b1d7c4f6cb88a
Gitweb: http://git.kernel.org/tip/c003ed928962a55eb446e78c544b1d7c4f6cb88a
Author: Denys Vlasenko 
AuthorDate: Fri, 8 Apr 2016 20:58:46 +0200
Committer:  Ingo Molnar 
CommitDate: Wed, 13 Apr 2016 10:06:13 +0200

locking/lockdep: Deinline register_lock_class(), save 2328 bytes

This function compiles to 1328 bytes of machine code. Three callsites.

Registering a new lock class is definitely not *that* time-critical to inline 
it.

Signed-off-by: Denys Vlasenko 
Cc: Andrew Morton 
Cc: Linus Torvalds 
Cc: Paul E. McKenney 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1460141926-13069-5-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 kernel/locking/lockdep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index ed94109..7cc43ef 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -708,7 +708,7 @@ look_up_lock_class(struct lockdep_map *lock, unsigned int 
subclass)
  * yet. Otherwise we look it up. We cache the result in the lock object
  * itself, so actual lookup of the hash should be once per lock object.
  */
-static inline struct lock_class *
+static struct lock_class *
 register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
 {
struct lockdep_subclass_key *key;


[tip:locking/core] locking/lockdep: Deinline register_lock_class(), save 2328 bytes

2016-04-13 Thread tip-bot for Denys Vlasenko
Commit-ID:  c003ed928962a55eb446e78c544b1d7c4f6cb88a
Gitweb: http://git.kernel.org/tip/c003ed928962a55eb446e78c544b1d7c4f6cb88a
Author: Denys Vlasenko 
AuthorDate: Fri, 8 Apr 2016 20:58:46 +0200
Committer:  Ingo Molnar 
CommitDate: Wed, 13 Apr 2016 10:06:13 +0200

locking/lockdep: Deinline register_lock_class(), save 2328 bytes

This function compiles to 1328 bytes of machine code. Three callsites.

Registering a new lock class is definitely not *that* time-critical to inline 
it.

Signed-off-by: Denys Vlasenko 
Cc: Andrew Morton 
Cc: Linus Torvalds 
Cc: Paul E. McKenney 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1460141926-13069-5-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 kernel/locking/lockdep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index ed94109..7cc43ef 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -708,7 +708,7 @@ look_up_lock_class(struct lockdep_map *lock, unsigned int 
subclass)
  * yet. Otherwise we look it up. We cache the result in the lock object
  * itself, so actual lookup of the hash should be once per lock object.
  */
-static inline struct lock_class *
+static struct lock_class *
 register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
 {
struct lockdep_subclass_key *key;


[tip:core/urgent] uapi/linux/stddef.h: Provide __always_inline to userspace headers

2016-03-30 Thread tip-bot for Denys Vlasenko
Commit-ID:  283d757378371e8044d873e661b1dccee46c5887
Gitweb: http://git.kernel.org/tip/283d757378371e8044d873e661b1dccee46c5887
Author: Denys Vlasenko 
AuthorDate: Wed, 30 Mar 2016 00:14:57 +0200
Committer:  Ingo Molnar 
CommitDate: Wed, 30 Mar 2016 12:50:17 +0200

uapi/linux/stddef.h: Provide __always_inline to userspace headers

Josh Boyer reported that my recent change to uapi/linux/swab.h broke the Qemu 
build:

  bc27fb68aaad ("include/uapi/linux/byteorder, swab: force inlining of some 
byteswap operations")

Unfortunately, UAPI headers don't include compiler.h so fixing it there is not 
enough,
add an __always_inline definition to uapi/linux/stddef.h instead.

Testcase: "make headers_install" and try to compile this:

#include 
void main() {}

Reported-by: Josh Boyer 
Signed-off-by: Denys Vlasenko 
Cc: Andrew Morton 
Cc: Arnd Bergmann 
Cc: David Rientjes 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: Thomas Graf 
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1459289697-12875-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 include/uapi/linux/stddef.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/include/uapi/linux/stddef.h b/include/uapi/linux/stddef.h
index aa9f104..621fa8a 100644
--- a/include/uapi/linux/stddef.h
+++ b/include/uapi/linux/stddef.h
@@ -1 +1,5 @@
 #include 
+
+#ifndef __always_inline
+#define __always_inline inline
+#endif


[tip:core/urgent] uapi/linux/stddef.h: Provide __always_inline to userspace headers

2016-03-30 Thread tip-bot for Denys Vlasenko
Commit-ID:  283d757378371e8044d873e661b1dccee46c5887
Gitweb: http://git.kernel.org/tip/283d757378371e8044d873e661b1dccee46c5887
Author: Denys Vlasenko 
AuthorDate: Wed, 30 Mar 2016 00:14:57 +0200
Committer:  Ingo Molnar 
CommitDate: Wed, 30 Mar 2016 12:50:17 +0200

uapi/linux/stddef.h: Provide __always_inline to userspace headers

Josh Boyer reported that my recent change to uapi/linux/swab.h broke the Qemu 
build:

  bc27fb68aaad ("include/uapi/linux/byteorder, swab: force inlining of some 
byteswap operations")

Unfortunately, UAPI headers don't include compiler.h so fixing it there is not 
enough,
add an __always_inline definition to uapi/linux/stddef.h instead.

Testcase: "make headers_install" and try to compile this:

#include 
void main() {}

Reported-by: Josh Boyer 
Signed-off-by: Denys Vlasenko 
Cc: Andrew Morton 
Cc: Arnd Bergmann 
Cc: David Rientjes 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: Thomas Graf 
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1459289697-12875-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 include/uapi/linux/stddef.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/include/uapi/linux/stddef.h b/include/uapi/linux/stddef.h
index aa9f104..621fa8a 100644
--- a/include/uapi/linux/stddef.h
+++ b/include/uapi/linux/stddef.h
@@ -1 +1,5 @@
 #include 
+
+#ifndef __always_inline
+#define __always_inline inline
+#endif


[tip:irq/core] x86/apic: Deinline _flat_send_IPI_mask, save ~150 bytes

2016-03-08 Thread tip-bot for Denys Vlasenko
Commit-ID:  fe2f95468e4bdf4a526be4f86efaefe48ca63b83
Gitweb: http://git.kernel.org/tip/fe2f95468e4bdf4a526be4f86efaefe48ca63b83
Author: Denys Vlasenko 
AuthorDate: Sun, 6 Mar 2016 19:11:16 +0100
Committer:  Ingo Molnar 
CommitDate: Tue, 8 Mar 2016 12:26:41 +0100

x86/apic: Deinline _flat_send_IPI_mask, save ~150 bytes

_flat_send_IPI_mask: 157 bytes, 3 callsites

 text data  bss   dec hex filename
 96183823 20860520 36122624 153166967 9212477 vmlinux1_before
 96183699 20860520 36122624 153166843 92123fb vmlinux

Signed-off-by: Denys Vlasenko 
Cc: Borislav Petkov 
Cc: Daniel J Blueman 
Cc: Linus Torvalds 
Cc: Mike Travis 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1457287876-6001-2-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/kernel/apic/apic_flat_64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/apic/apic_flat_64.c 
b/arch/x86/kernel/apic/apic_flat_64.c
index 9968f30..76f89e2 100644
--- a/arch/x86/kernel/apic/apic_flat_64.c
+++ b/arch/x86/kernel/apic/apic_flat_64.c
@@ -53,7 +53,7 @@ void flat_init_apic_ldr(void)
apic_write(APIC_LDR, val);
 }
 
-static inline void _flat_send_IPI_mask(unsigned long mask, int vector)
+static void _flat_send_IPI_mask(unsigned long mask, int vector)
 {
unsigned long flags;
 


[tip:irq/core] x86/apic: Deinline _flat_send_IPI_mask, save ~150 bytes

2016-03-08 Thread tip-bot for Denys Vlasenko
Commit-ID:  fe2f95468e4bdf4a526be4f86efaefe48ca63b83
Gitweb: http://git.kernel.org/tip/fe2f95468e4bdf4a526be4f86efaefe48ca63b83
Author: Denys Vlasenko 
AuthorDate: Sun, 6 Mar 2016 19:11:16 +0100
Committer:  Ingo Molnar 
CommitDate: Tue, 8 Mar 2016 12:26:41 +0100

x86/apic: Deinline _flat_send_IPI_mask, save ~150 bytes

_flat_send_IPI_mask: 157 bytes, 3 callsites

 text data  bss   dec hex filename
 96183823 20860520 36122624 153166967 9212477 vmlinux1_before
 96183699 20860520 36122624 153166843 92123fb vmlinux

Signed-off-by: Denys Vlasenko 
Cc: Borislav Petkov 
Cc: Daniel J Blueman 
Cc: Linus Torvalds 
Cc: Mike Travis 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1457287876-6001-2-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/kernel/apic/apic_flat_64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/apic/apic_flat_64.c 
b/arch/x86/kernel/apic/apic_flat_64.c
index 9968f30..76f89e2 100644
--- a/arch/x86/kernel/apic/apic_flat_64.c
+++ b/arch/x86/kernel/apic/apic_flat_64.c
@@ -53,7 +53,7 @@ void flat_init_apic_ldr(void)
apic_write(APIC_LDR, val);
 }
 
-static inline void _flat_send_IPI_mask(unsigned long mask, int vector)
+static void _flat_send_IPI_mask(unsigned long mask, int vector)
 {
unsigned long flags;
 


[tip:irq/core] x86/apic: Deinline __default_send_IPI_*, save ~200 bytes

2016-03-08 Thread tip-bot for Denys Vlasenko
Commit-ID:  1a8aa8acab4f3949e05ceb51e36f627b1651814c
Gitweb: http://git.kernel.org/tip/1a8aa8acab4f3949e05ceb51e36f627b1651814c
Author: Denys Vlasenko 
AuthorDate: Sun, 6 Mar 2016 19:11:15 +0100
Committer:  Ingo Molnar 
CommitDate: Tue, 8 Mar 2016 12:26:41 +0100

x86/apic: Deinline __default_send_IPI_*, save ~200 bytes

__default_send_IPI_shortcut: 49 bytes, 2 callsites
__default_send_IPI_dest_field: 108 bytes, 7 callsites

 text data  bss   dec hex filename
 96184086 20860488 36122624 153167198 921255e vmlinux_before
 96183823 20860520 36122624 153166967 9212477 vmlinux

Signed-off-by: Denys Vlasenko 
Cc: Borislav Petkov 
Cc: Daniel J Blueman 
Cc: Linus Torvalds 
Cc: Mike Travis 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1457287876-6001-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/include/asm/ipi.h | 58 ++--
 arch/x86/kernel/apic/ipi.c | 60 ++
 2 files changed, 62 insertions(+), 56 deletions(-)

diff --git a/arch/x86/include/asm/ipi.h b/arch/x86/include/asm/ipi.h
index cfc9a0d..a4fe16e 100644
--- a/arch/x86/include/asm/ipi.h
+++ b/arch/x86/include/asm/ipi.h
@@ -57,67 +57,13 @@ static inline void __xapic_wait_icr_idle(void)
cpu_relax();
 }
 
-static inline void
-__default_send_IPI_shortcut(unsigned int shortcut, int vector, unsigned int 
dest)
-{
-   /*
-* Subtle. In the case of the 'never do double writes' workaround
-* we have to lock out interrupts to be safe.  As we don't care
-* of the value read we use an atomic rmw access to avoid costly
-* cli/sti.  Otherwise we use an even cheaper single atomic write
-* to the APIC.
-*/
-   unsigned int cfg;
-
-   /*
-* Wait for idle.
-*/
-   __xapic_wait_icr_idle();
-
-   /*
-* No need to touch the target chip field
-*/
-   cfg = __prepare_ICR(shortcut, vector, dest);
-
-   /*
-* Send the IPI. The write to APIC_ICR fires this off.
-*/
-   native_apic_mem_write(APIC_ICR, cfg);
-}
+void __default_send_IPI_shortcut(unsigned int shortcut, int vector, unsigned 
int dest);
 
 /*
  * This is used to send an IPI with no shorthand notation (the destination is
  * specified in bits 56 to 63 of the ICR).
  */
-static inline void
- __default_send_IPI_dest_field(unsigned int mask, int vector, unsigned int 
dest)
-{
-   unsigned long cfg;
-
-   /*
-* Wait for idle.
-*/
-   if (unlikely(vector == NMI_VECTOR))
-   safe_apic_wait_icr_idle();
-   else
-   __xapic_wait_icr_idle();
-
-   /*
-* prepare target chip field
-*/
-   cfg = __prepare_ICR2(mask);
-   native_apic_mem_write(APIC_ICR2, cfg);
-
-   /*
-* program the ICR
-*/
-   cfg = __prepare_ICR(0, vector, dest);
-
-   /*
-* Send the IPI. The write to APIC_ICR fires this off.
-*/
-   native_apic_mem_write(APIC_ICR, cfg);
-}
+void __default_send_IPI_dest_field(unsigned int mask, int vector, unsigned int 
dest);
 
 extern void default_send_IPI_single(int cpu, int vector);
 extern void default_send_IPI_single_phys(int cpu, int vector);
diff --git a/arch/x86/kernel/apic/ipi.c b/arch/x86/kernel/apic/ipi.c
index eb45fc9..28bde88 100644
--- a/arch/x86/kernel/apic/ipi.c
+++ b/arch/x86/kernel/apic/ipi.c
@@ -18,6 +18,66 @@
 #include 
 #include 
 
+void __default_send_IPI_shortcut(unsigned int shortcut, int vector, unsigned 
int dest)
+{
+   /*
+* Subtle. In the case of the 'never do double writes' workaround
+* we have to lock out interrupts to be safe.  As we don't care
+* of the value read we use an atomic rmw access to avoid costly
+* cli/sti.  Otherwise we use an even cheaper single atomic write
+* to the APIC.
+*/
+   unsigned int cfg;
+
+   /*
+* Wait for idle.
+*/
+   __xapic_wait_icr_idle();
+
+   /*
+* No need to touch the target chip field
+*/
+   cfg = __prepare_ICR(shortcut, vector, dest);
+
+   /*
+* Send the IPI. The write to APIC_ICR fires this off.
+*/
+   native_apic_mem_write(APIC_ICR, cfg);
+}
+
+/*
+ * This is used to send an IPI with no shorthand notation (the destination is
+ * specified in bits 56 to 63 of the ICR).
+ */
+void __default_send_IPI_dest_field(unsigned int mask, int vector, unsigned int 
dest)
+{
+   unsigned long cfg;
+
+   /*
+* Wait for idle.
+*/
+   if (unlikely(vector == NMI_VECTOR))
+   safe_apic_wait_icr_idle();
+   else
+   

[tip:irq/core] x86/apic: Deinline __default_send_IPI_*, save ~200 bytes

2016-03-08 Thread tip-bot for Denys Vlasenko
Commit-ID:  1a8aa8acab4f3949e05ceb51e36f627b1651814c
Gitweb: http://git.kernel.org/tip/1a8aa8acab4f3949e05ceb51e36f627b1651814c
Author: Denys Vlasenko 
AuthorDate: Sun, 6 Mar 2016 19:11:15 +0100
Committer:  Ingo Molnar 
CommitDate: Tue, 8 Mar 2016 12:26:41 +0100

x86/apic: Deinline __default_send_IPI_*, save ~200 bytes

__default_send_IPI_shortcut: 49 bytes, 2 callsites
__default_send_IPI_dest_field: 108 bytes, 7 callsites

 text data  bss   dec hex filename
 96184086 20860488 36122624 153167198 921255e vmlinux_before
 96183823 20860520 36122624 153166967 9212477 vmlinux

Signed-off-by: Denys Vlasenko 
Cc: Borislav Petkov 
Cc: Daniel J Blueman 
Cc: Linus Torvalds 
Cc: Mike Travis 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1457287876-6001-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/include/asm/ipi.h | 58 ++--
 arch/x86/kernel/apic/ipi.c | 60 ++
 2 files changed, 62 insertions(+), 56 deletions(-)

diff --git a/arch/x86/include/asm/ipi.h b/arch/x86/include/asm/ipi.h
index cfc9a0d..a4fe16e 100644
--- a/arch/x86/include/asm/ipi.h
+++ b/arch/x86/include/asm/ipi.h
@@ -57,67 +57,13 @@ static inline void __xapic_wait_icr_idle(void)
cpu_relax();
 }
 
-static inline void
-__default_send_IPI_shortcut(unsigned int shortcut, int vector, unsigned int 
dest)
-{
-   /*
-* Subtle. In the case of the 'never do double writes' workaround
-* we have to lock out interrupts to be safe.  As we don't care
-* of the value read we use an atomic rmw access to avoid costly
-* cli/sti.  Otherwise we use an even cheaper single atomic write
-* to the APIC.
-*/
-   unsigned int cfg;
-
-   /*
-* Wait for idle.
-*/
-   __xapic_wait_icr_idle();
-
-   /*
-* No need to touch the target chip field
-*/
-   cfg = __prepare_ICR(shortcut, vector, dest);
-
-   /*
-* Send the IPI. The write to APIC_ICR fires this off.
-*/
-   native_apic_mem_write(APIC_ICR, cfg);
-}
+void __default_send_IPI_shortcut(unsigned int shortcut, int vector, unsigned 
int dest);
 
 /*
  * This is used to send an IPI with no shorthand notation (the destination is
  * specified in bits 56 to 63 of the ICR).
  */
-static inline void
- __default_send_IPI_dest_field(unsigned int mask, int vector, unsigned int 
dest)
-{
-   unsigned long cfg;
-
-   /*
-* Wait for idle.
-*/
-   if (unlikely(vector == NMI_VECTOR))
-   safe_apic_wait_icr_idle();
-   else
-   __xapic_wait_icr_idle();
-
-   /*
-* prepare target chip field
-*/
-   cfg = __prepare_ICR2(mask);
-   native_apic_mem_write(APIC_ICR2, cfg);
-
-   /*
-* program the ICR
-*/
-   cfg = __prepare_ICR(0, vector, dest);
-
-   /*
-* Send the IPI. The write to APIC_ICR fires this off.
-*/
-   native_apic_mem_write(APIC_ICR, cfg);
-}
+void __default_send_IPI_dest_field(unsigned int mask, int vector, unsigned int 
dest);
 
 extern void default_send_IPI_single(int cpu, int vector);
 extern void default_send_IPI_single_phys(int cpu, int vector);
diff --git a/arch/x86/kernel/apic/ipi.c b/arch/x86/kernel/apic/ipi.c
index eb45fc9..28bde88 100644
--- a/arch/x86/kernel/apic/ipi.c
+++ b/arch/x86/kernel/apic/ipi.c
@@ -18,6 +18,66 @@
 #include 
 #include 
 
+void __default_send_IPI_shortcut(unsigned int shortcut, int vector, unsigned 
int dest)
+{
+   /*
+* Subtle. In the case of the 'never do double writes' workaround
+* we have to lock out interrupts to be safe.  As we don't care
+* of the value read we use an atomic rmw access to avoid costly
+* cli/sti.  Otherwise we use an even cheaper single atomic write
+* to the APIC.
+*/
+   unsigned int cfg;
+
+   /*
+* Wait for idle.
+*/
+   __xapic_wait_icr_idle();
+
+   /*
+* No need to touch the target chip field
+*/
+   cfg = __prepare_ICR(shortcut, vector, dest);
+
+   /*
+* Send the IPI. The write to APIC_ICR fires this off.
+*/
+   native_apic_mem_write(APIC_ICR, cfg);
+}
+
+/*
+ * This is used to send an IPI with no shorthand notation (the destination is
+ * specified in bits 56 to 63 of the ICR).
+ */
+void __default_send_IPI_dest_field(unsigned int mask, int vector, unsigned int 
dest)
+{
+   unsigned long cfg;
+
+   /*
+* Wait for idle.
+*/
+   if (unlikely(vector == NMI_VECTOR))
+   safe_apic_wait_icr_idle();
+   else
+   __xapic_wait_icr_idle();
+
+   /*
+* prepare target chip field
+*/
+   cfg = __prepare_ICR2(mask);
+   native_apic_mem_write(APIC_ICR2, cfg);
+
+   /*
+* program the ICR
+ 

[tip:x86/asm] x86/asm/bitops: Force inlining of test_and_set_bit and friends

2016-02-09 Thread tip-bot for Denys Vlasenko
Commit-ID:  8dd5032d9c540111dd673078738d137a998d6c3f
Gitweb: http://git.kernel.org/tip/8dd5032d9c540111dd673078738d137a998d6c3f
Author: Denys Vlasenko 
AuthorDate: Sun, 7 Feb 2016 22:51:27 +0100
Committer:  Ingo Molnar 
CommitDate: Tue, 9 Feb 2016 10:31:54 +0100

x86/asm/bitops: Force inlining of test_and_set_bit and friends

Sometimes GCC mysteriously doesn't inline very small functions
we expect to be inlined, see:

  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66122

Arguably, GCC should do better, but GCC people aren't willing
to invest time into it and are asking to use __always_inline
instead.

With this .config:

  http://busybox.net/~vda/kernel_config_OPTIMIZE_INLINING_and_Os

here's an example of functions getting deinlined many times:

  test_and_set_bit (166 copies, ~1260 calls)
 55  push   %rbp
 48 89 e5mov%rsp,%rbp
 f0 48 0f ab 3e  lock bts %rdi,(%rsi)
 72 04   jb 
 31 c0   xor%eax,%eax
 eb 05   jmp
 b8 01 00 00 00  mov$0x1,%eax
 5d  pop%rbp
 c3  retq

  test_and_clear_bit (124 copies, ~1000 calls)
 55  push   %rbp
 48 89 e5mov%rsp,%rbp
 f0 48 0f b3 3e  lock btr %rdi,(%rsi)
 72 04   jb 
 31 c0   xor%eax,%eax
 eb 05   jmp
 b8 01 00 00 00  mov$0x1,%eax
 5d  pop%rbp
 c3  retq

  change_bit (3 copies, 8 calls)
 55  push   %rbp
 48 89 e5mov%rsp,%rbp
 f0 48 0f bb 3e  lock btc %rdi,(%rsi)
 5d  pop%rbp
 c3  retq

  clear_bit_unlock (2 copies, 11 calls)
 55  push   %rbp
 48 89 e5mov%rsp,%rbp
 f0 48 0f b3 3e  lock btr %rdi,(%rsi)
 5d  pop%rbp
 c3  retq

This patch works it around via s/inline/__always_inline/.

Code size decrease by ~13.5k after the patch:

  text data  bss   decfilename
  92110727 20826144 36417536 149354407vmlinux.before
  92097234 20826176 36417536 149340946vmlinux.after

Signed-off-by: Denys Vlasenko 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: David Rientjes 
Cc: H. Peter Anvin 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: Thomas Graf 
Link: 
http://lkml.kernel.org/r/1454881887-1367-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/include/asm/bitops.h | 36 ++--
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
index cfe3b95..7766d1c 100644
--- a/arch/x86/include/asm/bitops.h
+++ b/arch/x86/include/asm/bitops.h
@@ -91,7 +91,7 @@ set_bit(long nr, volatile unsigned long *addr)
  * If it's called on the same region of memory simultaneously, the effect
  * may be that only one operation succeeds.
  */
-static inline void __set_bit(long nr, volatile unsigned long *addr)
+static __always_inline void __set_bit(long nr, volatile unsigned long *addr)
 {
asm volatile("bts %1,%0" : ADDR : "Ir" (nr) : "memory");
 }
@@ -128,13 +128,13 @@ clear_bit(long nr, volatile unsigned long *addr)
  * clear_bit() is atomic and implies release semantics before the memory
  * operation. It can be used for an unlock.
  */
-static inline void clear_bit_unlock(long nr, volatile unsigned long *addr)
+static __always_inline void clear_bit_unlock(long nr, volatile unsigned long 
*addr)
 {
barrier();
clear_bit(nr, addr);
 }
 
-static inline void __clear_bit(long nr, volatile unsigned long *addr)
+static __always_inline void __clear_bit(long nr, volatile unsigned long *addr)
 {
asm volatile("btr %1,%0" : ADDR : "Ir" (nr));
 }
@@ -151,7 +151,7 @@ static inline void __clear_bit(long nr, volatile unsigned 
long *addr)
  * No memory barrier is required here, because x86 cannot reorder stores past
  * older loads. Same principle as spin_unlock.
  */
-static inline void __clear_bit_unlock(long nr, volatile unsigned long *addr)
+static __always_inline void __clear_bit_unlock(long nr, volatile unsigned long 
*addr)
 {
barrier();
__clear_bit(nr, addr);
@@ -166,7 +166,7 @@ static inline void __clear_bit_unlock(long nr, volatile 
unsigned long *addr)
  * If it's called on the same region of memory simultaneously, the effect
  * may be that only one operation succeeds.
  */
-static inline void __change_bit(long nr, volatile unsigned long *addr)
+static __always_inline void __change_bit(long nr, volatile unsigned long *addr)
 {
   

[tip:x86/asm] x86/asm/bitops: Force inlining of test_and_set_bit and friends

2016-02-09 Thread tip-bot for Denys Vlasenko
Commit-ID:  8dd5032d9c540111dd673078738d137a998d6c3f
Gitweb: http://git.kernel.org/tip/8dd5032d9c540111dd673078738d137a998d6c3f
Author: Denys Vlasenko 
AuthorDate: Sun, 7 Feb 2016 22:51:27 +0100
Committer:  Ingo Molnar 
CommitDate: Tue, 9 Feb 2016 10:31:54 +0100

x86/asm/bitops: Force inlining of test_and_set_bit and friends

Sometimes GCC mysteriously doesn't inline very small functions
we expect to be inlined, see:

  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66122

Arguably, GCC should do better, but GCC people aren't willing
to invest time into it and are asking to use __always_inline
instead.

With this .config:

  http://busybox.net/~vda/kernel_config_OPTIMIZE_INLINING_and_Os

here's an example of functions getting deinlined many times:

  test_and_set_bit (166 copies, ~1260 calls)
 55  push   %rbp
 48 89 e5mov%rsp,%rbp
 f0 48 0f ab 3e  lock bts %rdi,(%rsi)
 72 04   jb 
 31 c0   xor%eax,%eax
 eb 05   jmp
 b8 01 00 00 00  mov$0x1,%eax
 5d  pop%rbp
 c3  retq

  test_and_clear_bit (124 copies, ~1000 calls)
 55  push   %rbp
 48 89 e5mov%rsp,%rbp
 f0 48 0f b3 3e  lock btr %rdi,(%rsi)
 72 04   jb 
 31 c0   xor%eax,%eax
 eb 05   jmp
 b8 01 00 00 00  mov$0x1,%eax
 5d  pop%rbp
 c3  retq

  change_bit (3 copies, 8 calls)
 55  push   %rbp
 48 89 e5mov%rsp,%rbp
 f0 48 0f bb 3e  lock btc %rdi,(%rsi)
 5d  pop%rbp
 c3  retq

  clear_bit_unlock (2 copies, 11 calls)
 55  push   %rbp
 48 89 e5mov%rsp,%rbp
 f0 48 0f b3 3e  lock btr %rdi,(%rsi)
 5d  pop%rbp
 c3  retq

This patch works it around via s/inline/__always_inline/.

Code size decrease by ~13.5k after the patch:

  text data  bss   decfilename
  92110727 20826144 36417536 149354407vmlinux.before
  92097234 20826176 36417536 149340946vmlinux.after

Signed-off-by: Denys Vlasenko 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: David Rientjes 
Cc: H. Peter Anvin 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: Thomas Graf 
Link: 
http://lkml.kernel.org/r/1454881887-1367-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/include/asm/bitops.h | 36 ++--
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
index cfe3b95..7766d1c 100644
--- a/arch/x86/include/asm/bitops.h
+++ b/arch/x86/include/asm/bitops.h
@@ -91,7 +91,7 @@ set_bit(long nr, volatile unsigned long *addr)
  * If it's called on the same region of memory simultaneously, the effect
  * may be that only one operation succeeds.
  */
-static inline void __set_bit(long nr, volatile unsigned long *addr)
+static __always_inline void __set_bit(long nr, volatile unsigned long *addr)
 {
asm volatile("bts %1,%0" : ADDR : "Ir" (nr) : "memory");
 }
@@ -128,13 +128,13 @@ clear_bit(long nr, volatile unsigned long *addr)
  * clear_bit() is atomic and implies release semantics before the memory
  * operation. It can be used for an unlock.
  */
-static inline void clear_bit_unlock(long nr, volatile unsigned long *addr)
+static __always_inline void clear_bit_unlock(long nr, volatile unsigned long 
*addr)
 {
barrier();
clear_bit(nr, addr);
 }
 
-static inline void __clear_bit(long nr, volatile unsigned long *addr)
+static __always_inline void __clear_bit(long nr, volatile unsigned long *addr)
 {
asm volatile("btr %1,%0" : ADDR : "Ir" (nr));
 }
@@ -151,7 +151,7 @@ static inline void __clear_bit(long nr, volatile unsigned 
long *addr)
  * No memory barrier is required here, because x86 cannot reorder stores past
  * older loads. Same principle as spin_unlock.
  */
-static inline void __clear_bit_unlock(long nr, volatile unsigned long *addr)
+static __always_inline void __clear_bit_unlock(long nr, volatile unsigned long 
*addr)
 {
barrier();
__clear_bit(nr, addr);

[tip:x86/cleanups] x86: Deinline early_console_register, save 403 bytes

2015-09-30 Thread tip-bot for Denys Vlasenko
Commit-ID:  c368ef2866adbfc0e90fdecc09e3b3fe2cddcd14
Gitweb: http://git.kernel.org/tip/c368ef2866adbfc0e90fdecc09e3b3fe2cddcd14
Author: Denys Vlasenko 
AuthorDate: Mon, 28 Sep 2015 14:23:56 +0200
Committer:  Thomas Gleixner 
CommitDate: Wed, 30 Sep 2015 21:54:40 +0200

x86: Deinline early_console_register, save 403 bytes

This function compiles to 60 bytes of machine code.

Signed-off-by: Denys Vlasenko 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Link: 
http://lkml.kernel.org/r/1443443037-22077-3-git-send-email-dvlas...@redhat.com
Signed-off-by: Thomas Gleixner 
---
 arch/x86/kernel/early_printk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
index eec40f5..076a4a7 100644
--- a/arch/x86/kernel/early_printk.c
+++ b/arch/x86/kernel/early_printk.c
@@ -316,7 +316,7 @@ static struct console early_serial_console = {
.index =-1,
 };
 
-static inline void early_console_register(struct console *con, int keep_early)
+static void early_console_register(struct console *con, int keep_early)
 {
if (con->index != -1) {
printk(KERN_CRIT "ERROR: earlyprintk= %s already used\n",
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/cleanups] x86/signal: Deinline get_sigframe, save 240 bytes

2015-09-30 Thread tip-bot for Denys Vlasenko
Commit-ID:  dae0f305d61b07933a129dfe975342f3177277d5
Gitweb: http://git.kernel.org/tip/dae0f305d61b07933a129dfe975342f3177277d5
Author: Denys Vlasenko 
AuthorDate: Mon, 28 Sep 2015 14:23:57 +0200
Committer:  Thomas Gleixner 
CommitDate: Wed, 30 Sep 2015 21:54:40 +0200

x86/signal: Deinline get_sigframe, save 240 bytes

This function compiles to 277 bytes of machine code and has 4 callsites.

Signed-off-by: Denys Vlasenko 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Link: 
http://lkml.kernel.org/r/1443443037-22077-4-git-send-email-dvlas...@redhat.com
Signed-off-by: Thomas Gleixner 
---
 arch/x86/kernel/signal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
index da52e6b..2c3336b 100644
--- a/arch/x86/kernel/signal.c
+++ b/arch/x86/kernel/signal.c
@@ -196,7 +196,7 @@ static unsigned long align_sigframe(unsigned long sp)
return sp;
 }
 
-static inline void __user *
+static void __user *
 get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
 void __user **fpstate)
 {
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/cleanups] x86/e820: Deinline e820_type_to_string, save 126 bytes

2015-09-30 Thread tip-bot for Denys Vlasenko
Commit-ID:  e6e5f84092b1f3a8733c20e26838af4e21a4854f
Gitweb: http://git.kernel.org/tip/e6e5f84092b1f3a8733c20e26838af4e21a4854f
Author: Denys Vlasenko 
AuthorDate: Mon, 28 Sep 2015 14:23:55 +0200
Committer:  Thomas Gleixner 
CommitDate: Wed, 30 Sep 2015 21:54:40 +0200

x86/e820: Deinline e820_type_to_string, save 126 bytes

This function compiles to 102 bytes of machine code. It has two
callsites.

Signed-off-by: Denys Vlasenko 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Link: 
http://lkml.kernel.org/r/1443443037-22077-2-git-send-email-dvlas...@redhat.com
Signed-off-by: Thomas Gleixner 
---
 arch/x86/kernel/e820.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index a102564..569c1e4 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -911,7 +911,7 @@ void __init finish_e820_parsing(void)
}
 }
 
-static inline const char *e820_type_to_string(int e820_type)
+static const char *e820_type_to_string(int e820_type)
 {
switch (e820_type) {
case E820_RESERVED_KERN:
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/apic] x86/apic: Deinline various functions

2015-09-30 Thread tip-bot for Denys Vlasenko
Commit-ID:  d786ad32c305ca0f6be1924558866fe9f901e291
Gitweb: http://git.kernel.org/tip/d786ad32c305ca0f6be1924558866fe9f901e291
Author: Denys Vlasenko 
AuthorDate: Tue, 29 Sep 2015 22:37:02 +0200
Committer:  Thomas Gleixner 
CommitDate: Wed, 30 Sep 2015 21:15:53 +0200

x86/apic: Deinline various functions

__x2apic_disable: 178 bytes, 3 calls
__x2apic_enable: 117 bytes, 3 calls
__smp_spurious_interrupt: 110 bytes, 2 calls
__smp_error_interrupt: 208 bytes, 2 calls

Reduces code size by about 850 bytes.

Signed-off-by: Denys Vlasenko 
Cc: Borislav Petkov 
Cc: Andy Lutomirski 
Link: 
http://lkml.kernel.org/r/1443559022-23793-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Thomas Gleixner 
---
 arch/x86/kernel/apic/apic.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 24e94ce..2f69e3b 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -1431,7 +1431,7 @@ enum {
 };
 static int x2apic_state;
 
-static inline void __x2apic_disable(void)
+static void __x2apic_disable(void)
 {
u64 msr;
 
@@ -1447,7 +1447,7 @@ static inline void __x2apic_disable(void)
printk_once(KERN_INFO "x2apic disabled\n");
 }
 
-static inline void __x2apic_enable(void)
+static void __x2apic_enable(void)
 {
u64 msr;
 
@@ -1807,7 +1807,7 @@ int apic_version[MAX_LOCAL_APIC];
 /*
  * This interrupt should _never_ happen with our APIC/SMP architecture
  */
-static inline void __smp_spurious_interrupt(u8 vector)
+static void __smp_spurious_interrupt(u8 vector)
 {
u32 v;
 
@@ -1848,7 +1848,7 @@ __visible void smp_trace_spurious_interrupt(struct 
pt_regs *regs)
 /*
  * This interrupt should never happen with our APIC/SMP architecture
  */
-static inline void __smp_error_interrupt(struct pt_regs *regs)
+static void __smp_error_interrupt(struct pt_regs *regs)
 {
u32 v;
u32 i = 0;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/apic] x86/apic: Deinline various functions

2015-09-30 Thread tip-bot for Denys Vlasenko
Commit-ID:  d786ad32c305ca0f6be1924558866fe9f901e291
Gitweb: http://git.kernel.org/tip/d786ad32c305ca0f6be1924558866fe9f901e291
Author: Denys Vlasenko 
AuthorDate: Tue, 29 Sep 2015 22:37:02 +0200
Committer:  Thomas Gleixner 
CommitDate: Wed, 30 Sep 2015 21:15:53 +0200

x86/apic: Deinline various functions

__x2apic_disable: 178 bytes, 3 calls
__x2apic_enable: 117 bytes, 3 calls
__smp_spurious_interrupt: 110 bytes, 2 calls
__smp_error_interrupt: 208 bytes, 2 calls

Reduces code size by about 850 bytes.

Signed-off-by: Denys Vlasenko 
Cc: Borislav Petkov 
Cc: Andy Lutomirski 
Link: 
http://lkml.kernel.org/r/1443559022-23793-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Thomas Gleixner 
---
 arch/x86/kernel/apic/apic.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 24e94ce..2f69e3b 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -1431,7 +1431,7 @@ enum {
 };
 static int x2apic_state;
 
-static inline void __x2apic_disable(void)
+static void __x2apic_disable(void)
 {
u64 msr;
 
@@ -1447,7 +1447,7 @@ static inline void __x2apic_disable(void)
printk_once(KERN_INFO "x2apic disabled\n");
 }
 
-static inline void __x2apic_enable(void)
+static void __x2apic_enable(void)
 {
u64 msr;
 
@@ -1807,7 +1807,7 @@ int apic_version[MAX_LOCAL_APIC];
 /*
  * This interrupt should _never_ happen with our APIC/SMP architecture
  */
-static inline void __smp_spurious_interrupt(u8 vector)
+static void __smp_spurious_interrupt(u8 vector)
 {
u32 v;
 
@@ -1848,7 +1848,7 @@ __visible void smp_trace_spurious_interrupt(struct 
pt_regs *regs)
 /*
  * This interrupt should never happen with our APIC/SMP architecture
  */
-static inline void __smp_error_interrupt(struct pt_regs *regs)
+static void __smp_error_interrupt(struct pt_regs *regs)
 {
u32 v;
u32 i = 0;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/cleanups] x86/signal: Deinline get_sigframe, save 240 bytes

2015-09-30 Thread tip-bot for Denys Vlasenko
Commit-ID:  dae0f305d61b07933a129dfe975342f3177277d5
Gitweb: http://git.kernel.org/tip/dae0f305d61b07933a129dfe975342f3177277d5
Author: Denys Vlasenko 
AuthorDate: Mon, 28 Sep 2015 14:23:57 +0200
Committer:  Thomas Gleixner 
CommitDate: Wed, 30 Sep 2015 21:54:40 +0200

x86/signal: Deinline get_sigframe, save 240 bytes

This function compiles to 277 bytes of machine code and has 4 callsites.

Signed-off-by: Denys Vlasenko 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Link: 
http://lkml.kernel.org/r/1443443037-22077-4-git-send-email-dvlas...@redhat.com
Signed-off-by: Thomas Gleixner 
---
 arch/x86/kernel/signal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
index da52e6b..2c3336b 100644
--- a/arch/x86/kernel/signal.c
+++ b/arch/x86/kernel/signal.c
@@ -196,7 +196,7 @@ static unsigned long align_sigframe(unsigned long sp)
return sp;
 }
 
-static inline void __user *
+static void __user *
 get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
 void __user **fpstate)
 {
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/cleanups] x86: Deinline early_console_register, save 403 bytes

2015-09-30 Thread tip-bot for Denys Vlasenko
Commit-ID:  c368ef2866adbfc0e90fdecc09e3b3fe2cddcd14
Gitweb: http://git.kernel.org/tip/c368ef2866adbfc0e90fdecc09e3b3fe2cddcd14
Author: Denys Vlasenko 
AuthorDate: Mon, 28 Sep 2015 14:23:56 +0200
Committer:  Thomas Gleixner 
CommitDate: Wed, 30 Sep 2015 21:54:40 +0200

x86: Deinline early_console_register, save 403 bytes

This function compiles to 60 bytes of machine code.

Signed-off-by: Denys Vlasenko 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Link: 
http://lkml.kernel.org/r/1443443037-22077-3-git-send-email-dvlas...@redhat.com
Signed-off-by: Thomas Gleixner 
---
 arch/x86/kernel/early_printk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
index eec40f5..076a4a7 100644
--- a/arch/x86/kernel/early_printk.c
+++ b/arch/x86/kernel/early_printk.c
@@ -316,7 +316,7 @@ static struct console early_serial_console = {
.index =-1,
 };
 
-static inline void early_console_register(struct console *con, int keep_early)
+static void early_console_register(struct console *con, int keep_early)
 {
if (con->index != -1) {
printk(KERN_CRIT "ERROR: earlyprintk= %s already used\n",
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/cleanups] x86/e820: Deinline e820_type_to_string, save 126 bytes

2015-09-30 Thread tip-bot for Denys Vlasenko
Commit-ID:  e6e5f84092b1f3a8733c20e26838af4e21a4854f
Gitweb: http://git.kernel.org/tip/e6e5f84092b1f3a8733c20e26838af4e21a4854f
Author: Denys Vlasenko 
AuthorDate: Mon, 28 Sep 2015 14:23:55 +0200
Committer:  Thomas Gleixner 
CommitDate: Wed, 30 Sep 2015 21:54:40 +0200

x86/e820: Deinline e820_type_to_string, save 126 bytes

This function compiles to 102 bytes of machine code. It has two
callsites.

Signed-off-by: Denys Vlasenko 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Link: 
http://lkml.kernel.org/r/1443443037-22077-2-git-send-email-dvlas...@redhat.com
Signed-off-by: Thomas Gleixner 
---
 arch/x86/kernel/e820.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index a102564..569c1e4 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -911,7 +911,7 @@ void __init finish_e820_parsing(void)
}
 }
 
-static inline const char *e820_type_to_string(int e820_type)
+static const char *e820_type_to_string(int e820_type)
 {
switch (e820_type) {
case E820_RESERVED_KERN:
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/debug] x86/kgdb: Replace bool_int_array[NR_CPUS] with bitmap

2015-09-29 Thread tip-bot for Denys Vlasenko
Commit-ID:  0d44975d1e2791f6df2b84b182f49d815ba3c9e0
Gitweb: http://git.kernel.org/tip/0d44975d1e2791f6df2b84b182f49d815ba3c9e0
Author: Denys Vlasenko 
AuthorDate: Sat, 26 Sep 2015 14:47:17 +0200
Committer:  Ingo Molnar 
CommitDate: Mon, 28 Sep 2015 10:13:31 +0200

x86/kgdb: Replace bool_int_array[NR_CPUS] with bitmap

Straigntforward conversion from:

int was_in_debug_nmi[NR_CPUS]

to:

DECLARE_BITMAP(was_in_debug_nmi, NR_CPUS)

Saves about 2 kbytes in BSS for NR_CPUS=512.

Signed-off-by: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Jason Wessel 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1443271638-2568-1-git-send-email-dvlas...@redhat.com
[ Tidied up the code a bit. ]
Signed-off-by: Ingo Molnar 
---
 arch/x86/kernel/kgdb.c | 17 +++--
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
index d6178d9..44256a6 100644
--- a/arch/x86/kernel/kgdb.c
+++ b/arch/x86/kernel/kgdb.c
@@ -511,26 +511,31 @@ single_step_cont(struct pt_regs *regs, struct die_args 
*args)
return NOTIFY_STOP;
 }
 
-static int was_in_debug_nmi[NR_CPUS];
+static DECLARE_BITMAP(was_in_debug_nmi, NR_CPUS);
 
 static int kgdb_nmi_handler(unsigned int cmd, struct pt_regs *regs)
 {
+   int cpu;
+
switch (cmd) {
case NMI_LOCAL:
if (atomic_read(_active) != -1) {
/* KGDB CPU roundup */
-   kgdb_nmicallback(raw_smp_processor_id(), regs);
-   was_in_debug_nmi[raw_smp_processor_id()] = 1;
+   cpu = raw_smp_processor_id();
+   kgdb_nmicallback(cpu, regs);
+   set_bit(cpu, was_in_debug_nmi);
touch_nmi_watchdog();
+
return NMI_HANDLED;
}
break;
 
case NMI_UNKNOWN:
-   if (was_in_debug_nmi[raw_smp_processor_id()]) {
-   was_in_debug_nmi[raw_smp_processor_id()] = 0;
+   cpu = raw_smp_processor_id();
+
+   if (__test_and_clear_bit(cpu, was_in_debug_nmi))
return NMI_HANDLED;
-   }
+
break;
default:
/* do nothing */
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/debug] x86/kgdb: Replace bool_int_array[NR_CPUS] with bitmap

2015-09-29 Thread tip-bot for Denys Vlasenko
Commit-ID:  0d44975d1e2791f6df2b84b182f49d815ba3c9e0
Gitweb: http://git.kernel.org/tip/0d44975d1e2791f6df2b84b182f49d815ba3c9e0
Author: Denys Vlasenko 
AuthorDate: Sat, 26 Sep 2015 14:47:17 +0200
Committer:  Ingo Molnar 
CommitDate: Mon, 28 Sep 2015 10:13:31 +0200

x86/kgdb: Replace bool_int_array[NR_CPUS] with bitmap

Straigntforward conversion from:

int was_in_debug_nmi[NR_CPUS]

to:

DECLARE_BITMAP(was_in_debug_nmi, NR_CPUS)

Saves about 2 kbytes in BSS for NR_CPUS=512.

Signed-off-by: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Jason Wessel 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1443271638-2568-1-git-send-email-dvlas...@redhat.com
[ Tidied up the code a bit. ]
Signed-off-by: Ingo Molnar 
---
 arch/x86/kernel/kgdb.c | 17 +++--
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
index d6178d9..44256a6 100644
--- a/arch/x86/kernel/kgdb.c
+++ b/arch/x86/kernel/kgdb.c
@@ -511,26 +511,31 @@ single_step_cont(struct pt_regs *regs, struct die_args 
*args)
return NOTIFY_STOP;
 }
 
-static int was_in_debug_nmi[NR_CPUS];
+static DECLARE_BITMAP(was_in_debug_nmi, NR_CPUS);
 
 static int kgdb_nmi_handler(unsigned int cmd, struct pt_regs *regs)
 {
+   int cpu;
+
switch (cmd) {
case NMI_LOCAL:
if (atomic_read(_active) != -1) {
/* KGDB CPU roundup */
-   kgdb_nmicallback(raw_smp_processor_id(), regs);
-   was_in_debug_nmi[raw_smp_processor_id()] = 1;
+   cpu = raw_smp_processor_id();
+   kgdb_nmicallback(cpu, regs);
+   set_bit(cpu, was_in_debug_nmi);
touch_nmi_watchdog();
+
return NMI_HANDLED;
}
break;
 
case NMI_UNKNOWN:
-   if (was_in_debug_nmi[raw_smp_processor_id()]) {
-   was_in_debug_nmi[raw_smp_processor_id()] = 0;
+   cpu = raw_smp_processor_id();
+
+   if (__test_and_clear_bit(cpu, was_in_debug_nmi))
return NMI_HANDLED;
-   }
+
break;
default:
/* do nothing */
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/asm] x86/asm: Force inlining of cpu_relax()

2015-09-25 Thread tip-bot for Denys Vlasenko
Commit-ID:  0b101e62afe626ecae60173f92f1e0ec72151653
Gitweb: http://git.kernel.org/tip/0b101e62afe626ecae60173f92f1e0ec72151653
Author: Denys Vlasenko 
AuthorDate: Thu, 24 Sep 2015 14:02:29 +0200
Committer:  Ingo Molnar 
CommitDate: Fri, 25 Sep 2015 09:44:34 +0200

x86/asm: Force inlining of cpu_relax()

On x86, cpu_relax() simply calls rep_nop(), which generates one
instruction, PAUSE (aka REP NOP).

With this config:

  http://busybox.net/~vda/kernel_config_OPTIMIZE_INLINING_and_Os

gcc-4.7.2 does not always inline rep_nop(): it generates several
copies of this:

   (16 copies, 194 calls):
   55  push   %rbp
   48 89 e5mov%rsp,%rbp
   f3 90   pause
   5d  pop%rbp
   c3  retq

See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66122

This patch fixes this via s/inline/__always_inline/
on rep_nop() and cpu_relax().

( Forcing inlining only on rep_nop() causes GCC to
  deinline cpu_relax(), with almost no change in generated code).

  text data  bss   dec hex filename
  88118971 19905208 36421632 15811 89c1173 vmlinux.before
  88118139 19905208 36421632 14979 89c0e33 vmlinux

Signed-off-by: Denys Vlasenko 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: H. Peter Anvin 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1443096149-27291-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/include/asm/processor.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 19577dd..b55f309 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -556,12 +556,12 @@ static inline unsigned int cpuid_edx(unsigned int op)
 }
 
 /* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */
-static inline void rep_nop(void)
+static __always_inline void rep_nop(void)
 {
asm volatile("rep; nop" ::: "memory");
 }
 
-static inline void cpu_relax(void)
+static __always_inline void cpu_relax(void)
 {
rep_nop();
 }
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/asm] x86/asm: Force inlining of cpu_relax()

2015-09-25 Thread tip-bot for Denys Vlasenko
Commit-ID:  0b101e62afe626ecae60173f92f1e0ec72151653
Gitweb: http://git.kernel.org/tip/0b101e62afe626ecae60173f92f1e0ec72151653
Author: Denys Vlasenko 
AuthorDate: Thu, 24 Sep 2015 14:02:29 +0200
Committer:  Ingo Molnar 
CommitDate: Fri, 25 Sep 2015 09:44:34 +0200

x86/asm: Force inlining of cpu_relax()

On x86, cpu_relax() simply calls rep_nop(), which generates one
instruction, PAUSE (aka REP NOP).

With this config:

  http://busybox.net/~vda/kernel_config_OPTIMIZE_INLINING_and_Os

gcc-4.7.2 does not always inline rep_nop(): it generates several
copies of this:

   (16 copies, 194 calls):
   55  push   %rbp
   48 89 e5mov%rsp,%rbp
   f3 90   pause
   5d  pop%rbp
   c3  retq

See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66122

This patch fixes this via s/inline/__always_inline/
on rep_nop() and cpu_relax().

( Forcing inlining only on rep_nop() causes GCC to
  deinline cpu_relax(), with almost no change in generated code).

  text data  bss   dec hex filename
  88118971 19905208 36421632 15811 89c1173 vmlinux.before
  88118139 19905208 36421632 14979 89c0e33 vmlinux

Signed-off-by: Denys Vlasenko 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: H. Peter Anvin 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1443096149-27291-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/include/asm/processor.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 19577dd..b55f309 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -556,12 +556,12 @@ static inline unsigned int cpuid_edx(unsigned int op)
 }
 
 /* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */
-static inline void rep_nop(void)
+static __always_inline void rep_nop(void)
 {
asm volatile("rep; nop" ::: "memory");
 }
 
-static inline void cpu_relax(void)
+static __always_inline void cpu_relax(void)
 {
rep_nop();
 }
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/fpu] x86/fpu/math-emu, selftests: Add test for FISTTP instructions

2015-09-21 Thread tip-bot for Denys Vlasenko
Commit-ID:  a58e2ecd019d9ffb9f1813faf6151716fdecbae5
Gitweb: http://git.kernel.org/tip/a58e2ecd019d9ffb9f1813faf6151716fdecbae5
Author: Denys Vlasenko 
AuthorDate: Sun, 20 Sep 2015 16:03:10 +0200
Committer:  Ingo Molnar 
CommitDate: Sun, 20 Sep 2015 16:19:01 +0200

x86/fpu/math-emu, selftests: Add test for FISTTP instructions

  $ ./test_FISTTP_32
  [RUN] Testing fisttp instructions
  [OK]  fisttp

Signed-off-by: Denys Vlasenko 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Shuah Khan 
Cc: Thomas Gleixner 
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1442757790-27233-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 tools/testing/selftests/x86/Makefile  |   2 +-
 tools/testing/selftests/x86/test_FISTTP.c | 137 ++
 2 files changed, 138 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/x86/Makefile 
b/tools/testing/selftests/x86/Makefile
index c4c9b90..7145b3d 100644
--- a/tools/testing/selftests/x86/Makefile
+++ b/tools/testing/selftests/x86/Makefile
@@ -6,7 +6,7 @@ include ../lib.mk
 
 TARGETS_C_BOTHBITS := single_step_syscall sysret_ss_attrs ldt_gdt syscall_nt
 TARGETS_C_32BIT_ONLY := entry_from_vm86 syscall_arg_fault sigreturn \
-   test_FCMOV test_FCOMI
+   test_FCMOV test_FCOMI test_FISTTP
 
 TARGETS_C_32BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_32BIT_ONLY)
 BINARIES_32 := $(TARGETS_C_32BIT_ALL:%=%_32)
diff --git a/tools/testing/selftests/x86/test_FISTTP.c 
b/tools/testing/selftests/x86/test_FISTTP.c
new file mode 100644
index 000..b8e61a0
--- /dev/null
+++ b/tools/testing/selftests/x86/test_FISTTP.c
@@ -0,0 +1,137 @@
+#undef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#undef __USE_GNU
+#define __USE_GNU 1
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+unsigned long long res64 = -1;
+unsigned int res32 = -1;
+unsigned short res16 = -1;
+
+int test(void)
+{
+   int ex;
+
+   
feclearexcept(FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
+   asm volatile ("\n"
+   "   fld1""\n"
+   "   fisttp  res16""\n"
+   "   fld1""\n"
+   "   fisttpl res32""\n"
+   "   fld1""\n"
+   "   fisttpll res64""\n"
+   : : : "memory"
+   );
+   if (res16 != 1 || res32 != 1 || res64 != 1) {
+   printf("[BAD]\tfisttp 1\n");
+   return 1;
+   }
+   ex = 
fetestexcept(FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
+   if (ex != 0) {
+   printf("[BAD]\tfisttp 1: wrong exception state\n");
+   return 1;
+   }
+
+   
feclearexcept(FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
+   asm volatile ("\n"
+   "   fldpi""\n"
+   "   fisttp  res16""\n"
+   "   fldpi""\n"
+   "   fisttpl res32""\n"
+   "   fldpi""\n"
+   "   fisttpll res64""\n"
+   : : : "memory"
+   );
+   if (res16 != 3 || res32 != 3 || res64 != 3) {
+   printf("[BAD]\tfisttp pi\n");
+   return 1;
+   }
+   ex = 
fetestexcept(FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
+   if (ex != FE_INEXACT) {
+   printf("[BAD]\tfisttp pi: wrong exception state\n");
+   return 1;
+   }
+
+   
feclearexcept(FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
+   asm volatile ("\n"
+   "   fldpi""\n"
+   "   fchs""\n"
+   "   fisttp  res16""\n"
+   "   fldpi""\n"
+   "   fchs""\n"
+   "   fisttpl res32""\n"
+   "   fldpi""\n"
+   "   fchs""\n"
+   "   fisttpll res64""\n"
+   : : : "memory"
+   );
+   if (res16 != 0xfffd || res32 != 0xfffd || res64 != 
0xfffdULL) {
+   printf("[BAD]\tfisttp -pi\n");
+   return 1;
+   }
+   ex = 
fetestexcept(FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
+   if (ex != FE_INEXACT) {
+   printf("[BAD]\tfisttp -pi: wrong exception state\n");
+   return 1;
+   }
+
+   
feclearexcept(FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
+   asm volatile ("\n"
+   "   fldln2""\n"
+   "   fisttp  res16""\n"
+   "   fldln2""\n"
+   "   fisttpl res32""\n"
+   "   fldln2""\n"
+   "   fisttpll res64""\n"
+   : : : "memory"
+   );
+   /* Test truncation to zero (round-to-nearest would give 1 here) */
+   if (res16 != 0 || res32 != 0 || res64 != 0) {
+   printf("[BAD]\tfisttp ln2\n");
+   return 1;
+   }
+   ex = 
fetestexcept(FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
+   if (ex != FE_INEXACT) {
+   

[tip:x86/fpu] x86/fpu/math-emu: Add support for FISTTP instructions

2015-09-21 Thread tip-bot for Denys Vlasenko
Commit-ID:  e4877d64f00964d86a6e4a02301173899018
Gitweb: http://git.kernel.org/tip/e4877d64f00964d86a6e4a02301173899018
Author: Denys Vlasenko 
AuthorDate: Fri, 18 Sep 2015 20:23:34 +0200
Committer:  Ingo Molnar 
CommitDate: Sun, 20 Sep 2015 16:19:02 +0200

x86/fpu/math-emu: Add support for FISTTP instructions

These FPU instructions were added in SSE3-enabled CPUs.

Run-tested by booting with "no387 nofxsr" and running test
program:

[RUN]   Testing fisttp instructions
[OK]fisttp

Signed-off-by: Denys Vlasenko 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Shuah Khan 
Cc: Thomas Gleixner 
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1442600614-28428-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/math-emu/load_store.c | 63 ++
 1 file changed, 51 insertions(+), 12 deletions(-)

diff --git a/arch/x86/math-emu/load_store.c b/arch/x86/math-emu/load_store.c
index 2931ff3..95228ff 100644
--- a/arch/x86/math-emu/load_store.c
+++ b/arch/x86/math-emu/load_store.c
@@ -33,11 +33,12 @@
 
 #define pop_0(){ FPU_settag0(TAG_Empty); top++; }
 
+/* index is a 5-bit value: (3-bit FPU_modrm.reg field | opcode[2,1]) */
 static u_char const type_table[32] = {
-   _PUSH_, _PUSH_, _PUSH_, _PUSH_,
-   _null_, _null_, _null_, _null_,
-   _REG0_, _REG0_, _REG0_, _REG0_,
-   _REG0_, _REG0_, _REG0_, _REG0_,
+   _PUSH_, _PUSH_, _PUSH_, _PUSH_, /* /0: d9:fld f32,  db:fild m32,  
dd:fld f64,  df:fild m16 */
+   _null_, _REG0_, _REG0_, _REG0_, /* /1: d9:undef,db,dd,df:fisttp 
m32/64/16 */
+   _REG0_, _REG0_, _REG0_, _REG0_, /* /2: d9:fst f32,  db:fist m32,  
dd:fst f64,  df:fist m16 */
+   _REG0_, _REG0_, _REG0_, _REG0_, /* /3: d9:fstp f32, db:fistp m32, 
dd:fstp f64, df:fistp m16 */
_NONE_, _null_, _NONE_, _PUSH_,
_NONE_, _PUSH_, _null_, _PUSH_,
_NONE_, _null_, _NONE_, _REG0_,
@@ -45,15 +46,19 @@ static u_char const type_table[32] = {
 };
 
 u_char const data_sizes_16[32] = {
-   4, 4, 8, 2, 0, 0, 0, 0,
-   4, 4, 8, 2, 4, 4, 8, 2,
+   4, 4, 8, 2,
+   0, 4, 8, 2, /* /1: d9:undef, db,dd,df:fisttp */
+   4, 4, 8, 2,
+   4, 4, 8, 2,
14, 0, 94, 10, 2, 10, 0, 8,
14, 0, 94, 10, 2, 10, 2, 8
 };
 
 static u_char const data_sizes_32[32] = {
-   4, 4, 8, 2, 0, 0, 0, 0,
-   4, 4, 8, 2, 4, 4, 8, 2,
+   4, 4, 8, 2,
+   0, 4, 8, 2, /* /1: d9:undef, db,dd,df:fisttp */
+   4, 4, 8, 2,
+   4, 4, 8, 2,
28, 0, 108, 10, 2, 10, 0, 8,
28, 0, 108, 10, 2, 10, 2, 8
 };
@@ -65,6 +70,7 @@ int FPU_load_store(u_char type, fpu_addr_modes addr_modes,
FPU_REG *st0_ptr;
u_char st0_tag = TAG_Empty; /* This is just to stop a gcc warning. 
*/
u_char loaded_tag;
+   int sv_cw;
 
st0_ptr = NULL; /* Initialized just to stop compiler warnings. 
*/
 
@@ -111,7 +117,8 @@ int FPU_load_store(u_char type, fpu_addr_modes addr_modes,
}
 
switch (type) {
-   case 000:   /* fld m32real */
+   /* type is a 5-bit value: (3-bit FPU_modrm.reg field | opcode[2,1]) */
+   case 000:   /* fld m32real (d9 /0) */
clear_C1();
loaded_tag =
FPU_load_single((float __user *)data_address, _data);
@@ -123,13 +130,13 @@ int FPU_load_store(u_char type, fpu_addr_modes addr_modes,
}
FPU_copy_to_reg0(_data, loaded_tag);
break;
-   case 001:   /* fild m32int */
+   case 001:   /* fild m32int (db /0) */
clear_C1();
loaded_tag =
FPU_load_int32((long __user *)data_address, _data);
FPU_copy_to_reg0(_data, loaded_tag);
break;
-   case 002:   /* fld m64real */
+   case 002:   /* fld m64real (dd /0) */
clear_C1();
loaded_tag =
FPU_load_double((double __user *)data_address,
@@ -142,12 +149,44 @@ int FPU_load_store(u_char type, fpu_addr_modes addr_modes,
}
FPU_copy_to_reg0(_data, loaded_tag);
break;
-   case 003:   /* fild m16int */
+   case 003:   /* fild m16int (df /0) */
clear_C1();
loaded_tag =
FPU_load_int16((short __user *)data_address, _data);
FPU_copy_to_reg0(_data, loaded_tag);
break;
+   /* case 004: undefined (d9 /1) */
+   /* fisttp are enabled if CPUID(1).ECX(0) "sse3" is set */
+   case 005:   /* fisttp m32int (db /1) */
+   clear_C1();
+   sv_cw = control_word;
+   control_word |= RC_CHOP;
+   if (FPU_store_int32
+   

[tip:x86/fpu] x86/fpu/math-emu, selftests: Add test for FISTTP instructions

2015-09-21 Thread tip-bot for Denys Vlasenko
Commit-ID:  a58e2ecd019d9ffb9f1813faf6151716fdecbae5
Gitweb: http://git.kernel.org/tip/a58e2ecd019d9ffb9f1813faf6151716fdecbae5
Author: Denys Vlasenko 
AuthorDate: Sun, 20 Sep 2015 16:03:10 +0200
Committer:  Ingo Molnar 
CommitDate: Sun, 20 Sep 2015 16:19:01 +0200

x86/fpu/math-emu, selftests: Add test for FISTTP instructions

  $ ./test_FISTTP_32
  [RUN] Testing fisttp instructions
  [OK]  fisttp

Signed-off-by: Denys Vlasenko 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Shuah Khan 
Cc: Thomas Gleixner 
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1442757790-27233-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 tools/testing/selftests/x86/Makefile  |   2 +-
 tools/testing/selftests/x86/test_FISTTP.c | 137 ++
 2 files changed, 138 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/x86/Makefile 
b/tools/testing/selftests/x86/Makefile
index c4c9b90..7145b3d 100644
--- a/tools/testing/selftests/x86/Makefile
+++ b/tools/testing/selftests/x86/Makefile
@@ -6,7 +6,7 @@ include ../lib.mk
 
 TARGETS_C_BOTHBITS := single_step_syscall sysret_ss_attrs ldt_gdt syscall_nt
 TARGETS_C_32BIT_ONLY := entry_from_vm86 syscall_arg_fault sigreturn \
-   test_FCMOV test_FCOMI
+   test_FCMOV test_FCOMI test_FISTTP
 
 TARGETS_C_32BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_32BIT_ONLY)
 BINARIES_32 := $(TARGETS_C_32BIT_ALL:%=%_32)
diff --git a/tools/testing/selftests/x86/test_FISTTP.c 
b/tools/testing/selftests/x86/test_FISTTP.c
new file mode 100644
index 000..b8e61a0
--- /dev/null
+++ b/tools/testing/selftests/x86/test_FISTTP.c
@@ -0,0 +1,137 @@
+#undef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#undef __USE_GNU
+#define __USE_GNU 1
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+unsigned long long res64 = -1;
+unsigned int res32 = -1;
+unsigned short res16 = -1;
+
+int test(void)
+{
+   int ex;
+
+   
feclearexcept(FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
+   asm volatile ("\n"
+   "   fld1""\n"
+   "   fisttp  res16""\n"
+   "   fld1""\n"
+   "   fisttpl res32""\n"
+   "   fld1""\n"
+   "   fisttpll res64""\n"
+   : : : "memory"
+   );
+   if (res16 != 1 || res32 != 1 || res64 != 1) {
+   printf("[BAD]\tfisttp 1\n");
+   return 1;
+   }
+   ex = 
fetestexcept(FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
+   if (ex != 0) {
+   printf("[BAD]\tfisttp 1: wrong exception state\n");
+   return 1;
+   }
+
+   
feclearexcept(FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
+   asm volatile ("\n"
+   "   fldpi""\n"
+   "   fisttp  res16""\n"
+   "   fldpi""\n"
+   "   fisttpl res32""\n"
+   "   fldpi""\n"
+   "   fisttpll res64""\n"
+   : : : "memory"
+   );
+   if (res16 != 3 || res32 != 3 || res64 != 3) {
+   printf("[BAD]\tfisttp pi\n");
+   return 1;
+   }
+   ex = 
fetestexcept(FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
+   if (ex != FE_INEXACT) {
+   printf("[BAD]\tfisttp pi: wrong exception state\n");
+   return 1;
+   }
+
+   
feclearexcept(FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
+   asm volatile ("\n"
+   "   fldpi""\n"
+   "   fchs""\n"
+   "   fisttp  res16""\n"
+   "   fldpi""\n"
+   "   fchs""\n"
+   "   fisttpl res32""\n"
+   "   fldpi""\n"
+   "   fchs""\n"
+   "   fisttpll res64""\n"
+   : : : "memory"
+   );
+   if (res16 != 0xfffd || res32 != 0xfffd || res64 != 
0xfffdULL) {
+   printf("[BAD]\tfisttp -pi\n");
+   return 1;
+   }
+   ex = 
fetestexcept(FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
+   if (ex != FE_INEXACT) {
+   printf("[BAD]\tfisttp -pi: wrong exception state\n");
+   return 1;
+   }
+
+   
feclearexcept(FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
+   asm volatile ("\n"
+   "   fldln2""\n"
+   "   fisttp  res16""\n"
+   "   fldln2""\n"
+   "   fisttpl res32""\n"
+   "   fldln2""\n"
+   "   fisttpll res64""\n"
+   : : : "memory"
+   );
+   /* Test truncation to zero (round-to-nearest would give 1 here) */
+   if (res16 != 

[tip:x86/fpu] x86/fpu/math-emu: Add support for FISTTP instructions

2015-09-21 Thread tip-bot for Denys Vlasenko
Commit-ID:  e4877d64f00964d86a6e4a02301173899018
Gitweb: http://git.kernel.org/tip/e4877d64f00964d86a6e4a02301173899018
Author: Denys Vlasenko 
AuthorDate: Fri, 18 Sep 2015 20:23:34 +0200
Committer:  Ingo Molnar 
CommitDate: Sun, 20 Sep 2015 16:19:02 +0200

x86/fpu/math-emu: Add support for FISTTP instructions

These FPU instructions were added in SSE3-enabled CPUs.

Run-tested by booting with "no387 nofxsr" and running test
program:

[RUN]   Testing fisttp instructions
[OK]fisttp

Signed-off-by: Denys Vlasenko 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Shuah Khan 
Cc: Thomas Gleixner 
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1442600614-28428-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/math-emu/load_store.c | 63 ++
 1 file changed, 51 insertions(+), 12 deletions(-)

diff --git a/arch/x86/math-emu/load_store.c b/arch/x86/math-emu/load_store.c
index 2931ff3..95228ff 100644
--- a/arch/x86/math-emu/load_store.c
+++ b/arch/x86/math-emu/load_store.c
@@ -33,11 +33,12 @@
 
 #define pop_0(){ FPU_settag0(TAG_Empty); top++; }
 
+/* index is a 5-bit value: (3-bit FPU_modrm.reg field | opcode[2,1]) */
 static u_char const type_table[32] = {
-   _PUSH_, _PUSH_, _PUSH_, _PUSH_,
-   _null_, _null_, _null_, _null_,
-   _REG0_, _REG0_, _REG0_, _REG0_,
-   _REG0_, _REG0_, _REG0_, _REG0_,
+   _PUSH_, _PUSH_, _PUSH_, _PUSH_, /* /0: d9:fld f32,  db:fild m32,  
dd:fld f64,  df:fild m16 */
+   _null_, _REG0_, _REG0_, _REG0_, /* /1: d9:undef,db,dd,df:fisttp 
m32/64/16 */
+   _REG0_, _REG0_, _REG0_, _REG0_, /* /2: d9:fst f32,  db:fist m32,  
dd:fst f64,  df:fist m16 */
+   _REG0_, _REG0_, _REG0_, _REG0_, /* /3: d9:fstp f32, db:fistp m32, 
dd:fstp f64, df:fistp m16 */
_NONE_, _null_, _NONE_, _PUSH_,
_NONE_, _PUSH_, _null_, _PUSH_,
_NONE_, _null_, _NONE_, _REG0_,
@@ -45,15 +46,19 @@ static u_char const type_table[32] = {
 };
 
 u_char const data_sizes_16[32] = {
-   4, 4, 8, 2, 0, 0, 0, 0,
-   4, 4, 8, 2, 4, 4, 8, 2,
+   4, 4, 8, 2,
+   0, 4, 8, 2, /* /1: d9:undef, db,dd,df:fisttp */
+   4, 4, 8, 2,
+   4, 4, 8, 2,
14, 0, 94, 10, 2, 10, 0, 8,
14, 0, 94, 10, 2, 10, 2, 8
 };
 
 static u_char const data_sizes_32[32] = {
-   4, 4, 8, 2, 0, 0, 0, 0,
-   4, 4, 8, 2, 4, 4, 8, 2,
+   4, 4, 8, 2,
+   0, 4, 8, 2, /* /1: d9:undef, db,dd,df:fisttp */
+   4, 4, 8, 2,
+   4, 4, 8, 2,
28, 0, 108, 10, 2, 10, 0, 8,
28, 0, 108, 10, 2, 10, 2, 8
 };
@@ -65,6 +70,7 @@ int FPU_load_store(u_char type, fpu_addr_modes addr_modes,
FPU_REG *st0_ptr;
u_char st0_tag = TAG_Empty; /* This is just to stop a gcc warning. 
*/
u_char loaded_tag;
+   int sv_cw;
 
st0_ptr = NULL; /* Initialized just to stop compiler warnings. 
*/
 
@@ -111,7 +117,8 @@ int FPU_load_store(u_char type, fpu_addr_modes addr_modes,
}
 
switch (type) {
-   case 000:   /* fld m32real */
+   /* type is a 5-bit value: (3-bit FPU_modrm.reg field | opcode[2,1]) */
+   case 000:   /* fld m32real (d9 /0) */
clear_C1();
loaded_tag =
FPU_load_single((float __user *)data_address, _data);
@@ -123,13 +130,13 @@ int FPU_load_store(u_char type, fpu_addr_modes addr_modes,
}
FPU_copy_to_reg0(_data, loaded_tag);
break;
-   case 001:   /* fild m32int */
+   case 001:   /* fild m32int (db /0) */
clear_C1();
loaded_tag =
FPU_load_int32((long __user *)data_address, _data);
FPU_copy_to_reg0(_data, loaded_tag);
break;
-   case 002:   /* fld m64real */
+   case 002:   /* fld m64real (dd /0) */
clear_C1();
loaded_tag =
FPU_load_double((double __user *)data_address,
@@ -142,12 +149,44 @@ int FPU_load_store(u_char type, fpu_addr_modes addr_modes,
}
FPU_copy_to_reg0(_data, loaded_tag);
break;
-   case 003:   /* fild m16int */
+   case 003:   /* fild m16int (df /0) */
clear_C1();
loaded_tag =
FPU_load_int16((short __user *)data_address, _data);
FPU_copy_to_reg0(_data, loaded_tag);
break;
+   /* case 004: undefined (d9 /1) */
+ 

[tip:x86/fpu] x86/fpu/math-emu: Add support for FCMOVcc insns

2015-09-20 Thread tip-bot for Denys Vlasenko
Commit-ID:  9a9d8642d03a7512f78cbe7ed6a2011fad3cbca3
Gitweb: http://git.kernel.org/tip/9a9d8642d03a7512f78cbe7ed6a2011fad3cbca3
Author: Denys Vlasenko 
AuthorDate: Fri, 18 Sep 2015 16:53:30 +0200
Committer:  Ingo Molnar 
CommitDate: Sun, 20 Sep 2015 10:19:53 +0200

x86/fpu/math-emu: Add support for FCMOVcc insns

Run-tested by booting with "no387 nofxsr" and running test
program:

  [RUN]   Testing fcmovCC instructions
  [OK]fcmovCC

Signed-off-by: Denys Vlasenko 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1442588010-20055-3-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/math-emu/fpu_aux.c   | 70 +++
 arch/x86/math-emu/fpu_entry.c | 18 +--
 arch/x86/math-emu/fpu_proto.h |  8 +
 3 files changed, 87 insertions(+), 9 deletions(-)

diff --git a/arch/x86/math-emu/fpu_aux.c b/arch/x86/math-emu/fpu_aux.c
index dd76a05..024f6e9 100644
--- a/arch/x86/math-emu/fpu_aux.c
+++ b/arch/x86/math-emu/fpu_aux.c
@@ -169,6 +169,76 @@ void fxch_i(void)
fpu_tag_word = tag_word;
 }
 
+static void fcmovCC(void)
+{
+   /* fcmovCC st(i) */
+   int i = FPU_rm;
+   FPU_REG *st0_ptr = (0);
+   FPU_REG *sti_ptr = (i);
+   long tag_word = fpu_tag_word;
+   int regnr = top & 7;
+   int regnri = (top + i) & 7;
+   u_char sti_tag = (tag_word >> (regnri * 2)) & 3;
+
+   if (sti_tag == TAG_Empty) {
+   FPU_stack_underflow();
+   clear_C1();
+   return;
+   }
+   reg_copy(sti_ptr, st0_ptr);
+   tag_word &= ~(3 << (regnr * 2));
+   tag_word |= (sti_tag << (regnr * 2));
+   fpu_tag_word = tag_word;
+}
+
+void fcmovb(void)
+{
+   if (FPU_EFLAGS & X86_EFLAGS_CF)
+   fcmovCC();
+}
+
+void fcmove(void)
+{
+   if (FPU_EFLAGS & X86_EFLAGS_ZF)
+   fcmovCC();
+}
+
+void fcmovbe(void)
+{
+   if (FPU_EFLAGS & (X86_EFLAGS_CF|X86_EFLAGS_ZF))
+   fcmovCC();
+}
+
+void fcmovu(void)
+{
+   if (FPU_EFLAGS & X86_EFLAGS_PF)
+   fcmovCC();
+}
+
+void fcmovnb(void)
+{
+   if (!(FPU_EFLAGS & X86_EFLAGS_CF))
+   fcmovCC();
+}
+
+void fcmovne(void)
+{
+   if (!(FPU_EFLAGS & X86_EFLAGS_ZF))
+   fcmovCC();
+}
+
+void fcmovnbe(void)
+{
+   if (!(FPU_EFLAGS & (X86_EFLAGS_CF|X86_EFLAGS_ZF)))
+   fcmovCC();
+}
+
+void fcmovnu(void)
+{
+   if (!(FPU_EFLAGS & X86_EFLAGS_PF))
+   fcmovCC();
+}
+
 void ffree_(void)
 {
/* ffree st(i) */
diff --git a/arch/x86/math-emu/fpu_entry.c b/arch/x86/math-emu/fpu_entry.c
index 4ecf683..e945fed 100644
--- a/arch/x86/math-emu/fpu_entry.c
+++ b/arch/x86/math-emu/fpu_entry.c
@@ -40,7 +40,7 @@
 
 #define __BAD__ FPU_illegal/* Illegal on an 80486, causes SIGILL */
 
-/* f(u)comi(p) are enabled if CPUID(1).EDX(15) "cmov" is set */
+/* fcmovCC and f(u)comi(p) are enabled if CPUID(1).EDX(15) "cmov" is set */
 
 /* WARNING: "u" entries are not documented by Intel in their 80486 manual
and may not work on FPU clones or later Intel FPUs.
@@ -49,13 +49,13 @@
 static FUNC const st_instr_table[64] = {
 /* Opcode: d8  d9  da  db */
 /* dc  dd  de  df */
-/* c0..7 */fadd__, fld_i_, __BAD__,__BAD__,
+/* c0..7 */fadd__, fld_i_, fcmovb, fcmovnb,
 /* c0..7 */fadd_i, ffree_, faddp_, ffreep,/*u*/
-/* c8..f */fmul__, fxch_i, __BAD__,__BAD__,
+/* c8..f */fmul__, fxch_i, fcmove, fcmovne,
 /* c8..f */fmul_i, fxch_i,/*u*/fmulp_, fxch_i,/*u*/
-/* d0..7 */fcom_st,fp_nop, __BAD__,__BAD__,
+/* d0..7 */fcom_st,fp_nop, fcmovbe,fcmovnbe,
 /* d0..7 */fcom_st,/*u*/   fst_i_, fcompst,/*u*/   fstp_i,/*u*/
-/* d8..f */fcompst,fstp_i,/*u*/__BAD__,__BAD__,
+/* d8..f */fcompst,fstp_i,/*u*/fcmovu, fcmovnu,
 /* d8..f */fcompst,/*u*/   fstp_i, fcompp, fstp_i,/*u*/
 /* e0..7 */fsub__, FPU_etc,__BAD__,finit_,
 /* e0..7 */fsubri, fucom_, fsubrp, fstsw_,
@@ -80,10 +80,10 @@ static FUNC const st_instr_table[64] = {
 
 static u_char const type_table[64] = {
 /* Opcode: d8  d9  da  db  dc  dd  de  df */
-/* c0..7 */_REGI_, _NONE_, _null_, _null_, _REGIi, _REGi_, _REGIp, _REGi_,
-/* c8..f */_REGI_, _REGIn, _null_, _null_, _REGIi, _REGI_, _REGIp, _REGI_,
-/* d0..7 */_REGIc, _NONE_, _null_, _null_, _REGIc, _REG0_, _REGIc, _REG0_,
-/* d8..f */_REGIc, _REG0_, _null_, _null_, _REGIc, _REG0_, _REGIc, _REG0_,

[tip:x86/fpu] x86/fpu/math-emu, selftests: Add tests for FCMOV and FCOMI insns

2015-09-20 Thread tip-bot for Denys Vlasenko
Commit-ID:  57ca6897cd134efd8914cc230f602abad431c7db
Gitweb: http://git.kernel.org/tip/57ca6897cd134efd8914cc230f602abad431c7db
Author: Denys Vlasenko 
AuthorDate: Thu, 17 Sep 2015 15:02:13 +0200
Committer:  Ingo Molnar 
CommitDate: Sun, 20 Sep 2015 10:19:52 +0200

x86/fpu/math-emu, selftests: Add tests for FCMOV and FCOMI insns

Signed-off-by: Denys Vlasenko 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Shuah Khan 
Cc: Thomas Gleixner 
Link: 
http://lkml.kernel.org/r/1442494933-13798-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 tools/testing/selftests/x86/Makefile |   5 +-
 tools/testing/selftests/x86/test_FCMOV.c |  93 +
 tools/testing/selftests/x86/test_FCOMI.c | 331 +++
 3 files changed, 427 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/x86/Makefile 
b/tools/testing/selftests/x86/Makefile
index 29089b2..c4c9b90 100644
--- a/tools/testing/selftests/x86/Makefile
+++ b/tools/testing/selftests/x86/Makefile
@@ -5,7 +5,8 @@ include ../lib.mk
 .PHONY: all all_32 all_64 warn_32bit_failure clean
 
 TARGETS_C_BOTHBITS := single_step_syscall sysret_ss_attrs ldt_gdt syscall_nt
-TARGETS_C_32BIT_ONLY := entry_from_vm86 syscall_arg_fault sigreturn
+TARGETS_C_32BIT_ONLY := entry_from_vm86 syscall_arg_fault sigreturn \
+   test_FCMOV test_FCOMI
 
 TARGETS_C_32BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_32BIT_ONLY)
 BINARIES_32 := $(TARGETS_C_32BIT_ALL:%=%_32)
@@ -35,7 +36,7 @@ clean:
$(RM) $(BINARIES_32) $(BINARIES_64)
 
 $(TARGETS_C_32BIT_ALL:%=%_32): %_32: %.c
-   $(CC) -m32 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $^ -lrt -ldl
+   $(CC) -m32 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $^ -lrt -ldl -lm
 
 $(TARGETS_C_BOTHBITS:%=%_64): %_64: %.c
$(CC) -m64 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $^ -lrt -ldl
diff --git a/tools/testing/selftests/x86/test_FCMOV.c 
b/tools/testing/selftests/x86/test_FCMOV.c
new file mode 100644
index 000..4adcca0
--- /dev/null
+++ b/tools/testing/selftests/x86/test_FCMOV.c
@@ -0,0 +1,93 @@
+#undef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#undef __USE_GNU
+#define __USE_GNU 1
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define TEST(insn) \
+long double __attribute__((noinline)) insn(long flags) \
+{  \
+   long double out;\
+   asm ("\n"   \
+   "   push%1""\n" \
+   "   popf""\n"   \
+   "   fldpi""\n"  \
+   "   fld1""\n"   \
+   "   " #insn " %%st(1), %%st" "\n"   \
+   "   ffree   %%st(1)" "\n"   \
+   : "=t" (out)\
+   : "r" (flags)   \
+   );  \
+   return out; \
+}
+
+TEST(fcmovb)
+TEST(fcmove)
+TEST(fcmovbe)
+TEST(fcmovu)
+TEST(fcmovnb)
+TEST(fcmovne)
+TEST(fcmovnbe)
+TEST(fcmovnu)
+
+enum {
+   CF = 1 << 0,
+   PF = 1 << 2,
+   ZF = 1 << 6,
+};
+
+void sighandler(int sig)
+{
+   printf("[FAIL]\tGot signal %d, exiting\n", sig);
+   exit(1);
+}
+
+int main(int argc, char **argv, char **envp)
+{
+   int err = 0;
+
+   /* SIGILL triggers on 32-bit kernels w/o fcomi emulation
+* when run with "no387 nofxsr". Other signals are caught
+* just in case.
+*/
+   signal(SIGILL, sighandler);
+   signal(SIGFPE, sighandler);
+   signal(SIGSEGV, sighandler);
+
+   printf("[RUN]\tTesting fcmovCC instructions\n");
+   /* If fcmovCC() returns 1.0, the move wasn't done */
+   err |= !(fcmovb(0)   == 1.0); err |= !(fcmovnb(0)  != 1.0);
+   err |= !(fcmove(0)   == 1.0); err |= !(fcmovne(0)  != 1.0);
+   err |= !(fcmovbe(0)  == 1.0); err |= !(fcmovnbe(0) != 1.0);
+   err |= !(fcmovu(0)   == 1.0); err |= !(fcmovnu(0)  != 1.0);
+
+   err |= !(fcmovb(CF)  != 1.0); err |= !(fcmovnb(CF)  == 1.0);
+   err |= !(fcmove(CF)  == 1.0); err |= !(fcmovne(CF)  != 1.0);
+   err |= !(fcmovbe(CF) != 1.0); err |= !(fcmovnbe(CF) == 1.0);
+   err |= !(fcmovu(CF)  == 1.0); err |= !(fcmovnu(CF)  != 1.0);
+
+   err |= !(fcmovb(ZF)  == 1.0); err |= !(fcmovnb(ZF)  != 1.0);
+   err |= !(fcmove(ZF)  != 1.0); err |= !(fcmovne(ZF)  == 1.0);
+   err |= !(fcmovbe(ZF) != 1.0); err |= !(fcmovnbe(ZF) == 1.0);
+   err |= !(fcmovu(ZF)  == 1.0); err |= !(fcmovnu(ZF)  != 1.0);
+
+   err |= !(fcmovb(PF)  == 1.0); err |= !(fcmovnb(PF)  != 1.0);
+   err |= !(fcmove(PF)  == 1.0); err |= !(fcmovne(PF)  != 1.0);
+   err |= !(fcmovbe(PF) == 1.0); err |= !(fcmovnbe(PF) != 1.0);
+   err |= !(fcmovu(PF)  != 1.0); err |= !(fcmovnu(PF)  == 1.0);
+
+if (!err)
+

[tip:x86/fpu] x86/fpu/math-emu: Add support for F[U]COMI[P] insns

2015-09-20 Thread tip-bot for Denys Vlasenko
Commit-ID:  b8e4a910e576961009a87d07f6b7eff67c5c2e34
Gitweb: http://git.kernel.org/tip/b8e4a910e576961009a87d07f6b7eff67c5c2e34
Author: Denys Vlasenko 
AuthorDate: Fri, 18 Sep 2015 16:53:29 +0200
Committer:  Ingo Molnar 
CommitDate: Sun, 20 Sep 2015 10:19:53 +0200

x86/fpu/math-emu: Add support for F[U]COMI[P] insns

Run-tested by booting with "no387 nofxsr" and running test
program:

  [RUN]   Testing f[u]comi[p] instructions

  [OK]f[u]comi[p]

Signed-off-by: Denys Vlasenko 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1442588010-20055-2-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/math-emu/fpu_entry.c   |  27 +
 arch/x86/math-emu/fpu_proto.h   |   4 ++
 arch/x86/math-emu/reg_compare.c | 128 
 3 files changed, 147 insertions(+), 12 deletions(-)

diff --git a/arch/x86/math-emu/fpu_entry.c b/arch/x86/math-emu/fpu_entry.c
index 65afd46..4ecf683 100644
--- a/arch/x86/math-emu/fpu_entry.c
+++ b/arch/x86/math-emu/fpu_entry.c
@@ -40,6 +40,8 @@
 
 #define __BAD__ FPU_illegal/* Illegal on an 80486, causes SIGILL */
 
+/* f(u)comi(p) are enabled if CPUID(1).EDX(15) "cmov" is set */
+
 /* WARNING: "u" entries are not documented by Intel in their 80486 manual
and may not work on FPU clones or later Intel FPUs.
Changes to support them provided by Linus Torvalds. */
@@ -57,10 +59,10 @@ static FUNC const st_instr_table[64] = {
 /* d8..f */fcompst,/*u*/   fstp_i, fcompp, fstp_i,/*u*/
 /* e0..7 */fsub__, FPU_etc,__BAD__,finit_,
 /* e0..7 */fsubri, fucom_, fsubrp, fstsw_,
-/* e8..f */fsubr_, fconst, fucompp,__BAD__,
-/* e8..f */fsub_i, fucomp, fsubp_, __BAD__,
-/* f0..7 */fdiv__, FPU_triga,  __BAD__,__BAD__,
-/* f0..7 */fdivri, __BAD__,fdivrp, __BAD__,
+/* e8..f */fsubr_, fconst, fucompp,fucomi_,
+/* e8..f */fsub_i, fucomp, fsubp_, fucomip,
+/* f0..7 */fdiv__, FPU_triga,  __BAD__,fcomi_,
+/* f0..7 */fdivri, __BAD__,fdivrp, fcomip,
 /* f8..f */fdivr_, FPU_trigb,  __BAD__,__BAD__,
 /* f8..f */fdiv_i, __BAD__,fdivp_, __BAD__,
 };
@@ -77,14 +79,15 @@ static FUNC const st_instr_table[64] = {
 #define _REGIn 0   /* Uses st(0) and st(rm), but handle checks 
later */
 
 static u_char const type_table[64] = {
-   _REGI_, _NONE_, _null_, _null_, _REGIi, _REGi_, _REGIp, _REGi_,
-   _REGI_, _REGIn, _null_, _null_, _REGIi, _REGI_, _REGIp, _REGI_,
-   _REGIc, _NONE_, _null_, _null_, _REGIc, _REG0_, _REGIc, _REG0_,
-   _REGIc, _REG0_, _null_, _null_, _REGIc, _REG0_, _REGIc, _REG0_,
-   _REGI_, _NONE_, _null_, _NONE_, _REGIi, _REGIc, _REGIp, _NONE_,
-   _REGI_, _NONE_, _REGIc, _null_, _REGIi, _REGIc, _REGIp, _null_,
-   _REGI_, _NONE_, _null_, _null_, _REGIi, _null_, _REGIp, _null_,
-   _REGI_, _NONE_, _null_, _null_, _REGIi, _null_, _REGIp, _null_
+/* Opcode: d8  d9  da  db  dc  dd  de  df */
+/* c0..7 */_REGI_, _NONE_, _null_, _null_, _REGIi, _REGi_, _REGIp, _REGi_,
+/* c8..f */_REGI_, _REGIn, _null_, _null_, _REGIi, _REGI_, _REGIp, _REGI_,
+/* d0..7 */_REGIc, _NONE_, _null_, _null_, _REGIc, _REG0_, _REGIc, _REG0_,
+/* d8..f */_REGIc, _REG0_, _null_, _null_, _REGIc, _REG0_, _REGIc, _REG0_,
+/* e0..7 */_REGI_, _NONE_, _null_, _NONE_, _REGIi, _REGIc, _REGIp, _NONE_,
+/* e8..f */_REGI_, _NONE_, _REGIc, _REGIc, _REGIi, _REGIc, _REGIp, _REGIc,
+/* f0..7 */_REGI_, _NONE_, _null_, _REGIc, _REGIi, _null_, _REGIp, _REGIc,
+/* f8..f */_REGI_, _NONE_, _null_, _null_, _REGIi, _null_, _REGIp, _null_,
 };
 
 #ifdef RE_ENTRANT_CHECKING
diff --git a/arch/x86/math-emu/fpu_proto.h b/arch/x86/math-emu/fpu_proto.h
index 9779df4..1f8d130 100644
--- a/arch/x86/math-emu/fpu_proto.h
+++ b/arch/x86/math-emu/fpu_proto.h
@@ -108,6 +108,10 @@ extern void fcompp(void);
 extern void fucom_(void);
 extern void fucomp(void);
 extern void fucompp(void);
+extern void fcomi_(void);
+extern void fcomip(void);
+extern void fucomi_(void);
+extern void fucomip(void);
 /* reg_constant.c */
 extern void fconst(void);
 /* reg_ld_str.c */
diff --git a/arch/x86/math-emu/reg_compare.c b/arch/x86/math-emu/reg_compare.c
index ecce55f..b77360f 100644
--- a/arch/x86/math-emu/reg_compare.c
+++ b/arch/x86/math-emu/reg_compare.c
@@ -249,6 +249,54 @@ static int compare_st_st(int nr)
return 0;
 }
 
+static int compare_i_st_st(int nr)
+{
+   int f, c;
+   FPU_REG *st_ptr;
+
+   if (!NOT_EMPTY(0) || !NOT_EMPTY(nr)) {
+   FPU_EFLAGS |= 

[tip:x86/fpu] x86/fpu/math-emu: Remove define layer for undocumented opcodes

2015-09-20 Thread tip-bot for Denys Vlasenko
Commit-ID:  4aef363e48177d451b4d263c69dd2c86437e988b
Gitweb: http://git.kernel.org/tip/4aef363e48177d451b4d263c69dd2c86437e988b
Author: Denys Vlasenko 
AuthorDate: Fri, 18 Sep 2015 16:53:28 +0200
Committer:  Ingo Molnar 
CommitDate: Sun, 20 Sep 2015 10:19:52 +0200

x86/fpu/math-emu: Remove define layer for undocumented opcodes

No code changes.

Signed-off-by: Denys Vlasenko 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1442588010-20055-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/math-emu/fpu_entry.c | 43 +--
 1 file changed, 21 insertions(+), 22 deletions(-)

diff --git a/arch/x86/math-emu/fpu_entry.c b/arch/x86/math-emu/fpu_entry.c
index 929b1d5..65afd46 100644
--- a/arch/x86/math-emu/fpu_entry.c
+++ b/arch/x86/math-emu/fpu_entry.c
@@ -40,30 +40,29 @@
 
 #define __BAD__ FPU_illegal/* Illegal on an 80486, causes SIGILL */
 
-/* WARNING: These codes are not documented by Intel in their 80486 manual
-   and may not work on FPU clones or later Intel FPUs. */
-
-/* Changes to support the un-doc codes provided by Linus Torvalds. */
-
-#define _d9_d8_ fstp_i /* unofficial code (19) */
-#define _dc_d0_ fcom_st/* unofficial code (14) */
-#define _dc_d8_ fcompst/* unofficial code (1c) */
-#define _dd_c8_ fxch_i /* unofficial code (0d) */
-#define _de_d0_ fcompst/* unofficial code (16) */
-#define _df_c0_ ffreep /* unofficial code (07) ffree + pop */
-#define _df_c8_ fxch_i /* unofficial code (0f) */
-#define _df_d0_ fstp_i /* unofficial code (17) */
-#define _df_d8_ fstp_i /* unofficial code (1f) */
+/* WARNING: "u" entries are not documented by Intel in their 80486 manual
+   and may not work on FPU clones or later Intel FPUs.
+   Changes to support them provided by Linus Torvalds. */
 
 static FUNC const st_instr_table[64] = {
-   fadd__, fld_i_, __BAD__, __BAD__, fadd_i, ffree_, faddp_, _df_c0_,
-   fmul__, fxch_i, __BAD__, __BAD__, fmul_i, _dd_c8_, fmulp_, _df_c8_,
-   fcom_st, fp_nop, __BAD__, __BAD__, _dc_d0_, fst_i_, _de_d0_, _df_d0_,
-   fcompst, _d9_d8_, __BAD__, __BAD__, _dc_d8_, fstp_i, fcompp, _df_d8_,
-   fsub__, FPU_etc, __BAD__, finit_, fsubri, fucom_, fsubrp, fstsw_,
-   fsubr_, fconst, fucompp, __BAD__, fsub_i, fucomp, fsubp_, __BAD__,
-   fdiv__, FPU_triga, __BAD__, __BAD__, fdivri, __BAD__, fdivrp, __BAD__,
-   fdivr_, FPU_trigb, __BAD__, __BAD__, fdiv_i, __BAD__, fdivp_, __BAD__,
+/* Opcode: d8  d9  da  db */
+/* dc  dd  de  df */
+/* c0..7 */fadd__, fld_i_, __BAD__,__BAD__,
+/* c0..7 */fadd_i, ffree_, faddp_, ffreep,/*u*/
+/* c8..f */fmul__, fxch_i, __BAD__,__BAD__,
+/* c8..f */fmul_i, fxch_i,/*u*/fmulp_, fxch_i,/*u*/
+/* d0..7 */fcom_st,fp_nop, __BAD__,__BAD__,
+/* d0..7 */fcom_st,/*u*/   fst_i_, fcompst,/*u*/   fstp_i,/*u*/
+/* d8..f */fcompst,fstp_i,/*u*/__BAD__,__BAD__,
+/* d8..f */fcompst,/*u*/   fstp_i, fcompp, fstp_i,/*u*/
+/* e0..7 */fsub__, FPU_etc,__BAD__,finit_,
+/* e0..7 */fsubri, fucom_, fsubrp, fstsw_,
+/* e8..f */fsubr_, fconst, fucompp,__BAD__,
+/* e8..f */fsub_i, fucomp, fsubp_, __BAD__,
+/* f0..7 */fdiv__, FPU_triga,  __BAD__,__BAD__,
+/* f0..7 */fdivri, __BAD__,fdivrp, __BAD__,
+/* f8..f */fdivr_, FPU_trigb,  __BAD__,__BAD__,
+/* f8..f */fdiv_i, __BAD__,fdivp_, __BAD__,
 };
 
 #define _NONE_ 0   /* Take no special action */
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/fpu] x86/fpu/math-emu, selftests: Add tests for FCMOV and FCOMI insns

2015-09-20 Thread tip-bot for Denys Vlasenko
Commit-ID:  57ca6897cd134efd8914cc230f602abad431c7db
Gitweb: http://git.kernel.org/tip/57ca6897cd134efd8914cc230f602abad431c7db
Author: Denys Vlasenko 
AuthorDate: Thu, 17 Sep 2015 15:02:13 +0200
Committer:  Ingo Molnar 
CommitDate: Sun, 20 Sep 2015 10:19:52 +0200

x86/fpu/math-emu, selftests: Add tests for FCMOV and FCOMI insns

Signed-off-by: Denys Vlasenko 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Shuah Khan 
Cc: Thomas Gleixner 
Link: 
http://lkml.kernel.org/r/1442494933-13798-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 tools/testing/selftests/x86/Makefile |   5 +-
 tools/testing/selftests/x86/test_FCMOV.c |  93 +
 tools/testing/selftests/x86/test_FCOMI.c | 331 +++
 3 files changed, 427 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/x86/Makefile 
b/tools/testing/selftests/x86/Makefile
index 29089b2..c4c9b90 100644
--- a/tools/testing/selftests/x86/Makefile
+++ b/tools/testing/selftests/x86/Makefile
@@ -5,7 +5,8 @@ include ../lib.mk
 .PHONY: all all_32 all_64 warn_32bit_failure clean
 
 TARGETS_C_BOTHBITS := single_step_syscall sysret_ss_attrs ldt_gdt syscall_nt
-TARGETS_C_32BIT_ONLY := entry_from_vm86 syscall_arg_fault sigreturn
+TARGETS_C_32BIT_ONLY := entry_from_vm86 syscall_arg_fault sigreturn \
+   test_FCMOV test_FCOMI
 
 TARGETS_C_32BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_32BIT_ONLY)
 BINARIES_32 := $(TARGETS_C_32BIT_ALL:%=%_32)
@@ -35,7 +36,7 @@ clean:
$(RM) $(BINARIES_32) $(BINARIES_64)
 
 $(TARGETS_C_32BIT_ALL:%=%_32): %_32: %.c
-   $(CC) -m32 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $^ -lrt -ldl
+   $(CC) -m32 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $^ -lrt -ldl -lm
 
 $(TARGETS_C_BOTHBITS:%=%_64): %_64: %.c
$(CC) -m64 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $^ -lrt -ldl
diff --git a/tools/testing/selftests/x86/test_FCMOV.c 
b/tools/testing/selftests/x86/test_FCMOV.c
new file mode 100644
index 000..4adcca0
--- /dev/null
+++ b/tools/testing/selftests/x86/test_FCMOV.c
@@ -0,0 +1,93 @@
+#undef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#undef __USE_GNU
+#define __USE_GNU 1
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define TEST(insn) \
+long double __attribute__((noinline)) insn(long flags) \
+{  \
+   long double out;\
+   asm ("\n"   \
+   "   push%1""\n" \
+   "   popf""\n"   \
+   "   fldpi""\n"  \
+   "   fld1""\n"   \
+   "   " #insn " %%st(1), %%st" "\n"   \
+   "   ffree   %%st(1)" "\n"   \
+   : "=t" (out)\
+   : "r" (flags)   \
+   );  \
+   return out; \
+}
+
+TEST(fcmovb)
+TEST(fcmove)
+TEST(fcmovbe)
+TEST(fcmovu)
+TEST(fcmovnb)
+TEST(fcmovne)
+TEST(fcmovnbe)
+TEST(fcmovnu)
+
+enum {
+   CF = 1 << 0,
+   PF = 1 << 2,
+   ZF = 1 << 6,
+};
+
+void sighandler(int sig)
+{
+   printf("[FAIL]\tGot signal %d, exiting\n", sig);
+   exit(1);
+}
+
+int main(int argc, char **argv, char **envp)
+{
+   int err = 0;
+
+   /* SIGILL triggers on 32-bit kernels w/o fcomi emulation
+* when run with "no387 nofxsr". Other signals are caught
+* just in case.
+*/
+   signal(SIGILL, sighandler);
+   signal(SIGFPE, sighandler);
+   signal(SIGSEGV, sighandler);
+
+   printf("[RUN]\tTesting fcmovCC instructions\n");
+   /* If fcmovCC() returns 1.0, the move wasn't done */
+   err |= !(fcmovb(0)   == 1.0); err |= !(fcmovnb(0)  != 1.0);
+   err |= !(fcmove(0)   == 1.0); err |= !(fcmovne(0)  != 1.0);
+   err |= !(fcmovbe(0)  == 1.0); err |= !(fcmovnbe(0) != 1.0);
+   err |= !(fcmovu(0)   == 1.0); err |= !(fcmovnu(0)  != 1.0);
+
+   err |= !(fcmovb(CF)  != 1.0); err |= !(fcmovnb(CF)  == 1.0);
+   err |= !(fcmove(CF)  == 1.0); err |= !(fcmovne(CF)  != 1.0);
+   err |= !(fcmovbe(CF) != 1.0); err |= !(fcmovnbe(CF) == 1.0);
+   err |= !(fcmovu(CF)  == 1.0); err |= !(fcmovnu(CF)  != 1.0);
+
+   err |= !(fcmovb(ZF)  == 1.0); err |= !(fcmovnb(ZF)  != 1.0);
+   err |= !(fcmove(ZF)  != 1.0); err |= !(fcmovne(ZF)  == 1.0);
+   err |= !(fcmovbe(ZF) != 1.0); err |= !(fcmovnbe(ZF) == 1.0);
+   err |= !(fcmovu(ZF)  == 1.0); err |= !(fcmovnu(ZF)  != 1.0);
+
+   err |= !(fcmovb(PF)  == 1.0); err |= 

[tip:x86/fpu] x86/fpu/math-emu: Add support for F[U]COMI[P] insns

2015-09-20 Thread tip-bot for Denys Vlasenko
Commit-ID:  b8e4a910e576961009a87d07f6b7eff67c5c2e34
Gitweb: http://git.kernel.org/tip/b8e4a910e576961009a87d07f6b7eff67c5c2e34
Author: Denys Vlasenko 
AuthorDate: Fri, 18 Sep 2015 16:53:29 +0200
Committer:  Ingo Molnar 
CommitDate: Sun, 20 Sep 2015 10:19:53 +0200

x86/fpu/math-emu: Add support for F[U]COMI[P] insns

Run-tested by booting with "no387 nofxsr" and running test
program:

  [RUN]   Testing f[u]comi[p] instructions

  [OK]f[u]comi[p]

Signed-off-by: Denys Vlasenko 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1442588010-20055-2-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/math-emu/fpu_entry.c   |  27 +
 arch/x86/math-emu/fpu_proto.h   |   4 ++
 arch/x86/math-emu/reg_compare.c | 128 
 3 files changed, 147 insertions(+), 12 deletions(-)

diff --git a/arch/x86/math-emu/fpu_entry.c b/arch/x86/math-emu/fpu_entry.c
index 65afd46..4ecf683 100644
--- a/arch/x86/math-emu/fpu_entry.c
+++ b/arch/x86/math-emu/fpu_entry.c
@@ -40,6 +40,8 @@
 
 #define __BAD__ FPU_illegal/* Illegal on an 80486, causes SIGILL */
 
+/* f(u)comi(p) are enabled if CPUID(1).EDX(15) "cmov" is set */
+
 /* WARNING: "u" entries are not documented by Intel in their 80486 manual
and may not work on FPU clones or later Intel FPUs.
Changes to support them provided by Linus Torvalds. */
@@ -57,10 +59,10 @@ static FUNC const st_instr_table[64] = {
 /* d8..f */fcompst,/*u*/   fstp_i, fcompp, fstp_i,/*u*/
 /* e0..7 */fsub__, FPU_etc,__BAD__,finit_,
 /* e0..7 */fsubri, fucom_, fsubrp, fstsw_,
-/* e8..f */fsubr_, fconst, fucompp,__BAD__,
-/* e8..f */fsub_i, fucomp, fsubp_, __BAD__,
-/* f0..7 */fdiv__, FPU_triga,  __BAD__,__BAD__,
-/* f0..7 */fdivri, __BAD__,fdivrp, __BAD__,
+/* e8..f */fsubr_, fconst, fucompp,fucomi_,
+/* e8..f */fsub_i, fucomp, fsubp_, fucomip,
+/* f0..7 */fdiv__, FPU_triga,  __BAD__,fcomi_,
+/* f0..7 */fdivri, __BAD__,fdivrp, fcomip,
 /* f8..f */fdivr_, FPU_trigb,  __BAD__,__BAD__,
 /* f8..f */fdiv_i, __BAD__,fdivp_, __BAD__,
 };
@@ -77,14 +79,15 @@ static FUNC const st_instr_table[64] = {
 #define _REGIn 0   /* Uses st(0) and st(rm), but handle checks 
later */
 
 static u_char const type_table[64] = {
-   _REGI_, _NONE_, _null_, _null_, _REGIi, _REGi_, _REGIp, _REGi_,
-   _REGI_, _REGIn, _null_, _null_, _REGIi, _REGI_, _REGIp, _REGI_,
-   _REGIc, _NONE_, _null_, _null_, _REGIc, _REG0_, _REGIc, _REG0_,
-   _REGIc, _REG0_, _null_, _null_, _REGIc, _REG0_, _REGIc, _REG0_,
-   _REGI_, _NONE_, _null_, _NONE_, _REGIi, _REGIc, _REGIp, _NONE_,
-   _REGI_, _NONE_, _REGIc, _null_, _REGIi, _REGIc, _REGIp, _null_,
-   _REGI_, _NONE_, _null_, _null_, _REGIi, _null_, _REGIp, _null_,
-   _REGI_, _NONE_, _null_, _null_, _REGIi, _null_, _REGIp, _null_
+/* Opcode: d8  d9  da  db  dc  dd  de  df */
+/* c0..7 */_REGI_, _NONE_, _null_, _null_, _REGIi, _REGi_, _REGIp, _REGi_,
+/* c8..f */_REGI_, _REGIn, _null_, _null_, _REGIi, _REGI_, _REGIp, _REGI_,
+/* d0..7 */_REGIc, _NONE_, _null_, _null_, _REGIc, _REG0_, _REGIc, _REG0_,
+/* d8..f */_REGIc, _REG0_, _null_, _null_, _REGIc, _REG0_, _REGIc, _REG0_,
+/* e0..7 */_REGI_, _NONE_, _null_, _NONE_, _REGIi, _REGIc, _REGIp, _NONE_,
+/* e8..f */_REGI_, _NONE_, _REGIc, _REGIc, _REGIi, _REGIc, _REGIp, _REGIc,
+/* f0..7 */_REGI_, _NONE_, _null_, _REGIc, _REGIi, _null_, _REGIp, _REGIc,
+/* f8..f */_REGI_, _NONE_, _null_, _null_, _REGIi, _null_, _REGIp, _null_,
 };
 
 #ifdef RE_ENTRANT_CHECKING
diff --git a/arch/x86/math-emu/fpu_proto.h b/arch/x86/math-emu/fpu_proto.h
index 9779df4..1f8d130 100644
--- a/arch/x86/math-emu/fpu_proto.h
+++ b/arch/x86/math-emu/fpu_proto.h
@@ -108,6 +108,10 @@ extern void fcompp(void);
 extern void fucom_(void);
 extern void fucomp(void);
 extern void fucompp(void);
+extern void fcomi_(void);
+extern void fcomip(void);
+extern void fucomi_(void);
+extern void fucomip(void);
 /* reg_constant.c */
 extern void fconst(void);
 /* reg_ld_str.c */
diff --git a/arch/x86/math-emu/reg_compare.c b/arch/x86/math-emu/reg_compare.c
index ecce55f..b77360f 100644
--- a/arch/x86/math-emu/reg_compare.c
+++ 

[tip:x86/fpu] x86/fpu/math-emu: Add support for FCMOVcc insns

2015-09-20 Thread tip-bot for Denys Vlasenko
Commit-ID:  9a9d8642d03a7512f78cbe7ed6a2011fad3cbca3
Gitweb: http://git.kernel.org/tip/9a9d8642d03a7512f78cbe7ed6a2011fad3cbca3
Author: Denys Vlasenko 
AuthorDate: Fri, 18 Sep 2015 16:53:30 +0200
Committer:  Ingo Molnar 
CommitDate: Sun, 20 Sep 2015 10:19:53 +0200

x86/fpu/math-emu: Add support for FCMOVcc insns

Run-tested by booting with "no387 nofxsr" and running test
program:

  [RUN]   Testing fcmovCC instructions
  [OK]fcmovCC

Signed-off-by: Denys Vlasenko 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1442588010-20055-3-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/math-emu/fpu_aux.c   | 70 +++
 arch/x86/math-emu/fpu_entry.c | 18 +--
 arch/x86/math-emu/fpu_proto.h |  8 +
 3 files changed, 87 insertions(+), 9 deletions(-)

diff --git a/arch/x86/math-emu/fpu_aux.c b/arch/x86/math-emu/fpu_aux.c
index dd76a05..024f6e9 100644
--- a/arch/x86/math-emu/fpu_aux.c
+++ b/arch/x86/math-emu/fpu_aux.c
@@ -169,6 +169,76 @@ void fxch_i(void)
fpu_tag_word = tag_word;
 }
 
+static void fcmovCC(void)
+{
+   /* fcmovCC st(i) */
+   int i = FPU_rm;
+   FPU_REG *st0_ptr = (0);
+   FPU_REG *sti_ptr = (i);
+   long tag_word = fpu_tag_word;
+   int regnr = top & 7;
+   int regnri = (top + i) & 7;
+   u_char sti_tag = (tag_word >> (regnri * 2)) & 3;
+
+   if (sti_tag == TAG_Empty) {
+   FPU_stack_underflow();
+   clear_C1();
+   return;
+   }
+   reg_copy(sti_ptr, st0_ptr);
+   tag_word &= ~(3 << (regnr * 2));
+   tag_word |= (sti_tag << (regnr * 2));
+   fpu_tag_word = tag_word;
+}
+
+void fcmovb(void)
+{
+   if (FPU_EFLAGS & X86_EFLAGS_CF)
+   fcmovCC();
+}
+
+void fcmove(void)
+{
+   if (FPU_EFLAGS & X86_EFLAGS_ZF)
+   fcmovCC();
+}
+
+void fcmovbe(void)
+{
+   if (FPU_EFLAGS & (X86_EFLAGS_CF|X86_EFLAGS_ZF))
+   fcmovCC();
+}
+
+void fcmovu(void)
+{
+   if (FPU_EFLAGS & X86_EFLAGS_PF)
+   fcmovCC();
+}
+
+void fcmovnb(void)
+{
+   if (!(FPU_EFLAGS & X86_EFLAGS_CF))
+   fcmovCC();
+}
+
+void fcmovne(void)
+{
+   if (!(FPU_EFLAGS & X86_EFLAGS_ZF))
+   fcmovCC();
+}
+
+void fcmovnbe(void)
+{
+   if (!(FPU_EFLAGS & (X86_EFLAGS_CF|X86_EFLAGS_ZF)))
+   fcmovCC();
+}
+
+void fcmovnu(void)
+{
+   if (!(FPU_EFLAGS & X86_EFLAGS_PF))
+   fcmovCC();
+}
+
 void ffree_(void)
 {
/* ffree st(i) */
diff --git a/arch/x86/math-emu/fpu_entry.c b/arch/x86/math-emu/fpu_entry.c
index 4ecf683..e945fed 100644
--- a/arch/x86/math-emu/fpu_entry.c
+++ b/arch/x86/math-emu/fpu_entry.c
@@ -40,7 +40,7 @@
 
 #define __BAD__ FPU_illegal/* Illegal on an 80486, causes SIGILL */
 
-/* f(u)comi(p) are enabled if CPUID(1).EDX(15) "cmov" is set */
+/* fcmovCC and f(u)comi(p) are enabled if CPUID(1).EDX(15) "cmov" is set */
 
 /* WARNING: "u" entries are not documented by Intel in their 80486 manual
and may not work on FPU clones or later Intel FPUs.
@@ -49,13 +49,13 @@
 static FUNC const st_instr_table[64] = {
 /* Opcode: d8  d9  da  db */
 /* dc  dd  de  df */
-/* c0..7 */fadd__, fld_i_, __BAD__,__BAD__,
+/* c0..7 */fadd__, fld_i_, fcmovb, fcmovnb,
 /* c0..7 */fadd_i, ffree_, faddp_, ffreep,/*u*/
-/* c8..f */fmul__, fxch_i, __BAD__,__BAD__,
+/* c8..f */fmul__, fxch_i, fcmove, fcmovne,
 /* c8..f */fmul_i, fxch_i,/*u*/fmulp_, fxch_i,/*u*/
-/* d0..7 */fcom_st,fp_nop, __BAD__,__BAD__,
+/* d0..7 */fcom_st,fp_nop, fcmovbe,fcmovnbe,
 /* d0..7 */fcom_st,/*u*/   fst_i_, fcompst,/*u*/   fstp_i,/*u*/
-/* d8..f */fcompst,fstp_i,/*u*/__BAD__,__BAD__,
+/* d8..f */fcompst,fstp_i,/*u*/fcmovu, fcmovnu,
 /* d8..f */fcompst,/*u*/   fstp_i, fcompp, fstp_i,/*u*/
 /* e0..7 */fsub__, FPU_etc,__BAD__,finit_,
 /* e0..7 */fsubri, fucom_, fsubrp, fstsw_,
@@ -80,10 +80,10 @@ static FUNC const st_instr_table[64] = {
 
 static u_char const type_table[64] = {
 /* Opcode: d8  d9  da  db  dc  dd  de  df */
-/* c0..7 */_REGI_, _NONE_, _null_, _null_, _REGIi, _REGi_, _REGIp, 

[tip:x86/fpu] x86/fpu/math-emu: Remove define layer for undocumented opcodes

2015-09-20 Thread tip-bot for Denys Vlasenko
Commit-ID:  4aef363e48177d451b4d263c69dd2c86437e988b
Gitweb: http://git.kernel.org/tip/4aef363e48177d451b4d263c69dd2c86437e988b
Author: Denys Vlasenko 
AuthorDate: Fri, 18 Sep 2015 16:53:28 +0200
Committer:  Ingo Molnar 
CommitDate: Sun, 20 Sep 2015 10:19:52 +0200

x86/fpu/math-emu: Remove define layer for undocumented opcodes

No code changes.

Signed-off-by: Denys Vlasenko 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1442588010-20055-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/math-emu/fpu_entry.c | 43 +--
 1 file changed, 21 insertions(+), 22 deletions(-)

diff --git a/arch/x86/math-emu/fpu_entry.c b/arch/x86/math-emu/fpu_entry.c
index 929b1d5..65afd46 100644
--- a/arch/x86/math-emu/fpu_entry.c
+++ b/arch/x86/math-emu/fpu_entry.c
@@ -40,30 +40,29 @@
 
 #define __BAD__ FPU_illegal/* Illegal on an 80486, causes SIGILL */
 
-/* WARNING: These codes are not documented by Intel in their 80486 manual
-   and may not work on FPU clones or later Intel FPUs. */
-
-/* Changes to support the un-doc codes provided by Linus Torvalds. */
-
-#define _d9_d8_ fstp_i /* unofficial code (19) */
-#define _dc_d0_ fcom_st/* unofficial code (14) */
-#define _dc_d8_ fcompst/* unofficial code (1c) */
-#define _dd_c8_ fxch_i /* unofficial code (0d) */
-#define _de_d0_ fcompst/* unofficial code (16) */
-#define _df_c0_ ffreep /* unofficial code (07) ffree + pop */
-#define _df_c8_ fxch_i /* unofficial code (0f) */
-#define _df_d0_ fstp_i /* unofficial code (17) */
-#define _df_d8_ fstp_i /* unofficial code (1f) */
+/* WARNING: "u" entries are not documented by Intel in their 80486 manual
+   and may not work on FPU clones or later Intel FPUs.
+   Changes to support them provided by Linus Torvalds. */
 
 static FUNC const st_instr_table[64] = {
-   fadd__, fld_i_, __BAD__, __BAD__, fadd_i, ffree_, faddp_, _df_c0_,
-   fmul__, fxch_i, __BAD__, __BAD__, fmul_i, _dd_c8_, fmulp_, _df_c8_,
-   fcom_st, fp_nop, __BAD__, __BAD__, _dc_d0_, fst_i_, _de_d0_, _df_d0_,
-   fcompst, _d9_d8_, __BAD__, __BAD__, _dc_d8_, fstp_i, fcompp, _df_d8_,
-   fsub__, FPU_etc, __BAD__, finit_, fsubri, fucom_, fsubrp, fstsw_,
-   fsubr_, fconst, fucompp, __BAD__, fsub_i, fucomp, fsubp_, __BAD__,
-   fdiv__, FPU_triga, __BAD__, __BAD__, fdivri, __BAD__, fdivrp, __BAD__,
-   fdivr_, FPU_trigb, __BAD__, __BAD__, fdiv_i, __BAD__, fdivp_, __BAD__,
+/* Opcode: d8  d9  da  db */
+/* dc  dd  de  df */
+/* c0..7 */fadd__, fld_i_, __BAD__,__BAD__,
+/* c0..7 */fadd_i, ffree_, faddp_, ffreep,/*u*/
+/* c8..f */fmul__, fxch_i, __BAD__,__BAD__,
+/* c8..f */fmul_i, fxch_i,/*u*/fmulp_, fxch_i,/*u*/
+/* d0..7 */fcom_st,fp_nop, __BAD__,__BAD__,
+/* d0..7 */fcom_st,/*u*/   fst_i_, fcompst,/*u*/   fstp_i,/*u*/
+/* d8..f */fcompst,fstp_i,/*u*/__BAD__,__BAD__,
+/* d8..f */fcompst,/*u*/   fstp_i, fcompp, fstp_i,/*u*/
+/* e0..7 */fsub__, FPU_etc,__BAD__,finit_,
+/* e0..7 */fsubri, fucom_, fsubrp, fstsw_,
+/* e8..f */fsubr_, fconst, fucompp,__BAD__,
+/* e8..f */fsub_i, fucomp, fsubp_, __BAD__,
+/* f0..7 */fdiv__, FPU_triga,  __BAD__,__BAD__,
+/* f0..7 */fdivri, __BAD__,fdivrp, __BAD__,
+/* f8..f */fdivr_, FPU_trigb,  __BAD__,__BAD__,
+/* f8..f */fdiv_i, __BAD__,fdivp_, __BAD__,
 };
 
 #define _NONE_ 0   /* Take no special action */
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/asm] x86/asm/entry/32, selftests: Add 'test_syscall_vdso ' test

2015-09-18 Thread tip-bot for Denys Vlasenko
Commit-ID:  c25be94f2870bf75552a41ad8b15f756e19ffb1d
Gitweb: http://git.kernel.org/tip/c25be94f2870bf75552a41ad8b15f756e19ffb1d
Author: Denys Vlasenko 
AuthorDate: Wed, 16 Sep 2015 20:23:29 +0200
Committer:  Ingo Molnar 
CommitDate: Fri, 18 Sep 2015 09:40:48 +0200

x86/asm/entry/32, selftests: Add 'test_syscall_vdso' test

This new test checks that all x86 registers are preserved across
32-bit syscalls. It tests syscalls through VDSO (if available)
and through INT 0x80, normally and under ptrace.

If kernel is a 64-bit one, high registers (r8..r15) are poisoned
before the syscall is called and are checked afterwards.

They must be either preserved, or cleared to zero (but r11 is
special); r12..15 must be preserved for INT 0x80.

EFLAGS is checked for changes too, but change there is not
considered to be a bug (paravirt kernels do not preserve
arithmetic flags).

Run-tested on 64-bit kernel:

$ ./test_syscall_vdso_32
[RUN]   Executing 6-argument 32-bit syscall via VDSO
[OK]Arguments are preserved across syscall
[NOTE]  R11 has changed:00200ed7 - assuming clobbered by
SYSRET insn [OK]R8..R15 did not leak kernel data
[RUN]   Executing 6-argument 32-bit syscall via INT 80
[OK]Arguments are preserved across syscall
[OK]R8..R15 did not leak kernel data
[RUN]   Running tests under ptrace
[RUN]   Executing 6-argument 32-bit syscall via VDSO
[OK]Arguments are preserved across syscall
[OK]R8..R15 did not leak kernel data
[RUN]   Executing 6-argument 32-bit syscall via INT 80
[OK]Arguments are preserved across syscall
[OK]R8..R15 did not leak kernel data

On 32-bit paravirt kernel:

$ ./test_syscall_vdso_32
[NOTE]  Not a 64-bit kernel, won't test R8..R15 leaks
[RUN]   Executing 6-argument 32-bit syscall via VDSO
[WARN]  Flags before=00200ed7 id 0 00 o d i s z 0 a 0 p 1 c
[WARN]  Flags  after=00200246 id 0 00 i z 0 0 p 1
[WARN]  Flags change=0c91 0 00 o d s 0 a 0 0 c
[OK]Arguments are preserved across syscall
[RUN]   Executing 6-argument 32-bit syscall via INT 80
[OK]Arguments are preserved across syscall
[RUN]   Running tests under ptrace
[RUN]   Executing 6-argument 32-bit syscall via VDSO
[OK]Arguments are preserved across syscall
[RUN]   Executing 6-argument 32-bit syscall via INT 80
[OK]Arguments are preserved across syscall

Signed-off-by: Denys Vlasenko 
Acked-by: Andy Lutomirski 
Cc: Alexei Starovoitov 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Frederic Weisbecker 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Oleg Nesterov 
Cc: Peter Zijlstra 
Cc: Shuah Khan 
Cc: Steven Rostedt 
Cc: Thomas Gleixner 
Cc: Will Drewry 
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1442427809-2027-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 tools/testing/selftests/x86/Makefile   |   3 +-
 tools/testing/selftests/x86/test_syscall_vdso.c| 401 +
 .../selftests/x86/{thunks.S => thunks_32.S}|  66 ++--
 3 files changed, 430 insertions(+), 40 deletions(-)

diff --git a/tools/testing/selftests/x86/Makefile 
b/tools/testing/selftests/x86/Makefile
index 29089b2..fd55bc3 100644
--- a/tools/testing/selftests/x86/Makefile
+++ b/tools/testing/selftests/x86/Makefile
@@ -5,7 +5,7 @@ include ../lib.mk
 .PHONY: all all_32 all_64 warn_32bit_failure clean
 
 TARGETS_C_BOTHBITS := single_step_syscall sysret_ss_attrs ldt_gdt syscall_nt
-TARGETS_C_32BIT_ONLY := entry_from_vm86 syscall_arg_fault sigreturn
+TARGETS_C_32BIT_ONLY := entry_from_vm86 syscall_arg_fault sigreturn 
test_syscall_vdso
 
 TARGETS_C_32BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_32BIT_ONLY)
 BINARIES_32 := $(TARGETS_C_32BIT_ALL:%=%_32)
@@ -60,3 +60,4 @@ endif
 
 # Some tests have additional dependencies.
 sysret_ss_attrs_64: thunks.S
+test_syscall_vdso_32: thunks_32.S
diff --git a/tools/testing/selftests/x86/test_syscall_vdso.c 
b/tools/testing/selftests/x86/test_syscall_vdso.c
new file mode 100644
index 000..4037035
--- /dev/null
+++ b/tools/testing/selftests/x86/test_syscall_vdso.c
@@ -0,0 +1,401 @@
+/*
+ * 32-bit syscall ABI conformance test.
+ *
+ * Copyright (c) 2015 Denys Vlasenko
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ */
+/*
+ * Can be built statically:
+ * gcc -Os -Wall -static -m32 test_syscall_vdso.c thunks_32.S
+ */
+#undef 

[tip:x86/asm] x86/asm/entry/32, selftests: Add 'test_syscall_vdso ' test

2015-09-18 Thread tip-bot for Denys Vlasenko
Commit-ID:  c25be94f2870bf75552a41ad8b15f756e19ffb1d
Gitweb: http://git.kernel.org/tip/c25be94f2870bf75552a41ad8b15f756e19ffb1d
Author: Denys Vlasenko 
AuthorDate: Wed, 16 Sep 2015 20:23:29 +0200
Committer:  Ingo Molnar 
CommitDate: Fri, 18 Sep 2015 09:40:48 +0200

x86/asm/entry/32, selftests: Add 'test_syscall_vdso' test

This new test checks that all x86 registers are preserved across
32-bit syscalls. It tests syscalls through VDSO (if available)
and through INT 0x80, normally and under ptrace.

If kernel is a 64-bit one, high registers (r8..r15) are poisoned
before the syscall is called and are checked afterwards.

They must be either preserved, or cleared to zero (but r11 is
special); r12..15 must be preserved for INT 0x80.

EFLAGS is checked for changes too, but change there is not
considered to be a bug (paravirt kernels do not preserve
arithmetic flags).

Run-tested on 64-bit kernel:

$ ./test_syscall_vdso_32
[RUN]   Executing 6-argument 32-bit syscall via VDSO
[OK]Arguments are preserved across syscall
[NOTE]  R11 has changed:00200ed7 - assuming clobbered by
SYSRET insn [OK]R8..R15 did not leak kernel data
[RUN]   Executing 6-argument 32-bit syscall via INT 80
[OK]Arguments are preserved across syscall
[OK]R8..R15 did not leak kernel data
[RUN]   Running tests under ptrace
[RUN]   Executing 6-argument 32-bit syscall via VDSO
[OK]Arguments are preserved across syscall
[OK]R8..R15 did not leak kernel data
[RUN]   Executing 6-argument 32-bit syscall via INT 80
[OK]Arguments are preserved across syscall
[OK]R8..R15 did not leak kernel data

On 32-bit paravirt kernel:

$ ./test_syscall_vdso_32
[NOTE]  Not a 64-bit kernel, won't test R8..R15 leaks
[RUN]   Executing 6-argument 32-bit syscall via VDSO
[WARN]  Flags before=00200ed7 id 0 00 o d i s z 0 a 0 p 1 c
[WARN]  Flags  after=00200246 id 0 00 i z 0 0 p 1
[WARN]  Flags change=0c91 0 00 o d s 0 a 0 0 c
[OK]Arguments are preserved across syscall
[RUN]   Executing 6-argument 32-bit syscall via INT 80
[OK]Arguments are preserved across syscall
[RUN]   Running tests under ptrace
[RUN]   Executing 6-argument 32-bit syscall via VDSO
[OK]Arguments are preserved across syscall
[RUN]   Executing 6-argument 32-bit syscall via INT 80
[OK]Arguments are preserved across syscall

Signed-off-by: Denys Vlasenko 
Acked-by: Andy Lutomirski 
Cc: Alexei Starovoitov 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Frederic Weisbecker 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Oleg Nesterov 
Cc: Peter Zijlstra 
Cc: Shuah Khan 
Cc: Steven Rostedt 
Cc: Thomas Gleixner 
Cc: Will Drewry 
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1442427809-2027-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 tools/testing/selftests/x86/Makefile   |   3 +-
 tools/testing/selftests/x86/test_syscall_vdso.c| 401 +
 .../selftests/x86/{thunks.S => thunks_32.S}|  66 ++--
 3 files changed, 430 insertions(+), 40 deletions(-)

diff --git a/tools/testing/selftests/x86/Makefile 
b/tools/testing/selftests/x86/Makefile
index 29089b2..fd55bc3 100644
--- a/tools/testing/selftests/x86/Makefile
+++ b/tools/testing/selftests/x86/Makefile
@@ -5,7 +5,7 @@ include ../lib.mk
 .PHONY: all all_32 all_64 warn_32bit_failure clean
 
 TARGETS_C_BOTHBITS := single_step_syscall sysret_ss_attrs ldt_gdt syscall_nt
-TARGETS_C_32BIT_ONLY := entry_from_vm86 syscall_arg_fault sigreturn
+TARGETS_C_32BIT_ONLY := entry_from_vm86 syscall_arg_fault sigreturn 
test_syscall_vdso
 
 TARGETS_C_32BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_32BIT_ONLY)
 BINARIES_32 := $(TARGETS_C_32BIT_ALL:%=%_32)
@@ -60,3 +60,4 @@ endif
 
 # Some tests have additional dependencies.
 sysret_ss_attrs_64: thunks.S
+test_syscall_vdso_32: thunks_32.S
diff --git a/tools/testing/selftests/x86/test_syscall_vdso.c 
b/tools/testing/selftests/x86/test_syscall_vdso.c
new file mode 100644
index 000..4037035
--- /dev/null
+++ b/tools/testing/selftests/x86/test_syscall_vdso.c
@@ -0,0 +1,401 @@
+/*
+ * 32-bit syscall ABI conformance test.
+ *
+ * Copyright (c) 2015 Denys Vlasenko
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ 

[tip:x86/fpu] x86/fpu/math-emu: Remove !NO_UNDOC_CODE

2015-09-15 Thread tip-bot for Denys Vlasenko
Commit-ID:  73477bbb09e7022063d1737c7322ad2e08968c23
Gitweb: http://git.kernel.org/tip/73477bbb09e7022063d1737c7322ad2e08968c23
Author: Denys Vlasenko 
AuthorDate: Thu, 27 Aug 2015 20:15:28 +0200
Committer:  Ingo Molnar 
CommitDate: Tue, 15 Sep 2015 08:01:46 +0200

x86/fpu/math-emu: Remove !NO_UNDOC_CODE

We always want to support all FPU opcodes, including
undocumented ones. That define was fully justified ~20 years ago
but not today. Let's not complicate the code with it.

Signed-off-by: Denys Vlasenko 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Link: 
http://lkml.kernel.org/r/1440699330-1305-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/math-emu/fpu_entry.c | 36 
 1 file changed, 36 deletions(-)

diff --git a/arch/x86/math-emu/fpu_entry.c b/arch/x86/math-emu/fpu_entry.c
index 3d8f2e4..929b1d5 100644
--- a/arch/x86/math-emu/fpu_entry.c
+++ b/arch/x86/math-emu/fpu_entry.c
@@ -40,8 +40,6 @@
 
 #define __BAD__ FPU_illegal/* Illegal on an 80486, causes SIGILL */
 
-#ifndef NO_UNDOC_CODE  /* Un-documented FPU op-codes supported by 
default. */
-
 /* WARNING: These codes are not documented by Intel in their 80486 manual
and may not work on FPU clones or later Intel FPUs. */
 
@@ -68,21 +66,6 @@ static FUNC const st_instr_table[64] = {
fdivr_, FPU_trigb, __BAD__, __BAD__, fdiv_i, __BAD__, fdivp_, __BAD__,
 };
 
-#else /* Support only documented FPU op-codes */
-
-static FUNC const st_instr_table[64] = {
-   fadd__, fld_i_, __BAD__, __BAD__, fadd_i, ffree_, faddp_, __BAD__,
-   fmul__, fxch_i, __BAD__, __BAD__, fmul_i, __BAD__, fmulp_, __BAD__,
-   fcom_st, fp_nop, __BAD__, __BAD__, __BAD__, fst_i_, __BAD__, __BAD__,
-   fcompst, __BAD__, __BAD__, __BAD__, __BAD__, fstp_i, fcompp, __BAD__,
-   fsub__, FPU_etc, __BAD__, finit_, fsubri, fucom_, fsubrp, fstsw_,
-   fsubr_, fconst, fucompp, __BAD__, fsub_i, fucomp, fsubp_, __BAD__,
-   fdiv__, FPU_triga, __BAD__, __BAD__, fdivri, __BAD__, fdivrp, __BAD__,
-   fdivr_, FPU_trigb, __BAD__, __BAD__, fdiv_i, __BAD__, fdivp_, __BAD__,
-};
-
-#endif /* NO_UNDOC_CODE */
-
 #define _NONE_ 0   /* Take no special action */
 #define _REG0_ 1   /* Need to check for not empty st(0) */
 #define _REGI_ 2   /* Need to check for not empty st(0) and st(rm) 
*/
@@ -94,10 +77,6 @@ static FUNC const st_instr_table[64] = {
 #define _REGIc 0   /* Compare st(0) and st(rm) */
 #define _REGIn 0   /* Uses st(0) and st(rm), but handle checks 
later */
 
-#ifndef NO_UNDOC_CODE
-
-/* Un-documented FPU op-codes supported by default. (see above) */
-
 static u_char const type_table[64] = {
_REGI_, _NONE_, _null_, _null_, _REGIi, _REGi_, _REGIp, _REGi_,
_REGI_, _REGIn, _null_, _null_, _REGIi, _REGI_, _REGIp, _REGI_,
@@ -109,21 +88,6 @@ static u_char const type_table[64] = {
_REGI_, _NONE_, _null_, _null_, _REGIi, _null_, _REGIp, _null_
 };
 
-#else /* Support only documented FPU op-codes */
-
-static u_char const type_table[64] = {
-   _REGI_, _NONE_, _null_, _null_, _REGIi, _REGi_, _REGIp, _null_,
-   _REGI_, _REGIn, _null_, _null_, _REGIi, _null_, _REGIp, _null_,
-   _REGIc, _NONE_, _null_, _null_, _null_, _REG0_, _null_, _null_,
-   _REGIc, _null_, _null_, _null_, _null_, _REG0_, _REGIc, _null_,
-   _REGI_, _NONE_, _null_, _NONE_, _REGIi, _REGIc, _REGIp, _NONE_,
-   _REGI_, _NONE_, _REGIc, _null_, _REGIi, _REGIc, _REGIp, _null_,
-   _REGI_, _NONE_, _null_, _null_, _REGIi, _null_, _REGIp, _null_,
-   _REGI_, _NONE_, _null_, _null_, _REGIi, _null_, _REGIp, _null_
-};
-
-#endif /* NO_UNDOC_CODE */
-
 #ifdef RE_ENTRANT_CHECKING
 u_char emulating = 0;
 #endif /* RE_ENTRANT_CHECKING */
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/fpu] x86/fpu/math-emu: Remove !NO_UNDOC_CODE

2015-09-15 Thread tip-bot for Denys Vlasenko
Commit-ID:  73477bbb09e7022063d1737c7322ad2e08968c23
Gitweb: http://git.kernel.org/tip/73477bbb09e7022063d1737c7322ad2e08968c23
Author: Denys Vlasenko 
AuthorDate: Thu, 27 Aug 2015 20:15:28 +0200
Committer:  Ingo Molnar 
CommitDate: Tue, 15 Sep 2015 08:01:46 +0200

x86/fpu/math-emu: Remove !NO_UNDOC_CODE

We always want to support all FPU opcodes, including
undocumented ones. That define was fully justified ~20 years ago
but not today. Let's not complicate the code with it.

Signed-off-by: Denys Vlasenko 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Link: 
http://lkml.kernel.org/r/1440699330-1305-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/math-emu/fpu_entry.c | 36 
 1 file changed, 36 deletions(-)

diff --git a/arch/x86/math-emu/fpu_entry.c b/arch/x86/math-emu/fpu_entry.c
index 3d8f2e4..929b1d5 100644
--- a/arch/x86/math-emu/fpu_entry.c
+++ b/arch/x86/math-emu/fpu_entry.c
@@ -40,8 +40,6 @@
 
 #define __BAD__ FPU_illegal/* Illegal on an 80486, causes SIGILL */
 
-#ifndef NO_UNDOC_CODE  /* Un-documented FPU op-codes supported by 
default. */
-
 /* WARNING: These codes are not documented by Intel in their 80486 manual
and may not work on FPU clones or later Intel FPUs. */
 
@@ -68,21 +66,6 @@ static FUNC const st_instr_table[64] = {
fdivr_, FPU_trigb, __BAD__, __BAD__, fdiv_i, __BAD__, fdivp_, __BAD__,
 };
 
-#else /* Support only documented FPU op-codes */
-
-static FUNC const st_instr_table[64] = {
-   fadd__, fld_i_, __BAD__, __BAD__, fadd_i, ffree_, faddp_, __BAD__,
-   fmul__, fxch_i, __BAD__, __BAD__, fmul_i, __BAD__, fmulp_, __BAD__,
-   fcom_st, fp_nop, __BAD__, __BAD__, __BAD__, fst_i_, __BAD__, __BAD__,
-   fcompst, __BAD__, __BAD__, __BAD__, __BAD__, fstp_i, fcompp, __BAD__,
-   fsub__, FPU_etc, __BAD__, finit_, fsubri, fucom_, fsubrp, fstsw_,
-   fsubr_, fconst, fucompp, __BAD__, fsub_i, fucomp, fsubp_, __BAD__,
-   fdiv__, FPU_triga, __BAD__, __BAD__, fdivri, __BAD__, fdivrp, __BAD__,
-   fdivr_, FPU_trigb, __BAD__, __BAD__, fdiv_i, __BAD__, fdivp_, __BAD__,
-};
-
-#endif /* NO_UNDOC_CODE */
-
 #define _NONE_ 0   /* Take no special action */
 #define _REG0_ 1   /* Need to check for not empty st(0) */
 #define _REGI_ 2   /* Need to check for not empty st(0) and st(rm) 
*/
@@ -94,10 +77,6 @@ static FUNC const st_instr_table[64] = {
 #define _REGIc 0   /* Compare st(0) and st(rm) */
 #define _REGIn 0   /* Uses st(0) and st(rm), but handle checks 
later */
 
-#ifndef NO_UNDOC_CODE
-
-/* Un-documented FPU op-codes supported by default. (see above) */
-
 static u_char const type_table[64] = {
_REGI_, _NONE_, _null_, _null_, _REGIi, _REGi_, _REGIp, _REGi_,
_REGI_, _REGIn, _null_, _null_, _REGIi, _REGI_, _REGIp, _REGI_,
@@ -109,21 +88,6 @@ static u_char const type_table[64] = {
_REGI_, _NONE_, _null_, _null_, _REGIi, _null_, _REGIp, _null_
 };
 
-#else /* Support only documented FPU op-codes */
-
-static u_char const type_table[64] = {
-   _REGI_, _NONE_, _null_, _null_, _REGIi, _REGi_, _REGIp, _null_,
-   _REGI_, _REGIn, _null_, _null_, _REGIi, _null_, _REGIp, _null_,
-   _REGIc, _NONE_, _null_, _null_, _null_, _REG0_, _null_, _null_,
-   _REGIc, _null_, _null_, _null_, _null_, _REG0_, _REGIc, _null_,
-   _REGI_, _NONE_, _null_, _NONE_, _REGIi, _REGIc, _REGIp, _NONE_,
-   _REGI_, _NONE_, _REGIc, _null_, _REGIi, _REGIc, _REGIp, _null_,
-   _REGI_, _NONE_, _null_, _null_, _REGIi, _null_, _REGIp, _null_,
-   _REGI_, _NONE_, _null_, _null_, _REGIi, _null_, _REGIp, _null_
-};
-
-#endif /* NO_UNDOC_CODE */
-
 #ifdef RE_ENTRANT_CHECKING
 u_char emulating = 0;
 #endif /* RE_ENTRANT_CHECKING */
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:core/types] jiffies: Force inlining of {m,u}msecs_to_jiffies ()

2015-08-05 Thread tip-bot for Denys Vlasenko
Commit-ID:  accd0b9ec015d611eb7783dd86f1bb31bf8d62ab
Gitweb: http://git.kernel.org/tip/accd0b9ec015d611eb7783dd86f1bb31bf8d62ab
Author: Denys Vlasenko 
AuthorDate: Tue, 4 Aug 2015 16:15:16 +0200
Committer:  Ingo Molnar 
CommitDate: Wed, 5 Aug 2015 09:38:09 +0200

jiffies: Force inlining of {m,u}msecs_to_jiffies()

With this config:

  http://busybox.net/~vda/kernel_config_OPTIMIZE_INLINING_and_Os

gcc-4.7.2 generates many copies of these tiny functions:

msecs_to_jiffies (45 copies):
55  push   %rbp
48 89 e5mov%rsp,%rbp
e8 59 ec 03 00  callq  __msecs_to_jiffies
5d  pop%rbp
c3  retq

usecs_to_jiffies (10 copies):
55  push   %rbp
48 89 e5mov%rsp,%rbp
e8 5d 54 5e ff  callq  __usecs_to_jiffies
5d  pop%rbp
c3  retq

See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66122

This patch fixes this via s/inline/__always_inline/

text data  bss   dec  filename
86970954 17195912 36659200 140826066  vmlinux.before
86966150 17195912 36659200 140821262  vmlinux

Signed-off-by: Denys Vlasenko 
Cc: Andrew Morton 
Cc: David Rientjes 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: Thomas Graf 
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1438697716-28121-3-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 include/linux/jiffies.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
index 535fd3b..1ba48a1 100644
--- a/include/linux/jiffies.h
+++ b/include/linux/jiffies.h
@@ -351,7 +351,7 @@ static inline unsigned long _msecs_to_jiffies(const 
unsigned int m)
  * directly here and from __msecs_to_jiffies() in the case where
  * constant folding is not possible.
  */
-static inline unsigned long msecs_to_jiffies(const unsigned int m)
+static __always_inline unsigned long msecs_to_jiffies(const unsigned int m)
 {
if (__builtin_constant_p(m)) {
if ((int)m < 0)
@@ -405,7 +405,7 @@ static inline unsigned long _usecs_to_jiffies(const 
unsigned int u)
  * directly here and from __msecs_to_jiffies() in the case where
  * constant folding is not possible.
  */
-static inline unsigned long usecs_to_jiffies(const unsigned int u)
+static __always_inline unsigned long usecs_to_jiffies(const unsigned int u)
 {
if (__builtin_constant_p(u)) {
if (u > jiffies_to_usecs(MAX_JIFFY_OFFSET))
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:core/types] x86/hweight: Force inlining of __arch_hweight{32 ,64}()

2015-08-05 Thread tip-bot for Denys Vlasenko
Commit-ID:  d14edb1648221e59fc9fd47127fcc57bf26d759f
Gitweb: http://git.kernel.org/tip/d14edb1648221e59fc9fd47127fcc57bf26d759f
Author: Denys Vlasenko 
AuthorDate: Tue, 4 Aug 2015 16:15:15 +0200
Committer:  Ingo Molnar 
CommitDate: Wed, 5 Aug 2015 09:38:09 +0200

x86/hweight: Force inlining of __arch_hweight{32,64}()

With this config:

  http://busybox.net/~vda/kernel_config_OPTIMIZE_INLINING_and_Os

gcc-4.7.2 generates many copies of these tiny functions:

__arch_hweight32 (35 copies):
55  push   %rbp
e8 66 9b 4a 00  callq  __sw_hweight32
48 89 e5mov%rsp,%rbp
5d  pop%rbp
c3  retq

__arch_hweight64 (8 copies):
55  push   %rbp
e8 5e c2 8a 00  callq  __sw_hweight64
48 89 e5mov%rsp,%rbp
5d  pop%rbp
c3  retq

See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66122

This patch fixes this via s/inline/__always_inline/

To avoid touching 32-bit case where such change was not tested
to be a win, reformat __arch_hweight64() to have completely
disjoint 64-bit and 32-bit implementations. IOW: made #ifdef /
32 bits and 64 bits instead of having #ifdef / #else / #endif
inside a single function body. Only 64-bit __arch_hweight64() is
__always_inline'd.

text data  bss   dec  filename
86971120 17195912 36659200 140826232  vmlinux.before
86970954 17195912 36659200 140826066  vmlinux

Signed-off-by: Denys Vlasenko 
Cc: Andrew Morton 
Cc: David Rientjes 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: Thomas Graf 
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1438697716-28121-2-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/include/asm/arch_hweight.h | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/arch/x86/include/asm/arch_hweight.h 
b/arch/x86/include/asm/arch_hweight.h
index 9686c3d..259a7c1 100644
--- a/arch/x86/include/asm/arch_hweight.h
+++ b/arch/x86/include/asm/arch_hweight.h
@@ -21,7 +21,7 @@
  * ARCH_HWEIGHT_CFLAGS in  for the respective
  * compiler switches.
  */
-static inline unsigned int __arch_hweight32(unsigned int w)
+static __always_inline unsigned int __arch_hweight32(unsigned int w)
 {
unsigned int res = 0;
 
@@ -42,20 +42,23 @@ static inline unsigned int __arch_hweight8(unsigned int w)
return __arch_hweight32(w & 0xff);
 }
 
+#ifdef CONFIG_X86_32
 static inline unsigned long __arch_hweight64(__u64 w)
 {
-   unsigned long res = 0;
-
-#ifdef CONFIG_X86_32
return  __arch_hweight32((u32)w) +
__arch_hweight32((u32)(w >> 32));
+}
 #else
+static __always_inline unsigned long __arch_hweight64(__u64 w)
+{
+   unsigned long res = 0;
+
asm (ALTERNATIVE("call __sw_hweight64", POPCNT64, X86_FEATURE_POPCNT)
 : "="REG_OUT (res)
 : REG_IN (w));
-#endif /* CONFIG_X86_32 */
 
return res;
 }
+#endif /* CONFIG_X86_32 */
 
 #endif
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:core/types] linux/bitmap: Force inlining of bitmap weight functions

2015-08-05 Thread tip-bot for Denys Vlasenko
Commit-ID:  1a1d48a4a8fde49aedc045d894efe67173d59fe0
Gitweb: http://git.kernel.org/tip/1a1d48a4a8fde49aedc045d894efe67173d59fe0
Author: Denys Vlasenko 
AuthorDate: Tue, 4 Aug 2015 16:15:14 +0200
Committer:  Ingo Molnar 
CommitDate: Wed, 5 Aug 2015 09:38:08 +0200

linux/bitmap: Force inlining of bitmap weight functions

With this config:

  http://busybox.net/~vda/kernel_config_OPTIMIZE_INLINING_and_Os

gcc-4.7.2 generates many copies of these tiny functions:

bitmap_weight (55 copies):
55  push   %rbp
48 89 e5mov%rsp,%rbp
e8 3f 3a 8b 00  callq  __bitmap_weight
5d  pop%rbp
c3  retq

hweight_long (23 copies):
55  push   %rbp
e8 b5 65 8e 00  callq  __sw_hweight64
48 89 e5mov%rsp,%rbp
5d  pop%rbp
c3  retq

See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66122

This patch fixes this via s/inline/__always_inline/

While at it, replaced two "__inline__" with usual "inline"
(the rest of the source file uses the latter).

text data  bss   dec  filename
86971357 17195880 36659200 140826437  vmlinux.before
86971120 17195912 36659200 140826232  vmlinux

Signed-off-by: Denys Vlasenko 
Cc: Andrew Morton 
Cc: David Rientjes 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: Thomas Graf 
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1438697716-28121-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 include/linux/bitmap.h | 2 +-
 include/linux/bitops.h | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index ea17cca..9653fdb 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -295,7 +295,7 @@ static inline int bitmap_full(const unsigned long *src, 
unsigned int nbits)
return find_first_zero_bit(src, nbits) == nbits;
 }
 
-static inline int bitmap_weight(const unsigned long *src, unsigned int nbits)
+static __always_inline int bitmap_weight(const unsigned long *src, unsigned 
int nbits)
 {
if (small_const_nbits(nbits))
return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits));
diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index 297f5bd..e635533 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -57,7 +57,7 @@ extern unsigned long __sw_hweight64(__u64 w);
 (bit) < (size);\
 (bit) = find_next_zero_bit((addr), (size), (bit) + 1))
 
-static __inline__ int get_bitmask_order(unsigned int count)
+static inline int get_bitmask_order(unsigned int count)
 {
int order;
 
@@ -65,7 +65,7 @@ static __inline__ int get_bitmask_order(unsigned int count)
return order;   /* We could be slightly more clever with -1 here... */
 }
 
-static __inline__ int get_count_order(unsigned int count)
+static inline int get_count_order(unsigned int count)
 {
int order;
 
@@ -75,7 +75,7 @@ static __inline__ int get_count_order(unsigned int count)
return order;
 }
 
-static inline unsigned long hweight_long(unsigned long w)
+static __always_inline unsigned long hweight_long(unsigned long w)
 {
return sizeof(w) == 4 ? hweight32(w) : hweight64(w);
 }
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:core/types] linux/bitmap: Force inlining of bitmap weight functions

2015-08-05 Thread tip-bot for Denys Vlasenko
Commit-ID:  1a1d48a4a8fde49aedc045d894efe67173d59fe0
Gitweb: http://git.kernel.org/tip/1a1d48a4a8fde49aedc045d894efe67173d59fe0
Author: Denys Vlasenko dvlas...@redhat.com
AuthorDate: Tue, 4 Aug 2015 16:15:14 +0200
Committer:  Ingo Molnar mi...@kernel.org
CommitDate: Wed, 5 Aug 2015 09:38:08 +0200

linux/bitmap: Force inlining of bitmap weight functions

With this config:

  http://busybox.net/~vda/kernel_config_OPTIMIZE_INLINING_and_Os

gcc-4.7.2 generates many copies of these tiny functions:

bitmap_weight (55 copies):
55  push   %rbp
48 89 e5mov%rsp,%rbp
e8 3f 3a 8b 00  callq  __bitmap_weight
5d  pop%rbp
c3  retq

hweight_long (23 copies):
55  push   %rbp
e8 b5 65 8e 00  callq  __sw_hweight64
48 89 e5mov%rsp,%rbp
5d  pop%rbp
c3  retq

See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66122

This patch fixes this via s/inline/__always_inline/

While at it, replaced two __inline__ with usual inline
(the rest of the source file uses the latter).

text data  bss   dec  filename
86971357 17195880 36659200 140826437  vmlinux.before
86971120 17195912 36659200 140826232  vmlinux

Signed-off-by: Denys Vlasenko dvlas...@redhat.com
Cc: Andrew Morton a...@linux-foundation.org
Cc: David Rientjes rient...@google.com
Cc: Linus Torvalds torva...@linux-foundation.org
Cc: Peter Zijlstra pet...@infradead.org
Cc: Thomas Gleixner t...@linutronix.de
Cc: Thomas Graf tg...@suug.ch
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1438697716-28121-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar mi...@kernel.org
---
 include/linux/bitmap.h | 2 +-
 include/linux/bitops.h | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index ea17cca..9653fdb 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -295,7 +295,7 @@ static inline int bitmap_full(const unsigned long *src, 
unsigned int nbits)
return find_first_zero_bit(src, nbits) == nbits;
 }
 
-static inline int bitmap_weight(const unsigned long *src, unsigned int nbits)
+static __always_inline int bitmap_weight(const unsigned long *src, unsigned 
int nbits)
 {
if (small_const_nbits(nbits))
return hweight_long(*src  BITMAP_LAST_WORD_MASK(nbits));
diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index 297f5bd..e635533 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -57,7 +57,7 @@ extern unsigned long __sw_hweight64(__u64 w);
 (bit)  (size);\
 (bit) = find_next_zero_bit((addr), (size), (bit) + 1))
 
-static __inline__ int get_bitmask_order(unsigned int count)
+static inline int get_bitmask_order(unsigned int count)
 {
int order;
 
@@ -65,7 +65,7 @@ static __inline__ int get_bitmask_order(unsigned int count)
return order;   /* We could be slightly more clever with -1 here... */
 }
 
-static __inline__ int get_count_order(unsigned int count)
+static inline int get_count_order(unsigned int count)
 {
int order;
 
@@ -75,7 +75,7 @@ static __inline__ int get_count_order(unsigned int count)
return order;
 }
 
-static inline unsigned long hweight_long(unsigned long w)
+static __always_inline unsigned long hweight_long(unsigned long w)
 {
return sizeof(w) == 4 ? hweight32(w) : hweight64(w);
 }
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:core/types] x86/hweight: Force inlining of __arch_hweight{32 ,64}()

2015-08-05 Thread tip-bot for Denys Vlasenko
Commit-ID:  d14edb1648221e59fc9fd47127fcc57bf26d759f
Gitweb: http://git.kernel.org/tip/d14edb1648221e59fc9fd47127fcc57bf26d759f
Author: Denys Vlasenko dvlas...@redhat.com
AuthorDate: Tue, 4 Aug 2015 16:15:15 +0200
Committer:  Ingo Molnar mi...@kernel.org
CommitDate: Wed, 5 Aug 2015 09:38:09 +0200

x86/hweight: Force inlining of __arch_hweight{32,64}()

With this config:

  http://busybox.net/~vda/kernel_config_OPTIMIZE_INLINING_and_Os

gcc-4.7.2 generates many copies of these tiny functions:

__arch_hweight32 (35 copies):
55  push   %rbp
e8 66 9b 4a 00  callq  __sw_hweight32
48 89 e5mov%rsp,%rbp
5d  pop%rbp
c3  retq

__arch_hweight64 (8 copies):
55  push   %rbp
e8 5e c2 8a 00  callq  __sw_hweight64
48 89 e5mov%rsp,%rbp
5d  pop%rbp
c3  retq

See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66122

This patch fixes this via s/inline/__always_inline/

To avoid touching 32-bit case where such change was not tested
to be a win, reformat __arch_hweight64() to have completely
disjoint 64-bit and 32-bit implementations. IOW: made #ifdef /
32 bits and 64 bits instead of having #ifdef / #else / #endif
inside a single function body. Only 64-bit __arch_hweight64() is
__always_inline'd.

text data  bss   dec  filename
86971120 17195912 36659200 140826232  vmlinux.before
86970954 17195912 36659200 140826066  vmlinux

Signed-off-by: Denys Vlasenko dvlas...@redhat.com
Cc: Andrew Morton a...@linux-foundation.org
Cc: David Rientjes rient...@google.com
Cc: Linus Torvalds torva...@linux-foundation.org
Cc: Peter Zijlstra pet...@infradead.org
Cc: Thomas Gleixner t...@linutronix.de
Cc: Thomas Graf tg...@suug.ch
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1438697716-28121-2-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar mi...@kernel.org
---
 arch/x86/include/asm/arch_hweight.h | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/arch/x86/include/asm/arch_hweight.h 
b/arch/x86/include/asm/arch_hweight.h
index 9686c3d..259a7c1 100644
--- a/arch/x86/include/asm/arch_hweight.h
+++ b/arch/x86/include/asm/arch_hweight.h
@@ -21,7 +21,7 @@
  * ARCH_HWEIGHT_CFLAGS in arch/x86/Kconfig for the respective
  * compiler switches.
  */
-static inline unsigned int __arch_hweight32(unsigned int w)
+static __always_inline unsigned int __arch_hweight32(unsigned int w)
 {
unsigned int res = 0;
 
@@ -42,20 +42,23 @@ static inline unsigned int __arch_hweight8(unsigned int w)
return __arch_hweight32(w  0xff);
 }
 
+#ifdef CONFIG_X86_32
 static inline unsigned long __arch_hweight64(__u64 w)
 {
-   unsigned long res = 0;
-
-#ifdef CONFIG_X86_32
return  __arch_hweight32((u32)w) +
__arch_hweight32((u32)(w  32));
+}
 #else
+static __always_inline unsigned long __arch_hweight64(__u64 w)
+{
+   unsigned long res = 0;
+
asm (ALTERNATIVE(call __sw_hweight64, POPCNT64, X86_FEATURE_POPCNT)
 : =REG_OUT (res)
 : REG_IN (w));
-#endif /* CONFIG_X86_32 */
 
return res;
 }
+#endif /* CONFIG_X86_32 */
 
 #endif
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:core/types] jiffies: Force inlining of {m,u}msecs_to_jiffies ()

2015-08-05 Thread tip-bot for Denys Vlasenko
Commit-ID:  accd0b9ec015d611eb7783dd86f1bb31bf8d62ab
Gitweb: http://git.kernel.org/tip/accd0b9ec015d611eb7783dd86f1bb31bf8d62ab
Author: Denys Vlasenko dvlas...@redhat.com
AuthorDate: Tue, 4 Aug 2015 16:15:16 +0200
Committer:  Ingo Molnar mi...@kernel.org
CommitDate: Wed, 5 Aug 2015 09:38:09 +0200

jiffies: Force inlining of {m,u}msecs_to_jiffies()

With this config:

  http://busybox.net/~vda/kernel_config_OPTIMIZE_INLINING_and_Os

gcc-4.7.2 generates many copies of these tiny functions:

msecs_to_jiffies (45 copies):
55  push   %rbp
48 89 e5mov%rsp,%rbp
e8 59 ec 03 00  callq  __msecs_to_jiffies
5d  pop%rbp
c3  retq

usecs_to_jiffies (10 copies):
55  push   %rbp
48 89 e5mov%rsp,%rbp
e8 5d 54 5e ff  callq  __usecs_to_jiffies
5d  pop%rbp
c3  retq

See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66122

This patch fixes this via s/inline/__always_inline/

text data  bss   dec  filename
86970954 17195912 36659200 140826066  vmlinux.before
86966150 17195912 36659200 140821262  vmlinux

Signed-off-by: Denys Vlasenko dvlas...@redhat.com
Cc: Andrew Morton a...@linux-foundation.org
Cc: David Rientjes rient...@google.com
Cc: Linus Torvalds torva...@linux-foundation.org
Cc: Peter Zijlstra pet...@infradead.org
Cc: Thomas Gleixner t...@linutronix.de
Cc: Thomas Graf tg...@suug.ch
Cc: linux-kernel@vger.kernel.org
Link: 
http://lkml.kernel.org/r/1438697716-28121-3-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar mi...@kernel.org
---
 include/linux/jiffies.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
index 535fd3b..1ba48a1 100644
--- a/include/linux/jiffies.h
+++ b/include/linux/jiffies.h
@@ -351,7 +351,7 @@ static inline unsigned long _msecs_to_jiffies(const 
unsigned int m)
  * directly here and from __msecs_to_jiffies() in the case where
  * constant folding is not possible.
  */
-static inline unsigned long msecs_to_jiffies(const unsigned int m)
+static __always_inline unsigned long msecs_to_jiffies(const unsigned int m)
 {
if (__builtin_constant_p(m)) {
if ((int)m  0)
@@ -405,7 +405,7 @@ static inline unsigned long _usecs_to_jiffies(const 
unsigned int u)
  * directly here and from __msecs_to_jiffies() in the case where
  * constant folding is not possible.
  */
-static inline unsigned long usecs_to_jiffies(const unsigned int u)
+static __always_inline unsigned long usecs_to_jiffies(const unsigned int u)
 {
if (__builtin_constant_p(u)) {
if (u  jiffies_to_usecs(MAX_JIFFY_OFFSET))
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/urgent] x86/asm/entry/32: Revert ' Do not use R9 in SYSCALL32' commit

2015-07-24 Thread tip-bot for Denys Vlasenko
Commit-ID:  c0c3322e98029e752526d906d9e3a680ed213c03
Gitweb: http://git.kernel.org/tip/c0c3322e98029e752526d906d9e3a680ed213c03
Author: Denys Vlasenko 
AuthorDate: Fri, 24 Jul 2015 14:16:43 +0200
Committer:  Thomas Gleixner 
CommitDate: Fri, 24 Jul 2015 16:36:00 +0200

x86/asm/entry/32: Revert 'Do not use R9 in SYSCALL32' commit

This change reverts most of commit 53e9accf0f 'Do not use R9 in
SYSCALL32'. I don't yet understand how, but code in that commit
sometimes fails to preserve EBP.

See https://bugzilla.kernel.org/show_bug.cgi?id=101061
"Problems while executing 32-bit code on AMD64"

Reported-and-tested-by: Krzysztof A. Sobiecki 
Signed-off-by: Denys Vlasenko 
Cc: Linus Torvalds 
Cc: Steven Rostedt 
Cc: Borislav Petkov 
Cc: Andy Lutomirski 
Cc: Oleg Nesterov 
Cc: Frederic Weisbecker 
Cc: Alexei Starovoitov 
Cc: Will Drewry 
Cc: Kees Cook 
CC: x...@kernel.org
Link: 
http://lkml.kernel.org/r/1437740203-11552-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Thomas Gleixner 
---
 arch/x86/entry/entry_64_compat.S | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/arch/x86/entry/entry_64_compat.S b/arch/x86/entry/entry_64_compat.S
index bb187a6..5a18447 100644
--- a/arch/x86/entry/entry_64_compat.S
+++ b/arch/x86/entry/entry_64_compat.S
@@ -205,7 +205,6 @@ sysexit_from_sys_call:
movlRDX(%rsp), %edx /* arg3 */
movlRSI(%rsp), %ecx /* arg4 */
movlRDI(%rsp), %r8d /* arg5 */
-   movl%ebp, %r9d  /* arg6 */
.endm
 
.macro auditsys_exit exit
@@ -236,6 +235,7 @@ sysexit_from_sys_call:
 
 sysenter_auditsys:
auditsys_entry_common
+   movl%ebp, %r9d  /* reload 6th syscall arg */
jmp sysenter_dispatch
 
 sysexit_audit:
@@ -336,7 +336,7 @@ ENTRY(entry_SYSCALL_compat)
 * 32-bit zero extended:
 */
ASM_STAC
-1: movl(%r8), %ebp
+1: movl(%r8), %r9d
_ASM_EXTABLE(1b, ia32_badarg)
ASM_CLAC
orl $TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS)
@@ -346,7 +346,7 @@ ENTRY(entry_SYSCALL_compat)
 cstar_do_call:
/* 32-bit syscall -> 64-bit C ABI argument conversion */
movl%edi, %r8d  /* arg5 */
-   movl%ebp, %r9d  /* arg6 */
+   /* r9 already loaded */ /* arg6 */
xchg%ecx, %esi  /* rsi:arg2, rcx:arg4 */
movl%ebx, %edi  /* arg1 */
movl%edx, %edx  /* arg3 (zero extension) */
@@ -358,7 +358,6 @@ cstar_dispatch:
call*ia32_sys_call_table(, %rax, 8)
movq%rax, RAX(%rsp)
 1:
-   movlRCX(%rsp), %ebp
DISABLE_INTERRUPTS(CLBR_NONE)
TRACE_IRQS_OFF
testl   $_TIF_ALLWORK_MASK, ASM_THREAD_INFO(TI_flags, %rsp, 
SIZEOF_PTREGS)
@@ -392,7 +391,9 @@ sysretl_from_sys_call:
 
 #ifdef CONFIG_AUDITSYSCALL
 cstar_auditsys:
+   movl%r9d, R9(%rsp)  /* register to be clobbered by call */
auditsys_entry_common
+   movlR9(%rsp), %r9d  /* reload 6th syscall arg */
jmp cstar_dispatch
 
 sysretl_audit:
@@ -404,14 +405,16 @@ cstar_tracesys:
testl   $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT), 
ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS)
jz  cstar_auditsys
 #endif
+   xchgl   %r9d, %ebp
SAVE_EXTRA_REGS
xorl%eax, %eax  /* Do not leak kernel information */
movq%rax, R11(%rsp)
movq%rax, R10(%rsp)
-   movq%rax, R9(%rsp)
+   movq%r9, R9(%rsp)
movq%rax, R8(%rsp)
movq%rsp, %rdi  /* _regs -> arg1 */
callsyscall_trace_enter
+   movlR9(%rsp), %r9d
 
/* Reload arg registers from stack. (see sysenter_tracesys) */
movlRCX(%rsp), %ecx
@@ -421,6 +424,7 @@ cstar_tracesys:
movl%eax, %eax  /* zero extension */
 
RESTORE_EXTRA_REGS
+   xchgl   %ebp, %r9d
jmp cstar_do_call
 END(entry_SYSCALL_compat)
 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/urgent] x86/asm/entry/32: Revert ' Do not use R9 in SYSCALL32' commit

2015-07-24 Thread tip-bot for Denys Vlasenko
Commit-ID:  b1e194de6c8df2e5df8a8a1c1678cc2025439857
Gitweb: http://git.kernel.org/tip/b1e194de6c8df2e5df8a8a1c1678cc2025439857
Author: Denys Vlasenko 
AuthorDate: Fri, 24 Jul 2015 14:16:43 +0200
Committer:  Thomas Gleixner 
CommitDate: Fri, 24 Jul 2015 16:16:55 +0200

x86/asm/entry/32: Revert 'Do not use R9 in SYSCALL32' commit

This change reverts most of commit 53e9accf0f 'Do not use R9 in
SYSCALL32'. I don't yet understand how, but code in that commit
sometimes fails to preserve EBP.

See https://bugzilla.kernel.org/show_bug.cgi?id=101061
"Problems while executing 32-bit code on AMD64"

Reported-and-tested-by: Krzysztof A. Sobiecki 
Signed-off-by: Denys Vlasenko 
Cc: Linus Torvalds 
Cc: Steven Rostedt 
Cc: Borislav Petkov 
Cc: Andy Lutomirski 
Cc: Oleg Nesterov 
Cc: Frederic Weisbecker 
Cc: Alexei Starovoitov 
Cc: Will Drewry 
Cc: Kees Cook 
CC: x...@kernel.org
Link: 
http://lkml.kernel.org/r/1437740203-11552-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Thomas Gleixner 
---
 arch/x86/entry/entry_64_compat.S | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/arch/x86/entry/entry_64_compat.S b/arch/x86/entry/entry_64_compat.S
index bb187a6..5a18447 100644
--- a/arch/x86/entry/entry_64_compat.S
+++ b/arch/x86/entry/entry_64_compat.S
@@ -205,7 +205,6 @@ sysexit_from_sys_call:
movlRDX(%rsp), %edx /* arg3 */
movlRSI(%rsp), %ecx /* arg4 */
movlRDI(%rsp), %r8d /* arg5 */
-   movl%ebp, %r9d  /* arg6 */
.endm
 
.macro auditsys_exit exit
@@ -236,6 +235,7 @@ sysexit_from_sys_call:
 
 sysenter_auditsys:
auditsys_entry_common
+   movl%ebp, %r9d  /* reload 6th syscall arg */
jmp sysenter_dispatch
 
 sysexit_audit:
@@ -336,7 +336,7 @@ ENTRY(entry_SYSCALL_compat)
 * 32-bit zero extended:
 */
ASM_STAC
-1: movl(%r8), %ebp
+1: movl(%r8), %r9d
_ASM_EXTABLE(1b, ia32_badarg)
ASM_CLAC
orl $TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS)
@@ -346,7 +346,7 @@ ENTRY(entry_SYSCALL_compat)
 cstar_do_call:
/* 32-bit syscall -> 64-bit C ABI argument conversion */
movl%edi, %r8d  /* arg5 */
-   movl%ebp, %r9d  /* arg6 */
+   /* r9 already loaded */ /* arg6 */
xchg%ecx, %esi  /* rsi:arg2, rcx:arg4 */
movl%ebx, %edi  /* arg1 */
movl%edx, %edx  /* arg3 (zero extension) */
@@ -358,7 +358,6 @@ cstar_dispatch:
call*ia32_sys_call_table(, %rax, 8)
movq%rax, RAX(%rsp)
 1:
-   movlRCX(%rsp), %ebp
DISABLE_INTERRUPTS(CLBR_NONE)
TRACE_IRQS_OFF
testl   $_TIF_ALLWORK_MASK, ASM_THREAD_INFO(TI_flags, %rsp, 
SIZEOF_PTREGS)
@@ -392,7 +391,9 @@ sysretl_from_sys_call:
 
 #ifdef CONFIG_AUDITSYSCALL
 cstar_auditsys:
+   movl%r9d, R9(%rsp)  /* register to be clobbered by call */
auditsys_entry_common
+   movlR9(%rsp), %r9d  /* reload 6th syscall arg */
jmp cstar_dispatch
 
 sysretl_audit:
@@ -404,14 +405,16 @@ cstar_tracesys:
testl   $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT), 
ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS)
jz  cstar_auditsys
 #endif
+   xchgl   %r9d, %ebp
SAVE_EXTRA_REGS
xorl%eax, %eax  /* Do not leak kernel information */
movq%rax, R11(%rsp)
movq%rax, R10(%rsp)
-   movq%rax, R9(%rsp)
+   movq%r9, R9(%rsp)
movq%rax, R8(%rsp)
movq%rsp, %rdi  /* _regs -> arg1 */
callsyscall_trace_enter
+   movlR9(%rsp), %r9d
 
/* Reload arg registers from stack. (see sysenter_tracesys) */
movlRCX(%rsp), %ecx
@@ -421,6 +424,7 @@ cstar_tracesys:
movl%eax, %eax  /* zero extension */
 
RESTORE_EXTRA_REGS
+   xchgl   %ebp, %r9d
jmp cstar_do_call
 END(entry_SYSCALL_compat)
 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/urgent] x86/asm/entry/32: Revert ' Do not use R9 in SYSCALL32' commit

2015-07-24 Thread tip-bot for Denys Vlasenko
Commit-ID:  c0c3322e98029e752526d906d9e3a680ed213c03
Gitweb: http://git.kernel.org/tip/c0c3322e98029e752526d906d9e3a680ed213c03
Author: Denys Vlasenko dvlas...@redhat.com
AuthorDate: Fri, 24 Jul 2015 14:16:43 +0200
Committer:  Thomas Gleixner t...@linutronix.de
CommitDate: Fri, 24 Jul 2015 16:36:00 +0200

x86/asm/entry/32: Revert 'Do not use R9 in SYSCALL32' commit

This change reverts most of commit 53e9accf0f 'Do not use R9 in
SYSCALL32'. I don't yet understand how, but code in that commit
sometimes fails to preserve EBP.

See https://bugzilla.kernel.org/show_bug.cgi?id=101061
Problems while executing 32-bit code on AMD64

Reported-and-tested-by: Krzysztof A. Sobiecki sob...@gmail.com
Signed-off-by: Denys Vlasenko dvlas...@redhat.com
Cc: Linus Torvalds torva...@linux-foundation.org
Cc: Steven Rostedt rost...@goodmis.org
Cc: Borislav Petkov b...@alien8.de
Cc: Andy Lutomirski l...@amacapital.net
Cc: Oleg Nesterov o...@redhat.com
Cc: Frederic Weisbecker fweis...@gmail.com
Cc: Alexei Starovoitov a...@plumgrid.com
Cc: Will Drewry w...@chromium.org
Cc: Kees Cook keesc...@chromium.org
CC: x...@kernel.org
Link: 
http://lkml.kernel.org/r/1437740203-11552-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Thomas Gleixner t...@linutronix.de
---
 arch/x86/entry/entry_64_compat.S | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/arch/x86/entry/entry_64_compat.S b/arch/x86/entry/entry_64_compat.S
index bb187a6..5a18447 100644
--- a/arch/x86/entry/entry_64_compat.S
+++ b/arch/x86/entry/entry_64_compat.S
@@ -205,7 +205,6 @@ sysexit_from_sys_call:
movlRDX(%rsp), %edx /* arg3 */
movlRSI(%rsp), %ecx /* arg4 */
movlRDI(%rsp), %r8d /* arg5 */
-   movl%ebp, %r9d  /* arg6 */
.endm
 
.macro auditsys_exit exit
@@ -236,6 +235,7 @@ sysexit_from_sys_call:
 
 sysenter_auditsys:
auditsys_entry_common
+   movl%ebp, %r9d  /* reload 6th syscall arg */
jmp sysenter_dispatch
 
 sysexit_audit:
@@ -336,7 +336,7 @@ ENTRY(entry_SYSCALL_compat)
 * 32-bit zero extended:
 */
ASM_STAC
-1: movl(%r8), %ebp
+1: movl(%r8), %r9d
_ASM_EXTABLE(1b, ia32_badarg)
ASM_CLAC
orl $TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS)
@@ -346,7 +346,7 @@ ENTRY(entry_SYSCALL_compat)
 cstar_do_call:
/* 32-bit syscall - 64-bit C ABI argument conversion */
movl%edi, %r8d  /* arg5 */
-   movl%ebp, %r9d  /* arg6 */
+   /* r9 already loaded */ /* arg6 */
xchg%ecx, %esi  /* rsi:arg2, rcx:arg4 */
movl%ebx, %edi  /* arg1 */
movl%edx, %edx  /* arg3 (zero extension) */
@@ -358,7 +358,6 @@ cstar_dispatch:
call*ia32_sys_call_table(, %rax, 8)
movq%rax, RAX(%rsp)
 1:
-   movlRCX(%rsp), %ebp
DISABLE_INTERRUPTS(CLBR_NONE)
TRACE_IRQS_OFF
testl   $_TIF_ALLWORK_MASK, ASM_THREAD_INFO(TI_flags, %rsp, 
SIZEOF_PTREGS)
@@ -392,7 +391,9 @@ sysretl_from_sys_call:
 
 #ifdef CONFIG_AUDITSYSCALL
 cstar_auditsys:
+   movl%r9d, R9(%rsp)  /* register to be clobbered by call */
auditsys_entry_common
+   movlR9(%rsp), %r9d  /* reload 6th syscall arg */
jmp cstar_dispatch
 
 sysretl_audit:
@@ -404,14 +405,16 @@ cstar_tracesys:
testl   $(_TIF_WORK_SYSCALL_ENTRY  ~_TIF_SYSCALL_AUDIT), 
ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS)
jz  cstar_auditsys
 #endif
+   xchgl   %r9d, %ebp
SAVE_EXTRA_REGS
xorl%eax, %eax  /* Do not leak kernel information */
movq%rax, R11(%rsp)
movq%rax, R10(%rsp)
-   movq%rax, R9(%rsp)
+   movq%r9, R9(%rsp)
movq%rax, R8(%rsp)
movq%rsp, %rdi  /* pt_regs - arg1 */
callsyscall_trace_enter
+   movlR9(%rsp), %r9d
 
/* Reload arg registers from stack. (see sysenter_tracesys) */
movlRCX(%rsp), %ecx
@@ -421,6 +424,7 @@ cstar_tracesys:
movl%eax, %eax  /* zero extension */
 
RESTORE_EXTRA_REGS
+   xchgl   %ebp, %r9d
jmp cstar_do_call
 END(entry_SYSCALL_compat)
 
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/urgent] x86/asm/entry/32: Revert ' Do not use R9 in SYSCALL32' commit

2015-07-24 Thread tip-bot for Denys Vlasenko
Commit-ID:  b1e194de6c8df2e5df8a8a1c1678cc2025439857
Gitweb: http://git.kernel.org/tip/b1e194de6c8df2e5df8a8a1c1678cc2025439857
Author: Denys Vlasenko dvlas...@redhat.com
AuthorDate: Fri, 24 Jul 2015 14:16:43 +0200
Committer:  Thomas Gleixner t...@linutronix.de
CommitDate: Fri, 24 Jul 2015 16:16:55 +0200

x86/asm/entry/32: Revert 'Do not use R9 in SYSCALL32' commit

This change reverts most of commit 53e9accf0f 'Do not use R9 in
SYSCALL32'. I don't yet understand how, but code in that commit
sometimes fails to preserve EBP.

See https://bugzilla.kernel.org/show_bug.cgi?id=101061
Problems while executing 32-bit code on AMD64

Reported-and-tested-by: Krzysztof A. Sobiecki sob...@gmail.com
Signed-off-by: Denys Vlasenko dvlas...@redhat.com
Cc: Linus Torvalds torva...@linux-foundation.org
Cc: Steven Rostedt rost...@goodmis.org
Cc: Borislav Petkov b...@alien8.de
Cc: Andy Lutomirski l...@amacapital.net
Cc: Oleg Nesterov o...@redhat.com
Cc: Frederic Weisbecker fweis...@gmail.com
Cc: Alexei Starovoitov a...@plumgrid.com
Cc: Will Drewry w...@chromium.org
Cc: Kees Cook keesc...@chromium.org
CC: x...@kernel.org
Link: 
http://lkml.kernel.org/r/1437740203-11552-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Thomas Gleixner t...@linutronix.de
---
 arch/x86/entry/entry_64_compat.S | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/arch/x86/entry/entry_64_compat.S b/arch/x86/entry/entry_64_compat.S
index bb187a6..5a18447 100644
--- a/arch/x86/entry/entry_64_compat.S
+++ b/arch/x86/entry/entry_64_compat.S
@@ -205,7 +205,6 @@ sysexit_from_sys_call:
movlRDX(%rsp), %edx /* arg3 */
movlRSI(%rsp), %ecx /* arg4 */
movlRDI(%rsp), %r8d /* arg5 */
-   movl%ebp, %r9d  /* arg6 */
.endm
 
.macro auditsys_exit exit
@@ -236,6 +235,7 @@ sysexit_from_sys_call:
 
 sysenter_auditsys:
auditsys_entry_common
+   movl%ebp, %r9d  /* reload 6th syscall arg */
jmp sysenter_dispatch
 
 sysexit_audit:
@@ -336,7 +336,7 @@ ENTRY(entry_SYSCALL_compat)
 * 32-bit zero extended:
 */
ASM_STAC
-1: movl(%r8), %ebp
+1: movl(%r8), %r9d
_ASM_EXTABLE(1b, ia32_badarg)
ASM_CLAC
orl $TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS)
@@ -346,7 +346,7 @@ ENTRY(entry_SYSCALL_compat)
 cstar_do_call:
/* 32-bit syscall - 64-bit C ABI argument conversion */
movl%edi, %r8d  /* arg5 */
-   movl%ebp, %r9d  /* arg6 */
+   /* r9 already loaded */ /* arg6 */
xchg%ecx, %esi  /* rsi:arg2, rcx:arg4 */
movl%ebx, %edi  /* arg1 */
movl%edx, %edx  /* arg3 (zero extension) */
@@ -358,7 +358,6 @@ cstar_dispatch:
call*ia32_sys_call_table(, %rax, 8)
movq%rax, RAX(%rsp)
 1:
-   movlRCX(%rsp), %ebp
DISABLE_INTERRUPTS(CLBR_NONE)
TRACE_IRQS_OFF
testl   $_TIF_ALLWORK_MASK, ASM_THREAD_INFO(TI_flags, %rsp, 
SIZEOF_PTREGS)
@@ -392,7 +391,9 @@ sysretl_from_sys_call:
 
 #ifdef CONFIG_AUDITSYSCALL
 cstar_auditsys:
+   movl%r9d, R9(%rsp)  /* register to be clobbered by call */
auditsys_entry_common
+   movlR9(%rsp), %r9d  /* reload 6th syscall arg */
jmp cstar_dispatch
 
 sysretl_audit:
@@ -404,14 +405,16 @@ cstar_tracesys:
testl   $(_TIF_WORK_SYSCALL_ENTRY  ~_TIF_SYSCALL_AUDIT), 
ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS)
jz  cstar_auditsys
 #endif
+   xchgl   %r9d, %ebp
SAVE_EXTRA_REGS
xorl%eax, %eax  /* Do not leak kernel information */
movq%rax, R11(%rsp)
movq%rax, R10(%rsp)
-   movq%rax, R9(%rsp)
+   movq%r9, R9(%rsp)
movq%rax, R8(%rsp)
movq%rsp, %rdi  /* pt_regs - arg1 */
callsyscall_trace_enter
+   movlR9(%rsp), %r9d
 
/* Reload arg registers from stack. (see sysenter_tracesys) */
movlRCX(%rsp), %ecx
@@ -421,6 +424,7 @@ cstar_tracesys:
movl%eax, %eax  /* zero extension */
 
RESTORE_EXTRA_REGS
+   xchgl   %ebp, %r9d
jmp cstar_do_call
 END(entry_SYSCALL_compat)
 
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/asm] locking/spinlocks: Force inlining of spinlock ops

2015-07-21 Thread tip-bot for Denys Vlasenko
Commit-ID:  3490565b633c705d2fb1f6ede51228952664663d
Gitweb: http://git.kernel.org/tip/3490565b633c705d2fb1f6ede51228952664663d
Author: Denys Vlasenko 
AuthorDate: Mon, 13 Jul 2015 20:31:03 +0200
Committer:  Ingo Molnar 
CommitDate: Tue, 21 Jul 2015 10:14:07 +0200

locking/spinlocks: Force inlining of spinlock ops

With both gcc 4.7.2 and 4.9.2, sometimes GCC mysteriously
doesn't inline very small functions we expect to be inlined.
See:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66122

In particular, with this config:

   http://busybox.net/~vda/kernel_config

there are more than a thousand copies of tiny spinlock-related
functions:

  $ nm --size-sort vmlinux | grep -iF ' t ' | uniq -c | grep -v '^ *1 ' | sort 
-rn | grep ' spin'
473 000b t spin_unlock_irqrestore
292 000b t spin_unlock
215 000b t spin_lock
134 000b t spin_unlock_irq
130 000b t spin_unlock_bh
120 000b t spin_lock_irq
106 000b t spin_lock_bh

Disassembly:

 81004720 :
 81004720:   55  push   %rbp
 81004721:   48 89 e5mov%rsp,%rbp
 81004724:   e8 f8 4e e2 02  callq <_raw_spin_lock>
 81004729:   5d  pop%rbp
 8100472a:   c3  retq

This patch fixes this via s/inline/__always_inline/ in
spinlock.h. This decreases vmlinux by about 40k:

  text data  bss   dec hex filename
  82375570 22255544 20627456 125258570 7774b4a vmlinux.before
  82335059 22255416 20627456 125217931 776ac8b vmlinux

Signed-off-by: Denys Vlasenko 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Bart Van Assche 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: David Rientjes 
Cc: H. Peter Anvin 
Cc: Linus Torvalds 
Cc: Paul E. McKenney 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: Thomas Graf 
Link: 
http://lkml.kernel.org/r/1436812263-15243-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 include/linux/spinlock.h | 30 +++---
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/include/linux/spinlock.h b/include/linux/spinlock.h
index 0063b24..ffcd053 100644
--- a/include/linux/spinlock.h
+++ b/include/linux/spinlock.h
@@ -296,7 +296,7 @@ static inline void do_raw_spin_unlock(raw_spinlock_t *lock) 
__releases(lock)
  * Map the spin_lock functions to the raw variants for PREEMPT_RT=n
  */
 
-static inline raw_spinlock_t *spinlock_check(spinlock_t *lock)
+static __always_inline raw_spinlock_t *spinlock_check(spinlock_t *lock)
 {
return >rlock;
 }
@@ -307,17 +307,17 @@ do {  
\
raw_spin_lock_init(&(_lock)->rlock);\
 } while (0)
 
-static inline void spin_lock(spinlock_t *lock)
+static __always_inline void spin_lock(spinlock_t *lock)
 {
raw_spin_lock(>rlock);
 }
 
-static inline void spin_lock_bh(spinlock_t *lock)
+static __always_inline void spin_lock_bh(spinlock_t *lock)
 {
raw_spin_lock_bh(>rlock);
 }
 
-static inline int spin_trylock(spinlock_t *lock)
+static __always_inline int spin_trylock(spinlock_t *lock)
 {
return raw_spin_trylock(>rlock);
 }
@@ -337,7 +337,7 @@ do {
\
raw_spin_lock_nest_lock(spinlock_check(lock), nest_lock);   \
 } while (0)
 
-static inline void spin_lock_irq(spinlock_t *lock)
+static __always_inline void spin_lock_irq(spinlock_t *lock)
 {
raw_spin_lock_irq(>rlock);
 }
@@ -352,32 +352,32 @@ do {  
\
raw_spin_lock_irqsave_nested(spinlock_check(lock), flags, subclass); \
 } while (0)
 
-static inline void spin_unlock(spinlock_t *lock)
+static __always_inline void spin_unlock(spinlock_t *lock)
 {
raw_spin_unlock(>rlock);
 }
 
-static inline void spin_unlock_bh(spinlock_t *lock)
+static __always_inline void spin_unlock_bh(spinlock_t *lock)
 {
raw_spin_unlock_bh(>rlock);
 }
 
-static inline void spin_unlock_irq(spinlock_t *lock)
+static __always_inline void spin_unlock_irq(spinlock_t *lock)
 {
raw_spin_unlock_irq(>rlock);
 }
 
-static inline void spin_unlock_irqrestore(spinlock_t *lock, unsigned long 
flags)
+static __always_inline void spin_unlock_irqrestore(spinlock_t *lock, unsigned 
long flags)
 {
raw_spin_unlock_irqrestore(>rlock, flags);
 }
 
-static inline int spin_trylock_bh(spinlock_t *lock)
+static __always_inline int spin_trylock_bh(spinlock_t *lock)
 {
return raw_spin_trylock_bh(>rlock);
 }
 
-static inline int spin_trylock_irq(spinlock_t *lock)
+static __always_inline int spin_trylock_irq(spinlock_t *lock)
 {
return raw_spin_trylock_irq(>rlock);
 }
@@ -387,22 +387,22 @@ static inline int spin_trylock_irq(spinlock_t *lock)
raw_spin_trylock_irqsave(spinlock_check(lock), flags); 

[tip:x86/asm] locking/spinlocks: Force inlining of spinlock ops

2015-07-21 Thread tip-bot for Denys Vlasenko
Commit-ID:  3490565b633c705d2fb1f6ede51228952664663d
Gitweb: http://git.kernel.org/tip/3490565b633c705d2fb1f6ede51228952664663d
Author: Denys Vlasenko dvlas...@redhat.com
AuthorDate: Mon, 13 Jul 2015 20:31:03 +0200
Committer:  Ingo Molnar mi...@kernel.org
CommitDate: Tue, 21 Jul 2015 10:14:07 +0200

locking/spinlocks: Force inlining of spinlock ops

With both gcc 4.7.2 and 4.9.2, sometimes GCC mysteriously
doesn't inline very small functions we expect to be inlined.
See:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66122

In particular, with this config:

   http://busybox.net/~vda/kernel_config

there are more than a thousand copies of tiny spinlock-related
functions:

  $ nm --size-sort vmlinux | grep -iF ' t ' | uniq -c | grep -v '^ *1 ' | sort 
-rn | grep ' spin'
473 000b t spin_unlock_irqrestore
292 000b t spin_unlock
215 000b t spin_lock
134 000b t spin_unlock_irq
130 000b t spin_unlock_bh
120 000b t spin_lock_irq
106 000b t spin_lock_bh

Disassembly:

 81004720 spin_lock:
 81004720:   55  push   %rbp
 81004721:   48 89 e5mov%rsp,%rbp
 81004724:   e8 f8 4e e2 02  callq _raw_spin_lock
 81004729:   5d  pop%rbp
 8100472a:   c3  retq

This patch fixes this via s/inline/__always_inline/ in
spinlock.h. This decreases vmlinux by about 40k:

  text data  bss   dec hex filename
  82375570 22255544 20627456 125258570 7774b4a vmlinux.before
  82335059 22255416 20627456 125217931 776ac8b vmlinux

Signed-off-by: Denys Vlasenko dvlas...@redhat.com
Cc: Andrew Morton a...@linux-foundation.org
Cc: Andy Lutomirski l...@amacapital.net
Cc: Bart Van Assche bvanass...@acm.org
Cc: Borislav Petkov b...@alien8.de
Cc: Brian Gerst brge...@gmail.com
Cc: David Rientjes rient...@google.com
Cc: H. Peter Anvin h...@zytor.com
Cc: Linus Torvalds torva...@linux-foundation.org
Cc: Paul E. McKenney paul...@linux.vnet.ibm.com
Cc: Peter Zijlstra pet...@infradead.org
Cc: Thomas Gleixner t...@linutronix.de
Cc: Thomas Graf tg...@suug.ch
Link: 
http://lkml.kernel.org/r/1436812263-15243-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar mi...@kernel.org
---
 include/linux/spinlock.h | 30 +++---
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/include/linux/spinlock.h b/include/linux/spinlock.h
index 0063b24..ffcd053 100644
--- a/include/linux/spinlock.h
+++ b/include/linux/spinlock.h
@@ -296,7 +296,7 @@ static inline void do_raw_spin_unlock(raw_spinlock_t *lock) 
__releases(lock)
  * Map the spin_lock functions to the raw variants for PREEMPT_RT=n
  */
 
-static inline raw_spinlock_t *spinlock_check(spinlock_t *lock)
+static __always_inline raw_spinlock_t *spinlock_check(spinlock_t *lock)
 {
return lock-rlock;
 }
@@ -307,17 +307,17 @@ do {  
\
raw_spin_lock_init((_lock)-rlock);\
 } while (0)
 
-static inline void spin_lock(spinlock_t *lock)
+static __always_inline void spin_lock(spinlock_t *lock)
 {
raw_spin_lock(lock-rlock);
 }
 
-static inline void spin_lock_bh(spinlock_t *lock)
+static __always_inline void spin_lock_bh(spinlock_t *lock)
 {
raw_spin_lock_bh(lock-rlock);
 }
 
-static inline int spin_trylock(spinlock_t *lock)
+static __always_inline int spin_trylock(spinlock_t *lock)
 {
return raw_spin_trylock(lock-rlock);
 }
@@ -337,7 +337,7 @@ do {
\
raw_spin_lock_nest_lock(spinlock_check(lock), nest_lock);   \
 } while (0)
 
-static inline void spin_lock_irq(spinlock_t *lock)
+static __always_inline void spin_lock_irq(spinlock_t *lock)
 {
raw_spin_lock_irq(lock-rlock);
 }
@@ -352,32 +352,32 @@ do {  
\
raw_spin_lock_irqsave_nested(spinlock_check(lock), flags, subclass); \
 } while (0)
 
-static inline void spin_unlock(spinlock_t *lock)
+static __always_inline void spin_unlock(spinlock_t *lock)
 {
raw_spin_unlock(lock-rlock);
 }
 
-static inline void spin_unlock_bh(spinlock_t *lock)
+static __always_inline void spin_unlock_bh(spinlock_t *lock)
 {
raw_spin_unlock_bh(lock-rlock);
 }
 
-static inline void spin_unlock_irq(spinlock_t *lock)
+static __always_inline void spin_unlock_irq(spinlock_t *lock)
 {
raw_spin_unlock_irq(lock-rlock);
 }
 
-static inline void spin_unlock_irqrestore(spinlock_t *lock, unsigned long 
flags)
+static __always_inline void spin_unlock_irqrestore(spinlock_t *lock, unsigned 
long flags)
 {
raw_spin_unlock_irqrestore(lock-rlock, flags);
 }
 
-static inline int spin_trylock_bh(spinlock_t *lock)
+static __always_inline int spin_trylock_bh(spinlock_t *lock)
 {

[tip:x86/asm] x86/asm/entry/32: Replace RESTORE_RSI_RDI with open-coded 32-bit reads

2015-07-06 Thread tip-bot for Denys Vlasenko
Commit-ID:  c73e36b775a777abd67a1e15481923fcbd2040e1
Gitweb: http://git.kernel.org/tip/c73e36b775a777abd67a1e15481923fcbd2040e1
Author: Denys Vlasenko 
AuthorDate: Fri, 3 Jul 2015 22:19:02 +0200
Committer:  Ingo Molnar 
CommitDate: Mon, 6 Jul 2015 14:56:50 +0200

x86/asm/entry/32: Replace RESTORE_RSI_RDI with open-coded 32-bit reads

This doesn't change much, but uses shorter 32-bit insns:

-48 8b 74 24 68 mov0x68(%rsp),%rsi
-48 8b 7c 24 70 mov0x70(%rsp),%rdi
-48 8b 54 24 60 mov0x60(%rsp),%rdx
+8b 54 24 60mov0x60(%rsp),%edx
+8b 74 24 68mov0x68(%rsp),%esi
+8b 7c 24 70mov0x70(%rsp),%edi

and does the loads in pt_regs order.

Since these are the only uses of RESTORE_RSI_RDI[_RDX], drop
these macros.

Signed-off-by: Denys Vlasenko 
Cc: Alexei Starovoitov 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Frederic Weisbecker 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Oleg Nesterov 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Cc: Thomas Gleixner 
Cc: Will Drewry 
Link: 
http://lkml.kernel.org/r/1435954742-2545-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/entry/calling.h | 6 --
 arch/x86/entry/entry_64_compat.S | 7 +--
 2 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/arch/x86/entry/calling.h b/arch/x86/entry/calling.h
index f4e6308..519207f 100644
--- a/arch/x86/entry/calling.h
+++ b/arch/x86/entry/calling.h
@@ -193,12 +193,6 @@ For 32-bit we have the following conventions - kernel is 
built with
.macro RESTORE_C_REGS_EXCEPT_RCX_R11
RESTORE_C_REGS_HELPER 1,0,0,1,1
.endm
-   .macro RESTORE_RSI_RDI
-   RESTORE_C_REGS_HELPER 0,0,0,0,0
-   .endm
-   .macro RESTORE_RSI_RDI_RDX
-   RESTORE_C_REGS_HELPER 0,0,0,0,1
-   .endm
 
.macro REMOVE_PT_GPREGS_FROM_STACK addskip=0
subq $-(15*8+\addskip), %rsp
diff --git a/arch/x86/entry/entry_64_compat.S b/arch/x86/entry/entry_64_compat.S
index bb187a6..b868cfc 100644
--- a/arch/x86/entry/entry_64_compat.S
+++ b/arch/x86/entry/entry_64_compat.S
@@ -140,7 +140,8 @@ sysexit_from_sys_call:
 */
andl$~TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS)
movlRIP(%rsp), %ecx /* User %eip */
-   RESTORE_RSI_RDI
+   movlRSI(%rsp), %esi
+   movlRDI(%rsp), %edi
xorl%edx, %edx  /* Do not leak kernel information */
xorq%r8, %r8
xorq%r9, %r9
@@ -366,7 +367,9 @@ cstar_dispatch:
 
 sysretl_from_sys_call:
andl$~TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS)
-   RESTORE_RSI_RDI_RDX
+   movlRDX(%rsp), %edx
+   movlRSI(%rsp), %esi
+   movlRDI(%rsp), %edi
movlRIP(%rsp), %ecx
movlEFLAGS(%rsp), %r11d
xorq%r10, %r10
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/asm] x86/asm/entry/32: Replace RESTORE_RSI_RDI with open-coded 32-bit reads

2015-07-06 Thread tip-bot for Denys Vlasenko
Commit-ID:  c73e36b775a777abd67a1e15481923fcbd2040e1
Gitweb: http://git.kernel.org/tip/c73e36b775a777abd67a1e15481923fcbd2040e1
Author: Denys Vlasenko dvlas...@redhat.com
AuthorDate: Fri, 3 Jul 2015 22:19:02 +0200
Committer:  Ingo Molnar mi...@kernel.org
CommitDate: Mon, 6 Jul 2015 14:56:50 +0200

x86/asm/entry/32: Replace RESTORE_RSI_RDI with open-coded 32-bit reads

This doesn't change much, but uses shorter 32-bit insns:

-48 8b 74 24 68 mov0x68(%rsp),%rsi
-48 8b 7c 24 70 mov0x70(%rsp),%rdi
-48 8b 54 24 60 mov0x60(%rsp),%rdx
+8b 54 24 60mov0x60(%rsp),%edx
+8b 74 24 68mov0x68(%rsp),%esi
+8b 7c 24 70mov0x70(%rsp),%edi

and does the loads in pt_regs order.

Since these are the only uses of RESTORE_RSI_RDI[_RDX], drop
these macros.

Signed-off-by: Denys Vlasenko dvlas...@redhat.com
Cc: Alexei Starovoitov a...@plumgrid.com
Cc: Andy Lutomirski l...@amacapital.net
Cc: Borislav Petkov b...@alien8.de
Cc: Frederic Weisbecker fweis...@gmail.com
Cc: H. Peter Anvin h...@zytor.com
Cc: Kees Cook keesc...@chromium.org
Cc: Linus Torvalds torva...@linux-foundation.org
Cc: Oleg Nesterov o...@redhat.com
Cc: Peter Zijlstra pet...@infradead.org
Cc: Steven Rostedt rost...@goodmis.org
Cc: Thomas Gleixner t...@linutronix.de
Cc: Will Drewry w...@chromium.org
Link: 
http://lkml.kernel.org/r/1435954742-2545-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar mi...@kernel.org
---
 arch/x86/entry/calling.h | 6 --
 arch/x86/entry/entry_64_compat.S | 7 +--
 2 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/arch/x86/entry/calling.h b/arch/x86/entry/calling.h
index f4e6308..519207f 100644
--- a/arch/x86/entry/calling.h
+++ b/arch/x86/entry/calling.h
@@ -193,12 +193,6 @@ For 32-bit we have the following conventions - kernel is 
built with
.macro RESTORE_C_REGS_EXCEPT_RCX_R11
RESTORE_C_REGS_HELPER 1,0,0,1,1
.endm
-   .macro RESTORE_RSI_RDI
-   RESTORE_C_REGS_HELPER 0,0,0,0,0
-   .endm
-   .macro RESTORE_RSI_RDI_RDX
-   RESTORE_C_REGS_HELPER 0,0,0,0,1
-   .endm
 
.macro REMOVE_PT_GPREGS_FROM_STACK addskip=0
subq $-(15*8+\addskip), %rsp
diff --git a/arch/x86/entry/entry_64_compat.S b/arch/x86/entry/entry_64_compat.S
index bb187a6..b868cfc 100644
--- a/arch/x86/entry/entry_64_compat.S
+++ b/arch/x86/entry/entry_64_compat.S
@@ -140,7 +140,8 @@ sysexit_from_sys_call:
 */
andl$~TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS)
movlRIP(%rsp), %ecx /* User %eip */
-   RESTORE_RSI_RDI
+   movlRSI(%rsp), %esi
+   movlRDI(%rsp), %edi
xorl%edx, %edx  /* Do not leak kernel information */
xorq%r8, %r8
xorq%r9, %r9
@@ -366,7 +367,9 @@ cstar_dispatch:
 
 sysretl_from_sys_call:
andl$~TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS)
-   RESTORE_RSI_RDI_RDX
+   movlRDX(%rsp), %edx
+   movlRSI(%rsp), %esi
+   movlRDI(%rsp), %edi
movlRIP(%rsp), %ecx
movlEFLAGS(%rsp), %r11d
xorq%r10, %r10
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/asm] x86/asm/entry/32: Explain reloading of registers after __audit_syscall_entry()

2015-06-10 Thread tip-bot for Denys Vlasenko
Commit-ID:  1536bb46fac7672ef046a3b07848314263bc
Gitweb: http://git.kernel.org/tip/1536bb46fac7672ef046a3b07848314263bc
Author: Denys Vlasenko 
AuthorDate: Tue, 9 Jun 2015 20:54:08 +0200
Committer:  Ingo Molnar 
CommitDate: Wed, 10 Jun 2015 08:42:13 +0200

x86/asm/entry/32: Explain reloading of registers after __audit_syscall_entry()

Here it is not obvious why we load pt_regs->cx to %esi etc.
Lets improve comments.

Explain that here we combine two things: first, we reload
registers since some of them are clobbered by the C function we
just called; and we also convert 32-bit syscall params to 64-bit
C ABI, because we are going to jump back to syscall dispatch
code.

Move reloading of 6th argument into the macro instead of having
it after each of two macro invocations.

No actual code changes here.

Signed-off-by: Denys Vlasenko 
Cc: Alexei Starovoitov 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Frederic Weisbecker 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Oleg Nesterov 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Cc: Thomas Gleixner 
Cc: Will Drewry 
Link: 
http://lkml.kernel.org/r/1433876051-26604-2-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/entry/entry_64_compat.S | 20 
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/arch/x86/entry/entry_64_compat.S b/arch/x86/entry/entry_64_compat.S
index 2c44180..0fa108c 100644
--- a/arch/x86/entry/entry_64_compat.S
+++ b/arch/x86/entry/entry_64_compat.S
@@ -185,12 +185,18 @@ sysexit_from_sys_call:
movl%ebx, %esi  /* 2nd arg: 1st syscall arg */
movl%eax, %edi  /* 1st arg: syscall number */
call__audit_syscall_entry
-   movlORIG_RAX(%rsp), %eax/* reload syscall number */
-   movl%ebx, %edi  /* reload 1st syscall arg */
-   movlRCX(%rsp), %esi /* reload 2nd syscall arg */
-   movlRDX(%rsp), %edx /* reload 3rd syscall arg */
-   movlRSI(%rsp), %ecx /* reload 4th syscall arg */
-   movlRDI(%rsp), %r8d /* reload 5th syscall arg */
+   /*
+* We are going to jump back to syscall dispatch.
+* Prepare syscall args as required by 64-bit C ABI.
+* Clobbered registers are loaded from pt_regs on stack.
+*/
+   movlORIG_RAX(%rsp), %eax/* syscall number */
+   movl%ebx, %edi  /* arg1 */
+   movlRCX(%rsp), %esi /* arg2 */
+   movlRDX(%rsp), %edx /* arg3 */
+   movlRSI(%rsp), %ecx /* arg4 */
+   movlRDI(%rsp), %r8d /* arg5 */
+   movl%ebp, %r9d  /* arg6 */
.endm
 
.macro auditsys_exit exit
@@ -221,7 +227,6 @@ sysexit_from_sys_call:
 
 sysenter_auditsys:
auditsys_entry_common
-   movl%ebp, %r9d  /* reload 6th syscall arg */
jmp sysenter_dispatch
 
 sysexit_audit:
@@ -379,7 +384,6 @@ sysretl_from_sys_call:
 #ifdef CONFIG_AUDITSYSCALL
 cstar_auditsys:
auditsys_entry_common
-   movl%ebp, %r9d  /* reload 6th syscall arg */
jmp cstar_dispatch
 
 sysretl_audit:
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/asm] x86/asm/entry/32: Shorten __audit_syscall_entry() args preparation

2015-06-10 Thread tip-bot for Denys Vlasenko
Commit-ID:  a92fde25231a89d7d10895482556260c1b63767d
Gitweb: http://git.kernel.org/tip/a92fde25231a89d7d10895482556260c1b63767d
Author: Denys Vlasenko 
AuthorDate: Tue, 9 Jun 2015 20:54:09 +0200
Committer:  Ingo Molnar 
CommitDate: Wed, 10 Jun 2015 08:42:13 +0200

x86/asm/entry/32: Shorten __audit_syscall_entry() args preparation

We use three MOVs to swap edx and ecx. We can use one XCHG
instead.

Expand the comments. It's difficult to keep track which arg#
every register corresponds to, so spell it out.

Signed-off-by: Denys Vlasenko 
Cc: Alexei Starovoitov 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Frederic Weisbecker 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Oleg Nesterov 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Cc: Thomas Gleixner 
Cc: Will Drewry 
Link: 
http://lkml.kernel.org/r/1433876051-26604-3-git-send-email-dvlas...@redhat.com
[ Expanded the comments some more. ]
Signed-off-by: Ingo Molnar 
---
 arch/x86/entry/entry_64_compat.S | 27 ++-
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/arch/x86/entry/entry_64_compat.S b/arch/x86/entry/entry_64_compat.S
index 0fa108c..bb187a6 100644
--- a/arch/x86/entry/entry_64_compat.S
+++ b/arch/x86/entry/entry_64_compat.S
@@ -178,17 +178,26 @@ sysexit_from_sys_call:
 
 #ifdef CONFIG_AUDITSYSCALL
.macro auditsys_entry_common
-   movl%esi, %r8d  /* 5th arg: 4th syscall arg */
-   movl%ecx, %r9d  /* swap with edx */
-   movl%edx, %ecx  /* 4th arg: 3rd syscall arg */
-   movl%r9d, %edx  /* 3rd arg: 2nd syscall arg */
-   movl%ebx, %esi  /* 2nd arg: 1st syscall arg */
-   movl%eax, %edi  /* 1st arg: syscall number */
+   /*
+* At this point, registers hold syscall args in the 32-bit syscall ABI:
+* EAX is syscall number, the 6 args are in EBX,ECX,EDX,ESI,EDI,EBP.
+*
+* We want to pass them to __audit_syscall_entry(), which is a 64-bit
+* C function with 5 parameters, so shuffle them to match what
+* the function expects: RDI,RSI,RDX,RCX,R8.
+*/
+   movl%esi, %r8d  /* arg5 (R8 ) <= 4th syscall arg (ESI) 
*/
+   xchg%ecx, %edx  /* arg4 (RCX) <= 3rd syscall arg (EDX) 
*/
+   /* arg3 (RDX) <= 2nd syscall arg (ECX) 
*/
+   movl%ebx, %esi  /* arg2 (RSI) <= 1st syscall arg (EBX) 
*/
+   movl%eax, %edi  /* arg1 (RDI) <= syscall number  (EAX) 
*/
call__audit_syscall_entry
+
/*
-* We are going to jump back to syscall dispatch.
-* Prepare syscall args as required by 64-bit C ABI.
-* Clobbered registers are loaded from pt_regs on stack.
+* We are going to jump back to the syscall dispatch code.
+* Prepare syscall args as required by the 64-bit C ABI.
+* Registers clobbered by __audit_syscall_entry() are
+* loaded from pt_regs on stack:
 */
movlORIG_RAX(%rsp), %eax/* syscall number */
movl%ebx, %edi  /* arg1 */
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/asm] x86/asm/entry/32: Fix fallout from the R9 trick removal in the SYSCALL code

2015-06-10 Thread tip-bot for Denys Vlasenko
Commit-ID:  aee4b013a71666f11ffeac11ab45bb7c6e0e394d
Gitweb: http://git.kernel.org/tip/aee4b013a71666f11ffeac11ab45bb7c6e0e394d
Author: Denys Vlasenko 
AuthorDate: Tue, 9 Jun 2015 20:54:07 +0200
Committer:  Ingo Molnar 
CommitDate: Wed, 10 Jun 2015 08:42:12 +0200

x86/asm/entry/32: Fix fallout from the R9 trick removal in the SYSCALL code

I put %ebp restoration code too late. Under strace, it is not
reached and %ebp is not restored upon return to userspace.

This is the fix. Run-tested.

Signed-off-by: Denys Vlasenko 
Cc: Alexei Starovoitov 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Frederic Weisbecker 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Oleg Nesterov 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Cc: Thomas Gleixner 
Cc: Will Drewry 
Link: 
http://lkml.kernel.org/r/1433876051-26604-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/entry/entry_64_compat.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/entry/entry_64_compat.S b/arch/x86/entry/entry_64_compat.S
index 2093ce6..2c44180 100644
--- a/arch/x86/entry/entry_64_compat.S
+++ b/arch/x86/entry/entry_64_compat.S
@@ -344,6 +344,7 @@ cstar_dispatch:
call*ia32_sys_call_table(, %rax, 8)
movq%rax, RAX(%rsp)
 1:
+   movlRCX(%rsp), %ebp
DISABLE_INTERRUPTS(CLBR_NONE)
TRACE_IRQS_OFF
testl   $_TIF_ALLWORK_MASK, ASM_THREAD_INFO(TI_flags, %rsp, 
SIZEOF_PTREGS)
@@ -351,7 +352,6 @@ cstar_dispatch:
 
 sysretl_from_sys_call:
andl$~TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS)
-   movlRCX(%rsp), %ebp
RESTORE_RSI_RDI_RDX
movlRIP(%rsp), %ecx
movlEFLAGS(%rsp), %r11d
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/asm] x86/asm/entry/32: Explain reloading of registers after __audit_syscall_entry()

2015-06-10 Thread tip-bot for Denys Vlasenko
Commit-ID:  1536bb46fac7672ef046a3b07848314263bc
Gitweb: http://git.kernel.org/tip/1536bb46fac7672ef046a3b07848314263bc
Author: Denys Vlasenko dvlas...@redhat.com
AuthorDate: Tue, 9 Jun 2015 20:54:08 +0200
Committer:  Ingo Molnar mi...@kernel.org
CommitDate: Wed, 10 Jun 2015 08:42:13 +0200

x86/asm/entry/32: Explain reloading of registers after __audit_syscall_entry()

Here it is not obvious why we load pt_regs-cx to %esi etc.
Lets improve comments.

Explain that here we combine two things: first, we reload
registers since some of them are clobbered by the C function we
just called; and we also convert 32-bit syscall params to 64-bit
C ABI, because we are going to jump back to syscall dispatch
code.

Move reloading of 6th argument into the macro instead of having
it after each of two macro invocations.

No actual code changes here.

Signed-off-by: Denys Vlasenko dvlas...@redhat.com
Cc: Alexei Starovoitov a...@plumgrid.com
Cc: Andrew Morton a...@linux-foundation.org
Cc: Andy Lutomirski l...@amacapital.net
Cc: Borislav Petkov b...@alien8.de
Cc: Frederic Weisbecker fweis...@gmail.com
Cc: H. Peter Anvin h...@zytor.com
Cc: Kees Cook keesc...@chromium.org
Cc: Linus Torvalds torva...@linux-foundation.org
Cc: Oleg Nesterov o...@redhat.com
Cc: Peter Zijlstra pet...@infradead.org
Cc: Steven Rostedt rost...@goodmis.org
Cc: Thomas Gleixner t...@linutronix.de
Cc: Will Drewry w...@chromium.org
Link: 
http://lkml.kernel.org/r/1433876051-26604-2-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar mi...@kernel.org
---
 arch/x86/entry/entry_64_compat.S | 20 
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/arch/x86/entry/entry_64_compat.S b/arch/x86/entry/entry_64_compat.S
index 2c44180..0fa108c 100644
--- a/arch/x86/entry/entry_64_compat.S
+++ b/arch/x86/entry/entry_64_compat.S
@@ -185,12 +185,18 @@ sysexit_from_sys_call:
movl%ebx, %esi  /* 2nd arg: 1st syscall arg */
movl%eax, %edi  /* 1st arg: syscall number */
call__audit_syscall_entry
-   movlORIG_RAX(%rsp), %eax/* reload syscall number */
-   movl%ebx, %edi  /* reload 1st syscall arg */
-   movlRCX(%rsp), %esi /* reload 2nd syscall arg */
-   movlRDX(%rsp), %edx /* reload 3rd syscall arg */
-   movlRSI(%rsp), %ecx /* reload 4th syscall arg */
-   movlRDI(%rsp), %r8d /* reload 5th syscall arg */
+   /*
+* We are going to jump back to syscall dispatch.
+* Prepare syscall args as required by 64-bit C ABI.
+* Clobbered registers are loaded from pt_regs on stack.
+*/
+   movlORIG_RAX(%rsp), %eax/* syscall number */
+   movl%ebx, %edi  /* arg1 */
+   movlRCX(%rsp), %esi /* arg2 */
+   movlRDX(%rsp), %edx /* arg3 */
+   movlRSI(%rsp), %ecx /* arg4 */
+   movlRDI(%rsp), %r8d /* arg5 */
+   movl%ebp, %r9d  /* arg6 */
.endm
 
.macro auditsys_exit exit
@@ -221,7 +227,6 @@ sysexit_from_sys_call:
 
 sysenter_auditsys:
auditsys_entry_common
-   movl%ebp, %r9d  /* reload 6th syscall arg */
jmp sysenter_dispatch
 
 sysexit_audit:
@@ -379,7 +384,6 @@ sysretl_from_sys_call:
 #ifdef CONFIG_AUDITSYSCALL
 cstar_auditsys:
auditsys_entry_common
-   movl%ebp, %r9d  /* reload 6th syscall arg */
jmp cstar_dispatch
 
 sysretl_audit:
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/asm] x86/asm/entry/32: Shorten __audit_syscall_entry() args preparation

2015-06-10 Thread tip-bot for Denys Vlasenko
Commit-ID:  a92fde25231a89d7d10895482556260c1b63767d
Gitweb: http://git.kernel.org/tip/a92fde25231a89d7d10895482556260c1b63767d
Author: Denys Vlasenko dvlas...@redhat.com
AuthorDate: Tue, 9 Jun 2015 20:54:09 +0200
Committer:  Ingo Molnar mi...@kernel.org
CommitDate: Wed, 10 Jun 2015 08:42:13 +0200

x86/asm/entry/32: Shorten __audit_syscall_entry() args preparation

We use three MOVs to swap edx and ecx. We can use one XCHG
instead.

Expand the comments. It's difficult to keep track which arg#
every register corresponds to, so spell it out.

Signed-off-by: Denys Vlasenko dvlas...@redhat.com
Cc: Alexei Starovoitov a...@plumgrid.com
Cc: Andrew Morton a...@linux-foundation.org
Cc: Andy Lutomirski l...@amacapital.net
Cc: Borislav Petkov b...@alien8.de
Cc: Brian Gerst brge...@gmail.com
Cc: Frederic Weisbecker fweis...@gmail.com
Cc: H. Peter Anvin h...@zytor.com
Cc: Kees Cook keesc...@chromium.org
Cc: Linus Torvalds torva...@linux-foundation.org
Cc: Oleg Nesterov o...@redhat.com
Cc: Peter Zijlstra pet...@infradead.org
Cc: Steven Rostedt rost...@goodmis.org
Cc: Thomas Gleixner t...@linutronix.de
Cc: Will Drewry w...@chromium.org
Link: 
http://lkml.kernel.org/r/1433876051-26604-3-git-send-email-dvlas...@redhat.com
[ Expanded the comments some more. ]
Signed-off-by: Ingo Molnar mi...@kernel.org
---
 arch/x86/entry/entry_64_compat.S | 27 ++-
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/arch/x86/entry/entry_64_compat.S b/arch/x86/entry/entry_64_compat.S
index 0fa108c..bb187a6 100644
--- a/arch/x86/entry/entry_64_compat.S
+++ b/arch/x86/entry/entry_64_compat.S
@@ -178,17 +178,26 @@ sysexit_from_sys_call:
 
 #ifdef CONFIG_AUDITSYSCALL
.macro auditsys_entry_common
-   movl%esi, %r8d  /* 5th arg: 4th syscall arg */
-   movl%ecx, %r9d  /* swap with edx */
-   movl%edx, %ecx  /* 4th arg: 3rd syscall arg */
-   movl%r9d, %edx  /* 3rd arg: 2nd syscall arg */
-   movl%ebx, %esi  /* 2nd arg: 1st syscall arg */
-   movl%eax, %edi  /* 1st arg: syscall number */
+   /*
+* At this point, registers hold syscall args in the 32-bit syscall ABI:
+* EAX is syscall number, the 6 args are in EBX,ECX,EDX,ESI,EDI,EBP.
+*
+* We want to pass them to __audit_syscall_entry(), which is a 64-bit
+* C function with 5 parameters, so shuffle them to match what
+* the function expects: RDI,RSI,RDX,RCX,R8.
+*/
+   movl%esi, %r8d  /* arg5 (R8 ) = 4th syscall arg (ESI) 
*/
+   xchg%ecx, %edx  /* arg4 (RCX) = 3rd syscall arg (EDX) 
*/
+   /* arg3 (RDX) = 2nd syscall arg (ECX) 
*/
+   movl%ebx, %esi  /* arg2 (RSI) = 1st syscall arg (EBX) 
*/
+   movl%eax, %edi  /* arg1 (RDI) = syscall number  (EAX) 
*/
call__audit_syscall_entry
+
/*
-* We are going to jump back to syscall dispatch.
-* Prepare syscall args as required by 64-bit C ABI.
-* Clobbered registers are loaded from pt_regs on stack.
+* We are going to jump back to the syscall dispatch code.
+* Prepare syscall args as required by the 64-bit C ABI.
+* Registers clobbered by __audit_syscall_entry() are
+* loaded from pt_regs on stack:
 */
movlORIG_RAX(%rsp), %eax/* syscall number */
movl%ebx, %edi  /* arg1 */
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/asm] x86/asm/entry/32: Fix fallout from the R9 trick removal in the SYSCALL code

2015-06-10 Thread tip-bot for Denys Vlasenko
Commit-ID:  aee4b013a71666f11ffeac11ab45bb7c6e0e394d
Gitweb: http://git.kernel.org/tip/aee4b013a71666f11ffeac11ab45bb7c6e0e394d
Author: Denys Vlasenko dvlas...@redhat.com
AuthorDate: Tue, 9 Jun 2015 20:54:07 +0200
Committer:  Ingo Molnar mi...@kernel.org
CommitDate: Wed, 10 Jun 2015 08:42:12 +0200

x86/asm/entry/32: Fix fallout from the R9 trick removal in the SYSCALL code

I put %ebp restoration code too late. Under strace, it is not
reached and %ebp is not restored upon return to userspace.

This is the fix. Run-tested.

Signed-off-by: Denys Vlasenko dvlas...@redhat.com
Cc: Alexei Starovoitov a...@plumgrid.com
Cc: Andrew Morton a...@linux-foundation.org
Cc: Andy Lutomirski l...@amacapital.net
Cc: Borislav Petkov b...@alien8.de
Cc: Frederic Weisbecker fweis...@gmail.com
Cc: H. Peter Anvin h...@zytor.com
Cc: Kees Cook keesc...@chromium.org
Cc: Linus Torvalds torva...@linux-foundation.org
Cc: Oleg Nesterov o...@redhat.com
Cc: Peter Zijlstra pet...@infradead.org
Cc: Steven Rostedt rost...@goodmis.org
Cc: Thomas Gleixner t...@linutronix.de
Cc: Will Drewry w...@chromium.org
Link: 
http://lkml.kernel.org/r/1433876051-26604-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar mi...@kernel.org
---
 arch/x86/entry/entry_64_compat.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/entry/entry_64_compat.S b/arch/x86/entry/entry_64_compat.S
index 2093ce6..2c44180 100644
--- a/arch/x86/entry/entry_64_compat.S
+++ b/arch/x86/entry/entry_64_compat.S
@@ -344,6 +344,7 @@ cstar_dispatch:
call*ia32_sys_call_table(, %rax, 8)
movq%rax, RAX(%rsp)
 1:
+   movlRCX(%rsp), %ebp
DISABLE_INTERRUPTS(CLBR_NONE)
TRACE_IRQS_OFF
testl   $_TIF_ALLWORK_MASK, ASM_THREAD_INFO(TI_flags, %rsp, 
SIZEOF_PTREGS)
@@ -351,7 +352,6 @@ cstar_dispatch:
 
 sysretl_from_sys_call:
andl$~TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS)
-   movlRCX(%rsp), %ebp
RESTORE_RSI_RDI_RDX
movlRIP(%rsp), %ecx
movlEFLAGS(%rsp), %r11d
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/asm] x86/asm/entry/32: Reinstate clearing of pt_regs-> r8..r11 on EFAULT path

2015-06-08 Thread tip-bot for Denys Vlasenko
Commit-ID:  eb47854415825a69b1c578e7487da571227ba25a
Gitweb: http://git.kernel.org/tip/eb47854415825a69b1c578e7487da571227ba25a
Author: Denys Vlasenko 
AuthorDate: Sun, 7 Jun 2015 20:24:30 +0200
Committer:  Ingo Molnar 
CommitDate: Mon, 8 Jun 2015 23:43:37 +0200

x86/asm/entry/32: Reinstate clearing of pt_regs->r8..r11 on EFAULT path

I broke this recently when I changed pt_regs->r8..r11 clearing
logic in INT 80 code path.

There is a branch from SYSENTER/SYSCALL code to INT 80 code:
if we fail to retrieve arg6, we return EFAULT. Before this
patch, in this case we don't clear pt_regs->r8..r11.

This patch fixes this. The resulting code is smaller and
simpler.

While at it, remove incorrect comment about syscall dispatching
CALL insn: it does not use RIP-relative addressing form (the
comment was meant to be "TODO: make this rip-relative", and
morphed since then, dropping "TODO").

Signed-off-by: Denys Vlasenko 
Cc: Alexei Starovoitov 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Frederic Weisbecker 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Oleg Nesterov 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Cc: Thomas Gleixner 
Cc: Will Drewry 
Link: 
http://lkml.kernel.org/r/1433701470-28800-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/entry/entry_64_compat.S | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/arch/x86/entry/entry_64_compat.S b/arch/x86/entry/entry_64_compat.S
index 59840e3..5757dde 100644
--- a/arch/x86/entry/entry_64_compat.S
+++ b/arch/x86/entry/entry_64_compat.S
@@ -413,9 +413,7 @@ END(entry_SYSCALL_compat)
 
 ia32_badarg:
ASM_CLAC
-   movq$-EFAULT, %rax
-   jmp ia32_sysret
-
+   movq$-EFAULT, RAX(%rsp)
 ia32_ret_from_sys_call:
xorl%eax, %eax  /* Do not leak kernel information */
movq%rax, R11(%rsp)
@@ -486,9 +484,7 @@ ia32_do_call:
cmpq$(IA32_NR_syscalls-1), %rax
ja  1f
 
-   call*ia32_sys_call_table(, %rax, 8) /* RIP relative */
-
-ia32_sysret:
+   call*ia32_sys_call_table(, %rax, 8)
movq%rax, RAX(%rsp)
 1:
jmp int_ret_from_sys_call
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/asm] x86/asm/entry/32: Reinstate clearing of pt_regs- r8..r11 on EFAULT path

2015-06-08 Thread tip-bot for Denys Vlasenko
Commit-ID:  eb47854415825a69b1c578e7487da571227ba25a
Gitweb: http://git.kernel.org/tip/eb47854415825a69b1c578e7487da571227ba25a
Author: Denys Vlasenko dvlas...@redhat.com
AuthorDate: Sun, 7 Jun 2015 20:24:30 +0200
Committer:  Ingo Molnar mi...@kernel.org
CommitDate: Mon, 8 Jun 2015 23:43:37 +0200

x86/asm/entry/32: Reinstate clearing of pt_regs-r8..r11 on EFAULT path

I broke this recently when I changed pt_regs-r8..r11 clearing
logic in INT 80 code path.

There is a branch from SYSENTER/SYSCALL code to INT 80 code:
if we fail to retrieve arg6, we return EFAULT. Before this
patch, in this case we don't clear pt_regs-r8..r11.

This patch fixes this. The resulting code is smaller and
simpler.

While at it, remove incorrect comment about syscall dispatching
CALL insn: it does not use RIP-relative addressing form (the
comment was meant to be TODO: make this rip-relative, and
morphed since then, dropping TODO).

Signed-off-by: Denys Vlasenko dvlas...@redhat.com
Cc: Alexei Starovoitov a...@plumgrid.com
Cc: Andrew Morton a...@linux-foundation.org
Cc: Andy Lutomirski l...@amacapital.net
Cc: Borislav Petkov b...@alien8.de
Cc: Frederic Weisbecker fweis...@gmail.com
Cc: H. Peter Anvin h...@zytor.com
Cc: Kees Cook keesc...@chromium.org
Cc: Linus Torvalds torva...@linux-foundation.org
Cc: Oleg Nesterov o...@redhat.com
Cc: Peter Zijlstra pet...@infradead.org
Cc: Steven Rostedt rost...@goodmis.org
Cc: Thomas Gleixner t...@linutronix.de
Cc: Will Drewry w...@chromium.org
Link: 
http://lkml.kernel.org/r/1433701470-28800-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar mi...@kernel.org
---
 arch/x86/entry/entry_64_compat.S | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/arch/x86/entry/entry_64_compat.S b/arch/x86/entry/entry_64_compat.S
index 59840e3..5757dde 100644
--- a/arch/x86/entry/entry_64_compat.S
+++ b/arch/x86/entry/entry_64_compat.S
@@ -413,9 +413,7 @@ END(entry_SYSCALL_compat)
 
 ia32_badarg:
ASM_CLAC
-   movq$-EFAULT, %rax
-   jmp ia32_sysret
-
+   movq$-EFAULT, RAX(%rsp)
 ia32_ret_from_sys_call:
xorl%eax, %eax  /* Do not leak kernel information */
movq%rax, R11(%rsp)
@@ -486,9 +484,7 @@ ia32_do_call:
cmpq$(IA32_NR_syscalls-1), %rax
ja  1f
 
-   call*ia32_sys_call_table(, %rax, 8) /* RIP relative */
-
-ia32_sysret:
+   call*ia32_sys_call_table(, %rax, 8)
movq%rax, RAX(%rsp)
 1:
jmp int_ret_from_sys_call
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/asm] x86/asm/entry/32: Explain the stub32_clone logic

2015-06-07 Thread tip-bot for Denys Vlasenko
Commit-ID:  5cdc683b7d8b3341a3d18e0c5498bc1e4f3fb990
Gitweb: http://git.kernel.org/tip/5cdc683b7d8b3341a3d18e0c5498bc1e4f3fb990
Author: Denys Vlasenko 
AuthorDate: Wed, 3 Jun 2015 15:58:49 +0200
Committer:  Ingo Molnar 
CommitDate: Fri, 5 Jun 2015 13:41:27 +0200

x86/asm/entry/32: Explain the stub32_clone logic

The reason for copying of %r8 to %rcx is quite non-obvious.
Add a comment which explains why it is done.

Signed-off-by: Denys Vlasenko 
Cc: Alexei Starovoitov 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Frederic Weisbecker 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Oleg Nesterov 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Cc: Thomas Gleixner 
Cc: Will Drewry 
Link: 
http://lkml.kernel.org/r/149930-20880-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/entry/ia32entry.S | 8 
 1 file changed, 8 insertions(+)

diff --git a/arch/x86/entry/ia32entry.S b/arch/x86/entry/ia32entry.S
index 4bb9f7b..d0c7b28 100644
--- a/arch/x86/entry/ia32entry.S
+++ b/arch/x86/entry/ia32entry.S
@@ -528,6 +528,14 @@ GLOBAL(\label)
ALIGN
 GLOBAL(stub32_clone)
leaqsys_clone(%rip), %rax
+   /*
+* 32-bit clone API is clone(..., int tls_val, int *child_tidptr).
+* 64-bit clone API is clone(..., int *child_tidptr, int tls_val).
+* Native 64-bit kernel's sys_clone() implements the latter.
+* We need to swap args here. But since tls_val is in fact ignored
+* by sys_clone(), we can get away with an assignment
+* (arg4 = arg5) instead of a full swap:
+*/
mov %r8, %rcx
jmp ia32_ptregs_common
 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/asm] x86/asm/entry/32: Remove unnecessary optimization in stub32_clone

2015-06-07 Thread tip-bot for Denys Vlasenko
Commit-ID:  7a5a9824c18f93415944c997dc6bb8eecfddd2e7
Gitweb: http://git.kernel.org/tip/7a5a9824c18f93415944c997dc6bb8eecfddd2e7
Author: Denys Vlasenko 
AuthorDate: Wed, 3 Jun 2015 15:58:50 +0200
Committer:  Ingo Molnar 
CommitDate: Fri, 5 Jun 2015 13:41:28 +0200

x86/asm/entry/32: Remove unnecessary optimization in stub32_clone

Really swap arguments #4 and #5 in stub32_clone instead of
"optimizing" it into a move.

Yes, tls_val is currently unused. Yes, on some CPUs XCHG is a
little bit more expensive than MOV. But a cycle or two on an
expensive syscall like clone() is way below noise floor, and
this optimization is simply not worth the obfuscation of logic.

[ There's also ongoing work on the clone() ABI by Josh Triplett
  that will depend on this change later on. ]

Signed-off-by: Denys Vlasenko 
Cc: Alexei Starovoitov 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Frederic Weisbecker 
Cc: H. Peter Anvin 
Cc: Josh Triplett 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Oleg Nesterov 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Cc: Thomas Gleixner 
Cc: Will Drewry 
Link: 
http://lkml.kernel.org/r/149930-20880-2-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/entry/ia32entry.S | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/arch/x86/entry/ia32entry.S b/arch/x86/entry/ia32entry.S
index d0c7b28..9558dac 100644
--- a/arch/x86/entry/ia32entry.S
+++ b/arch/x86/entry/ia32entry.S
@@ -529,14 +529,13 @@ GLOBAL(\label)
 GLOBAL(stub32_clone)
leaqsys_clone(%rip), %rax
/*
-* 32-bit clone API is clone(..., int tls_val, int *child_tidptr).
-* 64-bit clone API is clone(..., int *child_tidptr, int tls_val).
-* Native 64-bit kernel's sys_clone() implements the latter.
-* We need to swap args here. But since tls_val is in fact ignored
-* by sys_clone(), we can get away with an assignment
-* (arg4 = arg5) instead of a full swap:
+* The 32-bit clone ABI is: clone(..., int tls_val, int *child_tidptr).
+* The 64-bit clone ABI is: clone(..., int *child_tidptr, int tls_val).
+*
+* The native 64-bit kernel's sys_clone() implements the latter,
+* so we need to swap arguments here before calling it:
 */
-   mov %r8, %rcx
+   xchg%r8, %rcx
jmp ia32_ptregs_common
 
ALIGN
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/asm] x86/asm/entry/32: Simplify the zeroing of pt_regs-> r8..r11 in the int80 code path

2015-06-07 Thread tip-bot for Denys Vlasenko
Commit-ID:  61b1e3e782d6784b714c0d80de529e0737d0e79c
Gitweb: http://git.kernel.org/tip/61b1e3e782d6784b714c0d80de529e0737d0e79c
Author: Denys Vlasenko 
AuthorDate: Tue, 2 Jun 2015 19:35:10 +0200
Committer:  Ingo Molnar 
CommitDate: Fri, 5 Jun 2015 13:22:21 +0200

x86/asm/entry/32: Simplify the zeroing of pt_regs->r8..r11 in the int80 code 
path

32-bit syscall entry points do not save the complete pt_regs struct,
they leave some fields uninitialized. However, they must be
careful to not leak uninitialized data in pt_regs->r8..r11 to
ptrace users.

CLEAR_RREGS macro is used to zero these fields out when needed.

However, in the int80 code path this zeroing is unconditional.
This patch simplifies it by storing zeroes there right away,
when pt_regs is constructed on stack.

This uses shorter instructions:

   textdata bss dec hex filename
   1423   0   01423 58f ia32entry.o.before
   1407   0   01407 57f ia32entry.o

Compile-tested.

Signed-off-by: Denys Vlasenko 
Cc: Alexei Starovoitov 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Frederic Weisbecker 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Oleg Nesterov 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Cc: Thomas Gleixner 
Cc: Will Drewry 
Link: 
http://lkml.kernel.org/r/1433266510-2938-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/entry/ia32entry.S | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/arch/x86/entry/ia32entry.S b/arch/x86/entry/ia32entry.S
index f167674..f00a409 100644
--- a/arch/x86/entry/ia32entry.S
+++ b/arch/x86/entry/ia32entry.S
@@ -421,6 +421,10 @@ ia32_badarg:
movq $-EFAULT,%rax
jmp ia32_sysret
 
+ia32_ret_from_sys_call:
+   CLEAR_RREGS
+   jmp int_ret_from_sys_call
+
 /*
  * Emulated IA32 system calls via int 0x80.
  *
@@ -462,8 +466,12 @@ ENTRY(ia32_syscall)
pushq   %rdx/* pt_regs->dx */
pushq   %rcx/* pt_regs->cx */
pushq   $-ENOSYS/* pt_regs->ax */
+   pushq   $0  /* pt_regs->r8 */
+   pushq   $0  /* pt_regs->r9 */
+   pushq   $0  /* pt_regs->r10 */
+   pushq   $0  /* pt_regs->r11 */
cld
-   sub $(10*8),%rsp /* pt_regs->r8-11,bp,bx,r12-15 not saved */
+   sub $(6*8),%rsp /* pt_regs->bp,bx,r12-15 not saved */
 
orl $TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS)
testl $_TIF_WORK_SYSCALL_ENTRY, ASM_THREAD_INFO(TI_flags, %rsp, 
SIZEOF_PTREGS)
@@ -481,13 +489,10 @@ ia32_do_call:
 ia32_sysret:
movq %rax,RAX(%rsp)
 1:
-ia32_ret_from_sys_call:
-   CLEAR_RREGS
jmp int_ret_from_sys_call
 
 ia32_tracesys:
SAVE_EXTRA_REGS
-   CLEAR_RREGS
movq %rsp,%rdi/* _regs -> arg1 */
call syscall_trace_enter
LOAD_ARGS32 /* reload args from stack in case ptrace changed it */
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/asm] x86/asm/entry/32: Open-code LOAD_ARGS32

2015-06-07 Thread tip-bot for Denys Vlasenko
Commit-ID:  73cbf687914fd5f4ef88a42a55784fd28b7450cf
Gitweb: http://git.kernel.org/tip/73cbf687914fd5f4ef88a42a55784fd28b7450cf
Author: Denys Vlasenko 
AuthorDate: Tue, 2 Jun 2015 21:04:02 +0200
Committer:  Ingo Molnar 
CommitDate: Fri, 5 Jun 2015 13:22:22 +0200

x86/asm/entry/32: Open-code LOAD_ARGS32

This macro is small, has only three callsites, and one of them
is slightly different using a conditional parameter.

A few saved lines aren't worth the resulting obfuscation.

Generated machine code is identical.

Signed-off-by: Denys Vlasenko 
Cc: Alexei Starovoitov 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Frederic Weisbecker 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Oleg Nesterov 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Cc: Thomas Gleixner 
Cc: Will Drewry 
Link: 
http://lkml.kernel.org/r/1433271842-9139-2-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/entry/ia32entry.S | 54 +-
 1 file changed, 29 insertions(+), 25 deletions(-)

diff --git a/arch/x86/entry/ia32entry.S b/arch/x86/entry/ia32entry.S
index 8a45d2c..56f819e 100644
--- a/arch/x86/entry/ia32entry.S
+++ b/arch/x86/entry/ia32entry.S
@@ -29,28 +29,6 @@
 
.section .entry.text, "ax"
 
-   /*
-* Reload arg registers from stack in case ptrace changed them.
-* We don't reload %eax because syscall_trace_enter() returned
-* the %rax value we should see.  Instead, we just truncate that
-* value to 32 bits again as we did on entry from user mode.
-* If it's a new value set by user_regset during entry tracing,
-* this matches the normal truncation of the user-mode value.
-* If it's -1 to make us punt the syscall, then (u32)-1 is still
-* an appropriately invalid value.
-*/
-   .macro LOAD_ARGS32 _r9=0
-   .if \_r9
-   movl R9(%rsp),%r9d
-   .endif
-   movl RCX(%rsp),%ecx
-   movl RDX(%rsp),%edx
-   movl RSI(%rsp),%esi
-   movl RDI(%rsp),%edi
-   movl %eax,%eax  /* zero extension */
-   .endm
-   
-
 #ifdef CONFIG_PARAVIRT
 ENTRY(native_usergs_sysret32)
swapgs
@@ -269,7 +247,14 @@ sysenter_tracesys:
movq%rax, R8(%rsp)
movq%rsp,%rdi/* _regs -> arg1 */
callsyscall_trace_enter
-   LOAD_ARGS32  /* reload args from stack in case ptrace changed it */
+
+   /* Reload arg registers from stack. (see sysenter_tracesys) */
+   movlRCX(%rsp), %ecx
+   movlRDX(%rsp), %edx
+   movlRSI(%rsp), %esi
+   movlRDI(%rsp), %edi
+   movl%eax, %eax  /* zero extension */
+
RESTORE_EXTRA_REGS
jmp sysenter_do_call
 ENDPROC(ia32_sysenter_target)
@@ -413,7 +398,15 @@ cstar_tracesys:
movq%rax, R8(%rsp)
movq %rsp,%rdi/* _regs -> arg1 */
call syscall_trace_enter
-   LOAD_ARGS32 1   /* reload args from stack in case ptrace changed it */
+   movlR9(%rsp),%r9d
+
+   /* Reload arg registers from stack. (see sysenter_tracesys) */
+   movlRCX(%rsp), %ecx
+   movlRDX(%rsp), %edx
+   movlRSI(%rsp), %esi
+   movlRDI(%rsp), %edi
+   movl%eax, %eax  /* zero extension */
+
RESTORE_EXTRA_REGS
xchgl %ebp,%r9d
jmp cstar_do_call
@@ -502,7 +495,18 @@ ia32_tracesys:
SAVE_EXTRA_REGS
movq %rsp,%rdi/* _regs -> arg1 */
call syscall_trace_enter
-   LOAD_ARGS32 /* reload args from stack in case ptrace changed it */
+   /*
+* Reload arg registers from stack in case ptrace changed them.
+* Don't reload %eax because syscall_trace_enter() returned
+* the %rax value we should see.  But do truncate it to 32 bits.
+* If it's -1 to make us punt the syscall, then (u32)-1 is still
+* an appropriately invalid value.
+*/
+   movlRCX(%rsp), %ecx
+   movlRDX(%rsp), %edx
+   movlRSI(%rsp), %esi
+   movlRDI(%rsp), %edi
+   movl%eax, %eax  /* zero extension */
RESTORE_EXTRA_REGS
jmp ia32_do_call
 END(ia32_syscall)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/asm] x86/asm/entry/32: Open-code CLEAR_RREGS

2015-06-07 Thread tip-bot for Denys Vlasenko
Commit-ID:  ef0cd5dc25404594f832dad9133abae52e3b2fa3
Gitweb: http://git.kernel.org/tip/ef0cd5dc25404594f832dad9133abae52e3b2fa3
Author: Denys Vlasenko 
AuthorDate: Tue, 2 Jun 2015 21:04:01 +0200
Committer:  Ingo Molnar 
CommitDate: Fri, 5 Jun 2015 13:22:22 +0200

x86/asm/entry/32: Open-code CLEAR_RREGS

This macro is small, has only four callsites, and one of them is
slightly different using a conditional parameter.

A few saved lines aren't worth the resulting obfuscation.

Generated machine code is identical.

Signed-off-by: Denys Vlasenko 
[ Added comments. ]
Cc: Alexei Starovoitov 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Frederic Weisbecker 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Oleg Nesterov 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Cc: Thomas Gleixner 
Cc: Will Drewry 
Link: 
http://lkml.kernel.org/r/1433271842-9139-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/entry/ia32entry.S | 33 -
 1 file changed, 20 insertions(+), 13 deletions(-)

diff --git a/arch/x86/entry/ia32entry.S b/arch/x86/entry/ia32entry.S
index f00a409..8a45d2c 100644
--- a/arch/x86/entry/ia32entry.S
+++ b/arch/x86/entry/ia32entry.S
@@ -29,15 +29,6 @@
 
.section .entry.text, "ax"
 
-   /* clobbers %rax */
-   .macro  CLEAR_RREGS _r9=rax
-   xorl%eax,%eax
-   movq%rax,R11(%rsp)
-   movq%rax,R10(%rsp)
-   movq%\_r9,R9(%rsp)
-   movq%rax,R8(%rsp)
-   .endm
-
/*
 * Reload arg registers from stack in case ptrace changed them.
 * We don't reload %eax because syscall_trace_enter() returned
@@ -243,7 +234,11 @@ sysexit_from_sys_call:
TRACE_IRQS_OFF
testl %edi, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS)
jz \exit
-   CLEAR_RREGS
+   xorl%eax, %eax  /* do not leak kernel information */
+   movq%rax, R11(%rsp)
+   movq%rax, R10(%rsp)
+   movq%rax, R9(%rsp)
+   movq%rax, R8(%rsp)
jmp int_with_check
.endm
 
@@ -267,7 +262,11 @@ sysenter_tracesys:
jz  sysenter_auditsys
 #endif
SAVE_EXTRA_REGS
-   CLEAR_RREGS
+   xorl%eax, %eax  /* do not leak kernel information */
+   movq%rax, R11(%rsp)
+   movq%rax, R10(%rsp)
+   movq%rax, R9(%rsp)
+   movq%rax, R8(%rsp)
movq%rsp,%rdi/* _regs -> arg1 */
callsyscall_trace_enter
LOAD_ARGS32  /* reload args from stack in case ptrace changed it */
@@ -407,7 +406,11 @@ cstar_tracesys:
 #endif
xchgl %r9d,%ebp
SAVE_EXTRA_REGS
-   CLEAR_RREGS r9
+   xorl%eax, %eax  /* do not leak kernel information */
+   movq%rax, R11(%rsp)
+   movq%rax, R10(%rsp)
+   movq%r9,  R9(%rsp)
+   movq%rax, R8(%rsp)
movq %rsp,%rdi/* _regs -> arg1 */
call syscall_trace_enter
LOAD_ARGS32 1   /* reload args from stack in case ptrace changed it */
@@ -422,7 +425,11 @@ ia32_badarg:
jmp ia32_sysret
 
 ia32_ret_from_sys_call:
-   CLEAR_RREGS
+   xorl%eax, %eax  /* do not leak kernel information */
+   movq%rax, R11(%rsp)
+   movq%rax, R10(%rsp)
+   movq%rax, R9(%rsp)
+   movq%rax, R8(%rsp)
jmp int_ret_from_sys_call
 
 /*
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/asm] x86/asm/entry/32: Do not use R9 in SYSCALL32 entry point

2015-06-07 Thread tip-bot for Denys Vlasenko
Commit-ID:  53e9accf0f7682d717c7b578b6e01fd297ba6630
Gitweb: http://git.kernel.org/tip/53e9accf0f7682d717c7b578b6e01fd297ba6630
Author: Denys Vlasenko 
AuthorDate: Wed, 3 Jun 2015 14:56:09 +0200
Committer:  Ingo Molnar 
CommitDate: Fri, 5 Jun 2015 13:22:22 +0200

x86/asm/entry/32: Do not use R9 in SYSCALL32 entry point

SYSENTER and SYSCALL 32-bit entry points differ in handling of
arg2 and arg6.

SYSENTER:
 * ecx  arg2
 * ebp  user stack
 * 0(%ebp) arg6

SYSCALL:
 * ebp  arg2
 * esp  user stack
 * 0(%esp) arg6

Sysenter code loads 0(%ebp) to %ebp right away.
(This destroys %ebp. It means we do not preserve it on return.
It's not causing problems since userspace VDSO code does not
depend on it, and SYSENTER insn can't be sanely used outside of
VDSO).

Syscall code loads 0(%ebp) to %r9. This allows to eliminate one
MOV insn (r9 is a register where arg6 should be for 64-bit ABI),
but on audit/ptrace code paths this requires juggling of r9 and
ebp: (1) ptrace expects arg6 to be in pt_regs->bp;
(2) r9 is callee-clobbered register and needs to be
saved/restored around calls to C functions.

This patch changes syscall code to load 0(%ebp) to %ebp, making
it more similar to sysenter code. It's a bit smaller:

   textdata bss dec hex filename
   1407   0   01407 57f ia32entry.o.before
   1391   0   01391 56f ia32entry.o

To preserve ABI compat, we restore ebp on exit.

Run-tested.

Signed-off-by: Denys Vlasenko 
Cc: Alexei Starovoitov 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Frederic Weisbecker 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Oleg Nesterov 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Cc: Thomas Gleixner 
Cc: Will Drewry 
Link: 
http://lkml.kernel.org/r/146169-18964-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/entry/ia32entry.S | 19 ---
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/arch/x86/entry/ia32entry.S b/arch/x86/entry/ia32entry.S
index 56f819e..6321915 100644
--- a/arch/x86/entry/ia32entry.S
+++ b/arch/x86/entry/ia32entry.S
@@ -323,7 +323,7 @@ ENTRY(ia32_cstar_target)
 * 32bit zero extended
 */
ASM_STAC
-1: movl(%r8),%r9d
+1: movl(%r8),%ebp
_ASM_EXTABLE(1b,ia32_badarg)
ASM_CLAC
orl $TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS)
@@ -333,7 +333,7 @@ ENTRY(ia32_cstar_target)
 cstar_do_call:
/* 32bit syscall -> 64bit C ABI argument conversion */
movl%edi,%r8d   /* arg5 */
-   /* r9 already loaded */ /* arg6 */
+   movl%ebp,%r9d   /* arg6 */
xchg%ecx,%esi   /* rsi:arg2, rcx:arg4 */
movl%ebx,%edi   /* arg1 */
movl%edx,%edx   /* arg3 (zero extension) */
@@ -349,6 +349,7 @@ cstar_dispatch:
jnz sysretl_audit
 sysretl_from_sys_call:
andl $~TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS)
+   movlRCX(%rsp), %ebp
RESTORE_RSI_RDI_RDX
movl RIP(%rsp),%ecx
movl EFLAGS(%rsp),%r11d
@@ -375,9 +376,8 @@ sysretl_from_sys_call:
 
 #ifdef CONFIG_AUDITSYSCALL
 cstar_auditsys:
-   movl %r9d,R9(%rsp)  /* register to be clobbered by call */
auditsys_entry_common
-   movl R9(%rsp),%r9d  /* reload 6th syscall arg */
+   movl%ebp, %r9d  /* reload 6th syscall arg */
jmp cstar_dispatch
 
 sysretl_audit:
@@ -389,16 +389,14 @@ cstar_tracesys:
testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT), 
ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS)
jz cstar_auditsys
 #endif
-   xchgl %r9d,%ebp
SAVE_EXTRA_REGS
xorl%eax, %eax  /* do not leak kernel information */
movq%rax, R11(%rsp)
movq%rax, R10(%rsp)
-   movq%r9,  R9(%rsp)
+   movq%rax, R9(%rsp)
movq%rax, R8(%rsp)
-   movq %rsp,%rdi/* _regs -> arg1 */
-   call syscall_trace_enter
-   movlR9(%rsp),%r9d
+   movq%rsp, %rdi/* _regs -> arg1 */
+   callsyscall_trace_enter
 
/* Reload arg registers from stack. (see sysenter_tracesys) */
movlRCX(%rsp), %ecx
@@ -408,8 +406,7 @@ cstar_tracesys:
movl%eax, %eax  /* zero extension */
 
RESTORE_EXTRA_REGS
-   xchgl %ebp,%r9d
-   jmp cstar_do_call
+   jmp cstar_do_call
 END(ia32_cstar_target)

 ia32_badarg:
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/asm] x86/asm/entry/32: Do not use R9 in SYSCALL32 entry point

2015-06-07 Thread tip-bot for Denys Vlasenko
Commit-ID:  53e9accf0f7682d717c7b578b6e01fd297ba6630
Gitweb: http://git.kernel.org/tip/53e9accf0f7682d717c7b578b6e01fd297ba6630
Author: Denys Vlasenko dvlas...@redhat.com
AuthorDate: Wed, 3 Jun 2015 14:56:09 +0200
Committer:  Ingo Molnar mi...@kernel.org
CommitDate: Fri, 5 Jun 2015 13:22:22 +0200

x86/asm/entry/32: Do not use R9 in SYSCALL32 entry point

SYSENTER and SYSCALL 32-bit entry points differ in handling of
arg2 and arg6.

SYSENTER:
 * ecx  arg2
 * ebp  user stack
 * 0(%ebp) arg6

SYSCALL:
 * ebp  arg2
 * esp  user stack
 * 0(%esp) arg6

Sysenter code loads 0(%ebp) to %ebp right away.
(This destroys %ebp. It means we do not preserve it on return.
It's not causing problems since userspace VDSO code does not
depend on it, and SYSENTER insn can't be sanely used outside of
VDSO).

Syscall code loads 0(%ebp) to %r9. This allows to eliminate one
MOV insn (r9 is a register where arg6 should be for 64-bit ABI),
but on audit/ptrace code paths this requires juggling of r9 and
ebp: (1) ptrace expects arg6 to be in pt_regs-bp;
(2) r9 is callee-clobbered register and needs to be
saved/restored around calls to C functions.

This patch changes syscall code to load 0(%ebp) to %ebp, making
it more similar to sysenter code. It's a bit smaller:

   textdata bss dec hex filename
   1407   0   01407 57f ia32entry.o.before
   1391   0   01391 56f ia32entry.o

To preserve ABI compat, we restore ebp on exit.

Run-tested.

Signed-off-by: Denys Vlasenko dvlas...@redhat.com
Cc: Alexei Starovoitov a...@plumgrid.com
Cc: Andrew Morton a...@linux-foundation.org
Cc: Andy Lutomirski l...@amacapital.net
Cc: Borislav Petkov b...@alien8.de
Cc: Brian Gerst brge...@gmail.com
Cc: Frederic Weisbecker fweis...@gmail.com
Cc: H. Peter Anvin h...@zytor.com
Cc: Kees Cook keesc...@chromium.org
Cc: Linus Torvalds torva...@linux-foundation.org
Cc: Oleg Nesterov o...@redhat.com
Cc: Peter Zijlstra pet...@infradead.org
Cc: Steven Rostedt rost...@goodmis.org
Cc: Thomas Gleixner t...@linutronix.de
Cc: Will Drewry w...@chromium.org
Link: 
http://lkml.kernel.org/r/146169-18964-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar mi...@kernel.org
---
 arch/x86/entry/ia32entry.S | 19 ---
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/arch/x86/entry/ia32entry.S b/arch/x86/entry/ia32entry.S
index 56f819e..6321915 100644
--- a/arch/x86/entry/ia32entry.S
+++ b/arch/x86/entry/ia32entry.S
@@ -323,7 +323,7 @@ ENTRY(ia32_cstar_target)
 * 32bit zero extended
 */
ASM_STAC
-1: movl(%r8),%r9d
+1: movl(%r8),%ebp
_ASM_EXTABLE(1b,ia32_badarg)
ASM_CLAC
orl $TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS)
@@ -333,7 +333,7 @@ ENTRY(ia32_cstar_target)
 cstar_do_call:
/* 32bit syscall - 64bit C ABI argument conversion */
movl%edi,%r8d   /* arg5 */
-   /* r9 already loaded */ /* arg6 */
+   movl%ebp,%r9d   /* arg6 */
xchg%ecx,%esi   /* rsi:arg2, rcx:arg4 */
movl%ebx,%edi   /* arg1 */
movl%edx,%edx   /* arg3 (zero extension) */
@@ -349,6 +349,7 @@ cstar_dispatch:
jnz sysretl_audit
 sysretl_from_sys_call:
andl $~TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS)
+   movlRCX(%rsp), %ebp
RESTORE_RSI_RDI_RDX
movl RIP(%rsp),%ecx
movl EFLAGS(%rsp),%r11d
@@ -375,9 +376,8 @@ sysretl_from_sys_call:
 
 #ifdef CONFIG_AUDITSYSCALL
 cstar_auditsys:
-   movl %r9d,R9(%rsp)  /* register to be clobbered by call */
auditsys_entry_common
-   movl R9(%rsp),%r9d  /* reload 6th syscall arg */
+   movl%ebp, %r9d  /* reload 6th syscall arg */
jmp cstar_dispatch
 
 sysretl_audit:
@@ -389,16 +389,14 @@ cstar_tracesys:
testl $(_TIF_WORK_SYSCALL_ENTRY  ~_TIF_SYSCALL_AUDIT), 
ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS)
jz cstar_auditsys
 #endif
-   xchgl %r9d,%ebp
SAVE_EXTRA_REGS
xorl%eax, %eax  /* do not leak kernel information */
movq%rax, R11(%rsp)
movq%rax, R10(%rsp)
-   movq%r9,  R9(%rsp)
+   movq%rax, R9(%rsp)
movq%rax, R8(%rsp)
-   movq %rsp,%rdi/* pt_regs - arg1 */
-   call syscall_trace_enter
-   movlR9(%rsp),%r9d
+   movq%rsp, %rdi/* pt_regs - arg1 */
+   callsyscall_trace_enter
 
/* Reload arg registers from stack. (see sysenter_tracesys) */
movlRCX(%rsp), %ecx
@@ -408,8 +406,7 @@ cstar_tracesys:
movl%eax, %eax  /* zero extension */
 
RESTORE_EXTRA_REGS
-   xchgl %ebp,%r9d
-   jmp cstar_do_call
+   jmp cstar_do_call
 END(ia32_cstar_target)

 ia32_badarg:
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More 

[tip:x86/asm] x86/asm/entry/32: Simplify the zeroing of pt_regs- r8..r11 in the int80 code path

2015-06-07 Thread tip-bot for Denys Vlasenko
Commit-ID:  61b1e3e782d6784b714c0d80de529e0737d0e79c
Gitweb: http://git.kernel.org/tip/61b1e3e782d6784b714c0d80de529e0737d0e79c
Author: Denys Vlasenko dvlas...@redhat.com
AuthorDate: Tue, 2 Jun 2015 19:35:10 +0200
Committer:  Ingo Molnar mi...@kernel.org
CommitDate: Fri, 5 Jun 2015 13:22:21 +0200

x86/asm/entry/32: Simplify the zeroing of pt_regs-r8..r11 in the int80 code 
path

32-bit syscall entry points do not save the complete pt_regs struct,
they leave some fields uninitialized. However, they must be
careful to not leak uninitialized data in pt_regs-r8..r11 to
ptrace users.

CLEAR_RREGS macro is used to zero these fields out when needed.

However, in the int80 code path this zeroing is unconditional.
This patch simplifies it by storing zeroes there right away,
when pt_regs is constructed on stack.

This uses shorter instructions:

   textdata bss dec hex filename
   1423   0   01423 58f ia32entry.o.before
   1407   0   01407 57f ia32entry.o

Compile-tested.

Signed-off-by: Denys Vlasenko dvlas...@redhat.com
Cc: Alexei Starovoitov a...@plumgrid.com
Cc: Andrew Morton a...@linux-foundation.org
Cc: Andy Lutomirski l...@amacapital.net
Cc: Borislav Petkov b...@alien8.de
Cc: Brian Gerst brge...@gmail.com
Cc: Frederic Weisbecker fweis...@gmail.com
Cc: H. Peter Anvin h...@zytor.com
Cc: Kees Cook keesc...@chromium.org
Cc: Linus Torvalds torva...@linux-foundation.org
Cc: Oleg Nesterov o...@redhat.com
Cc: Peter Zijlstra pet...@infradead.org
Cc: Steven Rostedt rost...@goodmis.org
Cc: Thomas Gleixner t...@linutronix.de
Cc: Will Drewry w...@chromium.org
Link: 
http://lkml.kernel.org/r/1433266510-2938-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar mi...@kernel.org
---
 arch/x86/entry/ia32entry.S | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/arch/x86/entry/ia32entry.S b/arch/x86/entry/ia32entry.S
index f167674..f00a409 100644
--- a/arch/x86/entry/ia32entry.S
+++ b/arch/x86/entry/ia32entry.S
@@ -421,6 +421,10 @@ ia32_badarg:
movq $-EFAULT,%rax
jmp ia32_sysret
 
+ia32_ret_from_sys_call:
+   CLEAR_RREGS
+   jmp int_ret_from_sys_call
+
 /*
  * Emulated IA32 system calls via int 0x80.
  *
@@ -462,8 +466,12 @@ ENTRY(ia32_syscall)
pushq   %rdx/* pt_regs-dx */
pushq   %rcx/* pt_regs-cx */
pushq   $-ENOSYS/* pt_regs-ax */
+   pushq   $0  /* pt_regs-r8 */
+   pushq   $0  /* pt_regs-r9 */
+   pushq   $0  /* pt_regs-r10 */
+   pushq   $0  /* pt_regs-r11 */
cld
-   sub $(10*8),%rsp /* pt_regs-r8-11,bp,bx,r12-15 not saved */
+   sub $(6*8),%rsp /* pt_regs-bp,bx,r12-15 not saved */
 
orl $TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS)
testl $_TIF_WORK_SYSCALL_ENTRY, ASM_THREAD_INFO(TI_flags, %rsp, 
SIZEOF_PTREGS)
@@ -481,13 +489,10 @@ ia32_do_call:
 ia32_sysret:
movq %rax,RAX(%rsp)
 1:
-ia32_ret_from_sys_call:
-   CLEAR_RREGS
jmp int_ret_from_sys_call
 
 ia32_tracesys:
SAVE_EXTRA_REGS
-   CLEAR_RREGS
movq %rsp,%rdi/* pt_regs - arg1 */
call syscall_trace_enter
LOAD_ARGS32 /* reload args from stack in case ptrace changed it */
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/asm] x86/asm/entry/32: Open-code LOAD_ARGS32

2015-06-07 Thread tip-bot for Denys Vlasenko
Commit-ID:  73cbf687914fd5f4ef88a42a55784fd28b7450cf
Gitweb: http://git.kernel.org/tip/73cbf687914fd5f4ef88a42a55784fd28b7450cf
Author: Denys Vlasenko dvlas...@redhat.com
AuthorDate: Tue, 2 Jun 2015 21:04:02 +0200
Committer:  Ingo Molnar mi...@kernel.org
CommitDate: Fri, 5 Jun 2015 13:22:22 +0200

x86/asm/entry/32: Open-code LOAD_ARGS32

This macro is small, has only three callsites, and one of them
is slightly different using a conditional parameter.

A few saved lines aren't worth the resulting obfuscation.

Generated machine code is identical.

Signed-off-by: Denys Vlasenko dvlas...@redhat.com
Cc: Alexei Starovoitov a...@plumgrid.com
Cc: Andrew Morton a...@linux-foundation.org
Cc: Andy Lutomirski l...@amacapital.net
Cc: Borislav Petkov b...@alien8.de
Cc: Brian Gerst brge...@gmail.com
Cc: Frederic Weisbecker fweis...@gmail.com
Cc: H. Peter Anvin h...@zytor.com
Cc: Kees Cook keesc...@chromium.org
Cc: Linus Torvalds torva...@linux-foundation.org
Cc: Oleg Nesterov o...@redhat.com
Cc: Peter Zijlstra pet...@infradead.org
Cc: Steven Rostedt rost...@goodmis.org
Cc: Thomas Gleixner t...@linutronix.de
Cc: Will Drewry w...@chromium.org
Link: 
http://lkml.kernel.org/r/1433271842-9139-2-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar mi...@kernel.org
---
 arch/x86/entry/ia32entry.S | 54 +-
 1 file changed, 29 insertions(+), 25 deletions(-)

diff --git a/arch/x86/entry/ia32entry.S b/arch/x86/entry/ia32entry.S
index 8a45d2c..56f819e 100644
--- a/arch/x86/entry/ia32entry.S
+++ b/arch/x86/entry/ia32entry.S
@@ -29,28 +29,6 @@
 
.section .entry.text, ax
 
-   /*
-* Reload arg registers from stack in case ptrace changed them.
-* We don't reload %eax because syscall_trace_enter() returned
-* the %rax value we should see.  Instead, we just truncate that
-* value to 32 bits again as we did on entry from user mode.
-* If it's a new value set by user_regset during entry tracing,
-* this matches the normal truncation of the user-mode value.
-* If it's -1 to make us punt the syscall, then (u32)-1 is still
-* an appropriately invalid value.
-*/
-   .macro LOAD_ARGS32 _r9=0
-   .if \_r9
-   movl R9(%rsp),%r9d
-   .endif
-   movl RCX(%rsp),%ecx
-   movl RDX(%rsp),%edx
-   movl RSI(%rsp),%esi
-   movl RDI(%rsp),%edi
-   movl %eax,%eax  /* zero extension */
-   .endm
-   
-
 #ifdef CONFIG_PARAVIRT
 ENTRY(native_usergs_sysret32)
swapgs
@@ -269,7 +247,14 @@ sysenter_tracesys:
movq%rax, R8(%rsp)
movq%rsp,%rdi/* pt_regs - arg1 */
callsyscall_trace_enter
-   LOAD_ARGS32  /* reload args from stack in case ptrace changed it */
+
+   /* Reload arg registers from stack. (see sysenter_tracesys) */
+   movlRCX(%rsp), %ecx
+   movlRDX(%rsp), %edx
+   movlRSI(%rsp), %esi
+   movlRDI(%rsp), %edi
+   movl%eax, %eax  /* zero extension */
+
RESTORE_EXTRA_REGS
jmp sysenter_do_call
 ENDPROC(ia32_sysenter_target)
@@ -413,7 +398,15 @@ cstar_tracesys:
movq%rax, R8(%rsp)
movq %rsp,%rdi/* pt_regs - arg1 */
call syscall_trace_enter
-   LOAD_ARGS32 1   /* reload args from stack in case ptrace changed it */
+   movlR9(%rsp),%r9d
+
+   /* Reload arg registers from stack. (see sysenter_tracesys) */
+   movlRCX(%rsp), %ecx
+   movlRDX(%rsp), %edx
+   movlRSI(%rsp), %esi
+   movlRDI(%rsp), %edi
+   movl%eax, %eax  /* zero extension */
+
RESTORE_EXTRA_REGS
xchgl %ebp,%r9d
jmp cstar_do_call
@@ -502,7 +495,18 @@ ia32_tracesys:
SAVE_EXTRA_REGS
movq %rsp,%rdi/* pt_regs - arg1 */
call syscall_trace_enter
-   LOAD_ARGS32 /* reload args from stack in case ptrace changed it */
+   /*
+* Reload arg registers from stack in case ptrace changed them.
+* Don't reload %eax because syscall_trace_enter() returned
+* the %rax value we should see.  But do truncate it to 32 bits.
+* If it's -1 to make us punt the syscall, then (u32)-1 is still
+* an appropriately invalid value.
+*/
+   movlRCX(%rsp), %ecx
+   movlRDX(%rsp), %edx
+   movlRSI(%rsp), %esi
+   movlRDI(%rsp), %edi
+   movl%eax, %eax  /* zero extension */
RESTORE_EXTRA_REGS
jmp ia32_do_call
 END(ia32_syscall)
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/asm] x86/asm/entry/32: Open-code CLEAR_RREGS

2015-06-07 Thread tip-bot for Denys Vlasenko
Commit-ID:  ef0cd5dc25404594f832dad9133abae52e3b2fa3
Gitweb: http://git.kernel.org/tip/ef0cd5dc25404594f832dad9133abae52e3b2fa3
Author: Denys Vlasenko dvlas...@redhat.com
AuthorDate: Tue, 2 Jun 2015 21:04:01 +0200
Committer:  Ingo Molnar mi...@kernel.org
CommitDate: Fri, 5 Jun 2015 13:22:22 +0200

x86/asm/entry/32: Open-code CLEAR_RREGS

This macro is small, has only four callsites, and one of them is
slightly different using a conditional parameter.

A few saved lines aren't worth the resulting obfuscation.

Generated machine code is identical.

Signed-off-by: Denys Vlasenko dvlas...@redhat.com
[ Added comments. ]
Cc: Alexei Starovoitov a...@plumgrid.com
Cc: Andrew Morton a...@linux-foundation.org
Cc: Andy Lutomirski l...@amacapital.net
Cc: Borislav Petkov b...@alien8.de
Cc: Brian Gerst brge...@gmail.com
Cc: Frederic Weisbecker fweis...@gmail.com
Cc: H. Peter Anvin h...@zytor.com
Cc: Kees Cook keesc...@chromium.org
Cc: Linus Torvalds torva...@linux-foundation.org
Cc: Oleg Nesterov o...@redhat.com
Cc: Peter Zijlstra pet...@infradead.org
Cc: Steven Rostedt rost...@goodmis.org
Cc: Thomas Gleixner t...@linutronix.de
Cc: Will Drewry w...@chromium.org
Link: 
http://lkml.kernel.org/r/1433271842-9139-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar mi...@kernel.org
---
 arch/x86/entry/ia32entry.S | 33 -
 1 file changed, 20 insertions(+), 13 deletions(-)

diff --git a/arch/x86/entry/ia32entry.S b/arch/x86/entry/ia32entry.S
index f00a409..8a45d2c 100644
--- a/arch/x86/entry/ia32entry.S
+++ b/arch/x86/entry/ia32entry.S
@@ -29,15 +29,6 @@
 
.section .entry.text, ax
 
-   /* clobbers %rax */
-   .macro  CLEAR_RREGS _r9=rax
-   xorl%eax,%eax
-   movq%rax,R11(%rsp)
-   movq%rax,R10(%rsp)
-   movq%\_r9,R9(%rsp)
-   movq%rax,R8(%rsp)
-   .endm
-
/*
 * Reload arg registers from stack in case ptrace changed them.
 * We don't reload %eax because syscall_trace_enter() returned
@@ -243,7 +234,11 @@ sysexit_from_sys_call:
TRACE_IRQS_OFF
testl %edi, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS)
jz \exit
-   CLEAR_RREGS
+   xorl%eax, %eax  /* do not leak kernel information */
+   movq%rax, R11(%rsp)
+   movq%rax, R10(%rsp)
+   movq%rax, R9(%rsp)
+   movq%rax, R8(%rsp)
jmp int_with_check
.endm
 
@@ -267,7 +262,11 @@ sysenter_tracesys:
jz  sysenter_auditsys
 #endif
SAVE_EXTRA_REGS
-   CLEAR_RREGS
+   xorl%eax, %eax  /* do not leak kernel information */
+   movq%rax, R11(%rsp)
+   movq%rax, R10(%rsp)
+   movq%rax, R9(%rsp)
+   movq%rax, R8(%rsp)
movq%rsp,%rdi/* pt_regs - arg1 */
callsyscall_trace_enter
LOAD_ARGS32  /* reload args from stack in case ptrace changed it */
@@ -407,7 +406,11 @@ cstar_tracesys:
 #endif
xchgl %r9d,%ebp
SAVE_EXTRA_REGS
-   CLEAR_RREGS r9
+   xorl%eax, %eax  /* do not leak kernel information */
+   movq%rax, R11(%rsp)
+   movq%rax, R10(%rsp)
+   movq%r9,  R9(%rsp)
+   movq%rax, R8(%rsp)
movq %rsp,%rdi/* pt_regs - arg1 */
call syscall_trace_enter
LOAD_ARGS32 1   /* reload args from stack in case ptrace changed it */
@@ -422,7 +425,11 @@ ia32_badarg:
jmp ia32_sysret
 
 ia32_ret_from_sys_call:
-   CLEAR_RREGS
+   xorl%eax, %eax  /* do not leak kernel information */
+   movq%rax, R11(%rsp)
+   movq%rax, R10(%rsp)
+   movq%rax, R9(%rsp)
+   movq%rax, R8(%rsp)
jmp int_ret_from_sys_call
 
 /*
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/asm] x86/asm/entry/32: Explain the stub32_clone logic

2015-06-07 Thread tip-bot for Denys Vlasenko
Commit-ID:  5cdc683b7d8b3341a3d18e0c5498bc1e4f3fb990
Gitweb: http://git.kernel.org/tip/5cdc683b7d8b3341a3d18e0c5498bc1e4f3fb990
Author: Denys Vlasenko dvlas...@redhat.com
AuthorDate: Wed, 3 Jun 2015 15:58:49 +0200
Committer:  Ingo Molnar mi...@kernel.org
CommitDate: Fri, 5 Jun 2015 13:41:27 +0200

x86/asm/entry/32: Explain the stub32_clone logic

The reason for copying of %r8 to %rcx is quite non-obvious.
Add a comment which explains why it is done.

Signed-off-by: Denys Vlasenko dvlas...@redhat.com
Cc: Alexei Starovoitov a...@plumgrid.com
Cc: Andrew Morton a...@linux-foundation.org
Cc: Andy Lutomirski l...@amacapital.net
Cc: Borislav Petkov b...@alien8.de
Cc: Brian Gerst brge...@gmail.com
Cc: Frederic Weisbecker fweis...@gmail.com
Cc: H. Peter Anvin h...@zytor.com
Cc: Kees Cook keesc...@chromium.org
Cc: Linus Torvalds torva...@linux-foundation.org
Cc: Oleg Nesterov o...@redhat.com
Cc: Peter Zijlstra pet...@infradead.org
Cc: Steven Rostedt rost...@goodmis.org
Cc: Thomas Gleixner t...@linutronix.de
Cc: Will Drewry w...@chromium.org
Link: 
http://lkml.kernel.org/r/149930-20880-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar mi...@kernel.org
---
 arch/x86/entry/ia32entry.S | 8 
 1 file changed, 8 insertions(+)

diff --git a/arch/x86/entry/ia32entry.S b/arch/x86/entry/ia32entry.S
index 4bb9f7b..d0c7b28 100644
--- a/arch/x86/entry/ia32entry.S
+++ b/arch/x86/entry/ia32entry.S
@@ -528,6 +528,14 @@ GLOBAL(\label)
ALIGN
 GLOBAL(stub32_clone)
leaqsys_clone(%rip), %rax
+   /*
+* 32-bit clone API is clone(..., int tls_val, int *child_tidptr).
+* 64-bit clone API is clone(..., int *child_tidptr, int tls_val).
+* Native 64-bit kernel's sys_clone() implements the latter.
+* We need to swap args here. But since tls_val is in fact ignored
+* by sys_clone(), we can get away with an assignment
+* (arg4 = arg5) instead of a full swap:
+*/
mov %r8, %rcx
jmp ia32_ptregs_common
 
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/asm] x86/asm/entry/32: Remove unnecessary optimization in stub32_clone

2015-06-07 Thread tip-bot for Denys Vlasenko
Commit-ID:  7a5a9824c18f93415944c997dc6bb8eecfddd2e7
Gitweb: http://git.kernel.org/tip/7a5a9824c18f93415944c997dc6bb8eecfddd2e7
Author: Denys Vlasenko dvlas...@redhat.com
AuthorDate: Wed, 3 Jun 2015 15:58:50 +0200
Committer:  Ingo Molnar mi...@kernel.org
CommitDate: Fri, 5 Jun 2015 13:41:28 +0200

x86/asm/entry/32: Remove unnecessary optimization in stub32_clone

Really swap arguments #4 and #5 in stub32_clone instead of
optimizing it into a move.

Yes, tls_val is currently unused. Yes, on some CPUs XCHG is a
little bit more expensive than MOV. But a cycle or two on an
expensive syscall like clone() is way below noise floor, and
this optimization is simply not worth the obfuscation of logic.

[ There's also ongoing work on the clone() ABI by Josh Triplett
  that will depend on this change later on. ]

Signed-off-by: Denys Vlasenko dvlas...@redhat.com
Cc: Alexei Starovoitov a...@plumgrid.com
Cc: Andrew Morton a...@linux-foundation.org
Cc: Andy Lutomirski l...@amacapital.net
Cc: Borislav Petkov b...@alien8.de
Cc: Brian Gerst brge...@gmail.com
Cc: Frederic Weisbecker fweis...@gmail.com
Cc: H. Peter Anvin h...@zytor.com
Cc: Josh Triplett j...@joshtriplett.org
Cc: Kees Cook keesc...@chromium.org
Cc: Linus Torvalds torva...@linux-foundation.org
Cc: Oleg Nesterov o...@redhat.com
Cc: Peter Zijlstra pet...@infradead.org
Cc: Steven Rostedt rost...@goodmis.org
Cc: Thomas Gleixner t...@linutronix.de
Cc: Will Drewry w...@chromium.org
Link: 
http://lkml.kernel.org/r/149930-20880-2-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar mi...@kernel.org
---
 arch/x86/entry/ia32entry.S | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/arch/x86/entry/ia32entry.S b/arch/x86/entry/ia32entry.S
index d0c7b28..9558dac 100644
--- a/arch/x86/entry/ia32entry.S
+++ b/arch/x86/entry/ia32entry.S
@@ -529,14 +529,13 @@ GLOBAL(\label)
 GLOBAL(stub32_clone)
leaqsys_clone(%rip), %rax
/*
-* 32-bit clone API is clone(..., int tls_val, int *child_tidptr).
-* 64-bit clone API is clone(..., int *child_tidptr, int tls_val).
-* Native 64-bit kernel's sys_clone() implements the latter.
-* We need to swap args here. But since tls_val is in fact ignored
-* by sys_clone(), we can get away with an assignment
-* (arg4 = arg5) instead of a full swap:
+* The 32-bit clone ABI is: clone(..., int tls_val, int *child_tidptr).
+* The 64-bit clone ABI is: clone(..., int *child_tidptr, int tls_val).
+*
+* The native 64-bit kernel's sys_clone() implements the latter,
+* so we need to swap arguments here before calling it:
 */
-   mov %r8, %rcx
+   xchg%r8, %rcx
jmp ia32_ptregs_common
 
ALIGN
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/apic] x86/asm/entry/64: Use shorter MOVs from segment registers

2015-05-17 Thread tip-bot for Denys Vlasenko
Commit-ID:  adeb5537849d9db428fe0ddc3562e5a765a347e2
Gitweb: http://git.kernel.org/tip/adeb5537849d9db428fe0ddc3562e5a765a347e2
Author: Denys Vlasenko 
AuthorDate: Fri, 15 May 2015 22:39:06 +0200
Committer:  Ingo Molnar 
CommitDate: Sun, 17 May 2015 07:57:54 +0200

x86/asm/entry/64: Use shorter MOVs from segment registers

The "movw %ds,%cx" instruction needs a 0x66 prefix, while
"movl %ds,%ecx" does not.

The difference is that latter form (on 64-bit CPUs)
overwrites the entire %ecx, not only its lower half.

But subsequent code doesn't depend on the value of upper
half of %ecx, so we can safely use the shorter instruction.

The new code is also faster than the old one - now we don't
depend on the old value of %ecx, but this code fragment is
not performance-critical so it does not matter much.

Signed-off-by: Denys Vlasenko 
Cc: Alexei Starovoitov 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Frederic Weisbecker 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Oleg Nesterov 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Cc: Thomas Gleixner 
Cc: Will Drewry 
Link: 
http://lkml.kernel.org/r/1431722346-26585-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/kernel/entry_64.S | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index 09c3f9e..47b9581 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -1190,17 +1190,17 @@ ENTRY(xen_failsafe_callback)
/*CFI_REL_OFFSET ds,DS*/
CFI_REL_OFFSET r11,8
CFI_REL_OFFSET rcx,0
-   movw %ds,%cx
+   movl %ds,%ecx
cmpw %cx,0x10(%rsp)
CFI_REMEMBER_STATE
jne 1f
-   movw %es,%cx
+   movl %es,%ecx
cmpw %cx,0x18(%rsp)
jne 1f
-   movw %fs,%cx
+   movl %fs,%ecx
cmpw %cx,0x20(%rsp)
jne 1f
-   movw %gs,%cx
+   movl %gs,%ecx
cmpw %cx,0x28(%rsp)
jne 1f
/* All segments match their saved values => Category 2 (Bad IRET). */
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/apic] x86/asm/entry/64: Use shorter MOVs from segment registers

2015-05-17 Thread tip-bot for Denys Vlasenko
Commit-ID:  adeb5537849d9db428fe0ddc3562e5a765a347e2
Gitweb: http://git.kernel.org/tip/adeb5537849d9db428fe0ddc3562e5a765a347e2
Author: Denys Vlasenko dvlas...@redhat.com
AuthorDate: Fri, 15 May 2015 22:39:06 +0200
Committer:  Ingo Molnar mi...@kernel.org
CommitDate: Sun, 17 May 2015 07:57:54 +0200

x86/asm/entry/64: Use shorter MOVs from segment registers

The movw %ds,%cx instruction needs a 0x66 prefix, while
movl %ds,%ecx does not.

The difference is that latter form (on 64-bit CPUs)
overwrites the entire %ecx, not only its lower half.

But subsequent code doesn't depend on the value of upper
half of %ecx, so we can safely use the shorter instruction.

The new code is also faster than the old one - now we don't
depend on the old value of %ecx, but this code fragment is
not performance-critical so it does not matter much.

Signed-off-by: Denys Vlasenko dvlas...@redhat.com
Cc: Alexei Starovoitov a...@plumgrid.com
Cc: Andy Lutomirski l...@amacapital.net
Cc: Borislav Petkov b...@alien8.de
Cc: Brian Gerst brge...@gmail.com
Cc: Frederic Weisbecker fweis...@gmail.com
Cc: H. Peter Anvin h...@zytor.com
Cc: Kees Cook keesc...@chromium.org
Cc: Linus Torvalds torva...@linux-foundation.org
Cc: Oleg Nesterov o...@redhat.com
Cc: Peter Zijlstra pet...@infradead.org
Cc: Steven Rostedt rost...@goodmis.org
Cc: Thomas Gleixner t...@linutronix.de
Cc: Will Drewry w...@chromium.org
Link: 
http://lkml.kernel.org/r/1431722346-26585-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar mi...@kernel.org
---
 arch/x86/kernel/entry_64.S | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index 09c3f9e..47b9581 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -1190,17 +1190,17 @@ ENTRY(xen_failsafe_callback)
/*CFI_REL_OFFSET ds,DS*/
CFI_REL_OFFSET r11,8
CFI_REL_OFFSET rcx,0
-   movw %ds,%cx
+   movl %ds,%ecx
cmpw %cx,0x10(%rsp)
CFI_REMEMBER_STATE
jne 1f
-   movw %es,%cx
+   movl %es,%ecx
cmpw %cx,0x18(%rsp)
jne 1f
-   movw %fs,%cx
+   movl %fs,%ecx
cmpw %cx,0x20(%rsp)
jne 1f
-   movw %gs,%cx
+   movl %gs,%ecx
cmpw %cx,0x28(%rsp)
jne 1f
/* All segments match their saved values = Category 2 (Bad IRET). */
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/asm] x86/entry: Remove unused 'kernel_stack' per-cpu variable

2015-05-08 Thread tip-bot for Denys Vlasenko
Commit-ID:  fed7c3f0f750f225317828d691e9eb76eec887b3
Gitweb: http://git.kernel.org/tip/fed7c3f0f750f225317828d691e9eb76eec887b3
Author: Denys Vlasenko 
AuthorDate: Fri, 24 Apr 2015 17:31:34 +0200
Committer:  Ingo Molnar 
CommitDate: Fri, 8 May 2015 13:49:43 +0200

x86/entry: Remove unused 'kernel_stack' per-cpu variable

Signed-off-by: Denys Vlasenko 
Acked-by: Andy Lutomirski 
Cc: Alexei Starovoitov 
Cc: Andrew Morton 
Cc: Borislav Petkov 
Cc: Frederic Weisbecker 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Oleg Nesterov 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Cc: Thomas Gleixner 
Cc: Will Drewry 
Link: 
http://lkml.kernel.org/r/1429889495-27850-2-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/include/asm/thread_info.h | 2 --
 arch/x86/kernel/cpu/common.c   | 4 
 arch/x86/kernel/process_32.c   | 5 +
 arch/x86/kernel/process_64.c   | 3 ---
 arch/x86/kernel/smpboot.c  | 2 --
 5 files changed, 1 insertion(+), 15 deletions(-)

diff --git a/arch/x86/include/asm/thread_info.h 
b/arch/x86/include/asm/thread_info.h
index d656a36..4722889 100644
--- a/arch/x86/include/asm/thread_info.h
+++ b/arch/x86/include/asm/thread_info.h
@@ -177,8 +177,6 @@ struct thread_info {
  */
 #ifndef __ASSEMBLY__
 
-DECLARE_PER_CPU(unsigned long, kernel_stack);
-
 static inline struct thread_info *current_thread_info(void)
 {
return (struct thread_info *)(current_top_of_stack() - THREAD_SIZE);
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index a62cf04..6bec0b5 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -1155,10 +1155,6 @@ static __init int setup_disablecpuid(char *arg)
 }
 __setup("clearcpuid=", setup_disablecpuid);
 
-DEFINE_PER_CPU(unsigned long, kernel_stack) =
-   (unsigned long)_thread_union + THREAD_SIZE;
-EXPORT_PER_CPU_SYMBOL(kernel_stack);
-
 #ifdef CONFIG_X86_64
 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
 struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
index 8ed2106..a99900c 100644
--- a/arch/x86/kernel/process_32.c
+++ b/arch/x86/kernel/process_32.c
@@ -302,13 +302,10 @@ __switch_to(struct task_struct *prev_p, struct 
task_struct *next_p)
arch_end_context_switch(next_p);
 
/*
-* Reload esp0, kernel_stack, and current_top_of_stack.  This changes
+* Reload esp0 and cpu_current_top_of_stack.  This changes
 * current_thread_info().
 */
load_sp0(tss, next);
-   this_cpu_write(kernel_stack,
-  (unsigned long)task_stack_page(next_p) +
-  THREAD_SIZE);
this_cpu_write(cpu_current_top_of_stack,
   (unsigned long)task_stack_page(next_p) +
   THREAD_SIZE);
diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
index ddfdbf7..8213450 100644
--- a/arch/x86/kernel/process_64.c
+++ b/arch/x86/kernel/process_64.c
@@ -409,9 +409,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct 
*next_p)
/* Reload esp0 and ss1.  This changes current_thread_info(). */
load_sp0(tss, next);
 
-   this_cpu_write(kernel_stack,
-   (unsigned long)task_stack_page(next_p) + THREAD_SIZE);
-
/*
 * Now maybe reload the debug registers and handle I/O bitmaps
 */
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index 50e547e..023cccf 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -792,8 +792,6 @@ void common_cpu_up(unsigned int cpu, struct task_struct 
*idle)
clear_tsk_thread_flag(idle, TIF_FORK);
initial_gs = per_cpu_offset(cpu);
 #endif
-   per_cpu(kernel_stack, cpu) =
-   (unsigned long)task_stack_page(idle) + THREAD_SIZE;
 }
 
 /*
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/asm] x86/entry: Define 'cpu_current_top_of_stack' for 64-bit code

2015-05-08 Thread tip-bot for Denys Vlasenko
Commit-ID:  3a23208e69679597e767cf3547b1a30dd845d9b5
Gitweb: http://git.kernel.org/tip/3a23208e69679597e767cf3547b1a30dd845d9b5
Author: Denys Vlasenko 
AuthorDate: Fri, 24 Apr 2015 17:31:35 +0200
Committer:  Ingo Molnar 
CommitDate: Fri, 8 May 2015 13:50:02 +0200

x86/entry: Define 'cpu_current_top_of_stack' for 64-bit code

32-bit code has PER_CPU_VAR(cpu_current_top_of_stack).
64-bit code uses somewhat more obscure: PER_CPU_VAR(cpu_tss + TSS_sp0).

Define the 'cpu_current_top_of_stack' macro on CONFIG_X86_64
as well so that the PER_CPU_VAR(cpu_current_top_of_stack)
expression can be used in both 32-bit and 64-bit code.

Signed-off-by: Denys Vlasenko 
Cc: Alexei Starovoitov 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Frederic Weisbecker 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Oleg Nesterov 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Cc: Thomas Gleixner 
Cc: Will Drewry 
Link: 
http://lkml.kernel.org/r/1429889495-27850-3-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/ia32/ia32entry.S  |  4 ++--
 arch/x86/include/asm/thread_info.h | 10 --
 arch/x86/kernel/entry_64.S |  2 +-
 arch/x86/xen/xen-asm_64.S  |  5 +++--
 4 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
index 1b1330c..63450a5 100644
--- a/arch/x86/ia32/ia32entry.S
+++ b/arch/x86/ia32/ia32entry.S
@@ -113,7 +113,7 @@ ENTRY(ia32_sysenter_target)
 * it is too small to ever cause noticeable irq latency.
 */
SWAPGS_UNSAFE_STACK
-   movqPER_CPU_VAR(cpu_tss + TSS_sp0), %rsp
+   movqPER_CPU_VAR(cpu_current_top_of_stack), %rsp
ENABLE_INTERRUPTS(CLBR_NONE)
 
/* Zero-extending 32-bit regs, do not remove */
@@ -346,7 +346,7 @@ ENTRY(ia32_cstar_target)
SWAPGS_UNSAFE_STACK
movl%esp,%r8d
CFI_REGISTERrsp,r8
-   movqPER_CPU_VAR(cpu_tss + TSS_sp0),%rsp
+   movqPER_CPU_VAR(cpu_current_top_of_stack),%rsp
ENABLE_INTERRUPTS(CLBR_NONE)
 
/* Zero-extending 32-bit regs, do not remove */
diff --git a/arch/x86/include/asm/thread_info.h 
b/arch/x86/include/asm/thread_info.h
index 4722889..225ee54 100644
--- a/arch/x86/include/asm/thread_info.h
+++ b/arch/x86/include/asm/thread_info.h
@@ -195,16 +195,14 @@ static inline unsigned long current_stack_pointer(void)
 
 #else /* !__ASSEMBLY__ */
 
+#ifdef CONFIG_X86_64
+# define cpu_current_top_of_stack (cpu_tss + TSS_sp0)
+#endif
+
 /* Load thread_info address into "reg" */
-#ifdef CONFIG_X86_32
 #define GET_THREAD_INFO(reg) \
_ASM_MOV PER_CPU_VAR(cpu_current_top_of_stack),reg ; \
_ASM_SUB $(THREAD_SIZE),reg ;
-#else
-#define GET_THREAD_INFO(reg) \
-   _ASM_MOV PER_CPU_VAR(cpu_tss + TSS_sp0),reg ; \
-   _ASM_SUB $(THREAD_SIZE),reg ;
-#endif
 
 /*
  * ASM operand which evaluates to a 'thread_info' address of
diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index c13b86b..09c3f9e 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -216,7 +216,7 @@ ENTRY(system_call)
 GLOBAL(system_call_after_swapgs)
 
movq%rsp,PER_CPU_VAR(rsp_scratch)
-   movqPER_CPU_VAR(cpu_tss + TSS_sp0),%rsp
+   movqPER_CPU_VAR(cpu_current_top_of_stack),%rsp
 
/* Construct struct pt_regs on stack */
pushq_cfi $__USER_DS/* pt_regs->ss */
diff --git a/arch/x86/xen/xen-asm_64.S b/arch/x86/xen/xen-asm_64.S
index 5aa7ec6..04529e6 100644
--- a/arch/x86/xen/xen-asm_64.S
+++ b/arch/x86/xen/xen-asm_64.S
@@ -16,6 +16,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -54,7 +55,7 @@ ENTRY(xen_sysret64)
 * still with the kernel gs, so we can easily switch back
 */
movq %rsp, PER_CPU_VAR(rsp_scratch)
-   movq PER_CPU_VAR(cpu_tss + TSS_sp0), %rsp
+   movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp
 
pushq $__USER_DS
pushq PER_CPU_VAR(rsp_scratch)
@@ -73,7 +74,7 @@ ENTRY(xen_sysret32)
 * still with the kernel gs, so we can easily switch back
 */
movq %rsp, PER_CPU_VAR(rsp_scratch)
-   movq PER_CPU_VAR(cpu_tss + TSS_sp0), %rsp
+   movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp
 
pushq $__USER32_DS
pushq PER_CPU_VAR(rsp_scratch)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/asm] x86: Force inlining of atomic ops

2015-05-08 Thread tip-bot for Denys Vlasenko
Commit-ID:  2a4e90b18c256d52a7f3f77d58114f6d4e4a7f9f
Gitweb: http://git.kernel.org/tip/2a4e90b18c256d52a7f3f77d58114f6d4e4a7f9f
Author: Denys Vlasenko 
AuthorDate: Fri, 8 May 2015 12:26:02 +0200
Committer:  Ingo Molnar 
CommitDate: Fri, 8 May 2015 12:55:50 +0200

x86: Force inlining of atomic ops

With both gcc 4.7.2 and 4.9.2, sometimes gcc mysteriously
doesn't inline very small functions we expect to be inlined:

$ nm --size-sort vmlinux | grep -iF ' t ' | uniq -c | grep -v '^
*1 ' | sort -rn 473 000b t spin_unlock_irqrestore
449 005f t rcu_read_unlock
355 0009 t atomic_inc<== THIS
353 006e t rcu_read_lock
350 0075 t rcu_read_lock_sched_held
291 000b t spin_unlock
266 0019 t arch_local_irq_restore
215 000b t spin_lock
180 0011 t kzalloc
165 0012 t list_add_tail
161 0019 t arch_local_save_flags
153 0016 t test_and_set_bit
134 000b t spin_unlock_irq
134 0009 t atomic_dec<== THIS
130 000b t spin_unlock_bh
122 0010 t brelse
120 0016 t test_and_clear_bit
120 000b t spin_lock_irq
119 001e t get_dma_ops
117 0053 t cpumask_next
116 0036 t kref_get
114 001a t schedule_work
106 000b t spin_lock_bh
103 0019 t arch_local_irq_disable
...

Note sizes of marked functions. They are merely 9 bytes long!
Selecting function with 'atomic' in their names:

355 0009 t atomic_inc
134 0009 t atomic_dec
 98 0014 t atomic_dec_and_test
 31 000e t atomic_add_return
 27 000a t atomic64_inc
 26 002f t kmap_atomic
 24 0009 t atomic_add
 12 0009 t atomic_sub
 10 0021 t __atomic_add_unless
 10 000a t atomic64_add
  5 001f t __atomic_add_unless.constprop.7
  5 000a t atomic64_dec
  4 001f t __atomic_add_unless.constprop.18
  4 001f t __atomic_add_unless.constprop.12
  4 001f t __atomic_add_unless.constprop.10
  3 001f t __atomic_add_unless.constprop.13
  3 0011 t atomic64_add_return
  2 001f t __atomic_add_unless.constprop.9
  2 001f t __atomic_add_unless.constprop.8
  2 001f t __atomic_add_unless.constprop.6
  2 001f t __atomic_add_unless.constprop.5
  2 001f t __atomic_add_unless.constprop.3
  2 001f t __atomic_add_unless.constprop.22
  2 001f t __atomic_add_unless.constprop.14
  2 001f t __atomic_add_unless.constprop.11
  2 001e t atomic_dec_if_positive
  2 0014 t atomic_inc_and_test
  2 0011 t atomic_add_return.constprop.4
  2 0011 t atomic_add_return.constprop.17
  2 0011 t atomic_add_return.constprop.16
  2 000d t atomic_inc.constprop.4
  2 000c t atomic_cmpxchg

This patch fixes this for x86 atomic ops via
s/inline/__always_inline/. This decreases allyesconfig kernel by
about 25k:

text data  bss   dec hex filename
82399481 22255416 20627456 125282353 777a831 vmlinux.before
82375570 22255544 20627456 125258570 7774b4a vmlinux

Signed-off-by: Denys Vlasenko 
Cc: Alexei Starovoitov 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Frederic Weisbecker 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Cc: Thomas Gleixner 
Cc: Will Drewry 
Link: 
http://lkml.kernel.org/r/1431080762-17797-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/include/asm/atomic.h | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
index 75a9ee8..e916895 100644
--- a/arch/x86/include/asm/atomic.h
+++ b/arch/x86/include/asm/atomic.h
@@ -22,7 +22,7 @@
  *
  * Atomically reads the value of @v.
  */
-static inline int atomic_read(const atomic_t *v)
+static __always_inline int atomic_read(const atomic_t *v)
 {
return ACCESS_ONCE((v)->counter);
 }
@@ -34,7 +34,7 @@ static inline int atomic_read(const atomic_t *v)
  *
  * Atomically sets the value of @v to @i.
  */
-static inline void atomic_set(atomic_t *v, int i)
+static __always_inline void atomic_set(atomic_t *v, int i)
 {
v->counter = i;
 }
@@ -126,7 +126,7 @@ static __always_inline int atomic_dec_and_test(atomic_t *v)
  * and returns true if the result is zero, or false for all
  * other cases.
  */
-static inline int atomic_inc_and_test(atomic_t *v)
+static __always_inline 

[tip:x86/asm] x86/entry: Stop using PER_CPU_VAR(kernel_stack)

2015-05-08 Thread tip-bot for Denys Vlasenko
Commit-ID:  63332a8455d8310b77d38779c6c21a660a8d9feb
Gitweb: http://git.kernel.org/tip/63332a8455d8310b77d38779c6c21a660a8d9feb
Author: Denys Vlasenko 
AuthorDate: Fri, 24 Apr 2015 17:31:33 +0200
Committer:  Ingo Molnar 
CommitDate: Fri, 8 May 2015 13:43:52 +0200

x86/entry: Stop using PER_CPU_VAR(kernel_stack)

PER_CPU_VAR(kernel_stack) is redundant:

  - On the 64-bit build, we can use PER_CPU_VAR(cpu_tss + TSS_sp0).
  - On the 32-bit build, we can use PER_CPU_VAR(cpu_current_top_of_stack).

PER_CPU_VAR(kernel_stack) will be deleted by a separate change.

Signed-off-by: Denys Vlasenko 
Cc: Alexei Starovoitov 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Frederic Weisbecker 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Oleg Nesterov 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Cc: Thomas Gleixner 
Cc: Will Drewry 
Link: 
http://lkml.kernel.org/r/1429889495-27850-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/ia32/ia32entry.S  | 2 +-
 arch/x86/include/asm/thread_info.h | 8 +++-
 arch/x86/kernel/entry_64.S | 2 +-
 arch/x86/xen/xen-asm_64.S  | 5 +++--
 4 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
index 2ab0f71..1b1330c 100644
--- a/arch/x86/ia32/ia32entry.S
+++ b/arch/x86/ia32/ia32entry.S
@@ -346,7 +346,7 @@ ENTRY(ia32_cstar_target)
SWAPGS_UNSAFE_STACK
movl%esp,%r8d
CFI_REGISTERrsp,r8
-   movqPER_CPU_VAR(kernel_stack),%rsp
+   movqPER_CPU_VAR(cpu_tss + TSS_sp0),%rsp
ENABLE_INTERRUPTS(CLBR_NONE)
 
/* Zero-extending 32-bit regs, do not remove */
diff --git a/arch/x86/include/asm/thread_info.h 
b/arch/x86/include/asm/thread_info.h
index b4bdec3..d656a36 100644
--- a/arch/x86/include/asm/thread_info.h
+++ b/arch/x86/include/asm/thread_info.h
@@ -198,9 +198,15 @@ static inline unsigned long current_stack_pointer(void)
 #else /* !__ASSEMBLY__ */
 
 /* Load thread_info address into "reg" */
+#ifdef CONFIG_X86_32
 #define GET_THREAD_INFO(reg) \
-   _ASM_MOV PER_CPU_VAR(kernel_stack),reg ; \
+   _ASM_MOV PER_CPU_VAR(cpu_current_top_of_stack),reg ; \
_ASM_SUB $(THREAD_SIZE),reg ;
+#else
+#define GET_THREAD_INFO(reg) \
+   _ASM_MOV PER_CPU_VAR(cpu_tss + TSS_sp0),reg ; \
+   _ASM_SUB $(THREAD_SIZE),reg ;
+#endif
 
 /*
  * ASM operand which evaluates to a 'thread_info' address of
diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index 7423e3e..c13b86b 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -216,7 +216,7 @@ ENTRY(system_call)
 GLOBAL(system_call_after_swapgs)
 
movq%rsp,PER_CPU_VAR(rsp_scratch)
-   movqPER_CPU_VAR(kernel_stack),%rsp
+   movqPER_CPU_VAR(cpu_tss + TSS_sp0),%rsp
 
/* Construct struct pt_regs on stack */
pushq_cfi $__USER_DS/* pt_regs->ss */
diff --git a/arch/x86/xen/xen-asm_64.S b/arch/x86/xen/xen-asm_64.S
index a2cabb8..5aa7ec6 100644
--- a/arch/x86/xen/xen-asm_64.S
+++ b/arch/x86/xen/xen-asm_64.S
@@ -15,6 +15,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -53,7 +54,7 @@ ENTRY(xen_sysret64)
 * still with the kernel gs, so we can easily switch back
 */
movq %rsp, PER_CPU_VAR(rsp_scratch)
-   movq PER_CPU_VAR(kernel_stack), %rsp
+   movq PER_CPU_VAR(cpu_tss + TSS_sp0), %rsp
 
pushq $__USER_DS
pushq PER_CPU_VAR(rsp_scratch)
@@ -72,7 +73,7 @@ ENTRY(xen_sysret32)
 * still with the kernel gs, so we can easily switch back
 */
movq %rsp, PER_CPU_VAR(rsp_scratch)
-   movq PER_CPU_VAR(kernel_stack), %rsp
+   movq PER_CPU_VAR(cpu_tss + TSS_sp0), %rsp
 
pushq $__USER32_DS
pushq PER_CPU_VAR(rsp_scratch)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/asm] x86/asm/entry/64: Tidy up JZ insns after TESTs

2015-05-08 Thread tip-bot for Denys Vlasenko
Commit-ID:  dde74f2e4a4447ef838c57e407f7139de3df68cb
Gitweb: http://git.kernel.org/tip/dde74f2e4a4447ef838c57e407f7139de3df68cb
Author: Denys Vlasenko 
AuthorDate: Mon, 27 Apr 2015 15:21:51 +0200
Committer:  Ingo Molnar 
CommitDate: Fri, 8 May 2015 11:07:31 +0200

x86/asm/entry/64: Tidy up JZ insns after TESTs

After TESTs, use logically correct JZ/JNZ mnemonics instead of
JE/JNE. This doesn't change code.

Signed-off-by: Denys Vlasenko 
Acked-by: Andy Lutomirski 
Cc: Alexei Starovoitov 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Frederic Weisbecker 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Oleg Nesterov 
Cc: Steven Rostedt 
Cc: Thomas Gleixner 
Cc: Will Drewry 
Link: 
http://lkml.kernel.org/r/1430140912-7960-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/kernel/entry_64.S | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index e952f6b..8f8b22a 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -666,7 +666,7 @@ END(irq_entries_start)
leaq -RBP(%rsp),%rdi/* arg1 for \func (pointer to pt_regs) */
 
testl $3, CS-RBP(%rsp)
-   je 1f
+   jz  1f
SWAPGS
 1:
/*
@@ -721,7 +721,7 @@ ret_from_intr:
CFI_ADJUST_CFA_OFFSET   RBP
 
testl $3,CS(%rsp)
-   je retint_kernel
+   jz  retint_kernel
/* Interrupt came from user space */
 
GET_THREAD_INFO(%rcx)
@@ -1310,7 +1310,7 @@ ENTRY(error_entry)
SAVE_EXTRA_REGS 8
xorl %ebx,%ebx
testl $3,CS+8(%rsp)
-   je error_kernelspace
+   jz  error_kernelspace
 error_swapgs:
SWAPGS
 error_sti:
@@ -1361,7 +1361,7 @@ ENTRY(error_exit)
TRACE_IRQS_OFF
GET_THREAD_INFO(%rcx)
testl %eax,%eax
-   jne retint_kernel
+   jnz retint_kernel
LOCKDEP_SYS_EXIT_IRQ
movl TI_flags(%rcx),%edx
movl $_TIF_WORK_MASK,%edi
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/asm] x86/asm/entry/64: Clean up usage of TEST insns

2015-05-08 Thread tip-bot for Denys Vlasenko
Commit-ID:  03335e95e27fc1f2b17b05b27342ad76986b3cf0
Gitweb: http://git.kernel.org/tip/03335e95e27fc1f2b17b05b27342ad76986b3cf0
Author: Denys Vlasenko 
AuthorDate: Mon, 27 Apr 2015 15:21:52 +0200
Committer:  Ingo Molnar 
CommitDate: Fri, 8 May 2015 11:07:32 +0200

x86/asm/entry/64: Clean up usage of TEST insns

By the nature of TEST operation, it is often possible
to test a narrower part of the operand:

"testl $3, mem"  -> "testb $3, mem"

This results in shorter insns, because TEST insn has no
sign-entending byte-immediate forms unlike other ALU ops.

   textdata bss dec hex filename
  11674   0   0   116742d9a entry_64.o.before
  11658   0   0   116582d8a entry_64.o

Changes in object code:

-   f7 84 24 88 00 00 00 03 00 00 00testl  $0x3,0x88(%rsp)
+   f6 84 24 88 00 00 00 03 testb  $0x3,0x88(%rsp)
-   f7 44 24 68 03 00 00 00 testl  $0x3,0x68(%rsp)
+   f6 44 24 68 03  testb  $0x3,0x68(%rsp)
-   f7 84 24 90 00 00 00 03 00 00 00testl  $0x3,0x90(%rsp)
+   f6 84 24 90 00 00 00 03 testb  $0x3,0x90(%rsp)

Signed-off-by: Denys Vlasenko 
Acked-by: Andy Lutomirski 
Cc: Alexei Starovoitov 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Frederic Weisbecker 
Cc: H. Peter Anvin 
Cc: Kees Cook 
Cc: Linus Torvalds 
Cc: Oleg Nesterov 
Cc: Steven Rostedt 
Cc: Thomas Gleixner 
Cc: Will Drewry 
Link: 
http://lkml.kernel.org/r/1430140912-7960-2-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/kernel/entry_64.S | 11 +--
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index 8f8b22a..60705b03 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -601,7 +601,7 @@ ENTRY(ret_from_fork)
 
RESTORE_EXTRA_REGS
 
-   testl $3,CS(%rsp)   # from kernel_thread?
+   testb   $3, CS(%rsp)# from kernel_thread?
 
/*
 * By the time we get here, we have no idea whether our pt_regs,
@@ -665,7 +665,7 @@ END(irq_entries_start)
 
leaq -RBP(%rsp),%rdi/* arg1 for \func (pointer to pt_regs) */
 
-   testl $3, CS-RBP(%rsp)
+   testb   $3, CS-RBP(%rsp)
jz  1f
SWAPGS
 1:
@@ -720,7 +720,7 @@ ret_from_intr:
CFI_DEF_CFA_REGISTERrsp
CFI_ADJUST_CFA_OFFSET   RBP
 
-   testl $3,CS(%rsp)
+   testb   $3, CS(%rsp)
jz  retint_kernel
/* Interrupt came from user space */
 
@@ -968,7 +968,7 @@ ENTRY(\sym)
.if \paranoid
.if \paranoid == 1
CFI_REMEMBER_STATE
-   testl $3, CS(%rsp)  /* If coming from userspace, switch */
+   testb   $3, CS(%rsp)/* If coming from userspace, switch */
jnz 1f  /* stacks. */
.endif
call paranoid_entry
@@ -1309,7 +1309,7 @@ ENTRY(error_entry)
SAVE_C_REGS 8
SAVE_EXTRA_REGS 8
xorl %ebx,%ebx
-   testl $3,CS+8(%rsp)
+   testb   $3, CS+8(%rsp)
jz  error_kernelspace
 error_swapgs:
SWAPGS
@@ -1606,7 +1606,6 @@ end_repeat_nmi:
je 1f
movq %r12, %cr2
 1:
-   
testl %ebx,%ebx /* swapgs needed? */
jnz nmi_restore
 nmi_swapgs:
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/asm] x86/asm/entry/64: Tidy up JZ insns after TESTs

2015-05-08 Thread tip-bot for Denys Vlasenko
Commit-ID:  dde74f2e4a4447ef838c57e407f7139de3df68cb
Gitweb: http://git.kernel.org/tip/dde74f2e4a4447ef838c57e407f7139de3df68cb
Author: Denys Vlasenko dvlas...@redhat.com
AuthorDate: Mon, 27 Apr 2015 15:21:51 +0200
Committer:  Ingo Molnar mi...@kernel.org
CommitDate: Fri, 8 May 2015 11:07:31 +0200

x86/asm/entry/64: Tidy up JZ insns after TESTs

After TESTs, use logically correct JZ/JNZ mnemonics instead of
JE/JNE. This doesn't change code.

Signed-off-by: Denys Vlasenko dvlas...@redhat.com
Acked-by: Andy Lutomirski l...@kernel.org
Cc: Alexei Starovoitov a...@plumgrid.com
Cc: Borislav Petkov b...@alien8.de
Cc: Brian Gerst brge...@gmail.com
Cc: Frederic Weisbecker fweis...@gmail.com
Cc: H. Peter Anvin h...@zytor.com
Cc: Kees Cook keesc...@chromium.org
Cc: Linus Torvalds torva...@linux-foundation.org
Cc: Oleg Nesterov o...@redhat.com
Cc: Steven Rostedt rost...@goodmis.org
Cc: Thomas Gleixner t...@linutronix.de
Cc: Will Drewry w...@chromium.org
Link: 
http://lkml.kernel.org/r/1430140912-7960-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar mi...@kernel.org
---
 arch/x86/kernel/entry_64.S | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index e952f6b..8f8b22a 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -666,7 +666,7 @@ END(irq_entries_start)
leaq -RBP(%rsp),%rdi/* arg1 for \func (pointer to pt_regs) */
 
testl $3, CS-RBP(%rsp)
-   je 1f
+   jz  1f
SWAPGS
 1:
/*
@@ -721,7 +721,7 @@ ret_from_intr:
CFI_ADJUST_CFA_OFFSET   RBP
 
testl $3,CS(%rsp)
-   je retint_kernel
+   jz  retint_kernel
/* Interrupt came from user space */
 
GET_THREAD_INFO(%rcx)
@@ -1310,7 +1310,7 @@ ENTRY(error_entry)
SAVE_EXTRA_REGS 8
xorl %ebx,%ebx
testl $3,CS+8(%rsp)
-   je error_kernelspace
+   jz  error_kernelspace
 error_swapgs:
SWAPGS
 error_sti:
@@ -1361,7 +1361,7 @@ ENTRY(error_exit)
TRACE_IRQS_OFF
GET_THREAD_INFO(%rcx)
testl %eax,%eax
-   jne retint_kernel
+   jnz retint_kernel
LOCKDEP_SYS_EXIT_IRQ
movl TI_flags(%rcx),%edx
movl $_TIF_WORK_MASK,%edi
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/asm] x86/asm/entry/64: Clean up usage of TEST insns

2015-05-08 Thread tip-bot for Denys Vlasenko
Commit-ID:  03335e95e27fc1f2b17b05b27342ad76986b3cf0
Gitweb: http://git.kernel.org/tip/03335e95e27fc1f2b17b05b27342ad76986b3cf0
Author: Denys Vlasenko dvlas...@redhat.com
AuthorDate: Mon, 27 Apr 2015 15:21:52 +0200
Committer:  Ingo Molnar mi...@kernel.org
CommitDate: Fri, 8 May 2015 11:07:32 +0200

x86/asm/entry/64: Clean up usage of TEST insns

By the nature of TEST operation, it is often possible
to test a narrower part of the operand:

testl $3, mem  - testb $3, mem

This results in shorter insns, because TEST insn has no
sign-entending byte-immediate forms unlike other ALU ops.

   textdata bss dec hex filename
  11674   0   0   116742d9a entry_64.o.before
  11658   0   0   116582d8a entry_64.o

Changes in object code:

-   f7 84 24 88 00 00 00 03 00 00 00testl  $0x3,0x88(%rsp)
+   f6 84 24 88 00 00 00 03 testb  $0x3,0x88(%rsp)
-   f7 44 24 68 03 00 00 00 testl  $0x3,0x68(%rsp)
+   f6 44 24 68 03  testb  $0x3,0x68(%rsp)
-   f7 84 24 90 00 00 00 03 00 00 00testl  $0x3,0x90(%rsp)
+   f6 84 24 90 00 00 00 03 testb  $0x3,0x90(%rsp)

Signed-off-by: Denys Vlasenko dvlas...@redhat.com
Acked-by: Andy Lutomirski l...@kernel.org
Cc: Alexei Starovoitov a...@plumgrid.com
Cc: Borislav Petkov b...@alien8.de
Cc: Brian Gerst brge...@gmail.com
Cc: Frederic Weisbecker fweis...@gmail.com
Cc: H. Peter Anvin h...@zytor.com
Cc: Kees Cook keesc...@chromium.org
Cc: Linus Torvalds torva...@linux-foundation.org
Cc: Oleg Nesterov o...@redhat.com
Cc: Steven Rostedt rost...@goodmis.org
Cc: Thomas Gleixner t...@linutronix.de
Cc: Will Drewry w...@chromium.org
Link: 
http://lkml.kernel.org/r/1430140912-7960-2-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar mi...@kernel.org
---
 arch/x86/kernel/entry_64.S | 11 +--
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index 8f8b22a..60705b03 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -601,7 +601,7 @@ ENTRY(ret_from_fork)
 
RESTORE_EXTRA_REGS
 
-   testl $3,CS(%rsp)   # from kernel_thread?
+   testb   $3, CS(%rsp)# from kernel_thread?
 
/*
 * By the time we get here, we have no idea whether our pt_regs,
@@ -665,7 +665,7 @@ END(irq_entries_start)
 
leaq -RBP(%rsp),%rdi/* arg1 for \func (pointer to pt_regs) */
 
-   testl $3, CS-RBP(%rsp)
+   testb   $3, CS-RBP(%rsp)
jz  1f
SWAPGS
 1:
@@ -720,7 +720,7 @@ ret_from_intr:
CFI_DEF_CFA_REGISTERrsp
CFI_ADJUST_CFA_OFFSET   RBP
 
-   testl $3,CS(%rsp)
+   testb   $3, CS(%rsp)
jz  retint_kernel
/* Interrupt came from user space */
 
@@ -968,7 +968,7 @@ ENTRY(\sym)
.if \paranoid
.if \paranoid == 1
CFI_REMEMBER_STATE
-   testl $3, CS(%rsp)  /* If coming from userspace, switch */
+   testb   $3, CS(%rsp)/* If coming from userspace, switch */
jnz 1f  /* stacks. */
.endif
call paranoid_entry
@@ -1309,7 +1309,7 @@ ENTRY(error_entry)
SAVE_C_REGS 8
SAVE_EXTRA_REGS 8
xorl %ebx,%ebx
-   testl $3,CS+8(%rsp)
+   testb   $3, CS+8(%rsp)
jz  error_kernelspace
 error_swapgs:
SWAPGS
@@ -1606,7 +1606,6 @@ end_repeat_nmi:
je 1f
movq %r12, %cr2
 1:
-   
testl %ebx,%ebx /* swapgs needed? */
jnz nmi_restore
 nmi_swapgs:
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/asm] x86/entry: Stop using PER_CPU_VAR(kernel_stack)

2015-05-08 Thread tip-bot for Denys Vlasenko
Commit-ID:  63332a8455d8310b77d38779c6c21a660a8d9feb
Gitweb: http://git.kernel.org/tip/63332a8455d8310b77d38779c6c21a660a8d9feb
Author: Denys Vlasenko dvlas...@redhat.com
AuthorDate: Fri, 24 Apr 2015 17:31:33 +0200
Committer:  Ingo Molnar mi...@kernel.org
CommitDate: Fri, 8 May 2015 13:43:52 +0200

x86/entry: Stop using PER_CPU_VAR(kernel_stack)

PER_CPU_VAR(kernel_stack) is redundant:

  - On the 64-bit build, we can use PER_CPU_VAR(cpu_tss + TSS_sp0).
  - On the 32-bit build, we can use PER_CPU_VAR(cpu_current_top_of_stack).

PER_CPU_VAR(kernel_stack) will be deleted by a separate change.

Signed-off-by: Denys Vlasenko dvlas...@redhat.com
Cc: Alexei Starovoitov a...@plumgrid.com
Cc: Andrew Morton a...@linux-foundation.org
Cc: Andy Lutomirski l...@amacapital.net
Cc: Borislav Petkov b...@alien8.de
Cc: Frederic Weisbecker fweis...@gmail.com
Cc: H. Peter Anvin h...@zytor.com
Cc: Kees Cook keesc...@chromium.org
Cc: Linus Torvalds torva...@linux-foundation.org
Cc: Oleg Nesterov o...@redhat.com
Cc: Peter Zijlstra pet...@infradead.org
Cc: Steven Rostedt rost...@goodmis.org
Cc: Thomas Gleixner t...@linutronix.de
Cc: Will Drewry w...@chromium.org
Link: 
http://lkml.kernel.org/r/1429889495-27850-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar mi...@kernel.org
---
 arch/x86/ia32/ia32entry.S  | 2 +-
 arch/x86/include/asm/thread_info.h | 8 +++-
 arch/x86/kernel/entry_64.S | 2 +-
 arch/x86/xen/xen-asm_64.S  | 5 +++--
 4 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
index 2ab0f71..1b1330c 100644
--- a/arch/x86/ia32/ia32entry.S
+++ b/arch/x86/ia32/ia32entry.S
@@ -346,7 +346,7 @@ ENTRY(ia32_cstar_target)
SWAPGS_UNSAFE_STACK
movl%esp,%r8d
CFI_REGISTERrsp,r8
-   movqPER_CPU_VAR(kernel_stack),%rsp
+   movqPER_CPU_VAR(cpu_tss + TSS_sp0),%rsp
ENABLE_INTERRUPTS(CLBR_NONE)
 
/* Zero-extending 32-bit regs, do not remove */
diff --git a/arch/x86/include/asm/thread_info.h 
b/arch/x86/include/asm/thread_info.h
index b4bdec3..d656a36 100644
--- a/arch/x86/include/asm/thread_info.h
+++ b/arch/x86/include/asm/thread_info.h
@@ -198,9 +198,15 @@ static inline unsigned long current_stack_pointer(void)
 #else /* !__ASSEMBLY__ */
 
 /* Load thread_info address into reg */
+#ifdef CONFIG_X86_32
 #define GET_THREAD_INFO(reg) \
-   _ASM_MOV PER_CPU_VAR(kernel_stack),reg ; \
+   _ASM_MOV PER_CPU_VAR(cpu_current_top_of_stack),reg ; \
_ASM_SUB $(THREAD_SIZE),reg ;
+#else
+#define GET_THREAD_INFO(reg) \
+   _ASM_MOV PER_CPU_VAR(cpu_tss + TSS_sp0),reg ; \
+   _ASM_SUB $(THREAD_SIZE),reg ;
+#endif
 
 /*
  * ASM operand which evaluates to a 'thread_info' address of
diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index 7423e3e..c13b86b 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -216,7 +216,7 @@ ENTRY(system_call)
 GLOBAL(system_call_after_swapgs)
 
movq%rsp,PER_CPU_VAR(rsp_scratch)
-   movqPER_CPU_VAR(kernel_stack),%rsp
+   movqPER_CPU_VAR(cpu_tss + TSS_sp0),%rsp
 
/* Construct struct pt_regs on stack */
pushq_cfi $__USER_DS/* pt_regs-ss */
diff --git a/arch/x86/xen/xen-asm_64.S b/arch/x86/xen/xen-asm_64.S
index a2cabb8..5aa7ec6 100644
--- a/arch/x86/xen/xen-asm_64.S
+++ b/arch/x86/xen/xen-asm_64.S
@@ -15,6 +15,7 @@
 #include asm/percpu.h
 #include asm/processor-flags.h
 #include asm/segment.h
+#include asm/asm-offsets.h
 
 #include xen/interface/xen.h
 
@@ -53,7 +54,7 @@ ENTRY(xen_sysret64)
 * still with the kernel gs, so we can easily switch back
 */
movq %rsp, PER_CPU_VAR(rsp_scratch)
-   movq PER_CPU_VAR(kernel_stack), %rsp
+   movq PER_CPU_VAR(cpu_tss + TSS_sp0), %rsp
 
pushq $__USER_DS
pushq PER_CPU_VAR(rsp_scratch)
@@ -72,7 +73,7 @@ ENTRY(xen_sysret32)
 * still with the kernel gs, so we can easily switch back
 */
movq %rsp, PER_CPU_VAR(rsp_scratch)
-   movq PER_CPU_VAR(kernel_stack), %rsp
+   movq PER_CPU_VAR(cpu_tss + TSS_sp0), %rsp
 
pushq $__USER32_DS
pushq PER_CPU_VAR(rsp_scratch)
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/asm] x86: Force inlining of atomic ops

2015-05-08 Thread tip-bot for Denys Vlasenko
Commit-ID:  2a4e90b18c256d52a7f3f77d58114f6d4e4a7f9f
Gitweb: http://git.kernel.org/tip/2a4e90b18c256d52a7f3f77d58114f6d4e4a7f9f
Author: Denys Vlasenko dvlas...@redhat.com
AuthorDate: Fri, 8 May 2015 12:26:02 +0200
Committer:  Ingo Molnar mi...@kernel.org
CommitDate: Fri, 8 May 2015 12:55:50 +0200

x86: Force inlining of atomic ops

With both gcc 4.7.2 and 4.9.2, sometimes gcc mysteriously
doesn't inline very small functions we expect to be inlined:

$ nm --size-sort vmlinux | grep -iF ' t ' | uniq -c | grep -v '^
*1 ' | sort -rn 473 000b t spin_unlock_irqrestore
449 005f t rcu_read_unlock
355 0009 t atomic_inc== THIS
353 006e t rcu_read_lock
350 0075 t rcu_read_lock_sched_held
291 000b t spin_unlock
266 0019 t arch_local_irq_restore
215 000b t spin_lock
180 0011 t kzalloc
165 0012 t list_add_tail
161 0019 t arch_local_save_flags
153 0016 t test_and_set_bit
134 000b t spin_unlock_irq
134 0009 t atomic_dec== THIS
130 000b t spin_unlock_bh
122 0010 t brelse
120 0016 t test_and_clear_bit
120 000b t spin_lock_irq
119 001e t get_dma_ops
117 0053 t cpumask_next
116 0036 t kref_get
114 001a t schedule_work
106 000b t spin_lock_bh
103 0019 t arch_local_irq_disable
...

Note sizes of marked functions. They are merely 9 bytes long!
Selecting function with 'atomic' in their names:

355 0009 t atomic_inc
134 0009 t atomic_dec
 98 0014 t atomic_dec_and_test
 31 000e t atomic_add_return
 27 000a t atomic64_inc
 26 002f t kmap_atomic
 24 0009 t atomic_add
 12 0009 t atomic_sub
 10 0021 t __atomic_add_unless
 10 000a t atomic64_add
  5 001f t __atomic_add_unless.constprop.7
  5 000a t atomic64_dec
  4 001f t __atomic_add_unless.constprop.18
  4 001f t __atomic_add_unless.constprop.12
  4 001f t __atomic_add_unless.constprop.10
  3 001f t __atomic_add_unless.constprop.13
  3 0011 t atomic64_add_return
  2 001f t __atomic_add_unless.constprop.9
  2 001f t __atomic_add_unless.constprop.8
  2 001f t __atomic_add_unless.constprop.6
  2 001f t __atomic_add_unless.constprop.5
  2 001f t __atomic_add_unless.constprop.3
  2 001f t __atomic_add_unless.constprop.22
  2 001f t __atomic_add_unless.constprop.14
  2 001f t __atomic_add_unless.constprop.11
  2 001e t atomic_dec_if_positive
  2 0014 t atomic_inc_and_test
  2 0011 t atomic_add_return.constprop.4
  2 0011 t atomic_add_return.constprop.17
  2 0011 t atomic_add_return.constprop.16
  2 000d t atomic_inc.constprop.4
  2 000c t atomic_cmpxchg

This patch fixes this for x86 atomic ops via
s/inline/__always_inline/. This decreases allyesconfig kernel by
about 25k:

text data  bss   dec hex filename
82399481 22255416 20627456 125282353 777a831 vmlinux.before
82375570 22255544 20627456 125258570 7774b4a vmlinux

Signed-off-by: Denys Vlasenko dvlas...@redhat.com
Cc: Alexei Starovoitov a...@plumgrid.com
Cc: Andrew Morton a...@linux-foundation.org
Cc: Andy Lutomirski l...@amacapital.net
Cc: Borislav Petkov b...@alien8.de
Cc: Frederic Weisbecker fweis...@gmail.com
Cc: H. Peter Anvin h...@zytor.com
Cc: Kees Cook keesc...@chromium.org
Cc: Linus Torvalds torva...@linux-foundation.org
Cc: Peter Zijlstra pet...@infradead.org
Cc: Steven Rostedt rost...@goodmis.org
Cc: Thomas Gleixner t...@linutronix.de
Cc: Will Drewry w...@chromium.org
Link: 
http://lkml.kernel.org/r/1431080762-17797-1-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar mi...@kernel.org
---
 arch/x86/include/asm/atomic.h | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
index 75a9ee8..e916895 100644
--- a/arch/x86/include/asm/atomic.h
+++ b/arch/x86/include/asm/atomic.h
@@ -22,7 +22,7 @@
  *
  * Atomically reads the value of @v.
  */
-static inline int atomic_read(const atomic_t *v)
+static __always_inline int atomic_read(const atomic_t *v)
 {
return ACCESS_ONCE((v)-counter);
 }
@@ -34,7 +34,7 @@ static inline int atomic_read(const atomic_t *v)
  *
  * Atomically sets the value of @v to @i.
  */
-static inline void atomic_set(atomic_t *v, int i)
+static __always_inline void 

[tip:x86/asm] x86/entry: Define 'cpu_current_top_of_stack' for 64-bit code

2015-05-08 Thread tip-bot for Denys Vlasenko
Commit-ID:  3a23208e69679597e767cf3547b1a30dd845d9b5
Gitweb: http://git.kernel.org/tip/3a23208e69679597e767cf3547b1a30dd845d9b5
Author: Denys Vlasenko dvlas...@redhat.com
AuthorDate: Fri, 24 Apr 2015 17:31:35 +0200
Committer:  Ingo Molnar mi...@kernel.org
CommitDate: Fri, 8 May 2015 13:50:02 +0200

x86/entry: Define 'cpu_current_top_of_stack' for 64-bit code

32-bit code has PER_CPU_VAR(cpu_current_top_of_stack).
64-bit code uses somewhat more obscure: PER_CPU_VAR(cpu_tss + TSS_sp0).

Define the 'cpu_current_top_of_stack' macro on CONFIG_X86_64
as well so that the PER_CPU_VAR(cpu_current_top_of_stack)
expression can be used in both 32-bit and 64-bit code.

Signed-off-by: Denys Vlasenko dvlas...@redhat.com
Cc: Alexei Starovoitov a...@plumgrid.com
Cc: Andrew Morton a...@linux-foundation.org
Cc: Andy Lutomirski l...@amacapital.net
Cc: Borislav Petkov b...@alien8.de
Cc: Frederic Weisbecker fweis...@gmail.com
Cc: H. Peter Anvin h...@zytor.com
Cc: Kees Cook keesc...@chromium.org
Cc: Linus Torvalds torva...@linux-foundation.org
Cc: Oleg Nesterov o...@redhat.com
Cc: Peter Zijlstra pet...@infradead.org
Cc: Steven Rostedt rost...@goodmis.org
Cc: Thomas Gleixner t...@linutronix.de
Cc: Will Drewry w...@chromium.org
Link: 
http://lkml.kernel.org/r/1429889495-27850-3-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar mi...@kernel.org
---
 arch/x86/ia32/ia32entry.S  |  4 ++--
 arch/x86/include/asm/thread_info.h | 10 --
 arch/x86/kernel/entry_64.S |  2 +-
 arch/x86/xen/xen-asm_64.S  |  5 +++--
 4 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
index 1b1330c..63450a5 100644
--- a/arch/x86/ia32/ia32entry.S
+++ b/arch/x86/ia32/ia32entry.S
@@ -113,7 +113,7 @@ ENTRY(ia32_sysenter_target)
 * it is too small to ever cause noticeable irq latency.
 */
SWAPGS_UNSAFE_STACK
-   movqPER_CPU_VAR(cpu_tss + TSS_sp0), %rsp
+   movqPER_CPU_VAR(cpu_current_top_of_stack), %rsp
ENABLE_INTERRUPTS(CLBR_NONE)
 
/* Zero-extending 32-bit regs, do not remove */
@@ -346,7 +346,7 @@ ENTRY(ia32_cstar_target)
SWAPGS_UNSAFE_STACK
movl%esp,%r8d
CFI_REGISTERrsp,r8
-   movqPER_CPU_VAR(cpu_tss + TSS_sp0),%rsp
+   movqPER_CPU_VAR(cpu_current_top_of_stack),%rsp
ENABLE_INTERRUPTS(CLBR_NONE)
 
/* Zero-extending 32-bit regs, do not remove */
diff --git a/arch/x86/include/asm/thread_info.h 
b/arch/x86/include/asm/thread_info.h
index 4722889..225ee54 100644
--- a/arch/x86/include/asm/thread_info.h
+++ b/arch/x86/include/asm/thread_info.h
@@ -195,16 +195,14 @@ static inline unsigned long current_stack_pointer(void)
 
 #else /* !__ASSEMBLY__ */
 
+#ifdef CONFIG_X86_64
+# define cpu_current_top_of_stack (cpu_tss + TSS_sp0)
+#endif
+
 /* Load thread_info address into reg */
-#ifdef CONFIG_X86_32
 #define GET_THREAD_INFO(reg) \
_ASM_MOV PER_CPU_VAR(cpu_current_top_of_stack),reg ; \
_ASM_SUB $(THREAD_SIZE),reg ;
-#else
-#define GET_THREAD_INFO(reg) \
-   _ASM_MOV PER_CPU_VAR(cpu_tss + TSS_sp0),reg ; \
-   _ASM_SUB $(THREAD_SIZE),reg ;
-#endif
 
 /*
  * ASM operand which evaluates to a 'thread_info' address of
diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index c13b86b..09c3f9e 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -216,7 +216,7 @@ ENTRY(system_call)
 GLOBAL(system_call_after_swapgs)
 
movq%rsp,PER_CPU_VAR(rsp_scratch)
-   movqPER_CPU_VAR(cpu_tss + TSS_sp0),%rsp
+   movqPER_CPU_VAR(cpu_current_top_of_stack),%rsp
 
/* Construct struct pt_regs on stack */
pushq_cfi $__USER_DS/* pt_regs-ss */
diff --git a/arch/x86/xen/xen-asm_64.S b/arch/x86/xen/xen-asm_64.S
index 5aa7ec6..04529e6 100644
--- a/arch/x86/xen/xen-asm_64.S
+++ b/arch/x86/xen/xen-asm_64.S
@@ -16,6 +16,7 @@
 #include asm/processor-flags.h
 #include asm/segment.h
 #include asm/asm-offsets.h
+#include asm/thread_info.h
 
 #include xen/interface/xen.h
 
@@ -54,7 +55,7 @@ ENTRY(xen_sysret64)
 * still with the kernel gs, so we can easily switch back
 */
movq %rsp, PER_CPU_VAR(rsp_scratch)
-   movq PER_CPU_VAR(cpu_tss + TSS_sp0), %rsp
+   movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp
 
pushq $__USER_DS
pushq PER_CPU_VAR(rsp_scratch)
@@ -73,7 +74,7 @@ ENTRY(xen_sysret32)
 * still with the kernel gs, so we can easily switch back
 */
movq %rsp, PER_CPU_VAR(rsp_scratch)
-   movq PER_CPU_VAR(cpu_tss + TSS_sp0), %rsp
+   movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp
 
pushq $__USER32_DS
pushq PER_CPU_VAR(rsp_scratch)
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  

[tip:x86/asm] x86/entry: Remove unused 'kernel_stack' per-cpu variable

2015-05-08 Thread tip-bot for Denys Vlasenko
Commit-ID:  fed7c3f0f750f225317828d691e9eb76eec887b3
Gitweb: http://git.kernel.org/tip/fed7c3f0f750f225317828d691e9eb76eec887b3
Author: Denys Vlasenko dvlas...@redhat.com
AuthorDate: Fri, 24 Apr 2015 17:31:34 +0200
Committer:  Ingo Molnar mi...@kernel.org
CommitDate: Fri, 8 May 2015 13:49:43 +0200

x86/entry: Remove unused 'kernel_stack' per-cpu variable

Signed-off-by: Denys Vlasenko dvlas...@redhat.com
Acked-by: Andy Lutomirski l...@kernel.org
Cc: Alexei Starovoitov a...@plumgrid.com
Cc: Andrew Morton a...@linux-foundation.org
Cc: Borislav Petkov b...@alien8.de
Cc: Frederic Weisbecker fweis...@gmail.com
Cc: H. Peter Anvin h...@zytor.com
Cc: Kees Cook keesc...@chromium.org
Cc: Linus Torvalds torva...@linux-foundation.org
Cc: Oleg Nesterov o...@redhat.com
Cc: Peter Zijlstra pet...@infradead.org
Cc: Steven Rostedt rost...@goodmis.org
Cc: Thomas Gleixner t...@linutronix.de
Cc: Will Drewry w...@chromium.org
Link: 
http://lkml.kernel.org/r/1429889495-27850-2-git-send-email-dvlas...@redhat.com
Signed-off-by: Ingo Molnar mi...@kernel.org
---
 arch/x86/include/asm/thread_info.h | 2 --
 arch/x86/kernel/cpu/common.c   | 4 
 arch/x86/kernel/process_32.c   | 5 +
 arch/x86/kernel/process_64.c   | 3 ---
 arch/x86/kernel/smpboot.c  | 2 --
 5 files changed, 1 insertion(+), 15 deletions(-)

diff --git a/arch/x86/include/asm/thread_info.h 
b/arch/x86/include/asm/thread_info.h
index d656a36..4722889 100644
--- a/arch/x86/include/asm/thread_info.h
+++ b/arch/x86/include/asm/thread_info.h
@@ -177,8 +177,6 @@ struct thread_info {
  */
 #ifndef __ASSEMBLY__
 
-DECLARE_PER_CPU(unsigned long, kernel_stack);
-
 static inline struct thread_info *current_thread_info(void)
 {
return (struct thread_info *)(current_top_of_stack() - THREAD_SIZE);
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index a62cf04..6bec0b5 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -1155,10 +1155,6 @@ static __init int setup_disablecpuid(char *arg)
 }
 __setup(clearcpuid=, setup_disablecpuid);
 
-DEFINE_PER_CPU(unsigned long, kernel_stack) =
-   (unsigned long)init_thread_union + THREAD_SIZE;
-EXPORT_PER_CPU_SYMBOL(kernel_stack);
-
 #ifdef CONFIG_X86_64
 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
 struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
index 8ed2106..a99900c 100644
--- a/arch/x86/kernel/process_32.c
+++ b/arch/x86/kernel/process_32.c
@@ -302,13 +302,10 @@ __switch_to(struct task_struct *prev_p, struct 
task_struct *next_p)
arch_end_context_switch(next_p);
 
/*
-* Reload esp0, kernel_stack, and current_top_of_stack.  This changes
+* Reload esp0 and cpu_current_top_of_stack.  This changes
 * current_thread_info().
 */
load_sp0(tss, next);
-   this_cpu_write(kernel_stack,
-  (unsigned long)task_stack_page(next_p) +
-  THREAD_SIZE);
this_cpu_write(cpu_current_top_of_stack,
   (unsigned long)task_stack_page(next_p) +
   THREAD_SIZE);
diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
index ddfdbf7..8213450 100644
--- a/arch/x86/kernel/process_64.c
+++ b/arch/x86/kernel/process_64.c
@@ -409,9 +409,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct 
*next_p)
/* Reload esp0 and ss1.  This changes current_thread_info(). */
load_sp0(tss, next);
 
-   this_cpu_write(kernel_stack,
-   (unsigned long)task_stack_page(next_p) + THREAD_SIZE);
-
/*
 * Now maybe reload the debug registers and handle I/O bitmaps
 */
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index 50e547e..023cccf 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -792,8 +792,6 @@ void common_cpu_up(unsigned int cpu, struct task_struct 
*idle)
clear_tsk_thread_flag(idle, TIF_FORK);
initial_gs = per_cpu_offset(cpu);
 #endif
-   per_cpu(kernel_stack, cpu) =
-   (unsigned long)task_stack_page(idle) + THREAD_SIZE;
 }
 
 /*
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


  1   2   3   >