<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux-toradex.git/arch, branch v4.1.20</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>KVM: x86: move steal time initialization to vcpu entry time</title>
<updated>2016-03-14T16:42:32+00:00</updated>
<author>
<name>Marcelo Tosatti</name>
<email>mtosatti@redhat.com</email>
</author>
<published>2016-03-11T08:53:11+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=b5c41530ef442dba667c4d964c722e8157f7da72'/>
<id>b5c41530ef442dba667c4d964c722e8157f7da72</id>
<content type='text'>
[ Upstream commit 7cae2bedcbd4680b155999655e49c27b9cf020fa ]

As reported at https://bugs.launchpad.net/qemu/+bug/1494350,
it is possible to have vcpu-&gt;arch.st.last_steal initialized
from a thread other than vcpu thread, say the iothread, via
KVM_SET_MSRS.

Which can cause an overflow later (when subtracting from vcpu threads
sched_info.run_delay).

To avoid that, move steal time accumulation to vcpu entry time,
before copying steal time data to guest.

Signed-off-by: Marcelo Tosatti &lt;mtosatti@redhat.com&gt;
Reviewed-by: David Matlack &lt;dmatlack@google.com&gt;
Signed-off-by: Paolo Bonzini &lt;pbonzini@redhat.com&gt;
Signed-off-by: Sasha Levin &lt;sasha.levin@oracle.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[ Upstream commit 7cae2bedcbd4680b155999655e49c27b9cf020fa ]

As reported at https://bugs.launchpad.net/qemu/+bug/1494350,
it is possible to have vcpu-&gt;arch.st.last_steal initialized
from a thread other than vcpu thread, say the iothread, via
KVM_SET_MSRS.

Which can cause an overflow later (when subtracting from vcpu threads
sched_info.run_delay).

To avoid that, move steal time accumulation to vcpu entry time,
before copying steal time data to guest.

Signed-off-by: Marcelo Tosatti &lt;mtosatti@redhat.com&gt;
Reviewed-by: David Matlack &lt;dmatlack@google.com&gt;
Signed-off-by: Paolo Bonzini &lt;pbonzini@redhat.com&gt;
Signed-off-by: Sasha Levin &lt;sasha.levin@oracle.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>MIPS: traps: Fix SIGFPE information leak from `do_ov' and `do_trap_or_bp'</title>
<updated>2016-03-14T16:42:31+00:00</updated>
<author>
<name>Maciej W. Rozycki</name>
<email>macro@imgtec.com</email>
</author>
<published>2016-03-04T01:42:49+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=5a4557b0eb8a2a0b3bccdcbc7a66b8b04262f878'/>
<id>5a4557b0eb8a2a0b3bccdcbc7a66b8b04262f878</id>
<content type='text'>
[ Upstream commit e723e3f7f9591b79e8c56b3d7c5a204a9c571b55 ]

Avoid sending a partially initialised `siginfo_t' structure along SIGFPE
signals issued from `do_ov' and `do_trap_or_bp', leading to information
leaking from the kernel stack.

Signed-off-by: Maciej W. Rozycki &lt;macro@imgtec.com&gt;
Cc: stable@vger.kernel.org
Signed-off-by: Ralf Baechle &lt;ralf@linux-mips.org&gt;
Signed-off-by: Sasha Levin &lt;sasha.levin@oracle.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[ Upstream commit e723e3f7f9591b79e8c56b3d7c5a204a9c571b55 ]

Avoid sending a partially initialised `siginfo_t' structure along SIGFPE
signals issued from `do_ov' and `do_trap_or_bp', leading to information
leaking from the kernel stack.

Signed-off-by: Maciej W. Rozycki &lt;macro@imgtec.com&gt;
Cc: stable@vger.kernel.org
Signed-off-by: Ralf Baechle &lt;ralf@linux-mips.org&gt;
Signed-off-by: Sasha Levin &lt;sasha.levin@oracle.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>PM / sleep / x86: Fix crash on graph trace through x86 suspend</title>
<updated>2016-03-09T18:15:25+00:00</updated>
<author>
<name>Todd E Brandt</name>
<email>todd.e.brandt@linux.intel.com</email>
</author>
<published>2016-03-03T00:05:29+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=8ef267aabd98f9df0279b9bb4245a3b985ead692'/>
<id>8ef267aabd98f9df0279b9bb4245a3b985ead692</id>
<content type='text'>
[ Upstream commit 92f9e179a702a6adbc11e2fedc76ecd6ffc9e3f7 ]

Pause/unpause graph tracing around do_suspend_lowlevel as it has
inconsistent call/return info after it jumps to the wakeup vector.
The graph trace buffer will otherwise become misaligned and
may eventually crash and hang on suspend.

To reproduce the issue and test the fix:
Run a function_graph trace over suspend/resume and set the graph
function to suspend_devices_and_enter. This consistently hangs the
system without this fix.

Signed-off-by: Todd Brandt &lt;todd.e.brandt@linux.intel.com&gt;
Cc: All applicable &lt;stable@vger.kernel.org&gt;
Signed-off-by: Rafael J. Wysocki &lt;rafael.j.wysocki@intel.com&gt;
Signed-off-by: Sasha Levin &lt;sasha.levin@oracle.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[ Upstream commit 92f9e179a702a6adbc11e2fedc76ecd6ffc9e3f7 ]

Pause/unpause graph tracing around do_suspend_lowlevel as it has
inconsistent call/return info after it jumps to the wakeup vector.
The graph trace buffer will otherwise become misaligned and
may eventually crash and hang on suspend.

To reproduce the issue and test the fix:
Run a function_graph trace over suspend/resume and set the graph
function to suspend_devices_and_enter. This consistently hangs the
system without this fix.

Signed-off-by: Todd Brandt &lt;todd.e.brandt@linux.intel.com&gt;
Cc: All applicable &lt;stable@vger.kernel.org&gt;
Signed-off-by: Rafael J. Wysocki &lt;rafael.j.wysocki@intel.com&gt;
Signed-off-by: Sasha Levin &lt;sasha.levin@oracle.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>parisc: Fix ptrace syscall number and return value modification</title>
<updated>2016-03-09T18:15:23+00:00</updated>
<author>
<name>Helge Deller</name>
<email>deller@gmx.de</email>
</author>
<published>2016-01-19T15:08:49+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=b8ad68546922dd5acb6cd32628bc9ae69a4795f9'/>
<id>b8ad68546922dd5acb6cd32628bc9ae69a4795f9</id>
<content type='text'>
[ Upstream commit 98e8b6c9ac9d1b1e9d1122dfa6783d5d566bb8f7 ]

Mike Frysinger reported that his ptrace testcase showed strange
behaviour on parisc: It was not possible to avoid a syscall and the
return value of a syscall couldn't be changed.

To modify a syscall number, we were missing to save the new syscall
number to gr20 which is then picked up later in assembly again.

The effect that the return value couldn't be changed is a side-effect of
another bug in the assembly code. When a process is ptraced, userspace
expects each syscall to report entrance and exit of a syscall.  If a
syscall number was given which doesn't exist, we jumped to the normal
syscall exit code instead of informing userspace that the (non-existant)
syscall exits. This unexpected behaviour confuses userspace and thus the
bug was misinterpreted as if we can't change the return value.

This patch fixes both problems and was tested on 64bit kernel with
32bit userspace.

Signed-off-by: Helge Deller &lt;deller@gmx.de&gt;
Cc: Mike Frysinger &lt;vapier@gentoo.org&gt;
Cc: stable@vger.kernel.org  # v4.0+
Tested-by: Mike Frysinger &lt;vapier@gentoo.org&gt;
Signed-off-by: Sasha Levin &lt;sasha.levin@oracle.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[ Upstream commit 98e8b6c9ac9d1b1e9d1122dfa6783d5d566bb8f7 ]

Mike Frysinger reported that his ptrace testcase showed strange
behaviour on parisc: It was not possible to avoid a syscall and the
return value of a syscall couldn't be changed.

To modify a syscall number, we were missing to save the new syscall
number to gr20 which is then picked up later in assembly again.

The effect that the return value couldn't be changed is a side-effect of
another bug in the assembly code. When a process is ptraced, userspace
expects each syscall to report entrance and exit of a syscall.  If a
syscall number was given which doesn't exist, we jumped to the normal
syscall exit code instead of informing userspace that the (non-existant)
syscall exits. This unexpected behaviour confuses userspace and thus the
bug was misinterpreted as if we can't change the return value.

This patch fixes both problems and was tested on 64bit kernel with
32bit userspace.

Signed-off-by: Helge Deller &lt;deller@gmx.de&gt;
Cc: Mike Frysinger &lt;vapier@gentoo.org&gt;
Cc: stable@vger.kernel.org  # v4.0+
Tested-by: Mike Frysinger &lt;vapier@gentoo.org&gt;
Signed-off-by: Sasha Levin &lt;sasha.levin@oracle.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>MIPS: kvm: Fix ioctl error handling.</title>
<updated>2016-03-09T18:15:18+00:00</updated>
<author>
<name>Michael S. Tsirkin</name>
<email>mst@redhat.com</email>
</author>
<published>2016-02-28T15:35:59+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=d850c054f3aeedf5e18290d14b097b5ed67fa9fb'/>
<id>d850c054f3aeedf5e18290d14b097b5ed67fa9fb</id>
<content type='text'>
[ Upstream commit 887349f69f37e71e2a8bfbd743831625a0b2ff51 ]

Calling return copy_to_user(...) or return copy_from_user in an ioctl
will not do the right thing if there's a pagefault:
copy_to_user/copy_from_user return the number of bytes not copied in
this case.

Fix up kvm on mips to do
	return copy_to_user(...)) ?  -EFAULT : 0;
and
	return copy_from_user(...)) ?  -EFAULT : 0;

everywhere.

Signed-off-by: Michael S. Tsirkin &lt;mst@redhat.com&gt;
Cc: Paolo Bonzini &lt;pbonzini@redhat.com&gt;
Cc: James Hogan &lt;james.hogan@imgtec.com&gt;
Cc: linux-kernel@vger.kernel.org
Cc: linux-mips@linux-mips.org
Cc: stable@vger.kernel.org
Cc: kvm@vger.kernel.org
Patchwork: https://patchwork.linux-mips.org/patch/12709/
Signed-off-by: Ralf Baechle &lt;ralf@linux-mips.org&gt;
Signed-off-by: Sasha Levin &lt;sasha.levin@oracle.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[ Upstream commit 887349f69f37e71e2a8bfbd743831625a0b2ff51 ]

Calling return copy_to_user(...) or return copy_from_user in an ioctl
will not do the right thing if there's a pagefault:
copy_to_user/copy_from_user return the number of bytes not copied in
this case.

Fix up kvm on mips to do
	return copy_to_user(...)) ?  -EFAULT : 0;
and
	return copy_from_user(...)) ?  -EFAULT : 0;

everywhere.

