Received: by 2002:a05:7412:b795:b0:e2:908c:2ebd with SMTP id iv21csp517170rdb; Thu, 2 Nov 2023 09:59:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFO8Xh8gJ7A+ezmeZgU7R6pRKKHH6KwtN8zlXUCZ2y595+0+d+lHprktOXUwH88VitoQGRw X-Received: by 2002:a17:902:f391:b0:1cc:fd1:c85f with SMTP id f17-20020a170902f39100b001cc0fd1c85fmr13929947ple.22.1698944395888; Thu, 02 Nov 2023 09:59:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698944395; cv=none; d=google.com; s=arc-20160816; b=pthma82b2o/ger5nxG3nKgS1WrjGKlfvb0xqNZyDzY7sRPUJiP1bLw6th9EsAhJqu9 zpNchjWOffVIJB7bNrELoLziFxk7wWd3zZhVcgqYIpLcGZgg5GwU6oPitHVQNe5tHmX7 V/Lnn0PyjmAz8Ona7jrsAMMUPsBQ76+Nc7TNy4yRPldMUZv+2H7eeHU7xPGwneveyOri 1Peccs7nrW5XjyjfIyxW8xjTZlr7expMecOIzl4aH166CCN/Qg52aIZ9S+pOpGOeCDOd VIa+HjANPh7biP2m/ntmOc7Lgg20mN18JJ1c3oF7gERLskH7grcmb47Dk73wAe8/kztH xdDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=qVDmqy32kfNuAumzg9Mk+S/QSc00yHsZhNScQO+2LN4=; fh=4a+UQK0/yEMPhRKcE8sR4tOYyNFGBn372Hojxz8yuW8=; b=fQl5cDZp+gpNPOEy7m6K68YkN0Ahe2xSczPGCA6O9B5oN/RcYjIsJcNAs1U1/hk5mK j9cDYAiK47XyZ4bMvo0cc/SVf971+JlnUhD4v33mC/XY0uCDWicw1AxN2Uu0M/b5sNDF 3+jeczwIHRqYm0n453DDWgVUssnY3rfZunjE8khfcrfldhXH6WA/8q9Cnl7XXWhNONMa XoVPr75xGAUbxW9k5xX20Eeh+ryrz+t/XgOZY36ApBx+2MzgpujX6RUB7omx8DgYWzQS QEBvQk+ygUDetShksu++CzmGkmptQzb9/NZQSegZPtR/Ow2oWWSliWvXocsPrNXNsoB/ ElEA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id kv15-20020a17090328cf00b001ca87c9e9d4si130590plb.598.2023.11.02.09.59.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 09:59:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id B1105837D968; Thu, 2 Nov 2023 09:59:52 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347626AbjKBQ7f (ORCPT + 99 others); Thu, 2 Nov 2023 12:59:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235479AbjKBQ7e (ORCPT ); Thu, 2 Nov 2023 12:59:34 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A5F3113A; Thu, 2 Nov 2023 09:59:31 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id AD8972F4; Thu, 2 Nov 2023 10:00:13 -0700 (PDT) Received: from FVFF77S0Q05N.cambridge.arm.com (FVFF77S0Q05N.cambridge.arm.com [10.1.27.166]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F1FDF3F738; Thu, 2 Nov 2023 09:59:28 -0700 (PDT) Date: Thu, 2 Nov 2023 16:59:26 +0000 From: Mark Rutland To: Puranjay Mohan 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 Subject: Re: [PATCH bpf-next v2 1/1] bpf, arm64: support exceptions Message-ID: References: <20230917000045.56377-1-puranjay12@gmail.com> <20230917000045.56377-2-puranjay12@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230917000045.56377-2-puranjay12@gmail.com> X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email 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 (fry.vger.email [0.0.0.0]); Thu, 02 Nov 2023 09:59:52 -0700 (PDT) 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-saved > 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 on > 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.rst > > 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[] = { > + 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)? > + > + struct unwind_state state = { > + .stacks = stacks, > + .nr_stacks = ARRAY_SIZE(stacks), > + }; > + unwind_init_common(&state, current); > + state.fp = (unsigned long)__builtin_frame_address(1); > + state.pc = (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 for 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 addition to the PC. Is there any other reason you need to open-code this? If not, I'd rather rework the common unwinder so that it's possible to get 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=arm64/stacktrace/metadata ... and I'm happy to rebase that and pull out the minimum necessary to make that possible. Mark. > diff --git a/tools/testing/selftests/bpf/DENYLIST.aarch64 b/tools/testing/selftests/bpf/DENYLIST.aarch64 > index f5065576cae9..7f768d335698 100644 > --- a/tools/testing/selftests/bpf/DENYLIST.aarch64 > +++ b/tools/testing/selftests/bpf/DENYLIST.aarch64 > @@ -1,6 +1,5 @@ > bpf_cookie/multi_kprobe_attach_api # kprobe_multi_link_api_subtest:FAIL:fentry_raw_skel_load unexpected error: -3 > bpf_cookie/multi_kprobe_link_api # kprobe_multi_link_api_subtest:FAIL:fentry_raw_skel_load unexpected error: -3 > -exceptions # JIT does not support calling kfunc bpf_throw: -524 > fexit_sleep # The test never returns. The remaining tests cannot start. > kprobe_multi_bench_attach # bpf_program__attach_kprobe_multi_opts unexpected error: -95 > kprobe_multi_test/attach_api_addrs # bpf_program__attach_kprobe_multi_opts unexpected error: -95 > -- > 2.40.1 > >