From owner-freebsd-fs@freebsd.org Fri Mar 12 18:57:58 2021 Return-Path: Delivered-To: freebsd-fs@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 9E2635AA2E5 for ; Fri, 12 Mar 2021 18:57:58 +0000 (UTC) (envelope-from alexander.lochmann@tu-dortmund.de) Received: from unimail.uni-dortmund.de (mx1.hrz.uni-dortmund.de [129.217.128.51]) (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-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "unimail.tu-dortmund.de", Issuer "DFN-Verein Global Issuing CA" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Dxw794LBgz4kXQ for ; Fri, 12 Mar 2021 18:57:57 +0000 (UTC) (envelope-from alexander.lochmann@tu-dortmund.de) Received: from [192.168.111.102] (p4fd97a57.dip0.t-ipconnect.de [79.217.122.87]) (authenticated bits=0) by unimail.uni-dortmund.de (8.16.1/8.16.1) with ESMTPSA id 12CIvson024280 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 12 Mar 2021 19:57:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tu-dortmund.de; s=unimail; t=1615575474; bh=qUJ8LUx7BgrWXlfspLIo9wsndlopGS0c1TpaokKHzxE=; h=To:From:Subject:Date; b=U386HjWwBTv/5TRkQ4OsUNIaqAzgu9qAOkkZc/oAaBbUb7fh6f0ASyZ3LSx5gm/RW v8P9AyADPe4uqztkPtxLN0R+MeMJw+EyMomyzS30cHP1r9klE7oRFy4tW3NYKxvRHc hy/PwOaGap9Vipn9Q1bPnzKhWFTFsZH6594zgbjs= To: freebsd-fs@freebsd.org From: Alexander Lochmann Subject: [RFC] Understanding the locking of struct buf Message-ID: <49130618-349a-bfc7-6d26-0c3763904dc5@tu-dortmund.de> Date: Fri, 12 Mar 2021 19:57:54 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4Dxw794LBgz4kXQ X-Spamd-Bar: ----- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=tu-dortmund.de header.s=unimail header.b=U386HjWw; dmarc=none; spf=pass (mx1.freebsd.org: domain of alexander.lochmann@tu-dortmund.de designates 129.217.128.51 as permitted sender) smtp.mailfrom=alexander.lochmann@tu-dortmund.de X-Spamd-Result: default: False [-5.20 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; RWL_MAILSPIKE_GOOD(0.00)[129.217.128.51:from]; R_SPF_ALLOW(-0.20)[+ip4:129.217.128.0/24]; TO_DN_NONE(0.00)[]; RCVD_DKIM_ARC_DNSWL_MED(-0.50)[]; RCVD_IN_DNSWL_MED(-0.20)[129.217.128.51:from]; DKIM_TRACE(0.00)[tu-dortmund.de:+]; NEURAL_HAM_SHORT(-1.00)[-1.000]; RECEIVED_SPAMHAUS_PBL(0.00)[79.217.122.87:received]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:680, ipnet:129.217.0.0/16, country:DE]; MID_RHS_MATCH_FROM(0.00)[]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[tu-dortmund.de:s=unimail]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-fs@freebsd.org]; DMARC_NA(0.00)[tu-dortmund.de]; RCPT_COUNT_ONE(0.00)[1]; DWL_DNSWL_LOW(-1.00)[tu-dortmund.de:dkim]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; MAILMAN_DEST(0.00)[freebsd-fs] X-Mailman-Approved-At: Fri, 12 Mar 2021 19:29:36 +0000 X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Mar 2021 18:57:58 -0000 Hi folks! According to the definition [1], any access to a struct buf is protected by a lock: 1) Are there exceptions to those locking rules for reading and/or writing a member? E.g. any read is permitted without a lock being held. Can b_bcount, for example, be read without a lock? 2) In vfs_bio.c, for example, the BUF_KERNPROC macro is used to move ownership of a buf.b_lock to the kernel. In _lockmgr_disown() [2] WITNESS_UNLOCK() is called to emulate an unlock. So, shouldn't be there a WITNESS_LOCK() for that lock? Otherwise, the Witness system might complain about the upcoming unlock. 3) Is the function brelse()/bqrelse() considered to be a destruction function? Hence, no lock (buf.b_lock) is needed within this function to access a struct buf. Thanks! Regards, Alex [1] https://github.com/freebsd/freebsd-src/blob/main/sys/sys/buf.h#L99 [2] https://github.com/freebsd/freebsd-src/blob/main/sys/kern/kern_lock.c#L1616 [3] https://github.com/freebsd/freebsd-src/blob/main/sys/sys/buf.h#L387 -- Technische Universität Dortmund Alexander Lochmann PGP key: 0xBC3EF6FD Otto-Hahn-Str. 16 phone: +49.231.7556141 D-44227 Dortmund fax: +49.231.7556116 http://ess.cs.tu-dortmund.de/Staff/al