[PATCH v9 1/2] Documentation: kdump: remind user of nr_cpus

2016-08-17 Thread Zhou Wenjian
nr_cpus can help to save memory. So we should remind user of it.

Signed-off-by: Zhou Wenjian 
Acked-by: Baoquan He 
Acked-by: Xunlei Pang 
---
 Documentation/kdump/kdump.txt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/kdump/kdump.txt b/Documentation/kdump/kdump.txt
index 88ff63d..d900080 100644
--- a/Documentation/kdump/kdump.txt
+++ b/Documentation/kdump/kdump.txt
@@ -393,6 +393,8 @@ Notes on loading the dump-capture kernel:
 * We generally don' have to bring up a SMP kernel just to capture the
   dump. Hence generally it is useful either to build a UP dump-capture
   kernel or specify maxcpus=1 option while loading dump-capture kernel.
+  Note, though maxcpus always works, you should replace it by nr_cpus to
+  save memory if supported by the current ARCH, such as x86.
 
 * For s390x there are two kdump modes: If a ELF header is specified with
   the elfcorehdr= kernel parameter, it is used by the kdump kernel as it
-- 
1.8.3.1



--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v9 0/2] update the doc of kdump

2016-08-17 Thread Zhou Wenjian
v8->v9: rearrange the patch.
it won't fix typo which original exists.
those should be fixed in other patch, which I'll post later.
v7->v8: fix "a SMP kernel" to "an SMP kernel" and replace "\" with "/"
v6->v7: fix typo
v5->v6: replace "we" with "you"
v4->v5: move change log to cover letter
v3->v4: update the description of bring up SMP dump-capture kernel
v2->v3: add description of nr_cpus.
v1->v2: change nr_cpus to maxcpus

Zhou Wenjian (2):
  Documentation: kdump: remind user of nr_cpus
  Documentation: kdump: add description of enable multi-cpus support

 Documentation/kdump/kdump.txt | 9 +
 1 file changed, 9 insertions(+)

-- 
1.8.3.1



--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v9 2/2] Documentation: kdump: add description of enable multi-cpus support

2016-08-17 Thread Zhou Wenjian
multi-cpu support is useful to improve the performance of kdump in
some cases. So add the description of enable multi-cpu support in
dump-capture kernel.

Signed-off-by: Zhou Wenjian 
Acked-by: Baoquan He 
Acked-by: Xunlei Pang 
---
 Documentation/kdump/kdump.txt | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/Documentation/kdump/kdump.txt b/Documentation/kdump/kdump.txt
index d900080..31e6b88 100644
--- a/Documentation/kdump/kdump.txt
+++ b/Documentation/kdump/kdump.txt
@@ -396,6 +396,13 @@ Notes on loading the dump-capture kernel:
   Note, though maxcpus always works, you should replace it by nr_cpus to
   save memory if supported by the current ARCH, such as x86.
 
+* You should enable multi-cpu support in dump-capture kernel if you intend
+  to use multi-thread programs with it, such as parallel dump feature of
+  makedumpfile. Otherwise, the multi-thread program may have a great
+  performance degradation. To enable multi-cpu support, you should bring up an
+  SMP dump-capture kernel and specify maxcpus/nr_cpus, disable_cpu_apicid=[X]
+  options while loading it.
+
 * For s390x there are two kdump modes: If a ELF header is specified with
   the elfcorehdr= kernel parameter, it is used by the kdump kernel as it
   is done on all other architectures. If no elfcorehdr= kernel parameter is
-- 
1.8.3.1



--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v8 1/2] Documentation: kdump: remind user of nr_cpus

2016-08-17 Thread Joe Perches
On Thu, 2016-08-18 at 10:31 +0800, Zhou Wenjian wrote:
> nr_cpus can help to save memory. So we should remind user of it.

trivia:
> diff --git a/Documentation/kdump/kdump.txt b/Documentation/kdump/kdump.txt
[]
> @@ -390,9 +390,11 @@ Notes on loading the dump-capture kernel:
>  * Boot parameter "1" boots the dump-capture kernel into single-user
>    mode without networking. If you want networking, use "3".
>  
> -* We generally don' have to bring up a SMP kernel just to capture the
> +* We generally don' have to bring up an SMP kernel just to capture the

don't or do not

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v8 1/2] Documentation: kdump: remind user of nr_cpus

2016-08-17 Thread Zhou Wenjian
nr_cpus can help to save memory. So we should remind user of it.

Signed-off-by: Zhou Wenjian 
Acked-by: Baoquan He 
Acked-by: Xunlei Pang 
---
 Documentation/kdump/kdump.txt | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Documentation/kdump/kdump.txt b/Documentation/kdump/kdump.txt
index 88ff63d..e8da1d5 100644
--- a/Documentation/kdump/kdump.txt
+++ b/Documentation/kdump/kdump.txt
@@ -390,9 +390,11 @@ Notes on loading the dump-capture kernel:
 * Boot parameter "1" boots the dump-capture kernel into single-user
   mode without networking. If you want networking, use "3".
 
-* We generally don' have to bring up a SMP kernel just to capture the
+* We generally don' have to bring up an SMP kernel just to capture the
   dump. Hence generally it is useful either to build a UP dump-capture
   kernel or specify maxcpus=1 option while loading dump-capture kernel.
+  Note, though maxcpus always works, you should replace it by nr_cpus to
+  save memory if supported by the current ARCH, such as x86.
 
 * For s390x there are two kdump modes: If a ELF header is specified with
   the elfcorehdr= kernel parameter, it is used by the kdump kernel as it
-- 
1.8.3.1



--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v8 0/2] update the doc of kdump

2016-08-17 Thread Zhou Wenjian
v7->v8: fix "a SMP kernel" to "an SMP kernel" and replace "\" with "/"
v6->v7: fix typo
v5->v6: replace "we" with "you"
v4->v5: move change log to cover letter
v3->v4: update the description of bring up SMP dump-capture kernel
v2->v3: add description of nr_cpus.
v1->v2: change nr_cpus to maxcpus

Zhou Wenjian (2):
  Documentation: kdump: remind user of nr_cpus
  Documentation: kdump: add description of enable multi-cpus support

 Documentation/kdump/kdump.txt | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

-- 
1.8.3.1



--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v8 2/2] Documentation: kdump: add description of enable multi-cpus support

2016-08-17 Thread Zhou Wenjian
multi-cpu support is useful to improve the performance of kdump in
some cases. So add the description of enable multi-cpu support in
dump-capture kernel.

Signed-off-by: Zhou Wenjian 
Acked-by: Baoquan He 
Acked-by: Xunlei Pang 
---
 Documentation/kdump/kdump.txt | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/Documentation/kdump/kdump.txt b/Documentation/kdump/kdump.txt
index e8da1d5..c781d49 100644
--- a/Documentation/kdump/kdump.txt
+++ b/Documentation/kdump/kdump.txt
@@ -396,6 +396,13 @@ Notes on loading the dump-capture kernel:
   Note, though maxcpus always works, you should replace it by nr_cpus to
   save memory if supported by the current ARCH, such as x86.
 
+* You should enable multi-cpu support in dump-capture kernel if you intend
+  to use multi-thread programs with it, such as parallel dump feature of
+  makedumpfile. Otherwise, the multi-thread program may have a great
+  performance degradation. To enable multi-cpu support, you should bring up an
+  SMP dump-capture kernel and specify maxcpus/nr_cpus, disable_cpu_apicid=[X]
+  options while loading it.
+
 * For s390x there are two kdump modes: If a ELF header is specified with
   the elfcorehdr= kernel parameter, it is used by the kdump kernel as it
   is done on all other architectures. If no elfcorehdr= kernel parameter is
-- 
1.8.3.1



--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v7 2/2] Documentation: kdump: add description of enable multi-cpus support

2016-08-17 Thread Xunlei Pang
On 2016/08/18 at 09:50, Zhou Wenjian wrote:
> multi-cpu support is useful to improve the performance of kdump in
> some cases. So add the description of enable multi-cpu support in
> dump-capture kernel.
>
> Signed-off-by: Zhou Wenjian 
> Acked-by: Baoquan He 
> ---
>  Documentation/kdump/kdump.txt | 7 +++
>  1 file changed, 7 insertions(+)
>
> diff --git a/Documentation/kdump/kdump.txt b/Documentation/kdump/kdump.txt
> index 96da2b7..c93a6e0 100644
> --- a/Documentation/kdump/kdump.txt
> +++ b/Documentation/kdump/kdump.txt
> @@ -396,6 +396,13 @@ Notes on loading the dump-capture kernel:
>Note, though maxcpus always works, you should replace it by nr_cpus to
>save memory if supported by the current ARCH, such as x86.
>  
> +* You should enable multi-cpu support in dump-capture kernel if you intend
> +  to use multi-thread programs with it, such as parallel dump feature of
> +  makedumpfile. Otherwise, the multi-thread program may have a great
> +  performance degradation. To enable multi-cpu support, you should bring up
> +  a SMP dump-capture kernel and specify maxcpus\nr_cpus, 
> disable_cpu_apicid=[X]

s/a SMP/an SMP/
For "maxcpus\nr_cpus", I think to use slash instead of backslash in Linux is 
better.

Otherwise, looks good to me.

Regards,
Xunlei

> +  options while loading it.
> +
>  * For s390x there are two kdump modes: If a ELF header is specified with
>the elfcorehdr= kernel parameter, it is used by the kdump kernel as it
>is done on all other architectures. If no elfcorehdr= kernel parameter is

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 0/2] update the doc of kdump

2016-08-17 Thread Zhou Wenjian
v6->v7: fix typo
v5->v6: replace "we" with "you"
v4->v5: move change log to cover letter
v3->v4: update the description of bring up SMP dump-capture kernel
v2->v3: add description of nr_cpus.
v1->v2: change nr_cpus to maxcpus


Zhou Wenjian (2):
  Documentation: kdump: remind user of nr_cpus
  Documentation: kdump: add description of enable multi-cpus support

 Documentation/kdump/kdump.txt | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

-- 
1.8.3.1



--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 1/2] Documentation: kdump: remind user of nr_cpus

2016-08-17 Thread Zhou Wenjian
nr_cpus can help to save memory. So we should remind user of it.

Signed-off-by: Zhou Wenjian 
Acked-by: Baoquan He 
---
 Documentation/kdump/kdump.txt | 2 +++-
 1 file changed, 2 insertions(+)

diff --git a/Documentation/kdump/kdump.txt b/Documentation/kdump/kdump.txt
index 88ff63d..96da2b7 100644
--- a/Documentation/kdump/kdump.txt
+++ b/Documentation/kdump/kdump.txt
@@ -393,6 +393,8 @@ Notes on loading the dump-capture kernel:
 * We generally don' have to bring up a SMP kernel just to capture the
   dump. Hence generally it is useful either to build a UP dump-capture
   kernel or specify maxcpus=1 option while loading dump-capture kernel.
+  Note, though maxcpus always works, you should replace it by nr_cpus to
+  save memory if supported by the current ARCH, such as x86.
 
 * For s390x there are two kdump modes: If a ELF header is specified with
   the elfcorehdr= kernel parameter, it is used by the kdump kernel as it
-- 
1.8.3.1



--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 2/2] Documentation: kdump: add description of enable multi-cpus support

2016-08-17 Thread Zhou Wenjian
multi-cpu support is useful to improve the performance of kdump in
some cases. So add the description of enable multi-cpu support in
dump-capture kernel.

Signed-off-by: Zhou Wenjian 
Acked-by: Baoquan He 
---
 Documentation/kdump/kdump.txt | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/Documentation/kdump/kdump.txt b/Documentation/kdump/kdump.txt
index 96da2b7..c93a6e0 100644
--- a/Documentation/kdump/kdump.txt
+++ b/Documentation/kdump/kdump.txt
@@ -396,6 +396,13 @@ Notes on loading the dump-capture kernel:
   Note, though maxcpus always works, you should replace it by nr_cpus to
   save memory if supported by the current ARCH, such as x86.
 
+* You should enable multi-cpu support in dump-capture kernel if you intend
+  to use multi-thread programs with it, such as parallel dump feature of
+  makedumpfile. Otherwise, the multi-thread program may have a great
+  performance degradation. To enable multi-cpu support, you should bring up
+  a SMP dump-capture kernel and specify maxcpus\nr_cpus, disable_cpu_apicid=[X]
+  options while loading it.
+
 * For s390x there are two kdump modes: If a ELF header is specified with
   the elfcorehdr= kernel parameter, it is used by the kdump kernel as it
   is done on all other architectures. If no elfcorehdr= kernel parameter is
-- 
1.8.3.1



--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 3/3] Documentation: livepatch: add section about arch-specific code

2016-08-17 Thread Jessica Yu
Document usage of arch-specific elf sections in livepatch as well
as implementation of arch-specific code.

Signed-off-by: Jessica Yu 
---
 Documentation/livepatch/module-elf-format.txt | 20 
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/Documentation/livepatch/module-elf-format.txt 
b/Documentation/livepatch/module-elf-format.txt
index eedbdcf..02bfafa 100644
--- a/Documentation/livepatch/module-elf-format.txt
+++ b/Documentation/livepatch/module-elf-format.txt
@@ -25,7 +25,8 @@ Table of Contents
3.3.2 Required name format
3.3.3 Example livepatch symbol names
3.3.4 Example `readelf --symbols` output
-4. Symbol table and Elf section access
+4. Architecture-specific sections
+5. Symbol table and Elf section access
 
 
 0. Background and motivation
@@ -46,7 +47,7 @@ architecture.
 
 Since apply_relocate_add() requires access to a module's section header
 table, symbol table, and relocation section indices, Elf information is
-preserved for livepatch modules (see section 4). Livepatch manages its own
+preserved for livepatch modules (see section 5). Livepatch manages its own
 relocation sections and symbols, which are described in this document. The
 Elf constants used to mark livepatch symbols and relocation sections were
 selected from OS-specific ranges according to the definitions from glibc.
@@ -117,7 +118,7 @@ also possible for a livepatch module to have no livepatch 
relocation
 sections, as in the case of the sample livepatch module (see
 samples/livepatch).
 
-Since Elf information is preserved for livepatch modules (see Section 4), a
+Since Elf information is preserved for livepatch modules (see Section 5), a
 livepatch relocation section can be applied simply by passing in the
 appropriate section index to apply_relocate_add(), which then uses it to
 access the relocation section and apply the relocations.
@@ -292,8 +293,19 @@ Symbol table '.symtab' contains 127 entries:
 [*] Note that the 'Ndx' (Section index) for these symbols is SHN_LIVEPATCH 
(0xff20).
 "OS" means OS-specific.
 
+-
+4. Architecture-specific sections
+-
+Architectures may override arch_klp_init_object_loaded() to perform
+additional arch-specific tasks when a target module loads, such as applying
+arch-specific sections. On x86 for example, we must apply per-object
+.altinstructions and .parainstructions sections when a target module loads.
+These sections can be prefixed with ".klp.arch.$objname." so that they can
+be easily identified when iterating through a patch module's Elf sections
+(See arch/x86/kernel/livepatch.c for a complete example).
+
 --
-4. Symbol table and Elf section access
+5. Symbol table and Elf section access
 --
 A livepatch module's symbol table is accessible through module->symtab.
 
-- 
2.5.5

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 0/3] Fix issue with alternatives/paravirt patches

2016-08-17 Thread Jessica Yu
Hi,

A few months ago, Chris Arges reported a bug involving alternatives/paravirt
patching that was discussed here [1] and here [2]. To briefly summarize the
bug, patch modules that contained .altinstructions or .parainstructions
sections would break because these alternative/paravirt patches would be
applied first by the module loader (see x86 module_finalize()), then
livepatch would later clobber these patches when applying per-object
relocations. This lead to crashes and unpredictable behavior.

One conclusion we reached from our last discussion was that we will
need to introduce some arch-specific code to address this problem.
This patchset presents a possible fix for the bug by adding a new
arch-specific arch_klp_init_object_loaded() function that by default
does nothing but can be overridden by different arches.

To fix this issue for x86, since we can access a patch module's Elf
sections through mod->klp_info, we can simply delay the calls to
apply_paravirt() and apply_alternatives() to arch_klp_init_object_loaded(),
which is called after relocations have been written for an object.
In addition, for patch modules, .parainstructions and .altinstructions are
prefixed by ".klp.arch.${objname}" so that the module loader ignores them
and livepatch can apply them manually.

Currently for kpatch, we don't support including jump table sections in
the patch module, and supporting .smp_locks is currently broken, so we
don't consider those sections (for now).

I did some light testing with some patches to kvm and verified that the
original issue reported in [2] was fixed.

Based on linux-next.

v2 here:
http://lkml.kernel.org/g/1469078640-26798-1-git-send-email-j...@redhat.com

v3: 
 - Add documentation about arch-specific code
 - Make sure to call module_enable_ro() when returning on error

v2:
 - add BUILD_BUG_ON() check in arch_klp_init_object_loaded (x86)

[1] http://thread.gmane.org/gmane.linux.kernel/2185604/
[2] https://github.com/dynup/kpatch/issues/580

Jessica Yu (3):
  livepatch: use arch_klp_init_object_loaded() to finish arch-specific tasks
  livepatch/x86: apply alternatives and paravirt patches after relocations
  Documentation: livepatch: add section about arch-specific code

 Documentation/livepatch/module-elf-format.txt | 20 +++--
 arch/x86/kernel/Makefile  |  1 +
 arch/x86/kernel/livepatch.c   | 65 +++
 include/linux/livepatch.h |  3 ++
 kernel/livepatch/core.c   | 16 +--
 5 files changed, 98 insertions(+), 7 deletions(-)
 create mode 100644 arch/x86/kernel/livepatch.c

-- 
2.5.5

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 2/3] livepatch/x86: apply alternatives and paravirt patches after relocations

2016-08-17 Thread Jessica Yu
Implement arch_klp_init_object_loaded() for x86, which applies
alternatives/paravirt patches. This fixes the order in which relocations
and alternatives/paravirt patches are applied.

Previously, if a patch module had alternatives or paravirt patches,
these were applied first by the module loader before livepatch can apply
per-object relocations. The (buggy) sequence of events was:

(1) Load patch module
(2) Apply alternatives and paravirt patches to patch module
* Note that these are applied to the new functions in the patch module
(3) Apply per-object relocations to patch module when target module loads.
* This clobbers what was written in step 2

This lead to crashes and corruption in general, since livepatch would
overwrite or step on previously applied alternative/paravirt patches.
The correct sequence of events should be:

(1) Load patch module
(2) Apply per-object relocations to patch module
(3) Apply alternatives and paravirt patches to patch module

This is fixed by delaying paravirt/alternatives patching until after
relocations are applied. Any .altinstructions or .parainstructions
sections are prefixed with ".klp.arch.${objname}" and applied in
arch_klp_init_object_loaded().

Signed-off-by: Jessica Yu 
---
 arch/x86/kernel/Makefile|  1 +
 arch/x86/kernel/livepatch.c | 65 +
 2 files changed, 66 insertions(+)
 create mode 100644 arch/x86/kernel/livepatch.c

diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
index d3f49c3..92fd50c 100644
--- a/arch/x86/kernel/Makefile
+++ b/arch/x86/kernel/Makefile
@@ -81,6 +81,7 @@ obj-$(CONFIG_X86_MPPARSE) += mpparse.o
 obj-y  += apic/
 obj-$(CONFIG_X86_REBOOTFIXUPS) += reboot_fixups_32.o
 obj-$(CONFIG_DYNAMIC_FTRACE)   += ftrace.o
+obj-$(CONFIG_LIVEPATCH)+= livepatch.o
 obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += ftrace.o
 obj-$(CONFIG_FTRACE_SYSCALLS)  += ftrace.o
 obj-$(CONFIG_X86_TSC)  += trace_clock.o
diff --git a/arch/x86/kernel/livepatch.c b/arch/x86/kernel/livepatch.c
new file mode 100644
index 000..e9d252d
--- /dev/null
+++ b/arch/x86/kernel/livepatch.c
@@ -0,0 +1,65 @@
+/*
+ * livepatch.c - x86-specific Kernel Live Patching Core
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see .
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+/* Apply per-object alternatives. Based on x86 module_finalize() */
+void arch_klp_init_object_loaded(struct klp_patch *patch,
+struct klp_object *obj)
+{
+   int cnt;
+   struct klp_modinfo *info;
+   Elf_Shdr *s, *alt = NULL, *para = NULL;
+   void *aseg, *pseg;
+   const char *objname;
+   char sec_objname[MODULE_NAME_LEN];
+   char secname[KSYM_NAME_LEN];
+
+   info = patch->mod->klp_info;
+   objname = obj->name ? obj->name : "vmlinux";
+
+   /* See livepatch core code for BUILD_BUG_ON() explanation */
+   BUILD_BUG_ON(MODULE_NAME_LEN < 56 || KSYM_NAME_LEN != 128);
+
+   for (s = info->sechdrs; s < info->sechdrs + info->hdr.e_shnum; s++) {
+   /* Apply per-object .klp.arch sections */
+   cnt = sscanf(info->secstrings + s->sh_name,
+".klp.arch.%55[^.].%127s",
+sec_objname, secname);
+   if (cnt != 2)
+   continue;
+   if (strcmp(sec_objname, objname))
+   continue;
+   if (!strcmp(".altinstructions", secname))
+   alt = s;
+   if (!strcmp(".parainstructions", secname))
+   para = s;
+   }
+
+   if (alt) {
+   aseg = (void *) alt->sh_addr;
+   apply_alternatives(aseg, aseg + alt->sh_size);
+   }
+
+   if (para) {
+   pseg = (void *) para->sh_addr;
+   apply_paravirt(pseg, pseg + para->sh_size);
+   }
+}
-- 
2.5.5

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 1/3] livepatch: use arch_klp_init_object_loaded() to finish arch-specific tasks

2016-08-17 Thread Jessica Yu
Introduce arch_klp_init_object_loaded() to complete any additional
arch-specific tasks during patching. Architecture code may override this
function.

Signed-off-by: Jessica Yu 
---
 include/linux/livepatch.h |  3 +++
 kernel/livepatch/core.c   | 16 +---
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/include/linux/livepatch.h b/include/linux/livepatch.h
index a93a0b2..9072f04 100644
--- a/include/linux/livepatch.h
+++ b/include/linux/livepatch.h
@@ -116,6 +116,9 @@ int klp_unregister_patch(struct klp_patch *);
 int klp_enable_patch(struct klp_patch *);
 int klp_disable_patch(struct klp_patch *);
 
