Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp2245843ybd; Mon, 24 Jun 2019 03:13:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqyQQBEwhCuQtb3KrB95/gho/6hXvUCwDcUahM9HHTZ8AIrcu9o9tGJZ3P53MF+H891KEI+p X-Received: by 2002:a17:902:9a82:: with SMTP id w2mr128458223plp.291.1561371223593; Mon, 24 Jun 2019 03:13:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561371223; cv=none; d=google.com; s=arc-20160816; b=oCzxL/exPSXBYmWw+fIPQY6M31nfBXbjPPx4q6mvkgu74ZyqxCrvrwzvaUO2/kNYtG JUMNi63g8chJ05Xwv+bUvzcZy8ECwH+mKXHd9hTBb+QSGLTd4vvrfqBsRvldg7LUOgl+ DyJ1BWIH0C9YGUuCK2CLsfIOYMG6YA6PDKTIgZQTP0+r4r0keo1f1Lmhux+w8ft5nQHI R/WMbzhRICW3hsMM6XB3yElL0FdqUije36GO+V0GnBzqOEeWiFWj6QnOhQgZffcDXX+B UK/ANin1SdJmY/vlNChKMPpT+DDuRtvramH66tgIIJziMg+Pi5gF8731kr+NVl9ajA8Q JrpA== 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=TrhPLzgMEttI3iCPoE3EiS/eaG+ZziYAjUK7C1U2zzg=; b=ulavRi62M9FzR52jgzSBYqkSA1zN9H/IkJMTIFtwxm9wOJZ4XfpkYu8k2waJOsryeU x04BYk8o50OD3bCREsyb4HONE5iMyaeU8RjOQnUs3jpAp3f95VVW4j9nvQ73BB5aVP22 9TUi3WwaJuIRDyvWdwJYXCfcg/yXdXufU0lkQr++9Vd3ejOODE/BUeCjwmbK63NlLcRB jGsMzoPtsXuLqOTKSOlt0PxztIVulaL7sljkX6CLOm4vWoa6wCH1gJ2fNT4xQYmlZNg5 DLbv1zCtaqXvZYfbV/Gav+d7GQprRXzSwt5EVhkmht6E53k5NPYfgB3CIVnwsjY1fBOu G0+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gGupMQro; 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 o1si11165586pja.67.2019.06.24.03.13.27; Mon, 24 Jun 2019 03:13:43 -0700 (PDT) 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=gGupMQro; 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 S1730637AbfFXKMl (ORCPT + 99 others); Mon, 24 Jun 2019 06:12:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:37648 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729958AbfFXKFj (ORCPT ); Mon, 24 Jun 2019 06:05:39 -0400 Received: from localhost (f4.8f.5177.ip4.static.sl-reverse.com [119.81.143.244]) (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 730AF208E3; Mon, 24 Jun 2019 10:05:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561370738; bh=QDjTKqNf3EIR6YyWhK76alWgvcTeu4rye7sa5YTk2RA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gGupMQrooLU34Vgz+7LDIuAoXBwJDq1n3I2ybRQnoK+iXPuR7LJ98cu71a5tf/rJx O113cEp2z/t1APaUZHEJ8kNlQsLwaoPt/UPbYLa+e5h81OuSfM55fAWr5hbkPKj3vw XNYIQRWMrTYRpburgEPld408B704nE4FmsXGZeR8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Naveen N. Rao" , Daniel Borkmann Subject: [PATCH 4.19 73/90] powerpc/bpf: use unsigned division instruction for 64-bit operations Date: Mon, 24 Jun 2019 17:57:03 +0800 Message-Id: <20190624092318.795077804@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190624092313.788773607@linuxfoundation.org> References: <20190624092313.788773607@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: Naveen N. Rao commit 758f2046ea040773ae8ea7f72dd3bbd8fa984501 upstream. BPF_ALU64 div/mod operations are currently using signed division, unlike BPF_ALU32 operations. Fix the same. DIV64 and MOD64 overflow tests pass with this fix. Fixes: 156d0e290e969c ("powerpc/ebpf/jit: Implement JIT compiler for extended BPF") Cc: stable@vger.kernel.org # v4.8+ Signed-off-by: Naveen N. Rao Signed-off-by: Daniel Borkmann Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/include/asm/ppc-opcode.h | 1 + arch/powerpc/net/bpf_jit.h | 2 +- arch/powerpc/net/bpf_jit_comp64.c | 8 ++++---- 3 files changed, 6 insertions(+), 5 deletions(-) --- a/arch/powerpc/include/asm/ppc-opcode.h +++ b/arch/powerpc/include/asm/ppc-opcode.h @@ -336,6 +336,7 @@ #define PPC_INST_MULLI 0x1c000000 #define PPC_INST_DIVWU 0x7c000396 #define PPC_INST_DIVD 0x7c0003d2 +#define PPC_INST_DIVDU 0x7c000392 #define PPC_INST_RLWINM 0x54000000 #define PPC_INST_RLWIMI 0x50000000 #define PPC_INST_RLDICL 0x78000000 --- a/arch/powerpc/net/bpf_jit.h +++ b/arch/powerpc/net/bpf_jit.h @@ -116,7 +116,7 @@ ___PPC_RA(a) | IMM_L(i)) #define PPC_DIVWU(d, a, b) EMIT(PPC_INST_DIVWU | ___PPC_RT(d) | \ ___PPC_RA(a) | ___PPC_RB(b)) -#define PPC_DIVD(d, a, b) EMIT(PPC_INST_DIVD | ___PPC_RT(d) | \ +#define PPC_DIVDU(d, a, b) EMIT(PPC_INST_DIVDU | ___PPC_RT(d) | \ ___PPC_RA(a) | ___PPC_RB(b)) #define PPC_AND(d, a, b) EMIT(PPC_INST_AND | ___PPC_RA(d) | \ ___PPC_RS(a) | ___PPC_RB(b)) --- a/arch/powerpc/net/bpf_jit_comp64.c +++ b/arch/powerpc/net/bpf_jit_comp64.c @@ -372,12 +372,12 @@ static int bpf_jit_build_body(struct bpf case BPF_ALU64 | BPF_DIV | BPF_X: /* dst /= src */ case BPF_ALU64 | BPF_MOD | BPF_X: /* dst %= src */ if (BPF_OP(code) == BPF_MOD) { - PPC_DIVD(b2p[TMP_REG_1], dst_reg, src_reg); + PPC_DIVDU(b2p[TMP_REG_1], dst_reg, src_reg); PPC_MULD(b2p[TMP_REG_1], src_reg, b2p[TMP_REG_1]); PPC_SUB(dst_reg, dst_reg, b2p[TMP_REG_1]); } else - PPC_DIVD(dst_reg, dst_reg, src_reg); + PPC_DIVDU(dst_reg, dst_reg, src_reg); break; case BPF_ALU | BPF_MOD | BPF_K: /* (u32) dst %= (u32) imm */ case BPF_ALU | BPF_DIV | BPF_K: /* (u32) dst /= (u32) imm */ @@ -405,7 +405,7 @@ static int bpf_jit_build_body(struct bpf break; case BPF_ALU64: if (BPF_OP(code) == BPF_MOD) { - PPC_DIVD(b2p[TMP_REG_2], dst_reg, + PPC_DIVDU(b2p[TMP_REG_2], dst_reg, b2p[TMP_REG_1]); PPC_MULD(b2p[TMP_REG_1], b2p[TMP_REG_1], @@ -413,7 +413,7 @@ static int bpf_jit_build_body(struct bpf PPC_SUB(dst_reg, dst_reg, b2p[TMP_REG_1]); } else - PPC_DIVD(dst_reg, dst_reg, + PPC_DIVDU(dst_reg, dst_reg, b2p[TMP_REG_1]); break; }