Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3705776ybv; Mon, 10 Feb 2020 05:03:42 -0800 (PST) X-Google-Smtp-Source: APXvYqwzroJeb4Bhv0uwQ3W/dsQztpbegd0BAI2yWF7sOaTDjVnATkti6ZNhnqPRX4wau3UiQTTG X-Received: by 2002:a9d:4c8e:: with SMTP id m14mr911136otf.245.1581339822250; Mon, 10 Feb 2020 05:03:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581339822; cv=none; d=google.com; s=arc-20160816; b=dVe7tuPh1yElxZ8/8Sa8J6AN9NBgRwpUzZkn8m8WOOFTBsLWSFyB4YdzoDqBmd3ocb pV7WP6Isp1p3J2pvioLr8+Xx13PbpOaXrX8ER611ok+opwrUR0vYLWLSLN33jcaJApTX L2DLh/Gs3mDGJG/qNszaFEKU/jYfvX450TMecxa86JdODM0cQ/ngwdoWxWf8UsxFzMN2 6BCfO+rROOA14xp32l5C5SGbIZQqRAPqUeUAkPij2/HJ9IEMtNg9JjcQZXHpueBbhq07 e8UDheaH2N0p1AML0MPFIkme2tpocU8uX79Q5suMG5wdEXtSt3wz8s5S6EejExW0a0Nu KIkw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ga+P8WNDj/H7xYNyjgcjLZIa44W1e3k+j888CP4CyqM=; b=un4HZT4bRNuCWeC/7urwzz+GDBF9Mb8E9mB7ErVCbWNEsqUuqg/4QcnkFOrWnPN+xr zGUKhcOEMHbS8LJR3MN2lp28URDyOGwpPTodvg30ZNxVEdF8p4cNTIbL5insi4IUgc6J 7ex3O3d/WQSAP0ST8nR7TYrlOrdW1e1Nqh+uyx5PsMn7ongDCXGDpkp8DUXJUiVymRx1 5+/6kJvHWPrpYI5kmj/IRXUkin9AXWeaPTptRV4DN32sQdf0ZwNWgwFLkypBW6QMy03t s8FSM03Lv3AInGeUYaev+OE1zlKhYk0YSmncEQKrj10n2L+ODthSY2GhuCY+f+in9V/V GweQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=F3SmhTtI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n25si147079oij.175.2020.02.10.05.03.28; Mon, 10 Feb 2020 05:03:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=F3SmhTtI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730256AbgBJNCo (ORCPT + 99 others); Mon, 10 Feb 2020 08:02:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:40726 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729001AbgBJMkb (ORCPT ); Mon, 10 Feb 2020 07:40:31 -0500 Received: from localhost (unknown [209.37.97.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3852C208C4; Mon, 10 Feb 2020 12:40:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581338431; bh=m+U00sw7e0xmBxIhKSkjHZxP8XgULJD6o0SKO1wayGA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F3SmhTtIrhaBpVnzr2KK9b6Cc64Nq71uv87HPb3LTcx0aMmGpCc4leML9Xl0hfgZY wPlmnmkxM7337q+DiwIFfAgLi8y1T1vPbba4lZZgfJqCxgux0GQu90eGthRI6eH/+u m4fbSNpdF3pBWOz6o9kryQdnJMf5KV2fLETWzx+M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Daniel Borkmann Subject: [PATCH 5.5 157/367] riscv, bpf: Fix broken BPF tail calls Date: Mon, 10 Feb 2020 04:31:10 -0800 Message-Id: <20200210122439.322516249@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200210122423.695146547@linuxfoundation.org> References: <20200210122423.695146547@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Björn Töpel commit f1003b787c00fbaa4b11619c6b23a885bfce8f07 upstream. The BPF JIT incorrectly clobbered the a0 register, and did not flag usage of s5 register when BPF stack was being used. Fixes: 2353ecc6f91f ("bpf, riscv: add BPF JIT for RV64G") Signed-off-by: Björn Töpel Signed-off-by: Daniel Borkmann Link: https://lore.kernel.org/bpf/20191216091343.23260-2-bjorn.topel@gmail.com Signed-off-by: Greg Kroah-Hartman --- arch/riscv/net/bpf_jit_comp.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) --- a/arch/riscv/net/bpf_jit_comp.c +++ b/arch/riscv/net/bpf_jit_comp.c @@ -120,6 +120,11 @@ static bool seen_reg(int reg, struct rv_ return false; } +static void mark_fp(struct rv_jit_context *ctx) +{ + __set_bit(RV_CTX_F_SEEN_S5, &ctx->flags); +} + static void mark_call(struct rv_jit_context *ctx) { __set_bit(RV_CTX_F_SEEN_CALL, &ctx->flags); @@ -596,7 +601,8 @@ static void __build_epilogue(u8 reg, str emit(rv_addi(RV_REG_SP, RV_REG_SP, stack_adjust), ctx); /* Set return value. */ - emit(rv_addi(RV_REG_A0, RV_REG_A5, 0), ctx); + if (reg == RV_REG_RA) + emit(rv_addi(RV_REG_A0, RV_REG_A5, 0), ctx); emit(rv_jalr(RV_REG_ZERO, reg, 0), ctx); } @@ -1426,6 +1432,10 @@ static void build_prologue(struct rv_jit { int stack_adjust = 0, store_offset, bpf_stack_adjust; + bpf_stack_adjust = round_up(ctx->prog->aux->stack_depth, 16); + if (bpf_stack_adjust) + mark_fp(ctx); + if (seen_reg(RV_REG_RA, ctx)) stack_adjust += 8; stack_adjust += 8; /* RV_REG_FP */ @@ -1443,7 +1453,6 @@ static void build_prologue(struct rv_jit stack_adjust += 8; stack_adjust = round_up(stack_adjust, 16); - bpf_stack_adjust = round_up(ctx->prog->aux->stack_depth, 16); stack_adjust += bpf_stack_adjust; store_offset = stack_adjust - 8;