From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CB8F2C43334 for ; Fri, 8 Jul 2022 08:26:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=5KlHliwTLZN/GBIAHdZJIzT6muxrdClBCt9rB5mLNUU=; b=uJuyY4xTqyHrrG g+/qjnOBQ8Dl++mNLpJT2ke0XBTdSpPApTnOeW+gY72QLerSQIq4u0IL1pPffoffmmcZ5bMJlUzKu kEa08D9FbwjchEJ+cM46KXmhiYbe+tv8p+nfp88yLI6H2NF8sdWVMJAM4Wi/tJiTRM6NjNCk4Y1LR kbY/eOAKPrjNPj7LGKm60A1PhXc1ekNVQllUvqchxaj4/snL7CtfFXf0FdrZuiT0atdbslTwnV3XG nHwSUJUyJHKNQIl6NNf3UiJdGGiQe35OhkI51TAXsLYA2WDSLYCiToLuyebbG70tPSpf/XmFvy+cl BiU6a4wbZq4xewvjldMQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o9jIX-002WCb-Nm; Fri, 08 Jul 2022 08:25:14 +0000 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o9jIB-002W1t-3M for linux-arm-kernel@lists.infradead.org; Fri, 08 Jul 2022 08:24:52 +0000 Received: by mail-wr1-x433.google.com with SMTP id bk26so14434329wrb.11 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=RDn9Gve6pHTwWJSZ9ODy17CzZh+iPifBTX4djw5b5/0hh0ZBVFrMmCwcyAmZpmUZWM kNRqQP4t5zownF9BMueQFeW/1mOo/TNbyU24kTYwV77VjEt+Dh1TX6VyGcYYp7kD1DKJ v4UslS0P+lup+d99Zk8K2Zxgj0+b1JLOZOFkaxTyLoIq1BN8Knn7HLhM74OFrZvzR87q ZgDVr/MQICCvVxFkeETuONX4Af2/OmOsE4DgrHLEbMJhAOLK7WbXqKQLplirGybkaVVY uA0KCN0Wg1S2IGGc3d/0sqsAYPI6Znkyk+9BLpz7a9VNBgO9nH571KMUcT8TjASCf4K7 JXQg== X-Gm-Message-State: AJIora9mwi1nvWAVz2eWMTjd/H3LDbtpf959Ko36Eq4pGsDjsyqRKSJa tB/8nno9oA3/Cq2wbzodmDcmKQ== X-Google-Smtp-Source: AGRyM1viKjtVrmUoxTanFr1pV6d7LMrE7leuT0XIliXYQcDoe0Ro78y5UhOmXgHGos2nagi880AGAA== 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-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220708_012451_240310_38E00E20 X-CRM114-Status: GOOD ( 28.49 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel