From nobody Mon May 11 04:12:41 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9FFEC47084 for ; Thu, 14 Apr 2022 15:45:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359447AbiDNPpQ (ORCPT ); Thu, 14 Apr 2022 11:45:16 -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: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 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 =E2=80=98set_rq_online.part.0=E2=80=99: | kernel/sched/sched.h:2197:52: error: array subscript -1 is outside | array bounds of =E2=80=98struct sched_class[44343134792571037]=E2=80=99 | [-Werror=3Darray-bounds] | 2197 | #define sched_class_lowest (__begin_sched_classes - 1) | | ^ | kernel/sched/sched.h:2200:41: note: in definition of macro | =E2=80=98for_class_range=E2=80=99 | 2200 | for (class =3D (_from); class !=3D (_to); class--) | | ^~~ | kernel/sched/sched.h:2203:53: note: in expansion of macro | =E2=80=98sched_class_lowest=E2=80=99 | 2203 |for_class_range(class, sched_class_highest, sched_class_lowest) | | ^~~~~~~~~~~~~~~~~~ | kernel/sched/core.c:9115:17: note: in expansion of macro | =E2=80=98for_each_class=E2=80=99 | 9115 | for_each_class(class) { | | ^~~~~~~~~~~~~~ | kernel/sched/sched.h:2193:27: note: at offset -208 into object | =E2=80=98__begin_sched_classes=E2=80=99 of size [0, 9223372036854775807] | 2193 | extern struct sched_class __begin_sched_classes[]; | | ^~~~~~~~~~~~~~~~~~~~~ | kernel/sched/core.c: In function =E2=80=98set_rq_offline.part.0=E2=80=99: | kernel/sched/sched.h:2197:52: error: array subscript -1 is outside | array bounds of =E2=80=98struct sched_class[44343134792571037]=E2=80=99 | [-Werror=3Darray-bounds] | 2197 | #define sched_class_lowest (__begin_sched_classes - 1) | | ^ | kernel/sched/sched.h:2200:41: note: in definition of macro | =E2=80=98for_class_range=E2=80=99 | 2200 | for (class =3D (_from); class !=3D (_to); class--) | | ^~~ | kernel/sched/sched.h:2203:53: note: in expansion of macro | =E2=80=98sched_class_lowest=E2=80=99 | 2203 |for_class_range(class, sched_class_highest, sched_class_lowest) | | ^~~~~~~~~~~~~~~~~~ | kernel/sched/core.c:9127:17: note: in expansion of macro | =E2=80=98for_each_class=E2=80=99 | 9127 | for_each_class(class) { | | ^~~~~~~~~~~~~~ | kernel/sched/sched.h:2193:27: note: at offset -208 into object | =E2=80=98__begin_sched_classes=E2=80=99 of size [0, 9223372036854775807] | 2193 | extern struct sched_class __begin_sched_classes[]; | | ^~~~~~~~~~~~~~~~~~~~~ | In function =E2=80=98__pick_next_task=E2=80=99, | inlined from =E2=80=98pick_next_task=E2=80=99 at kernel/sched/core.c:= 6204:9, | inlined from =E2=80=98__schedule=E2=80=99 at kernel/sched/core.c:6352= :9: | kernel/sched/sched.h:2197:52: error: array subscript -1 is outside | array bounds of =E2=80=98struct sched_class[44343134792571037]=E2=80=99 | [-Werror=3Darray-bounds] | 2197 | #define sched_class_lowest (__begin_sched_classes - 1) | | ^ | kernel/sched/sched.h:2200:41: note: in definition of macro | =E2=80=98for_class_range=E2=80=99 | 2200 | for (class =3D (_from); class !=3D (_to); class--) | | ^~~ | kernel/sched/sched.h:2203:53: note: in expansion of macro | =E2=80=98sched_class_lowest=E2=80=99 | 2203 |for_class_range(class, sched_class_highest, sched_class_lowest) | | ^~~~~~~~~~~~~~~~~~ | kernel/sched/core.c:5711:9: note: in expansion of macro | =E2=80=98for_each_class=E2=80=99 | 5711 | for_each_class(class) { | | ^~~~~~~~~~~~~~ | kernel/sched/sched.h: In function =E2=80=98__schedule=E2=80=99: | kernel/sched/sched.h:2193:27: note: at offset -208 into object | =E2=80=98__begin_sched_classes=E2=80=99 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[]; =20 -#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 o= utside + * 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) =20 +/* The + 1 below places the pointers within the range of their array */ #define for_class_range(class, _from, _to) \ - for (class =3D (_from); class !=3D (_to); class--) + for (class =3D (_from); class + 1 !=3D (_to) + 1; class--) =20 #define for_each_class(class) \ for_class_range(class, sched_class_highest, sched_class_lowest) --=20 2.35.1 From nobody Mon May 11 04:12:41 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2726EC4321E for ; Thu, 14 Apr 2022 15:45:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359461AbiDNPpY (ORCPT ); Thu, 14 Apr 2022 11:45:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245359AbiDNP0C (ORCPT ); Thu, 14 Apr 2022 11:26:02 -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 BD323F55C3 for ; Thu, 14 Apr 2022 08:09:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649948947; 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=xO4MPKDVg7yjY/S4cY28pZcVFGEmRz0kvVd69IjqQVk=; b=VnnOUcKF7XlG4I1F1nl1qKW2t52fuBc4mg5k16o+PcSbuWheFGcMzA30cUR9T5PIbWygvS /zK42tuJUuUOg07iyiqlbtQg4eQFINu56fyP6NbzS8BrG/JdhCWzeC6LZRiHp2/UXDDYIj I0N+V06nN3pOc8xnLheb6KWMr6yQmFs= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-669-qPItWNDPNS6znkLVWjh0hQ-1; Thu, 14 Apr 2022 11:09:05 -0400 X-MC-Unique: qPItWNDPNS6znkLVWjh0hQ-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 7B4AB296A619; Thu, 14 Apr 2022 15:09:04 +0000 (UTC) Received: from turbo.dinechin (unknown [10.39.192.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD40EC44CCA; Thu, 14 Apr 2022 15:09:01 +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 2/3] nodemask.h: Fix compilation error with GCC12 Date: Thu, 14 Apr 2022 17:08:54 +0200 Message-Id: <20220414150855.2407137-3-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: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 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), building with defconfig results in the following compilation error: | CC mm/swapfile.o | mm/swapfile.c: In function =E2=80=98setup_swap_info=E2=80=99: | mm/swapfile.c:2291:47: error: array subscript -1 is below array bounds | of =E2=80=98struct plist_node[]=E2=80=99 [-Werror=3Darray-bounds] | 2291 | p->avail_lists[i].prio =3D 1; | | ~~~~~~~~~~~~~~^~~ | In file included from mm/swapfile.c:16: | ./include/linux/swap.h:292:27: note: while referencing =E2=80=98avail_lis= ts=E2=80=99 | 292 | struct plist_node avail_lists[]; /* | | ^~~~~~~~~~~ This is due to the compiler detecting that the mask in node_states[__state] could theoretically be zero, which would lead to first_node() returning -1 through find_first_bit. I believe that the warning/error is legitimate. I first tried adding a test to check that the node mask is not emtpy, since a similar test exists in the case where MAX_NUMNODES =3D=3D 1. However, adding the if statement causes other warnings to appear in for_each_cpu_node_but, because it introduces a dangling else ambiguity. And unfortunately, GCC is not smart enough to detect that the added test makes the case where (node) =3D=3D -1 impossible, so it still complains with the same message. This is why I settled on replacing that with a harmless, but relatively useless (node) >=3D 0 test. Based on the warning for the dangling else, I also decided to fix the case where MAX_NUMNODES =3D=3D 1 by moving the condition inside the for loop. It will still only be tested once. This ensures that the meaning of an else following for_each_node_mask or derivatives would not silently have a different meaning depending on the configuration. Signed-off-by: Christophe de Dinechin Signed-off-by: Christophe de Dinechin --- include/linux/nodemask.h | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h index 567c3ddba2c4..c6199dbe2591 100644 --- a/include/linux/nodemask.h +++ b/include/linux/nodemask.h @@ -375,14 +375,13 @@ static inline void __nodes_fold(nodemask_t *dstp, con= st nodemask_t *origp, } =20 #if MAX_NUMNODES > 1 -#define for_each_node_mask(node, mask) \ - for ((node) =3D first_node(mask); \ - (node) < MAX_NUMNODES; \ - (node) =3D next_node((node), (mask))) +#define for_each_node_mask(node, mask) \ + for ((node) =3D first_node(mask); \ + (node >=3D 0) && (node) < MAX_NUMNODES; \ + (node) =3D next_node((node), (mask))) #else /* MAX_NUMNODES =3D=3D 1 */ -#define for_each_node_mask(node, mask) \ - if (!nodes_empty(mask)) \ - for ((node) =3D 0; (node) < 1; (node)++) +#define for_each_node_mask(node, mask) \ + for ((node) =3D 0; (node) < 1 && !nodes_empty(mask); (node)++) #endif /* MAX_NUMNODES */ =20 /* --=20 2.35.1 From nobody Mon May 11 04:12:41 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40AE3C38A04 for ; Thu, 14 Apr 2022 15:45:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359497AbiDNPpb (ORCPT ); Thu, 14 Apr 2022 11:45:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344538AbiDNP0G (ORCPT ); Thu, 14 Apr 2022 11:26:06 -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 39E43F55E0 for ; Thu, 14 Apr 2022 08:09:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649948951; 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=RtGebAgbSA9lYbaI57i+Rxn48XdJu/DmmwsLsGsA5XE=; b=h4E1dznwiky0aO7TPmmVB8bA51he+XsSUqEVkHoZJD9DvrJxaQsMtySW3Ea5rSgePuEexQ IKTx90BRBzUr6TaaIx3OT4RBsL04qrpeeuCGl4JGmKXzG7SSBDnC55r9i+Py5XvhUwDZix cDBVl18s4bk2AohzrlZMc64anZmKUBM= 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-433-C04J5NPBMgWBva7j5I52gA-1; Thu, 14 Apr 2022 11:09:08 -0400 X-MC-Unique: C04J5NPBMgWBva7j5I52gA-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 5B015185A7BA; Thu, 14 Apr 2022 15:09:07 +0000 (UTC) Received: from turbo.dinechin (unknown [10.39.192.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id B8B5FC07F51; Thu, 14 Apr 2022 15:09:04 +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 3/3] virtio-pci: Use cpumask_available to fix compilation error Date: Thu, 14 Apr 2022 17:08:55 +0200 Message-Id: <20220414150855.2407137-4-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: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With GCC 12 and defconfig, we get the following error: | CC drivers/virtio/virtio_pci_common.o | drivers/virtio/virtio_pci_common.c: In function =E2=80=98vp_del_vqs=E2=80= =99: | drivers/virtio/virtio_pci_common.c:257:29: error: the comparison will | always evaluate as =E2=80=98true=E2=80=99 for the pointer operand in | =E2=80=98vp_dev->msix_affinity_masks + (sizetype)((long unsigned int)i *= 8)=E2=80=99 | must not be NULL [-Werror=3Daddress] | 257 | if (vp_dev->msix_affinity_masks[i]) | | ^~~~~~ This happens in the case where CONFIG_CPUMASK_OFFSTACK is not defined, since we typedef cpumask_var_t as an array. The compiler is essentially complaining that an array pointer cannot be NULL. This is not a very important warning, but there is a function called cpumask_available that seems to be defined just for that case, so the fix is easy. Signed-off-by: Christophe de Dinechin Signed-off-by: Christophe de Dinechin --- drivers/virtio/virtio_pci_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci= _common.c index d724f676608b..5c44a2f13c93 100644 --- a/drivers/virtio/virtio_pci_common.c +++ b/drivers/virtio/virtio_pci_common.c @@ -254,7 +254,7 @@ void vp_del_vqs(struct virtio_device *vdev) =20 if (vp_dev->msix_affinity_masks) { for (i =3D 0; i < vp_dev->msix_vectors; i++) - if (vp_dev->msix_affinity_masks[i]) + if (cpumask_available(vp_dev->msix_affinity_masks[i])) free_cpumask_var(vp_dev->msix_affinity_masks[i]); } =20 --=20 2.35.1