Skip to content

Commit

Permalink
s390/nmi: get rid of private slab cache
Browse files Browse the repository at this point in the history
Get rid of private "nmi_save_areas" slab cache. The only reason this was
introduced years ago was that with some slab debugging options allocations
would only guarantee a minimum alignment of ARCH_KMALLOC_MINALIGN, which
was eight bytes back then. This is not sufficient for the extended machine
check save area.

However since commit 59bb479 ("mm, sl[aou]b: guarantee natural
alignment for kmalloc(power-of-two)") kmalloc guarantees a power-of-two
alignment even with debugging options enabled.

Therefore the private slab cache can be removed.

Reviewed-by: Alexander Gordeev <[email protected]>
Signed-off-by: Heiko Carstens <[email protected]>
Signed-off-by: Alexander Gordeev <[email protected]>
  • Loading branch information
hcahca authored and Alexander Gordeev committed Dec 6, 2022
1 parent 742aed0 commit bb3860c
Showing 1 changed file with 9 additions and 31 deletions.
40 changes: 9 additions & 31 deletions arch/s390/kernel/nmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,12 @@ struct mcck_struct {
};

static DEFINE_PER_CPU(struct mcck_struct, cpu_mcck);
static struct kmem_cache *mcesa_cache;
static unsigned long mcesa_origin_lc;

static inline int nmi_needs_mcesa(void)
{
return MACHINE_HAS_VX || MACHINE_HAS_GS;
}

static inline unsigned long nmi_get_mcesa_size(void)
{
if (MACHINE_HAS_GS)
return MCESA_MAX_SIZE;
return MCESA_MIN_SIZE;
}

/*
* The initial machine check extended save area for the boot CPU.
* It will be replaced on the boot CPU reinit with an allocated
Expand All @@ -74,44 +65,31 @@ void __init nmi_alloc_mcesa_early(u64 *mcesad)
*mcesad |= ilog2(MCESA_MAX_SIZE);
}

static void __init nmi_alloc_cache(void)
int nmi_alloc_mcesa(u64 *mcesad)
{
unsigned long size;

if (!nmi_needs_mcesa())
return;
size = nmi_get_mcesa_size();
if (size > MCESA_MIN_SIZE)
mcesa_origin_lc = ilog2(size);
/* create slab cache for the machine-check-extended-save-areas */
mcesa_cache = kmem_cache_create("nmi_save_areas", size, size, 0, NULL);
if (!mcesa_cache)
panic("Couldn't create nmi save area cache");
}

int __ref nmi_alloc_mcesa(u64 *mcesad)
{
unsigned long origin;
void *origin;

*mcesad = 0;
if (!nmi_needs_mcesa())
return 0;
if (!mcesa_cache)
nmi_alloc_cache();
origin = (unsigned long) kmem_cache_alloc(mcesa_cache, GFP_KERNEL);
size = MACHINE_HAS_GS ? MCESA_MAX_SIZE : MCESA_MIN_SIZE;
origin = kmalloc(size, GFP_KERNEL);
if (!origin)
return -ENOMEM;
/* The pointer is stored with mcesa_bits ORed in */
kmemleak_not_leak((void *) origin);
*mcesad = __pa(origin) | mcesa_origin_lc;
kmemleak_not_leak(origin);
*mcesad = __pa(origin);
if (MACHINE_HAS_GS)
*mcesad |= ilog2(MCESA_MAX_SIZE);
return 0;
}

void nmi_free_mcesa(u64 *mcesad)
{
if (!nmi_needs_mcesa())
return;
kmem_cache_free(mcesa_cache, __va(*mcesad & MCESA_ORIGIN_MASK));
kfree(__va(*mcesad & MCESA_ORIGIN_MASK));
}

static __always_inline char *nmi_puts(char *dest, const char *src)
Expand Down

0 comments on commit bb3860c

Please sign in to comment.