mirror of
https://github.com/linux-msm/laptops-kernel.git
synced 2026-08-13 14:19:53 -07:00
Pull misc kernel updates from Christian Brauner:
"Fixes
- rhashtable: give each instance its own lockdep class
syzbot reported a circular locking dependency between ht->mutex and
fs_reclaim via the simple_xattrs rhashtable being torn down during
inode eviction.
The predicted deadlock cannot occur: rhashtable_free_and_destroy()
cancels the deferred worker before taking ht->mutex and
acquisitions on distinct rhashtables are on distinct mutexes.
Lockdep flags a cycle anyway because every ht->mutex in the kernel
shared the single static lockdep class from
rhashtable_init_noprof().
The lockdep key is lifted to a per-call-site static key so every
rhashtable instance gets its own class.
- selftests/clone3: fix misuse of the libcap library interface in the
cap_checkpoint_restore test and remove unused variables
- selftests/pid_namespace: compute the pid_max test limits
dynamically instead of hardcoding values below the kernel-enforced
minimum of PIDS_PER_CPU_MIN * num_possible_cpus() which made the
tests fail on machines with many possible CPUs
- selftests: fix the Makefile TARGETS entry for nsfs which wasn't
adjusted when the tests moved under filesystems/
Cleanups
- ipc/sem.c: use unsigned int for nsops to match the declaration in
syscalls.h"
* tag 'kernel-7.2-rc1.misc' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs:
selftests/clone3: remove unused variables
selftests/clone3: fix libcap interface usage
ipc/sem.c: use unsigned int for nsops
selftests: Fix Makefile target for nsfs
rhashtable: give each instance its own lockdep class
selftests/pid_namespace: compute pid_max test limits dynamically
162 lines
4.3 KiB
C
162 lines
4.3 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
/*
|
|
* Resizable, Scalable, Concurrent Hash Table
|
|
*
|
|
* Simple structures that might be needed in include
|
|
* files.
|
|
*/
|
|
|
|
#ifndef _LINUX_RHASHTABLE_TYPES_H
|
|
#define _LINUX_RHASHTABLE_TYPES_H
|
|
|
|
#include <linux/alloc_tag.h>
|
|
#include <linux/atomic.h>
|
|
#include <linux/compiler.h>
|
|
#include <linux/irq_work_types.h>
|
|
#include <linux/mutex.h>
|
|
#include <linux/workqueue_types.h>
|
|
|
|
struct rhash_head {
|
|
struct rhash_head __rcu *next;
|
|
};
|
|
|
|
struct rhlist_head {
|
|
struct rhash_head rhead;
|
|
struct rhlist_head __rcu *next;
|
|
};
|
|
|
|
struct bucket_table;
|
|
|
|
/**
|
|
* struct rhashtable_compare_arg - Key for the function rhashtable_compare
|
|
* @ht: Hash table
|
|
* @key: Key to compare against
|
|
*/
|
|
struct rhashtable_compare_arg {
|
|
struct rhashtable *ht;
|
|
const void *key;
|
|
};
|
|
|
|
typedef u32 (*rht_hashfn_t)(const void *data, u32 len, u32 seed);
|
|
typedef u32 (*rht_obj_hashfn_t)(const void *data, u32 len, u32 seed);
|
|
typedef int (*rht_obj_cmpfn_t)(struct rhashtable_compare_arg *arg,
|
|
const void *obj);
|
|
|
|
/**
|
|
* struct rhashtable_params - Hash table construction parameters
|
|
* @nelem_hint: Hint on number of elements, should be 75% of desired size
|
|
* @key_len: Length of key
|
|
* @key_offset: Offset of key in struct to be hashed
|
|
* @head_offset: Offset of rhash_head in struct to be hashed
|
|
* @max_size: Maximum size while expanding
|
|
* @min_size: Minimum size while shrinking
|
|
* @insecure_elasticity: Set to true to disable chain length checks
|
|
* @automatic_shrinking: Enable automatic shrinking of tables
|
|
* @hashfn: Hash function (default: jhash2 if !(key_len % 4), or jhash)
|
|
* @obj_hashfn: Function to hash object
|
|
* @obj_cmpfn: Function to compare key with object
|
|
*/
|
|
struct rhashtable_params {
|
|
u16 nelem_hint;
|
|
u16 key_len;
|
|
u16 key_offset;
|
|
u16 head_offset;
|
|
unsigned int max_size;
|
|
u16 min_size;
|
|
bool insecure_elasticity;
|
|
bool automatic_shrinking;
|
|
rht_hashfn_t hashfn;
|
|
rht_obj_hashfn_t obj_hashfn;
|
|
rht_obj_cmpfn_t obj_cmpfn;
|
|
};
|
|
|
|
/**
|
|
* struct rhashtable - Hash table handle
|
|
* @tbl: Bucket table
|
|
* @key_len: Key length for hashfn
|
|
* @max_elems: Maximum number of elements in table
|
|
* @p: Configuration parameters
|
|
* @rhlist: True if this is an rhltable
|
|
* @run_work: Deferred worker to expand/shrink asynchronously
|
|
* @run_irq_work: Bounces the @run_work kick through hard IRQ context.
|
|
* @mutex: Mutex to protect current/future table swapping
|
|
* @lock: Spin lock to protect walker list
|
|
* @nelems: Number of elements in table
|
|
*/
|
|
struct rhashtable {
|
|
struct bucket_table __rcu *tbl;
|
|
unsigned int key_len;
|
|
unsigned int max_elems;
|
|
struct rhashtable_params p;
|
|
bool rhlist;
|
|
struct work_struct run_work;
|
|
struct irq_work run_irq_work;
|
|
struct mutex mutex;
|
|
spinlock_t lock;
|
|
atomic_t nelems;
|
|
#ifdef CONFIG_MEM_ALLOC_PROFILING
|
|
struct alloc_tag *alloc_tag;
|
|
#endif
|
|
};
|
|
|
|
/**
|
|
* struct rhltable - Hash table with duplicate objects in a list
|
|
* @ht: Underlying rhtable
|
|
*/
|
|
struct rhltable {
|
|
struct rhashtable ht;
|
|
};
|
|
|
|
/**
|
|
* struct rhashtable_walker - Hash table walker
|
|
* @list: List entry on list of walkers
|
|
* @tbl: The table that we were walking over
|
|
*/
|
|
struct rhashtable_walker {
|
|
struct list_head list;
|
|
struct bucket_table *tbl;
|
|
};
|
|
|
|
/**
|
|
* struct rhashtable_iter - Hash table iterator
|
|
* @ht: Table to iterate through
|
|
* @p: Current pointer
|
|
* @list: Current hash list pointer
|
|
* @walker: Associated rhashtable walker
|
|
* @slot: Current slot
|
|
* @skip: Number of entries to skip in slot
|
|
*/
|
|
struct rhashtable_iter {
|
|
struct rhashtable *ht;
|
|
struct rhash_head *p;
|
|
struct rhlist_head *list;
|
|
struct rhashtable_walker walker;
|
|
unsigned int slot;
|
|
unsigned int skip;
|
|
bool end_of_table;
|
|
};
|
|
|
|
int __rhashtable_init_noprof(struct rhashtable *ht,
|
|
const struct rhashtable_params *params,
|
|
struct lock_class_key *key);
|
|
#define rhashtable_init_noprof(ht, params) \
|
|
({ \
|
|
static struct lock_class_key __key; \
|
|
\
|
|
__rhashtable_init_noprof(ht, params, &__key); \
|
|
})
|
|
#define rhashtable_init(...) alloc_hooks(rhashtable_init_noprof(__VA_ARGS__))
|
|
|
|
int __rhltable_init_noprof(struct rhltable *hlt,
|
|
const struct rhashtable_params *params,
|
|
struct lock_class_key *key);
|
|
#define rhltable_init_noprof(hlt, params) \
|
|
({ \
|
|
static struct lock_class_key __key; \
|
|
\
|
|
__rhltable_init_noprof(hlt, params, &__key); \
|
|
})
|
|
#define rhltable_init(...) alloc_hooks(rhltable_init_noprof(__VA_ARGS__))
|
|
|
|
#endif /* _LINUX_RHASHTABLE_TYPES_H */
|