Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp3425461rwp; Sat, 15 Jul 2023 02:20:54 -0700 (PDT) X-Google-Smtp-Source: APBJJlHs7S/2kz7BGh6qFt4lNtS3IqFukpGUFLNr/eSyq2SyvhTfKej5M0NCPfdV8rvAiwht1E34 X-Received: by 2002:a05:651c:b1e:b0:2b6:7c3a:6adc with SMTP id b30-20020a05651c0b1e00b002b67c3a6adcmr1004797ljr.5.1689412853702; Sat, 15 Jul 2023 02:20:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689412853; cv=none; d=google.com; s=arc-20160816; b=rJ1KH/GSU0KisBezTheAGio1TiZtbudKy5dAuhRaamvWW73Cq+FXTocMQvxURmp6Ut DlyTI68bYW2UFEjk44lRGPmG0NqA3oqZE8J3OE7WCrZU3j01TxxYspg2+3ImYHL/bGhy SxH4yn3wv7mL6Tzkls32Xzxp0DUS2wjq4iRGk2X8SGgS9XLlJCkrnR4JgHnJyRV0Uk9n xPdjWumUiWIlro5WAokPssaiv4v9wyRFapJIzQ2SIdVrbSs/uDp3DA0tz1gr0MhB7utw w7kwXifYNarysISzHC801oxX2JWE2aL63iwtWcVAG+fMCAn34GijIowtbDsReKqU62z1 LopA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:to:content-language:subject:user-agent:mime-version:date :message-id; bh=nzTbZoMbsc0z0oBS6nVWyskL13S+k1imRImvuN5ukSw=; fh=Nox2pmuTFOQQZnNmFd2HCKvVYNtTmD/Y8bro1vowQ/o=; b=YJcsmBoYMTGERLwsE/G+WRC1cfxUN/ixyryTehOlAVkOPqiidslhN3oMTrVDOQxptL svID7fni4appU2/MgPa5rJrS74gvFaCg61u99kOY3awEyqd3X4FJJ4fqq8ElMHSv+ETV vxDt097jbhEVn7kD6WiJQwKAHENTmcng2H3dkYzrkk6CuKKWPHjYUGrlcgXwqtyiHODW zKwQa6LdhX7xiI8DaQ61HLULRHvghjziGYNG4E/GrW2DdfIBlOQWmqOQYs9yRkSXdQpE Nfn2ebNELsN68za9PLd/wXxnz4+tI5z5XEcxNJ2hiVvwe6axDbIRklfGCHFV8G9sDMFO nsRA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n17-20020a17090695d100b0099364d9f0e3si3454952ejy.562.2023.07.15.02.20.28; Sat, 15 Jul 2023 02:20:53 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229621AbjGOJDx (ORCPT + 99 others); Sat, 15 Jul 2023 05:03:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229487AbjGOJDv (ORCPT ); Sat, 15 Jul 2023 05:03:51 -0400 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59FFDE65; Sat, 15 Jul 2023 02:03:49 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4R32St5Fy5z4f3mK3; Sat, 15 Jul 2023 17:03:42 +0800 (CST) Received: from [10.67.111.192] (unknown [10.67.111.192]) by APP4 (Coremail) with SMTP id gCh0CgCHN6vwYLJk0+YROA--.24593S2; Sat, 15 Jul 2023 17:03:45 +0800 (CST) Message-ID: Date: Sat, 15 Jul 2023 17:03:44 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH bpf] bpf, arm64: Fix BTI type used for freplace attached functions Content-Language: en-US To: Alexander Duyck , bpf@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <168926677665.316237.9953845318337455525.stgit@ahduyck-xeon-server.home.arpa> From: Xu Kuohai In-Reply-To: <168926677665.316237.9953845318337455525.stgit@ahduyck-xeon-server.home.arpa> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-CM-TRANSID: gCh0CgCHN6vwYLJk0+YROA--.24593S2 X-Coremail-Antispam: 1UD129KBjvJXoW7Ww1xZFW7tF4xGryxJFy3XFb_yoW8CF1rpa 18CrZ0krs2qFn7WFWkJan7tr4rKw4vqFsxKw15XrWYyFyYqa4xKFn8K34Ykrs8ArW5Gw4r Zry2krnYkF1DZ3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUyKb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Cr0_Gr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I 0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40E x7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x 0Yz7v_Jr0_Gr1lF7xvr2IY64vIr41lc7I2V7IY0VAS07AlzVAYIcxG8wCF04k20xvY0x0E wIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E74 80Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0 I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF04 k26cxKx2IYs7xG6rW3Jr0E3s1lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY 1x0267AKxVWUJVW8JbIYCTnIWIevJa73UjIFyTuYvjxUzsqWUUUUU X-CM-SenderInfo: 50xn30hkdlqx5xdzvxpfor3voofrz/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,MAY_BE_FORGED, NICE_REPLY_A,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE, 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 On 7/14/2023 12:49 AM, Alexander Duyck wrote: > 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); LGTM. Thanks for the fixes. Acked-by: Xu Kuohai > > emit(A64_MOV(1, A64_R(9), A64_LR), ctx); > emit(A64_NOP, ctx); > >