Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp1984618lqp; Sat, 23 Mar 2024 19:40:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXx7ExGWIhMry1seflwxOJixGlpLcI9F8Pl0/3cMR6Wjtad2WYnIlm0Adi63cEo0gj+BqY2s5iNjyh91VXTjTNNuhYWliJK3gFEMtqv8w== X-Google-Smtp-Source: AGHT+IGLPM8juwDizD3IGo+Rq3IKORiokiJvvB/oUwRBNZwFxeG9DUjzeiSP7KZLat8ztMDZsb+y X-Received: by 2002:a17:906:aac4:b0:a45:231:9b4b with SMTP id kt4-20020a170906aac400b00a4502319b4bmr2468013ejb.20.1711248009125; Sat, 23 Mar 2024 19:40:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711248009; cv=pass; d=google.com; s=arc-20160816; b=NI+eG+dduUXONmaKc71XofQ+Rx38iJ4aVyYCw6gUVhar64jeJoU0OnWZ6Bp1TlK8p6 yhqb/uthBnsWRwMhScaPN8+pUoCYhN2Xt/9sVLFKYothZ7kHySb7z8EiyZL/bln+34qn 0HeiROhPRpeQmFWkXEM36XuChHV82rbGvfWAKIb2tT1Sm/FWlWksAqkSQ4tlwJ0cs1IT 4T9QMpDn7DyKwbp5agT+u3kjrJMAvAU37jaljZuXWMzvGREpM+LKvuIYbZ4r09j3nni1 pDDdnMzdIXFb946e05yca6sHDsg0S77c2l0k9He9VNFK0WT4o2Jul1SDlxrD0bKlpikK jlTg== 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=dlJ0ZejU2enM+rI34olXwOnKFIdFF565acZEnV1osiU=; fh=Yk28nyifHfvvQEbhyCEziw7WCbPbCZy4n3ZuZA9dL6g=; b=Yz7veq2vUmqF1g6DIXAvPwSECAIUCIrnKlZAA6QOZFoXn1r+TxbU5X8d1qN4GrgNet IxkCuJ6/vbM0dyn6wK9MeXxDY5ZSb2iTsoYoWYrJbj49GXmwFVTpdNBsL2sb3PHF2Uhs zQ9MaC+orJEiXpX0YxeYBEGMeyb2O2d4c80Qxqr1l7s+M1oxaSc2tdX7zQRPmp7ihnGs Qa2qM2LhUQRbfp9qIP/Zi6otyRfFUhD/jDDq76w0dlL4/ss/9rjNhKQL8s+xEVzDSC8O Uz5kKSk57OCgL9cIw5L4Gl049yGxG6bwULtl2gnfyAUuRYpz3rDfOL7MMdUDF8VNInQw KEHQ==; 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-112555-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112555-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=QUARANTINE) header.from=huawei.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id qb17-20020a1709077e9100b00a45f83050a5si1267618ejc.1006.2024.03.23.19.40.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Mar 2024 19:40:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112555-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; 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-112555-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112555-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 am.mirrors.kernel.org (Postfix) with ESMTPS id B54721F2231E for ; Sun, 24 Mar 2024 02:40:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6C30B28F1; Sun, 24 Mar 2024 02:39:58 +0000 (UTC) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (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 5C8E919E; Sun, 24 Mar 2024 02:39:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711247997; cv=none; b=piiwxLpYcDM0JzZvRvsTySYzSm3/Rovtkpgl0G7PACpXjgfGGctaDnEwRUVBIM6jKscDoSJJiP+6oPTD5HxdiZ3w5lTcpZtKyDgh9WVETnnfLjwUg3PpdUWbI59iqSGy0r0uqOZXUEHgLOfPYCgLnEGNEHeOWjDGi9QawwpcLgc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711247997; c=relaxed/simple; bh=/vmD1Hg9GT3TdhXbCTlhgCSzd6lXMUJPnovLcw2v91g=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=NZPfvKNKJ88nUpqDtDqvikVbNBaV6eBEDb6X4yXp7MwWvjcLsxTMLKz9TYhj9cYJDh0Bu6wImM+cydIED0IR1HnJSKjiMIuQcEyD7gg2rqdug4vAbdlRTjId/RPIMzewTwRqM3lMiPxYw8IYp3p0PBhk+JB583o39jMzxFowTmc= 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.187 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.163.174]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4V2KwN53PpztQWp; Sun, 24 Mar 2024 10:37:24 +0800 (CST) Received: from kwepemd100009.china.huawei.com (unknown [7.221.188.135]) by mail.maildlp.com (Postfix) with ESMTPS id 9C7CC1404F7; Sun, 24 Mar 2024 10:39:45 +0800 (CST) Received: from [10.67.109.184] (10.67.109.184) by kwepemd100009.china.huawei.com (7.221.188.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Sun, 24 Mar 2024 10:39:44 +0800 Message-ID: <6095ba3b-ffda-4ca7-9da4-d841782006a2@huawei.com> Date: Sun, 24 Mar 2024 10:39:43 +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 2/2] bpf,riscv: Implement bpf_addr_space_cast instruction Content-Language: en-US To: Puranjay Mohan CC: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Luke Nelson , Xi Wang , Paul Walmsley , Palmer Dabbelt , Albert Ou , , , References: <20240323154652.54572-1-puranjay12@gmail.com> <20240323154652.54572-3-puranjay12@gmail.com> <3e07fb21-da08-4183-8bd4-064b519c7ddb@huawei.com> From: Pu Lehui In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemd100009.china.huawei.com (7.221.188.135) On 2024/3/24 0:49, Puranjay Mohan wrote: > Pu Lehui writes: > >> On 2024/3/23 23:46, Puranjay Mohan wrote: >>> LLVM generates bpf_addr_space_cast instruction while translating >> [snip] >>> >>> /* Convert from ninsns to bytes. */ >>> diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c >>> index f51b832eafb6..3c389e75cb96 100644 >>> --- a/arch/riscv/net/bpf_jit_comp64.c >>> +++ b/arch/riscv/net/bpf_jit_comp64.c >>> @@ -1083,6 +1083,16 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx, >>> /* dst = src */ >>> case BPF_ALU | BPF_MOV | BPF_X: >>> case BPF_ALU64 | BPF_MOV | BPF_X: >>> + if (BPF_CLASS(insn->code) == BPF_ALU64 && insn->off == BPF_ADDR_SPACE_CAST && >>> + insn->imm == 1U << 16) { >>> + emit_mv(RV_REG_T1, rs, ctx); > + emit_zextw(RV_REG_T1, RV_REG_T1, ctx); >> combine mv and zextw will be better > > Do you suggest doing: > > emit_zextw(RV_REG_T1, rs, ctx); > > Will do it in next version. > >>> + emit_imm(rd, (ctx->user_vm_start >> 32) << 32, ctx); >>> + emit(rv_beq(RV_REG_T1, RV_REG_ZERO, 4), ctx); >>> + emit_or(RV_REG_T1, rd, RV_REG_T1, ctx); >>> + emit_mv(rd, RV_REG_T1, ctx); >> ditto, but for or and mv > > How would we combine or and mv? > also, we have a beq above and in one case both or and mv should happen, > but in other case only mv should happen. > Okay, another branch is that t1 is zero, but not rd. > Thanks, > Puranjay