From owner-freebsd-bugs@FreeBSD.ORG Sat Sep 24 20:20:11 2011 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3D559106568F for ; Sat, 24 Sep 2011 20:20:11 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id F2A408FC24 for ; Sat, 24 Sep 2011 20:20:10 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id p8OKKAn0064191 for ; Sat, 24 Sep 2011 20:20:10 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id p8OKKAsL064190; Sat, 24 Sep 2011 20:20:10 GMT (envelope-from gnats) Resent-Date: Sat, 24 Sep 2011 20:20:10 GMT Resent-Message-Id: <201109242020.p8OKKAsL064190@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Arnaud Lacombe Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 259DF1065670 for ; Sat, 24 Sep 2011 20:11:52 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22]) by mx1.freebsd.org (Postfix) with ESMTP id 15AD58FC14 for ; Sat, 24 Sep 2011 20:11:52 +0000 (UTC) Received: from red.freebsd.org (localhost [127.0.0.1]) by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p8OKBpvE069059 for ; Sat, 24 Sep 2011 20:11:51 GMT (envelope-from nobody@red.freebsd.org) Received: (from nobody@localhost) by red.freebsd.org (8.14.4/8.14.4/Submit) id p8OKBpfo069058; Sat, 24 Sep 2011 20:11:51 GMT (envelope-from nobody) Message-Id: <201109242011.p8OKBpfo069058@red.freebsd.org> Date: Sat, 24 Sep 2011 20:11:51 GMT From: Arnaud Lacombe To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: kern/160992: buf_ring(9) statistics accounting not MPSAFE X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 24 Sep 2011 20:20:11 -0000 >Number: 160992 >Category: kern >Synopsis: buf_ring(9) statistics accounting not MPSAFE >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sat Sep 24 20:20:10 UTC 2011 >Closed-Date: >Last-Modified: >Originator: Arnaud Lacombe >Release: 9-CURRENT >Organization: n/a >Environment: >Description: The following block of code, in `sys/sys/buf_ring.h': /* * If there are other enqueues in progress * that preceeded us, we need to wait for them * to complete */ while (br->br_prod_tail != prod_head) cpu_spinwait(); br->br_prod_bufs++; br->br_prod_bytes += nbytes; br->br_prod_tail = prod_next; critical_exit(); can be seen at runtime, memory-wise as: while (br->br_prod_tail != prod_head) cpu_spinwait(); br->br_prod_tail = prod_next; br->br_prod_bufs++; br->br_prod_bytes += nbytes; critical_exit(); That is, there is no memory barrier to enforce completion of the load/increment/store/load/load/addition/store operations before updating what other thread spin on. Even if `br_prod_tail' is marked `volatile', there is no guarantee that it will not be re-ordered wrt. non-volatile write (to `br_prod_bufs' and `br_prod_bytes'). Confirmed by Kip Macy (kmacy@) in http://lists.freebsd.org/pipermail/freebsd-hackers/2011-September/036454.html. >How-To-Repeat: code review. >Fix: >Release-Note: >Audit-Trail: >Unformatted: