From nobody Thu Mar 16 11:24:24 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 4PclKF5wGTz3ykYM for ; Thu, 16 Mar 2023 11:24:33 +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 4PclKF2D3Xz4GDZ for ; Thu, 16 Mar 2023 11:24:32 +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 32GBOPMa090742 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Thu, 16 Mar 2023 13:24:28 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 32GBOPMa090742 Received: (from kostik@localhost) by tom.home (8.17.1/8.17.1/Submit) id 32GBOPT3090741; Thu, 16 Mar 2023 13:24:25 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Thu, 16 Mar 2023 13:24:24 +0200 From: Konstantin Belousov To: Alexander Lochmann Cc: freebsd-fs@freebsd.org Subject: Re: Understanding locking for buf Message-ID: References: <8e8d9145-9ee1-195e-3dd3-4e3166ac8abb@tu-dortmund.de> <8e9ac2ec-6387-27b0-5cdc-1d61dbe2c831@tu-dortmund.de> <1743b9f5-69be-b775-fb57-92b8115d4a81@tu-dortmund.de> <6b1181f7-a58f-8d71-a05e-2dcb0a66ae4c@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: <6b1181f7-a58f-8d71-a05e-2dcb0a66ae4c@tu-dortmund.de> 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: 4PclKF2D3Xz4GDZ 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 Thu, Mar 16, 2023 at 10:03:15AM +0100, Alexander Lochmann wrote: > > > On 09.03.23 01:40, Konstantin Belousov wrote: > > > 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()]) > > I said that sometimes it is still subject to change even with sync ops. > Ok. Thx. > > Is the following correct? > The aforementioned accesses by 100033 in g_vfs_done() are no violations with > respect to the locking rule because from a global perspective the buf is > locked. It is the only concurrent access at that moment. I would formulate it differently: No other thread might legitimately get access to the buffer using either bread() or getblk() until current io operation finishes. The io operation is handled in two contexts: top-level, where a thread used getblk() as usual to claim buffer ownership, and completion thread context (geom up thread). The completion code legitimately manipulates the buffer, because the top-level code expects that after the buffer strategy routine is called, effectively moving the ownership to the geom up thread.