Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp112124ybg; Mon, 8 Jun 2020 17:57:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyImpVEMZfBnHvovaikn92xkea6UVXIeXMhEjdHuUiR0nzf4DnspHF7dZMhGJyszKASwHFK X-Received: by 2002:a50:934e:: with SMTP id n14mr24625661eda.88.1591664230180; Mon, 08 Jun 2020 17:57:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591664230; cv=none; d=google.com; s=arc-20160816; b=V4SJEAVHtTB8GSNHqhlcINgqU6wEv+xyyHIFHpX4wflJpDOo9ZstMGs3rUPXYhufhv nQtAhJus00hZb6myputsbTdMmLGOJa/YqQz8N1GBynmXasPKIFMLjKz+Aeo44eSfFAgx 00w1tH/9eE1ZuDpVShptSborvLwNzGLNVsZvFPgUZsZNIkc6q8pnOWSvIpzZ3wEyNkKF XQS5qSQ1X1Dic1WzKUYg5LgjRguMWonyL436WWmSf+j545g8ed95c+wVA1mHKAfcZyPt XoI/rti1pmWj45JRMfnrRluLZv1TGfOsSbwt2SWGAgY5RkoNJxXc6IbbtcJrAHfp+ETR d2vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=EkKGUJi847ZVYRroIctEfxsrydJW/qvSQCFgRykvjC8=; b=v8jkf5qe2OGMPPbYyUbU4fuoBxn5OFH+v616zcHB1CLKnn2fNv+qAb0CBtJLE2dt2J Rq2x9UAQtVmMhUTXi901L7NzNe5nC5qN9LLzj+qYgaGtCPRHjpjW+Bq5eoFK6Tu1TV/q 53NaHCpcdpOebPmjgAwUnKkPZigeZH15rirUOmhflqxRyPQQWXYtexC3cOk9A/+ULxqD AGeB529HcqS9pz3LnEuqVKE1cAOzRa68k2LwBg+6TcilCM3ddFw0NrkHF71+LWcNWJ8P /uYjvFPWO7wdRZq1mSipci8SQ7IfrpI9jC9Y/k7Z0ZGY1EfjbkW42ZP8EP6y/ebX5pM+ 0b4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=AB2x00QQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a9si10570050edm.76.2020.06.08.17.56.41; Mon, 08 Jun 2020 17:57:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=AB2x00QQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728525AbgFHXJw (ORCPT + 99 others); Mon, 8 Jun 2020 19:09:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:54422 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727000AbgFHXIx (ORCPT ); Mon, 8 Jun 2020 19:08:53 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6ED9D2085B; Mon, 8 Jun 2020 23:08:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591657732; bh=fK82cI40GO1yH3Ip1kLba1zXWfkLTxYg+MFpEbXh69w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AB2x00QQzebqBsUwR4YxJzpr5+xeA8I+kaWTScWv1pvzB4lZ32TZQhAQ72rT/0Htb iYMGZaiSMGr4z7ARXLCAUdlKvhYOxRin5QoowGhMP6wiqZswdRHKYnI2JDZ92dWtE7 6L5THfCOknEfk/y7lgBM629S6VtZ+NFlKLGNfXbU= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Luke Nelson , Luke Nelson , Alexei Starovoitov , Xi Wang , Sasha Levin , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH AUTOSEL 5.7 123/274] bpf, riscv: Fix tail call count off by one in RV32 BPF JIT Date: Mon, 8 Jun 2020 19:03:36 -0400 Message-Id: <20200608230607.3361041-123-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200608230607.3361041-1-sashal@kernel.org> References: <20200608230607.3361041-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Luke Nelson [ Upstream commit 745abfaa9eafa597d31fdf24a3249e5206a98768 ] This patch fixes an off by one error in the RV32 JIT handling for BPF tail call. Currently, the code decrements TCC before checking if it is less than zero. This limits the maximum number of tail calls to 32 instead of 33 as in other JITs. The fix is to instead check the old value of TCC before decrementing. Fixes: 5f316b65e99f ("riscv, bpf: Add RV32G eBPF JIT") Signed-off-by: Luke Nelson Signed-off-by: Alexei Starovoitov Acked-by: Xi Wang Link: https://lore.kernel.org/bpf/20200421002804.5118-1-luke.r.nels@gmail.com Signed-off-by: Sasha Levin --- arch/riscv/net/bpf_jit_comp32.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/riscv/net/bpf_jit_comp32.c b/arch/riscv/net/bpf_jit_comp32.c index 302934177760..11083d4d5f2d 100644 --- a/arch/riscv/net/bpf_jit_comp32.c +++ b/arch/riscv/net/bpf_jit_comp32.c @@ -770,12 +770,13 @@ static int emit_bpf_tail_call(int insn, struct rv_jit_context *ctx) emit_bcc(BPF_JGE, lo(idx_reg), RV_REG_T1, off, ctx); /* - * if ((temp_tcc = tcc - 1) < 0) + * temp_tcc = tcc - 1; + * if (tcc < 0) * goto out; */ emit(rv_addi(RV_REG_T1, RV_REG_TCC, -1), ctx); off = (tc_ninsn - (ctx->ninsns - start_insn)) << 2; - emit_bcc(BPF_JSLT, RV_REG_T1, RV_REG_ZERO, off, ctx); + emit_bcc(BPF_JSLT, RV_REG_TCC, RV_REG_ZERO, off, ctx); /* * prog = array->ptrs[index]; -- 2.25.1