Signed-off-by: Michael S. Tsirkin &lt;mst@redhat.com&gt;
Cc: Paolo Bonzini &lt;pbonzini@redhat.com&gt;
Cc: James Hogan &lt;james.hogan@imgtec.com&gt;
Cc: linux-kernel@vger.kernel.org
Cc: linux-mips@linux-mips.org
Cc: stable@vger.kernel.org
Cc: kvm@vger.kernel.org
Patchwork: https://patchwork.linux-mips.org/patch/12709/
Signed-off-by: Ralf Baechle &lt;ralf@linux-mips.org&gt;
Signed-off-by: Sasha Levin &lt;sasha.levin@oracle.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>arm/arm64: KVM: Fix ioctl error handling</title>
<updated>2016-03-09T18:15:17+00:00</updated>
<author>
<name>Michael S. Tsirkin</name>
<email>mst@redhat.com</email>
</author>
<published>2016-02-28T15:32:07+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=222b341c1063cb7aa497d7ed051ccb60349f54bb'/>
<id>222b341c1063cb7aa497d7ed051ccb60349f54bb</id>
<content type='text'>
[ Upstream commit 4cad67fca3fc952d6f2ed9e799621f07666a560f ]

Calling return copy_to_user(...) in an ioctl will not
do the right thing if there's a pagefault:
copy_to_user returns the number of bytes not copied
in this case.

Fix up kvm to do
	return copy_to_user(...)) ?  -EFAULT : 0;

everywhere.

Cc: stable@vger.kernel.org
Acked-by: Christoffer Dall &lt;christoffer.dall@linaro.org&gt;
Signed-off-by: Michael S. Tsirkin &lt;mst@redhat.com&gt;
Signed-off-by: Marc Zyngier &lt;marc.zyngier@arm.com&gt;
Signed-off-by: Sasha Levin &lt;sasha.levin@oracle.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[ Upstream commit 4cad67fca3fc952d6f2ed9e799621f07666a560f ]

Calling return copy_to_user(...) in an ioctl will not
do the right thing if there's a pagefault:
copy_to_user returns the number of bytes not copied
in this case.

Fix up kvm to do
	return copy_to_user(...)) ?  -EFAULT : 0;

everywhere.

Cc: stable@vger.kernel.org
Acked-by: Christoffer Dall &lt;christoffer.dall@linaro.org&gt;
Signed-off-by: Michael S. Tsirkin &lt;mst@redhat.com&gt;
Signed-off-by: Marc Zyngier &lt;marc.zyngier@arm.com&gt;
Signed-off-by: Sasha Levin &lt;sasha.levin@oracle.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>x86/mpx: Fix off-by-one comparison with nr_registers</title>
<updated>2016-03-09T18:15:11+00:00</updated>
<author>
<name>Colin Ian King</name>
<email>colin.king@canonical.com</email>
</author>
<published>2016-02-26T18:55:31+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=bb2b7d4ee6fc2c2dea54c12df9c0aea15e1a019c'/>
<id>bb2b7d4ee6fc2c2dea54c12df9c0aea15e1a019c</id>
<content type='text'>
[ Upstream commit 9bf148cb0812595bfdf5100bd2c07e9bec9c6ef5 ]

In the unlikely event that regno == nr_registers then we get an array
overrun on regoff because the invalid register check is currently
off-by-one. Fix this with a check that regno is &gt;= nr_registers instead.

Detected with static analysis using CoverityScan.

Fixes: fcc7ffd67991 "x86, mpx: Decode MPX instruction to get bound violation information"
Signed-off-by: Colin Ian King &lt;colin.king@canonical.com&gt;
Acked-by: Dave Hansen &lt;dave.hansen@linux.intel.com&gt;
Cc: Borislav Petkov &lt;bp@alien8.de&gt;
Cc: "Kirill A . Shutemov" &lt;kirill.shutemov@linux.intel.com&gt;
Cc: stable@vger.kernel.org
Link: http://lkml.kernel.org/r/1456512931-3388-1-git-send-email-colin.king@canonical.com
Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Signed-off-by: Sasha Levin &lt;sasha.levin@oracle.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[ Upstream commit 9bf148cb0812595bfdf5100bd2c07e9bec9c6ef5 ]

In the unlikely event that regno == nr_registers then we get an array
overrun on regoff because the invalid register check is currently
off-by-one. Fix this with a check that regno is &gt;= nr_registers instead.

Detected with static analysis using CoverityScan.

Fixes: fcc7ffd67991 "x86, mpx: Decode MPX instruction to get bound violation information"
Signed-off-by: Colin Ian King &lt;colin.king@canonical.com&gt;
Acked-by: Dave Hansen &lt;dave.hansen@linux.intel.com&gt;
Cc: Borislav Petkov &lt;bp@alien8.de&gt;
Cc: "Kirill A . Shutemov" &lt;kirill.shutemov@linux.intel.com&gt;
Cc: stable@vger.kernel.org
Link: http://lkml.kernel.org/r/1456512931-3388-1-git-send-email-colin.king@canonical.com
Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Signed-off-by: Sasha Levin &lt;sasha.levin@oracle.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>KVM: x86: fix root cause for missed hardware breakpoints</title>
<updated>2016-03-09T18:15:10+00:00</updated>
<author>
<name>Paolo Bonzini</name>
<email>pbonzini@redhat.com</email>
</author>
<published>2016-02-26T11:28:40+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=18d609bb0b8c6823a750b32106be5685ca3daff7'/>
<id>18d609bb0b8c6823a750b32106be5685ca3daff7</id>
<content type='text'>
[ Upstream commit 70e4da7a8ff62f2775337b705f45c804bb450454 ]

Commit 172b2386ed16 ("KVM: x86: fix missed hardware breakpoints",
2016-02-10) worked around a case where the debug registers are not loaded
correctly on preemption and on the first entry to KVM_RUN.