+void arch_klp_init_object_loaded(struct klp_patch *patch,
+struct klp_object *obj);
+
 /* Called from the module loader during module coming/going states */
 int klp_module_coming(struct module *mod);
 void klp_module_going(struct module *mod);
diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
index 8bbe507..5fbabe0 100644
--- a/kernel/livepatch/core.c
+++ b/kernel/livepatch/core.c
@@ -274,7 +274,6 @@ static int klp_write_object_relocations(struct module *pmod,
 
objname = klp_is_module(obj) ? obj->name : "vmlinux";
 
-   module_disable_ro(pmod);
/* For each klp relocation section */
for (i = 1; i < pmod->klp_info->hdr.e_shnum; i++) {
sec = pmod->klp_info->sechdrs + i;
@@ -309,7 +308,6 @@ static int klp_write_object_relocations(struct module *pmod,
break;
}
 
-   module_enable_ro(pmod, true);
return ret;
 }
 
@@ -763,6 +761,12 @@ static int klp_init_func(struct klp_object *obj, struct 
klp_func *func)
func->old_sympos ? func->old_sympos : 1);
 }
 
+/* Arches may override this to finish any remaining arch-specific tasks */
+void __weak arch_klp_init_object_loaded(struct klp_patch *patch,
+   struct klp_object *obj)
+{
+}
+
 /* parts of the initialization that is done only when the object is loaded */
 static int klp_init_object_loaded(struct klp_patch *patch,
  struct klp_object *obj)
@@ -770,9 +774,15 @@ static int klp_init_object_loaded(struct klp_patch *patch,
struct klp_func *func;
int ret;
 
+   module_disable_ro(patch->mod);
ret = klp_write_object_relocations(patch->mod, obj);
-   if (ret)
+   if (ret) {
+   module_enable_ro(patch->mod, true);
return ret;
+   }
+
+   arch_klp_init_object_loaded(patch, obj);
+   module_enable_ro(patch->mod, true);
 
klp_for_each_func(obj, func) {
ret = klp_find_object_symbol(obj->name, func->old_name,
-- 
2.5.5

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 06/10] docs: sphinxify kasan.txt and move to dev-tools

2016-08-17 Thread Andrey Ryabinin


On 08/09/2016 02:34 AM, Jonathan Corbet wrote:
> No textual changes beyond formatting.
> 
> Cc: Andrey Ryabinin 
> Cc: Alexander Potapenko 
> Cc: Dmitry Vyukov 
> Signed-off-by: Jonathan Corbet 
> ---
>  Documentation/dev-tools/kasan.rst | 173 
> ++
>  Documentation/dev-tools/tools.rst |   1 +
>  Documentation/kasan.txt   | 171 -
>  MAINTAINERS   |   2 +-
>  4 files changed, 175 insertions(+), 172 deletions(-)
>  create mode 100644 Documentation/dev-tools/kasan.rst
>  delete mode 100644 Documentation/kasan.txt
> 

Acked-by: Andrey Ryabinin 

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] crypto: doc - fix documentation for bulk registration functions

2016-08-17 Thread Eric Biggers
Update the documentation for crypto_register_algs() and
crypto_unregister_algs() to match the actual behavior.

Signed-off-by: Eric Biggers 
---
 Documentation/DocBook/crypto-API.tmpl | 38 ---
 1 file changed, 26 insertions(+), 12 deletions(-)

diff --git a/Documentation/DocBook/crypto-API.tmpl 
b/Documentation/DocBook/crypto-API.tmpl
index fb2a152..088b79c 100644
--- a/Documentation/DocBook/crypto-API.tmpl
+++ b/Documentation/DocBook/crypto-API.tmpl
@@ -797,7 +797,8 @@ kernel crypto API|   Caller
  include/linux/crypto.h and their definition can be seen below.
  The former function registers a single transformation, while
  the latter works on an array of transformation descriptions.
- The latter is useful when registering transformations in bulk.
+ The latter is useful when registering transformations in bulk,
+ for example when a driver implements multiple transformations.
 
 
 
@@ -822,18 +823,31 @@ kernel crypto API|   Caller
 
 
 
- The bulk registration / unregistration functions require
- that struct crypto_alg is an array of count size. These
- functions simply loop over that array and register /
- unregister each individual algorithm. If an error occurs,
- the loop is terminated at the offending algorithm definition.
- That means, the algorithms prior to the offending algorithm
- are successfully registered. Note, the caller has no way of
- knowing which cipher implementations have successfully
- registered. If this is important to know, the caller should
- loop through the different implementations using the single
- instance *_alg functions for each individual implementation.
+ The bulk registration/unregistration functions
+ register/unregister each transformation in the given array of
+ length count.  They handle errors as follows:
 
+
+ 
+  
+   crypto_register_algs() succeeds if and only if it
+   successfully registers all the given transformations. If an
+   error occurs partway through, then it rolls back successful
+   registrations before returning the error code. Note that if
+   a driver needs to handle registration errors for individual
+   transformations, then it will need to use the non-bulk
+   function crypto_register_alg() instead.
+  
+ 
+ 
+  
+   crypto_unregister_algs() tries to unregister all the given
+   transformations, continuing on error. It logs errors and
+   always returns zero.
+  
+ 
+
+

 
Single-Block Symmetric Ciphers [CIPHER]
-- 
2.8.0.rc3.226.g39d4020

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 0/3] USB Audio Gadget refactoring

2016-08-17 Thread Ruslan Bilovol
I came to this patch series when wanted to do two things:
 - use UAC1 as virtual ALSA sound card on gadget side,
   just like UAC2 is used so it's possible to do rate
   resampling
 - have both playback/capture support in UAC1

Since I wanted to have same behavior for both UAC1/UAC2,
obviously I've got an utility part (u_audio.c) for
virtual ALSA sound card handling like we have
for ethernet(u_ether) or serial(u_serial) functions.
Function-specific parts (f_uac1/f_uac2) became almost 
as storage for class-specific USB descriptors, some
boilerplate for configfs, binding and few USB
config request handling.

Originally in RFC [1] I've posted before, there was
major change to f_uac1 after that it couldn't do
direct play to existing ALSA sound card anymore,
representing audio on gadget side as virtual
ALSA sound card where audio streams are simply
sinked to and sourced from it, so it may break
current usecase for some people (and that's why
it was RFC).

During RFC discussion, it was agreed to not touch
existing f_uac1 implementation and create new one
instead. This patchset (v2) introduced new function
named f_uac1_newapi and doesn't touch current f_uac1
implementation, so people still can use old behavior

Now, it's possible to use existing user-space
applications for audio routing between Audio Gadget
and real sound card. I personally use alsaloop tool
from alsautils and have ability to create PCM
loopback between two different ALSA cards using
rate resampling, which was not possible with previous
"direct play to ALSA card" approach in f_uac1. 

While here, also dropped redundant platform
driver/device creation in f_uac2 driver (as well as
didn't add "never implemented" volume/mute functionality
in f_uac1 to f_uac1_newapi) that made this work even
easier to do.

This series is tested with both legacy g_audio.ko and
modern configfs approaches under Ubuntu 14.04 (UAC1 and
UAC2) and under Windows7 x64 (UAC1 only) having
perfect results in all cases.

Comments, testing are welcome.

v3 changes:
 - renamed u_audio exported symbols so they don't
   conflict with old f_uac1 if both are built-in.

v2 changes:
 - do not touch f_uac1, instead created f_uac1_newapi
 - added documentation for f_uac1_newapi
 - rebased on top of v4.8-rc1

[1] https://lkml.org/lkml/2016/5/23/649

Ruslan Bilovol (3):
  usb: gadget: f_uac2: remove platform driver/device creation
  usb: gadget: f_uac2: split out audio core
  usb: gadget: add f_uac1 variant based on new u_audio api

 .../ABI/testing/configfs-usb-gadget-uac1_newapi|  12 +
 Documentation/usb/gadget-testing.txt   |  41 ++
 drivers/usb/gadget/Kconfig |  25 +
 drivers/usb/gadget/function/Makefile   |   3 +
 drivers/usb/gadget/function/f_uac1_newapi.c| 795 +
 drivers/usb/gadget/function/f_uac2.c   | 778 +++-
 drivers/usb/gadget/function/u_audio.c  | 632 
 drivers/usb/gadget/function/u_audio.h  |  93 +++
 drivers/usb/gadget/function/u_uac1_newapi.h|  39 +
 drivers/usb/gadget/legacy/Kconfig  |  14 +-
 drivers/usb/gadget/legacy/audio.c  |  52 ++
 11 files changed, 1801 insertions(+), 683 deletions(-)
 create mode 100644 Documentation/ABI/testing/configfs-usb-gadget-uac1_newapi
 create mode 100644 drivers/usb/gadget/function/f_uac1_newapi.c
 create mode 100644 drivers/usb/gadget/function/u_audio.c
 create mode 100644 drivers/usb/gadget/function/u_audio.h
 create mode 100644 drivers/usb/gadget/function/u_uac1_newapi.h

-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 3/3] usb: gadget: add f_uac1 variant based on new u_audio api

2016-08-17 Thread Ruslan Bilovol
This patch adds new function f_uac1_newapi that
uses recently created u_audio api. This makes
f_uac1_newapi implementation much simpler by
reusing existing u_audio core utilities.

This also drops previous f_uac1 approach (write
audio samples directly to existing ALSA sound
card) and moves to more generic/flexible
one - create an f_uac1 ALSA sound card that
represents USB Audio function and allows to
be used by userspace tools.

f_uac1_newapi also has capture support (gadget->host).
By default, capture interface has 48000kHz/2ch
configuration, same as playback channel has.

f_uac1_newapi descriptors naming conventios
uses f_uac2 driver naming convention that
makes it more common and meaningful.

Comparing to f_uac1, the f_uac1_newapi doesn't
have volume/mute functionality. This is because
the volume/mute feature unit was dummy
implementation since that driver creation (2009)
and never had real volume control or mute
functionality.

g_audio can be built using one of existing
uac functions (f_uac1, f_uac1_newapi or f_uac2)

Signed-off-by: Ruslan Bilovol 
---
 .../ABI/testing/configfs-usb-gadget-uac1_newapi|  12 +
 Documentation/usb/gadget-testing.txt   |  41 ++
 drivers/usb/gadget/Kconfig |  21 +
 drivers/usb/gadget/function/Makefile   |   2 +
 drivers/usb/gadget/function/f_uac1_newapi.c| 795 +
 drivers/usb/gadget/function/u_uac1_newapi.h|  39 +
 drivers/usb/gadget/legacy/Kconfig  |  15 +-
 drivers/usb/gadget/legacy/audio.c  |  52 ++
 8 files changed, 975 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/ABI/testing/configfs-usb-gadget-uac1_newapi
 create mode 100644 drivers/usb/gadget/function/f_uac1_newapi.c
 create mode 100644 drivers/usb/gadget/function/u_uac1_newapi.h

diff --git a/Documentation/ABI/testing/configfs-usb-gadget-uac1_newapi 
b/Documentation/ABI/testing/configfs-usb-gadget-uac1_newapi
new file mode 100644
index 000..d355275
--- /dev/null
+++ b/Documentation/ABI/testing/configfs-usb-gadget-uac1_newapi
@@ -0,0 +1,12 @@
+What:  /config/usb-gadget/gadget/functions/uac1_newapi.name
+Date:  Aug 2016
+KernelVersion: 4.9
+Description:
+   The attributes:
+
+   c_chmask - capture channel mask
+   c_srate - capture sampling rate
+   c_ssize - capture sample size (bytes)
+   p_chmask - playback channel mask
+   p_srate - playback sampling rate
+   p_ssize - playback sample size (bytes)
diff --git a/Documentation/usb/gadget-testing.txt 
b/Documentation/usb/gadget-testing.txt
index 5819605..4598d7f 100644
--- a/Documentation/usb/gadget-testing.txt
+++ b/Documentation/usb/gadget-testing.txt
@@ -20,6 +20,7 @@ provided by gadgets.
 17. UAC2 function
 18. UVC function
 19. PRINTER function
+20. UAC1 function (new API)
 
 
 1. ACM function
@@ -770,3 +771,43 @@ host:
 
 More advanced testing can be done with the prn_example
 described in Documentation/usb/gadget-printer.txt.
+
+
+20. UAC1 function (new API, using u_audio)
+=
+
+The function is provided by usb_f_uac1_newapi.ko module.
+
+Function-specific configfs interface
+
+
+The function name to use when creating the function directory
+is "uac1_newapi". The uac1_newapi function provides these attributes
+in its function directory:
+
+   c_chmask - capture channel mask
+   c_srate - capture sampling rate
+   c_ssize - capture sample size (bytes)
+   p_chmask - playback channel mask
+   p_srate - playback sampling rate
+   p_ssize - playback sample size (bytes)
+
+The attributes have sane default values.
+
+Testing the UAC1 function
+-
+
+device: run the gadget
+host: aplay -l # should list our USB Audio Gadget
+
+This function does not require real hardware support, it just
+sends a stream of audio data to/from the host. In order to
+actually hear something at the device side, a command similar
+to this must be used at the device side:
+
+$ arecord -f dat -t wav -D hw:2,0 | aplay -D hw:0,0 &
+
+e.g.:
+
+$ arecord -f dat -t wav -D hw:CARD=UAC1Gadget,DEV=0 | \
+aplay -D default:CARD=OdroidU3
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index a25afd8..abcb539 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -194,6 +194,9 @@ config USB_F_FS
 config USB_F_UAC1
tristate
 
+config USB_F_UAC1_NEWAPI
+   tristate
+
 config USB_F_UAC2
tristate
 
@@ -397,6 +400,24 @@ config USB_CONFIGFS_F_UAC1
  This driver requires a real Audio codec to be present
  on the device.
 
+config USB_CONFIGFS_F_UAC1_NEWAPI
+   bool "Audio Class 1.0 (new API)"
+   depends on USB_CONFIGFS
+   depends on SND
+   select USB_LIBCOMPOSITE
+   select SND_PCM
+   select USB_U_AUDIO
+   select USB_F_UAC1_NEWAPI
+   help
+ 

[PATCH v3 1/3] usb: gadget: f_uac2: remove platform driver/device creation

2016-08-17 Thread Ruslan Bilovol
Simplify f_uac2 by removing platform driver/device
creation; use composite's usb_gadget device as
parent for sound card and for debug prints.
This removes extra layer of code without any functional
change.

Signed-off-by: Ruslan Bilovol 
---
 drivers/usb/gadget/function/f_uac2.c | 107 +--
 1 file changed, 28 insertions(+), 79 deletions(-)

diff --git a/drivers/usb/gadget/function/f_uac2.c 
b/drivers/usb/gadget/function/f_uac2.c
index cd214ec8..e14628c 100644
--- a/drivers/usb/gadget/function/f_uac2.c
+++ b/drivers/usb/gadget/function/f_uac2.c
@@ -13,7 +13,6 @@
 
 #include 
 #include 
-#include 
 #include 
 
 #include 
@@ -54,8 +53,6 @@
 #define UNFLW_CTRL 8
 #define OVFLW_CTRL 10
 
