Bug 123793 - [PATCH] problem with ffs() on x86_64?
Summary: [PATCH] problem with ffs() on x86_64?
Alias: None
Product: Red Hat Enterprise Linux 3
Classification: Red Hat
Component: kernel   
(Show other bugs)
Version: 3.0
Hardware: x86_64
OS: Linux
Target Milestone: ---
Assignee: Jim Paradis
QA Contact: Brian Brock
Depends On:
TreeView+ depends on / blocked
Reported: 2004-05-20 15:56 UTC by Eric Sandeen
Modified: 2013-08-06 01:07 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2004-09-02 04:31:37 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

External Trackers
Tracker ID Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2004:433 normal SHIPPED_LIVE Updated kernel packages available for Red Hat Enterprise Linux 3 Update 3 2004-09-02 04:00:00 UTC

Description Eric Sandeen 2004-05-20 15:56:29 UTC
I found this when using XFS, but wondering if it may be a problem in

I hit the following problem after merging xfs into an RHEL kernel:

and in that thread Andi suggested this change:

--- linux-2.6.0test3-amd64/include/asm-x86_64/bitops.h-o 2003-07-11
13:34:21.000000000 +0200
+++ linux-2.6.0test3-amd64/include/asm-x86_64/bitops.h 2003-08-22
11:17:53.000000000 +0200
@@ -466,7 +466,7 @@
    __asm__("bsfl %1,%0\n\t"
    "cmovzl %2,%0" 
-    : "=r" (r) : "g" (x), "r" (32));
+    : "=r" (r) : "g" (x), "r" (-1));
    return r+1;

the above is now what's in 2.6 for x86_64 ffs()... 

your linux-2.4.21-amd64.patch patch does this:

@@ -370,9 +442,8 @@ static __inline__ int ffs(int x)
        int r;
        __asm__("bsfl %1,%0\n\t"
-               "jnz 1f\n\t"
-               "movl $-1,%0\n"
-               "1:" : "=r" (r) : "g" (x));
+               "cmovzl %2,%0"
+               : "=r" (r) : "g" (x), "r" (32));
        return r+1;

... I'm guessing that this update came back from 2.6?  In any case
2.6 now has 

-    : "=r" (r) : "g" (x), "r" (32));
+    : "=r" (r) : "g" (x), "r" (-1));

I don't have a test case for any of your supported bits of the kernel,
but thought maybe I should bring this to your attention in case it's a 
missing update.



Comment 1 Eric Sandeen 2004-05-20 16:10:39 UTC
See also


Hi Andi, Andrew, Linus,

x86_64 has incorrect include/asm-x86_64/bitops.h::ffs() implementation. 
It uses "g" instead of "rm" in the insline assembled bsfl instruction. 
(This was spotted by Yuri Per.)

bsfl does not accept constant values but only memory ones.  On i386 the
correct "rm" is used.

This causes NTFS build to fail as gcc optimizes a variable into a
constant and ffs() then fails to assemble.

Please apply below patch.  Thanks!

Best regards,

Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net
WWW: http://linux-ntfs.sf.net/ &

--- bklinux-2.6/include/asm-x86_64/bitops.h.old	2004-05-12
14:40:32.524022336 +0100
+++ bklinux-2.6/include/asm-x86_64/bitops.h	2004-05-12
14:41:22.595410328 +0100
@@ -458,7 +458,7 @@ static __inline__ int ffs(int x)
 	__asm__("bsfl %1,%0\n\t"
 		"cmovzl %2,%0" 
-		: "=r" (r) : "g" (x), "r" (-1));
+		: "=r" (r) : "rm" (x), "r" (-1));
 	return r+1;

Comment 2 Ernie Petrides 2004-06-08 04:50:08 UTC
The fix for this problem has just been committed to the RHEL3 U3
patch pool this evening (in kernel version 2.4.21-15.7.EL).

Comment 3 John Flanagan 2004-09-02 04:31:37 UTC
An errata has been issued which should help the problem 
described in this bug report. This report is therefore being 
closed with a resolution of ERRATA. For more information
on the solution and/or where to find the updated files, 
please follow the link below. You may reopen this bug report 
if the solution does not work for you.


Note You need to log in before you can comment on or make changes to this bug.