Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp1393265rwp; Thu, 13 Jul 2023 10:09:00 -0700 (PDT) X-Google-Smtp-Source: APBJJlHSh/3GVK+3G66LC+bYiy6ylLqrxBiQKxZkfRfy63Ne2d5QfMa2xhubD6lb4nH2dZySDBTG X-Received: by 2002:a05:6402:1241:b0:51e:65d:1f6c with SMTP id l1-20020a056402124100b0051e065d1f6cmr2586560edw.9.1689268140456; Thu, 13 Jul 2023 10:09:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689268140; cv=none; d=google.com; s=arc-20160816; b=WGRBzPw7bIkJYvcfSoawYh1hOK7mxARCi/SUs78FMHcM+U22Tgk7VIcb4yeXr5jB3L 3bVk1Y4yOA9h18eH4fnxd08lwTsjzxTa/AY52Pp3wgAHsNo74qdYwLVXvM27s8ydZD7s DDOLRjhUGKJt/LlxfEHpHySnacyET2fRjIqpPcwmkS5Vzh/Z4lo2n25Y7LX8I0bp6c1I 8wSDKU3Mxo5/+bxs+2z4cntgJNrn8/yBQJYINmcxwgywFtentBHit0d0eEI/8WCejPM3 7877KAgPTywD/n4kY0fBC6tnp/h/iVeDhoqLY2os72WVaG/4DP77HXHeX8P0iarvwT00 R/1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:message-id:date:cc:to:from:subject:dkim-signature; bh=brLFB/e/7Oi0GsJYQKM7Ftuw8LYNUfDkAuTAqWsvQ7M=; fh=EIQxKEXzTcr8ltiwZRSYtXvNeE2oTfm+fhnk8AiT8nk=; b=oKAnD+p4WvvGgJ3gh4gG1UrXpG7NedMd6Y0Hk63RImx/OzI9G5DTIzde696hZFXD3G BKwAe9UlOWkAsKZb1OoleLVY+cOE53N7/Y2mU0EGfOuNNaMbmBKjY9cYK8idiKSc1RL9 hP876deGqhWp33HixRU3JfCrUczg6FdS7+BxCKwlg8znCrPEMGqvs6aPOS36F+2ygtit VfZXxqNhmvmXAoMUaJ4bb9AvOsrbhDzugVzCzWtPAB2OM8VPmw1PxQ5ZxlyGpW/vNggJ c9SoTudN09ymCbbbu8UB17eNYwhnVr+XVJ+grAHSwHn2Hn9V3lnHVb1XNFcBBCX34viN DLvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=Bpm7AH5+; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c21-20020aa7d615000000b0051d7e275e56si7617595edr.272.2023.07.13.10.08.36; Thu, 13 Jul 2023 10:09:00 -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=@gmail.com header.s=20221208 header.b=Bpm7AH5+; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235383AbjGMQtq (ORCPT + 99 others); Thu, 13 Jul 2023 12:49:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235376AbjGMQtf (ORCPT ); Thu, 13 Jul 2023 12:49:35 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 229572D75; Thu, 13 Jul 2023 09:49:34 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-676f16e0bc4so612990b3a.0; Thu, 13 Jul 2023 09:49:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689266973; x=1691858973; h=content-transfer-encoding:mime-version:user-agent:message-id:date :cc:to:from:subject:from:to:cc:subject:date:message-id:reply-to; bh=brLFB/e/7Oi0GsJYQKM7Ftuw8LYNUfDkAuTAqWsvQ7M=; b=Bpm7AH5+MZQDXC1YhqXdmriKkr1YpuXICsupjW+P5fuHWR5vG+hLmD0ArFqSW0GsgO 3pRbaQdD+hyxx3/hXfqKAzaVF3vIpmKp8F6SUe/MGm7LeGzW53lWYVnGZMwcwgi39UX+ MgRmrOx/gNQ66Lebaa5mmem/JqLHm1cqw7WXSGre8WKSxsYhQVxquLcNv6eS8wkZH24i 1DBiwx0h9lJmV2B1SXITA/IfJMmwRvMG6zr6yGxyBa8/fVj/7fuYNQw7r3IQYf09q+dn 8y2J0mHdQO+Rt1eJaTCAQBazhLUJdcc1mWt5W/AmI5syq5mCqyDGfTzC4NkuGO3mbOgR PJYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689266973; x=1691858973; h=content-transfer-encoding:mime-version:user-agent:message-id:date :cc:to:from:subject:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=brLFB/e/7Oi0GsJYQKM7Ftuw8LYNUfDkAuTAqWsvQ7M=; b=Z0lUs3cDVjhji90RgMxhqPz+DNeLgv6j27zOkeK0CwlMEvFUcin0wfgb3Chc1SRbf8 ZIEK1sByTDuKdOv1xJE4+klMI0v9KBOszggAMGX0EfcAK41QjeZ1AHjJ7MdLOncGLrPm fN8/T7jZLWGq8yxzEZGW4ahsY0BsolHT5/tHerk+v/H9aRAy0/GE2GS+dpJJtVJn6DKa 9RTdf5Q00z54vLowXDXC9/fulU6xdspsOFaW8uh/zr2NEYxVP2CqMYF/Z2WDIbHC2Ldw MRDSMvD8GTEurmFLd7ffYAERmO8VLBR+n6x/+jE/BiIsMUPY61IC8mZizKY96VldC4ML f28g== X-Gm-Message-State: ABy/qLbW6lxxJUrqerVx/XKTA+kqIO2Yp9bD2FuwH1i96a3rS6xMhlMn ZPQV1ttgSDuO1oaxCjUdPG8= X-Received: by 2002:a05:6a00:124b:b0:668:82fe:16e2 with SMTP id u11-20020a056a00124b00b0066882fe16e2mr1906844pfi.16.1689266973264; Thu, 13 Jul 2023 09:49:33 -0700 (PDT) Received: from ahduyck-xeon-server.home.arpa ([2605:59c8:448:b800:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id 18-20020a056a00073200b006833b73c749sm2341955pfm.22.2023.07.13.09.49.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 09:49:32 -0700 (PDT) Subject: [PATCH bpf] bpf, arm64: Fix BTI type used for freplace attached functions From: Alexander Duyck To: bpf@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: xukuohai@huaweicloud.com Date: Thu, 13 Jul 2023 09:49:31 -0700 Message-ID: <168926677665.316237.9953845318337455525.stgit@ahduyck-xeon-server.home.arpa> User-Agent: StGit/1.5 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 From: Alexander Duyck When running an freplace attached bpf program on an arm64 system w were seeing the following issue: Unhandled 64-bit el1h sync exception on CPU47, ESR 0x0000000036000003 -- BTI After a bit of work to track it down I determined that what appeared to be happening is that the 'bti c' at the start of the program was somehow being reached after a 'br' instruction. Further digging pointed me toward the fact that the function was attached via freplace. This in turn led me to build_plt which I believe is invoking the long jump which is triggering this error. To resolve it we can replace the 'bti c' with 'bti jc' and add a comment explaining why this has to be modified as such. Fixes: b2ad54e1533e ("bpf, arm64: Implement bpf_arch_text_poke() for arm64") Signed-off-by: Alexander Duyck --- arch/arm64/net/bpf_jit_comp.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c index 145b540ec34f..ec2174838f2a 100644 --- a/arch/arm64/net/bpf_jit_comp.c +++ b/arch/arm64/net/bpf_jit_comp.c @@ -322,7 +322,13 @@ static int build_prologue(struct jit_ctx *ctx, bool ebpf_from_cbpf) * */ - emit_bti(A64_BTI_C, ctx); + /* bpf function may be invoked by 3 instruction types: + * 1. bl, attached via freplace to bpf prog via short jump + * 2. br, attached via freplace to bpf prog via long jump + * 3. blr, working as a function pointer, used by emit_call. + * So BTI_JC should used here to support both br and blr. + */ + emit_bti(A64_BTI_JC, ctx); emit(A64_MOV(1, A64_R(9), A64_LR), ctx); emit(A64_NOP, ctx);