From patchwork Mon Sep 10 20:48:33 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 182956 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 EF4A32C0093 for ; Tue, 11 Sep 2012 06:48:41 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932462Ab2IJUsk (ORCPT ); Mon, 10 Sep 2012 16:48:40 -0400 Received: from mail-ee0-f46.google.com ([74.125.83.46]:63565 "EHLO mail-ee0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932152Ab2IJUsj (ORCPT ); Mon, 10 Sep 2012 16:48:39 -0400 Received: by eekc1 with SMTP id c1so1503729eek.19 for ; Mon, 10 Sep 2012 13:48:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:from:to:cc:in-reply-to:references:content-type:date :message-id:mime-version:x-mailer:content-transfer-encoding; bh=7D4XD4t+om2h7ed4IHnBumCYrEcZWTJT2HGGD5gqmaw=; b=uSPf8nwDaQMyza/ZOQWVsMcyHMxhM6PLzUKuJWl7/HP6rn2VfxWWekBIqkSmTn1SIH ptEcQD0Sy5nCcaq1eSbqf/kK6KPY5gGX8ATuoNGbY04zjmKjbnTwZP8t2GErBmDHeYWJ icmg2oXPh20qQaiqp70BT7Z1IkSOL6HTwGB2utHaNJN1yQRNtsBjeFj3DG9PbweJxboT pboE0I7IifdzXCVZUc12tkQd9wtH9VbwcCtoQ/mEoCegGufdpgvY3G0qT86zUfcAxo7O xzI2Yjk036KwosJNcO6Xayz3ZfKioKDH2PG4y5ybs19Ji12AmT3eEtuRnvZQtVkEg1EQ yqbA== Received: by 10.204.7.199 with SMTP id e7mr1155371bke.125.1347310117669; Mon, 10 Sep 2012 13:48:37 -0700 (PDT) Received: from [172.28.90.190] ([172.28.90.190]) by mx.google.com with ESMTPS id g6sm8272988bkg.2.2012.09.10.13.48.35 (version=SSLv3 cipher=OTHER); Mon, 10 Sep 2012 13:48:36 -0700 (PDT) Subject: [PATCH net-next] x86 bpf_jit: support MOD operation From: Eric Dumazet To: David Miller Cc: ak@linux.intel.com, gbakos@alpinista.org, netdev@vger.kernel.org In-Reply-To: <20120910.154537.639794042526369471.davem@davemloft.net> References: <20120907074910.2df46817@arrowsmith> <20120908030311.GM17289@tassilo.jf.intel.com> <1347091415.1234.317.camel@edumazet-glaptop> <20120910.154537.639794042526369471.davem@davemloft.net> Date: Mon, 10 Sep 2012 22:48:33 +0200 Message-ID: <1347310113.13103.8.camel@edumazet-glaptop> Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Eric Dumazet commit b6069a9570 (filter: add MOD operation) added generic support for modulus operation in BPF. This patch brings JIT support for x86_64 Signed-off-by: Eric Dumazet Cc: Andi Kleen Cc: George Bakos --- arch/x86/net/bpf_jit_comp.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) -- 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/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c index 33643a8..106c578 100644 --- a/arch/x86/net/bpf_jit_comp.c +++ b/arch/x86/net/bpf_jit_comp.c @@ -280,6 +280,31 @@ void bpf_jit_compile(struct sk_filter *fp) } EMIT4(0x31, 0xd2, 0xf7, 0xf3); /* xor %edx,%edx; div %ebx */ break; + case BPF_S_ALU_MOD_X: /* A %= X; */ + seen |= SEEN_XREG; + EMIT2(0x85, 0xdb); /* test %ebx,%ebx */ + if (pc_ret0 > 0) { + /* addrs[pc_ret0 - 1] is start address of target + * (addrs[i] - 6) is the address following this jmp + * ("xor %edx,%edx; div %ebx;mov %edx,%eax" being 6 bytes long) + */ + EMIT_COND_JMP(X86_JE, addrs[pc_ret0 - 1] - + (addrs[i] - 6)); + } else { + EMIT_COND_JMP(X86_JNE, 2 + 5); + CLEAR_A(); + EMIT1_off32(0xe9, cleanup_addr - (addrs[i] - 6)); /* jmp .+off32 */ + } + EMIT2(0x31, 0xd2); /* xor %edx,%edx */ + EMIT2(0xf7, 0xf3); /* div %ebx */ + EMIT2(0x89, 0xd0); /* mov %edx,%eax */ + break; + case BPF_S_ALU_MOD_K: /* A %= K; */ + EMIT2(0x31, 0xd2); /* xor %edx,%edx */ + EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */ + EMIT2(0xf7, 0xf1); /* div %ecx */ + EMIT2(0x89, 0xd0); /* mov %edx,%eax */ + break; case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */ EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */ EMIT(K, 4);