Received: by 2002:ab2:23c8:0:b0:1f2:fdbc:cb93 with SMTP id a8csp129553lqe; Wed, 27 Mar 2024 00:28:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUTqvZLaJNEM/dL66XXP0byg0wwLBCRCGoR8ZtW0D/hu7efMtNu1mdEZztIAITKdlzXdExARCSXizYO5py4SHqgI2G1vk5grTlYNhPD5g== X-Google-Smtp-Source: AGHT+IEthOB9isJhO1OQzPN/x++rGn/7grc/1a5kvv/XJGb+LgdyrbZLP6lJZyz/OcRuqsDEEoJp X-Received: by 2002:a05:6122:12b:b0:4d4:32e1:e7b4 with SMTP id a11-20020a056122012b00b004d432e1e7b4mr190642vko.4.1711524538207; Wed, 27 Mar 2024 00:28:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711524538; cv=pass; d=google.com; s=arc-20160816; b=gUdv20kMbobI86BuHzh+HkIhjhEhktVc8JnLbu84TWjlko71kOaPBwJeWPHMAWs7ty XWkIZ+tsoYtEs1vSlW2CEjR43tzknzmAWBTDGJKXY/U/pQ/Xck9G8jtOw5NETzAtROpz pwgR6l6oOzr/p//R6cr0DKm7JchOKeDMuE7tdbEv1wtksSxB24hUMVXiUf8KUDOxVlhX 9OGznmAGf79Kcaa3K9+2GD4drqB56SylvXbOVr1kDOPKBrKhbz0ID7zVALvSYDB7cRe2 ps8xjJs40QEjSHNZ53UHMxpPRTzt3fCnL7Nt3PlU+0GDJzVOXrnQY45S3dJMx+3sNBrz 1eIQ== 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:cc:references:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=TJSfqINAfMWq+Q359bfYXWgiEKwBN33az1VBbEy+V30=; fh=KBdqgnBUeqhLs9HjUeC2O5JzOFCpX8YfMxwZgp5V0I0=; b=jltpRWjsAsFj/8DbdPx2c+2I7wtbuaeBN4t4OaekYxg7TNFny8qGy3TwlLyhBhXSHJ /MRPzNAsoGHTxo5/5h/w1aZkE51bw2TlChOrK04Of5OF5/JE2vkMTFdCNNPYbGkLJ5Lj zsj0S4Ak+IEiN13fAd4dTmxvSabMWu8KMZQkh7PzgAKKx/B9vxPH8veml5xwIFKqr3TT ZpQZYCHcxjpUt/HfzEP1jl+FGTVQVk2AANc+tTYu3Hb5lDSKnskGP3hB4PNp2UJwysqu 2N1Ijh8Nbxe/ZaOpsLhm5sEEzK2eOeToHiepazC3QhG+naHYdzt/gpPtcza7d29W7VIf c4Aw==; 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-120431-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-120431-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 7-20020a05621420c700b00690bac7d116si12868133qve.369.2024.03.27.00.28.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 00:28:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-120431-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-120431-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-120431-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 E520B1C23787 for ; Wed, 27 Mar 2024 07:28:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6EB8028DD3; Wed, 27 Mar 2024 07:28:50 +0000 (UTC) Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) (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 69EB523754; Wed, 27 Mar 2024 07:28:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711524529; cv=none; b=atyGNzukVQnMzT9n/FJN+sAOf+EhVB7Cp5Seg6XaD3lUTnsgHUeapoidVh8gQO2dTPvNeBpSKY0fyrT6sdqSboPfxQqn7PRRue8I30RdBpbPdHiLHlvZU8jJMl9pzhWzCwI2snVo2I7Z4nyDWJ5XEwpS/w5FSceQm5OQeJAqcCg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711524529; c=relaxed/simple; bh=zRPikjOVGuxUHj0iYEwFs+kVUlxAZ63d9nP1HOlrotM=; h=Message-ID:Date:MIME-Version:Subject:To:References:Cc:From: In-Reply-To:Content-Type; b=ksRi3QfJYdIWNDzogKBV8m8+9DLDowMh4YDju322dLVxy4FuqDXRnKrDbaOTmeTspgz1MUmDmE+PzxsUwpkPFK/2QUjD/+aDVB+Fzh76Ymf4eVO57HT7CFXYlDul3AsHEwj5LhkW4t3sKhDsumnt6KvHwHTI0owT9a7wZpi9RNo= 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.56 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 dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4V4JF201Dbz4f3khv; Wed, 27 Mar 2024 15:28:37 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 389161A0568; Wed, 27 Mar 2024 15:28:44 +0800 (CST) Received: from [10.67.109.184] (unknown [10.67.109.184]) by APP1 (Coremail) with SMTP id cCh0CgBngQqrygNmXjPeIA--.44585S2; Wed, 27 Mar 2024 15:28:43 +0800 (CST) Message-ID: Date: Wed, 27 Mar 2024 15:28: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 v3 2/2] bpf,riscv: Implement bpf_addr_space_cast instruction Content-Language: en-US To: Puranjay Mohan References: <20240326224943.86912-1-puranjay12@gmail.com> <20240326224943.86912-3-puranjay12@gmail.com> 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 , bpf@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org From: Pu Lehui In-Reply-To: <20240326224943.86912-3-puranjay12@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-CM-TRANSID:cCh0CgBngQqrygNmXjPeIA--.44585S2 X-Coremail-Antispam: 1UD129KBjvJXoWxWw1xXr17Xw4xCw1fAry5urg_yoW5Xr1DpF 45GFn3CrWvqwn7XF13Ja1UWr45Ars5ua12gFy7CrW5XFsIqry8Gw1rK3W5JrZ8CFy8W3Wr CFWY9rnak3s7X37anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkjb4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x 0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG 6I80ewAv7VC0I7IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFV Cjc4AY6r1j6r4UM4x0Y48IcVAKI48JM4IIrI8v6xkF7I0E8cxan2IY04v7MxAIw28IcxkI 7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxV Cjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVW8ZVWrXwCIc40Y0x0EwIxGrwCI42IY 6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6x AIw20EY4v20xvaj40_Zr0_Wr1UMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIE c7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07UdxhLUUUUU= X-CM-SenderInfo: psxovxtxl6x35dzhxuhorxvhhfrp/ On 2024/3/27 6:49, Puranjay Mohan wrote: > LLVM generates bpf_addr_space_cast instruction while translating > pointers between native (zero) address space and > __attribute__((address_space(N))). The addr_space=0 is reserved as > bpf_arena address space. > > rY = addr_space_cast(rX, 0, 1) is processed by the verifier and > converted to normal 32-bit move: wX = wY > > rY = addr_space_cast(rX, 1, 0) has to be converted by JIT. > > Signed-off-by: Puranjay Mohan > --- > arch/riscv/net/bpf_jit.h | 1 + > arch/riscv/net/bpf_jit_comp64.c | 14 ++++++++++++++ > arch/riscv/net/bpf_jit_core.c | 1 + > 3 files changed, 16 insertions(+) > > diff --git a/arch/riscv/net/bpf_jit.h b/arch/riscv/net/bpf_jit.h > index 8a47da08dd9c..5fc374ed98ea 100644 > --- a/arch/riscv/net/bpf_jit.h > +++ b/arch/riscv/net/bpf_jit.h > @@ -82,6 +82,7 @@ struct rv_jit_context { > unsigned long flags; > int stack_size; > u64 arena_vm_start; > + u64 user_vm_start; > }; > > /* Convert from ninsns to bytes. */ > diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c > index 73726f455f6b..77ea306452d4 100644 > --- a/arch/riscv/net/bpf_jit_comp64.c > +++ b/arch/riscv/net/bpf_jit_comp64.c > @@ -1081,6 +1081,15 @@ 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 (insn_is_cast_user(insn)) { > + emit_mv(RV_REG_T1, rs, ctx); > + emit_zextw(RV_REG_T1, RV_REG_T1, ctx); > + 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); > + break; > + } > if (imm == 1) { > /* Special mov32 for zext */ > emit_zextw(rd, rd, ctx); > @@ -2026,3 +2035,8 @@ bool bpf_jit_supports_ptr_xchg(void) > { > return true; > } > + > +bool bpf_jit_supports_arena(void) > +{ > + return true; > +} > diff --git a/arch/riscv/net/bpf_jit_core.c b/arch/riscv/net/bpf_jit_core.c > index 9ab739b9f9a2..8a69d6d81e32 100644 > --- a/arch/riscv/net/bpf_jit_core.c > +++ b/arch/riscv/net/bpf_jit_core.c > @@ -81,6 +81,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog) > } > > ctx->arena_vm_start = bpf_arena_get_kern_vm_start(prog->aux->arena); > + ctx->user_vm_start = bpf_arena_get_user_vm_start(prog->aux->arena); > ctx->prog = prog; > ctx->offset = kcalloc(prog->len, sizeof(int), GFP_KERNEL); > if (!ctx->offset) { Reviewed-by: Pu Lehui Tested-by: Pu Lehui