Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp2523473rwj; Mon, 19 Dec 2022 05:50:39 -0800 (PST) X-Google-Smtp-Source: AMrXdXu4y/muhaQxLMlks0Q0syGOyr68z18G4uaVHvFi+rdnCIFo5aS78B8698Uq6zEUoXMcXyML X-Received: by 2002:a05:6402:35d3:b0:47b:16a8:63a2 with SMTP id z19-20020a05640235d300b0047b16a863a2mr2287541edc.6.1671457839113; Mon, 19 Dec 2022 05:50:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671457839; cv=none; d=google.com; s=arc-20160816; b=Un9K8T7zUHtWEbU1xCkJFhVDa2BSOmUuIOEXC4ZqHs+qR4heUSlvVyacNn2fRNlO4y zz62UzYY/r+Bp5/V7ym7RhvMb588vF1LsKArrfjDh0y3zeKxHhTBfAIskVcK2lQXyKOs i43Br7UJaxUTINTXq/gK4P3QSNlpVq9HWPwakD3rkns7Rc9xrFNJ937Duo9paVG29f8g cVHCAAL6ame/npbuoLd83TFc3tBzX8IiCcO5Wzw7K65ecG+FLbutBBRu733qeyGEJvW5 TUlD9TmaU2dqZxtEfFzuY7+cWMYCC7IgjMhgXeDGhqlpyuoGndJiNeitUoaUx7QndFm+ YK6A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=DU2LJ1er6FgUDddmbRgbEdTAR3QJqVIOrPkCsnxCt6o=; b=UvAnmMEH4SsjK5FMxmWOV/0YWshNHSwF6fm6z60UWtx+loZjaBLNAwq+0+j7RtPNuh xjBhE0OLwhnxpng/bOdxx9HvNH9mViQg2WPBFliOgceMqcCIZycn/PD6va/QbMu+DsfG VIOBrwu1XGsSyfEK5UHqi07a5xAtvXaIeid8Q4LU7mTXdCvf9M+MOfzjPoWI3dVaaSTJ eRu2eAXeCRTCzuWkssrRR89Xss43TDvgFAyLVRFhNT4Vbvmcg4Dxu5XqoPJuSNfcgw8g SJ/xW9OeQWIqE3PkEpjdYZtsa9pxg3d03tRG/6Ohjn7ADq+fkhYjGiO+5Oe+7a2XHsNc WnIQ== 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 i22-20020a05640242d600b00461c314f79fsi10406864edc.284.2022.12.19.05.50.22; Mon, 19 Dec 2022 05:50:39 -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 S232136AbiLSNgq (ORCPT + 70 others); Mon, 19 Dec 2022 08:36:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231754AbiLSNgg (ORCPT ); Mon, 19 Dec 2022 08:36:36 -0500 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8B0F25F4; Mon, 19 Dec 2022 05:36:34 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.169]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4NbLMc0twgz4f3l2h; Mon, 19 Dec 2022 21:36:28 +0800 (CST) Received: from localhost.localdomain (unknown [10.67.175.61]) by APP2 (Coremail) with SMTP id Syh0CgAH++jcaKBjpueTAA--.19298S3; Mon, 19 Dec 2022 21:36:31 +0800 (CST) From: Pu Lehui To: bpf@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , 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 , Pu Lehui Subject: [RFC PATCH bpf-next 1/4] bpf: Rollback to text_poke when arch not supported ftrace direct call Date: Mon, 19 Dec 2022 21:37:33 +0800 Message-Id: <20221219133736.1387008-2-pulehui@huaweicloud.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221219133736.1387008-1-pulehui@huaweicloud.com> References: <20221219133736.1387008-1-pulehui@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: Syh0CgAH++jcaKBjpueTAA--.19298S3 X-Coremail-Antispam: 1UD129KBjvJXoW7WF1UZw43uw17GF4rZrWUurg_yoW8JFykpF 43Gw13ua1jqFZrWF9rX3WkXrWYv3ykJ3yUGF47K34Fkan5Kr95tr4DZwn3XrWFkr9YvF1a yrWFqFZ0qa1UZa7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBE14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jr4l82xGYIkIc2 x26xkF7I0E14v26r4j6ryUM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2kIc2 xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMI IF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JU4T5dUUUUU = X-CM-SenderInfo: psxovxtxl6x35dzhxuhorxvhhfrp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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 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; - } if (bpf_trampoline_module_get(tr)) return -ENOENT; -- 2.25.1