Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp1447585lqt; Wed, 20 Mar 2024 04:35:07 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUv2wAkudwZkVjmgju6vOMnGhZ07V0/sSWIh616liwWOC+hKrV/Lz5PLM2V2v09gPL/LLfAXO56dLHAplIWDsMDiXa9Ac0D/TDtRXa24w== X-Google-Smtp-Source: AGHT+IGOKJeF9rYYEr7ZlTC1Iht7IksFZlcp3mNeKf5bx87cOw2SK3dkmUm9yCi3ua16bxbtY348 X-Received: by 2002:a05:6830:1293:b0:6e5:371b:5565 with SMTP id z19-20020a056830129300b006e5371b5565mr5946189otp.23.1710934507144; Wed, 20 Mar 2024 04:35:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710934507; cv=pass; d=google.com; s=arc-20160816; b=y/2uaNYluW3METqvWeINCSKmdHOwtNlQppG5Ex9h5SDzkMOk75h9JowBtnP14f4wV/ fLtNY//26ja9bh4BRdS5jRQzMUiiD7BGXLxUepgCV9k+oLV4o1cug8IR3iGYWX3ejvFy A3vOfje7cW16m+dL/kcH8kRqEUiZzq0r4cDT8r59yH/1N3VJI+rE5FuTMIPnIwlxCt2O L+VI5dpIbRDaspsW9c0zgyB2DbcQAG/LvWAVBCmHzoHKxntAHuqL8G6aVIsbUk+LV83z R5it8nRkx4vAq/adzVdVHjZdALkNqytoMtiqiPv3C0tJnFtM4pAaOtWcnnNBCBwywFuR WKgQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=YF0ocYGKjsoaEp5czwhEYFxrEcCjkH8QwsTiH0NNLCw=; fh=JDp006GgAEale6fSE2YgfaM4b0jNfAxPexaaGqHzppg=; b=DjYmnJiV7ITNZKO5oArXuHuGoDGfSuZj8L00E6CcI/tCrx2Ovg+v6z1V+2qvFEgp8B eJcMoJ0Gpe0xYkMV2/q1/6GPw9wgbQeDcpR3hQ3vj7GYcGVCkESeDAs9TuQImSauCgUj cvf5YPuZpPPAcjwO3zxsUjLE65++uCPPXEE46fhHqms1KIDgLVeb4NAn8rLW7jKWF30I 967D7PJ+TqVpC6aZEvuvcHGmBCZYv5WveOg6Ylbk68TSWAk2yjXvjmuE/5iEG+iGx33q o2oRXwhdPwfJwobhU1Vwgs8zV7o9QjaqW50SPps0BT5fYg9ZD5av5FJksKi8xICZSy17 /vTg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-108865-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108865-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id pc30-20020a05620a841e00b00789e6b10db5si10723587qkn.537.2024.03.20.04.35.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 04:35:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-108865-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-108865-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108865-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id B4AF51C223CD for ; Wed, 20 Mar 2024 11:35:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 077B53F9CD; Wed, 20 Mar 2024 11:34:55 +0000 (UTC) Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 29BAB3D984; Wed, 20 Mar 2024 11:34:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710934494; cv=none; b=UcEsjR0Qd6uxDh8kldtMDh4asbTazAwXDkBKiUYzyBZJywHuTTXAHSpD3OiqDQlc3lJR1t3idQE0JHaSSyFH2lF4T7aTyvvNu6LOvr11++F/kSjsXBXVXU4Yk1zpaxWrhG9zC3s7pMKbzZbW4SkCAW0/7jAUZTJtBU1blK6V5cc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710934494; c=relaxed/simple; bh=3WaKxkbQWcDCF2kXtI2Am05e+yUdzZw2ITQ8GoPRoSk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Rp56XkgJ4EQVOks4Ul9jdvN+mvxQ0PterGaHzowWqWpzFTOpVZcyOny/XRV0vwI8inNTTZaczUbIpjkUjoEl6Km1peZV6DFQQXPWl3qbmOVAOcJNQQrvKlLS5EldPAHoKyzPu8fC56zooQXd8eBd99GBAclk3v+vOen5tdYuc7w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4V062D0XMZz4f3l89; Wed, 20 Mar 2024 19:34:44 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id E87C31A0AAE; Wed, 20 Mar 2024 19:34:47 +0800 (CST) Received: from [10.67.111.192] (unknown [10.67.111.192]) by APP4 (Coremail) with SMTP id gCh0CgCX6GrWyfplm5SjHg--.34463S2; Wed, 20 Mar 2024 19:34:47 +0800 (CST) Message-ID: Date: Wed, 20 Mar 2024 19:34:46 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH bpf-next] arm64: bpf: zero upper bits after rev32 Content-Language: en-US To: Artem Savkov , Xi Wang , Catalin Marinas Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org References: <20240313140205.3191564-1-asavkov@redhat.com> From: Xu Kuohai In-Reply-To: <20240313140205.3191564-1-asavkov@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-CM-TRANSID:gCh0CgCX6GrWyfplm5SjHg--.34463S2 X-Coremail-Antispam: 1UD129KBjvJXoW7AFyxZF1kur1UJFykAw4Dtwb_yoW8try8pr 4ayrZakr4UWr17Aa4FganrJr1vkay2y3yUtryDWrWSka9Yv34kXryfKrW2939IvrW0vw4Y 9FyjyF93X3s2v3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUgmb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Cr0_Gr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I 0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40E x7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x 0Yz7v_Jr0_Gr1lF7xvr2IY64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_ Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1V AY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAI cVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWrZr1j6s0DMI IF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Jr0_GrUvcSsGvfC2 KfnxnUUI43ZEXa7IU1zuWJUUUUU== X-CM-SenderInfo: 50xn30hkdlqx5xdzvxpfor3voofrz/ On 3/13/2024 10:02 PM, Artem Savkov wrote: > Commit d63903bbc30c7 ("arm64: bpf: fix endianness conversion bugs") > added upper bits zeroing to byteswap operations, but it assumes they > will be already zeroed after rev32, which is not the case on some > systems at least: > > [ 9757.262607] test_bpf: #312 BSWAP 16: 0x0123456789abcdef -> 0xefcd jited:1 8 PASS > [ 9757.264435] test_bpf: #313 BSWAP 32: 0x0123456789abcdef -> 0xefcdab89 jited:1 ret 1460850314 != -271733879 (0x5712ce8a != 0xefcdab89)FAIL (1 times) > [ 9757.266260] test_bpf: #314 BSWAP 64: 0x0123456789abcdef -> 0x67452301 jited:1 8 PASS > [ 9757.268000] test_bpf: #315 BSWAP 64: 0x0123456789abcdef >> 32 -> 0xefcdab89 jited:1 8 PASS > [ 9757.269686] test_bpf: #316 BSWAP 16: 0xfedcba9876543210 -> 0x1032 jited:1 8 PASS > [ 9757.271380] test_bpf: #317 BSWAP 32: 0xfedcba9876543210 -> 0x10325476 jited:1 ret -1460850316 != 271733878 (0xa8ed3174 != 0x10325476)FAIL (1 times) > [ 9757.273022] test_bpf: #318 BSWAP 64: 0xfedcba9876543210 -> 0x98badcfe jited:1 7 PASS > [ 9757.274721] test_bpf: #319 BSWAP 64: 0xfedcba9876543210 >> 32 -> 0x10325476 jited:1 9 PASS > > Fixes: d63903bbc30c7 ("arm64: bpf: fix endianness conversion bugs") > Signed-off-by: Artem Savkov > --- > arch/arm64/net/bpf_jit_comp.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c > index c5b461dda4385..e86e5ba74dca2 100644 > --- a/arch/arm64/net/bpf_jit_comp.c > +++ b/arch/arm64/net/bpf_jit_comp.c > @@ -944,7 +944,8 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, > break; > case 32: > emit(A64_REV32(is64, dst, dst), ctx); > - /* upper 32 bits already cleared */ > + /* zero-extend 32 bits into 64 bits */ > + emit(A64_UXTW(is64, dst, dst), ctx); I think the problem only occurs when is64 == 1. In this case, the generated rev32 insn reverses byte order in both high and low 32-bit word. To fix it, we could just set the first arg to 0 for A64_REV32: emit(A64_REV32(0, dst, dst), ctx); No need to add an extra uxtw isnn. > break; > case 64: > emit(A64_REV64(dst, dst), ctx);