From owner-svn-src-head@freebsd.org Mon Apr 17 22:02:11 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 09E74D42794; Mon, 17 Apr 2017 22:02:11 +0000 (UTC) (envelope-from jkim@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D56FBAD2; Mon, 17 Apr 2017 22:02:10 +0000 (UTC) (envelope-from jkim@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v3HM2AoF034520; Mon, 17 Apr 2017 22:02:10 GMT (envelope-from jkim@FreeBSD.org) Received: (from jkim@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v3HM29oU034516; Mon, 17 Apr 2017 22:02:09 GMT (envelope-from jkim@FreeBSD.org) Message-Id: <201704172202.v3HM29oU034516@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jkim set sender to jkim@FreeBSD.org using -f From: Jung-uk Kim Date: Mon, 17 Apr 2017 22:02:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r317072 - in head/sys: amd64/amd64 i386/i386 net X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 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: Mon, 17 Apr 2017 22:02:11 -0000 Author: jkim Date: Mon Apr 17 22:02:09 2017 New Revision: 317072 URL: https://svnweb.freebsd.org/changeset/base/317072 Log: Use kmem_malloc() instead of malloc(9) for the native amd64 filter. r316767 broke the BPF JIT compiler for amd64 because malloc()'d space is no longer executable. Discussed with: kib, alc 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 Mon Apr 17 21:57:23 2017 (r317071) +++ head/sys/amd64/amd64/bpf_jit_machdep.c Mon Apr 17 22:02:09 2017 (r317072) @@ -1,6 +1,6 @@ /*- * Copyright (C) 2002-2003 NetGroup, Politecnico di Torino (Italy) - * Copyright (C) 2005-2016 Jung-uk Kim + * Copyright (C) 2005-2017 Jung-uk Kim * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -37,10 +37,14 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include +#include + #include +#include +#include +#include #else #include #include @@ -599,7 +603,11 @@ bpf_jit_compile(struct bpf_insn *prog, u *size = stream.cur_ip; #ifdef _KERNEL - stream.ibuf = malloc(*size, M_BPFJIT, M_NOWAIT); + /* + * We cannot use malloc(9) because DMAP is mapped as NX. + */ + stream.ibuf = (void *)kmem_malloc(kernel_arena, *size, + M_NOWAIT); if (stream.ibuf == NULL) break; #else @@ -648,3 +656,14 @@ bpf_jit_compile(struct bpf_insn *prog, u return ((bpf_filter_func)(void *)stream.ibuf); } + +void +bpf_jit_free(void *func, size_t size) +{ + +#ifdef _KERNEL + kmem_free(kernel_arena, (vm_offset_t)func, size); +#else + munmap(func, size); +#endif +} Modified: head/sys/i386/i386/bpf_jit_machdep.c ============================================================================== --- head/sys/i386/i386/bpf_jit_machdep.c Mon Apr 17 21:57:23 2017 (r317071) +++ head/sys/i386/i386/bpf_jit_machdep.c Mon Apr 17 22:02:09 2017 (r317072) @@ -1,6 +1,6 @@ /*- * Copyright (C) 2002-2003 NetGroup, Politecnico di Torino (Italy) - * Copyright (C) 2005-2016 Jung-uk Kim + * Copyright (C) 2005-2017 Jung-uk Kim * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -37,9 +37,10 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include +#include + #include #else #include @@ -678,3 +679,14 @@ bpf_jit_compile(struct bpf_insn *prog, u return ((bpf_filter_func)(void *)stream.ibuf); } + +void +bpf_jit_free(void *func, size_t size) +{ + +#ifdef _KERNEL + free(func, M_BPFJIT); +#else + munmap(func, size); +#endif +} Modified: head/sys/net/bpf_jitter.c ============================================================================== --- head/sys/net/bpf_jitter.c Mon Apr 17 21:57:23 2017 (r317071) +++ head/sys/net/bpf_jitter.c Mon Apr 17 22:02:09 2017 (r317072) @@ -1,6 +1,6 @@ /*- * Copyright (C) 2002-2003 NetGroup, Politecnico di Torino (Italy) - * Copyright (C) 2005-2009 Jung-uk Kim + * Copyright (C) 2005-2017 Jung-uk Kim * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -99,13 +99,11 @@ void bpf_destroy_jit_filter(bpf_jit_filter *filter) { -#ifdef _KERNEL if (filter->func != bpf_jit_accept_all) - free(filter->func, M_BPFJIT); + bpf_jit_free(filter->func, filter->size); +#ifdef _KERNEL free(filter, M_BPFJIT); #else - if (filter->func != bpf_jit_accept_all) - munmap(filter->func, filter->size); free(filter); #endif } Modified: head/sys/net/bpf_jitter.h ============================================================================== --- head/sys/net/bpf_jitter.h Mon Apr 17 21:57:23 2017 (r317071) +++ head/sys/net/bpf_jitter.h Mon Apr 17 22:02:09 2017 (r317072) @@ -86,5 +86,6 @@ void bpf_destroy_jit_filter(bpf_jit_fil struct bpf_insn; bpf_filter_func bpf_jit_compile(struct bpf_insn *, u_int, size_t *); +void bpf_jit_free(void *, size_t); #endif /* _NET_BPF_JITTER_H_ */