Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp4996942rwj; Tue, 20 Dec 2022 18:44:57 -0800 (PST) X-Google-Smtp-Source: AMrXdXtuuTxwF+ucDXM/uy5xwnYFmx+e3nEcYFeoqww1YS9VVgjJe7D0GoIpAouJb4uLShnWwnIt X-Received: by 2002:a17:906:380e:b0:7c0:be5d:59a9 with SMTP id v14-20020a170906380e00b007c0be5d59a9mr3648285ejc.20.1671590697162; Tue, 20 Dec 2022 18:44:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671590697; cv=none; d=google.com; s=arc-20160816; b=Xby/KtfGw/k2jZ4FV8UXwGzpdy7YKQplSnt1kBbgyum70f73rKplIuv/DaN7Ht49DJ KNbl4GbQFPZ5SrEcJ/NGpLFPxB4Krsl3UxuZmzLxp7205Xl67bwise9FiSJsGLSamkBG FpDg/JtWOUl6Wu0vTEIIHnYCj22LDB1nC+YUzMgy1LDjz5/mraOsCrY3gxniYs6tXioJ A3K8feACSKK04h8Cdwq/8SV6NHq8fx+LwizO7RXZDSQjCwd2UhuYihmiD1fVW2FTwxf0 pzdF1Ha1raO0O0o2taOnwEvrjCULlorwj3djVOYU0Tlq8SAgy0/RQvJPy8kTKn/fwp6g rCqg== 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:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=cK7APKHkCCmpMSb2hzPfEmFnJ7Y137VqPio43LmYaL4=; b=OEdO6wwE9Ya7+OcmXWH+6TV223wFyY0+d6GqM6VKVD0x5qPA3iz6Keh7N6Z8HV3LIx eFNQhue2uNYongyUBh5xbE1JPkZmfNyIMTydZ57xi9YbCrEPed+ufNrDfcMHsCJEBmaH UmFalDMTT2+lsvQHkg1soREBjf/PBFcITVadacFk6lBV5i+5y8IBMTFaNisWQqPqioCS v4yn1CdY2/wbsy0ioTafzdUlpSuVhOKOFHPhcL7SXX/3K+/qbRoWdIfc4WOY8HRxS+kH 3Ia+Y3QFKDE/SwwgYibWOO+DCXwNR2yQ8/1Ou91QgbTjJkfTT0TQRYdjH0n7hv4EPmKP Q+zg== 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 nc37-20020a1709071c2500b008334aeea096si1565961ejc.240.2022.12.20.18.44.40; Tue, 20 Dec 2022 18:44:57 -0800 (PST) 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 S234180AbiLUCgl (ORCPT + 70 others); Tue, 20 Dec 2022 21:36:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229448AbiLUCgi (ORCPT ); Tue, 20 Dec 2022 21:36:38 -0500 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F9B460DF; Tue, 20 Dec 2022 18:36:35 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.169]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4NcHd90y1Tz4f3kJr; Wed, 21 Dec 2022 10:36:29 +0800 (CST) Received: from [10.67.109.184] (unknown [10.67.109.184]) by APP3 (Coremail) with SMTP id _Ch0CgCHNCItcaJj3abcAA--.30228S2; Wed, 21 Dec 2022 10:36:31 +0800 (CST) Message-ID: <0039743b-5837-c0d3-7574-7719698f9dc1@huaweicloud.com> Date: Wed, 21 Dec 2022 10:36:29 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.3.0 Subject: Re: [RFC PATCH RESEND bpf-next 1/4] bpf: Rollback to text_poke when arch not supported ftrace direct call Content-Language: en-US To: Xu Kuohai , bpf@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Luke Nelson , Xi Wang , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Paul Walmsley , Palmer Dabbelt , Albert Ou , Pu Lehui References: <20221220021319.1655871-1-pulehui@huaweicloud.com> <20221220021319.1655871-2-pulehui@huaweicloud.com> From: Pu Lehui In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-CM-TRANSID: _Ch0CgCHNCItcaJj3abcAA--.30228S2 X-Coremail-Antispam: 1UD129KBjvJXoW7uF4kJr4xJF1xXw1DXF1UZFb_yoW8tr1fpF s3Ja45u3yUXrykWF9Fq3WUXFyYyw4kX34DGr4UJa4rGan3Kr92gF4UZrnYgryvkr48WF42 yF15Xr9IvFy7Za7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvIb4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x 0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG 6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFV Cjc4AY6r1j6r4UM4x0Y48IcVAKI48JM4IIrI8v6xkF7I0E8cxan2IY04v7Mxk0xIA0c2IE e2xFo4CEbIxvr21l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxV Aqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r4a 6rW5MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6x kF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWrZr1j6s0DMIIF0xvEx4A2jsIE 14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf 9x07UZ18PUUUUU= X-CM-SenderInfo: psxovxtxl6x35dzhxuhorxvhhfrp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, NICE_REPLY_A,SPF_HELO_NONE,SPF_NONE 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 2022/12/20 10:32, Xu Kuohai wrote: > On 12/20/2022 10:13 AM, Pu Lehui wrote: >> From: Pu Lehui >> >> The current bpf trampoline attach to kernel functions via ftrace direct >> call API, while text_poke is applied for bpf2bpf attach and tail call >> optimization. For architectures that do not support ftrace direct call, >> text_poke is still able to attach bpf trampoline to kernel functions. >> Let's relax it by rollback to text_poke when architecture not supported. >> >> Signed-off-by: Pu Lehui >> --- >>   kernel/bpf/trampoline.c | 8 ++------ >>   1 file changed, 2 insertions(+), 6 deletions(-) >> >> diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c >> index d6395215b849..386197a7952c 100644 >> --- a/kernel/bpf/trampoline.c >> +++ b/kernel/bpf/trampoline.c >> @@ -228,15 +228,11 @@ static int modify_fentry(struct bpf_trampoline >> *tr, void *old_addr, void *new_ad >>   static int register_fentry(struct bpf_trampoline *tr, void *new_addr) >>   { >>       void *ip = tr->func.addr; >> -    unsigned long faddr; >>       int ret; >> -    faddr = ftrace_location((unsigned long)ip); >> -    if (faddr) { >> -        if (!tr->fops) >> -            return -ENOTSUPP; >> +    if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS) && >> +        !!ftrace_location((unsigned long)ip)) >>           tr->func.ftrace_managed = true; >> -    } >> > > After this patch, a kernel function with true trace_location will be > patched > by bpf when CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS is disabled, which > means > that a kernel function may be patched by both bpf and ftrace in a mutually > unaware way. This will cause ftrace and bpf_arch_text_poke to fail in a > somewhat random way if the function to be patched was already patched > by the other. Thanks for your review. And yes, this is a backward compatible solution for architectures that not support DYNAMIC_FTRACE_WITH_DIRECT_CALLS. > >>       if (bpf_trampoline_module_get(tr)) >>           return -ENOENT;