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: <11a1d0f7-ef4e-4836-9bde-d7651eebcd03@redhat.com>
Date: Tue, 17 Jun 2025 13:27:18 +0200
From: David Hildenbrand <david@...hat.com>
To: Oscar Salvador <osalvador@...e.de>
Cc: Andrew Morton <akpm@...ux-foundation.org>,
 Muchun Song <muchun.song@...ux.dev>, James Houghton <jthoughton@...gle.com>,
 Peter Xu <peterx@...hat.com>, Gavin Guo <gavinguo@...lia.com>,
 linux-mm@...ck.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 2/5] mm,hugetlb: Document the reason to lock the folio in
 the faulting path


> 
> I see, this makes a lot of sense, thanks for walking me through David!

Well, I hope the same logic applies to hugetlb :D

> Alright, then, with all this clear now we should:
> 
> - Not take any locks on hugetlb_fault()->hugetlb_wp(), hugetlb_wp() will take it
>    if it's an anonymous folio (re-use check)
> - Drop the lock in hugetlb_no_page() after we have mapped the page in
>    the pagetables
> - hugetlb_wp() will take the lock IFF the folio is anonymous
> 
> This will lead to something like the following:
> 
>   diff --git a/mm/hugetlb.c b/mm/hugetlb.c
>   index dfa09fc3b2c6..4d48cda8a56d 100644
>   --- a/mm/hugetlb.c
>   +++ b/mm/hugetlb.c
>   @@ -6198,6 +6198,8 @@ static vm_fault_t hugetlb_wp(struct vm_fault *vmf)
>    	 * in scenarios that used to work. As a side effect, there can still
>    	 * be leaks between processes, for example, with FOLL_GET users.
>    	 */
>   +	if (folio_test_anon(old_folio))
>   +		folio_lock(old_folio);

If holding the PTL, this would not work. You'd have to unlock PTL, lock 
folio, retake PTL, check pte_same.

>    	if (folio_mapcount(old_folio) == 1 && folio_test_anon(old_folio)) {
>    		if (!PageAnonExclusive(&old_folio->page)) {
>    			folio_move_anon_rmap(old_folio, vma);
>   @@ -6212,6 +6214,8 @@ static vm_fault_t hugetlb_wp(struct vm_fault *vmf)
>    	}
>    	VM_BUG_ON_PAGE(folio_test_anon(old_folio) &&
>    		       PageAnonExclusive(&old_folio->page), &old_folio->page);
>   +	if (folio_test_anon(old_folio))
>   +		folio_unlock(old_folio);

[...]

>    
> This should be patch#2 with something like "Sorting out locking" per
> title, and maybe explaining a bit more why the lock in hugelb_wp for
> anonymous folios.

Jup.


-- 
Cheers,

David / dhildenb


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