From patchwork Tue Apr 9 13:17:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13622496 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 6394BCD1284 for ; Tue, 9 Apr 2024 13:17:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A6A266B007B; Tue, 9 Apr 2024 09:17:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A1A296B0082; Tue, 9 Apr 2024 09:17:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E14A6B0083; Tue, 9 Apr 2024 09:17:48 -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 70DB56B007B for ; Tue, 9 Apr 2024 09:17:48 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 72482403EB for ; Tue, 9 Apr 2024 13:17:46 +0000 (UTC) X-FDA: 81990045732.29.C238933 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf07.hostedemail.com (Postfix) with ESMTP id 4E71D40012 for ; Tue, 9 Apr 2024 13:17:43 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=i265qu+a; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="D9bum+q/"; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=i265qu+a; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="D9bum+q/"; spf=pass (imf07.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712668663; 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=v+QD8xLLYiM91+p4bVXmhbF/tnURmCnNpg59cARc7EI=; b=lCqNWL57FGsvBa6Rjrq43gbznWQ9U0TFakNjEh6mxcXXqja4xz/M2a67QWtcickSKof3UP KB+6Wa8skArrsLJW0FxZ5SHKXSq5NDz9UkPnDz68LrTR3VEZ/P/VOY37JZFevsm5t7sfxp VO72wkHXGlwxQHzsPm8TMWobUV3U1u4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712668663; a=rsa-sha256; cv=none; b=RDpVwIH11yPCR9yVV7VG3AzxRXcE5xOr7i2qaLrBIckAUa/d5ciyG6Iy6i9HaxfWPP+v08 mfdWnLLoceo5d/O49Z29dE2NqZWDXiXWZwtaT2xbo+J8ZOk7RYRf1nkv0zgZmN3QPg/U5z gEfEK49ZPeA1Fe8/NHYOm/fd1+nGKSg= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=i265qu+a; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="D9bum+q/"; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=i265qu+a; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="D9bum+q/"; spf=pass (imf07.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (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 smtp-out2.suse.de (Postfix) with ESMTPS id 6D57F209F7; Tue, 9 Apr 2024 13:17:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1712668661; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=v+QD8xLLYiM91+p4bVXmhbF/tnURmCnNpg59cARc7EI=; b=i265qu+aRIFb8KG038+Pd6xik78ieaPX8kr5wdypC2eNBCscCOig7uGOPAItRQbxri27JY ujuL//wZZmj86ntCpsv7qsOJtzZC0ECNU+htSfLLLdohUldP44aU0O7WI7Suv3HPFOHno9 +yhAgZSaswTUyiGN+Q+rslFIVtFUwoE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1712668661; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=v+QD8xLLYiM91+p4bVXmhbF/tnURmCnNpg59cARc7EI=; b=D9bum+q/8VzRGSTGX1UmjRXPIXxZRMZQ/Pzsq4vmnYjWbdD/2mop3ktmgz03R1xmZlrxNy c37w/ZiWhjEeMWBw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1712668661; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=v+QD8xLLYiM91+p4bVXmhbF/tnURmCnNpg59cARc7EI=; b=i265qu+aRIFb8KG038+Pd6xik78ieaPX8kr5wdypC2eNBCscCOig7uGOPAItRQbxri27JY ujuL//wZZmj86ntCpsv7qsOJtzZC0ECNU+htSfLLLdohUldP44aU0O7WI7Suv3HPFOHno9 +yhAgZSaswTUyiGN+Q+rslFIVtFUwoE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1712668661; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=v+QD8xLLYiM91+p4bVXmhbF/tnURmCnNpg59cARc7EI=; b=D9bum+q/8VzRGSTGX1UmjRXPIXxZRMZQ/Pzsq4vmnYjWbdD/2mop3ktmgz03R1xmZlrxNy c37w/ZiWhjEeMWBw== Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 0D4D01332F; Tue, 9 Apr 2024 13:17:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id qJJdO/Q/FWY0egAAn2gu4w (envelope-from ); Tue, 09 Apr 2024 13:17:40 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Vlastimil Babka , Kefeng Wang , Oscar Salvador Subject: [PATCH] mm,page_owner: Defer enablement of static branch Date: Tue, 9 Apr 2024 15:17:15 +0200 Message-ID: <20240409131715.13632-1-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-Rspamd-Queue-Id: 4E71D40012 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: bfaujrjxus91d9igp71rp1eddf9otpox X-HE-Tag: 1712668663-297670 X-HE-Meta: U2FsdGVkX1+mzmA1KXv623hkGIOBNXTmHwuGp/wYhStzyL+krXsoHJLcelpTPjd6rlBdm9LDsTzqpb6VT+39+/BQrvDLRxncfFmOmWIenosscIcW6ByR5ehJ23PuL4BmPOkx1J8lt6zdq2OXLiBHHlVrLlhHP6ETZAKNiz6j7aS6PJ593eD/SaSHJ5jdoXu7liZG5Yd4hsegeDHs0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eU0GDYnzuSj4203+J4CJMW3WtsUv/2UJiOp4JzivF5PKysvHYkDDTg== 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: Kefeng Wang reported that he was seeing some memory leaks with kmemleak with page_owner enabled. The reason behind is that we enable the page_owner_inited static branch and then proceed with the linking of stack_list struct to dummy_stack, which means that exists a race window between these two steps where we can have pages already being allocated calling add_stack_record_to_list(), allocating objects and linking them to stack_list, but then we set stack_list pointing to dummy_stack in init_page_owner. Which means that the objects that have been allocated during that time window are unreferenced and lost. Fix this by deferring the enablement of the branch until we have properly set up the list. Reported-by: Kefeng Wang Closes: https://lore.kernel.org/linux-mm/74b147b0-718d-4d50-be75-d6afc801cd24@huawei.com/ Tested-by: Kefeng Wang Fixes: 4bedfb314bdd ("mm,page_owner: maintain own list of stack_records structs") Signed-off-by: Oscar Salvador Acked-by: Vlastimil Babka --- Special thanks and kudos go to Kefeng Wang for helping me out chasing down this bug, as I could not reproduce it with any of my machines, and to Vlastimil to bring another pair of eyes, which was very helpful. mm/page_owner.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/page_owner.c b/mm/page_owner.c index 9bef0b442863..742f432e5bf0 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -118,7 +118,6 @@ static __init void init_page_owner(void) register_dummy_stack(); register_failure_stack(); register_early_stack(); - static_branch_enable(&page_owner_inited); init_early_allocated_pages(); /* Initialize dummy and failure stacks and link them to stack_list */ dummy_stack.stack_record = __stack_depot_get_stack_record(dummy_handle); @@ -129,6 +128,7 @@ static __init void init_page_owner(void) refcount_set(&failure_stack.stack_record->count, 1); dummy_stack.next = &failure_stack; stack_list = &dummy_stack; + static_branch_enable(&page_owner_inited); } struct page_ext_operations page_owner_ops = {