From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dl1-f48.google.com (mail-dl1-f48.google.com [74.125.82.48]) (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 50AFD31716A for ; Sun, 28 Jun 2026 07:34:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782632096; cv=none; b=Hm1xUKzRvNd9MjxLQm3YqXdMeH0ftu0r5cHIBdNZb45dDOSs1bTzhWolm/a9a7E7qNI0Rp/tZReHGpOp+geN68z42cAvxt4UqJ6tzNv7HbJd1KsrYWu8RgboCeVCrcEuHCAJUyw0uP1RBgp2OpFoFuz+Kvp78M3UPqn2WZ4rrP4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782632096; c=relaxed/simple; bh=EV8iC9i6Gy9ckKT7DkWM9xWacu6PAtfwN5tasg0SZVY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=FI3CqV/GAWG0NbMXT93UXyO+fYT9ap25eKO+FBzaaO+NNB++PPOGK38zJiC8ImFgjfOqRBhBeXFithlcJmQaaVopeBZGa7QyGppBuEKx/gmovBcmRSmWBB0zx5xTHW8nsV1hYSCCc38Ca7yorjew/GWmEX6Y+8DLZZW/P5fHUvs= 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=oKHB573e; arc=none smtp.client-ip=74.125.82.48 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="oKHB573e" Received: by mail-dl1-f48.google.com with SMTP id a92af1059eb24-139f1dfc9faso1092362c88.0 for ; Sun, 28 Jun 2026 00:34:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782632094; x=1783236894; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=vledIumPthBBbn2WzmCtAqEFwAG6SWS4TJU6ZxwEn40=; b=oKHB573ejPdUdQCoJvdQCIumBBpn4SJjQrB16z78AnsCJie07bAtUcXsI4GQrLErXq VbQdV58QNAM4PNvFDn74QjrKGqLqxjcV9NXl20R2os1VBDFhIuXMbSINWSsFHkvsyxl8 7W+l5cHt+x8tD4R8isJA9Mh8WYa6TZ9vNJ5TkyKBhdEOq3O60/8MPytTP/BtRszyyJo4 RD3b69FDr3PLqUY7HbTzHVB1zcaTgKikhcA3DXf5E6EFGvx/Zqo3qay5lZ3nl9xopdQT qxGajDNGvwnucpCiY9Xz4PTVH+FQ6BOxCWtEMJaapD7cAl7OGWygVBU2UpcdFNFdww61 oOEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782632094; x=1783236894; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vledIumPthBBbn2WzmCtAqEFwAG6SWS4TJU6ZxwEn40=; b=FBmWrMkGcqZFs1jywnS+ynE3koPOrA6Ah50ZSQoMxyunY4paV80OrLKa1yombtbS9S gaC0eWCXjbd1z8bTlcLkyV1DvVXyJxQAyPX2Iu+OhDRG6GzK0FJgkQoRQK1oJhiBpbUM hM/9zb1xZAZwKHDFYTg4GZswiA1q7QuX6rJX+PC9gW600tkxOrN1PRkVckuxnWgXrAcf LRxP5gWoaL5QaNTmTON78USlwCt5TmsuJ4Dz97Ov7fY6C9269z6bkiuU1iYMa6dRqEDn HAaUCMKXKjmfs3aejTeZFUkjTTqK5P0syWeOfitvlcIb8SUv92i9Zjg3ZOXwyRqje2w7 dxmw== X-Forwarded-Encrypted: i=1; AFNElJ/Q9kBaKXseMkXEoOgS/hdnjtI10LiOCSzeXKLs0IkLopBofA2GMDNs0w/l63y2cvAz3scZvtccCaTmKxU=@vger.kernel.org X-Gm-Message-State: AOJu0Yy1hftj9jUGF6dukGzsKKrt51E9SL5prylT+mIRem/024WukTY9 316z4Z9XAjH4DJdzEJm01kj6bTJVAKePLjImCD1MwYto7lXuiOhb7rlI X-Gm-Gg: AfdE7cl0Rw1hbdURAryN74YeyDRCaXKTA3bdchx3iedYiOuBwlUbo/3YXvF0O0QNyMF sGd9oWitkatN+iAp2S1NRRmeMw7/2DZ3QL9qnQRNhBxmFDJjZgnqrvZvoMGCqzloe33Whp2LpHu VYAv+Zk6LB5MsOcY+YQ+oyRR/mS0ntSak3zAkzsBtk/LuiLq6P3jYVjgTosDSLCn0enomgP9PCJ AZbpDufyZgap1puGFZyFtHZoy0XTi2w66jkWgeZ77PRoXXqR9v0OP8OEnu1D5IKE/FyRP63o68m 8xHYypnjJisEOU+meVAfs44xtUuHkX4s775LkqIpz4uvW0cACWSu7PyoQaWQBtucOw8YFllIP38 nxsZe45II0bAgth6k6K8F1EpNtbiFzEGQZpVYr3xwVVIJPiIWNVW/shgg4Rm4eX3opDx71csMZz TykrdfUeOXkT1WYwUkpnrTu8NqNQeD X-Received: by 2002:a05:7022:f694:b0:138:637:6227 with SMTP id a92af1059eb24-139dba0a865mr13084203c88.11.1782632094282; Sun, 28 Jun 2026 00:34:54 -0700 (PDT) Received: from computer ([2a09:bac5:3b4a:8aa::dd:15]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-139e42338f9sm19928106c88.0.2026.06.28.00.34.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jun 2026 00:34:53 -0700 (PDT) Date: Sun, 28 Jun 2026 13:04:42 +0530 From: Varun R Mallya To: Pu Lehui Cc: pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com, bjorn@kernel.org, alex@ghiti.fr, martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, jolsa@kernel.org, emil@etsalapatis.com, puranjay@kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH bpf-next 2/3] riscv, bpf: Add support for BPF exceptions Message-ID: References: <20260621144259.288135-1-varunrmallya@gmail.com> <20260621144259.288135-3-varunrmallya@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Tue, Jun 23, 2026 at 10:11:57AM +0800, Pu Lehui wrote: > > We don't need to duplicate code. Please merge it. Making this change in the next version! > > + > > + if (!aux->exception_cb && aux->exception_boundary) { > > + /* > > + * Boundary program: allocate the frame and save the > > + * full callee-saved set, capturing the caller's values. > > + */ > > + emit_addi(RV_REG_SP, RV_REG_SP, -stack_adjust, ctx); > > + for (i = 0; i < ARRAY_SIZE(rv_exception_csave_regs); i++) { > > + emit_sd(RV_REG_SP, store_offset, > > + rv_exception_csave_regs[i], ctx); > > + store_offset -= 8; > > + } > > + emit_addi(RV_REG_FP, RV_REG_SP, stack_adjust, ctx); > > + } else { > > + /* > > + * Exception callback, reuse the boundary program's > > + * frame, whose frame pointer is passed in a2. Setting > > something confused—why is it A2? I feel like I missed something. bpf_throw() invokes the exception callback as bpf_exception_cb(cookie, sp, bp, 0, 0) , whose 3rd argument (which, according to RISC-V's calling convention resides in A2) is the boundary prog's frame pointer. Since this else branch handles the callback, it expects A2 to have the frame pointer. The arm implementation does something very similar with emit(A64_MOV(1, A64_FP, A64_R(2)), ctx) where A64_R(2) is the third arg. > > + * SP = FP - stack_adjust lines the epilogue's loads up > > + * with the registers the boundary saved. > > + */ > > + emit_mv(RV_REG_FP, RV_REG_A2, ctx); > > + emit_addi(RV_REG_SP, RV_REG_FP, -stack_adjust, ctx); > > + } > > + > > + goto tail_setup; > > + } > > + > > if (seen_reg(RV_REG_RA, ctx)) > > stack_adjust += 8; > > stack_adjust += 8; /* RV_REG_FP */ > > @@ -2082,6 +2173,7 @@ void bpf_jit_build_prologue(struct rv_jit_context *ctx, bool is_subprog) > > emit_addi(RV_REG_FP, RV_REG_SP, stack_adjust, ctx); > > +tail_setup: > > if (bpf_stack_adjust) > > emit_addi(RV_REG_S5, RV_REG_SP, bpf_stack_adjust, ctx); > > @@ -2157,3 +2249,13 @@ bool bpf_jit_supports_fsession(void) > > { > > return true; > > } > > + > > +bool bpf_jit_supports_exceptions(void) > > +{ > > + /* > > + * bpf_throw() unwinds by walking the frame-pointer chain from inside > > + * the kernel back into the BPF frames (see arch_bpf_stack_walk()), so > > + * exceptions require the frame-pointer unwinder to be enabled. > > + */ > > + return IS_ENABLED(CONFIG_FRAME_POINTER); > > riscv select ARCH_WANT_FRAME_POINTERS, so this will always true I checked that the kernel compiled even when I turned CONFIG_FRAME_POINTER explicitly off, so not gating this would be a mistake, right ? ARCH_WANT_FRAME_POINTERS makes CONFIG_FRAME_POINTER user selectable and makes it default to true, but it's not always true. What does force it is PERF_EVENTS=y but if that too is turned off, then CONFIG_FRAME_POINTER can also be turned off. Thanks for the review!! - Varun > > +}