From patchwork Thu Nov 8 21:39:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Borkmann X-Patchwork-Id: 197897 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 7EF382C00F3 for ; Fri, 9 Nov 2012 08:39:49 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757107Ab2KHVjr (ORCPT ); Thu, 8 Nov 2012 16:39:47 -0500 Received: from mail-ea0-f174.google.com ([209.85.215.174]:53912 "EHLO mail-ea0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757099Ab2KHVjq (ORCPT ); Thu, 8 Nov 2012 16:39:46 -0500 Received: by mail-ea0-f174.google.com with SMTP id c13so1240810eaa.19 for ; Thu, 08 Nov 2012 13:39:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=4200misR8FxKDzZAhlqLZQkbZqDVYJ+EhnrFM3Rn0EY=; b=Bbm3DYaLRPUdJbVuXZeLxySMdl9W9n5tn5LnjiXLPvtCBpTtAFkQYQxel4mL8gyhJI vffFbVbRmQ/Q0wOiIGKJh8iJgKmNYJEr9qmJdmAQj/kOnFE1jqu5dWJYyvaOuNDM8Gyt p9wY6y9fSytWRJi5dqcMGsUZagH2Ab9fMrCfBRAwa9cT+TDRSypc0AzU1qqELVkcGvkV dxRRg0AOnonCM2REsGjMNgcOlOwOhLGL4HTHFKjB3QOmrzD7q9SRTn9yWUJbu2tt6rq4 P2oA+GUyiU4ioRW7ZYH1MEn9SRzB+YPzfZV6He5+CT0WhlLyXQVllxNI7MxYIg4Pabuz LU8g== Received: by 10.14.200.194 with SMTP id z42mr31311071een.13.1352410785494; Thu, 08 Nov 2012 13:39:45 -0800 (PST) Received: from thinkbox (74-25.196-178.cust.bluewin.ch. [178.196.25.74]) by mx.google.com with ESMTPS id g5sm72638913eem.4.2012.11.08.13.39.43 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 08 Nov 2012 13:39:44 -0800 (PST) Date: Thu, 8 Nov 2012 22:39:41 +0100 From: Daniel Borkmann To: davem@davemloft.net Cc: matt@ozlabs.org, benh@kernel.crashing.org, netdev@vger.kernel.org Subject: [PATCH net-next 1/2] PPC: net: bpf_jit_comp: add XOR instruction for BPF JIT Message-ID: <20121108213939.GA29696@thinkbox> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch is a follow-up for patch "filter: add XOR instruction for use with X/K" that implements BPF PowerPC JIT parts for the BPF XOR operation. Signed-off-by: Daniel Borkmann Cc: Matt Evans Cc: Benjamin Herrenschmidt Acked-by: Matt Evans --- Disclaimer: uncompiled and untested, since I don't have a PPC machine, but it should (hopefully) integrate cleanly; impl. after PPC instruction reference. arch/powerpc/include/asm/ppc-opcode.h | 3 +++ arch/powerpc/net/bpf_jit.h | 6 ++++++ arch/powerpc/net/bpf_jit_comp.c | 11 +++++++++++ 3 files changed, 20 insertions(+), 0 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/powerpc/include/asm/ppc-opcode.h b/arch/powerpc/include/asm/ppc-opcode.h index 5f73ce6..42b1f43 100644 --- a/arch/powerpc/include/asm/ppc-opcode.h +++ b/arch/powerpc/include/asm/ppc-opcode.h @@ -168,9 +168,12 @@ #define PPC_INST_AND 0x7c000038 #define PPC_INST_ANDDOT 0x7c000039 #define PPC_INST_OR 0x7c000378 +#define PPC_INST_XOR 0x7c000278 #define PPC_INST_ANDI 0x70000000 #define PPC_INST_ORI 0x60000000 #define PPC_INST_ORIS 0x64000000 +#define PPC_INST_XORI 0x68000000 +#define PPC_INST_XORIS 0x6c000000 #define PPC_INST_NEG 0x7c0000d0 #define PPC_INST_BRANCH 0x48000000 #define PPC_INST_BRANCH_COND 0x40800000 diff --git a/arch/powerpc/net/bpf_jit.h b/arch/powerpc/net/bpf_jit.h index 1fc8109..8a5dfaf 100644 --- a/arch/powerpc/net/bpf_jit.h +++ b/arch/powerpc/net/bpf_jit.h @@ -134,6 +134,12 @@ DECLARE_LOAD_FUNC(sk_load_byte_msh); ___PPC_RS(a) | IMM_L(i)) #define PPC_ORIS(d, a, i) EMIT(PPC_INST_ORIS | ___PPC_RA(d) | \ ___PPC_RS(a) | IMM_L(i)) +#define PPC_XOR(d, a, b) EMIT(PPC_INST_XOR | ___PPC_RA(d) | \ + ___PPC_RS(a) | ___PPC_RB(b)) +#define PPC_XORI(d, a, i) EMIT(PPC_INST_XORI | ___PPC_RA(d) | \ + ___PPC_RS(a) | IMM_L(i)) +#define PPC_XORIS(d, a, i) EMIT(PPC_INST_XORIS | ___PPC_RA(d) | \ + ___PPC_RS(a) | IMM_L(i)) #define PPC_SLW(d, a, s) EMIT(PPC_INST_SLW | ___PPC_RA(d) | \ ___PPC_RS(a) | ___PPC_RB(s)) #define PPC_SRW(d, a, s) EMIT(PPC_INST_SRW | ___PPC_RA(d) | \ diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c index dd11306..b9434de 100644 --- a/arch/powerpc/net/bpf_jit_comp.c +++ b/arch/powerpc/net/bpf_jit_comp.c @@ -232,6 +232,17 @@ static int bpf_jit_build_body(struct sk_filter *fp, u32 *image, if (K >= 65536) PPC_ORIS(r_A, r_A, IMM_H(K)); break; + case BPF_S_ANC_ALU_XOR_X: + case BPF_S_ALU_XOR_X: /* A ^= X */ + ctx->seen |= SEEN_XREG; + PPC_XOR(r_A, r_A, r_X); + break; + case BPF_S_ALU_XOR_K: /* A ^= K */ + if (IMM_L(K)) + PPC_XORI(r_A, r_A, IMM_L(K)); + if (K >= 65536) + PPC_XORIS(r_A, r_A, IMM_H(K)); + break; case BPF_S_ALU_LSH_X: /* A <<= X; */ ctx->seen |= SEEN_XREG; PPC_SLW(r_A, r_A, r_X);