From owner-freebsd-arch@FreeBSD.ORG Mon Jan 12 17:01:13 2015 Return-Path: Delivered-To: arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id BD2D7819 for ; Mon, 12 Jan 2015 17:01:13 +0000 (UTC) Received: from mail-yh0-f47.google.com (mail-yh0-f47.google.com [209.85.213.47]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 7DE1F904 for ; Mon, 12 Jan 2015 17:01:13 +0000 (UTC) Received: by mail-yh0-f47.google.com with SMTP id f73so10113531yha.6 for ; Mon, 12 Jan 2015 09:01:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:subject:mime-version:content-type:from :in-reply-to:date:cc:message-id:references:to; bh=1N+HsL2Q0Olbq+KP2lE8EZOY390mS0DhSGBYYWTqv3k=; b=gThkwPZ4WXIxzohvlXm2+m8JkUhaj418H7toboS5wW1N6dVFOyOIcf2rFxQObFa1k6 Mov6YnJGVQlFpvg/BDVYZvn1QpewSntXImv9kA0P8Qjn9Dj4tM9DHVIkveCYV3muaPPd m8Ez6Sv13Lu4JpuotlCH4zgNZdW1vCIZN56nQ1jy9LSLWNfSZxf5Nsqb2RdlWk2tX6Zo JKEB47DZnHGfFqaiSqJSUcd359txVGt6DbEjOup1AXuWRG2dchEe4eTcFSvMyQ3HMlj5 MM0T/Gyn3iqgpil4+0gb//ZOj2MvV9MpTlFU2hOgZVi0phbRMCOdriA+6R3FAj5LOKaw lGhg== X-Gm-Message-State: ALoCoQmYNCMH4PRncjhCfPNr0wXTBmVAXs9POHQic6JMJWyD0R6wEoDJWdWEQQ2NcLJCA4gzS43c X-Received: by 10.236.103.133 with SMTP id f5mr23506492yhg.50.1421082066174; Mon, 12 Jan 2015 09:01:06 -0800 (PST) Received: from [10.64.26.9] ([69.53.236.236]) by mx.google.com with ESMTPSA id y42sm2015616yhc.11.2015.01.12.09.01.04 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 12 Jan 2015 09:01:05 -0800 (PST) Sender: Warner Losh Subject: Re: devctl(8): A device control utility Mime-Version: 1.0 (Mac OS X Mail 8.1 \(1993\)) Content-Type: multipart/signed; boundary="Apple-Mail=_D6493F37-45A7-4144-A238-62995AB12EF8"; protocol="application/pgp-signature"; micalg=pgp-sha512 X-Pgp-Agent: GPGMail 2.5b3 From: Warner Losh In-Reply-To: <54B3F349.9050703@FreeBSD.org> Date: Mon, 12 Jan 2015 10:01:03 -0700 Message-Id: <11219A27-4C5B-4429-8847-3E54F9C4CD1E@bsdimp.com> References: <3200196.9ZgXApgRdA@ralph.baldwin.cx> <54AAF60A.9070609@FreeBSD.org> <54AAFAEB.2090505@selasky.org> <6155572.yV5dxPJznD@ralph.baldwin.cx> <54B3F349.9050703@FreeBSD.org> To: John Baldwin X-Mailer: Apple Mail (2.1993) Cc: Hans Petter Selasky , arch@freebsd.org X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Jan 2015 17:01:13 -0000 --Apple-Mail=_D6493F37-45A7-4144-A238-62995AB12EF8 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Jan 12, 2015, at 9:16 AM, John Baldwin wrote: >=20 > On 1/5/15 4:18 PM, John Baldwin wrote: >> On Monday, January 05, 2015 09:58:19 PM Hans Petter Selasky wrote: >>> On 01/05/15 21:37, John Baldwin wrote: >>>> On 1/5/15 3:13 PM, Hans Petter Selasky wrote: >>>>> On 01/05/15 21:01, John Baldwin wrote: >>>>>> The devctl(8) utility is then a thin wrapper around libdevctl = (and >>>>>> does not >>>>>> yet have a manpage). >>>>>>=20 >>>>>> Do folks have any feedback? >>>>>=20 >>>>> Hi, >>>>>=20 >>>>> In the USB area attach and detach must be synchronized to the USB = stack >>>>> and "usbconfig -d X.Y set_config Z" or "usbconfig -d X.Y reset" = should >>>>> be used to avoid races attaching and detaching drivers! >>>>=20 >>>> I think this points to one or more missing bus methods so that the = bus >>>> can hook into device_probe_and_attach() to reset a device as = needed. >>>> (e.g. if you had bus_probe_started / bus_probe_finished and = possibly >>>> similar methods for attach. PCI could use a bus_attach_finished() >>>> callback so that it could clean up any dangling resources and = possibly >>>> power down on a failed attach the way it does in bus_child_detached = as >>>> well). >>>=20 >>> Hi, >>>=20 >>> USB has its own threads to allocate/free devices. Another problem is = how >>> to atomically get a reference count across multiple layers like PCI = and >>> USB. It doesn't allow probe/attach when called from outside these = threads. >>=20 >> That just means you need to use some locks. :) Cardbus also uses an = event >> thread to handle auto-attach of devices when it detected a card = change event, >> but that doesn't prevent it from servicing an ioctl request. >=20 > Another option btw would be to add bus methods that wrap probe and > attach (rather than pre and post event hooks). I wish bus_add_child() > were done this way such that device_add_child_ordered() were renamed = to > bus_generic_add_child() (and was the default add_child method) and = that > device_add_child_ordered() called 'BUS_ADD_CHILD()' so that > 'device_add_child()' was the proper public API (instead of exposing > BUS_ADD_CHILD()). Similarly, I think that 'device_attach()' and > 'device_probe_and_attach()' should be the public API and that one way = or > another we should add hooks to allow bus drivers to modify their > behavior if needed. However, they should be fine for devctl ioctls to > invoke as well as other kernel bits. When I was doing CardBus and PC Card I wished for similar things. Then I realized I didn=E2=80=99t need them because as the bus author, I know = when these events happened and could take appropriate actions for the bus. I = didn=E2=80=99t have that atomic access issues though, since as the bus author I also = controlled how and when mutexes were taken out and when I allowed access to the bus. I only used mutexes in CardBus and PC Card because most of the sleeps were short, but other ways to do locking are quite possible... Warner --Apple-Mail=_D6493F37-45A7-4144-A238-62995AB12EF8 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP using GPGMail -----BEGIN PGP SIGNATURE----- Comment: GPGTools - https://gpgtools.org iQIcBAEBCgAGBQJUs/3PAAoJEGwc0Sh9sBEArfwP/2oRtY/d7tvFxbZ4C5+w77tt MPzQhy2V21ehXlba3oPiefx7Nck8XV8koW4W44VuxFKw84q477TOnUPsMGK/3JN4 cQw6WUXcWn7Z8kAmd3dQv3UGSnO44Tg64WFYdTSczluqOvBxocGGY9d5WaC2U/Qo lG99tq7xwcwmvNYz4Hw2DkN5puwJ38IXyFyDl826oz9JIuKhCToRSOncWLIpJfPL 4B9LxZeGyY4f1XXn1ABQiRHk6osGvAf0VEMrUyyRQ3BYAwNyGFesoOJU3FGc1a1i VTHrdKgp8MZNAzKw4IbNeYOCPkhYVOAE1VbKxx4GsKLKJ6Sm1vS3IxoKXDJup+1S IvDeVXKI9P4yalyVu2llaT116mYaaxJ2jj9hZT2woFIPy5qg753SfTSK3zVBHpwe OWbbSguFILcbSh4hxBRxbsMVySeL+CQ4VOgzG+V0MLb7+hyQG0DbWJENRdNuRxNe MYO6Zwwltwk81CE6GiTlzT26+trWKyUsqQ4EONLs1FTq3E8JBwYb1MYWKXLtFV4h 97bCzkdf880jrb89gOAEaASvEiCyJCyMbPYSVrwpR+bTyTDJK6FYWeBiSXu4G3hk q7Dl7xJkuiydodNLNlk2jLCD/6gbCGpHu1TfiKZqmMseyIt3huoOMtuTs+4NTiqf zXEFtYopM+QNnVqkx0w0 =Wv8m -----END PGP SIGNATURE----- --Apple-Mail=_D6493F37-45A7-4144-A238-62995AB12EF8--