Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2633006pxa; Mon, 17 Aug 2020 15:00:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxGocL5CdaEtbP1VEMDayQNLnPp1mdIipPrWBspzyz42qcpExdaaP2pimeBLnHQPQ9WAumE X-Received: by 2002:a17:906:cb0a:: with SMTP id lk10mr16903729ejb.209.1597701647442; Mon, 17 Aug 2020 15:00:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597701647; cv=none; d=google.com; s=arc-20160816; b=l/OWRwfR6Jf9LOZ648VZPCsaHy/S25bhOd37CCuR9oJrbN3vtVa+jiailJb9PDr100 1U0+dvw10aEKM327JVm9pHg/IvqvQ+yTpk5WRIOp6u37ABaoC0ga7rsFbFJcDF3EM6PE GyfZ4/OPD84J9juHpno3USU6NYLeoDFktOKo6UGuqoTlrRJXLKHJ1HBK73qw63HZO/Ma uAvCALp4pcD6q63elOz7T7Ocdkef6kmPCJI+2y9i8J4GR2ohpHIZbCyg8QJazUjMr0oe Xx08qHaoIneHetSGn2dcalRsGXonKXABdhF7bQEh4o8vy4pdlDIdfuqJJLlDb5S9x0Xl AQ4Q== 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=D/h8wlUJjvOZotV9s4fLcVNFAWJt8/wIofX9uMTPxco=; b=CP7Oh5JFvzzqrIE3cMLjCLsoZz8J4mxQWwz5RIkHyb9aPg6T4yuTtRUUqgJAwXqQ3B cUCte2nBprO7N/nFa/xQoqY8Et9Ey1QTKcPGrclCP7fJbjgUssH7DTDVsk8sQxsakqVn 0sE9gNqKsgMjQT/zDQHu1b0zI757YaoqRbRQRwgs5BwPOFcVWpvkPoKAIjx5pyp1DT6W No0Es5PvjKQyu4z5AhUxNEcqkvtc3R7a0Z3XPjmhTBPcsfK/0VD+CSuL0Vu7tPJzm9d7 STx5UlScedbhPbiFuyd5JMQy4F8QZ1Tyhwn9ij070awZXvG+8UuRrgGPyilUOrw1x+/e CqnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=o56TkhcY; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rs7si11933433ejb.165.2020.08.17.15.00.24; Mon, 17 Aug 2020 15:00:47 -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=o56TkhcY; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730544AbgHQPhR (ORCPT + 99 others); Mon, 17 Aug 2020 11:37:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:54636 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730267AbgHQPbM (ORCPT ); Mon, 17 Aug 2020 11:31:12 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 1A2FC22D07; Mon, 17 Aug 2020 15:31:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597678271; bh=NZLbzGdDFevx1h7AaxcS2n8qYxhLa4r240SWQpjOc8M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o56TkhcYNOubYjHfUV33x5Pxv+gPhoIFzShZ90GYkpHTHuAZ5D0vNAtJJ0mRkKrqq 4Ij6dRxhqbQ+amM4yYz8V476WiReOj9gPY0pRM/x7kNPLMXrJMhb4kzUvJJbVLye+w P78JMNaHHGyUswtUm+nJLO3Jd6I6UHkAWnTTTeL0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ilya Leoshkevich , Alexei Starovoitov , Sasha Levin Subject: [PATCH 5.8 276/464] s390/bpf: Tolerate not converging code shrinking Date: Mon, 17 Aug 2020 17:13:49 +0200 Message-Id: <20200817143846.989379419@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143833.737102804@linuxfoundation.org> References: <20200817143833.737102804@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: Ilya Leoshkevich [ Upstream commit 1491b73311a15bb5beeab5d30e03bff761ef6c18 ] "BPF_MAXINSNS: Maximum possible literals" unnecessarily falls back to the interpreter because of failing sanity check in bpf_set_addr. The problem is that there are a lot of branches that can be shrunk, and doing so opens up the possibility to shrink even more. This process does not converge after 3 passes, causing code offsets to change during the codegen pass, which must never happen. Fix by inserting nops during codegen pass in order to preserve code offets. Fixes: 4e9b4a6883dd ("s390/bpf: Use relative long branches") Signed-off-by: Ilya Leoshkevich Signed-off-by: Alexei Starovoitov Link: https://lore.kernel.org/bpf/20200717165326.6786-5-iii@linux.ibm.com Signed-off-by: Sasha Levin --- arch/s390/net/bpf_jit_comp.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c index 6b8968f6e207d..a78c5b59e1ab6 100644 --- a/arch/s390/net/bpf_jit_comp.c +++ b/arch/s390/net/bpf_jit_comp.c @@ -489,6 +489,24 @@ static void save_restore_regs(struct bpf_jit *jit, int op, u32 stack_depth) } while (re <= last); } +static void bpf_skip(struct bpf_jit *jit, int size) +{ + if (size >= 6 && !is_valid_rel(size)) { + /* brcl 0xf,size */ + EMIT6_PCREL_RIL(0xc0f4000000, size); + size -= 6; + } else if (size >= 4 && is_valid_rel(size)) { + /* brc 0xf,size */ + EMIT4_PCREL(0xa7f40000, size); + size -= 4; + } + while (size >= 2) { + /* bcr 0,%0 */ + _EMIT2(0x0700); + size -= 2; + } +} + /* * Emit function prologue * @@ -1503,7 +1521,14 @@ static bool bpf_is_new_addr_sane(struct bpf_jit *jit, int i) */ static int bpf_set_addr(struct bpf_jit *jit, int i) { - if (!bpf_is_new_addr_sane(jit, i)) + int delta; + + if (is_codegen_pass(jit)) { + delta = jit->prg - jit->addrs[i]; + if (delta < 0) + bpf_skip(jit, -delta); + } + if (WARN_ON_ONCE(!bpf_is_new_addr_sane(jit, i))) return -1; jit->addrs[i] = jit->prg; return 0; -- 2.25.1