Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp185838lqp; Wed, 20 Mar 2024 19:01:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXQahMXUZd/JjZfw+QwuyJ6ZEswI+lasyfcslMmFacEHxUEquyjaez3Pl2l5hmtxZGB1uq50Cxzj/mW40vEriGMzKlTc9YEgFesn+093A== X-Google-Smtp-Source: AGHT+IF1Q6elhF6GjTyYGkReATnRoc+h74806G3HRNyxzGtbwDW7rat6qjNLrkZvQE2D0lEBosxw X-Received: by 2002:a05:6870:858b:b0:221:a881:e07a with SMTP id f11-20020a056870858b00b00221a881e07amr8700288oal.44.1710986462436; Wed, 20 Mar 2024 19:01:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710986462; cv=pass; d=google.com; s=arc-20160816; b=LJe3SSDahJtdDBYiJ0YYAOIUSAal4GqkejhsC7ldZ1MVYkwVWm/dXDK4rdDpm+VFgJ f8/aM64sh63iz9eusrwdKlVqH72mDp30FOZD0kBQTE/eozrBSMxHyS4jyMzpJDCEVjHd uvfUKBhPVJfQP6ZRmJUJ4TGKpOnbkNEWgyw9KVb7vz+m2gx6XDEKx0zxX/qM7aORKMqm +MgutW+wQQnJgdmGx56fT38n++2yy3hKZYHuarBckSaACDctkQ6OTNFw5lOLt3dU6liV md2LqFg4tbFmPjLzMptN98ewy3XvbDgZfdsXnzx+Qa2CHVMrYOkRrdUB+M7zp2zjeYNF cchg== 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=is7wuUTa4USl2fzb1bWyNxhPbe2hVkxikb+l/U5/Wa0=; fh=ywIerOhsm/84P7oD1aXyUfMWdX9Oao+FRBGjlkynelw=; b=FgFvCZnHTsxE4NaDp3Fej3xCIbHVQJQ2nK3DK5oRl3wLh4T/N7PHCLC3BYa/U/fIG3 smPusmi78ewPlE3d+3ilQpV/kto413nKu76yjg9vg7VAQjsZo80424pSPWJvYjcziPRF OjNC0xDfH+6e+KS86b/fopVgndghLyealiLThTMeqM5xy9mBic2A4HLQbyFfqTTy+5CK yi+m08EuioPxgyDXRpI5DA1m+x/ppzOUntecYPlyopqr7V0/8Ul5lq5JCG6qpLgfeOxf hA6OK0V2S1P6PTpyIshk1/MsPAsEOpa7PNwKdt30n6+U2yOWfcuDj7lZXe0aUh6+1QZN DTww==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-109559-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109559-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=QUARANTINE) header.from=huawei.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id w62-20020a638241000000b005e838a81bf7si9759429pgd.480.2024.03.20.19.01.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 19:01:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-109559-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-109559-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109559-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=QUARANTINE) header.from=huawei.com 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id C4ED9B215E3 for ; Thu, 21 Mar 2024 02:01:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8CFCE5CB5; Thu, 21 Mar 2024 02:00:48 +0000 (UTC) Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (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 7405F187F; Thu, 21 Mar 2024 02:00:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710986448; cv=none; b=Qm1UJ0Rom42ZNaAniVlcVlP47wGDLhJi5B3VlWbrJgLMRGb881FiyUaSm5kyKZJW4sLmfX6uy3Q0LLpKCwx8ycacGSGEJObjMFjJz5RF8fS1z3CkaVdKPLIt93QqFEFXBLYr9OIigJOztff59RKdvth+e5qX5/Gw8gJl4Wyidf0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710986448; c=relaxed/simple; bh=4XNZOZhuU588jqDg6qXSd3S65FNa9UbFKh0DmUDjSXc=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=QCMuMGS1+8yYzXKvbrEIl8bJcFHl8WY2a+eywxYaQCPnoKKpoPGCX+CMWIAlxmVSN/YDvi8AVNciO27A5BjLezg2vDyyYPWyaMyzZdLdg7kOjq4g4MHFIuqp8LP6cFICSxwZqw9/c3cTx7WxDjq3Jwzwr5489nEiXBGn5+6M0X4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4V0TBL2QRLz2BgLp; Thu, 21 Mar 2024 09:58:02 +0800 (CST) Received: from kwepemd100012.china.huawei.com (unknown [7.221.188.214]) by mail.maildlp.com (Postfix) with ESMTPS id 4F6541A016C; Thu, 21 Mar 2024 10:00:36 +0800 (CST) Received: from [10.67.111.192] (10.67.111.192) by kwepemd100012.china.huawei.com (7.221.188.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Thu, 21 Mar 2024 10:00:35 +0800 Message-ID: <0c011cbb-0528-40de-8037-6a76120014fe@huawei.com> Date: Thu, 21 Mar 2024 10:00:35 +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: Xi Wang , Artem Savkov CC: Catalin Marinas , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , , , References: <20240313140205.3191564-1-asavkov@redhat.com> From: Xu Kuohai In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemd100012.china.huawei.com (7.221.188.214) On 3/21/2024 12:15 AM, Xi Wang wrote: > On Wed, Mar 13, 2024 at 7:02 AM 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") > > This tag is not right. It's unlikely that the bug has been around for 9 years. > > Maybe you meant 1104247f3f979 ("bpf, arm64: Support unconditional bswap")? > Agree, thanks for pointing it out. >> 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); > > The fix can pass the tests, but emitting an extra instruction is > unnecessary as the bug applies only to unconditional bswap. > >> break; >> case 64: >> emit(A64_REV64(dst, dst), ctx); >> -- >> 2.44.0 >> >