From mboxrd@z Thu Jan 1 00:00:00 1970 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 0EF9BC4320E for ; Wed, 1 Sep 2021 11:31:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D93796101B for ; Wed, 1 Sep 2021 11:31:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243252AbhIALcX (ORCPT ); Wed, 1 Sep 2021 07:32:23 -0400 Received: from new1-smtp.messagingengine.com ([66.111.4.221]:42585 "EHLO new1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238369AbhIALcT (ORCPT ); Wed, 1 Sep 2021 07:32:19 -0400 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailnew.nyi.internal (Postfix) with ESMTP id 571FC5802DF; Wed, 1 Sep 2021 07:31:22 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 01 Sep 2021 07:31:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kroah.com; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:content-transfer-encoding:in-reply-to; s=fm1; bh=S 1RVPrc/JniTsOu3BXowJ2wtLOesVnuNoMJ1MWL5+Lc=; b=yOfRhLvj3kho2weuO 7r+/zecodQnKYEo0U2s+PaKKrq4GXfZE1bOEJARXZXU+Qmd5kYXbxFiKWVT+vFJ5 LrZOsJ1gvELb1u1nXqjRNeUNby3pN2QW8HFzgiX1LPmza0iH4naxdxpdzMwvrF46 4olrClCssrBePfJ6zEVNJCecpvgPp3ynaUmEUOgZkvsAqjbMUJVXei/aD05BFIbC ujfu7Z6K+Wx/3wqojERCvH49WBDCMG1Nzf1DXWLdsdlaR+7ms2SxK2hzW9kb2nvD PkeBjcVivSfXHXstJ2A67ELhke4srjNOWnc78oCQs56gnF77V+Ms1hxW6m7IQSGf EWl/g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=S1RVPrc/JniTsOu3BXowJ2wtLOesVnuNoMJ1MWL5+ Lc=; b=BKPg07tJE1cUKlzd0dxkj3cOA43c5XguC+N0ICtkb1OR0f6CqiOJzFQYF BgDvBrUt8GO7MVSGDzbyNWP9vCHmsqhSf9i0zhowk802oA+0vHnfFqTZKPlBt9uA LlWpt1PSOhjIlvD2PV42NdQZWueoYAVVTqmlmomQQFvQNNbn6TuMK5OawSe6HLx9 /RkjIjzpwwv/alU9L3dG3X53njGmwaIDTAnwq8uoYCydJcMQg6F8BGu5gIFtnhWt HQuw2MgWGI2avjWC0n5BRfLjrC28UsoKZ65xg4MbZcjvEr/onYuuwoEeXi7npn2E MecJIb4jvxydo9jK4DcFYjMuSIaJw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddruddvfedggeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtugfgjgesthekredttddtjeenucfhrhhomhepifhrvghg ucfmjfcuoehgrhgvgheskhhrohgrhhdrtghomheqnecuggftrfgrthhtvghrnhepueehke ehlefffeeiudetfeekjeffvdeuheejjeffheeludfgteekvdelkeduuddvnecuvehluhhs thgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepghhrvghgsehkrhhorg hhrdgtohhm X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 1 Sep 2021 07:31:20 -0400 (EDT) Date: Wed, 1 Sep 2021 13:31:18 +0200 From: Greg KH To: Thadeu Lima de Souza Cascardo Cc: stable@vger.kernel.org, bpf@vger.kernel.org, Daniel Borkmann , Alexei Starovoitov , John Fastabend , Pavel Machek Subject: Re: [PATCH 4.14 1/4] bpf: Do not use ax register in interpreter on div/mod Message-ID: References: <20210830183211.339054-1-cascardo@canonical.com> <20210830183211.339054-2-cascardo@canonical.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On Wed, Sep 01, 2021 at 01:30:37PM +0200, Greg KH wrote: > On Mon, Aug 30, 2021 at 03:32:08PM -0300, Thadeu Lima de Souza Cascardo wrote: > > From: Daniel Borkmann > > > > Partially undo old commit 144cd91c4c2b ("bpf: move tmp variable into ax > > register in interpreter"). The reason we need this here is because ax > > register will be used for holding temporary state for div/mod instruction > > which otherwise interpreter would corrupt. This will cause a small +8 byte > > stack increase for interpreter, but with the gain that we can use it from > > verifier rewrites as scratch register. > > > > Signed-off-by: Daniel Borkmann > > Reviewed-by: John Fastabend > > [cascardo: This partial revert is needed in order to support using AX for > > the following two commits, as there is no JMP32 on 4.19.y] > > Signed-off-by: Thadeu Lima de Souza Cascardo > > --- > > kernel/bpf/core.c | 32 +++++++++++++++----------------- > > 1 file changed, 15 insertions(+), 17 deletions(-) > > > > diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c > > index e7211b0fa27c..30d871be9974 100644 > > --- a/kernel/bpf/core.c > > +++ b/kernel/bpf/core.c > > @@ -616,9 +616,6 @@ static int bpf_jit_blind_insn(const struct bpf_insn *from, > > * below. > > * > > * Constant blinding is only used by JITs, not in the interpreter. > > - * The interpreter uses AX in some occasions as a local temporary > > - * register e.g. in DIV or MOD instructions. > > - * > > * In restricted circumstances, the verifier can also use the AX > > * register for rewrites as long as they do not interfere with > > * the above cases! > > @@ -951,6 +948,7 @@ static unsigned int ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn, > > u32 tail_call_cnt = 0; > > void *ptr; > > int off; > > + u64 tmp; > > > > #define CONT ({ insn++; goto select_insn; }) > > #define CONT_JMP ({ insn++; goto select_insn; }) > > @@ -1013,22 +1011,22 @@ static unsigned int ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn, > > ALU64_MOD_X: > > if (unlikely(SRC == 0)) > > return 0; > > - div64_u64_rem(DST, SRC, &AX); > > - DST = AX; > > + div64_u64_rem(DST, SRC, &tmp); > > + DST = tmp; > > CONT; > > ALU_MOD_X: > > if (unlikely((u32)SRC == 0)) > > return 0; > > - AX = (u32) DST; > > - DST = do_div(AX, (u32) SRC); > > + tmp = (u32) DST; > > + DST = do_div(tmp, (u32) SRC); > > CONT; > > ALU64_MOD_K: > > - div64_u64_rem(DST, IMM, &AX); > > - DST = AX; > > + div64_u64_rem(DST, IMM, &tmp); > > + DST = tmp; > > CONT; > > ALU_MOD_K: > > - AX = (u32) DST; > > - DST = do_div(AX, (u32) IMM); > > + tmp = (u32) DST; > > + DST = do_div(tmp, (u32) IMM); > > CONT; > > ALU64_DIV_X: > > if (unlikely(SRC == 0)) > > @@ -1038,17 +1036,17 @@ static unsigned int ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn, > > ALU_DIV_X: > > if (unlikely((u32)SRC == 0)) > > return 0; > > - AX = (u32) DST; > > - do_div(AX, (u32) SRC); > > - DST = (u32) AX; > > + tmp = (u32) DST; > > + do_div(tmp, (u32) SRC); > > + DST = (u32) tmp; > > CONT; > > ALU64_DIV_K: > > DST = div64_u64(DST, IMM); > > CONT; > > ALU_DIV_K: > > - AX = (u32) DST; > > - do_div(AX, (u32) IMM); > > - DST = (u32) AX; > > + tmp = (u32) DST; > > + do_div(tmp, (u32) IMM); > > + DST = (u32) tmp; > > CONT; > > ALU_END_TO_BE: > > switch (IMM) { > > -- > > 2.30.2 > > > > Oops, no, this patch causes build errors: > > kernel/bpf/core.c: In function ‘___bpf_prog_run’: > kernel/bpf/core.c:951:13: error: redeclaration of ‘tmp’ with no linkage > 951 | u64 tmp; > | ^~~ > kernel/bpf/core.c:839:13: note: previous declaration of ‘tmp’ with type ‘u64’ {aka ‘long long unsigned int’} > 839 | u64 tmp; > | ^~~ > make[2]: *** [scripts/Makefile.build:329: kernel/bpf/core.o] Error 1 > > > Please fix up and resend the whole series, as I will go drop these 3 > patches from the 4.14.y queue now. All _4_ patches I mean. now dropped...