-static const char *uac2_name = "snd_uac2";
-
 struct uac2_req {
struct uac2_rtd_params *pp; /* parent param */
struct usb_request *req;
@@ -84,9 +81,6 @@ struct uac2_rtd_params {
 };
 
 struct snd_uac2_chip {
-   struct platform_device pdev;
-   struct platform_driver pdrv;
-
struct uac2_rtd_params p_prm;
struct uac2_rtd_params c_prm;
 
@@ -125,6 +119,7 @@ struct audio_dev {
 
struct usb_ep *in_ep, *out_ep;
struct usb_function func;
+   struct usb_gadget *gadget;
 
/* The ALSA Sound Card it represents on the USB-Client side */
struct snd_uac2_chip uac2;
@@ -143,12 +138,6 @@ struct audio_dev *uac2_to_agdev(struct snd_uac2_chip *u)
 }
 
 static inline
-struct snd_uac2_chip *pdev_to_uac2(struct platform_device *p)
-{
-   return container_of(p, struct snd_uac2_chip, pdev);
-}
-
-static inline
 struct f_uac2_opts *agdev_to_uac2_opts(struct audio_dev *agdev)
 {
return container_of(agdev->func.fi, struct f_uac2_opts, func_inst);
@@ -257,7 +246,7 @@ agdev_iso_complete(struct usb_ep *ep, struct usb_request 
*req)
 
 exit:
if (usb_ep_queue(ep, req, GFP_ATOMIC))
-   dev_err(>pdev.dev, "%d Error!\n", __LINE__);
+   dev_err(uac2->card->dev, "%d Error!\n", __LINE__);
 
if (update_alsa)
snd_pcm_period_elapsed(substream);
@@ -441,23 +430,22 @@ static struct snd_pcm_ops uac2_pcm_ops = {
.prepare = uac2_pcm_null,
 };
 
-static int snd_uac2_probe(struct platform_device *pdev)
+static int snd_uac2_probe(struct audio_dev *audio_dev)
 {
-   struct snd_uac2_chip *uac2 = pdev_to_uac2(pdev);
+   struct snd_uac2_chip *uac2 = _dev->uac2;
struct snd_card *card;
struct snd_pcm *pcm;
-   struct audio_dev *audio_dev;
struct f_uac2_opts *opts;
int err;
int p_chmask, c_chmask;
 
-   audio_dev = uac2_to_agdev(uac2);
opts = container_of(audio_dev->func.fi, struct f_uac2_opts, func_inst);
p_chmask = opts->p_chmask;
c_chmask = opts->c_chmask;
 
/* Choose any slot, with no id */
-   err = snd_card_new(>dev, -1, NULL, THIS_MODULE, 0, );
+   err = snd_card_new(_dev->gadget->dev,
+   -1, NULL, THIS_MODULE, 0, );
if (err < 0)
return err;
 
@@ -482,16 +470,15 @@ static int snd_uac2_probe(struct platform_device *pdev)
 
strcpy(card->driver, "UAC2_Gadget");
strcpy(card->shortname, "UAC2_Gadget");
-   sprintf(card->longname, "UAC2_Gadget %i", pdev->id);
+   sprintf(card->longname, "UAC2_Gadget %i", card->dev->id);
 
snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
snd_dma_continuous_data(GFP_KERNEL), 0, BUFF_SIZE_MAX);
 
err = snd_card_register(card);
-   if (!err) {
-   platform_set_drvdata(pdev, card);
+
+   if (!err)
return 0;
-   }
 
 snd_fail:
snd_card_free(card);
@@ -502,9 +489,9 @@ snd_fail:
return err;
 }
 
-static int snd_uac2_remove(struct platform_device *pdev)
+static int snd_uac2_remove(struct audio_dev *audio_dev)
 {
-   struct snd_card *card = platform_get_drvdata(pdev);
+   struct snd_card *card = audio_dev->uac2.card;
 
if (card)
return snd_card_free(card);
@@ -512,45 +499,6 @@ static int snd_uac2_remove(struct platform_device *pdev)
return 0;
 }
 
-static void snd_uac2_release(struct device *dev)
-{
-   dev_dbg(dev, "releasing '%s'\n", dev_name(dev));
-}
-
-static int alsa_uac2_init(struct audio_dev *agdev)
-{
-   struct snd_uac2_chip *uac2 = >uac2;
-   int err;
-
-   uac2->pdrv.probe = snd_uac2_probe;
-   uac2->pdrv.remove = snd_uac2_remove;
-   uac2->pdrv.driver.name = uac2_name;
-
-   uac2->pdev.id = 0;
-   uac2->pdev.name = uac2_name;
-   uac2->pdev.dev.release = snd_uac2_release;
-
-   /* Register snd_uac2 driver */
-   err = platform_driver_register(>pdrv);
-   if (err)
-   return err;
-
-   /* Register snd_uac2 device */
-   err = platform_device_register(>pdev);
-   if (err)
-   platform_driver_unregister(>pdrv);
-
-   return err;
-}
-

[PATCH v3 2/3] usb: gadget: f_uac2: split out audio core

2016-08-17 Thread Ruslan Bilovol
Abstract the peripheral side ALSA sound card code from
the f_uac2 function into a component that can be called
by various functions, so the various flavors can be split
apart and selectively reused.

Visible changes:
 - add uac_params structure to pass audio paramteres for
   g_audio_setup
 - make ALSA sound card's name configurable
 - add [in/out]_ep_maxpsize
 - allocate snd_uac_chip structure during g_audio_setup
 - add u_audio_[start/stop]_[capture/playback] functions

Signed-off-by: Ruslan Bilovol 
---
 drivers/usb/gadget/Kconfig|   4 +
 drivers/usb/gadget/function/Makefile  |   1 +
 drivers/usb/gadget/function/f_uac2.c  | 699 --
 drivers/usb/gadget/function/u_audio.c | 632 ++
 drivers/usb/gadget/function/u_audio.h |  93 +
 drivers/usb/gadget/legacy/Kconfig |   1 +
 6 files changed, 813 insertions(+), 617 deletions(-)
 create mode 100644 drivers/usb/gadget/function/u_audio.c
 create mode 100644 drivers/usb/gadget/function/u_audio.h

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 3c3f31c..a25afd8 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -158,6 +158,9 @@ config USB_U_SERIAL
 config USB_U_ETHER
tristate
 
+config USB_U_AUDIO
+   tristate
+
 config USB_F_SERIAL
tristate
 
@@ -400,6 +403,7 @@ config USB_CONFIGFS_F_UAC2
depends on SND
select USB_LIBCOMPOSITE
select SND_PCM
+   select USB_U_AUDIO
select USB_F_UAC2
help
  This Audio function is compatible with USB Audio Class
diff --git a/drivers/usb/gadget/function/Makefile 
b/drivers/usb/gadget/function/Makefile
index cb8c225..b29f2ae 100644
--- a/drivers/usb/gadget/function/Makefile
+++ b/drivers/usb/gadget/function/Makefile
@@ -32,6 +32,7 @@ usb_f_mass_storage-y  := f_mass_storage.o 
storage_common.o
 obj-$(CONFIG_USB_F_MASS_STORAGE)+= usb_f_mass_storage.o
 usb_f_fs-y := f_fs.o
 obj-$(CONFIG_USB_F_FS) += usb_f_fs.o
+obj-$(CONFIG_USB_U_AUDIO)  += u_audio.o
 usb_f_uac1-y   := f_uac1.o u_uac1.o
 obj-$(CONFIG_USB_F_UAC1)   += usb_f_uac1.o
 usb_f_uac2-y   := f_uac2.o
diff --git a/drivers/usb/gadget/function/f_uac2.c 
b/drivers/usb/gadget/function/f_uac2.c
index e14628c..ef8e976 100644
--- a/drivers/usb/gadget/function/f_uac2.c
+++ b/drivers/usb/gadget/function/f_uac2.c
@@ -15,15 +15,9 @@
 #include 
 #include 
 
-#include 
-#include 
-#include 
-
+#include "u_audio.h"
 #include "u_uac2.h"
 
-/* Keep everyone on toes */
-#define USB_XFERS  2
-
 /*
  * The driver implements a simple UAC_2 topology.
  * USB-OUT -> IT_1 -> OT_3 -> ALSA_Capture
@@ -53,453 +47,23 @@
 #define UNFLW_CTRL 8
 #define OVFLW_CTRL 10
 
-struct uac2_req {
-   struct uac2_rtd_params *pp; /* parent param */
-   struct usb_request *req;
-};
-
-struct uac2_rtd_params {
-   struct snd_uac2_chip *uac2; /* parent chip */
-   bool ep_enabled; /* if the ep is enabled */
-   /* Size of the ring buffer */
-   size_t dma_bytes;
-   unsigned char *dma_area;
-
-   struct snd_pcm_substream *ss;
-
-   /* Ring buffer */
-   ssize_t hw_ptr;
-
-   void *rbuf;
-
-   size_t period_size;
-
-   unsigned max_psize;
-   struct uac2_req ureq[USB_XFERS];
-
-   spinlock_t lock;
-};
-
-struct snd_uac2_chip {
-   struct uac2_rtd_params p_prm;
-   struct uac2_rtd_params c_prm;
-
-   struct snd_card *card;
-   struct snd_pcm *pcm;
-
-   /* timekeeping for the playback endpoint */
-   unsigned int p_interval;
-   unsigned int p_residue;
-
-   /* pre-calculated values for playback iso completion */
-   unsigned int p_pktsize;
-   unsigned int p_pktsize_residue;
-   unsigned int p_framesize;
-};
-
-#define BUFF_SIZE_MAX  (PAGE_SIZE * 16)
-#define PRD_SIZE_MAX   PAGE_SIZE
-#define MIN_PERIODS4
-
-static struct snd_pcm_hardware uac2_pcm_hardware = {
-   .info = SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER
-| SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID
-| SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME,
-   .rates = SNDRV_PCM_RATE_CONTINUOUS,
-   .periods_max = BUFF_SIZE_MAX / PRD_SIZE_MAX,
-   .buffer_bytes_max = BUFF_SIZE_MAX,
-   .period_bytes_max = PRD_SIZE_MAX,
-   .periods_min = MIN_PERIODS,
-};
-
-struct audio_dev {
-   u8 ac_intf, ac_alt;
-   u8 as_out_intf, as_out_alt;
-   u8 as_in_intf, as_in_alt;
-
-   struct usb_ep *in_ep, *out_ep;
-   struct usb_function func;
-   struct usb_gadget *gadget;
-
-   /* The ALSA Sound Card it represents on the USB-Client side */
-   struct snd_uac2_chip uac2;
+struct f_uac2 {
+   struct g_audio g_audio;
+   u8 ac_intf, as_in_intf, as_out_intf;
+   u8 ac_alt, as_in_alt, as_out_alt;   /* needed for get_alt() */
 };
 
-static inline
-struct 

Re: [PATCH 07/10] docs: sphinxify ubsan.txt and move it to dev-tools

2016-08-17 Thread Andrey Ryabinin


On 08/09/2016 02:34 AM, Jonathan Corbet wrote:
> Cc: Andrey Ryabinin 
> Signed-off-by: Jonathan Corbet 
> ---

Acked-by: Andrey Ryabinin 

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] Fix /proc/stat freezes (was [PATCH v15] "task_isolation" mode)

2016-08-17 Thread Christoph Lameter
On Tue, 16 Aug 2016, Chris Metcalf wrote:

> - Dropped Christoph Lameter's patch to avoid scheduling the
>   clocksource watchdog on nohz cores; the recommendation is to just
>   boot with tsc=reliable for NOHZ in any case, if necessary.

We also said that there should be a WARN_ON if tsc=reliable is not
specified and processors are put into NOHZ mode. This is something not
obvious causing scheduling events on NOHZ processors.


> Frederic, do you have a sense of what is left to be done there?
> I can certainly try to contribute to that effort as well.

Here is a potential fix to the problem that /proc/stat values freeze when
processors go into NOHZ busy mode. I'd like to hear what people think
about the approach here. In particular one issue may be that I am
accessing remote tick-sched structures without serialization. But for
top/ps this may be ok. I noticed that other values shown by top/os also
sometime are a bit fuzzy.



Subject: NOHZ: Correctly display increasing cputime when processor is busy

The tick may be switched off when the processor gets busy with nohz full.
The user time fields in /proc/stat will then no longer increase because
the tick is not run to update the cpustat values anymore.

Compensate for the missing ticks by checking if a processor is in
such a mode. If so then add the ticks that have passed since
the tick was switched off to the usertime.

Note that this introduces a slight inaccuracy. The process may
actually do syscalls without triggering a tick again but the
processing time in those calls is negligible. Any wait or sleep
occurrence during syscalls would activate the tick again.

Any inaccuracy is corrected once the tick is switched on again
since the actual value where cputime aggregates is not changed.

Signed-off-by: Christoph Lameter 

Index: linux/fs/proc/stat.c
===
--- linux.orig/fs/proc/stat.c   2016-08-04 09:04:57.681480937 -0500
+++ linux/fs/proc/stat.c2016-08-17 14:27:37.813445675 -0500
@@ -77,6 +77,12 @@ static u64 get_iowait_time(int cpu)

 #endif

+static unsigned long inline get_cputime_user(int cpu)
+{
+   return kcpustat_cpu(cpu).cpustat[CPUTIME_USER] +
+   tick_stopped_busy_ticks(cpu);
+}
+
 static int show_stat(struct seq_file *p, void *v)
 {
int i, j;
@@ -93,7 +99,7 @@ static int show_stat(struct seq_file *p,
getboottime64();

for_each_possible_cpu(i) {
-   user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
+   user += get_cputime_user(i);
nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
idle += get_idle_time(i);
@@ -130,7 +136,7 @@ static int show_stat(struct seq_file *p,

for_each_online_cpu(i) {
/* Copy values here to work around gcc-2.95.3, gcc-2.96 */
-   user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
+   user = get_cputime_user(i);
nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
idle = get_idle_time(i);
Index: linux/kernel/time/tick-sched.c
===
--- linux.orig/kernel/time/tick-sched.c 2016-07-27 08:41:17.109862517 -0500
+++ linux/kernel/time/tick-sched.c  2016-08-17 14:16:42.073835333 -0500
@@ -990,6 +990,24 @@ ktime_t tick_nohz_get_sleep_length(void)
return ts->sleep_length;
 }

+/**
+ * tick_stopped_busy_ticks - return the ticks that did not occur while the
+ * processor was busy and the tick was off
+ *
+ * Called from sysfs to correctly calculate cputime of nohz full processors
+ */
+unsigned long tick_stopped_busy_ticks(int cpu)
+{
+#ifdef CONFIG_NOHZ_FULL
+   struct tick_sched *ts = per_cpu_ptr(_cpu_sched, cpu);
+
+   if (!ts->inidle && ts->tick_stopped)
+   return jiffies - ts->idle_jiffies;
+   else
+#endif
+   return 0;
+}
+
 static void tick_nohz_account_idle_ticks(struct tick_sched *ts)
 {
 #ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
Index: linux/include/linux/sched.h
===
--- linux.orig/include/linux/sched.h2016-08-04 09:04:57.688480730 -0500
+++ linux/include/linux/sched.h 2016-08-17 14:18:30.983613830 -0500
@@ -2516,6 +2516,9 @@ static inline void wake_up_nohz_cpu(int

 #ifdef CONFIG_NO_HZ_FULL
 extern u64 scheduler_tick_max_deferment(void);
+extern unsigned long tick_stopped_busy_ticks(int cpu);
+#else
+static inline unsigned long tick_stopped_busy_ticks(int cpu) { return 0; }
 #endif

 #ifdef CONFIG_SCHED_AUTOGROUP
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PACTH v2 0/3] Implement /proc//totmaps

2016-08-17 Thread Sonny Rao
On Wed, Aug 17, 2016 at 6:03 AM, Michal Hocko  wrote:
> On Wed 17-08-16 11:31:25, Jann Horn wrote:
>> On Wed, Aug 17, 2016 at 10:22:00AM +0200, Michal Hocko wrote:
>> > On Tue 16-08-16 12:46:51, Robert Foss wrote:
>> > [...]
>> > > $ /usr/bin/time -v -p zsh -c "repeat 25 { awk '/^Rss/{rss+=\$2}
>> > > /^Pss/{pss+=\$2} END {printf \"rss:%d pss:%d\n\", rss, pss}\'
>> > > /proc/5025/smaps }"
>> > > [...]
>> > >   Command being timed: "zsh -c repeat 25 { awk '/^Rss/{rss+=$2}
>> > > /^Pss/{pss+=$2} END {printf "rss:%d pss:%d\n", rss, pss}\' 
>> > > /proc/5025/smaps
>> > > }"
>> > >   User time (seconds): 0.37
>> > >   System time (seconds): 0.45
>> > >   Percent of CPU this job got: 92%
>> > >   Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.89
>> >
>> > This is really unexpected. Where is the user time spent? Anyway, rather
>> > than measuring some random processes I've tried to measure something
>> > resembling the worst case. So I've created a simple program to mmap as
>> > much as possible:
>> >
>> > #include 
>> > #include 
>> > #include 
>> > #include 
>> > int main()
>> > {
>> > while (mmap(NULL, 4096, PROT_READ|PROT_WRITE, 
>> > MAP_ANON|MAP_SHARED|MAP_POPULATE, -1, 0) != MAP_FAILED)
>> > ;
>> >
>> > printf("pid:%d\n", getpid());
>> > pause();
>> > return 0;
>> > }
>>
>> Ah, nice, that's a reasonable test program. :)
>>
>>
>> > So with a reasonable user space the parsing is really not all that time
>> > consuming wrt. smaps handling. That being said I am still very skeptical
>> > about a dedicated proc file which accomplishes what userspace can done
>> > in a trivial way.
>>
>> Now, since your numbers showed that all the time is spent in the kernel,
>> also create this test program to just read that file over and over again:
>>
>> $ cat justreadloop.c
>> #include 
>> #include 
>> #include 
>> #include 
>> #include 
>> #include 
>> #include 
>>
>> char buf[100];
>>
>> int main(int argc, char **argv) {
>>   printf("pid:%d\n", getpid());
>>   while (1) {
>> int fd = open(argv[1], O_RDONLY);
>> if (fd < 0) continue;
>> if (read(fd, buf, sizeof(buf)) < 0)
>>   err(1, "read");
>> close(fd);
>>   }
>> }
>> $ gcc -Wall -o justreadloop justreadloop.c
>> $
>>
>> Now launch your test:
>>
>> $ ./mapstuff
>> pid:29397
>>
>> point justreadloop at it:
>>
>> $ ./justreadloop /proc/29397/smaps
>> pid:32567
>>
>> ... and then check the performance stats of justreadloop:
>>
>> # perf top -p 32567
>>
>> This is what I see:
>>
>> Samples: 232K of event 'cycles:ppp', Event count (approx.): 60448424325
>> Overhead  Shared Object Symbol
>>   30,43%  [kernel]  [k] format_decode
>>9,12%  [kernel]  [k] number
>>7,66%  [kernel]  [k] vsnprintf
>>7,06%  [kernel]  [k] __lock_acquire
>>3,23%  [kernel]  [k] lock_release
>>2,85%  [kernel]  [k] debug_lockdep_rcu_enabled
>>2,25%  [kernel]  [k] skip_atoi
>>2,13%  [kernel]  [k] lock_acquire
>>2,05%  [kernel]  [k] show_smap
>
> This is a lot! I would expect the rmap walk to consume more but it even
> doesn't show up in the top consumers.
>
>> That's at least 30.43% + 9.12% + 7.66% = 47.21% of the task's kernel
>> time spent on evaluating format strings. The new interface
>> wouldn't have to spend that much time on format strings because there
>> isn't so much text to format.
>
> well, this is true of course but I would much rather try to reduce the
> overhead of smaps file than add a new file. The following should help
> already. I've measured ~7% systime cut down. I guess there is still some
> room for improvements but I have to say I'm far from being convinced about
> a new proc file just because we suck at dumping information to the
> userspace.
> If this was something like /proc//stat which is
> essentially read all the time then it would be a different question but
> is the rss, pss going to be all that often? If yes why?

If the question is why do we need to read RSS, PSS, Private_*, Swap
and the other fields so often?

I have two use cases so far involving monitoring per-process memory
usage, and we usually need to read stats for about 25 processes.

Here's a timing example on an fairly recent ARM system 4 core RK3288
running at 1.8Ghz

localhost ~ # time cat /proc/25946/smaps > /dev/null

real0m0.036s
user0m0.020s
sys 0m0.020s

localhost ~ # time cat /proc/25946/totmaps > /dev/null

real0m0.027s
user0m0.010s
sys 0m0.010s
localhost ~ #

I'll ignore the user time for now, and we see about 20 ms of system
time with smaps and 10 ms with totmaps, with 20 similar processes it
would be 400 milliseconds of cpu time for the kernel to get this
information from smaps vs 200 milliseconds with totmaps.  Even totmaps
is still pretty slow, but much better than smaps.

Use cases:
1) Basic task monitoring -- like "top" that shows memory consumption
including PSS, Private, Swap
1 second update 

Re: [PATCH] mm, kasan: Update kasan docs to indicate arm64 support

2016-08-17 Thread Andrey Ryabinin


On 08/16/2016 07:30 PM, Laura Abbott wrote:
> KASAN has been supported on arm64 since 39d114ddc682 ("arm64: add KASAN
> support"). Update the docs to indicate this.
> 
> Signed-off-by: Laura Abbott 

Acked-by: Andrey Ryabinin 

> ---
>  Documentation/kasan.txt | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/Documentation/kasan.txt b/Documentation/kasan.txt
> index 7dd95b3..d167220 100644
> --- a/Documentation/kasan.txt
> +++ b/Documentation/kasan.txt
> @@ -12,7 +12,7 @@ KASAN uses compile-time instrumentation for checking every 
> memory access,
>  therefore you will need a GCC version 4.9.2 or later. GCC 5.0 or later is
>  required for detection of out-of-bounds accesses to stack or global 
> variables.
>  
> -Currently KASAN is supported only for x86_64 architecture.
> +Currently KASAN is supported only for x86_64 and arm64 architecture.
>  
>  1. Usage
>  
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC2 nowrap: PATCH v7 00/18] ILP32 for ARM64

2016-08-17 Thread Dr. Philipp Tomsich

> On 17 Aug 2016, at 16:29, Catalin Marinas  wrote:
> 
> On Wed, Aug 17, 2016 at 02:54:59PM +0200, Dr. Philipp Tomsich wrote:
>> On 17 Aug 2016, at 14:48, Yury Norov  wrote:
>>> On Wed, Aug 17, 2016 at 02:28:50PM +0200, Alexander Graf wrote:
 On 17 Aug 2016, at 13:46, Yury Norov  wrote:
> This series enables aarch64 with ilp32 mode, and as supporting work,
> introduces ARCH_32BIT_OFF_T configuration option that is enabled for
> existing 32-bit architectures but disabled for new arches (so 64-bit
> off_t is is used by new userspace).
> 
> This version is based on kernel v4.8-rc2.
> It works with glibc-2.23, and tested with LTP.
> 
> This is RFC because there is still no solid understanding what type of 
> registers
> top-halves delousing we prefer. In this patchset, w0-w7 are cleared for 
> each
> syscall in assembler entry. The alternative approach is in introducing 
> compat
> wrappers which is little faster for natively routed syscalls (~2.6% for 
> syscall
> with no payload) but much more complicated.
 
 So you’re saying there are 2 options:
 
 1) easy to get right, slightly slower, same ABI to user space as 2
 2) harder to get right, minor performance benefit
>>> 
>>> No, ABI is little different. If 1) we pass off_t in a pair to syscalls,
>>> if 2) - in a single register. So if 1, we 'd take some wrappers from 
>>> aarch32.
>>> See patch 12 here.
>> 
>> From our experience with ILP32, I’d prefer to have off_t (and similar)
>> in a single register whenever possible (i.e. option #2).  It feels
>> more natural to use the full 64bit registers whenever possible, as
>> ILP32 on ARMv8 should really be understood as a 64bit ABI with a 32bit
>> memory model.
> 
> I think we are well past the point where we considered ILP32 a 64-bit
> ABI. It would have been nice but we decided that breaking POSIX
> compatibility is a bad idea, so we went back (again) to a 32-bit ABI for
> ILP32. While there are 64-bit arguments that, at a first look, would
> make sense to be passed in 64-bit registers, the kernel maintenance cost
> is significant with changes to generic files.
> 
> Allowing 64-bit wide registers at the ILP32 syscall interface means that
> the kernel would have to zero/sign-extend the upper half of the 32-bit
> arguments for the cases where they are passed directly to a native
> syscall that expects a 64-bit argument. This (a) adds a significant
> number of wrappers to the generic code together additional annotations
> to the generic unistd.h and (b) it adds a small overhead to the AArch32
> (compat) ABI since it doesn't need such generic wrapping (the upper half
> of 64-bit registers is guaranteed to be zero/preserved by the
> architecture when coming from the AArch32 mode).

Yes, I remember the discussions and just wanted to put option #2 in context 
again.
Everything points to just going with the pair-of-registers and getting this 
merged 
quickly then, I suppose.

Cheers,
Philipp.--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC2 nowrap: PATCH v7 00/18] ILP32 for ARM64

2016-08-17 Thread Catalin Marinas
On Wed, Aug 17, 2016 at 02:54:59PM +0200, Dr. Philipp Tomsich wrote:
> On 17 Aug 2016, at 14:48, Yury Norov  wrote:
> > On Wed, Aug 17, 2016 at 02:28:50PM +0200, Alexander Graf wrote:
> >> On 17 Aug 2016, at 13:46, Yury Norov  wrote:
> >>> This series enables aarch64 with ilp32 mode, and as supporting work,
> >>> introduces ARCH_32BIT_OFF_T configuration option that is enabled for
> >>> existing 32-bit architectures but disabled for new arches (so 64-bit
> >>> off_t is is used by new userspace).
> >>> 
> >>> This version is based on kernel v4.8-rc2.
> >>> It works with glibc-2.23, and tested with LTP.
> >>> 
> >>> This is RFC because there is still no solid understanding what type of 
> >>> registers
> >>> top-halves delousing we prefer. In this patchset, w0-w7 are cleared for 
> >>> each
> >>> syscall in assembler entry. The alternative approach is in introducing 
> >>> compat
> >>> wrappers which is little faster for natively routed syscalls (~2.6% for 
> >>> syscall
> >>> with no payload) but much more complicated.
> >> 
> >> So you’re saying there are 2 options:
> >> 
> >>  1) easy to get right, slightly slower, same ABI to user space as 2
> >>  2) harder to get right, minor performance benefit
> > 
> > No, ABI is little different. If 1) we pass off_t in a pair to syscalls,
> > if 2) - in a single register. So if 1, we 'd take some wrappers from 
> > aarch32.
> > See patch 12 here.
> 
> From our experience with ILP32, I’d prefer to have off_t (and similar)
> in a single register whenever possible (i.e. option #2).  It feels
> more natural to use the full 64bit registers whenever possible, as
> ILP32 on ARMv8 should really be understood as a 64bit ABI with a 32bit
> memory model.

I think we are well past the point where we considered ILP32 a 64-bit
ABI. It would have been nice but we decided that breaking POSIX
compatibility is a bad idea, so we went back (again) to a 32-bit ABI for
ILP32. While there are 64-bit arguments that, at a first look, would
make sense to be passed in 64-bit registers, the kernel maintenance cost
is significant with changes to generic files.

Allowing 64-bit wide registers at the ILP32 syscall interface means that
the kernel would have to zero/sign-extend the upper half of the 32-bit
arguments for the cases where they are passed directly to a native
syscall that expects a 64-bit argument. This (a) adds a significant
number of wrappers to the generic code together additional annotations
to the generic unistd.h and (b) it adds a small overhead to the AArch32
(compat) ABI since it doesn't need such generic wrapping (the upper half
of 64-bit registers is guaranteed to be zero/preserved by the
architecture when coming from the AArch32 mode).

-- 
Catalin
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 17/18] arm64:ilp32: add vdso-ilp32 and use for signal return

2016-08-17 Thread Andreas Schwab
On Aug 17 2016, Yury Norov  wrote:

