Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp203379pxb; Thu, 21 Apr 2022 21:36:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDHxsYc8EF8Jv19vbqfUpw+u8JhJKFuHxO/5XqjImH401LPJLWX+iwawhS4riNR/5FkTJ+ X-Received: by 2002:a17:90b:4a0f:b0:1d2:bf83:163b with SMTP id kk15-20020a17090b4a0f00b001d2bf83163bmr14301604pjb.6.1650602198477; Thu, 21 Apr 2022 21:36:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650602198; cv=none; d=google.com; s=arc-20160816; b=sZaI6sxYiX9ulizGsuB72UF4/SOcJuw4yVF3gIo1eCg39eNgdPJ2+YgxmAu/nEakR9 0RAEvozyiAfrzeV43uMkmfXGv/bs2oqFonj9u1cTQGSSaeW3d+bTJw15qNnzt3nujWfe N6ZtfQJ5QqUUuIbGPMyERgcz1Ohbf1n4vu6Z6c+4lzNagd3syGVdlLvLdAdqf1h8VTLF 7JNrCNRgcKhPPyLLqTXPXeNcm9L2zJkAkFZbaHEQnxvcCdU0GlkQMcelg3K3FbocHlxq niXMx0xkVGP/MqQC6Kz/2EGWIu6z6Tt5aZxtmf+HLTi5OAvv68FyIZBNxJ5aPHqjCzOe WkuQ== 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 :user-agent:message-id:date:subject:cc:to:from:dkim-signature; bh=aI024WHC/bEMg8nvZ834auRImnWK7kVLOZ4xKww3Qfg=; b=Vj5ppVHz58oMgt+rY9/br6aYbsv+vgoNxDTYKJu/6fSiJe+92GR2clAmeT5kVX+pA7 7zhVUEg+jWG5Q8gkE1A2Y7EhScW50MbBaJg5TufNFVPI3LmcWeqTFSdoLyk/Of2h8f5f hxDSc9Mc2PHYztohQiCFsHk6OA5y+H6KJ1HUSQ1qfWy5HnAUhLFR0kXnlQfCsTFEjkvr sIHEfp8cKJ8TZlj0RYN9ezEkc75TwagYvGQL6NnlTKwuclIrE6SA4wqh2U0y4CXlu+iI x/0wIGa/Tm31NA4T5OspVhi+p58fBz0pcLrT79O5FefejssaXQYlyKkJFT8WuRrQbUDe tbiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=CRiCjvir; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l191-20020a6391c8000000b003aaa09647e2si2681151pge.548.2022.04.21.21.36.19; Thu, 21 Apr 2022 21:36:38 -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=@ibm.com header.s=pp1 header.b=CRiCjvir; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1388015AbiDUOFV (ORCPT + 99 others); Thu, 21 Apr 2022 10:05:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1388799AbiDUOFM (ORCPT ); Thu, 21 Apr 2022 10:05:12 -0400 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA6F33B287; Thu, 21 Apr 2022 07:02:15 -0700 (PDT) Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23LCNtng020172; Thu, 21 Apr 2022 14:02:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : mime-version : content-type : content-transfer-encoding; s=pp1; bh=aI024WHC/bEMg8nvZ834auRImnWK7kVLOZ4xKww3Qfg=; b=CRiCjvirWXl4MnbJVF7/otV8kD8HghhK81jWpyKyzW6Vw0YyWQCsVc6SWw7CUpVwhTir R1oqH8ayvLY8Jchbmokq95DNYftbhjgiDLD5lFJ2p+7jkFXlyUthR4LlchklkzlXXHcv ANvt+CiK9c6uMngU1TQ917DXmywz55JeDAKTNeBL6KlOfyst9U9Zz0/9cvbkOihVtCkk DVXjAMaKjq5OVdf9QygnF+eRomXZe0iwwqTWe6yPsnOiyu51FNTIM7LgEF//ZkkfqreP DW+ERxN9eX1WggA3NwqwqSkyXRLd0mr5jcMjw8zGEN+cKizqmcu1w8eclF1/Aiui/IwW 9w== Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 3fk1ye94cq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Apr 2022 14:02:13 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23LDrCWM015800; Thu, 21 Apr 2022 14:02:11 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma04ams.nl.ibm.com with ESMTP id 3ffne980hp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Apr 2022 14:02:11 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23LE28tQ25362744 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 21 Apr 2022 14:02:08 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3793D11C054; Thu, 21 Apr 2022 14:02:08 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EA16D11C04A; Thu, 21 Apr 2022 14:02:07 +0000 (GMT) Received: from tuxmaker.linux.ibm.com (unknown [9.152.85.9]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Thu, 21 Apr 2022 14:02:07 +0000 (GMT) From: Sven Schnelle To: Kees Cook Cc: linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, krebbel@linux.ibm.com, iii@linux.ibm.com, hca@linux.ibm.com, Linus Torvalds Subject: -Warray-bounds fun again Date: Thu, 21 Apr 2022 16:02:07 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: K4RxM8JLj-DcbUAXNWZRXoVGcuvmMJEe X-Proofpoint-GUID: K4RxM8JLj-DcbUAXNWZRXoVGcuvmMJEe X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-21_01,2022-04-21_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 spamscore=0 bulkscore=0 suspectscore=0 impostorscore=0 lowpriorityscore=0 priorityscore=1501 phishscore=0 mlxscore=0 clxscore=1011 adultscore=0 mlxlogscore=248 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204210077 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS 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 Hi, while compiling the latest upstream kernel on fedora 36 which uses gcc-12 by default, i got a lot of -Warray-bounds warnings: (Note that this is on s390 arch) In function =E2=80=98preempt_count=E2=80=99, inlined from =E2=80=98do_one_initcall=E2=80=99 at init/main.c:1290:14: ./include/asm-generic/rwonce.h:44:26: warning: array subscript 0 is outside= array bounds of =E2=80=98const volatile int[0]=E2=80=99 [-Warray-bounds] 44 | #define __READ_ONCE(x) (*(const volatile __unqual_scalar_typeof(x) *)= &(x)) | ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /include/asm-generic/rwonce.h:50:9: note: in expansion of macro =E2=80= =98__READ_ONCE=E2=80=99 50 | __READ_ONCE(x); | ^~~~~~~~~~~ ./arch/s390/include/asm/preempt.h:17:16: note: in expansion of macro =E2=80= =98READ_ONCE=E2=80=99 17 | return READ_ONCE(S390_lowcore.preempt_count) & ~PREEMPT_NEED_R= ESCHED; | ^~~~~~~~~ This is because S390_lowcore is defined as follows: #define S390_lowcore (*((struct lowcore *) 0)) Lowcore is a 8K cpu-local memory region on s390 at fixed address 0. The obvious 'fix' is to use absolute_pointer(): #define S390_lowcore (*((struct lowcore *)absolute_pointer(0))) That makes the warning go away, but unfortunately the compiler no longer knows that the memory access is fitting into a load/store with a 12 bit displacement. Without absolute_pointer(), reading the preempt count is just a single instruction: 'l %r11,936' static inline int preempt_count(void) { return READ_ONCE(S390_lowcore.preempt_count) & ~PREEMPT_NEED_RESCHE= D; 8c4: 58 b0 03 a8 l %r11,936 <--- load preempt count 8c8: b9 04 00 92 lgr %r9,%r2 int count =3D preempt_count(); with absolute pointer(), the compiler no longer optimizes the read to one instruction and uses an additional base register: static inline int preempt_count(void) { return READ_ONCE(S390_lowcore.preempt_count) & ~PREEMPT_NEED_RESCHE= D; 8c4: a7 19 00 00 lghi %r1,0 <-- use %r1 as ba= se, load with 0 8c8: b9 04 00 92 lgr %r9,%r2 int count =3D preempt_count(); char msgbuf[64]; 8cc: d7 3f f0 a8 f0 a8 xc 168(64,%r15),168(%r15) 8d2: 58 b0 13 a8 l %r11,936(%r1) <-- and finally ad= d the offset and fetch int ret; The reason for gcc to not optimize that further is likely the asm statement in RELOC_HIDE (located in include/linux/compiler-gcc.h) #define RELOC_HIDE(ptr, off) \ ({ \ unsigned long __ptr; \ __asm__ ("" : "=3Dr"(__ptr) : "0"(ptr)); \ (typeof(ptr)) (__ptr + (off)); \ }) For most of the code this wouldn't be a big problem, but we're storing information like preempt_count, current thread info, etc in lowcore because it is the fastest way. I would like to avoid to use additional instructions/registers just to avoid a warning. Does anyone have an idea about a different way to make this warning go away? Thanks Sven