Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2835725lqp; Mon, 25 Mar 2024 10:30:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXNLEkODFrxOcpojdV2+ixXJ17b6Rj2HP3uXoC4IqhazpXYUoK1yxMFYSjF8w1jpUdpVWmSOg8gFbT1r4OhiBumhUyKLiMJtDY8IWUkDw== X-Google-Smtp-Source: AGHT+IGT8jyABA8mGDVoRSdKhZv0bKK0hYAxkuH7/KMdvzTwHUBSiEIuTOhpAVIVCoeBjLreBVaF X-Received: by 2002:a17:90a:a404:b0:29b:33eb:1070 with SMTP id y4-20020a17090aa40400b0029b33eb1070mr438157pjp.14.1711387836651; Mon, 25 Mar 2024 10:30:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711387836; cv=pass; d=google.com; s=arc-20160816; b=sEjhDgqHjCUJIQGbQpiREX6/CyX43h0F2Of5ttYls+07lnYm4Qldw0Pb+zB+gEy34g cdSOl20/Hug/Sp4db4+SS3yQvtz//GlEgzvu7yeK9MzvrTF8Z7k1RrNUIcDPMVVnu5o3 ituYuf1huzmI5fhiCa6H+LpK6QLuIMwS6I59FK8vNelkz/oiiRQTp8Sqod4OeQbXDTw7 1YYUD3cSqOCxiNCDMUuxDhJqmtoSro6Bax7c2aGJ+igd8wKuBb7Y6vKsiO7RxG3wE1di iZdz4DlpVCuBWbOg47q9U8jCPvLFq1rtPYG9ZSNe1h1nKwN9WY3w2Z5X0QM7lt9c/v5x XYPw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=EmdLkk4cUe3qGPre+9kRw6NuC0B6UnfZpAvLyG4RAn0=; fh=bO15ipxIWQZJJBp0idUkmhN3tvobOLsxhtc/t8qEnSY=; b=ew0n6LdYIpnWbxJdO80clOvHnUfpSnOyNjBJkwSRpYNvZligJtN8gZST0tPWwiPzPD 11IpHG99/g4+cGI5T2sjahQSN3tNlIO1ODpXhm07c5wgYVNeBZt79Xgcj/Pjtz+tBqmj OUa0i9Fu6GNxbUD6EZBtxlkrf3V6K2EyK9gQRONx4V36iVitUQfVS0c34N3yIrSh4Ohn QN8UWyQEiczmyDjHP2tQEWcg4MV3unw/zNS9pWvFd+CD6S9ulxpyQGX+XtPV5VTYVEnZ 0730tudkkT98giYoxpdojsgpxzATuK+IPS/BwfMUdnQj3qzH9mNzTbeIVQELoA2/HB5c JjIg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=m6y84QBk; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-117418-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117418-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id k7-20020a17090a9d8700b002a0345c7909si7989856pjp.181.2024.03.25.10.30.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 10:30:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-117418-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=m6y84QBk; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-117418-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117418-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id E570E368C8A for ; Mon, 25 Mar 2024 17:15:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8B2A114EC64; Mon, 25 Mar 2024 15:54:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="m6y84QBk" Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0965A14EC48; Mon, 25 Mar 2024 15:54:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711382089; cv=none; b=PIDGkPUKzYh0w7zOo/SYQv5uEAMEMzaGz0u+9mYArYuy9vdXTBtRnEMEMQ2rIfE7xjmSMLy11DIc2OuqlJYMhCG2lxd+/5o4FPj4D/BUqgOSCBdoqPAN09o+pIIUZnUgXcivZjHfk3pbmWkeqhL0bd2qDKfxCEWvSY6PqwBf2DA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711382089; c=relaxed/simple; bh=VELhCbkpXwTeoCJK5f8UCZ2Pu8ss77KS0iQmHtC4trU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=S2zmiGseYq2bMJa9nfxIgNCfPFKtTcXLsjKBHs3BMnvhrSIOpEXThHzUMAWTdXlXDdrnIV4JkGYke4yAXze47KoinChyXKUdCn3LmHnbwkzZWyCZVW1JkxtaxDLdK3xM2OJBSdzbYE9qRMIyERWSfYZhpD6Bo/2KGPgVUZp1RoY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=m6y84QBk; arc=none smtp.client-ip=209.85.208.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-2d4a8bddc21so61966291fa.0; Mon, 25 Mar 2024 08:54:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711382086; x=1711986886; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EmdLkk4cUe3qGPre+9kRw6NuC0B6UnfZpAvLyG4RAn0=; b=m6y84QBkorqqLu3kZiqL3xrvbXWOF1+3RXVrgP6VdEdLh44h7u5/Ae3823Kq818hrx cJS9+lQFzQvh8P0v6FDVeMZ+jFxSDBfrAjWhKzLi0CwK4qDhUIE5AH9IIHIVeKJNE8h9 a7a1ZsB+gIrNEz2NU7pjey/nfBzgwMlNPOGKhN8pxICV3/Umm+/iDQkdOrqkEJNizZDX LKnP8k3jx0WoVPAyN3p9yLA8JuuCxj6ZVqr1bF2YTyUUT4cTx2U7ZJY6EvUIoaaFvlY4 E5aams5KfvXI0epAZyZGN9EICwxENS0behz5d3O0HZZAR/d/HhBkK703SKA5ArIsl00M qJ5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711382086; x=1711986886; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EmdLkk4cUe3qGPre+9kRw6NuC0B6UnfZpAvLyG4RAn0=; b=axtqSNK80uQ6/tALaGxHBHobkyPQ8yY4l9fbddeCXhQY65NhfbC/XZM+BFzF33uBhh yg8qhjXA8PAsuEUj+K3CAF4shawrpFGbQ3EGliIs9DD6nB6Gu/kO7MKFq8+tuNBuh5eM Tcb93gt7RsvFVca59kQAaXrbqvKbpqLELGUi8xYL/n6Du3Oyh97AZ+xhT8S5HL3bygf4 yN2dXagwDLHvJjTpiYdqZry05eG+8NWeEAr96QxOr84+TRH1F0q9NVR5qgChrKblIZCD FqwG/sBtEGwdAeJetlPHRCMooTxH5qiBJ7ny+eGxmUJp2GIUDIEIU4b3i3aHyqDwsQ1Q pk5A== X-Forwarded-Encrypted: i=1; AJvYcCVfWs0vMmIP17XzWBoReD4lqhshStS7Qo3wJKO7fVim7Fw2oqMHV3qh7LGtb13hOOxpZjbuaIjmWq46sqZGAJdTVFVQpQIxdSSQ84zpLsWvnM94EVLtGyj2CpTIILYPGI6l X-Gm-Message-State: AOJu0YzlXRnroRGOOQ/HDK0ftrH+viLMSi7TirMSQ2b4wIqm8iUdQa70 /iYMLZarAnqOn7yajLMKJo4ay/mFAXUEFFOquATqePIcMDSkj1tz X-Received: by 2002:a2e:8014:0:b0:2d6:a699:4bae with SMTP id j20-20020a2e8014000000b002d6a6994baemr4873921ljg.6.1711382085892; Mon, 25 Mar 2024 08:54:45 -0700 (PDT) Received: from localhost (54-240-197-231.amazon.com. [54.240.197.231]) by smtp.gmail.com with ESMTPSA id iv16-20020a05600c549000b0041409cabb39sm8734384wmb.18.2024.03.25.08.54.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Mar 2024 08:54:45 -0700 (PDT) From: Puranjay Mohan To: 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?q?Bj=C3=B6rn=20T=C3=B6pel?= , Luke Nelson , Xi Wang , Paul Walmsley , Palmer Dabbelt , Albert Ou , bpf@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Pu Lehui Cc: puranjay12@gmail.com Subject: [PATCH bpf-next v2 2/2] bpf,riscv: Implement bpf_addr_space_cast instruction Date: Mon, 25 Mar 2024 15:54:34 +0000 Message-Id: <20240325155434.65589-3-puranjay12@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240325155434.65589-1-puranjay12@gmail.com> References: <20240325155434.65589-1-puranjay12@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 0c0588e327af..a5f049e72da2 100644 --- a/arch/riscv/net/bpf_jit_comp64.c +++ b/arch/riscv/net/bpf_jit_comp64.c @@ -1083,6 +1083,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) { -- 2.40.1