From owner-svn-src-head@FreeBSD.ORG Wed Nov 18 22:39:07 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 7601A1065694; Wed, 18 Nov 2009 22:39:07 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 1BF568FC18; Wed, 18 Nov 2009 22:39:07 +0000 (UTC) Received: from fledge.watson.org (fledge.watson.org [65.122.17.41]) by cyrus.watson.org (Postfix) with ESMTPS id 7C4BB46B03; Wed, 18 Nov 2009 17:39:06 -0500 (EST) Date: Wed, 18 Nov 2009 22:39:06 +0000 (GMT) From: Robert Watson X-X-Sender: robert@fledge.watson.org To: Jung-uk Kim In-Reply-To: <200911181926.nAIJQHOR081471@svn.freebsd.org> Message-ID: References: <200911181926.nAIJQHOR081471@svn.freebsd.org> User-Agent: Alpine 2.00 (BSF 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r199492 - 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 22:39:07 -0000 On Wed, 18 Nov 2009, Jung-uk Kim wrote: > Author: jkim > Date: Wed Nov 18 19:26:17 2009 > New Revision: 199492 > URL: http://svn.freebsd.org/changeset/base/199492 > > Log: > - Make BPF JIT compiler working again in userland. We are limiting size of > generated native binary to page size for now. > - Update copyright date and fix some style nits. I'm not sure if you have noticed, but there are a bunch of embedded target ports of the BPF JIT in the PR collection -- ARM, MIPS, etc. Any chance we might see those integrated into 9.x at some point? The less cache-rich CPUs are especially helped by JIT parts. Robert N M Watson Computer Laboratory University of Cambridge > > Modified: > head/sys/amd64/amd64/bpf_jit_machdep.c > head/sys/amd64/amd64/bpf_jit_machdep.h > head/sys/i386/i386/bpf_jit_machdep.c > head/sys/i386/i386/bpf_jit_machdep.h > 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 18:48:18 2009 (r199491) > +++ head/sys/amd64/amd64/bpf_jit_machdep.c Wed Nov 18 19:26:17 2009 (r199492) > @@ -1,6 +1,6 @@ > /*- > * Copyright (C) 2002-2003 NetGroup, Politecnico di Torino (Italy) > - * Copyright (C) 2005-2008 Jung-uk Kim > + * Copyright (C) 2005-2009 Jung-uk Kim > * All rights reserved. > * > * Redistribution and use in source and binary forms, with or without > @@ -42,6 +42,8 @@ __FBSDID("$FreeBSD$"); > #include > #else > #include > +#include > +#include > #endif > > #include > @@ -97,9 +99,9 @@ emit_code(bpf_bin_stream *stream, u_int > bpf_filter_func > bpf_jit_compile(struct bpf_insn *prog, u_int nins, int *mem) > { > + bpf_bin_stream stream; > struct bpf_insn *ins; > u_int i, pass; > - bpf_bin_stream stream; > > /* > * NOTE: do not modify the name of this variable, as it's used by > @@ -475,20 +477,31 @@ bpf_jit_compile(struct bpf_insn *prog, u > } > > pass++; > - if (pass == 2) > + if (pass >= 2) { > +#ifndef _KERNEL > + if (mprotect(stream.ibuf, stream.cur_ip, > + PROT_READ | PROT_EXEC) != 0) { > + munmap(stream.ibuf, BPF_JIT_MAXSIZE); > + stream.ibuf = NULL; > + } > +#endif > break; > + } > > #ifdef _KERNEL > stream.ibuf = (char *)malloc(stream.cur_ip, M_BPFJIT, M_NOWAIT); > - if (stream.ibuf == NULL) { > - free(stream.refs, M_BPFJIT); > - return (NULL); > - } > + if (stream.ibuf == NULL) > + break; > #else > - stream.ibuf = (char *)malloc(stream.cur_ip); > - if (stream.ibuf == NULL) { > - free(stream.refs); > - return (NULL); > + if (stream.cur_ip > BPF_JIT_MAXSIZE) { > + stream.ibuf = NULL; > + break; > + } > + stream.ibuf = (char *)mmap(NULL, BPF_JIT_MAXSIZE, > + PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); > + if (stream.ibuf == MAP_FAILED) { > + stream.ibuf = NULL; > + break; > } > #endif > > > Modified: head/sys/amd64/amd64/bpf_jit_machdep.h > ============================================================================== > --- head/sys/amd64/amd64/bpf_jit_machdep.h Wed Nov 18 18:48:18 2009 (r199491) > +++ head/sys/amd64/amd64/bpf_jit_machdep.h Wed Nov 18 19:26:17 2009 (r199492) > @@ -1,6 +1,6 @@ > /*- > * Copyright (C) 2002-2003 NetGroup, Politecnico di Torino (Italy) > - * Copyright (C) 2005-2008 Jung-uk Kim > + * Copyright (C) 2005-2009 Jung-uk Kim > * All rights reserved. > * > * Redistribution and use in source and binary forms, with or without > > Modified: head/sys/i386/i386/bpf_jit_machdep.c > ============================================================================== > --- head/sys/i386/i386/bpf_jit_machdep.c Wed Nov 18 18:48:18 2009 (r199491) > +++ head/sys/i386/i386/bpf_jit_machdep.c Wed Nov 18 19:26:17 2009 (r199492) > @@ -1,6 +1,6 @@ > /*- > * Copyright (C) 2002-2003 NetGroup, Politecnico di Torino (Italy) > - * Copyright (C) 2005-2008 Jung-uk Kim > + * Copyright (C) 2005-2009 Jung-uk Kim > * All rights reserved. > * > * Redistribution and use in source and binary forms, with or without > @@ -42,6 +42,8 @@ __FBSDID("$FreeBSD$"); > #include > #else > #include > +#include > +#include > #endif > > #include > @@ -97,9 +99,9 @@ emit_code(bpf_bin_stream *stream, u_int > bpf_filter_func > bpf_jit_compile(struct bpf_insn *prog, u_int nins, int *mem) > { > + bpf_bin_stream stream; > struct bpf_insn *ins; > u_int i, pass; > - bpf_bin_stream stream; > > /* > * NOTE: do not modify the name of this variable, as it's used by > @@ -498,20 +500,31 @@ bpf_jit_compile(struct bpf_insn *prog, u > } > > pass++; > - if (pass == 2) > + if (pass >= 2) { > +#ifndef _KERNEL > + if (mprotect(stream.ibuf, stream.cur_ip, > + PROT_READ | PROT_EXEC) != 0) { > + munmap(stream.ibuf, BPF_JIT_MAXSIZE); > + stream.ibuf = NULL; > + } > +#endif > break; > + } > > #ifdef _KERNEL > stream.ibuf = (char *)malloc(stream.cur_ip, M_BPFJIT, M_NOWAIT); > - if (stream.ibuf == NULL) { > - free(stream.refs, M_BPFJIT); > - return (NULL); > - } > + if (stream.ibuf == NULL) > + break; > #else > - stream.ibuf = (char *)malloc(stream.cur_ip); > - if (stream.ibuf == NULL) { > - free(stream.refs); > - return (NULL); > + if (stream.cur_ip > BPF_JIT_MAXSIZE) { > + stream.ibuf = NULL; > + break; > + } > + stream.ibuf = (char *)mmap(NULL, BPF_JIT_MAXSIZE, > + PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); > + if (stream.ibuf == MAP_FAILED) { > + stream.ibuf = NULL; > + break; > } > #endif > > > Modified: head/sys/i386/i386/bpf_jit_machdep.h > ============================================================================== > --- head/sys/i386/i386/bpf_jit_machdep.h Wed Nov 18 18:48:18 2009 (r199491) > +++ head/sys/i386/i386/bpf_jit_machdep.h Wed Nov 18 19:26:17 2009 (r199492) > @@ -1,6 +1,6 @@ > /*- > * Copyright (C) 2002-2003 NetGroup, Politecnico di Torino (Italy) > - * Copyright (C) 2005-2008 Jung-uk Kim > + * Copyright (C) 2005-2009 Jung-uk Kim > * All rights reserved. > * > * Redistribution and use in source and binary forms, with or without > > Modified: head/sys/net/bpf_jitter.c > ============================================================================== > --- head/sys/net/bpf_jitter.c Wed Nov 18 18:48:18 2009 (r199491) > +++ head/sys/net/bpf_jitter.c Wed Nov 18 19:26:17 2009 (r199492) > @@ -1,6 +1,6 @@ > /*- > * Copyright (C) 2002-2003 NetGroup, Politecnico di Torino (Italy) > - * Copyright (C) 2005-2008 Jung-uk Kim > + * Copyright (C) 2005-2009 Jung-uk Kim > * All rights reserved. > * > * Redistribution and use in source and binary forms, with or without > @@ -43,6 +43,8 @@ __FBSDID("$FreeBSD$"); > #else > #include > #include > +#include > +#include > #include > #endif > > @@ -127,7 +129,7 @@ bpf_destroy_jit_filter(bpf_jit_filter *f > { > > if (filter->func != bpf_jit_accept_all) > - free(filter->func); > + munmap(filter->func, BPF_JIT_MAXSIZE); > free(filter); > } > #endif > > Modified: head/sys/net/bpf_jitter.h > ============================================================================== > --- head/sys/net/bpf_jitter.h Wed Nov 18 18:48:18 2009 (r199491) > +++ head/sys/net/bpf_jitter.h Wed Nov 18 19:26:17 2009 (r199492) > @@ -1,6 +1,6 @@ > /*- > * Copyright (C) 2002-2003 NetGroup, Politecnico di Torino (Italy) > - * Copyright (C) 2005-2008 Jung-uk Kim > + * Copyright (C) 2005-2009 Jung-uk Kim > * All rights reserved. > * > * Redistribution and use in source and binary forms, with or without > @@ -36,6 +36,8 @@ > > #ifdef _KERNEL > MALLOC_DECLARE(M_BPFJIT); > +#else > +#define BPF_JIT_MAXSIZE PAGE_SIZE > #endif > > extern int bpf_jitter_enable; >