From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.10 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793956317; b=iXMJL0S/dRQ1Yc4Z8goMHie7eErSJOf9uHG6Fjdc68EBtskxcH6fmEUtK4VLyK0tM4mT HRVYFYXlaRvZf81TdLvzO0rXc1R4BVrTHkgxs00nlCbvBNk1R2JIGGcAdzXkY6zRiupCN Y20xrLqJVCFr1a9CNdrSEAwqSrW4xgb1Z3D8vz4bIrPG2oF6s9sZGkZBI4PA/1/LCUyCJ qLYqTyo9ZlnHZHF7Y6G/BXUZ3xjCqe1BaDGtwEtU0mHIs/Dfd6RzpmHu/sBrSoebMYl4N wjLbDRTgy5BrlfrpdDJJBsSjHGytlJv6HFhUl4lf1M2PwGPBuvJvVJFzO2W1MCrTLEg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793956317; 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=AKi4F1XkSqKNw3b7+Ng4uXx+ZMXFkYDoN/Pwc1tdXyw=; b=PykDlbFtdaRVawjXsXTMij4WnpuS7hY9tVPlIcFSpYlxWQvkIF4D4WEvgO8GvSPxYCEV GfYkEaQ9DooYd8Pxheeoj+xR3rS+L55Rm+JRicLzGQ/9uprEegT6PmvNhEi/mx5TXzRR/ 3nAK+l0wefHqWDBue1UzC+6xsBufM4tnui7PcjH7WZLM6eFgVyzLlyWOI4DknPRmWFjA3 D0IlvhEaShhYf3RmuJrf/P/tN/QX5Rp14yN5O4jKmtKWnL6ho2z4A60boVI7RpbE5/swW 9X6YNpXHCQiIm3YO/WhJNDdh8LXhfrSxR/C5KLuoLTH6buq2rgn2+9i/hJrO50Lx80Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; arc=none smtp.remote-ip=91.218.175.10 Received: from mta0.migadu.com (out-10.mta0.migadu.com [91.218.175.10]) (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 BEDF6606A32F for ; Fri, 6 Nov 2026 09:11:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BEDF6606A32F 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 X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=RB9jCfeGXFtAeNZRCJe7qF1HA2DzPZCiRtQ6f8rlwO8=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1793956308; v=1; x=1794561108; b=SP14kqgHZegobLguKceMWVRaaEf3xj0wYia2VHIJv7nrvC8v/x1oCpRu272qEx3kMDDC6SEE DlL0PmcvKPbKwAj+xL2YncyuVQl1aPxY6vKPhNcd0sk3NnzrIjyjhtFA8ayH6u8Qep1tmr357io IqEHRdCNdAzL3+8AVKpJKnLM= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id a5d8b693a372ae24; Fri, 06 Nov 2026 09:11:48 +0000 X-Mizu-Trace-ID: a5d8b693a372ae24 X-Migadu-Flow: FLOW_OUT From: Lance Yang To: 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 17:11:39 +0800 Message-ID: <20261106091139.67845-1-lance.yang@linux.dev> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20261105-refcount_overflow_stable-v1-1-70b9c655da3e@kernel.org> References: <20261105-refcount_overflow_stable-v1-1-70b9c655da3e@kernel.org> 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 Thu, Nov 05, 2026 at 02:10:10PM +0100, 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. > >Also, just document -EHWPOISON for copy_present_ptes() while at it. > >Reported-by: Chris Mason >Fixes: 800d8c63b2e9 ("shmem: add huge pages support") >Fixes: 99cb0dbd47a1 ("mm,thp: add read-only THP support for (non-shmem) FS") >Fixes: 793917d997df ("mm/readahead: Add large folio readahead") >Cc: stable@vger.kernel.org >Signed-off-by: David Hildenbrand (Arm) >--- > include/linux/mm.h | 33 +++++++++++++++++++++++++++++++++ > mm/filemap.c | 6 ++++++ > mm/huge_memory.c | 24 ++++++++++++++++++++++-- > mm/memory.c | 23 ++++++++++++++++++++--- > mm/migrate.c | 11 +++++++++++ > mm/userfaultfd.c | 4 ++++ > 6 files changed, 96 insertions(+), 5 deletions(-) Nice work! I just went through all folio_add_file_rmap*() and folio_dup_file_rmap*() callers, including callers of set_pte_range(). All covered, looks good to me1 Reviewed-by: Lance Yang