android_kernel_motorola_sm6225/arch/ia64/kvm
Stephan Schreiber de53e9caa4 Wrong asm register contraints in the kvm implementation
The Linux Kernel contains some inline assembly source code which has
wrong asm register constraints in arch/ia64/kvm/vtlb.c.

I observed this on Kernel 3.2.35 but it is also true on the most
recent Kernel 3.9-rc1.

File arch/ia64/kvm/vtlb.c:

u64 guest_vhpt_lookup(u64 iha, u64 *pte)
{
	u64 ret;
	struct thash_data *data;

	data = __vtr_lookup(current_vcpu, iha, D_TLB);
	if (data != NULL)
		thash_vhpt_insert(current_vcpu, data->page_flags,
			data->itir, iha, D_TLB);

	asm volatile (
			"rsm psr.ic|psr.i;;"
			"srlz.d;;"
			"ld8.s r9=[%1];;"
			"tnat.nz p6,p7=r9;;"
			"(p6) mov %0=1;"
			"(p6) mov r9=r0;"
			"(p7) extr.u r9=r9,0,53;;"
			"(p7) mov %0=r0;"
			"(p7) st8 [%2]=r9;;"
			"ssm psr.ic;;"
			"srlz.d;;"
			"ssm psr.i;;"
			"srlz.d;;"
			: "=r"(ret) : "r"(iha), "r"(pte):"memory");

	return ret;
}

The list of output registers is
			: "=r"(ret) : "r"(iha), "r"(pte):"memory");
The constraint "=r" means that the GCC has to maintain that these vars
are in registers and contain valid info when the program flow leaves
the assembly block (output registers).
But "=r" also means that GCC can put them in registers that are used
as input registers. Input registers are iha, pte on the example.
If the predicate p7 is true, the 8th assembly instruction
			"(p7) mov %0=r0;"
is the first one which writes to a register which is maintained by the
register constraints; it sets %0. %0 means the first register operand;
it is ret here.
This instruction might overwrite the %2 register (pte) which is needed
by the next instruction:
			"(p7) st8 [%2]=r9;;"
Whether it really happens depends on how GCC decides what registers it
uses and how it optimizes the code.

The attached patch  fixes the register operand constraints in
arch/ia64/kvm/vtlb.c.
The register constraints should be
			: "=&r"(ret) : "r"(iha), "r"(pte):"memory");
The & means that GCC must not use any of the input registers to place
this output register in.

This is Debian bug#702639
(http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=702639).

The patch is applicable on Kernel 3.9-rc1, 3.2.35 and many other versions.

Signed-off-by: Stephan Schreiber <info@fs-driver.org>
Cc: stable@vger.kernel.org
Signed-off-by: Tony Luck <tony.luck@intel.com>
2013-03-19 16:14:54 -07:00
..
asm-offsets.c drop explicit include of autoconf.h 2009-12-12 13:08:15 +01:00
irq.h KVM: ia64: Fix the build errors due to lack of macros related to MSI. 2009-03-24 11:03:13 +02:00
Kconfig arch/ia64/kvm: remove depends on CONFIG_EXPERIMENTAL 2013-01-11 11:38:03 -08:00
kvm-ia64.c KVM: struct kvm_memory_slot.user_alloc -> bool 2012-12-13 23:24:38 -02:00
kvm_fw.c KVM: ia64: remove redundant kvm_get_exit_data() NULL tests 2010-03-01 12:35:52 -03:00
kvm_lib.c KVM: ia64: fix ia64 build due to missing kallsyms_lookup() and double export 2009-06-28 14:10:30 +03:00
kvm_minstate.h KVM: ia64: Re-organize data sturure of guests' data area 2008-12-31 16:51:49 +02:00
lapic.h x86, apicv: add virtual interrupt delivery support 2013-01-29 10:48:19 +02:00
Makefile ia64: change to new flag variables 2011-03-17 14:02:56 +01:00
memcpy.S KVM: ia64: fix GVMM module including position-dependent objects 2008-05-18 14:34:16 +03:00
memset.S KVM: ia64: fix GVMM module including position-dependent objects 2008-05-18 14:34:16 +03:00
misc.h KVM: ia64: Re-organize data sturure of guests' data area 2008-12-31 16:51:49 +02:00
mmio.c tree-wide: fix comment/printk typos 2010-11-01 15:38:34 -04:00
optvfault.S KVM: ia64: Drop in SN2 replacement of fast path ITC emulation fault handler 2009-06-10 11:48:29 +03:00
process.c Fix common misspellings 2011-03-31 11:26:23 -03:00
trampoline.S KVM: ia64: Add trampoline for guest/host mode switch 2008-04-27 12:01:08 +03:00
vcpu.c KVM: ia64: Fix string literal continuation lines 2010-03-01 12:36:07 -03:00
vcpu.h KVM: ia64: fix build breakage due to host spinlock change 2009-12-27 13:36:33 -02:00
vmm.c treewide: Put a space between #include and FILE 2012-06-28 11:44:36 +02:00
vmm_ivt.S Rename .text.ivt to .text..ivt. 2010-03-03 11:26:00 +01:00
vti.h KVM: ia64: fix sparse warnings 2011-05-22 08:39:57 -04:00
vtlb.c Wrong asm register contraints in the kvm implementation 2013-03-19 16:14:54 -07:00