Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp1992770rdf; Mon, 6 Nov 2023 01:04:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IHrP92TTWx3t1FOB6brhbDpmNpX+3kl2f2gEDU1S+68vGfpKiviBxusTdBByPYH1zM3i0hr X-Received: by 2002:a17:90a:7e8d:b0:280:ff37:8981 with SMTP id j13-20020a17090a7e8d00b00280ff378981mr1312566pjl.44.1699261468802; Mon, 06 Nov 2023 01:04:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699261468; cv=none; d=google.com; s=arc-20160816; b=BHmYXEN3VuEySILjnW51YvDoiXtkwIq/69dHzYWR/rUhF+zHnosG90qMNhqpyh651D Bw3AvCCuLba76V9tPHQ5CsEKZus6XwYv6o0mnUFlISL2R+OkTtxJffbJ1WNTtMD+GyAu g9DKO60vDmx1ML/qFhfCMUSeEGOSitAOts1QPMUN98yguhPW455pWZC6gjSMoA7SKxHS aI/RM4B0uHNFv94XlMLVUgS70Lnqj3ryrDQraNotR8iPojPe8E8tdtu2R3IIA8SBrOae 4LYxpcmp4DCRSRwMsARlQz4qMCi1BvrCMDpZvYi0tpCgnnJov/BT63IYhc/JyRtoJZ5t G/VA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=i/8Dv00RFeRNB2AjmLS+laUWw316tnEfZnwqT3z8dIA=; fh=hvJtFy8b+Nt26GPt5jgWzSOmOrD5QmwAkKvzBnW0wTA=; b=gR+YRDi/Df1EsO4qdz0j/pKTB/HXlYGvZmQ39BjyNLObbNRArw4Zm12lo35DOnQGEN x4qkMqBDkDCeiCfbSTBq2YMv06RvAeQSCfomz6OCcJDwfCysVSI1ImJ8m3pYf0RuZB51 2kEuHyGgrW2MVLo5o5ZliG+K+1hS19v95FxQGEQYsUY4jw+QDmCKhotRrqJSD3v7Hxi0 whjtAzJRm2cvA2b/A80y1LxMbrbwbk3TzvtztnjjlcqHTQOkiwM9fRN2OnKQLAWY6Y/E eJsJn9ShI3C0vaSxotXSo9SZUK2gR/Ex25lxjbg3i+ZUxbXGo8pt1Bwbw6L0k0TAbWRu pX6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=NXzg5zQm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id my17-20020a17090b4c9100b00280468bfb94si8422930pjb.185.2023.11.06.01.04.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 01:04:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=NXzg5zQm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id C0326802C654; Mon, 6 Nov 2023 01:04:27 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231266AbjKFJE0 (ORCPT + 99 others); Mon, 6 Nov 2023 04:04:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230475AbjKFJEZ (ORCPT ); Mon, 6 Nov 2023 04:04:25 -0500 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBF4583; Mon, 6 Nov 2023 01:04:22 -0800 (PST) Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-5079f9675c6so5559545e87.2; Mon, 06 Nov 2023 01:04:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699261461; x=1699866261; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=i/8Dv00RFeRNB2AjmLS+laUWw316tnEfZnwqT3z8dIA=; b=NXzg5zQms1jQzPvUf6x+JBwhYRznCCL42gLi2a9ryWtgCZiyZH/cgyHyVcG+TLsR0h cykJ0y27680DJLbYfaqLCFFs8LdrGug4+FuWGgzaJ2zP1OyvrDYgMZ7gepJZi5golY0K OIKIf3hpB3eGxwvqtPdOjwbZr5N7R9HoI2cFJklznuNe9sUk0JRarv4TVgmgLSwK2gZK oxCcGofOhoanoZeeNDwkUCc59eoUafGfzCmera7LAqBJuFV8T/Zxrlo8VffjN9aeQfe3 6BF8eMWtDBlcZs6GchTy/mqerXxJRruCVQdruPtx1HpVYT5L4Md7wRK1+wKysJHO98zC 4Pew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699261461; x=1699866261; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=i/8Dv00RFeRNB2AjmLS+laUWw316tnEfZnwqT3z8dIA=; b=S1OlEWJKjmUrJhVGxjTsOAhwFMk+mAEubUnwpZi+cFk5qVJakeiSZzPMUPjWQXHN51 Pajft3dAbm6rkCPcVwvGfY8q6Ju2mt714jzf5lR7vQTp4rylIpiq3agtcB4VdMnnpkw6 OhBkBgUUXsyKuZPulCu5rDhrwlk/+tidVeWtmWq8n8b4cRESR1fW97bmWlPrDAQ8MWrn R3OKIZUWLkIOLThnpi1Dp0ET4JtaHU4yCCspren9ixqI05yGxBKxtQR2SRZc9u6U6alA xTfUWJZCPt2OmHRpEXPElKppDgfwJle903sVV+uw06z5pKwR9J+DD0n6LsMoQJI3IbVR l7jA== X-Gm-Message-State: AOJu0Yw9FOeIb4EFl6yOQ4FHotK9xDOET40Vh84NLnKl5DCx6U1O4xPW RdjRoWZhu2LXp2H/yrq3c+DRK/M9dz2VCFDqkeA= X-Received: by 2002:ac2:54b7:0:b0:508:1aa7:dffa with SMTP id w23-20020ac254b7000000b005081aa7dffamr21919345lfk.18.1699261460489; Mon, 06 Nov 2023 01:04:20 -0800 (PST) MIME-Version: 1.0 References: <20230917000045.56377-1-puranjay12@gmail.com> <20230917000045.56377-2-puranjay12@gmail.com> In-Reply-To: From: Puranjay Mohan Date: Mon, 6 Nov 2023 10:04:09 +0100 Message-ID: Subject: Re: [PATCH bpf-next v2 1/1] bpf, arm64: support exceptions To: Mark Rutland Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Zi Shen Lim , Catalin Marinas , Will Deacon , bpf@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Kumar Kartikeya Dwivedi Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 06 Nov 2023 01:04:28 -0800 (PST) Hi Mark, On Thu, Nov 2, 2023 at 5:59=E2=80=AFPM Mark Rutland = wrote: > > On Sun, Sep 17, 2023 at 12:00:45AM +0000, Puranjay Mohan wrote: > > Implement arch_bpf_stack_walk() for the ARM64 JIT. This will be used > > by bpf_throw() to unwind till the program marked as exception boundary = and > > run the callback with the stack of the main program. > > > > The prologue generation code has been modified to make the callback > > program use the stack of the program marked as exception boundary where > > callee-saved registers are already pushed. > > > > As the bpf_throw function never returns, if it clobbers any callee-save= d > > registers, they would remain clobbered. So, the prologue of the > > exception-boundary program is modified to push R23 and R24 as well, > > which the callback will then recover in its epilogue. > > > > The Procedure Call Standard for the Arm 64-bit Architecture[1] states > > that registers r19 to r28 should be saved by the callee. BPF programs o= n > > ARM64 already save all callee-saved registers except r23 and r24. This > > patch adds an instruction in prologue of the program to save these > > two registers and another instruction in the epilogue to recover them. > > > > These extra instructions are only added if bpf_throw() used. Otherwise > > the emitted prologue/epilogue remains unchanged. > > > > [1] https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rs= t > > > > Signed-off-by: Puranjay Mohan > > --- > > [...] > > > +void arch_bpf_stack_walk(bool (*consume_fn)(void *cookie, u64 ip, u64 = sp, u64 bp), void *cookie) > > +{ > > + struct stack_info stacks[] =3D { > > + stackinfo_get_task(current), > > + }; > > Can bpf_throw() only be used by BPF programs that run in task context, or= is it > possible e.g. for those to run within an IRQ handler (or otherwise on the= IRQ > stack)? I will get back on this with more information. > > > + > > + struct unwind_state state =3D { > > + .stacks =3D stacks, > > + .nr_stacks =3D ARRAY_SIZE(stacks), > > + }; > > + unwind_init_common(&state, current); > > + state.fp =3D (unsigned long)__builtin_frame_address(1); > > + state.pc =3D (unsigned long)__builtin_return_address(0); > > + > > + if (unwind_next_frame_record(&state)) > > + return; > > + while (1) { > > + /* We only use the fp in the exception callback. Pass 0 f= or sp as it's unavailable*/ > > + if (!consume_fn(cookie, (u64)state.pc, 0, (u64)state.fp)) > > + break; > > + if (unwind_next_frame_record(&state)) > > + break; > > + } > > +} > > IIUC you're not using arch_stack_walk() because you need the FP in additi= on to > the PC. Yes, > > Is there any other reason you need to open-code this? No, > > If not, I'd rather rework the common unwinder so that it's possible to ge= t at > the FP. I had patches for that a while back: > > https://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git/log/?h= =3Darm64/stacktrace/metadata > > ... and I'm happy to rebase that and pull out the minimum necessary to ma= ke > that possible. It would be great if you can rebase and push the code, I can rebase this on your work and not open code this implementation. > > Mark. > Thanks, Puranjay