Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp326230pxm; Wed, 2 Mar 2022 16:27:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJz1ZdKfpB9M0924U/gtk8s7K2E0ahIFzUlvv0CC6yrGEQ/mqkryUd/JpiqYidatvckrYoIt X-Received: by 2002:a17:90a:7883:b0:1bd:2372:c990 with SMTP id x3-20020a17090a788300b001bd2372c990mr2422825pjk.55.1646267236304; Wed, 02 Mar 2022 16:27:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646267236; cv=none; d=google.com; s=arc-20160816; b=uOuSvLB+2EJHo60LDQkETbxC3iUSPV/dLjWXB9WHRQ+3EtbrnwrPyRkta2cXB/UryW vENSvZTsWb2o/GkqZC1fF8ykzHnQE7UkIqLvu2lsR7KtBaLwcU39KQrJFdzKrRgMaEAA pwSiP01SghYSB4sG2U1ToJpCeL7yZM6nVA27o6o3OOaQgnfhBLNQFxKZMpbrRT9qCi1o lEspx9DXDsaF3jhdTBPzagHJnnWnTT2i7oFbdeoIrcy8m+fVBFHUpcLsTCfuvZrZsJXC wUTKEFb4EawwTHbMXK4+7NtR0sUWR5PIIGEEBbx3dIGsGlMLoBu2ArqD00lKE5m2JMuR dq6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=aB+E32SV8Widsy5hZm4SDjs3y2zV+hJliWd8+r+tQKc=; b=q7My7V26/UK18MW6JmTjmHjBH6p1W16tY0tqYh2yO7juh7I80YCM6xTe5zjgIID+yE gjYZXAnAqO89WZKKeMzscuruEBWm5eMfswHWJqCATYTEQje7x7xMLkoIPyjvz6SIqXxn 2KvwBWQCvK0TLx2s+mIul6zVs2FGfBWopiw/T//4Nbkva4iRDaHv3D8VYNNWe+7nnv59 7t26Y0jQEA66TicauP97LFApjEnLFd3HHYX0jIWRy6OzQH9fa6vE+AdBvMPbfrWmty0w NtW6267ZFeTmL3zYcMze56Kx63oF3rAh1WjmX1Ra3Oe2HA9qR+uAya7NG2qEbqcrL/3p kD2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="WlHj8/Dc"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id t10-20020a056a0021ca00b004f63bca3276si587386pfj.352.2022.03.02.16.27.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 16:27:16 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="WlHj8/Dc"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 465B215F34E; Wed, 2 Mar 2022 15:38:55 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244699AbiCBSo7 (ORCPT + 99 others); Wed, 2 Mar 2022 13:44:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244691AbiCBSox (ORCPT ); Wed, 2 Mar 2022 13:44:53 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55C8FD04B4 for ; Wed, 2 Mar 2022 10:44:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=aB+E32SV8Widsy5hZm4SDjs3y2zV+hJliWd8+r+tQKc=; b=WlHj8/DcuQg8olNKD9pOlLvOcP EGN3ab2VLYSQocFmXfUHF72DLsPPNYkZ3b/ZN3nKLOPC90xJyqGR8QPdJbLlQ0rsvUnhBlcLkXqWL X8I5/cbUsC0wbrXpGGHo3atu0s/SxAdYjy7gYt4racnUp+KgGoqMXS6BPDq8lrMGQNXGX3y/qe28F 4x4ogm/OLsxX/+Ls5WHetLay8R0eVsSuXbO0k5Az3UD+CJ7xrcdEzCKuqBRjxse19yt9891w+RX/1 KM3jVC6UzpwCE78hgfeYP8Hv0FAHmd+0OlqcoWgrqTShXN+Vg1rsqbBqOKcfdDdSw7t5+qK/eGIfn wetp6sIQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1nPTx7-00AtAW-3b; Wed, 02 Mar 2022 18:43:57 +0000 Date: Wed, 2 Mar 2022 18:43:57 +0000 From: Matthew Wilcox To: Kees Cook Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Linus Torvalds , linux-kernel@vger.kernel.org Subject: Re: [PATCH 00/19] Enable -Wshadow=local for kernel/sched Message-ID: References: <20220302043451.2441320-1-willy@infradead.org> <202203021030.EEEF58C2@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202203021030.EEEF58C2@keescook> X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,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 On Wed, Mar 02, 2022 at 10:32:23AM -0800, Kees Cook wrote: > On Wed, Mar 02, 2022 at 04:34:32AM +0000, Matthew Wilcox (Oracle) wrote: > > I thought I'd choose one of the more core parts of the kernel to > > demonstrate the value of -Wshadow. It found two places where there are > > shadowed variables that are at least confusing. For all I know they're > > buggy and my resolution of these warnings is wrong. > > > > The first 12 patches just untangle the unclean uses of __ret in wait.h > > & friends. Then 4 patches to fix problems in headers that are noticed > > by kernel/sched. Two patches fix the two places in kernel/sched/ > > with shadowed variables and the final patch adds -Wshadow=local to > > the Makefile. > > You are my hero. I was pulling my hair out trying to figure out how > to deal with this a few months ago, and the use of UNIQUE_ID was the > key. Yay! > > > I'm quite certain this patch series isn't going in as-is. But maybe > > it'll inspire some patches that can go in. > > I think it's pretty darn close. One thing that can be done to test the > results for the first 12 patches is to do a binary comparison -- these > changes _should_ have no impact on the final machine code. (It'll > totally change the debug sections, etc, but the machine code should be > the same.) Peter pointed out that I got confused about which __ret was being referred to: +#define __wait_event_freezable_timeout(wq_head, condition, timeout, __ret) \ + ___wait_event(wq_head, ___wait_cond_timeout(condition, __ret), \ + TASK_INTERRUPTIBLE, 0, timeout, \ + __ret = freezable_schedule_timeout(__ret), UNIQUE_ID) so now that internal variable is UNIQUE_ID, whatever that is but the condition argument was supposed to look at that but you explicitly pulled that out ie "__ret = freezable_schedule_timeout(__ret)" is supposed to refer to the inner __ret, not the outer __ret. Which was the opposite of what I thought was supposed to happen. We can fix this, of course. Something like ... #define ___wait_event_freezable_timeout(wq_head, condition, timeout, ret) \ ___wait_event(wq_head, ___wait_cond_timeout(condition, ret), \ TASK_INTERRUPTIBLE, 0, timeout, \ ret = freezable_schedule_timeout(ret), ret) #define __wait_event_freezable_timeout(wq_head, condition, timeout) \ ___wait_event_freezable_timeout(wq_head, condition, timeout, UNIQUE_ID) ... and now all the 'ret' refer to the thing that they look like they're referring to.