Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 468a9428 authored by George Spelvin's avatar George Spelvin
Browse files

<linux/hash.h>: Add support for architecture-specific functions



This is just the infrastructure; there are no users yet.

This is modelled on CONFIG_ARCH_RANDOM; a CONFIG_ symbol declares
the existence of <asm/hash.h>.

That file may define its own versions of various functions, and define
HAVE_* symbols (no CONFIG_ prefix!) to suppress the generic ones.

Included is a self-test (in lib/test_hash.c) that verifies the basics.
It is NOT in general required that the arch-specific functions compute
the same thing as the generic, but if a HAVE_* symbol is defined with
the value 1, then equality is tested.

Signed-off-by: default avatarGeorge Spelvin <linux@sciencehorizons.net>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Greg Ungerer <gerg@linux-m68k.org>
Cc: Andreas Schwab <schwab@linux-m68k.org>
Cc: Philippe De Muyter <phdm@macq.eu>
Cc: linux-m68k@lists.linux-m68k.org
Cc: Alistair Francis <alistai@xilinx.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: uclinux-h8-devel@lists.sourceforge.jp
parent 2a18da7a
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -589,6 +589,14 @@ config HAVE_STACK_VALIDATION
	  Architecture supports the 'objtool check' host tool command, which
	  performs compile-time stack metadata validation.

config HAVE_ARCH_HASH
	bool
	default n
	help
	  If this is set, the architecture provides an <asm/hash.h>
	  file which provides platform-specific implementations of some
	  functions in <linux/hash.h> or fs/namei.c.

#
# ABI hall of shame
#
+5 −1
Original line number Diff line number Diff line
@@ -1788,7 +1788,11 @@ static int walk_component(struct nameidata *nd, int flags)

#include <asm/word-at-a-time.h>

#ifdef CONFIG_64BIT
#ifdef HASH_MIX

/* Architecture provides HASH_MIX and fold_hash() in <asm/hash.h> */

#elif defined(CONFIG_64BIT)
/*
 * Register pressure in the mixing function is an issue, particularly
 * on 32-bit x86, but almost any function requires one state value and
+24 −3
Original line number Diff line number Diff line
@@ -41,19 +41,40 @@
#define GOLDEN_RATIO_32 0x61C88647
#define GOLDEN_RATIO_64 0x61C8864680B583EBull

#ifdef CONFIG_HAVE_ARCH_HASH
/* This header may use the GOLDEN_RATIO_xx constants */
#include <asm/hash.h>
#endif

static inline u32 __hash_32(u32 val)
/*
 * The _generic versions exist only so lib/test_hash.c can compare
 * the arch-optimized versions with the generic.
 *
 * Note that if you change these, any <asm/hash.h> that aren't updated
 * to match need to have their HAVE_ARCH_* define values updated so the
 * self-test will not false-positive.
 */
#ifndef HAVE_ARCH__HASH_32
#define __hash_32 __hash_32_generic
#endif
static inline u32 __hash_32_generic(u32 val)
{
	return val * GOLDEN_RATIO_32;
}

static inline u32 hash_32(u32 val, unsigned int bits)
#ifndef HAVE_ARCH_HASH_32
#define hash_32 hash_32_generic
#endif
static inline u32 hash_32_generic(u32 val, unsigned int bits)
{
	/* High bits are more random, so use them. */
	return __hash_32(val) >> (32 - bits);
}

static __always_inline u32 hash_64(u64 val, unsigned int bits)
#ifndef HAVE_ARCH_HASH_64
#define hash_64 hash_64_generic
#endif
static __always_inline u32 hash_64_generic(u64 val, unsigned int bits)
{
#if BITS_PER_LONG == 64
	/* 64x64-bit multiply is efficient on all 64-bit processors */
+11 −0
Original line number Diff line number Diff line
@@ -1815,6 +1815,17 @@ config TEST_RHASHTABLE

	  If unsure, say N.

config TEST_HASH
	tristate "Perform selftest on hash functions"
	default n
	help
	  Enable this option to test the kernel's integer (<linux/hash,h>)
	  and string (<linux/stringhash.h>) hash functions on boot
	  (or module load).

	  This is intended to help people writing architecture-specific
	  optimized versions.  If unsure, say N.

endmenu # runtime tests

config PROVIDE_OHCI1394_DMA_INIT
+1 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ obj-$(CONFIG_TEST_HEXDUMP) += test_hexdump.o
obj-y += kstrtox.o
obj-$(CONFIG_TEST_BPF) += test_bpf.o
obj-$(CONFIG_TEST_FIRMWARE) += test_firmware.o
obj-$(CONFIG_TEST_HASH) += test_hash.o
obj-$(CONFIG_TEST_KASAN) += test_kasan.o
obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o
obj-$(CONFIG_TEST_LKM) += test_module.o
Loading