From owner-freebsd-hackers@freebsd.org Tue Nov 8 14:33:35 2016 Return-Path: Delivered-To: freebsd-hackers@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 9180FC37A46 for ; Tue, 8 Nov 2016 14:33:35 +0000 (UTC) (envelope-from sebastian.huber@embedded-brains.de) Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) (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 4F7F2BAE for ; Tue, 8 Nov 2016 14:33:34 +0000 (UTC) (envelope-from sebastian.huber@embedded-brains.de) Received: from [88.198.220.132] (helo=sslproxy03.your-server.de) by dedi548.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.85_2) (envelope-from ) id 1c473z-0005vL-Pi for freebsd-hackers@freebsd.org; Tue, 08 Nov 2016 15:07:47 +0100 Received: from [82.135.62.35] (helo=mail.embedded-brains.de) by sslproxy03.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.84_2) (envelope-from ) id 1c473z-0000wc-3p for freebsd-hackers@freebsd.org; Tue, 08 Nov 2016 15:07:47 +0100 Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 23B072A180C for ; Tue, 8 Nov 2016 15:07:55 +0100 (CET) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id B-MHgPNIRZBO for ; Tue, 8 Nov 2016 15:07:53 +0100 (CET) Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 3D9C02A01AE for ; Tue, 8 Nov 2016 15:07:53 +0100 (CET) X-Virus-Scanned: amavisd-new at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id E5fMCJO3RjtB for ; Tue, 8 Nov 2016 15:07:53 +0100 (CET) Received: from [192.168.96.129] (unknown [192.168.96.129]) by mail.embedded-brains.de (Postfix) with ESMTPSA id 0029B2A0003 for ; Tue, 8 Nov 2016 15:07:52 +0100 (CET) To: FreeBSD From: Sebastian Huber Subject: Should page allocator zero the pages for UMA? Message-ID: <5821DC2E.9020302@embedded-brains.de> Date: Tue, 8 Nov 2016 15:07:42 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Authenticated-Sender: smtp-embedded@poldinet.de X-Virus-Scanned: Clear (ClamAV 0.99.2/22499/Tue Nov 8 11:28:14 2016) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Nov 2016 14:33:35 -0000 Hello, we use the FreeBSD network, USB and SD/MMC card stacks for the real-time=20 operating system RTEMS: https://git.rtems.org/rtems-libbsd I update currently from FreeBSD 9.3 to head. We use the UMA from FreeBSD=20 with a custom page allocator: https://git.rtems.org/rtems-libbsd/tree/rtemsbsd/rtems/rtems-kernel-page.= c The FreeBSD 9.3 based port worked well with uninitialized pages, e.g.=20 random or previous content. However, after the update to head I had to=20 zero initialize the pages. One issue was an incomplete struct inpcb { [...] struct inpcbport *inp_phd; /* (i/h) head of this list */ #define inp_zero_size offsetof(struct inpcb, inp_gencnt) inp_gen_t inp_gencnt; /* (c) generation count */ struct llentry *inp_lle; /* cached L2 information */ struct rwlock inp_lock; rt_gen_t inp_rt_cookie; /* generation for route entry */ union { /* cached L3 information */ struct route inpu_route; struct route_in6 inpu_route6; } inp_rtu; #define inp_route inp_rtu.inpu_route #define inp_route6 inp_rtu.inpu_route6 }; initialization. The initialization consists of two parts: static int udp_inpcb_init(void *mem, int size, int flags) { struct inpcb *inp; inp =3D mem; INP_LOCK_INIT(inp, "inp", "udpinp"); return (0); } /* * Allocate a PCB and associate it with the socket. * On success return with the PCB locked. */ int in_pcballoc(struct socket *so, struct inpcbinfo *pcbinfo) { struct inpcb *inp; int error; #ifdef INVARIANTS if (pcbinfo =3D=3D &V_tcbinfo) { INP_INFO_RLOCK_ASSERT(pcbinfo); } else { INP_INFO_WLOCK_ASSERT(pcbinfo); } #endif error =3D 0; inp =3D uma_zalloc(pcbinfo->ipi_zone, M_NOWAIT); if (inp =3D=3D NULL) return (ENOBUFS); bzero(inp, inp_zero_size); inp->inp_pcbinfo =3D pcbinfo; inp->inp_socket =3D so; inp->inp_cred =3D crhold(so->so_cred); inp->inp_inc.inc_fibnum =3D so->so_fibnum; [...] This lets at least inp_route uninitialized leading to a crash during=20 destruction, e.g. if (inp->inp_route.ro_rt) { RTFREE(inp->inp_route.ro_rt); inp->inp_route.ro_rt =3D (struct rtentry *)NULL; } uses uninitialized data. Did something in the page allocator change between FreeBSD 9.3 and=20 trunk, so that page are now zero initialized or is this a bug in=20 udp_inpcb_init()? --=20 Sebastian Huber, embedded brains GmbH Address : Dornierstr. 4, D-82178 Puchheim, Germany Phone : +49 89 189 47 41-16 Fax : +49 89 189 47 41-09 E-Mail : sebastian.huber@embedded-brains.de PGP : Public key available on request. Diese Nachricht ist keine gesch=C3=A4ftliche Mitteilung im Sinne des EHUG= .