Message ID | 168926677665.316237.9953845318337455525.stgit@ahduyck-xeon-server.home.arpa |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1977239vqm; Thu, 13 Jul 2023 10:29:22 -0700 (PDT) X-Google-Smtp-Source: APBJJlHwiNGzzju/nNGT5NVEfrIZIzgUH2dTczLMjFld5uKKyBlZHgNZq/N+vwlY12YQHX9XwCFV X-Received: by 2002:a05:6a00:23c2:b0:680:fa5f:4ed6 with SMTP id g2-20020a056a0023c200b00680fa5f4ed6mr2069840pfc.27.1689269361785; Thu, 13 Jul 2023 10:29:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689269361; cv=none; d=google.com; s=arc-20160816; b=QcQpwAgpk8kl/9vrAXE5XWvxtQA0EGkv2Ui4mphskbb8bfJnDSV1bYvW66APh80wSv cvihaPh1PlsgSugrTtQ7JhibMffTdcky4SMSOtDjq/mIA5Q4IKwrkZnQXtPIpHXn/Lu+ sCovwFPkCQAqH5GbJUK/WAbNLnFI2gJMnQKrCVTVWHnVaQ4IaXz8rnrG9gvomSRiJcSF WzEAPzOuEDxH+tPlvkwT/oOQszZZoD5a1OieylvAHrAW0YG/6XcnxM2mL8iG85v7bswb xLvVWI/4IpBJMzcBXa3AcZHvpBNNJz8ZL7TecgXu5nngqFxG10A7O5H0dXqDGpJvQIW1 foZg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y185-20020a638ac2000000b0055bf134b7b5si5143507pgd.828.2023.07.13.10.29.08; Thu, 13 Jul 2023 10:29:21 -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 S233096AbjGMQtq (ORCPT <rfc822;ybw1215001957@gmail.com> + 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 <rfc822;linux-kernel@vger.kernel.org>); 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 <alexander.duyck@gmail.com> 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771327310606620617 X-GMAIL-MSGID: 1771327310606620617 |
Series |
[bpf] bpf, arm64: Fix BTI type used for freplace attached functions
|
|
Commit Message
Alexander Duyck
July 13, 2023, 4:49 p.m. UTC
From: Alexander Duyck <alexanderduyck@fb.com> 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 <alexanderduyck@fb.com> --- arch/arm64/net/bpf_jit_comp.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
Comments
On 7/14/2023 12:49 AM, Alexander Duyck wrote: > From: Alexander Duyck <alexanderduyck@fb.com> > > 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 <alexanderduyck@fb.com> > --- > 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); LGTM. Thanks for the fixes. Acked-by: Xu Kuohai <xukuohai@huawei.com> > > emit(A64_MOV(1, A64_R(9), A64_LR), ctx); > emit(A64_NOP, ctx); > >
On Sat, Jul 15, 2023 at 2:03 AM Xu Kuohai <xukuohai@huaweicloud.com> wrote: > > On 7/14/2023 12:49 AM, Alexander Duyck wrote: > > From: Alexander Duyck <alexanderduyck@fb.com> > > > > 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 <alexanderduyck@fb.com> > > --- > > 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); > > LGTM. Thanks for the fixes. > > Acked-by: Xu Kuohai <xukuohai@huawei.com> Applied. Thanks
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);