Re: [RFC PATCH] mm/vmalloc: add vmalloc_decrypted() and vzalloc_decrypted()

From: Matthew Wilcox

Date: Thu May 21 2026 - 23:20:53 EST


On Thu, May 21, 2026 at 01:58:34PM -0700, Kameron Carr wrote:
> +/*
> + * Transition a single contiguous block of @nr pages at index @idx in

There's no parameter called @nr_pages; you probably meant @nr.

> + * @area->pages to encrypted or decrypted state. On failure, the block's
> + * page-pointer slots are cleared so the standard free path will not return
> + * the pages to the allocator (they are leaked).
> + */
> +static int __vm_pages_enc_dec(struct vm_struct *area, unsigned int idx,
> + unsigned int nr, bool encrypt)

This 'bool encrypt' parameter is an antipattern. Just split this into
two functions.

> +{
> + unsigned long addr =
> + (unsigned long)kasan_reset_tag(page_address(area->pages[idx]));
> + int err = encrypt ? set_memory_encrypted(addr, nr) :
> + set_memory_decrypted(addr, nr);
> +
> + if (err)
> + memset(&area->pages[idx], 0, nr * sizeof(*area->pages));
> + return err;
> +}

Does it really make sense to pass in 'area' and 'idx' rather than
passing in &area->pages[idx]?