From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 B35B439891D for ; Tue, 2 Jun 2026 20:59:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780433976; cv=none; b=t4FiVJ5A2GgBJCBqNjGKGzxt4kRC6POUzeTxYrtppRPHXG9ZQSeMkEuOs8cNIg9p7EG6LH/9qUAGuf5jPBxl0eApSwxY/FuYhCIbnyflDMoKCIAJXLrr03P0kGAmX8IwGBhBIKezBeDiWH/jRFvliU1ngTpJbNHgLKjiFGZOC1A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780433976; c=relaxed/simple; bh=40YuMegnizHDre5rP/J67ecYybi5tbv7U9hYJ5stFqg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CIWxnoNGMByjc33X2q/jVlqN4NtVGPgiPLqKVRLy1Y1UVVTWeNDV5Lcne+t3ykeZ7u8vhaqF/28ztpPU7q8huPku/IgPIdkN/cp8rMS7VLCimf5x2cL8rArZg0GfFSMeW2/cLw4tyGyLeqSMqKgjAOtmvKVEmeb4o5LMhtGK/ZE= 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=dBajUGmu; arc=none smtp.client-ip=209.85.214.180 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dBajUGmu" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2bf30d530bdso45023575ad.3 for ; Tue, 02 Jun 2026 13:59:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780433974; x=1781038774; 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=FtyaF8m6RLOpOeiX8WoJduU1Pm23yBD2PG4I02qCKQE=; b=dBajUGmuXiduNnxYDigsK0NW+O8Y0gSoOAmVS3+WiUenfpr0m/M6EgXnWjAuEXMSze wvhmLXm0EpuZoCaNUut9lxp/bEN/iuHNxDDOcktz/V+Z1GrJHToBDWrAXEQJgvtgLZ4v R2liSxLhe0nXYad/K/tA2Sso0bBotJAE/AZIEbF9IKXxLCPjeDsLbmgIS1aFH+c7QbzV zLFlxTjvsuJCiJ0L6h0mM7uwdUMoXt+0FU/LvCbahl01MXA/TrQlVaeP7Gbqw9ooN/1D Xtw/ShTek/R/dcnrIumDF3X7BfakIIBsW/Tgxt7lmEhD/VkGWTsWv4Rvm1FAcGIs0OdV vF0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780433974; x=1781038774; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=FtyaF8m6RLOpOeiX8WoJduU1Pm23yBD2PG4I02qCKQE=; b=o0AXaYNjjdKXRcgG1hBShpLesdBBGEWzZuLfr+cR6/KVAw3oGxzIgVHB61Cz+b8sP5 pHJT1oZWmCZEDib3A7RNvzG5KxEjLJkE6MAbEaJyMDN+JSl+9SMkHmyCfJvOavtg0EaF Xa67gA5Ht+eOSmufo69EUgxcB0R/L17UAvY/PSb+7KRvaDzTMol1+WSh7Cjr6MUkhrLL zMZrXOShig7Tu/J/4JZmA9m19rQtUf4Bo5j9WWecY+cUzjCvfw7MAnKiZw3mHYT1BVK2 wKnXNNqdcfa+5RPrrI0uwx9EkkmFYlK5rOuDHpVzh4cChY1sE0AOxHtn4Vqk0DHkMaCb oSFQ== X-Forwarded-Encrypted: i=1; AFNElJ/Q3FduZnteOmTIJacITfA6yF442BHzCeJGRvo2mu62c6wrDkGB7yDJHOvfzntLVN21F4AWr2z8aJXwA/E=@vger.kernel.org X-Gm-Message-State: AOJu0Yxt22wj0us4Lk6nzXS/HhTkATk5AvJ34J4eAczdthbsdgbEI0N/ WLRRtstCb24WJja/DsKBcV1ypceYr171IbrYBW/nbU1M+1irRWnaz4Gj X-Gm-Gg: Acq92OH+1kirr7I6/VDsqkFPvZJkuP189W3JJ06tRH7pzKVs2ovqnImuQwzCPH3o96b DAGxFBf0R9SpUozOsx+qImlw1DIQDaVg86tM8EVIU9poi90wVpihBWSyCaAfnsh3YcXiUjzB0VA Dvy9qxwKXAwM8hEUunNjxBTkcDvsWgGcWOd0Clg3ANNK6GPFf6PGZwz3N7lsM09ro8frNVR3FZA m89ujcwsDT/WMZqXALLsmDDy4R9QUPZXgkgQyBjpll6Atp188/BjuMOcajAHUkd45iUnGOzSEP5 fIpTNDI3JG41ZSOIaHwWuZ03HBONu5oLuuYyT5+DvHwJx30A1DildF5EMKdjAd8tF75x4y043GE lfzBEq34N8D0A3CNjQIPM1KUZgN685OVsl7manAXziCv9V3xqS/zJsBAbN47IJf8WTn00MLtMhl 5WZ0McUD40mqf6JsC6n4FpMKmlAnRUPXdAGOIg/uwsGNa0uSOQAFoDJl/A7bAvUP4GR6uxm/FA/ QWii4STmCsBvJ2q X-Received: by 2002:a05:6a20:b598:b0:39c:126c:93b4 with SMTP id adf61e73a8af0-3b497449d82mr542621637.9.1780433973930; Tue, 02 Jun 2026 13:59:33 -0700 (PDT) Received: from computer.goose-salary.ts.net ([2a09:bac5:3b4a:11cd::1c6:2]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c85df043223sm157354a12.8.2026.06.02.13.59.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2026 13:59:33 -0700 (PDT) From: Varun R Mallya To: bpf@vger.kernel.org, linux-riscv@lists.infradead.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com, bjorn@kernel.org, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, puranjay@kernel.org, menglong8.dong@gmail.com Cc: martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, jolsa@kernel.org, pulehui@huawei.com, alex@ghiti.fr, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, varunrmallya@gmail.com Subject: [PATCH bpf-next 2/2] bpf, riscv: inline bpf_get_current_task() and bpf_get_current_task_btf() Date: Wed, 3 Jun 2026 02:28:47 +0530 Message-ID: <20260602205847.102825-3-varunrmallya@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260602205847.102825-1-varunrmallya@gmail.com> References: <20260602205847.102825-1-varunrmallya@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 On RISC-V, the current task pointer is stored in the thread pointer register (tp). Emit a single `mv a5, tp` instead of a full helper call for BPF_FUNC_get_current_task and BPF_FUNC_get_current_task_btf. Register bpf_jit_inlines_helper_call() entries for both helpers so the verifier treats them as inlined, and add the expected `mv a5, tp` annotation to the riscv64 selftests. The following show changes before and after this patch. Before patch: auipc t1,0x817a # load upper PC-relative address jalr -2004(t1) # call bpf_get_current_task helper mv a5,a0 # move return value to BPF_REG_0 After patch: mv a5,tp # directly: a5 = current (tp = thread pointer) Benchmark (bpf_prog_test_run wrapping bpf_get_current_task in loop, batch=100, 10s, QEMU RISC-V): | runs/sec | helper-calls/sec | ns/call -------------+-----------+------------------+--------- Before patch | 173,490 | 17,349,090 | 57 After patch | 320,497 | 32,049,780 | 31 -------------+-----------+------------------+--------- Improvement | +84.7% | +84.7% | -45.6% Signed-off-by: Varun R Mallya --- arch/riscv/net/bpf_jit_comp64.c | 9 +++++++++ tools/testing/selftests/bpf/progs/verifier_jit_inline.c | 2 ++ 2 files changed, 11 insertions(+) diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c index 2f1109dbf105..e2c70c70cca8 100644 --- a/arch/riscv/net/bpf_jit_comp64.c +++ b/arch/riscv/net/bpf_jit_comp64.c @@ -1808,6 +1808,13 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx, break; } + /* Implement helper call to bpf_get_current_task/_btf() inline */ + if (insn->src_reg == 0 && (insn->imm == BPF_FUNC_get_current_task || + insn->imm == BPF_FUNC_get_current_task_btf)) { + emit_mv(bpf_to_rv_reg(BPF_REG_0, ctx), RV_REG_TP, ctx); + break; + } + mark_call(ctx); ret = bpf_jit_get_func_addr(ctx->prog, insn, extra_pass, &addr, &fixed_addr); @@ -2138,6 +2145,8 @@ bool bpf_jit_inlines_helper_call(s32 imm) { switch (imm) { case BPF_FUNC_get_smp_processor_id: + case BPF_FUNC_get_current_task: + case BPF_FUNC_get_current_task_btf: return true; default: return false; diff --git a/tools/testing/selftests/bpf/progs/verifier_jit_inline.c b/tools/testing/selftests/bpf/progs/verifier_jit_inline.c index 885ff69a3a62..76d80605ec7f 100644 --- a/tools/testing/selftests/bpf/progs/verifier_jit_inline.c +++ b/tools/testing/selftests/bpf/progs/verifier_jit_inline.c @@ -10,6 +10,8 @@ __arch_x86_64 __jited(" addq %gs:{{.*}}, %rax") __arch_arm64 __jited(" mrs x8, SP_EL0") +__arch_riscv64 +__jited(" mv a5, tp") int inline_bpf_get_current_task(void) { bpf_get_current_task(); -- 2.54.0