From patchwork Mon Aug 9 09:34:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Almbladh X-Patchwork-Id: 12426055 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C7BFC19F31 for ; Mon, 9 Aug 2021 09:35:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 16E306113C for ; Mon, 9 Aug 2021 09:35:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234665AbhHIJfg (ORCPT ); Mon, 9 Aug 2021 05:35:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234650AbhHIJfa (ORCPT ); Mon, 9 Aug 2021 05:35:30 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 677D5C061799 for ; Mon, 9 Aug 2021 02:35:10 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id oz16so11633280ejc.7 for ; Mon, 09 Aug 2021 02:35:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anyfinetworks-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OOjKYdZ56IxXdoddh6gT5LzULhq+XYbTvDzYpe88OIo=; b=vh8Jsgh2G7NoqCxPcJvq2CcBOKUpX6sbGNCrktfTlKggrxMbxRfwrIFyRELsPPTT5+ L8h7YoO9fbeyvSg1sGrZvEc1o4qKaKwNyupBkQzTOc8evJ559OqpkUp4acXv78yKmJeN QduLtlsVaPTKoerVl1Qdz6ZZ4Z5vW6npEJyX+VXvfU0MiNwe7iirU+WGPtcx1I5DTt4M hn2Cr11+T5mueHpd3IwA/HUis33q/q7CxFFMJbLwo65aerYGnyTBLh8NsJI3SjOCq114 idvCnNbCGknR5s6Pzhq8Afz1zce3ZJUd9XoB9QbwRBUcBLEsMVFjwBhq8iPt1EHx8zZL r1EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OOjKYdZ56IxXdoddh6gT5LzULhq+XYbTvDzYpe88OIo=; b=LcGbYy4BOZNlXjhACHOcJk4Ss07Xk6W4mM2LoLaOzxX3s4KaXj6tPCDC8hgYNHVEjO w5ljtPemw1hj0UmRRVwNABxITPaQ3oQQrZbAlY7PvHQ8Os4k1yYpbUxzJH0lLxQHIt70 ZUSevf0VZMTiMaDgpmTjl/EX/Sj4X+o8aKYjx+8OEnkgFR0eon2aupWnB4TiZVB40PKp E+3aUboiD7C3p+YEAuZmpvUTR8TlWR/q/uu3N9KiFWE5ZfslfeKC7rom/ud5M+15WDaO TmzPW8K8zXdHYE+aTOc9gsm8MKU+DJTP67LHlnw3gnGq5G5TusSe1y5GI1051LM2Imvd bdwA== X-Gm-Message-State: AOAM532b3jmA19XGDtuY1cwVQevJosQ3fjHk2RUUM2W5jPTAh1iIsTTC 0qXatiTUKF1jt/S8KDQMYLrlDA== X-Google-Smtp-Source: ABdhPJwhg7f58AKgn5rt8ouratg49c6RPKgI1rtqXIbF4oM0hO3q9Q9GtqLPX2lLO7wZe9l7ogPH+w== X-Received: by 2002:a17:906:aac7:: with SMTP id kt7mr2976221ejb.4.1628501709060; Mon, 09 Aug 2021 02:35:09 -0700 (PDT) Received: from anpc2.lan (static-213-115-136-2.sme.telenor.se. [213.115.136.2]) by smtp.gmail.com with ESMTPSA id c8sm1989732ejp.124.2021.08.09.02.35.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Aug 2021 02:35:08 -0700 (PDT) From: Johan Almbladh To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org Cc: kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, illusionist.neo@gmail.com, zlim.lnx@gmail.com, paulburton@kernel.org, naveen.n.rao@linux.ibm.com, sandipan@linux.ibm.com, luke.r.nels@gmail.com, bjorn@kernel.org, iii@linux.ibm.com, hca@linux.ibm.com, gor@linux.ibm.com, davem@davemloft.net, udknight@gmail.com, Johan Almbladh Subject: [PATCH bpf-next 1/7] arm: bpf: Fix off-by-one in tail call count limiting Date: Mon, 9 Aug 2021 11:34:31 +0200 Message-Id: <20210809093437.876558-2-johan.almbladh@anyfinetworks.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210809093437.876558-1-johan.almbladh@anyfinetworks.com> References: <20210809093437.876558-1-johan.almbladh@anyfinetworks.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Before, the eBPF JIT allowed up to MAX_TAIL_CALL_CNT + 1 tail calls. Now, precisely MAX_TAIL_CALL_CNT is allowed, which is in line with the behaviour of the interpreter. Verified with the test_bpf test suite on qemu-system-arm. Signed-off-by: Johan Almbladh --- arch/arm/net/bpf_jit_32.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/arm/net/bpf_jit_32.c b/arch/arm/net/bpf_jit_32.c index a951276f0547..200ae9d24205 100644 --- a/arch/arm/net/bpf_jit_32.c +++ b/arch/arm/net/bpf_jit_32.c @@ -1180,12 +1180,12 @@ static int emit_bpf_tail_call(struct jit_ctx *ctx) /* tmp2[0] = array, tmp2[1] = index */ - /* if (tail_call_cnt > MAX_TAIL_CALL_CNT) + /* if (tail_call_cnt >= MAX_TAIL_CALL_CNT) * goto out; * tail_call_cnt++; */ - lo = (u32)MAX_TAIL_CALL_CNT; - hi = (u32)((u64)MAX_TAIL_CALL_CNT >> 32); + lo = (u32)(MAX_TAIL_CALL_CNT - 1); + hi = (u32)((u64)(MAX_TAIL_CALL_CNT - 1) >> 32); tc = arm_bpf_get_reg64(tcc, tmp, ctx); emit(ARM_CMP_I(tc[0], hi), ctx); _emit(ARM_COND_EQ, ARM_CMP_I(tc[1], lo), ctx); From patchwork Mon Aug 9 09:34:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Almbladh X-Patchwork-Id: 12426059 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3583C432BE for ; Mon, 9 Aug 2021 09:35:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CB7E86108D for ; Mon, 9 Aug 2021 09:35:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234700AbhHIJfi (ORCPT ); Mon, 9 Aug 2021 05:35:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234678AbhHIJfc (ORCPT ); Mon, 9 Aug 2021 05:35:32 -0400 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7C0DC061796 for ; Mon, 9 Aug 2021 02:35:11 -0700 (PDT) Received: by mail-ed1-x52d.google.com with SMTP id x14so1050526edr.12 for ; Mon, 09 Aug 2021 02:35:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anyfinetworks-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sh4cRycWMWzCRbwiJkF7TB0944OQB2vAB6mEODY+LIg=; b=UQLPkMecDxAZpR9aawXrXnanYl9BJUEr9P94N1ku9/joi9jSxjkfM8192rdduNtFW3 RGpyk2HYyTLTjqhluWXfD1V13U7wh5KwZyha4weRHIqpT8qAz8ujBcwKhemXhsz9uOHS 7CTmYfwM/Rd6zjg29OamtWlDALGITRyPIDL8e8hU0Mtu/dt4Way3dXmEo9DtqMc2ehAZ BDuGU0P6pryHmdgpmFDES27DRgl44cK/xXvBIrZhKytlGSoToCrEL2W0DmWQlCO4BQpJ VJcBcxxfCoanBSDOPd5ROO6Tbu3Igv8J6yts+DDcjjb/RPz1jEF7X+mHUSXVg4NyQPnp FDqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sh4cRycWMWzCRbwiJkF7TB0944OQB2vAB6mEODY+LIg=; b=pvg3M2rHzWZCHpZhnBGVSU18eF7oInl7UyAVYy4WV7HABlHtBKznJJbr0X8+m7rRsC XdzG5mR77aLhxGu968TyKO06w30J7KfXi4RLdzzgQc5cS8E0jpSqHinVx7+z6zo1x/CF nMwv44/H82ryGM1vD5C1XnqM16lf6ifC0kS8kq0hvK3u7S/3jc4orgtMQE1FXHvDDy5b 9FkOdGqfEJv76mFSfRAR4dlz3sca1SwyQ5B7qnzpGPM8j5TelB8z8Ju4vnY9PuBfmC9n gVF7caO4cFApMJtSu3YVFvDeceKgog0M6YLopB4PiT8syWozO634fhTPSaSG624+Cx+g Lt2w== X-Gm-Message-State: AOAM531YMdyifhSe4iR2lrzaDU70fS9BDWrKvnQVN1okBmCQAWhqw8PA jj1zs12G/bgXrZSFK/9ODytzqQ== X-Google-Smtp-Source: ABdhPJwukWaouuhkMqhAfHZRo40lEF5CPK9OrONFO8LhcrFR7OMhHw2Ea+L3a6BBHTvJO3055LHlpA== X-Received: by 2002:a05:6402:c1b:: with SMTP id co27mr28669384edb.147.1628501710408; Mon, 09 Aug 2021 02:35:10 -0700 (PDT) Received: from anpc2.lan (static-213-115-136-2.sme.telenor.se. [213.115.136.2]) by smtp.gmail.com with ESMTPSA id c8sm1989732ejp.124.2021.08.09.02.35.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Aug 2021 02:35:10 -0700 (PDT) From: Johan Almbladh To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org Cc: kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, illusionist.neo@gmail.com, zlim.lnx@gmail.com, paulburton@kernel.org, naveen.n.rao@linux.ibm.com, sandipan@linux.ibm.com, luke.r.nels@gmail.com, bjorn@kernel.org, iii@linux.ibm.com, hca@linux.ibm.com, gor@linux.ibm.com, davem@davemloft.net, udknight@gmail.com, Johan Almbladh Subject: [PATCH bpf-next 2/7] arm64: bpf: Fix off-by-one in tail call count limiting Date: Mon, 9 Aug 2021 11:34:32 +0200 Message-Id: <20210809093437.876558-3-johan.almbladh@anyfinetworks.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210809093437.876558-1-johan.almbladh@anyfinetworks.com> References: <20210809093437.876558-1-johan.almbladh@anyfinetworks.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Before, the eBPF JIT allowed up to MAX_TAIL_CALL_CNT + 1 tail calls. Now, precisely MAX_TAIL_CALL_CNT is allowed, which is in line with the behaviour of the interpreter. Verified with the test_bpf test suite on qemu-system-aarch64. Signed-off-by: Johan Almbladh --- arch/arm64/net/bpf_jit_comp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c index 41c23f474ea6..cda53e33bbec 100644 --- a/arch/arm64/net/bpf_jit_comp.c +++ b/arch/arm64/net/bpf_jit_comp.c @@ -286,11 +286,11 @@ static int emit_bpf_tail_call(struct jit_ctx *ctx) emit(A64_CMP(0, r3, tmp), ctx); emit(A64_B_(A64_COND_CS, jmp_offset), ctx); - /* if (tail_call_cnt > MAX_TAIL_CALL_CNT) + /* if (tail_call_cnt >= MAX_TAIL_CALL_CNT) * goto out; * tail_call_cnt++; */ - emit_a64_mov_i64(tmp, MAX_TAIL_CALL_CNT, ctx); + emit_a64_mov_i64(tmp, MAX_TAIL_CALL_CNT - 1, ctx); emit(A64_CMP(1, tcc, tmp), ctx); emit(A64_B_(A64_COND_HI, jmp_offset), ctx); emit(A64_ADD_I(1, tcc, tcc, 1), ctx); From patchwork Mon Aug 9 09:34:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Almbladh X-Patchwork-Id: 12426057 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33986C4338F for ; Mon, 9 Aug 2021 09:35:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1BA4F6108F for ; Mon, 9 Aug 2021 09:35:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234695AbhHIJfh (ORCPT ); Mon, 9 Aug 2021 05:35:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234643AbhHIJfd (ORCPT ); Mon, 9 Aug 2021 05:35:33 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2013AC061798 for ; Mon, 9 Aug 2021 02:35:13 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id y7so23577008eda.5 for ; Mon, 09 Aug 2021 02:35:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anyfinetworks-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zTHGmLGouU4onJNlIUfhsVpstydj2zsoOFj28SOcX2I=; b=AsmMb0l1iIz/FbTwdxzIK/MmEhR8aE+v2biehMPNoBacgy0P8h0nEnKVQSxZm6UcfZ s9UBA/ZcHKc9BGCQLDWt9oDF9iEhDoy4i8+vVtFfPvN7qRxZcJ/rA/hCZM+newx7krGk yidWXthlsTvdgy2goJGOqYgJeip0oKPUJTVk/u2K1qwRhbZCJGq6s/TDIJhkmdhlokry /bCec6Nz4QxgsE8BLhpdTkTE7VlGhfJs5GU+3FHmG5Y4rRx4sn3AqDfcQ7ZRf61oKBEP wN8GN4NSy57T98MKKll/4n3rBW2/czgFcydK7OqUUtZZKxMbJId7loF2ErWnjQ9f2V59 6yzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zTHGmLGouU4onJNlIUfhsVpstydj2zsoOFj28SOcX2I=; b=X0eFX5UbCpyb2BsolXNkhUXBmVxpqWDQtLfImgs9rS+WroTBlSRQg8TSnHWkeruKer ybZUuKtU7j0DPQ31Z5VpBYYq0T6gEFFEbLw+Cuc3GjmgBe4qQ2Not33UPycZWRBb7C/a 04RZ7+v5Jq+az67sfx+Q0X2EGPGn/qY1ZaqhrhH/mPvY4iPCimXn8YGQelJk4atqSKgB 1I5PmOMHVPUVYitWTGIJUDph+l/R2CN7XdIXV586j9pBoJ29Tet58U6dW5Mk6dU6DiRe mbLpb+wNi2b9KAfyegMuV03R6chcAIEaF4Elx3sj7CxmPDz1UgVgu7p7+FuKURnz5Grk rDDg== X-Gm-Message-State: AOAM5337x82Nbg3ky8QXScfNdwq/MnEjBNFacuDwjfFJ+5lM1mrHBkLq olFyfr6hGf7NndKTeDgkjT2Shw== X-Google-Smtp-Source: ABdhPJw2NYrzipLDFdyGBZ/wzTS6WLyxGQTpv32qMIVFb9661DjUwT8fRBeleuy37oJGVX86uzt+5g== X-Received: by 2002:aa7:d40f:: with SMTP id z15mr777078edq.113.1628501711748; Mon, 09 Aug 2021 02:35:11 -0700 (PDT) Received: from anpc2.lan (static-213-115-136-2.sme.telenor.se. [213.115.136.2]) by smtp.gmail.com with ESMTPSA id c8sm1989732ejp.124.2021.08.09.02.35.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Aug 2021 02:35:11 -0700 (PDT) From: Johan Almbladh To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org Cc: kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, illusionist.neo@gmail.com, zlim.lnx@gmail.com, paulburton@kernel.org, naveen.n.rao@linux.ibm.com, sandipan@linux.ibm.com, luke.r.nels@gmail.com, bjorn@kernel.org, iii@linux.ibm.com, hca@linux.ibm.com, gor@linux.ibm.com, davem@davemloft.net, udknight@gmail.com, Johan Almbladh Subject: [PATCH bpf-next 3/7] powerpc: bpf: Fix off-by-one in tail call count limiting Date: Mon, 9 Aug 2021 11:34:33 +0200 Message-Id: <20210809093437.876558-4-johan.almbladh@anyfinetworks.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210809093437.876558-1-johan.almbladh@anyfinetworks.com> References: <20210809093437.876558-1-johan.almbladh@anyfinetworks.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Before, the eBPF JITs allowed up to MAX_TAIL_CALL_CNT + 1 tail calls. Now, precisely MAX_TAIL_CALL_CNT is allowed, which is in line with the behaviour of the interpreter. Verified with the test_bpf test suite on qemu-system-ppc and qemu-system-ppc64, respectively. Signed-off-by: Johan Almbladh --- arch/powerpc/net/bpf_jit_comp32.c | 4 ++-- arch/powerpc/net/bpf_jit_comp64.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/powerpc/net/bpf_jit_comp32.c b/arch/powerpc/net/bpf_jit_comp32.c index beb12cbc8c29..6d720728df09 100644 --- a/arch/powerpc/net/bpf_jit_comp32.c +++ b/arch/powerpc/net/bpf_jit_comp32.c @@ -221,13 +221,13 @@ static void bpf_jit_emit_tail_call(u32 *image, struct codegen_context *ctx, u32 PPC_BCC(COND_GE, out); /* - * if (tail_call_cnt > MAX_TAIL_CALL_CNT) + * if (tail_call_cnt >= MAX_TAIL_CALL_CNT) * goto out; */ EMIT(PPC_RAW_CMPLWI(_R0, MAX_TAIL_CALL_CNT)); /* tail_call_cnt++; */ EMIT(PPC_RAW_ADDIC(_R0, _R0, 1)); - PPC_BCC(COND_GT, out); + PPC_BCC(COND_GE, out); /* prog = array->ptrs[index]; */ EMIT(PPC_RAW_RLWINM(_R3, b2p_index, 2, 0, 29)); diff --git a/arch/powerpc/net/bpf_jit_comp64.c b/arch/powerpc/net/bpf_jit_comp64.c index b87a63dba9c8..2f4d24ed90a4 100644 --- a/arch/powerpc/net/bpf_jit_comp64.c +++ b/arch/powerpc/net/bpf_jit_comp64.c @@ -227,12 +227,12 @@ static void bpf_jit_emit_tail_call(u32 *image, struct codegen_context *ctx, u32 PPC_BCC(COND_GE, out); /* - * if (tail_call_cnt > MAX_TAIL_CALL_CNT) + * if (tail_call_cnt >= MAX_TAIL_CALL_CNT) * goto out; */ PPC_BPF_LL(b2p[TMP_REG_1], 1, bpf_jit_stack_tailcallcnt(ctx)); EMIT(PPC_RAW_CMPLWI(b2p[TMP_REG_1], MAX_TAIL_CALL_CNT)); - PPC_BCC(COND_GT, out); + PPC_BCC(COND_GE, out); /* * tail_call_cnt++; From patchwork Mon Aug 9 09:34:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Almbladh X-Patchwork-Id: 12426061 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DFA40C432BE for ; Mon, 9 Aug 2021 09:35:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C7C03610A4 for ; Mon, 9 Aug 2021 09:35:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234708AbhHIJfl (ORCPT ); Mon, 9 Aug 2021 05:35:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234661AbhHIJff (ORCPT ); Mon, 9 Aug 2021 05:35:35 -0400 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63B82C0613CF for ; Mon, 9 Aug 2021 02:35:14 -0700 (PDT) Received: by mail-ed1-x532.google.com with SMTP id b7so23628293edu.3 for ; Mon, 09 Aug 2021 02:35:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anyfinetworks-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4iS6lRKIwb+H10UNVM+WiLO7lEaIzX0B59TM+au6wcw=; b=x1V+cagpq3wEGAJilDAKJQcSJGRsCCB/uIe2wAhFp5isaA2ACd6+KXpzIZ5JNKZh09 LNpCcPX8fePyollrGcX5JgiBfntG2JJ/yp/wh9r361sToCdDP93GB+GSeG9RpgSHIf/k 57ypxzAEKI5E297XqDfRr3ldN7a1gRAKvS/KVqzfVMBaR2hn/o/cOnCsMvrOMjvMGLlw idfW1YI9czbxhEjdJckwQeQN6bhznTHRlbuW5Ak3HC7IrQNkMk9KFIB+8l0X0etk0s9L 3B7t4bWarXMZn23t8XkUfRoxBKphiy2jkKR2AVIM7DfyRcc7iGOzFsOC6z/mXa6HTo1I w6Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4iS6lRKIwb+H10UNVM+WiLO7lEaIzX0B59TM+au6wcw=; b=qgnp+NIGYrPlBpTyL4yoegyrvl43+xLT8kjnwKjoJKIIJepa3m/DY/h/36kmtfzwOK 1qKPN1WL2OeY2YnM1CazrUHczkSO12RMuFcmzsBNU6kgL8M//Jh7tE4rPKaf0U9UWf0p +JHmzlmSmo4LqnfHUOOhmCd/KIdl8snUzc0IeMY+MbrRTimDcFmzwn/UVKvZ6IDPamrG o8HchMTPJ+FAJE9wfLmIkBszioDYroppDNPQN4CfhsIygTTzuOj/t3yKAJ4vbPsOlC/Y cGAKoBzOuDK1uZbrlS+EAqvIKQpZpesLi4MfcakxW/2JheQEKoVHv+p3l5pI+pI3SCUE 1RvQ== X-Gm-Message-State: AOAM533mpFbfaEZnRSC8EK/VC2QmgeurVVQlIKxWOD3yd4c8gsJ1z8Jz fvClXFqmgu2/s/WeqxOaNsOGwA== X-Google-Smtp-Source: ABdhPJwiy2AKXZpcwV2uYAGh60iTXCl2cnz4TRR2Q491uFzgpMgRHbDLtElSFveFDXwO1Y5XlnSGuQ== X-Received: by 2002:a05:6402:b88:: with SMTP id cf8mr1997348edb.281.1628501713083; Mon, 09 Aug 2021 02:35:13 -0700 (PDT) Received: from anpc2.lan (static-213-115-136-2.sme.telenor.se. [213.115.136.2]) by smtp.gmail.com with ESMTPSA id c8sm1989732ejp.124.2021.08.09.02.35.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Aug 2021 02:35:12 -0700 (PDT) From: Johan Almbladh To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org Cc: kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, illusionist.neo@gmail.com, zlim.lnx@gmail.com, paulburton@kernel.org, naveen.n.rao@linux.ibm.com, sandipan@linux.ibm.com, luke.r.nels@gmail.com, bjorn@kernel.org, iii@linux.ibm.com, hca@linux.ibm.com, gor@linux.ibm.com, davem@davemloft.net, udknight@gmail.com, Johan Almbladh Subject: [PATCH bpf-next 4/7] s390: bpf: Fix off-by-one in tail call count limiting Date: Mon, 9 Aug 2021 11:34:34 +0200 Message-Id: <20210809093437.876558-5-johan.almbladh@anyfinetworks.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210809093437.876558-1-johan.almbladh@anyfinetworks.com> References: <20210809093437.876558-1-johan.almbladh@anyfinetworks.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Before, the eBPF JIT allowed up to MAX_TAIL_CALL_CNT + 1 tail calls. Now, precisely MAX_TAIL_CALL_CNT is allowed, which is in line with the behaviour of the interpreter. Verified with the test_bpf test suite on qemu-system-s390x. Signed-off-by: Johan Almbladh Tested-by: Ilya Leoshkevich Acked-by: Ilya Leoshkevich --- arch/s390/net/bpf_jit_comp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c index 88419263a89a..f6cdf13285ed 100644 --- a/arch/s390/net/bpf_jit_comp.c +++ b/arch/s390/net/bpf_jit_comp.c @@ -1363,7 +1363,7 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp, jit->prg); /* - * if (tail_call_cnt++ > MAX_TAIL_CALL_CNT) + * if (tail_call_cnt++ >= MAX_TAIL_CALL_CNT) * goto out; */ @@ -1377,8 +1377,8 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp, EMIT6_DISP_LH(0xeb000000, 0x00fa, REG_W1, REG_W0, REG_15, off); /* clij %w1,MAX_TAIL_CALL_CNT,0x2,out */ patch_2_clij = jit->prg; - EMIT6_PCREL_RIEC(0xec000000, 0x007f, REG_W1, MAX_TAIL_CALL_CNT, - 2, jit->prg); + EMIT6_PCREL_RIEC(0xec000000, 0x007f, REG_W1, + MAX_TAIL_CALL_CNT - 1, 2, jit->prg); /* * prog = array->ptrs[index]; From patchwork Mon Aug 9 09:34:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Almbladh X-Patchwork-Id: 12426063 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62153C43214 for ; Mon, 9 Aug 2021 09:35:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3C8506108F for ; Mon, 9 Aug 2021 09:35:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234719AbhHIJfn (ORCPT ); Mon, 9 Aug 2021 05:35:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234688AbhHIJfg (ORCPT ); Mon, 9 Aug 2021 05:35:36 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEF78C061798 for ; Mon, 9 Aug 2021 02:35:15 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id oz16so11633722ejc.7 for ; Mon, 09 Aug 2021 02:35:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anyfinetworks-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3oERsgPvzwB7GwC2qkKhn+IS25jGzMfr+VwIN1gXGn0=; b=m9dNA8uh5kZm232vvfEoaTZLzR2LIlZFku02Am3SMwIBCfr5mYXPMIRmZxVq3g1sdR o69VF12H7WcvVcOUuakkXGuJL4J6TLZ8UDiKSZ//4ztVa4gCjQ2A4LhODxtyKbdpWtcA EFiY1fJotJ5qUH6Js1VchCvRpqA6HoDXkgibXS/uHaUDpTUvIm70bbGWf4NzdRmkBDh6 zdfliv0ZGITB9drvSS9RMhhJGj2YdfF7qxCe8a0rxofOpgOVyojLDt+39w36McFxI4Zt 8bYaKgRyFzN6rrv+lzY202w41ElyR5TxNm9g0ttGUBJBfl8YW0byglhBUB59wM+oIkjS R8PA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3oERsgPvzwB7GwC2qkKhn+IS25jGzMfr+VwIN1gXGn0=; b=L86kuvkk2BYf16C/LPFvzKhDE2ZFTFx4eGk9yZWMqFOlJARpkMJwUMNzibSY16CHol j3e2MsFtkY6078T/4Nu9oDhZoHDFgxQtzcD88psvLuTgkeRiaFS76RohKQw8BvPgAtZq NcMPiOVHbT7OdeaeIaHQNhrvIJ9xn1pa8gTf/DNr8L2iNUX26C6YKGgwrU2FQ9iXknaj 6SF3vmUK5+y0P64sYBeVbmwW83X3L1z5d0l3gt7gxCNBicILffFrcez9DzwZIackOSNu G52iicrWBom119CD8P18beRLRuuHZkBkD1LpWFIN6Rcj/qyWxLgnUZ4dwKBFmch57Z38 x83w== X-Gm-Message-State: AOAM5310jSlFPseFp/q7Cy15JsWVm3gTKhg9679n8ExkecfDOTdFf8WD yFLKOyE7AmoXDhlOEFJiZpCkQg== X-Google-Smtp-Source: ABdhPJxMUrgkw5idBC4jX8/Cq44edJLzgtYJYzA+EAEzlFLW84s6xcLSYq+nxax2zYveW18KndP9cg== X-Received: by 2002:a17:906:c4c:: with SMTP id t12mr7535683ejf.217.1628501714407; Mon, 09 Aug 2021 02:35:14 -0700 (PDT) Received: from anpc2.lan (static-213-115-136-2.sme.telenor.se. [213.115.136.2]) by smtp.gmail.com with ESMTPSA id c8sm1989732ejp.124.2021.08.09.02.35.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Aug 2021 02:35:14 -0700 (PDT) From: Johan Almbladh To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org Cc: kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, illusionist.neo@gmail.com, zlim.lnx@gmail.com, paulburton@kernel.org, naveen.n.rao@linux.ibm.com, sandipan@linux.ibm.com, luke.r.nels@gmail.com, bjorn@kernel.org, iii@linux.ibm.com, hca@linux.ibm.com, gor@linux.ibm.com, davem@davemloft.net, udknight@gmail.com, Johan Almbladh Subject: [PATCH bpf-next 5/7] sparc: bpf: Fix off-by-one in tail call count limiting Date: Mon, 9 Aug 2021 11:34:35 +0200 Message-Id: <20210809093437.876558-6-johan.almbladh@anyfinetworks.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210809093437.876558-1-johan.almbladh@anyfinetworks.com> References: <20210809093437.876558-1-johan.almbladh@anyfinetworks.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Before, the eBPF JIT allowed up to MAX_TAIL_CALL_CNT + 1 tail calls. Now, precisely MAX_TAIL_CALL_CNT is allowed, which is in line with the behaviour of the interpreter. Verified with the test_bpf test suite on qemu-system-sparc64. Signed-off-by: Johan Almbladh --- arch/sparc/net/bpf_jit_comp_64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/sparc/net/bpf_jit_comp_64.c b/arch/sparc/net/bpf_jit_comp_64.c index 9a2f20cbd48b..0bfe1c72a0c9 100644 --- a/arch/sparc/net/bpf_jit_comp_64.c +++ b/arch/sparc/net/bpf_jit_comp_64.c @@ -867,7 +867,7 @@ static void emit_tail_call(struct jit_ctx *ctx) emit(LD32 | IMMED | RS1(SP) | S13(off) | RD(tmp), ctx); emit_cmpi(tmp, MAX_TAIL_CALL_CNT, ctx); #define OFFSET2 13 - emit_branch(BGU, ctx->idx, ctx->idx + OFFSET2, ctx); + emit_branch(BGEU, ctx->idx, ctx->idx + OFFSET2, ctx); emit_nop(ctx); emit_alu_K(ADD, tmp, 1, ctx); From patchwork Mon Aug 9 09:34:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Almbladh X-Patchwork-Id: 12426065 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5DC3C4320E for ; Mon, 9 Aug 2021 09:35:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CA6C26108D for ; Mon, 9 Aug 2021 09:35:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234746AbhHIJfp (ORCPT ); Mon, 9 Aug 2021 05:35:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234693AbhHIJfh (ORCPT ); Mon, 9 Aug 2021 05:35:37 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AE13C061799 for ; Mon, 9 Aug 2021 02:35:17 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id by4so4833620edb.0 for ; Mon, 09 Aug 2021 02:35:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anyfinetworks-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=R8nPDlZ8MIDkJQ2qkzTmbl3dcManmeczWh/bnjgLMVI=; b=OJWw8If8eUJX/1o8BHkJ3jcN6fHCR8vVBjKDYajxsg2E5xub9TtztBSzpu147bvKaG 0aI58UN62MjGAdmuV/uWicHe2G5gwrqIqUm+246Egdnsdd4vTb49/g98J2/WfBIkjDCG P+wbVrDxeCq4ctNdUTVFUq1DbOlds9p/ROk3Vo8aw6wKPJDGqJejvubAsUZWpeIhWguB WVGL/KCObOUx+VtZZJskFZCIFsyxmd815JT3FXQR2BELGce81kBzV1iNpvS/1iXhTKLh 2zx4TDRUNFM2F2W/7KeJz1piJYP2/Mkr4lOPU2KNV9Q/UyE2DjR/Jczy8bf7dReEqDc2 qAiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=R8nPDlZ8MIDkJQ2qkzTmbl3dcManmeczWh/bnjgLMVI=; b=sptV+NPCahlwPvyMopST2GU2k8wHpVDYvBoa2/5qw78XLJBd/6JYPDauoXdZ/nDnPV pXw6M76OFbg8GQn+6gjwn3TvwBibW5KwI6JrMNlRsHfJj3j3TBgAI/rU8qdmKj+DGKXa xTtC/a+J0eyjrtvxkB5DCE4+ykU9ja/H2KVzFvVffWrVGEluAnA0TYqdnor6fqhbaCZI 5uyacOTbCBbzgulbhQ4SQRHUoBQgTDbfnjLjiLlBIzIottwwko95CBxNT/xafwR8gQV+ H75firOAFHlfMDlKsmtTVfnpInnUjdP002MaNj5AWZqbNGgGx81rNO1Dlo+8BR1innG1 0+KQ== X-Gm-Message-State: AOAM533zQUKZnchdRuHzX8UE7d1bd75t7H+L/7ecSVSnF2Pka0nOCsp8 6XF3FqXpRyD1umejr1C4Wg4ZBg== X-Google-Smtp-Source: ABdhPJzjUGd0t7g3ba5yr7i3vWuv/aPgvCA+VCrgqtGO73BQBNvPUR6zOYdWoOWtky9wyqx3QW737w== X-Received: by 2002:aa7:da52:: with SMTP id w18mr11638224eds.48.1628501715756; Mon, 09 Aug 2021 02:35:15 -0700 (PDT) Received: from anpc2.lan (static-213-115-136-2.sme.telenor.se. [213.115.136.2]) by smtp.gmail.com with ESMTPSA id c8sm1989732ejp.124.2021.08.09.02.35.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Aug 2021 02:35:15 -0700 (PDT) From: Johan Almbladh To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org Cc: kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, illusionist.neo@gmail.com, zlim.lnx@gmail.com, paulburton@kernel.org, naveen.n.rao@linux.ibm.com, sandipan@linux.ibm.com, luke.r.nels@gmail.com, bjorn@kernel.org, iii@linux.ibm.com, hca@linux.ibm.com, gor@linux.ibm.com, davem@davemloft.net, udknight@gmail.com, Johan Almbladh Subject: [PATCH bpf-next 6/7] mips: bpf: Fix off-by-one in tail call count limiting Date: Mon, 9 Aug 2021 11:34:36 +0200 Message-Id: <20210809093437.876558-7-johan.almbladh@anyfinetworks.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210809093437.876558-1-johan.almbladh@anyfinetworks.com> References: <20210809093437.876558-1-johan.almbladh@anyfinetworks.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Before, the eBPF JIT allowed up to MAX_TAIL_CALL_CNT + 1 tail calls. Now, precisely MAX_TAIL_CALL_CNT is allowed, which is in line with the behaviour of the interpreter. Verified with the test_bpf test suite on qemu-system-mips64. Signed-off-by: Johan Almbladh --- arch/mips/net/ebpf_jit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/mips/net/ebpf_jit.c b/arch/mips/net/ebpf_jit.c index 3a73e9375712..a93121d71c80 100644 --- a/arch/mips/net/ebpf_jit.c +++ b/arch/mips/net/ebpf_jit.c @@ -617,14 +617,14 @@ static int emit_bpf_tail_call(struct jit_ctx *ctx, int this_idx) b_off = b_imm(this_idx + 1, ctx); emit_instr(ctx, bne, MIPS_R_AT, MIPS_R_ZERO, b_off); /* - * if (TCC-- < 0) + * if (TCC-- <= 0) * goto out; */ /* Delay slot */ tcc_reg = (ctx->flags & EBPF_TCC_IN_V1) ? MIPS_R_V1 : MIPS_R_S4; emit_instr(ctx, daddiu, MIPS_R_T5, tcc_reg, -1); b_off = b_imm(this_idx + 1, ctx); - emit_instr(ctx, bltz, tcc_reg, b_off); + emit_instr(ctx, blez, tcc_reg, b_off); /* * prog = array->ptrs[index]; * if (prog == NULL) From patchwork Mon Aug 9 09:34:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Almbladh X-Patchwork-Id: 12426067 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 813C9C4338F for ; Mon, 9 Aug 2021 09:35:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 68CDE610FC for ; Mon, 9 Aug 2021 09:35:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234730AbhHIJfr (ORCPT ); Mon, 9 Aug 2021 05:35:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234702AbhHIJfi (ORCPT ); Mon, 9 Aug 2021 05:35:38 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BA1BC06179C for ; Mon, 9 Aug 2021 02:35:18 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id gs8so27724555ejc.13 for ; Mon, 09 Aug 2021 02:35:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anyfinetworks-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zUdGMump2UWFWhTKE7J223AILDuinxW6u2xGASPuBak=; b=I3AQTEXrs1Ypvdh/NfJ5dPwI7kXzCsA4vpIfrRac281YFW6gX31aJxlNNd0VZDXxh2 g48TlyO8w+ajNulrRKi5tWvNvuMGnu9VLWT9CqrV4R+tC6W3eStplkyYH0aWis0nJUG0 vSGlgPcO3RNP2YlJlgLts2T15TxYhB8c6gvZlh6I3YSJ1cprfzcVTlMdCzCGEMaU8IWT rBpStECV3oJqKCnQgaMU572DRaUYrTNdQfDZbvF2fw1ZRi1ZQAZo3XaVxCIp9jolTyxP Q/RRwN4Ir1N6nZYhqr7tII29uAV8oeKkykyjMUOtkpa41wWZX79G8ygakVWX9cSm6k9h 1H5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zUdGMump2UWFWhTKE7J223AILDuinxW6u2xGASPuBak=; b=MTwkPWxso0noN3/8m2HSQHXdbCkx01nz72tyv3W736J3sLw7FvWWT5mgL4O+BqHew9 tEHzMyRYgL3hXu9hH0J2u71n8g8SCBZNdM1t+5snDcsGdSFC0Y8gl8PCNR9kYOcXqFsw s6W59YEbmEeAjEEmuzsJzJX/HdZq59Wf6pNG8EI5t5ooMzG4ieqnQDI0WtitSoOETbo+ UdNTXhz0ffdH5IwWgNAPFx4UOnRjflJqE7s1cEBtQFDbJYzi/69N4JYLGfqNMDdoAsX7 oxryndBQ/kNFkYxQpm4kkJZG2lyTYw1g6Skot+jUqpdxDbxc12JHOosZ233qtEyAWP58 hUVQ== X-Gm-Message-State: AOAM531gi8PHBIYmtGUrc0i6LehBDerCU5BRFlf0HcPcUmc4CRSq/rPC WYapzke45YhLAxFKX9mi29q5/w== X-Google-Smtp-Source: ABdhPJzyTxuK5wBGFCXksJ9TUSHIWviY75jd8NuV5w9DeBlaY0I27Zv/YBnjY0fh7unkMFutWEJYQw== X-Received: by 2002:a17:906:a018:: with SMTP id p24mr21453229ejy.349.1628501717082; Mon, 09 Aug 2021 02:35:17 -0700 (PDT) Received: from anpc2.lan (static-213-115-136-2.sme.telenor.se. [213.115.136.2]) by smtp.gmail.com with ESMTPSA id c8sm1989732ejp.124.2021.08.09.02.35.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Aug 2021 02:35:16 -0700 (PDT) From: Johan Almbladh To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org Cc: kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, illusionist.neo@gmail.com, zlim.lnx@gmail.com, paulburton@kernel.org, naveen.n.rao@linux.ibm.com, sandipan@linux.ibm.com, luke.r.nels@gmail.com, bjorn@kernel.org, iii@linux.ibm.com, hca@linux.ibm.com, gor@linux.ibm.com, davem@davemloft.net, udknight@gmail.com, Johan Almbladh Subject: [PATCH bpf-next 7/7] x86: bpf: Fix comments on tail call count limiting Date: Mon, 9 Aug 2021 11:34:37 +0200 Message-Id: <20210809093437.876558-8-johan.almbladh@anyfinetworks.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210809093437.876558-1-johan.almbladh@anyfinetworks.com> References: <20210809093437.876558-1-johan.almbladh@anyfinetworks.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Before, the comments in the 32-bit eBPF JIT claimed that up to MAX_TAIL_CALL_CNT + 1 tail calls were allowed, when in fact the implementation was using the correct limit of MAX_TAIL_CALL_CNT. Now, the comments are in line with what the code actually does. Signed-off-by: Johan Almbladh --- arch/x86/net/bpf_jit_comp32.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/net/bpf_jit_comp32.c b/arch/x86/net/bpf_jit_comp32.c index 3bfda5f502cb..8db9ab11abda 100644 --- a/arch/x86/net/bpf_jit_comp32.c +++ b/arch/x86/net/bpf_jit_comp32.c @@ -1272,7 +1272,7 @@ static void emit_epilogue(u8 **pprog, u32 stack_depth) * ... bpf_tail_call(void *ctx, struct bpf_array *array, u64 index) ... * if (index >= array->map.max_entries) * goto out; - * if (++tail_call_cnt > MAX_TAIL_CALL_CNT) + * if (tail_call_cnt++ >= MAX_TAIL_CALL_CNT) * goto out; * prog = array->ptrs[index]; * if (prog == NULL) @@ -1307,7 +1307,7 @@ static void emit_bpf_tail_call(u8 **pprog) EMIT2(IA32_JBE, jmp_label(jmp_label1, 2)); /* - * if (tail_call_cnt > MAX_TAIL_CALL_CNT) + * if (tail_call_cnt >= MAX_TAIL_CALL_CNT) * goto out; */ lo = (u32)MAX_TAIL_CALL_CNT; @@ -1321,7 +1321,7 @@ static void emit_bpf_tail_call(u8 **pprog) /* cmp ecx,lo */ EMIT3(0x83, add_1reg(0xF8, IA32_ECX), lo); - /* ja out */ + /* jae out */ EMIT2(IA32_JAE, jmp_label(jmp_label1, 2)); /* add eax,0x1 */