From nobody Sun Feb 8 05:27:38 2026 Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A1AF221F0C for ; Thu, 15 Jan 2026 23:09:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.40.44.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768518565; cv=none; b=snGhx3wMNrRaluvcVUzTtL97lSe+zt1eAPRNjjSeTdKacncycKEADYoBt8t7cZfCrPTT4YUuyn8755FiYUlZA861NSbS3yDNnFdFfGTvHfysvHdTMgHi80YDfOeBNiZMZ6vjYTccjnv8a/xOCIQXulnaW+cDPa8gnSqXwoRJSOs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768518565; c=relaxed/simple; bh=U8PDQaiv+969cY1ES6pjpOZzTQd/MdGTAfA/bdaLJS8=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type; b=jxz2e+zBPO+xS4He5970tRWF/YfhtXmX7HXTYmHROGtck6fHNIo23gpcVq6qCw3tkj3WMbg34oTGLBv5vIsPl/FShxkn0f1uVWK9U3QXjMWNee8ON5G/vFHg4wVPQmC83y5w6uBMk/3fxV6KwKazbhXdHw00j/GIwrVwvinjrsw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=goodmis.org; spf=pass smtp.mailfrom=goodmis.org; arc=none smtp.client-ip=216.40.44.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=goodmis.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=goodmis.org Received: from omf02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id F23BD1404AB; Thu, 15 Jan 2026 23:09:21 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: rostedt@goodmis.org) by omf02.hostedemail.com (Postfix) with ESMTPA id 118CF80014; Thu, 15 Jan 2026 23:09:19 +0000 (UTC) Date: Thu, 15 Jan 2026 18:09:18 -0500 From: Steven Rostedt To: Linus Torvalds Cc: LKML , Masami Hiramatsu , Mathieu Desnoyers , Guenter Roeck , Mark Rutland Subject: [GIT PULL] ftrace: Fix for v6.19 Message-ID: <20260115180918.21dca431@fedora> X-Mailer: Claws Mail 4.3.1 (GTK 3.24.51; x86_64-redhat-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 118CF80014 X-Stat-Signature: ieu6qg5dz6358xeooij8n87x4tgsn9id X-Rspamd-Server: rspamout08 X-Session-Marker: 726F737465647440676F6F646D69732E6F7267 X-Session-ID: U2FsdGVkX18NvdidW28tai9u48grpau891fA4OtS9LY= X-HE-Tag: 1768518559-823731 X-HE-Meta: U2FsdGVkX182EvkFqx4ryIad0qUnnCYykK09W6D5znj5pHkrx+q/2JXerIZiZ0W8bG16O0govqKcejjLmZN+UlRZhG14B9SSDdhOYtM2KlgYSXh8kAqjqI32n4lWNlfSRcGB9uqpm0T41jFjSyfkDBXENnUP7Bnx/4sfSmeI0ORM7miBEkcOvw2FXUPPkFv7NO7IdQz6oRUQ1243lqrSlUTJRc3klFUGhhvN3atDvirVY6IpXYZA6adDkGTL00Cf6hfED6LOQKNP9+tpuo7g9cV/UTg9kW8Rt4evmF3Sl/fUE3hbK9Yrb97q8cu5LKxjSBuPSJIdDZI7Q3YG8d8ZU+oUqVmpOBTsx19aPKh9yibTSC7Rrz/eA6NMu5EJcCXOg5a7hDKP9eVKiVZo9JRZIcdx0ByA67q/6tcUYA8uAGpplp95IWhmE0YtcRaQrcRtsGsbKk5p//lAji2MjEvhg2Ourat0N1TI2maIPegctTYIWLtOiw/ixbCBFCSbJ1vHM5XlloSH8XuBoTtJp2msasOSAAJHtnC30XEL/1x78a8= Content-Type: text/plain; charset="utf-8" Linus, ftrace fixes for v6.19: - Fix allocation accounting on boot up The ftrace records for each function that ftrace can attach to is done in a group of pages. At boot up, the number of pages are calculated and allocated. After that, the pages are filled with data. It may allocate more than needed due to some functions not being recorded (because they are unused weak functions), this too is recorded. After the data is filled in, a check is made to make sure the right number of pages were allocated. But this was off due to the assumption that the same number of entries fit per every page. Because the size of an entry does not evenly divide into PAGE_SIZE, there is a rounding error when a large number of pages is allocated to hold the events. This causes the check to fail and triggers a warning. Fix the accounting by finding out how many pages are actually allocated from the functions that allocate them and use that to see if all the pages allocated were used and the ones not used are properly freed. Please pull the latest ftrace-v6.19-rc5 tree, which can be found at: git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git ftrace-v6.19-rc5 Tag SHA1: 39cb242e3a690f3e5cc4d22844fe9e837180268c Head SHA1: be55257fab181b93af38f8c4b1b3cb453a78d742 Guenter Roeck (1): ftrace: Do not over-allocate ftrace memory ---- kernel/trace/ftrace.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) --------------------------- commit be55257fab181b93af38f8c4b1b3cb453a78d742 Author: Guenter Roeck Date: Tue Jan 13 07:22:42 2026 -0800 ftrace: Do not over-allocate ftrace memory =20 The pg_remaining calculation in ftrace_process_locs() assumes that ENTRIES_PER_PAGE multiplied by 2^order equals the actual capacity of the allocated page group. However, ENTRIES_PER_PAGE is PAGE_SIZE / ENTRY_SI= ZE (integer division). When PAGE_SIZE is not a multiple of ENTRY_SIZE (e.g. 4096 / 24 =3D 170 with remainder 16), high-order allocations (like 256 = pages) have significantly more capacity than 256 * 170. This leads to pg_remai= ning being underestimated, which in turn makes skip (derived from skipped - pg_remaining) larger than expected, causing the WARN(skip !=3D remainin= g) to trigger. =20 Extra allocated pages for ftrace: 2 with 654 skipped WARNING: CPU: 0 PID: 0 at kernel/trace/ftrace.c:7295 ftrace_process_loc= s+0x5bf/0x5e0 =20 A similar problem in ftrace_allocate_records() can result in allocating too many pages. This can trigger the second warning in ftrace_process_locs(). =20 Extra allocated pages for ftrace WARNING: CPU: 0 PID: 0 at kernel/trace/ftrace.c:7276 ftrace_process_loc= s+0x548/0x580 =20 Use the actual capacity of a page group to determine the number of pages to allocate. Have ftrace_allocate_pages() return the number of allocated pages to avoid having to calculate it. Use the actual page group capaci= ty when validating the number of unused pages due to skipped entries. Drop the definition of ENTRIES_PER_PAGE since it is no longer used. =20 Cc: stable@vger.kernel.org Fixes: 4a3efc6baff93 ("ftrace: Update the mcount_loc check of skipped e= ntries") Link: https://patch.msgid.link/20260113152243.3557219-1-linux@roeck-us.= net Signed-off-by: Guenter Roeck Signed-off-by: Steven Rostedt (Google) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index ef2d5dca6f70..aa758efc3731 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -1148,7 +1148,6 @@ struct ftrace_page { }; =20 #define ENTRY_SIZE sizeof(struct dyn_ftrace) -#define ENTRIES_PER_PAGE (PAGE_SIZE / ENTRY_SIZE) =20 static struct ftrace_page *ftrace_pages_start; static struct ftrace_page *ftrace_pages; @@ -3834,7 +3833,8 @@ static int ftrace_update_code(struct module *mod, str= uct ftrace_page *new_pgs) return 0; } =20 -static int ftrace_allocate_records(struct ftrace_page *pg, int count) +static int ftrace_allocate_records(struct ftrace_page *pg, int count, + unsigned long *num_pages) { int order; int pages; @@ -3844,7 +3844,7 @@ static int ftrace_allocate_records(struct ftrace_page= *pg, int count) return -EINVAL; =20 /* We want to fill as much as possible, with no empty pages */ - pages =3D DIV_ROUND_UP(count, ENTRIES_PER_PAGE); + pages =3D DIV_ROUND_UP(count * ENTRY_SIZE, PAGE_SIZE); order =3D fls(pages) - 1; =20 again: @@ -3859,6 +3859,7 @@ static int ftrace_allocate_records(struct ftrace_page= *pg, int count) } =20 ftrace_number_of_pages +=3D 1 << order; + *num_pages +=3D 1 << order; ftrace_number_of_groups++; =20 cnt =3D (PAGE_SIZE << order) / ENTRY_SIZE; @@ -3887,12 +3888,14 @@ static void ftrace_free_pages(struct ftrace_page *p= ages) } =20 static struct ftrace_page * -ftrace_allocate_pages(unsigned long num_to_init) +ftrace_allocate_pages(unsigned long num_to_init, unsigned long *num_pages) { struct ftrace_page *start_pg; struct ftrace_page *pg; int cnt; =20 + *num_pages =3D 0; + if (!num_to_init) return NULL; =20 @@ -3906,7 +3909,7 @@ ftrace_allocate_pages(unsigned long num_to_init) * waste as little space as possible. */ for (;;) { - cnt =3D ftrace_allocate_records(pg, num_to_init); + cnt =3D ftrace_allocate_records(pg, num_to_init, num_pages); if (cnt < 0) goto free_pages; =20 @@ -7192,8 +7195,6 @@ static int ftrace_process_locs(struct module *mod, if (!count) return 0; =20 - pages =3D DIV_ROUND_UP(count, ENTRIES_PER_PAGE); - /* * Sorting mcount in vmlinux at build time depend on * CONFIG_BUILDTIME_MCOUNT_SORT, while mcount loc in @@ -7206,7 +7207,7 @@ static int ftrace_process_locs(struct module *mod, test_is_sorted(start, count); } =20 - start_pg =3D ftrace_allocate_pages(count); + start_pg =3D ftrace_allocate_pages(count, &pages); if (!start_pg) return -ENOMEM; =20 @@ -7305,27 +7306,27 @@ static int ftrace_process_locs(struct module *mod, /* We should have used all pages unless we skipped some */ if (pg_unuse) { unsigned long pg_remaining, remaining =3D 0; - unsigned long skip; + long skip; =20 /* Count the number of entries unused and compare it to skipped. */ - pg_remaining =3D (ENTRIES_PER_PAGE << pg->order) - pg->index; + pg_remaining =3D (PAGE_SIZE << pg->order) / ENTRY_SIZE - pg->index; =20 if (!WARN(skipped < pg_remaining, "Extra allocated pages for ftrace")) { =20 skip =3D skipped - pg_remaining; =20 - for (pg =3D pg_unuse; pg; pg =3D pg->next) + for (pg =3D pg_unuse; pg && skip > 0; pg =3D pg->next) { remaining +=3D 1 << pg->order; + skip -=3D (PAGE_SIZE << pg->order) / ENTRY_SIZE; + } =20 pages -=3D remaining; =20 - skip =3D 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 !=3D remaining, "Extra allocated pages for ftrace: %lu with %= lu skipped", + WARN(pg || skip > 0, "Extra allocated pages for ftrace: %lu with %lu sk= ipped", remaining, skipped); } /* Need to synchronize with ftrace_location_range() */