From patchwork Mon Sep 2 12:49:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pankaj Raghav (Samsung)" X-Patchwork-Id: 13787236 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 D2A66CA0ED3 for ; Mon, 2 Sep 2024 12:50:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5D0CB8D00D7; Mon, 2 Sep 2024 08:50:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 580A88D0098; Mon, 2 Sep 2024 08:50:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 498FA8D00D7; Mon, 2 Sep 2024 08:50:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 2AE7C8D0098 for ; Mon, 2 Sep 2024 08:50:18 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id BFEE1A1CE9 for ; Mon, 2 Sep 2024 12:50:17 +0000 (UTC) X-FDA: 82519781274.16.75F0040 Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) by imf20.hostedemail.com (Postfix) with ESMTP id C4A3D1C001D for ; Mon, 2 Sep 2024 12:50:15 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=V79wYxoF; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf20.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.152 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725281393; a=rsa-sha256; cv=none; b=jmTxBpdBS7MJyS/b5Vv4DaOpSRMw+nooAqT97FmnWX8zT7e/fJk0DhZATyJ8y5uUVZcaew z2PhEGKsC6V46Y2iMgIc/U+gJ6GQCcWIskXpDehdWDK6XpDGPYDN9J01v4IheFv6R9KdFw 7k9jYBwWsykK9sGpSQN2Wc4szdCRIic= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=V79wYxoF; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf20.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.152 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725281393; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=zgNc4EUwevKoCFWkdis1bQilpGFIfwwlx7wOLIpzp8s=; b=O69zhHDpniNkzmaXsymMgLzHXTpZeIsee88K91FRpwfOwBJeS6IEGztbDSO4Dfos4annco VthVdNie93u42O4jLHqrurK1/Q7e2cqd45gg2n8RvSLrZzZUEwzXVny3RvSJOI/bkSUsri y2kdCaIBeCpvXBUR4RvpPvRbCZoK1tU= Received: from smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4Wy7rg0Fg5z9tRr; Mon, 2 Sep 2024 14:50:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1725281411; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=zgNc4EUwevKoCFWkdis1bQilpGFIfwwlx7wOLIpzp8s=; b=V79wYxoFzz1cEfBpOLqEapMqH2GHIEkrnAlVAvhW9w6uJGoUvEo6nSXNpdBshWQUIqwZbR aGxoI+f2us3gFlrZNiEg4mpJ6o+Jhb0ulFG35wHmthyEUyFHS8eRaYFzrcPpVFy4kAdjoX tt1iq5gT4xDKLScygAVUa0JFh/58eugbWEv40ybmGAQ5GYa4n9JXrubJAIFOvHMbfHLPFB /3VbztVOKNji5vBocpsOE/I+MSHfnmX9haTSkjonrniUZHWv9Tv0mPW+uVn8hT7bXie2nG EsOS0LHht3Ntc6fUVyB4nwJGIoov9AkdhK13rWjME0ZLZf7N9W3Zexx32IOk4g== From: "Pankaj Raghav (Samsung)" To: brauner@kernel.org, sfr@canb.auug.org.au, akpm@linux-foundation.org Cc: linux-next@vger.kernel.org, mcgrof@kernel.org, willy@infradead.org, ziy@nvidia.com, da.gomez@samsung.com, kernel@pankajraghav.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Pankaj Raghav , Sven Schnelle Subject: [PATCH] mm: don't convert the page to folio before splitting in split_huge_page() Date: Mon, 2 Sep 2024 14:49:32 +0200 Message-ID: <20240902124931.506061-2-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: C4A3D1C001D X-Rspamd-Server: rspam01 X-Stat-Signature: 6hq9rc956np5jxz5gjedygk4e1ymri4c X-HE-Tag: 1725281415-788223 X-HE-Meta: U2FsdGVkX1/1gZehRJALH1bDJ1F9+6usdY/2WZTpw1q9lr8JVKBHd9QjTgxNXGGTBMz3q23ZAjAAvP4cIKuuJPQY+YU1mMLRwbfiFJ5Gwj7ZTuX/74lS0SW5iIHysHFVS357w5CBfL7u7a4BbFZT5LCG7VV3LHEfG4jQd+sEdI39mLRJgC2cQiQU4bhH/UDRrIMj+kqxCNnJ5HG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BOCWkJpvMVPoOWkG3mOR2SbvosthCXhjqONZEzFIS/khvjnC3ZxdGYSlxlBhOoLJAXWCK4= 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: From: Pankaj Raghav Sven reported that a commit from bs > ps series was breaking the ksm ltp test[1]. split_huge_page() takes precisely a page that is locked, and it also expects the folio that contains that page to be locked after that huge page has been split. The changes introduced converted the page to folio, and passed the head page to be split, which might not be locked, resulting in a kernel panic. This commit fixes it by always passing the correct page to be split from split_huge_page() with the appropriate minimum order for splitting. [1] https://lore.kernel.org/linux-xfs/yt9dttf3r49e.fsf@linux.ibm.com/ Reported-by: Sven Schnelle Fixes: fd031210c9ce ("mm: split a folio in minimum folio order chunks") Signed-off-by: Pankaj Raghav --- This applies to the vfs.blocksize branch on the vfs tree. @Christian, Stephen already sent a mail saying that there is a conflict with these changes and mm-unstable. For now, I have based these patches out of your tree. Let me know if you need the same patch based on linux-next. include/linux/huge_mm.h | 16 +++++++++++++++- mm/huge_memory.c | 21 +++++++++++++-------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 7c50aeed0522..7a570e0437c9 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -319,10 +319,24 @@ unsigned long thp_get_unmapped_area_vmflags(struct file *filp, unsigned long add bool can_split_folio(struct folio *folio, int *pextra_pins); int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, unsigned int new_order); +int min_order_for_split(struct folio *folio); int split_folio_to_list(struct folio *folio, struct list_head *list); static inline int split_huge_page(struct page *page) { - return split_folio(page_folio(page)); + struct folio *folio = page_folio(page); + int ret = min_order_for_split(folio); + + if (ret < 0) + return ret; + + /* + * split_huge_page() locks the page before splitting and + * expects the same page that has been split to be locked when + * returned. split_folio(page_folio(page)) cannot be used here + * because it converts the page to folio and passes the head + * page to be split. + */ + return split_huge_page_to_list_to_order(page, NULL, ret); } void deferred_split_folio(struct folio *folio); diff --git a/mm/huge_memory.c b/mm/huge_memory.c index c29af9451d92..9931ff1d9a9d 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3297,12 +3297,10 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, return ret; } -int split_folio_to_list(struct folio *folio, struct list_head *list) +int min_order_for_split(struct folio *folio) { - unsigned int min_order = 0; - if (folio_test_anon(folio)) - goto out; + return 0; if (!folio->mapping) { if (folio_test_pmd_mappable(folio)) @@ -3310,10 +3308,17 @@ int split_folio_to_list(struct folio *folio, struct list_head *list) return -EBUSY; } - min_order = mapping_min_folio_order(folio->mapping); -out: - return split_huge_page_to_list_to_order(&folio->page, list, - min_order); + return mapping_min_folio_order(folio->mapping); +} + +int split_folio_to_list(struct folio *folio, struct list_head *list) +{ + int ret = min_order_for_split(folio); + + if (ret < 0) + return ret; + + return split_huge_page_to_list_to_order(&folio->page, list, ret); } void __folio_undo_large_rmappable(struct folio *folio)