Date: Wed, 26 Sep 2012 18:54:05 +0200 From: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= <des@des.no> To: Ben Laurie <benl@freebsd.org> Cc: Jonathan Anderson <jonathan.anderson@cl.cam.ac.uk>, Pawel Jakub Dawidek <pjd@freebsd.org>, John Baldwin <jhb@freebsd.org>, freebsd-security@freebsd.org, RW <rwmaillists@googlemail.com>, Mariusz Gromada <mariusz.gromada@gmail.com> Subject: Re: Collecting entropy from device_attach() times. Message-ID: <86sja4sp1u.fsf@ds4.des.no> In-Reply-To: <86r4pqqwnm.fsf@ds4.des.no> ("Dag-Erling =?utf-8?Q?Sm=C3=B8rg?= =?utf-8?Q?rav=22's?= message of "Tue, 25 Sep 2012 11:28:13 %2B0200") References: <20120918211422.GA1400@garage.freebsd.pl> <20120919231051.4bc5335b@gumby.homeunix.com> <20120920102104.GA1397@garage.freebsd.pl> <201209200758.51924.jhb@freebsd.org> <20120922080323.GA1454@garage.freebsd.pl> <20120922195325.GH1454@garage.freebsd.pl> <505E59DC.7090505@gmail.com> <20120923151706.GN1454@garage.freebsd.pl> <5060D723.6020305@gmail.com> <CAG5KPzxf0Rfufk5K6Jt4e85xc7zXY_B3a2Sq0Uf_uVLHbV-baw@mail.gmail.com> <86r4pqqwnm.fsf@ds4.des.no>
next in thread | previous in thread | raw e-mail | index | archive | help
Dag-Erling Sm=C3=B8rgrav <des@des.no> writes:
> If you give me a couple of days, I'll try to come up with a patch that
> collects and stores attach times during boot so we can gather and
> analyse real data.
Here's the patch, as a superset of Pawel's. The output looks like this:
des@crashbox ~% sysctl -b hw.attachtimes| hexdump -C
00000000 72 61 6d 30 00 00 00 00 00 00 00 00 00 00 00 00 |ram0..........=
..|
00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 01 24 53 |..............=
$S|
00000020 63 70 75 30 00 00 00 00 00 00 00 00 00 00 00 00 |cpu0..........=
..|
00000030 00 00 00 00 00 00 00 00 00 00 00 00 01 4d 6c cb |.............M=
l.|
00000040 63 70 75 31 00 00 00 00 00 00 00 00 00 00 00 00 |cpu1..........=
..|
00000050 00 00 00 00 00 00 00 00 00 00 00 00 01 4d da b6 |.............M=
..|
00000060 61 74 74 69 6d 65 72 30 00 00 00 00 00 00 00 00 |attimer0......=
..|
00000070 00 00 00 00 00 00 00 00 00 00 00 00 04 59 70 8f |.............Y=
p.|
[...]
where the first 24 bytes of each record contain the device name
(dev->nameunit) and the last eight bytes contain d(cyclecount) for
device_attach() as a big-endian uint64_t.
DES
--=20
Dag-Erling Sm=C3=B8rgrav - des@des.no
Index: sys/dev/random/randomdev_soft.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- sys/dev/random/randomdev_soft.c (revision 240914)
+++ sys/dev/random/randomdev_soft.c (working copy)
@@ -303,7 +303,7 @@
KASSERT(origin =3D=3D RANDOM_START || origin =3D=3D RANDOM_WRITE ||
origin =3D=3D RANDOM_KEYBOARD || origin =3D=3D RANDOM_MOUSE ||
origin =3D=3D RANDOM_NET || origin =3D=3D RANDOM_INTERRUPT ||
- origin =3D=3D RANDOM_PURE,
+ origin =3D=3D RANDOM_PURE || origin =3D=3D RANDOM_DEVICE,
("random_harvest_internal: origin %d invalid\n", origin));
=20
/* Lockless read to avoid lock operations if fifo is full. */
Index: sys/sys/random.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- sys/sys/random.h (revision 240914)
+++ sys/sys/random.h (working copy)
@@ -45,6 +45,7 @@
RANDOM_NET,
RANDOM_INTERRUPT,
RANDOM_PURE,
+ RANDOM_DEVICE,
ENTROPYSOURCE
};
void random_harvest(void *, u_int, u_int, u_int, enum esource);
Index: sys/kern/subr_bus.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- sys/kern/subr_bus.c (revision 240914)
+++ sys/kern/subr_bus.c (working copy)
@@ -31,6 +31,7 @@
=20
#include <sys/param.h>
#include <sys/conf.h>
+#include <sys/endian.h>
#include <sys/filio.h>
#include <sys/lock.h>
#include <sys/kernel.h>
@@ -44,6 +45,7 @@
#include <sys/condvar.h>
#include <sys/queue.h>
#include <machine/bus.h>
+#include <sys/random.h>
#include <sys/rman.h>
#include <sys/selinfo.h>
#include <sys/signalvar.h>
@@ -53,6 +55,7 @@
#include <sys/bus.h>
#include <sys/interrupt.h>
=20
+#include <machine/cpu.h>
#include <machine/stdarg.h>
=20
#include <vm/uma.h>
@@ -60,6 +63,16 @@
SYSCTL_NODE(_hw, OID_AUTO, bus, CTLFLAG_RW, NULL, NULL);
SYSCTL_NODE(, OID_AUTO, dev, CTLFLAG_RW, NULL, NULL);
=20
+#define MAXNATTACHTIMES 128
+static struct attachtime {
+ char name[24];
+ uint64_t delta;
+} attachtimes[MAXNATTACHTIMES];
+static int nattachtimes;
+SYSCTL_OPAQUE(_hw, OID_AUTO, attachtimes, CTLFLAG_RD,
+ &attachtimes, sizeof(attachtimes), "S,attachtimes",
+ "time spent in device_attach()");
+
/*
* Used to attach drivers to devclasses.
*/
@@ -2760,8 +2773,10 @@
int
device_attach(device_t dev)
{
+ uint64_t attachtime;
int error;
=20
+ attachtime =3D get_cyclecount();
device_sysctl_init(dev);
if (!device_is_quiet(dev))
device_print_child(dev->parent, dev);
@@ -2784,6 +2799,15 @@
dev->state =3D DS_ATTACHED;
dev->flags &=3D ~DF_DONENOMATCH;
devadded(dev);
+ attachtime =3D get_cyclecount() - attachtime;
+ if (nattachtimes < MAXNATTACHTIMES) {
+ strlcpy(attachtimes[nattachtimes].name, dev->nameunit,
+ sizeof(attachtimes[nattachtimes]));
+ attachtimes[nattachtimes].delta =3D htobe64(attachtime);
+ ++nattachtimes;
+ }
+ random_harvest(&attachtime, sizeof(attachtime), 4, 0, RANDOM_DEVICE);
+
return (0);
}
=20
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86sja4sp1u.fsf>
