]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/3.4.44/wrong-asm-register-contraints-in-the-kvm-implementation.patch
4.14-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 3.4.44 / wrong-asm-register-contraints-in-the-kvm-implementation.patch
CommitLineData
64f24c1c
GKH
1From de53e9caa4c6149ef4a78c2f83d7f5b655848767 Mon Sep 17 00:00:00 2001
2From: Stephan Schreiber <info@fs-driver.org>
3Date: Tue, 19 Mar 2013 15:27:12 -0700
4Subject: Wrong asm register contraints in the kvm implementation
5
6From: Stephan Schreiber <info@fs-driver.org>
7
8commit de53e9caa4c6149ef4a78c2f83d7f5b655848767 upstream.
9
10The Linux Kernel contains some inline assembly source code which has
11wrong asm register constraints in arch/ia64/kvm/vtlb.c.
12
13I observed this on Kernel 3.2.35 but it is also true on the most
14recent Kernel 3.9-rc1.
15
16File arch/ia64/kvm/vtlb.c:
17
18u64 guest_vhpt_lookup(u64 iha, u64 *pte)
19{
20 u64 ret;
21 struct thash_data *data;
22
23 data = __vtr_lookup(current_vcpu, iha, D_TLB);
24 if (data != NULL)
25 thash_vhpt_insert(current_vcpu, data->page_flags,
26 data->itir, iha, D_TLB);
27
28 asm volatile (
29 "rsm psr.ic|psr.i;;"
30 "srlz.d;;"
31 "ld8.s r9=[%1];;"
32 "tnat.nz p6,p7=r9;;"
33 "(p6) mov %0=1;"
34 "(p6) mov r9=r0;"
35 "(p7) extr.u r9=r9,0,53;;"
36 "(p7) mov %0=r0;"
37 "(p7) st8 [%2]=r9;;"
38 "ssm psr.ic;;"
39 "srlz.d;;"
40 "ssm psr.i;;"
41 "srlz.d;;"
42 : "=r"(ret) : "r"(iha), "r"(pte):"memory");
43
44 return ret;
45}
46
47The list of output registers is
48 : "=r"(ret) : "r"(iha), "r"(pte):"memory");
49The constraint "=r" means that the GCC has to maintain that these vars
50are in registers and contain valid info when the program flow leaves
51the assembly block (output registers).
52But "=r" also means that GCC can put them in registers that are used
53as input registers. Input registers are iha, pte on the example.
54If the predicate p7 is true, the 8th assembly instruction
55 "(p7) mov %0=r0;"
56is the first one which writes to a register which is maintained by the
57register constraints; it sets %0. %0 means the first register operand;
58it is ret here.
59This instruction might overwrite the %2 register (pte) which is needed
60by the next instruction:
61 "(p7) st8 [%2]=r9;;"
62Whether it really happens depends on how GCC decides what registers it
63uses and how it optimizes the code.
64
65The attached patch fixes the register operand constraints in
66arch/ia64/kvm/vtlb.c.
67The register constraints should be
68 : "=&r"(ret) : "r"(iha), "r"(pte):"memory");
69The & means that GCC must not use any of the input registers to place
70this output register in.
71
72This is Debian bug#702639
73(http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=702639).
74
75The patch is applicable on Kernel 3.9-rc1, 3.2.35 and many other versions.
76
77Signed-off-by: Stephan Schreiber <info@fs-driver.org>
78Signed-off-by: Tony Luck <tony.luck@intel.com>
79Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
80
81---
82 arch/ia64/kvm/vtlb.c | 2 +-
83 1 file changed, 1 insertion(+), 1 deletion(-)
84
85--- a/arch/ia64/kvm/vtlb.c
86+++ b/arch/ia64/kvm/vtlb.c
87@@ -256,7 +256,7 @@ u64 guest_vhpt_lookup(u64 iha, u64 *pte)
88 "srlz.d;;"
89 "ssm psr.i;;"
90 "srlz.d;;"
91- : "=r"(ret) : "r"(iha), "r"(pte):"memory");
92+ : "=&r"(ret) : "r"(iha), "r"(pte) : "memory");
93
94 return ret;
95 }