> diff --git a/arch/arm64/kernel/vdso/gettimeofday.S 
> b/arch/arm64/kernel/vdso/gettimeofday.S
> index e00b467..143b39e 100644
> --- a/arch/arm64/kernel/vdso/gettimeofday.S
> +++ b/arch/arm64/kernel/vdso/gettimeofday.S
> @@ -25,6 +25,16 @@
>  #define NSEC_PER_SEC_LO160xca00
>  #define NSEC_PER_SEC_HI160x3b9a
>  
> +#ifdef __LP64__
> +#define PTR_REG(n)   x##n
> +#define OFFSET(n)n
> +#define DELOUSE(n)
> +#else
> +#define PTR_REG(n)   w##n
> +#define OFFSET(n)COMPAT_##n
> +#define DELOUSE(n)   mov w##n, w##n
> +#endif
> +
>  vdso_data.reqx6
>  seqcnt   .reqw7
>  w_tmp.reqw8
> @@ -136,6 +146,8 @@ x_tmp .reqx8
>  /* int __kernel_gettimeofday(struct timeval *tv, struct timezone *tz); */
>  ENTRY(__kernel_gettimeofday)
>   .cfi_startproc
> + DELOUSE(0)
> + DELOUSE(1)
>   adr vdso_data, _vdso_data
>   /* If tv is NULL, skip to the timezone code. */
>   cbz x0, 2f
> @@ -160,7 +172,7 @@ ENTRY(__kernel_gettimeofday)
>   mov x13, #1000
>   lsl x13, x13, x12
>   udivx11, x11, x13
> - stp x10, x11, [x0, #TVAL_TV_SEC]
> + stp PTR_REG(10), PTR_REG(11), [x0, #OFFSET(TVAL_TV_SEC)]
>  2:
>   /* If tz is NULL, return 0. */
>   cbz x1, 3f
> @@ -182,6 +194,7 @@ ENDPROC(__kernel_gettimeofday)
>  /* int __kernel_clock_gettime(clockid_t clock_id, struct timespec *tp); */
>  ENTRY(__kernel_clock_gettime)
>   .cfi_startproc
> + DELOUSE(1)
>   cmp w0, #JUMPSLOT_MAX
>   b.hisyscall
>   adr vdso_data, _vdso_data
> @@ -297,6 +310,7 @@ ENDPROC(__kernel_clock_gettime)
>  /* int __kernel_clock_getres(clockid_t clock_id, struct timespec *res); */
>  ENTRY(__kernel_clock_getres)
>   .cfi_startproc
> + DELOUSE(1)
>   cmp w0, #CLOCK_REALTIME
>   ccmpw0, #CLOCK_MONOTONIC, #0x4, ne
>   ccmpw0, #CLOCK_MONOTONIC_RAW, #0x4, ne
> @@ -311,7 +325,7 @@ ENTRY(__kernel_clock_getres)
>   ldr x2, 6f
>  2:
>   cbz w1, 3f
> - stp xzr, x2, [x1]
> + stp PTR_REG(zr), PTR_REG(2), [x1]
>  
>  3:   /* res == NULL. */
>   mov w0, wzr

I think this is missing:

diff --git a/arch/arm64/kernel/vdso/gettimeofday.S 
b/arch/arm64/kernel/vdso/gettimeofday.S
index 143b39e..b463c5a 100644
--- a/arch/arm64/kernel/vdso/gettimeofday.S
+++ b/arch/arm64/kernel/vdso/gettimeofday.S
@@ -129,7 +129,7 @@ x_tmp   .reqx8
.if \shift == 1
lsr x11, x11, x12
.endif
-   stp x10, x11, [x1, #TSPEC_TV_SEC]
+   stp PTR_REG(10), PTR_REG(11), [x1, #OFFSET(TSPEC_TV_SEC)]
mov x0, xzr
ret
.endm
-- 
2.9.3


Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC2 nowrap: PATCH v7 00/18] ILP32 for ARM64

2016-08-17 Thread Dr. Philipp Tomsich

> On 17 Aug 2016, at 14:48, Yury Norov  wrote:
> 
> On Wed, Aug 17, 2016 at 02:28:50PM +0200, Alexander Graf wrote:
>> 
>>> On 17 Aug 2016, at 13:46, Yury Norov  wrote:
>>> 
>>> This series enables aarch64 with ilp32 mode, and as supporting work,
>>> introduces ARCH_32BIT_OFF_T configuration option that is enabled for
>>> existing 32-bit architectures but disabled for new arches (so 64-bit
>>> off_t is is used by new userspace).
>>> 
>>> This version is based on kernel v4.8-rc2.
>>> It works with glibc-2.23, and tested with LTP.
>>> 
>>> This is RFC because there is still no solid understanding what type of 
>>> registers
>>> top-halves delousing we prefer. In this patchset, w0-w7 are cleared for each
>>> syscall in assembler entry. The alternative approach is in introducing 
>>> compat
>>> wrappers which is little faster for natively routed syscalls (~2.6% for 
>>> syscall
>>> with no payload) but much more complicated.
>> 
>> So you’re saying there are 2 options:
>> 
>>  1) easy to get right, slightly slower, same ABI to user space as 2
>>  2) harder to get right, minor performance benefit
> 
> No, ABI is little different. If 1) we pass off_t in a pair to syscalls,
> if 2) - in a single register. So if 1, we 'd take some wrappers from aarch32.
> See patch 12 here.

>From our experience with ILP32, I’d prefer to have off_t (and similar) in a 
>single register
whenever possible (i.e. option #2).  It feels more natural to use the full 
64bit registers 
whenever possible, as ILP32 on ARMv8 should really be understood as a 64bit ABI 
with 
a 32bit memory model.

Cheers,
Philipp.--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PACTH v2 0/3] Implement /proc//totmaps

2016-08-17 Thread Michal Hocko
On Wed 17-08-16 11:31:25, Jann Horn wrote:
> On Wed, Aug 17, 2016 at 10:22:00AM +0200, Michal Hocko wrote:
> > On Tue 16-08-16 12:46:51, Robert Foss wrote:
> > [...]
> > > $ /usr/bin/time -v -p zsh -c "repeat 25 { awk '/^Rss/{rss+=\$2}
> > > /^Pss/{pss+=\$2} END {printf \"rss:%d pss:%d\n\", rss, pss}\'
> > > /proc/5025/smaps }"
> > > [...]
> > >   Command being timed: "zsh -c repeat 25 { awk '/^Rss/{rss+=$2}
> > > /^Pss/{pss+=$2} END {printf "rss:%d pss:%d\n", rss, pss}\' 
> > > /proc/5025/smaps
> > > }"
> > >   User time (seconds): 0.37
> > >   System time (seconds): 0.45
> > >   Percent of CPU this job got: 92%
> > >   Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.89
> > 
> > This is really unexpected. Where is the user time spent? Anyway, rather
> > than measuring some random processes I've tried to measure something
> > resembling the worst case. So I've created a simple program to mmap as
> > much as possible:
> > 
> > #include 
> > #include 
> > #include 
> > #include 
> > int main()
> > {
> > while (mmap(NULL, 4096, PROT_READ|PROT_WRITE, 
> > MAP_ANON|MAP_SHARED|MAP_POPULATE, -1, 0) != MAP_FAILED)
> > ;
> > 
> > printf("pid:%d\n", getpid());
> > pause();
> > return 0;
> > }
> 
> Ah, nice, that's a reasonable test program. :)
> 
> 
> > So with a reasonable user space the parsing is really not all that time
> > consuming wrt. smaps handling. That being said I am still very skeptical
> > about a dedicated proc file which accomplishes what userspace can done
> > in a trivial way.
> 
> Now, since your numbers showed that all the time is spent in the kernel,
> also create this test program to just read that file over and over again:
> 
> $ cat justreadloop.c
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> 
> char buf[100];
> 
> int main(int argc, char **argv) {
>   printf("pid:%d\n", getpid());
>   while (1) {
> int fd = open(argv[1], O_RDONLY);
> if (fd < 0) continue;
> if (read(fd, buf, sizeof(buf)) < 0)
>   err(1, "read");
> close(fd);
>   }
> }
> $ gcc -Wall -o justreadloop justreadloop.c
> $ 
> 
> Now launch your test:
> 
> $ ./mapstuff 
> pid:29397
> 
> point justreadloop at it:
> 
> $ ./justreadloop /proc/29397/smaps
> pid:32567
> 
> ... and then check the performance stats of justreadloop:
> 
> # perf top -p 32567
> 
> This is what I see:
> 
> Samples: 232K of event 'cycles:ppp', Event count (approx.): 60448424325
> Overhead  Shared Object Symbol
>   30,43%  [kernel]  [k] format_decode
>9,12%  [kernel]  [k] number
>7,66%  [kernel]  [k] vsnprintf
>7,06%  [kernel]  [k] __lock_acquire
>3,23%  [kernel]  [k] lock_release
>2,85%  [kernel]  [k] debug_lockdep_rcu_enabled
>2,25%  [kernel]  [k] skip_atoi
>2,13%  [kernel]  [k] lock_acquire
>2,05%  [kernel]  [k] show_smap

This is a lot! I would expect the rmap walk to consume more but it even
doesn't show up in the top consumers.
 
> That's at least 30.43% + 9.12% + 7.66% = 47.21% of the task's kernel
> time spent on evaluating format strings. The new interface
> wouldn't have to spend that much time on format strings because there
> isn't so much text to format.

well, this is true of course but I would much rather try to reduce the
overhead of smaps file than add a new file. The following should help
already. I've measured ~7% systime cut down. I guess there is still some
room for improvements but I have to say I'm far from being convinced about
a new proc file just because we suck at dumping information to the
userspace. If this was something like /proc//stat which is
essentially read all the time then it would be a different question but
is the rss, pss going to be all that often? If yes why? These are the
questions which should be answered before we even start considering the
implementation.
---
>From 2a6883a7278ff8979808cb8e2dbcefe5ea3bf672 Mon Sep 17 00:00:00 2001
From: Michal Hocko 
Date: Wed, 17 Aug 2016 14:00:13 +0200
Subject: [PATCH] proc, smaps: reduce printing overhead

seq_printf (used by show_smap) can be pretty expensive when dumping a
lot of numbers.  Say we would like to get Rss and Pss from a particular
process.  In order to measure a pathological case let's generate as many
mappings as possible:

$ cat max_mmap.c
int main()
{
while (mmap(NULL, 4096, PROT_READ|PROT_WRITE, 
MAP_ANON|MAP_SHARED|MAP_POPULATE, -1, 0) != MAP_FAILED)
;

printf("pid:%d\n", getpid());
pause();
return 0;
}

$ awk '/^Rss/{rss+=$2} /^Pss/{pss+=$2} END {printf "rss:%d pss:%d\n", rss, 
pss}' /proc/$pid/smaps

would do a trick. The whole runtime is in the kernel space which is not
that that unexpected because smaps is not the cheapest one (we have to
do rmap walk etc.).

Command being timed: "awk /^Rss/{rss+=$2} /^Pss/{pss+=$2} END {printf 
"rss:%d pss:%d\n", rss, pss} /proc/3050/smaps"
User 

Re: [RFC2 nowrap: PATCH v7 00/18] ILP32 for ARM64

2016-08-17 Thread Yury Norov
On Wed, Aug 17, 2016 at 02:28:50PM +0200, Alexander Graf wrote:
> 
> > On 17 Aug 2016, at 13:46, Yury Norov  wrote:
> > 
> > This series enables aarch64 with ilp32 mode, and as supporting work,
> > introduces ARCH_32BIT_OFF_T configuration option that is enabled for
> > existing 32-bit architectures but disabled for new arches (so 64-bit
> > off_t is is used by new userspace).
> > 
> > This version is based on kernel v4.8-rc2.
> > It works with glibc-2.23, and tested with LTP.
> > 
> > This is RFC because there is still no solid understanding what type of 
> > registers
> > top-halves delousing we prefer. In this patchset, w0-w7 are cleared for each
> > syscall in assembler entry. The alternative approach is in introducing 
> > compat
> > wrappers which is little faster for natively routed syscalls (~2.6% for 
> > syscall
> > with no payload) but much more complicated.
> 
> So you’re saying there are 2 options:
> 
>   1) easy to get right, slightly slower, same ABI to user space as 2
>   2) harder to get right, minor performance benefit

No, ABI is little different. If 1) we pass off_t in a pair to syscalls,
if 2) - in a single register. So if 1, we 'd take some wrappers from aarch32.
See patch 12 here.

> That’s an obvious pick, no? Mark it non-RFC and stay with the clearing in 
> assembler entry. If anyone cares about those last few percent, they can still 
> push the harder path upstream later if they want to, but at least we’ll have 
> the ABI stable, so that you can start using and developing for ilp32 on 
> aarch64.
> 
> 
> Alex
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC2 nowrap: PATCH v7 00/18] ILP32 for ARM64

2016-08-17 Thread Alexander Graf

> On 17 Aug 2016, at 13:46, Yury Norov  wrote:
> 
> This series enables aarch64 with ilp32 mode, and as supporting work,
> introduces ARCH_32BIT_OFF_T configuration option that is enabled for
> existing 32-bit architectures but disabled for new arches (so 64-bit
> off_t is is used by new userspace).
> 
> This version is based on kernel v4.8-rc2.
> It works with glibc-2.23, and tested with LTP.
> 
> This is RFC because there is still no solid understanding what type of 
> registers
> top-halves delousing we prefer. In this patchset, w0-w7 are cleared for each
> syscall in assembler entry. The alternative approach is in introducing compat
> wrappers which is little faster for natively routed syscalls (~2.6% for 
> syscall
> with no payload) but much more complicated.

So you’re saying there are 2 options:

  1) easy to get right, slightly slower, same ABI to user space as 2
  2) harder to get right, minor performance benefit

That’s an obvious pick, no? Mark it non-RFC and stay with the clearing in 
assembler entry. If anyone cares about those last few percent, they can still 
push the harder path upstream later if they want to, but at least we’ll have 
the ABI stable, so that you can start using and developing for ilp32 on aarch64.


Alex

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 18/18] arm64:ilp32: add ARM64_ILP32 to Kconfig

2016-08-17 Thread Yury Norov
From: Andrew Pinski 

This patch adds the config option for ILP32.

Signed-off-by: Andrew Pinski 
Signed-off-by: Philipp Tomsich 
Signed-off-by: Christoph Muellner 
Signed-off-by: Yury Norov 
Reviewed-by: David Daney 
---
 arch/arm64/Kconfig | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 3d46250..e4042a9 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -991,7 +991,7 @@ source "fs/Kconfig.binfmt"
 
 config COMPAT
bool
-   depends on AARCH32_EL0
+   depends on AARCH32_EL0 || ARM64_ILP32
 
 config AARCH32_EL0
bool "Kernel support for 32-bit EL0"
@@ -1013,6 +1013,14 @@ config AARCH32_EL0
 
  If you want to execute 32-bit userspace applications, say Y.
 
+config ARM64_ILP32
+   bool "Kernel support for ILP32"
+   select COMPAT
+   help
+ This option enables support for AArch64 ILP32 user space.  ILP32
+ is an ABI where long and pointers are 32bits but it uses the AARCH64
+ instruction set. See Documentation/arm64/ilp32.txt for details.
+
 config SYSVIPC_COMPAT
def_bool y
depends on COMPAT && SYSVIPC
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 16/18] arm64: ptrace: handle ptrace_request differently for aarch32 and ilp32

2016-08-17 Thread Yury Norov
Here new aarch32 ptrace syscall handler is introsuced to avoid run-time
detection of the task type.

Signed-off-by: Yury Norov 
---
 arch/arm64/include/asm/unistd32.h |  2 +-
 arch/arm64/kernel/ptrace.c| 91 ++-
 arch/arm64/kernel/sys32.c |  1 +
 include/linux/ptrace.h|  6 +++
 kernel/ptrace.c   | 10 ++---
 5 files changed, 103 insertions(+), 7 deletions(-)

diff --git a/arch/arm64/include/asm/unistd32.h 
b/arch/arm64/include/asm/unistd32.h
index b7e8ef1..6da7cbd 100644
--- a/arch/arm64/include/asm/unistd32.h
+++ b/arch/arm64/include/asm/unistd32.h
@@ -74,7 +74,7 @@ __SYSCALL(__NR_getuid, sys_getuid16)
/* 25 was sys_stime */
 __SYSCALL(25, sys_ni_syscall)
 #define __NR_ptrace 26
-__SYSCALL(__NR_ptrace, compat_sys_ptrace)
+__SYSCALL(__NR_ptrace, compat_sys_aarch32_ptrace)
/* 27 was sys_alarm */
 __SYSCALL(27, sys_ni_syscall)
/* 28 was sys_fstat */
diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c
index 1d075ed..4f0df07 100644
--- a/arch/arm64/kernel/ptrace.c
+++ b/arch/arm64/kernel/ptrace.c
@@ -29,6 +29,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -40,6 +41,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -1215,7 +1217,7 @@ static int compat_ptrace_sethbpregs(struct task_struct 
*tsk, compat_long_t num,
 }
 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
 
-long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
+static long compat_a32_ptrace(struct task_struct *child, compat_long_t request,
compat_ulong_t caddr, compat_ulong_t cdata)
 {
unsigned long addr = caddr;
@@ -1292,8 +1294,95 @@ long compat_arch_ptrace(struct task_struct *child, 
compat_long_t request,
 
return ret;
 }
+
+COMPAT_SYSCALL_DEFINE4(aarch32_ptrace, compat_long_t, request, compat_long_t, 
pid,
+  compat_long_t, addr, compat_long_t, data)
+{
+   struct task_struct *child;
+   long ret;
+
+   if (request == PTRACE_TRACEME) {
+   ret = ptrace_traceme();
+   goto out;
+   }
+
+   child = ptrace_get_task_struct(pid);
+   if (IS_ERR(child)) {
+   ret = PTR_ERR(child);
+   goto out;
+   }
+
+   if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
+   ret = ptrace_attach(child, request, addr, data);
+   goto out_put_task_struct;
+   }
+
+   ret = ptrace_check_attach(child, request == PTRACE_KILL ||
+ request == PTRACE_INTERRUPT);
+   if (!ret) {
+   ret = compat_a32_ptrace(child, request, addr, data);
+   if (ret || request != PTRACE_DETACH)
+   ptrace_unfreeze_traced(child);
+   }
+
+ out_put_task_struct:
+   put_task_struct(child);
+ out:
+   return ret;
+}
+
 #endif /* CONFIG_AARCH32_EL0 */
 
+#ifdef CONFIG_ARM64_ILP32
+
+long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
+   compat_ulong_t caddr, compat_ulong_t cdata)
+{
+   sigset_t new_set;
+
+   switch (request) {
+   case PTRACE_GETSIGMASK:
+   if (caddr != sizeof(compat_sigset_t))
+   return -EINVAL;
+
+   return put_sigset_t((compat_sigset_t __user *) (u64) cdata,
+   >blocked);
+
+   case PTRACE_SETSIGMASK:
+   if (caddr != sizeof(compat_sigset_t))
+   return -EINVAL;
+
+   if (get_sigset_t(_set, (compat_sigset_t __user *) (u64) 
cdata))
+   return -EFAULT;
+
+   sigdelsetmask(_set, sigmask(SIGKILL)|sigmask(SIGSTOP));
+
+   /*
+* Every thread does recalc_sigpending() after resume, so
+* retarget_shared_pending() and recalc_sigpending() are not
+* called here.
+*/
+   spin_lock_irq(>sighand->siglock);
+   child->blocked = new_set;
+   spin_unlock_irq(>sighand->siglock);
+
+   return 0;
+
+   default:
+   return compat_ptrace_request(child, request, caddr, cdata);
+   }
+}
+
+#elif defined (CONFIG_COMPAT)
+
+long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
+   compat_ulong_t caddr, compat_ulong_t cdata)
+{
+   return 0;
+}
+
+#endif
+
 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
 {
 #ifdef CONFIG_AARCH32_EL0
diff --git a/arch/arm64/kernel/sys32.c b/arch/arm64/kernel/sys32.c
index a40b134..3752443 100644
--- a/arch/arm64/kernel/sys32.c
+++ b/arch/arm64/kernel/sys32.c
@@ -38,6 +38,7 @@ asmlinkage long compat_sys_fadvise64_64_wrapper(void);
 asmlinkage long compat_sys_sync_file_range2_wrapper(void);
 asmlinkage long 

[PATCH 13/18] arm64: signal: share lp64 signal routines to ilp32

2016-08-17 Thread Yury Norov
After that, it will be possible to reuse it in ilp32.

Signed-off-by: Yury Norov 
---
 arch/arm64/include/asm/signal_common.h | 33 
 arch/arm64/kernel/signal.c | 93 +-
 2 files changed, 92 insertions(+), 34 deletions(-)
 create mode 100644 arch/arm64/include/asm/signal_common.h

diff --git a/arch/arm64/include/asm/signal_common.h 
b/arch/arm64/include/asm/signal_common.h
new file mode 100644
index 000..756ed2c
--- /dev/null
+++ b/arch/arm64/include/asm/signal_common.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 1995-2009 Russell King
+ * Copyright (C) 2012 ARM Ltd.
+ * Copyright (C) 2016 Cavium Networks.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef __ASM_SIGNAL_COMMON_H
+#define __ASM_SIGNAL_COMMON_H
+
+#include 
+#include 
+#include 
+
+int preserve_fpsimd_context(struct fpsimd_context __user *ctx);
+int restore_fpsimd_context(struct fpsimd_context __user *ctx);
+int setup_sigcontext(struct sigcontext __user *uc_mcontext, struct pt_regs 
*regs);
+int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sf);
+void setup_return(struct pt_regs *regs, struct k_sigaction *ka,
+   void __user *frame, off_t sigframe_off, int usig);
+
+#endif /* __ASM_SIGNAL_COMMON_H */
diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c
index be02f65..5c73864 100644
--- a/arch/arm64/kernel/signal.c
+++ b/arch/arm64/kernel/signal.c
@@ -34,18 +34,26 @@
 #include 
 #include 
 #include 
+#include 
+
+#define RT_SIGFRAME_FP_POS (offsetof(struct rt_sigframe, sig)  \
+   + offsetof(struct sigframe, fp))
+
+struct sigframe {
+   struct ucontext uc;
+   u64 fp;
+   u64 lr;
+};
 
 /*
  * Do a signal return; undo the signal stack. These are aligned to 128-bit.
  */
 struct rt_sigframe {
struct siginfo info;
-   struct ucontext uc;
-   u64 fp;
-   u64 lr;
+   struct sigframe sig;
 };
 
-static int preserve_fpsimd_context(struct fpsimd_context __user *ctx)
+int preserve_fpsimd_context(struct fpsimd_context __user *ctx)
 {
struct fpsimd_state *fpsimd = >thread.fpsimd_state;
int err;
@@ -65,7 +73,7 @@ static int preserve_fpsimd_context(struct fpsimd_context 
__user *ctx)
return err ? -EFAULT : 0;
 }
 
