From owner-freebsd-arch@freebsd.org Tue May 28 16:43:31 2019 Return-Path: Delivered-To: freebsd-arch@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 D2F1D15A5710 for ; Tue, 28 May 2019 16:43:30 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (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 "smtp.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 62C81888A1; Tue, 28 May 2019 16:43:30 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from John-Baldwins-MacBook-Pro-4.local (ralph.baldwin.cx [66.234.199.215]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: jhb) by smtp.freebsd.org (Postfix) with ESMTPSA id ADF6F14083; Tue, 28 May 2019 16:43:27 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Subject: Re: proposal: require ivar accessors to succeed To: Warner Losh , Andriy Gapon Cc: "Bjoern A. Zeeb" , freebsd-arch@freebsd.org References: <2b2ab28f-45c5-1c28-f923-170d95c20c3d@FreeBSD.org> From: John Baldwin Openpgp: preference=signencrypt Autocrypt: addr=jhb@FreeBSD.org; keydata= mQGiBETQ+XcRBADMFybiq69u+fJRy/0wzqTNS8jFfWaBTs5/OfcV7wWezVmf9sgwn8TW0Dk0 c9MBl0pz+H01dA2ZSGZ5fXlmFIsee1WEzqeJzpiwd/pejPgSzXB9ijbLHZ2/E0jhGBcVy5Yo /Tw5+U/+laeYKu2xb0XPvM0zMNls1ah5OnP9a6Ql6wCgupaoMySb7DXm2LHD1Z9jTsHcAQMD /1jzh2B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IXIAcm3FGZFXy503DOA0KaTWwvOVdYCFLm3zWuSOmrX/GsEc7ovasOWwjPn878qVjbUKWwx Q4QkF4OhUV9zPtf9tDSAZ3x7QSwoKbCoRCZ/xbyTUPyQ1VvNy/mYrBcYlzHodsaqUDjHuW+I SQQYEQIACQUCRND5ggIbDAAKCRBy3lIGd+N/BCO8AJ9j1dWVQWxw/YdTbEyrRKOY8YZNwwCf afMAg8QvmOWnHx3wl8WslCaXaE8= Message-ID: <86d87d65-2eb1-d1bf-2e9f-53420b84c1a9@FreeBSD.org> Date: Tue, 28 May 2019 09:43:28 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 62C81888A1 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.89 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.89)[-0.888,0]; ASN(0.00)[asn:11403, ipnet:96.47.64.0/20, country:US] X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 May 2019 16:43:31 -0000 On 5/27/19 2:04 PM, Warner Losh wrote: > On Mon, May 27, 2019, 2:47 PM Andriy Gapon wrote: > >> On 27/05/2019 21:10, Bjoern A. Zeeb wrote: >>> On 27 May 2019, at 5:44, Andriy Gapon wrote: >>> >>>> __BUS_ACCESSOR() macro is used to define accessors to bus IVAR >> variables. >>>> Unfortunately, accessors defined in such a fashion completely ignore >> return >>>> values of BUS_READ_IVAR() and BUS_WRITE_IVAR() method calls. There is >> no way to >>>> see if a call is successful. Typically, this should not be a problem >> as a >>>> device driver targets a specific bus (sometimes, buses) and it should >> know what >>>> IVARs the bus has. So, the driver should make only those IVAR calls >> that are >>>> supposed to always succeed on the bus. >>>> But sometimes things can go wrong as with everything else. >>>> >>>> So, I am proposing to add some code to __BUS_ACCESSOR to verify the >> success. >>>> For example, we can panic when a call fails. The checks could be under >>>> INVARIANTS or under DIAGNOSTICS or under a new kernel option. >>>> A less drastic option is to print a warning message on an error. >>>> >>>> This is mostly intended to help driver writers and maintainers. >>>> >>>> Opinions, suggestions, etc are welcome. >>> >>> What about “fixing” the KPI (possibly adding a 2nd one), deprecating the >> old >>> one, and (slowly over time) migrating old stuff over? >> >> I think that the two proposals are not mutually exclusive. >> And I think that both make sense. >> However, it's hard for me to imagine a desire to replace code like this >> devid = pci_get_devid(dev); >> with this >> err = pci_get2_devid(dev, &devid); >> if (err != 0) { >> ... >> } >> >> Especially given that, modulo bugs, dev is going to be a device on the pci >> bus >> and the call is going to succeed. >> In other words, in my opinion, the only cases where an accessor is allowed >> to >> fail are: >> - a driver somehow attached to a device on an unexpected bus >> - uncoordinated changes in between a bus driver and a device driver >> So, programming errors. >> > > I'm cool with panic. The accessor functions are all supposed to be can't > fail. And creating a new set of APIs that can return failure for can't fail > things will just bloat the code with cargo cult error handler's that add no > value. > > So put me down on the NO to the new API. If you want to test if the ivar is > supported, use the lower level READ_IVAR. Let's not break the API because > one person had a bug... Fully agree with this. -- John Baldwin