mirror of
https://gitee.com/bianbu-linux/linux-6.6
synced 2025-04-24 14:07:52 -04:00
Merge branches 'slab/for-6.5/prandom', 'slab/for-6.5/slab_no_merge' and 'slab/for-6.5/slab-deprecate' into slab/for-next
Merge the feature branches scheduled for 6.5: - replace the usage of weak PRNGs, by David Keisar Schmidt - introduce the SLAB_NO_MERGE kmem_cache flag, by Jesper Dangaard Brouer - deprecate CONFIG_SLAB, with a planned removal, by myself
This commit is contained in:
commit
7bc162d5cc
141 changed files with 51 additions and 178 deletions
29
mm/slab.c
29
mm/slab.c
|
@ -2355,44 +2355,34 @@ static void cache_init_objs_debug(struct kmem_cache *cachep, struct slab *slab)
|
|||
|
||||
#ifdef CONFIG_SLAB_FREELIST_RANDOM
|
||||
/* Hold information during a freelist initialization */
|
||||
union freelist_init_state {
|
||||
struct {
|
||||
unsigned int pos;
|
||||
unsigned int *list;
|
||||
unsigned int count;
|
||||
};
|
||||
struct rnd_state rnd_state;
|
||||
struct freelist_init_state {
|
||||
unsigned int pos;
|
||||
unsigned int *list;
|
||||
unsigned int count;
|
||||
};
|
||||
|
||||
/*
|
||||
* Initialize the state based on the randomization method available.
|
||||
* return true if the pre-computed list is available, false otherwise.
|
||||
*/
|
||||
static bool freelist_state_initialize(union freelist_init_state *state,
|
||||
static bool freelist_state_initialize(struct freelist_init_state *state,
|
||||
struct kmem_cache *cachep,
|
||||
unsigned int count)
|
||||
{
|
||||
bool ret;
|
||||
unsigned int rand;
|
||||
|
||||
/* Use best entropy available to define a random shift */
|
||||
rand = get_random_u32();
|
||||
|
||||
/* Use a random state if the pre-computed list is not available */
|
||||
if (!cachep->random_seq) {
|
||||
prandom_seed_state(&state->rnd_state, rand);
|
||||
ret = false;
|
||||
} else {
|
||||
state->list = cachep->random_seq;
|
||||
state->count = count;
|
||||
state->pos = rand % count;
|
||||
state->pos = get_random_u32_below(count);
|
||||
ret = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Get the next entry on the list and randomize it using a random shift */
|
||||
static freelist_idx_t next_random_slot(union freelist_init_state *state)
|
||||
static freelist_idx_t next_random_slot(struct freelist_init_state *state)
|
||||
{
|
||||
if (state->pos >= state->count)
|
||||
state->pos = 0;
|
||||
|
@ -2413,7 +2403,7 @@ static void swap_free_obj(struct slab *slab, unsigned int a, unsigned int b)
|
|||
static bool shuffle_freelist(struct kmem_cache *cachep, struct slab *slab)
|
||||
{
|
||||
unsigned int objfreelist = 0, i, rand, count = cachep->num;
|
||||
union freelist_init_state state;
|
||||
struct freelist_init_state state;
|
||||
bool precomputed;
|
||||
|
||||
if (count < 2)
|
||||
|
@ -2442,8 +2432,7 @@ static bool shuffle_freelist(struct kmem_cache *cachep, struct slab *slab)
|
|||
|
||||
/* Fisher-Yates shuffle */
|
||||
for (i = count - 1; i > 0; i--) {
|
||||
rand = prandom_u32_state(&state.rnd_state);
|
||||
rand %= (i + 1);
|
||||
rand = get_random_u32_below(i + 1);
|
||||
swap_free_obj(slab, i, rand);
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue