From nobody Mon Feb 27 14:23:47 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 4PQN6F014Zz3v9SS for ; Mon, 27 Feb 2023 14:24:05 +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 4PQN6445Ygz3GMG for ; Mon, 27 Feb 2023 14:23:56 +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 31RENmKU050915 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 27 Feb 2023 16:23:51 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 31RENmKU050915 Received: (from kostik@localhost) by tom.home (8.17.1/8.17.1/Submit) id 31RENlP4050914; Mon, 27 Feb 2023 16:23:47 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Mon, 27 Feb 2023 16:23:47 +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> 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: <8e8d9145-9ee1-195e-3dd3-4e3166ac8abb@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: 4PQN6445Ygz3GMG 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 Mon, Feb 27, 2023 at 09:38:47AM +0100, Alexander Lochmann wrote: > On 24.02.23 21:41, Konstantin Belousov wrote: > > > Viewing it from a different angle: Are accesses in g_vfs_done safe because > > > the buf instance is already locked from a global perspective? > > > Hence, other code paths would block on BUF_LOCK(). > > geom completion code is the only code that allowed to touch the buffer > > after the ownership was relinguished. > > > > I believe I already tell that to you: consider the buffer lock after > > LK_KERNPROC as a semaphore and not lock. > Yeah, you already did. I understand it. > When synchronous IO is performed, the LK_KERNPROC thing isn't used. The lock > is still owned by the context that triggered the IO operation. Not quite. Sync io (bread()) means that caller performs bufwait() on the buffer. It is still subject to the LK_KERNPROC ownership move. > Am I right that even in this situation the accesses from g_vfs_done are > performed? I hope that the previous note answers this. > Can those accesses be considered as valid exceptions of the overall locking > rule 'use b_lock' since the buf is locked? I am not sure what would be 'valid exceptions'. I explained the locking scheme used.