mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Mike Rapoport <rppt@kernel.org>
Cc: "Baek Kyu, Kim" <pocj8ur4in@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	"Lorenzo Stoakes (Arm)" <ljs@kernel.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm/secretmem: Keep locked memory accounting until inode eviction
Date: Fri, 20 Nov 2026 10:32:05 +0100	[thread overview]
Message-ID: <857f5928-5aad-4e15-ad45-f8701e064c49@kernel.org> (raw)
In-Reply-To: <av6m4wU7iDOGviIa@kernel.org>

On 11/19/26 08:36, Mike Rapoport wrote:
> On Wed, Nov 18, 2026 at 11:59:57PM +0100, David Hildenbrand (Arm) wrote:
>> On 10/30/26 16:24, 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.
>>>
>>> Move private-state and locked-memory accounting cleanup to inode eviction,
>>> after truncating the page cache. Keep secretmem_users active over the same
>>> lifetime so that the hibernation guard covers retained secret pages. Let
>>> iput() handle file-creation failures and tolerate an inode with no private
>>> state.
> 
> I don't like the last part, see below.
> 
>>> Fixes: 97d34aa65c29 ("mm/secretmem: properly account locked pages")
>>> Signed-off-by: Baek Kyu, Kim <pocj8ur4in@gmail.com>
>>
>> Lorenzo, Mike, this problem seems real to me. Can you take a look?
> 
> Yep, it's real and the fix is correct.
>  
>>> ---
>>> On an arm64 QEMU guest with an 8 KiB RLIMIT_MEMLOCK, an O_PATH reference
>>> retained two secretmem pages. The baseline dropped the charge to zero and
>>> allowed a further one-page fault; the patch kept both pages charged and
>>> rejected that fault until the last path reference closed. The Image
>>> was built with KASAN and lockdep. Hibernation, other architectures,
>>> and long-running concurrency were not tested.
>>>
>>>  mm/secretmem.c | 31 ++++++++++++++++++-------------
>>>  1 file changed, 18 insertions(+), 13 deletions(-)
>>>
>>> diff --git a/mm/secretmem.c b/mm/secretmem.c
>>> index 384f5cfc457f..fa8be360bd2a 100644
>>> --- a/mm/secretmem.c
>>> +++ b/mm/secretmem.c
>>> @@ -185,18 +185,14 @@ static void secretmem_destroy_inode_priv(struct inode *inode)
>>>  {
>>>  	struct secretmem_inode_state *state = inode->i_private;
>>>  
>>> +	if (!state)
>>> +		return;
>>> +
> 
> Its really not obvious how we can get here with state == NULL. 
> 
> And since it is needed only for error path in secretmem_file_create(), I
> suggest rearranging the initialization so that we never get here with NULL
> state. 
> Allocate the state before creating the inode and adjust error handling in
> secretmem_file_create() so that we always get to iput with valid i_private.

Ack, Kim, can you resend (putting me on CC ?)

-- 
Cheers,

David

      reply	other threads:[~2026-11-20  9:32 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-30 15:24 Baek Kyu, Kim
2026-11-18 22:59 ` David Hildenbrand (Arm)
2026-11-19  7:36   ` Mike Rapoport
2026-11-20  9:32     ` David Hildenbrand (Arm) [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=857f5928-5aad-4e15-ad45-f8701e064c49@kernel.org \
    --to=david@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=pocj8ur4in@gmail.com \
    --cc=rppt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®