-static int restore_fpsimd_context(struct fpsimd_context __user *ctx)
+int restore_fpsimd_context(struct fpsimd_context __user *ctx)
 {
struct fpsimd_state fpsimd;
__u32 magic, size;
@@ -93,22 +101,30 @@ static int restore_fpsimd_context(struct fpsimd_context 
__user *ctx)
 }
 
 static int restore_sigframe(struct pt_regs *regs,
-   struct rt_sigframe __user *sf)
+   struct sigframe __user *sf)
 {
sigset_t set;
-   int i, err;
-   void *aux = sf->uc.uc_mcontext.__reserved;
-
+   int err;
err = __copy_from_user(, >uc.uc_sigmask, sizeof(set));
if (err == 0)
set_current_blocked();
 
+   err |= restore_sigcontext(regs, >uc.uc_mcontext);
+   return err;
+}
+
+
+int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user 
*uc_mcontext)
+{
+   int i, err = 0;
+   void *aux = uc_mcontext->__reserved;
+
for (i = 0; i < 31; i++)
-   __get_user_error(regs->regs[i], >uc.uc_mcontext.regs[i],
+   __get_user_error(regs->regs[i], _mcontext->regs[i],
 err);
-   __get_user_error(regs->sp, >uc.uc_mcontext.sp, err);
-   __get_user_error(regs->pc, >uc.uc_mcontext.pc, err);
-   __get_user_error(regs->pstate, >uc.uc_mcontext.pstate, err);
+   __get_user_error(regs->sp, _mcontext->sp, err);
+   __get_user_error(regs->pc, _mcontext->pc, err);
+   __get_user_error(regs->pstate, _mcontext->pstate, err);
 
/*
 * Avoid sys_rt_sigreturn() restarting.
@@ -145,10 +161,10 @@ asmlinkage long sys_rt_sigreturn(struct pt_regs *regs)
if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
goto badframe;
 
-   if (restore_sigframe(regs, frame))
+   if (restore_sigframe(regs, >sig))
goto badframe;
 
-   if (restore_altstack(>uc.uc_stack))
+   if (restore_altstack(>sig.uc.uc_stack))
goto badframe;
 
return regs->regs[0];
@@ -162,27 +178,36 @@ badframe:
return 0;
 }
 
-static int 

[PATCH 02/18] arm64: ilp32: add documentation on the ILP32 ABI for ARM64

2016-08-17 Thread Yury Norov
Based on Andrew Pinski's patch-series.

Signed-off-by: Yury Norov 
---
 Documentation/arm64/ilp32.txt | 57 +++
 1 file changed, 57 insertions(+)
 create mode 100644 Documentation/arm64/ilp32.txt

diff --git a/Documentation/arm64/ilp32.txt b/Documentation/arm64/ilp32.txt
new file mode 100644
index 000..d575ef9
--- /dev/null
+++ b/Documentation/arm64/ilp32.txt
@@ -0,0 +1,57 @@
+ILP32 AARCH64 SYSCALL ABI
+=
+
+This document describes the ILP32 syscall ABI and where it differs
+from the generic compat linux syscall interface.
+
+AARCH64/ILP32 userspace can potentially access top halves of registers that
+are passed as syscall arguments, so such registers (w0-w7) are deloused.
+
+AARCH64/ILP32 provides next types turned to 64-bit (comparing to AARCH32):
+ino_t   is u64 type.
+off_t   is s64 type.
+blkcnt_tis s64 type.
+fsblkcnt_t  is u64 type.
+fsfilcnt_t  is u64 type.
+rlim_t  is u64 type.
+
+AARCH64/ILP32 ABI uses standard syscall table which can be found at
+include/uapi/asm-generic/unistd.h, with the exceptions listed below.
+
+Syscalls which pass 64bit values are handled by the code shared from
+AARCH32 and pass that value as a pair. Next syscalls are affected:
+fadvise64_64()
+fallocate()
+ftruncate64()  
+pread64()
+pwrite64()
+readahead()
+sync_file_range()
+truncate64()
+sys_mmap()
+
+ptrace() syscall is handled by compat version.
+
+fcntl64() syscall is handled by non-compat handler as struct flock for ilp32
+is the same as for lp64
+
+shmat() syscall is handled by non-compat handler as aarch64/ilp32 has no
+limitation on 4-pages alignement for shared memory.
+
+Syscalls which take a pointer to stat, stat64, statfs, statfs64, rlimit
+structures are now routed to native handlers directly, as aarch64/ilp32
+defines userspace ino_t, off_t, blkcnt_t, fsblkcnt_t, fsfilcnt_t rlim_t
+types as 64-bit and it makes that structures have same layout as lp64.
+Next syscalls are affected:
+fstatat64()
+fstat64()
+statfs64()
+fstatfs64()
+setrlimit()
+getrlimit()
+
+struct rt_sigframe is redefined and contains struct compat_siginfo,
+as compat syscalls expects, and struct ilp32_sigframe, to handle
+AARCH64 register set and 32-bit userspace register representation.h
+
+elf_gregset_t is taken from lp64 to handle registers properly.
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 17/18] arm64:ilp32: add vdso-ilp32 and use for signal return

2016-08-17 Thread Yury Norov
From: Philipp Tomsich 

ILP32 VDSO exports next symbols:
 __kernel_rt_sigreturn;
 __kernel_gettimeofday;
 __kernel_clock_gettime;
 __kernel_clock_getres;

What shared object to use, kernel selects depending on result of
is_ilp32_compat_task() in arch/arm64/kernel/vdso.c, so it substitutes
correct pages and spec.

Adjusted to move the move data page before code pages in sync with
commit 601255ae3c98fd3a8bb4696425e4f868b4f1

Signed-off-by: Philipp Tomsich 
Signed-off-by: Christoph Muellner 
Signed-off-by: Yury Norov 
---
 arch/arm64/include/asm/vdso.h |  6 ++
 arch/arm64/kernel/Makefile| 11 
 arch/arm64/kernel/asm-offsets.c   |  7 ++
 arch/arm64/kernel/signal.c|  2 +
 arch/arm64/kernel/vdso-ilp32/.gitignore   |  2 +
 arch/arm64/kernel/vdso-ilp32/Makefile | 74 +
 arch/arm64/kernel/vdso-ilp32/vdso-ilp32.S | 33 ++
 arch/arm64/kernel/vdso-ilp32/vdso-ilp32.lds.S | 95 +++
 arch/arm64/kernel/vdso.c  | 75 -
 arch/arm64/kernel/vdso/gettimeofday.S | 18 -
 10 files changed, 305 insertions(+), 18 deletions(-)
 create mode 100644 arch/arm64/kernel/vdso-ilp32/.gitignore
 create mode 100644 arch/arm64/kernel/vdso-ilp32/Makefile
 create mode 100644 arch/arm64/kernel/vdso-ilp32/vdso-ilp32.S
 create mode 100644 arch/arm64/kernel/vdso-ilp32/vdso-ilp32.lds.S

diff --git a/arch/arm64/include/asm/vdso.h b/arch/arm64/include/asm/vdso.h
index 839ce00..649a9a4 100644
--- a/arch/arm64/include/asm/vdso.h
+++ b/arch/arm64/include/asm/vdso.h
@@ -29,6 +29,12 @@
 
 #include 
 
+#ifdef CONFIG_ARM64_ILP32
+#include 
+#else
+#define vdso_offset_sigtramp_ilp32
+#endif
+
 #define VDSO_SYMBOL(base, name)
   \
 ({\
(void *)(vdso_offset_##name - VDSO_LBASE + (unsigned long)(base)); \
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 7038ffb..86a12ba 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -53,6 +53,17 @@ arm64-obj-$(CONFIG_KEXEC)+= machine_kexec.o 
relocate_kernel.o\
   cpu-reset.o
 
 obj-y  += $(arm64-obj-y) vdso/ probes/
+obj-$(CONFIG_ARM64_ILP32)  += vdso-ilp32/
 obj-m  += $(arm64-obj-m)
 head-y := head.o
 extra-y+= $(head-y) vmlinux.lds
+
+# vDSO - this must be built first to generate the symbol offsets
+$(call objectify,$(arm64-obj-y)): $(obj)/vdso/vdso-offsets.h
+$(obj)/vdso/vdso-offsets.h: $(obj)/vdso
+
+ifeq ($(CONFIG_ARM64_ILP32),y)
+# vDSO - this must be built first to generate the symbol offsets
+$(call objectify,$(arm64-obj-y)): $(obj)/vdso-ilp32/vdso-ilp32-offsets.h
+$(obj)/vdso-ilp32/vdso-ilp32-offsets.h: $(obj)/vdso-ilp32
+endif
diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c
index 19a6883..5815015 100644
--- a/arch/arm64/kernel/asm-offsets.c
+++ b/arch/arm64/kernel/asm-offsets.c
@@ -118,6 +118,13 @@ int main(void)
   DEFINE(TSPEC_TV_SEC, offsetof(struct timespec, tv_sec));
   DEFINE(TSPEC_TV_NSEC,offsetof(struct timespec, tv_nsec));
   BLANK();
+#ifdef CONFIG_COMPAT
+  DEFINE(COMPAT_TVAL_TV_SEC,   offsetof(struct compat_timeval, tv_sec));
+  DEFINE(COMPAT_TVAL_TV_USEC,  offsetof(struct compat_timeval, tv_usec));
+  DEFINE(COMPAT_TSPEC_TV_SEC,  offsetof(struct compat_timespec, tv_sec));
+  DEFINE(COMPAT_TSPEC_TV_NSEC, offsetof(struct compat_timespec, tv_nsec));
+  BLANK();
+#endif
   DEFINE(TZ_MINWEST,   offsetof(struct timezone, tz_minuteswest));
   DEFINE(TZ_DSTTIME,   offsetof(struct timezone, tz_dsttime));
   BLANK();
diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c
index 241bfeb..7142b12 100644
--- a/arch/arm64/kernel/signal.c
+++ b/arch/arm64/kernel/signal.c
@@ -267,6 +267,8 @@ void setup_return(struct pt_regs *regs, struct k_sigaction 
*ka,
 
if (ka->sa.sa_flags & SA_RESTORER)
sigtramp = ka->sa.sa_restorer;
+   else if (is_ilp32_compat_task())
+   sigtramp = VDSO_SYMBOL(current->mm->context.vdso, 
sigtramp_ilp32);
else
sigtramp = VDSO_SYMBOL(current->mm->context.vdso, sigtramp);
 
diff --git a/arch/arm64/kernel/vdso-ilp32/.gitignore 
b/arch/arm64/kernel/vdso-ilp32/.gitignore
new file mode 100644
index 000..61806c3
--- /dev/null
+++ b/arch/arm64/kernel/vdso-ilp32/.gitignore
@@ -0,0 +1,2 @@
+vdso-ilp32.lds
+vdso-ilp32-offsets.h
diff --git a/arch/arm64/kernel/vdso-ilp32/Makefile 
b/arch/arm64/kernel/vdso-ilp32/Makefile
new file mode 100644
index 

[PATCH 09/18] arm64: introduce binfmt_elf32.c

2016-08-17 Thread Yury Norov
As we support more than one compat formats, it looks more reasonable
to not use fs/compat_binfmt.c. Custom binfmt_elf32.c allows to move aarch32
specific definitions there and make code more maintainable and readable.

Signed-off-by: Yury Norov 
---
 arch/arm64/Kconfig   |  1 -
 arch/arm64/include/asm/hwcap.h   |  2 --
 arch/arm64/kernel/Makefile   |  2 +-
 arch/arm64/kernel/binfmt_elf32.c | 31 +++
 4 files changed, 32 insertions(+), 4 deletions(-)
 create mode 100644 arch/arm64/kernel/binfmt_elf32.c

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 08ca1cb..3d46250 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -998,7 +998,6 @@ config AARCH32_EL0
def_bool y
depends on ARM64_4K_PAGES || EXPERT
select COMPAT
-   select COMPAT_BINFMT_ELF
select HAVE_UID16
select OLD_SIGSUSPEND3
select COMPAT_OLD_SIGACTION
diff --git a/arch/arm64/include/asm/hwcap.h b/arch/arm64/include/asm/hwcap.h
index 2c7fc5d..99dfd92 100644
--- a/arch/arm64/include/asm/hwcap.h
+++ b/arch/arm64/include/asm/hwcap.h
@@ -47,8 +47,6 @@
 #define ELF_HWCAP  (elf_hwcap)
 
 #ifdef CONFIG_AARCH32_EL0
-#define COMPAT_ELF_HWCAP   (compat_elf_hwcap)
-#define COMPAT_ELF_HWCAP2  (compat_elf_hwcap2)
 extern unsigned int compat_elf_hwcap, compat_elf_hwcap2;
 #endif
 
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 4ec5886..949187c 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -26,7 +26,7 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
$(call if_changed,objcopy)
 
 arm64-obj-$(CONFIG_AARCH32_EL0)+= sys32.o kuser32.o signal32.o 
\
-  sys_compat.o entry32.o
+  sys_compat.o entry32.o binfmt_elf32.o
 arm64-obj-$(CONFIG_FUNCTION_TRACER)+= ftrace.o entry-ftrace.o
 arm64-obj-$(CONFIG_MODULES)+= arm64ksyms.o module.o
 arm64-obj-$(CONFIG_ARM64_MODULE_PLTS)  += module-plts.o
diff --git a/arch/arm64/kernel/binfmt_elf32.c b/arch/arm64/kernel/binfmt_elf32.c
new file mode 100644
index 000..aec1c8a
--- /dev/null
+++ b/arch/arm64/kernel/binfmt_elf32.c
@@ -0,0 +1,31 @@
+/*
+ * Support for AArch32 Linux ELF binaries.
+ */
+
+/* AArch32 EABI. */
+#define EF_ARM_EABI_MASK   0xff00
+
+#define compat_start_threadcompat_start_thread
+#define COMPAT_SET_PERSONALITY(ex) \
+do {   \
+   clear_thread_flag(TIF_32BIT_AARCH64);   \
+   set_thread_flag(TIF_32BIT); \
+} while (0)
+
+#define COMPAT_ARCH_DLINFO
+#define COMPAT_ELF_HWCAP   (compat_elf_hwcap)
+#define COMPAT_ELF_HWCAP2  (compat_elf_hwcap2)
+
+#ifdef __AARCH64EB__
+#define COMPAT_ELF_PLATFORM("v8b")
+#else
+#define COMPAT_ELF_PLATFORM("v8l")
+#endif
+
+#define compat_arch_setup_additional_pages \
+   aarch32_setup_vectors_page
+struct linux_binprm;
+extern int aarch32_setup_vectors_page(struct linux_binprm *bprm,
+ int uses_interp);
+
+#include "../../../fs/compat_binfmt_elf.c"
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 01/18] 32-bit ABI: introduce ARCH_32BIT_OFF_T config option

2016-08-17 Thread Yury Norov
All new 32-bit architectures should have 64-bit off_t type, but existing
architectures has 32-bit ones.

To handle it, new config option is added to arch/Kconfig that defaults
ARCH_32BIT_OFF_T to be disabled for 64-bit and new 32-bit architectures.
All existing 32-bit architectures enable it explicitly here.

New option affects force_o_largefile() behaviour. Namely, if off_t is
64-bits long, we have no reason to reject user to open big files.

For syscalls sys_openat() and sys_open_by_handle_at() force_o_largefile()
is called, to set O_LARGEFILE flag, and this is the only difference
comparing to compat versions. So for now we can drop compat version of
that syscalls in standard unistd, as ARCH_32BIT_OFF_T controls the
behaviour explicitly.

Note that even if architectures has only 64-bit off_t in the kernel
(arc, c6x, h8300, hexagon, metag, nios2, openrisc, tile32 and unicore32),
a libc may use 32-bit off_t, and therefore want to limit the file size
to 4GB unless specified differently in the open flags.

Signed-off-by: Yury Norov 
---
 arch/Kconfig  | 4 
 arch/arc/Kconfig  | 1 +
 arch/arm/Kconfig  | 1 +
 arch/blackfin/Kconfig | 1 +
 arch/cris/Kconfig | 1 +
 arch/frv/Kconfig  | 1 +
 arch/h8300/Kconfig| 1 +
 arch/hexagon/Kconfig  | 1 +
 arch/m32r/Kconfig | 1 +
 arch/m68k/Kconfig | 1 +
 arch/metag/Kconfig| 1 +
 arch/microblaze/Kconfig   | 1 +
 arch/mips/Kconfig | 1 +
 arch/mn10300/Kconfig  | 1 +
 arch/nios2/Kconfig| 1 +
 arch/openrisc/Kconfig | 1 +
 arch/parisc/Kconfig   | 1 +
 arch/powerpc/Kconfig  | 1 +
 arch/score/Kconfig| 1 +
 arch/sh/Kconfig   | 1 +
 arch/sparc/Kconfig| 1 +
 arch/tile/Kconfig | 1 +
 arch/unicore32/Kconfig| 1 +
 arch/x86/Kconfig  | 1 +
 arch/x86/um/Kconfig   | 1 +
 arch/xtensa/Kconfig   | 1 +
 include/linux/fcntl.h | 2 +-
 include/uapi/asm-generic/unistd.h | 5 ++---
 28 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/arch/Kconfig b/arch/Kconfig
index e9c9334..eaf657c 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -234,6 +234,10 @@ config ARCH_THREAD_STACK_ALLOCATOR
 config ARCH_WANTS_DYNAMIC_TASK_STRUCT
bool
 
+config ARCH_32BIT_OFF_T
+   bool
+   depends on !64BIT
+
 config HAVE_REGS_AND_STACK_ACCESS_API
bool
help
diff --git a/arch/arc/Kconfig b/arch/arc/Kconfig
index 0d3e59f..d5ca749 100644
--- a/arch/arc/Kconfig
+++ b/arch/arc/Kconfig
@@ -9,6 +9,7 @@
 config ARC
def_bool y
select ARCH_SUPPORTS_ATOMIC_RMW if ARC_HAS_LLSC
+   select ARCH_32BIT_OFF_T
select BUILDTIME_EXTABLE_SORT
select CLKSRC_OF
select CLONE_BACKWARDS
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index a9c4e48..888b067 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1,6 +1,7 @@
 config ARM
bool
default y
+   select ARCH_32BIT_OFF_T
select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
select ARCH_HAS_DEVMEM_IS_ALLOWED
select ARCH_HAS_ELF_RANDOMIZE
diff --git a/arch/blackfin/Kconfig b/arch/blackfin/Kconfig
index 28c63fe..097e7a5 100644
--- a/arch/blackfin/Kconfig
+++ b/arch/blackfin/Kconfig
@@ -12,6 +12,7 @@ config RWSEM_XCHGADD_ALGORITHM
 
 config BLACKFIN
def_bool y
+   select ARCH_32BIT_OFF_T
select HAVE_ARCH_KGDB
select HAVE_ARCH_TRACEHOOK
select HAVE_DYNAMIC_FTRACE
diff --git a/arch/cris/Kconfig b/arch/cris/Kconfig
index deba266..b1376a9 100644
--- a/arch/cris/Kconfig
+++ b/arch/cris/Kconfig
@@ -50,6 +50,7 @@ config LOCKDEP_SUPPORT
 config CRIS
bool
default y
+   select ARCH_32BIT_OFF_T
select HAVE_IDE
select GENERIC_ATOMIC64
select HAVE_UID16
diff --git a/arch/frv/Kconfig b/arch/frv/Kconfig
index eefd9a4..2f14904 100644
--- a/arch/frv/Kconfig
+++ b/arch/frv/Kconfig
@@ -1,6 +1,7 @@
 config FRV
bool
default y
+   select ARCH_32BIT_OFF_T
select HAVE_IDE
select HAVE_ARCH_TRACEHOOK
select HAVE_PERF_EVENTS
diff --git a/arch/h8300/Kconfig b/arch/h8300/Kconfig
index 3ae8525..29bbcb1 100644
--- a/arch/h8300/Kconfig
+++ b/arch/h8300/Kconfig
@@ -1,5 +1,6 @@
 config H8300
 def_bool y
+   select ARCH_32BIT_OFF_T
select GENERIC_ATOMIC64
select HAVE_UID16
select VIRT_TO_BUS
diff --git a/arch/hexagon/Kconfig b/arch/hexagon/Kconfig
index 1941e4b..bbcea8c 100644
--- a/arch/hexagon/Kconfig
+++ b/arch/hexagon/Kconfig
@@ -3,6 +3,7 @@ comment "Linux Kernel Configuration for Hexagon"
 
 config HEXAGON
def_bool y
+   select ARCH_32BIT_OFF_T
select HAVE_OPROFILE
# Other pending projects/to-do items.
# 

[PATCH 07/18] arm64: introduce is_a32_task and is_a32_thread (for AArch32 compat)

2016-08-17 Thread Yury Norov
Based on patch of Andrew Pinski.

This patch introduces is_a32_compat_task and is_a32_thread so it is
easier to say this is a a32 specific thread or a generic compat thread/task.
Corresponding functions are located in  to avoid mess in
headers.

Some files include both  and ,
and this is wrong because  has  already
included. It was fixed too.

Signed-off-by: Yury Norov 
Signed-off-by: Philipp Tomsich 
Signed-off-by: Christoph Muellner 
Signed-off-by: Andrew Pinski 
Reviewed-by: David Daney 
---
 arch/arm64/include/asm/compat.h  | 19 ++-
 arch/arm64/include/asm/elf.h | 10 +++---
 arch/arm64/include/asm/ftrace.h  |  2 +-
 arch/arm64/include/asm/is_compat.h   | 64 
 arch/arm64/include/asm/memory.h  |  5 +--
 arch/arm64/include/asm/processor.h   |  5 +--
 arch/arm64/include/asm/syscall.h |  2 +-
 arch/arm64/include/asm/thread_info.h |  2 +-
 arch/arm64/kernel/hw_breakpoint.c| 10 +++---
 arch/arm64/kernel/perf_regs.c|  2 +-
 arch/arm64/kernel/process.c  |  7 ++--
 arch/arm64/kernel/ptrace.c   | 11 +++
 arch/arm64/kernel/signal.c   |  4 +--
 arch/arm64/kernel/traps.c|  3 +-
 14 files changed, 98 insertions(+), 48 deletions(-)
 create mode 100644 arch/arm64/include/asm/is_compat.h

diff --git a/arch/arm64/include/asm/compat.h b/arch/arm64/include/asm/compat.h
index eb8432b..df2f72d 100644
--- a/arch/arm64/include/asm/compat.h
+++ b/arch/arm64/include/asm/compat.h
@@ -24,6 +24,8 @@
 #include 
 #include 
 
+#include 
+
 #define COMPAT_USER_HZ 100
 #ifdef __AARCH64EB__
 #define COMPAT_UTS_MACHINE "armv8b\0\0"
@@ -298,23 +300,6 @@ struct compat_shmid64_ds {
compat_ulong_t __unused5;
 };
 
-static inline int is_compat_task(void)
-{
-   return test_thread_flag(TIF_32BIT);
-}
-
-static inline int is_compat_thread(struct thread_info *thread)
-{
-   return test_ti_thread_flag(thread, TIF_32BIT);
-}
-
-#else /* !CONFIG_COMPAT */
-
-static inline int is_compat_thread(struct thread_info *thread)
-{
-   return 0;
-}
-
 #endif /* CONFIG_COMPAT */
 #endif /* __KERNEL__ */
 #endif /* __ASM_COMPAT_H */
diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h
index a55384f..6a9049b 100644
--- a/arch/arm64/include/asm/elf.h
+++ b/arch/arm64/include/asm/elf.h
@@ -16,6 +16,10 @@
 #ifndef __ASM_ELF_H
 #define __ASM_ELF_H
 
+#ifndef __ASSEMBLY__
+#include 
+#endif
+
 #include 
 
 /*
@@ -153,13 +157,9 @@ extern int arch_setup_additional_pages(struct linux_binprm 
*bprm,
   int uses_interp);
 
 /* 1GB of VA */
-#ifdef CONFIG_COMPAT
-#define STACK_RND_MASK (test_thread_flag(TIF_32BIT) ? \
+#define STACK_RND_MASK (is_compat_task() ? \
0x7ff >> (PAGE_SHIFT - 12) : \
0x3 >> (PAGE_SHIFT - 12))
-#else
-#define STACK_RND_MASK (0x3 >> (PAGE_SHIFT - 12))
-#endif
 
 #ifdef __AARCH64EB__
 #define COMPAT_ELF_PLATFORM("v8b")
