Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp35475402rwd; Mon, 10 Jul 2023 08:00:47 -0700 (PDT) X-Google-Smtp-Source: APBJJlFaXHfUAqxT3HFYvSabybefAA1fGE44i3V4QHq8Se3sBLDYwwLy74lNHo0a+AmIAtI0ajkq X-Received: by 2002:a17:906:b055:b0:96f:b58e:7e21 with SMTP id bj21-20020a170906b05500b0096fb58e7e21mr14214601ejb.52.1689001247145; Mon, 10 Jul 2023 08:00:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689001247; cv=none; d=google.com; s=arc-20160816; b=TG6bvg30K2iy1ZNlDp94whu63Uu2zhZVLTUX9beckLsgJscqV+rRbX9jeD3TtsiwDK JSH90lM+L9HeU8UO69x3CMfIqDsdhyi894o9CCPvInGcRNBg9RV+nOaDZrbOeVY9Z4dK WRp2Wx397Q9zJbWSWwSzFm/DICFpYGRfJJKi03+u6FCTrQuP8EWmxsQaf3ovYjJFxxhj hUxad6sYMyycFhqWZT3UvNuRhi4eI95neLbgfW+5o+vVM7GnnpZ5GCNSGGA9YD3Fxg4b jxx0m2H4me5FyND0ehO0WGAoSBizPr4lvRZ+AO/46LXtC42VQsfPwoFLS/INEKkYoMoC 21Mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=uFVuOuXP4B94KEy0lfuzU1Feg3onECqzBawt4YQVIe4=; fh=L1quHuhtgpn2KtsWSY5lpjvYmiUhmZROXAzD65I9gqI=; b=EXanQQGekmAJ3RcYyLhLfWgruTGE3h0D2JCvDpWJ2FMhOnVUhk7A6mdq/clcAheUwJ j5Kb0fpolRPqwh5G7R8q4XLSp62gU3O8e2dEC9/MP5Z5Rt5z5RevX7oJB+zvZG3pP8eo pCe1TbcglIhWqNW+YXR5rnghdjj8s9JsBtXw4aFfLSzXmKw9h6luqCIbDPk1qHysrknj t3ya8BJsYEhCOVqS/cZPEVcEldFuDKUmGiUGqC7pqBdCwo9D3e/otUeJNf9b1Oo1G42T d4iRGzRmY1bzGV88P0BhUDQq8BHg6u1++P+NwjgOlHWuQO0yQHdqYgqGY/x9VxqBbUeP l8Tg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s17-20020a170906169100b00992e14a3655si8945568ejd.354.2023.07.10.08.00.18; Mon, 10 Jul 2023 08:00:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231716AbjGJOqb (ORCPT + 99 others); Mon, 10 Jul 2023 10:46:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229469AbjGJOqb (ORCPT ); Mon, 10 Jul 2023 10:46:31 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AA6F114; Mon, 10 Jul 2023 07:46:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0FFC061048; Mon, 10 Jul 2023 14:46:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE65BC433C8; Mon, 10 Jul 2023 14:46:26 +0000 (UTC) Date: Mon, 10 Jul 2023 10:46:25 -0400 From: Steven Rostedt To: Zheng Yejian Cc: , , Subject: Re: [PATCH] ftrace: Fix possible warning on checking all pages used in ftrace_process_locs() Message-ID: <20230710104625.421c851a@gandalf.local.home> In-Reply-To: <20230710212958.274126-1-zhengyejian1@huawei.com> References: <20230710212958.274126-1-zhengyejian1@huawei.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 11 Jul 2023 05:29:58 +0800 Zheng Yejian wrote: > As comments in ftrace_process_locs(), there may be NULL pointers in > mcount_loc section: > > Some architecture linkers will pad between > > the different mcount_loc sections of different > > object files to satisfy alignments. > > Skip any NULL pointers. > > After 20e5227e9f55 ("ftrace: allow NULL pointers in mcount_loc"), > NULL pointers will be accounted when allocating ftrace pages but > skipped before adding into ftrace pages, this may result in some > pages not being used. Then after 706c81f87f84 ("ftrace: Remove extra > helper functions"), warning may occur at: > WARN_ON(pg->next); > > So we may need to skip NULL pointers before allocating ftrace pages. > > Fixes: 706c81f87f84 ("ftrace: Remove extra helper functions") > Signed-off-by: Zheng Yejian > --- > kernel/trace/ftrace.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c > index 3740aca79fe7..5b474165df31 100644 > --- a/kernel/trace/ftrace.c > +++ b/kernel/trace/ftrace.c > @@ -6485,6 +6485,16 @@ static int ftrace_process_locs(struct module *mod, > if (!count) > return 0; > > + p = start; > + while (p < end) { > + /* > + * Refer to conments below, there may be NULL pointers, > + * skip them before allocating pages > + */ > + addr = ftrace_call_adjust(*p++); > + if (!addr) > + count--; > + } My main concern about this is the added overhead during boot to process this. There's 10s of thousands of functions, so this loop will be 10s of thousands. I also don't like that this is an unconditional loop (meaning it executes even when it is unnecessary to do so). > /* > * Sorting mcount in vmlinux at build time depend on > * CONFIG_BUILDTIME_MCOUNT_SORT, while mcount loc in How about something like this? -- Steve diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index b24c573934af..acd033371721 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -6474,6 +6474,7 @@ static int ftrace_process_locs(struct module *mod, struct ftrace_page *start_pg; struct ftrace_page *pg; struct dyn_ftrace *rec; + unsigned long skipped = 0; unsigned long count; unsigned long *p; unsigned long addr; @@ -6536,8 +6537,10 @@ static int ftrace_process_locs(struct module *mod, * object files to satisfy alignments. * Skip any NULL pointers. */ - if (!addr) + if (!addr) { + skipped++; continue; + } end_offset = (pg->index+1) * sizeof(pg->records[0]); if (end_offset > PAGE_SIZE << pg->order) { @@ -6551,12 +6554,24 @@ static int ftrace_process_locs(struct module *mod, rec->ip = addr; } - /* We should have used all pages */ - WARN_ON(pg->next); - /* Assign the last page to ftrace_pages */ ftrace_pages = pg; + /* We should have used all pages unless we skipped some */ + if (pg->next) { + WARN_ON(!skipped); + while (ftrace_pages->next) { + pg = ftrace_pages->next; + ftrace_pages->next = pg->next; + if (pg->records) { + free_pages((unsigned long)pg->records, pg->order); + ftrace_number_of_pages -= 1 << pg->order; + } + kfree(pg); + ftrace_number_of_groups--; + } + } + /* * We only need to disable interrupts on start up * because we are modifying code that an interrupt