Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2189104iof; Tue, 7 Jun 2022 22:38:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvz/L02sbmwNaCVHkMIOq3NxbSUg81SJW/cU9r/7zJQHO0tOEwMyzKaXj9A2Up23zjJiEg X-Received: by 2002:a65:6d16:0:b0:3c1:b056:5f5a with SMTP id bf22-20020a656d16000000b003c1b0565f5amr28306283pgb.469.1654666684224; Tue, 07 Jun 2022 22:38:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654666684; cv=none; d=google.com; s=arc-20160816; b=viVgP1HmsaO3hFx+XJsmlacPpZYI2Hc4YXjcsq7Ato7L1lONlWIOP6HoLmBTpstKUx gQi8cOfgOfWXWhaIzDleF0hbCOPpaUL1TCNQlrpwgiBSb4N60zQBr+KsFysmWf63ncoj pA2XesHxnbmFbBSRL5NhWYt7c5cdeyBgmXfGNp0Ph7pspqEc9NFtfdQlzY9dYpp7/9ab itK38WLzqnOD80C3d1/TvMesTHNECVtyyzNALpGNB44pIOXRxQaMeD7EnACIiHYHAQUB +3GaTgiGh53+wMGJttIanOdhIyiVEW1Z6urnaxPOqUA97ib11NhwfQovng37emx1w6to Gp4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=tSvHLWn7P/RjJxmI8dJzK7e+v4wUMVRCuDXsk4BKmjA=; b=rFoaUfiLwgjTl/sEuDf8tC4ZYQ2gDpaRLqCds7A1E7FLNgd2FZzyl4v2gznaI5/HVi T5wxhPlJ/Yyhet8P2z/5qHKfLj6R/pQM1HuesD6MuycUrjxm/ToJFIauTo4AaQqJ2cTa ctsujBXr4LkVyKBrVxggJzPt4afOlHs9QgyhoXnn1RTwTvr3OI9OIWKFYdXIDczSqFXK KrHYmmMhjZm117zFjp60/V9/QCZr1Do4ILOIODupcKspjVbSfUL/vcsvFptdhkS+zUWT IltCodNPPFgHcKn/DzzikDjnb36ENrjWqWsZDc4jWvsgHcCEzzStAqmK7ionoSH9iLEn I12g== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id qe18-20020a17090b4f9200b001e684125756si29202912pjb.142.2022.06.07.22.38.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:38:04 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 99FC93A15DC; Tue, 7 Jun 2022 22:04:02 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245395AbiFGOXl convert rfc822-to-8bit (ORCPT + 99 others); Tue, 7 Jun 2022 10:23:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244855AbiFGOXg (ORCPT ); Tue, 7 Jun 2022 10:23:36 -0400 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E5C2866CA7 for ; Tue, 7 Jun 2022 07:23:30 -0700 (PDT) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-160-GwpNDfyfMIKAFzFYkoJBmA-1; Tue, 07 Jun 2022 15:23:27 +0100 X-MC-Unique: GwpNDfyfMIKAFzFYkoJBmA-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) by AcuMS.aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) with Microsoft SMTP Server (TLS) id 15.0.1497.36; Tue, 7 Jun 2022 15:23:26 +0100 Received: from AcuMS.Aculab.com ([fe80::994c:f5c2:35d6:9b65]) by AcuMS.aculab.com ([fe80::994c:f5c2:35d6:9b65%12]) with mapi id 15.00.1497.036; Tue, 7 Jun 2022 15:23:25 +0100 From: David Laight To: 'Michael Ellerman' , Bagas Sanjaya , "linuxppc-dev@lists.ozlabs.org" CC: Anders Roxell , Arnd Bergmann , "linux-kernel@vger.kernel.org" , Paul Mackerras , Nicholas Piggin , Yang Li Subject: RE: outside array bounds error on ppc64_defconfig, GCC 12.1.0 Thread-Topic: outside array bounds error on ppc64_defconfig, GCC 12.1.0 Thread-Index: AQHYehMfGrZ1ohRgvU+RLIptsHpWBK1D/qnw Date: Tue, 7 Jun 2022 14:23:25 +0000 Message-ID: References: <87mtepns81.fsf@mpe.ellerman.id.au> In-Reply-To: <87mtepns81.fsf@mpe.ellerman.id.au> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, 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 From: Michael Ellerman > Sent: 07 June 2022 03:05 > > 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 :/ I had a quick look at the code - it is somewhat horrid! Not really surprising the compiler is confused. Although it shouldn't be outputting that error message unless it is certain. Could it be re-written to read the data into an __u128 (or whatever the compiler type is). Optionally byteswap the entire thing (swap the words and then byteswap each word). The do a put_user_8/16/32/64() to write out the value. I think that would remove all the memory accesses and make it a lot faster as well. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)