Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1647787iob; Thu, 19 May 2022 11:03:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3ep53/sQanjrfnSzHp0f8I8mI/UMJdr67glpvc6vbgm6xT5mn14k8H8B/vnkxfc7JQW2B X-Received: by 2002:a05:6402:1941:b0:413:2555:53e3 with SMTP id f1-20020a056402194100b00413255553e3mr6803473edz.164.1652983402114; Thu, 19 May 2022 11:03:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652983402; cv=none; d=google.com; s=arc-20160816; b=GeDW/QQcmMq9yu0eWWIWqtsp49Ww8UCGltwn/QwmOoJKIm2ekUzYlve5F0XYRqeOI9 mn6n85PpKtDCbiS1QKXbMMZzb9aDvJvwQTpBPMgzEm/DoKdnvmpaNRVKZgRDireOp2el IuSTs+HZSIqRK+0vMTFh6T4dLoz+dU+QwjFS7BYabCX8MIYTiNV+9HCw+QnyI3oH9OJ4 lCDq/3XZNhSkLI3DlwXUnQzfpx9gXa304JRLeSg6W5p4dbLqDknfsvsr1DCyfaAMXxzW AzlHtxXeuzPAnrtZCltu3+G58pJzRmNDGHijnci+gAF1fXONzKpDkeyPxmMzyqrEAsKL 1Www== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=fwaHgMGpyKxUjfrphlTtFfZFCA36vjc6kx8Yyplbjpk=; b=traJJ43oTfP7R/pnBLD0innr53Adt+OtoD257x3qO9l0i8DVSiAPX4P+Dw+dOVEl4m 7f8rdVMHuTV9m2oC/linvogJbL+blvoX2petKpndhqC6/w9oo15XzWtgAxzDFEbdMIE+ tNB0L9YG6VD1DqcybBnKoZkUMdF7iAtW4OjP0VdH+ERTyczqgM+1+KC0bU73rFQEVxBr YQ+qKp6XRuSZTeFrAN18ueDtMXGuvTQRZgw44R0MvcCf5E8vB8QY1ZxN/yCYPq7ggMZB rfQ7us+sit7RCwwb1ExbUyDO76dDAQDCCdzYj6A3TxGqInxoI7Ow4F7EpD0B3q50Y2SB jXkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=RYDCMXNp; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 24-20020a170906311800b006ec0aaff9cfsi5437585ejx.932.2022.05.19.11.02.49; Thu, 19 May 2022 11:03:22 -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=@infradead.org header.s=desiato.20200630 header.b=RYDCMXNp; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233562AbiESLQw (ORCPT + 99 others); Thu, 19 May 2022 07:16:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230008AbiESLQt (ORCPT ); Thu, 19 May 2022 07:16:49 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 032E552B37 for ; Thu, 19 May 2022 04:16:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=fwaHgMGpyKxUjfrphlTtFfZFCA36vjc6kx8Yyplbjpk=; b=RYDCMXNpjIlJnbpR6ajxa55hj9 BLxgLS+TW0KAVxKV4JaOWIwnjIdnLelGBL0amhS5m4Bj6RzVX88ZYv4ZnTYLQU2D2AXrBEXNbTXmE 5UPxBttFRv++AX6J1pfNJpVRGkFI41IgVezP8l3BQ65qAPDRGY3AZChhhVCtt/FZYt8FN/YmI5mcE 9UktynESLujWWXkmY4qq4fRUo+xa5bkKIefFafuZGBa7CHAxFJpl6jkuGN6nW7Rgs/GQ7d+UBzTFE aSXTOimSk22J98oidhup2X9gksk6VIYTjwwM0wx5BlnZzA93g8H6XrtmdIIBJwIA09gPKh0FyI3/P YS2nOp9Q==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=worktop.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1nre8Y-0020tX-GR; Thu, 19 May 2022 11:16:11 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id CBE9F980E0B; Thu, 19 May 2022 13:16:08 +0200 (CEST) Date: Thu, 19 May 2022 13:16:08 +0200 From: Peter Zijlstra To: Christophe de Dinechin Cc: Christophe de Dinechin , trivial@kernel.org, Ben Segall , "Michael S. Tsirkin" , Andrew Morton , Steven Rostedt , Ingo Molnar , Mel Gorman , Dietmar Eggemann , Vincent Guittot , Paolo Bonzini , Daniel Bristot de Oliveira , Jason Wang , virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Zhen Lei , Juri Lelli Subject: Re: [PATCH 1/3] sched/headers: Fix compilation error with GCC 12 Message-ID: <20220519111608.GF2578@worktop.programming.kicks-ass.net> References: <20220414150855.2407137-1-dinechin@redhat.com> <20220414150855.2407137-2-dinechin@redhat.com> <5AEAD35F-10E2-41A3-8269-E8358160D33B@dinechin.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <5AEAD35F-10E2-41A3-8269-E8358160D33B@dinechin.org> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,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, Apr 25, 2022 at 04:07:43PM +0200, Christophe de Dinechin wrote: > >> extern struct sched_class __begin_sched_classes[]; > >> extern struct sched_class __end_sched_classes[]; > >> > >> -#define sched_class_highest (__end_sched_classes - 1) > >> +/* > >> + * sched_class_highests is really __end_sched_classes - 1, but written in a way > >> + * that makes it clear that it is within __begin_sched_classes[] and not outside > >> + * of __end_sched_classes[]. > >> + */ > >> +#define sched_class_highest (__begin_sched_classes + \ > >> + (__end_sched_classes - __begin_sched_classes - 1)) > >> #define sched_class_lowest (__begin_sched_classes - 1) > >> > >> +/* The + 1 below places the pointers within the range of their array */ > >> #define for_class_range(class, _from, _to) \ > >> - for (class = (_from); class != (_to); class--) > >> + for (class = (_from); class + 1 != (_to) + 1; class--) > > > > Urgh, so now we get less readable code, > > You consider the original code readable? Yeah, because: x + y - x - 1 == y - 1, so wth would you want to write it with the x on. That's just silly. > It actually relies on a > precise layout that is not enforced in this code, not even documented, > but actually enforced by the linker script. It has a comment pointing at the linker script, and we have: /* Make sure the linker didn't screw up */ BUG_ON(&idle_sched_class + 1 != &fair_sched_class || &fair_sched_class + 1 != &rt_sched_class || &rt_sched_class + 1 != &dl_sched_class); #ifdef CONFIG_SMP BUG_ON(&dl_sched_class + 1 != &stop_sched_class); #endif On boot to verify the layout is as we expect. > > just because GCC is being > > stupid? > > I think that GCC is actually remarkably smart there. It tells you > that you are building pointers to A[] from B[], when there is a legit > way to say that the pointer is in A[] (which is what my patch does) We build with -fno-strict-aliasing, it must not assume anything like that, unless restrict is used. In this case, they're not two objects but the same one. Just because linker script can't really get us a sensible array definition. > > What's wrong with negative array indexes? memory is memory, stuff works. > > What’s wrong is that the compiler cannot prove theorems anymore. > These theorems are used to optimise code. When you write -1[B], the > compiler cannot optimise based on knowing this refers to A[B-A-1]. > > While at first, you might think that disabling a warning is a win, > what comes next is the compiler optimizing in a way you did not > anticipate, mysterious bugs showing up, and/or having to turn off some > potentially useful optimisation. We're usually fairly quick to call a compiler broken if doesn't do what we want it to. Dodgy optimizations go out the window real fast.