diff --git a/arch/arm64/include/asm/ftrace.h b/arch/arm64/include/asm/ftrace.h
index caa955f..0feb28a 100644
--- a/arch/arm64/include/asm/ftrace.h
+++ b/arch/arm64/include/asm/ftrace.h
@@ -54,7 +54,7 @@ static inline unsigned long ftrace_call_adjust(unsigned long 
addr)
 #define ARCH_TRACE_IGNORE_COMPAT_SYSCALLS
 static inline bool arch_trace_is_compat_syscall(struct pt_regs *regs)
 {
-   return is_compat_task();
+   return is_a32_compat_task();
 }
 #endif /* ifndef __ASSEMBLY__ */
 
diff --git a/arch/arm64/include/asm/is_compat.h 
b/arch/arm64/include/asm/is_compat.h
new file mode 100644
index 000..8dba5ca
--- /dev/null
+++ b/arch/arm64/include/asm/is_compat.h
@@ -0,0 +1,64 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef __ASM_IS_COMPAT_H
+#define __ASM_IS_COMPAT_H
+#ifndef __ASSEMBLY__
+
+#include 
+
+#ifdef CONFIG_AARCH32_EL0
+
+static inline int is_a32_compat_task(void)
+{
+   return test_thread_flag(TIF_32BIT);
+}
+
+static inline int is_a32_compat_thread(struct thread_info *thread)
+{
+   return test_ti_thread_flag(thread, TIF_32BIT);
+}
+
+#else
+
+static inline int is_a32_compat_task(void)
+
+{
+   return 0;
+}
+

[PATCH 03/18] arm64: ensure the kernel is compiled for LP64

2016-08-17 Thread Yury Norov
From: Andrew Pinski 

The kernel needs to be compiled as a LP64 binary for ARM64, even when
using a compiler that defaults to code-generation for the ILP32 ABI.
Consequently, we need to explicitly pass '-mabi=lp64' (supported on
gcc-4.9 and newer).

Signed-off-by: Andrew Pinski 
Signed-off-by: Philipp Tomsich 
Signed-off-by: Christoph Muellner 
Signed-off-by: Yury Norov 
Reviewed-by: David Daney 
---
 arch/arm64/Makefile | 5 +
 1 file changed, 5 insertions(+)

diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
index 5b54f8c..4800227 100644
--- a/arch/arm64/Makefile
+++ b/arch/arm64/Makefile
@@ -34,14 +34,19 @@ KBUILD_CFLAGS   += -fno-asynchronous-unwind-tables
 KBUILD_CFLAGS  += $(call cc-option, -mpc-relative-literal-loads)
 KBUILD_AFLAGS  += $(lseinstr)
 
+KBUILD_CFLAGS  += $(call cc-option,-mabi=lp64)
+KBUILD_AFLAGS  += $(call cc-option,-mabi=lp64)
+
 ifeq ($(CONFIG_CPU_BIG_ENDIAN), y)
 KBUILD_CPPFLAGS+= -mbig-endian
 AS += -EB
 LD += -EB
+LDFLAGS+= -maarch64linuxb
 else
 KBUILD_CPPFLAGS+= -mlittle-endian
 AS += -EL
 LD += -EL
+LDFLAGS+= -maarch64linux
 endif
 
 CHECKFLAGS += -D__aarch64__
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 12/18] arm64: ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-08-17 Thread Yury Norov
From: Andrew Pinski 

Add a separate syscall-table for ILP32, which dispatches either to native
LP64 system call implementation or to compat-syscalls, as appropriate.

Signed-off-by: Andrew Pinski 
Signed-off-by: Yury Norov 
---
 arch/arm64/include/asm/unistd.h |  6 ++-
 arch/arm64/kernel/Makefile  |  2 +-
 arch/arm64/kernel/entry.S   | 28 +-
 arch/arm64/kernel/sys_ilp32.c   | 86 +
 4 files changed, 118 insertions(+), 4 deletions(-)
 create mode 100644 arch/arm64/kernel/sys_ilp32.c

diff --git a/arch/arm64/include/asm/unistd.h b/arch/arm64/include/asm/unistd.h
index fe9d6c1..250654c 100644
--- a/arch/arm64/include/asm/unistd.h
+++ b/arch/arm64/include/asm/unistd.h
@@ -13,13 +13,17 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see .
  */
+
+#ifdef CONFIG_COMPAT
+#define __ARCH_WANT_SYS_LLSEEK
+#endif
+
 #ifdef CONFIG_AARCH32_EL0
 #define __ARCH_WANT_COMPAT_SYS_GETDENTS64
 #define __ARCH_WANT_COMPAT_STAT64
 #define __ARCH_WANT_SYS_GETHOSTNAME
 #define __ARCH_WANT_SYS_PAUSE
 #define __ARCH_WANT_SYS_GETPGRP
-#define __ARCH_WANT_SYS_LLSEEK
 #define __ARCH_WANT_SYS_NICE
 #define __ARCH_WANT_SYS_SIGPENDING
 #define __ARCH_WANT_SYS_SIGPROCMASK
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 4a81d93..36257b7 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -27,7 +27,7 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
 
 arm64-obj-$(CONFIG_AARCH32_EL0)+= sys32.o kuser32.o signal32.o 
\
   sys_compat.o entry32.o binfmt_elf32.o
-arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o
+arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o sys_ilp32.o
 arm64-obj-$(CONFIG_COMPAT) += entry32_common.o
 arm64-obj-$(CONFIG_FUNCTION_TRACER)+= ftrace.o entry-ftrace.o
 arm64-obj-$(CONFIG_MODULES)+= arm64ksyms.o module.o
diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
index 9e18747..4c44312 100644
--- a/arch/arm64/kernel/entry.S
+++ b/arch/arm64/kernel/entry.S
@@ -255,6 +255,23 @@ tsk.reqx28 // current thread_info
 
.text
 
+#ifdef CONFIG_ARM64_ILP32
+/*
+ * AARCH64/ILP32. Zero top halves of x0-x7
+ * registers as userspace may put garbage there.
+ */
+   .macro  delouse_input_regs
+   mov w0, w0
+   mov w1, w1
+   mov w2, w2
+   mov w3, w3
+   mov w4, w4
+   mov w5, w5
+   mov w6, w6
+   mov w7, w7
+   .endm
+#endif
+
 /*
  * Exception vectors.
  */
@@ -523,6 +540,7 @@ el0_svc_compat:
 * AArch32 syscall handling
 */
