Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DECLARE_WAIT_QUEUE_HEAD_ONSTACK triggers -Wuninitialized #499

Closed
nathanchance opened this issue May 29, 2019 · 8 comments
Closed

DECLARE_WAIT_QUEUE_HEAD_ONSTACK triggers -Wuninitialized #499

nathanchance opened this issue May 29, 2019 · 8 comments
Assignees
Labels
-Wuninitialized [BUG] llvm A bug that should be fixed in upstream LLVM [FIXED][LLVM] 9 This bug was fixed in LLVM 9.0 [Reported-by] KernelCI Reported-by: kernelci.org bot <bot@kernelci.org>

Comments

@nathanchance
Copy link
Member

mm/shmem.c:2719:35: warning: variable 'shmem_falloc_waitq' is uninitialized when used within its own initialization [-Wuninitialized]
                DECLARE_WAIT_QUEUE_HEAD_ONSTACK(shmem_falloc_waitq);
                                                ^~~~~~~~~~~~~~~~~~
include/linux/wait.h:74:63: note: expanded from macro 'DECLARE_WAIT_QUEUE_HEAD_ONSTACK'
        struct wait_queue_head name = __WAIT_QUEUE_HEAD_INIT_ONSTACK(name)
                               ~~~~                                  ^~~~
include/linux/wait.h:72:33: note: expanded from macro '__WAIT_QUEUE_HEAD_INIT_ONSTACK'
        ({ init_waitqueue_head(&name); name; })
                                       ^~~~
1 warning generated.

Arnd has a proposed fix that has not been sent out yet: https://lore.kernel.org/lkml/CAK8P3a20t1f6Fmjd7HcGVSXCxx9SP2q7_WpZyj16MgnJe8m8zQ@mail.gmail.com/

@nathanchance nathanchance added [BUG] linux A bug that should be fixed in the mainline kernel. [PATCH] Exists There is a patch that fixes this issue -Wuninitialized labels May 29, 2019
@nickdesaulniers
Copy link
Member

Multiple instances of this:

fs/proc/base.c:1876:35: warning: variable 'wq' is uninitialized when used within its own initialization [-Wuninitialized]
fs/proc/proc_sysctl.c:701:35: warning: variable 'wq' is uninitialized when used within its own initialization [-Wuninitialized]
fs/namei.c:1646:34: warning: variable 'wq' is uninitialized when used within its own initialization [-Wuninitialized]
fs/namei.c:3136:34: warning: variable 'wq' is uninitialized when used within its own initialization [-Wuninitialized]
fs/afs/dir_silly.c:205:34: warning: variable 'wq' is uninitialized when used within its own initialization [-Wuninitialized]
fs/cifs/readdir.c:83:34: warning: variable 'wq' is uninitialized when used within its own initialization [-Wuninitialized]
drivers/bluetooth/bluecard_cs.c:282:36: warning: variable 'wq' is uninitialized when used within its own initialization [-Wuninitialized]
fs/fuse/readdir.c:161:34: warning: variable 'wq' is uninitialized when used within its own initialization [-Wuninitialized]
fs/nfs/dir.c:451:34: warning: variable 'wq' is uninitialized when used within its own initialization [-Wuninitialized]
fs/nfs/dir.c:1573:34: warning: variable 'wq' is uninitialized when used within its own initialization [-Wuninitialized]net/nfc/hci/command.c:59:34: warning: variable 'ew_wq' is uninitialized when used within its own initialization [-Wuninitialized]
net/nfc/hci/llc_shdlc.c:687:34: warning: variable 'connect_wq' is uninitialized when used within its own initialization [-Wuninitialized]
...

Reported-by: kernelci.org bot bot@kernelci.org
arm64 linux-next

@nathanchance
Copy link
Member Author

