diff options
| author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-07-18 17:39:36 -0400 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-07-18 17:41:50 -0400 |
| commit | ae3c14a028ed10552803b68276b6833295ba18cf (patch) | |
| tree | 6317f5da60cc6b74cbf78d12b5d4b3c6aa0c9e68 /tools/include/linux | |
| parent | 3aa0042769313b720142c0ef8514dac389e14ebe (diff) | |
tools: Copy linux/{hash,poison}.h and check for drift
We were also using this directly from the kernel sources, the two last
cases, fix it.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-7o14xvacqcjc5llc7gvjjyl8@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/include/linux')
| -rw-r--r-- | tools/include/linux/hash.h | 105 | ||||
| -rw-r--r-- | tools/include/linux/poison.h | 91 |
2 files changed, 192 insertions, 4 deletions
diff --git a/tools/include/linux/hash.h b/tools/include/linux/hash.h index d026c6573018..ad6fa21d977b 100644 --- a/tools/include/linux/hash.h +++ b/tools/include/linux/hash.h | |||
| @@ -1,5 +1,104 @@ | |||
| 1 | #include "../../../include/linux/hash.h" | 1 | #ifndef _LINUX_HASH_H |
| 2 | #define _LINUX_HASH_H | ||
| 3 | /* Fast hashing routine for ints, longs and pointers. | ||
| 4 | (C) 2002 Nadia Yvette Chambers, IBM */ | ||
| 2 | 5 | ||
| 3 | #ifndef _TOOLS_LINUX_HASH_H | 6 | #include <asm/types.h> |
| 4 | #define _TOOLS_LINUX_HASH_H | 7 | #include <linux/compiler.h> |
| 8 | |||
| 9 | /* | ||
| 10 | * The "GOLDEN_RATIO_PRIME" is used in ifs/btrfs/brtfs_inode.h and | ||
| 11 | * fs/inode.c. It's not actually prime any more (the previous primes | ||
| 12 | * were actively bad for hashing), but the name remains. | ||
| 13 | */ | ||
| 14 | #if BITS_PER_LONG == 32 | ||
| 15 | #define GOLDEN_RATIO_PRIME GOLDEN_RATIO_32 | ||
| 16 | #define hash_long(val, bits) hash_32(val, bits) | ||
| 17 | #elif BITS_PER_LONG == 64 | ||
| 18 | #define hash_long(val, bits) hash_64(val, bits) | ||
| 19 | #define GOLDEN_RATIO_PRIME GOLDEN_RATIO_64 | ||
| 20 | #else | ||
| 21 | #error Wordsize not 32 or 64 | ||
| 22 | #endif | ||
| 23 | |||
| 24 | /* | ||
| 25 | * This hash multiplies the input by a large odd number and takes the | ||
| 26 | * high bits. Since multiplication propagates changes to the most | ||
| 27 | * significant end only, it is essential that the high bits of the | ||
| 28 | * product be used for the hash value. | ||
| 29 | * | ||
| 30 | * Chuck Lever verified the effectiveness of this technique: | ||
| 31 | * http://www.citi.umich.edu/techreports/reports/citi-tr-00-1.pdf | ||
| 32 | * | ||
| 33 | * Although a random odd number will do, it turns out that the golden | ||
| 34 | * ratio phi = (sqrt(5)-1)/2, or its negative, has particularly nice | ||
| 35 | * properties. (See Knuth vol 3, section 6.4, exercise 9.) | ||
| 36 | * | ||
| 37 | * These are the negative, (1 - phi) = phi**2 = (3 - sqrt(5))/2, | ||
| 38 | * which is very slightly easier to multiply by and makes no | ||
| 39 | * difference to the hash distribution. | ||
| 40 | */ | ||
| 41 | #define GOLDEN_RATIO_32 0x61C88647 | ||
| 42 | #define GOLDEN_RATIO_64 0x61C8864680B583EBull | ||
| 43 | |||
| 44 | #ifdef CONFIG_HAVE_ARCH_HASH | ||
| 45 | /* This header may use the GOLDEN_RATIO_xx constants */ | ||
| 46 | #include <asm/hash.h> | ||
| 47 | #endif | ||
| 48 | |||
| 49 | /* | ||
| 50 | * The _generic versions exist only so lib/test_hash.c can compare | ||
| 51 | * the arch-optimized versions with the generic. | ||
| 52 | * | ||
| 53 | * Note that if you change these, any <asm/hash.h> that aren't updated | ||
| 54 | * to match need to have their HAVE_ARCH_* define values updated so the | ||
| 55 | * self-test will not false-positive. | ||
| 56 | */ | ||
| 57 | #ifndef HAVE_ARCH__HASH_32 | ||
| 58 | #define __hash_32 __hash_32_generic | ||
| 59 | #endif | ||
| 60 | static inline u32 __hash_32_generic(u32 val) | ||
| 61 | { | ||
| 62 | return val * GOLDEN_RATIO_32; | ||
| 63 | } | ||
| 64 | |||
| 65 | #ifndef HAVE_ARCH_HASH_32 | ||
| 66 | #define hash_32 hash_32_generic | ||
| 5 | #endif | 67 | #endif |
| 68 | static inline u32 hash_32_generic(u32 val, unsigned int bits) | ||
| 69 | { | ||
| 70 | /* High bits are more random, so use them. */ | ||
| 71 | return __hash_32(val) >> (32 - bits); | ||
| 72 | } | ||
| 73 | |||
| 74 | #ifndef HAVE_ARCH_HASH_64 | ||
| 75 | #define hash_64 hash_64_generic | ||
| 76 | #endif | ||
| 77 | static __always_inline u32 hash_64_generic(u64 val, unsigned int bits) | ||
| 78 | { | ||
| 79 | #if BITS_PER_LONG == 64 | ||
| 80 | /* 64x64-bit multiply is efficient on all 64-bit processors */ | ||
| 81 | return val * GOLDEN_RATIO_64 >> (64 - bits); | ||
| 82 | #else | ||
| 83 | /* Hash 64 bits using only 32x32-bit multiply. */ | ||
| 84 | return hash_32((u32)val ^ __hash_32(val >> 32), bits); | ||
| 85 | #endif | ||
| 86 | } | ||
| 87 | |||
| 88 | static inline u32 hash_ptr(const void *ptr, unsigned int bits) | ||
| 89 | { | ||
| 90 | return hash_long((unsigned long)ptr, bits); | ||
| 91 | } | ||
| 92 | |||
| 93 | /* This really should be called fold32_ptr; it does no hashing to speak of. */ | ||
| 94 | static inline u32 hash32_ptr(const void *ptr) | ||
| 95 | { | ||
| 96 | unsigned long val = (unsigned long)ptr; | ||
| 97 | |||
| 98 | #if BITS_PER_LONG == 64 | ||
| 99 | val ^= (val >> 32); | ||
| 100 | #endif | ||
| 101 | return (u32)val; | ||
| 102 | } | ||
| 103 | |||
| 104 | #endif /* _LINUX_HASH_H */ | ||
diff --git a/tools/include/linux/poison.h b/tools/include/linux/poison.h index 0c27bdf14233..51334edec506 100644 --- a/tools/include/linux/poison.h +++ b/tools/include/linux/poison.h | |||
| @@ -1 +1,90 @@ | |||
| 1 | #include "../../../include/linux/poison.h" | 1 | #ifndef _LINUX_POISON_H |
| 2 | #define _LINUX_POISON_H | ||
| 3 | |||
| 4 | /********** include/linux/list.h **********/ | ||
| 5 | |||
| 6 | /* | ||
| 7 | * Architectures might want to move the poison pointer offset | ||
| 8 | * into some well-recognized area such as 0xdead000000000000, | ||
| 9 | * that is also not mappable by user-space exploits: | ||
| 10 | */ | ||
| 11 | #ifdef CONFIG_ILLEGAL_POINTER_VALUE | ||
| 12 | # define POISON_POINTER_DELTA _AC(CONFIG_ILLEGAL_POINTER_VALUE, UL) | ||
| 13 | #else | ||
| 14 | # define POISON_POINTER_DELTA 0 | ||
| 15 | #endif | ||
| 16 | |||
| 17 | /* | ||
| 18 | * These are non-NULL pointers that will result in page faults | ||
| 19 | * under normal circumstances, used to verify that nobody uses | ||
| 20 | * non-initialized list entries. | ||
| 21 | */ | ||
| 22 | #define LIST_POISON1 ((void *) 0x100 + POISON_POINTER_DELTA) | ||
| 23 | #define LIST_POISON2 ((void *) 0x200 + POISON_POINTER_DELTA) | ||
| 24 | |||
| 25 | /********** include/linux/timer.h **********/ | ||
| 26 | /* | ||
| 27 | * Magic number "tsta" to indicate a static timer initializer | ||
| 28 | * for the object debugging code. | ||
| 29 | */ | ||
| 30 | #define TIMER_ENTRY_STATIC ((void *) 0x300 + POISON_POINTER_DELTA) | ||
| 31 | |||
| 32 | /********** mm/debug-pagealloc.c **********/ | ||
| 33 | #ifdef CONFIG_PAGE_POISONING_ZERO | ||
| 34 | #define PAGE_POISON 0x00 | ||
| 35 | #else | ||
| 36 | #define PAGE_POISON 0xaa | ||
| 37 | #endif | ||
| 38 | |||
| 39 | /********** mm/page_alloc.c ************/ | ||
| 40 | |||
| 41 | #define TAIL_MAPPING ((void *) 0x400 + POISON_POINTER_DELTA) | ||
| 42 | |||
| 43 | /********** mm/slab.c **********/ | ||
| 44 | /* | ||
| 45 | * Magic nums for obj red zoning. | ||
| 46 | * Placed in the first word before and the first word after an obj. | ||
| 47 | */ | ||
| 48 | #define RED_INACTIVE 0x09F911029D74E35BULL /* when obj is inactive */ | ||
| 49 | #define RED_ACTIVE 0xD84156C5635688C0ULL /* when obj is active */ | ||
| 50 | |||
| 51 | #define SLUB_RED_INACTIVE 0xbb | ||
| 52 | #define SLUB_RED_ACTIVE 0xcc | ||
| 53 | |||
| 54 | /* ...and for poisoning */ | ||
| 55 | #define POISON_INUSE 0x5a /* for use-uninitialised poisoning */ | ||
| 56 | #define POISON_FREE 0x6b /* for use-after-free poisoning */ | ||
| 57 | #define POISON_END 0xa5 /* end-byte of poisoning */ | ||
| 58 | |||
| 59 | /********** arch/$ARCH/mm/init.c **********/ | ||
| 60 | #define POISON_FREE_INITMEM 0xcc | ||
| 61 | |||
| 62 | /********** arch/ia64/hp/common/sba_iommu.c **********/ | ||
| 63 | /* | ||
| 64 | * arch/ia64/hp/common/sba_iommu.c uses a 16-byte poison string with a | ||
| 65 | * value of "SBAIOMMU POISON\0" for spill-over poisoning. | ||
| 66 | */ | ||
| 67 | |||
| 68 | /********** fs/jbd/journal.c **********/ | ||
| 69 | #define JBD_POISON_FREE 0x5b | ||
| 70 | #define JBD2_POISON_FREE 0x5c | ||
| 71 | |||
| 72 | /********** drivers/base/dmapool.c **********/ | ||
| 73 | #define POOL_POISON_FREED 0xa7 /* !inuse */ | ||
| 74 | #define POOL_POISON_ALLOCATED 0xa9 /* !initted */ | ||
| 75 | |||
| 76 | /********** drivers/atm/ **********/ | ||
| 77 | #define ATM_POISON_FREE 0x12 | ||
| 78 | #define ATM_POISON 0xdeadbeef | ||
| 79 | |||
| 80 | /********** kernel/mutexes **********/ | ||
| 81 | #define MUTEX_DEBUG_INIT 0x11 | ||
| 82 | #define MUTEX_DEBUG_FREE 0x22 | ||
| 83 | |||
| 84 | /********** lib/flex_array.c **********/ | ||
| 85 | #define FLEX_ARRAY_FREE 0x6c /* for use-after-free poisoning */ | ||
| 86 | |||
| 87 | /********** security/ **********/ | ||
| 88 | #define KEY_DESTROY 0xbd | ||
| 89 | |||
| 90 | #endif | ||
