Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp256320pxm; Tue, 22 Feb 2022 09:59:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJwRvVTwUJMDRnTREANEB8HdDxmS5/WtlH46zRVRS64GxSPpS9GQT+hzrWrwvphfRQjkUAns X-Received: by 2002:a17:906:7e52:b0:6b6:bc81:eae9 with SMTP id z18-20020a1709067e5200b006b6bc81eae9mr19937164ejr.273.1645552787879; Tue, 22 Feb 2022 09:59:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645552787; cv=none; d=google.com; s=arc-20160816; b=UYpcjkRA9zo8Lrn6RvjUyUSjBHs8cC/U+BSIyrweU9LGcUjtYY7l2f7AteEoiEzpaB /6WhKro44Tndnmq8ZM7Whn4om4SEOnKPeWA/Vy+UFL0Vd5Q9avAIRP7LxyvXlNUodYlT GZ39uAcuRIq+AC3V2Atb+7oMf3e8/DMM3j801qEVZl9SGWJNgQ386NRoBfoRBnyJsbAH 4hZKKMU5RAgdI6IPpY+Tx8JzOK+03e/hUi1msNjOnzXon4kPmHiE9X3SmPDGPRqNHXJf ovP8BsCVAdfwqvMsfTslZXWMKK/A6R5oG9Y6lwojkK92sC1TLeYAX5OHzWFofhWHXbyJ yT/A== 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 :dkim-signature; bh=j5JVS9O/mplinxdJdBXn+LyIlfYozhcfrfLIXcD4Iuc=; b=0kE5RMT49pPaGQFVnoetFhfLAQMgDI5FmaqpGatIA3bsHnBnd8JlGEBCs7vkxk/SuH GrYKkLzsNtc4mvo2IgOgPEwtoiBPYRKRBcHyAI1/Czjs9FBkWI6Xi/99ux3H0mvTZcNd djkH7VH5KjrauqudI0kBlbWhsh8CObxE0F2UUv4HsDzoKdNq5dM4lWLjRM2p6a1NTP8S dR/ZRtP8PmYmPPFSs0lJwWmAe7SNmj+yx+cfWIUE1G+VpLBJxxJu3ez+RMciqsPmnUHd YmsLk8ozuC+Aj5m8AOH21POLhG1tWWVe9OolizcFqLUo1XTCdBXKhzcy+yBLr9VgcYo1 ETJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pmDa8PxQ; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bl11si104075ejb.315.2022.02.22.09.59.25; Tue, 22 Feb 2022 09:59:47 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pmDa8PxQ; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234539AbiBVRHd (ORCPT + 99 others); Tue, 22 Feb 2022 12:07:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234545AbiBVRHb (ORCPT ); Tue, 22 Feb 2022 12:07:31 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEDBDDE84; Tue, 22 Feb 2022 09:07:05 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D95F160F89; Tue, 22 Feb 2022 17:07:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 671A4C36AEB; Tue, 22 Feb 2022 17:06:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1645549624; bh=7gGtwxVWHRIA9qaPB3Q5gClXDbN5Gk7FLicmyv8ugAM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pmDa8PxQiE/gifqFM9N2SQADv5cyLNTBgNBio/yCR19/GLZd/GAb0kO66aro5D5NS 7PC11NJZS8d0DQ+HZvX1Q+Vz41kYtOn3L4IlCTOUTfu43rLPsdtwUW55q/zWAzs1nW ZQ4wpZrQZ2Yi37VUjZ2ViFpH5kPUaH9L0f2WEa/s3uzOLx9b0d3RRmDc6XK6ASOLnk 9HdlZB6oTAwZJOC0TWB50x5v4Y7O+NYcoE+tWo0ZKh0hdmhaS0/vg1ujQYfICpJWZJ yTI1UbKLjoeejkpzNWacxUSCWc8Lnc02aPDJRCJetgJdsUk13bMRh50+gBiCJY+SM8 zCGaym35TYntg== From: Jiri Olsa To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Masami Hiramatsu Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, lkml , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Steven Rostedt Subject: [PATCH 04/10] bpf: Add support to inline bpf_get_func_ip helper on x86 Date: Tue, 22 Feb 2022 18:05:54 +0100 Message-Id: <20220222170600.611515-5-jolsa@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220222170600.611515-1-jolsa@kernel.org> References: <20220222170600.611515-1-jolsa@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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: X-Mailing-List: linux-kernel@vger.kernel.org Adding support to inline it on x86, because it's single load instruction. Signed-off-by: Jiri Olsa --- kernel/bpf/verifier.c | 21 ++++++++++++++++++++- kernel/trace/bpf_trace.c | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index d7473fee247c..f125c33a37c9 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -13635,7 +13635,7 @@ static int do_misc_fixups(struct bpf_verifier_env *env) continue; } - /* Implement bpf_get_func_ip inline. */ + /* Implement tracing bpf_get_func_ip inline. */ if (prog_type == BPF_PROG_TYPE_TRACING && insn->imm == BPF_FUNC_get_func_ip) { /* Load IP address from ctx - 16 */ @@ -13650,6 +13650,25 @@ static int do_misc_fixups(struct bpf_verifier_env *env) continue; } +#ifdef CONFIG_X86 + /* Implement kprobe_multi bpf_get_func_ip inline. */ + if (prog_type == BPF_PROG_TYPE_KPROBE && + eatype == BPF_TRACE_KPROBE_MULTI && + insn->imm == BPF_FUNC_get_func_ip) { + /* Load IP address from ctx (struct pt_regs) ip */ + insn_buf[0] = BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, + offsetof(struct pt_regs, ip)); + + new_prog = bpf_patch_insn_data(env, i + delta, insn_buf, 1); + if (!new_prog) + return -ENOMEM; + + env->prog = prog = new_prog; + insn = new_prog->insnsi + i + delta; + continue; + } +#endif + patch_call_imm: fn = env->ops->get_func_proto(insn->imm, env->prog); /* all functions that have prototype and verifier allowed diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 64891b7b0885..c1998b9d5531 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -1039,6 +1039,7 @@ static const struct bpf_func_proto bpf_get_func_ip_proto_kprobe = { BPF_CALL_1(bpf_get_func_ip_kprobe_multi, struct pt_regs *, regs) { + /* This helper call is inlined by verifier on x86. */ return instruction_pointer(regs); } -- 2.35.1