Received: by 2002:a19:f614:0:0:0:0:0 with SMTP id x20csp43123lfe; Fri, 15 Apr 2022 18:33:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRG6oVc/gDVMQvrNr1U+BRucReTr6KPZUq/q3smxphthbRtHXtMpOV4XxISiH7dOgNJ6WW X-Received: by 2002:a17:90b:4b84:b0:1cb:6cf5:d2ff with SMTP id lr4-20020a17090b4b8400b001cb6cf5d2ffmr1645845pjb.41.1650072811372; Fri, 15 Apr 2022 18:33:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650072811; cv=none; d=google.com; s=arc-20160816; b=QRynftJRsL47BJKJpzEukw9udHy39ZaA6XMHI/qVZI3jVTnmtrFWd2VvZn2kt+WKZG N67uazMCWnFK6grbT3CBcVomeOSpKYBG77krYdBn/QXGdfC+lteOguNnmvnyIqKJXaTs UZQoRn/7x0GGpDa50i7sB/PGsc6cvGgaayJOaD1e5AwM15YgMp8KRkz3rS6rSPMx01jX r6LWoHLzibnluogr7FpJ1I7wIpSXVQ/H4KbQbt+vAWmbC5j0Zy7v//ZJ9DEPRoxI6xPi A+S2RTgR3MIdT1PRUaxmYROJBJwgJzKA5BgHlhpv6te7wVNsQ/DUpfWvPHJcG0l5/NzT AmEw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bOuiYKp/29n8d96xb4w4281yD5PlXvWzIE+ZYrKmO3I=; b=TIZo91Dz3fqAcCnjOPAQJ0g4Gvw8i+bR9uvLysCIPdBUIQdgPD5nAZDQ+mOPwMT8Y5 cGf56khaFQxZse14ysUDtoSuybphVpXdYjSQ5B//VY1r7DZNPukGBynwYx9NUtHTLEpe IDpZ98kE8MY1oYta7qz58EnEuWeIYVx0fToSyp0MGiPFczwry0wTsdPF4PoI4vshijA0 Rc6jdAlUD2Ww1wZockgGfaNJcUPdrQOfu/5B01JUik1TI3p4ZaZnN+xPFedk/PzTef2R e8/LbZEwR43zZcEOV0Qe6g1oeu+qEx0Dcx3k4QDVv/LeS4YzOftGmDLf/rKthX02tO25 UhEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MdBroEDn; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id m11-20020a170902f64b00b00153b2d1649dsi2739445plg.165.2022.04.15.18.33.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 18:33:31 -0700 (PDT) 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=@redhat.com header.s=mimecast20190719 header.b=MdBroEDn; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5E2AF151D3A; Fri, 15 Apr 2022 18:00:22 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359439AbiDNPpJ (ORCPT + 99 others); Thu, 14 Apr 2022 11:45:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357092AbiDNPZi (ORCPT ); Thu, 14 Apr 2022 11:25:38 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 187B0F47F4 for ; Thu, 14 Apr 2022 08:09:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649948945; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bOuiYKp/29n8d96xb4w4281yD5PlXvWzIE+ZYrKmO3I=; b=MdBroEDnkmpfKW8/HeD49LRY9u8jrRxfGV4cCnfI4FN1s2wY1RMV5T7cyhKsBiFKobYmd1 NtG634OgCoDdlTUTzM2PF7A630FUBT41+387ND2FSBoRwcsV1M8tyYU9iA7rgi4oZ8fKzR sbPocqTQMurvycYIcYcVnHkO4RGLusw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-653-ts_GjJCzNpedi50pTfN2Wg-1; Thu, 14 Apr 2022 11:09:02 -0400 X-MC-Unique: ts_GjJCzNpedi50pTfN2Wg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9D451800882; Thu, 14 Apr 2022 15:09:01 +0000 (UTC) Received: from turbo.dinechin (unknown [10.39.192.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 10AB4C07F51; Thu, 14 Apr 2022 15:08:58 +0000 (UTC) From: Christophe de Dinechin To: trivial@kernel.org Cc: 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 , Christophe de Dinechin , Juri Lelli , Peter Zijlstra Subject: [PATCH 1/3] sched/headers: Fix compilation error with GCC 12 Date: Thu, 14 Apr 2022 17:08:53 +0200 Message-Id: <20220414150855.2407137-2-dinechin@redhat.com> In-Reply-To: <20220414150855.2407137-1-dinechin@redhat.com> References: <20220414150855.2407137-1-dinechin@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, 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 With gcc version 12.0.1 20220401 (Red Hat 12.0.1-0) (GCC), the following errors are reported in sched.h when building after `make defconfig`: | CC kernel/sched/core.o | In file included from kernel/sched/core.c:81: | kernel/sched/core.c: In function ‘set_rq_online.part.0’: | kernel/sched/sched.h:2197:52: error: array subscript -1 is outside | array bounds of ‘struct sched_class[44343134792571037]’ | [-Werror=array-bounds] | 2197 | #define sched_class_lowest (__begin_sched_classes - 1) | | ^ | kernel/sched/sched.h:2200:41: note: in definition of macro | ‘for_class_range’ | 2200 | for (class = (_from); class != (_to); class--) | | ^~~ | kernel/sched/sched.h:2203:53: note: in expansion of macro | ‘sched_class_lowest’ | 2203 |for_class_range(class, sched_class_highest, sched_class_lowest) | | ^~~~~~~~~~~~~~~~~~ | kernel/sched/core.c:9115:17: note: in expansion of macro | ‘for_each_class’ | 9115 | for_each_class(class) { | | ^~~~~~~~~~~~~~ | kernel/sched/sched.h:2193:27: note: at offset -208 into object | ‘__begin_sched_classes’ of size [0, 9223372036854775807] | 2193 | extern struct sched_class __begin_sched_classes[]; | | ^~~~~~~~~~~~~~~~~~~~~ | kernel/sched/core.c: In function ‘set_rq_offline.part.0’: | kernel/sched/sched.h:2197:52: error: array subscript -1 is outside | array bounds of ‘struct sched_class[44343134792571037]’ | [-Werror=array-bounds] | 2197 | #define sched_class_lowest (__begin_sched_classes - 1) | | ^ | kernel/sched/sched.h:2200:41: note: in definition of macro | ‘for_class_range’ | 2200 | for (class = (_from); class != (_to); class--) | | ^~~ | kernel/sched/sched.h:2203:53: note: in expansion of macro | ‘sched_class_lowest’ | 2203 |for_class_range(class, sched_class_highest, sched_class_lowest) | | ^~~~~~~~~~~~~~~~~~ | kernel/sched/core.c:9127:17: note: in expansion of macro | ‘for_each_class’ | 9127 | for_each_class(class) { | | ^~~~~~~~~~~~~~ | kernel/sched/sched.h:2193:27: note: at offset -208 into object | ‘__begin_sched_classes’ of size [0, 9223372036854775807] | 2193 | extern struct sched_class __begin_sched_classes[]; | | ^~~~~~~~~~~~~~~~~~~~~ | In function ‘__pick_next_task’, | inlined from ‘pick_next_task’ at kernel/sched/core.c:6204:9, | inlined from ‘__schedule’ at kernel/sched/core.c:6352:9: | kernel/sched/sched.h:2197:52: error: array subscript -1 is outside | array bounds of ‘struct sched_class[44343134792571037]’ | [-Werror=array-bounds] | 2197 | #define sched_class_lowest (__begin_sched_classes - 1) | | ^ | kernel/sched/sched.h:2200:41: note: in definition of macro | ‘for_class_range’ | 2200 | for (class = (_from); class != (_to); class--) | | ^~~ | kernel/sched/sched.h:2203:53: note: in expansion of macro | ‘sched_class_lowest’ | 2203 |for_class_range(class, sched_class_highest, sched_class_lowest) | | ^~~~~~~~~~~~~~~~~~ | kernel/sched/core.c:5711:9: note: in expansion of macro | ‘for_each_class’ | 5711 | for_each_class(class) { | | ^~~~~~~~~~~~~~ | kernel/sched/sched.h: In function ‘__schedule’: | kernel/sched/sched.h:2193:27: note: at offset -208 into object | ‘__begin_sched_classes’ of size [0, 9223372036854775807] | 2193 | extern struct sched_class __begin_sched_classes[]; | | ^~~~~~~~~~~~~~~~~~~~~ | cc1: all warnings being treated as errors Rewrite the definitions of sched_class_highest and for_class_range to avoid this error as follows: 1/ The sched_class_highest is rewritten to be relative to __begin_sched_classes, so that GCC sees it as being part of the __begin_sched_classes array and not a distinct __end_sched_classes array. 2/ The for_class_range macro is modified to replace the comparison with an out-of-bound pointer __begin_sched_classes - 1 with an equivalent, but in-bounds comparison. In that specific case, I believe that the GCC analysis is correct and potentially valuable for other arrays, so it makes sense to keep it enabled. Signed-off-by: Christophe de Dinechin Signed-off-by: Christophe de Dinechin --- kernel/sched/sched.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 8dccb34eb190..6350fbc7418d 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -2193,11 +2193,18 @@ const struct sched_class name##_sched_class \ 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--) #define for_each_class(class) \ for_class_range(class, sched_class_highest, sched_class_lowest) -- 2.35.1