Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp3242723imc; Wed, 13 Mar 2019 12:31:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqz4SIqWdwxuhi+eB5fYSASLPTgQGhfdiXxHQC3vmHcaYZXxO1kaWdNwqfJdy0iZIZxu+LIk X-Received: by 2002:a65:5142:: with SMTP id g2mr41796475pgq.149.1552505495921; Wed, 13 Mar 2019 12:31:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552505495; cv=none; d=google.com; s=arc-20160816; b=FYpMuqTIU7EiOjxV3YVLM/cqwiObnFpuv9JuB+zjf6aYEKM+TxSy5JAGflRs6SrrFN 7BUeeqz/4CKHjdC2byjxGEiHC7NtqaZ95gB0E79gjMdojNl7Tts1w0FJXbjAz27JTtz9 KjBeMHkCYC34tp8LouHvwVl/N0SrzSwDJrehnOtqM1MetkA91dnActE04Rt93hocb/l4 NyWqoWvYcukHxcFAjMn0LXkY/mGqGVHBs4DKVHo2qCFK+Kvrjwe//Hkdnsvo5Pfw1oWE LxUEevpRy1ejXvanwccbOvcJSAIHjeLUqW0i+56xF2efLmtuiXo/sXqdfH0WyajMC8tD 33+w== 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=QeYEjy7bCCOzH9kkxmaFx7L1+1GmVU9fm30X+geX2Uk=; b=xnMHDztbus484SnKxi5VaoCE6Lq4MxhgoNwVyRQ/87nnFO++EfADVPewYwQv6FkAk/ OmHB82UYV3iscRmWW6qAK5DSG6VJsmbzkrOBxFZVhWyEqATgWAe+OUwdJOrp6/v2AvS3 hQlpKkZh1ynNw328Rep28C1xhYNW7zNyYO8IQhzTD3b9eDNzq0Ku3FC65Fjhrc+eX4HU ifTYb9SJRPdlCOW6m1tuSQTj472Mh+a2NcbuXKPDKDToqNeXurefo51LE7JfxLVT4W/1 JuWPznllkogHcAFptk9MNZQsnBGHnm20BaFEaOsvSy/L/PNR5MwWC/SnKTBVbA8TjjV/ VQUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0OtSfvst; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f8si10430051pgo.80.2019.03.13.12.31.19; Wed, 13 Mar 2019 12:31:35 -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=0OtSfvst; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727785AbfCMTMk (ORCPT + 99 others); Wed, 13 Mar 2019 15:12:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:43224 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726263AbfCMTMi (ORCPT ); Wed, 13 Mar 2019 15:12:38 -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 DAE17213A2; Wed, 13 Mar 2019 19:12:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552504357; bh=g6jNQynlDkCvnkhWeEHFkEbWXRDWqsc39VFtV3edg1Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0OtSfvstWUrhxWI2LCAet43PJXU+PCV7J/e7LDSj6LDDWNgWzxnRHKps7KE5qgKj5 ycJSLQ+cs8QBDbuC7GyBLyXSllu+XeH2T7kNJNMaBKttWoHYIXdTlnKHNt4/oSNxtx z+lKUtmzSoe45cntaY2nQBfkUA0A1sTHKVC+P/PY= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jiong Wang , Daniel Borkmann , Sasha Levin , netdev@vger.kernel.org, bpf@vger.kernel.org, oss-drivers@netronome.com Subject: [PATCH AUTOSEL 4.20 55/60] nfp: bpf: fix ALU32 high bits clearance bug Date: Wed, 13 Mar 2019 15:10:16 -0400 Message-Id: <20190313191021.158171-55-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190313191021.158171-1-sashal@kernel.org> References: <20190313191021.158171-1-sashal@kernel.org> MIME-Version: 1.0 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: Jiong Wang [ Upstream commit f036ebd9bfbe1e91a3d855e85e05fc5ff156b641 ] NFP BPF JIT compiler is doing a couple of small optimizations when jitting ALU imm instructions, some of these optimizations could save code-gen, for example: A & -1 = A A | 0 = A A ^ 0 = A However, for ALU32, high 32-bit of the 64-bit register should still be cleared according to ISA semantics. Fixes: cd7df56ed3e6 ("nfp: add BPF to NFP code translator") Reviewed-by: Jakub Kicinski Signed-off-by: Jiong Wang Signed-off-by: Daniel Borkmann Signed-off-by: Sasha Levin --- drivers/net/ethernet/netronome/nfp/bpf/jit.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/drivers/net/ethernet/netronome/nfp/bpf/jit.c b/drivers/net/ethernet/netronome/nfp/bpf/jit.c index 0762401ee3fe..c89381bad6e4 100644 --- a/drivers/net/ethernet/netronome/nfp/bpf/jit.c +++ b/drivers/net/ethernet/netronome/nfp/bpf/jit.c @@ -1291,15 +1291,10 @@ wrp_alu64_reg(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta, static int wrp_alu32_imm(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta, - enum alu_op alu_op, bool skip) + enum alu_op alu_op) { const struct bpf_insn *insn = &meta->insn; - if (skip) { - meta->skip = true; - return 0; - } - wrp_alu_imm(nfp_prog, insn->dst_reg * 2, alu_op, insn->imm); wrp_immed(nfp_prog, reg_both(insn->dst_reg * 2 + 1), 0); @@ -2309,7 +2304,7 @@ static int xor_reg(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta) static int xor_imm(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta) { - return wrp_alu32_imm(nfp_prog, meta, ALU_OP_XOR, !meta->insn.imm); + return wrp_alu32_imm(nfp_prog, meta, ALU_OP_XOR); } static int and_reg(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta) @@ -2319,7 +2314,7 @@ static int and_reg(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta) static int and_imm(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta) { - return wrp_alu32_imm(nfp_prog, meta, ALU_OP_AND, !~meta->insn.imm); + return wrp_alu32_imm(nfp_prog, meta, ALU_OP_AND); } static int or_reg(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta) @@ -2329,7 +2324,7 @@ static int or_reg(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta) static int or_imm(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta) { - return wrp_alu32_imm(nfp_prog, meta, ALU_OP_OR, !meta->insn.imm); + return wrp_alu32_imm(nfp_prog, meta, ALU_OP_OR); } static int add_reg(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta) @@ -2339,7 +2334,7 @@ static int add_reg(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta) static int add_imm(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta) { - return wrp_alu32_imm(nfp_prog, meta, ALU_OP_ADD, !meta->insn.imm); + return wrp_alu32_imm(nfp_prog, meta, ALU_OP_ADD); } static int sub_reg(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta) @@ -2349,7 +2344,7 @@ static int sub_reg(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta) static int sub_imm(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta) { - return wrp_alu32_imm(nfp_prog, meta, ALU_OP_SUB, !meta->insn.imm); + return wrp_alu32_imm(nfp_prog, meta, ALU_OP_SUB); } static int mul_reg(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta) -- 2.19.1