From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dl1-f49.google.com (mail-dl1-f49.google.com [74.125.82.49]) (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 5C7323264C8 for ; Sun, 28 Jun 2026 07:34:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782632097; cv=none; b=AY918pEBc8nRqRCMeoWgpwr4u6/T7tWSI9gZXtpeo9xQE7yinX2P3eP3PMjPWG/CT4MrPLyEMC1wBunsx2dxOn7OI4Tt+ajXN2JMyYSb+WQLQlE35qbnAL9elMzNe4wkRmoEUcCdTjnY5UDzsVXgkWpEoqji6ufee7HXt/g8j0k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782632097; c=relaxed/simple; bh=EV8iC9i6Gy9ckKT7DkWM9xWacu6PAtfwN5tasg0SZVY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Ngg9Orx5fdOxR70XVNHIj7htwUMMvfx3YvGrhAdeuug5CXhMrS1INRTwv3JRQTbU7yUDoYw1UKEkwK1OWM6IdnVcZljfN8lIaP6ebRk0FZB4z4XSr+7RC7Jtvu01eCPvoBWEFtkXqdIe/OdJj55dTCM1D9kFN4ye+P95Tf1BIhY= 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.49 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-f49.google.com with SMTP id a92af1059eb24-13809223fd4so2833723c88.1 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=QMPeEufWzq10IVU86tu/p9s8OTRSA4RbcnxQTrn31h5Qu4KSEwW19lEKF2+KrZw+Oe 3q3v51g3XQhzO+aQQBoew9a8bVZRrWLBtHap3T45xelXcGlPr4RGsk5ZuAbuZTMvDNI5 elTNtdSouPGDGH6HMYLmzbsjvVlYJIFMpy2YAIge5UyMA/bIhQTEfRN2qTlKHtkuSnkk a1XL/PXxOBBcsj3gj+LGH+pYOPfifeec+0A0bWhawuMbskZyvKMrEDeg5xW4apUARvmR bGAUtQa1bbvFCnJxPGB5hfJyqr0tq5OCGC6c0kxmxpcHSKVb4Rd4EzrSxz0J7GDhwJX2 BNPQ== X-Forwarded-Encrypted: i=1; AFNElJ8G0TDJ8P6I/C8doRZy62lwh3cvA0tJhXWbET0hdTjs/Kh/m5SIQAdHv62AwFYtxf3sO42E2kdJUSntR3sVX3U=@vger.kernel.org X-Gm-Message-State: AOJu0YyOwjFwDDwbbq2PpIY5NSpp/h6rm+EqzP25JP9saSFmyCyeVeQd M9xaoCTQx7X9ACsVAyDb4MvDFBmPHx/nXkIjh6F4uW00W2HGdqfkIHpZ X-Gm-Gg: AfdE7cmNZ8ZgJJbPp0H6IgOqbZeEmARM69PVhFkVEXTVR/PhNq4bInSgqBOhkB98sw5 Xvd5qOI3ueTf2O58+iOcjshwC+q2q7D8YlFxFse8IDA6BLTVgSjme269ec8VXLp7iwUmGbK8cMC wNzimLZogoMlADvNtRNWdTeRBRF+72hTa3OQEll4gY6LsuL0tGYhuaBe8OoTnI28QRJr9RIdZIF dnFP8i11yHFgkBcKLesiYL2z+RjGBK34hBhKfurhnM7WMNVYEgv7sT5MUWTqMFFSnqtOiamt0DU o6jcYMqHiEE7t1TJ9wPN5H0YHLl6NbDWskZKxFY6fcbmjOe/uyE9vsZZqvdjCqs7HXVldXXar/x d+fZL/ijk/0/9UvdSizcE6iiuhYzAT2NEYDn/Xhm1jk7yc3Efi/8bRgANlBhNBpw8AYpyvp5Jt1 uKttS+RJd6R50c09hk2CPP7zfNi0Vj 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-kselftest@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 > > +}