adrpstbl, compat_sys_call_table // load compat syscall table 
pointer
+   ldr x16, [tsk, #TI_FLAGS]
uxtwscno, w7// syscall number in w7 (r7)
mov sc_nr, #__NR_compat_syscalls
b   el0_svc_naked
@@ -749,15 +767,21 @@ ENDPROC(ret_from_fork)
.align  6
 el0_svc:
adrpstbl, sys_call_table// load syscall table pointer
+   ldr x16, [tsk, #TI_FLAGS]
uxtwscno, w8// syscall number in w8
mov sc_nr, #__NR_syscalls
+#ifdef CONFIG_ARM64_ILP32
+   tst x16, #_TIF_32BIT_AARCH64
+   b.eqel0_svc_naked   // We are using LP64  syscall 
table
+   adrpstbl, sys_call_ilp32_table  // load ilp32 syscall table 
pointer
+   delouse_input_regs
+#endif
 el0_svc_naked: // compat entry point
stp x0, scno, [sp, #S_ORIG_X0]  // save the original x0 and 
syscall number
enable_dbg_and_irq
ct_user_exit 1
 
-   ldr x16, [tsk, #TI_FLAGS]   // check for syscall hooks
-   tst x16, #_TIF_SYSCALL_WORK
+   tst x16, #_TIF_SYSCALL_WORK // check for syscall hooks
b.ne__sys_trace
cmp scno, sc_nr // check upper syscall limit
b.hsni_sys
diff --git a/arch/arm64/kernel/sys_ilp32.c b/arch/arm64/kernel/sys_ilp32.c
new file mode 100644
index 000..10fc0ca
--- /dev/null
+++ b/arch/arm64/kernel/sys_ilp32.c
@@ -0,0 +1,86 @@
+/*
+ * AArch64- ILP32 specific system calls implementation
+ *
+ * Copyright (C) 2016 Cavium Inc.
+ * Author: Andrew Pinski 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that 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.
+ *
+ 

[PATCH 06/18] thread: move thread bits accessors to separated file

2016-08-17 Thread Yury Norov
They may be accessed from low-level code, so isolating is a measure to
avoid circular dependencies in header files.

The exact reason for circular dependency is WARN_ON() macro added by Al
Viro in patch [edd63a27] "set_restore_sigmask() is never called without
SIGPENDING (and never should be)"

Signed-off-by: Yury Norov 
---
 include/linux/thread_bits.h | 55 +
 include/linux/thread_info.h | 44 +---
 2 files changed, 56 insertions(+), 43 deletions(-)
 create mode 100644 include/linux/thread_bits.h

diff --git a/include/linux/thread_bits.h b/include/linux/thread_bits.h
new file mode 100644
index 000..0d05d16
--- /dev/null
+++ b/include/linux/thread_bits.h
@@ -0,0 +1,55 @@
+
+/* thread_bits.h: common low-level thread bits accessors */
+
+#ifndef _LINUX_THREAD_BITS_H
+#define _LINUX_THREAD_BITS_H
+
+#ifndef __ASSEMBLY__
+
+#include 
+#include 
+
+/*
+ * flag set/clear/test wrappers
+ * - pass TIF_ constants to these functions
+ */
+
+static inline void set_ti_thread_flag(struct thread_info *ti, int flag)
+{
+   set_bit(flag, (unsigned long *)>flags);
+}
+
+static inline void clear_ti_thread_flag(struct thread_info *ti, int flag)
+{
+   clear_bit(flag, (unsigned long *)>flags);
+}
+
+static inline int test_and_set_ti_thread_flag(struct thread_info *ti, int flag)
+{
+   return test_and_set_bit(flag, (unsigned long *)>flags);
+}
+
+static inline int test_and_clear_ti_thread_flag(struct thread_info *ti, int 
flag)
+{
+   return test_and_clear_bit(flag, (unsigned long *)>flags);
+}
+
+static inline int test_ti_thread_flag(struct thread_info *ti, int flag)
+{
+   return test_bit(flag, (unsigned long *)>flags);
+}
+
+#define set_thread_flag(flag) \
+   set_ti_thread_flag(current_thread_info(), flag)
+#define clear_thread_flag(flag) \
+   clear_ti_thread_flag(current_thread_info(), flag)
+#define test_and_set_thread_flag(flag) \
+   test_and_set_ti_thread_flag(current_thread_info(), flag)
+#define test_and_clear_thread_flag(flag) \
+   test_and_clear_ti_thread_flag(current_thread_info(), flag)
+#define test_thread_flag(flag) \
+   test_ti_thread_flag(current_thread_info(), flag)
+
+#endif /* !__ASSEMBLY__ */
+#endif /* _LINUX_THREAD_BITS_H */
+
diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
index cbd8990..c778121 100644
--- a/include/linux/thread_info.h
+++ b/include/linux/thread_info.h
@@ -50,8 +50,7 @@ struct restart_block {
 
 extern long do_no_restart_syscall(struct restart_block *parm);
 
-#include 
-#include 
+#include 
 
 #ifdef __KERNEL__
 
@@ -62,47 +61,6 @@ extern long do_no_restart_syscall(struct restart_block 
*parm);
 # define THREADINFO_GFP(GFP_KERNEL_ACCOUNT | __GFP_NOTRACK)
 #endif
 
-/*
- * flag set/clear/test wrappers
- * - pass TIF_ constants to these functions
- */
-
-static inline void set_ti_thread_flag(struct thread_info *ti, int flag)
-{
-   set_bit(flag, (unsigned long *)>flags);
-}
-
-static inline void clear_ti_thread_flag(struct thread_info *ti, int flag)
-{
-   clear_bit(flag, (unsigned long *)>flags);
-}
-
-static inline int test_and_set_ti_thread_flag(struct thread_info *ti, int flag)
-{
-   return test_and_set_bit(flag, (unsigned long *)>flags);
-}
-
-static inline int test_and_clear_ti_thread_flag(struct thread_info *ti, int 
flag)
-{
-   return test_and_clear_bit(flag, (unsigned long *)>flags);
-}
-
-static inline int test_ti_thread_flag(struct thread_info *ti, int flag)
-{
-   return test_bit(flag, (unsigned long *)>flags);
-}
-
-#define set_thread_flag(flag) \
-   set_ti_thread_flag(current_thread_info(), flag)
-#define clear_thread_flag(flag) \
-   clear_ti_thread_flag(current_thread_info(), flag)
-#define test_and_set_thread_flag(flag) \
-   test_and_set_ti_thread_flag(current_thread_info(), flag)
-#define test_and_clear_thread_flag(flag) \
-   test_and_clear_ti_thread_flag(current_thread_info(), flag)
-#define test_thread_flag(flag) \
-   test_ti_thread_flag(current_thread_info(), flag)
-
 #define tif_need_resched() test_thread_flag(TIF_NEED_RESCHED)
 
 #ifndef CONFIG_HAVE_ARCH_WITHIN_STACK_FRAMES
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 11/18] arm64: ilp32: share aarch32 syscall handlers

2016-08-17 Thread Yury Norov
off_t is  passed in register pair just like in aarch32.
In this patch corresponding aarch32 handlers are shared to
ilp32 code.

Signed-off-by: Yury Norov 
---
 arch/arm64/kernel/Makefile |  1 +
 arch/arm64/kernel/entry32.S| 65 --
 arch/arm64/kernel/entry32_common.S | 93 ++
 3 files changed, 94 insertions(+), 65 deletions(-)
 create mode 100644 arch/arm64/kernel/entry32_common.S

diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 9b6c324..4a81d93 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -28,6 +28,7 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
 arm64-obj-$(CONFIG_AARCH32_EL0)+= sys32.o kuser32.o signal32.o 
\
   sys_compat.o entry32.o binfmt_elf32.o
 arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o
+arm64-obj-$(CONFIG_COMPAT) += entry32_common.o
 arm64-obj-$(CONFIG_FUNCTION_TRACER)+= ftrace.o entry-ftrace.o
 arm64-obj-$(CONFIG_MODULES)+= arm64ksyms.o module.o
 arm64-obj-$(CONFIG_ARM64_MODULE_PLTS)  += module-plts.o
diff --git a/arch/arm64/kernel/entry32.S b/arch/arm64/kernel/entry32.S
index f332d5d..fd2b0d5 100644
--- a/arch/arm64/kernel/entry32.S
+++ b/arch/arm64/kernel/entry32.S
@@ -54,68 +54,3 @@ ENTRY(compat_sys_fstatfs64_wrapper)
b   compat_sys_fstatfs64
 ENDPROC(compat_sys_fstatfs64_wrapper)
 
-/*
- * Note: off_4k (w5) is always in units of 4K. If we can't do the
- * requested offset because it is not page-aligned, we return -EINVAL.
- */
-ENTRY(compat_sys_mmap2_wrapper)
-#if PAGE_SHIFT > 12
-   tst w5, #~PAGE_MASK >> 12
-   b.ne1f
-   lsr w5, w5, #PAGE_SHIFT - 12
-#endif
-   b   sys_mmap_pgoff
-1: mov x0, #-EINVAL
-   ret
-ENDPROC(compat_sys_mmap2_wrapper)
-
-/*
- * Wrappers for AArch32 syscalls that either take 64-bit parameters
- * in registers or that take 32-bit parameters which require sign
- * extension.
- */
-ENTRY(compat_sys_pread64_wrapper)
-   regs_to_64  x3, x4, x5
-   b   sys_pread64
-ENDPROC(compat_sys_pread64_wrapper)
-
-ENTRY(compat_sys_pwrite64_wrapper)
-   regs_to_64  x3, x4, x5
-   b   sys_pwrite64
-ENDPROC(compat_sys_pwrite64_wrapper)
-
-ENTRY(compat_sys_truncate64_wrapper)
-   regs_to_64  x1, x2, x3
-   b   sys_truncate
-ENDPROC(compat_sys_truncate64_wrapper)
-
-ENTRY(compat_sys_ftruncate64_wrapper)
-   regs_to_64  x1, x2, x3
-   b   sys_ftruncate
-ENDPROC(compat_sys_ftruncate64_wrapper)
-
-ENTRY(compat_sys_readahead_wrapper)
-   regs_to_64  x1, x2, x3
-   mov w2, w4
-   b   sys_readahead
-ENDPROC(compat_sys_readahead_wrapper)
-
-ENTRY(compat_sys_fadvise64_64_wrapper)
-   mov w6, w1
-   regs_to_64  x1, x2, x3
-   regs_to_64  x2, x4, x5
-   mov w3, w6
-   b   sys_fadvise64_64
-ENDPROC(compat_sys_fadvise64_64_wrapper)
-
-ENTRY(compat_sys_sync_file_range2_wrapper)
-   regs_to_64  x2, x2, x3
-   regs_to_64  x3, x4, x5
-   b   sys_sync_file_range2
-ENDPROC(compat_sys_sync_file_range2_wrapper)
-
-ENTRY(compat_sys_fallocate_wrapper)
-   regs_to_64  x2, x2, x3
-   regs_to_64  x3, x4, x5
-   b   sys_fallocate
-ENDPROC(compat_sys_fallocate_wrapper)
diff --git a/arch/arm64/kernel/entry32_common.S 
b/arch/arm64/kernel/entry32_common.S
new file mode 100644
index 000..261cd97
--- /dev/null
+++ b/arch/arm64/kernel/entry32_common.S
@@ -0,0 +1,93 @@
+/*
+ * Compat system call wrappers
+ *
+ * Copyright (C) 2012 ARM Ltd.
+ * Authors: Will Deacon 
+ * Catalin Marinas 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * Note: off_4k (w5) is always in units of 4K. If we can't do the
+ * requested offset because it is not page-aligned, we return -EINVAL.
+ */
+ENTRY(compat_sys_mmap2_wrapper)
+#if PAGE_SHIFT > 12
+   tst w5, #~PAGE_MASK >> 12
+   b.ne1f
+   lsr w5, w5, #PAGE_SHIFT - 12
+#endif
+   b   sys_mmap_pgoff
+1: mov x0, #-EINVAL
+   ret
+ENDPROC(compat_sys_mmap2_wrapper)
+
+/*
+ * Wrappers for AArch32 syscalls that either take 64-bit parameters
+ * in registers or that take 32-bit parameters 

[PATCH 04/18] arm64: rename COMPAT to AARCH32_EL0 in Kconfig

2016-08-17 Thread Yury Norov
From: Andrew Pinski 

In this patchset  ILP32 ABI support is added. Additionally to AARCH32,
which is binary-compatible with ARM, ILP32 is (mostly) ABI-compatible.

>From now, AARCH32_EL0 (former COMPAT) config option means the support of
AARCH32 userspace, ARM64_ILP32 - support of ILP32 ABI (see next patches),
and COMPAT indicates that one of them, or both, is enabled.

Where needed, CONFIG_COMPAT is changed over to use CONFIG_AARCH32_EL0 instead

Reviewed-by: David Daney 
Signed-off-by: Andrew Pinski 
Signed-off-by: Philipp Tomsich 
Signed-off-by: Christoph Muellner 
Signed-off-by: Bamvor Jian Zhang 
Signed-off-by: Yury Norov 
---
 arch/arm64/Kconfig   | 10 --
 arch/arm64/include/asm/fpsimd.h  |  2 +-
 arch/arm64/include/asm/hwcap.h   |  4 ++--
 arch/arm64/include/asm/processor.h   |  6 +++---
 arch/arm64/include/asm/ptrace.h  |  2 +-
 arch/arm64/include/asm/signal32.h|  6 --
 arch/arm64/include/asm/unistd.h  |  2 +-
 arch/arm64/kernel/Makefile   |  2 +-
 arch/arm64/kernel/asm-offsets.c  |  2 +-
 arch/arm64/kernel/cpufeature.c   |  8 
 arch/arm64/kernel/cpuinfo.c  | 20 +++-
 arch/arm64/kernel/entry.S|  6 +++---
 arch/arm64/kernel/head.S |  2 +-
 arch/arm64/kernel/ptrace.c   |  8 
 arch/arm64/kernel/traps.c|  2 +-
 arch/arm64/kernel/vdso.c |  4 ++--
 drivers/clocksource/arm_arch_timer.c |  2 +-
 17 files changed, 49 insertions(+), 39 deletions(-)

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index bc3f00f..08ca1cb 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -394,7 +394,7 @@ config ARM64_ERRATUM_834220
 
 config ARM64_ERRATUM_845719
bool "Cortex-A53: 845719: a load might read incorrect data"
-   depends on COMPAT
+   depends on AARCH32_EL0
default y
help
  This option adds an alternative code sequence to work around ARM
@@ -720,7 +720,7 @@ config FORCE_MAX_ZONEORDER
 
 menuconfig ARMV8_DEPRECATED
bool "Emulate deprecated/obsolete ARMv8 instructions"
-   depends on COMPAT
+   depends on AARCH32_EL0
help
  Legacy software support may require certain instructions
  that have been deprecated or obsoleted in the architecture.
@@ -990,8 +990,14 @@ menu "Userspace binary formats"
 source "fs/Kconfig.binfmt"
 
 config COMPAT
+   bool
+   depends on AARCH32_EL0
+
+config AARCH32_EL0
bool "Kernel support for 32-bit EL0"
+   def_bool y
depends on ARM64_4K_PAGES || EXPERT
+   select COMPAT
select COMPAT_BINFMT_ELF
select HAVE_UID16
select OLD_SIGSUSPEND3
diff --git a/arch/arm64/include/asm/fpsimd.h b/arch/arm64/include/asm/fpsimd.h
index 50f559f..63b19f1 100644
--- a/arch/arm64/include/asm/fpsimd.h
+++ b/arch/arm64/include/asm/fpsimd.h
@@ -52,7 +52,7 @@ struct fpsimd_partial_state {
 };
 
 
-#if defined(__KERNEL__) && defined(CONFIG_COMPAT)
+#if defined(__KERNEL__) && defined(CONFIG_AARCH32_EL0)
 /* Masks for extracting the FPSR and FPCR from the FPSCR */
 #define VFP_FPSCR_STAT_MASK0xf89f
 #define VFP_FPSCR_CTRL_MASK0x07f79f00
diff --git a/arch/arm64/include/asm/hwcap.h b/arch/arm64/include/asm/hwcap.h
index 400b80b..2c7fc5d 100644
--- a/arch/arm64/include/asm/hwcap.h
+++ b/arch/arm64/include/asm/hwcap.h
@@ -46,7 +46,7 @@
  */
 #define ELF_HWCAP  (elf_hwcap)
 
-#ifdef CONFIG_COMPAT
+#ifdef CONFIG_AARCH32_EL0
 #define COMPAT_ELF_HWCAP   (compat_elf_hwcap)
 #define COMPAT_ELF_HWCAP2  (compat_elf_hwcap2)
 extern unsigned int compat_elf_hwcap, compat_elf_hwcap2;
@@ -54,7 +54,7 @@ extern unsigned int compat_elf_hwcap, compat_elf_hwcap2;
 
 enum {
CAP_HWCAP = 1,
-#ifdef CONFIG_COMPAT
+#ifdef CONFIG_AARCH32_EL0
CAP_COMPAT_HWCAP,
CAP_COMPAT_HWCAP2,
 #endif
diff --git a/arch/arm64/include/asm/processor.h 
b/arch/arm64/include/asm/processor.h
index ace0a96..c489317 100644
--- a/arch/arm64/include/asm/processor.h
+++ b/arch/arm64/include/asm/processor.h
@@ -81,7 +81,7 @@ struct cpu_context {
 struct thread_struct {
struct cpu_context  cpu_context;/* cpu context */
unsigned long   tp_value;   /* TLS register */
-#ifdef CONFIG_COMPAT
+#ifdef CONFIG_AARCH32_EL0
unsigned long   tp2_value;
 #endif
struct fpsimd_state fpsimd_state;
@@ -90,7 +90,7 @@ struct thread_struct {
struct debug_info   debug;  /* debugging */
 };
 
-#ifdef CONFIG_COMPAT
+#ifdef CONFIG_AARCH32_EL0
 #define task_user_tls(t)   \
 ({ \
unsigned long *__tls;  

[RFC2 nowrap: PATCH v7 00/18] ILP32 for ARM64

2016-08-17 Thread Yury Norov
This series enables aarch64 with ilp32 mode, and as supporting work,
introduces ARCH_32BIT_OFF_T configuration option that is enabled for
existing 32-bit architectures but disabled for new arches (so 64-bit
off_t is is used by new userspace).

This version is based on kernel v4.8-rc2.
It works with glibc-2.23, and tested with LTP.

This is RFC because there is still no solid understanding what type of registers
top-halves delousing we prefer. In this patchset, w0-w7 are cleared for each
syscall in assembler entry. The alternative approach is in introducing compat
wrappers which is little faster for natively routed syscalls (~2.6% for syscall
with no payload) but much more complicated.

There's no major changes here comparing to previous submission, mostly
the rebase to current master. All changes in details are listed below.
No additional regression is observed since previous submission.

Patch 1 may be applied separately from other patches of series.

v3: https://lkml.org/lkml/2014/9/3/704
v4: https://lkml.org/lkml/2015/4/13/691
v5: https://lkml.org/lkml/2015/9/29/911
v6: https://lkml.org/lkml/2016/5/23/661
v7: RFC nowrap: https://lkml.org/lkml/2016/6/17/990
v7: RFC2 nowrap:
 - rebased on kernel 4.8-rc2;
 - setrlimit(), getrlimit() are handled by non-compat handlers to follow 
   switching rlim_t to 64-bit in glibc, as pointed by Andreas Shwab;
 - fixed {GET,SET}SIGMASK handling in ptrace(), as pointed by Zhou Chengming;
 - removed put_sig{set,get)_t duplication;
 - patches 1 and 2 from previous submission are joined, missed chunk restored,
   found by by Andreas Shwab.

Links:
Kernel: https://github.com/norov/linux/commits/ilp32-4.8
glibc:  https://github.com/norov/glibc/commits/ilp32-2.24-dev

Andrew Pinski (6):
  arm64: ensure the kernel is compiled for LP64
  arm64: rename COMPAT to AARCH32_EL0 in Kconfig
  arm64:uapi: set __BITS_PER_LONG correctly for ILP32 and LP64
  arm64: ilp32: add sys_ilp32.c and a separate table (in entry.S) to use
it
  arm64: ilp32: introduce ilp32-specific handlers for sigframe and
ucontext
  arm64:ilp32: add ARM64_ILP32 to Kconfig

Philipp Tomsich (1):
  arm64:ilp32: add vdso-ilp32 and use for signal return

Yury Norov (11):
  32-bit ABI: introduce ARCH_32BIT_OFF_T config option
  arm64: ilp32: add documentation on the ILP32 ABI for ARM64
  thread: move thread bits accessors to separated file
  arm64: introduce is_a32_task and is_a32_thread (for AArch32 compat)
  arm64: ilp32: add is_ilp32_compat_{task,thread} and TIF_32BIT_AARCH64
  arm64: introduce binfmt_elf32.c
  arm64: ilp32: introduce binfmt_ilp32.c
  arm64: ilp32: share aarch32 syscall handlers
  arm64: signal: share lp64 signal routines to ilp32
  arm64: signal32: move ilp32 and aarch32 common code to separated file
  arm64: ptrace: handle ptrace_request differently for aarch32 and ilp32

 Documentation/arm64/ilp32.txt |  54 
 arch/Kconfig  |   4 +
 arch/arc/Kconfig  |   1 +
 arch/arm/Kconfig  |   1 +
 arch/arm64/Kconfig|  19 ++-
 arch/arm64/Makefile   |   5 +
 arch/arm64/include/asm/compat.h   |  19 +--
 arch/arm64/include/asm/elf.h  |  29 +++--
 arch/arm64/include/asm/fpsimd.h   |   2 +-
 arch/arm64/include/asm/ftrace.h   |   2 +-
 arch/arm64/include/asm/hwcap.h|   6 +-
 arch/arm64/include/asm/is_compat.h|  90 ++
 arch/arm64/include/asm/memory.h   |   5 +-
 arch/arm64/include/asm/processor.h|  11 +-
 arch/arm64/include/asm/ptrace.h   |   2 +-
 arch/arm64/include/asm/signal32.h |   9 +-
 arch/arm64/include/asm/signal32_common.h  |  28 +
 arch/arm64/include/asm/signal_common.h|  33 +
 arch/arm64/include/asm/signal_ilp32.h |  38 ++
 arch/arm64/include/asm/syscall.h  |   2 +-
 arch/arm64/include/asm/thread_info.h  |   4 +-
 arch/arm64/include/asm/unistd.h   |   6 +-
 arch/arm64/include/asm/unistd32.h |   2 +-
 arch/arm64/include/asm/vdso.h |   6 +
 arch/arm64/include/uapi/asm/bitsperlong.h |   9 +-
 arch/arm64/kernel/Makefile|  18 ++-
 arch/arm64/kernel/asm-offsets.c   |   9 +-
 arch/arm64/kernel/binfmt_elf32.c  |  31 +
 arch/arm64/kernel/binfmt_ilp32.c  |  96 +++
 arch/arm64/kernel/cpufeature.c|   8 +-
 arch/arm64/kernel/cpuinfo.c   |  20 +--
 arch/arm64/kernel/entry.S |  34 -
 arch/arm64/kernel/entry32.S   |  65 --
 arch/arm64/kernel/entry32_common.S|  93 ++
 arch/arm64/kernel/entry_ilp32.S   |  23 
 arch/arm64/kernel/head.S  |   2 +-
 arch/arm64/kernel/hw_breakpoint.c |  10 +-
 

[PATCH 14/18] arm64: signal32: move ilp32 and aarch32 common code to separated file

2016-08-17 Thread Yury Norov
Signed-off-by: Yury Norov 
---
 arch/arm64/include/asm/signal32.h|   3 +
 arch/arm64/include/asm/signal32_common.h |  28 +++
 arch/arm64/kernel/Makefile   |   2 +-
 arch/arm64/kernel/signal32.c | 107 
 arch/arm64/kernel/signal32_common.c  | 136 +++
 5 files changed, 168 insertions(+), 108 deletions(-)
 create mode 100644 arch/arm64/include/asm/signal32_common.h
 create mode 100644 arch/arm64/kernel/signal32_common.c

diff --git a/arch/arm64/include/asm/signal32.h 
b/arch/arm64/include/asm/signal32.h
index e68fcce..1c4ede7 100644
--- a/arch/arm64/include/asm/signal32.h
+++ b/arch/arm64/include/asm/signal32.h
@@ -13,6 +13,9 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see .
  */
+
+#include 
+
 #ifndef __ASM_SIGNAL32_H
 #define __ASM_SIGNAL32_H
 
diff --git a/arch/arm64/include/asm/signal32_common.h 
b/arch/arm64/include/asm/signal32_common.h
new file mode 100644
index 000..e3e2d01
--- /dev/null
+++ b/arch/arm64/include/asm/signal32_common.h
@@ -0,0 +1,28 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+#ifndef __ASM_SIGNAL32_COMMON_H
+#define __ASM_SIGNAL32_COMMON_H
+
+#ifdef CONFIG_COMPAT
+
+int copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from);
+int copy_siginfo_from_user32(siginfo_t *to, compat_siginfo_t __user *from);
+
+int put_sigset_t(compat_sigset_t __user *uset, sigset_t *set);
+int get_sigset_t(sigset_t *set, const compat_sigset_t __user *uset);
+
+#endif /* CONFIG_COMPAT*/
+
+#endif /* __ASM_SIGNAL32_COMMON_H */
+
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 36257b7..20e8e66 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -28,7 +28,7 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
 arm64-obj-$(CONFIG_AARCH32_EL0)+= sys32.o kuser32.o signal32.o 
\
   sys_compat.o entry32.o binfmt_elf32.o
 arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o sys_ilp32.o
-arm64-obj-$(CONFIG_COMPAT) += entry32_common.o
+arm64-obj-$(CONFIG_COMPAT) += entry32_common.o signal32_common.o
 arm64-obj-$(CONFIG_FUNCTION_TRACER)+= ftrace.o entry-ftrace.o
 arm64-obj-$(CONFIG_MODULES)+= arm64ksyms.o module.o
 arm64-obj-$(CONFIG_ARM64_MODULE_PLTS)  += module-plts.o
diff --git a/arch/arm64/kernel/signal32.c b/arch/arm64/kernel/signal32.c
index b7063de..f2c1a38 100644
--- a/arch/arm64/kernel/signal32.c
+++ b/arch/arm64/kernel/signal32.c
@@ -103,113 +103,6 @@ struct compat_rt_sigframe {
 
 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
 
-static inline int put_sigset_t(compat_sigset_t __user *uset, sigset_t *set)
-{
-   compat_sigset_t cset;
-
-   cset.sig[0] = set->sig[0] & 0xull;
-   cset.sig[1] = set->sig[0] >> 32;
-
-   return copy_to_user(uset, , sizeof(*uset));
-}
-
-static inline int get_sigset_t(sigset_t *set,
-  const compat_sigset_t __user *uset)
-{
-   compat_sigset_t s32;
-
-   if (copy_from_user(, uset, sizeof(*uset)))
-   return -EFAULT;
-
-   set->sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
-   return 0;
-}
-
-int copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from)
-{
-   int err;
-
-   if (!access_ok(VERIFY_WRITE, to, sizeof(*to)))
-   return -EFAULT;
-
-   /* If you change siginfo_t structure, please be sure
-* this code is fixed accordingly.
-* It should never copy any pad contained in the structure
-* to avoid security leaks, but must copy the generic
-* 3 ints plus the relevant union member.
-* This routine must convert siginfo from 64bit to 32bit as well
-* at the same time.
-*/
-   err = __put_user(from->si_signo, >si_signo);
-   err |= __put_user(from->si_errno, >si_errno);
-   err |= __put_user((short)from->si_code, >si_code);
-   if (from->si_code < 0)
-   err |= __copy_to_user(>_sifields._pad, 
>_sifields._pad,
- SI_PAD_SIZE);
-   else switch (from->si_code & __SI_MASK) {
-   case __SI_KILL:
-   err |= __put_user(from->si_pid, >si_pid);
-   err |= 

[PATCH 15/18] arm64: ilp32: introduce ilp32-specific handlers for sigframe and ucontext

2016-08-17 Thread Yury Norov
From: Andrew Pinski 

ILP32 uses AARCH32 compat structures and syscall handlers for signals.
But ILP32 struct rt_sigframe  and ucontext differs from both LP64 and
AARCH32. So some specific mechanism is needed to take care of it.

Signed-off-by: Andrew Pinski 
Signed-off-by: Yury Norov 
---
 arch/arm64/include/asm/signal_ilp32.h |  38 
 arch/arm64/kernel/Makefile|   3 +-
 arch/arm64/kernel/entry_ilp32.S   |  23 +
 arch/arm64/kernel/signal.c|   3 +
 arch/arm64/kernel/signal_ilp32.c  | 171 ++
 5 files changed, 237 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm64/include/asm/signal_ilp32.h
 create mode 100644 arch/arm64/kernel/entry_ilp32.S
 create mode 100644 arch/arm64/kernel/signal_ilp32.c

diff --git a/arch/arm64/include/asm/signal_ilp32.h 
b/arch/arm64/include/asm/signal_ilp32.h
new file mode 100644
index 000..3c6d737
--- /dev/null
+++ b/arch/arm64/include/asm/signal_ilp32.h
@@ -0,0 +1,38 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#include 
+#include 
+
+#ifndef __ASM_SIGNAL_ILP32_H
+#define __ASM_SIGNAL_ILP32_H
+
+#ifdef CONFIG_ARM64_ILP32
+
+#include 
+
+int ilp32_setup_rt_frame(int usig, struct ksignal *ksig, sigset_t *set,
+ struct pt_regs *regs);
+
+#else
+
+static inline int ilp32_setup_rt_frame(int usig, struct ksignal *ksig, 
sigset_t *set,
+ struct pt_regs *regs)
+{
+   return -ENOSYS;
+}
+
+#endif /* CONFIG_ARM64_ILP32 */
+
+#endif /* __ASM_SIGNAL_ILP32_H */
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 20e8e66..7038ffb 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -27,7 +27,8 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
 
 arm64-obj-$(CONFIG_AARCH32_EL0)+= sys32.o kuser32.o signal32.o 
\
   sys_compat.o entry32.o binfmt_elf32.o
-arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o sys_ilp32.o
+arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o sys_ilp32.o   
\
+  signal_ilp32.o entry_ilp32.o
 arm64-obj-$(CONFIG_COMPAT) += entry32_common.o signal32_common.o
 arm64-obj-$(CONFIG_FUNCTION_TRACER)+= ftrace.o entry-ftrace.o
 arm64-obj-$(CONFIG_MODULES)+= arm64ksyms.o module.o
diff --git a/arch/arm64/kernel/entry_ilp32.S b/arch/arm64/kernel/entry_ilp32.S
new file mode 100644
index 000..5063172
--- /dev/null
+++ b/arch/arm64/kernel/entry_ilp32.S
@@ -0,0 +1,23 @@
+/*
+ * ILP32 system call wrappers
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#include 
+
+ENTRY(ilp32_sys_rt_sigreturn_wrapper)
+   mov x0, sp
+   b   ilp32_sys_rt_sigreturn
+ENDPROC(ilp32_sys_rt_sigreturn_wrapper)
+
diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c
index 5c73864..241bfeb 100644
--- a/arch/arm64/kernel/signal.c
+++ b/arch/arm64/kernel/signal.c
@@ -35,6 +35,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define RT_SIGFRAME_FP_POS (offsetof(struct rt_sigframe, sig)  \
+ offsetof(struct sigframe, fp))
@@ -325,6 +326,8 @@ static void handle_signal(struct ksignal *ksig, struct 
pt_regs *regs)
ret = compat_setup_rt_frame(usig, ksig, oldset, regs);
else
ret = compat_setup_frame(usig, ksig, oldset, regs);
+   } else if (is_ilp32_compat_task()) {
+   ret = ilp32_setup_rt_frame(usig, ksig, oldset, regs);
} else {
ret = setup_rt_frame(usig, ksig, oldset, regs);
}
diff --git a/arch/arm64/kernel/signal_ilp32.c b/arch/arm64/kernel/signal_ilp32.c
new file mode 100644
index 000..7cc9122
--- /dev/null
+++ 

[PATCH 08/18] arm64: ilp32: add is_ilp32_compat_{task,thread} and TIF_32BIT_AARCH64

2016-08-17 Thread Yury Norov
ILP32 tasks are needed to be distinguished from lp64 and aarch32.
This patch adds helper functions is_ilp32_compat_{task,thread} and
thread flag TIF_32BIT_AARCH64 to address it. This is a preparation
for following patches in ilp32 patchset.

For consistency, SET_PERSONALITY is changed here accordingly.

Signed-off-by: Andrew Pinski 
Signed-off-by: Philipp Tomsich 
Signed-off-by: Christoph Muellner 
Signed-off-by: Yury Norov 
Reviewed-by: David Daney 
---
 arch/arm64/include/asm/elf.h | 13 +++--
 arch/arm64/include/asm/is_compat.h   | 30 --
 arch/arm64/include/asm/thread_info.h |  2 ++
 3 files changed, 41 insertions(+), 4 deletions(-)

diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h
index 6a9049b..f259fe8 100644
--- a/arch/arm64/include/asm/elf.h
+++ b/arch/arm64/include/asm/elf.h
@@ -142,7 +142,11 @@ typedef struct user_fpsimd_state elf_fpregset_t;
  */
 #define ELF_PLAT_INIT(_r, load_addr)   (_r)->regs[0] = 0
 
-#define SET_PERSONALITY(ex)clear_thread_flag(TIF_32BIT);
+#define SET_PERSONALITY(ex)\
+do {   \
+   clear_thread_flag(TIF_32BIT_AARCH64);   \
+   clear_thread_flag(TIF_32BIT);   \
+} while (0)
 
 /* update AT_VECTOR_SIZE_ARCH if the number of NEW_AUX_ENT entries changes */
 #define ARCH_DLINFO\
@@ -183,7 +187,12 @@ typedef compat_elf_greg_t  
compat_elf_gregset_t[COMPAT_ELF_NGREG];
 ((x)->e_flags & EF_ARM_EABI_MASK))
 
 #define compat_start_threadcompat_start_thread
-#define COMPAT_SET_PERSONALITY(ex) set_thread_flag(TIF_32BIT);
+#define COMPAT_SET_PERSONALITY(ex) \
+do {   \
+   clear_thread_flag(TIF_32BIT_AARCH64);   \
+   set_thread_flag(TIF_32BIT); \
+} while (0)
+
 #define COMPAT_ARCH_DLINFO
 extern int aarch32_setup_vectors_page(struct linux_binprm *bprm,
  int uses_interp);
diff --git a/arch/arm64/include/asm/is_compat.h 
b/arch/arm64/include/asm/is_compat.h
index 8dba5ca..7726beb 100644
--- a/arch/arm64/include/asm/is_compat.h
+++ b/arch/arm64/include/asm/is_compat.h
@@ -45,18 +45,44 @@ static inline int is_a32_compat_thread(struct thread_info 
*thread)
 
 #endif /* CONFIG_AARCH32_EL0 */
 
+#ifdef CONFIG_ARM64_ILP32
+
+static inline int is_ilp32_compat_task(void)
+{
+   return test_thread_flag(TIF_32BIT_AARCH64);
+}
+
+static inline int is_ilp32_compat_thread(struct thread_info *thread)
+{
+   return test_ti_thread_flag(thread, TIF_32BIT_AARCH64);
+}
+
+#else
+
+static inline int is_ilp32_compat_task(void)
+{
+   return 0;
+}
+
+static inline int is_ilp32_compat_thread(struct thread_info *thread)
+{
+   return 0;
+}
+
+#endif /* CONFIG_ARM64_ILP32 */
+
 #ifdef CONFIG_COMPAT
 
 static inline int is_compat_task(void)
 {
-   return is_a32_compat_task();
+   return is_a32_compat_task() || is_ilp32_compat_task();
 }
 
 #endif /* CONFIG_COMPAT */
 
 static inline int is_compat_thread(struct thread_info *thread)
 {
-   return is_a32_compat_thread(thread);
+   return is_a32_compat_thread(thread) || is_ilp32_compat_thread(thread);
 }
 
 
diff --git a/arch/arm64/include/asm/thread_info.h 
b/arch/arm64/include/asm/thread_info.h
index 4daa559..8802645 100644
--- a/arch/arm64/include/asm/thread_info.h
+++ b/arch/arm64/include/asm/thread_info.h
@@ -119,6 +119,7 @@ static inline struct thread_info *current_thread_info(void)
 #define TIF_RESTORE_SIGMASK20
 #define TIF_SINGLESTEP 21
 #define TIF_32BIT  22  /* AARCH32 process */
+#define TIF_32BIT_AARCH64  23  /* 32 bit process on AArch64(ILP32) */
 
 #define _TIF_SIGPENDING(1 << TIF_SIGPENDING)
 #define _TIF_NEED_RESCHED  (1 << TIF_NEED_RESCHED)
@@ -130,6 +131,7 @@ static inline struct thread_info *current_thread_info(void)
 #define _TIF_SYSCALL_TRACEPOINT(1 << TIF_SYSCALL_TRACEPOINT)
 #define _TIF_SECCOMP   (1 << TIF_SECCOMP)
 #define _TIF_32BIT (1 << TIF_32BIT)
+#define _TIF_32BIT_AARCH64 (1 << TIF_32BIT_AARCH64)
 
 #define _TIF_WORK_MASK (_TIF_NEED_RESCHED | _TIF_SIGPENDING | \
 _TIF_NOTIFY_RESUME | _TIF_FOREIGN_FPSTATE)
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 10/18] arm64: ilp32: introduce binfmt_ilp32.c

2016-08-17 Thread Yury Norov
binfmt_ilp32.c is needed to handle ILP32 binaries

Signed-off-by: Yury Norov 
---
 arch/arm64/include/asm/elf.h |  6 +++
 arch/arm64/kernel/Makefile   |  1 +
 arch/arm64/kernel/binfmt_ilp32.c | 96 
 3 files changed, 103 insertions(+)
 create mode 100644 arch/arm64/kernel/binfmt_ilp32.c

diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h
index f259fe8..be29dde 100644
--- a/arch/arm64/include/asm/elf.h
+++ b/arch/arm64/include/asm/elf.h
@@ -175,10 +175,16 @@ extern int arch_setup_additional_pages(struct 
linux_binprm *bprm,
 
 #define COMPAT_ELF_ET_DYN_BASE (2 * TASK_SIZE_32 / 3)
 
+#ifndef USE_AARCH64_GREG
 /* AArch32 registers. */
 #define COMPAT_ELF_NGREG   18
 typedef unsigned int   compat_elf_greg_t;
 typedef compat_elf_greg_t  compat_elf_gregset_t[COMPAT_ELF_NGREG];
+#else /* AArch64 registers for AARCH64/ILP32 */
+#define COMPAT_ELF_NGREG   ELF_NGREG
+#define compat_elf_greg_t  elf_greg_t
+#define compat_elf_gregset_t   elf_gregset_t
+#endif
 
 /* AArch32 EABI. */
 #define EF_ARM_EABI_MASK   0xff00
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 949187c..9b6c324 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -27,6 +27,7 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
 
 arm64-obj-$(CONFIG_AARCH32_EL0)+= sys32.o kuser32.o signal32.o 
\
   sys_compat.o entry32.o binfmt_elf32.o
+arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o
 arm64-obj-$(CONFIG_FUNCTION_TRACER)+= ftrace.o entry-ftrace.o
 arm64-obj-$(CONFIG_MODULES)+= arm64ksyms.o module.o
 arm64-obj-$(CONFIG_ARM64_MODULE_PLTS)  += module-plts.o
diff --git a/arch/arm64/kernel/binfmt_ilp32.c b/arch/arm64/kernel/binfmt_ilp32.c
new file mode 100644
index 000..416b3f5
--- /dev/null
+++ b/arch/arm64/kernel/binfmt_ilp32.c
@@ -0,0 +1,96 @@
+/*
+ * Support for ILP32 Linux/aarch64 ELF binaries.
+ */
+#define USE_AARCH64_GREG
+
+#include 
+#include 
+
+#undef ELF_CLASS
+#define ELF_CLASS  ELFCLASS32
+
+#undef elfhdr
+#undef elf_phdr
+#undef elf_shdr
+#undef elf_note
+#undef elf_addr_t
+#define elfhdr elf32_hdr
+#define elf_phdr   elf32_phdr
+#define elf_shdr   elf32_shdr
+#define elf_note   elf32_note
+#define elf_addr_t Elf32_Addr
+
+/*
+ * Some data types as stored in coredump.
+ */
+#define user_long_tcompat_long_t
+#define user_siginfo_t compat_siginfo_t
+#define copy_siginfo_to_user   copy_siginfo_to_user32
+
+/*
+ * The machine-dependent core note format types are defined in 
elfcore-compat.h,
+ * which requires asm/elf.h to define compat_elf_gregset_t et al.
+ */
+#define elf_prstatus   compat_elf_prstatus
+#define elf_prpsinfo   compat_elf_prpsinfo
+
+/*
+ * Compat version of cputime_to_compat_timeval, perhaps this
+ * should be an inline in .
+ */
+static void cputime_to_compat_timeval(const cputime_t cputime,
+ struct compat_timeval *value)
+{
+   struct timeval tv;
+   cputime_to_timeval(cputime, );
+   value->tv_sec = tv.tv_sec;
+   value->tv_usec = tv.tv_usec;
+}
+
+#undef cputime_to_timeval
+#define cputime_to_timeval cputime_to_compat_timeval
+
+/* AARCH64 ILP32 EABI. */
+#undef elf_check_arch
+#define elf_check_arch(x)  (((x)->e_machine == EM_AARCH64) \
+   && (x)->e_ident[EI_CLASS] == ELFCLASS32)
+
+#undef SET_PERSONALITY
+#define SET_PERSONALITY(ex)\
+do {   \
+   set_thread_flag(TIF_32BIT_AARCH64); \
+   clear_thread_flag(TIF_32BIT);   \
+} while (0)
+
+#undef ARCH_DLINFO
+#define ARCH_DLINFO\
+do {   \
+   NEW_AUX_ENT(AT_SYSINFO_EHDR,\
+   (elf_addr_t)(long)current->mm->context.vdso);   \
+} while (0)
+
+#undef ELF_PLATFORM
+#ifdef __AARCH64EB__
+#define ELF_PLATFORM   ("aarch64_be:ilp32")
+#else
+#define ELF_PLATFORM   ("aarch64:ilp32")
+#endif
+
+#undef ELF_ET_DYN_BASE
+#define ELF_ET_DYN_BASE COMPAT_ELF_ET_DYN_BASE
+
+#undef ELF_HWCAP
+#undef ELF_HWCAP2
+#define ELF_HWCAP  ((u32) elf_hwcap)
+#define ELF_HWCAP2 ((u32) (elf_hwcap >> 32))
+
+/*
+ * Rename a few of the symbols that binfmt_elf.c will define.
+ * These are all local so the names don't really matter, but it
+ * might make some debugging less confusing not to duplicate them.
+ */
+#define elf_format compat_elf_format
+#define init_elf_binfmtinit_compat_elf_binfmt
+#define exit_elf_binfmt  

[PATCH 05/18] arm64:uapi: set __BITS_PER_LONG correctly for ILP32 and LP64

2016-08-17 Thread Yury Norov
From: Andrew Pinski 

Define __BITS_PER_LONG depending on the ABI used (i.e. check whether
__ILP32__ or __LP64__ is defined).  This is necessary for glibc to
determine the appropriate type definitions for the system call interface.

Signed-off-by: Andrew Pinski 
Signed-off-by: Philipp Tomsich 
Signed-off-by: Christoph Muellner 
Signed-off-by: Yury Norov 
Reviewed-by: David Daney 
---
 arch/arm64/include/uapi/asm/bitsperlong.h | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/include/uapi/asm/bitsperlong.h 
b/arch/arm64/include/uapi/asm/bitsperlong.h
index fce9c29..4265243 100644
--- a/arch/arm64/include/uapi/asm/bitsperlong.h
+++ b/arch/arm64/include/uapi/asm/bitsperlong.h
@@ -16,7 +16,14 @@
 #ifndef __ASM_BITSPERLONG_H
 #define __ASM_BITSPERLONG_H
 
-#define __BITS_PER_LONG 64
+#if defined(__LP64__)
+/* Assuming __LP64__ will be defined for native ELF64's and not for ILP32. */
+#  define __BITS_PER_LONG 64
+#elif defined(__ILP32__)
+#  define __BITS_PER_LONG 32
+#else
+#  error "Neither LP64 nor ILP32: unsupported ABI in asm/bitsperlong.h"
+#endif
 
 #include 
 
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 0/7] doc-rst: sphinx sub-folders & parseheaders directive

2016-08-17 Thread Daniel Vetter
On Wed, Aug 17, 2016 at 7:44 AM, Markus Heiser
 wrote:
 - Along those lines, is parse-header the right name for this thing?
 "Parsing" isn't necessarily the goal of somebody who uses this directive,
 right?  They want to extract documentation information.  Can we come up
 with a better name?
>>>
>>> Mauro, what is your suggestion and how would we go on in this topic?
>>
>> Maybe we could call it as: "include-c-code-block" or something similar.
>
> Hmm, that's not any better, IMHO ... there is a 'parsed-literal' so, what's
> wrong with a 'parsed-header' directive or for my sake ' parse-c-header'.
> IMHO it is very unspecific what this directive does and it might be changed in
> the near future if someone (e.g. Daniel [1]) see more use cases then the one 
> yet.
>
> [1] https://www.mail-archive.com/linux-media%40vger.kernel.org/msg101129.html

I was wondering more whether we should uplift this to be the canonical
way to document uapi headers. Then we could call it kernel-uapi-header
or whatever, along the lines of our kernel-doc directive. But really
this was just an idea, atm it's a media exclusive feature of our doc
toolchain.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 4/4] zswap: Update document with sharing of duplicate pages feature

2016-08-17 Thread Srividya Desireddy
From: Srividya Desireddy 
Date: Wed, 17 Aug 2016 14:34:41 +0530
Subject: [PATCH 4/4] zswap: Update document with sharing of duplicate pages
 feature

Updated zswap document with details on the sharing of duplicate swap pages
feature. The usage of zswap.same_page_sharing module parameter is
explained.

Signed-off-by: Srividya Desireddy 
---
 Documentation/vm/zswap.txt |   18 ++
 1 file changed, 18 insertions(+)

diff --git a/Documentation/vm/zswap.txt b/Documentation/vm/zswap.txt
index 89fff7d..cf11807 100644
--- a/Documentation/vm/zswap.txt
+++ b/Documentation/vm/zswap.txt
@@ -98,5 +98,23 @@ request is made for a page in an old zpool, it is 
uncompressed using its
 original compressor.  Once all pages are removed from an old zpool, the zpool
 and its compressor are freed.
 
+Some of the pages swapped to zswap have same content as that of pages already
+stored in zswap. These pages are compressed and stored in the zpool memory.
+Same page sharing feature enables the duplicate pages to share same compressed
+zpool memory. This helps in reducing the zpool memory allocated by zswap to
+store compressed pages.
+
+Same page sharing feature is disabled by default and can be enabled at boot
+time by setting the "same_page_sharing" attribute to 1 at boot time. ie:
+zswap.same_page_sharing=1. It can also be enabled and disabled at runtime
+using the sysfs "same_page_sharing" attribute, e.g.
+
+echo 1 > /sys/module/zswap/parameters/same_page_sharing
+
+When zswap same page sharing is disabled at runtime it will stop sharing the
+new duplicate pages that are being swapped out. However, the existing duplicate
+pages will keep sharing the compressed memory pool until they are swapped in or
+invalidated.
+
 A debugfs interface is provided for various statistic about pool size, number
 of pages stored, and various counters for the reasons pages are rejected.
-- 
1.7.9.5



Re: [PACTH v2 0/3] Implement /proc//totmaps

2016-08-17 Thread Jann Horn
On Wed, Aug 17, 2016 at 10:22:00AM +0200, Michal Hocko wrote:
> On Tue 16-08-16 12:46:51, Robert Foss wrote:
> [...]
> > $ /usr/bin/time -v -p zsh -c "repeat 25 { awk '/^Rss/{rss+=\$2}
> > /^Pss/{pss+=\$2} END {printf \"rss:%d pss:%d\n\", rss, pss}\'
> > /proc/5025/smaps }"
> > [...]
> > Command being timed: "zsh -c repeat 25 { awk '/^Rss/{rss+=$2}
> > /^Pss/{pss+=$2} END {printf "rss:%d pss:%d\n", rss, pss}\' /proc/5025/smaps
> > }"
> > User time (seconds): 0.37
> > System time (seconds): 0.45
> > Percent of CPU this job got: 92%
> > Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.89
> 
> This is really unexpected. Where is the user time spent? Anyway, rather
> than measuring some random processes I've tried to measure something
> resembling the worst case. So I've created a simple program to mmap as
> much as possible:
> 
> #include 
> #include 
> #include 
> #include 
> int main()
> {
>   while (mmap(NULL, 4096, PROT_READ|PROT_WRITE, 
> MAP_ANON|MAP_SHARED|MAP_POPULATE, -1, 0) != MAP_FAILED)
>   ;
> 
>   printf("pid:%d\n", getpid());
>   pause();
>   return 0;
> }

Ah, nice, that's a reasonable test program. :)


> So with a reasonable user space the parsing is really not all that time
> consuming wrt. smaps handling. That being said I am still very skeptical
> about a dedicated proc file which accomplishes what userspace can done
> in a trivial way.

Now, since your numbers showed that all the time is spent in the kernel,
also create this test program to just read that file over and over again:

$ cat justreadloop.c
#include 
#include 
#include 
#include 
#include 
#include 
#include 

char buf[100];

int main(int argc, char **argv) {
  printf("pid:%d\n", getpid());
  while (1) {
int fd = open(argv[1], O_RDONLY);
if (fd < 0) continue;
if (read(fd, buf, sizeof(buf)) < 0)
  err(1, "read");
close(fd);
  }
}
$ gcc -Wall -o justreadloop justreadloop.c
$ 

Now launch your test:

$ ./mapstuff 
pid:29397

point justreadloop at it:

$ ./justreadloop /proc/29397/smaps
pid:32567

... and then check the performance stats of justreadloop:

# perf top -p 32567

This is what I see:

Samples: 232K of event 'cycles:ppp', Event count (approx.): 60448424325
Overhead  Shared Object Symbol
  30,43%  [kernel]  [k] format_decode
   9,12%  [kernel]  [k] number
   7,66%  [kernel]  [k] vsnprintf
   7,06%  [kernel]  [k] __lock_acquire
   3,23%  [kernel]  [k] lock_release
   2,85%  [kernel]  [k] debug_lockdep_rcu_enabled
   2,25%  [kernel]  [k] skip_atoi
   2,13%  [kernel]  [k] lock_acquire
   2,05%  [kernel]  [k] show_smap

That's at least 30.43% + 9.12% + 7.66% = 47.21% of the task's kernel
time spent on evaluating format strings. The new interface
wouldn't have to spend that much time on format strings because there
isn't so much text to format. (My kernel is built with a
bunch of debug options - the results might look very different on
distro kernels or so, so please try this yourself.)

I guess it could be argued that this is not just a problem with
smaps, but also a problem with format strings (or text-based interfaces
in general) just being slow in general.

(Here is a totally random and crazy thought: Can we put something into
the kernel build process that replaces printf calls that use simple
format strings with equivalent non-printf calls? Move the cost of
evaluating the format string to compile time?)


signature.asc
Description: Digital signature


Re: [PACTH v2 0/3] Implement /proc//totmaps

2016-08-17 Thread Michal Hocko
On Tue 16-08-16 12:46:51, Robert Foss wrote:
[...]
> $ /usr/bin/time -v -p zsh -c "repeat 25 { awk '/^Rss/{rss+=\$2}
> /^Pss/{pss+=\$2} END {printf \"rss:%d pss:%d\n\", rss, pss}\'
> /proc/5025/smaps }"
> [...]
>   Command being timed: "zsh -c repeat 25 { awk '/^Rss/{rss+=$2}
> /^Pss/{pss+=$2} END {printf "rss:%d pss:%d\n", rss, pss}\' /proc/5025/smaps
> }"
>   User time (seconds): 0.37
>   System time (seconds): 0.45
>   Percent of CPU this job got: 92%
>   Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.89

This is really unexpected. Where is the user time spent? Anyway, rather
than measuring some random processes I've tried to measure something
resembling the worst case. So I've created a simple program to mmap as
much as possible:

#include 
#include 
#include 
#include 
int main()
{
while (mmap(NULL, 4096, PROT_READ|PROT_WRITE, 
MAP_ANON|MAP_SHARED|MAP_POPULATE, -1, 0) != MAP_FAILED)
;

printf("pid:%d\n", getpid());
pause();
return 0;
}

so depending on /proc/sys/vm/max_map_count you will get the maximum
possible mmaps. I am using a default so 65k mappings. Then I have
retried your 25x file parsing:
$ cat s.sh
#!/bin/sh

pid=$1
for i in $(seq 25)
do
awk '/^Rss/{rss+=$2} /^Pss/{pss+=$2} END {printf "rss:%d pss:%d\n", 
rss, pss}' /proc/$pid/smaps
done

But I am getting different results from you:
$ awk '/^[0-9a-f]/{print}' /proc/14808/smaps | wc -l
65532
[...]
Command being timed: "sh s.sh 14808"
User time (seconds): 0.00
System time (seconds): 20.10
Percent of CPU this job got: 99%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:20.20

The results are stable when I try multiple times, in fact there
shouldn't be any reason for them not to be. Then I went on to increase
max_map_count to 250k and that behaves consistently:
$ awk '/^[0-9a-f]/{print}' /proc/16093/smaps | wc -l 
250002
[...]
Command being timed: "sh s.sh 16093"
User time (seconds): 0.00
System time (seconds): 77.93
Percent of CPU this job got: 98%
Elapsed (wall clock) time (h:mm:ss or m:ss): 1:19.09

So with a reasonable user space the parsing is really not all that time
consuming wrt. smaps handling. That being said I am still very skeptical
about a dedicated proc file which accomplishes what userspace can done
in a trivial way.
-- 
Michal Hocko
SUSE Labs
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 0/7] doc-rst: sphinx sub-folders & parseheaders directive

