From owner-svn-src-head@FreeBSD.ORG Wed Nov 18 23:40:19 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A6777106566C; Wed, 18 Nov 2009 23:40:19 +0000 (UTC) (envelope-from jkim@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 9340A8FC08; Wed, 18 Nov 2009 23:40:19 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nAINeJ6T087656; Wed, 18 Nov 2009 23:40:19 GMT (envelope-from jkim@svn.freebsd.org) Received: (from jkim@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nAINeJ3W087652; Wed, 18 Nov 2009 23:40:19 GMT (envelope-from jkim@svn.freebsd.org) Message-Id: <200911182340.nAINeJ3W087652@svn.freebsd.org> From: Jung-uk Kim Date: Wed, 18 Nov 2009 23:40:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r199498 - in head/sys: amd64/amd64 i386/i386 net X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Nov 2009 23:40:19 -0000 Author: jkim Date: Wed Nov 18 23:40:19 2009 New Revision: 199498 URL: http://svn.freebsd.org/changeset/base/199498 Log: - Change internal function bpf_jit_compile() to return allocated size of the generated binary and remove page size limitation for userland. - Use contigmalloc(9)/contigfree(9) instead of malloc(9)/free(9) to make sure the generated binary aligns properly and make it physically contiguous. Modified: head/sys/amd64/amd64/bpf_jit_machdep.c head/sys/i386/i386/bpf_jit_machdep.c head/sys/net/bpf_jitter.c head/sys/net/bpf_jitter.h Modified: head/sys/amd64/amd64/bpf_jit_machdep.c ============================================================================== --- head/sys/amd64/amd64/bpf_jit_machdep.c Wed Nov 18 22:53:05 2009 (r199497) +++ head/sys/amd64/amd64/bpf_jit_machdep.c Wed Nov 18 23:40:19 2009 (r199498) @@ -53,7 +53,7 @@ __FBSDID("$FreeBSD$"); #include -bpf_filter_func bpf_jit_compile(struct bpf_insn *, u_int, int *); +bpf_filter_func bpf_jit_compile(struct bpf_insn *, u_int, size_t *, int *); /* * emit routine to update the jump table @@ -97,7 +97,7 @@ emit_code(bpf_bin_stream *stream, u_int * Function that does the real stuff */ bpf_filter_func -bpf_jit_compile(struct bpf_insn *prog, u_int nins, int *mem) +bpf_jit_compile(struct bpf_insn *prog, u_int nins, size_t *size, int *mem) { bpf_bin_stream stream; struct bpf_insn *ins; @@ -481,23 +481,21 @@ bpf_jit_compile(struct bpf_insn *prog, u #ifndef _KERNEL if (mprotect(stream.ibuf, stream.cur_ip, PROT_READ | PROT_EXEC) != 0) { - munmap(stream.ibuf, BPF_JIT_MAXSIZE); + munmap(stream.ibuf, stream.cur_ip); stream.ibuf = NULL; } #endif + *size = stream.cur_ip; break; } #ifdef _KERNEL - stream.ibuf = (char *)malloc(stream.cur_ip, M_BPFJIT, M_NOWAIT); + stream.ibuf = (char *)contigmalloc(stream.cur_ip, M_BPFJIT, + M_NOWAIT, 0, ~0ULL, 16, 0); if (stream.ibuf == NULL) break; #else - if (stream.cur_ip > BPF_JIT_MAXSIZE) { - stream.ibuf = NULL; - break; - } - stream.ibuf = (char *)mmap(NULL, BPF_JIT_MAXSIZE, + stream.ibuf = (char *)mmap(NULL, stream.cur_ip, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); if (stream.ibuf == MAP_FAILED) { stream.ibuf = NULL; Modified: head/sys/i386/i386/bpf_jit_machdep.c ============================================================================== --- head/sys/i386/i386/bpf_jit_machdep.c Wed Nov 18 22:53:05 2009 (r199497) +++ head/sys/i386/i386/bpf_jit_machdep.c Wed Nov 18 23:40:19 2009 (r199498) @@ -53,7 +53,7 @@ __FBSDID("$FreeBSD$"); #include -bpf_filter_func bpf_jit_compile(struct bpf_insn *, u_int, int *); +bpf_filter_func bpf_jit_compile(struct bpf_insn *, u_int, size_t *, int *); /* * emit routine to update the jump table @@ -97,7 +97,7 @@ emit_code(bpf_bin_stream *stream, u_int * Function that does the real stuff */ bpf_filter_func -bpf_jit_compile(struct bpf_insn *prog, u_int nins, int *mem) +bpf_jit_compile(struct bpf_insn *prog, u_int nins, size_t *size, int *mem) { bpf_bin_stream stream; struct bpf_insn *ins; @@ -504,23 +504,21 @@ bpf_jit_compile(struct bpf_insn *prog, u #ifndef _KERNEL if (mprotect(stream.ibuf, stream.cur_ip, PROT_READ | PROT_EXEC) != 0) { - munmap(stream.ibuf, BPF_JIT_MAXSIZE); + munmap(stream.ibuf, stream.cur_ip); stream.ibuf = NULL; } #endif + *size = stream.cur_ip; break; } #ifdef _KERNEL - stream.ibuf = (char *)malloc(stream.cur_ip, M_BPFJIT, M_NOWAIT); + stream.ibuf = (char *)contigmalloc(stream.cur_ip, M_BPFJIT, + M_NOWAIT, 0, ~0ULL, 16, 0); if (stream.ibuf == NULL) break; #else - if (stream.cur_ip > BPF_JIT_MAXSIZE) { - stream.ibuf = NULL; - break; - } - stream.ibuf = (char *)mmap(NULL, BPF_JIT_MAXSIZE, + stream.ibuf = (char *)mmap(NULL, stream.cur_ip, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); if (stream.ibuf == MAP_FAILED) { stream.ibuf = NULL; Modified: head/sys/net/bpf_jitter.c ============================================================================== --- head/sys/net/bpf_jitter.c Wed Nov 18 22:53:05 2009 (r199497) +++ head/sys/net/bpf_jitter.c Wed Nov 18 23:40:19 2009 (r199498) @@ -51,7 +51,7 @@ __FBSDID("$FreeBSD$"); #include #include -bpf_filter_func bpf_jit_compile(struct bpf_insn *, u_int, int *); +bpf_filter_func bpf_jit_compile(struct bpf_insn *, u_int, size_t *, int *); static u_int bpf_jit_accept_all(u_char *, u_int, u_int); @@ -81,7 +81,8 @@ bpf_jitter(struct bpf_insn *fp, int nins } /* Create the binary */ - if ((filter->func = bpf_jit_compile(fp, nins, filter->mem)) == NULL) { + if ((filter->func = bpf_jit_compile(fp, nins, &filter->size, + filter->mem)) == NULL) { free(filter, M_BPFJIT); return (NULL); } @@ -94,7 +95,7 @@ bpf_destroy_jit_filter(bpf_jit_filter *f { if (filter->func != bpf_jit_accept_all) - free(filter->func, M_BPFJIT); + contigfree(filter->func, filter->size, M_BPFJIT); free(filter, M_BPFJIT); } #else @@ -116,7 +117,8 @@ bpf_jitter(struct bpf_insn *fp, int nins } /* Create the binary */ - if ((filter->func = bpf_jit_compile(fp, nins, filter->mem)) == NULL) { + if ((filter->func = bpf_jit_compile(fp, nins, &filter->size, + filter->mem)) == NULL) { free(filter); return (NULL); } @@ -129,7 +131,7 @@ bpf_destroy_jit_filter(bpf_jit_filter *f { if (filter->func != bpf_jit_accept_all) - munmap(filter->func, BPF_JIT_MAXSIZE); + munmap(filter->func, filter->size); free(filter); } #endif Modified: head/sys/net/bpf_jitter.h ============================================================================== --- head/sys/net/bpf_jitter.h Wed Nov 18 22:53:05 2009 (r199497) +++ head/sys/net/bpf_jitter.h Wed Nov 18 23:40:19 2009 (r199498) @@ -36,8 +36,6 @@ #ifdef _KERNEL MALLOC_DECLARE(M_BPFJIT); -#else -#define BPF_JIT_MAXSIZE PAGE_SIZE #endif extern int bpf_jitter_enable; @@ -55,7 +53,7 @@ typedef u_int (*bpf_filter_func)(u_char typedef struct bpf_jit_filter { /* The native filtering binary, in the form of a bpf_filter_func. */ bpf_filter_func func; - + size_t size; int mem[BPF_MEMWORDS]; /* Scratch memory */ } bpf_jit_filter;