From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932349AbcLLGyg (ORCPT ); Mon, 12 Dec 2016 01:54:36 -0500 Received: from terminus.zytor.com ([198.137.202.10]:49752 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932166AbcLLGyf (ORCPT ); Mon, 12 Dec 2016 01:54:35 -0500 Date: Sun, 11 Dec 2016 22:50:16 -0800 From: tip-bot for Peter Zijlstra Message-ID: Cc: mingo@kernel.org, akataria@vmware.com, xiaolong.ye@intel.com, tglx@linutronix.de, xinhui.pan@linux.vnet.ibm.com, bp@alien8.de, linux-kernel@vger.kernel.org, peterz@infradead.org, rusty@rustcorp.com.au, hpa@zytor.com, pbonzini@redhat.com, jeremy@goop.org, chrisw@sous-sol.org, torvalds@linux-foundation.org Reply-To: peterz@infradead.org, linux-kernel@vger.kernel.org, bp@alien8.de, tglx@linutronix.de, xinhui.pan@linux.vnet.ibm.com, mingo@kernel.org, xiaolong.ye@intel.com, akataria@vmware.com, chrisw@sous-sol.org, torvalds@linux-foundation.org, jeremy@goop.org, rusty@rustcorp.com.au, pbonzini@redhat.com, hpa@zytor.com In-Reply-To: <20161208154349.346057680@infradead.org> References: <20161208154349.346057680@infradead.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:locking/core] x86/paravirt: Fix bool return type for PVOP_CALL() Git-Commit-ID: 11f254dbb3a2e3f0d8552d0dd37f4faa432b6b16 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 11f254dbb3a2e3f0d8552d0dd37f4faa432b6b16 Gitweb: http://git.kernel.org/tip/11f254dbb3a2e3f0d8552d0dd37f4faa432b6b16 Author: Peter Zijlstra AuthorDate: Thu, 8 Dec 2016 16:42:15 +0100 Committer: Ingo Molnar CommitDate: Sun, 11 Dec 2016 13:09:20 +0100 x86/paravirt: Fix bool return type for PVOP_CALL() Commit: 3cded4179481 ("x86/paravirt: Optimize native pv_lock_ops.vcpu_is_preempted()") introduced a paravirt op with bool return type [*] It turns out that the PVOP_CALL*() macros miscompile when rettype is bool. Code that looked like: 83 ef 01 sub $0x1,%edi ff 15 32 a0 d8 00 callq *0xd8a032(%rip) # ffffffff81e28120 84 c0 test %al,%al ended up looking like so after PVOP_CALL1() was applied: 83 ef 01 sub $0x1,%edi 48 63 ff movslq %edi,%rdi ff 14 25 20 81 e2 81 callq *0xffffffff81e28120 48 85 c0 test %rax,%rax Note how it tests the whole of %rax, even though a typical bool return function only sets %al, like: 0f 95 c0 setne %al c3 retq This is because ____PVOP_CALL() does: __ret = (rettype)__eax; and while regular integer type casts truncate the result, a cast to bool tests for any !0 value. Fix this by explicitly truncating to sizeof(rettype) before casting. [*] The actual bug should've been exposed in commit: 446f3dc8cc0a ("locking/core, x86/paravirt: Implement vcpu_is_preempted(cpu) for KVM and Xen guests") but that didn't properly implement the paravirt call. Reported-by: kernel test robot Signed-off-by: Peter Zijlstra (Intel) Cc: Alok Kataria Cc: Borislav Petkov Cc: Chris Wright Cc: Jeremy Fitzhardinge Cc: Linus Torvalds Cc: Pan Xinhui Cc: Paolo Bonzini Cc: Peter Anvin Cc: Peter Zijlstra Cc: Rusty Russell Cc: Thomas Gleixner Fixes: 3cded4179481 ("x86/paravirt: Optimize native pv_lock_ops.vcpu_is_preempted()") Link: http://lkml.kernel.org/r/20161208154349.346057680@infradead.org Signed-off-by: Ingo Molnar --- arch/x86/include/asm/paravirt_types.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h index 2614bd7..3f2bc0f 100644 --- a/arch/x86/include/asm/paravirt_types.h +++ b/arch/x86/include/asm/paravirt_types.h @@ -510,6 +510,18 @@ int paravirt_disable_iospace(void); #define PVOP_TEST_NULL(op) ((void)op) #endif +#define PVOP_RETMASK(rettype) \ + ({ unsigned long __mask = ~0UL; \ + switch (sizeof(rettype)) { \ + case 1: __mask = 0xffUL; break; \ + case 2: __mask = 0xffffUL; break; \ + case 4: __mask = 0xffffffffUL; break; \ + default: break; \ + } \ + __mask; \ + }) + + #define ____PVOP_CALL(rettype, op, clbr, call_clbr, extra_clbr, \ pre, post, ...) \ ({ \ @@ -537,7 +549,7 @@ int paravirt_disable_iospace(void); paravirt_clobber(clbr), \ ##__VA_ARGS__ \ : "memory", "cc" extra_clbr); \ - __ret = (rettype)__eax; \ + __ret = (rettype)(__eax & PVOP_RETMASK(rettype)); \ } \ __ret; \ })