2016-08-17 Thread Markus Heiser

Am 17.08.2016 um 07:44 schrieb Markus Heiser :

> 
> @Daniel: I added you to this discussion. May you are interested in, 
> it is about the parse-headers functionality from Mauro.
> 
> Am 16.08.2016 um 20:22 schrieb Mauro Carvalho Chehab :
> 
>> Em Mon, 15 Aug 2016 10:21:07 +0200
>> Markus Heiser  escreveu:
>> 
>>> Am 14.08.2016 um 20:09 schrieb Jonathan Corbet :
> 
> ...
> 
 but stopped at parse-header.
 At this point, I have a few requests.  These are in approximate order of
 decreasing importance, but they're all important, I think.
>> 
>> After writing the PDF support, I'm starting to think that maybe we
>> should migrate the entire functionality to the Sphinx extension.
>> The rationale is that we won't need to be concerned about output
>> specific escape codes there.
> 
> What do you mean with "output specific escape codes"? This: 
> 
> 
> #
> # Add escape codes for special characters
> #
> $data =~ s,([\_\`\*\<\>\&:\/\|]),\\$1,g;
> 
> $data =~ s,DEPRECATED,**DEPRECATED**,g;
> 
> 
> will be resist, even if you implement it in python.
> 
> 
 - The new directive could really use some ... documentation.  Preferably in
 kernel-documentation.rst with the rest.  What is parse-header, how does
 it differ from kernel-doc, why might a kernel developer doing
 documentation want (or not want) to use it?  That's all pretty obscure
 now.  If we want others to jump onto this little bandwagon of ours, we
 need to make sure it's all really clear.  
>>> 
>>> This could be answered by Mauro.
>> 
>> We use it to allow including an entire header file as-is at the
>> documentation, and cross-reference it with the documents.
>> 
>> IMO, this is very useful to document the ioctl UAPI. There, the most
>> important things to be documented are the ioctl themselves. We don't
>> have any way to document via kernel-doc (as they're #define macros).
>> 
>> Also, when documenting an ioctl, we want to document the structures
>> that are used (most media ioctls use a struct instead of a single value).
>> 
>> So, what we do is that we write a proper description for the ioctl and
>> everything related to it outside the source code. As we want to be
>> sure that everything in the header is documented, we use the
>> "parse-header.pl" (ok, this name really sucks) to create cross-references
>> between the header and the documentation itself.
>> 
>> So, it is actually a script that replaces all occurrences of typedefs,
>> defines, structs, functions, enums into references to the uAPI
>> documentation.
>> 
>> This is is somewhat equivalent to:
>>  .. code-block:: c
>> 
>> Or, even better, it resembles the Doxygen's \example directive:
>>  https://www.stack.nl/~dimitri/doxygen/manual/commands.html#cmdexample
>> 
>> With produces a parsed file, like this one:
>>  https://linuxtv.org/docs/libdvbv5/dvb-fe-tool_8c-example.html
>> 
>> Except that:
>> 
>> 1) It doesn't randomly painting the file;
>> 
>> 2) All places where the a typedef, define, struct, struct member,
>> function or enum exists are replaced by a cross-reference to the
>> documentation (except if explicitly defined to not do that, via a
>> configuration file).
>> 
>> That, plus the nitpick mode at Sphinx, allows us to check what
>> parts of the uAPI file aren't documented.
>> 
 - Along those lines, is parse-header the right name for this thing?
 "Parsing" isn't necessarily the goal of somebody who uses this directive,
 right?  They want to extract documentation information.  Can we come up
 with a better name?  
>>> 
>>> Mauro, what is your suggestion and how would we go on in this topic?
>> 
>> Maybe we could call it as: "include-c-code-block" or something similar.
> 
> Hmm, that's not any better, IMHO ... there is a 'parsed-literal' so, what's
> wrong with a 'parsed-header' directive or for my sake ' parse-c-header'.
> IMHO it is very unspecific what this directive does and it might be changed in
> the near future if someone (e.g. Daniel [1]) see more use cases then the one 
> yet.
> 
> [1] https://www.mail-archive.com/linux-media%40vger.kernel.org/msg101129.html
> 
> -- Markus --
> 

One more thought; parse-header and kernel_doc, are parsing C code.
But both implement their own C-parser ... may it is time to look
for a more general parser solution:

   * http://git.kernel.org/cgit/devel/sparse/sparse.git
   * https://github.com/eliben/pycparser

Only read the documentation of pycparser, sound promising to me.
With something like "parse_file" we could parse the headers

   * https://github.com/eliben/pycparser/blob/master/pycparser/__init__.py#L54

and with subclassing the "CGenerator" class and overwriting some visit-methods:

   * 
https://github.com/eliben/pycparser/blob/master/pycparser/c_generator.py#L12

we can produce the reST output. There is a small example parsing C to
an AST and back to C: