From patchwork Tue Sep 20 13:11:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "zhaoyang.huang" X-Patchwork-Id: 12982159 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 614C8C54EE9 for ; Tue, 20 Sep 2022 13:12:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CB7BD940008; Tue, 20 Sep 2022 09:12:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C66EA940007; Tue, 20 Sep 2022 09:12:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B5702940008; Tue, 20 Sep 2022 09:12:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id A4AF0940007 for ; Tue, 20 Sep 2022 09:12:12 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 816351A01B3 for ; Tue, 20 Sep 2022 13:12:12 +0000 (UTC) X-FDA: 79932502104.27.043277D Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) by imf28.hostedemail.com (Postfix) with ESMTP id C32A3C001F for ; Tue, 20 Sep 2022 13:12:10 +0000 (UTC) Received: from SHSend.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by SHSQR01.spreadtrum.com with ESMTPS id 28KDBRE4083462 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NO); Tue, 20 Sep 2022 21:11:27 +0800 (CST) (envelope-from zhaoyang.huang@unisoc.com) Received: from bj03382pcu.spreadtrum.com (10.0.74.65) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Tue, 20 Sep 2022 21:11:28 +0800 From: "zhaoyang.huang" To: Andrew Morton , Catalin Marinas , Matthew Wilcox , Zhaoyang Huang , , , , Subject: [RFC PATCH] mm: track bad page via kmemleak Date: Tue, 20 Sep 2022 21:11:08 +0800 Message-ID: <1663679468-16757-1-git-send-email-zhaoyang.huang@unisoc.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [10.0.74.65] X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 28KDBRE4083462 ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf28.hostedemail.com: domain of zhaoyang.huang@unisoc.com designates 222.66.158.135 as permitted sender) smtp.mailfrom=zhaoyang.huang@unisoc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663679531; a=rsa-sha256; cv=none; b=wCRqQYKF6T5kHHzee+Vdi7lgy78JEfTZuuGCcF1cOtsH4qDzPrgtmSDaSpJkAqvS/PaLs7 Uqn2/ygADIavmR6iBOztp5s1iAFD/NyrKA38twdpNjZYFDXhyBmDFzVH97fjxo0ADh9KK9 BZXSADCnw7qNGPeZTHhDG9UmQ4J7jlk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663679531; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references; bh=lBuMZ5r6ubIc1cx3qfU2GarYu14AI3Ml0CoGOCxqKeQ=; b=GfMoWpYQOd4p7UUB4V7EAoUSsub46CuGQjHYnBwqv1J7cWeBai52bva5LcBUrzYLYZsKiM m5L9C/Y+TRj6+TCoGSXZ1i5ZBEl7PvYWEp4Q71eoGYi7dZl9QY6l3EIEChqYvIzfnw89B2 n7JoMfCPA+SI68KXTFxxMOrK5WeyDh0= X-Stat-Signature: he4w99xssh4xg16ihm1uxxu91zn9zjp1 X-Rspamd-Queue-Id: C32A3C001F Authentication-Results: imf28.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf28.hostedemail.com: domain of zhaoyang.huang@unisoc.com designates 222.66.158.135 as permitted sender) smtp.mailfrom=zhaoyang.huang@unisoc.com X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1663679530-413561 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: From: Zhaoyang Huang Bad pages will failed go back to allocator and leaved as orphan pages, track them down via kmemleak. Signed-off-by: Zhaoyang Huang --- mm/page_alloc.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index e5486d4..24f682e 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1408,7 +1408,7 @@ static __always_inline bool free_pages_prepare(struct page *page, __memcg_kmem_uncharge_page(page, order); reset_page_owner(page, order); page_table_check_free(page, order); - return false; + goto err; } /* @@ -1442,7 +1442,7 @@ static __always_inline bool free_pages_prepare(struct page *page, if (check_free) bad += check_free_page(page); if (bad) - return false; + goto err; page_cpupid_reset_last(page); page->flags &= ~PAGE_FLAGS_CHECK_AT_PREP; @@ -1486,6 +1486,10 @@ static __always_inline bool free_pages_prepare(struct page *page, debug_pagealloc_unmap_pages(page, 1 << order); return true; +err: + kmemleak_alloc(page_address(page), PAGE_SIZE << order, 1, GFP_KERNEL); + return false; + } #ifdef CONFIG_DEBUG_VM