However, Xiao Guangrong pointed out that the root cause must be that
KVM_DEBUGREG_BP_ENABLED is not being set correctly.  This can indeed
happen due to the lazy debug exit mechanism, which does not call
kvm_update_dr7.  Fix it by replacing the existing loop (more or less
equivalent to kvm_update_dr0123) with calls to all the kvm_update_dr*
functions.

Cc: stable@vger.kernel.org   # 4.1+
Fixes: 172b2386ed16a9143d9a456aae5ec87275c61489
Reviewed-by: Xiao Guangrong &lt;guangrong.xiao@linux.intel.com&gt;
Signed-off-by: Paolo Bonzini &lt;pbonzini@redhat.com&gt;
Signed-off-by: Sasha Levin &lt;sasha.levin@oracle.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[ Upstream commit 70e4da7a8ff62f2775337b705f45c804bb450454 ]

Commit 172b2386ed16 ("KVM: x86: fix missed hardware breakpoints",
2016-02-10) worked around a case where the debug registers are not loaded
correctly on preemption and on the first entry to KVM_RUN.

However, Xiao Guangrong pointed out that the root cause must be that
KVM_DEBUGREG_BP_ENABLED is not being set correctly.  This can indeed
happen due to the lazy debug exit mechanism, which does not call
kvm_update_dr7.  Fix it by replacing the existing loop (more or less
equivalent to kvm_update_dr0123) with calls to all the kvm_update_dr*
functions.

Cc: stable@vger.kernel.org   # 4.1+
Fixes: 172b2386ed16a9143d9a456aae5ec87275c61489
Reviewed-by: Xiao Guangrong &lt;guangrong.xiao@linux.intel.com&gt;
Signed-off-by: Paolo Bonzini &lt;pbonzini@redhat.com&gt;
Signed-off-by: Sasha Levin &lt;sasha.levin@oracle.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>KVM: x86: MMU: fix ubsan index-out-of-range warning</title>
<updated>2016-03-09T18:15:06+00:00</updated>
<author>
<name>Mike Krinkin</name>
<email>krinkin.m.u@gmail.com</email>
</author>
<published>2016-02-24T18:02:31+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=79e6eddd93bc3dfa020a57886d666dea9b9f452e'/>
<id>79e6eddd93bc3dfa020a57886d666dea9b9f452e</id>
<content type='text'>
[ Upstream commit 17e4bce0ae63c7e03f3c7fa8d80890e7af3d4971 ]

Ubsan reports the following warning due to a typo in
update_accessed_dirty_bits template, the patch fixes
the typo:

[  168.791851] ================================================================================
[  168.791862] UBSAN: Undefined behaviour in arch/x86/kvm/paging_tmpl.h:252:15
[  168.791866] index 4 is out of range for type 'u64 [4]'
[  168.791871] CPU: 0 PID: 2950 Comm: qemu-system-x86 Tainted: G           O L  4.5.0-rc5-next-20160222 #7
[  168.791873] Hardware name: LENOVO 23205NG/23205NG, BIOS G2ET95WW (2.55 ) 07/09/2013
[  168.791876]  0000000000000000 ffff8801cfcaf208 ffffffff81c9f780 0000000041b58ab3
[  168.791882]  ffffffff82eb2cc1 ffffffff81c9f6b4 ffff8801cfcaf230 ffff8801cfcaf1e0
[  168.791886]  0000000000000004 0000000000000001 0000000000000000 ffffffffa1981600
[  168.791891] Call Trace:
[  168.791899]  [&lt;ffffffff81c9f780&gt;] dump_stack+0xcc/0x12c
[  168.791904]  [&lt;ffffffff81c9f6b4&gt;] ? _atomic_dec_and_lock+0xc4/0xc4
[  168.791910]  [&lt;ffffffff81da9e81&gt;] ubsan_epilogue+0xd/0x8a
[  168.791914]  [&lt;ffffffff81daafa2&gt;] __ubsan_handle_out_of_bounds+0x15c/0x1a3
[  168.791918]  [&lt;ffffffff81daae46&gt;] ? __ubsan_handle_shift_out_of_bounds+0x2bd/0x2bd
[  168.791922]  [&lt;ffffffff811287ef&gt;] ? get_user_pages_fast+0x2bf/0x360
[  168.791954]  [&lt;ffffffffa1794050&gt;] ? kvm_largepages_enabled+0x30/0x30 [kvm]
[  168.791958]  [&lt;ffffffff81128530&gt;] ? __get_user_pages_fast+0x360/0x360
[  168.791987]  [&lt;ffffffffa181b818&gt;] paging64_walk_addr_generic+0x1b28/0x2600 [kvm]
[  168.792014]  [&lt;ffffffffa1819cf0&gt;] ? init_kvm_mmu+0x1100/0x1100 [kvm]
[  168.792019]  [&lt;ffffffff8129e350&gt;] ? debug_check_no_locks_freed+0x350/0x350
[  168.792044]  [&lt;ffffffffa1819cf0&gt;] ? init_kvm_mmu+0x1100/0x1100 [kvm]
[  168.792076]  [&lt;ffffffffa181c36d&gt;] paging64_gva_to_gpa+0x7d/0x110 [kvm]
[  168.792121]  [&lt;ffffffffa181c2f0&gt;] ? paging64_walk_addr_generic+0x2600/0x2600 [kvm]
[  168.792130]  [&lt;ffffffff812e848b&gt;] ? debug_lockdep_rcu_enabled+0x7b/0x90
[  168.792178]  [&lt;ffffffffa17d9a4a&gt;] emulator_read_write_onepage+0x27a/0x1150 [kvm]
[  168.792208]  [&lt;ffffffffa1794d44&gt;] ? __kvm_read_guest_page+0x54/0x70 [kvm]
[  168.792234]  [&lt;ffffffffa17d97d0&gt;] ? kvm_task_switch+0x160/0x160 [kvm]
[  168.792238]  [&lt;ffffffff812e848b&gt;] ? debug_lockdep_rcu_enabled+0x7b/0x90
[  168.792263]  [&lt;ffffffffa17daa07&gt;] emulator_read_write+0xe7/0x6d0 [kvm]
[  168.792290]  [&lt;ffffffffa183b620&gt;] ? em_cr_write+0x230/0x230 [kvm]
[  168.792314]  [&lt;ffffffffa17db005&gt;] emulator_write_emulated+0x15/0x20 [kvm]
[  168.792340]  [&lt;ffffffffa18465f8&gt;] segmented_write+0xf8/0x130 [kvm]
[  168.792367]  [&lt;ffffffffa1846500&gt;] ? em_lgdt+0x20/0x20 [kvm]
[  168.792374]  [&lt;ffffffffa14db512&gt;] ? vmx_read_guest_seg_ar+0x42/0x1e0 [kvm_intel]
[  168.792400]  [&lt;ffffffffa1846d82&gt;] writeback+0x3f2/0x700 [kvm]
[  168.792424]  [&lt;ffffffffa1846990&gt;] ? em_sidt+0xa0/0xa0 [kvm]
[  168.792449]  [&lt;ffffffffa185554d&gt;] ? x86_decode_insn+0x1b3d/0x4f70 [kvm]
[  168.792474]  [&lt;ffffffffa1859032&gt;] x86_emulate_insn+0x572/0x3010 [kvm]
[  168.792499]  [&lt;ffffffffa17e71dd&gt;] x86_emulate_instruction+0x3bd/0x2110 [kvm]
[  168.792524]  [&lt;ffffffffa17e6e20&gt;] ? reexecute_instruction.part.110+0x2e0/0x2e0 [kvm]
[  168.792532]  [&lt;ffffffffa14e9a81&gt;] handle_ept_misconfig+0x61/0x460 [kvm_intel]
[  168.792539]  [&lt;ffffffffa14e9a20&gt;] ? handle_pause+0x450/0x450 [kvm_intel]
[  168.792546]  [&lt;ffffffffa15130ea&gt;] vmx_handle_exit+0xd6a/0x1ad0 [kvm_intel]
[  168.792572]  [&lt;ffffffffa17f6a6c&gt;] ? kvm_arch_vcpu_ioctl_run+0xbdc/0x6090 [kvm]
[  168.792597]  [&lt;ffffffffa17f6bcd&gt;] kvm_arch_vcpu_ioctl_run+0xd3d/0x6090 [kvm]
[  168.792621]  [&lt;ffffffffa17f6a6c&gt;] ? kvm_arch_vcpu_ioctl_run+0xbdc/0x6090 [kvm]
[  168.792627]  [&lt;ffffffff8293b530&gt;] ? __ww_mutex_lock_interruptible+0x1630/0x1630
[  168.792651]  [&lt;ffffffffa17f5e90&gt;] ? kvm_arch_vcpu_runnable+0x4f0/0x4f0 [kvm]
[  168.792656]  [&lt;ffffffff811eeb30&gt;] ? preempt_notifier_unregister+0x190/0x190
[  168.792681]  [&lt;ffffffffa17e0447&gt;] ? kvm_arch_vcpu_load+0x127/0x650 [kvm]
[  168.792704]  [&lt;ffffffffa178e9a3&gt;] kvm_vcpu_ioctl+0x553/0xda0 [kvm]
[  168.792727]  [&lt;ffffffffa178e450&gt;] ? vcpu_put+0x40/0x40 [kvm]
[  168.792732]  [&lt;ffffffff8129e350&gt;] ? debug_check_no_locks_freed+0x350/0x350
[  168.792735]  [&lt;ffffffff82946087&gt;] ? _raw_spin_unlock+0x27/0x40
[  168.792740]  [&lt;ffffffff8163a943&gt;] ? handle_mm_fault+0x1673/0x2e40
[  168.792744]  [&lt;ffffffff8129daa8&gt;] ? trace_hardirqs_on_caller+0x478/0x6c0
[  168.792747]  [&lt;ffffffff8129dcfd&gt;] ? trace_hardirqs_on+0xd/0x10
[  168.792751]  [&lt;ffffffff812e848b&gt;] ? debug_lockdep_rcu_enabled+0x7b/0x90
[  168.792756]  [&lt;ffffffff81725a80&gt;] do_vfs_ioctl+0x1b0/0x12b0
[  168.792759]  [&lt;ffffffff817258d0&gt;] ? ioctl_preallocate+0x210/0x210
[  168.792763]  [&lt;ffffffff8174aef3&gt;] ? __fget+0x273/0x4a0
[  168.792766]  [&lt;ffffffff8174acd0&gt;] ? __fget+0x50/0x4a0
[  168.792770]  [&lt;ffffffff8174b1f6&gt;] ? __fget_light+0x96/0x2b0
[  168.792773]  [&lt;ffffffff81726bf9&gt;] SyS_ioctl+0x79/0x90
[  168.792777]  [&lt;ffffffff82946880&gt;] entry_SYSCALL_64_fastpath+0x23/0xc1
[  168.792780] ================================================================================

Signed-off-by: Mike Krinkin &lt;krinkin.m.u@gmail.com&gt;
Reviewed-by: Xiao Guangrong &lt;guangrong.xiao@linux.intel.com&gt;
Cc: stable@vger.kernel.org
Signed-off-by: Paolo Bonzini &lt;pbonzini@redhat.com&gt;
Signed-off-by: Sasha Levin &lt;sasha.levin@oracle.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[ Upstream commit 17e4bce0ae63c7e03f3c7fa8d80890e7af3d4971 ]

