From nobody@FreeBSD.org  Mon Apr 15 00:11:33 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115])
	by hub.freebsd.org (Postfix) with ESMTP id AB0E9EAD
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 15 Apr 2013 00:11:33 +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 9D1538AE
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 15 Apr 2013 00:11:33 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id r3F0BXKG059007
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 15 Apr 2013 00:11:33 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id r3F0BXuG058984;
	Mon, 15 Apr 2013 00:11:33 GMT
	(envelope-from nobody)
Message-Id: <201304150011.r3F0BXuG058984@red.freebsd.org>
Date: Mon, 15 Apr 2013 00:11:33 GMT
From: Maxim Ignatenko <gelraen.ua@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Fix atomic bitstring operations in sys/ofed/include/linux/bitops.h
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         177862
>Category:       kern
>Synopsis:       [ofed] [patch] Fix atomic bitstring operations in sys/ofed/include/linux/bitops.h
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Apr 15 00:20:00 UTC 2013
>Closed-Date:    
>Last-Modified:  Mon Apr 15 01:43:16 UTC 2013
>Originator:     Maxim Ignatenko
>Release:        stable/9
>Organization:
>Environment:
>Description:
test_and_{set,clear}_bit are currently broken as they do nothing if
bit > sizeof(long) * CHAR_BIT. Attached patch also changes int to
long in 3 previous macros, which could lead to inconsistent behavior
on non-little-endian architectures where sizeof(int) != sizeof(long).
>How-To-Repeat:

>Fix:


Patch attached with submission follows:

Index: sys/ofed/include/linux/bitops.h
===================================================================
--- sys/ofed/include/linux/bitops.h	(revision 244048)
+++ sys/ofed/include/linux/bitops.h	(working copy)
@@ -272,22 +272,24 @@
 	return (1);
 }
 
-#define	NBINT	(NBBY * sizeof(int))
+#define	NBLONG	(NBBY * sizeof(long))
 
 #define	set_bit(i, a)							\
-    atomic_set_int(&((volatile int *)(a))[(i)/NBINT], 1 << (i) % NBINT)
+    atomic_set_long(&((volatile long *)(a))[(i)/NBLONG], 1 << (i) % NBLONG)
 
 #define	clear_bit(i, a)							\
-    atomic_clear_int(&((volatile int *)(a))[(i)/NBINT], 1 << (i) % NBINT)
+    atomic_clear_long(&((volatile long *)(a))[(i)/NBLONG], 1 << (i) % NBLONG)
 
 #define	test_bit(i, a)							\
-    !!(atomic_load_acq_int(&((volatile int *)(a))[(i)/NBINT]) & 1 << ((i) % NBINT))
+    !!(atomic_load_acq_long(&((volatile long *)(a))[(i)/NBLONG]) & 1 << ((i) % NBLONG))
 
 static inline long
 test_and_clear_bit(long bit, long *var)
 {
 	long val;
 
+	var += bit / (sizeof(long) * NBBY);
+	bit %= sizeof(long) * NBBY;
 	bit = 1 << bit;
 	do {
 		val = *(volatile long *)var;
@@ -301,6 +303,8 @@
 {
 	long val;
 
+	var += bit / (sizeof(long) * NBBY);
+	bit %= sizeof(long) * NBBY;
 	bit = 1 << bit;
 	do {
 		val = *(volatile long *)var;


>Release-Note:
>Audit-Trail:
>Unformatted:
