Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3090670rwb; Mon, 15 Aug 2022 17:53:58 -0700 (PDT) X-Google-Smtp-Source: AA6agR4BFe4z9vBHxpIBtSkg+NQvEykfCp1m7y1hQ2J2YpSvmm6oHmaGWlbizlqOyTeShPUl1BhA X-Received: by 2002:a17:907:e88:b0:730:8e7d:2281 with SMTP id ho8-20020a1709070e8800b007308e7d2281mr12856222ejc.20.1660611238716; Mon, 15 Aug 2022 17:53:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660611238; cv=none; d=google.com; s=arc-20160816; b=OAv7tZ9IVc175dAm7PLqPx70caIgQ06W+0kx8HEd6zzZbYxnSVKQySlpb6ykScIl5g P6JKGIbibFJ8Gv9UrzKdqhhlFYY0/UJUOWV2XOhYXaA24j5Q/nrUhzZNV+uiQCnBIyhg JGfepUU/zdZZFnBfmTtM/hWjgzAP2gqsDATI3SV+/6I8TTnDoUjl69g8tgJn54xbIHni WegldO0M2htbBy5U1EuvEodp5iCX82yKC4GE93ca/aBB5KKwTbDT0QZRXJ/pCeHgazol GtW0hEUr857f1ATFMRW/kdLSRxDXP7UM5Am0Ja4J1Kaz+PtgB/lwihWg6tMInN1zQYnt Z3NQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Mjl6fAYB4O6CxbtFS+M+h6v4FJ/da17sTlm27S2NMgg=; b=qs1VqTtbW3W+RGTSmaqft3b4pYC2m/CbA0X/j+I76J597gdD/N9ZJn6fyexNJNST45 JxHVq7Ur0IgK5FjVLPswToTnnKVQPT/uhnea7Y5s+qnzPEyuZyHI5eVTb1HrWA2/EaqF D7PRxKLbZ0GPlyOB8xkh4jK7y/TD/9kvxZQwtT6GISUdLjRsrHRNbXkvFmvmTzn25xDp axy08u8ZVuqsSHDjlKh/USG68qgVNs4W9Zn6gZTJPmUYHR/lACzjVfmOiEzntKUIGZS9 cUvOBi5vS3fkAqmliHEQ4FhpTRZ/ybRU/WXQwOGTJzITuJVv95L6uOqY0Bm+mP5uUJ6B 1lJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=X5MVZLQ4; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g3-20020a1709065d0300b00732faab2567si9843689ejt.290.2022.08.15.17.53.33; Mon, 15 Aug 2022 17:53:58 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=X5MVZLQ4; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355557AbiHOX4j (ORCPT + 99 others); Mon, 15 Aug 2022 19:56:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354929AbiHOXvF (ORCPT ); Mon, 15 Aug 2022 19:51:05 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6A1F91081; Mon, 15 Aug 2022 13:16:13 -0700 (PDT) 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 D6E056069F; Mon, 15 Aug 2022 20:16:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DBE0BC433D6; Mon, 15 Aug 2022 20:16:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660594572; bh=hkB8txI6DXqZCUcx5c6Inq/0XsFh1cldRNeTZZowmFM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X5MVZLQ4Tv7VHUxvfgU2O0yqWaUVnsicYJFC4uBIYqaibON25hZfHT1zixSU9/CbI Zm5UuW8XfT76BJfkmUwgXwaO+dHVddJ4zlNFV2/BId5R6ZToqcY1tOg+xfvB4mctQ2 q7DkcbfAhrnPABtXnK2ukhzGkAbpQM808rc084lE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tony Ambardar , Jakub Sitnicki , Daniel Borkmann , Sasha Levin Subject: [PATCH 5.19 0491/1157] bpf, x64: Add predicate for bpf2bpf with tailcalls support in JIT Date: Mon, 15 Aug 2022 19:57:27 +0200 Message-Id: <20220815180459.271656380@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 From: Tony Ambardar [ Upstream commit 95acd8817e66d031d2e6ee7def3f1e1874819317 ] The BPF core/verifier is hard-coded to permit mixing bpf2bpf and tail calls for only x86-64. Change the logic to instead rely on a new weak function 'bool bpf_jit_supports_subprog_tailcalls(void)', which a capable JIT backend can override. Update the x86-64 eBPF JIT to reflect this. Signed-off-by: Tony Ambardar [jakub: drop MIPS bits and tweak patch subject] Signed-off-by: Jakub Sitnicki Signed-off-by: Daniel Borkmann Link: https://lore.kernel.org/bpf/20220617105735.733938-2-jakub@cloudflare.com Signed-off-by: Sasha Levin --- arch/x86/net/bpf_jit_comp.c | 6 ++++++ include/linux/filter.h | 1 + kernel/bpf/core.c | 6 ++++++ kernel/bpf/verifier.c | 3 ++- 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c index b808c9a80d1b..eba704b9ce1e 100644 --- a/arch/x86/net/bpf_jit_comp.c +++ b/arch/x86/net/bpf_jit_comp.c @@ -2506,3 +2506,9 @@ void *bpf_arch_text_copy(void *dst, void *src, size_t len) return ERR_PTR(-EINVAL); return dst; } + +/* Indicate the JIT backend supports mixing bpf2bpf and tailcalls. */ +bool bpf_jit_supports_subprog_tailcalls(void) +{ + return true; +} diff --git a/include/linux/filter.h b/include/linux/filter.h index ed0c0ff42ad5..d9a0db845b50 100644 --- a/include/linux/filter.h +++ b/include/linux/filter.h @@ -948,6 +948,7 @@ u64 __bpf_call_base(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5); struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog); void bpf_jit_compile(struct bpf_prog *prog); bool bpf_jit_needs_zext(void); +bool bpf_jit_supports_subprog_tailcalls(void); bool bpf_jit_supports_kfunc_call(void); bool bpf_helper_changes_pkt_data(void *func); diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index e7961508a47d..6e3fe4b7230b 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -2716,6 +2716,12 @@ bool __weak bpf_jit_needs_zext(void) return false; } +/* Return TRUE if the JIT backend supports mixing bpf2bpf and tailcalls. */ +bool __weak bpf_jit_supports_subprog_tailcalls(void) +{ + return false; +} + bool __weak bpf_jit_supports_kfunc_call(void) { return false; diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 0efbac0fd126..602366bc230f 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -6143,7 +6143,8 @@ static bool may_update_sockmap(struct bpf_verifier_env *env, int func_id) static bool allow_tail_call_in_subprogs(struct bpf_verifier_env *env) { - return env->prog->jit_requested && IS_ENABLED(CONFIG_X86_64); + return env->prog->jit_requested && + bpf_jit_supports_subprog_tailcalls(); } static int check_map_func_compatibility(struct bpf_verifier_env *env, -- 2.35.1