Ubsan reports the following warning due to a typo in
update_accessed_dirty_bits template, the patch fixes
the typo:

[  168.791851] ================================================================================
[  168.791862] UBSAN: Undefined behaviour in arch/x86/kvm/paging_tmpl.h:252:15
[  168.791866] index 4 is out of range for type 'u64 [4]'
[  168.791871] CPU: 0 PID: 2950 Comm: qemu-system-x86 Tainted: G           O L  4.5.0-rc5-next-20160222 #7
[  168.791873] Hardware name: LENOVO 23205NG/23205NG, BIOS G2ET95WW (2.55 ) 07/09/2013
[  168.791876]  0000000000000000 ffff8801cfcaf208 ffffffff81c9f780 0000000041b58ab3
[  168.791882]  ffffffff82eb2cc1 ffffffff81c9f6b4 ffff8801cfcaf230 ffff8801cfcaf1e0
[  168.791886]  0000000000000004 0000000000000001 0000000000000000 ffffffffa1981600
[  168.791891] Call Trace:
[  168.791899]  [&lt;ffffffff81c9f780&gt;] dump_stack+0xcc/0x12c
[  168.791904]  [&lt;ffffffff81c9f6b4&gt;] ? _atomic_dec_and_lock+0xc4/0xc4
[  168.791910]  [&lt;ffffffff81da9e81&gt;] ubsan_epilogue+0xd/0x8a
[  168.791914]  [&lt;ffffffff81daafa2&gt;] __ubsan_handle_out_of_bounds+0x15c/0x1a3
[  168.791918]  [&lt;ffffffff81daae46&gt;] ? __ubsan_handle_shift_out_of_bounds+0x2bd/0x2bd
[  168.791922]  [&lt;ffffffff811287ef&gt;] ? get_user_pages_fast+0x2bf/0x360
[  168.791954]  [&lt;ffffffffa1794050&gt;] ? kvm_largepages_enabled+0x30/0x30 [kvm]
[  168.791958]  [&lt;ffffffff81128530&gt;] ? __get_user_pages_fast+0x360/0x360
[  168.791987]  [&lt;ffffffffa181b818&gt;] paging64_walk_addr_generic+0x1b28/0x2600 [kvm]
[  168.792014]  [&lt;ffffffffa1819cf0&gt;] ? init_kvm_mmu+0x1100/0x1100 [kvm]
[  168.792019]  [&lt;ffffffff8129e350&gt;] ? debug_check_no_locks_freed+0x350/0x350
[  168.792044]  [&lt;ffffffffa1819cf0&gt;] ? init_kvm_mmu+0x1100/0x1100 [kvm]
[  168.792076]  [&lt;ffffffffa181c36d&gt;] paging64_gva_to_gpa+0x7d/0x110 [kvm]
[  168.792121]  [&lt;ffffffffa181c2f0&gt;] ? paging64_walk_addr_generic+0x2600/0x2600 [kvm]
[  168.792130]  [&lt;ffffffff812e848b&gt;] ? debug_lockdep_rcu_enabled+0x7b/0x90
[  168.792178]  [&lt;ffffffffa17d9a4a&gt;] emulator_read_write_onepage+0x27a/0x1150 [kvm]
[  168.792208]  [&lt;ffffffffa1794d44&gt;] ? __kvm_read_guest_page+0x54/0x70 [kvm]
[  168.792234]  [&lt;ffffffffa17d97d0&gt;] ? kvm_task_switch+0x160/0x160 [kvm]
[  168.792238]  [&lt;ffffffff812e848b&gt;] ? debug_lockdep_rcu_enabled+0x7b/0x90
[  168.792263]  [&lt;ffffffffa17daa07&gt;] emulator_read_write+0xe7/0x6d0 [kvm]
[  168.792290]  [&lt;ffffffffa183b620&gt;] ? em_cr_write+0x230/0x230 [kvm]
[  168.792314]  [&lt;ffffffffa17db005&gt;] emulator_write_emulated+0x15/0x20 [kvm]
[  168.792340]  [&lt;ffffffffa18465f8&gt;] segmented_write+0xf8/0x130 [kvm]
[  168.792367]  [&lt;ffffffffa1846500&gt;] ? em_lgdt+0x20/0x20 [kvm]
[  168.792374]  [&lt;ffffffffa14db512&gt;] ? vmx_read_guest_seg_ar+0x42/0x1e0 [kvm_intel]
[  168.792400]  [&lt;ffffffffa1846d82&gt;] writeback+0x3f2/0x700 [kvm]
[  168.792424]  [&lt;ffffffffa1846990&gt;] ? em_sidt+0xa0/0xa0 [kvm]
[  168.792449]  [&lt;ffffffffa185554d&gt;] ? x86_decode_insn+0x1b3d/0x4f70 [kvm]
[  168.792474]  [&lt;ffffffffa1859032&gt;] x86_emulate_insn+0x572/0x3010 [kvm]
[  168.792499]  [&lt;ffffffffa17e71dd&gt;] x86_emulate_instruction+0x3bd/0x2110 [kvm]
[  168.792524]  [&lt;ffffffffa17e6e20&gt;] ? reexecute_instruction.part.110+0x2e0/0x2e0 [kvm]
[  168.792532]  [&lt;ffffffffa14e9a81&gt;] handle_ept_misconfig+0x61/0x460 [kvm_intel]
[  168.792539]  [&lt;ffffffffa14e9a20&gt;] ? handle_pause+0x450/0x450 [kvm_intel]
[  168.792546]  [&lt;ffffffffa15130ea&gt;] vmx_handle_exit+0xd6a/0x1ad0 [kvm_intel]
[  168.792572]  [&lt;ffffffffa17f6a6c&gt;] ? kvm_arch_vcpu_ioctl_run+0xbdc/0x6090 [kvm]
[  168.792597]  [&lt;ffffffffa17f6bcd&gt;] kvm_arch_vcpu_ioctl_run+0xd3d/0x6090 [kvm]
[  168.792621]  [&lt;ffffffffa17f6a6c&gt;] ? kvm_arch_vcpu_ioctl_run+0xbdc/0x6090 [kvm]
[  168.792627]  [&lt;ffffffff8293b530&gt;] ? __ww_mutex_lock_interruptible+0x1630/0x1630
[  168.792651]  [&lt;ffffffffa17f5e90&gt;] ? kvm_arch_vcpu_runnable+0x4f0/0x4f0 [kvm]
[  168.792656]  [&lt;ffffffff811eeb30&gt;] ? preempt_notifier_unregister+0x190/0x190
[  168.792681]  [&lt;ffffffffa17e0447&gt;] ? kvm_arch_vcpu_load+0x127/0x650 [kvm]
[  168.792704]  [&lt;ffffffffa178e9a3&gt;] kvm_vcpu_ioctl+0x553/0xda0 [kvm]
[  168.792727]  [&lt;ffffffffa178e450&gt;] ? vcpu_put+0x40/0x40 [kvm]
[  168.792732]  [&lt;ffffffff8129e350&gt;] ? debug_check_no_locks_freed+0x350/0x350
[  168.792735]  [&lt;ffffffff82946087&gt;] ? _raw_spin_unlock+0x27/0x40
[  168.792740]  [&lt;ffffffff8163a943&gt;] ? handle_mm_fault+0x1673/0x2e40
[  168.792744]  [&lt;ffffffff8129daa8&gt;] ? trace_hardirqs_on_caller+0x478/0x6c0
[  168.792747]  [&lt;ffffffff8129dcfd&gt;] ? trace_hardirqs_on+0xd/0x10
[  168.792751]  [&lt;ffffffff812e848b&gt;] ? debug_lockdep_rcu_enabled+0x7b/0x90
[  168.792756]  [&lt;ffffffff81725a80&gt;] do_vfs_ioctl+0x1b0/0x12b0
[  168.792759]  [&lt;ffffffff817258d0&gt;] ? ioctl_preallocate+0x210/0x210
[  168.792763]  [&lt;ffffffff8174aef3&gt;] ? __fget+0x273/0x4a0
[  168.792766]  [&lt;ffffffff8174acd0&gt;] ? __fget+0x50/0x4a0
[  168.792770]  [&lt;ffffffff8174b1f6&gt;] ? __fget_light+0x96/0x2b0
[  168.792773]  [&lt;ffffffff81726bf9&gt;] SyS_ioctl+0x79/0x90
[  168.792777]  [&lt;ffffffff82946880&gt;] entry_SYSCALL_64_fastpath+0x23/0xc1
[  168.792780] ================================================================================

