From owner-svn-src-projects@FreeBSD.ORG Sun Oct 6 12:40:34 2013 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 3D536320; Sun, 6 Oct 2013 12:40:34 +0000 (UTC) (envelope-from markm@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 289FA2844; Sun, 6 Oct 2013 12:40:34 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r96CeYld034891; Sun, 6 Oct 2013 12:40:34 GMT (envelope-from markm@svn.freebsd.org) Received: (from markm@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r96CeW0F034884; Sun, 6 Oct 2013 12:40:32 GMT (envelope-from markm@svn.freebsd.org) Message-Id: <201310061240.r96CeW0F034884@svn.freebsd.org> From: Mark Murray Date: Sun, 6 Oct 2013 12:40:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r256086 - in projects/random_number_generator/sys: dev/random net netgraph X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Oct 2013 12:40:34 -0000 Author: markm Date: Sun Oct 6 12:40:32 2013 New Revision: 256086 URL: http://svnweb.freebsd.org/changeset/base/256086 Log: Debug run. This now works, except that the "live" sources haven't been tested. With all sources turned on, this unlocks itself in a couple of seconds! That is no my box, and there is no guarantee that this will be the case everywhere. * Cut debug prints. * Use the same locks/mutexes all the way through. * Be a tad more conservative about entropy estimates. Modified: projects/random_number_generator/sys/dev/random/live_entropy_sources.c projects/random_number_generator/sys/dev/random/random_harvestq.c projects/random_number_generator/sys/dev/random/random_harvestq.h projects/random_number_generator/sys/dev/random/yarrow.c projects/random_number_generator/sys/net/if_ethersubr.c projects/random_number_generator/sys/net/if_tun.c projects/random_number_generator/sys/netgraph/ng_iface.c Modified: projects/random_number_generator/sys/dev/random/live_entropy_sources.c ============================================================================== --- projects/random_number_generator/sys/dev/random/live_entropy_sources.c Sun Oct 6 12:39:12 2013 (r256085) +++ projects/random_number_generator/sys/dev/random/live_entropy_sources.c Sun Oct 6 12:40:32 2013 (r256086) @@ -51,7 +51,6 @@ __FBSDID("$FreeBSD$"); LIST_HEAD(les_head, live_entropy_sources); static struct les_head sources = LIST_HEAD_INITIALIZER(sources); -static struct sx les_lock; /* need a sleepable lock */ #define LES_THRESHOLD 10 @@ -65,9 +64,9 @@ live_entropy_source_register(struct rand les = malloc(sizeof(struct live_entropy_sources), M_ENTROPY, M_WAITOK); les->rsource = rsource; - sx_xlock(&les_lock); + mtx_lock_spin(&harvest_mtx); LIST_INSERT_HEAD(&sources, les, entries); - sx_xunlock(&les_lock); + mtx_unlock_spin(&harvest_mtx); } void @@ -77,7 +76,7 @@ live_entropy_source_deregister(struct ra KASSERT(rsource != NULL, ("invalid input to %s", __func__)); - sx_xlock(&les_lock); + mtx_lock_spin(&harvest_mtx); LIST_FOREACH(les, &sources, entries) { if (les->rsource == rsource) { LIST_REMOVE(les, entries); @@ -85,7 +84,7 @@ live_entropy_source_deregister(struct ra break; } } - sx_xunlock(&les_lock); + mtx_unlock_spin(&harvest_mtx); } static int @@ -96,7 +95,7 @@ live_entropy_source_handler(SYSCTL_HANDL count = error = 0; - sx_slock(&les_lock); + mtx_lock_spin(&harvest_mtx); if (LIST_EMPTY(&sources)) error = SYSCTL_OUT(req, "", 0); @@ -113,7 +112,7 @@ live_entropy_source_handler(SYSCTL_HANDL } } - sx_sunlock(&les_lock); + mtx_unlock_spin(&harvest_mtx); return (error); } @@ -126,8 +125,6 @@ live_entropy_sources_init(void *unused) CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, 0, live_entropy_source_handler, "", "List of Active Live Entropy Sources"); - - sx_init(&les_lock, "live_entropy_sources"); } /* @@ -138,6 +135,7 @@ live_entropy_sources_init(void *unused) * * BEWARE!!! * This function runs inside the RNG thread! Don't do anything silly! + * The harvest_mtx mutex is held; you may count on that. */ void live_entropy_sources_feed(int rounds, event_proc_f entropy_processor) @@ -147,8 +145,6 @@ live_entropy_sources_feed(int rounds, ev struct live_entropy_sources *les; int i, n; - sx_slock(&les_lock); - /* * Walk over all of live entropy sources, and feed their output * to the system-wide RNG. @@ -176,15 +172,11 @@ live_entropy_sources_feed(int rounds, ev } } - - sx_sunlock(&les_lock); } static void live_entropy_sources_deinit(void *unused) { - - sx_destroy(&les_lock); } SYSINIT(random_adaptors, SI_SUB_DRIVERS, SI_ORDER_FIRST, Modified: projects/random_number_generator/sys/dev/random/random_harvestq.c ============================================================================== --- projects/random_number_generator/sys/dev/random/random_harvestq.c Sun Oct 6 12:39:12 2013 (r256085) +++ projects/random_number_generator/sys/dev/random/random_harvestq.c Sun Oct 6 12:40:32 2013 (r256086) @@ -52,7 +52,7 @@ __FBSDID("$FreeBSD$"); /* * The harvest mutex protects the consistency of the entropy fifos and - * empty fifo. + * empty fifo and other associated structures. */ struct mtx harvest_mtx; Modified: projects/random_number_generator/sys/dev/random/random_harvestq.h ============================================================================== --- projects/random_number_generator/sys/dev/random/random_harvestq.h Sun Oct 6 12:39:12 2013 (r256085) +++ projects/random_number_generator/sys/dev/random/random_harvestq.h Sun Oct 6 12:40:32 2013 (r256086) @@ -37,5 +37,6 @@ void random_harvestq_internal(u_int64_t, u_int, u_int, enum esource); extern int random_kthread_control; +extern struct mtx harvest_mtx; #endif /* __RANDOM_HARVEST_H__ */ Modified: projects/random_number_generator/sys/dev/random/yarrow.c ============================================================================== --- projects/random_number_generator/sys/dev/random/yarrow.c Sun Oct 6 12:39:12 2013 (r256085) +++ projects/random_number_generator/sys/dev/random/yarrow.c Sun Oct 6 12:40:32 2013 (r256086) @@ -114,7 +114,7 @@ random_process_event(struct harvest *eve struct source *source; enum esource src; -#if 1 +#if 0 /* Do this better with DTrace */ { int i; @@ -243,6 +243,10 @@ reseed(u_int fastslow) u_int i; enum esource j; +#if 0 + printf("Yarrow: %s reseed\n", fastslow == FAST ? "fast" : "slow"); +#endif + /* The reseed task must not be jumped on */ mtx_lock(&random_reseed_mtx); Modified: projects/random_number_generator/sys/net/if_ethersubr.c ============================================================================== --- projects/random_number_generator/sys/net/if_ethersubr.c Sun Oct 6 12:39:12 2013 (r256085) +++ projects/random_number_generator/sys/net/if_ethersubr.c Sun Oct 6 12:40:32 2013 (r256086) @@ -639,7 +639,7 @@ ether_input_internal(struct ifnet *ifp, } if (harvest.ethernet) - random_harvest(&(m->m_data), 12, 3, RANDOM_NET_ETHER); + random_harvest(&(m->m_data), 12, 2, RANDOM_NET_ETHER); ether_demux(ifp, m); CURVNET_RESTORE(); Modified: projects/random_number_generator/sys/net/if_tun.c ============================================================================== --- projects/random_number_generator/sys/net/if_tun.c Sun Oct 6 12:39:12 2013 (r256085) +++ projects/random_number_generator/sys/net/if_tun.c Sun Oct 6 12:40:32 2013 (r256086) @@ -918,7 +918,7 @@ tunwrite(struct cdev *dev, struct uio *u return (EAFNOSUPPORT); } if (harvest.point_to_point) - random_harvest(&(m->m_data), 12, 3, RANDOM_NET_TUN); + random_harvest(&(m->m_data), 12, 2, RANDOM_NET_TUN); ifp->if_ibytes += m->m_pkthdr.len; ifp->if_ipackets++; CURVNET_SET(ifp->if_vnet); Modified: projects/random_number_generator/sys/netgraph/ng_iface.c ============================================================================== --- projects/random_number_generator/sys/netgraph/ng_iface.c Sun Oct 6 12:39:12 2013 (r256085) +++ projects/random_number_generator/sys/netgraph/ng_iface.c Sun Oct 6 12:40:32 2013 (r256086) @@ -775,7 +775,7 @@ ng_iface_rcvdata(hook_p hook, item_p ite return (EAFNOSUPPORT); } if (harvest.point_to_point) - random_harvest(&(m->m_data), 12, 3, RANDOM_NET_NG); + random_harvest(&(m->m_data), 12, 2, RANDOM_NET_NG); M_SETFIB(m, ifp->if_fib); netisr_dispatch(isr, m); return (0);