* [PATCH] mbcache: LLVMLinux: Remove double calculation from mbcache
@ 2014-04-30 1:10 behanw
2014-04-30 1:13 ` H. Peter Anvin
0 siblings, 1 reply; 4+ messages in thread
From: behanw @ 2014-04-30 1:10 UTC (permalink / raw)
To: viro
Cc: linux-fsdevel, linux-kernel, torvalds, hpa, dwmw2,
Mark Charlebois, Behan Webster
From: Mark Charlebois <charlebm@gmail.com>
The call to __builtin_log2 presumes there is a
double log2(double x) function defined in the kernel.
The call to hash_log is a call to hash_64 which is
defined in include/linux/hash.h
static __always_inline u64 hash_64(u64 val, unsigned int bits)
That means that __builtin_log2(NR_BG_LOCKS) is converting
NR_BG_LOCKS to a double and returning a double and then that
is converted to an unsigned int.
Using ilog2 is much more appropriate and efficient.
Another side effect of using __builtin_log2 is that is uses
__aeabi_* functions for ARM that require linking with libgcc.a.
Author: Mark Charlebois <charlebm@gmail.com>
Signed-off-by: Mark Charlebois <charlebm@gmail.com>
Signed-off-by: Behan Webster <behanw@converseincode.com>
---
fs/mbcache.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/mbcache.c b/fs/mbcache.c
index bf166e3..2c0752b 100644
--- a/fs/mbcache.c
+++ b/fs/mbcache.c
@@ -93,7 +93,7 @@
#define MB_CACHE_WRITER ((unsigned short)~0U >> 1)
-#define MB_CACHE_ENTRY_LOCK_BITS __builtin_log2(NR_BG_LOCKS)
+#define MB_CACHE_ENTRY_LOCK_BITS ilog2(NR_BG_LOCKS)
#define MB_CACHE_ENTRY_LOCK_INDEX(ce) \
(hash_long((unsigned long)ce, MB_CACHE_ENTRY_LOCK_BITS))
--
1.8.3.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] mbcache: LLVMLinux: Remove double calculation from mbcache
2014-04-30 1:10 [PATCH] mbcache: LLVMLinux: Remove double calculation from mbcache behanw
@ 2014-04-30 1:13 ` H. Peter Anvin
2014-04-30 5:19 ` H. Peter Anvin
0 siblings, 1 reply; 4+ messages in thread
From: H. Peter Anvin @ 2014-04-30 1:13 UTC (permalink / raw)
To: behanw, viro
Cc: linux-fsdevel, linux-kernel, torvalds, dwmw2, Mark Charlebois
I suspect this will generate FP instructions on x86 which will corrupt user space state. This is thus a critical bug!!
On April 29, 2014 6:10:39 PM PDT, behanw@converseincode.com wrote:
>From: Mark Charlebois <charlebm@gmail.com>
>
>The call to __builtin_log2 presumes there is a
>double log2(double x) function defined in the kernel.
>
>The call to hash_log is a call to hash_64 which is
>defined in include/linux/hash.h
>
>static __always_inline u64 hash_64(u64 val, unsigned int bits)
>
>That means that __builtin_log2(NR_BG_LOCKS) is converting
>NR_BG_LOCKS to a double and returning a double and then that
>is converted to an unsigned int.
>
>Using ilog2 is much more appropriate and efficient.
>
>Another side effect of using __builtin_log2 is that is uses
>__aeabi_* functions for ARM that require linking with libgcc.a.
>
>Author: Mark Charlebois <charlebm@gmail.com>
>Signed-off-by: Mark Charlebois <charlebm@gmail.com>
>Signed-off-by: Behan Webster <behanw@converseincode.com>
>---
> fs/mbcache.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/fs/mbcache.c b/fs/mbcache.c
>index bf166e3..2c0752b 100644
>--- a/fs/mbcache.c
>+++ b/fs/mbcache.c
>@@ -93,7 +93,7 @@
>
> #define MB_CACHE_WRITER ((unsigned short)~0U >> 1)
>
>-#define MB_CACHE_ENTRY_LOCK_BITS __builtin_log2(NR_BG_LOCKS)
>+#define MB_CACHE_ENTRY_LOCK_BITS ilog2(NR_BG_LOCKS)
> #define MB_CACHE_ENTRY_LOCK_INDEX(ce) \
> (hash_long((unsigned long)ce, MB_CACHE_ENTRY_LOCK_BITS))
>
--
Sent from my mobile phone. Please pardon brevity and lack of formatting.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] mbcache: LLVMLinux: Remove double calculation from mbcache
@ 2014-04-22 5:19 behanw
0 siblings, 0 replies; 4+ messages in thread
From: behanw @ 2014-04-22 5:19 UTC (permalink / raw)
To: viro
Cc: linux-fsdevel, linux-kernel, dwmw2, pageexec, Mark Charlebois,
Behan Webster
From: Mark Charlebois <charlebm@gmail.com>
The call to __builtin_log2 presumes there is a
double log2(double x) function defined in the kernel.
The call to hash_log is a call to hash_64 which is
defined in include/linux/hash.h
static __always_inline u64 hash_64(u64 val, unsigned int bits)
That means that __builtin_log2(NR_BG_LOCKS) is converting
NR_BG_LOCKS to a double and returning a double and then that
is converted to an unsigned int.
Using ilog2 is much more appropriate and efficient.
Another side effect of using __builtin_log2 is that is uses
__aeabi_* functions for ARM that require linking with libgcc.a.
Author: Mark Charlebois <charlebm@gmail.com>
Signed-off-by: Mark Charlebois <charlebm@gmail.com>
Signed-off-by: Behan Webster <behanw@converseincode.com>
---
fs/mbcache.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/mbcache.c b/fs/mbcache.c
index bf166e3..2c0752b 100644
--- a/fs/mbcache.c
+++ b/fs/mbcache.c
@@ -93,7 +93,7 @@
#define MB_CACHE_WRITER ((unsigned short)~0U >> 1)
-#define MB_CACHE_ENTRY_LOCK_BITS __builtin_log2(NR_BG_LOCKS)
+#define MB_CACHE_ENTRY_LOCK_BITS ilog2(NR_BG_LOCKS)
#define MB_CACHE_ENTRY_LOCK_INDEX(ce) \
(hash_long((unsigned long)ce, MB_CACHE_ENTRY_LOCK_BITS))
--
1.8.3.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-04-30 5:19 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-30 1:10 [PATCH] mbcache: LLVMLinux: Remove double calculation from mbcache behanw
2014-04-30 1:13 ` H. Peter Anvin
2014-04-30 5:19 ` H. Peter Anvin
-- strict thread matches above, loose matches on Subject: below --
2014-04-22 5:19 behanw
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).