From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DF90C369D9 for ; Wed, 30 Apr 2025 05:44:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 821C06B0089; Wed, 30 Apr 2025 01:44:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7CEB36B00C3; Wed, 30 Apr 2025 01:44:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 648546B00E1; Wed, 30 Apr 2025 01:44:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 41E246B0089 for ; Wed, 30 Apr 2025 01:44:33 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 3A1A0593B6 for ; Wed, 30 Apr 2025 05:44:33 +0000 (UTC) X-FDA: 83389620426.17.B213932 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf19.hostedemail.com (Postfix) with ESMTP id 7F6451A0002 for ; Wed, 30 Apr 2025 05:44:31 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf19.hostedemail.com: domain of dev.jain@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=dev.jain@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1745991871; a=rsa-sha256; cv=none; b=69ZYLg0Qj4zIsEUaxPfioKY/X6biYYdGaVJ1X9WwfxFSbI0p/zY7CLp9Gap8Wst/tDtsE6 RVBc6k9IsDjqoE0+qcGB9r7m5Q+G8VHMzQgwx7IUyCxKw8HDduX5qZJ1I43LVjNeSqwSUQ S8xPAwuvqt105j/lly0ucY2HsQi3+XQ= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf19.hostedemail.com: domain of dev.jain@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=dev.jain@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1745991871; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3+vMZjC6xxNpIpgNOscrmsGFDoKnecoDkfgYlhZhUcA=; b=M9l+KbHpg5m+PPJuZapLrwGSQP2dWkg049RrEBPfjWc5QWvKoWsjNl/Wy55BnFjxfCtSn4 EhwrMMHEDeS0Vk3U25mURdn6KE9/Ycwq8iiVmlGtiKoaZE0nNQ7lHa569pRRTs47SMLl8q mp3WSaV0AbIvOuX3RxLJXzWe0czBUOQ= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A4F4D106F; Tue, 29 Apr 2025 22:44:23 -0700 (PDT) Received: from [10.163.79.251] (unknown [10.163.79.251]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4FC553F5A1; Tue, 29 Apr 2025 22:44:22 -0700 (PDT) Message-ID: Date: Wed, 30 Apr 2025 11:14:18 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 6/7] mm: Batch around can_change_pte_writable() To: Lorenzo Stoakes , David Hildenbrand Cc: akpm@linux-foundation.org, ryan.roberts@arm.com, willy@infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, catalin.marinas@arm.com, will@kernel.org, Liam.Howlett@oracle.com, vbabka@suse.cz, jannh@google.com, anshuman.khandual@arm.com, peterx@redhat.com, joey.gouly@arm.com, ioworker0@gmail.com, baohua@kernel.org, kevin.brodsky@arm.com, quic_zhenhuah@quicinc.com, christophe.leroy@csgroup.eu, yangyicong@hisilicon.com, linux-arm-kernel@lists.infradead.org, hughd@google.com, yang@os.amperecomputing.com, ziy@nvidia.com References: <20250429052336.18912-1-dev.jain@arm.com> <20250429052336.18912-7-dev.jain@arm.com> <25dcf969-e479-4d4a-a95c-0e83706af99e@redhat.com> <9a770aec-a020-4199-a53e-eddda657999d@redhat.com> <7cf8235e-21f7-4643-82c4-82ad57d99b98@lucifer.local> Content-Language: en-US From: Dev Jain In-Reply-To: <7cf8235e-21f7-4643-82c4-82ad57d99b98@lucifer.local> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 7F6451A0002 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: f75ndh4othx71fee9o6ro1h6arzz59zi X-HE-Tag: 1745991871-188012 X-HE-Meta: U2FsdGVkX1//1Pff58IX9tKI9nSyiv3S5x1uMXxTLg1zs7nyM8ouMpEPvRXcEbth/96L4djfYwQ78zMINztpIL9Ztl+cNuh9gyey7bT5ik8wz3boKdudXV4wBqKYoMd+D5Ot/INLPipRYgJ8jB0Lbhzn9flNkKSz3Fpz3y4wvdOnco/whjO+Vr7JXlJSHRCXr/nwUbdTwE2xzaVnuOZ5yAX/P32tywVr+fpTABd2FIG0DaCrFJunrv8Top+5liZ991XHgpnrm2b2fRQA+HYE8ehk+GpcZJgnH/WPuBwPF+QGvX/j/uezEQydlKTZCk9S85Tr+voIoZS6xDxHt7+Uj9o66BJ3JKVSDH6/s2Wh4IEQvSzrC3htgj3WIxDPHrUf8pa68TiX+zM29QEEdLZnX/++Iy69tdSDYcpxzl7pLTSkNxiGg7Rs2WLvVE0xkn7MMstW9zvlWD/5m7cVIYi89smd1k94EGz8v27yLLqJkKQDAJ1JwZvz4w7iF4fJsS71Jtj3AHJTHbRjV0ca12uF/fU5gLOztbAVVlEBsc0RPmWDrzfDAhKRLB2yLkZoJJ7K+/CBqalCtPZZTeOWJ4LIKzUyjlj2okDzaGp1yrJrAvqzdRiCxw+9aHpHT2uDM7JC+hT0JgGb2wpzoCZU8k5jrPZNzKbdQmFLdqcWrDCVQbhl0VUwym7fqLv76t8XoEn3we2Mk0TdMqPUNfFfzLBbkMBeWDADXmYtFoOSlAiggtwo845UUvDLgkOkaEhD3UnHjyXb+hBJmlpgDbuf+AoUFLCzhHIl4TeKC9bDSegHMniY8AQsXW4mb12SYzNgeTRaccfDEEP4DXk9BVxp/85qaapd5m9/NoUdrDjv/iNSPh7wXheLChrUqpesDgVZMx5bw3V5Uh2ZZZ9IqD2tM8FUYTpkc+dSuLz1nQl/uVPVdwfNLzQwAs1gBh2NcstGR083B0L7E4EMhTpv95XErVJ v16eXoYd Ps9/MWf57zwdzQOSXizRooPDZAFrFbNzgzxnzYDU0DmIFeH51NJE7iUvaIucAvRM2YJlXwrVh1PrK1eH/fw4fZjgpnd2Iekn6xCGrA9Hi8fAb5r9fQmSGpo9ayVwsmFNjxTSLQS5HVHHO4iDy7clEQzxPY0WoCK+ye+2Y7uMW6Q4D4qfK/BwaaKla0229h0m/0JTX X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 29/04/25 7:27 pm, Lorenzo Stoakes wrote: > On Tue, Apr 29, 2025 at 11:27:43AM +0200, David Hildenbrand wrote: >> On 29.04.25 11:19, David Hildenbrand wrote: >>> >>>> #include "internal.h" >>>> -bool can_change_pte_writable(struct vm_area_struct *vma, unsigned long addr, >>>> - pte_t pte) >>>> +bool can_change_ptes_writable(struct vm_area_struct *vma, unsigned long addr, >>>> + pte_t pte, struct folio *folio, unsigned int nr) >>>> { >>>> struct page *page; >>>> @@ -67,8 +67,9 @@ bool can_change_pte_writable(struct vm_area_struct *vma, unsigned long addr, >>>> * write-fault handler similarly would map them writable without >>>> * any additional checks while holding the PT lock. >>>> */ >>>> - page = vm_normal_page(vma, addr, pte); >>>> - return page && PageAnon(page) && PageAnonExclusive(page); >>>> + if (!folio) >>>> + folio = vm_normal_folio(vma, addr, pte); >>>> + return folio_test_anon(folio) && !folio_maybe_mapped_shared(folio); >>> >>> Oh no, now I spot it. That is horribly wrong. >>> >>> Please understand first what you are doing. >> >> Also, would expect that the cow.c selftest would catch that: >> >> "vmsplice() + unmap in child with mprotect() optimization" >> >> After fork() we have a R/O PTE in the parent. Our child then uses vmsplice() >> and unmaps the R/O PTE, meaning it is only left mapped by the parent. >> >> ret = mprotect(mem, size, PROT_READ); >> ret |= mprotect(mem, size, PROT_READ|PROT_WRITE); >> >> should turn the PTE writable, although it shouldn't. > > This makes me concerned about the stability of this series as a whole... > >> >> If that test case does not detect the issue you're introducing, we should >> look into adding a test case that detects it. > > There are 25 tests that fail for the cow self-test with this series > applied: > > # [RUN] vmsplice() + unmap in child with mprotect() optimization ... with base page > # [RUN] vmsplice() + unmap in child with mprotect() optimization ... with PTE-mapped THP (16 kB) > # [RUN] vmsplice() + unmap in child with mprotect() optimization ... with single PTE of THP (16 kB) > # [RUN] vmsplice() + unmap in child with mprotect() optimization ... with partially shared THP (16 kB) > # [RUN] vmsplice() + unmap in child with mprotect() optimization ... with PTE-mapped THP (32 kB) > # [RUN] vmsplice() + unmap in child with mprotect() optimization ... with single PTE of THP (32 kB) > # [RUN] vmsplice() + unmap in child with mprotect() optimization ... with partially shared THP (32 kB) > # [RUN] vmsplice() + unmap in child with mprotect() optimization ... with PTE-mapped THP (64 kB) > # [RUN] vmsplice() + unmap in child with mprotect() optimization ... with single PTE of THP (64 kB) > # [RUN] vmsplice() + unmap in child with mprotect() optimization ... with partially shared THP (64 kB) > # [RUN] vmsplice() + unmap in child with mprotect() optimization ... with PTE-mapped THP (128 kB) > # [RUN] vmsplice() + unmap in child with mprotect() optimization ... with single PTE of THP (128 kB) > # [RUN] vmsplice() + unmap in child with mprotect() optimization ... with partially shared THP (128 kB) > # [RUN] vmsplice() + unmap in child with mprotect() optimization ... with PTE-mapped THP (256 kB) > # [RUN] vmsplice() + unmap in child with mprotect() optimization ... with single PTE of THP (256 kB) > # [RUN] vmsplice() + unmap in child with mprotect() optimization ... with partially shared THP (256 kB) > # [RUN] vmsplice() + unmap in child with mprotect() optimization ... with PTE-mapped THP (512 kB) > # [RUN] vmsplice() + unmap in child with mprotect() optimization ... with single PTE of THP (512 kB) > # [RUN] vmsplice() + unmap in child with mprotect() optimization ... with partially shared THP (512 kB) > # [RUN] vmsplice() + unmap in child with mprotect() optimization ... with PTE-mapped THP (1024 kB) > # [RUN] vmsplice() + unmap in child with mprotect() optimization ... with single PTE of THP (1024 kB) > # [RUN] vmsplice() + unmap in child with mprotect() optimization ... with partially shared THP (1024 kB) > # [RUN] vmsplice() + unmap in child with mprotect() optimization ... with PTE-mapped THP (2048 kB) > # [RUN] vmsplice() + unmap in child with mprotect() optimization ... with single PTE of THP (2048 kB) > # [RUN] vmsplice() + unmap in child with mprotect() optimization ... with partially shared THP (2048 kB) > > > Dev, please take a little more time to test your series :) the current > patch set doesn't compile and needs fixes applied to do so, and we're at > v2, and you've clearly not run self-tests as these also fail. > > Please ensure you do a smoke test and check compilation before sending out, > as well as running self tests also. Apologies, I over-confidently skipped over selftests, and didn't build for x86 :( Shall take care. > > Thanks, Lorenzo > >> >> -- >> Cheers, >> >> David / dhildenb >>