From patchwork Tue Jul 11 20:16:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zheng Yejian X-Patchwork-Id: 118314 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp322329vqm; Tue, 11 Jul 2023 01:22:51 -0700 (PDT) X-Google-Smtp-Source: APBJJlE4gVFlExKRe7rHD5oGZtb86AT//YyLwcQTa0v0UQA386nUODqOcuyqHNu6sd0dlcW6R4uc X-Received: by 2002:a17:907:c01c:b0:991:d727:6977 with SMTP id ss28-20020a170907c01c00b00991d7276977mr14415220ejc.38.1689063770883; Tue, 11 Jul 2023 01:22:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689063770; cv=none; d=google.com; s=arc-20160816; b=bHjdvBHyrmBwTy8bJfshPHECcy743ZhC3m9YtQcTa+QlXSs8eXqK+V204/rb2NL7sS TCnXqXDBD/OkxLnubks0O6KueJLDa2pxP7kHbJ6Uag5ZxwmTgiZHUYLFdnPqDx/nYa3/ G5rXHAQislyNG+9SXTxVrwWK6NwZdFrXz37ECQMEZK8aRcMSbJJ/uuJj4K89X1za6w/t OVwK3C6UqkuZcJu0g6r6NbVYt6hbrsuEIQD7J6FCY7RQdSF0ebo56Pggx9bNUAfAgsWW mtPFvZhiG3YdCUxPEfAIPcHQJJqOvUTFLakSDebIKetnOL1Q3THVgXVjJGSg74YzdSmj 0MQg== 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:date:subject:cc:to:from; bh=vTveLGaSlE1l2EqFB4mkvsINKTP+2LzvvlftwZxcf6E=; fh=APhBgUjYXesXWOIgKm8aSjIctaOGtmXBvn0W6GCNYWk=; b=G3uj5ptKaRNyQ1Io023/ZGBIhZYOZGf+Wwbozgb9iNb+0LgBvnLDVeQgboyR21tJgJ y/wORS9ZMH3yJYj0oIu64lMkia5G91+cGG5uCmuuN+OOAHvmujnhDEl2lZobwI4+MVxw vNM/frrdyk1g+Htj7Yy182KgGTl7p8Lsgcsej6SYUSvVlIaVJWxI1FcWjH0wymBOh6rD igzmhA9koS2V2ayaGoYVlyhuvKWxbJHsFXOpyTDqgCFnn0Ogmf+N1yel3ZQhOCAiI+HK fSAYGbcfhvztU11jPW7Fkfxzhj+xqxZhR6G21KfE3DhdF4t+3svHtFXI2J03bsN5wiXp gX+g== 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q2-20020a1709060e4200b009823926ec36si1349379eji.931.2023.07.11.01.22.27; Tue, 11 Jul 2023 01:22:50 -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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229583AbjGKIQB (ORCPT + 99 others); Tue, 11 Jul 2023 04:16:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231148AbjGKIP6 (ORCPT ); Tue, 11 Jul 2023 04:15:58 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CDE0E5C; Tue, 11 Jul 2023 01:15:54 -0700 (PDT) Received: from dggpeml500012.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4R0YXs0D7KzPkBF; Tue, 11 Jul 2023 16:13:33 +0800 (CST) Received: from localhost.localdomain (10.67.175.61) by dggpeml500012.china.huawei.com (7.185.36.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 11 Jul 2023 16:15:51 +0800 From: Zheng Yejian To: CC: , , , Subject: [PATCH v2] ftrace: Fix possible warning on checking all pages used in ftrace_process_locs() Date: Wed, 12 Jul 2023 04:16:30 +0800 Message-ID: <20230711201630.1837109-1-zhengyejian1@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230710104625.421c851a@gandalf.local.home> References: <20230710104625.421c851a@gandalf.local.home> MIME-Version: 1.0 X-Originating-IP: [10.67.175.61] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml500012.china.huawei.com (7.185.36.15) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,DATE_IN_FUTURE_12_24, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771026112620047218 X-GMAIL-MSGID: 1771111732360296372 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 commit 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 commit 706c81f87f84 ("ftrace: Remove extra helper functions"), warning may occur at: WARN_ON(pg->next); To fix it, only warn for case that no pointers skipped but pages not used up, then free those unused pages after releasing ftrace_lock. Fixes: 706c81f87f84 ("ftrace: Remove extra helper functions") Suggested-by: Steven Rostedt Signed-off-by: Zheng Yejian --- kernel/trace/ftrace.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 3740aca79fe7..b46e539dc085 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -6473,7 +6473,9 @@ static int ftrace_process_locs(struct module *mod, { struct ftrace_page *start_pg; struct ftrace_page *pg; + struct ftrace_page *pg_unuse = NULL; struct dyn_ftrace *rec; + unsigned long skipped = 0; unsigned long count; unsigned long *p; unsigned long addr; @@ -6536,8 +6538,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,9 +6555,8 @@ static int ftrace_process_locs(struct module *mod, rec->ip = addr; } - /* We should have used all pages */ - WARN_ON(pg->next); - + pg_unuse = pg->next; + pg->next = NULL; /* Assign the last page to ftrace_pages */ ftrace_pages = pg; @@ -6574,6 +6577,20 @@ static int ftrace_process_locs(struct module *mod, out: mutex_unlock(&ftrace_lock); + /* We should have used all pages unless we skipped some */ + if (pg_unuse) { + WARN_ON(!skipped); + while (pg_unuse) { + pg = pg_unuse; + pg_unuse = 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--; + } + } return ret; }