<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux-toradex.git/arch/arm64/lib, branch v4.2-rc8</title>
<subtitle>Linux kernel for Apalis and Colibri modules</subtitle>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/'/>
<entry>
<title>arm64: __clear_user: handle exceptions on strb</title>
<updated>2014-11-13T15:21:26+00:00</updated>
<author>
<name>Kyle McMartin</name>
<email>kyle@redhat.com</email>
</author>
<published>2014-11-12T21:07:44+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=97fc15436b36ee3956efad83e22a557991f7d19d'/>
<id>97fc15436b36ee3956efad83e22a557991f7d19d</id>
<content type='text'>
ARM64 currently doesn't fix up faults on the single-byte (strb) case of
__clear_user... which means that we can cause a nasty kernel panic as an
ordinary user with any multiple PAGE_SIZE+1 read from /dev/zero.
i.e.: dd if=/dev/zero of=foo ibs=1 count=1 (or ibs=65537, etc.)

This is a pretty obscure bug in the general case since we'll only
__do_kernel_fault (since there's no extable entry for pc) if the
mmap_sem is contended. However, with CONFIG_DEBUG_VM enabled, we'll
always fault.

if (!down_read_trylock(&amp;mm-&gt;mmap_sem)) {
	if (!user_mode(regs) &amp;&amp; !search_exception_tables(regs-&gt;pc))
		goto no_context;
retry:
	down_read(&amp;mm-&gt;mmap_sem);
} else {
	/*
	 * The above down_read_trylock() might have succeeded in
	 * which
	 * case, we'll have missed the might_sleep() from
	 * down_read().
	 */
	might_sleep();
	if (!user_mode(regs) &amp;&amp; !search_exception_tables(regs-&gt;pc))
		goto no_context;
}

Fix that by adding an extable entry for the strb instruction, since it
touches user memory, similar to the other stores in __clear_user.

Signed-off-by: Kyle McMartin &lt;kyle@redhat.com&gt;
Reported-by: Miloš Prchlík &lt;mprchlik@redhat.com&gt;
Cc: stable@vger.kernel.org
Signed-off-by: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
ARM64 currently doesn't fix up faults on the single-byte (strb) case of
__clear_user... which means that we can cause a nasty kernel panic as an
ordinary user with any multiple PAGE_SIZE+1 read from /dev/zero.
i.e.: dd if=/dev/zero of=foo ibs=1 count=1 (or ibs=65537, etc.)

This is a pretty obscure bug in the general case since we'll only
__do_kernel_fault (since there's no extable entry for pc) if the
mmap_sem is contended. However, with CONFIG_DEBUG_VM enabled, we'll
always fault.

if (!down_read_trylock(&amp;mm-&gt;mmap_sem)) {
	if (!user_mode(regs) &amp;&amp; !search_exception_tables(regs-&gt;pc))
		goto no_context;
retry:
	down_read(&amp;mm-&gt;mmap_sem);
} else {
	/*
	 * The above down_read_trylock() might have succeeded in
	 * which
	 * case, we'll have missed the might_sleep() from
	 * down_read().
	 */
	might_sleep();
	if (!user_mode(regs) &amp;&amp; !search_exception_tables(regs-&gt;pc))
		goto no_context;
}

Fix that by adding an extable entry for the strb instruction, since it
touches user memory, similar to the other stores in __clear_user.

Signed-off-by: Kyle McMartin &lt;kyle@redhat.com&gt;
Reported-by: Miloš Prchlík &lt;mprchlik@redhat.com&gt;
Cc: stable@vger.kernel.org
Signed-off-by: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>arm64: lib: Implement optimized string length routines</title>
<updated>2014-05-23T14:17:12+00:00</updated>
<author>
<name>zhichang.yuan</name>
<email>zhichang.yuan@linaro.org</email>
</author>
<published>2014-04-28T05:11:34+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=0a42cb0a6fa64cb17db11164a1ad3511b43acefe'/>
<id>0a42cb0a6fa64cb17db11164a1ad3511b43acefe</id>
<content type='text'>
This patch, based on Linaro's Cortex Strings library, adds
an assembly optimized strlen() and strnlen() functions.

Signed-off-by: Zhichang Yuan &lt;zhichang.yuan@linaro.org&gt;
Signed-off-by: Deepak Saxena &lt;dsaxena@linaro.org&gt;
Signed-off-by: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This patch, based on Linaro's Cortex Strings library, adds
an assembly optimized strlen() and strnlen() functions.

Signed-off-by: Zhichang Yuan &lt;zhichang.yuan@linaro.org&gt;
Signed-off-by: Deepak Saxena &lt;dsaxena@linaro.org&gt;
Signed-off-by: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>arm64: lib: Implement optimized string compare routines</title>
<updated>2014-05-23T14:16:59+00:00</updated>
<author>
<name>zhichang.yuan</name>
<email>zhichang.yuan@linaro.org</email>
</author>
<published>2014-04-28T05:11:33+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=192c4d902f19b66902d7aacc19e9b169bebfb2e5'/>
<id>192c4d902f19b66902d7aacc19e9b169bebfb2e5</id>
<content type='text'>
This patch, based on Linaro's Cortex Strings library, adds
an assembly optimized strcmp() and strncmp() functions.

Signed-off-by: Zhichang Yuan &lt;zhichang.yuan@linaro.org&gt;
Signed-off-by: Deepak Saxena &lt;dsaxena@linaro.org&gt;
Signed-off-by: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This patch, based on Linaro's Cortex Strings library, adds
an assembly optimized strcmp() and strncmp() functions.

Signed-off-by: Zhichang Yuan &lt;zhichang.yuan@linaro.org&gt;
Signed-off-by: Deepak Saxena &lt;dsaxena@linaro.org&gt;
Signed-off-by: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>arm64: lib: Implement optimized memcmp routine</title>
<updated>2014-05-23T14:07:57+00:00</updated>
<author>
<name>zhichang.yuan</name>
<email>zhichang.yuan@linaro.org</email>
</author>
<published>2014-04-28T05:11:32+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=d875c9b3724083cd2629cd8507e424cd3716cd28'/>
<id>d875c9b3724083cd2629cd8507e424cd3716cd28</id>
<content type='text'>
This patch, based on Linaro's Cortex Strings library, adds
an assembly optimized memcmp() function.

Signed-off-by: Zhichang Yuan &lt;zhichang.yuan@linaro.org&gt;
Signed-off-by: Deepak Saxena &lt;dsaxena@linaro.org&gt;
Signed-off-by: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This patch, based on Linaro's Cortex Strings library, adds
an assembly optimized memcmp() function.

Signed-off-by: Zhichang Yuan &lt;zhichang.yuan@linaro.org&gt;
Signed-off-by: Deepak Saxena &lt;dsaxena@linaro.org&gt;
Signed-off-by: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>arm64: lib: Implement optimized memset routine</title>
<updated>2014-05-23T14:07:48+00:00</updated>
<author>
<name>zhichang.yuan</name>
<email>zhichang.yuan@linaro.org</email>
</author>
<published>2014-04-28T05:11:31+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=b29a51fe0e0be63157d8661666be8bbfd8f0c5d7'/>
<id>b29a51fe0e0be63157d8661666be8bbfd8f0c5d7</id>
<content type='text'>
This patch, based on Linaro's Cortex Strings library, improves
the performance of the assembly optimized memset() function.

Signed-off-by: Zhichang Yuan &lt;zhichang.yuan@linaro.org&gt;
Signed-off-by: Deepak Saxena &lt;dsaxena@linaro.org&gt;
Signed-off-by: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This patch, based on Linaro's Cortex Strings library, improves
the performance of the assembly optimized memset() function.

Signed-off-by: Zhichang Yuan &lt;zhichang.yuan@linaro.org&gt;
Signed-off-by: Deepak Saxena &lt;dsaxena@linaro.org&gt;
Signed-off-by: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>arm64: lib: Implement optimized memmove routine</title>
<updated>2014-05-23T14:07:35+00:00</updated>
<author>
<name>zhichang.yuan</name>
<email>zhichang.yuan@linaro.org</email>
</author>
<published>2014-04-28T05:11:30+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=280adc1951c0c9fc8f2d85571ff563a1c412b1cd'/>
<id>280adc1951c0c9fc8f2d85571ff563a1c412b1cd</id>
<content type='text'>
This patch, based on Linaro's Cortex Strings library, improves
the performance of the assembly optimized memmove() function.

Signed-off-by: Zhichang Yuan &lt;zhichang.yuan@linaro.org&gt;
Signed-off-by: Deepak Saxena &lt;dsaxena@linaro.org&gt;
Signed-off-by: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This patch, based on Linaro's Cortex Strings library, improves
the performance of the assembly optimized memmove() function.

Signed-off-by: Zhichang Yuan &lt;zhichang.yuan@linaro.org&gt;
Signed-off-by: Deepak Saxena &lt;dsaxena@linaro.org&gt;
Signed-off-by: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>arm64: lib: Implement optimized memcpy routine</title>
<updated>2014-05-23T14:06:53+00:00</updated>
<author>
<name>zhichang.yuan</name>
<email>zhichang.yuan@linaro.org</email>
</author>
<published>2014-04-28T05:11:29+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=808dbac6b51f3441eb5a07724c0b0d1257046d51'/>
<id>808dbac6b51f3441eb5a07724c0b0d1257046d51</id>
<content type='text'>
This patch, based on Linaro's Cortex Strings library, improves
the performance of the assembly optimized memcpy() function.

Signed-off-by: Zhichang Yuan &lt;zhichang.yuan@linaro.org&gt;
Signed-off-by: Deepak Saxena &lt;dsaxena@linaro.org&gt;
Signed-off-by: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This patch, based on Linaro's Cortex Strings library, improves
the performance of the assembly optimized memcpy() function.

Signed-off-by: Zhichang Yuan &lt;zhichang.yuan@linaro.org&gt;
Signed-off-by: Deepak Saxena &lt;dsaxena@linaro.org&gt;
Signed-off-by: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>arm64: atomics: fix use of acquire + release for full barrier semantics</title>
<updated>2014-02-07T16:45:43+00:00</updated>
<author>
<name>Will Deacon</name>
<email>will.deacon@arm.com</email>
</author>
<published>2014-02-04T12:29:12+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=8e86f0b409a44193f1587e87b69c5dcf8f65be67'/>
<id>8e86f0b409a44193f1587e87b69c5dcf8f65be67</id>
<content type='text'>
Linux requires a number of atomic operations to provide full barrier
semantics, that is no memory accesses after the operation can be
observed before any accesses up to and including the operation in
program order.

On arm64, these operations have been incorrectly implemented as follows:

	// A, B, C are independent memory locations

	&lt;Access [A]&gt;

	// atomic_op (B)
1:	ldaxr	x0, [B]		// Exclusive load with acquire
	&lt;op(B)&gt;
	stlxr	w1, x0, [B]	// Exclusive store with release
	cbnz	w1, 1b

	&lt;Access [C]&gt;

The assumption here being that two half barriers are equivalent to a
full barrier, so the only permitted ordering would be A -&gt; B -&gt; C
(where B is the atomic operation involving both a load and a store).

Unfortunately, this is not the case by the letter of the architecture
and, in fact, the accesses to A and C are permitted to pass their
nearest half barrier resulting in orderings such as Bl -&gt; A -&gt; C -&gt; Bs
or Bl -&gt; C -&gt; A -&gt; Bs (where Bl is the load-acquire on B and Bs is the
store-release on B). This is a clear violation of the full barrier
requirement.

The simple way to fix this is to implement the same algorithm as ARMv7
using explicit barriers:

	&lt;Access [A]&gt;

	// atomic_op (B)
	dmb	ish		// Full barrier
1:	ldxr	x0, [B]		// Exclusive load
	&lt;op(B)&gt;
	stxr	w1, x0, [B]	// Exclusive store
	cbnz	w1, 1b
	dmb	ish		// Full barrier

	&lt;Access [C]&gt;

but this has the undesirable effect of introducing *two* full barrier
instructions. A better approach is actually the following, non-intuitive
sequence:

	&lt;Access [A]&gt;

	// atomic_op (B)
1:	ldxr	x0, [B]		// Exclusive load
	&lt;op(B)&gt;
	stlxr	w1, x0, [B]	// Exclusive store with release
	cbnz	w1, 1b
	dmb	ish		// Full barrier

	&lt;Access [C]&gt;

The simple observations here are:

  - The dmb ensures that no subsequent accesses (e.g. the access to C)
    can enter or pass the atomic sequence.

  - The dmb also ensures that no prior accesses (e.g. the access to A)
    can pass the atomic sequence.

  - Therefore, no prior access can pass a subsequent access, or
    vice-versa (i.e. A is strictly ordered before C).

  - The stlxr ensures that no prior access can pass the store component
    of the atomic operation.

The only tricky part remaining is the ordering between the ldxr and the
access to A, since the absence of the first dmb means that we're now
permitting re-ordering between the ldxr and any prior accesses.

From an (arbitrary) observer's point of view, there are two scenarios:

  1. We have observed the ldxr. This means that if we perform a store to
     [B], the ldxr will still return older data. If we can observe the
     ldxr, then we can potentially observe the permitted re-ordering
     with the access to A, which is clearly an issue when compared to
     the dmb variant of the code. Thankfully, the exclusive monitor will
     save us here since it will be cleared as a result of the store and
     the ldxr will retry. Notice that any use of a later memory
     observation to imply observation of the ldxr will also imply
     observation of the access to A, since the stlxr/dmb ensure strict
     ordering.

  2. We have not observed the ldxr. This means we can perform a store
     and influence the later ldxr. However, that doesn't actually tell
     us anything about the access to [A], so we've not lost anything
     here either when compared to the dmb variant.

This patch implements this solution for our barriered atomic operations,
ensuring that we satisfy the full barrier requirements where they are
needed.

Cc: &lt;stable@vger.kernel.org&gt;
Cc: Peter Zijlstra &lt;peterz@infradead.org&gt;
Signed-off-by: Will Deacon &lt;will.deacon@arm.com&gt;
Signed-off-by: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Linux requires a number of atomic operations to provide full barrier
semantics, that is no memory accesses after the operation can be
observed before any accesses up to and including the operation in
program order.

On arm64, these operations have been incorrectly implemented as follows:

	// A, B, C are independent memory locations

	&lt;Access [A]&gt;

	// atomic_op (B)
1:	ldaxr	x0, [B]		// Exclusive load with acquire
	&lt;op(B)&gt;
	stlxr	w1, x0, [B]	// Exclusive store with release
	cbnz	w1, 1b

	&lt;Access [C]&gt;

The assumption here being that two half barriers are equivalent to a
full barrier, so the only permitted ordering would be A -&gt; B -&gt; C
(where B is the atomic operation involving both a load and a store).

Unfortunately, this is not the case by the letter of the architecture
and, in fact, the accesses to A and C are permitted to pass their
nearest half barrier resulting in orderings such as Bl -&gt; A -&gt; C -&gt; Bs
or Bl -&gt; C -&gt; A -&gt; Bs (where Bl is the load-acquire on B and Bs is the
store-release on B). This is a clear violation of the full barrier
requirement.

The simple way to fix this is to implement the same algorithm as ARMv7
using explicit barriers:

	&lt;Access [A]&gt;

	// atomic_op (B)
	dmb	ish		// Full barrier
1:	ldxr	x0, [B]		// Exclusive load
	&lt;op(B)&gt;
	stxr	w1, x0, [B]	// Exclusive store
	cbnz	w1, 1b
	dmb	ish		// Full barrier

	&lt;Access [C]&gt;

but this has the undesirable effect of introducing *two* full barrier
instructions. A better approach is actually the following, non-intuitive
sequence:

	&lt;Access [A]&gt;

	// atomic_op (B)
1:	ldxr	x0, [B]		// Exclusive load
	&lt;op(B)&gt;
	stlxr	w1, x0, [B]	// Exclusive store with release
	cbnz	w1, 1b
	dmb	ish		// Full barrier

	&lt;Access [C]&gt;

The simple observations here are:

  - The dmb ensures that no subsequent accesses (e.g. the access to C)
    can enter or pass the atomic sequence.

  - The dmb also ensures that no prior accesses (e.g. the access to A)
    can pass the atomic sequence.

  - Therefore, no prior access can pass a subsequent access, or
    vice-versa (i.e. A is strictly ordered before C).

  - The stlxr ensures that no prior access can pass the store component
    of the atomic operation.

The only tricky part remaining is the ordering between the ldxr and the
access to A, since the absence of the first dmb means that we're now
permitting re-ordering between the ldxr and any prior accesses.

From an (arbitrary) observer's point of view, there are two scenarios:

  1. We have observed the ldxr. This means that if we perform a store to
     [B], the ldxr will still return older data. If we can observe the
     ldxr, then we can potentially observe the permitted re-ordering
     with the access to A, which is clearly an issue when compared to
     the dmb variant of the code. Thankfully, the exclusive monitor will
     save us here since it will be cleared as a result of the store and
     the ldxr will retry. Notice that any use of a later memory
     observation to imply observation of the ldxr will also imply
     observation of the access to A, since the stlxr/dmb ensure strict
     ordering.

  2. We have not observed the ldxr. This means we can perform a store
     and influence the later ldxr. However, that doesn't actually tell
     us anything about the access to [A], so we've not lost anything
     here either when compared to the dmb variant.

This patch implements this solution for our barriered atomic operations,
ensuring that we satisfy the full barrier requirements where they are
needed.

Cc: &lt;stable@vger.kernel.org&gt;
Cc: Peter Zijlstra &lt;peterz@infradead.org&gt;
Signed-off-by: Will Deacon &lt;will.deacon@arm.com&gt;
Signed-off-by: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>arm64: use generic strnlen_user and strncpy_from_user functions</title>
<updated>2013-12-19T17:43:06+00:00</updated>
<author>
<name>Will Deacon</name>
<email>will.deacon@arm.com</email>
</author>
<published>2013-11-06T17:20:22+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=12a0ef7b0ac38677bd2d85f33df5ca0a57868819'/>
<id>12a0ef7b0ac38677bd2d85f33df5ca0a57868819</id>
<content type='text'>
This patch implements the word-at-a-time interface for arm64 using the
same algorithm as ARM. We use the fls64 macro, which expands to a clz
instruction via a compiler builtin. Big-endian configurations make use
of the implementation from asm-generic.

With this implemented, we can replace our byte-at-a-time strnlen_user
and strncpy_from_user functions with the optimised generic versions.

Signed-off-by: Will Deacon &lt;will.deacon@arm.com&gt;
Signed-off-by: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This patch implements the word-at-a-time interface for arm64 using the
same algorithm as ARM. We use the fls64 macro, which expands to a clz
instruction via a compiler builtin. Big-endian configurations make use
of the implementation from asm-generic.

With this implemented, we can replace our byte-at-a-time strnlen_user
and strncpy_from_user functions with the optimised generic versions.

Signed-off-by: Will Deacon &lt;will.deacon@arm.com&gt;
Signed-off-by: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>arm64: Treat the bitops index argument as an 'int'</title>
<updated>2013-05-08T09:33:17+00:00</updated>
<author>
<name>Catalin Marinas</name>
<email>catalin.marinas@arm.com</email>
</author>
<published>2013-05-07T17:02:58+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=420c158dcf96ee3a5758c9bf1586b163584c75c7'/>
<id>420c158dcf96ee3a5758c9bf1586b163584c75c7</id>
<content type='text'>
The bitops prototype use an 'int' as the bit index type but the asm
implementation assume it to be a 'long'. Since the compiler does not
guarantee zeroing the upper 32-bits in a register when used as 'int',
change the bitops implementation accordingly.

Signed-off-by: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The bitops prototype use an 'int' as the bit index type but the asm
implementation assume it to be a 'long'. Since the compiler does not
guarantee zeroing the upper 32-bits in a register when used as 'int',
change the bitops implementation accordingly.

Signed-off-by: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
</pre>
</div>
</content>
</entry>
</feed>
