From patchwork Tue Jul 25 20:26:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 125802 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp3434vqo; Tue, 25 Jul 2023 13:49:05 -0700 (PDT) X-Google-Smtp-Source: APBJJlHV0rDcN91X37mhFvGT7G1ZC4JxUsfxCBvn9CCFCj/xdLwXZSI8uGzrdHqGBU3WPNuXniGt X-Received: by 2002:a05:6512:2342:b0:4f8:7568:e948 with SMTP id p2-20020a056512234200b004f87568e948mr12854lfu.51.1690318145523; Tue, 25 Jul 2023 13:49:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690318145; cv=none; d=google.com; s=arc-20160816; b=GZ1Fkc+KCkuyC15r0pGscFPkzxBPAIMIKfhNeYAX8/EDNPNHhzFXmogKCIFJW9QWR3 x6FSZ3HQ4QVe7dXLPuRBklCiHiIWz2yaTVjobo5yvb+HhYxyaaoIa1Zj3FiIIkqh8bMS uZPUSlHr70rzA18sCcAdQ1lxgqHgytZUODq9oMYVHCVF/dznj5l9EKOIV5DWateUeQHi ChJoWTepi5UzyEQLiLY0CHeyZvKA47QdZXmH0GRjLtuFlHYJeR+mSuJP9kuSR89xEDbQ VX0Jo+sIWTkmw7kuUFk/KAEUUoJRmyAYUCIpRRl04YjDsdyhZBxDFz7Iq/l70PemBhKz FW8w== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=/MbaCZsZl3N2q7Hje0LAdtorlqTL0EmNbcP7j9i0wuA=; fh=Ch0oQ9CBeli6gAEOF+nFDfwoxdLkObyLr3nBOyIe5Eg=; b=jyHvYQ0SRJpB8Uydg70igO6WczYJQHs+W+THoHm7fYx1MDKZKGbdSMEmHFZ8G9tYxU dnS1lVDHYq3TEbBn6mwqKULqbdQTIDbHPdPFou9hD9y7WHPuh2mCqz2GmJnfZVpAKd6P lZlW/19/871WC9AEJaHipv6ROCy3cIWO7+fz57EzZuyH113DIZHBogZc/Q5JhPr3gOkV 2bTZEmTKdsbeaKlLPOUlT6GxEzPKpos9jYpUctYkCz09yqlFLmKGbdYFEdgB3fquzB/Z zoBdkzJCMO/5rKI5agFtKVA8RSCW1qx0Hj4RYwE0jtiILxGwjmygeGUCr6mYiSGZp8+a FDxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sJOSbA51; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w10-20020a056402070a00b00522414b4882si1866894edx.187.2023.07.25.13.48.40; Tue, 25 Jul 2023 13:49:05 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sJOSbA51; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229522AbjGYU1E (ORCPT + 99 others); Tue, 25 Jul 2023 16:27:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229568AbjGYU1D (ORCPT ); Tue, 25 Jul 2023 16:27:03 -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 5E6E010EC for ; Tue, 25 Jul 2023 13:27:02 -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 C18D7618D9 for ; Tue, 25 Jul 2023 20:27:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8EEFEC433C8; Tue, 25 Jul 2023 20:26:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690316821; bh=gEzQPMn8Qpqa1JNOX+vH1aewrhLcYcM6fFBfClUEv/8=; h=From:To:Cc:Subject:Date:From; b=sJOSbA51Ti/uusknlq3hcUajShgMVP5z/PCyoNDaQKCdcs/uUIgZfXCX1UG1v0Oot my+3xnrTIt+cx7D1BZtbLrFTLldGkUUGrwVNRzH3n2oKhj4yR2G3AZhbpKqXDEYj+a twITw/WPtdabfmBPL6L4tWn6j7GYpJFgOWIxUxh+KCeNryHCSaxm6YHiINcP7MXc8l JQjvVQaLkbcYjJhKC+Q/PngVugBOQFKn7zfKu8nj4iswQ7Vzsk04tbSLVT0n6WQM20 wnrOvnfOKUCFX6HIjA5b6NUW5fzMIN5jA464TDQKcFU/9rytA81/bvOZ5+VKjdFWf2 8Fi3j79i7PbBg== From: Arnd Bergmann To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Hou Tao Cc: Arnd Bergmann , Alexei Starovoitov , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Kumar Kartikeya Dwivedi , bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] [v2] bpf: work around -Wuninitialized warning Date: Tue, 25 Jul 2023 22:26:40 +0200 Message-Id: <20230725202653.2905259-1-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772427039646131859 X-GMAIL-MSGID: 1772427039646131859 From: Arnd Bergmann Splitting these out into separate helper functions means that we actually pass an uninitialized variable into another function call if dec_active() happens to not be inlined, and CONFIG_PREEMPT_RT is disabled: kernel/bpf/memalloc.c: In function 'add_obj_to_free_list': kernel/bpf/memalloc.c:200:9: error: 'flags' is used uninitialized [-Werror=uninitialized] 200 | dec_active(c, flags); Avoid this by passing the flags by reference, so they either get initialized and dereferenced through a pointer, or the pointer never gets accessed at all. Fixes: 18e027b1c7c6d ("bpf: Factor out inc/dec of active flag into helpers.") Suggested-by: Alexei Starovoitov Signed-off-by: Arnd Bergmann --- kernel/bpf/memalloc.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/kernel/bpf/memalloc.c b/kernel/bpf/memalloc.c index 51d6389e5152e..14d9b1a9a4cac 100644 --- a/kernel/bpf/memalloc.c +++ b/kernel/bpf/memalloc.c @@ -183,11 +183,11 @@ static void inc_active(struct bpf_mem_cache *c, unsigned long *flags) WARN_ON_ONCE(local_inc_return(&c->active) != 1); } -static void dec_active(struct bpf_mem_cache *c, unsigned long flags) +static void dec_active(struct bpf_mem_cache *c, unsigned long *flags) { local_dec(&c->active); if (IS_ENABLED(CONFIG_PREEMPT_RT)) - local_irq_restore(flags); + local_irq_restore(*flags); } static void add_obj_to_free_list(struct bpf_mem_cache *c, void *obj) @@ -197,7 +197,7 @@ static void add_obj_to_free_list(struct bpf_mem_cache *c, void *obj) inc_active(c, &flags); __llist_add(obj, &c->free_llist); c->free_cnt++; - dec_active(c, flags); + dec_active(c, &flags); } /* Mostly runs from irq_work except __init phase. */ @@ -344,7 +344,7 @@ static void free_bulk(struct bpf_mem_cache *c) cnt = --c->free_cnt; else cnt = 0; - dec_active(c, flags); + dec_active(c, &flags); if (llnode) enque_to_free(tgt, llnode); } while (cnt > (c->high_watermark + c->low_watermark) / 2); @@ -384,7 +384,7 @@ static void check_free_by_rcu(struct bpf_mem_cache *c) llist_for_each_safe(llnode, t, llist_del_all(&c->free_llist_extra_rcu)) if (__llist_add(llnode, &c->free_by_rcu)) c->free_by_rcu_tail = llnode; - dec_active(c, flags); + dec_active(c, &flags); } if (llist_empty(&c->free_by_rcu)) @@ -408,7 +408,7 @@ static void check_free_by_rcu(struct bpf_mem_cache *c) inc_active(c, &flags); WRITE_ONCE(c->waiting_for_gp.first, __llist_del_all(&c->free_by_rcu)); c->waiting_for_gp_tail = c->free_by_rcu_tail; - dec_active(c, flags); + dec_active(c, &flags); if (unlikely(READ_ONCE(c->draining))) { free_all(llist_del_all(&c->waiting_for_gp), !!c->percpu_size);