lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <31D32C5B-6719-4E3D-880A-666044C4A48B@nvidia.com>
Date: Thu, 17 Jul 2025 11:30:36 -0400
From: Zi Yan <ziy@...dia.com>
To: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
Cc: Andrew Morton <akpm@...ux-foundation.org>,
 David Hildenbrand <david@...hat.com>,
 Dan Carpenter <dan.carpenter@...aro.org>,
 Antonio Quartulli <antonio@...delbit.com>, linux-mm@...ck.org,
 Hugh Dickins <hughd@...gle.com>, Kirill Shutemov <k.shutemov@...il.com>,
 Baolin Wang <baolin.wang@...ux.alibaba.com>,
 "Liam R. Howlett" <Liam.Howlett@...cle.com>, Nico Pache <npache@...hat.com>,
 Ryan Roberts <ryan.roberts@....com>, Dev Jain <dev.jain@....com>,
 Barry Song <baohua@...nel.org>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] mm/huge_memory: refactor after-split (page) cache code.

On 17 Jul 2025, at 10:46, Lorenzo Stoakes wrote:

> On Wed, Jul 16, 2025 at 01:11:12PM -0400, Zi Yan wrote:
>> Smatch/coverity checkers report NULL mapping referencing issues[1][2][3]
>> every time the code is modified, because they do not understand that
>> mapping cannot be NULL when a folio is in page cache in the code.
>> Refactor the code to make it explicit.
>>
>> No functional change is intended.
>>
>> [1]https://lore.kernel.org/linux-mm/2afe3d59-aca5-40f7-82a3-a6d976fb0f4f@stanley.mountain/
>> [2]https://lore.kernel.org/oe-kbuild/64b54034-f311-4e7d-b935-c16775dbb642@suswa.mountain/
>> [3]https://lore.kernel.org/linux-mm/20250716145804.4836-1-antonio@mandelbit.com/
>>
>> Suggested-by: David Hildenbrand <david@...hat.com>
>> Signed-off-by: Zi Yan <ziy@...dia.com>
>
> This is fantastic, thanks Zi! There's a nit below but I actually almost
> _don't_ want you to address it :P
>
> Therefore:
>
> Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
>
>> ---
>>  mm/huge_memory.c | 43 ++++++++++++++++++++++++++++---------------
>>  1 file changed, 28 insertions(+), 15 deletions(-)
>>
>> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
>> index 31b5c4e61a57..fe17b0a157cd 100644
>> --- a/mm/huge_memory.c
>> +++ b/mm/huge_memory.c
>> @@ -3804,6 +3804,8 @@ static int __folio_split(struct folio *folio, unsigned int new_order,
>>  		 */
>>  		for (new_folio = folio_next(folio); new_folio != next_folio;
>>  		     new_folio = next) {
>> +			unsigned long nr_pages = folio_nr_pages(new_folio);
>> +
>>  			next = folio_next(new_folio);
>>
>>  			expected_refs = folio_expected_ref_count(new_folio) + 1;
>> @@ -3811,25 +3813,36 @@ static int __folio_split(struct folio *folio, unsigned int new_order,
>>
>>  			lru_add_split_folio(folio, new_folio, lruvec, list);
>>
>> -			/* Some pages can be beyond EOF: drop them from cache */
>> -			if (new_folio->index >= end) {
>> -				if (shmem_mapping(mapping))
>> -					nr_shmem_dropped += folio_nr_pages(new_folio);
>> -				else if (folio_test_clear_dirty(new_folio))
>> -					folio_account_cleaned(
>> -						new_folio,
>> -						inode_to_wb(mapping->host));
>> -				__filemap_remove_folio(new_folio, NULL);
>> -				folio_put_refs(new_folio,
>> -					       folio_nr_pages(new_folio));
>> -			} else if (mapping) {
>> -				__xa_store(&mapping->i_pages, new_folio->index,
>> -					   new_folio, 0);
>> -			} else if (swap_cache) {
>> +			/*
>> +			 * Anonymous folio with swap cache.
>> +			 * NOTE: shmem in swap cache is not supported yet.
>
> Nice added context!
>
>> +			 */
>> +			if (swap_cache) {
>>  				__xa_store(&swap_cache->i_pages,
>>  					   swap_cache_index(new_folio->swap),
>>  					   new_folio, 0);
>> +				continue;
>> +			}
>> +
>> +			/* Anonymouse folio without swap cache */
>
> I almost don't want to comment here because 'anony-mouse' is really cute :P
> but yeah nit I think you have a trailing 'e' here that my cats would be
> VERY interested in... ;)

Will change it. :p

>
>> +			if (!mapping)
>> +				continue;
>> +
>> +			/* Add the new folio to the page cache. */
>> +			if (new_folio->index < end) {
>> +				__xa_store(&mapping->i_pages, new_folio->index,
>> +					   new_folio, 0);
>> +				continue;
>>  			}
>> +
>> +			/* Drop folio beyond EOF: ->index >= end */
>> +			if (shmem_mapping(mapping))
>> +				nr_shmem_dropped += nr_pages;
>> +			else if (folio_test_clear_dirty(new_folio))
>> +				folio_account_cleaned(
>> +					new_folio, inode_to_wb(mapping->host));
>> +			__filemap_remove_folio(new_folio, NULL);
>> +			folio_put_refs(new_folio, nr_pages);
>>  		}
>>  		/*
>>  		 * Unfreeze @folio only after all page cache entries, which
>> --
>> 2.47.2
>>
>
> Since we no longer need to make new_folio->index >= end work for anon
> folios, can we drop the end = -1 in the if (is_anon) { ... } branch?

Sure.

OK, since I also need to address your comments on
“mm/huge_memory: move unrelated code out of __split_unmapped_folio()”,
I am going to send a new series with both this patch and
patches from __split_unmapped_folio().

We are not in a rush, so let’s make it as good as possible. :)


Best Regards,
Yan, Zi

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