From nobody@FreeBSD.org  Thu Aug 12 19:28:45 2010
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 406BD106564A
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 12 Aug 2010 19:28:45 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 3001A8FC14
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 12 Aug 2010 19:28:45 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o7CJSj53043213
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 12 Aug 2010 19:28:45 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o7CJSiOE043212;
	Thu, 12 Aug 2010 19:28:44 GMT
	(envelope-from nobody)
Message-Id: <201008121928.o7CJSiOE043212@www.freebsd.org>
Date: Thu, 12 Aug 2010 19:28:44 GMT
From: John Giacomoni <John.Giacomoni@LineRateSystems.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: struct callout:c_flags should be volatile
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         149591
>Category:       kern
>Synopsis:       [kernel] struct callout:c_flags should be volatile
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    jilles
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Aug 12 19:30:09 UTC 2010
>Closed-Date:    Sun Apr 06 21:39:20 UTC 2014
>Last-Modified:  Sun Apr 06 21:39:20 UTC 2014
>Originator:     John Giacomoni
>Release:        7.3/8.1
>Organization:
LineRate Systems
>Environment:
>Description:
The following code sequence can result in an infinite loop (even if the
callout invokes callout_deactivate()

while(callout_active()) DELAY();

The problem is that callout_active checks c_flags to check if a callout
timer is active.

However, unless c_flags are volatile, the compiler can cache the value
of c_flags in a register and thus fail to notice a change in state when
repeatedly called from within a single scope.
>How-To-Repeat:

>Fix:


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: jilles 
State-Changed-When: Sun Apr 6 21:34:16 UTC 2014 
State-Changed-Why:  
Hi, 

Thanks for your request. I think the volatile qualifier should 
not be added. 

callout_active() should only be called when the callout's lock 
(Giant, given mutex or given rwlock) is held. The lock/unlock 
operations will force the compiler and CPU to fetch a new value. 

The volatile qualifier is not designed to protect against other 
threads, even though it might appear to help with that. 

In your example, note that DELAY is a busy-wait loop; it is 
sometimes useful to wait for hardware, but not to wait for 
software events. 


Responsible-Changed-From-To: freebsd-bugs->jilles 
Responsible-Changed-By: jilles 
Responsible-Changed-When: Sun Apr 6 21:34:16 UTC 2014 
Responsible-Changed-Why:  
Track replies. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=149591 
>Unformatted:
