Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2905874rdb; Sat, 9 Dec 2023 04:05:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IF3pmoEFP+9yr4owoyYbfcRqlrqDSatYdhxU18Yv0TXb8MeXZKuIpPX/dpBBLsOAx+FAmzA X-Received: by 2002:a17:902:e884:b0:1d2:e6ec:daa9 with SMTP id w4-20020a170902e88400b001d2e6ecdaa9mr2098234plg.2.1702123514283; Sat, 09 Dec 2023 04:05:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702123514; cv=none; d=google.com; s=arc-20160816; b=f9j1pq2xo15vR0eWGBKOPaAQZkDEMqEI3iZvtThP90wNVZDQ1a6OlXfMP7kme0gYCt PxchTKsLm8m9w6mD50zpF0qnB4D0ppMMIDGTB5aw8LYymqCG9rwLwKW7Wfl6Kqyfce5n ZXmdIHPSRyL/RNMHP0Y7eAVrahsiLz+X0Wl6m1z7JUSv6Cuf9xFTEg57omELI2OOLoi8 brgc93JmQwS3u/pHNdZGYrZ7Jb4L8VuyBYPDK3gy+OFp6bfiRg/KpXDIQ+e2RsPn425A s9pyBry18XzzcDKqa/OUIGzg/tuJ+FHkGkyYHngtoPNqGGkBI90EnJ+yofXR4CAG43lu az/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=gR6z19YGEuSs/Dabqz71O2NYwUVnSNix6oeRWyZvDA8=; fh=i7kc6GcDdtmZKH4ovHT6psmLujxOBPFVX1aC3lriuFQ=; b=Etx8hVsINhlRduoCls8QjHE5mHoJVQDwWiWVcX9tYVnaLrNUdzH0aY/v9ZC7ifCs/C PZA43PR5EzOd5cXKQq0CUVrsSsbU3h1Gk2Gj0YH8+sBIZ+vhQ6v1dyUO9+4a+aiURuM5 dSE40/h6meceuak/FlG9AQ4PGDe6SYxZa9NP4b0PCCQ/Ni4KrEZuCKWa9/Jie4G30IsL zLmVY/4GJcnT3k9hZuCDkkxf5ihMMjGtmPbCChMD0j+Kbbcv6KZl6E/cius3mkTFFVrV zNV5W1tQcfHfwYm1qTsrxh/4cJGiKVlatXpn07xULv0W0NOnECmclnjZSGZowMzzO01B K9wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MaU+cL8F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id l5-20020a17090270c500b001c60c5bbff2si2993257plt.201.2023.12.09.04.05.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Dec 2023 04:05:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MaU+cL8F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id EC277805F9F9; Sat, 9 Dec 2023 04:05:11 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230082AbjLIMBw (ORCPT + 99 others); Sat, 9 Dec 2023 07:01:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230088AbjLIMBu (ORCPT ); Sat, 9 Dec 2023 07:01:50 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FB9E10E6 for ; Sat, 9 Dec 2023 04:01:56 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D03DAC433C9 for ; Sat, 9 Dec 2023 12:01:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702123315; bh=ivFsOSgwviRbxCdV/HZOaDIko5Llynvw15OE80tETss=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=MaU+cL8FnSJCL5k2K8QhOzLor81yo9ImCRnWMnhPcP1bxO2ljA/GZq0lZWvN7pzRH NTPgdqW2qq1eO4N4AYGJtj9uJ6HZURtre7ySk28wk9m5iYp1TkidGV9+CNOafNP4B2 +yaQN/59F5s8MzSTsJENWzj46FEwFmaNd7uSdsq8/SP+Z3kshnJJxf7B3af8vt+xgW AZ0FWZKv2uZgVhUxpdJ9Tp6qI8r+6AQ1e1CmdBs0MVZ437A3F2OdvP3Fwbb5ZbeqcA 5/aMKX20yTq9d6TxsMYgeBS/3qgo4RpyCVNvgCsBk6FhHeCudQGWZcC8S1Hn8cTO6y eg6qBiB5SeTEA== Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-a1d2f89ddabso352705966b.1 for ; Sat, 09 Dec 2023 04:01:55 -0800 (PST) X-Gm-Message-State: AOJu0Yz+ZLL6yS9ZiBFwJdtsAc3xiBd8PtPnQRYuhzgH+M419Dqg7p7X Y/6zMgZmXqfa09dsrP8IqPKZ9gXQsqqemq9ztv0= X-Received: by 2002:a17:907:7663:b0:a18:b889:d453 with SMTP id kk3-20020a170907766300b00a18b889d453mr793925ejc.2.1702123314320; Sat, 09 Dec 2023 04:01:54 -0800 (PST) MIME-Version: 1.0 References: <20231207032951.16334-1-yangtiezhu@loongson.cn> <20231207032951.16334-3-yangtiezhu@loongson.cn> In-Reply-To: From: Huacai Chen Date: Sat, 9 Dec 2023 20:01:44 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v1 2/2] LoongArch: BPF: Fix unconditional bswap instructions To: Hengqi Chen Cc: Tiezhu Yang , loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sat, 09 Dec 2023 04:05:12 -0800 (PST) Applied, thanks. Huacai On Sat, Dec 9, 2023 at 2:06=E2=80=AFPM Hengqi Chen = wrote: > > On Thu, Dec 7, 2023 at 11:30=E2=80=AFAM Tiezhu Yang wrote: > > > > We can see that "bswap32: Takes an unsigned 32-bit number in either > > big- or little-endian format and returns the equivalent number with > > the same bit width but opposite endianness" in BPF Instruction Set > > Specification, so it should clear the upper 32 bits in the case 32 > > for BPF_ALU and BPF_ALU64. > > > > [root@linux fedora]# echo 1 > /proc/sys/net/core/bpf_jit_enable > > [root@linux fedora]# modprobe test_bpf > > > > Before: > > test_bpf: #313 BSWAP 32: 0x0123456789abcdef -> 0xefcdab89 jited:1 ret 1= 460850314 !=3D -271733879 (0x5712ce8a !=3D 0xefcdab89)FAIL (1 times) > > test_bpf: #317 BSWAP 32: 0xfedcba9876543210 -> 0x10325476 jited:1 ret -= 1460850316 !=3D 271733878 (0xa8ed3174 !=3D 0x10325476)FAIL (1 times) > > > > After: > > test_bpf: #313 BSWAP 32: 0x0123456789abcdef -> 0xefcdab89 jited:1 4 PAS= S > > test_bpf: #317 BSWAP 32: 0xfedcba9876543210 -> 0x10325476 jited:1 4 PAS= S > > > > Nice catch. I wasn't aware of test_bpf before. For the patch: > > Acked-by: Hengqi Chen > > > Fixes: 4ebf9216e7df ("LoongArch: BPF: Support unconditional bswap instr= uctions") > > Signed-off-by: Tiezhu Yang > > --- > > arch/loongarch/net/bpf_jit.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/arch/loongarch/net/bpf_jit.c b/arch/loongarch/net/bpf_jit.= c > > index 8c907c2c42f7..da48398e8794 100644 > > --- a/arch/loongarch/net/bpf_jit.c > > +++ b/arch/loongarch/net/bpf_jit.c > > @@ -774,8 +774,8 @@ static int build_insn(const struct bpf_insn *insn, = struct jit_ctx *ctx, bool ext > > break; > > case 32: > > emit_insn(ctx, revb2w, dst, dst); > > - /* zero-extend 32 bits into 64 bits */ > > - emit_zext_32(ctx, dst, is32); > > + /* clear the upper 32 bits */ > > + emit_zext_32(ctx, dst, true); > > break; > > case 64: > > emit_insn(ctx, revbd, dst, dst); > > -- > > 2.42.0 > >