From patchwork Thu Oct 24 03:23:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: cuigaosheng X-Patchwork-Id: 13848276 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 1FBCED0BB56 for ; Thu, 24 Oct 2024 03:23:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6663F6B007B; Wed, 23 Oct 2024 23:23:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6159D6B0082; Wed, 23 Oct 2024 23:23:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 504386B0083; Wed, 23 Oct 2024 23:23:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 30AD36B007B for ; Wed, 23 Oct 2024 23:23:08 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 13BAB1C6A63 for ; Thu, 24 Oct 2024 03:22:47 +0000 (UTC) X-FDA: 82707048774.01.4E4465C Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf13.hostedemail.com (Postfix) with ESMTP id C18092000F for ; Thu, 24 Oct 2024 03:22:46 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; spf=pass (imf13.hostedemail.com: domain of cuigaosheng1@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=cuigaosheng1@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729740109; 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: references; bh=/xbrQsVViNJzdCzDkTNY5osGwUja3fLDbBUZQe836Gs=; b=0aU4WRZgYzUG9sDxUm0JCE1UtAIZW4h/r+CczxW33As9cw3Kxo0CxVQJVGmBwgi2DYYaIN rEkFP1Kt0NidasoHT0mHWKWmsj/gtqx41Lo+0mn8ZmmLDf0ISvZj91TDRvmDpQCtgGpSBd ZQUAehQC2AWeyPPE6gDRK81AR2ByEFc= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; spf=pass (imf13.hostedemail.com: domain of cuigaosheng1@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=cuigaosheng1@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729740109; a=rsa-sha256; cv=none; b=UfMYoZbDKwJ+vPiTWWJ/WjSxCqw47TD1z+DliZ5EHN0f/CpwgVcePKOcMtW0TgUTD6LBUG cG1XLoFq9iUd3QxOP8SIFYO3//f6qZ7QorLR+rJdiW2hXUbqXKxkLnn43nqcsAaB6yX68L ykaUKg9COIMwTojnrpGIYKjrkbXczqw= Received: from mail.maildlp.com (unknown [172.19.88.194]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4XYrlL3JlJzdkP6; Thu, 24 Oct 2024 11:20:30 +0800 (CST) Received: from kwepemd200011.china.huawei.com (unknown [7.221.188.251]) by mail.maildlp.com (Postfix) with ESMTPS id 202611402E1; Thu, 24 Oct 2024 11:23:01 +0800 (CST) Received: from cgs.huawei.com (10.244.148.83) by kwepemd200011.china.huawei.com (7.221.188.251) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Thu, 24 Oct 2024 11:23:00 +0800 From: Gaosheng Cui To: , , , CC: Subject: [PATCH -next] mm/ksm: Add missing IS_ERR_OR_NULL check for stable_tree_search() Date: Thu, 24 Oct 2024 11:23:00 +0800 Message-ID: <20241024032300.2501949-1-cuigaosheng1@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.244.148.83] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemd200011.china.huawei.com (7.221.188.251) X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: C18092000F X-Stat-Signature: gztd9dp35g1op41gunno649hr1t4tq4d X-HE-Tag: 1729740166-607709 X-HE-Meta: U2FsdGVkX19QDWxz7shQMcPF7ZBY/CXpCAXGAcHkDGyNUL2VaaR9fDe7eCSUz/yNwnP7ilpjowtKSi20IKOCS9kUV8+e4AaF7+TANOD8cFjONj3A4Yme7ML/9kVaJn5ujND1AnVkEhzh9ZAFmkH1wE5FA6auqEg2v86g8kXIePCJHIix++RnN68usURE4j/OXxituSlkgXc3cDDulYPYLX71JeCEB4o93pFHjwLk8yTxTfacdi3j0s2vkVFnTtMPa80dUp2TthjvvibyeiHGnWgNlkRfENDDah1gD1RskRCu8/YuM7pUKYFraHPMfT4Uw9mhKSCYv+JhCcSueJG0UCPkeng+QWZbHPWe1mm93mEdOofzilLvaHZ1UaJJjFK0MPyjijoa2crjAH0L6Mo77gfbYFRSJ//XCyctqY3GbLZeM3IrizQFv46qIAJKnxm180jUh5eeVeIoJF1vTD/IRs8RF4/vcmKE1DHDpX2GHPL/fVOsUrmf1Vmr0AqTsnxND1G8DfQIS1YcCIkHx6WgDNJxpquh9try2tpQhYFtKcPu2OvKRSggBlPcLrmmIgfey4pi3t1o+bsQawkFFYr6B6PnxJ6EQ0SFOl7Hku5CZsF4pLT3KVBIfR/EkHjJ3NgpunjiSNujje/M6+ofTuMLw7KsAFav9Ar3ye+HgXIe2xyIpZmBTH8arVVzWxE+NI55Mewf2Iv7wnnDQZi53X8ZOR8LLUuMdBz208a1WooQBUbati+N29Q+38VdPJN0DANXMk2a+FuXlA6INHfgRdzcQXRBDtdcqk+QtQHU+kmVwp0kA96QPAJW5kKuyVu7ODivlgNd8PRXKIILt9MGjyrtSFLuy5yMmzY9I0x5B1oAQG19ZlDrFTfzN95B0Z/EI67TYfZNAWZKjZty8DkaAu7zrv8voJjH/hrZWUfytW77vPHZVJHIiX+FqM8BXRYuY4et1WoJ0xt1JdoEh7oroyd 2ET4wAFN YR/mdqqgrFx8SR+JTGiOfBbzfTiPlg3Vbiz5yXnMDyLnp0QSpemclLVDbEZiOa9L2DMlxSasGCL7qOJWvjakbmDggKa9Gcf566KHLNp5mCu/TyfxnqNQRCVR/P4VTg02MUfGK7y3LUsAyfb9e/pMXFHW8BKL+n+GDBPkPq4KYs4HI7pWnzY1UuIt9AOB7+o7THYHw 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: The stable_tree_search() maybe return -EBUSY if the stable node's page is being migrated or nullptr, we need to check kfolio with IS_ERR_OR_NULL() before dereference it. To mitigate this, add IS_ERR_OR_NULL check for stable_tree_search(). Fixes: 15605244fdce ("ksm: convert cmp_and_merge_page() to use a folio") Signed-off-by: Gaosheng Cui Acked-by: David Hildenbrand --- mm/ksm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index 4d482d011745..7ac59cde626c 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1787,7 +1787,7 @@ static __always_inline struct folio *chain(struct ksm_stable_node **s_n_d, * with identical content to the page that we are scanning right now. * * This function returns the stable tree node of identical content if found, - * NULL otherwise. + * -EBUSY if the stable node's page is being migrated, NULL otherwise. */ static struct folio *stable_tree_search(struct page *page) { @@ -2261,7 +2261,8 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite /* Start by searching for the folio in the stable tree */ kfolio = stable_tree_search(page); - if (&kfolio->page == page && rmap_item->head == stable_node) { + if (!IS_ERR_OR_NULL(kfolio) && &kfolio->page == page && + rmap_item->head == stable_node) { folio_put(kfolio); return; }