Re: [PATCH v3] mm/secretmem: Keep locked memory accounting until inode eviction
From: Mike Rapoport
Date: Sun Nov 29 2026 - 10:50:11 EST
Hi Kim,
On Sat, Nov 28, 2026 at 09:09:28PM +0900, Baek Kyu, Kim wrote:
> A secretmem inode can outlive its original file. An O_PATH descriptor
> opened through /proc/self/fd keeps the inode and its unevictable folios
> alive after the mapping and original descriptor are closed. The file
> release path nevertheless drops the locked-memory charge, allowing the
> same user to reuse RLIMIT_MEMLOCK while those folios remain allocated.
...
> mapping_set_gfp_mask(inode->i_mapping, GFP_USER);
> @@ -309,14 +295,14 @@ static struct file *secretmem_file_create(unsigned long flags)
> inode->i_mode |= S_IFREG;
> inode->i_size = 0;
>
> - atomic_inc(&secretmem_users);
> -
> return file;
> -err_free_priv:
> - secretmem_destroy_inode_priv(inode);
> err_free_inode:
> iput(inode);
> return ERR_PTR(err);
> +err_free_state:
> + free_uid(state->user);
> + kfree(state);
> + return ERR_PTR(err);
I was mistaken, and v1 with if (!state) in secretmem_evict_inode() looked
better.
The only thing that was missing there was a comment how we can reach
secretmem_evict_inode() with zero state.
--
Sincerely yours,
Mike.