Bug 123793 - [PATCH] problem with ffs() on x86_64?
[PATCH] problem with ffs() on x86_64?
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 3
Classification: Red Hat
Component: kernel (Show other bugs)
3.0
x86_64 Linux
medium Severity medium
: ---
: ---
Assigned To: Jim Paradis
Brian Brock
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2004-05-20 11:56 EDT by Eric Sandeen
Modified: 2013-08-05 21:07 EDT (History)
3 users (show)

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


Attachments (Terms of Use)

  None (edit)
Description Eric Sandeen 2004-05-20 11:56:29 EDT
I found this when using XFS, but wondering if it may be a problem in
general.

I hit the following problem after merging xfs into an RHEL kernel:
http://www.uwsg.iu.edu/hypermail/linux/kernel/0308.2/1763.html

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.

Thanks,

-Eric
Comment 1 Eric Sandeen 2004-05-20 12:10:39 EDT
See also
http://www.uwsg.iu.edu/hypermail/linux/kernel/0405.1/0937.html

---------

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
-- 
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/ &
http://www-stu.christs.cam.ac.uk/~aia21/

--- 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 00:50:08 EDT
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 00:31:37 EDT
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.

http://rhn.redhat.com/errata/RHBA-2004-433.html

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