Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp3545744rwo; Mon, 24 Jul 2023 12:43:20 -0700 (PDT) X-Google-Smtp-Source: APBJJlGnbiy+sdQVCnDssBGJfuYWE6AA/luCH5dX53Em8R0+xSb+6UeiRy0spEcXlmXMpHicxszX X-Received: by 2002:a05:6a20:3d7:b0:122:8096:7012 with SMTP id 23-20020a056a2003d700b0012280967012mr8522257pzu.3.1690227799786; Mon, 24 Jul 2023 12:43:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690227799; cv=none; d=google.com; s=arc-20160816; b=xrDY+9PsQsvBbTk6v66VtBCZy71FtGrufsnrKrcf1DxFYfvksSop6k6X2G8gQK/mp3 7cO0DYlsiczV6DFh8+043nKXUgVcpe/eC86OsxyYJ3fEgOwRXx60BQwTCvnakjPgtpWA 918GXazg8ekByCGM5vK6sREPdhYgDWRGkOk2UUPI1F2qCZXMd1fZdj5r0rvA4bRCQRsz xS4/RWoTjai7ng47DqYxwAyQ9512l30HAk9/VX3darVQRTE1gRqzd1yenBYmpsTwM190 GMUzpybqbXpTfRxRTCmQ1G0Qg5Ft8flb0yvJVvlKDWzzRIatmQZWlxXe8A6hQXeRoCuX XDhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=lucQsWRSX3kyNqfS6Jdqh+QWBRhNPWGEWAKdO35kj3s=; fh=zaAJOxXYpPLVdli4zlSoQR+ZjEXd6TymFngsL9BnR5U=; b=QNF7TRBt4sUlS06epe92jr1F9rdIea8ynDldoHI9MuFXXpm5RGRyaF3fBfVSVuIYL2 6Y4FoXXBeZPJs9+lMynngzd/g4C2vD2Monxqo7JAkxPOhZB1adk1z5hViDmzkimHXfoF 9GdZDxYmFPQT2swWBIriNVt77scrlGDL2sUsR5LU0daDAckpFiLtpXSK2uS27bPPmeXL Ys2NZg9xtKy9ksnVVIj5I5YbzLkflsjaWj0C5EKXRDMjIC6BKBWGucKtkEZGu9iL//YS IOFL1pTeNIycMO74bVn2fnCQZiHsKNBOeYV736mnF6AM07W9PyOH27/fCWE826plmgCy /bPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=Oec2qNUX; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u11-20020a6540cb000000b005578c6a767esi9591303pgp.885.2023.07.24.12.43.06; Mon, 24 Jul 2023 12:43:19 -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=@gmail.com header.s=20221208 header.b=Oec2qNUX; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230292AbjGXTQC (ORCPT + 99 others); Mon, 24 Jul 2023 15:16:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229479AbjGXTQB (ORCPT ); Mon, 24 Jul 2023 15:16:01 -0400 Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2133594; Mon, 24 Jul 2023 12:16:00 -0700 (PDT) Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-2b702319893so68083991fa.3; Mon, 24 Jul 2023 12:16:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690226158; x=1690830958; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=lucQsWRSX3kyNqfS6Jdqh+QWBRhNPWGEWAKdO35kj3s=; b=Oec2qNUXaD7VMmc08stO00SOxRtFT1l9vmjA/5kamiYXlUckT/B2gMY6GqBRW8VVTU g1FhZtR7sLtxwqxnJ1UKBgRX/2uc3MjkdRHda6EWo+WvfoAI+MZtTKlfsvGF3dlH5sdM Sk1jAFCus6VW1kAY1OcjqFRMrfHe4ssQ1zoa64xUO9pN28K8D5utZoJ1Z7oEJrrdp1iZ VF42uNCT+aOeXtr7j9D2/srvTB865a8d8CLZmis/YGC5W8bKTMRqXr1V1qhJTc0bx3r0 8x9xnUB6dTZ2G/DSKyC2xPc8g3Bbu1owZtGBuVZFoPJURKKsNBUckionvxX07v8CKKZY u7tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690226158; x=1690830958; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lucQsWRSX3kyNqfS6Jdqh+QWBRhNPWGEWAKdO35kj3s=; b=A8BDWSA+tmW5r5M/fNjgflSJiwSshGQs/JXdKXq/cs0OERc7ODaVdKmoI4J5HTVs8X 7GZcI/goJ2vf3i2jN7yHWXynxEAJgfC6ukgTVnlsAKjC+YZ99Skftbp8w8f8V268hJvK r0DLFzUfDg8G9u49jIvze10tDXxf8JzTerdoeDwUiBfuDj2LE1b4HOTgUyFUvAhSBhQp LWXJd7+enBYIzs/i4+q9lKTs/j20Z3PBvNW3thR9XmanYO3BjOUSTnGr42tq+xmiSuo6 ECveZVrucOEwuL1RoCshaTeUSgMcp3O9BPtvt7HnbxRwCJd6hmvE1/AZgEtZq6QvaUqo 7rjA== X-Gm-Message-State: ABy/qLbWtV/UdsMrPyal2nCNZ7Bua1osNDDYxT6W/zqBoYo6sFKDOQOa k33M3r6j+1UxBXbb8G/q7+v1DnYN5ckfSgnx7HM= X-Received: by 2002:a2e:6a11:0:b0:2b9:4c17:7939 with SMTP id f17-20020a2e6a11000000b002b94c177939mr6515964ljc.12.1690226158102; Mon, 24 Jul 2023 12:15:58 -0700 (PDT) MIME-Version: 1.0 References: <20230722074753.568696-1-arnd@kernel.org> <679d8d63-ce92-4294-8620-e98c82365b2c@app.fastmail.com> <39444a4e-70da-4d17-a40a-b51e05236d23@app.fastmail.com> In-Reply-To: <39444a4e-70da-4d17-a40a-b51e05236d23@app.fastmail.com> From: Alexei Starovoitov Date: Mon, 24 Jul 2023 12:15:45 -0700 Message-ID: Subject: Re: [PATCH] bpf: force inc_active()/dec_active() to be inline functions To: Arnd Bergmann Cc: Arnd Bergmann , Yafang Shao , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Hou Tao , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Kumar Kartikeya Dwivedi , bpf , LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 Mon, Jul 24, 2023 at 11:30=E2=80=AFAM Arnd Bergmann wr= ote: > > On Mon, Jul 24, 2023, at 20:13, Arnd Bergmann wrote: > > >>> One difference between gcc and clang is that gcc tries to > >>> be smart about warnings by using information from inlining > >>> to produce better warnings, while clang never uses information > >>> across function boundaries for generated warnings, so it won't > >>> find this one, but also would ignore an unconditional use > >>> of the uninitialized variable. > >>> > >>> >> If we have to change the kernel, what about the change below? > >>> > > >>> > To workaround the compiler bug we can simply init flag=3D0 to silen= ce > >>> > the warn, but even that is silly. Passing flag=3D0 into irqrestore = is buggy. > >>> > >>> Maybe inc_active() could return the flags instead of modifying > >>> the stack variable? that would also result in slightly better > >>> code when it's not inlined. > >> > >> Which gcc are we talking about here that is so buggy? > > > > I think I only tried versions 8 through 13 for this one, but > > can check others as well. > > I have a minimized test case at https://godbolt.org/z/hK4ev17fv > that shows the problem happening with all versions of gcc > (4.1 through 14.0) if I force the dec_active() function to be > inline and force inc_active() to be non-inline. That's a bit of cheating, but I see your point now. How about we do: diff --git a/kernel/bpf/memalloc.c b/kernel/bpf/memalloc.c index 51d6389e5152..3fa0944cb975 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) !=3D 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); It's symmetrical and there is no 'flags =3D 0' ugliness.