@nathanchance nathanchance added [PATCH] Submitted A patch has been submitted for review and removed [PATCH] Exists There is a patch that fixes this issue labels Jul 3, 2019
@nathanchance nathanchance self-assigned this Jul 3, 2019
@nickdesaulniers nickdesaulniers assigned arndb and unassigned nathanchance Jul 9, 2019
@nathanchance
Copy link
Member Author

Andrew Morton pushed back a bit while still tentatively picking up the patch:

https://lore.kernel.org/lkml/20190711174949.dc74310efd1fd3c8bd4ea276@linux-foundation.org/

https://www.ozlabs.org/~akpm/mmotm/broken-out/waitqueue-fix-clang-wuninitialized-warnings.patch

creduce spits out:

struct a {
} __init_waitqueue_head(struct a *, int);
b(void) {
  struct a c = ({
    __init_waitqueue_head((&c), b);
    c;
  });
}

With the following interestingness script:

#!/bin/bash

grep -F "__init_waitqueue_head((" shmem.i || exit 1

gcc -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE -Werror=implicit-function-declaration -Werror=implicit-int -Wno-format-security -std=gnu89 -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mskip-rax-setup -mtune=generic -mno-red-zone -mcmodel=kernel -Wno-sign-compare -fno-asynchronous-unwind-tables -mindirect-branch=thunk-extern -mindirect-branch-register -fno-jump-tables -fno-delete-null-pointer-checks -Wno-frame-address -Wno-format-truncation -Wno-format-overflow -Wno-address-of-packed-member -O2 --param=allow-store-data-races=0 -Wframe-larger-than=2048 -fstack-protector-strong -Wno-unused-but-set-variable -Wno-unused-const-variable -fomit-frame-pointer -fno-var-tracking-assignments -Wdeclaration-after-statement -Wimplicit-fallthrough=3 -Wvla -Wno-pointer-sign -Wno-stringop-truncation -fno-strict-overflow -fno-merge-all-constants -fmerge-constants -fno-stack-check -fconserve-stack -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -fmacro-prefix-map=./= -Wno-packed-not-aligned -c -o shmem.o shmem.i || exit 1

/home/nathan/cbl/usr/bin/clang -Qunused-arguments -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE -Werror=implicit-function-declaration -Werror=implicit-int -Wno-format-security -std=gnu89 -no-integrated-as -Werror=unknown-warning-option -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -m64 -mno-80387 -mstack-alignment=8 -mtune=generic -mno-red-zone -mcmodel=kernel -Wno-sign-compare -fno-asynchronous-unwind-tables -mretpoline-external-thunk -fno-delete-null-pointer-checks -Wno-address-of-packed-member -O2 -Wframe-larger-than=2048 -fstack-protector-strong -Wno-format-invalid-specifier -Wno-gnu -Wno-tautological-compare -mno-global-merge -Wno-unused-const-variable -fomit-frame-pointer -ftrivial-auto-var-init=pattern -Wdeclaration-after-statement -Wvla -Wno-pointer-sign -fno-strict-overflow -fno-merge-all-constants -fno-stack-check -Werror=date-time -Werror=incompatible-pointer-types -Wno-initializer-overrides -Wno-format -Wno-sign-compare -Wno-format-zero-length -c -o shmem.o shmem.i |& grep -F "is uninitialized when used within its own initialization [-Wuninitialized]"

I cleaned it up as I don't think the second parameter of __init_waitqueue_head is entirely necessary: https://godbolt.org/z/l0Z9UA

@nathanchance nathanchance added [PATCH] Accepted A submitted patch has been accepted upstream and removed [PATCH] Submitted A patch has been submitted for review labels Jul 12, 2019
@nickdesaulniers nickdesaulniers added [BUG] llvm A bug that should be fixed in upstream LLVM and removed [BUG] linux A bug that should be fixed in the mainline kernel. labels Jul 12, 2019
@nickdesaulniers
Copy link
Member

nickdesaulniers commented Jul 12, 2019

https://llvm.org/pr42604 (just seeing your creduce case @nathanchance now, sorry. Looks like the same thing I wrote up in the BR).

