Commit a5c21dce authored by Will Deacon's avatar Will Deacon Committed by Linus Torvalds

dcache: allow word-at-a-time name hashing with big-endian CPUs

When explicitly hashing the end of a string with the word-at-a-time
interface, we have to be careful which end of the word we pick up.

On big-endian CPUs, the upper-bits will contain the data we're after, so
ensure we generate our masks accordingly (and avoid hashing whatever
random junk may have been sitting after the string).

This patch adds a new dcache helper, bytemask_from_count, which creates
a mask appropriate for the CPU endianness.

Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 319720f5
...@@ -192,7 +192,7 @@ static inline int dentry_string_cmp(const unsigned char *cs, const unsigned char ...@@ -192,7 +192,7 @@ static inline int dentry_string_cmp(const unsigned char *cs, const unsigned char
if (!tcount) if (!tcount)
return 0; return 0;
} }
mask = ~(~0ul << tcount*8); mask = bytemask_from_count(tcount);
return unlikely(!!((a ^ b) & mask)); return unlikely(!!((a ^ b) & mask));
} }
......
...@@ -1598,11 +1598,6 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd) ...@@ -1598,11 +1598,6 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
* do a "get_unaligned()" if this helps and is sufficiently * do a "get_unaligned()" if this helps and is sufficiently
* fast. * fast.
* *
* - Little-endian machines (so that we can generate the mask
* of low bytes efficiently). Again, we *could* do a byte
* swapping load on big-endian architectures if that is not
* expensive enough to make the optimization worthless.
*
* - non-CONFIG_DEBUG_PAGEALLOC configurations (so that we * - non-CONFIG_DEBUG_PAGEALLOC configurations (so that we
* do not trap on the (extremely unlikely) case of a page * do not trap on the (extremely unlikely) case of a page
* crossing operation. * crossing operation.
...@@ -1646,7 +1641,7 @@ unsigned int full_name_hash(const unsigned char *name, unsigned int len) ...@@ -1646,7 +1641,7 @@ unsigned int full_name_hash(const unsigned char *name, unsigned int len)
if (!len) if (!len)
goto done; goto done;
} }
mask = ~(~0ul << len*8); mask = bytemask_from_count(len);
hash += mask & a; hash += mask & a;
done: done:
return fold_hash(hash); return fold_hash(hash);
......
...@@ -29,8 +29,10 @@ struct vfsmount; ...@@ -29,8 +29,10 @@ struct vfsmount;
/* The hash is always the low bits of hash_len */ /* The hash is always the low bits of hash_len */
#ifdef __LITTLE_ENDIAN #ifdef __LITTLE_ENDIAN
#define HASH_LEN_DECLARE u32 hash; u32 len; #define HASH_LEN_DECLARE u32 hash; u32 len;
#define bytemask_from_count(cnt) (~(~0ul << (cnt)*8))
#else #else
#define HASH_LEN_DECLARE u32 len; u32 hash; #define HASH_LEN_DECLARE u32 len; u32 hash;
#define bytemask_from_count(cnt) (~(~0ul >> (cnt)*8))
#endif #endif
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment