From patchwork Wed Mar 6 12:32:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13583998 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 CB170C5475B for ; Wed, 6 Mar 2024 12:31:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5B2446B0078; Wed, 6 Mar 2024 07:31:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5895F6B007D; Wed, 6 Mar 2024 07:31:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4076F6B007E; Wed, 6 Mar 2024 07:31:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 2D6156B0078 for ; Wed, 6 Mar 2024 07:31:13 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 04D5440BEF for ; Wed, 6 Mar 2024 12:31:12 +0000 (UTC) X-FDA: 81866549226.06.60AD17E Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf06.hostedemail.com (Postfix) with ESMTP id D545D18000A for ; Wed, 6 Mar 2024 12:31:09 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=GeEEvH7o; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=byNP0X5z; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=GeEEvH7o; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=byNP0X5z; spf=pass (imf06.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=1709728270; 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:in-reply-to:references:references:dkim-signature; bh=rBlJtVja81KFeI8Jp6o410PFrC90a2K0vJckbpWhMBc=; b=VeM87q2EpKxyoOkk1RsrLSWoIRDvKw9C8O5K0+x6eDLEl/D896ErQF2hMVsqZIfScY5VNq rtY8LS6DBU4KpxI8af6UOGV19MBgg1niCpokCzzUGFhzNJPQACLIFEd3D9HXrWXC+V7BXA dp9HsKVOjrpD1QcrfjHh/Pkg+gSdvnk= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=GeEEvH7o; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=byNP0X5z; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=GeEEvH7o; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=byNP0X5z; spf=pass (imf06.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709728270; a=rsa-sha256; cv=none; b=b2oBpfVPHHZbjR+KTGbwpzlqGp0msm8sFbOF7AVoz9JeF4YnyswfUUVelx9ERpWvUTLjEO quucSnPb5jRO5WQeIfxeOLCGMdQWVvtMe3k6JClKNBLmx0V8HORdp0BuD9Xr4Dwc/FvvpP 7pxQYZmg3iLSzqEk1bvvpfMCsd9KUuE= 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 34DD7759A5; Wed, 6 Mar 2024 12:31:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1709728268; 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: in-reply-to:in-reply-to:references:references; bh=rBlJtVja81KFeI8Jp6o410PFrC90a2K0vJckbpWhMBc=; b=GeEEvH7oKsaX6wN4AhpJKQ+b+OL817lZzSZEp8PpiEfVk2AyHlRcWIZ6nzYzy94FmbjdWB 22LQWNk+j7Rp3cZQSiqoaG7Ox2oEe6/GUdiATcLPr715wlWLkbHwkf4a8/2lmPw39hBhEN wMpw4TCBkafldEp3gXZMM6MAJvW074Q= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1709728268; 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: in-reply-to:in-reply-to:references:references; bh=rBlJtVja81KFeI8Jp6o410PFrC90a2K0vJckbpWhMBc=; b=byNP0X5z1ajkB68ZoOPJL5oehbqo35x5Oo4zLvow9uSs5KH9AuBSFzcsSu6i+WcQSPlpl/ Q7doAaJd3ptnLzDQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1709728268; 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: in-reply-to:in-reply-to:references:references; bh=rBlJtVja81KFeI8Jp6o410PFrC90a2K0vJckbpWhMBc=; b=GeEEvH7oKsaX6wN4AhpJKQ+b+OL817lZzSZEp8PpiEfVk2AyHlRcWIZ6nzYzy94FmbjdWB 22LQWNk+j7Rp3cZQSiqoaG7Ox2oEe6/GUdiATcLPr715wlWLkbHwkf4a8/2lmPw39hBhEN wMpw4TCBkafldEp3gXZMM6MAJvW074Q= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1709728268; 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: in-reply-to:in-reply-to:references:references; bh=rBlJtVja81KFeI8Jp6o410PFrC90a2K0vJckbpWhMBc=; b=byNP0X5z1ajkB68ZoOPJL5oehbqo35x5Oo4zLvow9uSs5KH9AuBSFzcsSu6i+WcQSPlpl/ Q7doAaJd3ptnLzDQ== 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 9A03F1377D; Wed, 6 Mar 2024 12:31:07 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id CJLKIgti6GUaTwAAn2gu4w (envelope-from ); Wed, 06 Mar 2024 12:31:07 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Vlastimil Babka , Marco Elver , Andrey Konovalov , Alexander Potapenko , Oscar Salvador , kernel test robot Subject: [PATCH 1/2] mm,page_owner: Check for null stack_record before bumping its refcount Date: Wed, 6 Mar 2024 13:32:16 +0100 Message-ID: <20240306123217.29774-2-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240306123217.29774-1-osalvador@suse.de> References: <20240306123217.29774-1-osalvador@suse.de> MIME-Version: 1.0 X-Rspamd-Queue-Id: D545D18000A X-Rspam-User: X-Stat-Signature: 7k4toazbtmudxxb86ztbqcaz5agd8ocn X-Rspamd-Server: rspam01 X-HE-Tag: 1709728269-847063 X-HE-Meta: U2FsdGVkX1+XWJLKmzcPdHawiQqqH+bYHLP7K7V5gqFge/u3hKujCRp58qxqgrLZfprETlixPfUdlgYv+Lwpk62U6o1ms4GMW2pzJgLsgzXkz4WAN2DRYAe6r1ZXIRKFY/GLCaof8k62v4vr0xrXXsJunZaDYSmAR7pWCepDAubv0LY8pVT53wzB7pB2K5vuynfqResp1dHkSBZRl7erhRStNUTT40v185zZW/r2ET49Qr+6sfiGSMdevcWuUCAMQWusONjBpNPwke8vBA1Jrik7wDDYxG9Y+ZeCWi/LyUxsCdatgNDXChKxRaw9oUinbOmiCsv/UVUc0xftz5YQAJV3OFigTblWZDsR6U89zjalMKmkBnmr3MMaGNsBg0+slsbT0V7/HErGUPxzRea1csH+yVleIqhVLI4ywdrThs+zKmtzckijeVrrMUDVbUYVkhczt+wNknwmEvgJhDeGk8ygMFr/lb6juUsSxkl0ERA2YPjNTdwM4jJaxMa+nEHHe633WrJLGVns8NvtnICdBepqaRwlakJ0JKeNPIBv5SdQmjab8aellFxqX9wQ7zcClrI67G1m7CXAvNrXEJvNV3w4qzTihoqLmjIpoACRByo4Ownrx20r/Uq5pxMTG/IdFytig3Nz+RB3a7sDJF67RnsfSijZGjl4ewrBHHCu/UE6Hqg4KGqBcmx3wDBePQ9Nqc3HGpFTodhiB7A314OIUx9wGOZq8UtwGQRAt0sr+Vi7BxAl8A6a2G+oiqCSDEcrIQCqC0H/h/5KBEJU8f6mhiOf0cidYd+m4uL3+pg6qxxGIZi2FZjOjXfnWKzxiApr1MelCZFoXN753SwKCOb14eRsuMa/OcoDzF54cItsdJuLEzt4rx5MfdcDKszpsS6hGS+qlVbqRjCgwCGWOpA2PaOOFX3RHYQ+Gdf1F9Ok/cb8LnFkU13D2sFW/2IejyFUnNcKVDojdQMQ8KzRSQT np0cEaG3 tHj72gy2GLKagaPzrIXdU191qa6CdjHHjy5dk 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: Although the retrieval of the stack_records for {dummy,failure}_handle happen when page_owner gets initialized, there seems to be some situations where stackdepot space has been already depleted by then, so we get 0-handles which make stack_records being NULL for those cases. Be careful to 1) only bump stack_records refcount and 2) only access stack_record fields if we actually have a non-null stack_record between hands. Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202403051032.e2f865a-lkp@intel.com Fixes: 4bedfb314bdd ("mm,page_owner: implement the tracking of the stacks count") Signed-off-by: Oscar Salvador Reviewed-by: Vlastimil Babka --- mm/page_owner.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mm/page_owner.c b/mm/page_owner.c index 033e349f6479..7163a1c44ccf 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -107,8 +107,10 @@ static __init void init_page_owner(void) /* Initialize dummy and failure stacks and link them to stack_list */ dummy_stack.stack_record = __stack_depot_get_stack_record(dummy_handle); failure_stack.stack_record = __stack_depot_get_stack_record(failure_handle); - refcount_set(&dummy_stack.stack_record->count, 1); - refcount_set(&failure_stack.stack_record->count, 1); + if (dummy_stack.stack_record) + refcount_set(&dummy_stack.stack_record->count, 1); + if (failure_stack.stack_record) + refcount_set(&failure_stack.stack_record->count, 1); dummy_stack.next = &failure_stack; stack_list = &dummy_stack; } @@ -856,6 +858,9 @@ static int stack_print(struct seq_file *m, void *v) unsigned long nr_entries; struct stack_record *stack_record = stack->stack_record; + if (!stack->stack_record) + return 0; + nr_entries = stack_record->size; entries = stack_record->entries; stack_count = refcount_read(&stack_record->count) - 1;