@nathanchance
Copy link
Member Author

No worries, I think yours makes it clearer what is going on here :)

@nathanchance nathanchance removed the [PATCH] Accepted A submitted patch has been accepted upstream label Jul 13, 2019
@nickdesaulniers
Copy link
Member

WIP: https://reviews.llvm.org/D64678

@nickdesaulniers nickdesaulniers added the [PATCH] Submitted A patch has been submitted for review label Jul 18, 2019
@nickdesaulniers
Copy link
Member

@nickdesaulniers nickdesaulniers added [FIXED][LLVM] 10 This bug was fixed in LLVM 10.0 and removed [PATCH] Submitted A patch has been submitted for review labels Jul 26, 2019
@nickdesaulniers
Copy link
Member

The Clang-9 release manager Hans picked this up for clang-9: r367150

@nickdesaulniers nickdesaulniers added [FIXED][LLVM] 9 This bug was fixed in LLVM 9.0 and removed [FIXED][LLVM] 10 This bug was fixed in LLVM 10.0 labels Jul 26, 2019
@nickdesaulniers nickdesaulniers added the [Reported-by] KernelCI Reported-by: kernelci.org bot <bot@kernelci.org> label Mar 24, 2020
fengguang pushed a commit to 0day-ci/linux that referenced this issue Feb 16, 2021
-Wunintialized was disabled in commit c562746 ("drm/i915: Disable
-Wuninitialized") because there were two warnings that were false
positives. The first was due to DECLARE_WAIT_QUEUE_HEAD_ONSTACK, which
was fixed in LLVM 9.0.0. The second was in busywait_stop, which was
fixed in LLVM 10.0.0 (issue 415). The kernel's minimum version for LLVM
is 10.0.1 so this warning can be safely enabled, where it has already
caught a couple bugs.

Link: ClangBuiltLinux#220
Link: ClangBuiltLinux#415
Link: ClangBuiltLinux#499
Link: llvm/llvm-project@2e04039
Link: llvm/llvm-project@c667cdc
Fixes: c562746 ("drm/i915: Disable -Wuninitialized")
References: 2ea4a7b ("drm/i915/gt: Avoid uninitialized use of rpcurupei in frequency_show")
References: 2034c21 ("drm/i915/display: Ensure that ret is always initialized in icl_combo_phy_verify_state")
Reported-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
sys-oak pushed a commit to intel/linux-intel-lts that referenced this issue Mar 16, 2021
-Wunintialized was disabled in commit c562746 ("drm/i915: Disable
-Wuninitialized") because there were two warnings that were false
positives. The first was due to DECLARE_WAIT_QUEUE_HEAD_ONSTACK, which
was fixed in LLVM 9.0.0. The second was in busywait_stop, which was
fixed in LLVM 10.0.0 (issue 415). The kernel's minimum version for LLVM
is 10.0.1 so this warning can be safely enabled, where it has already
caught a couple bugs.

Link: ClangBuiltLinux/linux#220
Link: ClangBuiltLinux/linux#415
Link: ClangBuiltLinux/linux#499
Link: llvm/llvm-project@2e04039
Link: llvm/llvm-project@c667cdc
Fixes: c562746 ("drm/i915: Disable -Wuninitialized")
References: 2ea4a7b ("drm/i915/gt: Avoid uninitialized use of rpcurupei in frequency_show")
References: 2034c21 ("drm/i915/display: Ensure that ret is always initialized in icl_combo_phy_verify_state")
Reported-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Link: https://patchwork.freedesktop.org/patch/msgid/20210216212953.24458-1-nathan@kernel.org
(cherry picked from commit b242318)
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
-Wuninitialized [BUG] llvm A bug that should be fixed in upstream LLVM [FIXED][LLVM] 9 This bug was fixed in LLVM 9.0 [Reported-by] KernelCI Reported-by: kernelci.org bot <bot@kernelci.org>
Projects
None yet
Development

No branches or pull requests

4 participants