From owner-svn-src-head@freebsd.org Tue Jul 18 09:33:12 2017 Return-Path: Delivered-To: svn-src-head@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 5C17BCFD5F8; Tue, 18 Jul 2017 09:33:12 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail110.syd.optusnet.com.au (mail110.syd.optusnet.com.au [211.29.132.97]) by mx1.freebsd.org (Postfix) with ESMTP id 232D2677A6; Tue, 18 Jul 2017 09:33:11 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from [192.168.0.102] (c110-21-101-228.carlnfd1.nsw.optusnet.com.au [110.21.101.228]) by mail110.syd.optusnet.com.au (Postfix) with ESMTPS id 29DDB1024D4; Tue, 18 Jul 2017 19:33:04 +1000 (AEST) Date: Tue, 18 Jul 2017 19:33:03 +1000 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Konstantin Belousov cc: Ian Lepore , Bruce Evans , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r320901 - in head/sys: amd64/amd64 isa x86/isa In-Reply-To: <20170717164310.GM1935@kib.kiev.ua> Message-ID: <20170718180856.P1105@besplex.bde.org> References: <201707120242.v6C2gvDB026199@repo.freebsd.org> <20170712224803.G1991@besplex.bde.org> <1500308973.22314.89.camel@freebsd.org> <20170717164310.GM1935@kib.kiev.ua> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.2 cv=VbSHBBh9 c=1 sm=1 tr=0 a=PalzARQSbocsUSjMRkwAPg==:117 a=PalzARQSbocsUSjMRkwAPg==:17 a=kj9zAlcOel0A:10 a=9LpXibFZ7eA5Nq7F3o0A:9 a=CjuIK1q_8ugA:10 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Jul 2017 09:33:12 -0000 On Mon, 17 Jul 2017, Konstantin Belousov wrote: > On Mon, Jul 17, 2017 at 10:29:33AM -0600, Ian Lepore wrote: >> I assumed the reason the efirt code was using the same mutex that >> protected access to the at rtc was because under the hood, the efi rt >> clock is really the same hardware too, accessed via bios code. > > EFI spec states it explicitely, e.g. in the description of the GetTime() > function of the Time Services interface: > > During runtime, if a PC-AT CMOS device is present in the platform the > caller must synchronize access to the device before calling GetTime(). The clock_lock mutex still protects individual cmos registers, provided efi uses rtcin() etc., which it apparently doesn't. The new atrtc_time_lock mutex doesn't protect even the rtc cmos registers as a group. Other subsystems can still access the registers holding only their own lock or just clock_lock. Only write accesses would be harmful. Read accesses do occur if rtcintr() is active, but these only change the index register. Even the rtc subsystem has (groups of) write accesses that are not properly locked. These are for (re)initializations. Reinitializations occur for changing the rtc rate for profiling and for resuming. There is no locking except possibly Giant for even the rtc_status[ab] images vs their registers. Giant locking might work for that, but it doesn't work for settime() calling rtc code, at least after removing Giant from settime(). If efi accesses the rtc directly, then that is just broken and sharing the new mutex doesn't help much. The new mutex only prevents contention between efi code that uses it and rtc code that use it -- that is, just the rtc timer parts of the rtc code (as the name of the new mutex suggests). The following remain unprotected: - rtc initialization code - more seriously, rtc interrupt code and rtcin()/writertc() generally. resettodr_mtx was no better. But further abuse of clock_lock might have worked. Holding clock_lock around efi_runtime->rt_gettime() calls would prevent both rtc timer code and rtc_intr() from contending. I can't find rt_gettime(). I think these sources of contention are normally inactive if efi is used, but efi can still race with rtc initialization, the cmos driver, and possibly acpi code. Bruce