Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2181254iof; Tue, 7 Jun 2022 22:23:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlhEjEGfTV91S6nn0CU2ed9x1LxRSSlS21+0dK8ZGc9ZvL87pmwQIX7x2RY7Riu92MwHEm X-Received: by 2002:a17:90b:350b:b0:1e8:46b9:5bc5 with SMTP id ls11-20020a17090b350b00b001e846b95bc5mr25357306pjb.100.1654665837083; Tue, 07 Jun 2022 22:23:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654665837; cv=none; d=google.com; s=arc-20160816; b=suCKIkbU2YVt/7e+fm7DAH/iyfLV760KOD7/5rY3MzqWR+HpLgWiRiJeCZXDZMgMPE ftb07w6ivmmtRI17SztxcmJlEsh4nnOZ6bdPAjy0hK5zlkt0HGc+tjK83acz+rKS+AaX vGgGVquQpl1c9NhFZThgu+0/F9Z802GPssKY2JcReQhfNk+Nw7MpsGUUWA7gkX1ZeZkr ue4b3bn/OdkCDTmNW9uuvKJp4uRV4x8ASy+9/NBnBpxHmc3fajo+kBxqUBpSI9TmiVlX GSVDqnklt6H3DsAcHVRriWiQoXIr0rHH6pVeaYeAXjFaXb46wd1QFM4Y2u+acXLnurfB yuOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=8PBLOfNNVcxe/BchOfdldd1aRlQCoiHtBdRm4jougLQ=; b=lA3Ctku0CbpezDYQRoDP6WSq1Ztdo58JKQs1exEooANHYjQaOSALyi12jTqOV4DDJy RWqF23yh/5Dd20iy3M/mdse1f0oCQKkNTvL5d/5xD8jDRuK5TxBDG99PoJRwG7zt7WU8 UNWyuCkmiv1xuU/iebmK+JmdlJ5ypDHCbBqMNOMGia8LAIZHw0L7Yu6Ku5081hdxmzMb dt7fjifXasKYkgDOZUPbNqhcmfFcoIVfE3981t7VYSBHwfYF54KhwucPEsEic/e8lhYk v4CWZFqdEFgVigB5PDpZHX4FpfFdJZ0VfNa2minOLeidaSuPg4EmVh4FgBnV4VS9ke4+ fIEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=W1DZDLCw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id ob1-20020a17090b390100b001e31028a53csi11275194pjb.185.2022.06.07.22.23.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:23:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=W1DZDLCw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 17BCD3A390D; Tue, 7 Jun 2022 21:50:43 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236109AbiFGCGV (ORCPT + 99 others); Mon, 6 Jun 2022 22:06:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235953AbiFGCFh (ORCPT ); Mon, 6 Jun 2022 22:05:37 -0400 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C92D4BC6D6 for ; Mon, 6 Jun 2022 19:05:28 -0700 (PDT) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4LHDG95Jvpz4xZ7; Tue, 7 Jun 2022 12:05:21 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ellerman.id.au; s=201909; t=1654567524; bh=8PBLOfNNVcxe/BchOfdldd1aRlQCoiHtBdRm4jougLQ=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=W1DZDLCw0u7bl+3KdOLO3E4JCzPchbpIy2zcqZPBay4042yh5i4ln0MRuWhSVJOz2 2NQIfrMEG6mCS3D7pkm1LGyYEetCH5E+BXMC2ZinYQisMrh760p1W9D2oby2EJ4svT rU2MA1wyPZgnSUgVia4gzfTVQ1Mvz7nSTVPJXwPWMq1llrJ1XXP05ANpImpq6wQ5yQ Lh0JyAAMcC8WaWw4phBmpH4xvWZ25nLntkYEKfN1zsar9homM2jZ6wFG5h8jX9rxwO PSniNMuQSbyQE4kTCn0rSFx3K9c5w9+f0tbWdUkjL2eAZpj+Xlu9yn1f8j9FkuFoGR 5Kr/n2q7FTVtA== From: Michael Ellerman To: Bagas Sanjaya , linuxppc-dev@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org, Benjamin Herrenschmidt , Paul Mackerras , Nicholas Piggin , Christophe Leroy , Anders Roxell , Arnd Bergmann , Yang Li Subject: Re: outside array bounds error on ppc64_defconfig, GCC 12.1.0 In-Reply-To: References: Date: Tue, 07 Jun 2022 12:05:18 +1000 Message-ID: <87mtepns81.fsf@mpe.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain 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 Bagas Sanjaya writes: > Hi, > > I'm trying to verify Drop ppc_inst_as_str() patch on [1] by performing > ppc64_defconfig build with powerpc64-unknown-linux-gnu-gcc (GCC 12.1.0). > The patch is applied on top of powerpc tree, next branch. Yeah I see it too. > I got outside array bounds error: > > CC arch/powerpc/kernel/dbell.o > In function 'do_byte_reverse', > inlined from 'do_vec_store' at arch/powerpc/lib/sstep.c:722:3, > inlined from 'emulate_loadstore' at arch/powerpc/lib/sstep.c:3509:9: > arch/powerpc/lib/sstep.c:286:25: error: array subscript [3, 4] is outside array bounds of 'union [1]' [-Werror=array-bounds] > 286 | up[0] = byterev_8(up[3]); > | ^~~~~~~~~~~~~~~~ > > arch/owerpc/lib/sstep.c: In function 'emulate_loadstore': > arch/powerpc/lib/sstep.c:708:11: note: at offset [24, 39] into object 'u' of size 16 > 708 | } u; > | ^ > In function 'do_byte_reverse', > inlined from 'do_vec_store' at arch/powerpc/lib/sstep.c:722:3, > inlined from 'emulate_loadstore' at arch/powerpc/lib/sstep.c:3509:9: > arch/powerpc/lib/sstep.c:287:23: error: array subscript [3, 4] is outside array bounds of 'union [1]' [-Werror=array-bounds] > 287 | up[3] = tmp; > | ~~~~~~^~~~~ This happens because we have a generic byte reverse function (do_byte_reverse()), that takes a size as a parameter. So it will reverse 8, 16, 32 bytes etc. In some cases the compiler can see that we're passing a pointer to storage that is smaller than 32 bytes, but it isn't convinced that the size parameter is also smaller than 32 bytes. Which I think is reasonable, the code that sets the size is separate from this code, so the compiler can't really deduce that it's safe. I don't see a really simple fix. I tried clamping the size parameter to do_byte_reverse() with max(), but that didn't work :/ cheers