Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp3405304rwj; Mon, 19 Dec 2022 18:18:52 -0800 (PST) X-Google-Smtp-Source: AA0mqf43wiHJR4+A49BN92BNUtSWFyIr3yuHmAaXhRKmk4t1kayTCM2tG0gS6ocmt4/Gn9Tq7sjq X-Received: by 2002:a05:6402:43ce:b0:46c:a43d:5e23 with SMTP id p14-20020a05640243ce00b0046ca43d5e23mr47008366edc.28.1671502732063; Mon, 19 Dec 2022 18:18:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671502732; cv=none; d=google.com; s=arc-20160816; b=Id9OZtfzjEKz9E/R3nRVz+Mczt8yHRAWmjR+ADl1LcRmEBQQwrTvGsPpvzwtk0LBwz aPIZNuU6NCRz3qMbnCwHCyGipRY4Mm78gpagdRNrDDWbhY535GRjoBI03BjogZmpC/Um KnPmXhwbXgwqZKhPfBFPjbKrstmPOcORB1CYEmRzhrFLA/aq5k5a9j6DUEyOa857m6Qf TVekk7U0fUo0LJDQmk5n9D9JNrsoynaAWegH18maj2AdsZSMNk8ZD99TyaW3qqueh5ie NEqj86RioJluS9iLquvksG+sK5mPZOdlY6bjFK989meFTl7ionm+DUEJQ+uUn8t3T3PN K3WQ== 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=xZxfzAtSteEGTea1pX5Krd9vL27Sz9lUjmwgeq181z1Lwnl7Xu/kXBePHvnBxsykRj 3DJ8FKYhjXpuC4PJFrHnFbhsbnJ1T0qU9tzSZ82KahGsybpHG5DsEsKzxgjpY76ndpMN qmj2umASt5061HmmBhYPeTpGPRiZWIFRhOe78ccof00yY5b0fDX0dhKEO6mTXydj5iIs V+7wl9tgjpeiX2BFsMvz4KlgFjjkPqlUTGaYuK6G3aiBGdsgjWuVE/PDQUxl6fncBx0T jsVzxvYIEBgtYBQHeNaZKTlf2KXZL09ZfOGd1jOWOGw6Ql0aGqvDZUQ3Cg5+V3U6wtBv 61EA== 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 h8-20020a056402094800b00461d726439asi9025558edz.538.2022.12.19.18.18.35; Mon, 19 Dec 2022 18:18:52 -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 S232913AbiLTCMX (ORCPT + 71 others); Mon, 19 Dec 2022 21:12:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232618AbiLTCMT (ORCPT ); Mon, 19 Dec 2022 21:12:19 -0500 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A84DA1B3; Mon, 19 Dec 2022 18:12:17 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4Nbg7b1HjFz4f3kpC; Tue, 20 Dec 2022 10:12:11 +0800 (CST) Received: from localhost.localdomain (unknown [10.67.175.61]) by APP4 (Coremail) with SMTP id gCh0CgDnT7P6GaFju6m1AA--.8438S3; Tue, 20 Dec 2022 10:12:14 +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?= , 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 , Pu Lehui Subject: [RFC PATCH RESEND bpf-next 1/4] bpf: Rollback to text_poke when arch not supported ftrace direct call Date: Tue, 20 Dec 2022 10:13:16 +0800 Message-Id: <20221220021319.1655871-2-pulehui@huaweicloud.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221220021319.1655871-1-pulehui@huaweicloud.com> References: <20221220021319.1655871-1-pulehui@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: gCh0CgDnT7P6GaFju6m1AA--.8438S3 X-Coremail-Antispam: 1UD129KBjvJXoW7WF1UZw43uw17GF4rZrWUurg_yoW8JFykpF 43Gw13ua1jqFZrWF9rX3WkXrWYv3ykJ3yUGF47K34Fkan5Kr95tr4DZwn3XrWFkr9YvF1a yrWFqFZ0qa1UZa7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBE14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jr4l82xGYIkIc2 x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2kIc2 xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMI IF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUHE__UUUUU = 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