Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp257952imw; Fri, 8 Jul 2022 02:22:37 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vIEEKlhPH39DPsKlYwiAwCO8VU0yqNXM7tyU+z2gBl8e/nS7jFJ6cs9Wv0MmsYQIitdHo6 X-Received: by 2002:a17:906:9b8a:b0:722:e6e0:33d with SMTP id dd10-20020a1709069b8a00b00722e6e0033dmr2483060ejc.317.1657272157546; Fri, 08 Jul 2022 02:22:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657272157; cv=none; d=google.com; s=arc-20160816; b=v6eoXP7K9Ee6zFZ8+wkVdptmYlxtleQYf9JBJX33kO+VpG93Kx2CnSnFtW1k8hAaSe +jxQysVsE3dHdSBYGzUxa0Pyfx+sCTfoaMXaiTps5+sl8gIDGsXwuE96L1f4Q6SCJydL +H26jkocL6Zsk5SAwJJ9GyaSnUmQ4d7X1GsbYFZTrNA5WYpMPepLTg7xjmTjZ+8X38kn m0bWUvE3k44yPIuKEhp+9NOVaj3ZBk3Z+PVa21xbVBjZeGXlWokj2LsEKX15QbUxzWiz vOcANkn6znely60Sf4D7IY/ogFUg2VKJorhSPV41kBDMGAvnVYiISNuILM+PouYG0bgt xQZA== 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:dkim-signature; bh=mIwFg075RvwVYz9+/Y+xL9IEwu5sJHlYJ/YyVZSg0lY=; b=xY07BhBjFzQ19TSKFvqQ6LVK0Cbmp3dERmuXa48v0JF3Zj4zsOGWswMJi5RMsKYXn2 6vaLo9W6LfM66CfjSLwdq/2k4AgpQVF2fc34S1nxkc+YhSX1nS7MNDzH0o7oTTTJ8ggD gYP7SxiCx0+MQpiarexL0ejVK4w91BXtR/1xChJhZIGQV6xQ+kpRo+NJBsdc5E44pouy 9jYt3muNF9j6CcjDvwV4dyo52BFaIT/j7VhXW8sukwCLvBvP7WnprlFiINWmgZl2OSB4 iDeC6Q6AjnHdClVbaQoVAbW6N+Nrzz/5EJodl9rmj6up54ZS5Bwjlr8ZioXt2Qad/FU3 kR7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Hb9QsIsy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o22-20020a056402439600b0043aae23b80fsi1212595edc.280.2022.07.08.02.22.11; Fri, 08 Jul 2022 02:22:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Hb9QsIsy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237798AbiGHIYy (ORCPT + 99 others); Fri, 8 Jul 2022 04:24:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237539AbiGHIYv (ORCPT ); Fri, 8 Jul 2022 04:24:51 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2975814A1 for ; Fri, 8 Jul 2022 01:24:48 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id o4so29509195wrh.3 for ; Fri, 08 Jul 2022 01:24:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=mIwFg075RvwVYz9+/Y+xL9IEwu5sJHlYJ/YyVZSg0lY=; b=Hb9QsIsy3zrdkNF7D7KWN7V9xWmBnlnqukEu8VQO760EvPnCTgR7YaaANXCVvHFhG8 azGVU8v/yUeYegEIgmmaKflxUqaohJdfHBD0rtW/STrfWOLiHNQTL2u3xQe8ziPn37Tp KperCCH8+Rsgixu8wrN/mbJVA3rhSsKGl2aOlADbg6XXnewNcscnnFvz+pqLe4iqnJHA zq3s15m3tNnJHcbuScXgMIPMUNpfZjSdtaTKbGQrtAGToOwTcSyiz9akBnE8KKn7Cahy sS9hB+7l1qMZEn7F61+CTCeYnNdL/RgeTOMXypf4x/Gnu8ySOpRtLqY0aWNZCHpwATqH tn0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=mIwFg075RvwVYz9+/Y+xL9IEwu5sJHlYJ/YyVZSg0lY=; b=B7qEhxfxuegTehv1J3XMoymS+F9tBSnHCU7xXyA3oENw2NKL1kyKbPGdJlGXyIsi0x w+CMOzVfChg31eUhwTbbFsqsFmUM4ubSf4gNcJOMdw/sty457wiCOWpcqt2MVUJgDgt4 2DjUP8SWOYaQTvgmvelBfA3IvayJHiodyq+jDzD0P91yx4Ty1UhU9GMms2rtpfi5FMN5 d2oU/8iYTb2ci9GraHv+m6TqJyhncqdp7y+idHoIC8VvpJOUzRcmAH/mqnW/X859tWWA jGFdpcFfoGN54dBygDOCSnVi5pgdrqao22r6bfR0be01GdhQQcymkD2P8I88yTrWQ41v ThlA== X-Gm-Message-State: AJIora9V9Zi0Mn3Dg1ue5in9vqTQbLBJtv+8vRAhRCPjkXYoaFutqjVv RWGcFnV851oZS1QPdpZkDsAkbg== X-Received: by 2002:a5d:588d:0:b0:21d:865c:54e9 with SMTP id n13-20020a5d588d000000b0021d865c54e9mr2109574wrf.3.1657268687247; Fri, 08 Jul 2022 01:24:47 -0700 (PDT) Received: from myrica (cpc92880-cmbg19-2-0-cust679.5-4.cable.virginm.net. [82.27.106.168]) by smtp.gmail.com with ESMTPSA id h15-20020a1ccc0f000000b0039749b01ea7sm1670902wmb.32.2022.07.08.01.24.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jul 2022 01:24:46 -0700 (PDT) Date: Fri, 8 Jul 2022 09:24:22 +0100 From: Jean-Philippe Brucker To: Xu Kuohai Cc: bpf@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Mark Rutland , Catalin Marinas , Will Deacon , Daniel Borkmann , Alexei Starovoitov , Zi Shen Lim , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , "David S . Miller" , Hideaki YOSHIFUJI , David Ahern , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , Jakub Kicinski , Jesper Dangaard Brouer , Russell King , James Morse , Hou Tao , Jason Wang Subject: Re: [PATCH bpf-next v6 4/4] bpf, arm64: bpf trampoline for arm64 Message-ID: References: <20220625161255.547944-1-xukuohai@huawei.com> <20220625161255.547944-5-xukuohai@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 08, 2022 at 12:35:33PM +0800, Xu Kuohai wrote: > >> + > >> + emit(A64_ADD_I(1, A64_R(0), A64_SP, args_off), ctx); > >> + if (!p->jited) > >> + emit_addr_mov_i64(A64_R(1), (const u64)p->insnsi, ctx); > >> + > >> + emit_call((const u64)p->bpf_func, ctx); > >> + > >> + /* store return value */ > >> + if (save_ret) > >> + emit(A64_STR64I(r0, A64_SP, retval_off), ctx); > > > > Here too I think it should be x0. I'm guessing r0 may work for jitted > > functions but not interpreted ones > > > > Yes, r0 is only correct for jitted code, will fix it to: > > if (save_ret) > emit(A64_STR64I(p->jited ? r0 : A64_R(0), A64_SP, retval_off), > ctx); I don't think we need this test because x0 should be correct in all cases. x7 happens to equal x0 when jitted due to the way build_epilogue() builds the function at the moment, but we shouldn't rely on that. > >> + if (flags & BPF_TRAMP_F_CALL_ORIG) { > >> + restore_args(ctx, args_off, nargs); > >> + /* call original func */ > >> + emit(A64_LDR64I(A64_R(10), A64_SP, retaddr_off), ctx); > >> + emit(A64_BLR(A64_R(10)), ctx); > > > > I don't think we can do this when BTI is enabled because we're not jumping > > to a BTI instruction. We could introduce one in a patched BPF function > > (there currently is one if CONFIG_ARM64_PTR_AUTH_KERNEL), but probably not > > in a kernel function. > > > > We could fo like FUNCTION_GRAPH_TRACER does and return to the patched > > function after modifying its LR. Not sure whether that works with pointer > > auth though. > > > > Yes, the blr instruction should be replaced with ret instruction, thanks! > > The layout for bpf prog and regular kernel function is as follows, with > bti always coming first and paciasp immediately after patchsite, so the > ret instruction should work in all cases. > > bpf prog or kernel function: > bti c // if BTI > mov x9, lr > bl ------> trampoline: > ... > mov lr, > mov x10, > ORIG_CALL_entry: <------- ret x10 > return_entry: > ... > paciasp // if PA > ... Actually I just noticed that CONFIG_ARM64_BTI_KERNEL depends on CONFIG_ARM64_PTR_AUTH_KERNEL, so we should be able to rely on there always being a PACIASP at ORIG_CALL_entry, and since it's a landing pad for BLR we don't need to make this a RET 92e2294d870b ("arm64: bti: Support building kernel C code using BTI") Thanks, Jean