From patchwork Tue Feb 18 19:59:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 13980832 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B8B5AC021AD for ; Tue, 18 Feb 2025 20:34:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:Subject:Cc:To:From:Date:Message-ID:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: List-Owner; bh=fZojzVLy2tMfil75IXAXZ03S3XDVrP0r5Q56Ndp4Rwk=; b=UstUycZktekPAA w0Px/cBXkcwAy3jSrGLyPu2qSQ7e2KIvP11lRQKxA6Qq9iTo342yPBy3PjeL0wveeRX4Ctpin2a+4 3y6cjIlUpUzBWmipiSUlCW7qjkJrydTNFbUKNbOTojIZK5xZz83PibNq3BpqOCvsShHp986qsGR9Z ysqLI/1fUNcpMuKvJmBiECrrwJqQEds3OdE+5QN+BE5/DmPGozwo+uE3ZTVfEv+OK26Tj0kHuMCo7 i/ScUUlz1BxgmH1Fm3NAzvB/HVMPqqhUD8rYgaWFGjCensBhTtVzdYPOTgfNDQjKVjnw5KFi7KU2e T5mE4c07FaEsbnux6Xew==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tkUIF-00000009n9J-2Nr8; Tue, 18 Feb 2025 20:34:11 +0000 Received: from nyc.source.kernel.org ([2604:1380:45d1:ec00::3]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tkTlC-00000009fnG-1J27 for linux-arm-kernel@lists.infradead.org; Tue, 18 Feb 2025 20:00:06 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 2461FA41AFD; Tue, 18 Feb 2025 19:58:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7FB78C4CEF5; Tue, 18 Feb 2025 20:00:00 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1tkTlX-00000004ArJ-0q9Y; Tue, 18 Feb 2025 15:00:23 -0500 Message-ID: <20250218200023.055162048@goodmis.org> User-Agent: quilt/0.68 Date: Tue, 18 Feb 2025 14:59:23 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, bpf , linux-arm-kernel@lists.infradead.org, linux-s390@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Peter Zijlstra , Linus Torvalds , Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Zheng Yejian , Martin Kelly , Christophe Leroy , Josh Poimboeuf , Heiko Carstens , Catalin Marinas , Will Deacon , Vasily Gorbik , Alexander Gordeev Subject: [PATCH v5 5/6] ftrace: Update the mcount_loc check of skipped entries References: <20250218195918.255228630@goodmis.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250218_120002_427395_31130063 X-CRM114-Status: GOOD ( 14.17 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Steven Rostedt Now that weak functions turn into skipped entries, update the check to make sure the amount that was allocated would fit both the entries that were allocated as well as those that were skipped. Signed-off-by: Steven Rostedt (Google) --- Changes since v4: https://lore.kernel.org/20250217153453.792481985@goodmis.org - Initialized variable "remaining" to zero kernel/trace/ftrace.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index e3f89924f603..e657013424aa 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -7111,7 +7111,28 @@ static int ftrace_process_locs(struct module *mod, /* We should have used all pages unless we skipped some */ if (pg_unuse) { - WARN_ON(!skipped); + unsigned long pg_remaining, remaining = 0; + unsigned long skip; + + /* Count the number of entries unused and compare it to skipped. */ + pg_remaining = (ENTRIES_PER_PAGE << pg->order) - pg->index; + + if (!WARN(skipped < pg_remaining, "Extra allocated pages for ftrace")) { + + skip = skipped - pg_remaining; + + for (pg = pg_unuse; pg; pg = pg->next) + remaining += 1 << pg->order; + + skip = DIV_ROUND_UP(skip, ENTRIES_PER_PAGE); + + /* + * Check to see if the number of pages remaining would + * just fit the number of entries skipped. + */ + WARN(skip != remaining, "Extra allocated pages for ftrace: %lu with %lu skipped", + remaining, skipped); + } /* Need to synchronize with ftrace_location_range() */ synchronize_rcu(); ftrace_free_pages(pg_unuse);