From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.234 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793959622; b=Z3luuQLoSrZqW4Jq/Lr6/BFeuImf19Y3meCizW4UjrAfky4IM+F2f0bKJVIIiwQBxm13 VLibeVpzFpEcDliFiUyanceZ33sQR5/TJwHnZN3WkbgKR1LC8+AI7XqOgcMg9wjy6LNms bJTBhGZZjtc5gG85Zu8ghX8xnMWUPBntkoRQ39xjuQc83kmn1P1XWMS4SZt250glrD94G MTzqbI9lL6aAgafuvGQAWcRejGh8dEk1l61ZwthBLVX5YxXhXBa8cxN9x91qO/D3Q+b16 YbOmdAWSEkQipnAKSS16KqEsaFTQlna8vkNzJbJRNsH6Pul9JKa+UikD7ErzSFnlyLg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793959622; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=wS8HVyR4zbY3pfGi/Mj8Yz7yzAVziAm8n3+oqxcnzgc=; b=tNUs7+9JXpKYfgF69bMe9pa/paGBL5RoEd6HA0vit81o4AYljGTJa0FaN45QYcvrk1QK A8C+aWn+q91eJnwbILW7lf2JVKpugmnPsXJnpHGRsNXNFqWV2h0vCxGfv7Cw4R0Ty3Eh/ l2VpayN940urZzTafqKoHfmasm95eRo5gnQkImbh2xbXYVGTFOQuEyF4baCQquBqTBDY8 TKQ2clqbrCwzfcI2dXoOE0YFVmAU31tn1J9qgg1V7ApnLIe8ez5vs8cfcopMtJlEJvg1w CznjXJ54rhIg0OAuNrmUn2Y7427V/BLzlS5rvJCjlmk2od9qmSs4h04B8nfOjTuk2iw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=EziUgwa2; arc=none smtp.remote-ip=95.215.58.234 Received: from mta1.migadu.com (out-234.mta1.migadu.com [95.215.58.234]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1402E606A330 for ; Fri, 6 Nov 2026 10:07:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1402E606A330 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=EziUgwa2 X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=RbNpr/gp/P3/FChdryWgHiDNE03PXpM0ZDpmAqvKnzE=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1793959619; v=1; x=1794564419; b=EziUgwa2y6pX6lOUce9W+3Pcj4so/8hyEMAWywYesjK8x6xHOAX/A3zDdlSpe6i/qDPi0g8V QNh1T9foTRG6i+++DrYKw5bF27iENNmcG9PEKvCKss+gS3dYDWPFzg9K0E9L0zqjnAwhnYd68dG Lso2HTCdggWNVfngEUj4sCWc= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id b7c33c397d809dcb; Fri, 06 Nov 2026 10:06:58 +0000 X-Mizu-Trace-ID: b7c33c397d809dcb X-Migadu-Flow: FLOW_OUT From: Lance Yang To: azpijr@gmail.com, david@kernel.org Cc: akpm@linux-foundation.org, ljs@kernel.org, liam@infradead.org, vbabka@kernel.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com, willy@infradead.org, jack@suse.cz, ziy@nvidia.com, baolin.wang@linux.alibaba.com, nico.pache@linux.dev, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev, usama.arif@linux.dev, kas@kernel.org, matthew.brost@intel.com, joshua.hahnjy@gmail.com, byungchul@sk.com, gourry@gourry.net, ying.huang@linux.alibaba.com, apopple@nvidia.com, peterx@redhat.com, hannes@cmpxchg.org, songliubraving@fb.com, riel@surriel.com, hughd@google.com, will@kernel.org, aneesh.kumar@kernel.org, npiggin@gmail.com, peterz@infradead.org, jgg@ziepe.ca, kevin.tian@intel.com, joro@8bytes.org, robin.murphy@arm.com, steven.sistare@oracle.com, jhubbard@nvidia.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, iommu@lists.linux.dev, mason@kernel.org, stable@vger.kernel.org Subject: Re: [PATCH 1/5] mm: limit pagecache folio refcount when mapping pages Date: Fri, 6 Nov 2026 18:06:45 +0800 Message-ID: <20261106100645.77296-1-lance.yang@linux.dev> X-Mailer: git-send-email 2.49.0 In-Reply-To: <528e3a0e-04fb-427f-88c7-63a7f4bbc505@gmail.com> References: <528e3a0e-04fb-427f-88c7-63a7f4bbc505@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On Fri, Nov 06, 2026 at 10:42:17AM +0100, Jose A. Perez de Azpillaga wrote: >On 11/5/26 2:10 PM, David Hildenbrand (Arm) wrote: >> With large file folios, overflowing the folio mapcount and refcount >> became possible. For anon folios it is currently not really an issue: >> each large anon folio can only be mapped once into a process. >> >> That's not really big news, but it's about time that we do something >> about it because some modern technology might find ways to abuse it :) >> >> One of the enablers for that was commit ddc58f27f9ee ("mm: drop tail page >> refcounting"), however, file thp support was added later. >> >> File folios can be mapped multiple times into the same process, allowing >> for processes to hold many references to the same folio. >> >> As a short-term solution, let's introduce two folio refcount limits: >> one for ordinary consumers and one for admins. Leave some headroom >> before the refcount goes negative, which we really don't want (having >> the mapcount go negative is also not expected). >> >> Start reporting SIGBUS if we run into limits. When restoring mappings >> from migration entries, instead zap the pte/pmd entry. We allow for >> slightly exceeding the limit to keep things simpler. >> >> This is far from ideal, but better than all easy alternatives we can >> backport comfortably. For now it fixes the big problem: letting >> the refcount (+mapcount) go negative and cause trouble. >> >> This is only a temporary fix, we'll follow up with something better. >> >> While the refcount checks are not required for order 0 folios, let's >> just add them for consistency: each folio_add_file_rmap*() and >> folio_dup_file_rmap*() needs a prior check. >in mm-new copy_huge_pmd() now does a folio_dup_file_rmap_pmd() at fork, >since Konstantin's "mm/huge_memory: copy file THPs at fork like >copy_present_ptes() does". doesn't that one need the check too? Ah, good catch! My local tree didn't have Konstantin's series [1] yet. And right, that path needs a check too I guess :) [1] https://lore.kernel.org/all/20261104-b4-prep-vstor-149847-copy_huge_pmd-recheck-special-pmd-v5-2-c56d0d26f970@virtuozzo.com/ > >the rest LGTM: > >Reviewed-by: Jose A. Perez de Azpillaga > >-- >cheers, >jose a. p-a >