diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2016-05-28 19:15:25 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-05-28 19:15:25 -0400 |
| commit | 7e0fb73c52c4037b4d5ef9ff56c7296a3151bd92 (patch) | |
| tree | 9ab023505d388563d937b3c3ac26ef3c2045dba2 /include/linux/sunrpc | |
| parent | 4e8440b3b6b801953b2e53c55491cf98fc8f6c01 (diff) | |
| parent | 4684fe95300c071983f77653e354c040fe80a265 (diff) | |
Merge branch 'hash' of git://ftp.sciencehorizons.net/linux
Pull string hash improvements from George Spelvin:
"This series does several related things:
- Makes the dcache hash (fs/namei.c) useful for general kernel use.
(Thanks to Bruce for noticing the zero-length corner case)
- Converts the string hashes in <linux/sunrpc/svcauth.h> to use the
above.
- Avoids 64-bit multiplies in hash_64() on 32-bit platforms. Two
32-bit multiplies will do well enough.
- Rids the world of the bad hash multipliers in hash_32.
This finishes the job started in commit 689de1d6ca95 ("Minimal
fix-up of bad hashing behavior of hash_64()")
The vast majority of Linux architectures have hardware support for
32x32-bit multiply and so derive no benefit from "simplified"
multipliers.
The few processors that do not (68000, h8/300 and some models of
Microblaze) have arch-specific implementations added. Those
patches are last in the series.
- Overhauls the dcache hash mixing.
The patch in commit 0fed3ac866ea ("namei: Improve hash mixing if
CONFIG_DCACHE_WORD_ACCESS") was an off-the-cuff suggestion.
Replaced with a much more careful design that's simultaneously
faster and better. (My own invention, as there was noting suitable
in the literature I could find. Comments welcome!)
- Modify the hash_name() loop to skip the initial HASH_MIX(). This
would let us salt the hash if we ever wanted to.
- Sort out partial_name_hash().
The hash function is declared as using a long state, even though
it's truncated to 32 bits at the end and the extra internal state
contributes nothing to the result. And some callers do odd things:
- fs/hfs/string.c only allocates 32 bits of state
- fs/hfsplus/unicode.c uses it to hash 16-bit unicode symbols not bytes
- Modify bytemask_from_count to handle inputs of 1..sizeof(long)
rather than 0..sizeof(long)-1. This would simplify users other
than full_name_hash"
Special thanks to Bruce Fields for testing and finding bugs in v1. (I
learned some humbling lessons about "obviously correct" code.)
On the arch-specific front, the m68k assembly has been tested in a
standalone test harness, I've been in contact with the Microblaze
maintainers who mostly don't care, as the hardware multiplier is never
omitted in real-world applications, and I haven't heard anything from
the H8/300 world"
* 'hash' of git://ftp.sciencehorizons.net/linux:
h8300: Add <asm/hash.h>
microblaze: Add <asm/hash.h>
m68k: Add <asm/hash.h>
<linux/hash.h>: Add support for architecture-specific functions
fs/namei.c: Improve dcache hash function
Eliminate bad hash multipliers from hash_32() and hash_64()
Change hash_64() return value to 32 bits
<linux/sunrpc/svcauth.h>: Define hash_str() in terms of hashlen_string()
fs/namei.c: Add hashlen_string() function
Pull out string hash to <linux/stringhash.h>
Diffstat (limited to 'include/linux/sunrpc')
| -rw-r--r-- | include/linux/sunrpc/svcauth.h | 40 |
1 files changed, 9 insertions, 31 deletions
diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h index c00f53a4ccdd..91d5a5d6f52b 100644 --- a/include/linux/sunrpc/svcauth.h +++ b/include/linux/sunrpc/svcauth.h | |||
| @@ -16,6 +16,7 @@ | |||
| 16 | #include <linux/sunrpc/cache.h> | 16 | #include <linux/sunrpc/cache.h> |
| 17 | #include <linux/sunrpc/gss_api.h> | 17 | #include <linux/sunrpc/gss_api.h> |
| 18 | #include <linux/hash.h> | 18 | #include <linux/hash.h> |
| 19 | #include <linux/stringhash.h> | ||
| 19 | #include <linux/cred.h> | 20 | #include <linux/cred.h> |
| 20 | 21 | ||
| 21 | struct svc_cred { | 22 | struct svc_cred { |
| @@ -165,41 +166,18 @@ extern int svcauth_unix_set_client(struct svc_rqst *rqstp); | |||
| 165 | extern int unix_gid_cache_create(struct net *net); | 166 | extern int unix_gid_cache_create(struct net *net); |
| 166 | extern void unix_gid_cache_destroy(struct net *net); | 167 | extern void unix_gid_cache_destroy(struct net *net); |
| 167 | 168 | ||
| 168 | static inline unsigned long hash_str(char *name, int bits) | 169 | /* |
| 170 | * The <stringhash.h> functions are good enough that we don't need to | ||
| 171 | * use hash_32() on them; just extracting the high bits is enough. | ||
| 172 | */ | ||
| 173 | static inline unsigned long hash_str(char const *name, int bits) | ||
| 169 | { | 174 | { |
| 170 | unsigned long hash = 0; | 175 | return hashlen_hash(hashlen_string(name)) >> (32 - bits); |
| 171 | unsigned long l = 0; | ||
| 172 | int len = 0; | ||
| 173 | unsigned char c; | ||
| 174 | do { | ||
| 175 | if (unlikely(!(c = *name++))) { | ||
| 176 | c = (char)len; len = -1; | ||
| 177 | } | ||
| 178 | l = (l << 8) | c; | ||
| 179 | len++; | ||
| 180 | if ((len & (BITS_PER_LONG/8-1))==0) | ||
| 181 | hash = hash_long(hash^l, BITS_PER_LONG); | ||
| 182 | } while (len); | ||
| 183 | return hash >> (BITS_PER_LONG - bits); | ||
| 184 | } | 176 | } |
| 185 | 177 | ||
| 186 | static inline unsigned long hash_mem(char *buf, int length, int bits) | 178 | static inline unsigned long hash_mem(char const *buf, int length, int bits) |
| 187 | { | 179 | { |
| 188 | unsigned long hash = 0; | 180 | return full_name_hash(buf, length) >> (32 - bits); |
| 189 | unsigned long l = 0; | ||
| 190 | int len = 0; | ||
| 191 | unsigned char c; | ||
| 192 | do { | ||
| 193 | if (len == length) { | ||
| 194 | c = (char)len; len = -1; | ||
| 195 | } else | ||
| 196 | c = *buf++; | ||
| 197 | l = (l << 8) | c; | ||
| 198 | len++; | ||
| 199 | if ((len & (BITS_PER_LONG/8-1))==0) | ||
| 200 | hash = hash_long(hash^l, BITS_PER_LONG); | ||
| 201 | } while (len); | ||
| 202 | return hash >> (BITS_PER_LONG - bits); | ||
| 203 | } | 181 | } |
| 204 | 182 | ||
| 205 | #endif /* __KERNEL__ */ | 183 | #endif /* __KERNEL__ */ |
