Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2790146rdb; Fri, 8 Dec 2023 22:07:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IHHcslcyH8n4J+5QbO0XdSWXuDAMX2IDtqbZ4S7zagjHPBkI0lBfPIbchdeukDhQU8UOZ1Y X-Received: by 2002:a54:418e:0:b0:3b8:b063:ae1a with SMTP id 14-20020a54418e000000b003b8b063ae1amr1377607oiy.119.1702102057507; Fri, 08 Dec 2023 22:07:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702102057; cv=none; d=google.com; s=arc-20160816; b=n7MzfVQyZzy7kqhnBDhVTbMmhd3WT2t6xEk1KxMe4fGsUSmGDH0GTe9yGSIuY+nLlD 8fx005UWy1tuaVaGuPJJTptGjv/v8uyG1XMhWChW5GO3yjgRepor8/CNahlfeDUA0s3E +2oligNKiwgQjDwJIy0MgKXlNONNipbVPuG5oJ9ac9mwM6xsWsYkv/AwcI6/eWy2NUnU 7UHVjDHgWns+BPocdC68VuEPXvwUICyASk+PjMhaRXFYj8tnUowMirIYTpE28U9h9OIq gmF8rNRzDo0tdH7bJOLU624/KbqGISurgIOf3UvfzvedKvUF8m4A5Xk8VLQR1IkPksaX NaiQ== 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=nf6OOTcG7PxYCx6vPFQxKfuzNKzfWsQNsizZ/iXT2to=; fh=/RRef5tZdIJLbCV2SmiycgKftJcnOrCY/HMHqBd9iFg=; b=g1vd5rT0nRkgub8AQEGPwpsx681/LBzaF1/Rz6LvZYRZY+/mhrb12MbSHJnMK2S4lU ZAv1jlWUE4S4FrBv8uTozqXnvrvYvhXRD2s8wlp9k31nrZBUx2m0QsND1gLZ2/9scKY/ ygSbbPPjZfBXjh2/DiZM8L4t9vp7P9lVUn4ondCEDWhitQmfsOMrMoB0T1U0SHre5woV y1dqzxj9CkPtgR21CfIf8eHR38ocERHBNtpLcT+kVil5/klWAn9HWCQs8FQ/RP/veqRV BiwAXVRxms3sOi4GXCZTGwb+leVOp6xIDIyoe6zfNHEbhRQc/YisnZtDFJ76cfUxcY0O +mqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Ac8p8MJW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id l1-20020a632501000000b005a1d88169casi2565976pgl.189.2023.12.08.22.07.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 22:07:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Ac8p8MJW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 54C4C80725E2; Fri, 8 Dec 2023 22:06:51 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229731AbjLIGGf (ORCPT + 99 others); Sat, 9 Dec 2023 01:06:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbjLIGGe (ORCPT ); Sat, 9 Dec 2023 01:06:34 -0500 Received: from mail-oa1-x36.google.com (mail-oa1-x36.google.com [IPv6:2001:4860:4864:20::36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DA6710DF for ; Fri, 8 Dec 2023 22:06:40 -0800 (PST) Received: by mail-oa1-x36.google.com with SMTP id 586e51a60fabf-1fb104887fbso1796399fac.3 for ; Fri, 08 Dec 2023 22:06:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702101999; x=1702706799; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=nf6OOTcG7PxYCx6vPFQxKfuzNKzfWsQNsizZ/iXT2to=; b=Ac8p8MJWzVQTOc94MqD9cJmpKz1SjIurkpHFJFZSRSW4VMKaYX1gG3KXFoNILY3EnC 8JpNIB/pVDRRsC7k3WzLaBH5DylfyAMMpd6JWnWKmEr4iB+WS7QuI3iSc6Z20m2KFAdF QhnuKoWJAujgzHGX464mQsmk4/+KiN1W4Ih5O7YW9Zgmxl5+C44QNR+mYIO6xJP7J2c7 e/JDXgms/grfRURyA6u7OhPV4V3hijknSPSeINg4m7+TrpwHmiMEzCKNAjio7y3BYGrF pWBWWKBE8IPv6y2KiS4SSZ9XPoXsNongCDvp1lPJJmQxM/RxTzDvUzesJbKH15ijBQSq 1w9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702101999; x=1702706799; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nf6OOTcG7PxYCx6vPFQxKfuzNKzfWsQNsizZ/iXT2to=; b=XJQjsYUjy7LiR31BWfUz2fsfRIGakUBcNlnxz1inYDYBekQjpw1gKQxhkx9nzpKRqQ GgR0PJVxsvhsBor+1bteYg1V8UwLXkrLnZznS85alaQRiy21p7+QiSNH5+Tvd6auCOAx x8TIXd0Y6Fm4cA9Y83S07sBYJlZjfnqlqWcqfD9+NNCRg9nbFzd3WhpwCPwyhoXPpR8w 4j3Wm37SQFEFaXWwmmmD96L59+CA7hafiRrpTrpBme6oadOq8DpSGKm5DQnxxIitj3tQ 2rhvgK5CTzk0XDAj/ko8YFoZ0fRKt53cFC4/tLwqPYfsSXTYgSERptjHs1SLvmHMyKeW o8Bg== X-Gm-Message-State: AOJu0Yz1xk+UVRll43KPEzeK3OB3DhaYurjWnwRad6553KrmYVYVPFRx 2knm6GX4ohjPLOw1HA5p/Qu49vOd0LBdv+JopN4s7XIskJLJtw== X-Received: by 2002:a05:6870:d38a:b0:1fb:6e5d:1ecb with SMTP id k10-20020a056870d38a00b001fb6e5d1ecbmr1708470oag.54.1702101999590; Fri, 08 Dec 2023 22:06:39 -0800 (PST) MIME-Version: 1.0 References: <20231207032951.16334-1-yangtiezhu@loongson.cn> <20231207032951.16334-3-yangtiezhu@loongson.cn> In-Reply-To: <20231207032951.16334-3-yangtiezhu@loongson.cn> From: Hengqi Chen Date: Sat, 9 Dec 2023 14:06:28 +0800 Message-ID: Subject: Re: [PATCH v1 2/2] LoongArch: BPF: Fix unconditional bswap instructions To: Tiezhu Yang Cc: Huacai Chen , 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=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email 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 (pete.vger.email [0.0.0.0]); Fri, 08 Dec 2023 22:06:51 -0800 (PST) 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 146= 0850314 !=3D -271733879 (0x5712ce8a !=3D 0xefcdab89)FAIL (1 times) > test_bpf: #317 BSWAP 32: 0xfedcba9876543210 -> 0x10325476 jited:1 ret -14= 60850316 !=3D 271733878 (0xa8ed3174 !=3D 0x10325476)FAIL (1 times) > > After: > test_bpf: #313 BSWAP 32: 0x0123456789abcdef -> 0xefcdab89 jited:1 4 PASS > test_bpf: #317 BSWAP 32: 0xfedcba9876543210 -> 0x10325476 jited:1 4 PASS > Nice catch. I wasn't aware of test_bpf before. For the patch: Acked-by: Hengqi Chen > Fixes: 4ebf9216e7df ("LoongArch: BPF: Support unconditional bswap instruc= tions") > 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, st= ruct 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 >