Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp4672426rwb; Tue, 8 Aug 2023 11:53:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF2Yg8EGibhbwlbNdntyKVfEfefzXEneCvuHM0OCvZiXpDDOizxhrKA/tmbMihOcAwDPSTJ X-Received: by 2002:a17:906:cc0f:b0:99c:57ed:baf1 with SMTP id ml15-20020a170906cc0f00b0099c57edbaf1mr336330ejb.51.1691520828597; Tue, 08 Aug 2023 11:53:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691520828; cv=none; d=google.com; s=arc-20160816; b=sqCjIE29CAL8XHOVkBJ7IbocuSoJlr5lLULbQ5jjbaEsORyrP2HzErMVSGLnKyeXNs NfiotFUJBexN6hUgEHBQ4MY3eDvXqTGkoAf7fX5sShykWk1jP9kCLwAdS54Gg2T5Qih9 Ye8xB4AhvHzqwjdyynFiUQmgbjIp8Ura7To4Mtf0ZISnbii9TMtWt7WrlOIg9nYIeHEl Pi/FuyeAc6uwdyrvtxk1wg2ho+AEFjIbeFJZj9IG3ovL7mTeWOyNYveJFCygpynKPGMe uh2r5EQLVrn1UAM9l0Kgtth+g5L6S8QM0Dd066eUDiR8iaXZUiW+K/JBSTgF92ZXeXmP B39w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=Iitn5cuOhlQstNpnubJ9xUVqIDI2aiSTMtUo1rg4ji8=; fh=MoibUNA24HvlZMrPw3aRgvVUGDMC1X96rN1VYAplVsk=; b=mexBhlMFibPTWuzQgLJM7wIuvIxLz91zT+c4sOEh7ULOZBGcSOwgVQUgsxfswK4F2l 8C7y2PbZtrGQXq1e05vVUDQ0ua99sL5EwAwLYzciiC5IDavWTsI5r3LEY0s0BliA+/Xo wnE2q7jHqJJ/DRJcNE6aM1jPORBRl8b4/BSa7FIWuvywZi1fU4qlSGz38JFtNER02yud dayoFkhdsQHFrJLv0hfcMkUiJWjZJR2q+Fal31P16KVkcRT3YpkwWUFUmgxjEUgPxvx7 lginsTldr9LNm++UpePfbY1ppyF5KPUJB5F4vArc/ybvzVwen5apaG7816Hj3kpvjUYV nxaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cs.washington.edu header.s=goo201206 header.b=UrZYxnPX; 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=cs.washington.edu Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j10-20020a170906474a00b0099bcd480030si7420232ejs.879.2023.08.08.11.53.23; Tue, 08 Aug 2023 11:53:48 -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=@cs.washington.edu header.s=goo201206 header.b=UrZYxnPX; 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=cs.washington.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234496AbjHHRXE (ORCPT + 99 others); Tue, 8 Aug 2023 13:23:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234433AbjHHRWg (ORCPT ); Tue, 8 Aug 2023 13:22:36 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6613D7D78E for ; Tue, 8 Aug 2023 09:09:23 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-686c06b806cso3945775b3a.2 for ; Tue, 08 Aug 2023 09:09:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.washington.edu; s=goo201206; t=1691510929; x=1692115729; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Iitn5cuOhlQstNpnubJ9xUVqIDI2aiSTMtUo1rg4ji8=; b=UrZYxnPX6wJckLqe+jHS3YavknBWzDGsZVaSQcowb/6drHVG5WTFt/e2c+tnfwi9XI WSWbIvmK2HuHalP3bQO/ORywMviWjLTgM/fZLeeWonueuvPNciSz+q0DBP5t7QsKE0nC aU571hs+oXkjBZ5hGWq6QJOU7DICgyw4X2reQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691510929; x=1692115729; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Iitn5cuOhlQstNpnubJ9xUVqIDI2aiSTMtUo1rg4ji8=; b=QAYUALPQDMhV1BDR1jGc6HAMcDgdv++uo2LAF/JJbH1DNXl4esi4tPVqXJXhDiP9qQ XcwlrBCQwiGsHVaGqBADCFCVsSefPN5ICBZusSaVvW1G9A78O6XG2swfhfHEH29Bs48f 6UBGffLjydATi3pwis4RfzXMiqyyY3axOL3vowyLJCmDbm0plOFlQRRCorKM0M7ZDJSt c7dLJVG6+UpPvoclT3tgRjQ1wpCtO9CCGG5u8fisCi3tSz/f7NDw10T5foA0wqQ8OSHl DtMU+s1Ya9CjeA3JGSwMfDP3QQmA3OEr6ck28wcmAh8Mv86Mrm2bCWhI7aiOaEH4U19+ y2Qw== X-Gm-Message-State: AOJu0YzWtfrXl9T8HLmK2x2Pq5z+lbfK6yaTgzkQO0e1CsCf+iAU0A1v 8qoXk5rA0L3X1BIn4cDGGP5R2Q== X-Received: by 2002:a05:6a20:8e0b:b0:13b:1482:261 with SMTP id y11-20020a056a208e0b00b0013b14820261mr13582306pzj.44.1691510929663; Tue, 08 Aug 2023 09:08:49 -0700 (PDT) Received: from smtpclient.apple ([50.234.50.204]) by smtp.gmail.com with ESMTPSA id n12-20020aa78a4c000000b00682af82a9desm8497446pfa.98.2023.08.08.09.08.48 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Aug 2023 09:08:49 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6\)) Subject: Re: [PATCH bpf-next] riscv/bpf: Fix truncated immediate warning in rv_s_insn From: Luke Nelson In-Reply-To: Date: Tue, 8 Aug 2023 09:08:38 -0700 Cc: bpf@vger.kernel.org, kernel test robot , Xi Wang , Daniel Borkmann , Alexei Starovoitov , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , =?utf-8?B?QmrDtnJuIFTDtnBlbA==?= , Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <20230727024931.17156-1-luke.r.nels@gmail.com> To: Pu Lehui X-Mailer: Apple Mail (2.3731.700.6) X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED 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 >> static inline u32 rv_s_insn(u16 imm11_0, u8 rs2, u8 rs1, u8 funct3, = u8 opcode) >> { >> - u8 imm11_5 =3D imm11_0 >> 5, imm4_0 =3D imm11_0 & 0x1f; >> + u32 imm11_5 =3D (imm11_0 >> 5) & 0x7f, imm4_0 =3D imm11_0 & 0x1f; >=20 > Hi Luke, >=20 > keep u8 and add 0x7f explicit mask should work. I ran the repro case = and it can silence the warning. >=20 >>=20 >> return (imm11_5 << 25) | (rs2 << 20) | (rs1 << 15) | (funct3 << 12) = | >> (imm4_0 << 7) | opcode; That does fix the warning, but I think explicitly declaring imm11_5 as u32 is more clear here than the current code which relies on implicit promotion of imm11_5 from u8 to signed int in the expression (imm11_5 << 25). Because of the promotion to signed int, (imm11_5 << 25) is technically signed overflow and undefined behavior whenever the shift changes the value in the sign bit. In practice, this isn't an issue; both because the kernel is compiled with -fno-strict-overflow, but also because GCC documentation explicitly states that "GCC does not use the latitude given in C99 and C11 only to treat certain aspects of signed '<<' as undefined" [1]. Though it may not be an issue in practice, since I'm touching this line anyways to fix the warning, I think it makes sense to update the type of imm11_5 to be u32 at the same time. > Nit: maybe use "riscv, bpf" for the subject will look nice for the = riscv-bpf git log tree. Sure, I can send out a new revision with an updated subject line. - Luke [1]: https://gcc.gnu.org/onlinedocs/gcc/Integers-implementation.html