Signed-off-by: Mike Krinkin &lt;krinkin.m.u@gmail.com&gt;
Reviewed-by: Xiao Guangrong &lt;guangrong.xiao@linux.intel.com&gt;
Cc: stable@vger.kernel.org
Signed-off-by: Paolo Bonzini &lt;pbonzini@redhat.com&gt;
Signed-off-by: Sasha Levin &lt;sasha.levin@oracle.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>KVM: x86: fix missed hardware breakpoints</title>
<updated>2016-03-07T21:35:09+00:00</updated>
<author>
<name>Paolo Bonzini</name>
<email>pbonzini@redhat.com</email>
</author>
<published>2016-02-10T16:50:23+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=0ccb848f62b5c9077cdeb903e324ca635806f804'/>
<id>0ccb848f62b5c9077cdeb903e324ca635806f804</id>
<content type='text'>
[ Upstream commit 172b2386ed16a9143d9a456aae5ec87275c61489 ]

Sometimes when setting a breakpoint a process doesn't stop on it.
This is because the debug registers are not loaded correctly on
VCPU load.

The following simple reproducer from Oleg Nesterov tries using debug
registers in two threads.  To see the bug, run a 2-VCPU guest with
"taskset -c 0" and run "./bp 0 1" inside the guest.

    #include &lt;unistd.h&gt;
    #include &lt;signal.h&gt;
    #include &lt;stdlib.h&gt;
    #include &lt;stdio.h&gt;
    #include &lt;sys/wait.h&gt;
    #include &lt;sys/ptrace.h&gt;
    #include &lt;sys/user.h&gt;
    #include &lt;asm/debugreg.h&gt;
    #include &lt;assert.h&gt;

    #define offsetof(TYPE, MEMBER) ((size_t) &amp;((TYPE *)0)-&gt;MEMBER)

    unsigned long encode_dr7(int drnum, int enable, unsigned int type, unsigned int len)
    {
        unsigned long dr7;

        dr7 = ((len | type) &amp; 0xf)
            &lt;&lt; (DR_CONTROL_SHIFT + drnum * DR_CONTROL_SIZE);
        if (enable)
            dr7 |= (DR_GLOBAL_ENABLE &lt;&lt; (drnum * DR_ENABLE_SIZE));

        return dr7;
    }

    int write_dr(int pid, int dr, unsigned long val)
    {
        return ptrace(PTRACE_POKEUSER, pid,
                offsetof (struct user, u_debugreg[dr]),
                val);
    }

    void set_bp(pid_t pid, void *addr)
    {
        unsigned long dr7;
        assert(write_dr(pid, 0, (long)addr) == 0);
        dr7 = encode_dr7(0, 1, DR_RW_EXECUTE, DR_LEN_1);
        assert(write_dr(pid, 7, dr7) == 0);
    }

    void *get_rip(int pid)
    {
        return (void*)ptrace(PTRACE_PEEKUSER, pid,
                offsetof(struct user, regs.rip), 0);
    }

    void test(int nr)
    {
        void *bp_addr = &amp;&amp;label + nr, *bp_hit;
        int pid;

        printf("test bp %d\n", nr);
        assert(nr &lt; 16); // see 16 asm nops below

        pid = fork();
        if (!pid) {
            assert(ptrace(PTRACE_TRACEME, 0,0,0) == 0);
            kill(getpid(), SIGSTOP);
            for (;;) {
                label: asm (
                    "nop; nop; nop; nop;"
                    "nop; nop; nop; nop;"
                    "nop; nop; nop; nop;"
                    "nop; nop; nop; nop;"
                );
            }
        }

        assert(pid == wait(NULL));
        set_bp(pid, bp_addr);

        for (;;) {
            assert(ptrace(PTRACE_CONT, pid, 0, 0) == 0);
            assert(pid == wait(NULL));

            bp_hit = get_rip(pid);
            if (bp_hit != bp_addr)
                fprintf(stderr, "ERR!! hit wrong bp %ld != %d\n",
                    bp_hit - &amp;&amp;label, nr);
        }
    }

    int main(int argc, const char *argv[])
    {
        while (--argc) {
            int nr = atoi(*++argv);
            if (!fork())
                test(nr);
        }

        while (wait(NULL) &gt; 0)
            ;
        return 0;
    }

