From patchwork Tue Jun 28 11:37:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?WWVlIExlZSAo5p2O5bu66Kq8KQ==?= X-Patchwork-Id: 12898171 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 638F5C43334 for ; Tue, 28 Jun 2022 12:18:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D7FB68E0002; Tue, 28 Jun 2022 08:18:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D30138E0001; Tue, 28 Jun 2022 08:18:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BF75B8E0002; Tue, 28 Jun 2022 08:18:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id B111C8E0001 for ; Tue, 28 Jun 2022 08:18:01 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 75B40342A0 for ; Tue, 28 Jun 2022 12:18:01 +0000 (UTC) X-FDA: 79627546362.27.3F2BB82 Received: from mailgw02.mediatek.com (mailgw02.mediatek.com [216.200.240.185]) by imf29.hostedemail.com (Postfix) with ESMTP id 10D7D12003A for ; Tue, 28 Jun 2022 12:17:58 +0000 (UTC) X-UUID: 24d200fb1ecc478781ce5c9009635f16-20220628 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.7,REQID:0e93d573-6df8-4583-9bd7-bb5a313d2dd0,OB:0,LO B:0,IP:0,URL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,RULE:Release_Ham,ACTI ON:release,TS:0 X-CID-META: VersionHash:87442a2,CLOUDID:7a500ed6-5d6d-4eaf-a635-828a3ee48b7c,C OID:IGNORED,Recheck:0,SF:nil,TC:nil,Content:0,EDM:-3,IP:nil,URL:0,File:nil ,QS:nil,BEC:nil,COL:0 X-UUID: 24d200fb1ecc478781ce5c9009635f16-20220628 Received: from mtkmbs11n1.mediatek.inc [(172.21.101.185)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 587943295; Tue, 28 Jun 2022 05:17:53 -0700 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs10n2.mediatek.inc (172.21.101.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.3; Tue, 28 Jun 2022 19:37:18 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 28 Jun 2022 19:37:18 +0800 From: To: CC: , Yee Lee , "Alexander Potapenko" , Marco Elver , Dmitry Vyukov , Andrew Morton , "Matthias Brugger" , "open list:KFENCE" , "open list:MEMORY MANAGEMENT" , "moderated list:ARM/Mediatek SoC support" , "moderated list:ARM/Mediatek SoC support" Subject: [PATCH v2 1/1] mm: kfence: apply kmemleak_ignore_phys on early allocated pool Date: Tue, 28 Jun 2022 19:37:11 +0800 Message-ID: <20220628113714.7792-2-yee.lee@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20220628113714.7792-1-yee.lee@mediatek.com> References: <20220628113714.7792-1-yee.lee@mediatek.com> MIME-Version: 1.0 X-MTK: N ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656418681; a=rsa-sha256; cv=none; b=CR/rTMXrjK1bh8Fry675iJaHs97XptdnjuEIYJv1Ka0KQSwqLhFvdPyocBb9EsNmSw4SzI 5z5QRsidZ0Sm5fXSQY3ao9hlnkQ0rmTAuFpLqJLqlBF5zrAu3t3ubVPpZ+A7xuRidG3qkY LUisRGg2oWXzvhPHZrgwB3uNQCiyeLk= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; spf=pass (imf29.hostedemail.com: domain of yee.lee@mediatek.com designates 216.200.240.185 as permitted sender) smtp.mailfrom=yee.lee@mediatek.com; dmarc=pass (policy=quarantine) header.from=mediatek.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656418681; 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: in-reply-to:in-reply-to:references:references; bh=7zXu0ktyw7BMrjs+/PsBz2fQRMG/j+JasIZ/NDWZBX0=; b=KQBdWn22ZX+3V+mo6QTc76uVgXGvu66f20JrtFR5hIBmbsY+A5nfXUyfwsRqWq2gb0F0L1 7W5Ch6XmkXj55sR6CKTP4FbtWrLJuW6GBpF17i3QVdfWEsLkqY/J7UulDsgbS2ldmsqg10 edxqlprhAlHXaXr7eW73RUTfOqYy6s8= X-Rspam-User: Authentication-Results: imf29.hostedemail.com; dkim=none; spf=pass (imf29.hostedemail.com: domain of yee.lee@mediatek.com designates 216.200.240.185 as permitted sender) smtp.mailfrom=yee.lee@mediatek.com; dmarc=pass (policy=quarantine) header.from=mediatek.com X-Rspamd-Server: rspam02 X-Stat-Signature: ibghr3zp58g3dowkt37kjoqgstr4g5ex X-Rspamd-Queue-Id: 10D7D12003A X-HE-Tag: 1656418678-86045 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: Yee Lee This patch solves two issues. (1) The pool allocated by memblock needs to unregister from kmemleak scanning. Apply kmemleak_ignore_phys to replace the original kmemleak_free as its address now is stored in the phys tree. (2) The pool late allocated by page-alloc doesn't need to unregister. Move out the freeing operation from its call path. Suggested-by: Catalin Marinas Suggested-by: Marco Elver Signed-off-by: Yee Lee Reviewed-by: Catalin Marinas Tested-by: Geert Uytterhoeven --- mm/kfence/core.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/mm/kfence/core.c b/mm/kfence/core.c index 4e7cd4c8e687..32a4a75e820c 100644 --- a/mm/kfence/core.c +++ b/mm/kfence/core.c @@ -600,14 +600,6 @@ static unsigned long kfence_init_pool(void) addr += 2 * PAGE_SIZE; } - /* - * The pool is live and will never be deallocated from this point on. - * Remove the pool object from the kmemleak object tree, as it would - * otherwise overlap with allocations returned by kfence_alloc(), which - * are registered with kmemleak through the slab post-alloc hook. - */ - kmemleak_free(__kfence_pool); - return 0; } @@ -620,8 +612,16 @@ static bool __init kfence_init_pool_early(void) addr = kfence_init_pool(); - if (!addr) + if (!addr) { + /* + * The pool is live and will never be deallocated from this point on. + * Ignore the pool object from the kmemleak phys object tree, as it would + * otherwise overlap with allocations returned by kfence_alloc(), which + * are registered with kmemleak through the slab post-alloc hook. + */ + kmemleak_ignore_phys(__pa(__kfence_pool)); return true; + } /* * Only release unprotected pages, and do not try to go back and change