From nobody Thu Mar 9 00:40:04 2023 X-Original-To: freebsd-fs@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PX9M72VKDz3x5rY for ; Thu, 9 Mar 2023 00:40:19 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4PX9M62Mckz3LTq for ; Thu, 9 Mar 2023 00:40:18 +0000 (UTC) (envelope-from kostikbel@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.17.1/8.17.1) with ESMTPS id 3290e47X037336 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Thu, 9 Mar 2023 02:40:07 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 3290e47X037336 Received: (from kostik@localhost) by tom.home (8.17.1/8.17.1/Submit) id 3290e4vf037111; Thu, 9 Mar 2023 02:40:04 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Thu, 9 Mar 2023 02:40:04 +0200 From: Konstantin Belousov To: Alexander Lochmann Cc: freebsd-fs@freebsd.org Subject: Re: Understanding locking for buf Message-ID: References: <45d84dae-0ca9-95ed-f6fd-8243797453ff@tu-dortmund.de> <8e8d9145-9ee1-195e-3dd3-4e3166ac8abb@tu-dortmund.de> <8e9ac2ec-6387-27b0-5cdc-1d61dbe2c831@tu-dortmund.de> <1743b9f5-69be-b775-fb57-92b8115d4a81@tu-dortmund.de> List-Id: Filesystems List-Archive: https://lists.freebsd.org/archives/freebsd-fs List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-fs@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-14) on tom.home X-Rspamd-Queue-Id: 4PX9M62Mckz3LTq X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-ThisMailContainsUnwantedMimeParts: N On Wed, Mar 08, 2023 at 10:19:23AM +0100, Alexander Lochmann wrote: > On 03.03.23 01:19, Konstantin Belousov wrote: > > All it means it that the statistic output by mount -v would be somewhat off > > in the split of io ops by sync/async. The total count is still correct. > Ic. Thx. > > So. The b_lock is subject to the ownership switch even if a synchronous read > via breadn_flags() and bufwait() is performed. Am I right? > > In our log, I see the following: > - Kernel tries to mount the rootfs via readsuper(). The thread id is 100002. > - 100002 allocates an instance of struct buf. > - The b_lock is acquired by 100002 in buf_alloc(). > - Various accesses to buf by 100002. > - Various accesses to buf by 100033 during g_vfs_done(). > - Again various accesses to buf by 100002. > - The instances is unlocked and freed by 100002. (readsuper() -> > ffs_use_bread() -> brelse() -> buf_free()[ -> BUF_UNLOCK()]) > > If that instance's ownership were changed during the IO op, the b_lock would > have been unlocked by the wrong context. > Is that correct? Am I missing something? I said that sometimes it is still subject to change even with sync ops.