From owner-svn-src-all@freebsd.org Sat Jun 8 17:44:44 2019 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7369A15AE950; Sat, 8 Jun 2019 17:44:44 +0000 (UTC) (envelope-from bz@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 19F406BEAF; Sat, 8 Jun 2019 17:44:44 +0000 (UTC) (envelope-from bz@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id E9A821EDFF; Sat, 8 Jun 2019 17:44:43 +0000 (UTC) (envelope-from bz@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x58HihgV046311; Sat, 8 Jun 2019 17:44:43 GMT (envelope-from bz@FreeBSD.org) Received: (from bz@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x58HigVH046303; Sat, 8 Jun 2019 17:44:42 GMT (envelope-from bz@FreeBSD.org) Message-Id: <201906081744.x58HigVH046303@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bz set sender to bz@FreeBSD.org using -f From: "Bjoern A. Zeeb" Date: Sat, 8 Jun 2019 17:44:42 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r348808 - in head: . sys/conf sys/kern sys/netinet sys/sys X-SVN-Group: head X-SVN-Commit-Author: bz X-SVN-Commit-Paths: in head: . sys/conf sys/kern sys/netinet sys/sys X-SVN-Commit-Revision: 348808 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 19F406BEAF X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.998,0]; NEURAL_HAM_SHORT(-0.98)[-0.975,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 Jun 2019 17:44:44 -0000 Author: bz Date: Sat Jun 8 17:44:42 2019 New Revision: 348808 URL: https://svnweb.freebsd.org/changeset/base/348808 Log: Fix dpcpu and vnet panics with complex types at the end of the section. Apply a linker script when linking i386 kernel modules to apply padding to a set_pcpu or set_vnet section. The padding value is kind-of random and is used to catch modules not compiled with the linker-script, so possibly still having problems leading to kernel panics. This is needed as the code generated on certain architectures for non-simple-types, e.g., an array can generate an absolute relocation on the edge (just outside) the section and thus will not be properly relocated. Adding the padding to the end of the section will ensure that even absolute relocations of complex types will be inside the section, if they are the last object in there and hence relocation will work properly and avoid panics such as observed with carp.ko or ipsec.ko. There is a rather lengthy discussion of various options to apply in the mentioned PRs and their depends/blocks, and the review. There seems no best solution working across multiple toolchains and multiple version of them, so I took the liberty of taking one, as currently our users (and our CI system) are hitting this on just i386 and we need some solution. I wish we would have a proper fix rather than another "hack". Also backout r340009 which manually, temporarily fixed CARP before 12.0-R "by chance" after a lead-up of various other link-elf.c and related fixes. PR: 230857,238012 With suggestions from: arichardson (originally last year) Tested by: lwhsu Event: Waterloo Hackathon 2019 Reported by: lwhsu, olivier MFC after: 6 weeks Differential Revision: https://reviews.freebsd.org/D17512 Added: head/sys/conf/ldscript.set_padding (contents, props changed) Modified: head/UPDATING head/sys/conf/kmod.mk head/sys/kern/link_elf.c head/sys/netinet/ip_carp.c head/sys/sys/param.h Modified: head/UPDATING ============================================================================== --- head/UPDATING Sat Jun 8 17:38:27 2019 (r348807) +++ head/UPDATING Sat Jun 8 17:44:42 2019 (r348808) @@ -31,6 +31,11 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 13.x IS SLOW: disable the most expensive debugging functionality run "ln -s 'abort:false,junk:false' /etc/malloc.conf".) +20190608: + A fix was applied to i386 kernel modules to avoid panics with + dpcpu or vnet. Users need to recompile i386 kernel modules + having pcpu or vnet sections or they will refuse to load. + 20190513: User-wired pages now have their own counter, vm.stats.vm.v_user_wire_count. The vm.max_wired sysctl was renamed Modified: head/sys/conf/kmod.mk ============================================================================== --- head/sys/conf/kmod.mk Sat Jun 8 17:38:27 2019 (r348807) +++ head/sys/conf/kmod.mk Sat Jun 8 17:44:42 2019 (r348808) @@ -242,7 +242,13 @@ ${KMOD}.kld: ${OBJS} .else ${FULLPROG}: ${OBJS} .endif +.if !defined(FIRMWS) && (${MACHINE_CPUARCH} == "i386") + ${LD} -m ${LD_EMULATION} ${_LDFLAGS} -r \ + -T ${SYSDIR}/conf/ldscript.set_padding \ + -d -o ${.TARGET} ${OBJS} +.else ${LD} -m ${LD_EMULATION} ${_LDFLAGS} -r -d -o ${.TARGET} ${OBJS} +.endif .if ${MK_CTF} != "no" ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS} .endif Added: head/sys/conf/ldscript.set_padding ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/conf/ldscript.set_padding Sat Jun 8 17:44:42 2019 (r348808) @@ -0,0 +1,46 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2018 Bjoern A. Zeeb + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ +SECTIONS +{ + set_pcpu : + { + *(set_pcpu) + LONG(0x90909090) ; + } +} + +SECTIONS +{ + set_vnet : + { + *(set_vnet) + LONG(0x90909090) ; + } +} +/* end */ Modified: head/sys/kern/link_elf.c ============================================================================== --- head/sys/kern/link_elf.c Sat Jun 8 17:38:27 2019 (r348807) +++ head/sys/kern/link_elf.c Sat Jun 8 17:44:42 2019 (r348808) @@ -615,10 +615,14 @@ parse_dynamic(elf_file_t ef) return (0); } +#define LS_PADDING 0x90909090 static int parse_dpcpu(elf_file_t ef) { int error, size; +#if defined(__i386__) + uint32_t pad; +#endif ef->pcpu_start = 0; ef->pcpu_stop = 0; @@ -631,6 +635,26 @@ parse_dpcpu(elf_file_t ef) /* Empty set? */ if (size < 1) return (0); +#if defined(__i386__) + /* In case we do find __start/stop_set_ symbols double-check. */ + if (size < 4) { + uprintf("Kernel module '%s' must be recompiled with " + "linker script\n", ef->lf.pathname); + return (ENOEXEC); + } + + /* Padding from linker-script correct? */ + pad = *(uint32_t *)((uintptr_t)ef->pcpu_stop - sizeof(pad)); + if (pad != LS_PADDING) { + uprintf("Kernel module '%s' must be recompiled with " + "linker script, invalid padding %#04x (%#04x)\n", + ef->lf.pathname, pad, LS_PADDING); + return (ENOEXEC); + } + /* If we only have valid padding, nothing to do. */ + if (size == 4) + return (0); +#endif /* * Allocate space in the primary pcpu area. Copy in our * initialization from the data section and then initialize @@ -656,6 +680,9 @@ static int parse_vnet(elf_file_t ef) { int error, size; +#if defined(__i386__) + uint32_t pad; +#endif ef->vnet_start = 0; ef->vnet_stop = 0; @@ -668,6 +695,26 @@ parse_vnet(elf_file_t ef) /* Empty set? */ if (size < 1) return (0); +#if defined(__i386__) + /* In case we do find __start/stop_set_ symbols double-check. */ + if (size < 4) { + uprintf("Kernel module '%s' must be recompiled with " + "linker script\n", ef->lf.pathname); + return (ENOEXEC); + } + + /* Padding from linker-script correct? */ + pad = *(uint32_t *)((uintptr_t)ef->vnet_stop - sizeof(pad)); + if (pad != LS_PADDING) { + uprintf("Kernel module '%s' must be recompiled with " + "linker script, invalid padding %#04x (%#04x)\n", + ef->lf.pathname, pad, LS_PADDING); + return (ENOEXEC); + } + /* If we only have valid padding, nothing to do. */ + if (size == 4) + return (0); +#endif /* * Allocate space in the primary vnet area. Copy in our * initialization from the data section and then initialize @@ -688,6 +735,7 @@ parse_vnet(elf_file_t ef) return (0); } #endif +#undef LS_PADDING static int link_elf_link_preload(linker_class_t cls, Modified: head/sys/netinet/ip_carp.c ============================================================================== --- head/sys/netinet/ip_carp.c Sat Jun 8 17:38:27 2019 (r348807) +++ head/sys/netinet/ip_carp.c Sat Jun 8 17:44:42 2019 (r348808) @@ -2180,21 +2180,6 @@ static struct protosw in6_carp_protosw = { }; #endif -#ifdef VIMAGE -#if defined(__i386__) -/* - * XXX This is a hack to work around an absolute relocation outside - * set_vnet by one (on the stop symbol) for carpstats. Add a dummy variable - * to the end of the file in the hope that the linker will just keep the - * order (as it seems to do at the moment). It is understood to be fragile. - * See PR 230857 for a longer discussion of the problem and the referenced - * review for possible alternate solutions. Each is a hack; we just need - * the least intrusive one for the next release. - */ -VNET_DEFINE(char, carp_zzz) = 0xde; -#endif -#endif - static void carp_mod_cleanup(void) { Modified: head/sys/sys/param.h ============================================================================== --- head/sys/sys/param.h Sat Jun 8 17:38:27 2019 (r348807) +++ head/sys/sys/param.h Sat Jun 8 17:44:42 2019 (r348808) @@ -60,7 +60,7 @@ * in the range 5 to 9. */ #undef __FreeBSD_version -#define __FreeBSD_version 1300030 /* Master, propagated to newvers */ +#define __FreeBSD_version 1300031 /* Master, propagated to newvers */ /* * __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,