lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20150505143007.GO21418@twins.programming.kicks-ass.net>
Date:	Tue, 5 May 2015 16:30:07 +0200
From:	Peter Zijlstra <peterz@...radead.org>
To:	Tahsin Erdogan <tahsin@...gle.com>
Cc:	Raghavendra K T <raghavendra.kt@...ux.vnet.ibm.com>,
	tglx@...utronix.de, mingo@...hat.com, hpa@...or.com,
	x86@...nel.org, Waiman.Long@...com, borntraeger@...ibm.com,
	oleg@...hat.com, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] x86/spinlocks: Fix regression in spinlock contention
 detection

On Tue, May 05, 2015 at 07:10:19AM -0700, Tahsin Erdogan wrote:
> The conversion to signed happens with types shorter than int
> (__ticket_t is either u8 or u16).

Argh yes, I see.

(ISO C99) 6.3.1.1 rule 2 states that: "If an int can represent all values
of the original type, the value is converted to an int;... "

Originally I had only looked at: 6.3.1.8 Usual arithmetic conversions,
which has the following bit: "If both operands have the same type, then
no further conversion is needed."

Looking more closely, a sentence prior to that states: "Otherwise,
the integer promotions are performed on both operands." which brings us
back to that 6.3.1.1 rule 2.


I've slightly modified your Changelog to explicitly state this.

---
Subject: x86/spinlocks: Fix regression in spinlock contention detection
From: Tahsin Erdogan <tahsin@...gle.com>
Date: Mon, 4 May 2015 21:15:31 -0700

A spinlock is regarded as contended when there is at least one waiter.

Currently, the code that checks whether there are any waiters rely on
tail value being greater than head. However, this is not true if tail
reaches the max value and wraps back to zero, so arch_spin_is_contended()
incorrectly returns 0 (not contended) when tail is smaller than head.

This is because the normal C integer promotion rules will promote
__ticket_t to int because its of lower rank (u8,u16 < int).

The original code (before regression) handled this case by casting the
(tail - head) to an unsigned value. This change simply restores that
behavior.

Cc: hpa@...or.com
Cc: x86@...nel.org
Cc: Waiman.Long@...com
Cc: borntraeger@...ibm.com
Cc: oleg@...hat.com
Cc: raghavendra.kt@...ux.vnet.ibm.com
Cc: tglx@...utronix.de
Cc: mingo@...hat.com
Fixes: d6abfdb20223 ("x86/spinlocks/paravirt: Fix memory corruption on unlock")
Signed-off-by: Tahsin Erdogan <tahsin@...gle.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@...radead.org>
Link: http://lkml.kernel.org/r/1430799331-20445-1-git-send-email-tahsin@google.com
---
 arch/x86/include/asm/spinlock.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/arch/x86/include/asm/spinlock.h
+++ b/arch/x86/include/asm/spinlock.h
@@ -173,7 +173,7 @@ static inline int arch_spin_is_contended
 	struct __raw_tickets tmp = READ_ONCE(lock->tickets);
 
 	tmp.head &= ~TICKET_SLOWPATH_FLAG;
-	return (tmp.tail - tmp.head) > TICKET_LOCK_INC;
+	return (__ticket_t)(tmp.tail - tmp.head) > TICKET_LOCK_INC;
 }
 #define arch_spin_is_contended	arch_spin_is_contended
 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