Cc: stable@vger.kernel.org
Suggested-by: Nadav Amit &lt;namit@cs.technion.ac.il&gt;
Reported-by: Andrey Wagin &lt;avagin@gmail.com&gt;
Signed-off-by: Paolo Bonzini &lt;pbonzini@redhat.com&gt;
Signed-off-by: Sasha Levin &lt;sasha.levin@oracle.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[ Upstream commit 172b2386ed16a9143d9a456aae5ec87275c61489 ]

Sometimes when setting a breakpoint a process doesn't stop on it.
This is because the debug registers are not loaded correctly on
VCPU load.

The following simple reproducer from Oleg Nesterov tries using debug
registers in two threads.  To see the bug, run a 2-VCPU guest with
"taskset -c 0" and run "./bp 0 1" inside the guest.

    #include &lt;unistd.h&gt;
    #include &lt;signal.h&gt;
    #include &lt;stdlib.h&gt;
    #include &lt;stdio.h&gt;
    #include &lt;sys/wait.h&gt;
    #include &lt;sys/ptrace.h&gt;
    #include &lt;sys/user.h&gt;
    #include &lt;asm/debugreg.h&gt;
    #include &lt;assert.h&gt;

    #define offsetof(TYPE, MEMBER) ((size_t) &amp;((TYPE *)0)-&gt;MEMBER)

    unsigned long encode_dr7(int drnum, int enable, unsigned int type, unsigned int len)
    {
        unsigned long dr7;

        dr7 = ((len | type) &amp; 0xf)
            &lt;&lt; (DR_CONTROL_SHIFT + drnum * DR_CONTROL_SIZE);
        if (enable)
            dr7 |= (DR_GLOBAL_ENABLE &lt;&lt; (drnum * DR_ENABLE_SIZE));

        return dr7;
    }

    int write_dr(int pid, int dr, unsigned long val)
    {
        return ptrace(PTRACE_POKEUSER, pid,
                offsetof (struct user, u_debugreg[dr]),
                val);
    }

    void set_bp(pid_t pid, void *addr)
    {
        unsigned long dr7;
        assert(write_dr(pid, 0, (long)addr) == 0);
        dr7 = encode_dr7(0, 1, DR_RW_EXECUTE, DR_LEN_1);
        assert(write_dr(pid, 7, dr7) == 0);
    }

    void *get_rip(int pid)
    {
        return (void*)ptrace(PTRACE_PEEKUSER, pid,
                offsetof(struct user, regs.rip), 0);
    }

    void test(int nr)
    {
        void *bp_addr = &amp;&amp;label + nr, *bp_hit;
        int pid;

        printf("test bp %d\n", nr);
        assert(nr &lt; 16); // see 16 asm nops below

        pid = fork();
        if (!pid) {
            assert(ptrace(PTRACE_TRACEME, 0,0,0) == 0);
            kill(getpid(), SIGSTOP);
            for (;;) {
                label: asm (
                    "nop; nop; nop; nop;"
                    "nop; nop; nop; nop;"
                    "nop; nop; nop; nop;"
                    "nop; nop; nop; nop;"
                );
            }
        }

        assert(pid == wait(NULL));
        set_bp(pid, bp_addr);

        for (;;) {
            assert(ptrace(PTRACE_CONT, pid, 0, 0) == 0);
            assert(pid == wait(NULL));

            bp_hit = get_rip(pid);
            if (bp_hit != bp_addr)
                fprintf(stderr, "ERR!! hit wrong bp %ld != %d\n",
                    bp_hit - &amp;&amp;label, nr);
        }
    }

    int main(int argc, const char *argv[])
    {
        while (--argc) {
            int nr = atoi(*++argv);
            if (!fork())
                test(nr);
        }

        while (wait(NULL) &gt; 0)
            ;
        return 0;
    }

Cc: stable@vger.kernel.org
Suggested-by: Nadav Amit &lt;namit@cs.technion.ac.il&gt;
Reported-by: Andrey Wagin &lt;avagin@gmail.com&gt;
Signed-off-by: Paolo Bonzini &lt;pbonzini@redhat.com&gt;
Signed-off-by: Sasha Levin &lt;sasha.levin@oracle.com&gt;
</pre>
</div>
</content>
</entry>
</feed>
